xoops forums

luciorota

Module Developer
Posted on: 2009/8/19 14:50
luciorota
luciorota (Show more)
Module Developer
Posts: 197
Since: 2007/4/20
#1

A way to modulize image manager

Here you are a way to modulize image manager.
I think this is the first step to realize a new and improved image manager for xoops...

NOTE: This is a skeleton of an alfa version of a module... don't worry if it isn't complete.

Try this hack in XOOPS 233,it runs also in XOOPS 240b... but step 2 is a little different...

1. add a config in "xoops_data/config/xoopsconfig.php"

<?php

return array(
        
/**#@+
         * Extended HTML editor for {@link XoopsFormDhtmlTextArea}
         *
         * <p>If an extended HTML editor is set, the renderer will be replaced by the specified editor, usually a visual or WYSIWYG editor.</p>
         *
         * <ul>Developer and user guide:
         *  <li><ul>For run-time settings per call
         *          <li>To use an editor pre-configured by {@link XoopsEditor}, e.g. 'fckeditor': <code>$options['editor'] = 'fckeditor';</code></li>
         *          <li>To use a custom editor, e.g. 'MyEditor' class located in "/modules/myeditor/myeditor.php": <code>$options['editor'] = array('MyEditor', XOOPS_ROOT_PATH . "/modules/myeditor/myeditor.php");</code></li>
         *      </ul></li>
         *  <li><ul>For pre-configured settings, which will force to use a editor if no specific editor is set for call
         *          <li><ul>Set up custom configs: in XOOPS_VAR_PATH . '/configs/xoopsconfig.php' set a editor as default, e.g.
         *                  <li>a pre-configured editor 'fckeditor': <code>return array('editor' => 'fckeditor');</code></li>
         *                  <li>a custom editor 'MyEditor' class located in "/modules/myeditor/myeditor.php": <code>return array('editor' => array('MyEditor', XOOPS_ROOT_PATH . "/modules/myeditor/myeditor.php");</code></li>
         *              </ul></li>
         *          <li>To disable the default editor, in XOOPS_VAR_PATH . '/configs/xoopsconfig.php': <code>return array();</code></li>
         *          <li>To disable the default editor for a specific call: <code>$options['editor'] = 'dhtmltextarea';</code></li>
         *      </ul></li>
         * </ul>
         */
        //"editor"    => "fckeditor",
        //"editor"    => "dhtmlext",
        /**#@-*/


        /**#@+
         * Debug level for XOOPS
         *
         * Note: temporary solution only. Will be re-designed in XOOPS 3.0
         *
         * <ul>Displaying debug information to different level(s) of users:
         *  <li> 0 - To all users</li>
         *  <li> 1 - To members</li>
         *  <li> 2 - To admins only</li>
         * </ul>
         */
        
"debugLevel" => 1,
        
/**#@-*/

        /**#@+
         * Imagemanager // hack
         *
         * <p>Relative path to default/custom imagemanager</p>
         */
        //"Imagemanager" => "/imagemanager.php", // XOOPS default image manager
        
"Imagemanager" => "/modules/imagemanager/imagemanager.php",
        
/**#@-*/
    
);

?>




2. modify funcion "codeIcon" in "/class/xoopsform/formdhtmltextarea.php"

function codeIcon()
    {
        
// get imagemanager form xoopsconfig.php
        
$configs =@ include $GLOBALS['xoops']->path"var/configs/xoopsconfig.php" ); // hack
        
$Imagemanager = @$configs['Imagemanager']; // hack

        
$textarea_id $this->getName();
        
$code "<a name='moresmiley'></a>" .
            
"<img src='" XOOPS_URL "/images/url.gif' alt='" _XOOPS_FORM_ALT_URL "' title='" _XOOPS_FORM_ALT_URL "' onclick='xoopsCodeUrl("{$textarea_id}", "" . htmlspecialchars(_ENTERURL, ENT_QUOTES) . "", "" . htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES) . "");' onmouseover='style.cursor="hand"'/>&nbsp;" .
            
"<img src='" XOOPS_URL "/images/email.gif' alt='" _XOOPS_FORM_ALT_EMAIL "' title='" _XOOPS_FORM_ALT_EMAIL "' onclick='xoopsCodeEmail("{$textarea_id}", "" . htmlspecialchars(_ENTEREMAIL, ENT_QUOTES) . "");'  onmouseover='style.cursor="hand"'/>&nbsp;" .
            
