Beispiel #1
0
function upgrade_db($out = false)
{
    loader_import('saf.File.Directory');
    $files = Dir::find('*-' . upgrade_version_num() . '.sql', 'upgrade');
    if (count($files) == 0) {
        return true;
    }
    $file = array_shift($files);
    $sql = join('', file($file));
    $sql = sql_split($sql);
    foreach ($sql as $query) {
        if ($out) {
            echo '<pre>' . $query . '</pre>';
        }
        if (!db_execute($query)) {
            return false;
        }
    }
    return true;
}
Beispiel #2
0
 public function postElimDir()
 {
     $id = Input::get('id');
     $dir = Dir::find($id);
     $dir->deleted = 1;
     if ($dir->save()) {
         return Response::json(array('type' => 'success', 'msg' => 'Se ha eliminado la dirección.'));
     } else {
         return Response::json(array('type' => 'danger', 'msg' => 'Error al eliminar la dirección.'));
     }
 }
Beispiel #3
0
 /**
  * List all the services for a given app.  Return value is a 2-dimensional
  * array, with the keys being the service names, and the values being the
  * parsed contents of the service.php files.
  *
  * @access public
  * @param string
  * @return array
  *
  */
 function getServices($app)
 {
     $services = array();
     loader_import('saf.File.Directory');
     $files = Dir::find('service.php', 'inc/app/' . $app . '/boxes', true);
     foreach ($files as $file) {
         $c = ini_parse($file, false);
         $c['handler'] = 'box:' . str_replace('inc/app/' . $app . '/boxes', $app, $file);
         $c['handler'] = str_replace('/service.php', '', $c['handler']);
         $c['actions'] = preg_split('/, ?/', $c['actions']);
         $c['active'] = Workflow::active($c['name'], $c['actions']);
         $services[$c['name']] = $c;
     }
     return $services;
 }
