]> git.mxchange.org Git - friendica.git/commitdiff
feed related
authorMike Macgirvin <mike@macgirvin.com>
Thu, 15 Jul 2010 06:04:10 +0000 (23:04 -0700)
committerMike Macgirvin <mike@macgirvin.com>
Thu, 15 Jul 2010 06:04:10 +0000 (23:04 -0700)
boot.php
include/group.php
include/notifier.php
mod/dfrn_notify.php
mod/item.php
simplepie/simplepie.inc
update.sql

index 0633a828f6760d9f1c5084ef5384ea4d5cf24f5c..c94548c3f3bcdf16a815e54990d9844ec86c3588 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -424,4 +424,16 @@ function paginate(&$a) {
                $o .= '</div>'."\r\n";
        }
        return $o;
-}
\ No newline at end of file
+}
+
+function expand_acl($s) {
+
+       if(strlen($s)) {
+               $a = explode('<',$s);
+               for($x = 0; $x < count($a); $x ++) {
+                       $a[$x] = intval(str_replace(array('<','>'),array('',''),$a[$x]));
+               }
+               return $a;
+       }
+       return array();
+}              
index 1f48cdd56be83c20dba457d10012c96c8f24c1aa..f2e3d18203b570266cc70edaaba32f7350d65942 100644 (file)
@@ -150,4 +150,17 @@ EOT;
        $o .= " </ul>\r\n       </div>\r\n</div>";      
 
        return $o;
-}
\ No newline at end of file
+}
+
+function expand_groups($a) {
+       if(! (is_array($a) && count($a)))
+               return array();
+       $groups = implode(',', $a);
+       $groups = dbesc($groups);
+       $r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )");
+       $ret = array();
+       if(count($r))
+               foreach($r as $rr)
+                       $ret[] = $rr['contact-id'];
+       return $ret;
+}
index f1231839b83854df3116cb49634299472fa0d0ea..a28f6364bdc8930626664ce33f2cfb951b86637d 100644 (file)
@@ -32,79 +32,161 @@ if($argc < 3)
        }
 
 
-       $is_parent = false;
-
        $recipients = array();
 
-       // fetch requested item(s)
+       // find ancestors
 
-       $r = q("SELECT `item`.*,  `contact`.*,`item`.`id` AS `item_id` FROM `item` LEFT JOIN `contact` ON `item`.`contact-id` = `contact`.`id` 
-               WHERE `item`.`id` = %d LIMIT 1",
+       $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
                intval($item_id)
        );
        if(! count($r))
                killme();
 
-       $item = $r[0];
+       $parent = $r[0]['parent'];
+       $uid = $r[0]['uid'];
+       $updated = $r[0]['edited'];
+
+       $items = q("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id` ASC",
+               intval($parent)
+       );
+
+       if(! count($items))
+               killme();
+
+       $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
+               intval($uid)
+       );
+
+       if(count($r))
+               $owner = $r[0];
+       else
+               killme();
+
 
-       $recipients[] = $item['contact-id'];
+       require_once('include/group.php');
 
-       if($item['parent'] == $item['id']) {
-               $is_parent = true;
+       $parent = $items[0];
+
+       if(strlen($parent['remote-id'])) {
+               $followup = true;
+               $conversant_str = dbesc($parent['contact-id']);
        }
        else {
-               $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
-                       intval($item['parent'])
-               );
-               if(count($r))
-                       $parent = $r[0];
-       }
+               $followup = false;
 
-       if(is_array($parent))
-               $recipients[] = $parent['contact-id'];
+               $allow_people = expand_acl($parent['allow_cid']);
+               $allow_groups = expand_groups(expand_acl($parent['allow_gid']));
+               $deny_people = expand_acl($parent['deny_cid']);
+               $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
 
-       $r = q("SELECT `contact-id` FROM `item` WHERE `hash` = '%s' AND `id` != %d AND `id` != %d",
-               dbesc($item['hash']),
-               intval($item['id']),
-               intval($item['parent'])
-       );
-       if(count($r)) {
-               foreach($r as $rr) {
-                       if($rr['contact-id'] != $item['contact-id'])
-                               $recipients[] = $rr['contact-id'];
+               $conversants = array();
+
+               foreach($items as $item) {
+                       $recipients[] = $item['contact-id'];
+                       $conversants[] = $item['contact-id'];
                }
+
+               $conversants = array_unique($conversants,SORT_NUMERIC);
+
+
+               $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups),SORT_NUMERIC);
+               $deny = array_unique(array_merge($deny_people,$deny_groups),SORT_NUMERIC);
+               $recipients = array_diff($recipients,$deny);
+       
+               $conversant_str = dbesc(implode(', ',$conversants));
        }
 
