/**
* 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;
}
Esempio n. 2
0
 /**
  * Configuration du texte à retourner suivant le status du code d'erreur
  * @param $http_error
  * @return mixed
  */
 private function setTxtHeader($http_error)
 {
     if (isset($http_error)) {
         switch ($http_error) {
             case 404:
                 $message = frontend_model_template::getConfigVars('txt_status_404');
                 $status = self::init()->setStatusCode(404, $message);
                 break;
             case 403:
                 $message = frontend_model_template::getConfigVars('txt_status_403');
                 $status = self::init()->setStatusCode(403, $message);
                 break;
         }
         return $status;
     }
 }
function patternCatalog($name = null)
{
    $ModelTemplate = new frontend_model_template();
    $tr = array('show_product' => $ModelTemplate->getConfigVars('show_product'));
    switch ($name) {
        case 'product':
            $pattern = array('container' => array('before' => '<div class="product-list row">', 'after' => '</div>'), 'item' => array('before' => '<div class="thumbnail col-sm-6 col-md-4 col-lg-3">', 'after' => '</div></div>'));
            break;
        case 'sidebar':
            $pattern = array('container' => array('before' => '<div class="news-list-last sidebar-list row">', 'after' => '</div>'), 'item' => array('before' => '<a class="thumbnail text-center col-xs-6 col-sm-12 #current-last#" href="#url#" title="' . $tr['show_news'] . '" >', 'after' => '</a>'), 'img' => array('before' => ' ', 'classLink' => 'none', 'after' => ' '), 'name' => array('before' => '<span class="panel-title">', 'classLink' => 'none', 'after' => '</span>'), 'price' => array('before' => '<span class="price label label-primary">', 'after' => '</span>'));
            break;
        default:
            $pattern = array('container' => array('before' => '<div class="product-list">', 'after' => '</div>'), 'item' => array('before' => '<div class="thumbnail">', 'after' => '</div></div>'), 'img' => array('before' => ' ', 'classLink' => 'none', 'after' => ' '), 'name' => array('before' => '<div class="caption"> <h3>', 'classLink' => 'name', 'after' => '</h3>'), 'descr' => array('before' => '<p>', 'lenght' => 250, 'delemiter' => '...', 'after' => '</p>'), 'price' => array('before' => '<a class="btn" href="#url#" title="' . $tr['show_product'] . '">', 'currency' => ' € TTC', 'after' => '</a>'), 'active' => array('class' => ' active'), 'last' => array('class' => ' last', 'col' => 1), 'allow' => array('', 'img', 'name', 'price', 'descr'), 'display' => array(1 => array('', 'img', 'name', 'descr', 'price'), 2 => array('', 'img', 'name', 'descr', 'price'), 3 => array('', 'img', 'name', 'descr', 'price')));
    }
    return $pattern;
}
function patternNews($name = null)
{
    $ModelTemplate = new frontend_model_template();
    $tr = array('show_news' => $ModelTemplate->getConfigVars('show_news_page'));
    switch ($name) {
        case 'sidebar':
            $pattern = array('container' => array('before' => '<div class="news-list-last sidebar-list row">', 'after' => '</div>'), 'item' => array('before' => '<a class="thumbnail text-center col-xs-6 col-sm-12 #current-last#" href="#url#" title="' . $tr['show_news'] . '" >', 'after' => '</span></a>'), 'img' => array('before' => ' ', 'after' => ' '), 'date' => array('before' => '<span class="date label label-default">', 'format' => array('day' => 'd/', 'month' => 'm/', 'year' => 'Y'), 'after' => '</span>'), 'name' => array('before' => '<span class="caption"></span><span class="panel-title">', 'after' => '</span>'), 'tag' => array('before' => '<span class="tag">', 'after' => '<span>'), 'display' => array(1 => array('img', 'name', 'date')));
            break;
        default:
            $pattern = array('container' => array('before' => '<div class="news-list">', 'after' => '</div>'), 'item' => array('before' => '<div class="thumbnail col-xs-6 col-lg-6">', 'after' => '</div></div>'), 'img' => array('before' => ' ', 'after' => ' '), 'date' => array('before' => '<div class="caption"><span class="date badge badge-info pull-right">', 'format' => array('day' => 'd/', 'month' => 'm/', 'year' => 'Y'), 'after' => '</span>'), 'name' => array('before' => '<h3>
                                <a href="#url#" title="' . $tr['show_news'] . '">', 'after' => '</a>
                            </h3>'), 'descr' => array('before' => '<p>', 'lenght' => 250, 'delemiter' => '...', 'after' => '</p>'), 'pagination' => array('before' => '<div>', 'class' => 'pagination', 'after' => '</div>'), 'tag' => array('before' => '<span class="tag">', 'after' => '</span>'), 'active' => array('class' => ' active'), 'last' => array('class' => ' last', 'col' => 1), 'display' => array(1 => array('img', 'date', 'name', 'descr')), 'allow' => array('', 'img', 'name', 'descr', 'date', 'tag'));
    }
    return $pattern;
}
/**
 * Smarty {widget_lang_display} function plugin
 *
 * Type:     function
 * Name:     widget_lang_display
 * Date:     03/01/2013
 * Date Update : 12/01/2013
 * Output:
 * @author   Sire Sam (http://www.sire-sam.be)
 * @author   Gerits Aurélien (http://www.magix-dev.be)
 * @link
 * @version  1.0
 * @param $params
 * @param $template
 * @return string
 */
function smarty_function_widget_lang_display($params, $template)
{
    $ModelConstructor = new magixglobal_model_constructor();
    // *** Catch location var
    $iso_current = magixcjquery_filter_request::isGet('strLangue');
    // *** Load SQL DATA
    $data = frontend_db_lang::s_fetch_lang();
    $output = null;
    if ($data != null) {
        // *** set default html structure
        $strucHtml_default = array('container' => array('before' => '<ul class="nav">', 'after' => '</ul>'), 'item' => array('before' => '<li>', 'after' => '</li>'), 'icon' => array('before' => ' ', 'after' => ' '), 'name' => array('before' => ' ', 'after' => ' '), 'iso' => array('before' => '(', 'after' => ')'), 'current' => array('class' => ' current'), 'last' => array('class' => ' last', 'col' => 1));
        // *** Set default elem to display
        $strucHtml_default['allow'] = array('', 'icon', 'name', 'iso');
        $strucHtml_default['display'] = array(1 => array('', 'icon', 'name', 'iso'));
        // *** Update html struct & item setting with custom var (params['structureHTML']) @TODO vérifier si le paramaètre htmlDispaly tj opérationnel
        $structHtml_custom = $params['htmlStructure'] ? $params['htmlStructure'] : null;
        $strucHtml = $ModelConstructor->mergeHtmlPattern($strucHtml_default, $structHtml_custom);
        // *** Set translation var
        $t_go_to_version = frontend_model_template::getConfigVars('go_to_version');
        // *** format items loop (foreach item)
        $items = null;
        $i = 0;
        foreach ($data as $row) {
            $i++;
            // *** set additional var in htmlStruct
            $strucHtml['is_current'] = $iso_current == $row['iso'] ? 1 : 0;
            $strucHtml['is_last'] = 0;
            if ($i == $strucHtml['last']['col']) {
                $strucHtml['is_last'] = 1;
                $i = 0;
            }
            // *** in case diplay is null, we take default value
            if ($strucHtml['display'][1] == null) {
                $strucHtml['display'][1] = $strucHtml_default['display'][1];
            }
            // *** set link class
            $item_classLink = null;
            if ($strucHtml['is_last'] == 1 or $strucHtml['is_current'] == 1) {
                $item_class = ' class="';
                $item_class .= $strucHtml['is_last'] == 1 ? $strucHtml['last']['class'] : '';
                $item_class .= $strucHtml['is_current'] == 1 ? $strucHtml['current']['class'] : '';
                $item_class .= '"';
            }
            // *** format item loop (foreach element)
            $item = null;
            foreach ($strucHtml['display'][1] as $elem_type) {
                $strucHtml_elem = $strucHtml[$elem_type];
                if (array_search($elem_type, $strucHtml['display'][1])) {
                    switch ($elem_type) {
                        case 'name':
                            $elem = ucfirst($row['language']);
                            break;
                        case 'icon':
                            $elem = '<img src="/skin/' . frontend_model_template::frontendTheme()->themeSelected() . '/img/lang/' . $row['iso'] . '.png" alt="' . $row['name'] . '"/>';
                            break;
                        case 'iso':
                            $elem = $row['iso'];
                            break;
                        default:
                            $elem = null;
                    }
                    // *** elem construct
                    if ($elem != null) {
                        $item .= $strucHtml_elem['before'];
                        $item .= $elem;
                        $item .= $strucHtml_elem['after'];
                    }
                }
            }
            // *** item construct
            $items .= $strucHtml['item']['before'];
            $items .= '<a href="/' . $row['iso'] . '/" hreflang="' . $row['iso'] . '" title="' . ucfirst($t_go_to_version) . ': ' . $row['language'] . '">';
            $items .= $item;
            $items .= '</a>';
            $items .= $strucHtml['item']['after'];
        }
        // *** container construct
        $output .= $strucHtml['container']['before'];
        $output .= isset($params['htmlPrepend']) ? $params['htmlPrepend'] : null;
        $output .= $items;
        $output .= isset($params['htmlAppend']) ? $params['htmlAppend'] : null;
        $output .= $strucHtml['container']['after'];
    }
    return $output;
}
/**
* Smarty {widget_share_display} function plugin
*
* Type:     function
* Name:     widget_share_display
* Date:     04/01/2012
* Update:   12/01/2013
* Output:
* @author   Sire Sam (http://www.sire-sam.be)
* @author   Gerits Aurélien (http://www.magix-dev.be)
* @version  1.0
* @param array
* @param Smarty
* @return string
* <ul id="share-box" class="nav navbar-nav navbar-right">
   <li>
   <a href="#" class="dropdown-toggle" data-toggle="dropdown">
   <span class="glyphicon glyphicon-share">&nbsp;</span>
   <span class="dropdown-text">
   {#share#|ucfirst}
   </span>
   </a>
   {widget_share_display
   htmlStructure=[
   'container' => [
   'before' => '<ul id="share-nav" class="dropdown-menu">',
   'after' => '</ul>'
   ]
   ]
   }
   </li>
   </ul>
*/
function smarty_function_widget_share_display($params, $template)
{
    // *** Load active script var
    // ** Catch Domain var
    $url['root'] = magixcjquery_html_helpersHtml::getUrl();
    $url['relativ'] = $_SERVER["REQUEST_URI"];
    //strrpos récupère la dernière occurence de / et de .
    $url['share'] = $url['root'] . $url['relativ'];
    // ** Catch module's page name
    $smarty = frontend_model_smarty::getInstance();
    // ** find active module
    $script['fileName'] = substr($_SERVER['SCRIPT_NAME'], 1);
    $script['chartBeforeExt'] = strpos($script['fileName'], '.');
    $active_mod = substr($script['fileName'], 0, $script['chartBeforeExt']);
    // ** set active module name
    $name = null;
    switch ($active_mod) {
        case 'index':
            $name = $smarty->getTemplateVars('title');
            break;
        case 'catalog':
            if (isset($_GET['idproduct'])) {
                $productData = $smarty->getTemplateVars('product');
                $name = $productData['name'];
            } elseif (isset($_GET['idcls'])) {
                $subcatData = $smarty->getTemplateVars('subcat');
                $name = $subcatData['name'];
            } elseif (isset($_GET['idclc'])) {
                $catData = $smarty->getTemplateVars('cat');
                $name = $catData['name'];
            } else {
                $name = $smarty->getConfigVars('catalog_root_h1');
            }
            break;
        case 'cms':
            $name = $smarty->getTemplateVars('name_page');
            break;
        case 'news':
            if (isset($_GET['getnews'])) {
                $name = $smarty->getTemplateVars('name_news');
            } elseif (isset($_GET['tag'])) {
                $name = $smarty->getConfigVars('news_root_h1') . ': ' . $_GET['tag'];
            } else {
                $name = $smarty->getConfigVars('news_root_h1');
            }
            break;
        case 'plugin':
            $active_plugin = $_GET['magixmod'];
            switch ($active_plugin) {
                case 'contact':
                    $name = $smarty->getConfigVars('contact_root_h1');
                    break;
                default:
                    if (isset($_GET['pstring3'])) {
                        $name = ucfirst(str_replace('-', ' ', 'pstring3'));
                    } elseif (isset($_GET['pstring2'])) {
                        $name = ucfirst(str_replace('-', ' ', 'pstring2'));
                    } elseif (isset($_GET['pstring1'])) {
                        $name = ucfirst(str_replace('-', ' ', 'pstring1'));
                    } else {
                        $name = $smarty->getConfigVars($active_mod . '_root_h1');
                    }
            }
    }
    // *** Set share data
    $name = str_replace(' ', '%20', $name);
    // W3C validation require no ' ' in url
    $data_default = array('facebook' => array('name' => 'facebook', 'url' => 'http://www.facebook.com/share.php?u=' . $url['share'], 'img' => 'facebook.png'), 'twitter' => array('name' => 'twitter', 'url' => 'https://twitter.com/intent/tweet?text=' . $name . '&amp;url=' . $url['share'], 'img' => 'twitter.png'), 'viadeo' => array('name' => 'viadeo', 'url' => 'http://www.viadeo.com/shareit/share/?url=' . $url['share'] . '&amp;title=' . $name . '&amp;overview=' . $name, 'img' => 'viadeo.png'), 'google' => array('name' => 'google', 'url' => 'https://plus.google.com/share?url=' . $url['share'], 'onclick' => 'javascript:window.open(this.href,\'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600\');return false;', 'img' => 'google.png'));
    // ** Select Data
    if (isset($params['dataSelect']['context'])) {
        $dataSelect = explode(',', $params['dataSelect']['context']);
        foreach ($dataSelect as $share) {
            if (array_key_exists($share, $data_default)) {
                $data[] = $data_default[$share];
            }
        }
    } else {
        $data = $data_default;
    }
    // *** Set default html structure
    $strucHtml_default = array('container' => array('before' => '<ul>', 'after' => '</ul>'), 'item' => array('before' => '<li>', 'after' => '</li>'), 'img' => array('before' => ' ', 'after' => ' '), 'name' => array('before' => ' ', 'after' => ' '), 'current' => array('class' => ' current'), 'last' => array('class' => ' last', 'col' => 1));
    // ** Set default elem to display
    $strucHtml_default['allow'] = array('', 'name', 'img');
    $strucHtml_default['display'] = array(1 => array('', 'img', 'name'));
    // ** Update html struct & item setting with custom var (params['htmlStructure'])
    $custom = $params['htmlStructure'] ? $params['htmlStructure'] : null;
    $default = $strucHtml_default;
    if (is_array($custom)) {
        $default['display'] = array();
        foreach ($custom as $k => $v) {
            foreach ($v as $sk => $sv) {
                if ($sv != null) {
                    $default[$k][$sk] = $sv;
                }
            }
            if (array_search($k, $default['allow'])) {
                $default['display'][1][] = $k;
            }
        }
    }
    // ** Update html struct with display params (params['htmlDisplay'])
    if (isset($params['htmlDisplay'])) {
        $default['display'] = $params['htmlDisplay'];
    }
    // * push null value on case[0] (allow array search on format function)
    foreach ($default['display'] as $k => $v) {
        array_unshift($default['display'][$k], null);
    }
    $strucHtml = $default;
    // ** in cas diplay is null, we take default value
    if ($strucHtml['display'][1] == null) {
        $strucHtml['display'][1] = $strucHtml_default['display'][1];
    }
    // *** Set translation var
    $t_share_on = frontend_model_template::getConfigVars('share_on');
    // *** format items loop (foreach item)
    $items = null;
    foreach ($data as $row) {
        // ** format item loop (foreach element)
        $elem = null;
        foreach ($strucHtml['display'][1] as $elem_type) {
            if (array_search($elem_type, $strucHtml['display'][1])) {
                switch ($elem_type) {
                    case 'name':
                        $elem .= ucfirst($row['name']);
                        break;
                    case 'img':
                        $elem .= '<img src="' . '/skin/' . frontend_model_template::frontendTheme()->themeSelected() . '/img/share/' . $row['img'] . '" alt="' . $row['name'] . '" />';
                }
            }
        }
        // ** item construct
        $items .= $strucHtml['item']['before'];
        $items .= '<a id="share-' . $row['name'] . '" class="targetblank" href="' . $row['url'] . '" title="' . ucfirst($t_share_on) . ': ' . $row['name'] . '">';
        $items .= $elem;
        $items .= '</a>';
        $items .= $strucHtml['item']['after'];
    }
    // *** container construct
    $output = $strucHtml['container']['before'];
    $output .= isset($params['htmlPrepend']) ? $params['htmlPrepend'] : null;
    $output .= $items;
    $output .= isset($params['htmlAppend']) ? $params['htmlAppend'] : null;
    $output .= $strucHtml['container']['after'];
    return $output;
}