]> git.mxchange.org Git - friendica-addons.git/commitdiff
Merge commit 'upstream/master'
authorMichael Vogel <icarus@dabo.de>
Sun, 11 Mar 2012 18:27:18 +0000 (19:27 +0100)
committerMichael Vogel <icarus@dabo.de>
Sun, 11 Mar 2012 18:27:18 +0000 (19:27 +0100)
facebook/facebook.php
pages/README [new file with mode: 0755]
pages/pages.php [new file with mode: 0755]
pages/test.php [new file with mode: 0644]

index 35338fa16d7bbff606b3217d1c99f9f0cc0af159..b2f21b93ed291abb84d56dcb696b72fe9df76f76 100755 (executable)
@@ -1176,12 +1176,17 @@ function fb_consume_stream($uid,$j,$wall = false) {
                                $datarray['private'] = 1;
                                $datarray['allow_cid'] = '<' . $uid . '>';
                        }
-                       
+
+                       if(trim($datarray['body']) == '') {
+                               logger('facebook: empty body');
+                               continue;
+                       }
+
                        $top_item = item_store($datarray);
                        $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                                intval($top_item),
                                intval($uid)
-                       );                      
+                       );
                        if(count($r)) {
                                $orig_post = $r[0];
                                logger('fb: new top level item posted');
diff --git a/pages/README b/pages/README
new file mode 100755 (executable)
index 0000000..6ec314b
--- /dev/null
@@ -0,0 +1,3 @@
+Pages
+
+Shows lists of community pages
diff --git a/pages/pages.php b/pages/pages.php
new file mode 100755 (executable)
index 0000000..9e90cc2
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+/**
+ * Name: Pages
+ * Description: Shows lists of community pages
+ * Version: 1.0
+ * Author: Michael Vogel <ike@piratenpartei.de>
+ *
+ */
+
+function pages_install() {
+       register_hook('page_end', 'addon/pages/pages.php', 'pages_page_end');
+}
+
+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"], "id"=>$contact["id"]);
+       }
+
+       // 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">
+                       <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="'.$a->get_baseurl().'/redir/'.$contact["id"].'" class="label" target="external-link">'.
+                               $contact["Name"]."</a></li>";
+       }
+       $pages .= "</ul></div></div>";
+       if (sizeof($contacts) > 0)
+               $a->page['aside'] = $pages.$a->page['aside'];
+}
+?>
diff --git a/pages/test.php b/pages/test.php
new file mode 100644 (file)
index 0000000..4490c4a
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+$test[] = array("test"=>"Blubb");
+$test[] = array("test"=>"Blubb");
+
+print_r($test);
+$serial = serialize($test);
+
+print_r(unserialize($serial));
+die();
+
+$url = "https://pirati.ca/profile/test1";
+
+$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);
+
+if (strpos($page, '<meta name="friendika.community" content="true" />'))
+       echo "Ping";
+
+?>