/**
  * Get list of files in a directory
  *
  * PHP Extension
  *
  * @access public
  * @static
  * @param string $dir Directory Name
  * @param string $ext File Extension
  * @param bool $recursive Traverse Recursively
  * @return array array of filenames
  * @uses is_dir()
  * @uses opendir()
  * @uses readdir()
  * @version $Id: v 1.0 2008-06-05 11:14:46 sonots $
  */
 function &get_existfiles($dir, $ext = '', $recursive = false)
 {
     if (($dp = @opendir($dir)) == false) {
         return false;
     }
     $pattern = '/' . preg_quote($ext, '/') . '$/';
     $dir = $dir[strlen($dir) - 1] == '/' ? $dir : $dir . '/';
     $dir = $dir == '.' . '/' ? '' : $dir;
     $files = array();
     while (($file = readdir($dp)) !== false) {
         if ($file != '.' && $file != '..' && is_dir($dir . $file) && $recursive) {
             $files = array_merge($files, get_existfiles($dir . $file, $ext, $recursive));
         } else {
             $matches = array();
             if (preg_match($pattern, $file, $matches)) {
                 $files[] = $dir . $file;
             }
         }
     }
     closedir($dp);
     return $files;
 }
示例#2
0
function links_init()
{
    global $whatsnew;
    // if (PKWK_READONLY) return; // Do nothing
    if (auth::check_role('readonly')) {
        return;
    }
    // Do nothing
    if (ini_get('safe_mode') == '0') {
        set_time_limit(0);
    }
    // Init database
    foreach (get_existfiles(CACHE_DIR, '.ref') as $cache) {
        unlink($cache);
    }
    foreach (get_existfiles(CACHE_DIR, '.rel') as $cache) {
        unlink($cache);
    }
    $ref = array();
    // 参照元
    foreach (get_existpages() as $page) {
        if ($page == $whatsnew) {
            continue;
        }
        $rel = array();
        // 参照先
        $links = links_get_objects($page);
        foreach ($links as $_obj) {
            if (!isset($_obj->type) || $_obj->type != 'pagename' || $_obj->name == $page || $_obj->name == '') {
                continue;
            }
            if (is_a($_obj, 'Link_autoalias')) {
                $_aliases = get_autoaliases($_obj->name);
                foreach ($_aliases as $_alias) {
                    if (is_pagename($_alias)) {
                        $rel[] = $_alias;
                    }
                }
            } else {
                $rel[] = $_obj->name;
            }
        }
        $rel = array_unique($rel);
        foreach ($rel as $_name) {
            if (!isset($ref[$_name][$page])) {
                $ref[$_name][$page] = 1;
            }
            if (!is_a($_obj, 'Link_autolink')) {
                $ref[$_name][$page] = 0;
            }
        }
        if (!empty($rel)) {
            $fp = fopen(CACHE_DIR . encode($page) . '.rel', 'w') or die_message('cannot write ' . htmlspecialchars(CACHE_DIR . encode($page) . '.rel'));
            fputs($fp, join("\t", $rel));
            fclose($fp);
        }
    }
    foreach ($ref as $page => $arr) {
        $fp = fopen(CACHE_DIR . encode($page) . '.ref', 'w') or die_message('cannot write ' . htmlspecialchars(CACHE_DIR . encode($page) . '.ref'));
        foreach ($arr as $ref_page => $ref_auto) {
            fputs($fp, $ref_page . "\t" . $ref_auto . "\n");
        }
        fclose($fp);
    }
}
 function get_cache_filenames()
 {
     return get_existfiles(CACHE_DIR, ".{$this->plugin}");
 }
示例#4
0
 /**
  * Get all tags_filename
  *
  * Overwrite Me! if you changed get_tags_filename
  *
  * @return array
  * @access protected
  */
 function get_tags_filenames()
 {
     return get_existfiles('.', '_tags.tag');
 }