';
- foreach($arr as $r) {
+ foreach ($arr as $r) {
$matches = false;
$icon = '';
$cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
+ if ($cnt) {
+ foreach ($matches as $mtch) {
$mime = $mtch[3];
- if((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN))
+ if ((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) {
$the_url = 'redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1];
- else
+ } else {
$the_url = $mtch[1];
+ }
- if(strpos($mime, 'video') !== false) {
- if(!$vhead) {
+ if (strpos($mime, 'video') !== false) {
+ if (!$vhead) {
$vhead = true;
$a->page['htmlhead'] .= replace_macros(get_markup_template('videos_head.tpl'), array(
'$baseurl' => z_root(),
@@ -1388,21 +1402,20 @@ function prepare_body(&$item,$attach = false, $preview = false) {
$id = end(explode('/', $the_url));
$as .= replace_macros(get_markup_template('video_top.tpl'), array(
- '$video' => array(
- 'id' => $id,
- 'title' => t('View Video'),
- 'src' => $the_url,
- 'mime' => $mime,
+ '$video' => array(
+ 'id' => $id,
+ 'title' => t('View Video'),
+ 'src' => $the_url,
+ 'mime' => $mime,
),
));
}
$filetype = strtolower(substr( $mime, 0, strpos($mime,'/') ));
- if($filetype) {
+ if ($filetype) {
$filesubtype = strtolower(substr( $mime, strpos($mime,'/') + 1 ));
$filesubtype = str_replace('.', '-', $filesubtype);
- }
- else {
+ } else {
$filetype = 'unkn';
$filesubtype = 'unkn';
}
@@ -1433,7 +1446,7 @@ function prepare_body(&$item,$attach = false, $preview = false) {
$s = $s . $as;
// map
- if(strpos($s,'
') !== false && $item['coord']) {
+ if (strpos($s, '
') !== false && x($item, 'coord')) {
$x = generate_map(trim($item['coord']));
if ($x) {
$s = preg_replace('/\
/','$0' . $x,$s);
@@ -1445,37 +1458,36 @@ function prepare_body(&$item,$attach = false, $preview = false) {
$spoilersearch = '
';
// Remove line breaks before the spoiler
- while ((strpos($s, "\n".$spoilersearch) !== false))
- $s = str_replace("\n".$spoilersearch, $spoilersearch, $s);
- while ((strpos($s, "
".$spoilersearch) !== false))
- $s = str_replace("
".$spoilersearch, $spoilersearch, $s);
+ while ((strpos($s, "\n" . $spoilersearch) !== false)) {
+ $s = str_replace("\n" . $spoilersearch, $spoilersearch, $s);
+ }
+ while ((strpos($s, "
" . $spoilersearch) !== false)) {
+ $s = str_replace("
" . $spoilersearch, $spoilersearch, $s);
+ }
while ((strpos($s, $spoilersearch) !== false)) {
-
$pos = strpos($s, $spoilersearch);
$rnd = random_string(8);
- $spoilerreplace = '
'.sprintf(t('Click to open/close')).''.
- '';
- $s = substr($s, 0, $pos).$spoilerreplace.substr($s, $pos+strlen($spoilersearch));
+ $spoilerreplace = '
' . sprintf(t('Click to open/close')) . ''.
+ '';
+ $s = substr($s, 0, $pos) . $spoilerreplace . substr($s, $pos + strlen($spoilersearch));
}
// Look for quote with author
$authorsearch = '';
while ((strpos($s, $authorsearch) !== false)) {
-
$pos = strpos($s, $authorsearch);
$rnd = random_string(8);
- $authorreplace = '
'.sprintf(t('Click to open/close')).''.
- '';
- $s = substr($s, 0, $pos).$authorreplace.substr($s, $pos+strlen($authorsearch));
+ $authorreplace = '
' . sprintf(t('Click to open/close')) . ''.
+ '';
+ $s = substr($s, 0, $pos) . $authorreplace . substr($s, $pos + strlen($authorsearch));
}
// replace friendica image url size with theme preference
- if (x($a->theme_info,'item_image_size')){
- $ps = $a->theme_info['item_image_size'];
-
- $s = preg_replace('|(]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|',"$1-".$ps, $s);
+ if (x($a->theme_info, 'item_image_size')){
+ $ps = $a->theme_info['item_image_size'];
+ $s = preg_replace('|(]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|', "$1-" . $ps, $s);
}
$prep_arr = array('item' => $item, 'html' => $s);
@@ -1485,7 +1497,7 @@ function prepare_body(&$item,$attach = false, $preview = false) {
}}
-if(! function_exists('prepare_text')) {
+if (! function_exists('prepare_text')) {
/**
* Given a text string, convert from bbcode to html and add smilie icons.
*
@@ -1494,12 +1506,13 @@ if(! function_exists('prepare_text')) {
*/
function prepare_text($text) {
- require_once('include/bbcode.php');
+ require_once 'include/bbcode.php';
- if(stristr($text,'[nosmile]'))
+ if (stristr($text, '[nosmile]')) {
$s = bbcode($text);
- else
+ } else {
$s = Smilies::replace(bbcode($text));
+ }
return trim($s);
}}
@@ -1539,10 +1552,11 @@ function get_cats_and_terms($item) {
$categories = array();
$folders = array();
- $matches = false; $first = true;
- $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
+ $matches = false;
+ $first = true;
+ $cnt = preg_match_all('/<(.*?)>/', $item['file'], $matches, PREG_SET_ORDER);
+ if ($cnt) {
+ foreach ($matches as $mtch) {
$categories[] = array(
'name' => xmlify(file_tag_decode($mtch[1])),
'url' => "#",
@@ -1553,18 +1567,21 @@ function get_cats_and_terms($item) {
$first = false;
}
}
- if (count($categories)) $categories[count($categories)-1]['last'] = true;
+ if (count($categories)) {
+ $categories[count($categories) - 1]['last'] = true;
+ }
- if(local_user() == $item['uid']) {
- $matches = false; $first = true;
- $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
+ if (local_user() == $item['uid']) {
+ $matches = false;
+ $first = true;
+ $cnt = preg_match_all('/\[(.*?)\]/', $item['file'], $matches, PREG_SET_ORDER);
+ if ($cnt) {
+ foreach ($matches as $mtch) {
$folders[] = array(
'name' => xmlify(file_tag_decode($mtch[1])),
'url' => "#",
- 'removeurl' => ((local_user() == $item['uid'])?'filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])):""),
+ 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])) : ""),
'first' => $first,
'last' => false
);
@@ -1573,12 +1590,14 @@ function get_cats_and_terms($item) {
}
}
- if (count($folders)) $folders[count($folders)-1]['last'] = true;
+ if (count($folders)) {
+ $folders[count($folders) - 1]['last'] = true;
+ }
return array($categories, $folders);
}
-if(! function_exists('get_plink')) {
+if (! function_exists('get_plink')) {
/**
* get private link for item
* @param array $item
@@ -1589,33 +1608,32 @@ function get_plink($item) {
if ($a->user['nickname'] != "") {
$ret = array(
- //'href' => "display/".$a->user['nickname']."/".$item['id'],
- 'href' => "display/".$item['guid'],
- 'orig' => "display/".$item['guid'],
+ //'href' => "display/" . $a->user['nickname'] . "/" . $item['id'],
+ 'href' => "display/" . $item['guid'],
+ 'orig' => "display/" . $item['guid'],
'title' => t('View on separate page'),
'orig_title' => t('view on separate page'),
);
- if (x($item,'plink')) {
+ if (x($item, 'plink')) {
$ret["href"] = $a->remove_baseurl($item['plink']);
$ret["title"] = t('link to source');
}
- } elseif (x($item,'plink') && ($item['private'] != 1))
+ } elseif (x($item, 'plink') && ($item['private'] != 1)) {
$ret = array(
'href' => $item['plink'],
'orig' => $item['plink'],
'title' => t('link to source'),
);
- else
+ } else {
$ret = array();
+ }
- //if (x($item,'plink') && ($item['private'] != 1))
-
- return($ret);
+ return $ret;
}}
-if(! function_exists('unamp')) {
+if (! function_exists('unamp')) {
/**
* replace html amp entity with amp char
* @param string $s
@@ -1626,7 +1644,7 @@ function unamp($s) {
}}
-if(! function_exists('return_bytes')) {
+if (! function_exists('return_bytes')) {
/**
* return number of bytes in size (K, M, G)
* @param string $size_str
@@ -1651,9 +1669,11 @@ function generate_user_guid() {
$x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
dbesc($guid)
);
- if(! count($x))
+ if (! dbm::is_result($x)) {
$found = false;
+ }
} while ($found == true );
+
return $guid;
}
@@ -1665,10 +1685,11 @@ function generate_user_guid() {
*/
function base64url_encode($s, $strip_padding = false) {
- $s = strtr(base64_encode($s),'+/','-_');
+ $s = strtr(base64_encode($s), '+/', '-_');
- if($strip_padding)
+ if ($strip_padding) {
$s = str_replace('=','',$s);
+ }
return $s;
}
@@ -1679,7 +1700,7 @@ function base64url_encode($s, $strip_padding = false) {
*/
function base64url_decode($s) {
- if(is_array($s)) {
+ if (is_array($s)) {
logger('base64url_decode: illegal input: ' . print_r(debug_backtrace(), true));
return $s;
}
@@ -1690,11 +1711,11 @@ function base64url_decode($s) {
* // Uncomment if you find you need it.
*
* $l = strlen($s);
- * if(! strpos($s,'=')) {
+ * if (! strpos($s,'=')) {
* $m = $l % 4;
- * if($m == 2)
+ * if ($m == 2)
* $s .= '==';
- * if($m == 3)
+ * if ($m == 3)
* $s .= '=';
* }
*
@@ -1786,10 +1807,10 @@ function bb_translate_video($s) {
$matches = null;
$r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER);
if ($r) {
- foreach($matches as $mtch) {
- if((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be')))
+ foreach ($matches as $mtch) {
+ if ((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be')))
$s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s);
- elseif(stristr($mtch[1],'vimeo'))
+ elseif (stristr($mtch[1],'vimeo'))
$s = str_replace($mtch[0],'[vimeo]' . $mtch[1] . '[/vimeo]',$s);
}
}
@@ -1816,8 +1837,11 @@ function html2bb_video($s) {
* @return array
*/
function array_xmlify($val){
- if (is_bool($val)) return $val?"true":"false";
- if (is_array($val)) return array_map('array_xmlify', $val);
+ if (is_bool($val)) {
+ return $val?"true":"false";
+ } elseif (is_array($val)) {
+ return array_map('array_xmlify', $val);
+ }
return xmlify((string) $val);
}
@@ -1830,8 +1854,9 @@ function array_xmlify($val){
* @return string
*/
function reltoabs($text, $base) {
- if (empty($base))
- return $text;
+ if (empty($base)) {
+ return $text;
+ }
$base = rtrim($base,'/');
@@ -1867,14 +1892,16 @@ function reltoabs($text, $base) {
* @return string
*/
function item_post_type($item) {
- if(intval($item['event-id']))
+ if (intval($item['event-id'])) {
return t('event');
- if(strlen($item['resource-id']))
+ } elseif (strlen($item['resource-id'])) {
return t('photo');
- if(strlen($item['verb']) && $item['verb'] !== ACTIVITY_POST)
+ } elseif (strlen($item['verb']) && $item['verb'] !== ACTIVITY_POST) {
return t('activity');
- if($item['id'] != $item['parent'])
+ } elseif ($item['id'] != $item['parent']) {
return t('comment');
+ }
+
return t('post');
}
@@ -1888,34 +1915,34 @@ function file_tag_encode($s) {
}
function file_tag_decode($s) {
- return str_replace(array('%3c','%3e','%5b','%5d'),array('<','>','[',']'),$s);
+ return str_replace(array('%3c', '%3e', '%5b', '%5d'), array('<', '>', '[', ']'), $s);
}
function file_tag_file_query($table,$s,$type = 'file') {
- if($type == 'file')
- $str = preg_quote( '[' . str_replace('%','%%',file_tag_encode($s)) . ']' );
- else
- $str = preg_quote( '<' . str_replace('%','%%',file_tag_encode($s)) . '>' );
+ if ($type == 'file') {
+ $str = preg_quote( '[' . str_replace('%', '%%', file_tag_encode($s)) . ']' );
+ } else {
+ $str = preg_quote( '<' . str_replace('%', '%%', file_tag_encode($s)) . '>' );
+ }
return " AND " . (($table) ? dbesc($table) . '.' : '') . "file regexp '" . dbesc($str) . "' ";
}
// ex. given music,video return