X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fcontent.php;h=c4b1f2f68f9a51a11d3f13b1e878544b970de9aa;hb=313bc5b0d26546fb92f2d5f4a4d98cc27924155e;hp=06f5d58b22accd6c3b69389bc720f6acdbcf912d;hpb=0d4d15c73d0bd7f571753d40937ead4c55a797b8;p=friendica.git diff --git a/mod/content.php b/mod/content.php index 06f5d58b22..c4b1f2f68f 100644 --- a/mod/content.php +++ b/mod/content.php @@ -11,8 +11,8 @@ // There is no "pagination query", but we will manage the "current page" on the client // and provide a link to fetch the next page - until there are no pages left to fetch. -// With the exception of complex tag and text searches, this prototype is incredibly -// fast - e.g. one or two milliseconds to fetch parent items for the current content, +// With the exception of complex tag and text searches, this prototype is incredibly +// fast - e.g. one or two milliseconds to fetch parent items for the current content, // and 10-20 milliseconds to fetch all the child items. @@ -131,7 +131,9 @@ function content_content(&$a, $update = 0) { } $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` like '" . protect_sprintf('%<' . intval($group) . '>%') . "' ) and deleted = 0 ) "; - $o = '

' . t('Group: ') . $r[0]['name'] . '

' . $o; + $o = replace_macros(get_markup_template("section_title.tpl"),array( + '$title' => sprintf( t('Group: %s'), $r[0]['name']) + )) . $o; } elseif($cid) { @@ -173,27 +175,15 @@ function content_content(&$a, $update = 0) { if (get_config('system','only_tag_search')) $tag = true; - /*if (get_config('system','use_fulltext_engine')) { - if(strpos($search,'#') === 0) - $sql_extra .= sprintf(" AND (MATCH(tag) AGAINST ('%s' in boolean mode)) ", - dbesc(protect_sprintf($search)) - ); - else - $sql_extra .= sprintf(" AND (MATCH(`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode)) ", - dbesc(protect_sprintf($search)), - dbesc(protect_sprintf($search)) - ); - } else { - $sql_extra .= sprintf(" AND ( `item`.`body` like '%s' OR `item`.`tag` like '%s' ) ", - dbesc(protect_sprintf('%' . $search . '%')), - dbesc(protect_sprintf('%]' . $search . '[%')) - ); - }*/ - if($tag) { - $sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ", - dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); - $sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; + //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ", + // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); + //$sql_table = "`term` INNER JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; + + $sql_extra = ""; + $sql_table = sprintf("`item` INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", + dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval(local_user())); + } else { if (get_config('system','use_fulltext_engine')) $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search))); @@ -211,18 +201,6 @@ function content_content(&$a, $update = 0) { $myurl = substr($myurl,strpos($myurl,'://')+3); $myurl = str_replace('www.','',$myurl); $diasp_url = str_replace('/profile/','/u/',$myurl); - /*if (get_config('system','use_fulltext_engine')) - $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from $sql_table where (MATCH(`author-link`, `tag`) AGAINST ('%s' in boolean mode) or MATCH(tag) AGAINST ('%s' in boolean mode))) ", - dbesc(protect_sprintf($myurl)), - dbesc(protect_sprintf($myurl)), - dbesc(protect_sprintf($diasp_url)) - ); - else - $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from $sql_table where ( `author-link` like '%s' or `tag` like '%s' or tag like '%s' )) ", - dbesc(protect_sprintf('%' . $myurl)), - dbesc(protect_sprintf('%' . $myurl . ']%')), - dbesc(protect_sprintf('%' . $diasp_url . ']%')) - );*/ $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)", dbesc(protect_sprintf($myurl)), @@ -239,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` - FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + `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']) ); @@ -264,7 +242,7 @@ function content_content(&$a, $update = 0) { $start = dba_timer(); $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid` - FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + 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 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`parent` = `item`.`id` @@ -290,8 +268,8 @@ 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` - FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + `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 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 @@ -331,8 +309,8 @@ function content_content(&$a, $update = 0) { function render_content(&$a, $items, $mode, $update, $preview = false) { - require_once('include/bbcode.php'); + require_once('mod/proxy.php'); $ssl_state = ((local_user()) ? true : false); @@ -341,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; @@ -371,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); @@ -383,14 +368,16 @@ 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) $threads = array(); $threadsid = -1; - + if($items && count($items)) { if($mode === 'network-new' || $mode === 'search' || $mode === 'community') { @@ -411,18 +398,22 @@ 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']; } else $nickname = $a->user['nickname']; - + // prevent private email from leaking. if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) continue; - + $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); if($item['author-link'] && (! $item['author-name'])) $profile_name = $item['author-link']; @@ -436,18 +427,19 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { if($sp) $sparkle = ' sparkle'; else - $profile_link = zrl($profile_link); + $profile_link = zrl($profile_link); - $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']); - if(($normalised != 'mailbox') && (x($a->contacts[$normalised]))) - $profile_avatar = $a->contacts[$normalised]['thumb']; + // 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"]) + $profile_avatar = $author_contact["thumb"]; else - $profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']); + $profile_avatar = $item['author-avatar']; $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => ''); call_hooks('render_location',$locate); - $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate)); + $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate)); localize_item($item); if($mode === 'network-new') @@ -464,7 +456,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { $star = false; $isstarred = "unstarred"; - + $lock = false; $likebuttons = false; $shareable = false; @@ -487,7 +479,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { $location_e = $location; $owner_name_e = $owner_name; } - + //$tmp_item = replace_macros($tpl,array( $tmp_item = array( 'template' => $tpl, @@ -498,7 +490,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { 'name' => $name_e, 'sparkle' => $sparkle, 'lock' => $lock, - 'thumb' => $profile_avatar, + 'thumb' => proxy_url($profile_avatar, false, PROXY_SIZE_THUMB), 'title' => $title_e, 'body' => $body_e, 'text' => $text_e, @@ -507,7 +499,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { 'indent' => '', 'owner_name' => $owner_name_e, 'owner_url' => $owner_url, - 'owner_photo' => $owner_photo, + 'owner_photo' => proxy_url($owner_photo, false, PROXY_SIZE_THUMB), 'plink' => get_plink($item), 'edpost' => false, 'isstarred' => $isstarred, @@ -517,7 +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/' . $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'))), 'previewing' => $previewing, 'wait' => t('Please wait'), ); @@ -551,12 +544,11 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { $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; @@ -577,8 +569,11 @@ 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))) + 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; @@ -589,7 +584,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { // (author collapsing is currently disabled) // If a single author has more than 3 consecutive top-level posts, squash the remaining ones. // If there are more than two comments, squash all but the last 2. - + if($toplevelpost) { $item_writeable = (($item['writable'] || $item['self']) ? true : false); @@ -598,7 +593,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { $comments_collapsed = false; $comment_lastcollapsed = false; $comment_firstcollapsed = false; - + $threadsid++; $threads[$threadsid]['id'] = $item['item_id']; $threads[$threadsid]['private'] = $item['private']; @@ -614,7 +609,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { $comments_seen ++; $comment_lastcollapsed = false; $comment_firstcollapsed = false; - } + } $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false); $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false); @@ -636,7 +631,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { $comment_lastcollapsed = true; } - $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ; + $redirect_url = 'redir/' . $item['cid'] ; $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])))) @@ -661,7 +656,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { $owner_photo = $a->page_contact['thumb']; $owner_name = $a->page_contact['name']; $template = $wallwall; - $commentww = 'ww'; + $commentww = 'ww'; } if((! $item['wall']) && $item['owner-link']) { @@ -679,7 +674,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { // well that it's the same Bob Smith. // But it could be somebody else with the same name. It just isn't highly likely. - + $owner_url = $item['owner-link']; $owner_photo = $item['owner-avatar']; @@ -782,6 +777,28 @@ 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 (count($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"); } @@ -806,29 +823,45 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { if($sp) $sparkle = ' sparkle'; else - $profile_link = zrl($profile_link); + $profile_link = zrl($profile_link); - $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']); - if(($normalised != 'mailbox') && (x($a->contacts,$normalised))) - $profile_avatar = $a->contacts[$normalised]['thumb']; + // 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"]) + $profile_avatar = $author_contact["thumb"]; else - $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb)); - - $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']) : ''); + $profile_avatar = $item['author-avatar']; + + $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); - $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate)); + $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate)); $indent = (($toplevelpost) ? '' : ' comment'); $shiny = ""; if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0) - $shiny = 'shiny'; + $shiny = 'shiny'; - // + // localize_item($item); @@ -866,12 +899,14 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { 'comment_lastcollapsed' => $comment_lastcollapsed, // template to use to render item (wall, walltowall, search) 'template' => $template, - + 'type' => implode("",array_slice(explode("/",$item['verb']),-1)), 'tags' => $tags, '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'), @@ -880,30 +915,40 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), 'name' => $name_e, - 'thumb' => $profile_avatar, + 'thumb' => proxy_url($profile_avatar, false, PROXY_SIZE_THUMB), '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, 'shiny' => $shiny, 'owner_url' => $owner_url, - 'owner_photo' => $owner_photo, + 'owner_photo' => proxy_url($owner_photo, false, PROXY_SIZE_THUMB), 'owner_name' => $owner_name_e, 'plink' => get_plink($item), '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), );