]> git.mxchange.org Git - friendica-addons.git/blobdiff - dav/friendica/main.php
Update function names
[friendica-addons.git] / dav / friendica / main.php
index 1b9fff86f95b9d691bb516181494adcdff7a8fba..d73edfd3197b1f58baa0765585da68ec2fa4d6af 100644 (file)
@@ -1,22 +1,26 @@
 <?php
 
+use Friendica\Core\Addon;
+use Friendica\Module\Login;
+use Friendica\Util\Emailer;
+
 require_once('include/security.php');
 
 function dav_install()
 {
-       register_hook('event_created', 'addon/dav/dav.php', 'dav_event_created_hook');
-       register_hook('event_updated', 'addon/dav/dav.php', 'dav_event_updated_hook');
-       register_hook('profile_tabs', 'addon/dav/dav.php', 'dav_profile_tabs_hook');
-       register_hook('cron', 'addon/dav/dav.php', 'dav_cron');
+       Addon::registerHook('event_created', 'addon/dav/dav.php', 'dav_event_created_hook');
+       Addon::registerHook('event_updated', 'addon/dav/dav.php', 'dav_event_updated_hook');
+       Addon::registerHook('profile_tabs', 'addon/dav/dav.php', 'dav_profile_tabs_hook');
+       Addon::registerHook('cron', 'addon/dav/dav.php', 'dav_cron');
 }
 
 
 function dav_uninstall()
 {
-       unregister_hook('event_created', 'addon/dav/dav.php', 'dav_event_created_hook');
-       unregister_hook('event_updated', 'addon/dav/dav.php', 'dav_event_updated_hook');
-       unregister_hook('profile_tabs', 'addon/dav/dav.php', 'dav_profile_tabs_hook');
-       unregister_hook('cron', 'addon/dav/dav.php', 'dav_cron');
+       Addon::unregisterHook('event_created', 'addon/dav/dav.php', 'dav_event_created_hook');
+       Addon::unregisterHook('event_updated', 'addon/dav/dav.php', 'dav_event_updated_hook');
+       Addon::unregisterHook('profile_tabs', 'addon/dav/dav.php', 'dav_profile_tabs_hook');
+       Addon::unregisterHook('cron', 'addon/dav/dav.php', 'dav_cron');
 }
 
 
@@ -147,7 +151,7 @@ function dav_content()
 {
        $a = get_app();
        if (!isset($a->user["uid"]) || $a->user["uid"] == 0) {
-               return login();
+               return Login::form();
        }
 
        $x = "";
@@ -159,11 +163,11 @@ function dav_content()
                                if ($a->argv[2] == "new") {
                                        $o = "";
                                        if (isset($_REQUEST["save"])) {
-                                               check_form_security_token_redirectOnErr($a->get_baseurl() . "/dav/wdcal/", "caledit");
+                                               check_form_security_token_redirectOnErr("/dav/wdcal/", "caledit");
                                                $ret = wdcal_postEditPage("new", "", $a->user["uid"], $a->timezone, $a->get_baseurl() . "/dav/wdcal/");
                                                if ($ret["ok"]) notice($ret["msg"]);
                                                else info($ret["msg"]);
-                                               goaway($a->get_baseurl() . "/dav/wdcal/");
+                                               goaway('dav/wdcal/');
                                        }
                                        $o .= wdcal_getNewPage();
                                        return $o;
@@ -177,11 +181,11 @@ function dav_content()
                                                if (isset($a->argv[4]) && $a->argv[4] == "edit") {
                                                        $o = "";
                                                        if (isset($_REQUEST["save"])) {
-                                                               check_form_security_token_redirectOnErr($a->get_baseurl() . "/dav/wdcal/", "caledit");
+                                                               check_form_security_token_redirectOnErr("/dav/wdcal/", "caledit");
                                                                $ret = wdcal_postEditPage($a->argv[3], $a->user["uid"], $a->timezone, $a->get_baseurl() . "/dav/wdcal/");
                                                                if ($ret["ok"]) notice($ret["msg"]);
                                                                else info($ret["msg"]);
-                                                               goaway($a->get_baseurl() . "/dav/wdcal/");
+                                                               goaway('dav/wdcal/');
                                                        }
                                                        $o .= wdcal_getEditPage($calendar_id, $a->argv[3]);
                                                        return $o;
@@ -195,11 +199,11 @@ function dav_content()
                        } else {
                                $server = dav_create_server(true, true, false);
                                $cals   = dav_get_current_user_calendars($server, DAV_ACL_READ);
-                               $x      = wdcal_printCalendar($cals, array(), $a->get_baseurl() . "/dav/wdcal/feed/", "week", 0, 200);
+                               $x      = wdcal_printCalendar($cals, [], $a->get_baseurl() . "/dav/wdcal/feed/", "week", 0, 200);
                        }
                }
        } catch (DAVVersionMismatchException $e) {
-               $x = t("The current version of this plugin has not been set up correctly. Please contact the system administrator of your installation of friendica to fix this.");
+               $x = t("The current version of this addon has not been set up correctly. Please contact the system administrator of your installation of friendica to fix this.");
        }
        return $x;
 }
