adding zend project folders into old campcaster.
This commit is contained in:
parent
56abfaf28e
commit
7ef0c18b26
4045 changed files with 1054952 additions and 0 deletions
410
library/Zend/Tag/Cloud.php
Normal file
410
library/Zend/Tag/Cloud.php
Normal file
|
@ -0,0 +1,410 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @subpackage Cloud
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Cloud.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Tag_Item
|
||||
*/
|
||||
require_once 'Zend/Tag/Item.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Tag_Cloud
|
||||
{
|
||||
/**
|
||||
* Decorator for the cloud
|
||||
*
|
||||
* @var Zend_Tag_Cloud_Decorator_Cloud
|
||||
*/
|
||||
protected $_cloudDecorator = null;
|
||||
|
||||
/**
|
||||
* Decorator for the tags
|
||||
*
|
||||
* @var Zend_Tag_Cloud_Decorator_Tag
|
||||
*/
|
||||
protected $_tagDecorator = null;
|
||||
|
||||
/**
|
||||
* List of all tags
|
||||
*
|
||||
* @var Zend_Tag_ItemList
|
||||
*/
|
||||
protected $_tags = null;
|
||||
|
||||
/**
|
||||
* Plugin loader for decorators
|
||||
*
|
||||
* @var Zend_Loader_PluginLoader
|
||||
*/
|
||||
protected $_pluginLoader = null;
|
||||
|
||||
/**
|
||||
* Option keys to skip when calling setOptions()
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_skipOptions = array(
|
||||
'options',
|
||||
'config',
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new tag cloud with options
|
||||
*
|
||||
* @param mixed $options
|
||||
*/
|
||||
public function __construct($options = null)
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$this->setConfig($options);
|
||||
}
|
||||
|
||||
if (is_array($options)) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options from Zend_Config
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @return Zend_Tag_Cloud
|
||||
*/
|
||||
public function setConfig(Zend_Config $config)
|
||||
{
|
||||
$this->setOptions($config->toArray());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options from array
|
||||
*
|
||||
* @param array $options Configuration for Zend_Tag_Cloud
|
||||
* @return Zend_Tag_Cloud
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
if (isset($options['prefixPath'])) {
|
||||
$this->addPrefixPaths($options['prefixPath']);
|
||||
unset($options['prefixPath']);
|
||||
}
|
||||
|
||||
foreach ($options as $key => $value) {
|
||||
if (in_array(strtolower($key), $this->_skipOptions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$method = 'set' . ucfirst($key);
|
||||
if (method_exists($this, $method)) {
|
||||
$this->$method($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tags for the tag cloud.
|
||||
*
|
||||
* $tags should be an array containing single tags as array. Each tag
|
||||
* array should at least contain the keys 'title' and 'weight'. Optionally
|
||||
* you may supply the key 'url', to which the tag links to. Any additional
|
||||
* parameter in the array is silently ignored and can be used by custom
|
||||
* decorators.
|
||||
*
|
||||
* @param array $tags
|
||||
* @return Zend_Tag_Cloud
|
||||
*/
|
||||
public function setTags(array $tags)
|
||||
{
|
||||
// Validate and cleanup the tags
|
||||
$itemList = $this->getItemList();
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
if ($tag instanceof Zend_Tag_Taggable) {
|
||||
$itemList[] = $tag;
|
||||
} else if (is_array($tag)) {
|
||||
$itemList[] = new Zend_Tag_Item($tag);
|
||||
} else {
|
||||
require_once 'Zend/Tag/Cloud/Exception.php';
|
||||
throw new Zend_Tag_Cloud_Exception('Tag must be an instance of Zend_Tag_Taggable or an array');
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a single tag to the cloud
|
||||
*
|
||||
* @param Zend_Tag_Taggable|array $tag
|
||||
* @return Zend_Tag_Cloud
|
||||
*/
|
||||
public function appendTag($tag)
|
||||
{
|
||||
$tags = $this->getItemList();
|
||||
if ($tag instanceof Zend_Tag_Taggable) {
|
||||
$tags[] = $tag;
|
||||
} else if (is_array($tag)) {
|
||||
$tags[] = new Zend_Tag_Item($tag);
|
||||
} else {
|
||||
require_once 'Zend/Tag/Cloud/Exception.php';
|
||||
throw new Zend_Tag_Cloud_Exception('Tag must be an instance of Zend_Tag_Taggable or an array');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the item list
|
||||
*
|
||||
* @param Zend_Tag_ItemList $itemList
|
||||
* @return Zend_Tag_Cloud
|
||||
*/
|
||||
public function setItemList(Zend_Tag_ItemList $itemList)
|
||||
{
|
||||
$this->_tags = $itemList;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the item list
|
||||
*
|
||||
* If item list is undefined, creates one.
|
||||
*
|
||||
* @return Zend_Tag_ItemList
|
||||
*/
|
||||
public function getItemList()
|
||||
{
|
||||
if (null === $this->_tags) {
|
||||
require_once 'Zend/Tag/ItemList.php';
|
||||
$this->setItemList(new Zend_Tag_ItemList());
|
||||
}
|
||||
return $this->_tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the decorator for the cloud
|
||||
*
|
||||
* @param mixed $decorator
|
||||
* @return Zend_Tag_Cloud
|
||||
*/
|
||||
public function setCloudDecorator($decorator)
|
||||
{
|
||||
$options = null;
|
||||
|
||||
if (is_array($decorator)) {
|
||||
if (isset($decorator['options'])) {
|
||||
$options = $decorator['options'];
|
||||
}
|
||||
|
||||
if (isset($decorator['decorator'])) {
|
||||
$decorator = $decorator['decorator'];
|
||||
}
|
||||
}
|
||||
|
||||
if (is_string($decorator)) {
|
||||
$classname = $this->getPluginLoader()->load($decorator);
|
||||
$decorator = new $classname($options);
|
||||
}
|
||||
|
||||
if (!($decorator instanceof Zend_Tag_Cloud_Decorator_Cloud)) {
|
||||
require_once 'Zend/Tag/Cloud/Exception.php';
|
||||
throw new Zend_Tag_Cloud_Exception('Decorator is no instance of Zend_Tag_Cloud_Decorator_Cloud');
|
||||
}
|
||||
|
||||
$this->_cloudDecorator = $decorator;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the decorator for the cloud
|
||||
*
|
||||
* @return Zend_Tag_Cloud_Decorator_Cloud
|
||||
*/
|
||||
public function getCloudDecorator()
|
||||
{
|
||||
if (null === $this->_cloudDecorator) {
|
||||
$this->setCloudDecorator('htmlCloud');
|
||||
}
|
||||
return $this->_cloudDecorator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the decorator for the tags
|
||||
*
|
||||
* @param mixed $decorator
|
||||
* @return Zend_Tag_Cloud
|
||||
*/
|
||||
public function setTagDecorator($decorator)
|
||||
{
|
||||
$options = null;
|
||||
|
||||
if (is_array($decorator)) {
|
||||
if (isset($decorator['options'])) {
|
||||
$options = $decorator['options'];
|
||||
}
|
||||
|
||||
if (isset($decorator['decorator'])) {
|
||||
$decorator = $decorator['decorator'];
|
||||
}
|
||||
}
|
||||
|
||||
if (is_string($decorator)) {
|
||||
$classname = $this->getPluginLoader()->load($decorator);
|
||||
$decorator = new $classname($options);
|
||||
}
|
||||
|
||||
if (!($decorator instanceof Zend_Tag_Cloud_Decorator_Tag)) {
|
||||
require_once 'Zend/Tag/Cloud/Exception.php';
|
||||
throw new Zend_Tag_Cloud_Exception('Decorator is no instance of Zend_Tag_Cloud_Decorator_Tag');
|
||||
}
|
||||
|
||||
$this->_tagDecorator = $decorator;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the decorator for the tags
|
||||
*
|
||||
* @return Zend_Tag_Cloud_Decorator_Tag
|
||||
*/
|
||||
public function getTagDecorator()
|
||||
{
|
||||
if (null === $this->_tagDecorator) {
|
||||
$this->setTagDecorator('htmlTag');
|
||||
}
|
||||
return $this->_tagDecorator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set plugin loaders for use with decorators
|
||||
*
|
||||
* @param Zend_Loader_PluginLoader_Interface $loader
|
||||
* @return Zend_Tag_Cloud
|
||||
*/
|
||||
public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader)
|
||||
{
|
||||
$this->_pluginLoader = $loader;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin loader for decorators
|
||||
*
|
||||
* @return Zend_Loader_PluginLoader
|
||||
*/
|
||||
public function getPluginLoader()
|
||||
{
|
||||
if ($this->_pluginLoader === null) {
|
||||
$prefix = 'Zend_Tag_Cloud_Decorator_';
|
||||
$pathPrefix = 'Zend/Tag/Cloud/Decorator/';
|
||||
|
||||
require_once 'Zend/Loader/PluginLoader.php';
|
||||
$this->_pluginLoader = new Zend_Loader_PluginLoader(array($prefix => $pathPrefix));
|
||||
}
|
||||
|
||||
return $this->_pluginLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add many prefix paths at once
|
||||
*
|
||||
* @param array $paths
|
||||
* @return Zend_Tag_Cloud
|
||||
*/
|
||||
public function addPrefixPaths(array $paths)
|
||||
{
|
||||
if (isset($paths['prefix']) && isset($paths['path'])) {
|
||||
return $this->addPrefixPath($paths['prefix'], $paths['path']);
|
||||
}
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (!isset($path['prefix']) || !isset($path['path'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->addPrefixPath($path['prefix'], $path['path']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add prefix path for plugin loader
|
||||
*
|
||||
* @param string $prefix
|
||||
* @param string $path
|
||||
* @return Zend_Tag_Cloud
|
||||
*/
|
||||
public function addPrefixPath($prefix, $path)
|
||||
{
|
||||
$loader = $this->getPluginLoader();
|
||||
$loader->addPrefixPath($prefix, $path);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the tag cloud
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$tags = $this->getItemList();
|
||||
|
||||
if (count($tags) === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$tagsResult = $this->getTagDecorator()->render($tags);
|
||||
$cloudResult = $this->getCloudDecorator()->render($tagsResult);
|
||||
|
||||
return $cloudResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the tag cloud
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
try {
|
||||
$result = $this->render();
|
||||
return $result;
|
||||
} catch (Exception $e) {
|
||||
$message = "Exception caught by tag cloud: " . $e->getMessage()
|
||||
. "\nStack Trace:\n" . $e->getTraceAsString();
|
||||
trigger_error($message, E_USER_WARNING);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
88
library/Zend/Tag/Cloud/Decorator/Cloud.php
Normal file
88
library/Zend/Tag/Cloud/Decorator/Cloud.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @subpackage Cloud
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Cloud.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract class for cloud decorators
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Tag_Cloud_Decorator_Cloud
|
||||
{
|
||||
/**
|
||||
* Option keys to skip when calling setOptions()
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_skipOptions = array(
|
||||
'options',
|
||||
'config',
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new cloud decorator with options
|
||||
*
|
||||
* @param mixed $options
|
||||
*/
|
||||
public function __construct($options = null)
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
}
|
||||
|
||||
if (is_array($options)) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options from array
|
||||
*
|
||||
* @param array $options Configuration for the decorator
|
||||
* @return Zend_Tag_Cloud
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
foreach ($options as $key => $value) {
|
||||
if (in_array(strtolower($key), $this->_skipOptions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$method = 'set' . $key;
|
||||
if (method_exists($this, $method)) {
|
||||
$this->$method($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a list of formatted tags
|
||||
*
|
||||
* @param array $tags
|
||||
* @return string
|
||||
*/
|
||||
abstract public function render(array $tags);
|
||||
}
|
39
library/Zend/Tag/Cloud/Decorator/Exception.php
Normal file
39
library/Zend/Tag/Cloud/Decorator/Exception.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @subpackage Cloud
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Tag_Cloud_Exception
|
||||
*/
|
||||
require_once 'Zend/Tag/Cloud/Exception.php';
|
||||
|
||||
/**
|
||||
* Exception class for Zend_Tag_Cloud_Decorator
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @uses Zend_Tag_Cloud_Exception
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Tag_Cloud_Decorator_Exception extends Zend_Tag_Cloud_Exception
|
||||
{
|
||||
}
|
155
library/Zend/Tag/Cloud/Decorator/HtmlCloud.php
Normal file
155
library/Zend/Tag/Cloud/Decorator/HtmlCloud.php
Normal file
|
@ -0,0 +1,155 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @subpackage Cloud
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: HtmlCloud.php 20104 2010-01-06 21:26:01Z matthew $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Tag_Cloud_Decorator_Cloud
|
||||
*/
|
||||
require_once 'Zend/Tag/Cloud/Decorator/Cloud.php';
|
||||
|
||||
/**
|
||||
* Simple HTML decorator for clouds
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @uses Zend_Tag_Cloud_Decorator_Cloud
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Tag_Cloud_Decorator_HtmlCloud extends Zend_Tag_Cloud_Decorator_Cloud
|
||||
{
|
||||
/**
|
||||
* @var string Encoding to use
|
||||
*/
|
||||
protected $_encoding = 'UTF-8';
|
||||
|
||||
/**
|
||||
* List of HTML tags
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_htmlTags = array(
|
||||
'ul' => array('class' => 'Zend_Tag_Cloud')
|
||||
);
|
||||
|
||||
/**
|
||||
* Separator for the single tags
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_separator = ' ';
|
||||
|
||||
/**
|
||||
* Get encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding()
|
||||
{
|
||||
return $this->_encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set encoding
|
||||
*
|
||||
* @param string
|
||||
* @return Zend_Tag_Cloud_Decorator_HtmlCloud
|
||||
*/
|
||||
public function setEncoding($value)
|
||||
{
|
||||
$this->_encoding = (string) $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the HTML tags surrounding all tags
|
||||
*
|
||||
* @param array $htmlTags
|
||||
* @return Zend_Tag_Cloud_Decorator_HtmlCloud
|
||||
*/
|
||||
public function setHtmlTags(array $htmlTags)
|
||||
{
|
||||
$this->_htmlTags = $htmlTags;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve HTML tag map
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHtmlTags()
|
||||
{
|
||||
return $this->_htmlTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the separator between the single tags
|
||||
*
|
||||
* @param string
|
||||
* @return Zend_Tag_Cloud_Decorator_HtmlCloud
|
||||
*/
|
||||
public function setSeparator($separator)
|
||||
{
|
||||
$this->_separator = $separator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tag separator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSeparator()
|
||||
{
|
||||
return $this->_separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Tag_Cloud_Decorator_Cloud
|
||||
*
|
||||
* @param array $tags
|
||||
* @return string
|
||||
*/
|
||||
public function render(array $tags)
|
||||
{
|
||||
$cloudHtml = implode($this->getSeparator(), $tags);
|
||||
|
||||
$enc = $this->getEncoding();
|
||||
foreach ($this->getHtmlTags() as $key => $data) {
|
||||
if (is_array($data)) {
|
||||
$htmlTag = $key;
|
||||
$attributes = '';
|
||||
|
||||
foreach ($data as $param => $value) {
|
||||
$attributes .= ' ' . $param . '="' . htmlspecialchars($value, ENT_COMPAT, $enc) . '"';
|
||||
}
|
||||
} else {
|
||||
$htmlTag = $data;
|
||||
$attributes = '';
|
||||
}
|
||||
|
||||
$cloudHtml = sprintf('<%1$s%3$s>%2$s</%1$s>', $htmlTag, $cloudHtml, $attributes);
|
||||
}
|
||||
|
||||
return $cloudHtml;
|
||||
}
|
||||
}
|
306
library/Zend/Tag/Cloud/Decorator/HtmlTag.php
Normal file
306
library/Zend/Tag/Cloud/Decorator/HtmlTag.php
Normal file
|
@ -0,0 +1,306 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @subpackage Cloud
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: HtmlTag.php 20104 2010-01-06 21:26:01Z matthew $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Tag_Cloud_Decorator_Tag
|
||||
*/
|
||||
require_once 'Zend/Tag/Cloud/Decorator/Tag.php';
|
||||
|
||||
/**
|
||||
* Simple HTML decorator for tags
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @uses Zend_Tag_Cloud_Decorator_Tag
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Tag_Cloud_Decorator_HtmlTag extends Zend_Tag_Cloud_Decorator_Tag
|
||||
{
|
||||
/**
|
||||
* List of tags which get assigned to the inner element instead of
|
||||
* font-sizes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_classList = null;
|
||||
|
||||
/**
|
||||
* @var string Encoding to utilize
|
||||
*/
|
||||
protected $_encoding = 'UTF-8';
|
||||
|
||||
/**
|
||||
* Unit for the fontsize
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_fontSizeUnit = 'px';
|
||||
|
||||
/**
|
||||
* Allowed fontsize units
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_alloweFontSizeUnits = array('em', 'ex', 'px', 'in', 'cm', 'mm', 'pt', 'pc', '%');
|
||||
|
||||
/**
|
||||
* List of HTML tags
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_htmlTags = array(
|
||||
'li'
|
||||
);
|
||||
|
||||
/**
|
||||
* Maximum fontsize
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_maxFontSize = 20;
|
||||
|
||||
/**
|
||||
* Minimum fontsize
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_minFontSize = 10;
|
||||
|
||||
/**
|
||||
* Set a list of classes to use instead of fontsizes
|
||||
*
|
||||
* @param array $classList
|
||||
* @throws Zend_Tag_Cloud_Decorator_Exception When the classlist is empty
|
||||
* @throws Zend_Tag_Cloud_Decorator_Exception When the classlist contains an invalid classname
|
||||
* @return Zend_Tag_Cloud_Decorator_HtmlTag
|
||||
*/
|
||||
public function setClassList(array $classList = null)
|
||||
{
|
||||
if (is_array($classList)) {
|
||||
if (count($classList) === 0) {
|
||||
require_once 'Zend/Tag/Cloud/Decorator/Exception.php';
|
||||
throw new Zend_Tag_Cloud_Decorator_Exception('Classlist is empty');
|
||||
}
|
||||
|
||||
foreach ($classList as $class) {
|
||||
if (!is_string($class)) {
|
||||
require_once 'Zend/Tag/Cloud/Decorator/Exception.php';
|
||||
throw new Zend_Tag_Cloud_Decorator_Exception('Classlist contains an invalid classname');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_classList = $classList;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getClassList()
|
||||
{
|
||||
return $this->_classList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding()
|
||||
{
|
||||
return $this->_encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set encoding
|
||||
*
|
||||
* @param string $value
|
||||
* @return Zend_Tag_Cloud_Decorator_HtmlTag
|
||||
*/
|
||||
public function setEncoding($value)
|
||||
{
|
||||
$this->_encoding = (string) $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the font size unit
|
||||
*
|
||||
* Possible values are: em, ex, px, in, cm, mm, pt, pc and %
|
||||
*
|
||||
* @param string $fontSizeUnit
|
||||
* @throws Zend_Tag_Cloud_Decorator_Exception When an invalid fontsize unit is specified
|
||||
* @return Zend_Tag_Cloud_Decorator_HtmlTag
|
||||
*/
|
||||
public function setFontSizeUnit($fontSizeUnit)
|
||||
{
|
||||
if (!in_array($fontSizeUnit, $this->_alloweFontSizeUnits)) {
|
||||
require_once 'Zend/Tag/Cloud/Decorator/Exception.php';
|
||||
throw new Zend_Tag_Cloud_Decorator_Exception('Invalid fontsize unit specified');
|
||||
}
|
||||
|
||||
$this->_fontSizeUnit = (string) $fontSizeUnit;
|
||||
$this->setClassList(null);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve font size unit
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFontSizeUnit()
|
||||
{
|
||||
return $this->_fontSizeUnit;
|
||||
}
|
||||
/**
|
||||
* Set the HTML tags surrounding the <a> element
|
||||
*
|
||||
* @param array $htmlTags
|
||||
* @return Zend_Tag_Cloud_Decorator_HtmlTag
|
||||
*/
|
||||
public function setHtmlTags(array $htmlTags)
|
||||
{
|
||||
$this->_htmlTags = $htmlTags;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTML tags map
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHtmlTags()
|
||||
{
|
||||
return $this->_htmlTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set maximum font size
|
||||
*
|
||||
* @param integer $maxFontSize
|
||||
* @throws Zend_Tag_Cloud_Decorator_Exception When fontsize is not numeric
|
||||
* @return Zend_Tag_Cloud_Decorator_HtmlTag
|
||||
*/
|
||||
public function setMaxFontSize($maxFontSize)
|
||||
{
|
||||
if (!is_numeric($maxFontSize)) {
|
||||
require_once 'Zend/Tag/Cloud/Decorator/Exception.php';
|
||||
throw new Zend_Tag_Cloud_Decorator_Exception('Fontsize must be numeric');
|
||||
}
|
||||
|
||||
$this->_maxFontSize = (int) $maxFontSize;
|
||||
$this->setClassList(null);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve maximum font size
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxFontSize()
|
||||
{
|
||||
return $this->_maxFontSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set minimum font size
|
||||
*
|
||||
* @param int $minFontSize
|
||||
* @throws Zend_Tag_Cloud_Decorator_Exception When fontsize is not numeric
|
||||
* @return Zend_Tag_Cloud_Decorator_HtmlTag
|
||||
*/
|
||||
public function setMinFontSize($minFontSize)
|
||||
{
|
||||
if (!is_numeric($minFontSize)) {
|
||||
require_once 'Zend/Tag/Cloud/Decorator/Exception.php';
|
||||
throw new Zend_Tag_Cloud_Decorator_Exception('Fontsize must be numeric');
|
||||
}
|
||||
|
||||
$this->_minFontSize = (int) $minFontSize;
|
||||
$this->setClassList(null);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve minimum font size
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMinFontSize()
|
||||
{
|
||||
return $this->_minFontSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Tag_Cloud_Decorator_Tag
|
||||
*
|
||||
* @param Zend_Tag_ItemList $tags
|
||||
* @return array
|
||||
*/
|
||||
public function render(Zend_Tag_ItemList $tags)
|
||||
{
|
||||
if (null === ($weightValues = $this->getClassList())) {
|
||||
$weightValues = range($this->getMinFontSize(), $this->getMaxFontSize());
|
||||
}
|
||||
|
||||
$tags->spreadWeightValues($weightValues);
|
||||
|
||||
$result = array();
|
||||
|
||||
$enc = $this->getEncoding();
|
||||
foreach ($tags as $tag) {
|
||||
if (null === ($classList = $this->getClassList())) {
|
||||
$attribute = sprintf('style="font-size: %d%s;"', $tag->getParam('weightValue'), $this->getFontSizeUnit());
|
||||
} else {
|
||||
$attribute = sprintf('class="%s"', htmlspecialchars($tag->getParam('weightValue'), ENT_COMPAT, $enc));
|
||||
}
|
||||
|
||||
$tagHtml = sprintf('<a href="%s" %s>%s</a>', htmlSpecialChars($tag->getParam('url'), ENT_COMPAT, $enc), $attribute, $tag->getTitle());
|
||||
|
||||
foreach ($this->getHtmlTags() as $key => $data) {
|
||||
if (is_array($data)) {
|
||||
$htmlTag = $key;
|
||||
$attributes = '';
|
||||
|
||||
foreach ($data as $param => $value) {
|
||||
$attributes .= ' ' . $param . '="' . htmlspecialchars($value, ENT_COMPAT, $enc) . '"';
|
||||
}
|
||||
} else {
|
||||
$htmlTag = $data;
|
||||
$attributes = '';
|
||||
}
|
||||
|
||||
$tagHtml = sprintf('<%1$s%3$s>%2$s</%1$s>', $htmlTag, $tagHtml, $attributes);
|
||||
}
|
||||
|
||||
$result[] = $tagHtml;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
88
library/Zend/Tag/Cloud/Decorator/Tag.php
Normal file
88
library/Zend/Tag/Cloud/Decorator/Tag.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @subpackage Cloud
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Tag.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract class for tag decorators
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Tag_Cloud_Decorator_Tag
|
||||
{
|
||||
/**
|
||||
* Option keys to skip when calling setOptions()
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_skipOptions = array(
|
||||
'options',
|
||||
'config',
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new cloud decorator with options
|
||||
*
|
||||
* @param mixed $options
|
||||
*/
|
||||
public function __construct($options = null)
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
}
|
||||
|
||||
if (is_array($options)) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options from array
|
||||
*
|
||||
* @param array $options Configuration for the decorator
|
||||
* @return Zend_Tag_Cloud
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
foreach ($options as $key => $value) {
|
||||
if (in_array(strtolower($key), $this->_skipOptions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$method = 'set' . $key;
|
||||
if (method_exists($this, $method)) {
|
||||
$this->$method($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a list of tags
|
||||
*
|
||||
* @param Zend_Tag_ItemList $tags
|
||||
* @return array
|
||||
*/
|
||||
abstract public function render(Zend_Tag_ItemList $tags);
|
||||
}
|
38
library/Zend/Tag/Cloud/Exception.php
Normal file
38
library/Zend/Tag/Cloud/Exception.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Tag_Exception
|
||||
*/
|
||||
require_once 'Zend/Tag/Exception.php';
|
||||
|
||||
/**
|
||||
* Exception class for Zend_Tag_Cloud
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @uses Zend_Exception
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Tag_Cloud_Exception extends Zend_Tag_Exception
|
||||
{
|
||||
}
|
38
library/Zend/Tag/Exception.php
Normal file
38
library/Zend/Tag/Exception.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* Exception class for Zend_Tag
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @uses Zend_Exception
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Tag_Exception extends Zend_Exception
|
||||
{
|
||||
}
|
220
library/Zend/Tag/Item.php
Normal file
220
library/Zend/Tag/Item.php
Normal file
|
@ -0,0 +1,220 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @subpackage Item
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Item.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Tag_Taggable
|
||||
*/
|
||||
require_once 'Zend/Tag/Taggable.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @uses Zend_Tag_Taggable
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Tag_Item implements Zend_Tag_Taggable
|
||||
{
|
||||
/**
|
||||
* Title of the tag
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title = null;
|
||||
|
||||
/**
|
||||
* Weight of the tag
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $_weight = null;
|
||||
|
||||
/**
|
||||
* Custom parameters
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_params = array();
|
||||
|
||||
/**
|
||||
* Option keys to skip when calling setOptions()
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_skipOptions = array(
|
||||
'options',
|
||||
'param'
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new tag according to the options
|
||||
*
|
||||
* @param array|Zend_Config $options
|
||||
* @throws Zend_Tag_Exception When invalid options are provided
|
||||
* @throws Zend_Tag_Exception When title was not set
|
||||
* @throws Zend_Tag_Exception When weight was not set
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
}
|
||||
|
||||
if (!is_array($options)) {
|
||||
require_once 'Zend/Tag/Exception.php';
|
||||
throw new Zend_Tag_Exception('Invalid options provided to constructor');
|
||||
}
|
||||
|
||||
$this->setOptions($options);
|
||||
|
||||
if ($this->_title === null) {
|
||||
require_once 'Zend/Tag/Exception.php';
|
||||
throw new Zend_Tag_Exception('Title was not set');
|
||||
}
|
||||
|
||||
if ($this->_weight === null) {
|
||||
require_once 'Zend/Tag/Exception.php';
|
||||
throw new Zend_Tag_Exception('Weight was not set');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options of the tag
|
||||
*
|
||||
* @param array $options
|
||||
* @return Zend_Tag_Item
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
foreach ($options as $key => $value) {
|
||||
if (in_array(strtolower($key), $this->_skipOptions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$method = 'set' . $key;
|
||||
if (method_exists($this, $method)) {
|
||||
$this->$method($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Tag_Taggable
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->_title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title
|
||||
*
|
||||
* @param string $title
|
||||
* @throws Zend_Tag_Exception When title is no string
|
||||
* @return Zend_Tag_Item
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
if (!is_string($title)) {
|
||||
require_once 'Zend/Tag/Exception.php';
|
||||
throw new Zend_Tag_Exception('Title must be a string');
|
||||
}
|
||||
|
||||
$this->_title = (string) $title;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Tag_Taggable
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getWeight()
|
||||
{
|
||||
return $this->_weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the weight
|
||||
*
|
||||
* @param float $weight
|
||||
* @throws Zend_Tag_Exception When weight is not numeric
|
||||
* @return Zend_Tag_Item
|
||||
*/
|
||||
public function setWeight($weight)
|
||||
{
|
||||
if (!is_numeric($weight)) {
|
||||
require_once 'Zend/Tag/Exception.php';
|
||||
throw new Zend_Tag_Exception('Weight must be numeric');
|
||||
}
|
||||
|
||||
$this->_weight = (float) $weight;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set multiple params at once
|
||||
*
|
||||
* @param array $params
|
||||
* @return Zend_Tag_Item
|
||||
*/
|
||||
public function setParams(array $params)
|
||||
{
|
||||
foreach ($params as $name => $value) {
|
||||
$this->setParam($name, $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Tag_Taggable
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return Zend_Tag_Item
|
||||
*/
|
||||
public function setParam($name, $value)
|
||||
{
|
||||
$this->_params[$name] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Tag_Taggable
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParam($name)
|
||||
{
|
||||
if (isset($this->_params[$name])) {
|
||||
return $this->_params[$name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
238
library/Zend/Tag/ItemList.php
Normal file
238
library/Zend/Tag/ItemList.php
Normal file
|
@ -0,0 +1,238 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @subpackage ItemList
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ItemList.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Tag_Taggable
|
||||
*/
|
||||
require_once 'Zend/Tag/Taggable.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Tag_ItemList implements Countable, SeekableIterator, ArrayAccess
|
||||
{
|
||||
/**
|
||||
* Items in this list
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_items = array();
|
||||
|
||||
/**
|
||||
* Count all items
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->_items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Spread values in the items relative to their weight
|
||||
*
|
||||
* @param array $values
|
||||
* @throws Zend_Tag_Exception When value list is empty
|
||||
* @return void
|
||||
*/
|
||||
public function spreadWeightValues(array $values)
|
||||
{
|
||||
// Don't allow an empty value list
|
||||
if (count($values) === 0) {
|
||||
require_once 'Zend/Tag/Exception.php';
|
||||
throw new Zend_Tag_Exception('Value list may not be empty');
|
||||
}
|
||||
|
||||
// Re-index the array
|
||||
$values = array_values($values);
|
||||
|
||||
// If just a single value is supplied simply assign it to to all tags
|
||||
if (count($values) === 1) {
|
||||
foreach ($this->_items as $item) {
|
||||
$item->setParam('weightValue', $values[0]);
|
||||
}
|
||||
} else {
|
||||
// Calculate min- and max-weight
|
||||
$minWeight = null;
|
||||
$maxWeight = null;
|
||||
|
||||
foreach ($this->_items as $item) {
|
||||
if ($minWeight === null && $maxWeight === null) {
|
||||
$minWeight = $item->getWeight();
|
||||
$maxWeight = $item->getWeight();
|
||||
} else {
|
||||
$minWeight = min($minWeight, $item->getWeight());
|
||||
$maxWeight = max($maxWeight, $item->getWeight());
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the thresholds
|
||||
$steps = count($values);
|
||||
$delta = ($maxWeight - $minWeight) / ($steps - 1);
|
||||
$thresholds = array();
|
||||
|
||||
for ($i = 0; $i < $steps; $i++) {
|
||||
$thresholds[$i] = floor(100 * log(($minWeight + $i * $delta) + 2));
|
||||
}
|
||||
|
||||
// Then assign the weight values
|
||||
foreach ($this->_items as $item) {
|
||||
$threshold = floor(100 * log($item->getWeight() + 2));
|
||||
|
||||
for ($i = 0; $i < $steps; $i++) {
|
||||
if ($threshold <= $thresholds[$i]) {
|
||||
$item->setParam('weightValue', $values[$i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Seek to an absolute positio
|
||||
*
|
||||
* @param integer $index
|
||||
* @throws OutOfBoundsException When the seek position is invalid
|
||||
* @return void
|
||||
*/
|
||||
public function seek($index)
|
||||
{
|
||||
$this->rewind();
|
||||
$position = 0;
|
||||
|
||||
while ($position < $index && $this->valid()) {
|
||||
$this->next();
|
||||
$position++;
|
||||
}
|
||||
|
||||
if (!$this->valid()) {
|
||||
throw new OutOfBoundsException('Invalid seek position');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current element
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return current($this->_items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move forward to next element
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
return next($this->_items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the key of the current element
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return key($this->_items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is a current element after calls to rewind() or next()
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return ($this->current() !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind the Iterator to the first element
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
reset($this->_items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an offset exists
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @return boolean
|
||||
*/
|
||||
public function offsetExists($offset) {
|
||||
return array_key_exists($offset, $this->_items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of an offset
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @return Zend_Tag_Taggable
|
||||
*/
|
||||
public function offsetGet($offset) {
|
||||
return $this->_items[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a new item
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @param Zend_Tag_Taggable $item
|
||||
* @throws OutOfBoundsException When item does not implement Zend_Tag_Taggable
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($offset, $item) {
|
||||
// We need to make that check here, as the method signature must be
|
||||
// compatible with ArrayAccess::offsetSet()
|
||||
if (!($item instanceof Zend_Tag_Taggable)) {
|
||||
require_once 'Zend/Tag/Exception.php';
|
||||
throw new Zend_Tag_Exception('Item must implement Zend_Tag_Taggable');
|
||||
}
|
||||
|
||||
if ($offset === null) {
|
||||
$this->_items[] = $item;
|
||||
} else {
|
||||
$this->_items[$offset] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset an item
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset($offset) {
|
||||
unset($this->_items[$offset]);
|
||||
}
|
||||
}
|
60
library/Zend/Tag/Taggable.php
Normal file
60
library/Zend/Tag/Taggable.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @subpackage Item
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Taggable.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Tag
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Tag_Taggable
|
||||
{
|
||||
/**
|
||||
* Get the title of the tag
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle();
|
||||
|
||||
/**
|
||||
* Get the weight of the tag
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getWeight();
|
||||
|
||||
/**
|
||||
* Set a parameter
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function setParam($name, $value);
|
||||
|
||||
/**
|
||||
* Get a parameter
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParam($name);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue