Пример #1
0
 /**
  * вывод html-карты сайта по шорт-коду [sitemap-html]
  */
 static function viewSitemap()
 {
     $sitemap = Storage::get(md5('mgPluginSitemapHtml'));
     if ($sitemap == null) {
         $pages = self::getPages();
         $catalog = self::getCatalog();
         $html = '
 <div class="sitemap-html">
  <h2 class="new-products-title">Карта сайта</h2>
 <ul class="js_listSiteMap">';
         foreach ($pages as $url => $title) {
             $partsUrl = URL::getSections($url);
             $priority = count($partsUrl);
             if (is_array($title)) {
                 $html .= '<li><a href="' . SITE . '/' . $url . '">' . $title[$url] . '<ul>';
                 foreach ($title as $suburl => $subtitle) {
                     if ($suburl != $url) {
                         $html .= '<li><a href="' . SITE . '/' . $suburl . '" title="' . $subtitle . '">' . $subtitle . '</a></li>';
                     }
                 }
                 $html .= '</ul></li>';
             } else {
                 $html .= '<li><a href="' . SITE . '/' . $url . '" title="' . $title . '">' . $title . '</a></li>';
                 if ($url == 'catalog') {
                     $html .= '<ul>' . $catalog . '</ul>';
                 }
             }
         }
         $sitemap = $html . '</ul></div>';
         Storage::save(md5('mgPluginSitemapHtml'), $sitemap);
     }
     return $sitemap;
 }
