]> git.mxchange.org Git - friendica.git/commitdiff
diaspora photos ?
authorFriendika <info@friendika.com>
Wed, 24 Aug 2011 01:17:35 +0000 (18:17 -0700)
committerFriendika <info@friendika.com>
Wed, 24 Aug 2011 01:17:35 +0000 (18:17 -0700)
boot.php
database.sql
include/Photo.php
include/diaspora.php
include/group.php
include/poller.php
mod/receive.php
update.php
view/api_timeline_atom.tpl
view/diaspora_photo.tpl [new file with mode: 0644]

index b0ff7830c6fd5fe302fde4c5cac2c9a7b32f93c7..16b8f9c850154aebcdab717e8e3c5c924bb2aa0e 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -7,9 +7,9 @@ require_once('include/text.php');
 require_once("include/pgettext.php");
 
 
-define ( 'FRIENDIKA_VERSION',      '2.2.1080' );
+define ( 'FRIENDIKA_VERSION',      '2.2.1081' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.21'    );
-define ( 'DB_UPDATE_VERSION',      1081      );
+define ( 'DB_UPDATE_VERSION',      1082      );
 
 define ( 'EOL',                    "<br />\r\n"     );
 define ( 'ATOM_TIME',              'Y-m-d\TH:i:s\Z' );
index 605433e6e2044b75491484ff80be8f2f05408099..f659e80498d706da724e046381cab6bb5acfd43c 100644 (file)
@@ -267,6 +267,7 @@ CREATE TABLE IF NOT EXISTS `photo` (
   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
   `uid` int(10) unsigned NOT NULL,
   `contact-id` int(10) unsigned NOT NULL,
+  `guid` char(64) NOT NULL, 
   `resource-id` char(255) NOT NULL,
   `created` datetime NOT NULL,
   `edited` datetime NOT NULL,
@@ -288,7 +289,8 @@ CREATE TABLE IF NOT EXISTS `photo` (
   KEY `resource-id` (`resource-id`),
   KEY `album` (`album`),
   KEY `scale` (`scale`),
-  KEY `profile` (`profile`)
+  KEY `profile` (`profile`),
+  KEY `guid` (`guid`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
index de4c3d9e0439c11aa30dbbc3ad32b5f6e15c7d6f..1450374ffc27971fd91b20d325c5593d3ac33413 100644 (file)
@@ -185,11 +185,20 @@ class Photo {
 
        public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') {
 
+               $r = q("select `guid` from photo where `resource-id` = '%s' and `guid` != '' limit 1",
+                       dbesc($rid)
+               );
+               if(count($r))
+                       $guid = $r[0]['guid'];
+               else
+                       $guid = get_guid();
+
                $r = q("INSERT INTO `photo`
-                       ( `uid`, `contact-id`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
-                       VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s' )",
+                       ( `uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
+                       VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s' )",
                        intval($uid),
                        intval($cid),
+                       dbesc($guid),
                        dbesc($rid),
                        dbesc(datetime_convert()),
                        dbesc(datetime_convert()),
index 345ea5562a532b5a67028dd777727ebe99eae50c..a1edd08a684d5043f3704467afa2629200eaf3d6 100644 (file)
@@ -597,6 +597,57 @@ function diaspora_comment($importer,$xml,$msg) {
 
 }
 
+function diaspora_photo($importer,$xml,$msg) {
+
+       $remote_photo_path = notags(unxmlify($xml->remote_photo_path));
+
+       $remote_photo_name = notags(unxmlify($xml->remote_photo_name));
+
+       $status_message_guid = notags(unxmlify($xml->status_message_guid));
+
+       $guid = notags(unxmlify($xml->guid));
+
+       $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
+
+       $public = notags(unxmlify($xml->public));
+
+       $created_at = notags(unxmlify($xml_created_at));
+
+
+       $contact = diaspora_get_contact_by_handle($importer['uid'],$msg['author']);
+       if(! $contact)
+               return;
+
+       if(($contact['rel'] == CONTACT_IS_FOLLOWER) || ($contact['blocked']) || ($contact['readonly'])) { 
+               logger('diaspora_photo: Ignoring this author.');
+               http_status_exit(202);
+               // NOTREACHED
+       }
+
+       $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
+               intval($importer['uid']),
+               dbesc($status_message_guid)
+       );
+       if(! count($r)) {
+               logger('diaspora_photo: parent item not found: parent: ' . $parent_guid . ' item: ' . $guid);
+               return;
+       }
+       $parent_item = $r[0];
+
+       $link_text = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n";
+
+       $r = q("update item set `body` = '%s' where `id` = %d and `uid` = %d limit 1",
+               dbesc($link_text . $parent_item['body']),
+               intval($parent_item['id']),
+               intval($parent_item['uid'])
+       );
+
+       return;
+}
+
+
+
+
 function diaspora_like($importer,$xml,$msg) {
 
        $a = get_app();
@@ -847,7 +898,25 @@ function diaspora_send_status($item,$owner,$contact) {
        $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
        $theiraddr = $contact['addr'];
 
-       $body = xmlify(bb2diaspora($item['body']));
+       $images = array();
+
+       $body = $item['body'];
+
+       $cnt = preg_match_all('|\[img\](.*?)\[\/img\]|',$body,$matches,PREG_SET_ORDER);
+       if($cnt) {
+               foreach($matches as $mtch) {
+                       $detail = array();
+                       $detail['str'] = $mtch[0];
+                       $detail['path'] = dirname($mtch[1]);
+                       $detail['file'] = basename($mtch[1]);
+                       $detail['guid'] = $item['guid'];
+                       $detail['handle'] = $myaddr;
+                       $images[] = $detail;
+                       $body = str_replace($detail['str'],'',$body);
+               }
+       }       
+
+       $body = xmlify(bb2diaspora($body));
        $public = (($item['private']) ? 'false' : 'true');
 
        require_once('include/datetime.php');
@@ -869,10 +938,55 @@ function diaspora_send_status($item,$owner,$contact) {
        post_url($contact['notify'] . '/',$slap);
        $return_code = $a->get_curl_code();
        logger('diaspora_send_status: returns: ' . $return_code);
+
+       if(count($images)) {
+               diaspora_send_images($item,$owner,$contact,$images);
+       }
+
        return $return_code;
 }
 
 
+function diaspora_send_images($item,$owner,$contact,$images) {
+       $a = get_app();
+       if(! count($images))
+               return;
+       $mysite = substr($a->get_baseurl(),strpos($a->get_baseurl(),'://') + 3) . '/photo';
+
+       $tpl = get_markup_template('diaspora_photo.tpl');
+       foreach($images as $image) {
+               if(! stristr($image['path'],$mysite))
+                       continue;
+               $resource = str_replace('.jpg','',$image['file']);
+               $resource = substr($resource,0,strpos($resource,'-'));
+
+               $r = q("select * from photo where `resource-id` = '%s' and `uid` = %d limit 1",
+                       dbesc($resource),
+                       intval($owner['uid'])
+               );
+               if(! count($r))
+                       continue;
+               $public = (($r[0]['allow_cid'] || $r[0]['allow_gid'] || $r[0]['deny_cid'] || $r[0]['deny_gid']) ? 'false' : 'true' );
+               $msg = replace_macros($tpl,array(               
+                       '$path' => xmlify($image['path']),
+                       '$filename' => xmlify($image['file']),
+                       '$msg_guid' => xmlify($image['guid']),
+                       '$guid' => xmlify($r[0]['guid']),
+                       '$handle' => xmlify($image['handle']),
+                       '$public' => xmlify($public),
+                       '$created_at' => xmlify('UTC','UTC',$r[0]['created'],'Y-m-d h:i:s \U\T\C')
+               ));
+
+               logger('diaspora_send_photo: base message: ' . $msg, LOGGER_DATA);
+               $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'])));
+
+               post_url($contact['notify'] . '/',$slap);
+               $return_code = $a->get_curl_code();
+               logger('diaspora_send_photo: returns: ' . $return_code);
+       }
+
+}
+
 function diaspora_send_followup($item,$owner,$contact) {
 
        $a = get_app();
index 1ebae7b7b07f8a02e2e674f2cc133def7d94bb3a..5e3a1511a8c94456c2cd66d6e7aa3920361c2dbd 100644 (file)
@@ -124,9 +124,10 @@ function group_public_members($gid) {
                $r = q("SELECT `contact`.`id` AS `contact-id` FROM `group_member` 
                        LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` 
                        WHERE `gid` = %d AND `group_member`.`uid` = %d 
-                       AND `contact`.`network` != 'dfrn' AND `contact`.`network` != 'mail' AND `contact`.`network` != 'face' ",
+                       AND `contact`.`network` = '%' AND `contact`.`notify` != '' ",
                        intval($gid),
-                       intval(local_user())
+                       intval(local_user()),
+                       dbesc(NETWORK_OSTATUS)
                );              
                if(count($r))
                        $ret = count($r);
index 651736a99a82844c317e3e7fd7bb7bedfa780131..e80b696bf8615f9ca89df7963f01a76f1cd4d9c1 100644 (file)
@@ -82,12 +82,18 @@ function poller_run($argv, $argc){
        if(! $restart)
                proc_run('php','include/cronhooks.php');
 
+       // Only poll from those with suitable relationships,
+       // and which have a polling address and ignore Diaspora since 
+       // we are unable to match those posts with a Diaspora GUID and prevent duplicates.
+
        $contacts = q("SELECT `id` FROM `contact` 
                WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != ''
+               AND `network` != '%s'
                $sql_extra 
                AND `self` = 0 AND `blocked` = 0 AND `readonly` = 0 ORDER BY RAND()",
                intval(CONTACT_IS_SHARING),
-               intval(CONTACT_IS_FRIEND)
+               intval(CONTACT_IS_FRIEND),
+               dbesc(NETWORK_DIASPORA)
        );
 
        if(! count($contacts)) {
index c3738c1431c20e28221e24ad79bdc31cf96648e3..b50774933d349f2ac6e7d038a5c6dda9b65036ea 100644 (file)
@@ -63,6 +63,9 @@ function receive_post(&$a) {
        elseif($xmlbase->retraction) {
                diaspora_retraction($importer,$xmlbase->retraction,$msg);
        }
+       elseif($xmlbase->photo) {
+               diaspora_photo($importer,$xmlbase->photo,$msg);
+       }
        else {
                logger('mod-diaspora: unknown message type: ' . print_r($xmlbase,true));
        }
index adfb5fe0288e74a6989a640df11b3afb59760d53..ef036008fcb4abae39ad19f5b1cf27966b227d3e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-define( 'UPDATE_VERSION' , 1081 );
+define( 'UPDATE_VERSION' , 1082 );
 
 /**
  *
@@ -673,4 +673,19 @@ function update_1079() {
 
 function update_1080() {
        q("ALTER TABLE `fcontact` ADD `updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'");
-}
\ No newline at end of file
+}
+
+function update_1081() {
+       q("ALTER TABLE `photo` ADD `guid` CHAR( 64 ) NOT NULL AFTER `contact`id`,
+               ADD INDEX ( `guid` )  ");
+       $r = q("SELECT distinct(`resource-id`) FROM `photo` WHERE 1 group by `id`");
+       if(count($r)) {
+               foreach($r as $rr) {
+                       $guid = get_guid();
+                       q("update `photo` set `guid` = '%s' where `resource-id` = '%s'",
+                               dbesc($guid),
+                               dbesc($rr['resource-id'])
+                       );
+               }
+       }
+}
index 0e427feaaaf83b9907a5ceb6bf34304ccb7266c0..fb4f51f591c87cb7ea07ce8acb6988846f555fc9 100644 (file)
@@ -83,7 +83,7 @@
                                <poco:primary>true</poco:primary>
                        </poco:urls>
                </author>
-               <link rel="ostatus:conversation" href="$status.url"/> 
+               <link rel="ostatus:conversation" type="text/html" href="$status.url"/> 
 
        </entry>    
     {{ endfor }}
diff --git a/view/diaspora_photo.tpl b/view/diaspora_photo.tpl
new file mode 100644 (file)
index 0000000..75ca7f1
--- /dev/null
@@ -0,0 +1,13 @@
+<XML>
+  <post>
+    <photo>
+      <remote_photo_path>$path</remote_photo_path>
+      <remote_photo_name>$filename</remote_photo_name>
+      <status_message_guid>$msg_guid</status_message_guid>
+      <guid>$guid</guid>
+      <diaspora_handle>$handle</diaspora_handle>
+      <public>$public</public>
+      <created_at>$created_at</created_at>
+    </photo>
+  </post>
+</XML>
\ No newline at end of file