<?php
use Friendica\App;
+use Friendica\Core\System;
require_once "include/template_processor.php";
require_once "include/friendica_smarty.php";
$a = get_app();
// pass $baseurl to all templates
- $r['$baseurl'] = App::get_baseurl();
+ $r['$baseurl'] = System::baseUrl();
$t = $a->template_engine();
try {
$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);
}
$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);
}
* @param string $item
*/
function sanitise_acl(&$item) {
- if (intval($item))
+ if (intval($item)) {
$item = '<' . intval(notags(trim($item))) . '>';
- else
+ } else {
unset($item);
+ }
}}
*/
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;
}}
function item_new_uri($hostname, $uid, $guid = "") {
do {
- $dups = false;
-
if ($guid == "") {
$hash = get_guid(32);
} else {
$uri = "urn:X-dfrn:" . $hostname . ':' . $uid . ':' . $hash;
- $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
- dbesc($uri));
- if (dbm::is_result($r)) {
- $dups = true;
- }
+ $dups = dba::exists('item', array('uri' => $uri));
} while ($dups == true);
return $uri;
$theme = current_theme();
// Make sure $root ends with a slash /
- if ($root !== '' && $root[strlen($root) - 1] !== '/') {
+ if ($root !== '' && substr($root, -1, 1) !== '/') {
$root = $root . '/';
}
if (file_exists("{$root}view/theme/$theme/$filename")) {
$template_file = "{$root}view/theme/$theme/$filename";
- } elseif (x($a->theme_info, "extends") && file_exists("{$root}view/theme/{$a->theme_info[\"extends\"]}/$filename")) {
- $template_file = "{$root}view/theme/{$a->theme_info[\"extends\"]}/$filename";
+ } elseif (x($a->theme_info, "extends") && file_exists(sprintf('%sview/theme/%s}/%s', $root, $a->theme_info["extends"], $filename))) {
+ $template_file = sprintf('%sview/theme/%s}/%s', $root, $a->theme_info["extends"], $filename);
} elseif (file_exists("{$root}/$filename")) {
$template_file = "{$root}/$filename";
} else {
}}
-
-
-
-
-
if (! function_exists('attribute_contains')) {
/**
* for html,xml parsing - let's say you've got
* @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);
}}
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.
$item["rendered-hash"] = hash("md5", $item["body"]);
$item["body"] = $body;
- if ($update AND ($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"]));
+ if ($update && ($item["id"] > 0)) {
+ dba::update('item', array('rendered-html' => $item["rendered-html"], 'rendered-hash' => $item["rendered-hash"]),
+ array('id' => $item["id"]), false);
}
}
}
* @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 = System::baseUrl() . "/search?tag=";
- $tags=array();
+ $tags = array();
$hashtags = array();
$mentions = array();
if (!get_config('system','suppress_tags')) {
- $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`",
+ $taglist = dba::p("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = ? AND `oid` = ? AND `type` IN (?, ?) ORDER BY `tid`",
intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
- foreach ($taglist as $tag) {
-
+ while ($tag = dba::fetch($taglist)) {
if ($tag["url"] == "") {
$tag["url"] = $searchpath.strtolower($tag["term"]);
}
+ $orig_tag = $tag["url"];
+
+ $tag["url"] = best_link_url($item, $sp, $tag["url"]);
+
+ if ($orig_tag != $tag["url"]) {
+ $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']);
+ }
+
if ($tag["type"] == TERM_HASHTAG) {
$hashtags[] = "#<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
$prefix = "#";
}
$tags[] = $prefix."<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
}
+ dba::close($taglist);
}
$item['tags'] = $tags;
$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"];
$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) {
$matches = false;
$icon = '';
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) {
$vhead = true;
$a->page['htmlhead'] .= replace_macros(get_markup_template('videos_head.tpl'), array(
- '$baseurl' => z_root(),
+ '$baseurl' => System::baseUrl(),
));
$a->page['end'] .= replace_macros(get_markup_template('videos_end.tpl'), array(
- '$baseurl' => z_root(),
+ '$baseurl' => System::baseUrl(),
));
}
$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,'/') ));
+ $filetype = strtolower(substr($mime, 0, strpos($mime,'/')));
if ($filetype) {
- $filesubtype = strtolower(substr( $mime, strpos($mime,'/') + 1 ));
+ $filesubtype = strtolower(substr($mime, strpos($mime,'/') + 1));
$filesubtype = str_replace('.', '-', $filesubtype);
- }
- else {
+ } else {
$filetype = 'unkn';
$filesubtype = 'unkn';
}
- $icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
- /*$icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/')));
- switch($icontype) {
- case 'video':
- case 'audio':
- case 'image':
- case 'text':
- $icon = '<div class="attachtype icon s22 type-' . $icontype . '"></div>';
- break;
- default:
- $icon = '<div class="attachtype icon s22 type-unkn"></div>';
- break;
- }*/
-
$title = ((strlen(trim($mtch[4]))) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1]));
$title .= ' ' . $mtch[2] . ' ' . t('bytes');
- $as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" >' . $icon . '</a>';
+ if (($filetype == 'image') AND ($item['network'] == NETWORK_OSTATUS)) {
+ $icon = '<img class="attached" src="'.$the_url.'" alt="" title="'.$title.'">';
+ $s .= '<br><a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attached" target="_blank" >' . $icon . '</a>';
+ } else {
+ $icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
+ $as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" >' . $icon . '</a>';
+ }
+
}
}
}
- $as .= '<div class="clear"></div></div>';
}
- $s = $s . $as;
+ if ($as != '') {
+ $s .= '<div class="body-attach">'.$as.'<div class="clear"></div></div>';
+ }
// 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);
$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(
}
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(
$ret = array();
}
- //if (x($item,'plink') && ($item['private'] != 1))
-
- return($ret);
+ return $ret;
}}
if (! function_exists('unamp')) {
if (! dbm::is_result($x)) {
$found = false;
}
- } while ($found == true );
+ } while ($found == true);
return $guid;
}
}
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) . "' ";
}
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;
}
}
$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]);
}
}
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
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]);
}
}
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))
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))
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);
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]);
}
*/
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;
}