more spaces and curly braces

Signed-off-by: Roland Haeder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2017-04-08 20:00:54 +02:00
parent 80f41991a5
commit a66f6fe668
No known key found for this signature in database
GPG Key ID: B72F8185C6C7BD78
1 changed files with 85 additions and 62 deletions

View File

@ -70,8 +70,9 @@ function item_redir_and_replace_images($body, $images, $cid) {
$newbody .= substr($origbody, 0, $pos['start']['open']);
$subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
$origbody = substr($origbody, $pos['end']['close']);
if ($origbody === false)
if ($origbody === false) {
$origbody = '';
}
$subject = preg_replace($search, $replace, $subject);
$newbody .= $subject;
@ -100,9 +101,11 @@ function item_redir_and_replace_images($body, $images, $cid) {
function localize_item(&$item) {
$extracted = item_extract_images($item['body']);
if ($extracted['images'])
if ($extracted['images']) {
$item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
}
/// @Separted ???
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
if (activity_match($item['verb'], ACTIVITY_LIKE)
|| activity_match($item['verb'], ACTIVITY_DISLIKE)
@ -110,8 +113,10 @@ function localize_item(&$item){
|| activity_match($item['verb'], ACTIVITY_ATTENDNO)
|| activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
$r = q("SELECT * from `item`,`contact` WHERE
`item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
/// @TODO may hurt performance
$r = q("SELECT * FROM `item`, `contact`
WHERE `item`.`contact-id`=`contact`.`id`
AND `item`.`uri`='%s'",
dbesc($item['parent-uri']));
if (!dbm::is_result($r)) {
return;
@ -182,21 +187,25 @@ function localize_item(&$item){
case "alternate": $Blink = $atts['href'];
case "photo": $Bphoto = $atts['href'];
}
}
$A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
if ($Bphoto != "") {
$Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
}
$item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
}
if (stristr($item['verb'], ACTIVITY_POKE)) {
$verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
if (! $verb)
if (! $verb) {
return;
if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
}
if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) {
return;
}
$Aname = $item['author-name'];
$Alink = $item['author-link'];
@ -207,22 +216,26 @@ function localize_item(&$item){
$links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
$Bname = $obj->title;
$Blink = ""; $Bphoto = "";
$Blink = "";
$Bphoto = "";
foreach ($links->link as $l) {
$atts = $l->attributes();
switch ($atts['rel']) {
case "alternate": $Blink = $atts['href'];
case "photo": $Bphoto = $atts['href'];
}
}
$A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
if ($Bphoto != "") {
$Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
}
// we can't have a translation string with three positions but no distinguishable text
// So here is the translate string.
/*
* we can't have a translation string with three positions but no distinguishable text
* So here is the translate string.
*/
$txt = t('%1$s poked %2$s');
// now translate the verb
@ -236,8 +249,9 @@ function localize_item(&$item){
}
if (stristr($item['verb'], ACTIVITY_MOOD)) {
$verb = urldecode(substr($item['verb'], strpos($item['verb'], '#') + 1));
if (! $verb)
if (! $verb) {
return;
}
$Aname = $item['author-name'];
$Alink = $item['author-link'];
@ -249,10 +263,16 @@ function localize_item(&$item){
}
if (activity_match($item['verb'], ACTIVITY_TAG)) {
$r = q("SELECT * from `item`,`contact` WHERE
`item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
/// @TODO may hurt performance "joining" two tables + asterisk
$r = q("SELECT * FROM `item`, `contact`
WHERE `item`.`contact-id`=`contact`.`id`
AND `item`.`uri`='%s'",
dbesc($item['parent-uri']));
if (!dbm::is_result($r)) return;
if (!dbm::is_result($r)) {
return;
}
$obj = $r[0];
$author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
@ -276,6 +296,8 @@ function localize_item(&$item){
} else {
$post_type = t('status');
}
// Let's break everthing ... ;-)
break;
}
$plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
@ -287,8 +309,9 @@ function localize_item(&$item){
}
if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
if ($item['object-type']== "")
if ($item['object-type'] == "") {
return;
}
$Aname = $item['author-name'];
$Alink = $item['author-link'];
@ -297,10 +320,11 @@ function localize_item(&$item){
$obj = parse_xml_string($xmlhead.$item['object']);
if (strlen($obj->id)) {
$r = q("select * from item where uri = '%s' and uid = %d limit 1",
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($obj->id),
intval($item['uid'])
);
if (dbm::is_result($r) && $r[0]['plink']) {
$target = $r[0];
$Bname = $target['author-name'];
@ -309,17 +333,17 @@ function localize_item(&$item){
$B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
$P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
$item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
}
}
}
$matches = null;
if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) {
foreach ($matches as $mtch) {
if (! strpos($mtch[1],'zrl='))
if (! strpos($mtch[1], 'zrl=')) {
$item['body'] = str_replace($mtch[0], '@[url=' . zrl($mtch[1]) . ']', $item['body']);
}
}
}
// add zrl's to public images
$photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
@ -339,13 +363,11 @@ function localize_item(&$item){
$item['plink'] = $y . '?f=&url=' . $item['plink'];
}
}
}
/**
* Count the total of comments on this item and its desendants
* @TODO proper type-hint + doc-tag
*/
function count_descendants($item) {
$total = count($item['children']);
@ -363,8 +385,10 @@ function count_descendants($item) {
function visible_activity($item) {
// likes (etc.) can apply to other things besides posts. Check if they are post children,
// in which case we handle them specially
/*
* likes (etc.) can apply to other things besides posts. Check if they are post children,
* in which case we handle them specially
*/
$hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
foreach ($hidden_activities as $act) {
@ -386,7 +410,6 @@ function visible_activity($item) {
* @brief SQL query for items
*/
function item_query() {
return "SELECT ".item_fieldlists()." FROM `item` ".
item_joins()." WHERE ".item_condition();
}
@ -446,7 +469,6 @@ These Fields are not added below (yet). They are here to for bug search.
* @brief SQL join for contacts that are needed for displaying items
*/
function item_joins() {
return "STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND
(NOT `contact`.`blocked` OR `contact`.`pending`)
LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
@ -457,10 +479,10 @@ function item_joins() {
* @brief SQL condition for items that are needed for displaying items
*/
function item_condition() {
return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`";
}
if (!function_exists('conversation')) {
/**
* "Render" a conversation or list of items for HTML display.
* There are two major forms of display:
@ -471,8 +493,6 @@ function item_condition() {
* that are based on unique features of the calling module.
*
*/
if (!function_exists('conversation')) {
function conversation(App $a, $items, $mode, $update, $preview = false) {
require_once 'include/bbcode.php';
@ -605,9 +625,12 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
// "New Item View" on network page or search page results
// - just loop through the items and format them minimally for display
/*
* "New Item View" on network page or search page results
* - just loop through the items and format them minimally for display
*/
/// @TODO old lost code?
// $tpl = get_markup_template('search_item.tpl');
$tpl = 'search_item.tpl';
@ -688,7 +711,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$profile_link = zrl($profile_link);
}
if (!isset($item['author-thumb']) OR ($item['author-thumb'] == "")) {
if (!x($item, 'author-thumb') OR ($item['author-thumb'] == "")) {
$author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
if ($author_contact["thumb"]) {
$item['author-thumb'] = $author_contact["thumb"];
@ -975,7 +998,7 @@ function item_photo_menu($item) {
}
if (local_user()) {
$menu = Array(
$menu = array(
t('Follow Thread') => $sub_link,
t('View Status') => $status_link,
t('View Profile') => $profile_link,