]> git.mxchange.org Git - friendica.git/blobdiff - mod/network.php
Several default features are now in the core
[friendica.git] / mod / network.php
index 6f02e8c1139d012e4387c2320916c1d66ac12b07..58f9484250f2cd8e8f41f808948b7b1be5bdd48f 100644 (file)
@@ -10,13 +10,16 @@ use Friendica\Content\ForumManager;
 use Friendica\Content\Nav;
 use Friendica\Content\Pager;
 use Friendica\Content\Widget;
+use Friendica\Content\Text\HTML;
 use Friendica\Core\ACL;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\Hook;
 use Friendica\Core\L10n;
+use Friendica\Core\Logger;
 use Friendica\Core\PConfig;
 use Friendica\Core\Protocol;
+use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
@@ -25,6 +28,7 @@ use Friendica\Model\Profile;
 use Friendica\Module\Login;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Proxy as ProxyUtils;
+use Friendica\Util\Strings;
 
 require_once 'include/conversation.php';
 require_once 'include/items.php';
@@ -38,7 +42,7 @@ function network_init(App $a)
 
        Hook::add('head', __FILE__, 'network_infinite_scroll_head');
 
-       $search = (x($_GET, 'search') ? escape_tags($_GET['search']) : '');
+       $search = (x($_GET, 'search') ? Strings::escapeHtml($_GET['search']) : '');
 
        if (($search != '') && !empty($_GET['submit'])) {
                $a->internalRedirect('search?search=' . urlencode($search));
@@ -156,9 +160,8 @@ function network_init(App $a)
                $a->page['aside'] = '';
        }
 
-       $a->page['aside'] .= (Feature::isEnabled(local_user(), 'groups') ?
-               Group::sidebarWidget('network/0', 'network', 'standard', $group_id) : '');
-       $a->page['aside'] .= (Feature::isEnabled(local_user(), 'forumlist_widget') ? ForumManager::widget(local_user(), $cid) : '');
+       $a->page['aside'] .= Group::sidebarWidget('network/0', 'network', 'standard', $group_id);
+       $a->page['aside'] .= ForumManager::widget(local_user(), $cid);
        $a->page['aside'] .= posted_date_widget('network', local_user(), false);
        $a->page['aside'] .= Widget::networks('network', (x($_GET, 'nets') ? $_GET['nets'] : ''));
        $a->page['aside'] .= saved_searches($search);
@@ -167,10 +170,6 @@ function network_init(App $a)
 
 function saved_searches($search)
 {
-       if (!Feature::isEnabled(local_user(), 'savedsearch')) {
-               return '';
-       }
-
        $a = get_app();
 
        $srchurl = '/network?f='
@@ -199,11 +198,11 @@ function saved_searches($search)
                ];
        }
 
-       $tpl = get_markup_template('saved_searches_aside.tpl');
-       $o = replace_macros($tpl, [
+       $tpl = Renderer::getMarkupTemplate('saved_searches_aside.tpl');
+       $o = Renderer::replaceMacros($tpl, [
                '$title'     => L10n::t('Saved Searches'),
                '$add'       => L10n::t('add'),
-               '$searchbox' => search($search, 'netsearch-box', $srchurl, true),
+               '$searchbox' => HTML::search($search, 'netsearch-box', $srchurl, true),
                '$saved'     => $saved,
        ]);
 
@@ -342,11 +341,16 @@ function networkConversation(App $a, $items, Pager $pager, $mode, $update, $orde
        // Set this so that the conversation function can find out contact info for our wall-wall items
        $a->page_contact = $a->contact;
 
+       if (!is_array($items)) {
+               Logger::log("Expecting items to be an array. Got " . print_r($items, true));
+               $items = [];
+       }
+
        $o = conversation($a, $items, $pager, $mode, $update, false, $ordering, local_user());
 
        if (!$update) {
                if (PConfig::get(local_user(), 'system', 'infinite_scroll')) {
-                       $o .= scroll_loader();
+                       $o .= HTML::scrollLoader();
                } else {
                        $o .= $pager->renderMinimal(count($items));
                }
@@ -385,6 +389,10 @@ function network_content(App $a, $update = 0, $parent = 0)
                $o = networkThreadedView($a, $update, $parent);
        }
 
+       if ($o === '') {
+               info("No items found");
+       }
+
        return $o;
 }
 
@@ -459,6 +467,9 @@ function networkFlatView(App $a, $update = 0)
                }
                DBA::close($result);
 
+               if (count($posts) == 0) {
+                       return '';
+               }
                $condition = ['uid' => local_user(), 'id' => $posts];
        } else {
                $condition = ['uid' => local_user()];
@@ -515,9 +526,9 @@ function networkThreadedView(App $a, $update, $parent)
                for ($x = 1; $x < $a->argc; $x ++) {
                        if (is_a_date_arg($a->argv[$x])) {
                                if ($datequery) {
-                                       $datequery2 = escape_tags($a->argv[$x]);
+                                       $datequery2 = Strings::escapeHtml($a->argv[$x]);
                                } else {
-                                       $datequery = escape_tags($a->argv[$x]);
+                                       $datequery = Strings::escapeHtml($a->argv[$x]);
                                        $_GET['order'] = 'post';
                                }
                        } elseif (intval($a->argv[$x])) {
@@ -533,7 +544,7 @@ function networkThreadedView(App $a, $update, $parent)
        $star  = intval(defaults($_GET, 'star' , 0));
        $bmark = intval(defaults($_GET, 'bmark', 0));
        $conv  = intval(defaults($_GET, 'conv' , 0));
-       $order = notags(defaults($_GET, 'order', 'comment'));
+       $order = Strings::escapeTags(defaults($_GET, 'order', 'comment'));
        $nets  =        defaults($_GET, 'nets' , '');
 
        if ($cid) {
@@ -646,13 +657,13 @@ function networkThreadedView(App $a, $update, $parent)
 
                        $sql_post_table .= " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = " . $sql_table . "." . $sql_parent;
                        $sql_extra3 .= " AND (`thread`.`contact-id` IN ($contact_str) ";
-                       $sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '" . protect_sprintf('%<' . intval($gid) . '>%') . "' AND `temp1`.`private`))";
+                       $sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '" . Strings::protectSprintf('%<' . intval($gid) . '>%') . "' AND `temp1`.`private`))";
                } else {
                        $sql_extra3 .= " AND false ";
                        info(L10n::t('Group is empty'));
                }
 