"<img src='" XOOPS_URL "/images/imgsrc.gif' alt='" _XOOPS_FORM_ALT_IMG "' title='" _XOOPS_FORM_ALT_IMG "' onclick='xoopsCodeImg("{$textarea_id}", "" . htmlspecialchars(_ENTERIMGURL, ENT_QUOTES) . "", "" . htmlspecialchars(_ENTERIMGPOS, ENT_QUOTES) . "", "" . htmlspecialchars(_IMGPOSRORL, ENT_QUOTES) . "", "" . htmlspecialchars(_ERRORIMGPOS, ENT_QUOTES) . "", "" . htmlspecialchars(_XOOPS_FORM_ALT_ENTERWIDTH, ENT_QUOTES) . "");'  onmouseover='style.cursor="hand"'/>&nbsp;" .
            
//"<img src='" . XOOPS_URL . "/images/image.gif' alt='" . _XOOPS_FORM_ALT_IMAGE . "' title='" . _XOOPS_FORM_ALT_IMAGE . "' onclick='openWithSelfMain("" . XOOPS_URL . "/imagemanager.php/?target={$textarea_id}","imgmanager",400,430);'  onmouseover='style.cursor="hand"'/>&nbsp;" . // original
            
"<img src='" XOOPS_URL "/images/image.gif' alt='" _XOOPS_FORM_ALT_IMAGE "' title='" _XOOPS_FORM_ALT_IMAGE "' onclick='openWithSelfMain("" . XOOPS_URL . $Imagemanager . "/?target={$textarea_id}","imgmanager",400,430);'  onmouseover='style.cursor="hand"'/>&nbsp;" // hack
            
"<img src='" XOOPS_URL "/images/smiley.gif' alt='" _XOOPS_FORM_ALT_SMILEY "' title='" _XOOPS_FORM_ALT_SMILEY "' onclick='openWithSelfMain("" . XOOPS_URL . "/misc.php?action=showpopups&type=smilies&target={$textarea_id}","smilies",300,475);'  onmouseover='style.cursor="hand"'/>&nbsp;";
        
$myts =& MyTextSanitizer::getInstance();

        
$extensions array_filter($myts->config['extensions']);
        foreach (
array_keys($extensions) as $key) {
            
$extension $myts->loadExtension($key);
            @list(
$encode$js) = $extension->encode($textarea_id);
            if (empty(
$encode)) continue;
            
$code .= $encode;
            if (!empty(
$js)) {
                
$this->js .= $js;
            }
        }
        
$code .=
            
"<img src='" XOOPS_URL "/images/code.gif' alt='" _XOOPS_FORM_ALT_CODE "' title='" _XOOPS_FORM_ALT_CODE "' onclick='xoopsCodeCode("{$textarea_id}", "" . htmlspecialchars(_ENTERCODE, ENT_QUOTES) . "");'  onmouseover='style.cursor="hand"'/>&nbsp;" .
            
"<img src='" XOOPS_URL "/images/quote.gif' alt='" _XOOPS_FORM_ALT_QUOTE "' title='" _XOOPS_FORM_ALT_QUOTE "' onclick='xoopsCodeQuote("{$textarea_id}", "" . htmlspecialchars(_ENTERQUOTE, ENT_QUOTES) . "");' onmouseover='style.cursor="hand"'/>";
        return 
$code;
    }




3. download here http://luciorota.altervista.org/xoops ... nglefile.php?cid=3&lid=14 and install the MODULE imagemanager (tnx to XGarb)

4. try it!

A QUESTION TO ANY XOOPS GURU
What about this hack... might it be the right way?
Tell me if i'm loosing my time...

TNX

trabis

Core Developer
Posted on: 2009/8/19 15:18
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#2

Re: A way to modulize image manager

I'm not sure if we should do it on configuration or if using same method we use for profile and pm.

We could assume that if a module imagemanager exists and if it is active it should be used.

