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

Comments with images #35

Open
gfr opened this issue Jul 23, 2012 · 3 comments
Open

Comments with images #35

gfr opened this issue Jul 23, 2012 · 3 comments

Comments

@gfr
Copy link

gfr commented Jul 23, 2012

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 '';
}

@ghost
Copy link

ghost commented Jul 23, 2012

Please could you open a PR with this?

@phaidon
Copy link
Member

phaidon commented Jul 24, 2012

Is this really the right way? Should not we use a hook for that?

@nmpetkov
Copy link
Contributor

nmpetkov commented Jul 8, 2014

One way to add images to comments, is to hook Scribite (visual editor) to EZcomments, with possibility to upload images (for example CKEditor with KCFinder).

Note: In this case, instead to show comment form under the commented content (with visual editor loaded), it is good idea to display a button only for adding comment. It is not implemented yet in the module, but is not difficult to implement.

@Guite Guite added this to the EZComments 4.0.0 milestone Jan 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants