Your IP : 216.73.216.89


Current Path : /home/azimutno/www/plugins/jsnpagebuilder/defaultelements/articlelist/helpers/
Upload File :
Current File : /home/azimutno/www/plugins/jsnpagebuilder/defaultelements/articlelist/helpers/helper.php

<?php
/**
 * @version    $Id$
 * @package    JSN_PageBuilder
 * @author     JoomlaShine Team <support@joomlashine.com>
 * @copyright  Copyright (C) 2012 JoomlaShine.com. All Rights Reserved.
 * @license    GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
 *
 * Websites: http://www.joomlashine.com
 * Technical Support:  Feedback - http://www.joomlashine.com/contact-us/get-support.html
 */

// No direct access to this file.
defined('_JEXEC') || die('Restricted access');

include_once JPATH_PLUGINS . '/jsnpagebuilder/defaultelements/articlelist/models/categories.php';
include_once JPATH_PLUGINS . '/jsnpagebuilder/defaultelements/articlelist/models/articles.php';

/**
 * Helper class for article list element
 *
 * @package  JSN_PageBuilder
 * @since    1.0.0
 */
class JSNPbArticleListHelper
{
    const PB_ARTICLE_LIST_LAYOUT = "layout_list";
    const PB_ARTICLE_HORIZONTAL_LAYOUT = "layout_horizontal";
    const PB_ARTICLE_VERTICAL_LAYOUT = "layout_vertical";

    const PB_ARTICLE_LIST_STYLE_NONE = "none";
    const PB_ARTICLE_LIST_STYLE_DISC = "disc";
    const PB_ARTICLE_LIST_STYLE_CIRCLE = "circle";
    const PB_ARTICLE_LIST_STYLE_SQUARE = "square";
    const PB_ARTICLE_LIST_STYLE_NUMBER = "1";
    const PB_ARTICLE_LIST_STYLE_UP_LETTERS = "A";
    const PB_ARTICLE_LIST_STYLE_LOW_LETTERS = "a";
    const PB_ARTICLE_LIST_STYLE_UP_NUMBERS = "I";
    const PB_ARTICLE_LIST_STYLE_LOW_NUMBERS = "i";
    const PB_ARTICLE_LIST_STYLE_IMAGE = "image";
    const PB_ARTICLE_LIST_STYLE_THUMBNAIL = "thumbnail";

    const PB_ARTICLE_META_DATA_AUTHOR = "article_author";
    const PB_ARTICLE_META_DATA_DATE_PUBLISHED = "article_date_published";
    const PB_ARTICLE_META_DATA_CATEGORY = "article_category";
    const PB_ARTICLE_META_DATA_HITS = "article_hits";

    const PB_ARTICLE_SORT_ORDER_ASC = "ASC";
    const PB_ARTICLE_SORT_ORDER_DESC = "DESC";

    const PB_SHORTCODE_SYNTAX = '#\[(\[?)(pb_row)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)#';

    /**
     * @return array
     */
    public static function getArticleListSource()
    {
        return array(
            "joomla_article" => JText::_('Joomla article'),
        );
    }

    /**
     * @return array
     */
    public static function getArticleListSortBy()
    {
        return array(
            "title"      => JText::_('Title'),
            "publish_up" => JText::_('Published'),
            "hits"       => JText::_('Hits'),
        );
    }

    /**
     * @return array
     */
    public static function getArticleListSortOrder()
    {
        return array(
            self::PB_ARTICLE_SORT_ORDER_ASC => JText::_('Ascending'),
            self::PB_ARTICLE_SORT_ORDER_DESC => JText::_('Descending'),
        );
    }


