/** * Quoted-printable string encoder * * @param string $input * @return string */ function nc_quoted_printable_encode($input) { $tohex = 'sprintf("=%02X", ord("$1"))'; $str = preg_replace('/([^\\x09\\x20\\x0D\\x0A\\x21-\\x3C\\x3E-\\x7E])/e', $tohex, $input); // encode x20, x09 at the end of lines $str = preg_replace("/([ \t])(\r?\n)/e", $tohex . '$2', $str); $str = str_replace("\r", "", $str); // split into chunks // Из-за разбиения строки по RFC (=CRLF) возникают "лишние" переносы строк на некоторых почтовых серверах $lines = explode("\n", $str); foreach ($lines as $num => $line) { if (strlen($line) > 76) { nc_preg_match_all('/.{1,73}([^=]{0,2})?/', $line, $regs); $lines[$num] = join("=\n", $regs[0]); } } $str = join("\n", $lines); return $str; }
/** * Функция получения title и мета-данных страниц * @see http://php.net/manual/en/function.get-meta-tags.php * @param string адрес страницы * @return array */ public function get_meta_tags($url) { $result = array(); $contents = @file_get_contents($url); if (!$contents) { return false; } nc_preg_match('/<title>([^>]*)<\\/title>/si', $contents, $match); if (isset($match) && is_array($match) && count($match) > 0) { $result['title'] = strip_tags($match[1]); } nc_preg_match_all('/<[\\s]*meta[\\s]*name=["\']?' . '([^>\'"]*)["\']?[\\s]*' . 'content=["\']?([^>"\']*)["\']?[\\s]*[\\/]?[\\s]*>/si', $contents, $match); if (isset($match) && is_array($match) && count($match) == 3) { $originals = $match[0]; $names = $match[1]; $values = $match[2]; if (count($originals) == count($names) && count($names) == count($values)) { for ($i = 0, $limiti = count($names); $i < $limiti; $i++) { $result[strtolower($names[$i])] = $values[$i]; } } } return $result; }
} $nc_parent_field_path = null; $nc_field_path = null; } else { eval($addCond); } } require $ROOT_FOLDER . "message_fields.php"; if (!$cc_only) { if (!$posting) { if ($cc_env['File_Mode']) { $addTemplate = file_get_contents($file_class->get_field_path('AddTemplate')); } if ($addTemplate) { if ($warnText) { nc_preg_match_all('#\\$([a-z0-9_]+)#i', $addTemplate, $all_template_variables); foreach ($all_template_variables[1] as $template_variable) { if ($_REQUEST[$template_variable] == ${$template_variable}) { ${$template_variable} = stripslashes(${$template_variable}); } } } if ($cc_env['File_Mode']) { // обертка для вывода ошибки в админке if ($warnText && ($nc_core->inside_admin || $isNaked)) { ob_start(); nc_print_status($warnText, 'error'); $warnText = ob_get_clean(); } $nc_parent_field_path = $file_class->get_parent_fiend_path('AddTemplate'); $nc_field_path = $file_class->get_field_path('AddTemplate');
/** * Проставить счетчики на указанные макеты дизайна * @param bool ставить ли в xml и пустые макеты, 0 (по умолчанию) - не ставить * @param mixed массив ID макетов дизайна * @return int 0 в случае успеха */ function nc_openstat_put_counter_to_templates($check_xml = 0, $put_templ_ids = NULL) { global $db, $nc_core; if (!$put_templ_ids) { $templates = $db->get_results("SELECT `Template_ID`, `Parent_Template_ID`, `Header`, `Footer`, `File_Mode`, `File_Path` FROM `Template`WHERE `Template_ID`<>'" . $nc_core->get_settings('EditDesignTemplateID') . "'"); } else { $where_in = join($put_templ_ids, "', '"); $where_in = "'" . $where_in . "'"; $templates = $db->get_results("SELECT `Template_ID`, `Parent_Template_ID`, `Header`, `Footer`, `File_Mode`, `File_Path` FROM `Template` WHERE `Template_ID` IN (" . $where_in . ")"); } if (!$templates) { return 1; } foreach ($templates as $templ) { if ($templ->File_Mode) { $templ->Header = file_get_contents($nc_core->TEMPLATE_FOLDER . $templ->File_Path . '/Header.html'); $templ->Footer = file_get_contents($nc_core->TEMPLATE_FOLDER . $templ->File_Path . '/Footer.html'); } if (!$check_xml) { // считаем, что в пустых xml макетах все и так хорошо и счетчик не нужен if (nc_strpos($templ->Header, "<?xml") !== FALSE) { continue; } if ($templ->Footer == '' && $templ->Header == '' && $templ->Parent_Template_ID == 0) { continue; } } if (!($templ->Footer == '' && $templ->Parent_Template_ID != 0)) { // если есть родитель и футер пустой, то он же наследуется if (nc_strpos($templ->Footer, NC_OPENSTAT_COUNTER) === FALSE) { if (nc_preg_match_all("#[ \t]*<[ \t]*\\/[ \t]*body[ \t]*>#i", $templ->Footer, $matches, PREG_OFFSET_CAPTURE)) { //ищем </body> $body_pos = $matches[0][count($matches[0]) - 1][1]; // позиция последнего тега </body> $new_footer = substr_replace($templ->Footer, NC_OPENSTAT_COUNTER . "\n", $body_pos, 0); // вставка подстроки } elseif (nc_preg_match_all("#[ \t]*<[ \t]*\\/[ \t]*html[ \t]*>#i", $templ->Footer, $matches, PREG_OFFSET_CAPTURE)) { //ищем </html> $body_pos = $matches[0][count($matches[0]) - 1][1]; // позиция последнего тега </html> $new_footer = substr_replace($templ->Footer, NC_OPENSTAT_COUNTER . "\n", $body_pos, 0); // вставка подстроки } else { // на худой конец вставляем просто в конец футеры $new_footer = $templ->Footer . "\n" . NC_OPENSTAT_COUNTER; } if ($templ->File_Mode) { $res = file_put_contents($nc_core->TEMPLATE_FOLDER . $templ->File_Path . '/Footer.html', $new_footer); if (false === $res) { return 1; } } else { $db->query("UPDATE `Template` SET `Footer`=\"" . $db->prepare($new_footer) . "\" WHERE `Template_ID`='" . $templ->Template_ID . "'"); } } } else { if (nc_openstat_check_counter_in_templates_sub_check($templ->Template_ID, $tmp, $check_xml)) { // если в родительских нет счетчика $new_footer = NC_OPENSTAT_COUNTER . "\n%Footer"; if ($templ->File_Mode) { $res = file_put_contents($nc_core->TEMPLATE_FOLDER . $templ->File_Path . '/Footer.html', $new_footer); if (false === $res) { return 1; } } else { $db->query("UPDATE `Template` SET `Footer`=\"" . $db->prepare($new_footer) . "\" WHERE `Template_ID`='" . $templ->Template_ID . "'"); } } } } return 0; }