Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Comments with images #35

Description

@gfr

I added a function to EZComments so that a user can also add an image to a comment.

diff -r org/lib/EZComments/Api/User.php mod/lib/EZComments/Api/User.php
221a222,223
>         
>         $args['image'] = isset($args['image']) ? trim($args['image']) : '';
284a287
>           'image'       => $args['image'],
diff -r org/lib/EZComments/Controller/User.php mod/lib/EZComments/Controller/User.php
228a229
>         $image      = isset($args['image'])   ? $args['image']     : $this->request->files->get('image');
290a292,325
>         
>       $fileName = '';
>       
>       if($image['name'] != ''){
>           $fileNameParts = explode('.', $image['name']);
>           $extension = $fileNameParts[count($fileNameParts) - 1];
>           $extension = str_replace('jpeg', 'jpg', strtolower($extension));
>   
>           if($extension != "jpg")
>           {
>               SessionUtil::setVar('ezcomment', serialize($ezcomment));
>               return LogUtil::registerError($this->__('Error! Only .jpg images are allowed!'), null,
>               $redirect."#commentform_{$mod}_{$objectid}");
>           }
>   
>           $basePath = FileUtil::getDataDirectory() . '/EZComments/image/';
>   
>               
>               
>           do {
>               $fileName = md5(uniqid(mt_rand(), TRUE)) . '.' . $extension;
>           }
>           while (file_exists($basePath . $fileName)); // repeat until we have a new name
>   
>           $upload = FileUtil::uploadFile('image', $basePath, $fileName);
>               
>               
>           if($upload !== true){
>               SessionUtil::setVar('ezcomment', serialize($ezcomment));
>               return LogUtil::registerError($this->__('Error during upload!') . ' ' . $upload, null,
>               $redirect."#commentform_{$mod}_{$objectid}");
>           }
> 
>       }
309c344,345
<                                  'anonwebsite' => $anonwebsite));

---
>                                  'anonwebsite' => $anonwebsite,
>                                'image'       => $fileName));
diff -r org/lib/EZComments/Installer.php mod/lib/EZComments/Installer.php
66a67,70
>         // Image upload
>         if(mkdir(FileUtil::getDataDirectory() . '/EZComments/image/') == false){
>             LogUtil::registerError($this->__('Error! Could not create upload directory. (' . FileUtil::getDataDirectory() . '/EZComments/image/)'));
>         }
135a140,144
>                 // Image upload
>                 
>                 if(mkdir(FileUtil::getDataDirectory() . '/EZComments/image/') == false){
>                   LogUtil::registerError($this->__('Error! Could not create upload directory. (' . FileUtil::getDataDirectory() . '/EZComments/image/)'));
>                 }
diff -r org/tables.php mod/tables.php
42c42,43
<         'anonwebsite' => 'anonwebsite'

---
>         'anonwebsite' => 'anonwebsite',
>       'image'     => 'image'
61c62,63
<         'anonwebsite' => "C(255) NOTNULL DEFAULT ''"

---
>         'anonwebsite' => "C(255) NOTNULL DEFAULT ''",
>       'image' => "C(255) NOTNULL DEFAULT ''"
diff -r org/templates/Standard/ezcomments_user_view.tpl mod/templates/Standard/ezcomments_user_view.tpl
54a55,57
>                                 <div class="ezc_image">
>                                     {$comment.image|showImage}
>                                 </div>
105a109,113
>                 </div>
>                 
>                 <div class="z-formrow">
>                     <label for="image">{gt text='Image' domain='module_ezcomments'}</label>
>                     <input name="image" type="file" />
<?php
/**
 * EZComments
 *
 * @copyright (C) EZComments Development Team
 * @link https://github.com/zikula-modules/EZComments
 * @license See license.txt
 */

/**
 * Smarty modifier to show a comment-image
 * 
 * Example
 * 
 *   {$MyVar|showImage}
 * 
 * 
 * @author  Gabriel Freinbichler
 * @since        23.07.2012
 * @param array    $string     the name of the image
 * @return string   html-img tag
 */
function smarty_modifier_showImage($name)
{
    if($name != '')
    {
        return '<img src="' . FileUtil::getDataDirectory() . '/EZComments/image/' . $name . '" />';
    }
    return '';
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions