function parents_out_way_to($page_id = 0) { $cache_key = 'parents_out_way_to' . $page_id; $k = mso_get_cache($cache_key); if ($k) { return $k; } // да есть в кэше $r = ''; $CI =& get_instance(); $CI->db->select('page_id, page_id_parent, page_title, page_slug'); $CI->db->where('page_id', $page_id); $CI->db->order_by('page_menu_order'); $query = $CI->db->get('page'); $result = $query->result_array(); if ($result) { foreach ($result as $key => $page2) { extract($page2); $r = $page_title; if ($page_id_parent > 0) { $parents = parents_out_way_parents($page_id_parent); if ($parents) { $r = $parents . ' <span class="arr">→</span> ' . $page_title; } } } } mso_add_cache($cache_key, $r); // в кэш return $r; }
function authors_widget_custom($options = array(), $num = 1) { // кэш $cache_key = 'authors_widget_custom' . serialize($options) . $num; $k = mso_get_cache($cache_key); if ($k) { return $k; } // да есть в кэше $out = ''; if (!isset($options['header'])) { $options['header'] = t('Авторы'); } // получаем всех авторов $CI =& get_instance(); $CI->db->select('users_nik, users_id'); $CI->db->order_by('users_nik'); $query = $CI->db->get('users'); if ($query->num_rows() > 0) { $users = $query->result_array(); $out = ''; foreach ($users as $user) { $out .= NR . '<li><a href="' . getinfo('siteurl') . 'author/' . $user['users_id'] . '">' . $user['users_nik'] . '</a></li>'; } if ($out) { $out = $options['header'] . '<ul class="mso-widget-list">' . $out . '</ul>' . NR; } } mso_add_cache($cache_key, $out); // сразу в кэш добавим return $out; }
function links_widget_custom($options = array(), $num = 1) { // кэш $cache_key = 'links_widget_custom' . serialize($options) . $num; $k = mso_get_cache($cache_key); if ($k) { return $k; } // да есть в кэше $out = ''; if (!isset($options['header'])) { $options['header'] = ''; } if (isset($options['links'])) { $links = explode("\n", $options['links']); // разбиваем по строкам foreach ($links as $row) { $ar_link = explode('|', $row); // разбиваем по | // всего должно быть 5 элементов if (isset($ar_link[0]) and trim($ar_link[0])) { $href = trim($ar_link[0]); // адрес if ($href and isset($ar_link[1]) and trim($ar_link[1])) { $title = trim($ar_link[1]); // название if (isset($ar_link[2]) and trim($ar_link[2])) { $descr = '<div>' . trim($ar_link[2]) . '</div>'; } else { $descr = ''; } if (isset($ar_link[3]) and trim($ar_link[3])) { $noindex1 = ''; $noindex2 = ''; $nofollow = ' rel="nofollow"'; } else { $noindex1 = $noindex2 = $nofollow = ''; } if (isset($ar_link[4]) and trim($ar_link[4])) { $blank = ' target="_blank"'; } else { $blank = ''; } // обычный вывод списком $out .= NR . '<li>' . $noindex1 . '<a href="' . $href . '" title="' . htmlspecialchars($title) . '"' . $nofollow . $blank . '>' . $title . '</a>' . $descr . $noindex2 . '</li>'; } } } } if ($out) { $out = $options['header'] . NR . '<ul class="mso-widget-list">' . $out . NR . '</ul>' . NR; } mso_add_cache($cache_key, $out); // сразу в кэш добавим return $out; }
function page_comments_widget_custom($options = array(), $num = 1) { // кэш $cache_key = 'page_comments_widget_custom' . serialize($options) . $num; $k = mso_get_cache($cache_key); if ($k) { return $k; } // да есть в кэше $out = ''; if (!isset($options['header'])) { $options['header'] = ''; } if (!isset($options['limit'])) { $options['limit'] = 10; } if (!isset($options['format'])) { $options['format'] = '[A][TITLE][/A] <sup>[COUNT]</sup>'; } $CI =& get_instance(); $CI->db->select('page_slug, page_title, COUNT(comments_id) AS page_count_comments', false); $CI->db->from('page'); $CI->db->where('page_date_publish <', date('Y-m-d H:i:s')); // $CI->db->where('page_date_publish < ', 'NOW()', false); $CI->db->where('page_status', 'publish'); $CI->db->join('comments', 'comments.comments_page_id = page.page_id AND comments_approved = 1', 'left'); $CI->db->order_by('page_count_comments', 'desc'); $CI->db->limit($options['limit']); $CI->db->group_by('page.page_id'); $CI->db->group_by('comments_page_id'); $query = $CI->db->get(); if ($query->num_rows() > 0) { $pages = $query->result_array(); $link = '<a href="' . getinfo('siteurl') . 'page/'; $out .= '<ul class="mso-widget-list">' . NR; foreach ($pages as $page) { if ($page['page_count_comments'] > 0) { $out1 = $options['format']; $out1 = str_replace('[TITLE]', $page['page_title'], $out1); $out1 = str_replace('[COUNT]', $page['page_count_comments'], $out1); $out1 = str_replace('[A]', $link . $page['page_slug'] . '" title="' . tf('Комментариев: ') . $page['page_count_comments'] . '">', $out1); $out1 = str_replace('[/A]', '</a>', $out1); $out .= '<li>' . $out1 . '</li>' . NR; } } $out .= '</ul>' . NR; if ($options['header']) { $out = $options['header'] . $out; } } mso_add_cache($cache_key, $out); // сразу в кэш добавим return $out; }
function global_cache_start($arg = array()) { if ($k = mso_get_cache(global_cache_key(), true)) { // да есть в кэше $CI =& get_instance(); $mq = $CI->db->query_count; // колво sql-запросов $k = str_replace('<!--global_cache_footer-->', ' | Cache ON (' . $mq . 'sql)', $k); echo $k; return true; } ob_start(); return false; }
function catclouds_widget_custom($options = array(), $num = 1) { // кэш $cache_key = 'catclouds_widget_custom' . serialize($options) . $num; $k = mso_get_cache($cache_key); if ($k) { return $k; } // да есть в кэше // формат вывода %SIZE% %URL% %TAG% %COUNT% // параметры $min_size $max_size $block_start $block_end // сортировка $out = ''; if (!isset($options['header'])) { $options['header'] = ''; } if (!isset($options['block_start'])) { $options['block_start'] = '<div class="catclouds">'; } if (!isset($options['block_end'])) { $options['block_end'] = '</div>'; } if (!isset($options['min_size'])) { $min_size = 90; } else { $min_size = (int) $options['min_size']; } if (!isset($options['max_size'])) { $max_size = 230; } else { $max_size = (int) $options['max_size']; } if (!isset($options['cat_id'])) { $cat_id = 0; } else { $cat_id = (int) $options['cat_id']; } if (!isset($options['format'])) { $options['format'] = '<span style="font-size: %SIZE%%"><a href="%URL%">%CAT%</a><sub style="font-size: 7pt;">%COUNT%</sub></span>'; } if (!isset($options['sort'])) { $sort = 0; } else { $sort = (int) $options['sort']; } $url = getinfo('siteurl') . 'category/'; require_once getinfo('common_dir') . 'category.php'; // функции мета $all_cat = mso_cat_array_single('page', 'category_name', 'ASC', 'blog'); $catcloud = array(); foreach ($all_cat as $key => $val) { if ($cat_id) { // выводим саму рубрику и всех её детей if ($val['category_id'] == $cat_id or $val['category_id_parent'] == $cat_id) { if (count($val['pages']) > 0) { // кол-во страниц в этой рубрике > 0 $catcloud[$val['category_name']] = array('count' => count($val['pages']), 'slug' => $val['category_slug']); } } } else { if (count($val['pages']) > 0) { // кол-во страниц в этой рубрике > 0 $catcloud[$val['category_name']] = array('count' => count($val['pages']), 'slug' => $val['category_slug']); } } } asort($catcloud); $min = reset($catcloud); $min = $min['count']; $max = end($catcloud); $max = $max['count']; if ($max == $min) { $max++; } // сортировка перед выводом if ($sort == 0) { arsort($catcloud); } elseif ($sort == 1) { asort($catcloud); } elseif ($sort == 2) { ksort($catcloud); } elseif ($sort == 3) { krsort($catcloud); } else { arsort($catcloud); } // по умолчанию foreach ($catcloud as $cat => $ar) { $count = $ar['count']; $slug = $ar['slug']; $font_size = round(($count - $min) / ($max - $min) * ($max_size - $min_size) + $min_size); $af = str_replace(array('%SIZE%', '%URL%', '%CAT%', '%COUNT%'), array($font_size, $url . $slug, $cat, $count), $options['format']); $out .= $af . ' '; } if ($out) { $out = $options['header'] . $options['block_start'] . $out . $options['block_end']; } mso_add_cache($cache_key, $out); // сразу в кэш добавим return $out; }
function last_pages_unit_widget_custom($arg = array(), $num = 1) { if (!isset($arg['header'])) { $arg['header'] = mso_get_val('widget_header_start', '<div class="mso-widget-header"><span>') . t('Последние записи') . mso_get_val('widget_header_end', '</span></div>'); } if (!isset($arg['cache_time'])) { $arg['cache_time'] = 0; } if (!isset($arg['prefs'])) { $arg['prefs'] = ''; } $out = ''; $cache_key = 'last_pages_unit_widget-' . serialize($arg) . '-' . $num; if ($arg['cache_time'] > 0 and $out = mso_get_cache($cache_key)) { return $out; # да есть в кэше } $units = mso_section_to_array('[unit]' . $arg['prefs'] . '[/unit]', '!\\[unit\\](.*?)\\[\\/unit\\]!is'); ob_start(); if ($units and isset($units[0]) and $units[0]) { $UNIT = $units[0]; require dirname(realpath(__FILE__)) . '/last-pages.php'; } $out = $arg['header'] . ob_get_clean(); if ($arg['cache_time'] > 0) { mso_add_cache($cache_key, $out, $arg['cache_time'] * 60); } return $out; }
function page_views_widget_custom($options = array(), $num = 1) { // кэш $cache_key = 'page_views_widget_custom' . serialize($options) . $num; $k = mso_get_cache($cache_key); if ($k) { return $k; } // да есть в кэше $out = ''; if (!isset($options['header'])) { $options['header'] = ''; } if (!isset($options['limit'])) { $options['limit'] = 10; } if (!isset($options['page_type'])) { $options['page_type'] = 0; } if (!isset($options['format'])) { $options['format'] = '[A][TITLE][/A] <sup>[COUNT]</sup>'; } # получаем все записи как есть # в полученном массиве меняем общее кол-во прочтений на кол-во прочтений в сутки # сортируем массив по новомк значению $curdate = time(); $CI =& get_instance(); $CI->db->select('page_slug, page_title, page_id, page_view_count, page_date_publish'); $CI->db->where('page_status', 'publish'); $CI->db->where('page_view_count > ', '0'); if ($options['page_type']) { $CI->db->where('page_type_id', $options['page_type']); } $CI->db->where('page_date_publish <', date('Y-m-d H:i:s')); $CI->db->order_by('page_id', 'desc'); $query = $CI->db->get('page'); if ($query->num_rows() > 0) { $pages = $query->result_array(); foreach ($pages as $key => $val) { // если еще сутки не прошли, то ставим общее колво прочтений if ($curdate - strtotime($val['page_date_publish']) > 86400) { $pages[$key]['sutki'] = round($val['page_view_count'] / ($curdate - strtotime($val['page_date_publish'])) * 86400); } else { $pages[$key]['sutki'] = $val['page_view_count']; } } usort($pages, 'page_views_cmp'); // отсортируем по ['sutki'] // сам вывод $link = '<a href="' . getinfo('siteurl') . 'page/'; $i = 1; foreach ($pages as $page) { if ($page['sutki'] > 0) { if ($i > $options['limit']) { break; } // лимит $out1 = $options['format']; $out1 = str_replace('[TITLE]', $page['page_title'], $out1); $out1 = str_replace('[COUNT]', $page['sutki'], $out1); $out1 = str_replace('[ALLCOUNT]', $page['page_view_count'], $out1); $out1 = str_replace('[A]', $link . $page['page_slug'] . '" title="' . tf('Просмотров в сутки: ') . $page['sutki'] . '">', $out1); $out1 = str_replace('[/A]', '</a>', $out1); $out .= '<li>' . $out1 . '</li>' . NR; $i++; } else { break; } // всё } if ($out) { $out = '<ul class="mso-widget-list">' . NR . $out . '</ul>' . NR; if ($options['header']) { $out = $options['header'] . $out; } } } mso_add_cache($cache_key, $out); // сразу в кэш добавим return $out; }
function category_widget_custom($options = array(), $num = 1) { if (!isset($options['include'])) { $options['include'] = array(); } if (!isset($options['exclude'])) { $options['exclude'] = array(); } if (!isset($options['format'])) { $options['format'] = '[LINK][TITLE]<sup>[COUNT]</sup>[/LINK]<br>[DESCR]'; } if (!isset($options['format_current'])) { $options['format_current'] = '<span>[TITLE]<sup>[COUNT]</sup></span><br>[DESCR]'; } if (!isset($options['header'])) { $options['header'] = ''; } if (!isset($options['hide_empty'])) { $options['hide_empty'] = 0; } if (!isset($options['order'])) { $options['order'] = 'category_name'; } if (!isset($options['order_asc'])) { $options['order_asc'] = 'ASC'; } if (!isset($options['include_child'])) { $options['include_child'] = 0; } if (!isset($options['nofollow'])) { $options['nofollow'] = false; } if (!isset($options['group_header_no_link'])) { $options['group_header_no_link'] = false; } $cache_key = 'category_widget' . serialize($options) . $num; $k = mso_get_cache($cache_key); if ($k) { $all = $k; } else { /* $type = 'page', $parent_id = 0, $order = 'category_menu_order', $asc = 'asc', $child_order = 'category_menu_order', $child_asc = 'asc', $in = false, $ex = false, $in_child = false, $hide_empty = false, $only_page_publish = false, $date_now = true, $get_pages = true */ $all = mso_cat_array('page', 0, $options['order'], $options['order_asc'], $options['order'], $options['order_asc'], $options['include'], $options['exclude'], $options['include_child'], $options['hide_empty'], true, true, false); mso_add_cache($cache_key, $all); // сразу в кэш добавим } // pr($all); $out = mso_create_list($all, array('childs' => 'childs', 'format' => $options['format'], 'format_current' => $options['format_current'], 'class_ul' => 'mso-widget-list', 'title' => 'category_name', 'link' => 'category_slug', 'current_id' => false, 'prefix' => 'category/', 'count' => 'pages_count', 'slug' => 'category_slug', 'id' => 'category_id', 'menu_order' => 'category_menu_order', 'id_parent' => 'category_id_parent', 'nofollow' => $options['nofollow'], 'group_header_no_link' => $options['group_header_no_link'])); if ($out and $options['header']) { $out = $options['header'] . $out; } return $out; }
/** * возвращает массив структуры всех pages * включается title description keywords date dir url, а также массива $DATA в variables.php * date — время создания файла text.php (или явно заданное в $DATA['date']) * * @param $include — включить только указанные страницы * @param $exclude — исключить указанные страницы * @param $dir — основной каталог, если не указано то это PAGES_DIR * @param $url — основной http-путь, если не указано то это BASE_URL * * @return array * * [home] => Array ( * // обязательные * [page] => home * [title] => Blog * [description] => Best page * [keywords] => * [date] => 2014-10-22 12:56 * [dir] => путь к странице * [url] => http-адрес страницы * * // все что задано в $DATA * [menu_name] => home * [menu_class] => icon star * [menu_order] => 23 * [cat] => news, blog * [tag] => first, second * ) */ function mso_pages_data($include = array(), $exclude = array(), $dir = false, $url = false, $cache_time = 3600) { static $cache = array(); // кеш хранится как массив с ключам = входящим параметрам $cache_key = md5(serialize($include) . serialize($exclude) . serialize($dir) . serialize($url)); // уже получали данные, отдаем результат if (isset($cache[$cache_key])) { return $cache[$cache_key]; } else { // возможно есть данные в файловом кеше if ($out = mso_get_cache('pages_data' . $cache_key, $cache_time)) { $cache[$cache_key] = $out; // статичный кеш return $out; } } $out = array(); // путь на сервере if ($dir === false) { $dir = PAGES_DIR; } // url-путь if ($url === false) { $url = BASE_URL; } $pages = mso_get_dirs($dir, $exclude, 'variables.php'); if ($pages) { if ($include) { $pages = array_intersect($include, $pages); } // для вложенных страниц добавляем префикс равный отличию от PAGES_DIR // pages/about => about // pages/blog/about => blog/about $prefix = str_replace(PAGES_DIR, '', $dir); foreach ($pages as $page) { if (!file_exists($dir . $page . '/text.php')) { continue; } // если нет text.php выходим $page_k = $prefix . $page; if ($page == HOME_PAGE) { $out[$page_k] = array('page' => '/'); } else { $out[$page_k] = array('page' => $page_k); } // обнуляем данные $TITLE = ''; $META = array(); $DATA = array(); // считываем данные require $dir . $page . '/variables.php'; $out[$page_k]['title'] = $TITLE; $out[$page_k]['description'] = isset($META['description']) ? $META['description'] : ''; $out[$page_k]['keywords'] = isset($META['keywords']) ? $META['keywords'] : ''; // дата создания text.php $out[$page_k]['date'] = date('Y-m-d H:i', filemtime($dir . $page . '/text.php')); // путь на сервере $out[$page_k]['dir'] = $dir . $page; // url $out[$page_k]['url'] = $url . $page; if (isset($DATA)) { $out[$page_k] = array_merge($out[$page_k], $DATA); } } } $cache[$cache_key] = $out; // статичный кеш mso_add_cache('pages_data' . $cache_key, $out); // файловый return $out; }
function twitter_go($url = false, $count = 5, $format = '<p><strong>%DATE%</strong><br>%TITLE% <a href="%LINK%">>>></a></p>', $format_date = 'd/m/Y H:i:s', $max_word_description = false, $show_nick = true) { if (!$url) { return false; } # проверим кеш, может уже есть в нем все данные $cache_key = 'rss/' . 'twitter_go' . $url . $count . $format . $format_date . (int) $max_word_description; $k = mso_get_cache($cache_key, true); if ($k) { return $k; } // да есть в кэше if (!defined('MAGPIE_CACHE_AGE')) { define('MAGPIE_CACHE_AGE', 600); } // время кэширования MAGPIE require_once getinfo('common_dir') . 'magpierss/rss_fetch.inc'; $rss = fetch_rss($url); $rss = array_slice($rss->items, 0, $count); $out = ''; foreach ($rss as $item) { $out .= $format; if ($show_nick) { $item['title'] = preg_replace('|(\\S+): (.*)|si', '<strong>\\1:</strong> \\2', $item['title']); } else { $item['title'] = preg_replace('|(\\S+): (.*)|si', '\\2', $item['title']); } // подсветим ссылки $item['title'] = preg_replace('|(http:\\/\\/)(\\S+)|si', '<a rel="nofollow" href="http://\\2" target="_blank">\\2</a>', $item['title']); $out = str_replace('%TITLE%', $item['title'], $out); // [title] = [description] = [summary] if ($max_word_description) { $item['description'] = mso_str_word($item['description'], $max_word_description) . '...'; } $item['description'] = preg_replace('|(\\S+): (.*)|si', '<strong>\\1:</strong> \\2', $item['description']); $item['description'] = preg_replace('|(http:\\/\\/)(\\S+)|si', '<a rel="nofollow" href="http://\\2" target="_blank">\\2</a>', $item['description']); $out = str_replace('%DESCRIPTION%', $item['description'], $out); // [title] = [description] = [summary] $out = str_replace('%DATE%', date($format_date, (int) $item['date_timestamp']), $out); // [pubdate] $out = str_replace('%LINK%', $item['link'], $out); // [link] = [guid] } mso_add_cache($cache_key, $out, 600, true); return $out; }
<?php if (!defined('BASEPATH')) { exit('No direct script access allowed'); } /** * MaxSite CMS * (c) http://max-3000.com/ */ header('Content-type: text/html; charset=utf-8'); header('Content-Type: application/rss+xml'); $cache_key = mso_md5('feed_' . mso_current_url()); $k = mso_get_cache($cache_key); if ($k) { return print $k; } // да есть в кэше ob_start(); require_once getinfo('common_dir') . 'page.php'; // основные функции страниц require_once getinfo('common_dir') . 'category.php'; // функции рубрик $this->load->helper('xml'); $time_zone = getinfo('time_zone'); // 2.00 -> 200 $time_zone_server = date('O') / 100; // +0100 -> 1.00 $time_zone = $time_zone + $time_zone_server; // 3 $time_zone = number_format($time_zone, 2, '.', ''); // 3.00
function links_widget_custom($options = array(), $num = 1) { // кэш $cache_key = 'links_widget_custom' . serialize($options) . $num; $k = mso_get_cache($cache_key); if ($k) { return $k; } // да есть в кэше $out = ''; if (!isset($options['header'])) { $options['header'] = ''; } if (!isset($options['screenshot'])) { $options['screenshot'] = 0; } if (isset($options['links'])) { $links = explode("\n", $options['links']); // разбиваем по строкам foreach ($links as $row) { $ar_link = explode('|', $row); // разбиваем по | // всего должно быть 5 элементов if (isset($ar_link[0]) and trim($ar_link[0])) { $href = trim($ar_link[0]); // адрес if ($href and isset($ar_link[1]) and trim($ar_link[1])) { $title = trim($ar_link[1]); // название if (isset($ar_link[2]) and trim($ar_link[2])) { $descr = '<div>' . trim($ar_link[2]) . '</div>'; } else { $descr = ''; } if (isset($ar_link[3]) and trim($ar_link[3])) { //$noindex1 = '<noindex>'; //$noindex2 = '</noindex>'; $noindex1 = ''; $noindex2 = ''; $nofollow = ' rel="nofollow"'; } else { $noindex1 = $noindex2 = $nofollow = ''; } if (isset($ar_link[4]) and trim($ar_link[4])) { $blank = ' target="_blank"'; } else { $blank = ''; } if (!$options['screenshot']) { // обычный вывод списком $out .= NR . '<li>' . $noindex1 . '<a href="' . $href . '" title="' . htmlspecialchars($title) . '"' . $nofollow . $blank . '>' . $title . '</a>' . $descr . $noindex2 . '</li>'; } else { // скриншоты $href_w = str_replace('http://', '', $href); if ($options['screenshot'] == 1) { $width = '120'; $height = '83'; $s = 'm'; } elseif ($options['screenshot'] == 2) { $width = '202'; $height = '139'; $s = 's'; } elseif ($options['screenshot'] == 3) { $width = '305'; $height = '210'; $s = 'n'; } else { $width = '400'; $height = '275'; $s = 'b'; } $out .= NR . '<p>' . $noindex1 . '<a href="' . $href . '" title="' . htmlspecialchars($title) . '"' . $nofollow . $blank . '>' . '<img src="http://webmorda.kz/site2img/?s=' . $s . '&u=' . $href_w . '" alt="' . htmlspecialchars($title) . '" title="' . $title . '" width="' . $width . '" height="' . $height . '"></a>' . $descr . '' . $noindex2 . '</p>'; /* http://www.webmorda.kz/api.html http://webmorda.kz/site2img/?u={1}&s={2}&q={3}&r={4} */ } } } } } if ($out) { if (!$options['screenshot']) { // обычным списком $out = $options['header'] . NR . '<ul class="is_link links">' . $out . NR . '</ul>' . NR; } else { // скриншоты $out = $options['header'] . NR . '<div class="links">' . $out . '</div><div class="break"></div>' . NR; } } mso_add_cache($cache_key, $out); // сразу в кэш добавим return $out; }
function tagclouds_widget_custom($options = array(), $num = 1) { // кэш $cache_key = 'tagclouds_widget_custom' . serialize($options) . $num; $k = mso_get_cache($cache_key); if ($k) { return $k; } // да есть в кэше // формат вывода %SIZE% %URL% %TAG% %COUNT% // параметры $min_size $max_size $block_start $block_end // сортировка if (!isset($options['header'])) { $options['header'] = ''; } if (!isset($options['block_start'])) { $options['block_start'] = '<div class="tagclouds">'; } if (!isset($options['block_end'])) { $options['block_end'] = '</div>'; } if (!isset($options['min_size'])) { $min_size = 90; } else { $min_size = (int) $options['min_size']; } if (!isset($options['max_size'])) { $max_size = 230; } else { $max_size = (int) $options['max_size']; } if (!isset($options['max_num'])) { $max_num = 50; } else { $max_num = (int) $options['max_num']; } if (!isset($options['min_count'])) { $min_count = 0; } else { $min_count = (int) $options['min_count']; } if (!isset($options['format'])) { $options['format'] = '<span style="font-size: %SIZE%%"><a href="%URL%">%TAG%</a><sub style="font-size: 7pt;">%COUNT%</sub></span>'; } if (!isset($options['sort'])) { $sort = 0; } else { $sort = (int) $options['sort']; } require_once getinfo('common_dir') . 'meta.php'; // функции мета $tagcloud = mso_get_all_tags_page(); asort($tagcloud); $min = reset($tagcloud); $max = end($tagcloud); if ($max == $min) { $max++; } // сортировка перед выводом if ($sort == 0) { arsort($tagcloud); } elseif ($sort == 1) { asort($tagcloud); } elseif ($sort == 2) { ksort($tagcloud); } elseif ($sort == 3) { krsort($tagcloud); } else { arsort($tagcloud); } // по умолчанию $url = getinfo('siteurl') . 'tag/'; $out = ''; $i = 0; foreach ($tagcloud as $tag => $count) { if ($min_count) { if ($count < $min_count) { continue; } } $font_size = round(($count - $min) / ($max - $min) * ($max_size - $min_size) + $min_size); $af = str_replace(array('%SIZE%', '%URL%', '%TAG%', '%COUNT%'), array($font_size, $url . urlencode($tag), $tag, $count), $options['format']); // альтернативный синтаксис с [] $af = str_replace(array('[SIZE]', '[URL]', '[TAG]', '[COUNT]'), array($font_size, $url . urlencode($tag), $tag, $count), $af); $out .= $af . ' '; $i++; if ($max_num != 0 and $i == $max_num) { break; } } if ($out) { $out = $options['header'] . $options['block_start'] . $out . $options['block_end']; } mso_add_cache($cache_key, $out); // сразу в кэш добавим return $out; }
function mso_get_comusers_all($args = array()) { $cache_key = mso_md5('mso_get_comusers_all'); $k = mso_get_cache($cache_key); if ($k) { return $k; } // да есть в кэше $comusers = array(); $CI =& get_instance(); $CI->db->select('*'); $CI->db->from('comusers'); $query = $CI->db->get(); if ($query->num_rows() > 0) { $comusers = $query->result_array(); mso_add_cache($cache_key, $comusers); } // получим все мета одним запросом $CI->db->select('meta_id_obj, meta_key, meta_value'); $CI->db->where('meta_table', 'comusers'); $CI->db->order_by('meta_id_obj'); $query = $CI->db->get('meta'); if ($query->num_rows() > 0) { $all_meta = $query->result_array(); } else { $all_meta = array(); } // переделываем формат массива, чтобы индекс был равен номеру комюзера $r_array = array(); foreach ($all_meta as $val) { $r_array[$val['meta_id_obj']][$val['meta_key']] = $val['meta_value']; } $all_meta = $r_array; // получить все номера страниц, где оставил комментарий комюзер $CI->db->select('comments_id, comments_page_id, comments_comusers_id'); $CI->db->where('comments_comusers_id >', '0'); $CI->db->order_by('comments_comusers_id, comments_page_id'); $query = $CI->db->get('comments'); if ($query->num_rows() > 0) { $all_comments = $query->result_array(); } else { $all_comments = array(); } // переделываем массив под удобный формат $r_array = array(); $all_comments_page_id = array(); // тут массив номеров страниц, где участвовал комюзер foreach ($all_comments as $val) { $r_array[$val['comments_comusers_id']][$val['comments_id']] = $val['comments_page_id']; $all_comments_page_id[$val['comments_comusers_id']][$val['comments_page_id']] = $val['comments_page_id']; } $all_comments = $r_array; // добавляем в каждого комюзера элемент массива meta, comments и comments_pages_id $r_array = array(); foreach ($comusers as $key => $val) { $r_array[$key] = $val; if (isset($all_meta[$val['comusers_id']])) { $r_array[$key]['meta'] = $all_meta[$val['comusers_id']]; } else { $r_array[$key]['meta'] = array(); } if (isset($all_comments[$val['comusers_id']])) { $r_array[$key]['comments'] = $all_comments[$val['comusers_id']]; } else { $r_array[$key]['comments'] = array(); } if (isset($all_comments_page_id[$val['comusers_id']])) { $r_array[$key]['comments_pages_id'] = $all_comments_page_id[$val['comusers_id']]; } else { $r_array[$key]['comments_pages_id'] = array(); } } $comusers = $r_array; mso_add_cache($cache_key, $comusers); return $comusers; }
/** * Получение yaml-конфигурации из файла и сохранение её в глобальные переменные */ function mso_get_yaml($fn) { global $VAR, $TITLE, $META, $META_LINK; $key = 'yaml-' . $fn; $conf = mso_get_cache($key, 0, false, filemtime($fn)); if (!$conf) { $data = file_get_contents($fn); // проверяем вхождение /* === конфигурация === */ if (preg_match('!\\/\\* \\=\\=\\=(.*?)\\=\\=\\= \\*\\/!is', $data, $conf)) { $yaml = trim($conf[1]); // разрешено использовать php-шаблонизатор ob_start(); eval(mso_tmpl_prepare($yaml)); $yaml = ob_get_clean(); require_once ENGINE_DIR . 'yaml/Spyc.php'; $conf = spyc_load($yaml); mso_add_cache($key, $conf); } } if ($conf) { if (isset($conf['TITLE'])) { $TITLE = $conf['TITLE']; } if (isset($conf['VAR']) and is_array($conf['VAR'])) { $VAR = array_merge($VAR, $conf['VAR']); } if (isset($conf['META']) and is_array($conf['META'])) { $META = array_merge($META, $conf['META']); } if (isset($conf['META_LINK']) and is_array($conf['META_LINK'])) { $META_LINK = array_merge($META_LINK, $conf['META_LINK']); } } }
function mso_cat_ul($li_format = '%NAME%', $show_empty = true, $checked_id = array(), $selected_id = array(), $ul_class = 'category', $type_page = 'blog', $type = 'page', $order = 'category_menu_order', $asc = 'asc', $custom_array = false, $include = array(), $exclude = array()) { // спасибо за помощь http://tedbeer.net/wp/ // $include = array('3'); // $exclude = array('3'); // возможно, что этот список уже сформирован, поэтому посмотрим в кэше $cache_key = mso_md5('mso_cat_ul' . $li_format . $show_empty . implode(' ', $checked_id) . implode(' ', $selected_id) . $ul_class . $type_page . $type . $order . $asc . implode(' ', $include) . implode(' ', $exclude)); $k = mso_get_cache($cache_key); if ($k) { // находим текущий url (код повтояет внизу) $current_url = getinfo('siteurl') . mso_current_url(); // текущий урл $out = str_replace('<a href="' . $current_url . '">', '<a href="' . $current_url . '" class="current_url">', $k); $pattern = '|<li class="(.*?)">(.*?)(<a href="' . $current_url . '")|ui'; $out = preg_replace($pattern, '<li class="$1 current_url">$2$3', $out); return $out; } # получим все рубрики в виде одномерного массива if ($custom_array) { $all = $custom_array; } else { $all = mso_cat_array_single('page', $order, $asc, $type_page); } $top = array(); foreach ($all as $item) { $parentId = $item['category_id_parent']; $id = $item['category_id']; if ($parentId && isset($all[$parentId])) { if (!isset($all[$parentId]['children'])) { $all[$parentId]['children'] = array($id); } else { $all[$parentId]['children'][] = $id; } } else { $top[] = $id; } } // непосредственно формирование списка $out = _mso_cat_ul_glue($top, $all, $li_format, $checked_id, $selected_id, $show_empty, $include, $exclude); # $out = str_replace("\n{*}</li>", "</li>", $out); if ($ul_class) { $out = '<ul class="' . $ul_class . '">' . "\n" . $out . "\n" . '</ul>'; } else { $out = '<ul>' . "\n" . $out . "\n" . '</ul>'; } mso_add_cache($cache_key, $out); // сразу в кэш добавим // отметим текущую рубрику. Поскольку у нас к кэше должен быть весь список и не делать кэш для каждого url // то мы просто перед отдачей заменяем текущий url на url с li.current_url $current_url = getinfo('siteurl') . mso_current_url(); // текущий урл $out = str_replace('<a href="' . $current_url . '">', '<a href="' . $current_url . '" class="current_url">', $out); $pattern = '|<li class="(.*?)">(.*?)(<a href="' . $current_url . '")|ui'; $out = preg_replace($pattern, '<li class="$1 current_url">$2$3', $out); return $out; }
function sitemap_cat($arg = '') { $cache_key = 'sitemap_cat'; $k = mso_get_cache($cache_key); if ($k) { return $k; } // да есть в кэше $out = ''; $out .= '<div class="page_content sitemap">' . NR . mso_hook('sitemap_do'); $out .= '<div class="sitemap-link"><a href="' . getinfo('siteurl') . 'sitemap">' . tf('Группировка по датам') . '</a>' . NR . '</div>'; $all = mso_cat_array('page', 0, 'category_menu_order', 'asc', 'category_name', 'asc', array(), array(), 0, 0, true); $out .= mso_create_list($all, array('function' => '_sitemap_cat_elem', 'childs' => 'childs', 'format' => '<h3>[TITLE_HTML]</h3><p><em>[DESCR_HTML]</em></p>[FUNCTION]', 'format_current' => '', 'class_ul' => '', 'title' => 'category_name', 'link' => 'category_slug', 'current_id' => false, 'prefix' => 'category/', 'count' => 'pages_count', 'slug' => 'category_slug', 'id' => 'category_id', 'menu_order' => 'category_menu_order', 'id_parent' => 'category_id_parent')); $out .= NR . mso_hook('sitemap_posle') . '</div>' . NR; mso_add_cache($cache_key, $out); // сразу в кэш добавим return $out; }
function rss_get_go($arg) { // здесь нет проверок на корректность $arg, потому что мы её уже выполнили в rss_get_widget_custom if (!$arg['url']) { return false; } # проверим кеш, может уже есть в нем все данные $cache_key = 'rss/' . 'rss_get_' . md5(serialize($arg)); $k = mso_get_cache($cache_key, true); if ($k) { return $k; // да есть в кэше } else { require_once getinfo('plugins_dir') . 'rss_get/lastrss.php'; $rss_pars = new lastRSS(); $rss_pars->convert_cp = $arg['charset']; $rss_pars->itemtags = mso_explode($arg['fields'], false); $rss = $rss_pars->Get($arg['url']); } if (!$rss) { return ''; } if (isset($rss[$arg['fields_items']])) { $rss = $rss[$arg['fields_items']]; $rss = array_slice($rss, 0, $arg['count']); // колво записей } else { return ''; // нет items } // меняем ключи с values и заполняем нулями - это шаблон для полей $fields = array_fill_keys(mso_explode($arg['fields'], false), false); $out = ''; foreach ($rss as $item) { // заполним массив шаблона полей значениями из итема $fields_out = $fields; foreach ($fields as $field => $tmp) { if (isset($item[$field])) { $fields_out[$field] = $item[$field]; continue; } } $out1 = $arg['format']; foreach ($fields_out as $field => $value) { // обратное преобразование в html $value = str_replace('<', '<', $value); $value = str_replace('>', '>', $value); $value = str_replace('&', '&', $value); $value = str_replace('<![CDATA[', '', $value); $value = str_replace(']]>', '', $value); // если стоит максимальное колво слов, то обрежем лишнее if ($arg['max_word_description'] and $field != 'link') { $value = mso_str_word($value, $arg['max_word_description']); } // если поле содержит date, то пробуем его преобразовать в нужный нам формат даты if (strpos($field, 'dc:date') !== false or strpos($field, 'date') !== false or $field == 'published' or $field == 'updated') { if (($d = strtotime($value)) !== -1) { // успешное преобразование $value = date($arg['format_date'], $d); } } if ($field == 'link') { $link_host = parse_url($value); $link_host = $link_host['host']; $out1 = str_replace('[link-host]', $link_host, $out1); } $out1 = str_replace('[' . $field . ']', $value, $out1); } $out .= $out1; } if ($out and $arg['time_cache']) { mso_add_cache($cache_key, $out, $arg['time_cache'] * 60, true); } return $out; }
function last_comments_widget_custom($options = array(), $num = 1) { if (!isset($options['count'])) { $options['count'] = 5; } if (!isset($options['words'])) { $options['words'] = 20; } if (!isset($options['maxchars'])) { $options['maxchars'] = 20; } if (!isset($options['header'])) { $options['header'] = ''; } $options['count'] = (int) $options['count']; if ($options['count'] < 1) { $options['count'] = 5; } $options['words'] = (int) $options['words']; if ($options['words'] < 1) { $options['words'] = 20; } $options['maxchars'] = (int) $options['maxchars']; if ($options['maxchars'] < 1) { $options['maxchars'] = 20; } $cache_key = 'last_comments_widget_' . $num . mso_md5(serialize($options)); $k = mso_get_cache($cache_key, true); if ($k) { return $k; } // да есть в кэше require_once getinfo('common_dir') . 'comments.php'; // функции комментариев $comments = mso_get_comments(false, array('limit' => $options['count'], 'order' => 'desc')); $out = ''; if ($comments) { // сгруппируем все комментарии по записям $arr_com_page = array(); $arr_com_page_title = array(); foreach ($comments as $comment) { $arr_com_page[$comment['page_id']][$comment['comments_id']] = $comment; $arr_com_page_title[$comment['page_id']] = $comment['page_title']; } // выводим по странично foreach ($arr_com_page as $key => $comments) { $out .= '<h5>' . $arr_com_page_title[$key] . '</h5>'; $comments = array_reverse($comments); // чтобы комментарии были в привычном порядке сверху вниз $out .= '<ul class="mso-widget-list">'; foreach ($comments as $comment) { extract($comment); if ($comment['comments_users_id']) { $css_style_add = 'last_comment_users ' . ' mso-last-comment-users-' . $comment['comments_users_id']; } elseif ($comment['comments_comusers_id']) { $css_style_add = 'last_comment_comusers ' . ' mso-last-comment-comusers-' . $comment['comments_comusers_id']; } else { $css_style_add = 'last_comment_anonim'; } $out .= '<li class="' . $css_style_add . '"><a href="' . getinfo('siteurl') . 'page/' . mso_slug($page_slug) . '#comment-' . $comments_id . '"><b>'; if ($comments_users_id) { $out .= $users_nik; } elseif ($comments_comusers_id) { if ($comusers_nik) { $out .= $comusers_nik; } else { $out .= t('Комментатор') . ' ' . $comusers_id; } } elseif ($comments_author_name) { $out .= $comments_author_name; } else { $out .= ' ' . t('Аноним'); } $comments_content_1 = strip_tags($comments_content); // удалим тэги $comments_content = mso_str_word($comments_content_1, $options['words']); // ограничение на количество слов // если старый и новый текст после обрезки разные, значит добавим в конце ... if ($comments_content_1 != $comments_content) { $comments_content .= '...'; } // каждое слово нужно проверить на длину и если оно больше maxchars, то добавить пробел в wordwrap $words = explode(' ', $comments_content); foreach ($words as $key => $word) { $words[$key] = mso_wordwrap($word, $options['maxchars'], ' '); } $comments_content = implode(' ', $words); $out .= ' »</b> ' . strip_tags($comments_content) . '</a>'; $out .= '</li>' . NR; } $out .= '</ul>'; } if ($options['header']) { $out = $options['header'] . $out; } } mso_add_cache($cache_key, $out, false, true); // сразу в кэш добавим return trim($out); }
function top_commentators_widget_custom($options = array(), $num = 1) { if (!isset($options['format'])) { $options['format'] = '[LINK_URL][NAME][/LINK]<sup>[COUNT]</sup>'; } if (!isset($options['commentators_cnt'])) { $options['commentators_cnt'] = 10; } if (!isset($options['days'])) { $options['days'] = 30; } $cache_key = 'top_commentators_widget' . serialize($options) . $num; $k = mso_get_cache($cache_key); if ($k) { $out = $k; } else { $CI =& get_instance(); $CI->db->select('comusers_id,comusers_nik,comusers_url,count(comments_id) as com_cnt'); $CI->db->from('comments'); $CI->db->join('comusers', 'comusers.comusers_id = comments.comments_comusers_id'); $CI->db->limit($options['commentators_cnt']); $CI->db->where('comments_date >', date('Y-m-d H:i:s', time() - $options['days'] * 24 * 60 * 60)); $CI->db->where('comments_approved', '1'); $CI->db->where('comusers_activate_string', 'comusers_activate_key', false); $CI->db->group_by('comusers_nik'); $CI->db->order_by('com_cnt', 'DESC'); $query = $CI->db->get(); $out = ''; if ($query->num_rows() > 0) { $users = $query->result_array(); foreach ($users as $user) { if ($user['comusers_nik'] == '') { $user['comusers_nik'] = t('Комментатор') . ' ' . $user['comusers_id']; } if ($user['comusers_url'] == '') { $user['comusers_url'] = getinfo('siteurl') . 'users/' . $user['comusers_id']; } $out .= '<li>' . str_replace(array('[NAME]', '[COUNT]', '[/LINK]', '[LINK_URL]', '[LINK_PAGE]'), array($user['comusers_nik'], $user['com_cnt'], '</a>', '<a href="' . $user['comusers_url'] . '">', '<a href="' . getinfo('siteurl') . 'users/' . $user['comusers_id'] . '">'), $options['format']) . '</a></li>'; } if ($out) { $out = $options['header'] . '<ul class="mso-widget-list">' . $out . '</ul>' . NR; } } mso_add_cache($cache_key, $out); // сразу в кэш добавим } return $out; }
* MaxSite CMS * (c) http://max-3000.com/ */ echo NR . '<div class="mso-type-home-cat-block">' . NR; if ($f = mso_page_foreach('home-cat-block-text-do')) { require $f; } // нужно считать каждую указанную рубрику и в цикле // получить для неё все данные и сразу вывести // параметры для получения страниц - общие для всех $par = array('limit' => mso_get_option('home_limit_post', 'templates', '7'), 'cut' => mso_get_option('more', 'templates', tf('Читать полностью »')), 'cat_order' => 'category_id_parent', 'cat_order_asc' => 'asc', 'pagination' => false, 'exclude_page_id' => mso_get_val('exclude_page_id')); $home_cat_block = mso_explode(mso_get_option('home_cat_id', 'templates', '0')); // в массив // все блоки можно закэшировать на 15 минут $key_home_cache = serialize($home_cat_block); if ($k = mso_get_cache($key_home_cache)) { print $k; } else { ob_start(); if ($home_cat_block) { // перебираем рубрики foreach ($home_cat_block as $cat_id) { if ($f = mso_page_foreach('home-cat-block')) { require $f; // подключаем кастомный вывод continue; // следующая итерация } $par['cat_id'] = $cat_id; // подключаем кастомный вывод, где можно изменить массив параметров $par для своих задач if ($f = mso_page_foreach('home-cat-block-mso-get-pages')) {
function events_widget_custom($options = array(), $num = 1) { // кэш $cache_key = 'events_widget_custom' . serialize($options) . $num; $k = mso_get_cache($cache_key); if ($k) { return $k; } // да есть в кэше $out = ''; if (!isset($options['events'])) { return ''; } // нет событий, выходим if (!isset($options['header'])) { $options['header'] = ''; } if (!isset($options['format_date'])) { $options['format_date'] = 'l, j F'; } /* дата | до | после | событие 2008-09-01 | 5 | 1 | Пора в школу! */ // для перевода дат $day_en = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); $day_ru = array(t('Понедельник'), t('Вторник'), t('Среда'), t('Четверг'), t('Пятница'), t('Суббота'), t('Воскресенье'), t('Пн'), t('Вт'), t('Ср'), t('Чт'), t('Пт'), t('Сб'), t('Вс'), t('января'), t('февраля'), t('марта'), t('апреля'), t('мая'), t('июня'), t('июля'), t('августа'), t('сентября'), t('октября'), t('ноября'), t('декабря'), t('янв'), t('фев'), t('мар'), t('апр'), t('май'), t('июн'), t('июл'), t('авг'), t('сен'), t('окт'), t('ноя'), t('дек')); $events = explode("\n", trim($options['events'])); asort($events); $curdate = time() + getinfo('time_zone') * 60 * 60; //pr($curdate); pr('========='); foreach ($events as $event) { $event = trim($event); if (!$event) { continue; } $event = explode('|', $event); if (count($event) < 4) { continue; } // неверные данные $date = strtotime(trim($event[0])) + getinfo('time_zone') * 60 * 60; // дата учитываем смещение времени для сайта $do = strtotime("-" . trim($event[1]) . " day", $date); // до указаной даты $posle = strtotime("+" . trim($event[2]) . " day", $date); // после указанной даты // pr($date); pr($do); pr($posle); pr('----------'); if ($curdate >= $do and $curdate <= $posle) { $od = date($options['format_date'], $date); // форматируем вывод даты $od = str_replace($day_en, $day_ru, $od); // переводим на русский // if ($curdate > $date and ( ( $curdate - $date ) > 86400 ) ) if ($curdate - $date > 86400) { $out .= '<li><del><span>' . $od . '</span> - ' . $event[3] . '</del></li>' . NR; } else { $out .= '<li><span>' . $od . '</span> - ' . $event[3] . '</li>' . NR; } } } if ($out) { $out = $options['header'] . '<ul class="mso-widget-list">' . NR . $out . '</ul>' . NR; } mso_add_cache($cache_key, $out); // сразу в кэш добавим return $out; }
function perelinks_custom($content = '') { // получаем список всех титлов - возможно из кэша // после этого выполняем замену всех этих вхождений в тексте на ссылки global $page; // текущая страница - это массив $options = mso_get_option('perelinks', 'plugins', array()); // получаем опции $options['linkcount'] = isset($options['linkcount']) ? (int) $options['linkcount'] : 0; $options['wordcount'] = isset($options['wordcount']) ? (int) $options['wordcount'] : 0; $options['allowlate'] = isset($options['allowlate']) ? (int) $options['allowlate'] : 1; $options['stopwords'] = isset($options['stopwords']) ? $options['stopwords'] : 'будет нужно'; if (isset($options['stopwords'])) { $stopwords = explode(' ', $options['stopwords']); } $cache_key = 'perelinks_custom'; if ($k = mso_get_cache($cache_key)) { $all_title = $k; } else { $CI =& get_instance(); $CI->db->select('page_title, page_slug'); if ($options['allowlate'] > 0) { $CI->db->where('page_date_publish <', date('Y-m-d H:i:s')); // $CI->db->where('page_date_publish <', 'NOW()', false); } else { $CI->db->where('page_date_publish <', $page['page_date_publish']); } $CI->db->where('page_status', 'publish'); $CI->db->from('page'); $query = $CI->db->get(); $all_title = array(); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { $title = mb_strtolower($row['page_title'], 'UTF-8'); $title = str_replace(array('\\', '|', '/', '?', '%', '*', '`', ',', '.', '$', '!', '\'', '"', '«', '»', '—'), '', $title); $a_words = explode(' ', $title); $a_words = array_unique($a_words); $title = array(); foreach ($a_words as $word) { if (mb_strlen($word, 'UTF-8') > 3 and !in_array($word, $stopwords)) { $title[] = $word; } } foreach ($title as $word) { $all_title[$word][] = $row['page_slug']; } } } mso_add_cache($cache_key, $all_title); } $curr_page_slug = $page['page_slug']; // текущая страница - для ссылки $my_site = getinfo('siteurl') . 'page/'; // ищем вхождения $linkcounter = 0; foreach ($all_title as $key => $word) { $r = '| (' . preg_quote($key) . ') |siu'; if (preg_match($r, $content)) { if (!in_array($curr_page_slug, $word)) { if ($options['wordcount'] > 0) { $r = '| (' . preg_quote($key) . ') (.*$)|siu'; } //Если только первое найденное слово-дубликат делать ссылкой $content = preg_replace($r, ' <a href="' . $my_site . $word[0] . '" class="perelink">\\1</a> \\2', $content); $linkcounter++; } } if ($linkcounter > 0 and $linkcounter == $options['linkcount']) { break; } } return $content; }
function mso_page_map($page_id = 0, $page_id_parent = 0) { $cache_key = 'mso_page_map' . $page_id . '-' . $page_id_parent; $k = mso_get_cache($cache_key); if ($k) { return $k; } // да есть в кэше $CI =& get_instance(); $CI->db->select('page_id, page_id_parent, page_title, page_slug'); if ($page_id) { $CI->db->where('page_id', $page_id); $CI->db->where('page_id_parent', '0'); $CI->db->where('page_status', 'publish'); $CI->db->where('page_date_publish < ', date('Y-m-d H:i:s')); // $CI->db->where('page_date_publish <', 'NOW'); $CI->db->or_where('page_id', $page_id_parent); } $CI->db->order_by('page_menu_order'); $query = $CI->db->get('page'); $result = $query->result_array(); // здесь все страницы foreach ($result as $key => $row) { $k = $row['page_id']; $r[$k] = $row; if ($k == $page_id) { $r[$k]['current'] = 1; } $ch = _mso_page_map_get_child($row['page_id'], $page_id); if ($ch) { $r[$k]['childs'] = $ch; } } // pr($k); // pr($r); if (!isset($r[$k]['childs'])) { $r = array(); } // в итоге нет детей у первого элемента, все обнуляем mso_add_cache($cache_key, $r); // в кэш return $r; }
function last_pages_widget_custom($arg = array(), $num = 1) { if (!isset($arg['count'])) { $arg['count'] = 7; } if (!isset($arg['page_type'])) { $arg['page_type'] = 'blog'; } if (!isset($arg['sort'])) { $arg['sort'] = 'page_date_publish'; } if (!isset($arg['sort_order'])) { $arg['sort_order'] = 'desc'; } if (!isset($arg['date_format'])) { $arg['date_format'] = 'd/m/Y'; } if (!isset($arg['format'])) { $arg['format'] = '<h4>[TITLE]</h4><p>[DATE] [COMMENTS]</p>[IMG]<p>[TEXT]</p>'; } if (!isset($arg['comments_format'])) { $arg['comments_format'] = ' | ' . t('Комментариев: ') . '[COUNT]'; } if (!isset($arg['include_cat'])) { $arg['include_cat'] = ''; } if (!isset($arg['img_prev_def'])) { $arg['img_prev_def'] = ''; } if (!isset($arg['img_prev_attr'])) { $arg['img_prev_attr'] = 'class="b-left w100"'; } if (!isset($arg['max_words'])) { $arg['max_words'] = 20; } if (!isset($arg['text_do'])) { $arg['text_do'] = ''; } if (!isset($arg['text_posle'])) { $arg['text_posle'] = ''; } if (!isset($arg['header'])) { $arg['header'] = mso_get_val('widget_header_start', '<div class="mso-widget-header"><span>') . t('Последние записи') . mso_get_val('widget_header_end', '</span></div>'); } if (!isset($arg['block_start'])) { $arg['block_start'] = ''; } if (!isset($arg['block_end'])) { $arg['block_end'] = ''; } if ($arg['sort_order'] != 'random') { $cache_key = 'last_pages_widget' . serialize($arg) . $num; if ($k = mso_get_cache($cache_key)) { return $k; } // да есть в кэше } $par = array('limit' => $arg['count'], 'cut' => '', 'cat_order' => 'category_name', 'cat_order_asc' => 'asc', 'pagination' => false, 'cat_id' => $arg['include_cat'], 'order' => $arg['sort'], 'order_asc' => $arg['sort_order'], 'type' => $arg['page_type'], 'custom_type' => 'home'); $pages = mso_get_pages($par, $temp); $out = ''; if ($pages) { foreach ($pages as $page) { // [TITLE] [DATE] [TEXT] [IMG] [COMMENTS] [URL] $title = mso_page_title($page['page_slug'], $page['page_title'], '', '', true, false, 'page'); $url = getinfo('site_url') . 'page/' . $page['page_slug']; $date = mso_page_date($page['page_date_publish'], $arg['date_format'], '', '', false); $img = isset($page['page_meta']['image_for_page'][0]) ? $page['page_meta']['image_for_page'][0] : ''; if (!$img and $arg['img_prev_def']) { $img = $arg['img_prev_def']; } if ($img) { $img = '<a href="' . $url . '"><img src="' . $img . '" alt="' . $page['page_title'] . '" ' . $arg['img_prev_attr'] . '></a>'; } if ($page['page_count_comments']) { $comments = str_replace('[COUNT]', $page['page_count_comments'], $arg['comments_format']); } else { $comments = ''; } $text = mso_str_word(strip_tags($page['page_content']), $arg['max_words']) . ' ...'; $out_page = $arg['format']; $out_page = str_replace('[TITLE]', $title, $out_page); $out_page = str_replace('[DATE]', $date, $out_page); $out_page = str_replace('[COMMENTS]', $comments, $out_page); $out_page = str_replace('[URL]', $url, $out_page); $out_page = str_replace('[TEXT]', $text, $out_page); $out_page = str_replace('[IMG]', $img, $out_page); $out .= $out_page; } $out = $arg['header'] . $arg['block_start'] . $arg['text_do'] . $out . $arg['text_posle'] . $arg['block_end']; } if ($arg['sort_order'] != 'random') { mso_add_cache($cache_key, $out); } // в кэш return $out; }
function picasa_go($url = false, $show_type = 1, $albums_count = 10, $album_name = false, $img_size = 32) { if (!$url) { return false; } # проверим кеш, может уже есть в нем все данные $cache_key = 'rss/' . 'picasa_' . $url . $show_type . (int) $albums_count . $album_name . $img_size; $k = mso_get_cache($cache_key, true); if ($k) { return $k; } // да есть в кэше if (!defined('MAGPIE_CACHE_AGE')) { define('MAGPIE_CACHE_AGE', 3600); } // время кэширования MAGPIE require_once getinfo('common_dir') . 'magpierss/rss_fetch.inc'; if ($show_type == 1) { $rss = fetch_rss("http://picasaweb.google.com/data/feed/base/user/" . $url . "?alt=rss&kind=album&hl=ru&access=public"); $rss = array_slice($rss->items, 0, $albums_count); $result = ''; foreach ($rss as $item) { $title = $item['title']; $title = str_replace("'", "", $title); $title = str_replace('"', "", $title); $result .= "<p><a href='" . $item['link'] . "' target='_blank' rel='nofollow'>" . $title . "</a></p>"; } } if ($show_type == 2) { $rss = fetch_rss("http://picasaweb.google.com/data/feed/base/user/" . $url . "?alt=rss&kind=album&hl=ru&access=public"); $rss = array_slice($rss->items, 0, $albums_count); $result = ''; foreach ($rss as $item) { $title = $item['title']; $title = str_replace("'", "", $title); $title = str_replace('"', "", $title); preg_match('/.*src="(.*?)".*/', $item['description'], $img_src); $path = $img_src[1]; $path = str_replace("s160-", "s" . $img_size . "-", $path); $result .= "<a href='" . $item['link'] . "' target='_blank' rel='nofollow'><img src='" . $path . "' class='picasa-photo' alt='' title='" . $title . "' width='" . $img_size . "' height='" . $img_size . "'></a>"; } } if ($show_type == 3) { $rss = fetch_rss("http://picasaweb.google.com/data/feed/base/user/" . $url . "/album/" . $album_name . "?alt=rss&kind=photo&hl=ru&access=public"); $rss = array_slice($rss->items, 0, $albums_count); $result = ''; foreach ($rss as $item) { $title = $item['title']; $title = str_replace("'", "", $title); $title = str_replace('"', "", $title); preg_match('/.*src="(.*?)".*/', $item['description'], $img_src); $path = $img_src[1]; $path = str_replace("s288", "s" . $img_size, $path); $result .= "<a href='" . $item['link'] . "' target='_blank' rel='nofollow'><img src='" . $path . "' class='picasa-photo' alt='' title='" . $title . "'></a>"; } } mso_add_cache($cache_key, $result, 300, true); return $result; }
function mso_get_author_info($id = 0) { if (!$id) { $id = mso_segment(2); } if (!$id or !is_numeric($id)) { return array(); } // неверный id $key_cache = 'mso_get_author_info_' . $id; if ($k = mso_get_cache($key_cache)) { return $k; } // да есть в кэше $out = array(); $CI =& get_instance(); $CI->db->select('*'); $CI->db->where('users_id', $id); $query = $CI->db->get('users'); if ($query->num_rows() > 0) { $out = $query->result_array(); $out = $out[0]; } mso_add_cache($key_cache, $out); return $out; }
exit('No direct script access allowed'); } /** * MaxSite CMS * (c) http://max-3000.com/ * 25-11-2015 */ /* Универсальный юнит для вывода записей по множеству критериев [unit] file = last-pages.php limit = 3 [/unit] Значение ключей по-умолчанию см. переменную $def */ # используем кэширование $home_cache_time = (int) mso_get_option('home_cache_time', 'templates', 0); $home_cache_key = getinfo('template') . '-' . __FILE__ . '-' . mso_current_paged() . '-' . $UNIT_NUM; if ($home_cache_time > 0 and $k = mso_get_cache($home_cache_key)) { echo $k; } else { $def = array('limit' => 3, 'cat_id' => "0", 'page_id' => "0", 'pagination' => false, 'type' => 'blog', 'order' => 'page_date_publish', 'order_asc' => 'desc', 'cut' => '»»»', 'show_cut' => false, 'date_now' => true, 'page_id_autor' => 0, 'thumb' => true, 'thumb_width' => 100, 'thumb_height' => 100, 'class_thumb' => 'b-left mar15-r rounded', 'content' => true, 'content_words' => 0, 'content_chars' => 0, 'content_cut' => '...', 'content_start' => '<div class="mso-page-content clearfix">', 'content_end' => '</div>', 'line1' => '[title][date]', 'line2' => '[thumb]', 'line3' => '', 'line4' => '[cat]', 'line5' => '<p class="t-right"><a href="[page_url]">Читать дальше</a></p>', 'title_start' => '<h4>', 'title_end' => '</h4>', 'block_start' => '<div class="layout-center flex flex-wrap pad5-rl">', 'block_end' => '</div>', 'page_start' => '<div class="w32 w48-tablet w100-phone pad20 mar15-tb bor1px bor-solid bor-gray400 rounded">', 'page_end' => '</div>', 'date' => 'j F Y, H:i', 'date_start' => '<p class="italic t90 i-calendar"><time datetime="[page_date_publish_iso]">', 'date_end' => '</time></p>', 'cat_start' => '<p class="i-folder t90">', 'cat_end' => '', 'cat_sep' => ',&NBSP;', 'tag_start' => '<p class="i-tag t90">', 'tag_end' => '</p>', 'tag_sep' => ',&NBSP;', 'author_start' => '', 'author_end' => '', 'read' => '»»»', 'read_start' => '<p>', 'read_end' => '</p>', 'comments_count_start' => '', 'comments_count_end' => '', 'placehold' => true, 'placehold_path' => 'http://placehold.it/', 'placehold_pattern' => '[W]x[H].png', 'placehold_file' => 'data', 'placehold_data_bg' => '#EEEEEE', 'pagination_start' => '', 'pagination_end' => '', 'exclude_page_allow' => true, 'exclude_page_add' => true); $UNIT = mso_merge_array($UNIT, $def); ob_start(); $b = new Block_pages(array('limit' => $UNIT['limit'], 'cat_id' => $UNIT['cat_id'], 'page_id' => $UNIT['page_id'], 'pagination' => $UNIT['pagination'], 'type' => $UNIT['type'], 'order' => $UNIT['order'], 'order_asc' => $UNIT['order_asc'], 'cut' => $UNIT['cut'], 'show_cut' => $UNIT['show_cut'], 'date_now' => $UNIT['date_now'], 'page_id_autor' => $UNIT['page_id_autor'], 'exclude_page_allow' => $UNIT['exclude_page_allow'])); if ($b->go) { $b->output(array('block_start' => $UNIT['block_start'], 'block_end' => $UNIT['block_end'], 'content' => $UNIT['content'], 'content_words' => $UNIT['content_words'], 'content_chars' => $UNIT['content_chars'], 'content_cut' => $UNIT['content_cut'], 'content_start' => $UNIT['content_start'], 'content_end' => $UNIT['content_end'], 'thumb' => $UNIT['thumb'], 'thumb_width' => $UNIT['thumb_width'], 'thumb_height' => $UNIT['thumb_height'], 'thumb_class' => $UNIT['class_thumb'], 'line1' => $UNIT['line1'], 'line2' => $UNIT['line2'], 'line3' => $UNIT['line3'], 'line4' => $UNIT['line4'], 'line5' => $UNIT['line5'], 'title_start' => $UNIT['title_start'], 'title_end' => $UNIT['title_end'], 'page_start' => $UNIT['page_start'], 'page_end' => $UNIT['page_end'], 'date' => $UNIT['date'], 'date_start' => $UNIT['date_start'], 'date_end' => $UNIT['date_end'], 'cat_start' => $UNIT['cat_start'], 'cat_end' => $UNIT['cat_end'], 'cat_sep' => $UNIT['cat_sep'], 'tag_start' => $UNIT['tag_start'], 'tag_end' => $UNIT['tag_end'], 'tag_sep' => $UNIT['tag_sep'], 'author_start' => $UNIT['author_start'], 'author_end' => $UNIT['author_end'], 'read' => $UNIT['read'], 'read_start' => $UNIT['read_start'], 'read_end' => $UNIT['read_end'], 'comments_count_start' => $UNIT['comments_count_start'], 'comments_count_end' => $UNIT['comments_count_start'], 'placehold' => $UNIT['placehold'], 'placehold_path' => $UNIT['placehold_path'], 'placehold_pattern' => $UNIT['placehold_pattern'], 'placehold_file' => $UNIT['placehold_file'], 'placehold_data_bg' => $UNIT['placehold_data_bg'], 'pagination_start' => $UNIT['pagination_start'], 'pagination_end' => $UNIT['pagination_end'], 'exclude_page_add' => $UNIT['exclude_page_add'])); } mso_add_cache($home_cache_key, ob_get_flush(), $home_cache_time * 60); } # end of file
function tagclouds3d_widget_custom($options = array(), $num = 1) { // кэш $cache_key = 'tagclouds3d_widget_custom' . serialize($options) . $num; $k = mso_get_cache($cache_key); if ($k) { return $k; } // да есть в кэше // формат вывода %SIZE% %URL% %TAG% %COUNT% // параметры $min_size $max_size $block_start $block_end // сортировка if (!isset($options['header'])) { $options['header'] = ''; } if (!isset($options['block_start'])) { $options['block_start'] = '<div class="tagclouds3d">'; } if (!isset($options['block_end'])) { $options['block_end'] = '</div>'; } if (!isset($options['min_size'])) { $min_size = 90; } else { $min_size = (int) $options['min_size']; } if (!isset($options['max_size'])) { $max_size = 230; } else { $max_size = (int) $options['max_size']; } if (!isset($options['max_num'])) { $max_num = 50; } else { $max_num = (int) $options['max_num']; } if (!isset($options['min_count'])) { $min_count = 0; } else { $min_count = (int) $options['min_count']; } if (!isset($options['width'])) { $width = 150; } else { $width = (int) $options['width']; } if (!isset($options['height'])) { $height = 150; } else { $height = (int) $options['height']; } if (!isset($options['speed'])) { $speed = 220; } else { $speed = (int) $options['speed']; } /* === */ if (!isset($options['bgcolor'])) { $bgcolor = 'FFFFFF'; } else { $bgcolor = $options['bgcolor']; } if (!isset($options['text_color'])) { $text_color = '000000'; } else { $text_color = $options['text_color']; } if (!isset($options['text_color2'])) { $text_color2 = 'CCCCCC'; } else { $text_color2 = $options['text_color2']; } if (!isset($options['hover_color'])) { $hover_color = '999999'; } else { $hover_color = $options['hover_color']; } /* === */ if (!isset($options['sort'])) { $sort = 0; } else { $sort = (int) $options['sort']; } require_once getinfo('common_dir') . 'meta.php'; // функции мета $tagcloud = mso_get_all_tags_page(); asort($tagcloud); $min = reset($tagcloud); $max = end($tagcloud); if ($max == $min) { $max++; } // сортировка перед выводом if ($sort == 0) { arsort($tagcloud); } elseif ($sort == 1) { asort($tagcloud); } elseif ($sort == 2) { ksort($tagcloud); } elseif ($sort == 3) { krsort($tagcloud); } else { arsort($tagcloud); } // по умолчанию $url = getinfo('siteurl') . 'tag/'; $out = ''; $links = ''; $links_noscript = ''; $i = 0; $format = '<a href=\'%URL%\' style=\'font-size:%SIZE%px;\'>%TAG%<\\/a>'; $no_script = '<a href="%URL%" style="font-size:%SIZE%px;">%TAG%</a>'; /* ============ */ foreach ($tagcloud as $tag => $count) { if ($min_count) { if ($count < $min_count) { continue; } } $font_size = round(($count - $min) / ($max - $min) * ($max_size - $min_size) + $min_size); $tag_url = urlencode($tag); $f = str_replace(array('%SIZE%', '%URL%', '%TAG%', '%COUNT%'), array($font_size, $url . $tag_url, $tag, $count), $format); $af = str_replace(array('%SIZE%', '%URL%', '%TAG%'), array($font_size, $url . $tag_url, $tag), $no_script); $links .= $f . ' '; $links_noscript .= $af . ' '; $i++; if ($max_num != 0 and $i == $max_num) { break; } } $out .= '<script src="' . getinfo('plugins_url') . 'tagclouds3d/swfobject.js"></script> <div id="tag3dcontent">'; $out .= $links_noscript; $out .= '<script> //<![CDATA[ var rnumber = Math.floor(Math.random()*9999999); var widget_so = new SWFObject("' . getinfo('plugins_url') . 'tagclouds3d/tagcloud.swf?r="+rnumber, "tagcloudflash", "' . $width . '", "' . $height . '", "9", "#' . $bgcolor . '"); widget_so.addParam("wmode", "transparent") widget_so.addParam("allowScriptAccess", "always"); widget_so.addVariable("tcolor", "0x' . $text_color . '"); widget_so.addVariable("tcolor2", "0x' . $text_color2 . '"); widget_so.addVariable("hicolor", "0x' . $hover_color . '"); widget_so.addVariable("tspeed", "' . $speed . '"); widget_so.addVariable("distr", "true"); widget_so.addVariable("mode", "tags"); widget_so.addVariable("tagcloud", "<span>'; $out .= $links . '<\\/span>"); widget_so.write("tag3dcontent"); //]]> </script> </div>'; if ($out) { $out = $options['header'] . $options['block_start'] . $out . $options['block_end']; } mso_add_cache($cache_key, $out); // сразу в кэш добавим return $out; }