<?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);
}
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;
$callers = debug_backtrace();
$logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n",
- datetime_convert(),
+ datetime_convert('UTC', 'UTC', 'now', 'Y-m-d\TH:i:s\Z'),
$process_id,
$LOGGER_LEVELS[$level],
basename($callers[0]['file']),
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);
}
}
}
$a = get_app();
call_hooks('prepare_body_init', $item);
- $searchpath = z_root() . "/search?tag=";
+ $searchpath = System::baseUrl() . "/search?tag=";
$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 ($tag["type"] == TERM_HASHTAG) {
+ if ($orig_tag != $tag["url"]) {
+ $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']);
+ }
$hashtags[] = "#<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
$prefix = "#";
} elseif ($tag["type"] == TERM_MENTION) {
}
$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 {
$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');
+ $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);
if (! dbm::is_result($x)) {
$found = false;
}
- } while ($found == true );
+ } while ($found == true);
return $guid;
}
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;
}
}
}
if ($cnt) {
foreach ($matches as $mtch) {
- if (strlen($list))
+ if (strlen($list)) {
$list .= ',';
+ }
$list .= file_tag_decode($mtch[1]);
}
}