-       $tpl = file_get_contents('view/atomic.tpl');
-
-       // FIXME should dump the entire conversation
-
-       $atom = replace_macros($tpl, array(
-               '$feed_id' => xmlify($baseurl),
-               '$feed_title' => xmlify('Wall Item'),
-               '$feed_updated' => xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00' ,'Y-m-d\Th:i:s\Z')) ,
-               '$name' => xmlify($item['name']),
-               '$profile_page' => xmlify($item['url']),
-               '$thumb' => xmlify($item['thumb']),
-               '$item_id' => xmlify($item['hash'] . '-' . $item['id']),
-               '$title' => xmlify(''),
-               '$link' => xmlify($baseurl . '/item/' . $item['id']),
-               '$updated' => xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00' ,'Y-m-d\Th:i:s\Z')),
-               '$summary' => xmlify(''),
-               '$content' => xmlify($item['body'])
+       $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) ");
+
+       if( ! count($r))
+               killme();
+
+       $contacts = $r;
+
+
+       $feed_template = file_get_contents('view/atom_feed.tpl');
+       $tomb_template = file_get_contents('view/atom_tomb.tpl');
+       $item_template = file_get_contents('view/atom_item.tpl');
+       $cmnt_template = file_get_contents('view/atom_cmnt.tpl');
+
+       $atom = '';
+
+
+       $atom .= replace_macros($feed_template, array(
+                       '$feed_id' => xmlify($baseurl),
+                       '$feed_title' => xmlify($owner['name']),
+                       '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , 'Y-m-d\Th:i:s\Z')) ,
+                       '$name' => xmlify($owner['name']),
+                       '$profile_page' => xmlify($owner['url']),
+                       '$thumb' => xmlify($owner['thumb'])
        ));
 
+       if($followup) {
+               $atom .= replace_macros($cmnt_template, array(
+                       '$name' => xmlify($contact['name']),
+                       '$profile_page' => xmlify($contact['url']),
+                       '$thumb' => xmlify($contact['thumb']),
+                       '$item_id' => xmlify("urn:X-dfrn:{$item['hash']}"),
+                       '$title' => xmlify($item['title']),
+                       '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\Th:i:s\Z')),
+                       '$content' =>xmlify($item['body']),
+                       '$parent_id' => xmlify("{$items[0]['remote-id']}")
+               ));
+       }
+       else {
+               foreach($items as $item) {
+                       if($item['deleted']) {
+                               $atom .= replace_macros($tomb_template, array(
+                                       '$id' => xmlify("urn:X-dfrn:{$item['hash']}"),
+                                       '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\Th:i:s\Z'))
+                               ));
+                       }
+                       else {
+                               foreach($contacts as $contact) {
+                                       if($item['contact-id'] == $contact['id']) {
+                                               if($item['parent'] == $item['id']) {
+                                                       $atom .= replace_macros($item_template, array(
+                                                               '$name' => xmlify($contact['name']),
+                                                               '$profile_page' => xmlify($contact['url']),
+                                                               '$thumb' => xmlify($contact['thumb']),
+                                                               '$item_id' => xmlify("urn:X-dfrn:{$item['hash']}"),
+                                                               '$title' => xmlify($item['title']),
+                                                               '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\Th:i:s\Z')),
+                                                               '$content' =>xmlify($item['body'])
+                                                       ));
+                                               }
+                                               else {
+                                                       $atom .= replace_macros($cmnt_template, array(
+                                                               '$name' => xmlify($contact['name']),
+                                                               '$profile_page' => xmlify($contact['url']),
+                                                               '$thumb' => xmlify($contact['thumb']),
+                                                               '$item_id' => xmlify("urn:X-dfrn:{$item['hash']}"),
+                                                               '$title' => xmlify($item['title']),
+                                                               '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\Th:i:s\Z')),
+                                                               '$content' =>xmlify($item['body']),
+                                                               '$parent_id' => xmlify("urn:X-dfrn:{$items[0]['hash']}")
+                                                       ));
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+       $atom .= "</feed>";
+
 print_r($atom);
-       // atomify
 
-       // expand list of recipients
 
 dbg(3);
 
 
-       $recipients = array_unique($recipients);
+
 print_r($recipients);
-       $recip_str = implode(', ', $recipients);
+
+       if($followup)
+               $recip_str = $parent['contact-id'];
+       else
+               $recip_str = implode(', ', $recipients);
 
        $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
                dbesc($recip_str)
@@ -149,9 +231,9 @@ echo "pubkey:" . $rr['pubkey'] . "\r\n";
                $postvars['data'] = $atom;
 
 print_r($postvars);
-               $xml = fetch_url($url,$postvars);
+               $xml = post_url($url,$postvars);
 
-                               
+print_r($xml);                         
        }
 
        killme();
index 2d9d06fd1c4c99b400bde409d8c0cf0fdff63a4d..301beaf2f9932fc0f7086f16d2dfb2fd455f14c3 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-
+require_once('simplepie/simplepie.inc');
 
 
 
