1
luciorota
A way to modulize image manager
  • 2009/8/19 14:50

  • luciorota

  • Module Developer

  • Posts: 216

  • Since: 2007/4/20


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"


return array(
        
/**#@+
         * Extended HTML editor for {@link XoopsFormDhtmlTextArea}
         *
         * 

If an extended HTML editor is set, the renderer will be replaced by the specified editor, usually a visual or WYSIWYG editor.


         *
         * 
    Developer and user guide:
             *  
    • For run-time settings per call
               *          
    • To use an editor pre-configured by {@link XoopsEditor}, e.g. 'fckeditor': $options['editor'] = 'fckeditor';

    •          *          
    • To use a custom editor, e.g. 'MyEditor' class located in "/modules/myeditor/myeditor.php": $options['editor'] = array('MyEditor', XOOPS_ROOT_PATH . "/modules/myeditor/myeditor.php");

    •          *      

  •          *  
    • For pre-configured settings, which will force to use a editor if no specific editor is set for call
               *          
      • Set up custom configs: in XOOPS_VAR_PATH . '/configs/xoopsconfig.php' set a editor as default, e.g.
                 *                  
      • a pre-configured editor 'fckeditor': return array('editor' => 'fckeditor');

      •          *                  
      • a custom editor 'MyEditor' class located in "/modules/myeditor/myeditor.php": return array('editor' => array('MyEditor', XOOPS_ROOT_PATH . "/modules/myeditor/myeditor.php");

      •          *              

    •          *          
    • To disable the default editor, in XOOPS_VAR_PATH . '/configs/xoopsconfig.php': return array();

    •          *          
    • To disable the default editor for a specific call: $options['editor'] = 'dhtmltextarea';

    •          *      

  •          * 

         */
        //"editor"    => "fckeditor",
        //"editor"    => "dhtmlext",
        /**#@-*/


        /**#@+
         * Debug level for XOOPS
         *
         * Note: temporary solution only. Will be re-designed in XOOPS 3.0
         *
         * 
    Displaying debug information to different level(s) of users:
             *  
  •  0 - To all users

  •          *  
  •  1 - To members

  •          *  
  •  2 - To admins only

  •          * 

         */
        
"debugLevel" => 1,
        
/**#@-*/

        /**#@+
         * Imagemanager // hack
         *
         * 

Relative path to default/custom imagemanager


         */
        //"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 ".
            
"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"'/> " .
            
"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"'/> " .
            
"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"'/> " .
            
//" " . // original
            
"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"'/> " // hack
            
"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"'/> ";
        
$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 .=
            
"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"'/> " .
            
"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/modules/wfdownloads/singlefile.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

2
trabis
Re: A way to modulize image manager
  • 2009/8/19 15:18

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


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')) {



3
sailjapan
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.

4
luciorota
Re: A way to modulize image manager
  • 2009/8/20 8:45

  • luciorota

  • Module Developer

  • Posts: 216

  • Since: 2007/4/20


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?

5
trabis
Re: A way to modulize image manager
  • 2009/8/29 8:55

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


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!


6
trabis
Re: A way to modulize image manager
  • 2009/8/29 9:36

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


OK, I added one preload point in formdhtmltextarea.php
old code
function codeIcon()
    {
        
$textarea_id $this->getName();
        
$code ""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"'/> " "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"'/> " "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"'/> " "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"'/> " "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"'/> ";
        
$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 .= "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"'/> " "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 ""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"'/> " "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"'/> " "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"'/> " "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"'/> " "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"'/> ";
        
$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 .= "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"'/> " "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:
/**
 * 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 GNU public license
 * @package         imagemanager
 * @since           2.4.0
 * @author          trabis 
 * @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 GNU public license
 * @author          trabis 
 */
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.

7
Mamba
Re: A way to modulize image manager
  • 2009/8/29 10:30

  • Mamba

  • Moderator

  • Posts: 11381

  • Since: 2004/4/23


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!

8
luciorota
Re: A way to modulize image manager
  • 2009/8/29 21:07

  • luciorota

  • Module Developer

  • Posts: 216

  • Since: 2007/4/20


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/modules/wfdownloads/singlefile.php?cid=3&lid=14

9
luciorota
Re: A way to modulize image manager
  • 2009/9/2 10:53

  • luciorota

  • Module Developer

  • Posts: 216

  • Since: 2007/4/20


@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?)

10
trabis
Re: A way to modulize image manager
  • 2009/9/2 12:36

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


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)
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.

Login

Who's Online

170 user(s) are online (31 user(s) are browsing Support Forums)


Members: 0


Guests: 170


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Oct 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits