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
$stamp1 = microtime(true);
$a = get_app();
+
+ // pass $baseurl to all templates
+ $r['$baseurl'] = $a->get_baseurl();
+
$t = $a->template_engine();
try {
$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);
* @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;
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($class)
$class = ' ' . $class;
+ if ($contact["addr"] == "")
+ $contact["addr"] = $contact["url"];
+
$url = $contact['url'];
$sparkle = '';
$redir = false;
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
- . '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name']
+ . '" title="' . $contact['name'] . ' [' . $contact['addr'] . ']" alt="' . $contact['name']
. '" >'. $contact['name'] . '</a></div>' . "\r\n";
}
else {
. (($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['addr'] . ']" 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')) {
*/
function valid_email($x){
- if(get_config('system','disable_email_validation'))
- return true;
+ // Removed because Fabio told me so.
+ //if(get_config('system','disable_email_validation'))
+ // return true;
if(preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x))
return true;
);
$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;
}
put_item_in_cache($item, true);
$s = $item["rendered-html"];
- require_once("mod/proxy.php");
- $s = proxy_parse_html($s);
-
$prep_arr = array('item' => $item, 'html' => $s, 'preview' => $preview);
call_hooks('prepare_body', $prep_arr);
$s = $prep_arr['html'];
}
$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(
}}
-
-
-if(! function_exists('lang_selector')) {
-/**
- * get html for language selector
- * @global string $lang
- * @return string
- * @template lang_selector.tpl
- */
-function lang_selector() {
- global $lang;
-
- $langs = glob('view/*/strings.php');
-
- $lang_options = array();
- $selected = "";
-
- if(is_array($langs) && count($langs)) {
- $langs[] = '';
- if(! in_array('view/en/strings.php',$langs))
- $langs[] = 'view/en/';
- asort($langs);
- foreach($langs as $l) {
- if($l == '') {
- $lang_options[""] = t('default');
- continue;
- }
- $ll = substr($l,5);
- $ll = substr($ll,0,strrpos($ll,'/'));
- $selected = (($ll === $lang && (x($_SESSION, 'language'))) ? $ll : $selected);
- $lang_options[$ll]=$ll;
- }
- }
-
- $tpl = get_markup_template("lang_selector.tpl");
- $o = replace_macros($tpl, array(
- '$title' => t('Select an alternate language'),
- '$langs' => array($lang_options, $selected),
-
- ));
- return $o;
-}}
-
-
if(! function_exists('return_bytes')) {
/**
* return number of bytes in size (K, M, G)
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];
+}