About this topic

  • Posted by elm 1 year ago. There are 11 posts. The latest reply is from claralisse.
  • This topic is resolved
  1. Hi,

    first of all I like to say thank you for this amazing Plugin. It is one of the best Wordpress-Plugins and definitely the best Gallery-Plugin out there.

    I have two questions. The first is a quick-one. How can I limit the characters used in a textfield of a custom-field? I created a custom-field "Description" and I would like to limit the characters used here. I guess I must insert the limitation in bwbps-uploadform.php somewhere around line 1230, but I can`t get it to work.... .

    The second qustion is about the limitation of uploads per user to a gallery. I've read your posting in the forum:

    To accomplish this, you'd need to extend the galleries table to include a setting for max_images_byuser. 0 would = unlimited and be the default. Database extensions are done in admin/bwbps-init.php

    Then, probably in the bwbps-uploadform.php file somewhere, you'd need to check if gallery['max_images_byuser'] > 0 then how many images does the user have uploaded for tht gallery? If >= gallery['max_images_byuser'] then put a message in the form "You have already uploaded your alloted limit of images to this gallery." Else, get the normal form.

    Then in ajax_upload.php, you should do the check again and bomb out if they've hit the limit.

    I like to use photosmash for a contest and it would be essentiell, that every contestant can only upload one image per gallery. Since I am not the greatest expert (actually I'm no expert at all) with php, this is a bit heavy for me. Does anyone maybe have tried this and has some more information/code on this?

    Thank you very much!

  2. Hi Elm,

    Thanks for the kind words! Glad you like PS.

    Here's some thoughts on your questions:
    1) There isn't anything built into PhotoSmash that allows limiting characters, but you could build your form fields in a Custom Layout and set the maxlength value in the form like:

    <input type='text' maxlength=15 name='my_field' />

    You will just need to figure out what name/id photosmash would assign to your fields.

    I'd really recommend against changing the code because of future updates. Anytime you update, you'll lose all your customizations, but if you use the custom forms and custom layouts, you don't lose those unless you delete them yourself.

    2) Since PhotoSmash doesn't limit the # of photos a user can upload, you can do a couple of things without changing the photosmash code.
    a) You could always just reject any additional images a user might upload in moderation, but depending on volume, that might be hard. If it's a couple hundred users, you could preview their author page to see how many images they've got uploaded...like: http://smashly.net/blog/author/byron/

    b) If you want to do some coding, you could create a little plugin that would hook into the 'bwbps_add_photo_link' filter and do a database query like:

    add_filter('bwbps_add_photo_link', 'limitUserUploads');
    
    function limitUserUploads( $photo_link ){
    $result = $wpdb->get_row("SELECT user_id from " . PSIMAGESTABLE . " WHERE user_id = " . (int)$current_user->ID . " AND gallery_id= " . (int)$yourGalleryID );
    
    if( $result ){
      $photo_link = "";
    } 
    
    return $photo_link;
    }

    You would just need to provide it with the Gallery ID you are dealing with at the moment.

    Hope that helps,
    Byron

  3. Hi Byron,

    thanks for your quick response. I am having some trouble with the LimitUserUploads-Function. I created a little Plugin with your code and provided it with my Gallery ID. But I keep getting the fatal error: Call to a member function get_row() on a non-object.

    Any ideas? Thanks again for your help.

  4. Hi elm,

    Make sure you have this in your code:

    global $wpdb;

    Hopefully that does it. If not, here's the documentation on how to use $wpdb class:

    http://codex.wordpress.org/Function_Reference/wpdb_Class
    Cheers,
    Byron

  5. Hi Byron,

    sorry to bother you again. I got rid of the fatal error. Thanks.

    But I still have some problems with the LimitUserUploads-Function. The part WHERE user_id = " . (int)$current_user->IDdoes not get a result. When I put it in manually (user_id=x) the function is getting a result and the Upload-Link is not showing.

    But even if the part with the current_user ID would be working, it would only allow a single upload. Because once a user has uploaded an image, the function would retrieve a result and would not show the Upload-link on any gallery. Even the ones the user has not yet contributet to. Right? Or did staring at code all day, mess up my head... ?

    Cheers and thank you once again.

  6. Hi Elm,

    Ooops, missing:

    global $current_user;

    Hopefully that fixes that...I'll add a fixed version below.

    So, if you're going to have multiple galleries where they can only upload a single image, the next thing you need to do is extract the gallery ID from the $photo_link variable that gets passed to your function.

    Right now, that function will only affect the gallery that you supply in the SQL statement, so they will still be able to upload to other galleries, but as much as they want. So, the function below fixes it so that they can only upload a single image to all galleries (1 per gallery). I haven't tried it, so let me know if it doesn't work:

    add_filter('bwbps_add_photo_link', 'limitUserUploads');
    
    function limitUserUploads( $photo_link ){
    global $wpdb;
    global $current_user;
    
    // Let's try to get the gallery ID from the upload link...
    // I'm sure you could do it easier with preg_match, but I'd have to Google the next 30 minutes to figure it out
    $temp = strstr( $photo_link, 'bwbpsFormSpace_' );
    $pos = strpos(  $temp, '"' );
    
    if( $pos > 0 ){
    $pos++;
    $gallery_id = substr( $temp, 0, $pos );
    
    $result = $wpdb->get_row("SELECT user_id from " . PSIMAGESTABLE . " WHERE user_id = " . (int)$current_user->ID . " AND gallery_id= " . (int)$gallery_id );
    }
    
    if( $result ){
      $photo_link = "";
    } 
    
    return $photo_link;
    }
  7. Hey Byron,

    thanks again. It seems, that the function is not retreiving the gallery_id correctly. I've been reading on Sites on php for hours and tried different mods on your code. But I just can't figure it out... .

    I'm wondering, what happens with the function on pages with more than on gallery, like the category page? (It wouldn't be a big deal, though.)

    Thank you Byron, cheers

  8. Hi Elm,

    Ok...I tested this one, so it should actually work (if you're using the standard Pop-up form) ;-)

    Try this:

    add_filter('bwbps_add_photo_link', 'limitUserUploads');
    
    function limitUserUploads( $photo_link ){
    global $wpdb;
    global $current_user;
    
    // Let's try to get the gallery ID from the upload link...
    // I'm sure you could do it easier with preg_match, but I'd have to Google the next 30 minutes to figure it out
    $temp = strstr( $photo_link, 'bwbpsShowPhotoUpload(' );
    $temp = str_replace("bwbpsShowPhotoUpload(","",$temp);
    $pos = strpos(  $temp, ',' );
    
    if( $pos > 0 ){
    
    $gallery_id = substr( $temp, 0, $pos );
    
    $result = $wpdb->get_row("SELECT user_id from " . PSIMAGESTABLE . " WHERE user_id = " . (int)$current_user->ID . " AND gallery_id= " . (int)$gallery_id );
    }
    
    if( $result ){
      $photo_link = "";
    } 
    
    return $photo_link;
    }

    Hope that works!
    Byron

  9. Sweet, it works! Byron, you are the best!

    Thank you very much for the best Plugin-Support I have ever seen.

  10. Excellent! You're welcome.

    BB

  11. Hi elm,

    I have limit the upsloads per user in each gallery and I have had a problem that could be interesting for you elm.

    Be careful with the upload form if you are using Thickbox for floating upload form because this way you are only hidding the add photo link. The problem appears when if the user uploads pictures without closing the upload form because he will be able to upload the number of photos he wants.

    If you have this problem I can tell you how I solved it.

RSS feed for this topic