-               $o = replace_macros(get_markup_template('section_title.tpl'), [
+               $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
                        '$title' => L10n::t('Group: %s', $group['name'])
                ]) . $o;
        } elseif ($cid) {
@@ -673,7 +684,7 @@ function networkThreadedView(App $a, $update, $parent)
 
                        $entries[0]['account_type'] = Contact::getAccountType($contact);
 
-                       $o = replace_macros(get_markup_template('viewcontact_template.tpl'), [
+                       $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('viewcontact_template.tpl'), [
                                'contacts' => $entries,
                                'id' => 'network',
                        ]) . $o;
@@ -694,11 +705,11 @@ function networkThreadedView(App $a, $update, $parent)
        }
 
        if ($datequery) {
-               $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created <= '%s' ",
+               $sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.created <= '%s' ",
                                DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
        }
        if ($datequery2) {
-               $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created >= '%s' ",
+               $sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.created >= '%s' ",
                                DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
        }
 
@@ -871,7 +882,7 @@ function networkThreadedView(App $a, $update, $parent)
                                $_SESSION['network_last_date'] = $tag_top_limit;
                        }
 
-                       logger('Tagged items: ' . count($data) . ' - ' . $bottom_limit . ' - ' . $top_limit . ' - ' . local_user().' - '.(int)$update);
+                       Logger::log('Tagged items: ' . count($data) . ' - ' . $bottom_limit . ' - ' . $top_limit . ' - ' . local_user().' - '.(int)$update);
                        $s = [];
                        foreach ($r as $item) {
                                $s[$item['uri']] = $item;
@@ -879,7 +890,7 @@ function networkThreadedView(App $a, $update, $parent)
                        foreach ($data as $item) {
                                // Don't show hash tag posts from blocked or ignored contacts
                                $condition = ["`nurl` = ? AND `uid` = ? AND (`blocked` OR `readonly`)",
-                                       normalise_link($item['author-link']), local_user()];
+                                       Strings::normaliseLink($item['author-link']), local_user()];
                                if (!DBA::exists('contact', $condition)) {
                                        $s[$item['uri']] = $item;
                                }
@@ -977,16 +988,14 @@ function network_tabs(App $a)
                ],
        ];
 
-       if (Feature::isEnabled(local_user(), 'personal_tab')) {
-               $tabs[] = [
-                       'label' => L10n::t('Personal'),
-                       'url'   => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1',
-                       'sel'   => $conv_active,
-                       'title' => L10n::t('Posts that mention or involve you'),
-                       'id'    => 'personal-tab',
-                       'accesskey' => 'r',
-               ];
-       }
+       $tabs[] = [
+               'label' => L10n::t('Personal'),
+               'url'   => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1',
+               'sel'   => $conv_active,
+               'title' => L10n::t('Posts that mention or involve you'),
+               'id'    => 'personal-tab',
+               'accesskey' => 'r',
+       ];
 
        if (Feature::isEnabled(local_user(), 'new_tab')) {
                $tabs[] = [
@@ -1010,16 +1019,14 @@ function network_tabs(App $a)
                ];
        }
 
-       if (Feature::isEnabled(local_user(), 'star_posts')) {
-               $tabs[] = [
-                       'label' => L10n::t('Starred'),
-                       'url'   => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1',
-                       'sel'   => $starred_active,
-                       'title' => L10n::t('Favourite Posts'),
-                       'id'    => 'starred-posts-tab',
-                       'accesskey' => 'm',
-               ];
-       }
+       $tabs[] = [
+               'label' => L10n::t('Starred'),
+               'url'   => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1',
+               'sel'   => $starred_active,
+               'title' => L10n::t('Favourite Posts'),
+               'id'    => 'starred-posts-tab',
+               'accesskey' => 'm',
+       ];
 
        // save selected tab, but only if not in file mode
        if (!x($_GET, 'file')) {
@@ -1031,9 +1038,9 @@ function network_tabs(App $a)
        $arr = ['tabs' => $tabs];
        Addon::callHooks('network_tabs', $arr);
 
-       $tpl = get_markup_template('common_tabs.tpl');
+       $tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
 
-       return replace_macros($tpl, ['$tabs' => $arr['tabs']]);
+       return Renderer::replaceMacros($tpl, ['$tabs' => $arr['tabs']]);
 
        // --- end item filter tabs
 }
@@ -1057,10 +1064,10 @@ function network_infinite_scroll_head(App $a, &$htmlhead)
        if (PConfig::get(local_user(), 'system', 'infinite_scroll')
                && defaults($_GET, 'mode', '') != 'minimal'
        ) {
-               $tpl = get_markup_template('infinite_scroll_head.tpl');
-               $htmlhead .= replace_macros($tpl, [
+               $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
+               $htmlhead .= Renderer::replaceMacros($tpl, [
                        '$pageno'     => $pager->getPage(),
                        '$reload_uri' => $pager->getBaseQueryString()
                ]);
        }
-}
\ No newline at end of file
+}