]> git.mxchange.org Git - friendica.git/commitdiff
more photo progress
authorMike Macgirvin <mike@macgirvin.com>
Thu, 5 Aug 2010 03:03:38 +0000 (20:03 -0700)
committerMike Macgirvin <mike@macgirvin.com>
Thu, 5 Aug 2010 03:03:38 +0000 (20:03 -0700)
database.sql
include/Photo.php
mod/dfrn_confirm.php
mod/item.php
mod/photo.php
mod/profile_photo.php
mod/wall_upload.php
view/jot-header.tpl

index 6b8b1281b35f26cff31e7c112475a3f9587fe53f..93d793cd0033aaeb121ae0d23b8dfbf7d035190d 100644 (file)
@@ -217,9 +217,9 @@ CREATE TABLE IF NOT EXISTS `photo` (
   `data` mediumblob NOT NULL,
   `scale` tinyint(3) NOT NULL,
   `profile` tinyint(1) NOT NULL DEFAULT '0',
-  `allow_uid` mediumtext NOT NULL,
+  `allow_cid` mediumtext NOT NULL,
   `allow_gid` mediumtext NOT NULL,
-  `deny_uid` mediumtext NOT NULL,
+  `deny_cid` mediumtext NOT NULL,
   `deny_gid` mediumtext NOT NULL,
   PRIMARY KEY (`id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
index 95ccccc88df6da1bdf9702a55d61318e0a72e79d..b8557e7ec326a6852a7e5953c6735e63a2f9765d 100644 (file)
@@ -167,5 +167,32 @@ class Photo {
        }
 
 
+
+       public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0) {
+
+               $r = q("INSERT INTO `photo`
+                       ( `uid`, `contact-id`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `data`, `scale`, `profile` )
+                       VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d )",
+                       intval($uid),
+                       intval($cid),
+                       dbesc($rid),
+                       dbesc(datetime_convert()),
+                       dbesc(datetime_convert()),
+                       dbesc(basename($filename)),
+                       dbesc($album),
+                       intval($this->height),
+                       intval($this->width),
+                       dbesc($this->imageString()),
+                       intval($scale),
+                       intval($profile)
+               );
+               return $r;
+       }
+
+
+
+
+
 }}
 
+
index e5a550cd9511c26969bcf60d2a75523c5c4ba7a7..263c88f6772d9e77a0abae09c113c3d50b5c40e8 100644 (file)
@@ -91,36 +91,14 @@ function dfrn_confirm_post(&$a) {
                                        
                                        $hash = hash('md5',uniqid(mt_rand(),true));
 
-                                       $r = q("INSERT INTO `photo` ( `uid`, `contact-id`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `data`, `scale` )
-                                               VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 4 )",
-                                               intval($local_uid),
-                                               intval($dfrn_record),
-                                               dbesc($hash),
-                                               datetime_convert(),
-                                               datetime_convert(),
-                                               dbesc(basename($r[0]['photo'])),
-                                               dbesc( t('Contact Photos') ),
-                                               intval($img->getHeight()),
-                                               intval($img->getWidth()),
-                                               dbesc($img->imageString())
-                                       );
+                                       $r = $img->store($local_uid, $dfrn_record, $hash, $filename, t('Contact Photos') , 4);
+
                                        if($r === false)
                                                $photo_failure = true;
                                        
                                        $img->scaleImage(80);
-                                       $r =  q("INSERT INTO `photo` ( `uid`, `contact-id`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `data`, `scale` )
-                                               VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 5 )",
-                                               intval($local_uid),
-                                               intval($dfrn_record),
-                                               dbesc($hash),
-                                               datetime_convert(),
-                                               datetime_convert(),
-                                               dbesc(basename($r[0]['photo'])),
-                                               dbesc( t('Contact Photos')),
-                                               intval($img->getHeight()),
-                                               intval($img->getWidth()),
-                                               dbesc($img->imageString())
-                                       );
+                                       $r = $img->store($local_uid, $dfrn_record, $hash, $filename, t('Contact Photos') , 5);
+
                                        if($r === false)
                                                $photo_failure = true;
 
@@ -190,7 +168,7 @@ function dfrn_confirm_post(&$a) {
                $uid = $_SESSION['uid'];
 
                if(! $uid) {
-                       notice(t("Permission denied.") . EOL );
+                       notice( t("Permission denied.") . EOL );
                        return;
                }       
        
@@ -319,33 +297,14 @@ function dfrn_confirm_post(&$a) {
                                        
                                $hash = hash('md5',uniqid(mt_rand(),true));
 
-                               $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `data`, `scale` )
-                                               VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 4 )",
-                                       intval($local_uid),
-                                       dbesc($hash),
-                                       datetime_convert(),
-                                       datetime_convert(),
-                                       dbesc(basename($r[0]['photo'])),
-                                       dbesc( t('Contact Photos') ),
-                                       intval($img->getHeight()),
-                                       intval($img->getWidth()),
-                                       dbesc($img->imageString())
-                               );
+                               $r = $img->store($local_uid, $contact_id, $hash, $filename, t('Contact Photos'), 4 );
+
                                if($r === false)
                                        $photo_failure = true;
                                $img->scaleImage(80);
-                               $r =  q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `data`, `scale` )
-                                       VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 5 )",
-                                       intval($local_uid),
-                                       dbesc($hash),
-                                       datetime_convert(),
-                                       datetime_convert(),
-                                       dbesc(basename($r[0]['photo'])),
-                                       dbesc( t('Contact Photos') ),
-                                       intval($img->getHeight()),
-                                       intval($img->getWidth()),
-                                       dbesc($img->imageString())
-                               );
+
+                               $r = $img->store($local_uid, $contact_id, $hash, $filename, t('Contact Photos'), 5 );
+
                                if($r === false)
                                        $photo_failure = true;
 
index 49067d940be7709402458d00ab0efe7ebd1dacf5..5f53eccf334ce8b7833c0187a7005f07050324e7 100644 (file)
@@ -23,7 +23,7 @@ function item_post(&$a) {
                        intval($parent)
                );
                if(! count($r)) {
-                       notice("Unable to locate original post." . EOL);
+                       notice( t('Unable to locate original post.') . EOL);
                        goaway($a->get_baseurl() . "/" . $_POST['return'] );
                }
                $parent_item = $r[0];
@@ -68,7 +68,7 @@ function item_post(&$a) {
        $body = escape_tags(trim($_POST['body']));
 
        if(! strlen($body)) {
-               notice("Empty post discarded." . EOL );
+               notice( t('Empty post discarded.') . EOL );
                goaway($a->get_baseurl() . "/" . $_POST['return'] );
 
        }
@@ -221,6 +221,19 @@ function item_content(&$a) {
                                intval($item['id'])
                        );
 
+                       // If item is a link to a photo resource, nuke all the associated photos 
+                       // (visitors will not have photo resources)
+                       // This only applies to photos uploaded from the photos page. Photos inserted into a post do not
+                       // generate a resource-id and therefore aren't intimately linked to the item. 
+
+                       if(strlen($item['resource-id'])) {
+                               $q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ",
+                                       dbesc($item['resource-id']),
+                                       intval($item['uid'])
+                               );
+                               // ignore the result
+                       }
+
                        // If it's the parent of a comment thread, kill all the kids
 
                        if($item['uri'] == $item['parent-uri']) {
@@ -230,6 +243,7 @@ function item_content(&$a) {
                                        dbesc($item['parent-uri']),
                                        intval($item['uid'])
                                );
+                               // ignore the result
                        }
 
                        $url = $a->get_baseurl();
index f922c7ab26355043d01fc336c25ccf789791f1d8..6e4d981d27f2484876a376c6259a10609d97ed9f 100644 (file)
@@ -44,6 +44,7 @@ function photo_init(&$a) {
                }
        }
        else {
+
                $resolution = 0;
                $photo = str_replace('.jpg','',$photo);
        
@@ -52,12 +53,56 @@ function photo_init(&$a) {
                        $photo = substr($photo,0,-2);
                }
 
-               $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1",
+               $r = q("SELECT `uid` FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1",
                        dbesc($photo),
                        intval($resolution)
                );
                if(count($r)) {
-                       $data = $r[0]['data'];
+                       
+                       $owner = $r[0]['uid'];
+
+                       $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
+
+                       if(local_user() && ($owner == $_SESSION['uid'])) {
+
+                               // Owner can always see his/her photos
+                               $sql_extra = ''; 
+
+                       }
+                       elseif(remote_user()) {
+
+                               // authenticated visitor - here lie dragons
+
+                               $groups = init_groups_visitor($_SESSION['visitor_id']);
+                               $gs = '<<>>'; // should be impossible to match
+                               if(count($groups)) {
+                                       foreach($groups as $g)
+                                               $gs .= '|<' . intval($g) . '>';
+                               } 
+
+                               $sql_extra = sprintf(
+                                       " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) 
+                                         AND ( `deny_cid`  = '' OR  NOT `deny_cid` REGEXP '<%d>' ) 
+                                         AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
+                                         AND ( `deny_gid`  = '' OR NOT `deny_gid` REGEXP '%s') ",
+
+                                       intval($_SESSION['visitor_id']),
+                                       intval($_SESSION['visitor_id']),
+                                       dbesc($gs),
+                                       dbesc($gs)
+                               );
+                       }
+
+                       // Now we'll see if we can access the photo
+
+                       $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d $sql_extra LIMIT 1",
+                               dbesc($photo),
+                               intval($resolution)
+                       );
+
+                       if(count($r)) {
+                               $data = $r[0]['data'];
+                       }
                }
        }
 
index 818cbecb2e71ba9baac41dba27d1b11ff02ed363..151277249a1b7e8254691378c747c1ad032b354d 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($_SESSION['uid']),
@@ -55,38 +55,14 @@ function profile_photo_post(&$a) {
                        $im = new Photo($base_image['data']);
                        $im->cropImage(175,$srcX,$srcY,$srcW,$srcH);
 
-                       $ret = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`, 
-                               `height`, `width`, `data`, `scale`, `profile` )
-                               VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 4, 1 )",
-                               intval($_SESSION['uid']),
-                               dbesc($base_image['resource-id']),
-                               datetime_convert(),
-                               datetime_convert(),
-                               dbesc($base_image['filename']),
-                               dbesc( t('Profile Photos') ),
-                               intval($im->getHeight()),
-                               intval($im->getWidth()),
-                               dbesc($im->imageString())
-                       );
+                       $r = $im->store($_SESSION['uid'], 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 4, 1);
 
                        if($r === false)
                                notice ( t('Image size reduction (175) failed.') . EOL );
 
                        $im->scaleImage(80);
 
