]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Degrade priority step by step
[friendica.git] / include / text.php
index e8384123c4a64cb2547ab13ca84adf031a493a19..ea5deb4c1442a7c43ebb8929dbac66f64209290a 100644 (file)
@@ -293,7 +293,7 @@ function paginate_data(App $a, $count = null) {
        $stripped = trim($stripped, '/');
        $pagenum = $a->pager['page'];
 
-       if (($a->page_offset != '') AND !preg_match('/[?&].offset=/', $stripped)) {
+       if (($a->page_offset != '') && !preg_match('/[?&].offset=/', $stripped)) {
                $stripped .= '&offset=' . urlencode($a->page_offset);
        }
 
@@ -425,9 +425,9 @@ function expand_acl($s) {
        $ret = array();
 
        if (strlen($s)) {
-               $t = str_replace('<','',$s);
-               $a = explode('>',$t);
-               foreach($a as $aa) {
+               $t = str_replace('<', '', $s);
+               $a = explode('>', $t);
+               foreach ($a as $aa) {
                        if (intval($aa)) {
                                $ret[] = intval($aa);
                        }
@@ -442,10 +442,11 @@ if (! function_exists('sanitise_acl')) {
  * @param string $item
  */
 function sanitise_acl(&$item) {
-       if (intval($item))
+       if (intval($item)) {
                $item = '<' . intval(notags(trim($item))) . '>';
-       else
+       } else {
                unset($item);
+       }
 }}
 
 
@@ -461,14 +462,15 @@ if (! function_exists('perms2str')) {
  */
 function perms2str($p) {
        $ret = '';
-       if (is_array($p))
+       if (is_array($p)) {
                $tmp = $p;
-       else
+       } else {
                $tmp = explode(',',$p);
+       }
 
        if (is_array($tmp)) {
-               array_walk($tmp,'sanitise_acl');
-               $ret = implode('',$tmp);
+               array_walk($tmp, 'sanitise_acl');
+               $ret = implode('', $tmp);
        }
        return $ret;
 }}
@@ -670,11 +672,6 @@ function get_template_file($a, $filename, $root = '') {
 }}
 
 
-
-
-
-
-
 if (! function_exists('attribute_contains')) {
 /**
  *  for html,xml parsing - let's say you've got
@@ -1249,7 +1246,7 @@ if (! function_exists('link_compare')) {
  * @return boolean True if the URLs match, otherwise False
  *
  */
-function link_compare($a,$b) {
+function link_compare($a, $b) {
        return (strcasecmp(normalise_link($a), normalise_link($b)) === 0);
 }}
 
@@ -1279,8 +1276,8 @@ function redir_private_images($a, &$item)
 
 function put_item_in_cache(&$item, $update = false) {
 
-       if (($item["rendered-hash"] != hash("md5", $item["body"])) OR ($item["rendered-hash"] == "") OR
-               ($item["rendered-html"] == "") OR get_config("system", "ignore_cache")) {
+       if (($item["rendered-hash"] != hash("md5", $item["body"])) || ($item["rendered-hash"] == "") ||
+               ($item["rendered-html"] == "") || get_config("system", "ignore_cache")) {
 
                // The function "redir_private_images" changes the body.
                // I'm not sure if we should store it permanently, so we save the old value.
@@ -1293,7 +1290,7 @@ function put_item_in_cache(&$item, $update = false) {
                $item["rendered-hash"] = hash("md5", $item["body"]);
                $item["body"] = $body;
 
-               if ($update AND ($item["id"] != 0)) {
+               if ($update && ($item["id"] != 0)) {
                        q("UPDATE `item` SET `rendered-html` = '%s', `rendered-hash` = '%s' WHERE `id` = %d",
                                dbesc($item["rendered-html"]), dbesc($item["rendered-hash"]), intval($item["id"]));
                }
@@ -1315,14 +1312,14 @@ if (! function_exists('prepare_body')) {
  * @hook prepare_body ('item'=>item array, 'html'=>body string) after first bbcode to html
  * @hook prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author)
  */
-function prepare_body(&$item,$attach = false, $preview = false) {
+function prepare_body(&$item, $attach = false, $preview = false) {
 
        $a = get_app();
        call_hooks('prepare_body_init', $item);
 
-       $searchpath = z_root()."/search?tag=";
+       $searchpath = z_root() . "/search?tag=";
 
-       $tags=array();
+       $tags = array();
        $hashtags = array();
        $mentions = array();
 
@@ -1355,8 +1352,9 @@ function prepare_body(&$item,$attach = false, $preview = false) {
        $update = (!local_user() and !remote_user() and ($item["uid"] == 0));
 
        // Or update it if the current viewer is the intented viewer
-       if (($item["uid"] == local_user()) AND ($item["uid"] != 0))
+       if (($item["uid"] == local_user()) && ($item["uid"] != 0)) {
                $update = true;
+       }
 
        put_item_in_cache($item, $update);
        $s = $item["rendered-html"];
@@ -1374,7 +1372,7 @@ function prepare_body(&$item,$attach = false, $preview = false) {
 
        $as = '';
        $vhead = false;
-       $arr = explode('[/attach],',$item['attach']);
+       $arr = explode('[/attach],', $item['attach']);
        if (count($arr)) {
                $as .= '<div class="body-attach">';
                foreach ($arr as $r) {
@@ -1385,10 +1383,11 @@ function prepare_body(&$item,$attach = false, $preview = false) {
                                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) {
@@ -1403,11 +1402,11 @@ 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,
                                                        ),
                                                ));
                                        }
@@ -1416,8 +1415,7 @@ function prepare_body(&$item,$attach = false, $preview = false) {
                                        if ($filetype) {
                                                $filesubtype = strtolower(substr( $mime, strpos($mime,'/') + 1 ));
                                                $filesubtype = str_replace('.', '-', $filesubtype);
-                                       }
-                                       else {
+                                       } else {
                                                $filetype = 'unkn';
                                                $filesubtype = 'unkn';
                                        }
@@ -1448,7 +1446,7 @@ function prepare_body(&$item,$attach = false, $preview = false) {
        $s = $s . $as;
 
        // map
-       if (strpos($s, '<div class="map">') !== false && $item['coord']) {
+       if (strpos($s, '<div class="map">') !== false && x($item, 'coord')) {
                $x = generate_map(trim($item['coord']));
                if ($x) {
                        $s = preg_replace('/\<div class\=\"map\"\>/','$0' . $x,$s);
@@ -1554,8 +1552,9 @@ function get_cats_and_terms($item) {
        $categories = array();
        $folders = array();
 
-       $matches = false; $first = true;
-       $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER);
+       $matches = false;
+       $first = true;
+       $cnt = preg_match_all('/<(.*?)>/', $item['file'], $matches, PREG_SET_ORDER);
        if ($cnt) {
                foreach ($matches as $mtch) {
                        $categories[] = array(
@@ -1574,8 +1573,9 @@ function get_cats_and_terms($item) {
        }
 
        if (local_user() == $item['uid']) {
-               $matches = false; $first = true;
-               $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER);
+               $matches = false;
+               $first = true;
+               $cnt = preg_match_all('/\[(.*?)\]/', $item['file'], $matches, PREG_SET_ORDER);
                if ($cnt) {
                        foreach ($matches as $mtch) {
                                $folders[] = array(
@@ -1630,9 +1630,7 @@ function get_plink($item) {
                $ret = array();
        }
 
-       //if (x($item,'plink') && ($item['private'] != 1))
-
-       return($ret);
+       return $ret;
 }}
 
 if (! function_exists('unamp')) {
@@ -1917,15 +1915,16 @@ 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) . "' ";
 }
 
@@ -1937,14 +1936,13 @@ function file_tag_list_to_file($list,$type = 'file') {
                if ($type == 'file') {
                        $lbracket = '[';
                        $rbracket = ']';
-               }
-               else {
+               } else {
                        $lbracket = '<';
                        $rbracket = '>';
                }
 
                foreach ($list_array as $item) {
-                 if (strlen($item)) {
+                       if (strlen($item)) {
                                $tag_list .= $lbracket . file_tag_encode(trim($item))  . $rbracket;
                        }
                }
@@ -1957,15 +1955,15 @@ function file_tag_file_to_list($file,$type = 'file') {
        $matches = false;
        $list = '';
        if ($type == 'file') {
-               $cnt = preg_match_all('/\[(.*?)\]/',$file,$matches,PREG_SET_ORDER);
-       }
-       else {
-               $cnt = preg_match_all('/<(.*?)>/',$file,$matches,PREG_SET_ORDER);
+               $cnt = preg_match_all('/\[(.*?)\]/', $file, $matches, PREG_SET_ORDER);
+       } else {
+               $cnt = preg_match_all('/<(.*?)>/', $file, $matches, PREG_SET_ORDER);
        }
        if ($cnt) {
                foreach ($matches as $mtch) {
-                       if (strlen($list))
+                       if (strlen($list)) {
                                $list .= ',';
+                       }
                        $list .= file_tag_decode($mtch[1]);
                }
        }
@@ -1973,7 +1971,7 @@ function file_tag_file_to_list($file,$type = 'file') {
        return $list;
 }
 
-function file_tag_update_pconfig($uid,$file_old,$file_new,$type = 'file') {
+function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
        // $file_old - categories previously associated with an item
        // $file_new - new list of categories for an item
 
@@ -2025,10 +2023,6 @@ function file_tag_update_pconfig($uid,$file_old,$file_new,$type = 'file') {
                                intval($termtype),
                                intval($uid));
 
-                       //$r = q("select file from item where uid = %d " . file_tag_file_query('item',$tag,$type),
-                       //      intval($uid)
-                       //);
-
                        if (dbm::is_result($r)) {
                                unset($deleted_tags[$key]);
                        }
@@ -2038,19 +2032,19 @@ function file_tag_update_pconfig($uid,$file_old,$file_new,$type = 'file') {
                }
 
                if ($saved != $filetags_updated) {
-                       set_pconfig($uid,'system','filetags', $filetags_updated);
+                       set_pconfig($uid, 'system', 'filetags', $filetags_updated);
                }
                return true;
        }
        else
                if (strlen($file_new)) {
-                       set_pconfig($uid,'system','filetags', $file_new);
+                       set_pconfig($uid, 'system', 'filetags', $file_new);
                }
                return true;
 }
 
-function file_tag_save_file($uid,$item,$file) {
-       require_once("include/files.php");
+function file_tag_save_file($uid, $item, $file) {
+       require_once "include/files.php";
 
        $result = false;
        if (! intval($uid))
@@ -2060,25 +2054,27 @@ function file_tag_save_file($uid,$item,$file) {
                intval($uid)
        );
        if (dbm::is_result($r)) {
-               if (! stristr($r[0]['file'],'[' . file_tag_encode($file) . ']'))
+               if (! stristr($r[0]['file'],'[' . file_tag_encode($file) . ']')) {
                        q("UPDATE `item` SET `file` = '%s' WHERE `id` = %d AND `uid` = %d",
                                dbesc($r[0]['file'] . '[' . file_tag_encode($file) . ']'),
                                intval($item),
                                intval($uid)
                        );
+               }
 
                create_files_from_item($item);
 
                $saved = get_pconfig($uid,'system','filetags');
-               if ((! strlen($saved)) || (! stristr($saved,'[' . file_tag_encode($file) . ']')))
-                       set_pconfig($uid,'system','filetags',$saved . '[' . file_tag_encode($file) . ']');
+               if ((! strlen($saved)) || (! stristr($saved, '[' . file_tag_encode($file) . ']'))) {
+                       set_pconfig($uid, 'system', 'filetags', $saved . '[' . file_tag_encode($file) . ']');
+               }
                info( t('Item filed') );
        }
        return true;
 }
 
-function file_tag_unsave_file($uid,$item,$file,$cat = false) {
-       require_once("include/files.php");
+function file_tag_unsave_file($uid, $item, $file, $cat = false) {
+       require_once "include/files.php";
 
        $result = false;
        if (! intval($uid))
@@ -2115,25 +2111,22 @@ function file_tag_unsave_file($uid,$item,$file,$cat = false) {
                intval($termtype),
                intval($uid));
 
-       //$r = q("select file from item where uid = %d and deleted = 0 " . file_tag_file_query('item',$file,(($cat) ? 'category' : 'file')),
-       //);
-
        if (! dbm::is_result($r)) {
                $saved = get_pconfig($uid,'system','filetags');
-               set_pconfig($uid,'system','filetags',str_replace($pattern,'',$saved));
+               set_pconfig($uid, 'system', 'filetags', str_replace($pattern, '', $saved));
        }
 
        return true;
 }
 
 function normalise_openid($s) {
-       return trim(str_replace(array('http://','https://'),array('',''),$s),'/');
+       return trim(str_replace(array('http://', 'https://'), array('', ''), $s), '/');
 }
 
 
 function undo_post_tagging($s) {
        $matches = null;
-       $cnt = preg_match_all('/([!#@])\[url=(.*?)\](.*?)\[\/url\]/ism',$s,$matches,PREG_SET_ORDER);
+       $cnt = preg_match_all('/([!#@])\[url=(.*?)\](.*?)\[\/url\]/ism', $s, $matches, PREG_SET_ORDER);
        if ($cnt) {
                foreach ($matches as $mtch) {
                        $s = str_replace($mtch[0], $mtch[1] . $mtch[3],$s);
@@ -2174,7 +2167,7 @@ function deindent($text, $chr = "[\t ]", $count = NULL) {
                preg_match("|^" . $chr . "*|", $lines[$k], $m);
                $count = strlen($m[0]);
        }
-       for ($k=0; $k < count($lines); $k++) {
+       for ($k = 0; $k < count($lines); $k++) {
                $lines[$k] = preg_replace("|^" . $chr . "{" . $count . "}|", "", $lines[$k]);
        }
 
@@ -2204,11 +2197,12 @@ function formatBytes($bytes, $precision = 2) {
  */
 function format_network_name($network, $url = 0) {
        if ($network != "") {
-               require_once('include/contact_selectors.php');
-               if ($url != "")
+               require_once 'include/contact_selectors.php';
+               if ($url != "") {
                        $network_name = '<a href="'.$url.'">'.network_to_name($network, $url)."</a>";
-               else
+               } else {
                        $network_name = network_to_name($network);
+               }
 
                return $network_name;
        }