]> git.mxchange.org Git - friendica.git/blobdiff - mod/content.php
Bump DB version
[friendica.git] / mod / content.php
index 71ed927636623ed5eb504d366772c273b0646256..43f3fc2ba686e9acfb39d119c114262a4700a95c 100644 (file)
 // and 10-20 milliseconds to fetch all the child items.
 
 
-function content_content(&$a, $update = 0) {
+function content_content(App $a, $update = 0) {
 
        require_once('include/conversation.php');
 
 
        // Currently security is based on the logged in user
 
-       if(! local_user()) {
+       if (! local_user()) {
                return;
        }
 
@@ -61,7 +61,7 @@ function content_content(&$a, $update = 0) {
 
        $o = '';
 
-       
+
 
        $contact_id = $a->cid;
 
@@ -93,14 +93,14 @@ function content_content(&$a, $update = 0) {
                );
 
                $str = '';
-               if(count($r))
+               if (dbm::is_result($r))
                        foreach($r as $rr)
                                $str .= '<' . $rr['id'] . '>';
                if(strlen($str))
                        $def_acl = array('allow_cid' => $str);
        }
 
-       
+
        $sql_options  = (($star) ? " and starred = 1 " : '');
        $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
 
@@ -113,11 +113,11 @@ function content_content(&$a, $update = 0) {
                        intval($group),
                        intval($_SESSION['uid'])
                );
-               if(! count($r)) {
+               if (! dbm::is_result($r)) {
                        if($update)
                                killme();
                        notice( t('No such group') . EOL );
-                       goaway($a->get_baseurl(true) . '/network');
+                       goaway(App::get_baseurl(true) . '/network');
                        // NOTREACHED
                }
 
@@ -137,11 +137,11 @@ function content_content(&$a, $update = 0) {
        }
        elseif($cid) {
 
-               $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d 
+               $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
                                AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
                        intval($cid)
                );
-               if(count($r)) {
+               if (dbm::is_result($r)) {
                        $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " and deleted = 0 ) ";
 
                }
@@ -197,7 +197,7 @@ function content_content(&$a, $update = 0) {
        }
 
        if($conv) {
-               $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
+               $myurl = App::get_baseurl() . '/profile/'. $a->user['nickname'];
                $myurl = substr($myurl,strpos($myurl,'://')+3);
                $myurl = str_replace('www.','',$myurl);
                $diasp_url = str_replace('/profile/','/u/',$myurl);
@@ -217,14 +217,14 @@ function content_content(&$a, $update = 0) {
                $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
                        `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
                        `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
-                       `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
+                       `contact`.`id` AS `cid`
                        FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                        WHERE `item`.`uid` = %d AND `item`.`visible` = 1
                        AND `item`.`deleted` = 0 and `item`.`moderated` = 0
                        $simple_update
                        AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                        $sql_extra $sql_nets
-                       ORDER BY `item`.`received` DESC $pager_sql ",
+                       ORDER BY `item`.`id` DESC $pager_sql ",
                        intval($_SESSION['uid'])
                );
 
@@ -259,7 +259,7 @@ function content_content(&$a, $update = 0) {
                $parents_arr = array();
                $parents_str = '';
 
-               if(count($r)) {
+               if (dbm::is_result($r)) {
                        foreach($r as $rr)
                                if(! in_array($rr['item_id'],$parents_arr))
                                        $parents_arr[] = $rr['item_id'];
@@ -268,7 +268,7 @@ function content_content(&$a, $update = 0) {
                        $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
                                `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
                                `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
-                               `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
+                               `contact`.`id` AS `cid`
                                FROM $sql_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                                WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
                                AND `item`.`moderated` = 0
@@ -307,7 +307,7 @@ function content_content(&$a, $update = 0) {
 
 
 
-function render_content(&$a, $items, $mode, $update, $preview = false) {
+function render_content(App $a, $items, $mode, $update, $preview = false) {
 
        require_once('include/bbcode.php');
        require_once('mod/proxy.php');
@@ -319,6 +319,15 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
 
        $previewing = (($preview) ? ' preview ' : '');
 
+       $edited = false;
+       if (strcmp($item['created'], $item['edited'])<>0) {
+               $edited = array(
+                       'label' => t('This entry was edited'),
+                       'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'),
+                       'relative' => relative_date($item['edited'])
+               );
+       }
+
        if($mode === 'network') {
                $profile_owner = local_user();
                $page_writeable = true;
@@ -349,8 +358,6 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
        else
                $return_url = $_SESSION['return_url'] = $a->query_string;
 
-       load_contact_links(local_user());
-
        $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
        call_hooks('conversation_start',$cb);
 
@@ -361,8 +368,10 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
        $wallwall    = 'wallwall_item.tpl';
        $hide_comments_tpl = get_markup_template('hide_comments.tpl');
 
-       $alike = array();
-       $dlike = array();
+       $conv_responses = array(
+               'like' => array('title' => t('Likes','title')), 'dislike' => array('title' => t('Dislikes','title')),
+               'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
+       );
 
 
        // array with html for each thread (parent+comments)
@@ -373,7 +382,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
 
                if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
 
-                       // "New Item View" on network page or search page results 
+                       // "New Item View" on network page or search page results
                        // - just loop through the items and format them minimally for display
 
                        //$tpl = get_markup_template('search_item.tpl');
@@ -389,7 +398,11 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
                                $sparkle     = '';
 
                                if($mode === 'search' || $mode === 'community') {
-                                       if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
+                                       if(((activity_match($item['verb'],ACTIVITY_LIKE))
+                                               || (activity_match($item['verb'],ACTIVITY_DISLIKE))
+                                               || activity_match($item['verb'],ACTIVITY_ATTEND)
+                                               || activity_match($item['verb'],ACTIVITY_ATTENDNO)
+                                               || activity_match($item['verb'],ACTIVITY_ATTENDMAYBE))
                                                && ($item['id'] != $item['parent']))
                                                continue;
                                        $nickname = $item['nickname'];
@@ -437,7 +450,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
 
                                $drop = array(
                                        'dropping' => $dropping,
-                                       'select' => t('Select'), 
+                                       'select' => t('Select'),
                                        'delete' => t('Delete'),
                                );
 
@@ -496,8 +509,8 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
                                        'like' => '',
                                        'dislike' => '',
                                        'comment' => '',
-                                       //'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
-                                       'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state).'/display/'.$item['guid'], 'title'=> t('View in context'))),
+                                       //'conv' => (($preview) ? '' : array('href'=> App::get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
+                                       'conv' => (($preview) ? '' : array('href'=> App::get_baseurl($ssl_state).'/display/'.$item['guid'], 'title'=> t('View in context'))),
                                        'previewing' => $previewing,
                                        'wait' => t('Please wait'),
                                );
@@ -527,16 +540,15 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
                                                $comments[$item['parent']] = 1;
                                        else
                                                $comments[$item['parent']] += 1;
-                               } elseif(! x($comments,$item['parent'])) 
+                               } elseif(! x($comments,$item['parent']))
                                        $comments[$item['parent']] = 0; // avoid notices later on
                        }
 
-                       // map all the like/dislike activities for each parent item 
+                       // map all the like/dislike/attendance activities for each parent item
                        // Store these in the $alike and $dlike arrays
 
                        foreach($items as $item) {
-                               like_puller($a,$item,$alike,'like');
-                               like_puller($a,$item,$dlike,'dislike');
+                               builtin_activity_puller($item, $conv_responses);
                        }
 
                        $comments_collapsed = false;
@@ -558,7 +570,10 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
                                // We've already parsed out like/dislike for special treatment. We can ignore them now
 
                                if(((activity_match($item['verb'],ACTIVITY_LIKE))
-                                       || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
+                                       || (activity_match($item['verb'],ACTIVITY_DISLIKE)
+                                       || activity_match($item['verb'],ACTIVITY_ATTEND)
+                                       || activity_match($item['verb'],ACTIVITY_ATTENDNO)
+                                       || activity_match($item['verb'],ACTIVITY_ATTENDMAYBE)))
                                        && ($item['id'] != $item['parent']))
                                        continue;
 
@@ -618,14 +633,14 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
 
                                $redirect_url = 'redir/' . $item['cid'] ;
 
-                               $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
+                               $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
                                        || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
                                        ? t('Private Message')
                                        : false);
 
 
                                // Top-level wall post not written by the wall owner (wall-to-wall)
-                               // First figure out who owns it. 
+                               // First figure out who owns it.
 
                                $osparkle = '';
 
@@ -652,13 +667,13 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
                                                if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
 
                                                        // The author url doesn't match the owner (typically the contact)
-                                                       // and also doesn't match the contact alias. 
-                                                       // The name match is a hack to catch several weird cases where URLs are 
+                                                       // and also doesn't match the contact alias.
+                                                       // The name match is a hack to catch several weird cases where URLs are
                                                        // all over the park. It can be tricked, but this prevents you from
                                                        // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
-                                                       // well that it's the same Bob Smith. 
+                                                       // well that it's the same Bob Smith.
 
-                                                       // But it could be somebody else with the same name. It just isn't highly likely. 
+                                                       // But it could be somebody else with the same name. It just isn't highly likely.
 
 
                                                        $owner_url = $item['owner-link'];
@@ -667,7 +682,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
                                                        $template = $wallwall;
                                                        $commentww = 'ww';
                                                        // If it is our contact, use a friendly redirect link
-                                                       if((link_compare($item['owner-link'],$item['url'])) 
+                                                       if((link_compare($item['owner-link'],$item['url']))
                                                                && ($item['network'] === NETWORK_DFRN)) {
                                                                $owner_url = $redirect_url;
                                                                $osparkle = ' sparkle';
@@ -679,7 +694,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
                                }
 
                                $likebuttons = '';
-                               $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false); 
+                               $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false);
 
                                if($page_writeable) {
 /*                                     if($toplevelpost) {  */
@@ -699,7 +714,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
 
                                        if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
                                                $comment = replace_macros($cmnt_tpl,array(
-                                                       '$return_path' => '', 
+                                                       '$return_path' => '',
                                                        '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
                                                        '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
                                                        '$id' => $item['item_id'],
@@ -727,10 +742,11 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
                                        }
                                }
 
-                               if(local_user() && link_compare($a->contact['url'],$item['author-link']))
-                                       $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
-                               else
+                               if (local_user() && link_compare($a->contact['url'],$item['author-link'])) {
+                                       $edpost = array(App::get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
+                               } else {
                                        $edpost = false;
+                               }
 
                                $drop = '';
                                $dropping = false;
@@ -740,7 +756,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
 
                                $drop = array(
                                        'dropping' => $dropping,
-                                       'select' => t('Select'), 
+                                       'select' => t('Select'),
                                        'delete' => t('Delete'),
                                );
 
@@ -749,7 +765,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
 
                                $isstarred = "unstarred";
                                if ($profile_owner == local_user()) {
-                                       if($toplevelpost) {
+                                       if ($toplevelpost) {
                                                $isstarred = (($item['starred']) ? "starred" : "unstarred");
 
                                                $star = array(
@@ -762,6 +778,29 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
                                                        'tagger' => t("add tag"),
                                                        'classtagger' => "",
                                                );
+
+                                               $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1",
+                                                       intval($item['uid']),
+                                                       intval($item['id'])
+                                               );
+
+                                               if (dbm::is_result($r)) {
+                                                       $ignore = array(
+                                                               'do' => t("ignore thread"),
+                                                               'undo' => t("unignore thread"),
+                                                               'toggle' => t("toggle ignore status"),
+                                                               'classdo' => (($r[0]['ignored']) ? "hidden" : ""),
+                                                               'classundo' => (($r[0]['ignored']) ? "" : "hidden"),
+                                                               'ignored' =>  t('ignored'),
+                                                       );
+                                               }
+                                               $tagger = '';
+                                               if (feature_enabled($profile_owner,'commtag')) {
+                                                       $tagger = array(
+                                                               'add' => t("add tag"),
+                                                               'class' => "",
+                                                       );
+                                               }
                                        }
                                        $filer = t("save to folder");
                                }
@@ -781,22 +820,40 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
 
                                $sp = false;
                                $profile_link = best_link_url($item,$sp);
-                               if($profile_link === 'mailbox')
+                               if ($profile_link === 'mailbox') {
                                        $profile_link = '';
-                               if($sp)
+                               }
+                               if ($sp) {
                                        $sparkle = ' sparkle';
-                               else
+                               } else {
                                        $profile_link = zrl($profile_link);
+                               }
 
                                // Don't rely on the author-avatar. It is better to use the data from the contact table
                                $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
-                               if ($author_contact["thumb"])
+                               if ($author_contact["thumb"]) {
                                        $profile_avatar = $author_contact["thumb"];
-                               else
+                               } else {
                                        $profile_avatar = $item['author-avatar'];
+                               }
 
-                               $like    = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
-                               $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
+                               $like    = ((x($conv_responses['like'],$item['uri'])) ? format_like($conv_responses['like'][$item['uri']],$conv_responses['like'][$item['uri'] . '-l'],'like',$item['uri']) : '');
+                               $dislike = ((x($conv_responses['dislike'],$item['uri'])) ? format_like($conv_responses['dislike'][$item['uri']],$conv_responses['dislike'][$item['uri'] . '-l'],'dislike',$item['uri']) : '');
+
+                               // process action responses - e.g. like/dislike/attend/agree/whatever
+                               $response_verbs = array('like');
+                               if(feature_enabled($profile_owner,'dislike'))
+                                       $response_verbs[] = 'dislike';
+                               if($item['object-type'] === ACTIVITY_OBJ_EVENT) {
+                                       $response_verbs[] = 'attendyes';
+                                       $response_verbs[] = 'attendno';
+                                       $response_verbs[] = 'attendmaybe';
+                                       if($page_writeable) {
+                                               $isevent = true;
+                                               $attend = array( t('I will attend'), t('I will not attend'), t('I might attend'));
+                                       }
+                               }
+                               $responses = get_responses($conv_responses,$response_verbs,'',$item);
 
                                $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
                                call_hooks('render_location',$locate);
@@ -853,6 +910,8 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
                                        'body' => $body_e,
                                        'text' => $text_e,
                                        'id' => $item['item_id'],
+                                       'isevent' => $isevent,
+                                       'attend' => $attend,
                                        'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
                                        'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
                                        'to' => t('to'),
@@ -865,7 +924,10 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
                                        'osparkle' => $osparkle,
                                        'sparkle' => $sparkle,
                                        'title' => $title_e,
+                                       'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
                                        'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
+                                       'app' => $item['app'],
+                                       'created' => relative_date($item['created']),
                                        'lock' => $lock,
                                        'location' => $location_e,
                                        'indent' => $indent,
@@ -877,14 +939,21 @@ function render_content(&$a, $items, $mode, $update, $preview = false) {
                                        'edpost' => $edpost,
                                        'isstarred' => $isstarred,
                                        'star' => $star,
-                                       'filer' => $filer,
+                                       'ignore'  => ((feature_enabled($profile_owner,'ignore_posts')) ? $ignore : ''),
+                                       'tagger' => $tagger,
+                                       'filer' => ((feature_enabled($profile_owner,'filing')) ? $filer : ''),
                                        'drop' => $drop,
                                        'vote' => $likebuttons,
+                                       'responses' => $responses,
                                        'like' => $like,
                                        'dislike' => $dislike,
+                                       'switchcomment' => t('Comment'),
                                        'comment' => $comment,
                                        'previewing' => $previewing,
                                        'wait' => t('Please wait'),
+                                       'edited' => $edited,
+                                       'network' => $item["item_network"],
+                                       'network_name' => network_to_name($item['network'], $profile_link),
 
                                );