-                       $ret = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`,
-                               `height`, `width`, `data`, `scale`, `profile` )
-                               VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 5, 1 )",
-                               intval($_SESSION['uid']),
-                               dbesc($base_image['resource-id']),
-                               datetime_convert(),
-                               datetime_convert(),
-                               dbesc($base_image['filename']),
-                               dbesc( t('Profile Photos') ),
-                               intval($im->getHeight()),
-                               intval($im->getWidth()),
-                               dbesc($im->imageString())
-                       );
+                       $r = $im->store($_SESSION['uid'], 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 5, 1);
                        
                        if($r === false)
                                notice( t('Image size reduction (80) failed.') . EOL );
@@ -129,21 +105,11 @@ function profile_photo_post(&$a) {
 
        $hash = hash('md5',uniqid(mt_rand(),true));
        
-       $str_image = $ph->imageString();
+
        $smallest = 0;
 
-       $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`, 
-               `height`, `width`, `data`, `scale` )
-               VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 0 )",
-               intval($_SESSION['uid']),
-               dbesc($hash),
-               datetime_convert(),
-               datetime_convert(),
-               dbesc(basename($filename)),
-               dbesc( t('Profile Photos') ),
-               intval($height),
-               intval($width),
-               dbesc($str_image));
+       $r = $ph->store($_SESSION['uid'], 0 , $hash, $filename, t('Profile Photos'), 0 );       
+
        if($r)
                notice( t('Image uploaded successfully.') . EOL );
        else
