function _edit_doc_link($row) { // global function inside a method... huh? if (!$row["Subdivision_ID"]) { return ""; } // oops $resolved_url_data = nc_resolve_url($row["Referrer_URL"]); $url = parse_url($row["Referrer_URL"]); $edit_link_params = array("sub" => nc_array_value($resolved_url_data, "folder_id"), "cc" => nc_array_value($resolved_url_data, "infoblock_id"), "message" => nc_array_value($resolved_url_data, "object_id")); $edit_link = $url['scheme'] . "://" . $url['host'] . nc_core("SUB_FOLDER") . nc_core("HTTP_ROOT_PATH") . ($resolved_url_data["resource_type"] == "object" ? "message.php" : "") . "?" . (isset($url["query"]) ? $url["query"] . "&" : "") . http_build_query($edit_link_params); return "<a href='" . htmlspecialchars($edit_link) . "' target='_blank'>" . NETCAT_MODULE_SEARCH_ADMIN_BROKEN_LINK_EDIT . "</a>"; }
/** * * @return integer */ protected function get_id() { if ($this->id === null) { $site_id = null; if (strpos($this->url, "://")) { // hostname, huh?! $host = parse_url($this->url, PHP_URL_HOST); try { $site_settings = nc_Core::get_object()->catalogue->get_by_host_name($host); $site_id = $site_settings['Catalogue_ID']; } catch (Exception $e) { } } $resolved_path = nc_resolve_url($this->url, 'GET', $site_id); if (isset($resolved_path['folder_id'])) { $this->id = $resolved_path['folder_id']; } else { $this->id = false; } } return $this->id; }
/** * * @param nc_search_document $doc * @return nc_search_document */ protected function apply_hierarchy_options(nc_search_document $doc) { $nc_core = nc_Core::get_object(); // попробовать в два захода: сначала сайт try { $site = $nc_core->catalogue->get_by_host_name(parse_url($doc->get('url'), PHP_URL_HOST)); $site_id = $site["Catalogue_ID"]; $doc->set('language', $site["Language"]); } catch (Exception $e) { nc_search::log(nc_search::LOG_INDEXING_NO_SUB, "Cannot determine site of the document '{$doc->get('url')}': {$e->getMessage()}"); $site_id = 1; // наугад } $doc->set('site_id', $site_id); // теперь раздел try { $resolved_path = nc_resolve_url($doc->get('url'), 'GET'); if ($resolved_path && isset($resolved_path['folder_id'])) { $sub_id = $resolved_path['folder_id']; $sub = $nc_core->subdivision->get_by_id($sub_id); } else { throw new nc_search_exception(); } $ancestors = array(); $tree = $nc_core->subdivision->get_parent_tree($sub_id); // включает собственно раздел! foreach ($tree as $s) { if (isset($s["Subdivision_ID"])) { $ancestors[] = "sub{$s['Subdivision_ID']}"; } } $doc->set_values(array('sub_id' => $sub_id, 'language' => $nc_core->subdivision->get_lang($sub_id), 'ancestor_ids' => join(',', $ancestors))); $p = $nc_core->page; if ($sub[$p->get_field_name('sitemap_include')]) { $doc->set_values(array('sitemap_include' => true, 'sitemap_changefreq' => $sub[$p->get_field_name('sitemap_changefreq')], 'sitemap_priority' => $sub[$p->get_field_name('sitemap_priority')])); } } catch (Exception $e) { nc_search::log(nc_search::LOG_INDEXING_NO_SUB, "Cannot set subdivision data for the document '{$doc->get('url')}': {$e->getMessage()}"); } return $doc; }
function nc_browse_messages($cc_env, $range, $user_template = false) { if ($user_template) { $browse_msg = $user_template; } else { global $browse_msg; } global $classPreview, $admin_mode, $inside_admin; $nc_core = nc_Core::get_object(); if (isset($classPreview)) { $classPreview += 0; } if ($cc_env['cur_cc'] == $nc_core->input->fetch_get("cur_cc")) { $curPos = $cc_env['curPos'] + 0; } else { $curPos = 0; } $maxRows = $cc_env['maxRows']; $totRows = $cc_env['totRows']; if (!$maxRows || !$totRows) { return ''; } if ($cc_env['cur_cc']) { $cur_cc = $cc_env['cur_cc']; } $page_count = ceil($totRows / $maxRows); $half_range = ceil($range / 2); $cur_page = ceil($curPos / $maxRows) + 1; if ($page_count < 2) { return ''; } $maybe_from = $cur_page - $half_range; $maybe_to = $cur_page + $half_range - (is_even($range) ? 0 : 1); if ($maybe_from < 0) { $maybe_to = $maybe_to - $maybe_from; $maybe_from = 0; if ($maybe_to > $page_count) { $maybe_to = $page_count; } } if ($maybe_to > $page_count) { $maybe_from = $page_count - $range; $maybe_to = $page_count; if ($maybe_from < 0) { $maybe_from = 0; } } // формируем ссылку // const_url не меняется для каждой страницы $const_url = $cc_env['LocalQuery']; if ($const_url == '?') { $const_url = ''; } //$const_url = rawurlencode ($const_url); // добавим get-парметры $_get_arr = $nc_core->input->fetch_get(); $get_params = array(); // добавим в ссылку cur_cc if (isset($cur_cc)) { $get_params['cur_cc'] = $cur_cc; } if (!empty($_get_arr)) { $ignore_arr = array('sid', 'ced', 'inside_admin', 'catalogue', 'sub', 'cc', 'curPos', 'cur_cc', 'REQUEST_URI', 'srchPat'); if ($inside_admin || $admin_mode) { $ignore_arr[] = 'isNaked'; } foreach ($_get_arr as $k => $v) { if (!in_array($k, $ignore_arr)) { $get_params[$k] = $nc_core->input->recursive_striptags_escape($v); } } } $const_url .= count($get_params) ? (strstr($const_url, "?") ? "&" : "?") . $nc_core->url->build_url($get_params) : ""; if (!$admin_mode && nc_module_check_by_keyword('routing')) { $use_routing_module = true; $routing_parameters = nc_resolve_url($nc_core->url); $routing_parameters['variables'] = array_merge(nc_array_value($routing_parameters, 'variables', array()), $get_params, array('curPos' => null, 'nc_page' => null)); $routing_parameters['page'] = null; $routing_resource_type = $routing_parameters['resource_type']; if ($routing_resource_type == 'folder' && $routing_parameters['infoblock_id']) { $routing_resource_type = 'infoblock'; } } else { $use_routing_module = $routing_parameters = $routing_resource_type = false; } $array_result = array(); for ($i = $maybe_from; $i < $maybe_to; $i++) { $page_number = $i + 1; $page_from = $i * $maxRows; $page_to = $page_from + $maxRows; if ($use_routing_module) { $routing_parameters['variables']['curPos'] = $page_from ? $page_from : null; $routing_parameters['page'] = $page_number > 1 ? $page_number : null; $url = nc_routing::get_resource_path($routing_resource_type, $routing_parameters); } elseif ($page_from && !$admin_mode) { // ссылка не на первую страницу $url = $nc_core->url->get_parsed_url('path') . $const_url . (strpos($const_url, "?") !== false ? "&" : "?") . "curPos=" . $page_from; $url = $nc_core->SUB_FOLDER . $url; } elseif ($page_from && $admin_mode) { $url = $const_url . (strpos($const_url, "?") !== false ? "&" : "?") . "curPos=" . $page_from; } else { // ссылка на первую страницу, curPos не нужен $url = $const_url ? $const_url : $nc_core->url->get_parsed_url('path'); } // replace existing & with & then replace all & to & $url = nc_preg_replace(array("/&/", "/&/"), array("&", "&"), $url); if ($curPos == $page_from) { $array_result[$i] = $browse_msg['active']; } else { $array_result[$i] = $browse_msg['unactive']; } $array_result[$i] = str_replace("%URL", $url, $array_result[$i]); $array_result[$i] = str_replace("%PAGE", $page_number, $array_result[$i]); $array_result[$i] = str_replace("%FROM", $page_from + 1, $array_result[$i]); $array_result[$i] = str_replace("%TO", $page_to, $array_result[$i]); } $result = $browse_msg['prefix']; $result .= join($browse_msg['divider'], $array_result); $result .= $browse_msg['suffix']; return $result; }
// ------- Определение цели запроса (раздела/инфоблока/объекта/скрипта) -------- if ($nc_core->url->get_parsed_url('path') == '/') { // Путь к главной странице: без участия модуля маршрутизации $sub = $title_sub; $nc_core->subdivision->set_current_by_id($sub); $cc_in_sub = $nc_core->sub_class->get_by_subdivision_id($sub); foreach ((array) $cc_in_sub as $row) { if ($row['Checked'] || $row['sysTbl'] == 3) { $cc_array[] = $row['Sub_Class_ID']; } } if (count($cc_array)) { $cc = $_db_cc = $cc_array[0]; } } else { $routing_result = nc_resolve_url($nc_core->url, $_SERVER['REQUEST_METHOD']); // принятие решения о необходимости переадресации или добавления канонического адреса // (только при включённом модуле маршрутизации) if (is_array($routing_result) && nc_module_check_by_keyword('routing')) { $routing_duplicate_route_action = nc_routing::get_setting('DuplicateRouteAction', $catalogue); if ($routing_duplicate_route_action != nc_routing::DUPLICATE_ROUTE_NO_ACTION) { // попробуем получить путь, соответствующий полученным параметрам $routing_canonical_request = $routing_result; $routing_result_variables = nc_array_value($routing_result, 'variables', array()); if ($routing_result_variables) { // подходящий маршрут должен содержать эти переменные в «дополнительных переменных» (query_variables) $routing_canonical_request['route_variables'] = $routing_result_variables; } // добавим GET-переменные, если они есть if ($nc_core->input->fetch_get()) { $routing_canonical_request['variables'] = array_merge((array) $nc_core->input->fetch_get(), $routing_result_variables);