@@ -22,11 +22,21 @@ function dfrn_notify_post(&$a) {
                dbesc($challenge)
        );
 
+       $feed = new SimplePie();
+       $feed->set_raw_data($data);
+       $feed->init();
 
+       echo "Feed title:" . $feed->get_title();
 
+       foreach ($feed->get_items() as $item) {
 
+                       echo $item->get_permalink();
+                       echo $item->get_content();
+       
+       }
 
 
+       killme();
 
 }
 
index 83854ed159db25b95df4b56df4a97a7c38fcb185..c7b5b4885823da37ae43e5ea95d9c0366a41824c 100644 (file)
@@ -5,7 +5,7 @@ function sanitise_acl(&$item) {
 }
 
 function item_post(&$a) {
-dbg(2);
+
        if((! local_user()) && (! remote_user()))
                return;
 
@@ -149,7 +149,7 @@ dbg(2);
                        array(),$foo));
 
        }
-//     goaway($a->get_baseurl() . "/profile/$profile_uid");
+       goaway($a->get_baseurl() . "/profile/$profile_uid");
 
 
 
index 9e4fa301bb8998b150c43dab6dd6f9394d5ae434..1f40ac5934000b14a909e6c58195e384f833fbc4 100644 (file)
@@ -2431,6 +2431,7 @@ class SimplePie
                        $name = null;
                        $uri = null;
                        $email = null;
+                       $avatar = null;
                        if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
                        {
                                $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
@@ -2443,9 +2444,13 @@ class SimplePie
                        {
                                $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
                        }
-                       if ($name !== null || $email !== null || $uri !== null)
+                       if (isset($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data']))
+                       {
+                               $avatar = $this->sanitize($$author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]));
+                       }
+                       if ($name !== null || $email !== null || $uri !== null || $avatar !== null)
                        {
-                               $authors[] =& new $this->author_class($name, $uri, $email);
+                               $authors[] =& new $this->author_class($name, $uri, $email, $avatar);
                        }
                }
                if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
@@ -3475,6 +3480,7 @@ class SimplePie_Item
                        $name = null;
                        $uri = null;
                        $email = null;
+                       $avatar = null;
                        if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
                        {
                                $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
@@ -3487,9 +3493,14 @@ class SimplePie_Item
                        {
                                $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
                        }
-                       if ($name !== null || $email !== null || $uri !== null)
+                       if (isset($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data']))
                        {
-                               $authors[] =& new $this->feed->author_class($name, $uri, $email);
+                               $avatar = $this->sanitize($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]));
+                       }
+                       if ($name !== null || $email !== null || $uri !== null || $avatar !== null)
+                       {
+                               $authors[] =& new $this->feed->author_class($name, $uri, $email, $avatar);
+
                        }
                }
                if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
@@ -5897,6 +5908,7 @@ class SimplePie_Source
                        $name = null;
                        $uri = null;
                        $email = null;
+                       $avatar = null;
                        if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
                        {
                                $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
@@ -5909,9 +5921,13 @@ class SimplePie_Source
                        {
                                $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
                        }
-                       if ($name !== null || $email !== null || $uri !== null)
                        {
-                               $authors[] =& new $this->item->feed->author_class($name, $uri, $email);
+                               $avatar = $this->sanitize($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child']['http://purl.org/macgirvin/dfrn/1.0']['avatar'][0]));
+                       }
+                       if ($name !== null || $email !== null || $uri !== null || $avatar !== null)
+                       {
+                               $authors[] =& new $this->item->feed->author_class($name, $uri, $email, $avatar);
+
                        }
                }
                if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
@@ -6283,13 +6299,15 @@ class SimplePie_Author
        var $name;
        var $link;
        var $email;
+       var $avatar;
 
        // Constructor, used to input the data
-       function SimplePie_Author($name = null, $link = null, $email = null)
+       function SimplePie_Author($name = null, $link = null, $email = null, $avatar = null)
        {
                $this->name = $name;
                $this->link = $link;
                $this->email = $email;
+               $this->avatar = $avatar;
        }
 
        function __toString()
@@ -6333,6 +6351,20 @@ class SimplePie_Author
                        return null;
                }
        }
+
+       function get_avatar()
+       {
+               if ($this->avatar !== null)
+               {
+                       return $this->avatar;
+               }
+               else
+               {
+                       return null;
+               }
+       }
+
+
 }
 
 class SimplePie_Category
index 63a46bce6eaa86d6b2cb965ce9a9fb27501b86f9..65fc69f7898ea91f746c43857465b20afa34fb5b 100644 (file)
@@ -2,3 +2,6 @@
 CHANGE `deny_uid` `deny_cid` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ;
 
  ALTER TABLE `item` CHANGE `last-child` `last-child` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1';
+
+alter table `item` insert `remote-id` char( 255 ) character set utf-8 collate utf8_general_ci NOT NULL;
\ No newline at end of file