]> git.mxchange.org Git - friendica.git/commitdiff
couple of issues w/ profile photo update propogation
authorFriendika <info@friendika.com>
Wed, 10 Nov 2010 02:24:35 +0000 (18:24 -0800)
committerFriendika <info@friendika.com>
Wed, 10 Nov 2010 02:24:35 +0000 (18:24 -0800)
boot.php
include/Photo.php
include/dba.php
include/items.php
mod/dfrn_request.php
mod/photos.php
mod/profile_photo.php

index 4fc917bcc75285059f31a989285fa49e915c66b6..2ac6ee7914a89ad8af770c30c78be9d2036feef8 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -954,6 +954,7 @@ function webfinger_dfrn($s) {
                return $s;
        }
        $links = webfinger($s);
+       logger('webfinger_dfrn: ' . $s . ':' . print_r($links,true), LOGGER_DATA);
        if(count($links)) {
                foreach($links as $link)
                        if($link['@attributes']['rel'] === NAMESPACE_DFRN)
@@ -978,6 +979,7 @@ function webfinger($s) {
        }
        if(strlen($host)) {
                $tpl = fetch_lrdd_template($host);
+               logger('webfinger: lrdd template: ' . $tpl);
                if(strlen($tpl)) {
                        $pxrd = str_replace('{uri}', urlencode('acct:'.$s), $tpl);
                        $links = fetch_xrd_links($pxrd);
@@ -1066,9 +1068,12 @@ function fetch_lrdd_template($host) {
 if(! function_exists('fetch_xrd_links')) {
 function fetch_xrd_links($url) {
 
+
        $xml = fetch_url($url);
        if (! $xml)
                return array();
+
+       logger('fetch_xrd_links: ' . $xml, LOGGER_DATA);
        $h = simplexml_load_string($xml);
        $arr = convert_xml_element_to_array($h);
 
index 98b11ab39ff05eda68349677e294f2f087656e12..9934b9a3928f2e79ec060ede1cb55f547718f4ef 100644 (file)
@@ -175,8 +175,7 @@ class Photo {
 
 
 
-       public function store($uid, $cid, $rid, $filename, $album, $scale, 
-               $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') {
+       public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') {
 
                $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` )
@@ -188,9 +187,9 @@ class Photo {
                        dbesc(datetime_convert()),
                        dbesc(basename($filename)),
                        dbesc($album),
-                       intval($this->height),
-                       intval($this->width),
-                       dbesc($this->imageString()),
+                       intval($this->height),
+                       intval($this->width),
+                       dbesc($this->imageString()),
                        intval($scale),
                        intval($profile),
                        dbesc($allow_cid),
index 54084d8358ea12602b794c7068ee857b97bec0d5..4e3f11f7befbfbfa15666dafc698a88912ef9c9c 100644 (file)
@@ -37,7 +37,7 @@ class dba {
                        $mesg = '';
 
                        if($this->db->errno)
-                               $debug_text .=  $this->db->error . EOL;
+                               logger('dba: ' . $this->db->error);
 
                        if($result === false)
                                $mesg = 'false';
@@ -48,14 +48,7 @@ class dba {
         
                        $str =  'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg . EOL;
 
-                       switch($this->debug) {
-                               case 3:
-                                       echo $str;
-                                       break;
-                               default:
-                                       $debug_text .= $str;
-                                       break;
-                       }
+                       logger('dba: ' . $str );
                }
                else {
                        if($result === false) {
@@ -75,11 +68,8 @@ class dba {
                        $result->free_result();
                }
     
-               if($this->debug == 2)
-                       $debug_text .= printable(print_r($r, true). EOL);
-               elseif($this->debug == 3)
-                       echo printable(print_r($r, true) . EOL) ;
-
+               if($this->debug)
+                       logger('dba: ' . printable(print_r($r, true)), LOGGER_DATA);
                return($r);
        }
 
index 20f84361300d8fd5c3ce99a1689d7cb9da214180..8dbb591288edbc84a3c48a46482aae76627d771b 100644 (file)
@@ -761,17 +761,12 @@ function consume_feed($xml,$importer,$contact, &$hub, $datedir = 0) {
                        $photo_url = $elems['link'][0]['attribs']['']['href'];
                }
        }
-       if(! $photo_timestamp) {
-               $photo_rawupdate = $feed->get_feed_tags(NAMESPACE_DFRN,'icon-updated');
-               if($photo_rawupdate) {
-                       $photo_timestamp = datetime_convert('UTC','UTC',$photo_rawupdate[0]['data']);
-                       $photo_url = $feed->get_image_url();
-               }
-       }
-       if((is_array($contact)) && ($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $contact['avatar-date'])) {
 
+       if((is_array($contact)) && ($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $contact['avatar-date'])) {
+               logger('Consume feed: Updating photo for ' . $contact['name']);
                require_once("Photo.php");
                $photo_failure = false;
+               $have_photo = false;
 
                $r = q("SELECT `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d LIMIT 1",
                        intval($contact['id']),
@@ -779,33 +774,45 @@ function consume_feed($xml,$importer,$contact, &$hub, $datedir = 0) {
                );
                if(count($r)) {
                        $resource_id = $r[0]['resource-id'];
-                       $img_str = fetch_url($photo_url,true);
-                       $img = new Photo($img_str);
-                       if($img->is_valid()) {
-                               q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND contact-id` = %d AND `uid` = %d",
+                       $have_photo = true;
+               }
+               else {
+                       $resource_id = photo_new_resource();
+               }
+                       
+               $img_str = fetch_url($photo_url,true);
+               $img = new Photo($img_str);
+               if($img->is_valid()) {
+                       if($have_photo) {
+                               q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `contact-id` = %d AND `uid` = %d",
                                        dbesc($resource_id),
                                        intval($contact['id']),
                                        intval($contact['uid'])
                                );
-
-                               $img->scaleImageSquare(175);
+                       }
                                
-                               $hash = $resource_id;
-                               $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 4);
+                       $img->scaleImageSquare(175);
                                
-                               $img->scaleImage(80);
-                               $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 5);
-
-                               $img->scaleImage(48);
-                               $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 6);
-
-                               if($r)
-                                       q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
-                                               dbesc(datetime_convert()),
-                                               intval($contact['uid']),
-                                               intval($contact['id'])
-                                       );
-                       }
+                       $hash = $resource_id;
+                       $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 4);
+                               
+                       $img->scaleImage(80);
+                       $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 5);
+
+                       $img->scaleImage(48);
+                       $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 6);
+
+                       $a = get_app();
+
+                       q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s'  
+                               WHERE `uid` = %d AND `id` = %d LIMIT 1",
+                               dbesc(datetime_convert()),
+                               dbesc($a->get_baseurl() . '/photo/' . $hash . '-4.jpg'),
+                               dbesc($a->get_baseurl() . '/photo/' . $hash . '-5.jpg'),
+                               dbesc($a->get_baseurl() . '/photo/' . $hash . '-6.jpg'),
+                               intval($contact['uid']),
+                               intval($contact['id'])
+                       );
                }
        }
 
index 8c259f231a2627d94642b52c00d8220c73d19600..60106661cb38afd37d07f3581a731c5446716617 100644 (file)
@@ -192,6 +192,8 @@ function dfrn_request_post(&$a) {
                        $network = 'dfrn';
                }
 
+               logger('dfrn_request: url: ' . $url);
+
                if(! strlen($url)) {
                        notice( t("Unable to resolve your name at the provided location.") . EOL);                      
                        return;
index e1926bb568b4d0dab0699eb73e9152ce067e052b..addc04d76c7f10df41fa26ae56d6fb2901294aaf 100644 (file)
@@ -453,6 +453,14 @@ function photos_post(&$a) {
        $filename          = basename($_FILES['userfile']['name']);
        $filesize          = intval($_FILES['userfile']['size']);
 
+       $maximagesize = get_config('system','maximagesize');
+
+       if(($maximagesize) && ($filesize > $maximagesize)) {
+               notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
+               @unlink($src);
+               return;
+       }
+
        $imagedata = @file_get_contents($src);
        $ph = new Photo($imagedata);
 
index 32ace62f0583580dd7060de3ca487712189c6dfb..39808776b7e4fad331db8a0cc9028221b3f73a97 100644 (file)
@@ -42,7 +42,7 @@ function profile_photo_post(&$a) {
                $srcY = $_POST['ystart'];
                $srcW = $_POST['xfinal'] - $srcX;
                $srcH = $_POST['yfinal'] - $srcY;
-//dbg(3);
+
                $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = %d LIMIT 1",
                        dbesc($image_id),
                        dbesc(local_user()),
@@ -97,6 +97,7 @@ function profile_photo_post(&$a) {
                        else
                                notice( t('Unable to process image') . EOL);
                }
+
                goaway($a->get_baseurl() . '/profiles');
                return; // NOTREACHED
        }
@@ -105,6 +106,14 @@ function profile_photo_post(&$a) {
        $filename = basename($_FILES['userfile']['name']);
        $filesize = intval($_FILES['userfile']['size']);
 
+       $maximagesize = get_config('system','maximagesize');
+
+       if(($maximagesize) && ($filesize > $maximagesize)) {
+               notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
+               @unlink($src);
+               return;
+       }
+
        $imagedata = @file_get_contents($src);
        $ph = new Photo($imagedata);