@@ -235,12 +239,12 @@ function dav_event_updated_hook(&$a, &$b)
  */
 function dav_profile_tabs_hook(&$a, &$b)
 {
-       $b["tabs"][] = array(
+       $b["tabs"][] = [
                "label" => t('Calendar'),
                "url"   => $a->get_baseurl() . "/dav/wdcal/",
                "sel"   => "",
                "title" => t('Extended calendar with CalDAV-support'),
-       );
+       ];
 }
 
 
@@ -258,7 +262,7 @@ function dav_cron(&$a, &$b)
                q("UPDATE %s%snotifications SET `notified` = 1 WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $not["id"]);
                $event    = q("SELECT * FROM %s%sjqcalendar WHERE `calendarobject_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $not["calendarobject_id"]);
                $calendar = q("SELECT * FROM %s%scalendars WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $not["calendar_id"]);
-               $users    = array();
+               $users    = [];
                if (count($calendar) != 1 || count($event) == 0) continue;
                switch ($calendar[0]["namespace"]) {
                        case CALDAV_NAMESPACE_PRIVATE:
@@ -271,11 +275,11 @@ function dav_cron(&$a, &$b)
                        case "email":
                        case "display": // @TODO implement "Display"
                                foreach ($users as $user) {
-                                       $find      = array("%to%", "%event%", "%url%");
-                                       $repl      = array($user["username"], $event[0]["Summary"], $a->get_baseurl() . "/dav/wdcal/" . $calendar[0]["id"] . "/" . $not["calendarobject_id"] . "/");
+                                       $find      = ["%to%", "%event%", "%url%"];
+                                       $repl      = [$user["username"], $event[0]["Summary"], $a->get_baseurl() . "/dav/wdcal/" . $calendar[0]["id"] . "/" . $not["calendarobject_id"] . "/"];
                                        $text_text = str_replace($find, $repl, "Hi %to%!\n\nThe event \"%event%\" is about to begin:\n%url%");
                                        $text_html = str_replace($find, $repl, "Hi %to%!<br>\n<br>\nThe event \"%event%\" is about to begin:<br>\n<a href='" . "%url%" . "'>%url%</a>");
-                                       $params    = array(
+                                       $params    = [
                                                'fromName'             => FRIENDICA_PLATFORM,
                                                'fromEmail'            => t('noreply') . '@' . $a->get_hostname(),
                                                'replyTo'              => t('noreply') . '@' . $a->get_hostname(),
@@ -284,8 +288,7 @@ function dav_cron(&$a, &$b)
                                                'htmlVersion'          => $text_html,
                                                'textVersion'          => $text_text,
                                                'additionalMailHeader' => "",
-                                       );
-                                       require_once('include/Emailer.php');
+                                       ];
                                        Emailer::send($params);
                                }
                                break;
@@ -299,9 +302,9 @@ function dav_cron(&$a, &$b)
  * @param App $a
  * @param null|object $o
  */
-function dav_plugin_admin_post(&$a = null, &$o = null)
+function dav_addon_admin_post(&$a = null, &$o = null)
 {
-       check_form_security_token_redirectOnErr('/admin/plugins/dav', 'dav_admin_save');
+       check_form_security_token_redirectOnErr('/admin/addons/dav', 'dav_admin_save');
 
        dav_include_files();
        require_once(__DIR__ . "/database-init.inc.php");
@@ -324,7 +327,7 @@ function dav_plugin_admin_post(&$a = null, &$o = null)
  * @param App $a
  * @param string $o
  */
-function dav_plugin_admin(&$a, &$o)
+function dav_addon_admin(&$a, &$o)
 {
        dav_include_files();
        require_once(__DIR__ . "/database-init.inc.php");