示例#1
0
/**
 * Test a URL as a broken link.
 *
 * @param  URLPATH		URL to test.
 * @param  string			Comcode tag type, to which the URL is associated.
 * @param  string			URL actually provided.
 * @param  MEMBER			The member who is responsible for this Comcode
 * @return tempcode		Error message, or blank if no error.
*/
function test_url($url_full, $tag_type, $given_url, $source_member)
{
    if (get_option('check_broken_urls') == '0') {
        return new ocp_tempcode();
    }
    if (strpos($url_full, '{$') !== false) {
        return new ocp_tempcode();
    }
    $temp_tpl = new ocp_tempcode();
    if (!handle_has_checked_recently($url_full)) {
        $GLOBALS['COMCODE_PARSE_URLS_CHECKED']++;
        $test = $GLOBALS['COMCODE_PARSE_URLS_CHECKED'] >= MAX_URLS_TO_READ ? '' : http_download_file($url_full, 0, false);
        if (is_null($test) && in_array($GLOBALS['HTTP_MESSAGE'], array('404', 'could not connect to host'))) {
            $temp_tpl = do_template('WARNING_TABLE', array('FOR_GUESTS' => false, 'WARNING' => do_lang_tempcode('MISSING_URL_COMCODE', $tag_type, escape_html($url_full))));
            if (array_key_exists('COMCODE_BROKEN_URLS', $GLOBALS)) {
                $GLOBALS['COMCODE_BROKEN_URLS'][] = array($url_full, NULL);
            } elseif (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe') && !running_script('comcode_convert') && !running_script('preview')) {
                $found_in_post = false;
                // We don't want to send email if someone's just posting it right now, because they'll see the error on their screen, and we don't want staff spammed by member mistakes
                foreach ($_POST as $val) {
                    if (is_array($_POST)) {
                        continue;
                    }
                    if (get_magic_quotes_gpc()) {
                        $val = stripslashes($val);
                    }
                    if (is_string($val) && strpos($val, $given_url) !== false) {
                        $found_in_post = true;
                    }
                }
                if (!$found_in_post) {
                    require_code('failure');
                    relay_error_notification(do_lang('MISSING_URL_COMCODE', $tag_type, $url_full), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference');
                }
            }
        }
    }
    return $temp_tpl;
}
示例#2
0
/**
 * Render that the page wasn't found. Show alternate likely candidates based on misspellings.
 *
 * @param  ID_TEXT		The codename of the page to load
 * @param  ID_TEXT		The zone the page is being loaded in
 * @return tempcode		Message
 */
function page_not_found($codename, $zone)
{
    $GLOBALS['HTTP_STATUS_CODE'] = '404';
    if (!headers_sent()) {
        if (!browser_matches('ie') && strpos(ocp_srv('SERVER_SOFTWARE'), 'IIS') === false) {
            header('HTTP/1.0 404 Not Found');
        }
    }
    // Maybe problem with SEO URLs
    if (get_zone_name() == '' && get_option('htm_short_urls') == '1' && has_zone_access(get_member(), 'adminzone')) {
        $self_url = get_self_url_easy();
        $zones = find_all_zones();
        foreach ($zones as $_zone) {
            if ($_zone != '' && $_zone != 'site' && strpos($self_url, '/' . $_zone . '/') !== false) {
                attach_message(do_lang_tempcode('HTACCESS_SEO_PROBLEM'), 'warn');
            }
        }
    }
    // "Did you mean?" support
    $all_pages_in_zone = array_keys(find_all_pages_wrap($zone));
    $did_mean = array();
    foreach ($all_pages_in_zone as $possibility) {
        if (is_integer($possibility)) {
            $possibility = strval($possibility);
        }
        // e.g. '404' page has been converted to integer by PHP, grr
        $from = str_replace('cms_', '', str_replace('admin_', '', $possibility));
        $to = str_replace('cms_', '', str_replace('admin_', '', $codename));
        //$dist=levenshtein($from,$to);  If we use this, change > to < also
        //$threshold=4;
        $dist = 0.0;
        similar_text($from, $to, $dist);
        $threshold = 75.0;
        if ($dist > $threshold && has_page_access(get_member(), $codename, $zone)) {
            $did_mean[$dist] = $possibility;
        }
    }
    ksort($did_mean);
    $_did_mean = array_pop($did_mean);
    if ($_did_mean == '') {
        $_did_mean = NULL;
    }
    if (ocp_srv('HTTP_REFERER') != '' && !handle_has_checked_recently('request-' . $zone . ':' . $codename)) {
        require_code('failure');
        relay_error_notification(do_lang('_MISSING_RESOURCE', $zone . ':' . $codename) . ' ' . do_lang('REFERRER', ocp_srv('HTTP_REFERER'), substr(get_browser_string(), 0, 255)), false, 'error_occurred_missing_page');
    }
    $title = get_page_title('ERROR_OCCURRED');
    $add_access = has_actual_page_access(get_member(), 'cms_comcode_pages', NULL, NULL, 'submit_highrange_content');
    $redirect_access = addon_installed('redirects_editor') && has_actual_page_access(get_member(), 'admin_redirects');
    require_lang('zones');
    $add_url = $add_access ? build_url(array('page' => 'cms_comcode_pages', 'type' => '_ed', 'page_link' => $zone . ':' . $codename), get_module_zone('cms_comcode_pages')) : new ocp_tempcode();
    $add_redirect_url = $redirect_access ? build_url(array('page' => 'admin_redirects', 'type' => 'misc', 'page_link' => $zone . ':' . $codename), get_module_zone('admin_redirects')) : new ocp_tempcode();
    return do_template('MISSING_SCREEN', array('_GUID' => '22f371577cd2ba437e7b0cb241931575', 'TITLE' => $title, 'DID_MEAN' => $_did_mean, 'ADD_URL' => $add_url, 'ADD_REDIRECT_URL' => $add_redirect_url, 'PAGE' => $codename));
}