    /**
     * @return array
     */
    public static function getArticleListStyle()
    {
        return array(
            self::PB_ARTICLE_LIST_STYLE_NONE        => JText::_('None'),
            self::PB_ARTICLE_LIST_STYLE_DISC        => JText::_('Disc'),
            self::PB_ARTICLE_LIST_STYLE_CIRCLE      => JText::_('Circle'),
            self::PB_ARTICLE_LIST_STYLE_SQUARE      => JText::_('Square'),
            self::PB_ARTICLE_LIST_STYLE_NUMBER      => JText::_('Number'),
            self::PB_ARTICLE_LIST_STYLE_UP_LETTERS  => JText::_('Uppercase letters'),
            self::PB_ARTICLE_LIST_STYLE_LOW_LETTERS => JText::_('Lowercase letters'),
            self::PB_ARTICLE_LIST_STYLE_UP_NUMBERS  => JText::_('Uppercase numbers'),
            self::PB_ARTICLE_LIST_STYLE_LOW_NUMBERS => JText::_('Lowercase numbers'),
            self::PB_ARTICLE_LIST_STYLE_IMAGE       => JText::_('Image/Icon'),
            self::PB_ARTICLE_LIST_STYLE_THUMBNAIL   => JText::_('Thumbnail Article'),
        );
    }

    public static function getArticleOlListStyle()
    {
        return array(
            self::PB_ARTICLE_LIST_STYLE_NUMBER,
            self::PB_ARTICLE_LIST_STYLE_UP_LETTERS,
            self::PB_ARTICLE_LIST_STYLE_LOW_LETTERS,
            self::PB_ARTICLE_LIST_STYLE_UP_NUMBERS,
            self::PB_ARTICLE_LIST_STYLE_LOW_NUMBERS,
        );
    }

    /**
     * @return array
     */
    public static function getArticleMetaDataType()
    {
        return array(
            self::PB_ARTICLE_META_DATA_AUTHOR         => JText::_('Author'),
            self::PB_ARTICLE_META_DATA_DATE_PUBLISHED => JText::_('Published'),
            self::PB_ARTICLE_META_DATA_CATEGORY       => JText::_('Category'),
            self::PB_ARTICLE_META_DATA_HITS           => JText::_('Hits'),
        );
    }

    /**
     * @return string
     */
    public static function getArticleDefaultMetaDataType()
    {
        return implode("__#__", array(
            self::PB_ARTICLE_META_DATA_DATE_PUBLISHED,
            self::PB_ARTICLE_META_DATA_CATEGORY,
        ));
    }

    /**
     * @return array
     */
    public static function getArticleListLayout()
    {
        return array(
            self::PB_ARTICLE_LIST_LAYOUT       => array(JText::_('List'), "class" => "jsn-icon-formfields jsn-icon-list-basic"),
            self::PB_ARTICLE_VERTICAL_LAYOUT => array(JText::_('Primary - Secondary - Vertical'), "class" => "jsn-icon-formfields jsn-icon-list-special-1"),
            self::PB_ARTICLE_HORIZONTAL_LAYOUT   => array(JText::_('Primary - Secondary - Horizontal'), "class" => "jsn-icon-formfields jsn-icon-list-special-2"),
        );
    }

    /**
     * @return array
     */
    public static function getArticleListCategories()
    {
        $categoriesModel = new JSNPbCategoriesModel();
        $categories = $categoriesModel->getCategories();

        $options = array();
        foreach ($categories as $_categoryId => $_category) {
            $options[(int) $_categoryId] = $_category['title'];
        }

        return $options;
    }

    /**
     * @param array $attributes
     *
     * @return array
     */
    public static function getArticles($attributes)
    {
        $articlesModel = new JSNPbArticlesModel();
        $articles = $articlesModel->getArticlesByAttributes($attributes);

        return $articles;
    }

    public static function wordLimiter($str, $limit = 100, $end_char = '&#8230;')
    {
        if (trim($str) == '')
        {
            return $str;
        }

        $str = strip_tags($str);
        preg_match('/\s*(?:\S*\s*){'. (int) $limit .'}/', $str, $matches);
        if (strlen($matches[0]) == strlen($str))
        {
            $end_char = '';
        }
        return rtrim($matches[0]).$end_char;
    }
}