@@ -151,23 +117,8 @@ function profile_photo_post(&$a) {
 
        if($width > 640 || $height > 640) {
                $ph->scaleImage(640);
-               $str_image = $ph->imageString();
-               $width = $ph->getWidth();
-               $height = $ph->getHeight();
+               $r = $ph->store($_SESSION['uid'], 0 , $hash, $filename, t('Profile Photos'), 1 );       
 
-               $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`,
-                       `height`, `width`, `data`, `scale` )
-                       VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 1 )",
-                       intval($_SESSION['uid']),
-                       dbesc($hash),
-                       datetime_convert(),
-                       datetime_convert(),
-                       dbesc(basename($filename)),
-                       dbesc( t('Profile Photos') ),
-                       intval($ph->getHeight()),
-                       intval($ph->getWidth()),
-                       dbesc($ph->imageString())
-               );
                if($r === false)
                        notice( t('Image size reduction (640) failed.') . EOL );
                else
index 34c541677590839cd09cce08e1d9db9721c4f7bd..d05c8cf921bc23df0cf76676557d76bca55aba9c 100644 (file)
@@ -5,7 +5,7 @@ require_once('Photo.php');
 function wall_upload_post(&$a) {
 
         if(! local_user()) {
-                echo ( "Permission denied." . EOL );
+                echo ( t('Permission denied.') . EOL );
                 killme();
         }
 
@@ -20,7 +20,7 @@ function wall_upload_post(&$a) {
        $ph = new Photo($imagedata);
 
        if(! ($image = $ph->getImage())) {
-               echo ("Unable to process image." . EOL);
+               echo ( t('Unable to process image.') . EOL);
                @unlink($src);
                killme();
        }
@@ -32,62 +32,25 @@ function wall_upload_post(&$a) {
 
        $hash = hash('md5',uniqid(mt_rand(),true));
        
-       $str_image = $ph->imageString();
        $smallest = 0;
 
-       $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`,
-               `height`, `width`, `data`, `scale` )
-               VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 0 )",
-               intval($_SESSION['uid']),
-               dbesc($hash),
-               datetime_convert(),
-               datetime_convert(),
-               dbesc(basename($filename)),
-               dbesc( t('Wall Photos')),
-               intval($height),
-               intval($width),
-               dbesc($str_image));
+       $r = $ph->store($_SESSION['uid'], 0, $hash, $filename, t('Wall Photos'), 0 );
+
        if(! $r) {
-               echo ("Image upload failed." . EOL);
+               echo ( t('Image upload failed.') . EOL);
                killme();
        }
 
        if($width > 640 || $height > 640) {
                $ph->scaleImage(640);
-
-               $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`,
-                       `height`, `width`, `data`, `scale` )
-                       VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 1 )",
-                       intval($_SESSION['uid']),
-                       dbesc($hash),
-                       datetime_convert(),
-                       datetime_convert(),
-                       dbesc(basename($filename)),
-                       dbesc( t('Wall Photos') ),
-                       intval($ph->getHeight()),
-                       intval($ph->getWidth()),
-                       dbesc($ph->imageString())
-               );
+               $r = $ph->store($_SESSION['uid'], 0, $hash, $filename, t('Wall Photos'), 1 );
                if($r) 
                        $smallest = 1;
        }
 
        if($width > 320 || $height > 320) {
                $ph->scaleImage(320);
-
-               $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, `album`,
-                       `height`, `width`, `data`, `scale` )
-                       VALUES ( %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', 2 )",
-                       intval($_SESSION['uid']),
-                       dbesc($hash),
-                       datetime_convert(),
-                       datetime_convert(),
-                       dbesc(basename($filename)),
-                       dbesc( t('Wall Photos') ),
-                       intval($ph->getHeight()),
-                       intval($ph->getWidth()),
-                       dbesc($ph->imageString())
-               );
+               $r = $ph->store($_SESSION['uid'], 0, $hash, $filename, t('Wall Photos'), 2 );
                if($r)
                        $smallest = 2;
        }
index fc05a40be19f4fc5df65aa351cb3eb8ba54cb437..6402d5db60d6ea30d39d04625cf2f230d0972728 100644 (file)
@@ -31,7 +31,7 @@ tinyMCE.init({
                                name: 'userfile',
                                onSubmit: function(file,ext) { $('#profile-rotator').show(); },
                                onComplete: function(file,response) {
-alert(response);                                       tinyMCE.execCommand('mceInsertRawHTML',false,response);
+                                       tinyMCE.execCommand('mceInsertRawHTML',false,response);
                                        $('#profile-rotator').hide();
                                }                                
                        }