Beispiel #1
0
/**
 * Get an array of all the pages of the specified type (module, etc) and extension (for small sites everything will be returned, for larger ones it depends on the show method).
 *
 * @param  ID_TEXT		The zone name
 * @param  ID_TEXT		The type (including language, if appropriate)
 * @set    modules modules_custom comcode/EN comcode_custom/EN html/EN html_custom/EN
 * @param  string			The file extension to limit us to (without a dot)
 * @param  boolean		Whether to leave file extensions on the page name
 * @param  ?TIME			Only show pages newer than (NULL: no restriction)
 * @param  integer		Selection algorithm constant
 * @set 0 1 2
 * @param  ?boolean		Whether to search under the custom-file-base (NULL: auto-decide)
 * @return array			A map of page name to type (modules_custom, etc)
 */
function _find_all_pages($zone, $type, $ext = 'php', $keep_ext_on = false, $cutoff_time = NULL, $show_method = 0, $custom = NULL)
{
    $out = array();
    $module_path = $zone == '' ? 'pages/' . filter_naughty($type) : filter_naughty($zone) . '/pages/' . filter_naughty($type);
    if (is_null($custom)) {
        $custom = strpos($type, 'comcode_custom') !== false || strpos($type, 'html_custom') !== false;
        if ($custom && get_custom_file_base() != get_file_base()) {
            $out = _find_all_pages($zone, $type, $ext, false, NULL, $show_method, false);
        }
    }
    $stub = $custom ? get_custom_file_base() : get_file_base();
    $dh = @opendir($stub . '/' . $module_path);
    if ($dh !== false) {
        while (($file = readdir($dh)) !== false) {
            if (substr($file, -4) == '.' . $ext && file_exists($stub . '/' . $module_path . '/' . $file) && preg_match('#^[\\w\\-\\.]*$#', substr($file, 0, strlen($file) - 4)) != 0) {
                if (!is_null($cutoff_time)) {
                    if (filectime($stub . '/' . $module_path . '/' . $file) < $cutoff_time) {
                        continue;
                    }
                }
                if ($ext == 'txt') {
                    switch ($show_method) {
                        case FIND_ALL_PAGES__NEWEST:
                            // Only gets newest if it's a large site
                            if (count($out) > 300) {
                                $out = array();
                                $records = $GLOBALS['SITE_DB']->query_select('comcode_pages', array('the_page'), array('the_zone' => $zone), 'ORDER BY p_add_date DESC', 300);
                                foreach ($records as $record) {
                                    $file = $record['the_page'] . '.txt';
                                    if (!file_exists($stub . '/' . $module_path . '/' . $file)) {
                                        continue;
                                    }
                                    if (!is_null($cutoff_time)) {
                                        if (filectime($stub . '/' . $module_path . '/' . $file) < $cutoff_time) {
                                            continue;
                                        }
                                    }
                                    $out[$keep_ext_on ? $file : substr($file, 0, strlen($file) - 4)] = $type;
                                }
                            } else {
                                break;
                            }
                            //break; Actually, no, let it roll on to the next one to get key files too
                        //break; Actually, no, let it roll on to the next one to get key files too
                        case FIND_ALL_PAGES__PERFORMANT:
                            // Default, chooses selection carefully based on site size
                            if ($show_method == FIND_ALL_PAGES__NEWEST || count($out) > 300) {
                                if ($show_method != FIND_ALL_PAGES__NEWEST) {
                                    $out = array();
                                }
                                $records = $GLOBALS['SITE_DB']->query('SELECT the_page FROM ' . get_table_prefix() . 'comcode_pages WHERE ' . db_string_equal_to('the_zone', $zone) . ' AND (' . db_string_equal_to('the_page', get_zone_default_page($zone)) . ' OR the_page LIKE \'' . db_encode_like('panel\\_%') . '\') ORDER BY p_add_date DESC');
                                foreach ($records as $record) {
                                    $file = $record['the_page'] . '.txt';
                                    if (!file_exists($stub . '/' . $module_path . '/' . $file)) {
                                        continue;
                                    }
                                    if (!is_null($cutoff_time)) {
                                        if (filectime($stub . '/' . $module_path . '/' . $file) < $cutoff_time) {
                                            continue;
                                        }
                                    }
                                    $out[$keep_ext_on ? $file : substr($file, 0, strlen($file) - 4)] = $type;
                                }
                                break 2;
                            }
                            break;
                        case FIND_ALL_PAGES__ALL:
                            // Nothing special
                            break;
                    }
                }
                $out[$keep_ext_on ? $file : substr($file, 0, strlen($file) - 4)] = $type;
            }
        }
        closedir($dh);
    }
    if ($zone == '' && get_option('collapse_user_zones', true) === '1') {
        $out += _find_all_pages('site', $type, $ext, $keep_ext_on);
    }
    ksort($out);
    return $out;
}
Beispiel #2
0
/**
 * Get an array of all the pages of the specified type (module, etc) and extension (for small sites everything will be returned, for larger ones it depends on the show method).
 *
 * @param  ID_TEXT		The zone name
 * @param  ID_TEXT		The type
 * @set    modules modules_custom comcode comcode_custom html html_custom
 * @param  string			The file extension to limit us to (without a dot)
 * @param  boolean		Whether to leave file extensions on the page name
 * @param  ?TIME			Only show pages newer than (NULL: no restriction)
 * @param  integer		Selection algorithm constant
 * @set 0 1 2
 * @return array			A map of page name to type (modules_custom, etc)
 */
function find_all_pages($zone, $type, $ext = 'php', $keep_ext_on = false, $cutoff_time = NULL, $show_method = 0)
{
    require_code('zones2');
    return _find_all_pages($zone, $type, $ext, $keep_ext_on, $cutoff_time, $show_method);
}