1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

237 lines
5.3 KiB
PHP
Raw Normal View History

<?php
/*
* e107 website system
*
* Copyright (c) 2008-2009 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Featurebox Item model
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/featurebox/includes/item.php,v $
2010-02-10 18:18:01 +00:00
* $Revision$
* $Date$
* $Author$
*
*/
if (!defined('e107_INIT')) { exit; }
// TODO - sc_* methods
class plugin_featurebox_item extends e_model
{
/**
* @see e_model::_field_id
* @var string
*/
protected $_field_id = 'fb_id';
2011-06-21 15:27:01 +00:00
/**
* @see e_model::_db_table
* @var string
*/
protected $_db_table = 'featurebox';
2011-06-21 15:27:01 +00:00
/**
* @var plugin_featurebox_category
*/
protected $_category = null;
/**
* Parameter list (GET string format):
* - alt: return title as tag attribute text
* - url: add url tag to the output (only if 'fb_imageurl' is available)
2011-06-21 15:43:33 +00:00
* - rel: rel tag attribute
2011-06-21 15:27:01 +00:00
*
* @param string $parm
* @return string
*/
public function sc_featurebox_title($parm = '')
{
parse_str($parm, $parm);
$tp = e107::getParser();
if(isset($parm['alt']))
{
return $tp->toAttribute($this->get('fb_title'));
}
2011-06-21 15:27:01 +00:00
$ret = $tp->toHTML($this->get('fb_title'), false, 'TITLE');
if(isset($parm['url']) && $this->get('fb_imageurl'))
{
2011-06-21 15:43:33 +00:00
return '<a id="featurebox-titleurl-'.$this->getId().'" href="'.$tp->replaceConstants($this->get('fb_imageurl'), 'full').'" title="'.$tp->toAttribute($this->get('fb_title')).'" rel="'.$tp->toAttribute(vartrue($parm['rel'], '')).'">'.$ret.'</a>';
}
2011-06-21 15:27:01 +00:00
return $ret;
}
2011-06-21 15:27:01 +00:00
2011-06-21 15:43:33 +00:00
/**
* Parameter list (GET string format):
* - text: used if href is true
* - href (1/0): return only URL if false, else return tag
* - rel: rel tag attribute
*
* @param string $parm
* @return string
*/
public function sc_featurebox_url($parm = '')
{
$tp = e107::getParser();
$url = $tp->replaceConstants($this->get('fb_imageurl'), 'full');
if(empty($url)) return '';
parse_str($parm, $parm);
if(!vartrue($parm['href']))
{
return $tp->replaceConstants($url);
}
$title = vartrue($parm['text']) ? defset($parm['text']) : FBLAN_02;
$alt = $tp->toAttribute($this->get('fb_title'), false, 'TITLE');
return '<a id="featurebox-url-'.$this->getId().'" href="'.$url.'" title="'.$alt.'" rel="'.$tp->toAttribute(vartrue($parm['rel'], '')).'">'.$title.'</a>';
}
public function sc_featurebox_text()
{
return e107::getParser()->toHTML($this->get('fb_text'), true, 'BODY');
}
2011-06-21 15:27:01 +00:00
/**
* Parameter list (GET string format):
* - src: return image src URL only
* - nourl: force no url tag
2011-06-21 15:27:01 +00:00
*
* @param string $parm
* @return string
*/
public function sc_featurebox_image($parm = '')
{
if(!$this->get('fb_image'))
{
return '';
}
parse_str($parm, $parm);
$tp = e107::getParser();
2011-06-21 15:27:01 +00:00
$src = $tp->replaceConstants($this->get('fb_image'), 'full');
2009-12-11 00:36:30 +00:00
if(isset($parm['src']))
{
return $src;
}
2009-12-11 23:49:35 +00:00
$tag = '<img id="featurebox-image-'.$this->getId().'" src="'.$src.'" alt="'.$tp->toAttribute($this->get('fb_title')).'" class="featurebox" />';
if(isset($parm['nourl']) || !$this->get('fb_imageurl'))
{
return $tag;
}
2009-12-12 10:30:33 +00:00
return '<a id="featurebox-imageurl-'.$this->getId().'" href="'.$tp->replaceConstants($this->get('fb_imageurl'), 'full').'" title="'.$tp->toAttribute($this->get('fb_title')).'" rel="'.$tp->toAttribute(vartrue($parm['rel'], 'external')).'">'.$tag.'</a>';
}
public function sc_featurebox_thumb($parm='')
{
if(!$this->get('fb_image'))
{
return '';
}
$att = ($parm) ?$parm : 'aw=100&ah=60';
return e107::getParser()->thumbUrl($this->get('fb_image'),$att);
}
2011-06-21 15:27:01 +00:00
2009-12-11 13:11:36 +00:00
/**
* Item counter number (starting from 1)
*/
public function sc_featurebox_counter()
{
return $this->getParam('counter', 1);
}
2011-06-21 15:27:01 +00:00
2009-12-11 13:11:36 +00:00
/**
* Item limit number
*/
public function sc_featurebox_limit()
{
return $this->getParam('limit', 0);
}
2011-06-21 15:27:01 +00:00
2009-12-11 13:11:36 +00:00
/**
* Number of items (real) currently loaded
*/
public function sc_featurebox_total()
{
return $this->getParam('total', 0);
}
2011-06-21 15:27:01 +00:00
2009-12-11 13:11:36 +00:00
/**
* Total Number of items (no matter of the limit)
*/
public function sc_featurebox_all()
{
return $this->getCategory()->sc_featurebox_category_all();
}
2011-06-21 15:27:01 +00:00
2009-12-11 13:11:36 +00:00
/**
* Number of items per column
*/
public function sc_featurebox_cols()
{
return $this->getParam('cols', 1);
}
2011-06-21 15:27:01 +00:00
2009-12-11 13:11:36 +00:00
/**
* Item counter number inside a column (1 to sc_featurebox_cols)
*/
public function sc_featurebox_colcount()
{
return $this->getParam('col_counter', 1);
}
2011-06-21 15:27:01 +00:00
2009-12-11 13:11:36 +00:00
/**
* Column counter
*/
public function sc_featurebox_colscount()
{
return $this->getParam('cols_counter', 1);
}
2011-06-21 15:27:01 +00:00
/**
* Set current category
* @param plugin_featurebox_category $category
* @return plugin_featurebox_item
*/
public function setCategory($category)
{
2011-06-21 15:27:01 +00:00
$this->_category = $category;
return $this;
}
/**
* Get Category model instance
* @return plugin_featurebox_category
*/
public function getCategory()
{
if(null === $this->_category)
{
$this->_category = new plugin_featurebox_category();
$this->_category->load($this->get('fb_category'));
}
return $this->_category;
}
2011-06-21 15:27:01 +00:00
/**
* Magic call - category shortcodes
2011-06-21 15:27:01 +00:00
*
* @param string $method
* @param array $arguments
*/
public function __call($method, $arguments)
{
if (strpos($method, "sc_featurebox_") === 0)
{
return call_user_func_array(array($this->getCategory(), $method), $arguments);
}
}
}