Beispiel #4
0
    /**
     * Returns the display HTML for this widget.  The optional
     * parameter determines whether or not to automatically display the widget
     * nicely, or whether to simply return the widget (for use in a template).
     * 
     * @access	public
     * @param	boolean	$generate_html
     * @return	string
     * 
     */
    function display($generate_html = 0)
    {
        $_dl = new MF_Widget_select('MF_' . $this->name . '_DIRLIST');
        $_dl->extra = $this->extra;
        $dir = new Dir($this->directory);
        if ($this->recursive == 0) {
            $list = $dir->read_all();
            $goodlist = array();
            $dir->close();
            foreach ($list as $file) {
                if (!eregi('^\\.ht', $file) && (eregi('\\.(' . join('|', $this->extensions) . ')$', $file) || count($this->extensions) == 0) && $file != '.' && $file != '..') {
                    $goodlist[$file] = $file;
                }
            }
        } else {
            $goodlist = array();
            // recurse
            $list = $dir->find('*', $this->directory, 1);
            for ($i = 0; $i < count($list); $i++) {
                if (!@is_dir($list[$i]) && !eregi('^\\.ht', $list[$i]) && (eregi('\\.(' . join('|', $this->extensions) . ')$', $list[$i]) || count($this->extensions) == 0) && $list[$i] != '.' && $list[$i] != '..') {
                    $list[$i] = preg_replace('/^' . preg_quote($this->directory . '/', '/') . '/', '', $list[$i]);
                    $goodlist[$list[$i]] = $list[$i];
                }
            }
        }
        $_dl->setValues($goodlist);
        $_dl->data_value = $this->data_value_DIRLIST;
        $_dirlist = new MF_Widget_hidden($this->name);
        $data = '';
        if ($this->show_viewbutton) {
            global $intl;
            $data .= '<script language="JavaScript">
<!--

function ' . $this->name . '_preview (name, params, formname) {
	// get src from form widget
	path = "' . $this->web_path . '/' . '" + document.forms[formname].elements[name].options[document.forms[formname].elements[name].selectedIndex].value;

	pop = window.open (\'\', name, params);
	pop.document.open ();
	pop.document.write (\'<link rel="stylesheet" type="text/css" href="css/site.css" />\');
	pop.document.write (\'<div align="center">\');
	pop.document.write (\'<img src="\' + path + \'" alt="\' + name + \'" border="0" />\');
	pop.document.write (\'<br /><br /><a href="#" onclick="window.close ()">' . $intl->get('Close Window') . '</a></div>\');
}

// -->
</script>';
            $showbutton = '&nbsp;<a href="#" onclick="' . $this->name . '_preview (\'MF_' . $this->name . '_DIRLIST\', \'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,dependent=no,fullscreen=no,width=300,height=300,top=50,left=160\', \'' . $this->formname . '\')">' . $intl->get('Preview') . '</a>';
        } else {
            $showbutton = '';
        }
        if ($generate_html) {
            $data .= $_dirlist->display(0) . "\n";
            $data .= "\t<tr>\n\t\t<td>" . '<label for="' . $this->name . '"' . $this->invalid() . '>' . $this->display_value . "</label></td>\n\t\t<td>" . $_dl->display(0) . $showbutton . "</td>\n\t</tr>\n";
        } else {
            $data .= $_dirlist->display(0);
            $data .= $_dl->display(0);
            $data .= $showbutton;
        }
        return $data;
    }
Beispiel #5
0
    $style = str_replace(' ', '', $style);
    //find last slash
    $lastslash = strrpos($style, '/');
    //break up $style into file and folder
    $file_name = substr($style, $lastslash + 1);
    $style_path = substr($style, 0, $lastslash);
    //remove leading inc/html/ from path
    $style_path = str_replace('inc/html/', '', $style_path);
    if (substr($style_path, 0, 1) == '/') {
        $style_path = substr($style_path, 1);
    }
    $name = str_replace('.css', '', $file_name);
    $data['styles'][] = array('path' => $style_path, 'file' => $file_name, 'name' => $name);
}
//the below code populates $data['images']
$allfiles = Dir::find('*.(jpg|png|gif)', 'inc/html/' . $path . '/pix');
//info($allfiles);
foreach ($allfiles as $image) {
    if (strpos($image, '/.') || @is_dir($image) || strpos($image, 'CVS')) {
        continue;
    }
    $width;
    $height;
    //remove whitespace from file
    $image = str_replace(' ', '', $image);
    //find last slash
    $lastslash = strrpos($image, '/');
    //break up $image into file and folder
    $file_name = substr($image, $lastslash + 1);
    $image_path = substr($image, 0, $lastslash);
    //remove leading inc/html/ from path
Beispiel #6
0
function help_get_pages($appname, $lang)
{
    loader_import('saf.File.Directory');
    $files = Dir::find('*.html', 'inc/app/' . $appname . '/docs/' . $lang);
    if (count($files) == 0) {
        return array();
        // no help files
    }
    foreach ($files as $k => $v) {
        if (strstr($v, '/.')) {
            unset($files[$k]);
        }
    }
    sort($files);
    return $files;
}
Beispiel #7
0
 /**
  * Retrieves the data from  and stores it in $data.
  */
 function getData()
 {
     foreach (Dir::find('*.php', $this->dir, false) as $file) {
         if (strpos($file, '.') === 0) {
             continue;
         }
         $inidata = ini_parse($file, true);
         $this->data[$inidata['role']['name']] = $inidata;
     }
 }
Beispiel #8
0
<?php

// BEGIN CLI KEEPOUT CHECKING
if (php_sapi_name() !== 'cli') {
    // Add these lines to the very top of any file you don't want people to
    // be able to access directly.
    header('HTTP/1.1 404 Not Found');
    echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" . "<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n" . "The requested URL " . $PHP_SELF . " was not found on this server.<p>\n<hr>\n" . $_SERVER['SERVER_SIGNATURE'] . "</body></html>";
    exit;
}
// END CLI KEEPOUT CHECKING
include_once 'init.php';
$loader->import('saf.File.Directory');
$skip = '/^lib\\/(CVS|Ext|PEAR)/';
$files = Dir::find('*.php', 'lib', 1);
$new_tests = array();
foreach ($files as $k => $file) {
    if (preg_match($skip, $file)) {
        unset($files[$k]);
        continue;
    }
    $test_file = preg_replace('/\\.php$/', '', strtolower($file));
    $test_file = explode('/', $test_file);
    array_shift($test_file);
    if ($test_file[0] == $test_file[1]) {
        array_shift($test_file);
    }
    if ($test_file[count($test_file) - 1] == $test_file[count($test_file) - 2]) {
        array_pop($test_file);
    }
    $test_file = join('_', $test_file) . '.phpt';
Beispiel #9
0
    foreach ($settings as $k => $v) {
        if ($k == 'Meta') {
            continue;
        }
        $attrs[] = (object) array('name' => $k, 'typedef' => ini_write($v));
    }
    //info ($settings);
} else {
    $attrs = db_fetch_array('select * from xed_attributes where element = ? order by id asc', $cgi->tag);
    $defaults = db_fetch_array('select * from xed_attributes where element = ? order by id asc', 'default');
    $attrs = array_merge($attrs, $defaults);
}
$css = new CSS_Parser();
$classes = array();
$ids = array();
foreach (Dir::find('*.css', 'inc/html/' . conf('Server', 'default_template_set')) as $file) {
    $css->parse(@join('', @file($file)));
    $classes = array_merge($classes, $css->getClasses($cgi->tag));
    $ids = array_merge($ids, $css->getIDs($cgi->tag));
}
$classes = array_unique($classes);
$ids = array_unique($ids);
$form = new MailForm();
ini_add_filter('ini_filter_split_comma_single', array('rule 0', 'rule 1', 'rule 2', 'rule 3', 'rule 4', 'rule 5', 'rule 6', 'rule 7', 'rule 8', 'button 0', 'button 1', 'button 2', 'button 3', 'button 4', 'button 5', 'button 6', 'button 7', 'button 8', 'submitButtons'));
foreach ($attrs as $attr) {
    $w =& $form->createWidget($attr->name, ini_parse($attr->typedef, false));
    if (isset($cgi->{$attr->name})) {
        $w->setDefault($cgi->{$attr->name});
    }
}
ini_clear();
Beispiel #10
0
<?php

loader_import('saf.File.Directory');
$parameters['images'] = Dir::find('*.jpg', 'pix/' . $parameters['folder']);
header('Content-Type: text/xml');
echo template_simple('xml.spt', $parameters);
exit;
Beispiel #11
0
<?php

global $cgi;
$data = array();
$content_types = array();
$GLOBALS['_content_weights'] = array();
$applications = parse_ini_file('inc/conf/auth/applications/index.php');
loader_import('saf.File.Directory');
$files = Dir::find('*.php', 'inc/app/cms/conf/collections', false);
foreach ($files as $file) {
    if (strstr($file, '/.')) {
        continue;
    }
    $data = ini_parse($file);
    $GLOBALS['_content_weights'][$data['Collection']['name']] = $data['Collection']['list_weight'];
    if (!isset($data['Collection']['visible']) || $data['Collection']['visible'] != false) {
        if (session_is_resource($data['Collection']['name']) && !session_allowed($data['Collection']['name'], 'rw', 'resource')) {
            continue;
        }
        if (isset($data['Collection']['app']) && isset($applications[$data['Collection']['app']]) && !$applications[$data['Collection']['app']]) {
            continue;
        }
        $content_types[$data['Collection']['name']] = intl_get($data['Collection']['display']);
    }
}
function cms_collection_sort($a, $b)
{
    global $_content_weights, $_content_types;
    if ($a == $b) {
        return 0;
    }
Beispiel #12
0
 /**
  * COPY method handler
  *
  * @param  array  general parameter passing array
  * @return bool   true on success
  */
 function COPY($options, $del = false)
 {
     // TODO Property updates still broken (Litmus should detect this?)
     $options['path'] = rtrim($this->_path(), '/');
     $options['dest'] = rtrim($this->_fix_name($options['dest']), '/');
     // $options['path'] is '/path/file1.ext'
     // $options['dest'] is '/path/file2.ext'
     // these do not include /webfiles-app nor /inc/data
     // strip dot-files
     if (strpos($options['dest'], '/.') !== false) {
         $this->_debug(__LINE__, 403, 'Can\'t upload dot-files: ' . $options['dest']);
         return '403 Forbidden';
     }
     if ($del && $this->checkLock($options['path'], true)) {
         $this->_debug(__LINE__, 423, 'Locked: ' . $options['path']);
         return '423 Locked';
     }
     if (!empty($this->_SERVER["CONTENT_LENGTH"])) {
         // no body parsing yet
         $this->_debug(__LINE__, 415, 'Unsupported media type?');
         return "415 Unsupported media type";
     }
     // no copying to different WebDAV Servers yet
     // dest_url is set if the url is not within the same webdav repository
     if (isset($options["dest_url"])) {
         $this->_debug(__LINE__, 502, 'Can\'t copy from one repos to another: ' . $options['dest_url']);
         return "502 bad gateway";
     }
     // $source is inc/data/path/file1.ext
     $source = strtolower($this->base . $options["path"]);
     if (!file_exists($source)) {
         $this->_debug(__LINE__, 404, 'Not found: ' . $source);
         return "404 Not found";
     }
     // $dest is inc/data/path/file2.ext
     $dest = strtolower($this->base . $options["dest"]);
     $new = !file_exists($dest);
     $existing_col = false;
     // this part is still fuzzy...
     if (!$new) {
         if ($del && is_dir($dest)) {
             if (!$options["overwrite"]) {
                 $this->_debug(__LINE__, 412, 'Conditions failed since dir already exists: ' . $dest . ' (new=false, del=true, is_dir=true, overwrite=false)');
                 return "412 precondition failed";
             }
             //$dest .= basename ($source);
             //if (file_exists ($dest)) {
             //	$options["dest"] .= basename ($source);
             //} else {
             //	$new		  = true;
             //	$existing_col = true;
             //}
         }
     }
     // delete destination first if we're overwriting
     if (!$new) {
         if ($options["overwrite"]) {
             if (@file_exists($dest)) {
                 $stat = $this->DELETE(array("dest" => $options["dest"]));
                 if ($stat[0] != "2" && substr($stat, 0, 3) != "404") {
                     $this->_debug(__LINE__, substr($stat, 0, 3), 'Failed on delete: ' . $options['dest']);
                     return $stat;
                 }
             }
         } elseif (@file_exists($dest) && !$options['overwrite']) {
             $this->_debug(__LINE__, 412, 'Conditions failed since file already exists: ' . $dest . ' (new=false, file_exists=true, overwrite=false)');
             return "412 precondition failed";
         }
     }
     //if (is_dir ($source) && ($options["depth"] != "infinity")) {
     // RFC 2518 Section 9.2, last paragraph
     //return "400 Bad request";
     //}
     if ($del) {
         loader_import('saf.File.Directory');
         if (is_dir($source)) {
             $files = array_merge(array($source), Dir::find('*', $source, 1));
             //$files = array_reverse ($files);
             if (!is_array($files) || count($files) == 0) {
                 $this->_debug(__LINE__, 500, 'No files from source: ' . $source);
                 return '500 Internal server error';
             }
             // todo: handle recursive moves!!!
             foreach ($files as $file) {
                 if ($file == $source) {
                     if (!mkdir($dest, 0777)) {
                         $this->_debug(__LINE__, 409, 'Mkdir failed: ' . $dest);
                         return '409 Conflict';
                     }
                 } elseif (is_dir($file)) {
                     $destfile = str_replace($source, $dest, $file);
                     $res = Dir::build($destfile, 0777);
                     if (!$res) {
                         $this->_debug(__LINE__, 409, 'Mkdir recursive failed: ' . $destfile);
                         return '409 Conflict';
                     }
                 } elseif (!@is_dir($file)) {
                     $info = $this->rex->getCurrent(preg_replace('|^inc/data/|', '', $file));
                     if (!session_allowed($info, 'rw')) {
                         $this->_debug(__LINE__, 403, 'Permissions failed: ' . $this->rex->error . ' (' . $info->name . ')');
                         return '403 Forbidden';
                     }
                     $destfile = str_replace($source, $dest, $file);
                     $method = $this->rex->determineAction(preg_replace('|^inc/data/|', '', $file));
                     $res = $this->rex->{$method}(preg_replace('|^inc/data/|', '', $file), array('name' => preg_replace('|^inc/data/|', '', $destfile)));
                     if (!$res) {
                         $this->_debug(__LINE__, 500, 'Unknown rex error: ' . $this->rex->error . ' (' . $destfile . ')');
                         return '500 Internal server error';
                     }
                 }
             }
             // erase the source once everything's been moved over successfully
             if (@file_exists($source)) {
                 $this->DELETE(array('dest' => $options['path']));
             }
         } else {
             $info = $this->rex->getCurrent(trim($options['path'], '/'));
             if (!session_allowed($info, 'rw')) {
                 $this->_debug(__LINE__, 403, 'Permissions failed: ' . $info->name);
                 return '403 Forbidden';
             }
             $method = $this->rex->determineAction(trim($options['path'], '/'));
             $res = $this->rex->{$method}(trim($options['path'], '/'), array('name' => trim($options['dest'], '/')));
             if (!$res) {
                 $this->_debug(__LINE__, 500, 'Unknown rex error: ' . $this->rex->error . ' (' . $options['dest'] . ')');
                 return '500 Internal server error';
             }
         }
     } else {
         loader_import('saf.File.Directory');
         if (is_dir($source)) {
             //$files = System::find ($source);
             $files = array_merge(array($source), Dir::find('*', $source, 1));
             $files = array_reverse($files);
         } else {
             $files = array($source);
         }
         $single = count($files) == 1 ? true : false;
         if (!is_array($files) || count($files) == 0) {
             $this->_debug(__LINE__, 500, 'No files from source: ' . $source);
             return "500 Internal server error";
         }
         foreach ($files as $file) {
             if (is_dir($file)) {
                 $file = $this->_slashify($file);
             }
             $destfile = str_replace($source, $dest, $file);
             if (is_dir($file)) {
                 if (!is_dir($destfile)) {
                     $res = Dir::build($destfile, 0777);
                     if (!$res) {
                         $this->_debug(__LINE__, 409, 'Mkdir recursive failed: ' . $destfile);
                         return '409 Conflict';
                     }
                 }
             } else {
                 if ($single && !@is_dir(dirname($destfile))) {
                     $this->_debug(__LINE__, 409, 'Not a directory: ' . $destfile);
                     return '409 Conflict';
                 }
                 if (!$options['overwrite'] && @file_exists($destfile)) {
                     $this->_debug(__LINE__, 409, 'File exists, overwrite not set: ' . $destfile);
                     return '409 Conflict';
                 }
                 $info = (array) $this->rex->getCurrent(preg_replace('|^inc/data/|', '', $file));
                 if (!session_allowed($info, 'r')) {
                     $this->_debug(__LINE__, 403, 'Permissions failed: ' . $info['name']);
                     return '403 Forbidden';
                 }
                 $info['name'] = preg_replace('|^inc/data/|', '', $destfile);
                 unset($info['filesize']);
                 unset($info['last_modified']);
                 unset($info['date_created']);
                 $info['sitellite_status'] = 'draft';
                 $info['sitellite_access'] = 'private';
                 $res = $this->rex->create($info, 'Copied via WebDAV.');
                 if (!$res) {
                     $this->_debug(__LINE__, 409, 'Unknown rex error: ' . $this->rex->error . ' (' . $infp['name'] . ')');
                     return "409 Conflict";
                 }
             }
         }
     }
     return $new && !$existing_col ? "201 Created" : "204 No Content";
 }
Beispiel #13
0
<?php

loader_import('saf.File.Directory');
loader_import('monoslideshow.Functions');
if (!empty($parameters['folder'])) {
    $folder = 'pix/' . $parameters['folder'];
} else {
    $folder = 'pix';
}
$images = Dir::find('*.jpg', $folder);
$parameters['images'] = array();
$parameters['album_thumb'] = false;
foreach ($images as $image) {
    $thumb = monoslideshow_thumbnail($image);
    $parameters['images'][] = array('image' => $image, 'thumb' => $thumb);
    if (!$parameters['album_thumb']) {
        $parameters['album_thumb'] = $thumb;
    }
}
//info ($parameters);
//exit;
header('Content-Type: text/xml');
echo template_simple('xml.spt', $parameters);
exit;
Beispiel #14
0
 /**
  * Compiles all the data for a given class and its properties and methods.
  */
 function getClass($package, $cls)
 {
     $app = array_shift(explode('.', $package));
     if ($app == 'saf') {
         $prefix = 'saf/lib/';
     } else {
         $prefix = 'inc/app/' . $app . '/lib/';
     }
     if (@is_dir($prefix . str_replace($app . '.', '', $package))) {
         $files = Dir::find('*.php', $prefix . str_replace($app . '.', '', $package), true);
     } else {
         $files = array();
     }
     if (@file_exists($prefix . str_replace($app . '.', '', $package) . '.php')) {
         $files[] = $prefix . str_replace($app . '.', '', $package) . '.php';
     } elseif (@file_exists($prefix . '_' . str_replace($app . '.', '', $package) . '.php')) {
         $files[] = $prefix . '_' . str_replace($app . '.', '', $package) . '.php';
     }
     $out = array('name' => $cls, 'package' => $package, 'info' => array(), 'vars' => array(), 'methods' => array(), 'params' => array());
     $class = false;
     $class_name = false;
     $class_count = 0;
     $count = 0;
     foreach ($files as $file) {
         $src = file_get_contents($file);
         $tokens = token_get_all($src);
         foreach ($tokens as $k => $token) {
             if (is_string($token)) {
                 if (strpos($token, '{') !== false) {
                     $count++;
                 } elseif (strpos($token, '}') !== false) {
                     $count--;
                     if ($class !== false && $count <= $class_count) {
                         $class = false;
                         $class_count = 0;
                     }
                 }
                 continue;
             }
             if ($token[0] == T_CLASS) {
                 $class = true;
                 $class_count = $count;
                 $class_name = $tokens[$k + 2][1];
                 if ($class_name == $cls) {
                     $info = Docs::_getClass($k, $tokens);
                     $out['extends'] = $info->class_extends;
                     $out['comment'] = $info->comment;
                     $out['code'] = $info->code;
                     $out['params'] = $info->params;
                 }
             }
             if ($token[0] == T_VAR && count($out['methods']) == 0) {
                 $out['vars'][$tokens[$k + 2][1]] = Docs::_getVar($k, $tokens);
             }
             if ($token[0] == T_FUNCTION) {
                 if ($class && $class_name == $cls) {
                     if ($tokens[$k + 2] == '&') {
                         $out['methods'][$tokens[$k + 3][1]] = Docs::_getFunction($k, $tokens);
                     } else {
                         $out['methods'][$tokens[$k + 2][1]] = Docs::_getFunction($k, $tokens);
                     }
                 }
             }
         }
     }
     return $out;
 }
Beispiel #15
0
    $apps[$apps[$k]] = Workflow::getServices($k);
    unset($apps[$k]);
}
if (empty($cgi->submit_button)) {
    echo template_simple('workflow.spt', $apps);
} else {
    $services = array();
    foreach ($apps as $app) {
        foreach ($app as $service) {
            if ($parameters[$service['name']]) {
                foreach ($service['actions'] as $action) {
                    if (!is_array($services[$action])) {
                        $services[$action] = array();
                    }
                    $services[$action]['service:' . $service['name']] = array('name' => $service['title'], 'handler' => $service['handler']);
                }
            }
        }
    }
    loader_import('saf.File');
    loader_import('saf.File.Directory');
    foreach ($services as $action => $servs) {
        file_overwrite('inc/app/cms/conf/services/' . $action . '.php', ini_write($servs));
    }
    foreach (Dir::find('*.php', 'inc/app/cms/conf/services') as $file) {
        if (!isset($services[str_replace('.php', '', basename($file))])) {
            file_overwrite($file, ini_write(array()));
        }
    }
    echo '<p>' . intl_get('Workflow settings saved.') . '  <a href="' . site_prefix() . '/index/cms-cpanel-action">' . intl_get('Continue') . '</a></p>';
}
Beispiel #16
0
 /**
  * Searches a directory or directories (recursively) for a file
  * that matches a given pattern.
  * 
  * @access	public
  * @param	string	$pattern
  * @param	string	$basedir
  * @param	boolean	$recursive
  * @return	array
  * 
  */
 function find($pattern = '*', $basedir, $recursive = 0)
 {
     $dir = new Dir($basedir);
     $res = array();
     $files = $dir->read_all();
     //echo "evaluating $basedir...\n";
     foreach ($files as $file) {
         if ($file == '.' || $file == '..') {
             continue;
         }
         //echo "trying file $file...\n";
         if ($dir->matches($pattern, $file)) {
             array_push($res, $basedir . '/' . $file);
         }
         //exit;
         if ($recursive && is_dir($basedir . '/' . $file)) {
             $new_res = Dir::find($pattern, $basedir . '/' . $file, $recursive);
             // add $new_res to $res
             foreach ($new_res as $n) {
                 array_push($res, $n);
             }
         }
     }
     $dir->close();
     return $res;
 }