public static function getInstance() { if (self::$instance === null) { self::$instance = new self(); } return self::$instance; }
public static function returnShortCodes() { $tpl = static::returnTpl(); shortcode::add("gallery", function ($params = null) use($tpl) { $default = array('tpl' => "gallery-default"); $params = array_merge($default, (array) $params); if (empty($params['tpl']) || !View::exists($tpl . $params['tpl'])) { throw new Exception('Template not found: ' . $tpl . $params['tpl']); } if (!isset($params['id'])) { #return false; #return "Error: id of gallery is not defined!"; throw new Exception('ID of gallery is not defined'); } $gallery_id = $params['id']; $gallery = Gallery::where('id', $gallery_id)->first(); if (!is_object($gallery) || !@$gallery->id) { return false; #return "Error: gallery #{$gallery_id} doesn't exist!"; } $photos = $gallery->photos; if (!$photos->count()) { return false; } #dd($tpl.$params['tpl']); #dd(compact($photos)); #return View::make($tpl.$params['tpl'], compact($photos)); ## don't work return View::make($tpl . $params['tpl'], array('photos' => $photos)); }); }
private static function shortcode($clear, $data = NULL) { ## $clear - строка шорткода без квадратных скобок [] #dd($clear); $str = explode(" ", $clear); #$type = $str[0]; ## name of shortcode $type = array_shift($str); $options = NULL; if (count($str)) { #for($i=1; $i<count($str); $i++) { foreach ($str as $expr) { if (!strpos($expr, "=")) { continue; } #preg_match_all("~([^\=]+?)=['\"]([^'\"\s\t\r\n]+?)['\"]~", $str[$i], $rendered); #dd($rendered); list($key, $value) = explode("=", $expr); $key = trim($key); $value = trim($value, "'\""); if ($key != '' && $value != '') { $options[$key] = $value; } } } #dd($type); #dd($options); return shortcode::run($type, $options); }
public static function returnShortCodes() { $tpl = static::returnTpl(); shortcode::add("news", function ($params = null) use($tpl) { #print_r($params); die; if (!Allow::module('news')) { return false; } ## Параметры по-умолчанию $default = array('tpl' => Config::get('app-default.news_template', 'default'), 'limit' => Config::get('app-default.news_count_on_page', 3), 'order' => Helper::stringToArray(News::$order_by), 'pagination' => 1, 'type' => false, 'exclude_type' => false, 'include' => false, 'exclude' => false); ## Применяем переданные настройки $params = $params + $default; #dd($params); #echo $tpl.$params['tpl']; if (empty($params['tpl']) || !View::exists($tpl . $params['tpl'])) { throw new Exception('Template [' . $tpl . $params['tpl'] . '] not found.'); } $news = News::orderBy('news.published_at', 'desc')->with('meta.photo', 'meta.gallery.photos', 'meta.seo'); /* ## Получаем новости, делаем LEFT JOIN с news_meta, с проверкой языка и тайтла $selected_news = News::where('news.publication', 1) ->leftJoin('news_meta', 'news_meta.news_id', '=', 'news.id') ->where('news_meta.language', Config::get('app.locale')) ->where('news_meta.title', '!=', '') ->select('*', 'news.id AS original_id', 'news.published_at AS created_at') ->orderBy('news.published_at', 'desc'); #$selected_news = $selected_news->where('news_meta.wtitle', '!=', ''); ## Получаем новости с учетом пагинации #echo $selected_news->toSql(); die; #var_dump($params['limit']); $news = $selected_news->paginate($params['limit']); ## news list with pagination #$news = $selected_news->get(); ## all news, without pagination */ /** * Показываем новости только определенных типов */ if (@$params['type']) { $params['types'] = (array) explode(',', $params['type']); #Helper::d($params); if (isset($params['types']) && is_array($params['types']) && count($params['types']) && Allow::module('dictionaries') && class_exists('DicVal')) { $types = DicVal::whereIn('slug', $params['types'])->get(); #Helper::tad($types); if ($types->count()) { $types = $types->lists('id'); #Helper::tad($types); if (count($types)) { $news = $news->whereIn('type_id', $types); } } } } /** * Исключаем новости определенных типов */ if (@$params['exclude_type']) { $params['exclude_types'] = (array) explode(',', $params['exclude_type']); #Helper::d($params); if (isset($params['exclude_types']) && is_array($params['exclude_types']) && count($params['exclude_types']) && Allow::module('dictionaries') && class_exists('DicVal')) { $types = DicVal::whereIn('slug', $params['exclude_types'])->get(); #Helper::tad($types); if ($types->count()) { $types = $types->lists('id'); #Helper::tad($types); if (count($types)) { $news = $news->whereNotIn('type_id', $types); } } } } /** * Будем выводить только новости, ID которых указаны */ if (@$params['include']) { $params['includes'] = (array) explode(',', $params['include']); if (isset($params['includes']) && is_array($params['includes']) && count($params['includes'])) { $news = $news->whereIn('id', $params['includes']); } } /** * Исключаем новости с заданными ID */ if (@$params['exclude']) { $params['excludes'] = (array) explode(',', $params['exclude']); if (isset($params['excludes']) && is_array($params['excludes']) && count($params['excludes'])) { $news = $news->whereNotIn('id', $params['excludes']); } } $news = $news->paginate($params['limit']); #Helper::tad($news); /* foreach ($news as $n => $new) { #print_r($new); die; $gall = Rel_mod_gallery::where('module', 'news')->where('unit_id', $new->original_id)->first(); #foreach ($gall->photos as $photo) { # print_r($photo->path()); #} #print_r($gall->photos); die; $new->gall = @$gall; $new->image = is_object(@$gall->photos[0]) ? @$gall->photos[0]->path() : ""; $news[$n]->$new; } */ #echo $news->count(); die; if (!$news->count()) { return false; } return View::make($tpl . $params['tpl'], compact('news')); }); }