Classes

File phpboost/menu/feed/FeedMenu.class.php

File phpboost/menu/feed/FeedMenu.class.php

  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 
<?php
/**
 * @package     PHPBoost
 * @subpackage  Menu\feed
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Loic ROUCHON <horn@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2018 03 26
 * @since       PHPBoost 2.0 - 2009 01 14
 * @contributor Kevin MASSY <reidlos@phpboost.com>
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
 * @contributor Arnaud GENET <elenwii@phpboost.com>
*/

class FeedMenu extends Menu
{
    const FEED_MENU__CLASS = 'FeedMenu';

    /**
     * @var string the feed url
     */
    public $url = '';
    public $module_id = '';
    public $name = '';
    public $category = 0;
    public $number = 10;
    public $begin_at = 0;

    public function __construct($title, $module_id, $category = 0, $name = Feed::DEFAULT_FEED_NAME, $number = 10, $begin_at = 0)
    {
        parent::__construct($title);
        $this->module_id = $module_id;
        $this->category = $category;
        $this->name = $name;
        $this->number = $number;
        $this->begin_at = $begin_at;
    }

    /**
     * Returns the tpl to parse a feed
     * @param string $id The feed id
     * @param string $name The feed name
     * @param string $block_position The indentifier block position defined in the inherit class menu
     * @return the tpl to parse a feed
     * @static
     */
    public static function get_template($id, $name = '', $block_position = Menu::BLOCK_POSITION__LEFT, $hidden_with_small_screens = false)
    {
        $tpl = new FileTemplate('framework/menus/feed.tpl');
        $tpl->put_all(array(
            'NAME' => $name,
            'ID' => $id,
            'C_NAME' => !empty($name),
            'C_VERTICAL_BLOCK' => ($block_position == Menu::BLOCK_POSITION__LEFT || $block_position == Menu::BLOCK_POSITION__RIGHT),
            'C_HIDDEN_WITH_SMALL_SCREENS' => $hidden_with_small_screens
        ));

        return $tpl;
    }

    ## Getters ##
    /**
     * @return string the feed menu module id
     */
    public function get_module_id() { return $this->module_id; }

    /**
    * @param bool $relative If false, compute the absolute url, else, returns the relative one
    * @return Return the absolute feed Url
    */
    public function get_url($relative = false)
    {
        $url = DispatchManager::get_url('/syndication', '/rss/' . $this->module_id . '/' . $this->category . '/' . $this->name . '/');
        if ($relative)
        {
            return $url->relative();
        }
        return $url->absolute();
    }

    ## Setters ##
    /**
     * @param string $value the feed's module_id
     */
    public function set_module_id($value) { $this->module_id = $value; }
    /**
     * @param int $value the feed's category
     */
    public function set_cat($value) { $this->category = is_numeric($value) ? NumberHelper::numeric($value) : 0; }
    /**
     * @param string $value the feed's name
     */
    public function set_name($value) { $this->name = $value; }

    /**
    * @return Return the number of elements displayed in the menu
    */
    public function get_number()
    {
        return $this->number;
    }

    /**
     * @param string $value the number of elements displayed in the menu
     */
    public function set_number($value) { $this->number = $value; }

    public function display()
    {
        $filters = $this->get_filters();
        $is_displayed = empty($filters) || $filters[0]->get_pattern() == '/';

        foreach ($filters as $key => $filter)
        {
            if ($filter->get_pattern() != '/' && $filter->match())
            {
                $is_displayed = true;
                break;
            }
        }

        if ($is_displayed)
        {
            return Feed::get_parsed($this->module_id, $this->name, $this->category, self::get_template($this->id, $this->get_title(), $this->get_block(), $this->hidden_with_small_screens), $this->number, $this->begin_at);
        }
        return '';
    }
}
?>
Annonces