]> git.mxchange.org Git - friendica.git/commitdiff
service limits for photo uploads
authorfriendica <info@friendica.com>
Mon, 25 Jun 2012 08:37:44 +0000 (01:37 -0700)
committerfriendica <info@friendica.com>
Mon, 25 Jun 2012 08:37:44 +0000 (01:37 -0700)
include/plugin.php
mod/photos.php
view/photos_upload.tpl
view/theme/duepuntozero/style.css

index 89715485ee63be69a0ec41694795bb4bf012ae9b..e8fec4cbeae88296df046c50678d079d641fcc27 100644 (file)
@@ -355,6 +355,31 @@ function service_class_allows($uid,$property,$usage = false) {
        }
 }
 
+
+function service_class_fetch($uid,$property) {
+
+       if($uid == local_user()) {
+               $service_class = $a->user['service_class'];
+       }
+       else {
+               $r = q("select service_class from user where uid = %d limit 1",
+                       intval($uid)
+               );
+               if($r !== false and count($r)) {
+                       $service_class = $r[0]['service_class'];
+               }
+       }
+       if(! x($service_class))
+               return false; // everything is allowed
+
+       $arr = get_config('service_class',$service_class);
+       if(! is_array($arr) || (! count($arr)))
+               return false;
+
+       return((array_key_exists($property,$arr)) ? $arr[$property] : false);
+
+}
+
 function upgrade_link() {
        $l = get_config('service_class','upgrade_link');
        $t = sprintf('<a href="%s">' . t('Click here to upgrade.') . '</div>', $l);
index 31046565d8ea076b065e48695cd53360e15c13f0..ea4d7f81f50ffb7eda81fbe9d82fd8c44c60b713 100644 (file)
@@ -711,6 +711,24 @@ function photos_post(&$a) {
        logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
 
        $imagedata = @file_get_contents($src);
+
+
+
+       $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
+               intval($a->data['user']['uid'])
+       );
+
+       $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
+
+       if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
+               notice( upgrade_message() . EOL );
+               @unlink($src);
+               $foo = 0;
+               call_hooks('photo_post_end',$foo);
+               killme();
+       }
+               
+
        $ph = new Photo($imagedata, $type);
 
        if(! $ph->is_valid()) {
@@ -968,12 +986,25 @@ function photos_content(&$a) {
                <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
 
 
+               $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
+                       intval($a->data['user']['uid'])
+               );
+
+
+               $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
+               if($limit !== false) {
+                       $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
+               }
+               else {
+                       $usage_message = sprintf( t('You have used %1$.2f Mbytes of photo storage.'), $r[0]['total'] / 1024000 );
+               }
+
 
                $tpl = get_markup_template('photos_upload.tpl');
                $o .= replace_macros($tpl,array(
                        '$pagename' => t('Upload Photos'),
                        '$sessid' => session_id(),
+                       '$usage' => $usage_message,
                        '$nickname' => $a->data['user']['nickname'],
                        '$newalbum' => t('New album name: '),
                        '$existalbumtext' => t('or existing album name: '),
index 318a9242771ecaf8c84f72266d0e80fa1748a7f7..706b3398dd8fdc59b25c9b61eefba84c94f4590a 100644 (file)
@@ -1,4 +1,7 @@
 <h3>$pagename</h3>
+
+<div id="photos-usage-message">$usage</div>
+
 <form action="photos/$nickname" enctype="multipart/form-data" method="post" name="photos-upload-form" id="photos-upload-form" >
        <div id="photos-upload-new-wrapper" >
                <div id="photos-upload-newalbum-div">
index de366210b6e0d06ca8a6d69745fc23c89bab4182..ea3a2da9c6f33446b40db3186c5ae58dc6ff6dfe 100644 (file)
@@ -1644,6 +1644,9 @@ input#dfrn-url {
        display:block!important;
 }
 
+#photos-usage-message {
+       margin-bottom: 15px;
+}
 
 
 #acl-wrapper {