diff --git a/boot.php b/boot.php
index be97cab75..379d1bf3d 100644
--- a/boot.php
+++ b/boot.php
@@ -573,6 +573,51 @@ function x($s, $k = null)
}
}
+/**
+ * Return the provided variable value if it exists and is truthy or the provided
+ * default value instead.
+ *
+ * Works with initialized variables and potentially uninitialized array keys
+ *
+ * Usages:
+ * - defaults($var, $default)
+ * - defaults($array, 'key', $default)
+ *
+ * @brief Returns a defaut value if the provided variable or array key is falsy
+ * @see x()
+ * @return mixed
+ */
+function defaults() {
+ $args = func_get_args();
+
+ if (count($args) < 2) {
+ throw new BadFunctionCallException('defaults() requires at least 2 parameters');
+ }
+ if (count($args) > 3) {
+ throw new BadFunctionCallException('defaults() cannot use more than 3 parameters');
+ }
+ if (count($args) === 3 && !is_array($args[0])) {
+ throw new BadFunctionCallException('defaults($arr, $key, $def) requires an array as first parameter');
+ }
+ if (count($args) === 3 && is_null($args[1])) {
+ throw new BadFunctionCallException('defaults($arr, $key, $def) $key is null');
+ }
+
+ $default = array_pop($args);
+
+ if (call_user_func_array('x', $args)) {
+ if (count($args) === 1) {
+ $return = $args[0];
+ } else {
+ $return = $args[0][$args[1]];
+ }
+ } else {
+ $return = $default;
+ }
+
+ return $return;
+}
+
/**
* @brief Returns the baseurl.
*
@@ -1516,14 +1561,11 @@ function argv($x)
function infinite_scroll_data($module)
{
if (PConfig::get(local_user(), 'system', 'infinite_scroll')
- && ($module == "network") && ($_GET["mode"] != "minimal")
+ && $module == 'network'
+ && defaults($_GET, 'mode', '') != 'minimal'
) {
// get the page number
- if (is_string($_GET["page"])) {
- $pageno = $_GET["page"];
- } else {
- $pageno = 1;
- }
+ $pageno = defaults($_GET, 'page', 1);
$reload_uri = "";
@@ -1534,7 +1576,8 @@ function infinite_scroll_data($module)
}
}
- if (($a->page_offset != "") && ! strstr($reload_uri, "&offset=")) {
+ $a = get_app();
+ if ($a->page_offset != "" && !strstr($reload_uri, "&offset=")) {
$reload_uri .= "&offset=" . urlencode($a->page_offset);
}
diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php
index e1a67d432..714d78004 100644
--- a/include/bb2diaspora.php
+++ b/include/bb2diaspora.php
@@ -7,7 +7,6 @@ use Friendica\Network\Probe;
use League\HTMLToMarkdown\HtmlConverter;
-require_once 'include/oembed.php';
require_once 'include/event.php';
require_once 'library/markdown.php';
require_once 'include/html2bbcode.php';
diff --git a/include/bbcode.php b/include/bbcode.php
index be59c1807..261bdfcf6 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -2,13 +2,13 @@
use Friendica\App;
use Friendica\Content\Smilies;
+use Friendica\Content\OEmbed;
use Friendica\Core\Cache;
use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Model\Contact;
use Friendica\Util\Map;
-require_once 'include/oembed.php';
require_once 'include/event.php';
require_once 'mod/proxy.php';
require_once 'include/plaintext.php';
@@ -232,7 +232,7 @@ function tryoembed($match) {
$url = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"),
array("https://www.youtube.com/", "https://player.vimeo.com/"), $url);
- $o = oembed_fetch_url($url);
+ $o = OEmbed::fetchURL($url);
if (!is_object($o)) {
return $match[0];
@@ -246,7 +246,7 @@ function tryoembed($match) {
return $match[0];
}
- $html = oembed_format_object($o);
+ $html = OEmbed::formatObject($o);
return $html;
}
@@ -435,60 +435,65 @@ function bb_replace_images($body, $images) {
return $newbody;
}
-function bb_ShareAttributes($share, $simplehtml) {
+function bb_ShareAttributes($share, $simplehtml)
+{
$attributes = $share[2];
$author = "";
preg_match("/author='(.*?)'/ism", $attributes, $matches);
- if ($matches[1] != "")
- $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
+ if (x($matches, 1)) {
+ $author = html_entity_decode($matches[1], ENT_QUOTES, 'UTF-8');
+ }
preg_match('/author="(.*?)"/ism', $attributes, $matches);
- if ($matches[1] != "")
+ if (x($matches, 1)) {
$author = $matches[1];
+ }
$profile = "";
preg_match("/profile='(.*?)'/ism", $attributes, $matches);
- if ($matches[1] != "")
+ if (x($matches, 1)) {
$profile = $matches[1];
+ }
preg_match('/profile="(.*?)"/ism', $attributes, $matches);
- if ($matches[1] != "")
+ if (x($matches, 1)) {
$profile = $matches[1];
+ }
$avatar = "";
preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
- if ($matches[1] != "")
+ if (x($matches, 1)) {
$avatar = $matches[1];
+ }
preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
- if ($matches[1] != "")
+ if (x($matches, 1)) {
$avatar = $matches[1];
+ }
$link = "";
preg_match("/link='(.*?)'/ism", $attributes, $matches);
- if ($matches[1] != "")
+ if (x($matches, 1)) {
$link = $matches[1];
+ }
preg_match('/link="(.*?)"/ism', $attributes, $matches);
- if ($matches[1] != "")
+ if (x($matches, 1)) {
$link = $matches[1];
+ }
$posted = "";
- $itemcache = get_itemcachepath();
-
preg_match("/posted='(.*?)'/ism", $attributes, $matches);
- if ($matches[1] != "")
+ if (x($matches, 1)) {
$posted = $matches[1];
+ }
preg_match('/posted="(.*?)"/ism', $attributes, $matches);
- if ($matches[1] != "")
+ if (x($matches, 1)) {
$posted = $matches[1];
-
- // relative dates only make sense when they aren't cached
- if ($itemcache == "")
- $reldate = (($posted) ? " " . relative_date($posted) : '');
+ }
// We only call this so that a previously unknown contact can be added.
// This is important for the function "get_contact_details_by_url".
@@ -497,99 +502,107 @@ function bb_ShareAttributes($share, $simplehtml) {
$data = Contact::getDetailsByURL($profile);
- if (isset($data["name"]) && ($data["name"] != "") && isset($data["addr"]) && ($data["addr"] != ""))
- $userid_compact = $data["name"]." (".$data["addr"].")";
- else
- $userid_compact = GetProfileUsername($profile,$author, true);
+ if (x($data, "name") && x($data, "addr")) {
+ $userid_compact = $data["name"] . " (" . $data["addr"] . ")";
+ } else {
+ $userid_compact = GetProfileUsername($profile, $author, true);
+ }
- if (isset($data["addr"]) && ($data["addr"] != ""))
+ if (x($data, "addr")) {
$userid = $data["addr"];
- else
- $userid = GetProfileUsername($profile,$author, false);
+ } else {
+ $userid = GetProfileUsername($profile, $author, false);
+ }
- if (isset($data["name"]) && ($data["name"] != ""))
+ if (x($data, "name")) {
$author = $data["name"];
+ }
- if (isset($data["micro"]) && ($data["micro"] != ""))
+ if (x($data, "micro")) {
$avatar = $data["micro"];
+ }
$preshare = trim($share[1]);
- if ($preshare != "")
+ if ($preshare != "") {
$preshare .= "
";
+ }
switch ($simplehtml) {
case 1:
- $text = $preshare.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$userid.":
»".$share[3]."«";
+ $text = $preshare . html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8') . ' ' . $userid . ":
»" . $share[3] . "«";
break;
case 2:
- $text = $preshare.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$userid_compact.":
".$share[3];
+ $text = $preshare . html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8') . ' ' . $userid_compact . ":
" . $share[3];
break;
case 3: // Diaspora
- $headline .= ''.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').$userid.':
';
+ $headline .= '' . html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8') . $userid . ':
';
$text = trim($share[1]);
- if ($text != "")
+ if ($text != "") {
$text .= "
'.trim($share[3])."
' . trim($share[3]) . "
'.trim($share[3])."
' . trim($share[3]) . "
"; var_dump($a->user); killme();
-
if (is_null($nickname)) {
- $nickname = $a->user['nickname'];
+ $nickname = $a->user['nickname'];
}
+ $tab = false;
if (x($_GET, 'tab')) {
$tab = notags(trim($_GET['tab']));
}
@@ -836,85 +824,85 @@ function profile_tabs($a, $is_owner = false, $nickname = null)
$tabs = array(
array(
- 'label'=>t('Status'),
- 'url' => $url,
- 'sel' => ((!isset($tab) && $a->argv[0]=='profile') ? 'active' : ''),
+ 'label' => t('Status'),
+ 'url' => $url,
+ 'sel' => !$tab && $a->argv[0] == 'profile' ? 'active' : '',
'title' => t('Status Messages and Posts'),
- 'id' => 'status-tab',
+ 'id' => 'status-tab',
'accesskey' => 'm',
),
array(
'label' => t('Profile'),
- 'url' => $url.'/?tab=profile',
- 'sel' => ((isset($tab) && $tab=='profile') ? 'active' : ''),
+ 'url' => $url . '/?tab=profile',
+ 'sel' => $tab == 'profile' ? 'active' : '',
'title' => t('Profile Details'),
- 'id' => 'profile-tab',
+ 'id' => 'profile-tab',
'accesskey' => 'r',
),
array(
'label' => t('Photos'),
- 'url' => System::baseUrl() . '/photos/' . $nickname,
- 'sel' => ((!isset($tab) && $a->argv[0]=='photos') ? 'active' : ''),
+ 'url' => System::baseUrl() . '/photos/' . $nickname,
+ 'sel' => !$tab && $a->argv[0] == 'photos' ? 'active' : '',
'title' => t('Photo Albums'),
- 'id' => 'photo-tab',
+ 'id' => 'photo-tab',
'accesskey' => 'h',
),
array(
'label' => t('Videos'),
- 'url' => System::baseUrl() . '/videos/' . $nickname,
- 'sel' => ((!isset($tab) && $a->argv[0]=='videos') ? 'active' : ''),
+ 'url' => System::baseUrl() . '/videos/' . $nickname,
+ 'sel' => !$tab && $a->argv[0] == 'videos' ? 'active' : '',
'title' => t('Videos'),
- 'id' => 'video-tab',
+ 'id' => 'video-tab',
'accesskey' => 'v',
),
);
// the calendar link for the full featured events calendar
if ($is_owner && $a->theme_events_in_profile) {
- $tabs[] = array(
- 'label' => t('Events'),
- 'url' => System::baseUrl() . '/events',
- 'sel' =>((!isset($tab) && $a->argv[0]=='events') ? 'active' : ''),
- 'title' => t('Events and Calendar'),
- 'id' => 'events-tab',
- 'accesskey' => 'e',
- );
+ $tabs[] = array(
+ 'label' => t('Events'),
+ 'url' => System::baseUrl() . '/events',
+ 'sel' => !$tab && $a->argv[0] == 'events' ? 'active' : '',
+ 'title' => t('Events and Calendar'),
+ 'id' => 'events-tab',
+ 'accesskey' => 'e',
+ );
// if the user is not the owner of the calendar we only show a calendar
// with the public events of the calendar owner
- } elseif (! $is_owner) {
+ } elseif (!$is_owner) {
$tabs[] = array(
- 'label' => t('Events'),
- 'url' => System::baseUrl() . '/cal/' . $nickname,
- 'sel' =>((!isset($tab) && $a->argv[0]=='cal') ? 'active' : ''),
- 'title' => t('Events and Calendar'),
- 'id' => 'events-tab',
- 'accesskey' => 'e',
- );
+ 'label' => t('Events'),
+ 'url' => System::baseUrl() . '/cal/' . $nickname,
+ 'sel' => !$tab && $a->argv[0] == 'cal' ? 'active' : '',
+ 'title' => t('Events and Calendar'),
+ 'id' => 'events-tab',
+ 'accesskey' => 'e',
+ );
}
if ($is_owner) {
$tabs[] = array(
'label' => t('Personal Notes'),
- 'url' => System::baseUrl() . '/notes',
- 'sel' =>((!isset($tab) && $a->argv[0]=='notes') ? 'active' : ''),
+ 'url' => System::baseUrl() . '/notes',
+ 'sel' => !$tab && $a->argv[0] == 'notes' ? 'active' : '',
'title' => t('Only You Can See This'),
- 'id' => 'notes-tab',
+ 'id' => 'notes-tab',
'accesskey' => 't',
);
}
- if ((! $is_owner) && ((count($a->profile)) || (! $a->profile['hide-friends']))) {
+ if ((!$is_owner) && ((count($a->profile)) || (!$a->profile['hide-friends']))) {
$tabs[] = array(
'label' => t('Contacts'),
- 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
- 'sel' => ((!isset($tab) && $a->argv[0]=='viewcontacts') ? 'active' : ''),
+ 'url' => System::baseUrl() . '/viewcontacts/' . $nickname,
+ 'sel' => !$tab && $a->argv[0] == 'viewcontacts' ? 'active' : '',
'title' => t('Contacts'),
- 'id' => 'viewcontacts-tab',
+ 'id' => 'viewcontacts-tab',
'accesskey' => 'k',
);
}
- $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs);
+ $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => $tab, 'tabs' => $tabs);
call_hooks('profile_tabs', $arr);
$tpl = get_markup_template('common_tabs.tpl');
@@ -939,9 +927,9 @@ function zrl_init(App $a)
// The check fetches the cached value from gprobe to reduce the load for this system
$urlparts = parse_url($my_url);
- $result = Cache::get("gprobe:" . $urlparts["host"]);
- if ((!is_null($result)) && (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
- logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG);
+ $result = Cache::get('gprobe:' . $urlparts['host']);
+ if ((!is_null($result)) && (in_array($result['network'], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
+ logger('DDoS attempt detected for ' . $urlparts['host'] . ' by ' . $_SERVER['REMOTE_ADDR'] . '. server data: ' . print_r($_SERVER, true), LOGGER_DEBUG);
return;
}
@@ -953,10 +941,10 @@ function zrl_init(App $a)
function zrl($s, $force = false)
{
- if (! strlen($s)) {
+ if (!strlen($s)) {
return $s;
}
- if ((! strpos($s, '/profile/')) && (! $force)) {
+ if ((!strpos($s, '/profile/')) && (!$force)) {
return $s;
}
if ($force && substr($s, -1, 1) !== '/') {
@@ -964,7 +952,7 @@ function zrl($s, $force = false)
}
$achar = strpos($s, '?') ? '&' : '?';
$mine = get_my_url();
- if ($mine && ! link_compare($mine, $s)) {
+ if ($mine && !link_compare($mine, $s)) {
return $s . $achar . 'zrl=' . urlencode($mine);
}
return $s;
@@ -987,7 +975,7 @@ function zrl($s, $force = false)
function get_theme_uid()
{
$uid = ((!empty($_REQUEST['puid'])) ? intval($_REQUEST['puid']) : 0);
- if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (! $uid))) {
+ if ((local_user()) && ((PConfig::get(local_user(), 'system', 'always_my_theme')) || (!$uid))) {
return local_user();
}
diff --git a/include/items.php b/include/items.php
index 275052c1f..8f15f9479 100644
--- a/include/items.php
+++ b/include/items.php
@@ -20,8 +20,6 @@ use Friendica\Protocol\OStatus;
use Friendica\Protocol\Feed;
require_once 'include/bbcode.php';
-require_once 'include/oembed.php';
-require_once 'include/crypto.php';
require_once 'include/tags.php';
require_once 'include/files.php';
require_once 'include/text.php';
@@ -423,7 +421,7 @@ function uri_to_guid($uri, $host = "") {
* @return array Item array with removed conversation data
*/
function store_conversation($arr) {
- if (in_array($arr['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)) && !empty($arr['uri'])) {
+ if (in_array(defaults($arr, 'network', NETWORK_PHANTOM), array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)) && !empty($arr['uri'])) {
$conversation = array('item-uri' => $arr['uri'], 'received' => DBM::date());
if (isset($arr['parent-uri']) && ($arr['parent-uri'] != $arr['uri'])) {
@@ -481,8 +479,8 @@ function store_conversation($arr) {
}
/// @TODO add type-hint array
-function item_store($arr, $force_parent = false, $notify = false, $dontcache = false) {
-
+function item_store($arr, $force_parent = false, $notify = false, $dontcache = false)
+{
$a = get_app();
// If it is a posting where users should get notifications, then define it as wall posting
@@ -504,6 +502,8 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
$arr['guid'] = uri_to_guid($arr['uri'], $a->get_hostname());
}
}
+ } else {
+ $arr['network'] = trim(defaults($arr, 'network', NETWORK_PHANTOM));
}
if ($notify) {
@@ -583,7 +583,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
* We have to check several networks since Friendica posts could be repeated
* via OStatus (maybe Diasporsa as well)
*/
- if (in_array(trim($arr['network']), array(NETWORK_DIASPORA, NETWORK_DFRN, NETWORK_OSTATUS, ""))) {
+ if (in_array($arr['network'], array(NETWORK_DIASPORA, NETWORK_DFRN, NETWORK_OSTATUS, ""))) {
$r = q("SELECT `id`, `network` FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `network` IN ('%s', '%s', '%s') LIMIT 1",
dbesc(trim($arr['uri'])),
intval($uid),
@@ -646,7 +646,6 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
$arr['attach'] = ((x($arr, 'attach')) ? notags(trim($arr['attach'])) : '');
$arr['app'] = ((x($arr, 'app')) ? notags(trim($arr['app'])) : '');
$arr['origin'] = ((x($arr, 'origin')) ? intval($arr['origin']) : 0 );
- $arr['network'] = ((x($arr, 'network')) ? trim($arr['network']) : '');
$arr['postopts'] = ((x($arr, 'postopts')) ? trim($arr['postopts']) : '');
$arr['resource-id'] = ((x($arr, 'resource-id')) ? trim($arr['resource-id']) : '');
$arr['event-id'] = ((x($arr, 'event-id')) ? intval($arr['event-id']) : 0 );
@@ -676,18 +675,19 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
$arr['plink'] = System::baseUrl() . '/display/' . urlencode($arr['guid']);
}
- if ($arr['network'] == "") {
+ if ($arr['network'] == NETWORK_PHANTOM) {
$r = q("SELECT `network` FROM `contact` WHERE `network` IN ('%s', '%s', '%s') AND `nurl` = '%s' AND `uid` = %d LIMIT 1",
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS),
dbesc(normalise_link($arr['author-link'])),
intval($arr['uid'])
);
- if (!DBM::is_result($r))
+ if (!DBM::is_result($r)) {
$r = q("SELECT `network` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND `nurl` = '%s' LIMIT 1",
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS),
dbesc(normalise_link($arr['author-link']))
);
+ }
if (!DBM::is_result($r)) {
$r = q("SELECT `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@@ -735,7 +735,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
logger("Contact-id was missing for post ".$arr["guid"]." from user id ".$uid." - now set to ".$arr["contact-id"], LOGGER_DEBUG);
}
- if ($arr["gcontact-id"] == 0) {
+ if (!x($arr, "gcontact-id")) {
/*
* The gcontact should mostly behave like the contact. But is is supposed to be global for the system.
* This means that wall posts, repeated posts, etc. should have the gcontact id of the owner.
diff --git a/include/oembed.php b/include/oembed.php
deleted file mode 100644
index b7c1616fe..000000000
--- a/include/oembed.php
+++ /dev/null
@@ -1,317 +0,0 @@
- normalise_link($embedurl));
- $r = dba::select('oembed', array('content'), $condition, array('limit' => 1));
-
- if (DBM::is_result($r)) {
- $txt = $r["content"];
- } else {
- $txt = Cache::get($a->videowidth . $embedurl);
- }
- // These media files should now be caught in bbcode.php
- // left here as a fallback in case this is called from another source
-
- $noexts = array("mp3", "mp4", "ogg", "ogv", "oga", "ogm", "webm");
- $ext = pathinfo(strtolower($embedurl), PATHINFO_EXTENSION);
-
-
- if (is_null($txt)) {
- $txt = "";
-
- if (!in_array($ext, $noexts)){
- // try oembed autodiscovery
- $redirects = 0;
- $html_text = fetch_url($embedurl, false, $redirects, 15, "text/*");
- if ($html_text) {
- $dom = @DOMDocument::loadHTML($html_text);
- if ($dom) {
- $xpath = new DOMXPath($dom);
- $attr = "oembed";
- $xattr = oe_build_xpath("class","oembed");
- $entries = $xpath->query("//link[@type='application/json+oembed']");
- foreach ($entries as $e) {
- $href = $e->getAttributeNode("href")->nodeValue;
- $txt = fetch_url($href . '&maxwidth=' . $a->videowidth);
- break;
- }
- $entries = $xpath->query("//link[@type='text/json+oembed']");
- foreach ($entries as $e) {
- $href = $e->getAttributeNode("href")->nodeValue;
- $txt = fetch_url($href . '&maxwidth=' . $a->videowidth);
- break;
- }
- }
- }
- }
-
- $txt = trim($txt);
-
- if ($txt[0] != "{") {
- $txt = '{"type":"error"}';
- } else { //save in cache
- $j = json_decode($txt);
- if ($j->type != "error") {
- dba::insert('oembed', array('url' => normalise_link($embedurl),
- 'content' => $txt, 'created' => datetime_convert()), true);
- }
-
- Cache::set($a->videowidth.$embedurl, $txt, CACHE_DAY);
- }
- }
-
- $j = json_decode($txt);
-
- if (!is_object($j)) {
- return false;
- }
-
- // Always embed the SSL version
- if (isset($j->html)) {
- $j->html = str_replace(array("http://www.youtube.com/", "http://player.vimeo.com/"),
- array("https://www.youtube.com/", "https://player.vimeo.com/"), $j->html);
- }
-
- $j->embedurl = $embedurl;
-
- // If fetching information doesn't work, then improve via internal functions
- if (($j->type == "error") || ($no_rich_type && ($j->type == "rich"))) {
- $data = ParseUrl::getSiteinfoCached($embedurl, true, false);
- $j->type = $data["type"];
-
- if ($j->type == "photo") {
- $j->url = $data["url"];
- //$j->width = $data["images"][0]["width"];
- //$j->height = $data["images"][0]["height"];
- }
-
- if (isset($data["title"])) {
- $j->title = $data["title"];
- }
-
- if (isset($data["text"])) {
- $j->description = $data["text"];
- }
-
- if (is_array($data["images"])) {
- $j->thumbnail_url = $data["images"][0]["src"];
- $j->thumbnail_width = $data["images"][0]["width"];
- $j->thumbnail_height = $data["images"][0]["height"];
- }
- }
-
- call_hooks('oembed_fetch_url', $embedurl, $j);
-
- return $j;
-}
-
-function oembed_format_object($j){
- require_once("mod/proxy.php");
-
- $embedurl = $j->embedurl;
- $jhtml = oembed_iframe($j->embedurl,(isset($j->width) ? $j->width : null), (isset($j->height) ? $j->height : null) );
- $ret="";
- $ret = str_replace("\n","",$ret);
- return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret));
-}
-
-/**
- * @brief Generates the iframe HTML for an oembed attachment.
- *
- * Width and height are given by the remote, and are regularly too small for
- * the generated iframe.
- *
- * The width is entirely discarded for the actual width of the post, while fixed
- * height is used as a starting point before the inevitable resizing.
- *
- * Since the iframe is automatically resized on load, there are no need for ugly
- * and impractical scrollbars.
- *
- * @param string $src Original remote URL to embed
- * @param string $width
- * @param string $height
- * @return string formatted HTML
- *
- * @see oembed_format_object()
- */
-function oembed_iframe($src, $width, $height) {
- $a = get_app();
-
- if (!$height || strstr($height,'%')) {
- $height = '200';
- }
- $width = '100%';
-
- $s = System::baseUrl() . '/oembed/' . base64url_encode($src);
- return '';
-}
-
-
-
-function oembed_bbcode2html($text){
- $stopoembed = Config::get("system","no_oembed");
- if ($stopoembed == true){
- return preg_replace("/\[embed\](.+?)\[\/embed\]/is", "". t('Embedding disabled') ." : $1" ,$text);
- }
- return preg_replace_callback("/\[embed\](.+?)\[\/embed\]/is", 'oembed_replacecb' ,$text);
-}
-
-
-function oe_build_xpath($attr, $value){
- // http://westhoffswelt.de/blog/0036_xpath_to_select_html_by_class.html
- return "contains( normalize-space( @$attr ), ' $value ' ) or substring( normalize-space( @$attr ), 1, string-length( '$value' ) + 1 ) = '$value ' or substring( normalize-space( @$attr ), string-length( @$attr ) - string-length( '$value' ) ) = ' $value' or @$attr = '$value'";
-}
-
-function oe_get_inner_html($node) {
- $innerHTML= '';
- $children = $node->childNodes;
- foreach ($children as $child) {
- $innerHTML .= $child->ownerDocument->saveXML($child);
- }
- return $innerHTML;
-}
-
-/**
- * Find
- * and replace it with [embed]url[/embed]
- */
-function oembed_html2bbcode($text) {
- // start parser only if 'oembed' is in text
- if (strpos($text, "oembed")) {
-
- // convert non ascii chars to html entities
- $html_text = mb_convert_encoding($text, 'HTML-ENTITIES', mb_detect_encoding($text));
-
- // If it doesn't parse at all, just return the text.
- $dom = @DOMDocument::loadHTML($html_text);
- if (! $dom) {
- return $text;
- }
- $xpath = new DOMXPath($dom);
- $attr = "oembed";
-
- $xattr = oe_build_xpath("class","oembed");
- $entries = $xpath->query("//span[$xattr]");
-
- $xattr = "@rel='oembed'";//oe_build_xpath("rel","oembed");
- foreach ($entries as $e) {
- $href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue;
- if (!is_null($href)) {
- $e->parentNode->replaceChild(new DOMText("[embed]".$href."[/embed]"), $e);
- }
- }
- return oe_get_inner_html( $dom->getElementsByTagName("body")->item(0) );
- } else {
- return $text;
- }
-}
diff --git a/include/tags.php b/include/tags.php
index 8d8fb7655..584ed30e5 100644
--- a/include/tags.php
+++ b/include/tags.php
@@ -1,4 +1,5 @@
$link) {
+ $pattern = '/\W([\#@])\[url\=(.*?)\](.*?)\[\/url\]/ism';
+ if (preg_match_all($pattern, $data, $matches, PREG_SET_ORDER)) {
+ foreach ($matches as $match) {
+ $tags[$match[1] . strtolower(trim($match[3], ',.:;[]/\"?!'))] = $match[2];
+ }
+ }
- if (substr(trim($tag), 0, 1) == "#") {
+ foreach ($tags as $tag => $link) {
+ if (substr(trim($tag), 0, 1) == '#') {
// try to ignore #039 or #1 or anything like that
- if (ctype_digit(substr(trim($tag),1)))
+ if (ctype_digit(substr(trim($tag), 1)))
continue;
// try to ignore html hex escapes, e.g. #x2317
- if ((substr(trim($tag),1,1) == 'x' || substr(trim($tag),1,1) == 'X') && ctype_digit(substr(trim($tag),2)))
+ if ((substr(trim($tag), 1, 1) == 'x' || substr(trim($tag), 1, 1) == 'X') && ctype_digit(substr(trim($tag), 2)))
continue;
$type = TERM_HASHTAG;
$term = substr($tag, 1);
- } elseif (substr(trim($tag), 0, 1) == "@") {
+ } elseif (substr(trim($tag), 0, 1) == '@') {
$type = TERM_MENTION;
$term = substr($tag, 1);
} else { // This shouldn't happen
@@ -77,78 +85,78 @@ function create_tags_from_item($itemid) {
$term = $tag;
}
- if ($message["uid"] == 0) {
+ if ($message['uid'] == 0) {
$global = true;
q("UPDATE `term` SET `global` = 1 WHERE `otype` = %d AND `guid` = '%s'",
- intval(TERM_OBJ_POST), dbesc($message["guid"]));
+ intval(TERM_OBJ_POST), dbesc($message['guid']));
} else {
$isglobal = q("SELECT `global` FROM `term` WHERE `uid` = 0 AND `otype` = %d AND `guid` = '%s'",
- intval(TERM_OBJ_POST), dbesc($message["guid"]));
+ intval(TERM_OBJ_POST), dbesc($message['guid']));
$global = (count($isglobal) > 0);
}
$r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`, `guid`, `created`, `received`, `global`)
VALUES (%d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', %d)",
- intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval($type), dbesc($term),
- dbesc($link), dbesc($message["guid"]), dbesc($message["created"]), dbesc($message["received"]), intval($global));
+ intval($message['uid']), intval($itemid), intval(TERM_OBJ_POST), intval($type), dbesc($term),
+ dbesc($link), dbesc($message['guid']), dbesc($message['created']), dbesc($message['received']), intval($global));
// Search for mentions
if ((substr($tag, 0, 1) == '@') && (strpos($link, $profile_base_friendica) || strpos($link, $profile_base_diaspora))) {
$users = q("SELECT `uid` FROM `contact` WHERE self AND (`url` = '%s' OR `nurl` = '%s')", $link, $link);
foreach ($users AS $user) {
- if ($user["uid"] == $message["uid"]) {
+ if ($user['uid'] == $message['uid']) {
q("UPDATE `item` SET `mention` = 1 WHERE `id` = %d", intval($itemid));
- q("UPDATE `thread` SET `mention` = 1 WHERE `iid` = %d", intval($message["parent"]));
+ q("UPDATE `thread` SET `mention` = 1 WHERE `iid` = %d", intval($message['parent']));
}
}
}
}
}
-function create_tags_from_itemuri($itemuri, $uid) {
+function create_tags_from_itemuri($itemuri, $uid)
+{
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
if (count($messages)) {
foreach ($messages as $message) {
- create_tags_from_item($message["id"]);
+ create_tags_from_item($message['id']);
}
}
}
-function update_items() {
-
+function update_items()
+{
$messages = dba::p("SELECT `oid`,`item`.`guid`, `item`.`created`, `item`.`received` FROM `term` INNER JOIN `item` ON `item`.`id`=`term`.`oid` WHERE `term`.`otype` = 1 AND `term`.`guid` = ''");
- logger("fetched messages: ".dba::num_rows($messages));
+ logger('fetched messages: ' . dba::num_rows($messages));
while ($message = dba::fetch($messages)) {
-
- if ($message["uid"] == 0) {
+ if ($message['uid'] == 0) {
$global = true;
q("UPDATE `term` SET `global` = 1 WHERE `otype` = %d AND `guid` = '%s'",
- intval(TERM_OBJ_POST), dbesc($message["guid"]));
+ intval(TERM_OBJ_POST), dbesc($message['guid']));
} else {
$isglobal = q("SELECT `global` FROM `term` WHERE `uid` = 0 AND `otype` = %d AND `guid` = '%s'",
- intval(TERM_OBJ_POST), dbesc($message["guid"]));
+ intval(TERM_OBJ_POST), dbesc($message['guid']));
$global = (count($isglobal) > 0);
}
q("UPDATE `term` SET `guid` = '%s', `created` = '%s', `received` = '%s', `global` = %d WHERE `otype` = %d AND `oid` = %d",
- dbesc($message["guid"]), dbesc($message["created"]), dbesc($message["received"]),
- intval($global), intval(TERM_OBJ_POST), intval($message["oid"]));
+ dbesc($message['guid']), dbesc($message['created']), dbesc($message['received']),
+ intval($global), intval(TERM_OBJ_POST), intval($message['oid']));
}
dba::close($messages);
$messages = dba::p("SELECT `guid` FROM `item` WHERE `uid` = 0");
- logger("fetched messages: ".dba::num_rows($messages));
+ logger('fetched messages: ' . dba::num_rows($messages));
while ($message = dba::fetch(messages)) {
- q("UPDATE `item` SET `global` = 1 WHERE `guid` = '%s'", dbesc($message["guid"]));
+ q("UPDATE `item` SET `global` = 1 WHERE `guid` = '%s'", dbesc($message['guid']));
}
dba::close($messages);
@@ -166,21 +174,22 @@ function update_items() {
*
* @return arr Alphabetical sorted array of used tags of an user.
*/
-function tagadelic($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HASHTAG) {
- require_once('include/security.php');
+function tagadelic($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HASHTAG)
+{
+ require_once 'include/security.php';
$item_condition = item_condition();
$sql_options = item_permissions_sql($uid);
- $limit = $count ? sprintf("LIMIT %d", intval($count)) : "";
+ $limit = $count ? sprintf('LIMIT %d', intval($count)) : '';
if ($flags) {
if ($flags === 'wall') {
- $sql_options .= " AND `item`.`wall` ";
+ $sql_options .= ' AND `item`.`wall` ';
}
}
if ($owner_id) {
- $sql_options .= " AND `item`.`owner-id` = ".intval($owner_id)." ";
+ $sql_options .= ' AND `item`.`owner-id` = ' . intval($owner_id) . ' ';
}
// Fetch tags
@@ -194,7 +203,7 @@ function tagadelic($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HA
$type,
TERM_OBJ_POST
);
- if(!DBM::is_result($r)) {
+ if (!DBM::is_result($r)) {
return array();
}
@@ -212,32 +221,32 @@ function tagadelic($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HA
*
* @return string HTML formatted output.
*/
-function wtagblock($uid, $count = 0,$owner_id = 0, $flags = '', $type = TERM_HASHTAG) {
+function wtagblock($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HASHTAG)
+{
$o = '';
$r = tagadelic($uid, $count, $owner_id, $flags, $type);
if (count($r)) {
$contact = dba::select(
- "contact",
- array("url"),
- array("id" => $uid),
- array("limit" => 1)
+ 'contact',
+ array('url'),
+ array('id' => $uid),
+ array('limit' => 1)
);
$url = System::removedBaseUrl($contact['url']);
foreach ($r as $rr) {
$tag['level'] = $rr[2];
- $tag['url'] = $url."?tag=".urlencode($rr[0]);
+ $tag['url'] = $url . '?tag=' . urlencode($rr[0]);
$tag['name'] = $rr[0];
$tags[] = $tag;
}
- $tpl = get_markup_template("tagblock_widget.tpl");
+ $tpl = get_markup_template('tagblock_widget.tpl');
$o = replace_macros($tpl, array(
'$title' => t('Tags'),
- '$tags' => $tags
+ '$tags' => $tags
));
-
}
return $o;
}
@@ -248,7 +257,8 @@ function wtagblock($uid, $count = 0,$owner_id = 0, $flags = '', $type = TERM_HAS
* @param array $arr Array of tags/terms with tag/term name and total count of use.
* @return array Alphabetical sorted array of used tags/terms of an user.
*/
-function tag_calc($arr) {
+function tag_calc($arr)
+{
$tags = array();
$min = 1e9;
$max = -1e9;
@@ -285,7 +295,8 @@ function tag_calc($arr) {
*
* @return int
*/
-function tags_sort($a, $b) {
+function tags_sort($a, $b)
+{
if (strtolower($a[0]) == strtolower($b[0])) {
return 0;
}
@@ -298,21 +309,22 @@ function tags_sort($a, $b) {
* @param int $limit Max number of displayed tags.
* @return string HTML formattat output.
*/
-function tagcloud_wall_widget($limit = 50) {
+function tagcloud_wall_widget($limit = 50)
+{
$a = get_app();
- if(!$a->profile['profile_uid'] || !$a->profile['url']) {
- return "";
+ if (!$a->profile['profile_uid'] || !$a->profile['url']) {
+ return '';
}
- if(Feature::isEnabled($a->profile['profile_uid'], 'tagadelic')) {
+ if (Feature::isEnabled($a->profile['profile_uid'], 'tagadelic')) {
$owner_id = Contact::getIdForURL($a->profile['url']);
- if(!$owner_id) {
- return "";
+ if (!$owner_id) {
+ return '';
}
return wtagblock($a->profile['profile_uid'], $limit, $owner_id, 'wall');
}
- return "";
+ return '';
}
diff --git a/include/text.php b/include/text.php
index cbba8d0c5..5a24c68ed 100644
--- a/include/text.php
+++ b/include/text.php
@@ -994,7 +994,7 @@ function contact_block() {
function micropro($contact, $redirect = false, $class = '', $textmode = false) {
// Use the contact URL if no address is available
- if ($contact["addr"] == "") {
+ if (!x($contact, "addr")) {
$contact["addr"] = $contact["url"];
}
@@ -1020,7 +1020,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) {
}
return replace_macros(get_markup_template(($textmode)?'micropro_txt.tpl':'micropro_img.tpl'),array(
- '$click' => (($contact['click']) ? $contact['click'] : ''),
+ '$click' => defaults($contact, 'click', ''),
'$class' => $class,
'$url' => $url,
'$photo' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB),
@@ -1202,11 +1202,15 @@ function redir_private_images($a, &$item)
}
}
-function put_item_in_cache(&$item, $update = false) {
-
- if (($item["rendered-hash"] != hash("md5", $item["body"])) || ($item["rendered-hash"] == "") ||
- ($item["rendered-html"] == "") || Config::get("system", "ignore_cache")) {
+function put_item_in_cache(&$item, $update = false)
+{
+ $rendered_hash = defaults($item, 'rendered-hash', '');
+ if ($rendered_hash == ''
+ || $item["rendered-html"] == ""
+ || $rendered_hash != hash("md5", $item["body"])
+ || Config::get("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"];
@@ -2026,7 +2030,7 @@ function deindent($text, $chr = "[\t ]", $count = NULL) {
}
function formatBytes($bytes, $precision = 2) {
- $units = array('B', 'KB', 'MB', 'GB', 'TB');
+ $units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
diff --git a/index.php b/index.php
index 2f58321ae..711478fe1 100644
--- a/index.php
+++ b/index.php
@@ -98,6 +98,7 @@ if (!$a->is_backend()) {
session_start();
$a->save_timestamp($stamp1, "parser");
} else {
+ $_SESSION = [];
Worker::executeIfIdle();
}
diff --git a/mod/contacts.php b/mod/contacts.php
index 3421babf6..c58dc0fc4 100644
--- a/mod/contacts.php
+++ b/mod/contacts.php
@@ -35,8 +35,9 @@ function contacts_init(App $a) {
require_once 'include/contact_widgets.php';
- if ($_GET['nets'] == "all") {
- $_GET['nets'] = "";
+ $nets = defaults($_GET, 'nets', '');
+ if ($nets == "all") {
+ $nets = "";
}
if (! x($a->page,'aside')) {
@@ -63,22 +64,22 @@ function contacts_init(App $a) {
'$account_type' => Contact::getAccountType($a->data['contact'])
));
- $finpeople_widget = '';
+ $findpeople_widget = '';
$follow_widget = '';
$networks_widget = '';
} else {
$vcard_widget = '';
- $networks_widget .= networks_widget('contacts',$_GET['nets']);
+ $networks_widget = networks_widget('contacts', $nets);
if (isset($_GET['add'])) {
$follow_widget = follow_widget($_GET['add']);
} else {
$follow_widget = follow_widget();
}
- $findpeople_widget .= findpeople_widget();
+ $findpeople_widget = findpeople_widget();
}
- $groups_widget .= Group::sidebarWidget('contacts','group','full',0,$contact_id);
+ $groups_widget = Group::sidebarWidget('contacts','group','full',0,$contact_id);
$a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
'$vcard_widget' => $vcard_widget,
@@ -515,8 +516,6 @@ function contacts_content(App $a) {
require_once 'include/contact_selectors.php';
- $tpl = get_markup_template("contact_edit.tpl");
-
switch($contact['rel']) {
case CONTACT_IS_FRIEND:
$dir_icon = 'images/lrarrow.gif';
@@ -577,6 +576,7 @@ function contacts_content(App $a) {
$lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
+ $fetch_further_information = null;
if ($contact['network'] == NETWORK_FEED) {
$fetch_further_information = array('fetch_further_information',
t('Fetch further information for feeds'),
@@ -587,12 +587,19 @@ function contacts_content(App $a) {
'3' => t('Fetch keywords'),
'2' => t('Fetch information and keywords')));
}
- if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL)))
+
+ $poll_interval = null;
+ if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL))) {
$poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
+ }
- if ($contact['network'] == NETWORK_DFRN)
+ $profile_select = null;
+ if ($contact['network'] == NETWORK_DFRN) {
$profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
+ }
+ $follow = '';
+ $follow_text = '';
if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
if ($contact['rel'] == CONTACT_IS_FOLLOWER) {
$follow = System::baseUrl(true)."/follow?url=".urlencode($contact["url"]);
@@ -606,7 +613,7 @@ function contacts_content(App $a) {
// Load contactact related actions like hide, suggest, delete and others
$contact_actions = contact_actions($contact);
-
+ $tpl = get_markup_template("contact_edit.tpl");
$o .= replace_macros($tpl, array(
//'$header' => t('Contact Editor'),
'$header' => t("Contact"),
@@ -618,9 +625,7 @@ function contacts_content(App $a) {
'$lbl_info2' => t('Their personal note'),
'$reason' => trim(notags($contact['reason'])),
'$infedit' => t('Edit contact notes'),
- '$common_text' => $common_text,
'$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
- '$all_friends' => $all_friends,
'$relation_text' => $relation_text,
'$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
'$blockunblock' => t('Block/Unblock contact'),
@@ -658,7 +663,6 @@ function contacts_content(App $a) {
'$photo' => $contact['photo'],
'$name' => htmlentities($contact['name']),
'$dir_icon' => $dir_icon,
- '$alt_text' => $alt_text,
'$sparkle' => $sparkle,
'$url' => $url,
'$profileurllabel' => t('Profile URL'),
@@ -688,36 +692,33 @@ function contacts_content(App $a) {
}
- $blocked = false;
- $hidden = false;
- $ignored = false;
- $all = false;
+ $blocked = false;
+ $hidden = false;
+ $ignored = false;
+ $archived = false;
+ $all = false;
if(($a->argc == 2) && ($a->argv[1] === 'all')) {
$sql_extra = '';
$all = true;
- }
- elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
+ } elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
$sql_extra = " AND `blocked` = 1 ";
$blocked = true;
- }
- elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
+ } elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
$sql_extra = " AND `hidden` = 1 ";
$hidden = true;
- }
- elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
+ } elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
$sql_extra = " AND `readonly` = 1 ";
$ignored = true;
- }
- elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
+ } elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
$sql_extra = " AND `archive` = 1 ";
$archived = true;
- }
- else
+ } else {
$sql_extra = " AND `blocked` = 0 ";
+ }
- $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
- $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
+ $search = x($_GET, 'search') ? notags(trim($_GET['search'])) : '';
+ $nets = x($_GET, 'nets') ? notags(trim($_GET['nets'])) : '';
$tabs = array(
array(
@@ -786,25 +787,25 @@ function contacts_content(App $a) {
$tab_tpl = get_markup_template('common_tabs.tpl');
$t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
-
-
$searching = false;
- if($search) {
+ $search_hdr = null;
+ if ($search) {
$search_hdr = $search;
$search_txt = dbesc(protect_sprintf(preg_quote($search)));
$searching = true;
}
$sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
- if($nets)
+ if ($nets) {
$sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
+ }
$sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
-
$r = q("SELECT COUNT(*) AS `total` FROM `contact`
WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
- intval($_SESSION['uid']));
+ intval($_SESSION['uid'])
+ );
if (DBM::is_result($r)) {
$a->set_pager_total($r[0]['total']);
$total = $r[0]['total'];
@@ -834,7 +835,7 @@ function contacts_content(App $a) {
'$total' => $total,
'$search' => $search_hdr,
'$desc' => t('Search your contacts'),
- '$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
+ '$finding' => $searching ? t('Results for: %s', $search) : "",
'$submit' => t('Find'),
'$cmd' => $a->cmd,
'$contacts' => $contacts,
@@ -849,7 +850,6 @@ function contacts_content(App $a) {
),
'$h_batch_actions' => t('Batch Actions'),
'$paginate' => paginate($a),
-
));
return $o;
@@ -927,12 +927,11 @@ function contact_posts($a, $contact_id) {
$contact = $r[0];
$a->page['aside'] = "";
profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
- } else
- $profile = "";
+ }
$tab_str = contacts_tab($a, $contact_id, 1);
- $o .= $tab_str;
+ $o = $tab_str;
$o .= Contact::getPostsFromUrl($contact["url"]);
diff --git a/mod/crepair.php b/mod/crepair.php
index 32db9be92..1a135a602 100644
--- a/mod/crepair.php
+++ b/mod/crepair.php
@@ -1,4 +1,5 @@
argc == 2) && intval($a->argv[1])) {
+ if (($a->argc == 2) && intval($a->argv[1])) {
$contact_id = intval($a->argv[1]);
$r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
intval(local_user()),
intval($contact_id)
);
- if (! DBM::is_result($r)) {
+ if (!DBM::is_result($r)) {
$contact_id = 0;
}
}
- if(! x($a->page,'aside'))
+ if (!x($a->page, 'aside')) {
$a->page['aside'] = '';
+ }
- if($contact_id) {
+ if ($contact_id) {
$a->data['contact'] = $r[0];
$contact = $r[0];
profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
}
}
-function crepair_post(App $a) {
- if (! local_user()) {
+function crepair_post(App $a)
+{
+ if (!local_user()) {
return;
}
$cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
- if($cid) {
+ if ($cid) {
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($cid),
intval(local_user())
);
}
- if (! DBM::is_result($r)) {
+ if (!DBM::is_result($r)) {
return;
}
$contact = $r[0];
- $name = ((x($_POST,'name')) ? $_POST['name'] : $contact['name']);
- $nick = ((x($_POST,'nick')) ? $_POST['nick'] : '');
- $url = ((x($_POST,'url')) ? $_POST['url'] : '');
- $request = ((x($_POST,'request')) ? $_POST['request'] : '');
- $confirm = ((x($_POST,'confirm')) ? $_POST['confirm'] : '');
- $notify = ((x($_POST,'notify')) ? $_POST['notify'] : '');
- $poll = ((x($_POST,'poll')) ? $_POST['poll'] : '');
- $attag = ((x($_POST,'attag')) ? $_POST['attag'] : '');
- $photo = ((x($_POST,'photo')) ? $_POST['photo'] : '');
- $remote_self = ((x($_POST,'remote_self')) ? $_POST['remote_self'] : false);
- $nurl = normalise_link($url);
+ $name = defaults($_POST, 'name' , $contact['name']);
+ $nick = defaults($_POST, 'nick' , '');
+ $url = defaults($_POST, 'url' , '');
+ $request = defaults($_POST, 'request' , '');
+ $confirm = defaults($_POST, 'confirm' , '');
+ $notify = defaults($_POST, 'notify' , '');
+ $poll = defaults($_POST, 'poll' , '');
+ $attag = defaults($_POST, 'attag' , '');
+ $photo = defaults($_POST, 'photo' , '');
+ $remote_self = defaults($_POST, 'remote_self', false);
+ $nurl = normalise_link($url);
$r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `nurl` = '%s', `request` = '%s', `confirm` = '%s', `notify` = '%s', `poll` = '%s', `attag` = '%s' , `remote_self` = %d
WHERE `id` = %d AND `uid` = %d",
@@ -101,26 +105,24 @@ function crepair_post(App $a) {
return;
}
-
-
-function crepair_content(App $a) {
-
- if (! local_user()) {
- notice( t('Permission denied.') . EOL);
+function crepair_content(App $a)
+{
+ if (!local_user()) {
+ notice(t('Permission denied.') . EOL);
return;
}
$cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
- if($cid) {
+ if ($cid) {
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($cid),
intval(local_user())
);
}
- if (! DBM::is_result($r)) {
- notice( t('Contact not found.') . EOL);
+ if (!DBM::is_result($r)) {
+ notice(t('Contact not found.') . EOL);
return;
}
@@ -131,45 +133,44 @@ function crepair_content(App $a) {
$returnaddr = "contacts/$cid";
- $allow_remote_self = Config::get('system','allow_users_remote_self');
+ $allow_remote_self = Config::get('system', 'allow_users_remote_self');
// Disable remote self for everything except feeds.
// There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
// Problem is, you couldn't reply to both networks.
- if (!in_array($contact['network'], array(NETWORK_FEED, NETWORK_DFRN, NETWORK_DIASPORA)))
+ if (!in_array($contact['network'], array(NETWORK_FEED, NETWORK_DFRN, NETWORK_DIASPORA))) {
$allow_remote_self = false;
+ }
- if ($contact['network'] == NETWORK_FEED)
- $remote_self_options = array('0'=>t('No mirroring'), '1'=>t('Mirror as forwarded posting'), '2'=>t('Mirror as my own posting'));
- else
- $remote_self_options = array('0'=>t('No mirroring'), '2'=>t('Mirror as my own posting'));
+ if ($contact['network'] == NETWORK_FEED) {
+ $remote_self_options = array('0' => t('No mirroring'), '1' => t('Mirror as forwarded posting'), '2' => t('Mirror as my own posting'));
+ } else {
+ $remote_self_options = array('0' => t('No mirroring'), '2' => t('Mirror as my own posting'));
+ }
- $update_profile = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_DSPR, NETWORK_OSTATUS));
+ $update_profile = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS));
$tab_str = contacts_tab($a, $contact['id'], 5);
-
$tpl = get_markup_template('crepair.tpl');
- $o .= replace_macros($tpl, array(
- //'$title' => t('Repair Contact Settings'),
- '$tab_str' => $tab_str,
- '$warning' => $warning,
- '$info' => $info,
- '$returnaddr' => $returnaddr,
- '$return' => t('Return to contact editor'),
- '$update_profile' => update_profile,
- '$udprofilenow' => t('Refetch contact data'),
- '$contact_id' => $contact['id'],
- '$lbl_submit' => t('Submit'),
-
+ $o = replace_macros($tpl, array(
+ '$tab_str' => $tab_str,
+ '$warning' => $warning,
+ '$info' => $info,
+ '$returnaddr' => $returnaddr,
+ '$return' => t('Return to contact editor'),
+ '$update_profile' => $update_profile,
+ '$udprofilenow' => t('Refetch contact data'),
+ '$contact_id' => $contact['id'],
+ '$lbl_submit' => t('Submit'),
'$label_remote_self' => t('Remote Self'),
'$allow_remote_self' => $allow_remote_self,
'$remote_self' => array('remote_self',
- t('Mirror postings from this contact'),
- $contact['remote_self'],
- t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
- $remote_self_options
- ),
+ t('Mirror postings from this contact'),
+ $contact['remote_self'],
+ t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
+ $remote_self_options
+ ),
'$name' => array('name', t('Name') , htmlentities($contact['name'])),
'$nick' => array('nick', t('Account Nickname'), htmlentities($contact['nick'])),
@@ -183,5 +184,4 @@ function crepair_content(App $a) {
));
return $o;
-
}
diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php
index 112ee34ab..a5f5f1bd3 100644
--- a/mod/dfrn_confirm.php
+++ b/mod/dfrn_confirm.php
@@ -29,6 +29,7 @@ use Friendica\Model\Group;
use Friendica\Model\User;
use Friendica\Network\Probe;
use Friendica\Protocol\Diaspora;
+use Friendica\Util\Crypto;
require_once 'include/enotify.php';
@@ -162,9 +163,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) {
* worried about key leakage than anybody cracking it.
*
*/
- require_once 'include/crypto.php';
-
- $res = new_keypair(4096);
+ $res = Crypto::newKeypair(4096);
$private_key = $res['prvkey'];
diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php
index d27c7d621..69e86f1bc 100644
--- a/mod/dfrn_poll.php
+++ b/mod/dfrn_poll.php
@@ -1,4 +1,5 @@
argc > 1) && ($dfrn_id == '') && !strstr($_SERVER["HTTP_USER_AGENT"], 'Friendica')) {
$nickname = $a->argv[1];
header("Content-type: application/atom+xml");
- echo OStatus::feed($a, $nickname, $last_update, 10);
+ echo OStatus::feed($nickname, $last_update, 10);
killme();
}
- $direction = (-1);
+ $direction = -1;
-
- if(strpos($dfrn_id,':') == 1) {
- $direction = intval(substr($dfrn_id,0,1));
- $dfrn_id = substr($dfrn_id,2);
+ if (strpos($dfrn_id, ':') == 1) {
+ $direction = intval(substr($dfrn_id, 0, 1));
+ $dfrn_id = substr($dfrn_id, 2);
}
$hidewall = false;
- if(($dfrn_id === '') && (! x($_POST,'dfrn_id'))) {
- if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
+ if (($dfrn_id === '') && (!x($_POST, 'dfrn_id'))) {
+ if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
http_status_exit(403);
}
$user = '';
- if($a->argc > 1) {
+ if ($a->argc > 1) {
$r = q("SELECT `hidewall`,`nickname` FROM `user` WHERE `user`.`nickname` = '%s' LIMIT 1",
dbesc($a->argv[1])
);
- if (!$r)
+ if (!$r) {
http_status_exit(404);
+ }
$hidewall = ($r[0]['hidewall'] && !local_user());
@@ -63,16 +65,15 @@ function dfrn_poll_init(App $a) {
logger('dfrn_poll: public feed request from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $user);
header("Content-type: application/atom+xml");
- echo DFRN::feed('', $user,$last_update, 0, $hidewall);
+ echo DFRN::feed('', $user, $last_update, 0, $hidewall);
killme();
}
- if(($type === 'profile') && (! strlen($sec))) {
-
+ if (($type === 'profile') && (!strlen($sec))) {
$sql_extra = '';
- switch($direction) {
- case (-1):
- $sql_extra = sprintf(" AND ( `dfrn-id` = '%s' OR `issued-id` = '%s' ) ", dbesc($dfrn_id),dbesc($dfrn_id));
+ switch ($direction) {
+ case -1:
+ $sql_extra = sprintf(" AND ( `dfrn-id` = '%s' OR `issued-id` = '%s' ) ", dbesc($dfrn_id), dbesc($dfrn_id));
$my_id = $dfrn_id;
break;
case 0:
@@ -96,28 +97,29 @@ function dfrn_poll_init(App $a) {
);
if (DBM::is_result($r)) {
-
$s = fetch_url($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check');
logger("dfrn_poll: old profile returns " . $s, LOGGER_DATA);
- if(strlen($s)) {
-
+ if (strlen($s)) {
$xml = parse_xml_string($s);
- if((int) $xml->status == 1) {
+ if ((int) $xml->status === 1) {
$_SESSION['authenticated'] = 1;
- if(! x($_SESSION,'remote'))
+ if (!x($_SESSION, 'remote')) {
$_SESSION['remote'] = array();
+ }
- $_SESSION['remote'][] = array('cid' => $r[0]['id'],'uid' => $r[0]['uid'],'url' => $r[0]['url']);
+ $_SESSION['remote'][] = array('cid' => $r[0]['id'], 'uid' => $r[0]['uid'], 'url' => $r[0]['url']);
$_SESSION['visitor_id'] = $r[0]['id'];
$_SESSION['visitor_home'] = $r[0]['url'];
$_SESSION['visitor_handle'] = $r[0]['addr'];
$_SESSION['visitor_visiting'] = $r[0]['uid'];
- if(!$quiet)
- info( sprintf(t('%1$s welcomes %2$s'), $r[0]['username'] , $r[0]['name']) . EOL);
+ if (!$quiet) {
+ info(sprintf(t('%1$s welcomes %2$s'), $r[0]['username'], $r[0]['name']) . EOL);
+ }
+
// Visitors get 1 day session.
$session_id = session_id();
$expire = time() + 86400;
@@ -131,53 +133,53 @@ function dfrn_poll_init(App $a) {
goaway((strlen($destination_url)) ? $destination_url : System::baseUrl() . '/profile/' . $profile);
}
goaway(System::baseUrl());
-
}
- if($type === 'profile-check' && $dfrn_version < 2.2 ) {
-
- if((strlen($challenge)) && (strlen($sec))) {
-
+ if ($type === 'profile-check' && $dfrn_version < 2.2) {
+ if ((strlen($challenge)) && (strlen($sec))) {
q("DELETE FROM `profile_check` WHERE `expire` < " . intval(time()));
$r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1",
dbesc($sec)
);
- if (! DBM::is_result($r)) {
+ if (!DBM::is_result($r)) {
xml_status(3, 'No ticket');
// NOTREACHED
}
+
$orig_id = $r[0]['dfrn_id'];
- if(strpos($orig_id, ':'))
- $orig_id = substr($orig_id,2);
+ if (strpos($orig_id, ':')) {
+ $orig_id = substr($orig_id, 2);
+ }
$c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
intval($r[0]['cid'])
);
- if (! DBM::is_result($c)) {
+ if (!DBM::is_result($c)) {
xml_status(3, 'No profile');
}
+
$contact = $c[0];
$sent_dfrn_id = hex2bin($dfrn_id);
- $challenge = hex2bin($challenge);
+ $challenge = hex2bin($challenge);
$final_dfrn_id = '';
- if(($contact['duplex']) && strlen($contact['prvkey'])) {
- openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']);
- openssl_private_decrypt($challenge,$decoded_challenge,$contact['prvkey']);
- }
- else {
- openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']);
- openssl_public_decrypt($challenge,$decoded_challenge,$contact['pubkey']);
+ if (($contact['duplex']) && strlen($contact['prvkey'])) {
+ openssl_private_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['prvkey']);
+ openssl_private_decrypt($challenge, $decoded_challenge, $contact['prvkey']);
+ } else {
+ openssl_public_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['pubkey']);
+ openssl_public_decrypt($challenge, $decoded_challenge, $contact['pubkey']);
}
$final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
- if(strpos($final_dfrn_id,':') == 1)
- $final_dfrn_id = substr($final_dfrn_id,2);
+ if (strpos($final_dfrn_id, ':') == 1) {
+ $final_dfrn_id = substr($final_dfrn_id, 2);
+ }
- if($final_dfrn_id != $orig_id) {
+ if ($final_dfrn_id != $orig_id) {
logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG);
// did not decode properly - cannot trust this site
xml_status(3, 'Bad decryption');
@@ -187,11 +189,9 @@ function dfrn_poll_init(App $a) {
echo "0 $decoded_challenge $sec ";
killme();
// NOTREACHED
- }
- else {
- // old protocol
-
- switch($direction) {
+ } else {
+ // old protocol
+ switch ($direction) {
case 1:
$dfrn_id = '0:' . $dfrn_id;
break;
@@ -202,7 +202,6 @@ function dfrn_poll_init(App $a) {
break;
}
-
q("DELETE FROM `profile_check` WHERE `expire` < " . intval(time()));
$r = q("SELECT * FROM `profile_check` WHERE `dfrn_id` = '%s' ORDER BY `expire` DESC",
dbesc($dfrn_id));
@@ -214,67 +213,65 @@ function dfrn_poll_init(App $a) {
return; // NOTREACHED
}
}
-
}
+function dfrn_poll_post(App $a)
+{
+ $dfrn_id = x($_POST,'dfrn_id') ? $_POST['dfrn_id'] : '';
+ $challenge = x($_POST,'challenge') ? $_POST['challenge'] : '';
+ $url = x($_POST,'url') ? $_POST['url'] : '';
+ $sec = x($_POST,'sec') ? $_POST['sec'] : '';
+ $ptype = x($_POST,'type') ? $_POST['type'] : '';
+ $dfrn_version = x($_POST,'dfrn_version') ? (float) $_POST['dfrn_version'] : 2.0;
+ $perm = x($_POST,'perm') ? $_POST['perm'] : 'r';
-
-function dfrn_poll_post(App $a) {
-
- $dfrn_id = ((x($_POST,'dfrn_id')) ? $_POST['dfrn_id'] : '');
- $challenge = ((x($_POST,'challenge')) ? $_POST['challenge'] : '');
- $url = ((x($_POST,'url')) ? $_POST['url'] : '');
- $sec = ((x($_POST,'sec')) ? $_POST['sec'] : '');
- $ptype = ((x($_POST,'type')) ? $_POST['type'] : '');
- $dfrn_version = ((x($_POST,'dfrn_version')) ? (float) $_POST['dfrn_version'] : 2.0);
- $perm = ((x($_POST,'perm')) ? $_POST['perm'] : 'r');
-
- if($ptype === 'profile-check') {
-
- if((strlen($challenge)) && (strlen($sec))) {
-
+ if ($ptype === 'profile-check') {
+ if (strlen($challenge) && strlen($sec)) {
logger('dfrn_poll: POST: profile-check');
q("DELETE FROM `profile_check` WHERE `expire` < " . intval(time()));
$r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1",
dbesc($sec)
);
- if (! DBM::is_result($r)) {
+ if (!DBM::is_result($r)) {
xml_status(3, 'No ticket');
// NOTREACHED
}
+
$orig_id = $r[0]['dfrn_id'];
- if(strpos($orig_id, ':'))
- $orig_id = substr($orig_id,2);
+ if (strpos($orig_id, ':')) {
+ $orig_id = substr($orig_id, 2);
+ }
$c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
intval($r[0]['cid'])
);
- if (! DBM::is_result($c)) {
+ if (!DBM::is_result($c)) {
xml_status(3, 'No profile');
}
+
$contact = $c[0];
$sent_dfrn_id = hex2bin($dfrn_id);
- $challenge = hex2bin($challenge);
+ $challenge = hex2bin($challenge);
$final_dfrn_id = '';
- if(($contact['duplex']) && strlen($contact['prvkey'])) {
- openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']);
- openssl_private_decrypt($challenge,$decoded_challenge,$contact['prvkey']);
- }
- else {
- openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']);
- openssl_public_decrypt($challenge,$decoded_challenge,$contact['pubkey']);
+ if ($contact['duplex'] && strlen($contact['prvkey'])) {
+ openssl_private_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['prvkey']);
+ openssl_private_decrypt($challenge, $decoded_challenge, $contact['prvkey']);
+ } else {
+ openssl_public_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['pubkey']);
+ openssl_public_decrypt($challenge, $decoded_challenge, $contact['pubkey']);
}
$final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
- if(strpos($final_dfrn_id,':') == 1)
- $final_dfrn_id = substr($final_dfrn_id,2);
+ if (strpos($final_dfrn_id, ':') == 1) {
+ $final_dfrn_id = substr($final_dfrn_id, 2);
+ }
- if($final_dfrn_id != $orig_id) {
+ if ($final_dfrn_id != $orig_id) {
logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG);
// did not decode properly - cannot trust this site
xml_status(3, 'Bad decryption');
@@ -285,22 +282,20 @@ function dfrn_poll_post(App $a) {
killme();
// NOTREACHED
}
-
}
- $direction = (-1);
- if(strpos($dfrn_id,':') == 1) {
- $direction = intval(substr($dfrn_id,0,1));
- $dfrn_id = substr($dfrn_id,2);
+ $direction = -1;
+ if (strpos($dfrn_id, ':') == 1) {
+ $direction = intval(substr($dfrn_id, 0, 1));
+ $dfrn_id = substr($dfrn_id, 2);
}
-
$r = q("SELECT * FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s' LIMIT 1",
dbesc($dfrn_id),
dbesc($challenge)
);
- if (! DBM::is_result($r)) {
+ if (!DBM::is_result($r)) {
killme();
}
@@ -314,8 +309,8 @@ function dfrn_poll_post(App $a) {
$sql_extra = '';
- switch($direction) {
- case (-1):
+ switch ($direction) {
+ case -1:
$sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($dfrn_id));
$my_id = $dfrn_id;
break;
@@ -332,11 +327,8 @@ function dfrn_poll_post(App $a) {
break; // NOTREACHED
}
-
$r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 $sql_extra LIMIT 1");
-
-
- if (! DBM::is_result($r)) {
+ if (!DBM::is_result($r)) {
killme();
}
@@ -344,8 +336,7 @@ function dfrn_poll_post(App $a) {
$owner_uid = $r[0]['uid'];
$contact_id = $r[0]['id'];
-
- if($type === 'reputation' && strlen($url)) {
+ if ($type === 'reputation' && strlen($url)) {
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
dbesc($url),
intval($owner_uid)
@@ -357,7 +348,7 @@ function dfrn_poll_post(App $a) {
$reputation = $r[0]['rating'];
$text = $r[0]['reason'];
- if($r[0]['id'] == $contact_id) { // inquiring about own reputation not allowed
+ if ($r[0]['id'] == $contact_id) { // inquiring about own reputation not allowed
$reputation = 0;
$text = '';
}
@@ -372,18 +363,17 @@ function dfrn_poll_post(App $a) {
";
killme();
// NOTREACHED
- }
- else {
-
+ } else {
// Update the writable flag if it changed
- logger('dfrn_poll: post request feed: ' . print_r($_POST,true),LOGGER_DATA);
- if($dfrn_version >= 2.21) {
- if($perm === 'rw')
+ logger('dfrn_poll: post request feed: ' . print_r($_POST, true), LOGGER_DATA);
+ if ($dfrn_version >= 2.21) {
+ if ($perm === 'rw') {
$writable = 1;
- else
+ } else {
$writable = 0;
+ }
- if($writable != $contact['writable']) {
+ if ($writable != $contact['writable']) {
q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d",
intval($writable),
intval($contact_id)
@@ -395,29 +385,27 @@ function dfrn_poll_post(App $a) {
$o = DFRN::feed($dfrn_id, $a->argv[1], $last_update, $direction);
echo $o;
killme();
-
}
}
-function dfrn_poll_content(App $a) {
+function dfrn_poll_content(App $a)
+{
+ $dfrn_id = x($_GET,'dfrn_id') ? $_GET['dfrn_id'] : '';
+ $type = x($_GET,'type') ? $_GET['type'] : 'data';
+ $last_update = x($_GET,'last_update') ? $_GET['last_update'] : '';
+ $destination_url = x($_GET,'destination_url') ? $_GET['destination_url'] : '';
+ $sec = x($_GET,'sec') ? $_GET['sec'] : '';
+ $dfrn_version = x($_GET,'dfrn_version') ? (float) $_GET['dfrn_version'] : 2.0;
+ $perm = x($_GET,'perm') ? $_GET['perm'] : 'r';
+ $quiet = x($_GET,'quiet') ? true : false;
- $dfrn_id = ((x($_GET,'dfrn_id')) ? $_GET['dfrn_id'] : '');
- $type = ((x($_GET,'type')) ? $_GET['type'] : 'data');
- $last_update = ((x($_GET,'last_update')) ? $_GET['last_update'] : '');
- $destination_url = ((x($_GET,'destination_url')) ? $_GET['destination_url'] : '');
- $sec = ((x($_GET,'sec')) ? $_GET['sec'] : '');
- $dfrn_version = ((x($_GET,'dfrn_version')) ? (float) $_GET['dfrn_version'] : 2.0);
- $perm = ((x($_GET,'perm')) ? $_GET['perm'] : 'r');
- $quiet = ((x($_GET,'quiet')) ? true : false);
-
- $direction = (-1);
- if(strpos($dfrn_id,':') == 1) {
- $direction = intval(substr($dfrn_id,0,1));
- $dfrn_id = substr($dfrn_id,2);
+ $direction = -1;
+ if (strpos($dfrn_id, ':') == 1) {
+ $direction = intval(substr($dfrn_id, 0, 1));
+ $dfrn_id = substr($dfrn_id, 2);
}
-
- if($dfrn_id != '') {
+ if ($dfrn_id != '') {
// initial communication from external contact
$hash = random_string();
@@ -425,7 +413,7 @@ function dfrn_poll_content(App $a) {
$r = q("DELETE FROM `challenge` WHERE `expire` < " . intval(time()));
- if($type !== 'profile') {
+ if ($type !== 'profile') {
$r = q("INSERT INTO `challenge` ( `challenge`, `dfrn-id`, `expire` , `type`, `last_update` )
VALUES( '%s', '%s', '%s', '%s', '%s' ) ",
dbesc($hash),
@@ -435,13 +423,16 @@ function dfrn_poll_content(App $a) {
dbesc($last_update)
);
}
+
$sql_extra = '';
- switch($direction) {
- case (-1):
- if($type === 'profile')
- $sql_extra = sprintf(" AND ( `dfrn-id` = '%s' OR `issued-id` = '%s' ) ", dbesc($dfrn_id),dbesc($dfrn_id));
- else
+ switch ($direction) {
+ case -1:
+ if ($type === 'profile') {
+ $sql_extra = sprintf(" AND ( `dfrn-id` = '%s' OR `issued-id` = '%s' ) ", dbesc($dfrn_id), dbesc($dfrn_id));
+ } else {
$sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($dfrn_id));
+ }
+
$my_id = $dfrn_id;
break;
case 0:
@@ -465,36 +456,30 @@ function dfrn_poll_content(App $a) {
AND `user`.`nickname` = '%s' $sql_extra LIMIT 1",
dbesc($nickname)
);
-
if (DBM::is_result($r)) {
-
$challenge = '';
$encrypted_id = '';
- $id_str = $my_id . '.' . mt_rand(1000,9999);
+ $id_str = $my_id . '.' . mt_rand(1000, 9999);
- if(($r[0]['duplex'] && strlen($r[0]['pubkey'])) || (! strlen($r[0]['prvkey']))) {
- openssl_public_encrypt($hash,$challenge,$r[0]['pubkey']);
- openssl_public_encrypt($id_str,$encrypted_id,$r[0]['pubkey']);
- }
- else {
- openssl_private_encrypt($hash,$challenge,$r[0]['prvkey']);
- openssl_private_encrypt($id_str,$encrypted_id,$r[0]['prvkey']);
+ if (($r[0]['duplex'] && strlen($r[0]['pubkey'])) || !strlen($r[0]['prvkey'])) {
+ openssl_public_encrypt($hash, $challenge, $r[0]['pubkey']);
+ openssl_public_encrypt($id_str, $encrypted_id, $r[0]['pubkey']);
+ } else {
+ openssl_private_encrypt($hash, $challenge, $r[0]['prvkey']);
+ openssl_private_encrypt($id_str, $encrypted_id, $r[0]['prvkey']);
}
$challenge = bin2hex($challenge);
$encrypted_id = bin2hex($encrypted_id);
- }
- else {
+ } else {
$status = 1;
$challenge = '';
$encrypted_id = '';
}
- if(($type === 'profile') && (strlen($sec))) {
-
+ if (($type === 'profile') && (strlen($sec))) {
// URL reply
-
- if($dfrn_version < 2.2) {
+ if ($dfrn_version < 2.2) {
$s = fetch_url($r[0]['poll']
. '?dfrn_id=' . $encrypted_id
. '&type=profile-check'
@@ -502,8 +487,7 @@ function dfrn_poll_content(App $a) {
. '&challenge=' . $challenge
. '&sec=' . $sec
);
- }
- else {
+ } else {
$s = post_url($r[0]['poll'], array(
'dfrn_id' => $encrypted_id,
'type' => 'profile-check',
@@ -515,7 +499,7 @@ function dfrn_poll_content(App $a) {
$profile = ((DBM::is_result($r) && $r[0]['nickname']) ? $r[0]['nickname'] : $nickname);
- switch($destination_url) {
+ switch ($destination_url) {
case 'profile':
$dest = System::baseUrl() . '/profile/' . $profile . '?f=&tab=profile';
break;
@@ -534,26 +518,28 @@ function dfrn_poll_content(App $a) {
logger("dfrn_poll: sec profile: " . $s, LOGGER_DATA);
- if(strlen($s) && strstr($s,'challenge . ' expecting ' . $hash);
logger('dfrn_poll: secure profile: sec: ' . $xml->sec . ' expecting ' . $sec);
-
- if(((int) $xml->status == 0) && ($xml->challenge == $hash) && ($xml->sec == $sec)) {
+ if (((int) $xml->status == 0) && ($xml->challenge == $hash) && ($xml->sec == $sec)) {
$_SESSION['authenticated'] = 1;
- if(! x($_SESSION,'remote'))
+ if (!x($_SESSION, 'remote')) {
$_SESSION['remote'] = array();
- $_SESSION['remote'][] = array('cid' => $r[0]['id'],'uid' => $r[0]['uid'],'url' => $r[0]['url']);
+ }
+
+ $_SESSION['remote'][] = array('cid' => $r[0]['id'], 'uid' => $r[0]['uid'], 'url' => $r[0]['url']);
$_SESSION['visitor_id'] = $r[0]['id'];
$_SESSION['visitor_home'] = $r[0]['url'];
$_SESSION['visitor_visiting'] = $r[0]['uid'];
- if(!$quiet)
- info( sprintf(t('%1$s welcomes %2$s'), $r[0]['username'] , $r[0]['name']) . EOL);
+ if (!$quiet) {
+ info(sprintf(t('%1$s welcomes %2$s'), $r[0]['username'], $r[0]['name']) . EOL);
+ }
+
// Visitors get 1 day session.
$session_id = session_id();
$expire = time() + 86400;
@@ -567,9 +553,7 @@ function dfrn_poll_content(App $a) {
}
goaway($dest);
// NOTREACHED
-
- }
- else {
+ } else {
// XML reply
header("Content-type: text/xml");
echo '' . "\r\n"
@@ -578,7 +562,7 @@ function dfrn_poll_content(App $a) {
. "\t" . '' . DFRN_PROTOCOL_VERSION . ' ' . "\r\n"
. "\t" . '' . $encrypted_id . ' ' . "\r\n"
. "\t" . '' . $challenge . ' ' . "\r\n"
- . '' . "\r\n" ;
+ . '' . "\r\n";
killme();
// NOTREACHED
}
diff --git a/mod/display.php b/mod/display.php
index 67e6f435e..2d91d2d1a 100644
--- a/mod/display.php
+++ b/mod/display.php
@@ -202,8 +202,9 @@ function display_content(App $a, $update = false, $update_uid = 0) {
if ($update) {
$item_id = $_REQUEST['item_id'];
- $item = dba::select('item', ['uid'], ['id' => $item_id], ['limit' => 1]);
+ $item = dba::select('item', ['uid', 'parent'], ['id' => $item_id], ['limit' => 1]);
$a->profile = array('uid' => intval($item['uid']), 'profile_uid' => intval($item['uid']));
+ $item_parent = $item['parent'];
} else {
$item_id = (($a->argc > 2) ? $a->argv[2] : 0);
@@ -261,7 +262,7 @@ function display_content(App $a, $update = false, $update_uid = 0) {
$contact_id = 0;
- if (is_array($_SESSION['remote'])) {
+ if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
foreach ($_SESSION['remote'] as $v) {
if ($v['uid'] == $a->profile['uid']) {
$contact_id = $v['cid'];
@@ -295,7 +296,7 @@ function display_content(App $a, $update = false, $update_uid = 0) {
}
$is_owner = (local_user() && (in_array($a->profile['profile_uid'], [local_user(), 0])) ? true : false);
- if ($a->profile['hidewall'] && !$is_owner && !$remote_contact) {
+ if (x($a->profile, 'hidewall') && !$is_owner && !$remote_contact) {
notice(t('Access to this profile has been restricted.') . EOL);
return;
}
diff --git a/mod/events.php b/mod/events.php
index 7a05274e2..eb804b5d6 100644
--- a/mod/events.php
+++ b/mod/events.php
@@ -20,7 +20,7 @@ function events_init(App $a) {
return;
}
- if ($a->argc == 1) {
+ if ($a->argc > 1) {
// If it's a json request abort here because we don't
// need the widget data
if ($a->argv[1] === 'json') {
@@ -234,6 +234,7 @@ function events_content(App $a) {
));
$o = '';
+ $tabs = '';
// tabs
if ($a->theme_events_in_profile) {
$tabs = profile_tabs($a, true);
@@ -309,10 +310,13 @@ function events_content(App $a) {
$start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
$finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
-
- if ($a->argv[1] === 'json') {
- if (x($_GET, 'start')) {$start = $_GET['start'];}
- if (x($_GET, 'end')) {$finish = $_GET['end'];}
+ if ($a->argc > 1 && $a->argv[1] === 'json') {
+ if (x($_GET, 'start')) {
+ $start = $_GET['start'];
+ }
+ if (x($_GET, 'end')) {
+ $finish = $_GET['end'];
+ }
}
$start = datetime_convert('UTC', 'UTC', $start);
@@ -358,7 +362,7 @@ function events_content(App $a) {
$events = process_events($r);
}
- if ($a->argv[1] === 'json'){
+ if ($a->argc > 1 && $a->argv[1] === 'json'){
echo json_encode($events);
killme();
}
diff --git a/mod/fetch.php b/mod/fetch.php
index 68f6acc91..c097ee4c4 100644
--- a/mod/fetch.php
+++ b/mod/fetch.php
@@ -8,8 +8,6 @@ use Friendica\Core\System;
use Friendica\Protocol\Diaspora;
use Friendica\Util\XML;
-require_once "include/crypto.php";
-
function fetch_init(App $a)
{
diff --git a/mod/hostxrd.php b/mod/hostxrd.php
index 0403945ef..1da8fda99 100644
--- a/mod/hostxrd.php
+++ b/mod/hostxrd.php
@@ -1,18 +1,21 @@
$a->get_hostname(),
'$zroot' => System::baseUrl(),
'$domain' => System::baseUrl(),
- '$bigkey' => salmon_key(Config::get('system','site_pubkey')),
- ));
- exit();
+ '$bigkey' => Salmon::salmonKey(Config::get('system', 'site_pubkey')))
+ );
+ exit();
}
diff --git a/mod/hovercard.php b/mod/hovercard.php
index 8ad5cd0eb..29dfd2689 100644
--- a/mod/hovercard.php
+++ b/mod/hovercard.php
@@ -7,90 +7,87 @@
* Author: Rabuzarus
* License: GNU AFFERO GENERAL PUBLIC LICENSE (Version 3)
*/
-
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
-function hovercard_init(App $a) {
+function hovercard_init(App $a)
+{
// Just for testing purposes
- $_GET["mode"] = "minimal";
+ $_GET['mode'] = 'minimal';
}
-function hovercard_content() {
- $profileurl = (x($_REQUEST,'profileurl') ? $_REQUEST['profileurl'] : "");
- $datatype = (x($_REQUEST,'datatype') ?$_REQUEST['datatype'] : "json");
+function hovercard_content()
+{
+ $profileurl = defaults($_REQUEST, 'profileurl', '');
+ $datatype = defaults($_REQUEST, 'datatype' , 'json');
// Get out if the system doesn't have public access allowed
- if(intval(Config::get('system','block_public')))
+ if (intval(Config::get('system', 'block_public'))) {
http_status_exit(401);
+ }
// Return the raw content of the template. We use this to make templates usable for js functions.
// Look at hovercard.js (function getHoverCardTemplate()).
- // This part should be moved in it's own module. Maybe we could make more templates accessabel.
- // (We need to discuss possible security lacks before doing this)
- if ($datatype == "tpl") {
- $templatecontent = get_template_content("hovercard.tpl");
+ // This part should be moved in its own module. Maybe we could make more templates accessible.
+ // (We need to discuss possible security leaks before doing this)
+ if ($datatype == 'tpl') {
+ $templatecontent = get_template_content('hovercard.tpl');
echo $templatecontent;
killme();
}
- // If a contact is connected the url is internally changed to "redir/CID". We need the pure url to search for
+ // If a contact is connected the url is internally changed to 'redir/CID'. We need the pure url to search for
// the contact. So we strip out the contact id from the internal url and look in the contact table for
// the real url (nurl)
- if (local_user() && strpos($profileurl, "redir/") === 0) {
+ $cid = 0;
+ if (local_user() && strpos($profileurl, 'redir/') === 0) {
$cid = intval(substr($profileurl, 6));
- $r = dba::select('contact', array('nurl', 'self'), array('id' => $cid), array('limit' => 1));
- $profileurl = ($r["nurl"] ? $r["nurl"] : "");
- $self = ($r["self"] ? $r["self"] : "");
+ $r = dba::select('contact', array('nurl'), array('id' => $cid), array('limit' => 1));
+ $profileurl = defaults($r, 'nurl', '');
}
+ $contact = [];
// if it's the url containing https it should be converted to http
$nurl = normalise_link(GContact::cleanContactUrl($profileurl));
- if($nurl) {
+ if ($nurl) {
// Search for contact data
$contact = Contact::getDetailsByURL($nurl);
}
- if(!is_array($contact))
+ if (!count($contact)) {
return;
+ }
// Get the photo_menu - the menu if possible contact actions
- if(local_user())
+ if (local_user()) {
$actions = Contact::photoMenu($contact);
-
+ }
// Move the contact data to the profile array so we can deliver it to
- //
$profile = array(
- 'name' => $contact["name"],
- 'nick' => $contact["nick"],
- 'addr' => (($contact["addr"] != "") ? $contact["addr"] : $contact["url"]),
- 'thumb' => proxy_url($contact["thumb"], false, PROXY_SIZE_THUMB),
- 'url' => ($cid ? ("redir/".$cid) : zrl($contact["url"])),
- 'nurl' => $contact["nurl"], // We additionally store the nurl as identifier
-// 'alias' => $contact["alias"],
- 'location' => $contact["location"],
- 'gender' => $contact["gender"],
- 'about' => $contact["about"],
- 'network' => format_network_name($contact["network"], $contact["url"]),
- 'tags' => $contact["keywords"],
-// 'nsfw' => intval($contact["nsfw"]),
-// 'server_url' => $contact["server_url"],
- 'bd' => (($contact["birthday"] <= '0001-01-01') ? "" : $contact["birthday"]),
-// 'generation' => $contact["generation"],
+ 'name' => $contact['name'],
+ 'nick' => $contact['nick'],
+ 'addr' => defaults($contact, 'addr', $contact['url']),
+ 'thumb' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB),
+ 'url' => $cid ? ('redir/' . $cid) : zrl($contact['url']),
+ 'nurl' => $contact['nurl'], // We additionally store the nurl as identifier
+ 'location' => $contact['location'],
+ 'gender' => $contact['gender'],
+ 'about' => $contact['about'],
+ 'network' => format_network_name($contact['network'], $contact['url']),
+ 'tags' => $contact['keywords'],
+ 'bd' => $contact['birthday'] <= '0001-01-01' ? '' : $contact['birthday'],
'account_type' => Contact::getAccountType($contact),
- 'actions' => $actions,
+ 'actions' => $actions,
);
- if($datatype == "html") {
- $t = get_markup_template("hovercard.tpl");
-
- $o = replace_macros($t, array(
+ if ($datatype == 'html') {
+ $tpl = get_markup_template('hovercard.tpl');
+ $o = replace_macros($tpl, array(
'$profile' => $profile,
));
return $o;
-
} else {
json_return_and_die($profile);
}
@@ -104,15 +101,15 @@ function hovercard_content() {
*
* @return string|bool Output the raw content if existent, otherwise false
*/
-function get_template_content($template, $root = "") {
-
+function get_template_content($template, $root = '')
+{
// We load the whole template system to get the filename.
// Maybe we can do it a little bit smarter if I get time.
$t = get_markup_template($template, $root);
$filename = $t->filename;
// Get the content of the template file
- if(file_exists($filename)) {
+ if (file_exists($filename)) {
$content = file_get_contents($filename);
return $content;
diff --git a/mod/item.php b/mod/item.php
index 13877fb35..1faef9601 100644
--- a/mod/item.php
+++ b/mod/item.php
@@ -29,7 +29,6 @@ use Friendica\Protocol\Diaspora;
use Friendica\Protocol\Email;
use Friendica\Util\Emailer;
-require_once 'include/crypto.php';
require_once 'include/enotify.php';
require_once 'include/tags.php';
require_once 'include/files.php';
diff --git a/mod/message.php b/mod/message.php
index eba1c9a62..9e0cb32c0 100644
--- a/mod/message.php
+++ b/mod/message.php
@@ -10,107 +10,104 @@ require_once 'include/acl_selectors.php';
require_once 'include/message.php';
require_once 'include/conversation.php';
-function message_init(App $a) {
-
+function message_init(App $a)
+{
$tabs = '';
- if ($a->argc >1 && is_numeric($a->argv[1])) {
- $tabs = render_messages(get_messages(local_user(),0,5), 'mail_list.tpl');
+ if ($a->argc > 1 && is_numeric($a->argv[1])) {
+ $tabs = render_messages(get_messages(local_user(), 0, 5), 'mail_list.tpl');
}
$new = array(
'label' => t('New Message'),
'url' => 'message/new',
- 'sel'=> ($a->argv[1] == 'new'),
+ 'sel' => $a->argc > 1 && $a->argv[1] == 'new',
'accesskey' => 'm',
);
$tpl = get_markup_template('message_side.tpl');
$a->page['aside'] = replace_macros($tpl, array(
- '$tabs'=>$tabs,
- '$new'=>$new,
+ '$tabs' => $tabs,
+ '$new' => $new,
));
$base = System::baseUrl();
$head_tpl = get_markup_template('message-head.tpl');
- $a->page['htmlhead'] .= replace_macros($head_tpl,array(
+ $a->page['htmlhead'] .= replace_macros($head_tpl, array(
'$baseurl' => System::baseUrl(true),
'$base' => $base
));
$end_tpl = get_markup_template('message-end.tpl');
- $a->page['end'] .= replace_macros($end_tpl,array(
+ $a->page['end'] .= replace_macros($end_tpl, array(
'$baseurl' => System::baseUrl(true),
'$base' => $base
));
-
}
-function message_post(App $a) {
-
- if (! local_user()) {
- notice( t('Permission denied.') . EOL);
+function message_post(App $a)
+{
+ if (!local_user()) {
+ notice(t('Permission denied.') . EOL);
return;
}
- $replyto = ((x($_REQUEST,'replyto')) ? notags(trim($_REQUEST['replyto'])) : '');
- $subject = ((x($_REQUEST,'subject')) ? notags(trim($_REQUEST['subject'])) : '');
- $body = ((x($_REQUEST,'body')) ? escape_tags(trim($_REQUEST['body'])) : '');
- $recipient = ((x($_REQUEST,'messageto')) ? intval($_REQUEST['messageto']) : 0 );
+ $replyto = x($_REQUEST, 'replyto') ? notags(trim($_REQUEST['replyto'])) : '';
+ $subject = x($_REQUEST, 'subject') ? notags(trim($_REQUEST['subject'])) : '';
+ $body = x($_REQUEST, 'body') ? escape_tags(trim($_REQUEST['body'])) : '';
+ $recipient = x($_REQUEST, 'messageto') ? intval($_REQUEST['messageto']) : 0;
$ret = send_message($recipient, $body, $subject, $replyto);
$norecip = false;
- switch($ret){
+ switch ($ret) {
case -1:
- notice( t('No recipient selected.') . EOL );
+ notice(t('No recipient selected.') . EOL);
$norecip = true;
break;
case -2:
- notice( t('Unable to locate contact information.') . EOL );
+ notice(t('Unable to locate contact information.') . EOL);
break;
case -3:
- notice( t('Message could not be sent.') . EOL );
+ notice(t('Message could not be sent.') . EOL);
break;
case -4:
- notice( t('Message collection failure.') . EOL );
+ notice(t('Message collection failure.') . EOL);
break;
default:
- info( t('Message sent.') . EOL );
+ info(t('Message sent.') . EOL);
}
// fake it to go back to the input form if no recipient listed
-
if ($norecip) {
$a->argc = 2;
$a->argv[1] = 'new';
- } else
+ } else {
goaway($_SESSION['return_url']);
-
+ }
}
-function message_content(App $a) {
-
+function message_content(App $a)
+{
$o = '';
nav_set_selected('messages');
- if (! local_user()) {
- notice( t('Permission denied.') . EOL);
+ if (!local_user()) {
+ notice(t('Permission denied.') . EOL);
return;
}
- $myprofile = System::baseUrl().'/profile/' . $a->user['nickname'];
+ $myprofile = System::baseUrl() . '/profile/' . $a->user['nickname'];
$tpl = get_markup_template('mail_head.tpl');
$header = replace_macros($tpl, array(
'$messages' => t('Messages'),
- '$tab_content' => $tab_content
));
-
if (($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) {
- if (! intval($a->argv[2]))
+ if (!intval($a->argv[2])) {
return;
+ }
// Check if we should do HTML-based delete confirmation
if ($_REQUEST['confirm']) {
@@ -118,7 +115,7 @@ function message_content(App $a) {
// so add any arguments as hidden inputs
$query = explode_querystring($a->query_string);
$inputs = array();
- foreach($query['args'] as $arg) {
+ foreach ($query['args'] as $arg) {
if (strpos($arg, 'confirm=') === false) {
$arg_parts = explode('=', $arg);
$inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
@@ -148,7 +145,7 @@ function message_content(App $a) {
intval(local_user())
);
if ($r) {
- info( t('Message deleted.') . EOL );
+ info(t('Message deleted.') . EOL);
}
//goaway(System::baseUrl(true) . '/message' );
goaway($_SESSION['return_url']);
@@ -170,24 +167,22 @@ function message_content(App $a) {
// Actually if we do this, we can never receive another reply to that conversation,
// as we will never again have the info we need to re-create it.
// We'll just have to orphan it.
-
//if ($convid) {
// q("delete from conv where id = %d limit 1",
// intval($convid)
// );
//}
- if ($r)
- info( t('Conversation removed.') . EOL );
+ if ($r) {
+ info(t('Conversation removed.') . EOL);
+ }
}
//goaway(System::baseUrl(true) . '/message' );
goaway($_SESSION['return_url']);
}
-
}
if (($a->argc > 1) && ($a->argv[1] === 'new')) {
-
$o .= $header;
$tpl = get_markup_template('msg-header.tpl');
@@ -204,8 +199,7 @@ function message_content(App $a) {
'$linkurl' => t('Please enter a link URL:')
));
- $preselect = (isset($a->argv[2])?array($a->argv[2]):false);
-
+ $preselect = isset($a->argv[2]) ? array($a->argv[2]) : false;
$prename = $preurl = $preid = '';
@@ -233,18 +227,18 @@ function message_content(App $a) {
$preurl = $r[0]['url'];
$preid = $r[0]['id'];
$preselect = array($preid);
- } else
+ } else {
$preselect = false;
+ }
}
- $prefill = (($preselect) ? $prename : '');
+ $prefill = $preselect ? $prename : '';
// the ugly select box
-
- $select = contact_select('messageto','message-to-select', $preselect, 4, true, false, false, 10);
+ $select = contact_select('messageto', 'message-to-select', $preselect, 4, true, false, false, 10);
$tpl = get_markup_template('prv_message.tpl');
- $o .= replace_macros($tpl,array(
+ $o .= replace_macros($tpl, array(
'$header' => t('Send Private Message'),
'$to' => t('To:'),
'$showinputs' => 'true',
@@ -252,8 +246,8 @@ function message_content(App $a) {
'$autocomp' => $autocomp,
'$preid' => $preid,
'$subject' => t('Subject:'),
- '$subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''),
- '$text' => ((x($_REQUEST,'body')) ? escape_tags(htmlspecialchars($_REQUEST['body'])) : ''),
+ '$subjtxt' => x($_REQUEST, 'subject') ? strip_tags($_REQUEST['subject']) : '',
+ '$text' => x($_REQUEST, 'body') ? escape_tags(htmlspecialchars($_REQUEST['body'])) : '',
'$readonly' => '',
'$yourmessage' => t('Your message:'),
'$select' => $select,
@@ -286,8 +280,8 @@ function message_content(App $a) {
$r = get_messages(local_user(), $a->pager['start'], $a->pager['itemspage']);
- if (! DBM::is_result($r)) {
- info( t('No messages.') . EOL);
+ if (!DBM::is_result($r)) {
+ info(t('No messages.') . EOL);
return $o;
}
@@ -325,8 +319,8 @@ function message_content(App $a) {
intval(local_user())
);
}
- if (! count($messages)) {
- notice( t('Message not available.') . EOL );
+ if (!count($messages)) {
+ notice(t('Message not available.') . EOL);
return $o;
}
@@ -355,24 +349,24 @@ function message_content(App $a) {
$seen = 0;
$unknown = false;
- foreach($messages as $message) {
+ foreach ($messages as $message) {
if ($message['unknown'])
$unknown = true;
if ($message['from-url'] == $myprofile) {
$from_url = $myprofile;
$sparkle = '';
} elseif ($message['contact-id'] != 0) {
- $from_url = 'redir/'.$message['contact-id'];
+ $from_url = 'redir/' . $message['contact-id'];
$sparkle = ' sparkle';
} else {
- $from_url = $message['from-url']."?zrl=".urlencode($myprofile);
+ $from_url = $message['from-url'] . "?zrl=" . urlencode($myprofile);
$sparkle = ' sparkle';
}
-
$extracted = item_extract_images($message['body']);
- if ($extracted['images'])
+ if ($extracted['images']) {
$message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']);
+ }
$from_name_e = $message['from-name'];
$subject_e = $message['title'];
@@ -380,10 +374,11 @@ function message_content(App $a) {
$to_name_e = $message['name'];
$contact = Contact::getDetailsByURL($message['from-url']);
- if (isset($contact["thumb"]))
+ if (isset($contact["thumb"])) {
$from_photo = $contact["thumb"];
- else
+ } else {
$from_photo = $message['from-photo'];
+ }
$mails[] = array(
'id' => $message['id'],
@@ -396,26 +391,22 @@ function message_content(App $a) {
'body' => $body_e,
'delete' => t('Delete message'),
'to_name' => $to_name_e,
- 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'),
- 'ago' => relative_date($message['created']),
+ 'date' => datetime_convert('UTC', date_default_timezone_get(), $message['created'], 'D, d M Y - g:i A'),
+ 'ago' => relative_date($message['created']),
);
$seen = $message['seen'];
}
-
$select = $message['name'] . '';
$parent = '';
$tpl = get_markup_template('mail_display.tpl');
-
- $subjtxt_e = $message['title'];
-
$o = replace_macros($tpl, array(
'$thread_id' => $a->argv[1],
'$thread_subject' => $message['title'],
'$thread_seen' => $seen,
- '$delete' => t('Delete conversation'),
+ '$delete' => t('Delete conversation'),
'$canreply' => (($unknown) ? false : '1'),
'$unknown_text' => t("No secure communications available. You may be able to respond from the sender's profile page."),
'$mails' => $mails,
@@ -425,7 +416,7 @@ function message_content(App $a) {
'$to' => t('To:'),
'$showinputs' => '',
'$subject' => t('Subject:'),
- '$subjtxt' => $subjtxt_e,
+ '$subjtxt' => $message['title'],
'$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ',
'$yourmessage' => t('Your message:'),
'$text' => '',
@@ -435,14 +426,14 @@ function message_content(App $a) {
'$insert' => t('Insert web link'),
'$submit' => t('Submit'),
'$wait' => t('Please wait')
-
));
return $o;
}
}
-function get_messages($user, $lstart, $lend) {
+function get_messages($user, $lstart, $lend)
+{
//TODO: rewritte with a sub-query to get the first message of each private thread with certainty
return q("SELECT max(`mail`.`created`) AS `mailcreated`, min(`mail`.`seen`) AS `mailseen`,
ANY_VALUE(`mail`.`id`) AS `id`, ANY_VALUE(`mail`.`uid`) AS `uid`, ANY_VALUE(`mail`.`guid`) AS `guid`,
@@ -461,33 +452,34 @@ function get_messages($user, $lstart, $lend) {
);
}
-function render_messages(array $msg, $t) {
-
+function render_messages(array $msg, $t)
+{
$a = get_app();
$tpl = get_markup_template($t);
$rslt = '';
- $myprofile = System::baseUrl().'/profile/' . $a->user['nickname'];
+ $myprofile = System::baseUrl() . '/profile/' . $a->user['nickname'];
- foreach($msg as $rr) {
-
- if ($rr['unknown'])
- $participants = sprintf( t("Unknown sender - %s"),$rr['from-name']);
- elseif (link_compare($rr['from-url'], $myprofile))
- $participants = sprintf( t("You and %s"), $rr['name']);
- else
- $participants = sprintf(t("%s and You"), $rr['from-name']);
+ foreach ($msg as $rr) {
+ if ($rr['unknown']) {
+ $participants = t("Unknown sender - %s", $rr['from-name']);
+ } elseif (link_compare($rr['from-url'], $myprofile)) {
+ $participants = t("You and %s", $rr['name']);
+ } else {
+ $participants = t("%s and You", $rr['from-name']);
+ }
$subject_e = (($rr['mailseen']) ? $rr['title'] : '' . $rr['title'] . '');
$body_e = $rr['body'];
$to_name_e = $rr['name'];
$contact = Contact::getDetailsByURL($rr['url']);
- if (isset($contact["thumb"]))
+ if (isset($contact["thumb"])) {
$from_photo = $contact["thumb"];
- else
+ } else {
$from_photo = (($rr['thumb']) ? $rr['thumb'] : $rr['from-photo']);
+ }
$rslt .= replace_macros($tpl, array(
'$id' => $rr['id'],
@@ -500,10 +492,10 @@ function render_messages(array $msg, $t) {
'$delete' => t('Delete conversation'),
'$body' => $body_e,
'$to_name' => $to_name_e,
- '$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['mailcreated'], t('D, d M Y - g:i A')),
- '$ago' => relative_date($rr['mailcreated']),
+ '$date' => datetime_convert('UTC', date_default_timezone_get(), $rr['mailcreated'], t('D, d M Y - g:i A')),
+ '$ago' => relative_date($rr['mailcreated']),
'$seen' => $rr['mailseen'],
- '$count' => sprintf( tt('%d message', '%d messages', $rr['count']), $rr['count']),
+ '$count' => tt('%d message', '%d messages', $rr['count']),
));
}
diff --git a/mod/network.php b/mod/network.php
index 1933c3d1e..65b15cb03 100644
--- a/mod/network.php
+++ b/mod/network.php
@@ -366,7 +366,7 @@ function networkConversation($a, $items, $mode, $update) {
// Set this so that the conversation function can find out contact info for our wall-wall items
$a->page_contact = $a->contact;
- $o .= conversation($a, $items, $mode, $update);
+ $o = conversation($a, $items, $mode, $update);
if (!$update) {
if (PConfig::get(local_user(), 'system', 'infinite_scroll')) {
@@ -568,9 +568,9 @@ function networkThreadedView(App $a, $update = 0) {
if ($group) {
if (($t = Contact::getOStatusCountByGroupId($group)) && !PConfig::get(local_user(), 'system', 'nowarn_insecure')) {
- notice(sprintf(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
+ notice(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
"Warning: This group contains %s members from a network that doesn't allow non public messages.",
- $t), $t).EOL);
+ $t) . EOL);
notice(t("Messages in this group won't be send to these receivers.").EOL);
}
}
@@ -664,7 +664,7 @@ function networkThreadedView(App $a, $update = 0) {
}
$o = replace_macros(get_markup_template("section_title.tpl"),array(
- '$title' => sprintf(t('Group: %s'), $r['name'])
+ '$title' => t('Group: %s', $r['name'])
)) . $o;
} elseif ($cid) {
@@ -716,13 +716,6 @@ function networkThreadedView(App $a, $update = 0) {
$sql_order = "";
$order_mode = "received";
- if (strlen($file)) {
- $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
- dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
- $sql_order = "`item`.`id`";
- $order_mode = "id";
- }
-
if ($conv) {
$sql_extra3 .= " AND $sql_table.`mention`";
}
@@ -744,7 +737,7 @@ function networkThreadedView(App $a, $update = 0) {
$sql_order = "$sql_table.$ordering";
}
- if (($_GET["offset"] != "")) {
+ if (x($_GET, 'offset')) {
$sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
}
@@ -816,9 +809,10 @@ function networkThreadedView(App $a, $update = 0) {
$parents_str = '';
$date_offset = "";
+ $items = array();
if (DBM::is_result($r)) {
foreach ($r as $rr) {
- if (!in_array($rr['item_id'],$parents_arr)) {
+ if (!in_array($rr['item_id'], $parents_arr)) {
$parents_arr[] = $rr['item_id'];
}
}
@@ -833,12 +827,10 @@ function networkThreadedView(App $a, $update = 0) {
$max_comments = 100;
}
- $items = array();
-
foreach ($parents_arr AS $parents) {
- $thread_items = dba::p(item_query()." AND `item`.`uid` = ?
+ $thread_items = dba::p(item_query() . " AND `item`.`uid` = ?
AND `item`.`parent` = ?
- ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
+ ORDER BY `item`.`commented` DESC LIMIT " . intval($max_comments + 1),
local_user(),
$parents
);
@@ -847,15 +839,15 @@ function networkThreadedView(App $a, $update = 0) {
$items = array_merge($items, dba::inArray($thread_items));
}
}
- $items = conv_sort($items,$ordering);
- } else {
- $items = array();
+ $items = conv_sort($items, $ordering);
}
- if ($_GET["offset"] == "") {
+ if (x($_GET, 'offset')) {
+ $date_offset = $_GET["offset"];
+ } elseif(count($items)) {
$date_offset = $items[0][$order_mode];
} else {
- $date_offset = $_GET["offset"];
+ $date_offset = '';
}
$a->page_offset = $date_offset;
diff --git a/mod/nogroup.php b/mod/nogroup.php
index d80b6d3db..9f5425d9e 100644
--- a/mod/nogroup.php
+++ b/mod/nogroup.php
@@ -41,28 +41,25 @@ function nogroup_content(App $a)
$contact_details = Contact::getDetailsByURL($rr['url'], local_user(), $rr);
$contacts[] = array(
- 'img_hover' => sprintf(t('Visit %s\'s profile [%s]'), $contact_details['name'], $rr['url']),
+ 'img_hover' => t('Visit %s\'s profile [%s]', $contact_details['name'], $rr['url']),
'edit_hover' => t('Edit contact'),
'photo_menu' => Contact::photoMenu($rr),
'id' => $rr['id'],
- 'alt_text' => $alt_text,
- 'dir_icon' => $dir_icon,
'thumb' => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
'name' => $contact_details['name'],
'username' => $contact_details['name'],
'details' => $contact_details['location'],
'tags' => $contact_details['keywords'],
'about' => $contact_details['about'],
- 'sparkle' => $sparkle,
'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
'url' => $rr['url'],
- 'network' => network_to_name($rr['network'], $url),
+ 'network' => network_to_name($rr['network'], $rr['url']),
);
}
}
$tpl = get_markup_template("nogroup-template.tpl");
- $o .= replace_macros(
+ $o = replace_macros(
$tpl,
array(
'$header' => t('Contacts who are not members of a group'),
diff --git a/mod/oembed.php b/mod/oembed.php
deleted file mode 100644
index 3266ad963..000000000
--- a/mod/oembed.php
+++ /dev/null
@@ -1,38 +0,0 @@
-query_string, LOGGER_ALL);
-
- if ($a->argv[1]=='b2h'){
- $url = array( "", trim(hex2bin($_REQUEST['url'])));
- echo oembed_replacecb($url);
- killme();
- }
-
- if ($a->argv[1]=='h2b'){
- $text = trim(hex2bin($_REQUEST['text']));
- echo oembed_html2bbcode($text);
- killme();
- }
-
- if ($a->argc == 2){
- echo "";
- $url = base64url_decode($a->argv[1]);
- $j = oembed_fetch_url($url);
-
- // workaround for media.ccc.de (and any other endpoint that return size 0)
- if (substr($j->html, 0, 7) == "
{{/if}}
- {{*{{$author}} wrote the following post{{$reldate}}:*}}
diff --git a/view/theme/frio/style.php b/view/theme/frio/style.php
index 04379b244..a7b8c8a9d 100644
--- a/view/theme/frio/style.php
+++ b/view/theme/frio/style.php
@@ -8,7 +8,7 @@ $schemecss = "";
$schemecssfile = false;
$scheme_modified = 0;
-if (! $a->install) {
+if ($a->module !== 'install') {
// Get the UID of the profile owner.
$uid = get_theme_uid();
if ($uid) {
@@ -57,7 +57,7 @@ if (! $a->install) {
// Setting $schema to '' wasn't working for some reason, so we'll check it's
// not --- like the mobile theme does instead.
// Allow layouts to over-ride the schema.
-if ($_REQUEST['schema']) {
+if (x($_REQUEST, 'schema')) {
$schema = $_REQUEST['schema'];
}
@@ -103,7 +103,7 @@ $contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != "") ? $co
// Calculate some colors in dependance of existing colors.
// Some colors are calculated to don't have too many selection
// fields in the theme settings.
-if (! $menu_background_hover_color) {
+if (!isset($menu_background_hover_color)) {
$mbhc = new Color($nav_bg);
$mcolor = $mbhc->getHex();
@@ -115,7 +115,7 @@ if (! $menu_background_hover_color) {
$menu_background_hover_color = '#' . $mbhc->lighten(5);
}
}
-if (! $nav_icon_hover_color) {
+if (!isset($nav_icon_hover_color)) {
$nihc = new Color($nav_bg);
if ($nihc->isLight()) {
@@ -124,7 +124,7 @@ if (! $nav_icon_hover_color) {
$nav_icon_hover_color = '#' . $nihc->lighten(10);
}
}
-if (! $link_hover_color) {
+if (!isset($link_hover_color)) {
$lhc = new Color($link_color);
$lcolor = $lhc->getHex();
@@ -137,6 +137,9 @@ if (! $link_hover_color) {
}
// Convert $bg_image_options into css.
+if (!isset($bg_image_option)) {
+ $bg_image_option = null;
+}
switch ($bg_image_option) {
case "stretch":
$background_size_img = "100%";
diff --git a/view/theme/frio/templates/searchbox.tpl b/view/theme/frio/templates/searchbox.tpl
index 7d6fbef65..d95d1a411 100644
--- a/view/theme/frio/templates/searchbox.tpl
+++ b/view/theme/frio/templates/searchbox.tpl
@@ -47,8 +47,10 @@ Some parts of this template will be moved by js to other places (see theme.js) -
{{* This form is inserted as experiment to move the search-save button to the second navbar with js *}}
+ {{if $savedsearch}}
+ {{/if}}
diff --git a/view/theme/frio/theme.php b/view/theme/frio/theme.php
index 8b1713026..c529b1f98 100644
--- a/view/theme/frio/theme.php
+++ b/view/theme/frio/theme.php
@@ -1,4 +1,5 @@
ReadMe.
@@ -18,8 +19,8 @@ $frio = "view/theme/frio";
global $frio;
-function frio_init(App $a) {
-
+function frio_init(App $a)
+{
// disable the events module link in the profile tab
$a->theme_events_in_profile = false;
@@ -35,19 +36,21 @@ function frio_init(App $a) {
// if the device is a mobile device set js is_mobile
// variable so the js scripts can use this information
- if($a->is_mobile || $a->is_tablet) {
+ if ($a->is_mobile || $a->is_tablet) {
$a->page["htmlhead"] .= <<< EOT
EOT;
-}
+ }
- if ($style == "")
+ if ($style == "") {
$style = Config::get('frio', 'style');
+ }
}
-function frio_install() {
+function frio_install()
+{
register_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
register_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
register_hook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
@@ -58,7 +61,8 @@ function frio_install() {
logger("installed theme frio");
}
-function frio_uninstall() {
+function frio_uninstall()
+{
unregister_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
unregister_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
unregister_hook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
@@ -68,6 +72,7 @@ function frio_uninstall() {
logger("uninstalled theme frio");
}
+
/**
* @brief Replace friendica photo links hook
*
@@ -86,19 +91,19 @@ function frio_item_photo_links(App $a, &$body_info)
$occurence = 1;
$p = bb_find_open_close($body_info['html'], "");
- while($p !== false && ($occurence++ < 500)) {
+ while ($p !== false && ($occurence++ < 500)) {
$link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
$matches = array();
preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches);
- if($matches) {
+ if ($matches) {
// Replace the link for the photo's page with a direct link to the photo itself
$newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
// Add a "quiet" parameter to any redir links to prevent the "XX welcomes YY" info boxes
$newlink = preg_replace("/href=\"([^\"]+)\/redir\/([^\"]+)&url=([^\"]+)\"/", 'href="$1/redir/$2&quiet=1&url=$3"', $newlink);
- // Having any arguments to the link for Colorbox causes it to fetch base64 code instead of the image
+ // Having any arguments to the link for Colorbox causes it to fetch base64 code instead of the image
$newlink = preg_replace("/\/[?&]zrl=([^&\"]+)/", '', $newlink);
$body_info['html'] = str_replace($link, $newlink, $body_info['html']);
@@ -118,15 +123,14 @@ function frio_item_photo_links(App $a, &$body_info)
* @param App $a Unused but required by the hook definition
* @param array $arr Contains item data and the original photo_menu
*/
-function frio_item_photo_menu(App $a, &$arr) {
-
- foreach($arr["menu"] as $k =>$v) {
- if(strpos($v,'poke/?f=&c=') === 0 || strpos($v,'message/new/') === 0) {
+function frio_item_photo_menu(App $a, &$arr)
+{
+ foreach ($arr["menu"] as $k => $v) {
+ if (strpos($v, 'poke/?f=&c=') === 0 || strpos($v, 'message/new/') === 0) {
$v = "javascript:addToModal('" . $v . "'); return false;";
$arr["menu"][$k] = $v;
}
}
- $args = array('item' => $item, 'menu' => $menu);
}
/**
@@ -141,12 +145,8 @@ function frio_item_photo_menu(App $a, &$arr) {
* @param App $a The app data
* @param array $args Contains contact data and the original photo_menu
*/
-function frio_contact_photo_menu(App $a, &$args){
-
- $pokelink = "";
- $pmlink = "";
- $cid = "";
-
+function frio_contact_photo_menu(App $a, &$args)
+{
$cid = $args["contact"]["id"];
$pokelink = $args["menu"]["poke"][1];
$pmlink = $args["menu"]["pm"][1];
@@ -160,8 +160,8 @@ function frio_contact_photo_menu(App $a, &$args){
// The value for opening in a new tab is e.g. when
// $args["menu"]["status"][2] is true. If the value of the [2] key is true
// and if it's a friendica contact we set it to false
- foreach($args["menu"] as $k =>$v) {
- if($k === "status" || $k === "profile" || $k === "photos") {
+ foreach ($args["menu"] as $k => $v) {
+ if ($k === "status" || $k === "profile" || $k === "photos") {
$v[2] = (($args["contact"]["network"] === "dfrn") ? false : true);
$args["menu"][$k][2] = $v[2];
}
@@ -170,13 +170,13 @@ function frio_contact_photo_menu(App $a, &$args){
// Add to pm and poke links a new key with the value 'modal'.
// Later we can make conditions in the corresponing templates (e.g.
// contact_template.tpl)
- if(strpos($pokelink,'poke/?f=&c='. $cid) !== false)
+ if (strpos($pokelink, 'poke/?f=&c=' . $cid) !== false) {
$args["menu"]["poke"][3] = "modal";
+ }
- if(strpos($pmlink,'message/new/' . $cid) !== false)
+ if (strpos($pmlink, 'message/new/' . $cid) !== false) {
$args["menu"]["pm"][3] = "modal";
-
- $args = array('contact' => $contact, 'menu' => &$menu);
+ }
}
/**
@@ -193,11 +193,13 @@ function frio_contact_photo_menu(App $a, &$args){
* @param App $a The App class
* @param array $nav The original nav menu
*/
-function frio_remote_nav($a,&$nav) {
+function frio_remote_nav($a, &$nav)
+{
// get the homelink from $_XSESSION
$homelink = get_my_url();
- if(! $homelink)
- $homelink = ((x($_SESSION,'visitor_home')) ? $_SESSION['visitor_home'] : '');
+ if (!$homelink) {
+ $homelink = defaults($_SESSION, 'visitor_home', '');
+ }
// split up the url in it's parts (protocol,domain/directory, /profile/, nickname
// I'm not familiar with regex, so someone might find a better solutionen
@@ -213,7 +215,7 @@ function frio_remote_nav($a,&$nav) {
// And construct a webbie (e.g. mickey@friendica.domain.com for the search in gcontact
// We use the webbie for search in gcontact because we don't know if gcontact table stores
// the right value if its http or https protocol
- if(count($url_parts)) {
+ if (count($url_parts)) {
$server_url = $url_parts[1] . $url_parts[2];
$webbie = $url_parts[4] . '@' . $url_parts[2];
}
@@ -228,11 +230,9 @@ function frio_remote_nav($a,&$nav) {
$r[0]['photo'] = (DBM::is_result($r) ? $a->remove_baseurl($r[0]['micro']) : "images/person-48.jpg");
$r[0]['name'] = $a->user['username'];
-
} elseif (!local_user() && remote_user()) {
$r = q("SELECT `name`, `nick`, `micro` AS `photo` FROM `contact` WHERE `id` = %d", intval(remote_user()));
$nav['remote'] = t("Guest");
-
} elseif (get_my_url()) {
$r = q("SELECT `name`, `nick`, `photo` FROM `gcontact`
WHERE `addr` = '%s' AND `network` = 'dfrn'",
@@ -243,18 +243,18 @@ function frio_remote_nav($a,&$nav) {
}
if (DBM::is_result($r)) {
- $nav['userinfo'] = array(
- 'icon' => (DBM::is_result($r) ? $r[0]['photo'] : "images/person-48.jpg"),
- 'name' => $r[0]['name'],
- );
- }
+ $nav['userinfo'] = array(
+ 'icon' => (DBM::is_result($r) ? $r[0]['photo'] : "images/person-48.jpg"),
+ 'name' => $r[0]['name'],
+ );
+ }
if (!local_user() && !empty($server_url)) {
$nav['logout'] = Array($server_url . '/logout', t('Logout'), "", t('End this session'));
// user menu
$nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname'], t('Status'), "", t('Your posts and conversations'));
- $nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
+ $nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname'] . '?tab=profile', t('Profile'), "", t('Your profile page'));
$nav['usermenu'][] = Array($server_url . '/photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
$nav['usermenu'][] = Array($server_url . '/videos/' . $a->user['nickname'], t('Videos'), "", t('Your videos'));
$nav['usermenu'][] = Array($server_url . '/events/', t('Events'), "", t('Your events'));
@@ -263,11 +263,12 @@ function frio_remote_nav($a,&$nav) {
$nav['network'] = array($server_url . '/network', t('Network'), "", t('Conversations from your friends'));
$nav['events'] = Array($server_url . '/events', t('Events'), "", t('Events and Calendar'));
$nav['messages'] = array($server_url . '/message', t('Messages'), "", t('Private mail'));
- $nav['settings'] = array($server_url . '/settings', t('Settings'),"", t('Account settings'));
- $nav['contacts'] = array($server_url . '/contacts', t('Contacts'),"", t('Manage/edit friends and contacts'));
+ $nav['settings'] = array($server_url . '/settings', t('Settings'), "", t('Account settings'));
+ $nav['contacts'] = array($server_url . '/contacts', t('Contacts'), "", t('Manage/edit friends and contacts'));
$nav['sitename'] = $a->config['sitename'];
}
}
+
/**
* @brief: Search for contacts
*
@@ -281,10 +282,11 @@ function frio_remote_nav($a,&$nav) {
* @param App $a The app data @TODO Unused
* @param array $results The array with the originals from acl_lookup()
*/
-function frio_acl_lookup(App $a, &$results) {
- require_once("mod/contacts.php");
+function frio_acl_lookup(App $a, &$results)
+{
+ require_once 'mod/contacts.php';
- $nets = ((x($_GET,"nets")) ? notags(trim($_GET["nets"])) : "");
+ $nets = x($_GET, "nets") ? notags(trim($_GET["nets"])) : "";
// we introduce a new search type, r should do the same query like it's
// done in /mod/contacts for connections
@@ -295,17 +297,17 @@ function frio_acl_lookup(App $a, &$results) {
$search_txt = dbesc(protect_sprintf(preg_quote($search)));
$searching = true;
}
- $sql_extra .= (($searching) ? " AND (`attag` LIKE '%%".dbesc($search_txt)."%%' OR `name` LIKE '%%".dbesc($search_txt)."%%' OR `nick` LIKE '%%".dbesc($search_txt)."%%') " : "");
+ $sql_extra = '';
+ if ($searching) {
+ $sql_extra .= " AND (`attag` LIKE '%%" . dbesc($search_txt) . "%%' OR `name` LIKE '%%" . dbesc($search_txt) . "%%' OR `nick` LIKE '%%" . dbesc($search_txt) . "%%') ";
+ }
if ($nets) {
$sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
}
- $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
-
-
$r = q("SELECT COUNT(*) AS `total` FROM `contact`
- WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra $sql_extra2 ",
+ WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra ",
intval($_SESSION['uid']));
if (DBM::is_result($r)) {
$total = $r[0]["total"];
@@ -313,7 +315,7 @@ function frio_acl_lookup(App $a, &$results) {
$sql_extra3 = unavailable_networks();
- $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra $sql_extra2 $sql_extra3 ORDER BY `name` ASC LIMIT 100 ",
+ $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra $sql_extra3 ORDER BY `name` ASC LIMIT 100 ",
intval($_SESSION['uid'])
);
@@ -332,19 +334,19 @@ function frio_acl_lookup(App $a, &$results) {
/**
* @brief Manipulate the data of the item
- *
+ *
* At the moment we use this function to add some own stuff to the item menu
- *
+ *
* @param App $a App $a The app data
* @param array $arr Array with the item and the item actions