so you could use:
$module_handler =& xoops_gethandler('module');
$imagemanager_module $module_handler->getByDirname('imagemanager');
if (
$imagemanager_module && $imagemanager_module->getVar('isactive')) {


sailjapan

Moderator
Posted on: 2009/8/20 1:23
sailjapan
sailjapan (Show more)
Moderator
Posts: 1672
Since: 2005/11/16
#3

Re: A way to modulize image manager

I haven't tried this yet, but I applaud the initiative! I think a new imagemanager is much needed.

luciorota

Module Developer
Posted on: 2009/8/20 8:45
luciorota
luciorota (Show more)
Module Developer
Posts: 197
Since: 2007/4/20
#4

Re: A way to modulize image manager

Quote:

trabis wrote:
I'm not sure if we should do it on configuration or if using same method we use for profile and pm.

We could assume that if a module imagemanager exists and if it is active it should be used.


OR

an other possibility is to have imagemanager as System module plugin... what do you think about it?

trabis

Core Developer
Posted on: 2009/8/29 8:55
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#5

Re: A way to modulize image manager

Hi, we have implemented a preload system on xoops. This preload system is based on the observer pattern and it is very low level. It provides mechanism for modules to extend core. Core triggers events and observers(preloads) execute code related to those events.
Using preloads we can avoid hacking core(good for maintenance).
This preloads are now being used by profile module, pm module, protector module, xlanguage module and defacer module.
For example, if you want yogurt to do issue redirects in userinfo.php, you do not have to hack userinfo.php any more.

Old userinfo.php:
include dirname(__FILE__) . DIRECTORY_SEPARATOR 'mainfile.php';

$module_handler xoops_gethandler('module');
$profile_module $module_handler->getByDirname('profile');
if (
$profile_module && $profile_module->getVar('isactive')) {
    
header("location: ./modules/profile/userinfo.php" . (empty($_SERVER['QUERY_STRING']) ? "" "?" $_SERVER['QUERY_STRING']));
    exit();
}


New userinfo.php
include dirname(__FILE__) . DIRECTORY_SEPARATOR 'mainfile.php';

$xoopsPreload =& XoopsPreload::getInstance();
$xoopsPreload->triggerEvent('core.userinfo.start');


Any module can attach to this event and not just profile module.

So now that we have preloads, we can use this preload system to implement image manager. We just need to place this events triggers where they are needed. I imagine /class/xoopsform/formdhtmltextarea.php will need one!

trabis

Core Developer
Posted on: 2009/8/29 9:36
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#6

Re: A way to modulize image manager

OK, I added one preload point in formdhtmltextarea.php
old code
function codeIcon()
    {
        
$textarea_id $this->getName();
        
$code "<a name='moresmiley'></a>" "<img src='" XOOPS_URL "/images/url.gif' alt='" _XOOPS_FORM_ALT_URL "' title='" _XOOPS_FORM_ALT_URL "' onclick='xoopsCodeUrl("{$textarea_id}", "" . htmlspecialchars(_ENTERURL, ENT_QUOTES) . "", "" . htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES) . "");' onmouseover='style.cursor="hand"'/>&nbsp;" "<img src='" XOOPS_URL "/images/email.gif' alt='" _XOOPS_FORM_ALT_EMAIL "' title='" _XOOPS_FORM_ALT_EMAIL "' onclick='xoopsCodeEmail("{$textarea_id}", "" . htmlspecialchars(_ENTEREMAIL, ENT_QUOTES) . "");'  onmouseover='style.cursor="hand"'/>&nbsp;" "<img src='" XOOPS_URL "/images/imgsrc.gif' alt='" _XOOPS_FORM_ALT_IMG "' title='" _XOOPS_FORM_ALT_IMG "' onclick='xoopsCodeImg("{$textarea_id}", "" . htmlspecialchars(_ENTERIMGURL, ENT_QUOTES) . "", "" . htmlspecialchars(_ENTERIMGPOS, ENT_QUOTES) . "", "" . htmlspecialchars(_IMGPOSRORL, ENT_QUOTES) . "", "" . htmlspecialchars(_ERRORIMGPOS, ENT_QUOTES) . "", "" . htmlspecialchars(_XOOPS_FORM_ALT_ENTERWIDTH, ENT_QUOTES) . "");'  onmouseover='style.cursor="hand"'/>&nbsp;" "<img src='" XOOPS_URL "/images/image.gif' alt='" _XOOPS_FORM_ALT_IMAGE "' title='" _XOOPS_FORM_ALT_IMAGE "' onclick='openWithSelfMain("" . XOOPS_URL . "/imagemanager.php?target={$textarea_id}","imgmanager",400,430);'  onmouseover='style.cursor="hand"'/>&nbsp;" "<img src='" XOOPS_URL "/images/smiley.gif' alt='" _XOOPS_FORM_ALT_SMILEY "' title='" _XOOPS_FORM_ALT_SMILEY "' onclick='openWithSelfMain("" . XOOPS_URL . "/misc.php?action=showpopups&amp;type=smilies&amp;target={$textarea_id}","smilies",300,475);'  onmouseover='style.cursor="hand"'/>&nbsp;";
        
$myts = &MyTextSanitizer::getInstance();
        
        
$extensions array_filter($myts->config['extensions']);
        foreach(
array_keys($extensions) as $key) {
            
$extension $myts->loadExtension($key);
            @list (
$encode$js) = $extension->encode($textarea_id);
            if (empty(
$encode))
                continue;
            
$code .= $encode;
            if (! empty(
$js)) {
                
$this->js .= $js;
            }
        }
        
$code .= "<img src='" XOOPS_URL "/images/code.gif' alt='" _XOOPS_FORM_ALT_CODE "' title='" _XOOPS_FORM_ALT_CODE "' onclick='xoopsCodeCode("{$textarea_id}", "" . htmlspecialchars(_ENTERCODE, ENT_QUOTES) . "");'  onmouseover='style.cursor="hand"'/>&nbsp;" "<img src='" XOOPS_URL "/images/quote.gif' alt='" _XOOPS_FORM_ALT_QUOTE "' title='" _XOOPS_FORM_ALT_QUOTE "' onclick='xoopsCodeQuote("{$textarea_id}", "" . htmlspecialchars(_ENTERQUOTE, ENT_QUOTES) . "");' onmouseover='style.cursor="hand"'/>";

        
        return 
$code;
    }


new code
function codeIcon()
    {
        
$textarea_id $this->getName();
        
$code "<a name='moresmiley'></a>" "<img src='" XOOPS_URL "/images/url.gif' alt='" _XOOPS_FORM_ALT_URL "' title='" _XOOPS_FORM_ALT_URL "' onclick='xoopsCodeUrl("{$textarea_id}", "" . htmlspecialchars(_ENTERURL, ENT_QUOTES) . "", "" . htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES) . "");' onmouseover='style.cursor="hand"'/>&nbsp;" "<img src='" XOOPS_URL "/images/email.gif' alt='" _XOOPS_FORM_ALT_EMAIL "' title='" _XOOPS_FORM_ALT_EMAIL "' onclick='xoopsCodeEmail("{$textarea_id}", "" . htmlspecialchars(_ENTEREMAIL, ENT_QUOTES) . "");'  onmouseover='style.cursor="hand"'/>&nbsp;" "<img src='" XOOPS_URL "/images/imgsrc.gif' alt='" _XOOPS_FORM_ALT_IMG "' title='" _XOOPS_FORM_ALT_IMG "' onclick='xoopsCodeImg("{$textarea_id}", "" . htmlspecialchars(_ENTERIMGURL, ENT_QUOTES) . "", "" . htmlspecialchars(_ENTERIMGPOS, ENT_QUOTES) . "", "" . htmlspecialchars(_IMGPOSRORL, ENT_QUOTES) . "", "" . htmlspecialchars(_ERRORIMGPOS, ENT_QUOTES) . "", "" . htmlspecialchars(_XOOPS_FORM_ALT_ENTERWIDTH, ENT_QUOTES) . "");'  onmouseover='style.cursor="hand"'/>&nbsp;" "<img src='" XOOPS_URL "/images/image.gif' alt='" _XOOPS_FORM_ALT_IMAGE "' title='" _XOOPS_FORM_ALT_IMAGE "' onclick='openWithSelfMain("" . XOOPS_URL . "/imagemanager.php?target={$textarea_id}","imgmanager",400,430);'  onmouseover='style.cursor="hand"'/>&nbsp;" "<img src='" XOOPS_URL "/images/smiley.gif' alt='" _XOOPS_FORM_ALT_SMILEY "' title='" _XOOPS_FORM_ALT_SMILEY "' onclick='openWithSelfMain("" . XOOPS_URL . "/misc.php?action=showpopups&amp;type=smilies&amp;target={$textarea_id}","smilies",300,475);'  onmouseover='style.cursor="hand"'/>&nbsp;";
        
$myts = &MyTextSanitizer::getInstance();
        
        
$extensions array_filter($myts->config['extensions']);
        foreach(
array_keys($extensions) as $key) {
            
$extension $myts->loadExtension($key);
            @list (
$encode$js) = $extension->encode($textarea_id);
            if (empty(
$encode))
                continue;
            
$code .= $encode;
            if (! empty(
$js)) {
                
$this->js .= $js;
            }
        }
        
$code .= "<img src='" XOOPS_URL "/images/code.gif' alt='" _XOOPS_FORM_ALT_CODE "' title='" _XOOPS_FORM_ALT_CODE "' onclick='xoopsCodeCode("{$textarea_id}", "" . htmlspecialchars(_ENTERCODE, ENT_QUOTES) . "");'  onmouseover='style.cursor="hand"'/>&nbsp;" "<img src='" XOOPS_URL "/images/quote.gif' alt='" _XOOPS_FORM_ALT_QUOTE "' title='" _XOOPS_FORM_ALT_QUOTE "' onclick='xoopsCodeQuote("{$textarea_id}", "" . htmlspecialchars(_ENTERQUOTE, ENT_QUOTES) . "");' onmouseover='style.cursor="hand"'/>";
        
//this is only what was added
        
$xoopsPreload =& XoopsPreload::getInstance();
        
$xoopsPreload->triggerEvent('core.class.xoopsform.formdhtmltextarea.codeicon', array(&$code));
        return 
$code;
    }


Now you need to create a folder named preloads and a file inside named core.php
Then you add this inside:
<?php
/**
 * Image Manager
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
 * @license         http://www.fsf.org/copyleft/gpl.html& ...  public license
 * @package         imagemanager
 * @since           2.4.0
 * @author          trabis <lusopoemas@gmail.com>
 * @version         $Id: core.php 3333 2009-08-27 10:46:15Z trabis $
 */

defined('XOOPS_ROOT_PATH') or die('Restricted access');

/**
 * Image Manager core preloads
 *
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
 * @license         http://www.fsf.org/copyleft/gpl.html& ...  public license
 * @author          trabis <lusopoemas@gmail.com>
 */
class ImagemanagerCorePreload extends XoopsPreloadItem
{

    function 
eventCoreClassXoopsformFormdhtmltextareaCodeicon($args)
    {
        if (
ImagemanagerCorePreload::isActive()) {
            
$args[0] = str_replace('imagemanager.php''modules/imagemanager/imagemanager.php'$args[0]);
        }
    }

    function 
isActive()
    {
        
$module_handler =& xoops_getHandler('module');
        
$module $module_handler->getByDirname('imagemanager');
        return (
$module && $module->getVar('isactive')) ? true false;
    }
}
?>


Working with XOOPS 2.4.0 from trunk.

Mamba

Moderator
Posted on: 2009/8/29 10:30
Mamba
Mamba (Show more)
Moderator
Posts: 10797
Since: 2004/4/23
#7

Re: A way to modulize image manager

Trabis, this is awesome!!!

Now we could have 5 different ImageManagers, and user could choose one that is best for him, install it, and it would work seamlessly with XOOPS. I like it!

Now we just need an Image Manager/Editor!!!

for Image Editor, you could use one of these:

http://www.phpimageeditor.se/
http://www.ajaxprogrammer.com/?p=9
http://kozak.si/widethoughts/category/wideimage/
http://htmlblog.net/demo/pixidou/

If somebody could encapsulate one of them into the Image Manager, it would be awesome!

luciorota

Module Developer
Posted on: 2009/8/29 21:07
luciorota
luciorota (Show more)
Module Developer
Posts: 197
Since: 2007/4/20
#8

Re: A way to modulize image manager

Thanks Trabis... great improvement!!!

And now...

modulized image manager

THIS MODULE IS ONLY A TESTING MODULE... MAYBE I WILL NEVER IMPROVE IT... SORRY

Now, thanks to Trabis, now it runs well in XOOPS 240b2 WITHOUT HACKING XOOPS...
THIS IS A GREAT... GREAT... GREAT XOOPS revolution!!!
In XOOPS 240b2 JUST install this module


http://luciorota.altervista.org/xoops ... nglefile.php?cid=3&lid=14

luciorota

Module Developer
Posted on: 2009/9/2 10:53
luciorota
luciorota (Show more)
Module Developer
Posts: 197
Since: 2007/4/20
#9

Re: A way to modulize image manager

@Trabis

And if I would like to add a "preload point" also to XOOPS original image manager admin side? How can I?

This request is because I think that a new Image Manager should also change the Image manager admin side (or shouldn't?)

trabis

Core Developer
Posted on: 2009/9/2 12:36
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#10

Re: A way to modulize image manager

Hi, you can add preload triggers in system module. I'm following some conventions so the hook name reflects the path to the file + a short description: For your image manager you would likely use this code:
$xoopsPreload =& XoopsPreload::getInstance();

$xoopsPreload->triggerEvent('system.admin.images.main.start');

You can pass an array with triggerEvent $xoopsPreload->triggerEvent('hookname', $args);

Then you create in your preloads folder a system.php file with the following code (minimal)
<?php
class ImagemanagerSystemPreload extends XoopsPreloadItem
{

    function 
eventSystemAdminImagesMainStart($args)
    {
        
// any code goes here
    
}

}
?>


Creating extra system.php preload file is not really needed, it could go on the core.php you already have. It just help to make things clear.

What is really necessary for the trigger to work is that:
- you have a file in preloads folder with a class that extends
XoopsPreloadItem and follows ModuledirnameFilenamePreload convention
- class has a method that begins with 'event' followed by the hook name without '.'. Does not have to be Camel Case but it should!

After you have things working you can ask the Core Team to add the preload trigger in core.