/** * Smarty {widget_news_nav} * function plugin * * Type: function * Name: widget news nav * Date: September 26, 2012 * Update: December 29, 2012 * Purpose: * Examples: {widget_news_nav} {widget_news_nav htmlAttribut=[ 'id_container' => 'secondary-nav', 'class_container' => 'v-nav' ] title='<p class="title">Actualités par thèmes</p>' } * Output: string (<ul><li><a>tag_name<///) * @link * @author Gerits Aurelien * @author Samuel Lesre * @version 1.1 * @param array * @param Smarty * @return string */ function smarty_function_widget_news_nav($params, $template) { $ModelNews = new frontend_model_news(); $ModelSystem = new magixglobal_model_system(); // *** Load SQL DATA $current = $ModelSystem->setCurrentId(); $conf = array('level' => 'tag', 'limit' => null); $data = $ModelNews->getData($conf, $current); $current = $current['news']; $output = null; if ($data != null) { // *** set default html attributs if ($params['htmlAttribut']) { $htmlAttr = $params['htmlAttribut']; $id_container = isset($htmlAttr['id_container']) ? ' id="' . $htmlAttr['id_container'] . '"' : null; $class_container = isset($htmlAttr['class_container']) ? ' class="' . $htmlAttr['class_container'] . '"' : null; $class_current = isset($htmlAttr['class_current']) ? $htmlAttr['class_current'] : 'current'; } // *** Set translation var $tr_show_news = frontend_model_template::getConfigVars('show_news'); // *** format items loop (foreach item) $items = null; foreach ($data as $row) { $current_item = $row['name_tag'] == $current['tag']['id'] ? $class_current : null; $uri_item = magixglobal_model_rewrite::filter_news_tag_url($row['iso'], urlencode($row['name_tag']), true); $name_item = $row['name_tag']; $class_item = $current_item != null ? ' class="' . $current_item . '"' : null; // *** item construct $item = '<li' . $class_item . '>'; $item .= '<a href="' . $uri_item . '" title="' . $tr_show_news . ': ' . $name_item . '">'; $item .= $name_item; $item .= '</a>'; $item .= '</li>'; $items .= $item; } // *** container construct $output = isset($params['title']) ? $params['title'] : ''; $output .= '<ul' . $id_container . $class_container . '>'; $output .= isset($params['prepend']) ? $params['prepend'] : null; $output .= $items; $output .= isset($params['append']) ? $params['append'] : null; $output .= '</ul>'; } return $output; }
/** * Smarty plugin * @package Smarty * @subpackage plugins * Type: function * Name: widget_news_display * date: 25/12/2013 * Update: 10/03/2013 * Examples: {widget_news_display} * @author Sire Sam (sire-sam.be) * @link htt://www.sire-sam.be, http://www.magix-dev.be * @author Gerits Aurelien * @version 1.1 * @param array * @param Smarty * @return string */ function smarty_function_widget_news_data($params, $template) { $ModelSystem = new magixglobal_model_system(); $ModelRewrite = new magixglobal_model_rewrite(); $ModelNews = new frontend_model_news(); $ModelPager = new magixglobal_model_pager(); // Set and load data $current = $ModelSystem->setCurrentId(); $conf = is_array($params['conf']) ? $params['conf'] : array(); $override = $params['conf']['plugins']['override'] ? $params['conf']['plugins']['override'] : ''; $data = $ModelNews->getData($conf, $current, $override); $newrow = is_array($params['conf']['plugins']['item']) ? $params['conf']['plugins']['item'] : array(); // Set Pagination $pagination = array(); if (isset($data['total']) and isset($data['limit'])) { $pagination = $ModelPager->setPaginationData($data['total'], $data['limit'], '/' . $current['lang']['iso'] . $ModelRewrite->mod_news_lang($current['lang']['iso']), $current['news']['pagination']['id'], '/'); unset($data['total']); unset($data['limit']); } $current = $current['news']; // Format data $items = array(); if ($data != null) { foreach ($data as $row) { if (isset($row['idnews'])) { $items[] = $ModelNews->setItemData($row, $current, $newrow); } elseif (isset($row['name_tag'])) { $items[] = array('id' => $row['name_tag'], 'name' => $row['name_tag'], 'iso' => $row['iso'], 'url' => magixglobal_model_rewrite::filter_news_tag_url($row['iso'], urlencode($row['name_tag']), true)); } } } $assign = isset($params['assign']) ? $params['assign'] : 'data'; $template->assign($assign, $items); $assignPager = isset($params['assignPagination']) ? $params['assignPagination'] : 'paginationData'; $template->assign($assignPager, $pagination); }
/** * Smarty plugin * @package Smarty * @subpackage plugins * Type: function * Name: widget_news_display * date: 25/12/2013 * Update: 10/03/2013 * Examples: {widget_news_display} * @author Sire Sam (sire-sam.be) * @link htt://www.sire-sam.be, http://www.magix-dev.be * @author Gerits Aurelien * @version 1.1 * @param array * @param Smarty * @return string */ function smarty_function_widget_news_display($params, $template) { $ModelSystem = new magixglobal_model_system(); $ModelRewrite = new magixglobal_model_rewrite(); $ModelConstructor = new magixglobal_model_constructor(); $ModelNews = new frontend_model_news(); $ModelPager = new magixglobal_model_pager(); $Debug = new magixcjquery_debug_magixfire(); // Set and load data $current = $ModelSystem->setCurrentId(); $conf = is_array($params['conf']) ? $params['conf'] : array(); $data = $ModelNews->getData($conf, $current); // Set Pagination $pagination['html'] = null; if (isset($data['total']) and isset($data['limit'])) { $pagination['src'] = $ModelPager->setPaginationData($data['total'], $data['limit'], '/' . $current['lang']['iso'] . $ModelRewrite->mod_news_lang($current['lang']['iso']), $current['news']['pagination']['id'], '/'); $pagination['html'] = $ModelConstructor->formatPaginationHtml($pagination['src'], $current['news']['pagination']['id']); unset($data['total']); unset($data['limit']); } $current = $current['news']; // Format data $html = null; if ($data != null) { $pattern['default'] = patternNews(); $pattern['custom'] = null; if ($params['pattern']) { $pattern['custom'] = is_array($params['pattern']) ? $params['pattern'] : patternNews($params['pattern']); } $pattern['global'] = $ModelConstructor->mergeHtmlPattern($pattern['default'], $pattern['custom']); $i = 0; $items['html'] = null; foreach ($data as $row) { $i++; $itemData = $ModelNews->setItemData($row, $current); // *** set item html structure & var $pattern['global']['is_active'] = $itemData['active'] === true ? 1 : 0; $pattern['global']['id'] = isset($itemData['id']) ? $itemData['id'] : 0; $pattern['global']['url'] = isset($itemData['uri']) ? $itemData['uri'] : '#'; $pattern['item'] = $ModelConstructor->setItemPattern($pattern['global'], $i); // *** Reset iteration if item is last of the line if ($pattern['item']['is_last'] == 1) { $i = 0; } // *** in case diplay is null, we take default value if ($pattern['item']['display'][1] == null) { $pattern['item']['display'][1] = $pattern['default']['display'][1]; } $imgSize = isset($pattern['item']['img']['size']) ? $pattern['item']['img']['size'] : 'small'; if (isset($itemData['imgSrc'][$imgSize])) { $itemData['imgSrc'] = $itemData['imgSrc'][$imgSize]; } else { $itemData['imgSrc'] = $itemData['imgSrc']['default']; } // *** format item loop (foreach element) $itemHtml = null; foreach ($pattern['item']['display'][1] as $elem_type) { $pattern['elem'] = $pattern['item'][$elem_type]; if (array_search($elem_type, $pattern['item']['display'][1])) { switch ($elem_type) { case 'name': $elem = $itemData['name']; break; case 'img': $elem = '<img src="' . $itemData['imgSrc'] . '" alt="' . $itemData['name'] . '"/>'; break; case 'descr': $elem = magixcjquery_form_helpersforms::inputCleanTruncate(magixcjquery_form_helpersforms::inputTagClean($itemData['content']), $pattern['item']['descr']['lenght'], $pattern['item']['descr']['delemiter']); break; case 'date': $elem = $ModelConstructor->formatDateHtml($itemData['date']['publish'], $pattern['item']); break; case 'tag': $elem = $itemData['tag']; break; default: $elem = null; } if ($elem != null or isset($pattern['elem']['before']) or isset($pattern['elem']['after'])) { $itemHtml .= $pattern['elem']['before']; $itemHtml .= $elem; $itemHtml .= $pattern['elem']['after']; } } } // *** item construct $items['html'] .= $pattern['item']['item']['before']; $items['html'] .= $itemHtml; $items['html'] .= $pattern['item']['item']['after']; } // *** container construct $html = isset($params['title']) ? $params['title'] : ''; $html .= $pattern['global']['container']['before']; $html .= isset($params['prepend']) ? $params['prepend'] : null; $html .= $items['html']; $html .= isset($params['append']) ? $params['append'] : null; $html .= $pattern['global']['container']['after']; $html .= $pagination['html']; } return $html; }
/** * Assign news' data to smarty * @access private */ private function load_news_data() { $template = new frontend_model_template(); $News = new frontend_model_news(); $data = parent::s_newsData($this->idNews, $this->dateNews); $dataClean = $News->setItemData($data, true); $template->assign('news', $dataClean); }