/**
 * 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;
}
/**
 * Smarty plugin
 * @package     Smarty
 * @subpackage  plugins
 * Type:        function
 * Name:        widget_catalog_display
 * Date:        27/09/2013
 * Update:      05/03/2013
 * @author      Samuel Lesire
 * @author      Gerits Aurelien
 * @link        htt://www.sire-sam.be, http://www.magix-dev.be
 * @version     1.1
 * @param       array
 * @param       Smarty
 * @return      string
 */
function smarty_function_widget_catalog_display($params, $template)
{
    $ModelSystem = new magixglobal_model_system();
    $ModelConstructor = new magixglobal_model_constructor();
    $ModelCatalog = new frontend_model_catalog();
    // Set and load data
    $current = $ModelSystem->setCurrentId();
    $conf = is_array($params['conf']) ? $params['conf'] : array();
    $data = $ModelCatalog->getData($conf, $current);
    $html = null;
    if ($data != null) {
        $pattern['default'] = patternCatalog();
        $pattern['custom'] = null;
        if ($params['pattern']) {
            $pattern['custom'] = is_array($params['pattern']) ? $params['pattern'] : patternCatalog($params['pattern']);
        }
        $pattern['global'] = $ModelConstructor->mergeHtmlPattern($pattern['default'], $pattern['custom']);
        // *** format items loop (foreach item)
        // ** Loop management var
        $deep = 1;
        $deep_minus = $deep - 1;
        $deep_plus = $deep + 1;
        $pass_trough = 0;
        $data_empty = false;
        // ** Loop format & output var
        $row = array();
        $items = array();
        $i[$deep] = 0;
        // *** boucle / loop
        do {
            // *** loop management START
            if ($pass_trough == 0) {
                // Si je n'ai plus de données à traiter je vide ma variable
                $row[$deep] = null;
            } else {
                // Sinon j'active le traitement des données
                $pass_trough = 0;
            }
            // Si je suis au premier niveaux et que je n'ai pas de donnée à traiter
            if ($deep == 1 and $row[$deep] == null) {
                // récupération des données dans $data
                $row[$deep] = array_shift($data);
            }
            // Si ma donnée possède des sous-donnée sous-forme de tableau
            if (isset($row[$deep]['subdata'])) {
                if (is_array($row[$deep]['subdata']) and $row[$deep]['subdata'] != null) {
                    // On monte d'une profondeur
                    $deep++;
                    $deep_minus++;
                    $deep_plus++;
                    // on récupére la  première valeur des sous-données en l'éffacant du tableau d'origine
                    $row[$deep] = array_shift($row[$deep_minus]['subdata']);
                    // Désactive le traitement des données
                    $pass_trough = 1;
                }
            } elseif ($deep != 1) {
                if ($row[$deep] == null) {
                    if ($row[$deep_minus]['subdata'] == null) {
                        // Si je n'ai pas de sous-données & pas de données à traiter & pas de frères à récupérer dans mon parent
                        // ====> désactive le tableaux de sous-données du parent et retourne au niveau de mon parent
                        unset($row[$deep_minus]['subdata']);
                        unset($i[$deep]);
                        $items[$deep] = $pattern['item']['container']['before'] . $items[$deep] . $pattern['item']['container']['after'];
                        $deep--;
                        $deep_minus = $deep - 1;
                        $deep_plus = $deep + 1;
                    } else {
                        // Je récupère un frère dans mon parent
                        $row[$deep] = array_shift($row[$deep_minus]['subdata']);
                    }
                    // Désactive le traitement des données
                    $pass_trough = 1;
                }
            }
            // *** loop management END
            // *** list format START
            if ($row[$deep] != null and $pass_trough != 1) {
                $i[$deep]++;
                // Construit doonées de l'item en array avec clée nominative unifiée ('name' => 'monname,'descr' => '<p>ma descr</p>,...)
                $itemData = $ModelCatalog->setItemData($row[$deep], $current['catalog']);
                // Configuration de la structure HTML de l'item
                $pattern['global']['is_current'] = $itemData['active'];
                $pattern['global']['id'] = isset($itemData['id']) ? $itemData['id'] : 0;
                $pattern['global']['url'] = isset($itemData['url']) ? $itemData['url'] : '#';
                $pattern['item'] = $ModelConstructor->setItemPattern($pattern['global'], $i[$deep], $deep);
                // Récupération de la taille de l'image
                if (isset($pattern['global']['img']['size_' . $deep])) {
                    $row[$deep]['img_size'] = $pattern['global']['img']['size_' . $deep];
                } elseif (isset($pattern['global']['img']['size'])) {
                    $row[$deep]['img_size'] = $pattern['global']['img']['size'];
                } else {
                    $row[$deep]['img_size'] = 'medium';
                }
                $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'];
                }
                // remise à zero du compteur si élément est le dernier de la ligne
                if ($pattern['item']['is_last'] == 1) {
                    $i[$deep] = 0;
                }
                // Récupération de l'affichage pour le niveau
                $pattern['item']['display'] = is_array($pattern['global']['display'][$deep]) ? $pattern['global']['display'][$deep] : $pattern['global']['display'][1];
                if ($pattern['item']['display'] == null) {
                    $pattern['item']['display'] = $pattern['default']['display'][1];
                }
                // Récupération des sous-données (enfants)
                if (isset($items[$deep_plus]) != null) {
                    $subitems = $items[$deep_plus];
                    $items[$deep_plus] = null;
                } else {
                    $subitems = null;
                }
                $item = null;
                foreach ($pattern['item']['display'] as $elem_type) {
                    // BOUCLE de formatage des éléments contenus dans item
                    $pattern['elem'] = $pattern['item'][$elem_type];
                    if (array_search($elem_type, $pattern['item']['display'])) {
                        // Config class link
                        $item_classLink = null;
                        if (isset($pattern['elem']['classLink'])) {
                            $item_classLink = ' class="' . $pattern['elem']['classLink'] . '"';
                            $item_classLink = $pattern['elem']['classLink'] == 'none' ? 'none' : $item_classLink;
                        }
                        // Format element on switch
                        switch ($elem_type) {
                            case 'name':
                                $elem = $item_classLink != 'none' ? '<a' . $item_classLink . ' href="' . $itemData['url'] . '" title="' . $itemData['name'] . '">' : '';
                                $elem .= $itemData['name'];
                                $elem .= $item_classLink != 'none' ? '</a>' : '';
                                break;
                            case 'img':
                                $elem = $item_classLink != 'none' ? '<a' . $item_classLink . ' href="' . $itemData['url'] . '" title="' . $itemData['name'] . '">' : '';
                                $elem .= '<img src="' . $itemData['imgSrc'] . '" alt="' . $itemData['name'] . '"/>';
                                $elem .= $item_classLink != 'none' ? '</a>' : '';
                                break;
                            case 'descr':
                                $elem = magixcjquery_form_helpersforms::inputCleanTruncate(magixcjquery_form_helpersforms::inputTagClean($itemData['content']), $pattern['item']['descr']['lenght'], $pattern['item']['descr']['delemiter']);
                                break;
                            case 'price':
                                if (is_numeric($itemData['price'])) {
                                    $elem = $itemData['price'] . $pattern['item']['price']['currency'];
                                } else {
                                    $elem = null;
                                }
                                break;
                            default:
                                $elem = null;
                        }
                        if ($elem != null) {
                            $item .= $pattern['elem']['before'];
                            $item .= $elem;
                            $item .= $pattern['elem']['after'];
                        }
                    }
                }
                $items[$deep] .= $pattern['item']['item']['before'];
                $items[$deep] .= $item;
                $items[$deep] .= $subitems;
                $items[$deep] .= $pattern['item']['item']['after'];
            }
            // *** list format END
            // Si $data est vide => arrête la boucle
            if (empty($data) and $row[1] == null) {
                $data_empty = true;
            }
        } while ($data_empty == false);
        // *** container construct
        if ($items[1] != null) {
            $html = isset($params['title']) ? $params['title'] : '';
            $html .= $pattern['global']['container']['before'];
            $html .= isset($params['prepend']) ? $params['prepend'] : null;
            $html .= $items[1];
            $html .= isset($params['append']) ? $params['append'] : null;
            $html .= $pattern['global']['container']['after'];
        } else {
            $html = null;
        }
    }
    return $html;
}
Ejemplo n.º 3
0
 /**
  * [truncat] 'clean html' tag and 'trim' $string[value] where $conf[value][trim] = xx caracters + $conf[value][delemiter]
  * [dateFormat] format (date_time)$string[value] in '<span class="$conf[value][dateFormat][key]">$conf[value][dateFormat][key]|val</span>'
  * @param array $string
  * @param array $conf
  * @return array
  */
 public function formatString($string, $conf)
 {
     if (!is_array($conf)) {
         return array();
     }
     if (is_array($string)) {
         foreach ($string as $k => $v) {
             if (isset($conf[$k])) {
                 foreach ($conf[$k] as $operation => $setting) {
                     switch ($operation) {
                         case 'truncat':
                             if (!is_int($setting)) {
                                 continue;
                             }
                             $delim = $conf[$k]['delemiter'] ? $conf[$k]['delemiter'] : '';
                             $string[$k] = magixcjquery_form_helpersforms::inputCleanTruncate(magixcjquery_form_helpersforms::inputTagClean($v), $setting, $delim);
                             break;
                         case 'dateFormat':
                             if (is_array($setting)) {
                                 $this->formatDateHtml($v, $setting);
                             }
                     }
                 }
             }
         }
     }
     return $string;
 }