4 * Description: Shows lists of community pages
6 * Author: Michael Vogel <ike@piratenpartei.de>
10 function pages_install() {
11 register_hook('page_end', 'addon/pages/pages.php', 'pages_page_end');
14 function pages_uninstall() {
15 unregister_hook('page_end', 'addon/pages/pages.php', 'pages_page_end');
18 function pages_iscommunity($url, &$pagelist) {
19 // check every week for the status - should be enough
20 if ($pagelist[$url]["checked"]<time()-86400*7) {
21 // When too old or not found fetch the status from the profile
24 curl_setopt($ch, CURLOPT_URL, $url);
25 curl_setopt($ch, CURLOPT_HEADER, 0);
26 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
27 curl_setopt($ch, CURLOPT_TIMEOUT, 2);
29 $page = curl_exec($ch);
33 $iscommunity = (strpos($page, '<meta name="friendika.community" content="true" />') != 0);
35 $pagelist[$url] = array("community" => $iscommunity, "checked" => time());
36 } else // Fetch from cache
37 $iscommunity = $pagelist[$url]["community"];
41 function pages_getpages($uid) {
43 // Fetch cached pagelist from configuration
44 $pagelist = get_pconfig($uid,'pages','pagelist');
46 if (sizeof($pagelist) == 0)
49 $contacts = q("SELECT `id`, `url`, `Name` FROM `contact`
50 WHERE `network`= 'dfrn' AND `uid` = %d",
55 // Look if the profile is a community page
56 foreach($contacts as $contact) {
57 if (pages_iscommunity($contact["url"], $pagelist))
58 $pages[] = array("url"=>$contact["url"], "Name"=>$contact["Name"], "id"=>$contact["id"]);
61 // Write back cached pagelist
62 set_pconfig($uid,'pages','pagelist', $pagelist);
66 function pages_page_end($a,&$b) {
67 // Only move on if if it's the "network" module and there is a logged on user
68 if (($a->module != "network") OR ($a->user['uid'] == 0))
71 $pages = '<div id="pages-sidebar" class="widget">
72 <div class="title tool">
73 <h3>'.t("Community").'</h3></div>
74 <div id="sidebar-pages-list"><ul>';
76 $contacts = pages_getpages($a->user['uid']);
78 foreach($contacts as $contact) {
79 $pages .= '<li class="tool"><a href="'.$a->get_baseurl().'/redir/'.$contact["id"].'" class="label" target="external-link">'.
80 $contact["Name"]."</a></li>";
82 $pages .= "</ul></div></div>";
83 if (sizeof($contacts) > 0)
84 $a->page['aside'] = $pages.$a->page['aside'];