Beispiel #1
0
function dir2array($dir, $content)
{
    if ($dir[strlen($dir) - 1] != '/') {
        $dir .= '/';
    }
    if (!is_dir($dir)) {
        return array();
    }
    $dir_handle = opendir($dir);
    $array = array();
    while ($object = readdir($dir_handle)) {
        if (!in_array($object, array('.', '..'))) {
            $filepath = $dir . $object;
            $file_object = array('name' => $object, 'path' => $dir, 'size' => filesize($filepath), 'type' => filetype($filepath), 'node' => fileinode($filepath), 'group' => filegroup($filepath), 'time' => getTime($filepath), 'perms' => getPermissions($filepath));
            if ($file_object['type'] == 'dir') {
                if ($content == true) {
                    $file_object['content'] = dir2array($filepath, $content);
                }
            } else {
                if ($content == true) {
                    $file_object['content'] = file2base64($filepath);
                }
                $file_object['mime'] = getMime($filepath);
            }
            $array[] = $file_object;
        }
    }
    return $array;
}
/**
 * This function takes a directory and maps its content
 * out into an Array. An easier form of doing a CMS
 * without needing to build big tools.
 */
function dir2array($directory, $map = null)
{
    $CI =& get_instance();
    $CI->load->helpers(array('directory', 'file', 'url', 'typography'));
    if (!$map || !is_array($map)) {
        $map = directory_map($directory);
    }
    $text_extensions = array('txt');
    $html_extensions = array('htm', 'html');
    $url_extensions = array('url');
    $data = array();
    foreach ($map as $key => $item) {
        // respect numeric order, 11 should not be in front of 2
        $key_split = explode("--", $key);
        $skey = $key;
        // recurse
        if (is_array($item)) {
            if (count($key_split) > 1) {
                if (is_numeric($key_split[0])) {
                    $skey = $key_split[0];
                }
            }
            $data[$skey] = dir2array($directory . '/' . $key, $item);
            // parse
        } else {
            $info = pathinfo($item);
            $ext = $info['extension'];
            $name = $info['filename'];
            if (in_array($ext, $text_extensions) || in_array($ext, $html_extensions)) {
                $text = read_file($directory . '/' . $item);
                if (in_array($ext, $text_extensions)) {
                    $text = auto_typography($text);
                }
                $data[$name] = $text;
            } else {
                if (in_array($ext, $url_extensions)) {
                    $url = explode("\n", $project['link']);
                    if (count($url) > 1) {
                        $data[$name] = array('text' => $url[0], 'url' => $url[1]);
                    } else {
                        $data[$name] = array('url' => $url[0]);
                    }
                } else {
                    $data[$info['filename']] = base_url($directory . '/' . $item);
                }
            }
        }
    }
    ksort($data);
    return $data;
}
function dir2array($dir)
{
    $rv = array();
    foreach (scandir($dir) as $fn) {
        if ($fn == "." or $fn == "..") {
            continue;
        }
        $fn_new = $dir . "/" . $fn;
        if (is_dir($fn_new)) {
            $rv[$fn] = dir2array($fn_new);
        } elseif (is_file($fn_new)) {
            $rv[$fn] = file_get_contents($fn_new);
        }
    }
    return $rv;
}
Beispiel #4
0
 function dir2array($dir, $separator = DIRECTORY_SEPARATOR, $paths = 'relative')
 {
     $result = [];
     $cdir = scandir($dir);
     foreach ($cdir as $key => $value) {
         if (!in_array($value, [".", ".."])) {
             if (is_dir($dir . $separator . $value)) {
                 $result[$value] = dir2array($dir . $separator . $value, $separator, $paths);
             }
             /*else
               {
                   if ($paths == 'relative')
                   {
                       $result[] = $dir . '/' . $value;                    
                   }
                   elseif ($paths == 'absolute')
                   {
                       $result[] = base_url() . $dir . '/' . $value;
                   }
               }*/
         }
     }
     return $result;
 }
$plugin = new PluginPackage();
$plugin->code = $code;
$plugin->classname = $options["classname"];
$plugin->name = $options["pluginname"];
$plugin->author = $options["author"];
$plugin->versiontext = $options["versiontext"];
$plugin->versioncount = $options["versioncount"];
$plugin->api = $options["api"];
$plugin->short_description = $options["shortdesc"];
if (isset($options["updatepath"])) {
    $plugin->updatepath = $options["updatepath"];
}
if (isset($options["web"])) {
    $plugin->web = $options["web"];
}
if (isset($options["licensefile"])) {
    $plugin->license = @file_get_contents($options["licensefile"]);
}
if (isset($options["helpfile"])) {
    $plugin->help = @file_get_contents($options["helpfile"]);
}
if (isset($options["custompub"])) {
    $plugin->custompub = dir2array($options["custompub"]);
}
if (isset($options["custompriv"])) {
    $plugin->custompriv = dir2array($options["custompriv"]);
}
if (isset($options["tpldir"])) {
    $plugin->tpls = dir2array($options["tpldir"]);
}
file_put_contents($options["output"], $plugin->save());
Beispiel #6
0
 public function dir2array($dir, $content = false)
 {
     return dir2array($dir, $content);
 }