require_once("include/template_processor.php");
require_once("include/friendica_smarty.php");
+require_once("include/map.php");
require_once("mod/proxy.php");
+
if(! function_exists('replace_macros')) {
/**
* This is our template processor
$buffer = mb_ereg_replace("<", "<", $buffer);
$buffer = mb_ereg_replace(">", ">", $buffer);
*/
- $buffer = htmlspecialchars($str, ENT_QUOTES);
+ $buffer = htmlspecialchars($str, ENT_QUOTES, "UTF-8");
$buffer = trim($buffer);
return($buffer);
* @return Array data for pagination template
*/
function paginate_data(&$a, $count=null) {
- $stripped = preg_replace('/(&page=[0-9]*)/','',$a->query_string);
+ $stripped = preg_replace('/([&?]page=[0-9]*)/','',$a->query_string);
$stripped = str_replace('q=','',$stripped);
$stripped = trim($stripped,'/');
* @param int $uid
* @return string
*/
-function item_new_uri($hostname,$uid) {
+function item_new_uri($hostname,$uid, $guid = "") {
do {
$dups = false;
- $hash = random_string();
+
+ if ($guid == "")
+ $hash = get_guid(32);
+ else {
+ $hash = $guid;
+ $guid = "";
+ }
$uri = "urn:X-dfrn:" . $hostname . ':' . $uid . ':' . $hash;
function get_tags($s) {
$ret = array();
+ // Convert hashtag links to hashtags
+ $s = preg_replace("/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism", "#$2", $s);
+
// ignore anything in a code block
$s = preg_replace('/\[code\](.*?)\[\/code\]/sm','',$s);
foreach($arr as $x) {
$matches = null;
if(preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) {
- $o .= "\t\t" . '<link rel="mentioned" href="' . $matches[1] . '" />' . "\r\n";
$o .= "\t\t" . '<link rel="ostatus:attention" href="' . $matches[1] . '" />' . "\r\n";
+ $o .= "\t\t" . '<link rel="mentioned" href="' . $matches[1] . '" />' . "\r\n";
}
}
+
+ if (!$item['private']) {
+ $o .= "\t\t".'<link rel="ostatus:attention" href="http://activityschema.org/collection/public"/>'."\r\n";
+ $o .= "\t\t".'<link rel="mentioned" href="http://activityschema.org/collection/public"/>'."\r\n";
+ }
+
return $o;
}}
if((! is_array($a->profile)) || ($a->profile['hide-friends']))
return $o;
- $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 AND `archive` = 0",
- intval($a->profile['uid'])
+ $r = q("SELECT COUNT(*) AS `total` FROM `contact`
+ WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0
+ AND `hidden` = 0 AND `archive` = 0
+ AND `network` IN ('%s', '%s', '%s')",
+ intval($a->profile['uid']),
+ dbesc(NETWORK_DFRN),
+ dbesc(NETWORK_OSTATUS),
+ dbesc(NETWORK_DIASPORA)
);
if(count($r)) {
$total = intval($r[0]['total']);
$micropro = Null;
} else {
- $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 AND `archive` = 0 ORDER BY RAND() LIMIT %d",
+ $r = q("SELECT * FROM `contact`
+ WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0
+ AND `hidden` = 0 AND `archive` = 0
+ AND `network` IN ('%s', '%s', '%s') ORDER BY RAND() LIMIT %d",
intval($a->profile['uid']),
+ dbesc(NETWORK_DFRN),
+ dbesc(NETWORK_OSTATUS),
+ dbesc(NETWORK_DIASPORA),
intval($shown)
);
if(count($r)) {
if($redirect) {
$a = get_app();
$redirect_url = $a->get_baseurl() . '/redir/' . $contact['id'];
- if(local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === 'dfrn')) {
+ if(local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === NETWORK_DFRN)) {
$redir = true;
$url = $redirect_url;
$sparkle = ' sparkle';
. (($click) ? ' fakelink' : '') . '" '
. (($redir) ? ' target="redir" ' : '')
. (($url) ? ' href="' . $url . '"' : '') . $click . ' ><img class="contact-block-img' . $class . $sparkle . '" src="'
- . proxy_url($contact['micro']) . '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name']
+ . proxy_url($contact['micro'], false, PROXY_SIZE_THUMB) . '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name']
. '" /></a></div>' . "\r\n";
}
}}
* @param string $s search query
* @param string $id html id
* @param string $url search url
- * @param boolean $save show save search button
- * @return string html for search box #FIXME: remove html
+ * @param boolean $savedsearch show save search button
*/
-function search($s,$id='search-box',$url='/search',$save = false) {
+function search($s,$id='search-box',$url='/search',$save = false, $aside = true) {
$a = get_app();
- $o = '<div id="' . $id . '">';
- $o .= '<form action="' . $a->get_baseurl((stristr($url,'network')) ? true : false) . $url . '" method="get" >';
- $o .= '<input type="text" name="search" id="search-text" placeholder="' . t('Search') . '" value="' . $s .'" />';
- $o .= '<input type="submit" name="submit" id="search-submit" value="' . t('Search') . '" />';
- if($save)
- $o .= '<input type="submit" name="save" id="search-save" value="' . t('Save') . '" />';
- $o .= '</form></div>';
- return $o;
+
+ $values = array(
+ '$s' => $s,
+ '$id' => $id,
+ '$action_url' => $a->get_baseurl((stristr($url,'network')) ? true : false) . $url,
+ '$search_label' => t('Search'),
+ '$save_label' => t('Save'),
+ '$savedsearch' => feature_enabled(local_user(),'savedsearch'),
+ );
+
+ if (!$aside) {
+ $values['$searchoption'] = array(
+ t("Full Text"),
+ t("Tags"),
+ t("Contacts"));
+
+ if (get_config('system','poco_local_search'))
+ $values['$searchoption'][] = t("Forums");
+ }
+
+ return replace_macros(get_markup_template('searchbox.tpl'), $values);
}}
if(! function_exists('valid_email')) {
);
$icons = array(
- '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
- '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
- '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="<\\3" />',
+ '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
+ '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
+ '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="<\\3" />',
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":-)" />',
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-wink.gif" alt=";-)" />',
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":-(" />',
return $x[0];
$t = '';
for($cnt = 0; $cnt < strlen($x[1]); $cnt ++)
- $t .= '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />';
+ $t .= '<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />';
$r = str_replace($x[0],$t,$x[0]);
return $r;
}
}}
-function put_item_in_cache($item) {
- $cachefile = get_cachefile(urlencode($item["guid"])."-".hash("md5", $item['body']));
+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")) {
+
+ // The function "redir_private_images" changes the body.
+ // I'm not sure if we should store it permanently, so we save the old value.
+ $body = $item["body"];
- if (($cachefile != '') AND !file_exists($cachefile)) {
- $s = prepare_text($item['body']);
$a = get_app();
- $stamp1 = microtime(true);
- file_put_contents($cachefile, $s);
- $a->save_timestamp($stamp1, "file");
- logger('put item '.$item["guid"].' into cachefile '.$cachefile);
+ redir_private_images($a, $item);
+
+ $item["rendered-html"] = prepare_text($item["body"]);
+ $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"]));
+ }
}
}
$item['hashtags'] = $hashtags;
$item['mentions'] = $mentions;
-
- $cachefile = get_cachefile(urlencode($item["guid"])."-".hash("md5", $item['body']));
-
- if (($cachefile != '')) {
- if (file_exists($cachefile)) {
- $stamp1 = microtime(true);
- $s = file_get_contents($cachefile);
- $a->save_timestamp($stamp1, "file");
- } else {
- redir_private_images($a, $item);
- $s = prepare_text($item['body']);
-
- $stamp1 = microtime(true);
- file_put_contents($cachefile, $s);
- $a->save_timestamp($stamp1, "file");
-
- logger('prepare_body: put item '.$item["id"].' into cachefile '.$cachefile);
- }
- } else {
- redir_private_images($a, $item);
- $s = prepare_text($item['body']);
- }
-
- require_once("mod/proxy.php");
- $s = proxy_parse_html($s);
+ put_item_in_cache($item, true);
+ $s = $item["rendered-html"];
$prep_arr = array('item' => $item, 'html' => $s, 'preview' => $preview);
call_hooks('prepare_body', $prep_arr);
}
$s = $s . $as;
+ // map
+ if(strpos($s,'<div class="map">') !== false && $item['coord']) {
+ $x = generate_map(trim($item['coord']));
+ if($x) {
+ $s = preg_replace('/\<div class\=\"map\"\>/','$0' . $x,$s);
+ }
+ }
+
// Look for spoiler
$spoilersearch = '<blockquote class="spoiler">';
//'href' => $a->get_baseurl()."/display/".$a->user['nickname']."/".$item['id'],
'href' => $a->get_baseurl()."/display/".$item['guid'],
'orig' => $a->get_baseurl()."/display/".$item['guid'],
- 'title' => t('link to source'),
+ 'title' => t('View on separate page'),
+ 'orig_title' => t('view on separate page'),
);
- if (x($item,'plink'))
+ if (x($item,'plink')) {
$ret["href"] = $item['plink'];
+ $ret["title"] = t('link to source');
+ }
} elseif (x($item,'plink') && ($item['private'] != 1))
$ret = array(
function generate_user_guid() {
$found = true;
do {
- $guid = random_string(16);
+ $guid = get_guid(32);
$x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
dbesc($guid)
);
return implode("\n", $lines);
}
+
+function formatBytes($bytes, $precision = 2) {
+ $units = array('B', 'KB', 'MB', 'GB', 'TB');
+
+ $bytes = max($bytes, 0);
+ $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
+ $pow = min($pow, count($units) - 1);
+
+ $bytes /= pow(1024, $pow);
+
+ return round($bytes, $precision) . ' ' . $units[$pow];
+}