Пример #2
0
 static function breadcrumbs()
 {
     $breadcrumbs = Storage::get(md5('breadcrumbs' . URL::getUrl()));
     if ($breadcrumbs == null) {
         $sections = URL::getSections();
         array_splice($sections, 0, 1);
         if (SHORT_LINK == 1 && MG::get('controller') == 'controllers_product') {
             $product_url = URL::getLastSection();
             $res = DB::query('SELECT CONCAT(c.`parent_url`, c.`url`) as fullurl
       FROM `' . PREFIX . 'product` p LEFT JOIN `' . PREFIX . 'category` c 
       ON p.cat_id  = c.id WHERE p.url = ' . DB::quote($product_url));
             $cat = DB::fetchArray($res);
             $sections = explode('/', $cat['fullurl']);
             $sections[] = $product_url;
         }
         $breadcrumbs = '<a href="' . SITE . '/catalog">Каталог</a>';
         $max = count($sections);
         $i = 0;
         $par = '';
         foreach ($sections as $section) {
             $url = $section;
             $cat = 'title';
             if ($url != 'catalog') {
                 $data = self::checkURLname('*', 'category', $section, 'url', $par);
                 $url = $data[0]['parent_url'] . $section;
                 $res = $data[0]['title'];
                 $par = $data[0]['id'];
                 if (!$data[0]['title']) {
                     $cat = 'name';
                     $n = '';
                     $result = self::checkURLname('*', 'product', $section, 'url', $n);
                     $url = $data[0]['parent_url'] . $sections[1] . '/' . $sections[2];
                     $categoryRes = self::checkURLname('url, parent_url', 'category', $result[0]['cat_id'], 'id');
                     $url = $categoryRes[0]['parent_url'] . $categoryRes[0]['url'] . '/' . $result[0]['url'];
                     $res = $result[0]['title'];
                 }
             }
             $i++;
             if ($max == $i) {
                 $breadcrumbs .= ' » <span class="last-crumb">' . $res . '</span>';
             } else {
                 $breadcrumbs .= ' » <a href="' . SITE . '/' . $url . '">' . $res . '</a>';
             }
         }
         $breadcrumbs = "<div class='bread-crumbs'>" . $breadcrumbs . "</div>";
         //сохраняем объект в кэш
         Storage::save(md5('breadcrumbs' . URL::getUrl()), $breadcrumbs);
     }
     return $breadcrumbs;
 }
Пример #3
0
 private static function resizeCategoryImg($file)
 {
     $categoryImgHeight = MG::getSetting('categoryImgHeight') ? MG::getSetting('categoryImgHeight') : 200;
     $categoryImgWidth = MG::getSetting('categoryImgWidth') ? MG::getSetting('categoryImgWidth') : 200;
     $arName = URL::getSections($file);
     $name = array_pop($arName);
     $pos = strpos($name, 'cat_');
     if ($pos != 0 || $pos === false) {
         $name = 'cat_' . $name;
     }
     $realDocumentRoot = str_replace(DIRECTORY_SEPARATOR . 'mg-core' . DIRECTORY_SEPARATOR . 'lib', '', $dirname = dirname(__FILE__));
     $upload = new Upload(false);
     $upload->_reSizeImage($name, $realDocumentRoot . $file, $categoryImgWidth, $categoryImgHeight, "PROPORTIONAL", "uploads/");
     return '/uploads/' . $name;
 }
Пример #4
0
 static function breadcrumbs()
 {
     $breadcrumbs = Storage::get(md5('breadcrumbs' . URL::getUrl()));
     if ($breadcrumbs == null) {
         $sections = URL::getSections();
         array_splice($sections, 0, 1);
         $breadcrumbs = '<a href="' . SITE . '/catalog">Каталог</a>';
         $max = count($sections);
         $i = 0;
         $par = '';
         foreach ($sections as $section) {
             $url = $section;
             $cat = 'title';
             if ($url != 'catalog') {
                 $data = self::checkURLname('*', 'category', $section, 'url', $par);
                 $url = $data[0]['parent_url'] . $section;
                 $res = $data[0]['title'];
                 $par = $data[0]['id'];
                 if (!$data[0]['title']) {
                     $cat = 'name';
                     $n = '';
                     $result = self::checkURLname('*', 'product', $section, 'url', $n);
                     $url = $data[0]['parent_url'] . $sections[1] . '/' . $sections[2];
                     $categoryRes = self::checkURLname('url, parent_url', 'category', $result[0]['cat_id'], 'id');
                     $url = $categoryRes[0]['parent_url'] . $categoryRes[0]['url'] . '/' . $result[0]['url'];
                     $res = $result[0]['title'];
                 }
             }
             $i++;
             if ($max == $i) {
                 $breadcrumbs .= ' » <span class="last-crumb">' . $res . '</span>';
             } else {
                 $breadcrumbs .= ' » <a href="' . SITE . '/' . $url . '">' . $res . '</a>';
             }
         }
         $breadcrumbs = "<div class='bread-crumbs'>" . $breadcrumbs . "</div>";
         //сохраняем объект в кэш
         Storage::save(md5('breadcrumbs' . URL::getUrl()), $breadcrumbs);
     }
     return $breadcrumbs;
 }
Пример #5
0
 /**
  * Получает название класса контролера, который будет обрабатывать текущий запрос.
  * @return string название класса нужного контролера.
  */
 private function getController()
 {
     if ($this->route == 'mg-admin') {
         $this->route = 'mgadmin';
     }
     // если отрывается главная страница, и при этом в настройках указано что нужно вывести каталог на главной
     if ($this->route == 'index' && MG::getSetting('mainPageIsCatalog') != 'true') {
         return false;
     }
     $sections = URL::getSections();
     if (count($sections) == 2 || count($sections) == 1 || $this->route == 'ajax' || $this->route == 'product' || $this->route == 'catalog') {
         if (file_exists(CORE_DIR . 'controllers/' . $this->route . '.php') || file_exists(PATH_TEMPLATE . '/controllers/' . $this->route . '.php')) {
             return 'controllers_' . $this->route;
         }
     }
     return false;
 }
Пример #6
0
 public static function printNews($arg)
 {
     $aUri = URL::getSections();
     $result = $arg['result'];
     if ($aUri[1] == 'news' && empty($aUri[2])) {
         MG::titlePage('Новости');
         $listNews = self::getListNews(MG::getOption('countPrintRowsNews'));
         $result = '
   <div class="page-content">
     <ul class="breadcrumbs bor-b">
       <li><a href="' . SITE . '" class="home">Главная</a></li>
       <span> / </span>
       <li>Новости</li>
     </ul><!-- !ul.breadcrumbs -->
     <h1 class="title-page">Новости</h1>';
         if (!empty($listNews['listNews'])) {
             foreach ($listNews['listNews'] as $news) {
                 $result .= '
       <div class="news-blocks-main">
         <div class="title-news-main">
           <a href="news/' . $news['url'] . '">' . ucfirst($news['title']) . '</a>
         </div>
         <div class="white-box bor-b clearfix">
           <img src="' . SITE . '/uploads/news/' . $news['image_url'] . '" alt="' . $news['title'] . '" title="' . $news['title'] . '">
           ' . mb_substr(strip_tags(PM::stripShortcodes($news['description'])), 0, 140, 'utf-8') . '
         </div><!-- !div.white-box -->
       </div><!-- !div.news-blocks-main -->
       ';
             }
             $result .= "{$listNews['pagination']}";
         } else {
             $result .= '<div class="white-box bor-b">Новости не найдены</div><!-- !div.page-content-box -->';
         }
         $result .= '</div><!-- !div.page-content -->';
     } else {
         if (URL::isSection('news')) {
             $news = self::getNewsByUrl(URL::getLastSection());
             if (empty($news)) {
                 MG::redirect('/404.html');
             }
             MG::titlePage($news['title']);
             MG::seoMeta($news);
             $body = MG::inlineEditor('mpl_news', 'description', $news['id'], $news['description']);
             $result = '
     <div class="page-content">
       <ul class="breadcrumbs bor-b">
         <li><a href="' . SITE . '" class="home">Главная</a></li>
         <span> / </span>
         <li><a href="' . SITE . '/news' . '">Новости</a></li>
         <span> / </span>
         <li>' . $news['title'] . '</li>
       </ul><!-- !ul.breadcrumbs -->
       <h1 class="title-page">' . $news['title'] . '</h1>
       <div class="white-box bor-b">
         ' . $body . '
       </div><!-- !div.page-content-box -->
       <div class="clearfix static-comments-btn">
         <div class="left">
           <p>Комментарии:</p>
         </div>
         <div class="right">
           <a href="#" class="add-cmt jq-add-cmt-static-page">Добавить комментарий</a>
         </div>
       </div><!-- !div.clearfix -->
       [comments]
     </div><!-- !div.page-content -->';
         }
     }
     return $result;
 }
Пример #7
0
echo MG::getOption('adminEmail');
?>
" class="gray"><?php 
echo MG::getOption('adminEmail');
?>
</a></td>
					</tr>
				</table>
				</div>			
			</div><!-- !div#header-info -->
		</div><!-- !div#header -->
		<div class="middle">
			<div class="container">
				<main class="content">
				<?php 
$aUri = URL::getSections();
?>
			<?php 
if (MG::get('isStaticPage')) {
    ?>
				<?php 
    $pageId = MG::get('page-id');
    ?>
				<div class="page-content">
				<ul class="breadcrumbs bor-b">
					<li><a href="<?php 
    echo SITE;
    ?>
" class="home">Главная</a></li>
					<span> / </span>
					<li><?php 
Пример #8
0
 /**
  * Получить путь до пользовательского файла, создающего контент страницы.
  * Файл должен находиться в папке mg-pages.
  * @return string - путь к php файлу.
  */
 public static function getPhpContent()
 {
     $result = false;
     $sections = URL::getSections();
     //проверем наличие скрипта в папке 'mg-pages', при этом нельзя напрямую обратьиться через 'mg-pages' в адресной строке
     if (count($sections) >= 1 && $sections[1] != 'mg-pages') {
         // если запрошен файл из корня 'mg-pages'
         if (file_exists(PAGE_DIR . URL::getRoute() . '.php')) {
             $result = PAGE_DIR . URL::getRoute() . '.php';
         } elseif (file_exists(PAGE_DIR . URL::getRoute() . '/index.php') && '/' == substr(URL::getURI(), -1)) {
             // если запрошена субдиректория из корня 'mg-pages' то пытаемся открыть в ней index.php
             $result = PAGE_DIR . URL::getRoute() . '/index.php';
         } elseif (file_exists(PAGE_DIR . URL::getRoute() . '/index.html') && '/' == substr(URL::getURI(), -1)) {
             // если запрошена субдиректория из корня 'mg-pages' в ней index.html
             $result = PAGE_DIR . URL::getRoute() . '/index.html';
         } elseif (file_exists(PAGE_DIR . URL::getUri()) && !is_dir(PAGE_DIR . URL::getUri())) {
             // если запрошен существующий файл и он не является директорией, а является файлом с расширением отличным от phph и HTML
             $result = PAGE_DIR . URL::getUri();
         }
     }
     $args = func_get_args();
     return self::createHook(__CLASS__ . "_" . __FUNCTION__, $result, $args);
 }
Пример #9
0
 public function __construct()
 {
     $aUri = URL::getSections();
     $settings = MG::get('settings');
     // Если нажата кнопка купить.
     $_REQUEST['category_id'] = URL::getQueryParametr('category_id');
     if (!empty($_REQUEST['inCartProductId'])) {
         $cart = new Models_Cart();
         $property = $cart->createProperty($_POST);
         $cart->addToCart($_REQUEST['inCartProductId'], $_REQUEST['amount_input'], $property);
         SmalCart::setCartData();
         MG::redirect('/cart');
     }
     $countСatalogProduct = $settings['countСatalogProduct'];
     // Показать первую страницу выбранного раздела.
     $page = 1;
     // Запрашиваемая страница.
     if (isset($_REQUEST['p'])) {
         $page = $_REQUEST['p'];
     }
     $sortType = 'desc';
     $countGoods = $settings['countСatalogProduct'];
     $isStock = 0;
     // Обработка GET параметров
     if (isset($_GET['count'])) {
         switch ($_GET['count']) {
             case 8:
                 $countGoods = 8;
                 break;
             case 12:
                 $countGoods = 12;
                 break;
             case 16:
                 $countGoods = 16;
                 break;
             default:
                 $countGoods = 8;
                 break;
         }
     }
     if (isset($_GET['sort'])) {
         switch ($_GET['sort']) {
             case 'priceDesc':
                 $sortType = 'desc';
                 break;
             case 'priceAsc':
                 $sortType = 'asc';
                 break;
             case 'comments':
                 $sortType = 'comments';
                 break;
             case 'popular':
                 $sortType = 'popular';
                 break;
             default:
                 $sortType = 'desc';
                 break;
         }
     }
     if (isset($_GET['stock'])) {
         if ($_GET['stock'] == 1) {
             $isStock = 1;
         } else {
             $isStock = 0;
         }
     }
     $model = new Models_Catalog();
     $isMainCat = TRUE;
     $subCat = MG::get('category')->getCategoryList($_REQUEST['category_id']);
     if (empty($subCat)) {
         $isMainCat = FALSE;
     }
     // Если происходит поиск по ключевым словам.
     $keyword = URL::getQueryParametr('search');
     if (!empty($keyword)) {
         $items = $model->getListProductByKeyWord($keyword, false, false, false, $sortType, $isStock, $countGoods);
         $searchData = array('keyword' => $keyword, 'count' => $items['numRows']);
     } else {
         if ($isMainCat) {
             $model->categoryId = MG::get('category')->getCategoryList($_REQUEST['category_id']);
             $model->categoryId[] = $_REQUEST['category_id'];
             $subCatList = $model->getChildCat();
             if (!empty($subCatList)) {
                 $productList = $model->getMainCatProduct($subCatList);
                 $catList = $model->getMainCatInfo($subCatList);
                 $i = 0;
                 foreach ($catList as $cat) {
                     foreach ($productList as $prd) {
                         if ($prd['cat_id'] == $cat['id']) {
                             $imagesUrl = explode("|", $prd['image_url']);
                             if (!empty($imagesUrl[0])) {
                                 $prd['image_url'] = $imagesUrl[0];
                             }
                             $catList[$i]['items'][] = $prd;
                         }
                     }
                     $i++;
                 }
             }
         } else {
             // Получаем список вложенных категорий, для вывода всех продуктов, на страницах текущей категории.
             $model->categoryId = MG::get('category')->getCategoryList($_REQUEST['category_id']);
             // В конец списка, добавляем корневую текущую категорию.
             $model->categoryId[] = $_REQUEST['category_id'];
             $items = $model->getList($countGoods, false, true, $sortType, $isStock);
         }
     }
     $settings = MG::get('settings');
     if (!$isMainCat) {
         foreach ($items['catalogItems'] as $item) {
             $productIds[] = $item['id'];
         }
         $product = new Models_Product();
         $blocksVariants = $product->getBlocksVariantsToCatalog($productIds);
         foreach ($items['catalogItems'] as $k => $item) {
             $items['catalogItems'][$k]["recommend"] = 0;
             $items['catalogItems'][$k]["new"] = 0;
             $imagesUrl = explode("|", $item['image_url']);
             $items['catalogItems'][$k]["image_url"] = "";
             if (!empty($imagesUrl[0])) {
                 $items['catalogItems'][$k]["image_url"] = $imagesUrl[0];
             }
             $items['catalogItems'][$k]['title'] = MG::modalEditor('catalog', $item['title'], 'edit', $item["id"]);
             // Формируем варианты товара.
             if ($item['variant_exist']) {
                 // Легкая форма без характеристик.
                 $liteFormData = $product->createPropertyForm($param = array('id' => $item['id'], 'maxCount' => $item['count'], 'productUserFields' => null, 'action' => "/catalog", 'method' => "POST", 'ajax' => true, 'blockedProp' => array(), 'noneAmount' => true, 'titleBtn' => "В корзину", 'blockVariants' => $blocksVariants[$item['id']]));
                 $items['catalogItems'][$k]['liteFormData'] = $liteFormData['html'];
             }
         }
     }
     $categoryDesc = MG::get('category')->getDesctiption($_REQUEST['category_id']);
     if ($_REQUEST['category_id']) {
         $categoryDesc = MG::inlineEditor(PREFIX . 'category', "html_content", $_REQUEST['category_id'], $categoryDesc);
     }
     if ($isMainCat) {
         $data = array('titeCategory' => $model->currentCategory['title'], 'cat_desc' => $categoryDesc, 'meta_title' => !empty($model->currentCategory['meta_title']) ? $model->currentCategory['meta_title'] : $model->currentCategory['title'], 'meta_keywords' => !empty($model->currentCategory['meta_keywords']) ? $model->currentCategory['meta_keywords'] : "товары,продукты,изделия", 'meta_desc' => !empty($model->currentCategory['meta_desc']) ? $model->currentCategory['meta_desc'] : "В каталоге нашего магазина есть все.", 'is_main_cat' => $isMainCat, 'category_info' => $catList, 'currency' => MG::getSetting('currency'), 'id_category' => $model->getCurrentId(), 'searchData' => empty($searchData) ? '' : $searchData);
     } else {
         $data = array('items' => $items['catalogItems'], 'titeCategory' => $model->currentCategory['title'], 'cat_desc' => $categoryDesc, 'pager' => $items['pager'], 'searchData' => empty($searchData) ? '' : $searchData, 'meta_title' => !empty($model->currentCategory['meta_title']) ? $model->currentCategory['meta_title'] : $model->currentCategory['title'], 'meta_keywords' => !empty($model->currentCategory['meta_keywords']) ? $model->currentCategory['meta_keywords'] : "товары,продукты,изделия", 'meta_desc' => !empty($model->currentCategory['meta_desc']) ? $model->currentCategory['meta_desc'] : "В каталоге нашего магазина есть все.", 'currency' => $settings['currency'], 'actionButton' => MG::getSetting('actionInCatalog') === "true" ? 'actionBuy' : 'actionView', 'is_main_cat' => $isMainCat, 'id_category' => $model->getCurrentId());
     }
     if ($keyword) {
         $data['meta_title'] = 'Поиск по фразе: ' . $keyword;
     }
     $this->data = $data;
     if ($aUri[1] == 'catalog' && empty($aUri[2]) && empty($_GET['search'])) {
         MG::redirect('/');
     }
 }