From aaa327ca056fe8d1315b8fff9bb08b1c1d40fa1c Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 15 Apr 2016 01:25:15 -0700 Subject: [PATCH 1/5] testing the new router/module code --- Zotlabs/Web/Router.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Zotlabs/Web/Router.php b/Zotlabs/Web/Router.php index 29f2b5206..699b27891 100644 --- a/Zotlabs/Web/Router.php +++ b/Zotlabs/Web/Router.php @@ -54,7 +54,17 @@ class Router { */ if(! (\App::$module_loaded)) { - if(file_exists("mod/site/{$module}.php")) { + $newmod = ucfirst($module); +logger('0' . "Zotlabs/Module/{$newmod}.php"); + if(file_exists("Zotlabs/Module/{$newmod}.php")) { +logger('1' . "Zotlabs/Module/{$newmod}.php"); + include_once("Zotlabs/Module/{$newmod}.php"); +logger('2'); + if(class_exists("Zotlabs\\Module\\{$newmod}")) + \App::$module_loaded = true; +logger('3'); + } + elseif(file_exists("mod/site/{$module}.php")) { include_once("mod/site/{$module}.php"); \App::$module_loaded = true; } @@ -122,6 +132,12 @@ class Router { * Call module functions */ + $nmod = false; + + $newmod = ucfirst(\App::$module); + if(class_exists("Zotlabs\\Module\\{$newmod}")) + $nmod = true; + if(\App::$module_loaded) { \App::$page['page_title'] = \App::$module; $placeholder = ''; @@ -133,6 +149,10 @@ class Router { * to over-ride them. */ + $modname = (($nmod) ? "Zotlabs\\Module\\{$newmod}" : ''); + if($modname && method_exists($modname,'init')) + logger('function_exists: ' . $modname . '->init'); + if(function_exists(\App::$module . '_init')) { $arr = array('init' => true, 'replace' => false); call_hooks(\App::$module . '_mod_init', $arr); From 07650b4646137e35ec975664ee69f077c9f370d3 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 15 Apr 2016 16:13:55 -0700 Subject: [PATCH 2/5] get init() working with class modules --- Zotlabs/Web/Controller.php | 12 ++++++++++++ Zotlabs/Web/Router.php | 24 +++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 Zotlabs/Web/Controller.php diff --git a/Zotlabs/Web/Controller.php b/Zotlabs/Web/Controller.php new file mode 100644 index 000000000..ac835e008 --- /dev/null +++ b/Zotlabs/Web/Controller.php @@ -0,0 +1,12 @@ +init'); - - if(function_exists(\App::$module . '_init')) { - $arr = array('init' => true, 'replace' => false); - call_hooks(\App::$module . '_mod_init', $arr); - if(! $arr['replace']) { + $arr = array('init' => true, 'replace' => false); + call_hooks(\App::$module . '_mod_init', $arr); + if(! $arr['replace']) { + if($modname && method_exists($modname,'init')) { + logger('function_exists: ' . $modname . '->init'); + $modclass = new $modname; + $modclass->init(); + } + elseif(function_exists(\App::$module . '_init')) { $func = \App::$module . '_init'; $func($a); } @@ -199,6 +204,7 @@ logger('3'); } } + if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! \App::$error) && (function_exists(\App::$module . '_post')) && (! x($_POST, 'auth-params'))) { From b57f69d14d98630caab3207b23e9cc96df34dc43 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 15 Apr 2016 20:43:05 -0700 Subject: [PATCH 3/5] cleanup and test of new router --- Zotlabs/Web/Router.php | 78 +++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/Zotlabs/Web/Router.php b/Zotlabs/Web/Router.php index cbd9c107a..6330efa17 100644 --- a/Zotlabs/Web/Router.php +++ b/Zotlabs/Web/Router.php @@ -5,6 +5,9 @@ namespace Zotlabs\Web; class Router { + private $modname = ''; + private $controller = null; + function __construct(&$a) { /** @@ -54,25 +57,26 @@ class Router { */ if(! (\App::$module_loaded)) { - $newmod = ucfirst($module); -logger('0' . "Zotlabs/Module/{$newmod}.php"); - if(file_exists("Zotlabs/Module/{$newmod}.php")) { -logger('1' . "Zotlabs/Module/{$newmod}.php"); - include_once("Zotlabs/Module/{$newmod}.php"); -logger('2'); - if(class_exists("Zotlabs\\Module\\{$newmod}")) + try { + $modname = "Zotlabs\\Module\\" . ucfirst($module); + $filename = 'Zotlabs/Module/'. ucfirst($module). '.php'; + if(file_exists($filename)) { + $this->controller = new $modname; \App::$module_loaded = true; -logger('3'); + } + else throw new \Exception('Module not found'); } - elseif(file_exists("mod/site/{$module}.php")) { - include_once("mod/site/{$module}.php"); - \App::$module_loaded = true; + catch(\Exception $e) { + if(file_exists("mod/site/{$module}.php")) { + include_once("mod/site/{$module}.php"); + \App::$module_loaded = true; + } + elseif(file_exists("mod/{$module}.php")) { + include_once("mod/{$module}.php"); + \App::$module_loaded = true; + } + else logger("mod/{$module}.php not found."); } - elseif(file_exists("mod/{$module}.php")) { - include_once("mod/{$module}.php"); - \App::$module_loaded = true; - } - else logger("mod/{$module}.php not found."); } @@ -132,16 +136,6 @@ logger('3'); * Call module functions */ - $nmod = false; - $modname = ''; - - $newmod = ucfirst(\App::$module); - - if(class_exists("Zotlabs\\Module\\{$newmod}")) { - $nmod = true; - $modname = "Zotlabs\\Module\\{$newmod}"; - } - if(\App::$module_loaded) { \App::$page['page_title'] = \App::$module; $placeholder = ''; @@ -156,10 +150,8 @@ logger('3'); $arr = array('init' => true, 'replace' => false); call_hooks(\App::$module . '_mod_init', $arr); if(! $arr['replace']) { - if($modname && method_exists($modname,'init')) { - logger('function_exists: ' . $modname . '->init'); - $modclass = new $modname; - $modclass->init(); + if($this->controller && method_exists($this->controller,'init')) { + $this->controller->init(); } elseif(function_exists(\App::$module . '_init')) { $func = \App::$module . '_init'; @@ -204,22 +196,30 @@ logger('3'); } } - - if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! \App::$error) - && (function_exists(\App::$module . '_post')) - && (! x($_POST, 'auth-params'))) { + if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! \App::$error) && (! x($_POST, 'auth-params'))) { call_hooks(\App::$module . '_mod_post', $_POST); - $func = \App::$module . '_post'; - $func($a); + + if($this->controller && method_exists($this->controller,'post')) { + $this->controller->post(); + } + elseif(function_exists(\App::$module . '_post')) { + $func = \App::$module . '_post'; + $func($a); + } } - if((! \App::$error) && (function_exists(\App::$module . '_content'))) { + if(! \App::$error) { $arr = array('content' => \App::$page['content'], 'replace' => false); call_hooks(\App::$module . '_mod_content', $arr); \App::$page['content'] = $arr['content']; if(! $arr['replace']) { - $func = \App::$module . '_content'; - $arr = array('content' => $func($a)); + if($this->controller && method_exists($this->controller,'get')) { + $arr = array('content' => $this->controller->get()); + } + elseif(function_exists(\App::$module . '_content')) { + $func = \App::$module . '_content'; + $arr = array('content' => $func($a)); + } } call_hooks(\App::$module . '_mod_aftercontent', $arr); \App::$page['content'] .= $arr['content']; From 0865d0ef51363764e3a40ba1f146b0cbae70f299 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 15 Apr 2016 22:36:07 -0700 Subject: [PATCH 4/5] Convert Channel to new module --- mod/channel.php => Zotlabs/Module/Channel.php | 90 ++++++++++--------- .../Module/Update_channel.php | 11 ++- 2 files changed, 56 insertions(+), 45 deletions(-) rename mod/channel.php => Zotlabs/Module/Channel.php (69%) rename mod/update_channel.php => Zotlabs/Module/Update_channel.php (91%) diff --git a/mod/channel.php b/Zotlabs/Module/Channel.php similarity index 69% rename from mod/channel.php rename to Zotlabs/Module/Channel.php index 9bc7332dc..cae561266 100644 --- a/mod/channel.php +++ b/Zotlabs/Module/Channel.php @@ -1,4 +1,6 @@ 1) $which = argv(1); if(! $which) { if(local_channel()) { - $channel = App::get_channel(); + $channel = \App::get_channel(); if($channel && $channel['channel_address']) $which = $channel['channel_address']; } @@ -27,19 +30,19 @@ function channel_init(&$a) { } $profile = 0; - $channel = App::get_channel(); + $channel = \App::get_channel(); if((local_channel()) && (argc() > 2) && (argv(2) === 'view')) { $which = $channel['channel_address']; $profile = argv(1); } - App::$page['htmlhead'] .= '' . "\r\n" ; - App::$page['htmlhead'] .= '' . "\r\n" ; + \App::$page['htmlhead'] .= '' . "\r\n" ; + \App::$page['htmlhead'] .= '' . "\r\n" ; // Not yet ready for prime time -// App::$page['htmlhead'] .= '' . "\r\n" ; -// App::$page['htmlhead'] .= '' . "\r\n" ; +// \App::$page['htmlhead'] .= '' . "\r\n" ; +// \App::$page['htmlhead'] .= '' . "\r\n" ; // Run profile_load() here to make sure the theme is set before // we start loading content @@ -48,13 +51,13 @@ function channel_init(&$a) { } -function channel_content(&$a, $update = 0, $load = false) { +function get($update = 0, $load = false) { if($load) $_SESSION['loadtime'] = datetime_convert(); - $checkjs = new Zotlabs\Web\CheckJS(); + $checkjs = new \Zotlabs\Web\CheckJS(); $category = $datequery = $datequery2 = ''; @@ -76,27 +79,27 @@ function channel_content(&$a, $update = 0, $load = false) { if($update) { // Ensure we've got a profile owner if updating. - App::$profile['profile_uid'] = App::$profile_uid = $update; + \App::$profile['profile_uid'] = \App::$profile_uid = $update; } else { - if(App::$profile['profile_uid'] == local_channel()) { + if(\App::$profile['profile_uid'] == local_channel()) { nav_set_selected('home'); } } - $is_owner = (((local_channel()) && (App::$profile['profile_uid'] == local_channel())) ? true : false); + $is_owner = (((local_channel()) && (\App::$profile['profile_uid'] == local_channel())) ? true : false); - $channel = App::get_channel(); - $observer = App::get_observer(); + $channel = \App::get_channel(); + $observer = \App::get_observer(); $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); - $perms = get_all_perms(App::$profile['profile_uid'],$ob_hash); + $perms = get_all_perms(\App::$profile['profile_uid'],$ob_hash); if(! $perms['view_stream']) { // We may want to make the target of this redirect configurable if($perms['view_profile']) { notice( t('Insufficient permissions. Request redirected to profile page.') . EOL); - goaway (z_root() . "/profile/" . App::$profile['channel_address']); + goaway (z_root() . "/profile/" . \App::$profile['channel_address']); } notice( t('Permission denied.') . EOL); return; @@ -105,9 +108,9 @@ function channel_content(&$a, $update = 0, $load = false) { if(! $update) { - $o .= profile_tabs($a, $is_owner, App::$profile['channel_address']); + $o .= profile_tabs($a, $is_owner, \App::$profile['channel_address']); - $o .= common_friends_visitor_widget(App::$profile['profile_uid']); + $o .= common_friends_visitor_widget(\App::$profile['profile_uid']); if($channel && $is_owner) { $channel_acl = array( @@ -125,15 +128,15 @@ function channel_content(&$a, $update = 0, $load = false) { $x = array( 'is_owner' => $is_owner, - 'allow_location' => ((($is_owner || $observer) && (intval(get_pconfig(App::$profile['profile_uid'],'system','use_browser_location')))) ? true : false), - 'default_location' => (($is_owner) ? App::$profile['channel_location'] : ''), - 'nickname' => App::$profile['channel_address'], - 'lockstate' => (((strlen(App::$profile['channel_allow_cid'])) || (strlen(App::$profile['channel_allow_gid'])) || (strlen(App::$profile['channel_deny_cid'])) || (strlen(App::$profile['channel_deny_gid']))) ? 'lock' : 'unlock'), - 'acl' => (($is_owner) ? populate_acl($channel_acl,true,((App::$profile['channel_r_stream'] & PERMS_PUBLIC) ? t('Public') : '')) : ''), + 'allow_location' => ((($is_owner || $observer) && (intval(get_pconfig(\App::$profile['profile_uid'],'system','use_browser_location')))) ? true : false), + 'default_location' => (($is_owner) ? \App::$profile['channel_location'] : ''), + 'nickname' => \App::$profile['channel_address'], + 'lockstate' => (((strlen(\App::$profile['channel_allow_cid'])) || (strlen(\App::$profile['channel_allow_gid'])) || (strlen(\App::$profile['channel_deny_cid'])) || (strlen(\App::$profile['channel_deny_gid']))) ? 'lock' : 'unlock'), + 'acl' => (($is_owner) ? populate_acl($channel_acl,true,((\App::$profile['channel_r_stream'] & PERMS_PUBLIC) ? t('Public') : '')) : ''), 'showacl' => (($is_owner) ? 'yes' : ''), 'bang' => '', 'visitor' => (($is_owner || $observer) ? true : false), - 'profile_uid' => App::$profile['profile_uid'], + 'profile_uid' => \App::$profile['profile_uid'], 'editor_autocomplete' => true, 'bbco_autocomplete' => 'bbcode', 'bbcode' => true @@ -150,18 +153,18 @@ function channel_content(&$a, $update = 0, $load = false) { */ $item_normal = item_normal(); - $sql_extra = item_permissions_sql(App::$profile['profile_uid']); + $sql_extra = item_permissions_sql(\App::$profile['profile_uid']); - if(get_pconfig(App::$profile['profile_uid'],'system','channel_list_mode') && (! $mid)) + if(get_pconfig(\App::$profile['profile_uid'],'system','channel_list_mode') && (! $mid)) $page_mode = 'list'; else $page_mode = 'client'; - $abook_uids = " and abook.abook_channel = " . intval(App::$profile['profile_uid']) . " "; + $abook_uids = " and abook.abook_channel = " . intval(\App::$profile['profile_uid']) . " "; $simple_update = (($update) ? " AND item_unseen = 1 " : ''); - App::$page['htmlhead'] .= "\r\n" . '' . "\r\n"; + \App::$page['htmlhead'] .= "\r\n" . '' . "\r\n"; if($update && $_SESSION['loadtime']) $simple_update = " AND (( item_unseen = 1 AND item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' ) OR item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' ) "; @@ -174,7 +177,7 @@ function channel_content(&$a, $update = 0, $load = false) { $r = q("SELECT parent AS item_id from item where mid like '%s' and uid = %d $item_normal AND item_wall = 1 AND item_unseen = 1 $sql_extra limit 1", dbesc($mid . '%'), - intval(App::$profile['profile_uid']) + intval(\App::$profile['profile_uid']) ); } else { $r = q("SELECT distinct parent AS `item_id`, created from item @@ -184,7 +187,7 @@ function channel_content(&$a, $update = 0, $load = false) { AND (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra ORDER BY created DESC", - intval(App::$profile['profile_uid']) + intval(\App::$profile['profile_uid']) ); $_SESSION['loadtime'] = datetime_convert(); } @@ -207,15 +210,15 @@ function channel_content(&$a, $update = 0, $load = false) { } $itemspage = get_pconfig(local_channel(),'system','itemspage'); - App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20)); - $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start'])); + \App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20)); + $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start'])); if($load || ($checkjs->disabled())) { if ($mid) { $r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d $item_normal AND item_wall = 1 $sql_extra limit 1", dbesc($mid), - intval(App::$profile['profile_uid']) + intval(\App::$profile['profile_uid']) ); if (! $r) { notice( t('Permission denied.') . EOL); @@ -229,7 +232,7 @@ function channel_content(&$a, $update = 0, $load = false) { AND (abook_blocked = 0 or abook.abook_flags is null) $sql_extra $sql_extra2 ORDER BY created DESC $pager_sql ", - intval(App::$profile['profile_uid']) + intval(\App::$profile['profile_uid']) ); } } @@ -247,7 +250,7 @@ function channel_content(&$a, $update = 0, $load = false) { WHERE `item`.`uid` = %d $item_normal AND `item`.`parent` IN ( %s ) $sql_extra ", - intval(App::$profile['profile_uid']), + intval(\App::$profile['profile_uid']), dbesc($parents_str) ); @@ -270,19 +273,19 @@ function channel_content(&$a, $update = 0, $load = false) { // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, // because browser prefetching might change it on us. We have to deliver it with the page. - $maxheight = get_pconfig(App::$profile['profile_uid'],'system','channel_divmore_height'); + $maxheight = get_pconfig(\App::$profile['profile_uid'],'system','channel_divmore_height'); if(! $maxheight) $maxheight = 400; $o .= '
' . "\r\n"; - $o .= "\r\n"; - App::$page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"),array( + \App::$page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"),array( '$baseurl' => z_root(), '$pgtype' => 'channel', - '$uid' => ((App::$profile['profile_uid']) ? App::$profile['profile_uid'] : '0'), + '$uid' => ((\App::$profile['profile_uid']) ? \App::$profile['profile_uid'] : '0'), '$gid' => '0', '$cid' => '0', '$cmin' => '0', @@ -294,7 +297,7 @@ function channel_content(&$a, $update = 0, $load = false) { '$nouveau' => '0', '$wall' => '1', '$fh' => '0', - '$page' => ((App::$pager['page'] != 1) ? App::$pager['page'] : 1), + '$page' => ((\App::$pager['page'] != 1) ? \App::$pager['page'] : 1), '$search' => '', '$order' => '', '$list' => ((x($_REQUEST,'list')) ? intval($_REQUEST['list']) : 0), @@ -348,7 +351,7 @@ function channel_content(&$a, $update = 0, $load = false) { if((! $update) || ($checkjs->disabled())) { $o .= alt_pager($a,count($items)); if ($mid && $items[0]['title']) - App::$page['title'] = $items[0]['title'] . " - " . App::$page['title']; + \App::$page['title'] = $items[0]['title'] . " - " . \App::$page['title']; } if($mid) @@ -356,3 +359,6 @@ function channel_content(&$a, $update = 0, $load = false) { return $o; } + + +} \ No newline at end of file diff --git a/mod/update_channel.php b/Zotlabs/Module/Update_channel.php similarity index 91% rename from mod/update_channel.php rename to Zotlabs/Module/Update_channel.php index 63a3735ea..b1b2d5103 100644 --- a/mod/update_channel.php +++ b/Zotlabs/Module/Update_channel.php @@ -1,5 +1,7 @@ 1) && (argv(1) == 'load')) ? 1 : 0); @@ -33,7 +35,9 @@ function update_channel_content(&$a) { * */ - $text = channel_content($a,$profile_uid,$load); + $mod = new Channel(); + + $text = $mod->get($profile_uid,$load); $pattern = "/]*) src=\"([^\"]*)\"/"; $replace = "\r\n"; killme(); +} } \ No newline at end of file From 521d404013bd677f26e1343a8612631f49ac2fca Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 17 Apr 2016 16:37:44 -0700 Subject: [PATCH 5/5] remove the date hack on public feeds which was a temporary fix for an issue limiting the number of posts returned and no longer needed. --- include/items.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/items.php b/include/items.php index 95822c0ba..fde7ca9a2 100755 --- a/include/items.php +++ b/include/items.php @@ -555,8 +555,8 @@ function get_public_feed($channel, $params) { // put a sane lower limit on feed requests if not specified - if($params['begin'] === NULL_DATE) - $params['begin'] = datetime_convert('UTC','UTC','now - 1 month'); +// if($params['begin'] === NULL_DATE) +// $params['begin'] = datetime_convert('UTC','UTC','now - 1 month'); switch($params['type']) { case 'json':