Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - Version 4.3

[eluser]Sam Dark[/eluser]
Are there v.5.x version similar to 4.2.05?

[eluser]wiredesignz[/eluser]
Yes Sam, version 4.2 is based on the new version 5.0

[eluser]Sam Dark[/eluser]
Some code from Russian community, © AndrewWB.

Allows nested view folders for modules.

modules_helper.php, modules_find():
Code:
/** Find a file
    *
    * Scans for files located anywhere within application/modules directory.
    * Also scans application directories for config, controllers, models and views.
    * Generates fatal error on file not found.
    *
    * Hack by Andrew <[email protected]>
    *
    **/
    function modules_find($file, $path = '', $base = 'controllers/', $subpath = '')
    {
        
        $spath = '';
                
        if (($pos = strrpos($file, '/')) !== FALSE)
        {
            $exp = explode('/', $file);
            
            if (is_array($exp) AND sizeof($exp) > 0){
                
                $c = 1;
                $size = sizeof($exp);
                
                foreach ($exp as $k => $v){

                    if ($size > $c){
                        if ($c > 2) { $spath .= '/'; }
                        $spath .= $v;
                    } else {
                        $file = $v;
                    }
                    
                    $c++;
                }                
            }

        } else {
            $spath = '';
        }

        ($path) AND $path .= '/';
        ($spath) AND $spath .= '/';
                    
        /* scan module directory first */
        $paths2scan = array(MODBASE.$path.$base.$spath);
          
        /* then scan application directories for these types */
        if (in_array($base, array('controllers/', 'models/', 'views/')))
        {
            $paths2scan = array_merge($paths2scan, array(APPPATH.$base.$spath, APPPATH.$base.$path.$spath));
        }

        /* and also scan sub-directories */
        if ($subpath)
        {
            $subpath .= '/';

            $paths2scan = array_merge($paths2scan, array(MODBASE.$path.$base.$subpath, APPPATH.$base.$subpath));
        }
                        
        /* then scan further sub-directories for language */
        if (in_array($base, array('language/')))

            $paths2scan = array_merge($paths2scan, array(MODBASE.$subpath.$base.$path));


        $file_ext = strpos($file, '.') ? $file : $file.EXT;

        foreach ($paths2scan as $path2)
        {
            /* echo '<p>',$path2,$file_ext,'</p>'; /* debug paths */

            foreach (array($file_ext, ucfirst($file_ext)) as $name)
            {
                if (is_file($path2.$name))

                    return array($path2, $file, substr($path, 0, -1));
            }
        }

        /* file not found */

        /* don't die just yet, we handle these types back in the caller */
        if (in_array($base, array('config/', 'controllers/', 'helpers/', 'language/', 'libraries/', 'plugins/')))

            return array(FALSE, $file, FALSE);


        /* ok, die now */
        show_error("Unable to locate the requested file: ".$path2.$file_ext);
    }

[eluser]wiredesignz[/eluser]
Thats weird Sam, modules_find already scans for views in view/sub-directories that match the controller name.

That code does the same job as the code already in modules_find but the extra segment $spath will slow the whole search process.

[eluser]sophistry[/eluser]
wiredesignz... i'm trying to make a moblogging module using ME as a test.

i just tried loading a plugin (file is in applications/modules/moblog/plugins/pretty_print_pi.php).

the error is can't load file and the filename has an extra _pi appended to it, so for some reason load_module() in modules_helper gets a request for pretty_print_pi_pi.php and of course, it can find that file. i solved it by just renaming the file with two _pi suffixes, but that is just wrong.

do you know why two suffixes are being added to the plugin filename? is there a fix?

thanks!

[eluser]wiredesignz[/eluser]
@Sophistry, you don't need to use the _pi extension in your code. ME and CI both add the extension for you.
Code:
$this->load->plugin('pretty_print');

[eluser]sophistry[/eluser]
yes, sorry for not posting my code snippet! that is what i did, (meaning i have exactly the code you wrote above) but somewhere another _pi is being added. not sure where that is happening except that it is already part of the $file argument sent to modules_load_file() function in the modules_helper.php. (meaning by the time it is getting sent to the modules_load_file() function it already has two _pi suffixes added.

thanks!

[eluser]wiredesignz[/eluser]
@sophistry, Yes you are totally correct, ME plugin loader has a bug (adds _pi then CI adds _pi)

Try changing these lines in ME Controller
Code:
//Controller.php - line 369
list($path, $_plugin) = modules_find($plugin.'_pi', $this->_module, 'plugins/');    
        
//Controller.php - line 378
modules_load_file($_plugin, $path);
Let me know how it goes. Thanks sophistry ;)

[eluser]sophistry[/eluser]
great! that worked. thanks for the fix.

now, back to "plugging" along.

[eluser]wiredesignz[/eluser]
@sophistry, Thank you, I will add this fix to next upload. Wink




Theme © iAndrew 2016 - Forum software by © MyBB