1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Image Upload 0.2

Discussion in 'Plugins' started by Nick, Aug 17, 2010.

  1. Nick

    Nick Well-Known Member

    Image Upload
    Version: 0.2
    Author: Nick Ramsay
    Created: 2010/06
    Last Updated:
    2010/11/19
    Tested on: Hotaru 1.4.0 ~ 1.4.2
    Plugins Required: Tim Thumb
    Plug & Play: Yes
    Supported: No

    Description
    This plugin enables the post submitter to upload an image from his or her computer to attach to the post. See the Magazine demo here.

    Features:
    - Adds option to attach an uploaded image to new and old posts
    - Includes the ability to remove an attachment
    - Creates an "uploads" folder if one doesn't already exist
    - Stores images in folders organized by site id and date
    - Displays thumbnails on list pages and embeds a larger image on post pages
    - Uses the Tim Thumb plugin for thumbnail creation and caching
    - Uses the Thickbox plugin for displaying images when thumbnails are clicked
    - Options to resize thumbnails and embedded images
    - Option to set the maximum filesize for images that can be uploaded
    - Advanced function for overriding size settings within templates

    NOTE: This plugin only allows a single image per post. The position of the image is determined by where you put the plugin hook in your template, and is the same for every post.
    Image Upload was designed to make article posting as quick as possible. You type your text, upload an image and you're finished. See the Magazine Demo as an example of how effective this fixed position, single image concept is.

    If you want to control the sizes, position and number of images per post, this plugin is not for you.


    Instructions
    1. Upload the "image_upload" folder to your plugins folder.
    2. Install it from Plugin Management in Admin.
    3. Edited image sizes in Admin -> Plugin Settings -> Image Upload
    4. Add this plugin hook to submit2.php and submit_edit.php on the line AFTER the last closing </form> tag:

    PHP:
    <?php $h->pluginHook('image_upload'); ?>
    By default, thumbnail and embedded images are displayed via the "show_post_content_list" and "show_post_content_post" plugin hooks in bookmarking_list.php and bookmarking_post.php respectively (or their equivalent templates in the Magazine plugin).

    Advanced Usage
    You can prevent the default behavior by excluding the image_upload plugin from the show_post hooks, i.e.:

    PHP:
    <?php $h->pluginHook('show_post_content_list''', array(), array('image_upload')); ?>
    PHP:
    <?php $h->pluginHook('show_post_content_post''', array(), array('image_upload')); ?>
    Then, as a replacement, use:

    PHP:
    <?php $h->pluginHook('show_post_image'); ?>
    Highly customized themes may need unique sizes per plugin hook. To specify them, set the image size like this:
    PHP:
    <?php $h->pluginHook('show_post_image''', array('width'=>125'height'=>125)); ?>
    Revision History
    v.0.2 2010/11/11 - Nick - Upgrade attempts to move all files from "uploads/1" to "uploads" and remove "1" folder.
    v.0.1 2010/08/16 - Nick - Released first version

    Please click "Rate Thread" and give this plugin a rating. Thank you.
     

    Attached Files:

    Last edited: Aug 17, 2010
  2. norby500

    norby500 New Member Donor

    wish i had the knowledge to port this into a avatar upload plugin
     
  3. zigstonk

    zigstonk Donor Donor

    Nick - big kudos for coming up with this much-needed plug-in/solution! Thanks for all the hard work.
     
  4. narc

    narc Well-Known Member

    nick you are to fast :)
    many thanks.
     
  5. agent314

    agent314 Donor

    Will this work somehow for Bookmarking? Or is it not for that?
     
  6. Nick

    Nick Well-Known Member

    It works with Bookmarking.
     
  7. agent314

    agent314 Donor

    Position of Thumbnail in List view

    I'm wanting to position the thumbnail floated right even with the title... is there is simple fix in the code or ?? Image below...

    ImageUpload.jpg

    Thanks much...

    Jeff
     
  8. Nick

    Nick Well-Known Member

    The images ages shown via plugin hooks in the post content, so if you want to show them elsewhere, you need to follow the instructions under Advanced Usage in the first post.
     
  9. agent314

    agent314 Donor

    Nick... What I'm trying to accomplish is to get the thumbnail (which I have sized in the plugin to 70x70) to float right directly across from my Vote button as shown in the image below. I've tried as best I can to use the Advanced Instructions it seems like something is really missing... I only get the original image size, no link, no thickbox...

    image_pos.jpg

    Any help or clarification would be greatly appreciated! Thanks,

    Jeff
     
  10. Nick

    Nick Well-Known Member

    Could you paste here the section of code you've edited? Thanks.
     
  11. agent314

    agent314 Donor

    For the listing page bookmarking_list.php (I don't think I made any changes):

    Code:
    <!-- POST -->
    <?php $h->pluginHook('pre_show_post'); ?>
    
        <div class="show_post vote_button_space" id="show_post_<?php echo $h->post->id ?>" >
        
            <?php $h->pluginHook('show_post_pre_title'); ?>
            
            <?php   // Show avatars if enabled (requires an avatars plugin)
                if($h->isActive('avatar')) {
                    $h->setAvatar($user->id, 32);
                    echo $h->wrapAvatar();
                }
            ?>
            
            <div class="show_post_title">
                <?php if ($h->vars['link_action'] == 'source') { 
                    echo "<a href=' ". $h->post->origUrl ."' " . $h->vars['target'] ." class='click_to_source' rel='nofollow'>" . $h->post->title . "</a>";
                 } else { 
                    echo "<a href='" . $h->url(array('page'=>$h->post->id)) ."' " . $h->vars['target'] . " class='click_to_post'>" . $h->post->title . "</a>";
                 } 
                $h->pluginHook('show_post_title');
    	    ?>
            </div> 
        
            <div class="show_post_author_date">    
                <?php echo " " . $h->lang["bookmarking_post_posted_by"] . " "; ?>
    
    			<?php 
    			if ($user->name)
    			{
    				echo "<a href='" . $h->url(array('user' => $user->name)) . "'>" . $user->name . "</a>";
    			}
    			else
    			{
    				echo $h->lang['main_anonymous'];
    			}
    			?>
    
                <?php echo time_difference(unixtimestamp($h->post->date), $h->lang) . " " . $h->lang["bookmarking_post_ago"]; ?>
                <?php $h->pluginHook('show_post_author_date'); ?>
                <?php 
                    if (($h->currentUser->getPermission('can_edit_posts') == 'yes') 
                        || (($h->currentUser->getPermission('can_edit_posts') == 'own') && ($h->currentUser->id == $user->id))) { 
                        echo "<a class='show_post_edit' href='" . BASEURL . "index.php?page=edit_post&amp;post_id=" . $h->post->id . "'>" . $h->lang["bookmarking_post_edit"] . "</a>"; 
                    }
                ?> 
            </div>
                
            <?php if ($h->vars['use_content']) { ?>
                <div class="show_post_content">
                    <?php $h->pluginHook('show_post_content_list'); ?>
                    <?php if ($h->vars['use_summary']) { ?>
                        <?php echo truncate($h->post->content, $h->vars['summary_length']); ?>
                    <?php } else { ?>
                        <?php echo $h->post->content; ?>
                    <?php } ?>    
                    <small><a href='<?php echo $h->url(array('page'=>$h->post->id)); ?>'><?php echo $h->lang['bookmarking_post_read_more']; ?></a></small>
                </div>
            <?php } ?>	
    	
            <div class="show_post_extra_fields">
                <ul>
                    <?php $h->pluginHook('show_post_extra_fields'); ?>
                </ul>
            </div>
    
    	<div class="clear"></div>
            
            <div class="show_post_extras">
                <?php $h->pluginHook('show_post_extras'); ?>
            </div>
    
        </div>
    
    <?php } ?>
    <!-- END POST --> 
    For the Post page, my goal is the have exactly the same thing for each post that is on the Listing page... that is, Thumbnail that expands via Thickbox. I have made some changes to bookmarking_post.php page but obviously have not achieved that result as you can see at http://eventzapoppin.com. Here's the code...

    Code:
    <!-- POST -->
    <div class="show_post vote_button_space" id="show_post_<?php echo $h->post->id ?>" >
    
        <?php $h->pluginHook('show_post_pre_title'); ?>
    
        <?php   // Show avatars if enabled (requires an avatars plugin)
            if($h->isActive('avatar')) {
                $h->setAvatar($user->id, 32);
                echo $h->wrapAvatar();
            }
        ?>
            
        <div class="show_post_title">
            <?php if (!$h->vars['editorial']) { ?> 
                <a href='<?php echo $h->post->origUrl; ?>' <?php echo $h->vars['target']; ?> class="click_to_source" rel="nofollow"><?php echo $h->post->title; ?></a>
            <?php } else { ?>
                <?php echo $h->post->title; ?>
            <?php } ?>
            <?php $h->pluginHook('show_post_title'); ?>
        </div>
    
        <div class="show_post_author_date">
            <?php echo " " . $h->lang["bookmarking_post_posted_by"] . " "; ?>
    
    		<?php 
    		if ($user->name)
    		{
    			echo "<a href='" . $h->url(array('user' => $user->name)) . "'>" . $user->name . "</a>";
    		}
    		else
    		{
    			echo $h->lang['main_anonymous'];
    		}
    		?>
    
            <?php echo time_difference(unixtimestamp($h->post->date), $h->lang) . " " . $h->lang["bookmarking_post_ago"]; ?>
            <?php $h->pluginHook('show_post_author_date'); ?>
            <?php
                if (($h->pageName != 'submit3') 
                    && (($h->currentUser->getPermission('can_edit_posts') == 'yes') 
                    || (($h->currentUser->getPermission('can_edit_posts') == 'own') && ($h->currentUser->id == $user->id)))) { 
                    echo "<a class='show_post_edit' href='" . BASEURL . "index.php?page=edit_post&amp;post_id=" . $h->post->id . "'>" . $h->lang["bookmarking_post_edit"] . "</a>"; 
                }
            ?> 
        </div>
            
        <?php if ($h->vars['use_content']) { ?>
            <div class="show_post_content">
            	<div style="float:right; margin-left:1em;"><?php $h->pluginHook('show_post_image'); ?></div>
                <?php echo nl2br($h->post->content); ?>
                <?php $h->pluginHook('show_post_content_post', '', array(), array('image_upload')); ?> 
            </div>
        <?php } ?>
        
        <div class="show_post_extra_fields">
            <ul>
                <?php $h->pluginHook('show_post_extra_fields'); ?>
            </ul>
        </div>
        
    	<div class="clear"></div>
            
        <div class="show_post_extras">
            <?php $h->pluginHook('show_post_extras'); ?>
        </div>
        
    </div>
    
    <?php $h->pluginHook('show_post_middle'); ?>
    
    <?php $h->pluginHook('post_show_post'); ?>
    
    <!-- END POST --> 
    Does that help, Nick? The way it is now is just a stop-gap, I do think the image would look better if it were aligned with the Vote box... if that can't be done, maybe I can just get the Post page to work like the Listing page with thumbnail... either way, I appreciate the help... Jeff
     
  12. Nick

    Nick Well-Known Member

    You just need to move
    PHP:
    <div style="float:right; margin-left:1em;"><?php $h->pluginHook('show_post_image'); ?></div>
    much further up the page, probably just before

    PHP:
    <div class="show_post_title">
     
  13. agent314

    agent314 Donor

    Do you think that will work for both pages... Listing and Post? I can try it and see.
     
  14. agent314

    agent314 Donor

    Nick, I've decided to leave the Listing page as is... I was able to move the Post page up but it doesn't look that good... oh well... so my only remaining question is... is there a way to have the thumbnail/thickbox, etc on the Post page so that it's the same? It's not critical but might be good. I know it's probably not orthodox... and may not be worth the trouble. Thanks.
    Jeff
     
  15. narc

    narc Well-Known Member

    I have just installed the plugin. the upload directory set to 777. if I have a picture upload to I get a message "successfully". in the post but not the image I see. bookmarking_post.php in my file I have here inserted:

    <?php $h->pluginHook('show_post_content_post', '', array(), array('image_upload')); ?>

    is the file itself is in the upload directory does not exist. what can that be?
     
  16. agent314

    agent314 Donor

    You have to put the image upload plugin back in I believe where you want it to show as in the instructions...
     
    Nick likes this.
  17. Nick

    Nick Well-Known Member

    You should not insert anything in bookmarking_post.php unless you want to use the advanced features described in the instructions.
     
  18. narc

    narc Well-Known Member

    Thank you. it works.
    is it possible with this plugin to generate a thumbnail? so the post is displayed in the small visual items. You can click on is displayed but the source file. I think that may be of interest to many users here. Pligg has in the plugin always a lot of enthusiasm: http://forums.pligg.com/free-modules/17484-upload-module-file-image-attachment.html

    would be happy if it could be extended in hotaru this plugin.
     
  19. Nick

    Nick Well-Known Member

    I don't understand. This plugin already generates thumbnails.

     
  20. narc

    narc Well-Known Member

    sorry nick, was my error. I had my custom theme mixed up some parameters.

    I had a question yet. how can I place the upload form UP. below, it looks funny. If I submit when the next button and have them still can attach images. See if we can combine the upload and submit with each other? so my picture will be uploaded as soon as the submit next click on.
     

Share This Page