aboutsummaryrefslogtreecommitdiffstats
path: root/addon/pages/pages.php
diff options
context:
space:
mode:
authorMichael Vogel <icarus@dabo.de>2012-03-11 17:45:12 +0100
committerMichael Vogel <icarus@dabo.de>2012-03-11 17:45:12 +0100
commitb879a1ddf1575a3bd355edcee634be4a8d179c25 (patch)
treef3079c07ef0ffd7551662d68bdaf485d1209ce95 /addon/pages/pages.php
parenteb3b211461906c405c7d016401cb3cd6d7d03b83 (diff)
downloadvolse-hubzilla-b879a1ddf1575a3bd355edcee634be4a8d179c25.tar.gz
volse-hubzilla-b879a1ddf1575a3bd355edcee634be4a8d179c25.tar.bz2
volse-hubzilla-b879a1ddf1575a3bd355edcee634be4a8d179c25.zip
Pages: Show every community page - even from foreign servers (with caching)
Diffstat (limited to 'addon/pages/pages.php')
-rwxr-xr-xaddon/pages/pages.php70
1 files changed, 58 insertions, 12 deletions
diff --git a/addon/pages/pages.php b/addon/pages/pages.php
index 13e6c4b59..6b242be31 100755
--- a/addon/pages/pages.php
+++ b/addon/pages/pages.php
@@ -15,25 +15,71 @@ function pages_uninstall() {
unregister_hook('page_end', 'addon/pages/pages.php', 'pages_page_end');
}
+function pages_iscommunity($url, &$pagelist) {
+ // check every week for the status - should be enough
+ if ($pagelist[$url]["checked"]<time()-86400*7) {
+ // When too old or not found fetch the status from the profile
+ $ch = curl_init();
+
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 2);
+
+ $page = curl_exec($ch);
+
+ curl_close($ch);
+
+ $iscommunity = (strpos($page, '<meta name="friendika.community" content="true" />') != 0);
+
+ $pagelist[$url] = array("community" => $iscommunity, "checked" => time());
+ } else // Fetch from cache
+ $iscommunity = $pagelist[$url]["community"];
+ return($iscommunity);
+}
+
+function pages_getpages($uid) {
+
+ // Fetch cached pagelist from configuration
+ $pagelist = get_pconfig($uid,'pages','pagelist');
+
+ if (sizeof($pagelist) == 0)
+ $pagelist = array();
+
+ $contacts = q("SELECT `id`, `url`, `Name` FROM `contact`
+ WHERE `network`= 'dfrn' AND `uid` = %d",
+ intval($uid));
+
+ $pages = array();
+
+ // Look if the profile is a community page
+ foreach($contacts as $contact) {
+ if (pages_iscommunity($contact["url"], $pagelist))
+ $pages[] = array("url"=>$contact["url"], "Name"=>$contact["Name"]);
+ }
+
+ // Write back cached pagelist
+ set_pconfig($uid,'pages','pagelist', $pagelist);
+ return($pages);
+}
+
function pages_page_end($a,&$b) {
+ // Only move on if if it's the "network" module and there is a logged on user
if (($a->module != "network") OR ($a->user['uid'] == 0))
return;
- $pages = '<div id="pages-sidebar" class="widget"><h3>'.t("Community").'</h3><ul>';
- $contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`Name` FROM `contact`, `user`
- WHERE `network`= 'dfrn' AND `duplex`
- AND `contact`.`nick`=`user`.`nickname`
- AND `user`.`page-flags`= %d
- AND `contact`.`uid` = %d",
- intval(PAGE_COMMUNITY),
- intval($a->user['uid']));
+ $pages = '<div id="pages-sidebar" class="widget">
+ <div class="title tool">
+ <h3>'.t("Community").'</h3></div>
+ <div id="sidebar-pages-list"><ul>';
+
+ $contacts = pages_getpages($a->user['uid']);
+
foreach($contacts as $contact) {
- $pages .= '<li class="tool"><a href="'.$contact["url"].'">'.$contact["Name"]."</a></li>";
+ $pages .= '<li class="tool"><a href="'.$contact["url"].'" class="label" target="external-link">'.$contact["Name"]."</a></li>";
}
- $pages .= "</ul>";
+ $pages .= "</ul></div></div>";
if (sizeof($contacts) > 0)
$a->page['aside'] = $pages.$a->page['aside'];
-
}
-
?>