initial commit

This commit is contained in:
Chris Sewell
2012-11-28 03:55:08 -05:00
parent 7adb399b2e
commit cf140a2e97
3247 changed files with 492437 additions and 0 deletions

View File

@ -0,0 +1,495 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
* (c) 2004 David Heinemeier Hansson
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* AssetHelper.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author David Heinemeier Hansson
* @version SVN: $Id: AssetHelper.php 3775 2007-04-13 07:08:08Z fabien $
*/
/**
* Returns a <link> tag that browsers and news readers
* can use to auto-detect a RSS or ATOM feed for the current page,
* to be included in the <head> section of a HTML document.
*
* <b>Options:</b>
* - rel - defaults to 'alternate'
* - type - defaults to 'application/rss+xml'
* - title - defaults to the feed type in upper case
*
* <b>Examples:</b>
* <code>
* echo auto_discovery_link_tag('rss', 'module/feed');
* => <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.curenthost.com/module/feed" />
* echo auto_discovery_link_tag('rss', 'module/feed', array('title' => 'My RSS'));
* => <link rel="alternate" type="application/rss+xml" title="My RSS" href="http://www.curenthost.com/module/feed" />
* </code>
*
* @param string feed type ('rss', 'atom')
* @param string 'module/action' or '@rule' of the feed
* @param array additional HTML compliant <link> tag parameters
* @return string XHTML compliant <link> tag
*/
function auto_discovery_link_tag($type = 'rss', $url_options = array(), $tag_options = array())
{
return tag('link', array(
'rel' => isset($tag_options['rel']) ? $tag_options['rel'] : 'alternate',
'type' => isset($tag_options['type']) ? $tag_options['type'] : 'application/'.$type.'+xml',
'title' => isset($tag_options['title']) ? $tag_options['title'] : ucfirst($type),
'href' => url_for($url_options, true)
));
}
/**
* Returns the path to a JavaScript asset.
*
* <b>Example:</b>
* <code>
* echo javascript_path('myscript');
* => /js/myscript.js
* </code>
*
* <b>Note:</b> The asset name can be supplied as a...
* - full path, like "/my_js/myscript.css"
* - file name, like "myscript.js", that gets expanded to "/js/myscript.js"
* - file name without extension, like "myscript", that gets expanded to "/js/myscript.js"
*
* @param string asset name
* @param bool return absolute path ?
* @return string file path to the JavaScript file
* @see javascript_include_tag
*/
function javascript_path($source, $absolute = false)
{
return _compute_public_path($source, 'js', 'js', $absolute);
}
/**
* Returns a <script> include tag per source given as argument.
*
* <b>Examples:</b>
* <code>
* echo javascript_include_tag('xmlhr');
* => <script language="JavaScript" type="text/javascript" src="/js/xmlhr.js"></script>
* echo javascript_include_tag('common.javascript', '/elsewhere/cools');
* => <script language="JavaScript" type="text/javascript" src="/js/common.javascript"></script>
* <script language="JavaScript" type="text/javascript" src="/elsewhere/cools.js"></script>
* </code>
*
* @param string asset names
* @return string XHTML compliant <script> tag(s)
* @see javascript_path
*/
function javascript_include_tag()
{
$html = '';
foreach (func_get_args() as $source)
{
$source = javascript_path($source);
$html .= content_tag('script', '', array('type' => 'text/javascript', 'src' => $source))."\n";
}
return $html;
}
/**
* Returns the path to a stylesheet asset.
*
* <b>Example:</b>
* <code>
* echo stylesheet_path('style');
* => /css/style.css
* </code>
*
* <b>Note:</b> The asset name can be supplied as a...
* - full path, like "/my_css/style.css"
* - file name, like "style.css", that gets expanded to "/css/style.css"
* - file name without extension, like "style", that gets expanded to "/css/style.css"
*
* @param string asset name
* @param bool return absolute path ?
* @return string file path to the stylesheet file
* @see stylesheet_tag
*/
function stylesheet_path($source, $absolute = false)
{
return _compute_public_path($source, 'css', 'css', $absolute);
}
/**
* Returns a css <link> tag per source given as argument,
* to be included in the <head> section of a HTML document.
*
* <b>Options:</b>
* - rel - defaults to 'stylesheet'
* - type - defaults to 'text/css'
* - media - defaults to 'screen'
*
* <b>Examples:</b>
* <code>
* echo stylesheet_tag('style');
* => <link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />
* echo stylesheet_tag('style', array('media' => 'all'));
* => <link href="/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />
* echo stylesheet_tag('random.styles', '/css/stylish');
* => <link href="/stylesheets/random.styles" media="screen" rel="stylesheet" type="text/css" />
* <link href="/css/stylish.css" media="screen" rel="stylesheet" type="text/css" />
* </code>
*
* @param string asset names
* @param array additional HTML compliant <link> tag parameters
* @return string XHTML compliant <link> tag(s)
* @see stylesheet_path
*/
function stylesheet_tag()
{
$sources = func_get_args();
$sourceOptions = (func_num_args() > 1 && is_array($sources[func_num_args() - 1])) ? array_pop($sources) : array();
$html = '';
foreach ($sources as $source)
{
$source = stylesheet_path($source);
$options = array_merge(array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen', 'href' => $source), $sourceOptions);
$html .= tag('link', $options)."\n";
}
return $html;
}
/**
* Adds a stylesheet to the response object.
*
* @see sfResponse->addStylesheet()
*/
function use_stylesheet($css, $position = '', $options = array())
{
sfContext::getInstance()->getResponse()->addStylesheet($css, $position, $options);
}
/**
* Adds a javascript to the response object.
*
* @see sfResponse->addJavascript()
*/
function use_javascript($js, $position = '')
{
sfContext::getInstance()->getResponse()->addJavascript($js, $position);
}
/**
* Decorates the current template with a given layout.
*
* @param mixed The layout name or path or false to disable the layout
*/
function decorate_with($layout)
{
$view = sfContext::getInstance()->getActionStack()->getLastEntry()->getViewInstance();
if (false === $layout)
{
$view->setDecorator(false);
}
else
{
$view->setDecoratorTemplate($layout);
}
}
/**
* Returns the path to an image asset.
*
* <b>Example:</b>
* <code>
* echo image_path('foobar');
* => /images/foobar.png
* </code>
*
* <b>Note:</b> The asset name can be supplied as a...
* - full path, like "/my_images/image.gif"
* - file name, like "rss.gif", that gets expanded to "/images/rss.gif"
* - file name without extension, like "logo", that gets expanded to "/images/logo.png"
*
* @param string asset name
* @param bool return absolute path ?
* @return string file path to the image file
* @see image_tag
*/
function image_path($source, $absolute = false)
{
return _compute_public_path($source, 'images', 'png', $absolute);
}
/**
* Returns an <img> image tag for the asset given as argument.
*
* <b>Options:</b>
* - 'absolute' - to output absolute file paths, useful for embedded images in emails
* - 'alt' - defaults to the file name part of the asset (capitalized and without the extension)
* - 'size' - Supplied as "XxY", so "30x45" becomes width="30" and height="45"
*
* <b>Examples:</b>
* <code>
* echo image_tag('foobar');
* => <img src="images/foobar.png" alt="Foobar" />
* echo image_tag('/my_images/image.gif', array('alt' => 'Alternative text', 'size' => '100x200'));
* => <img src="/my_images/image.gif" alt="Alternative text" width="100" height="200" />
* </code>
*
* @param string image asset name
* @param array additional HTML compliant <img> tag parameters
* @return string XHTML compliant <img> tag
* @see image_path
*/
function image_tag($source, $options = array())
{
if (!$source)
{
return '';
}
$options = _parse_attributes($options);
$absolute = false;
if (isset($options['absolute']))
{
unset($options['absolute']);
$absolute = true;
}
$options['src'] = image_path($source, $absolute);
if (!isset($options['alt']))
{
$path_pos = strrpos($source, '/');
$dot_pos = strrpos($source, '.');
$begin = $path_pos ? $path_pos + 1 : 0;
$nb_str = ($dot_pos ? $dot_pos : strlen($source)) - $begin;
$options['alt'] = ucfirst(substr($source, $begin, $nb_str));
}
if (isset($options['size']))
{
list($options['width'], $options['height']) = split('x', $options['size'], 2);
unset($options['size']);
}
return tag('img', $options);
}
function _compute_public_path($source, $dir, $ext, $absolute = false)
{
if (strpos($source, '://'))
{
return $source;
}
$request = sfContext::getInstance()->getRequest();
$sf_relative_url_root = $request->getRelativeUrlRoot();
if (0 !== strpos($source, '/'))
{
$source = $sf_relative_url_root.'/'.$dir.'/'.$source;
}
$query_string = '';
if (false !== $pos = strpos($source, '?'))
{
$query_string = substr($source, $pos);
$source = substr($source, 0, $pos);
}
if (false === strpos(basename($source), '.'))
{
$source .= '.'.$ext;
}
if ($sf_relative_url_root && 0 !== strpos($source, $sf_relative_url_root))
{
$source = $sf_relative_url_root.$source;
}
if ($absolute)
{
$source = 'http'.($request->isSecure() ? 's' : '').'://'.$request->getHost().$source;
}
return $source.$query_string;
}
/**
* Prints a set of <meta> tags according to the response attributes,
* to be included in the <head> section of a HTML document.
*
* <b>Examples:</b>
* <code>
* include_metas();
* => <meta name="title" content="symfony - open-source PHP5 web framework" />
* <meta name="robots" content="index, follow" />
* <meta name="description" content="symfony - open-source PHP5 web framework" />
* <meta name="keywords" content="symfony, project, framework, php, php5, open-source, mit, symphony" />
* <meta name="language" content="en" /><link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />
* </code>
*
* <b>Note:</b> Modify the sfResponse object or the view.yml to change, add or remove metas.
*
* @return string XHTML compliant <meta> tag(s)
* @see include_http_metas
*/
function include_metas()
{
foreach (sfContext::getInstance()->getResponse()->getMetas() as $name => $content)
{
echo tag('meta', array('name' => $name, 'content' => $content))."\n";
}
}
/**
* Returns a set of <meta http-equiv> tags according to the response attributes,
* to be included in the <head> section of a HTML document.
*
* <b>Examples:</b>
* <code>
* include_http_metas();
* => <meta http-equiv="content-type" content="text/html; charset=utf-8" />
* </code>
*
* <b>Note:</b> Modify the sfResponse object or the view.yml to change, add or remove metas.
*
* @return string XHTML compliant <meta> tag(s)
* @see include_metas
*/
function include_http_metas()
{
foreach (sfContext::getInstance()->getResponse()->getHttpMetas() as $httpequiv => $value)
{
echo tag('meta', array('http-equiv' => $httpequiv, 'content' => $value))."\n";
}
}
/**
* Returns the title of the current page according to the response attributes,
* to be included in the <title> section of a HTML document.
*
* <b>Note:</b> Modify the sfResponse object or the view.yml to modify the title of a page.
*
* @return string page title
*/
function include_title()
{
$title = sfContext::getInstance()->getResponse()->getTitle();
echo content_tag('title', $title)."\n";
}
/**
* Returns <script> tags for all javascripts configured in view.yml or added to the response object.
*
* You can use this helper to decide the location of javascripts in pages.
* By default, if you don't call this helper, symfony will automatically include javascripts before </head>.
* Calling this helper disables this behavior.
*
* @return string <script> tags
*/
function get_javascripts()
{
$response = sfContext::getInstance()->getResponse();
$response->setParameter('javascripts_included', true, 'symfony/view/asset');
$already_seen = array();
$html = '';
foreach (array('first', '', 'last') as $position)
{
foreach ($response->getJavascripts($position) as $files)
{
if (!is_array($files))
{
$files = array($files);
}
foreach ($files as $file)
{
$file = javascript_path($file);
if (isset($already_seen[$file])) continue;
$already_seen[$file] = 1;
$html .= javascript_include_tag($file);
}
}
}
return $html;
}
/**
* Prints <script> tags for all javascripts configured in view.yml or added to the response object.
*
* @see get_javascripts()
*/
function include_javascripts()
{
echo get_javascripts();
}
/**
* Returns <link> tags for all stylesheets configured in view.yml or added to the response object.
*
* You can use this helper to decide the location of stylesheets in pages.
* By default, if you don't call this helper, symfony will automatically include stylesheets before </head>.
* Calling this helper disables this behavior.
*
* @return string <link> tags
*/
function get_stylesheets()
{
$response = sfContext::getInstance()->getResponse();
$response->setParameter('stylesheets_included', true, 'symfony/view/asset');
$already_seen = array();
$html = '';
foreach (array('first', '', 'last') as $position)
{
foreach ($response->getStylesheets($position) as $files => $options)
{
if (!is_array($files))
{
$files = array($files);
}
foreach ($files as $file)
{
$file = stylesheet_path($file);
if (isset($already_seen[$file])) continue;
$already_seen[$file] = 1;
$html .= stylesheet_tag($file, $options);
}
}
}
return $html;
}
/**
* Prints <link> tags for all stylesheets configured in view.yml or added to the response object.
*
* @see get_stylesheets()
*/
function include_stylesheets()
{
echo get_stylesheets();
}

View File

@ -0,0 +1,88 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* CacheHelper.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: CacheHelper.php 5085 2007-09-14 20:09:53Z fabien $
*/
/* Usage
<?php if (!cache('name')): ?>
... HTML ...
<?php cache_save() ?>
<?php endif; ?>
*/
function cache($name, $lifeTime = 86400)
{
$context = sfContext::getInstance();
if (!sfConfig::get('sf_cache'))
{
return null;
}
$request = $context->getRequest();
$cache = $context->getViewCacheManager();
if (!is_null($request->getAttribute('started', null, 'symfony/action/sfAction/cache')))
{
throw new sfCacheException('Cache already started');
}
$data = $cache->start($name, $lifeTime);
if ($data === null)
{
$request->setAttribute('started', 1, 'symfony/action/sfAction/cache');
$request->setAttribute('current_name', $name, 'symfony/action/sfAction/cache');
return 0;
}
else
{
echo $data;
return 1;
}
}
function cache_save()
{
$context = sfContext::getInstance();
if (!sfConfig::get('sf_cache'))
{
return null;
}
$request = $context->getRequest();
if (is_null($request->getAttribute('started', null, 'symfony/action/sfAction/cache')))
{
throw new sfCacheException('Cache not started');
}
$name = $request->getAttribute('current_name', '', 'symfony/action/sfAction/cache');
$data = $context->getViewCacheManager()->stop($name);
$request->setAttribute('started', null, 'symfony/action/sfAction/cache');
$request->setAttribute('current_name', null, 'symfony/action/sfAction/cache');
echo $data;
}

View File

@ -0,0 +1,955 @@
<?php
use_helper('Form');
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* DateFormHelper.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: DateFormHelper.php 3294 2007-01-16 06:53:15Z fabien $
*/
/**
* Returns a <select> tag populated with all the days of the month (1 - 31).
*
* By default, the <i>$value</i> parameter is set to today's day. To override this, simply pass an integer
* (1 - 31) to the <i>$value</i> parameter. You can also set the <i>$value</i> parameter to null which will disable
* the <i>$value</i>, however this will only be useful if you pass 'include_blank' or 'include_custom' to the <i>$options</i>
* parameter. For convenience, symfony also offers the select_date_tag helper function which combines the
* select_year_tag, select_month_tag, and select_day_tag functions into a single helper.
*
* <b>Options:</b>
* - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.
* - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.
*
* <b>Examples:</b>
* <code>
* echo submit_day_tag('day', 14);
* </code>
*
* @param string field name
* @param integer selected value (1 - 31)
* @param array additional HTML compliant <select> tag parameters
* @return string <select> tag populated with all the days of the month (1 - 31).
* @see select_date_tag, select datetime_tag
*/
function select_day_tag($name, $value = null, $options = array(), $html_options = array())
{
if ($value === null)
{
$value = date('j');
}
$options = _parse_attributes($options);
$select_options = array();
_convert_include_custom_for_select($options, $select_options);
for ($x = 1; $x < 32; $x++)
{
$select_options[$x] = str_pad($x, 2, '0', STR_PAD_LEFT);
}
return select_tag($name, options_for_select($select_options, $value), $html_options);
}
/**
* Returns a <select> tag populated with all the months of the year (1 - 12).
*
* By default, the <i>$value</i> parameter is set to today's month. To override this, simply pass an integer
* (1 - 12) to the <i>$value</i> parameter. You can also set the <i>$value</i> parameter to null which will disable
* the <i>$value</i>, however this will only be useful if you pass 'include_blank' or 'include_custom' to the <i>$options</i>
* parameter. Also, the each month's display title is set to return its respective full month name, which can be easily
* overridden by passing the 'use_short_names' or 'use_month_numbers' options to the <i>$options</i> parameter.
* For convenience, Symfony also offers the select_date_tag helper function which combines the
* select_year_tag, select_month_tag, and select_day_tag functions into a single helper.
*
* <b>Options:</b>
* - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value
* - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value
* - use_month_numbers - If set to true, will show the month's numerical value (1 - 12) instead of the months full name.
* - use_short_month - If set to true, will show the month's short name (i.e. Jan, Feb, Mar) instead of its full name.
*
* <b>Examples:</b>
* <code>
* echo submit_month_tag('month', 5, array('use_short_month' => true));
* </code>
*
* <code>
* echo submit_month_tag('month', null, array('use_month_numbers' => true, 'include_blank' => true));
* </code>
*
* @param string field name
* @param integer selected value (1 - 12)
* @param array additional HTML compliant <select> tag parameters
* @return string <select> tag populated with all the months of the year (1 - 12).
* @see select_date_tag, select datetime_tag
*/
function select_month_tag($name, $value = null, $options = array(), $html_options = array())
{
if ($value === null)
{
$value = date('n');
}
$options = _parse_attributes($options);
$select_options = array();
_convert_include_custom_for_select($options, $select_options);
if (_get_option($options, 'use_month_numbers'))
{
for ($k = 1; $k < 13; $k++)
{
$select_options[$k] = str_pad($k, 2, '0', STR_PAD_LEFT);
}
}
else
{
$culture = _get_option($options, 'culture', sfContext::getInstance()->getUser()->getCulture());
$I18n_arr = _get_I18n_date_locales($culture);
if (_get_option($options, 'use_short_month'))
{
$month_names = $I18n_arr['dateFormatInfo']->getAbbreviatedMonthNames();
}
else
{
$month_names = $I18n_arr['dateFormatInfo']->getMonthNames();
}
$add_month_numbers = _get_option($options, 'add_month_numbers');
foreach ($month_names as $k => $v)
{
$select_options[$k + 1] = $add_month_numbers ? ($k + 1).' - '.$v : $v;
}
}
return select_tag($name, options_for_select($select_options, $value), $html_options);
}
/**
* Returns a <select> tag populated with a range of years.
*
* By default, the <i>$value</i> parameter is set to today's year. To override this, simply pass a four-digit integer (YYYY)
* to the <i>$value</i> parameter. You can also set the <i>$value</i> parameter to null which will disable
* the <i>$value</i>, however this will only be useful if you pass 'include_blank' or 'include_custom' to the <i>$options</i>
* parameter. Also, the default selectable range of years is set to show five years back and five years forward from today's year.
* For instance, if today's year is 2006, the default 'year_start' option will be set to 2001 and the 'year_end' option will be set
* to 2011. These start and end dates can easily be overwritten by setting the 'year_start' and 'year_end' options in the <i>$options</i>
* parameter. For convenience, Symfony also offers the select_date_tag helper function which combines the
* select_year_tag, select_month_tag, and select_day_tag functions into a single helper.
*
* <b>Options:</b>
* - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value
* - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value
* - year_start - If set, the range of years will begin at this four-digit date (i.e. 1979)
* - year_end - If set, the range of years will end at this four-digit date (i.e. 2025)
*
* <b>Examples:</b>
* <code>
* echo submit_year_tag('year');
* </code>
*
* <code>
* $year_start = date('Y', strtotime('-10 years'));
* $year_end = date('Y', strtotime('+10 years'));
* echo submit_year_tag('year', null, array('year_start' => $year_start, 'year_end' => $year_end));
* </code>
*
* @param string field name
* @param integer selected value within the range of years.
* @param array additional HTML compliant <select> tag parameters
* @return string <select> tag populated with a range of years.
* @see select_date_tag, select datetime_tag
*/
function select_year_tag($name, $value = null, $options = array(), $html_options = array())
{
if ($value === null)
{
$value = date('Y');
}
$options = _parse_attributes($options);
$select_options = array();
_convert_include_custom_for_select($options, $select_options);
if (strlen($value) > 0 && is_numeric($value))
{
$year_origin = $value;
}
else
{
$year_origin = date('Y');
}
$year_start = _get_option($options, 'year_start', $year_origin - 5);
$year_end = _get_option($options, 'year_end', $year_origin + 5);
$ascending = ($year_start < $year_end);
$until_year = ($ascending) ? $year_end + 1 : $year_end - 1;
for ($x = $year_start; $x != $until_year; ($ascending) ? $x++ : $x--)
{
$select_options[$x] = $x;
}
return select_tag($name, options_for_select($select_options, $value), $html_options);
}
/**
* Returns three <select> tags populated with a range of months, days, and years.
*
* By default, the <i>$value</i> parameter is set to today's month, day and year. To override this, simply pass a valid date
* or a correctly formatted date array (see example) to the <i>$value</i> parameter. You can also set the <i>$value</i>
* parameter to null which will disable the <i>$value</i>, however this will only be useful if you pass 'include_blank' or
* 'include_custom' to the <i>$options</i> parameter. Also, the default selectable range of years is set to show five years
* back and five years forward from today's year. For instance, if today's year is 2006, the default 'year_start' option will
* be set to 2001 and the 'year_end' option will be set to 2011. These start and end dates can easily be overwritten by
* setting the 'year_start' and 'year_end' options in the <i>$options</i> parameter.
*
* <b>Note:</b> The <i>$name</i> parameter will automatically converted to array names. For example, a <i>$name</i> of "date" becomes:
* <samp>
* <select name="date[month]">...</select>
* <select name="date[day]">...</select>
* <select name="date[year]">...</select>
* </samp>
*
* <b>Options:</b>
* - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.
* - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.
* - discard_month - If set to true, will only return select tags for day and year.
* - discard_day - If set to true, will only return select tags for month and year.
* - discard_year - If set to true, will only return select tags for month and day.
* - use_month_numbers - If set to true, will show the month's numerical value (1 - 12) instead of the months full name.
* - use_short_month - If set to true, will show the month's short name (i.e. Jan, Feb, Mar) instead of its full name.
* - year_start - If set, the range of years will begin at this four-digit date (i.e. 1979)
* - year_end - If set, the range of years will end at this four-digit date (i.e. 2025)
* - date_seperator - Includes a string of defined text between each generated select tag
*
* <b>Examples:</b>
* <code>
* echo submit_date_tag('date');
* </code>
*
* <code>
* echo select_date_tag('date', '2006-10-30');
* </code>
*
* <code>
* $date = array('year' => '1979', 'month' => 10, 'day' => 30);
* echo select_date_tag('date', $date, array('year_start' => $date['year'] - 10, 'year_end' => $date['year'] + 10));
* </code>
*
* @param string field name (automatically becomes an array of parts: name[year], name[month], year[day])
* @param mixed accepts a valid date string or properly formatted date array
* @param array additional HTML compliant <select> tag parameters
* @return string three <select> tags populated with a months, days and years
* @see select datetime_tag, select_month_tag, select_date_tag, select_year_tag
*/
function select_date_tag($name, $value = null, $options = array(), $html_options = array())
{
$options = _parse_attributes($options);
$culture = _get_option($options, 'culture', sfContext::getInstance()->getUser()->getCulture());
// set it back for month tag
$options['culture'] = $culture;
$I18n_arr = _get_I18n_date_locales($culture);
$date_seperator = _get_option($options, 'date_seperator', $I18n_arr['date_seperator']);
$discard_month = _get_option($options, 'discard_month');
$discard_day = _get_option($options, 'discard_day');
$discard_year = _get_option($options, 'discard_year');
// discarding month automatically discards day
if ($discard_month)
{
$discard_day = true;
}
$order = _get_option($options, 'order');
$tags = array();
if (is_array($order) && count($order) == 3)
{
foreach ($order as $v)
{
$tags[] = $v[0];
}
}
else
{
$tags = $I18n_arr['date_order'];
}
if ($include_custom = _get_option($options, 'include_custom'))
{
$include_custom_month = is_array($include_custom)
? (isset($include_custom['month']) ? array('include_custom' => $include_custom['month']) : array())
: array('include_custom' => $include_custom);
$include_custom_day = is_array($include_custom)
? (isset($include_custom['day']) ? array('include_custom' => $include_custom['day']) : array())
: array('include_custom' => $include_custom);
$include_custom_year = is_array($include_custom)
? (isset($include_custom['year']) ? array('include_custom' => $include_custom['year']) : array())
: array('include_custom' => $include_custom);
}
else
{
$include_custom_month = array();
$include_custom_day = array();
$include_custom_year = array();
}
$month_name = $name.'[month]';
$m = !$discard_month ? select_month_tag($month_name, _parse_value_for_date($value, 'month', 'm'), $options + $include_custom_month, $html_options) : '';
$day_name = $name.'[day]';
$d = !$discard_day ? select_day_tag($day_name, _parse_value_for_date($value, 'day', 'd'), $options + $include_custom_day, $html_options) : '';
$year_name = $name.'[year]';
$y = !$discard_year ? select_year_tag($year_name, _parse_value_for_date($value, 'year', 'Y'), $options + $include_custom_year, $html_options) : '';
// we have $tags = array ('m','d','y')
foreach ($tags as $k => $v)
{
// $tags['m|d|y'] = $m|$d|$y
$tags[$k] = $$v;
}
return implode($date_seperator, $tags);
}
/**
* Returns a <select> tag populated with 60 seconds (0 - 59).
*
* By default, the <i>$value</i> parameter is set to the current second (right now). To override this, simply pass an integer
* (0 - 59) to the <i>$value</i> parameter. You can also set the <i>$value</i> parameter to null which will disable
* the <i>$value</i>, however this will only be useful if you pass 'include_blank' or 'include_custom' to the <i>$options</i>
* parameter. In many cases, you have no need for all 60 seconds in a minute. the 'second_step' option in the
* <i>$options</i> parameter gives you the ability to define intervals to display. So for instance you could define 15 as your
* 'minute_step' interval and the select tag would return the values 0, 15, 30, and 45. For convenience, Symfony also offers the
* select_time_tag select_datetime_tag helper functions which combine other date and time helpers to easily build date and time select boxes.
*
* <b>Options:</b>
* - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.
* - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.
* - second_step - If set, the seconds will be incremented in blocks of X, where X = 'second_step'
*
* <b>Examples:</b>
* <code>
* echo submit_second_tag('second');
* </code>
*
* <code>
* echo submit_second_tag('second', 15, array('second_step' => 15));
* </code>
*
* @param string field name
* @param integer selected value (0 - 59)
* @param array additional HTML compliant <select> tag parameters
* @return string <select> tag populated with 60 seconds (0 - 59).
* @see select_time_tag, select datetime_tag
*/
function select_second_tag($name, $value = null, $options = array(), $html_options = array())
{
if ($value === null)
{
$value = date('s');
}
$options = _parse_attributes($options);
$select_options = array();
_convert_include_custom_for_select($options, $select_options);
$second_step = _get_option($options, 'second_step', 1);
for ($x = 0; $x < 60; $x += $second_step)
{
$select_options[$x] = str_pad($x, 2, '0', STR_PAD_LEFT);
}
return select_tag($name, options_for_select($select_options, $value), $html_options);
}
/**
* Returns a <select> tag populated with 60 minutes (0 - 59).
*
* By default, the <i>$value</i> parameter is set to the current minute. To override this, simply pass an integer
* (0 - 59) to the <i>$value</i> parameter. You can also set the <i>$value</i> parameter to null which will disable
* the <i>$value</i>, however this will only be useful if you pass 'include_blank' or 'include_custom' to the <i>$options</i>
* parameter. In many cases, you have no need for all 60 minutes in an hour. the 'minute_step' option in the
* <i>$options</i> parameter gives you the ability to define intervals to display. So for instance you could define 15 as your
* 'minute_step' interval and the select tag would return the values 0, 15, 30, and 45. For convenience, Symfony also offers the
* select_time_tag select_datetime_tag helper functions which combine other date and time helpers to easily build date and time select boxes.
*
* <b>Options:</b>
* - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.
* - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.
* - minute_step - If set, the minutes will be incremented in blocks of X, where X = 'minute_step'
*
* <b>Examples:</b>
* <code>
* echo submit_minute_tag('minute');
* </code>
*
* <code>
* echo submit_minute_tag('minute', 15, array('minute_step' => 15));
* </code>
*
* @param string field name
* @param integer selected value (0 - 59)
* @param array additional HTML compliant <select> tag parameters
* @return string <select> tag populated with 60 minutes (0 - 59).
* @see select_time_tag, select datetime_tag
*/
function select_minute_tag($name, $value = null, $options = array(), $html_options = array())
{
if ($value === null)
{
$value = date('i');
}
$options = _parse_attributes($options);
$select_options = array();
_convert_include_custom_for_select($options, $select_options);
$minute_step = _get_option($options, 'minute_step', 1);
for ($x = 0; $x < 60; $x += $minute_step)
{
$select_options[$x] = str_pad($x, 2, '0', STR_PAD_LEFT);
}
return select_tag($name, options_for_select($select_options, $value), $html_options);
}
/**
* Returns a <select> tag populated with 24 hours (0 - 23), or optionally 12 hours (1 - 12).
*
* By default, the <i>$value</i> parameter is set to the current hour. To override this, simply pass an integer
* (0 - 23 or 1 - 12 if '12hour_time' = true) to the <i>$value</i> parameter. You can also set the <i>$value</i> parameter to null which will disable
* the <i>$value</i>, however this will only be useful if you pass 'include_blank' or 'include_custom' to the <i>$options</i>
* parameter. For convenience, Symfony also offers the select_time_tag select_datetime_tag helper functions
* which combine other date and time helpers to easily build date and time select boxes.
*
* <b>Options:</b>
* - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.
* - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.
* - 12hour_time - If set to true, will return integers 1 through 12 instead of the default 0 through 23 as well as an AM/PM select box.
*
* <b>Examples:</b>
* <code>
* echo submit_hour_tag('hour');
* </code>
*
* <code>
* echo submit_hour_tag('hour', 6, array('12hour_time' => true));
* </code>
*
* @param string field name
* @param integer selected value (0 - 23 or 1 - 12 if '12hour_time' = true)
* @param array additional HTML compliant <select> tag parameters
* @return string <select> tag populated with 24 hours (0 - 23), or optionally 12 hours (1 - 12).
* @see select_time_tag, select datetime_tag
*/
function select_hour_tag($name, $value = null, $options = array(), $html_options = array())
{
$options = _parse_attributes($options);
$select_options = array();
_convert_include_custom_for_select($options, $select_options);
$_12hour_time = _get_option($options, '12hour_time');
if ($value === null)
{
$value = date($_12hour_time ? 'h' : 'H');
}
$start_hour = $_12hour_time ? 1 : 0;
$end_hour = $_12hour_time ? 12 : 23;
for ($x = $start_hour; $x <= $end_hour; $x++)
{
$select_options[$x] = str_pad($x, 2, '0', STR_PAD_LEFT);
}
return select_tag($name, options_for_select($select_options, $value), $html_options);
}
/**
* Returns a <select> tag populated with AM and PM options for use with 12-Hour time.
*
* By default, the <i>$value</i> parameter is set to the correct AM/PM setting based on the current time.
* To override this, simply pass either AM or PM to the <i>$value</i> parameter. You can also set the
* <i>$value</i> parameter to null which will disable the <i>$value</i>, however this will only be
* useful if you pass 'include_blank' or 'include_custom' to the <i>$options</i> parameter. For
* convenience, Symfony also offers the select_time_tag select_datetime_tag helper functions
* which combine other date and time helpers to easily build date and time select boxes.
*
* <b>Options:</b>
* - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.
* - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.
*
* <b>Examples:</b>
* <code>
* echo submit_ampm_tag('ampm');
* </code>
*
* <code>
* echo submit_ampm_tag('ampm', 'PM', array('include_blank' => true));
* </code>
*
* @param string field name
* @param integer selected value (AM or PM)
* @param array additional HTML compliant <select> tag parameters
* @return string <select> tag populated with AM and PM options for use with 12-Hour time.
* @see select_time_tag, select datetime_tag
*/
function select_ampm_tag($name, $value = null, $options = array(), $html_options = array())
{
if ($value === null)
{
$value = date('A');
}
$options = _parse_attributes($options);
$select_options = array();
_convert_include_custom_for_select($options, $select_options);
$select_options['AM'] = 'AM';
$select_options['PM'] = 'PM';
return select_tag($name, options_for_select($select_options, $value), $html_options);
}
/**
* Returns three <select> tags populated with hours, minutes, and optionally seconds.
*
* By default, the <i>$value</i> parameter is set to the current hour and minute. To override this, simply pass a valid time
* or a correctly formatted time array (see example) to the <i>$value</i> parameter. You can also set the <i>$value</i>
* parameter to null which will disable the <i>$value</i>, however this will only be useful if you pass 'include_blank' or
* 'include_custom' to the <i>$options</i> parameter. To include seconds to the result, use set the 'include_second' option in the
* <i>$options</i> parameter to true. <b>Note:</b> The <i>$name</i> parameter will automatically converted to array names.
* For example, a <i>$name</i> of "time" becomes:
* <samp>
* <select name="time[hour]">...</select>
* <select name="time[minute]">...</select>
* <select name="time[second]">...</select>
* </samp>
*
* <b>Options:</b>
* - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.
* - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.
* - include_second - If set to true, includes the "seconds" select tag as part of the result.
* - second_step - If set, the seconds will be incremented in blocks of X, where X = 'second_step'
* - minute_step - If set, the minutes will be incremented in blocks of X, where X = 'minute_step'
* - 12hour_time - If set to true, will return integers 1 through 12 instead of the default 0 through 23 as well as an AM/PM select box.
* - time_seperator - Includes a string of defined text between each generated select tag
* - ampm_seperator - Includes a string of defined text between the minute/second select box and the AM/PM select box
*
* <b>Examples:</b>
* <code>
* echo submit_time_tag('time');
* </code>
*
* <code>
* echo select_time_tag('date', '09:31');
* </code>
*
* <code>
* $time = array('hour' => '15', 'minute' => 46, 'second' => 01);
* echo select_time_tag('time', $time, array('include_second' => true, '12hour_time' => true));
* </code>
*
* @param string field name (automatically becomes an array of parts: name[hour], name[minute], year[second])
* @param mixed accepts a valid time string or properly formatted time array
* @param array additional HTML compliant <select> tag parameters
* @return string three <select> tags populated with a hours, minutes and optionally seconds.
* @see select datetime_tag, select_hour_tag, select_minute_tag, select_second_tag
*/
function select_time_tag($name, $value = null, $options = array(), $html_options = array())
{
$options = _parse_attributes($options);
$time_seperator = _get_option($options, 'time_seperator', ':');
$ampm_seperator = _get_option($options, 'ampm_seperator', '');
$include_second = _get_option($options, 'include_second');
$_12hour_time = _get_option($options, '12hour_time');
$options['12hour_time'] = $_12hour_time; // set it back. hour tag needs it.
if ($include_custom = _get_option($options, 'include_custom'))
{
$include_custom_hour = (is_array($include_custom))
? ((isset($include_custom['hour'])) ? array('include_custom'=>$include_custom['hour']) : array())
: array('include_custom'=>$include_custom);
$include_custom_minute = (is_array($include_custom))
? ((isset($include_custom['minute'])) ? array('include_custom'=>$include_custom['minute']) : array())
: array('include_custom'=>$include_custom);
$include_custom_second = (is_array($include_custom))
? ((isset($include_custom['second'])) ? array('include_custom'=>$include_custom['second']) : array())
: array('include_custom'=>$include_custom);
$include_custom_ampm = (is_array($include_custom))
? ((isset($include_custom['ampm'])) ? array('include_custom'=>$include_custom['ampm']) : array())
: array('include_custom'=>$include_custom);
}
else
{
$include_custom_hour = array();
$include_custom_minute = array();
$include_custom_second = array();
$include_custom_ampm = array();
}
$tags = array();
$hour_name = $name.'[hour]';
$tags[] = select_hour_tag($hour_name, _parse_value_for_date($value, 'hour', $_12hour_time ? 'h' : 'H'), $options + $include_custom_hour, $html_options);
$minute_name = $name.'[minute]';
$tags[] = select_minute_tag($minute_name, _parse_value_for_date($value, 'minute', 'i'), $options + $include_custom_minute, $html_options);
if ($include_second)
{
$second_name = $name.'[second]';
$tags[] = select_second_tag($second_name, _parse_value_for_date($value, 'second', 's'), $options + $include_custom_second, $html_options);
}
$time = implode($time_seperator, $tags);
if ($_12hour_time)
{
$ampm_name = $name.'[ampm]';
$time .= $ampm_seperator.select_ampm_tag($ampm_name, _parse_value_for_date($value, 'ampm', 'A'), $options + $include_custom_ampm, $html_options);
}
return $time;
}
/**
* Returns a variable number of <select> tags populated with date and time related select boxes.
*
* The select_datetime_tag is the culmination of both the select_date_tag and the select_time_tag.
* By default, the <i>$value</i> parameter is set to the current date and time. To override this, simply pass a valid
* date, time, datetime string or correctly formatted array (see example) to the <i>$value</i> parameter.
* You can also set the <i>$value</i> parameter to null which will disable the <i>$value</i>, however this
* will only be useful if you pass 'include_blank' or 'include_custom' to the <i>$options</i> parameter.
* To include seconds to the result, use set the 'include_second' option in the <i>$options</i> parameter to true.
* <b>Note:</b> The <i>$name</i> parameter will automatically converted to array names.
* For example, a <i>$name</i> of "datetime" becomes:
* <samp>
* <select name="datetime[month]">...</select>
* <select name="datetime[day]">...</select>
* <select name="datetime[year]">...</select>
* <select name="datetime[hour]">...</select>
* <select name="datetime[minute]">...</select>
* <select name="datetime[second]">...</select>
* </samp>
*
* <b>Options:</b>
* - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.
* - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.
* - include_second - If set to true, includes the "seconds" select tag as part of the result.
* - discard_month - If set to true, will only return select tags for day and year.
* - discard_day - If set to true, will only return select tags for month and year.
* - discard_year - If set to true, will only return select tags for month and day.
* - use_month_numbers - If set to true, will show the month's numerical value (1 - 12) instead of the months full name.
* - use_short_month - If set to true, will show the month's short name (i.e. Jan, Feb, Mar) instead of its full name.
* - year_start - If set, the range of years will begin at this four-digit date (i.e. 1979)
* - year_end - If set, the range of years will end at this four-digit date (i.e. 2025)
* - second_step - If set, the seconds will be incremented in blocks of X, where X = 'second_step'
* - minute_step - If set, the minutes will be incremented in blocks of X, where X = 'minute_step'
* - 12hour_time - If set to true, will return integers 1 through 12 instead of the default 0 through 23.
* - date_seperator - Includes a string of defined text between each generated select tag
* - time_seperator - Includes a string of defined text between each generated select tag
* - ampm_seperator - Includes a string of defined text between the minute/second select box and the AM/PM select box
*
* <b>Examples:</b>
* <code>
* echo submit_datetime_tag('datetime');
* </code>
*
* <code>
* echo select_datetime_tag('datetime', '1979-10-30');
* </code>
*
* <code>
* $datetime = array('year' => '1979', 'month' => 10, 'day' => 30, 'hour' => '15', 'minute' => 46);
* echo select_datetime_tag('time', $datetime, array('use_short_month' => true, '12hour_time' => true));
* </code>
*
* @param string field name (automatically becomes an array of date and time parts)
* @param mixed accepts a valid time string or properly formatted time array
* @param array additional HTML compliant <select> tag parameters
* @return string a variable number of <select> tags populated with date and time related select boxes
* @see select date_tag, select_time_tag
*/
function select_datetime_tag($name, $value = null, $options = array(), $html_options = array())
{
$options = _parse_attributes($options);
$datetime_seperator = _get_option($options, 'datetime_seperator', '');
$date = select_date_tag($name, $value, $options, $html_options);
$time = select_time_tag($name, $value, $options, $html_options);
return $date.$datetime_seperator.$time;
}
/**
* Returns a <select> tag, populated with a range of numbers
*
* By default, the select_number_tag generates a list of numbers from 1 - 10, with an incremental value of 1. These values
* can be easily changed by passing one or several <i>$options</i>. Numbers can be either positive or negative, integers or decimals,
* and can be incremented by any number, decimal or integer. If you require the range of numbers to be listed in descending order, pass
* the 'reverse' option to easily display the list of numbers in the opposite direction.
*
* <b>Options:</b>
* - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value.
* - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.
* - multiple - If set to true, the select tag will allow multiple numbers to be selected at once.
* - start - The first number in the list. If not specified, the default value is 1.
* - end - The last number in the list. If not specified, the default value is 10.
* - increment - The number by which to increase each number in the list by until the number is greater than or equal to the 'end' option.
* If not specified, the default value is 1.
* - reverse - Reverses the order of numbers so they are display in descending order
*
* <b>Examples:</b>
* <code>
* echo select_number_tag('rating', '', array('reverse' => true));
* </code>
*
* <code>
* echo echo select_number_tag('tax_rate', '0.07', array('start' => '0.05', 'end' => '0.09', 'increment' => '0.01'));
* </code>
*
* <code>
* echo select_number_tag('limit', 5, array('start' => 5, 'end' => 120, 'increment' => 15));
* </code>
*
* @param string field name
* @param string the selected option
* @param array <i>$options</i> to manipulate the output of the tag.
* @param array additional HTML compliant <select> tag parameters
* @return string <select> tag populated with a range of numbers.
* @see options_for_select, content_tag
*/
function select_number_tag($name, $value, $options = array(), $html_options = array())
{
$increment = _get_option($options, 'increment', 1);
$range = array();
$max = _get_option($options, 'end', 10) + $increment;
for ($x = _get_option($options, 'start', 1); $x < $max; $x += $increment)
{
$range[(string) $x] = $x;
}
if (_get_option($options, 'reverse'))
{
$range = array_reverse($range, true);
}
return select_tag($name, options_for_select($range, $value, $options), $html_options);
}
/**
* Returns a <select> tag populated with all the timezones in the world.
*
* The select_timezone_tag builds off the traditional select_tag function, and is conveniently populated with
* all the timezones in the world (sorted alphabetically). Each option in the list has a unique timezone identifier
* for its value and the timezone's locale as its display title. The timezone data is retrieved via the sfCultureInfo
* class, which stores a wide variety of i18n and i10n settings for various countries and cultures throughout the world.
* Here's an example of an <option> tag generated by the select_timezone_tag:
*
* <b>Options:</b>
* - display -
* identifer - Display the PHP timezone identifier (e.g. America/Denver)
* timezone - Display the full timezone name (e.g. Mountain Standard Time)
* timezone_abbr - Display the timezone abbreviation (e.g. MST)
* timzone_dst - Display the full timezone name with daylight savings time (e.g. Mountain Daylight Time)
* timezone_dst_abbr - Display the timezone abbreviation with daylight savings time (e.g. MDT)
* city - Display the city/region that relates to the timezone (e.g. Denver)
*
* <samp>
* <option value="America/Denver">America/Denver</option>
* </samp>
*
* <b>Examples:</b>
* <code>
* echo select_timezone_tag('timezone', 'America/Denver');
* </code>
*
* @param string field name
* @param string selected field value (timezone identifier)
* @param array additional HTML compliant <select> tag parameters
* @return string <select> tag populated with all the timezones in the world.
* @see select_tag, options_for_select, sfCultureInfo
*/
function select_timezone_tag($name, $selected = null, $options = array())
{
if (!isset($options['display'])) $options['display'] = 'identifier';
$c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
$timezone_groups = $c->getTimeZones();
$display_key = 0;
switch ($options['display'])
{
case "identifier":
$display_key = 0;
break;
case "timezone":
$display_key = 1;
break;
case "timezone_abbr":
$display_key = 2;
break;
case "timezone_dst":
$display_key = 3;
break;
case "timezone_dst_abbr":
$display_key = 3;
break;
case "city":
$display_key = 4;
break;
default:
$display_key = 0;
break;
}
unset($options['display']);
$timezones = array();
foreach ($timezone_groups as $tz_group_key => $tz_group)
{
$array_key = null;
foreach ($tz_group as $tz_key => $tz)
{
if ($tz_key == 0) $array_key = $tz;
if ($tz_key == $display_key AND !empty($tz)) $timezones[$array_key] = $tz;
}
}
// Remove duplicate values
$timezones = array_unique($timezones);
if ($timezone_option = _get_option($options, 'timezones'))
{
$diff = array_diff_key($timezones, array_flip((array) $timezone_option));
foreach ($diff as $key => $v)
{
unset($timezones[$key]);
}
}
asort($timezones);
$option_tags = options_for_select($timezones, $selected);
return select_tag($name, $option_tags, $options);
}
/**
* Converts date values (<i>$value</i>) into its correct date format (<i>$format_char</i>)
*
* This function is primarily used in select_date_tag, select_time_tag and select_datetime_tag.
*
* <b>Note:</b> If <i>$value</i> is empty, it will be populated with the current date and time.
*
* @param string date or date part
* @param string custom key for array values
* @return string properly formatted date part value.
* @see select_date_tag, select_time_tag, select_datetime_tag
*/
function _parse_value_for_date($value, $key, $format_char)
{
if (is_array($value))
{
return (isset($value[$key])) ? $value[$key] : '';
}
else if (is_numeric($value))
{
return date($format_char, $value);
}
else if ($value == '' || ($key == 'ampm' && ($value == 'AM' || $value == 'PM')))
{
return $value;
}
else if (empty($value))
{
$value = date('Y-m-d H:i:s');
}
// english text presentation
return date($format_char, strtotime($value));
}
/**
* Retrieves the proper date format based on the specified <i>$culture</i> setting
*
* <b>Note:</b> If no <i>$culture</i> is defined, the user's culture setting will be used in its place.
*
* @param string two or three character culture setting variable
* @return string formatted date/time format based on the specified date/time setting
* @see sfUser
*/
function _get_I18n_date_locales($culture = null)
{
if (!$culture)
{
$culture = sfContext::getInstance()->getUser()->getCulture();
}
$retval = array('culture'=>$culture);
$dateFormatInfo = sfDateTimeFormatInfo::getInstance($culture);
$date_format = strtolower($dateFormatInfo->getShortDatePattern());
$retval['dateFormatInfo'] = $dateFormatInfo;
$match_pattern = "/([dmy]+)(.*?)([dmy]+)(.*?)([dmy]+)/";
if (!preg_match($match_pattern, $date_format, $match_arr))
{
// if matching fails use en shortdate
preg_match($match_pattern, 'm/d/yy', $match_arr);
}
$retval['date_seperator'] = $match_arr[2];
// unset all but [dmy]+
unset($match_arr[0], $match_arr[2], $match_arr[4]);
$retval['date_order'] = array();
foreach ($match_arr as $v)
{
// 'm/d/yy' => $retval[date_order] = array ('m', 'd', 'y');
$retval['date_order'][] = $v[0];
}
return $retval;
}

170
lib/symfony/helper/DateHelper.php Executable file
View File

@ -0,0 +1,170 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* DateHelper.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: DateHelper.php 3815 2007-04-18 16:44:39Z fabien $
*/
function format_daterange($start_date, $end_date, $format = 'd', $full_text, $start_text, $end_text, $culture = null, $charset = null)
{
if ($start_date != '' && $end_date != '')
{
return sprintf($full_text, format_date($start_date, $format, $culture, $charset), format_date($end_date, $format, $culture, $charset));
}
else if ($start_date != '')
{
return sprintf($start_text, format_date($start_date, $format, $culture, $charset));
}
else if ($end_date != '')
{
return sprintf($end_text, format_date($end_date, $format, $culture, $charset));
}
}
function format_date($date, $format = 'd', $culture = null, $charset = null)
{
static $dateFormats = array();
if (is_null($date))
{
return null;
}
if (!$culture)
{
$culture = sfContext::getInstance()->getUser()->getCulture();
}
if (!$charset)
{
$charset = sfConfig::get('sf_charset');
}
if (!isset($dateFormats[$culture]))
{
$dateFormats[$culture] = new sfDateFormat($culture);
}
return $dateFormats[$culture]->format($date, $format, null, $charset);
}
function format_datetime($date, $format = 'F', $culture = null, $charset = null)
{
return format_date($date, $format, $culture, $charset);
}
function distance_of_time_in_words($from_time, $to_time = null, $include_seconds = false)
{
$to_time = $to_time? $to_time: time();
$distance_in_minutes = floor(abs($to_time - $from_time) / 60);
$distance_in_seconds = floor(abs($to_time - $from_time));
$string = '';
$parameters = array();
if ($distance_in_minutes <= 1)
{
if (!$include_seconds)
{
$string = $distance_in_minutes == 0 ? 'less than a minute' : '1 minute';
}
else
{
if ($distance_in_seconds <= 5)
{
$string = 'less than 5 seconds';
}
else if ($distance_in_seconds >= 6 && $distance_in_seconds <= 10)
{
$string = 'less than 10 seconds';
}
else if ($distance_in_seconds >= 11 && $distance_in_seconds <= 20)
{
$string = 'less than 20 seconds';
}
else if ($distance_in_seconds >= 21 && $distance_in_seconds <= 40)
{
$string = 'half a minute';
}
else if ($distance_in_seconds >= 41 && $distance_in_seconds <= 59)
{
$string = 'less than a minute';
}
else
{
$string = '1 minute';
}
}
}
else if ($distance_in_minutes >= 2 && $distance_in_minutes <= 44)
{
$string = '%minutes% minutes';
$parameters['%minutes%'] = $distance_in_minutes;
}
else if ($distance_in_minutes >= 45 && $distance_in_minutes <= 89)
{
$string = 'about 1 hour';
}
else if ($distance_in_minutes >= 90 && $distance_in_minutes <= 1439)
{
$string = 'about %hours% hours';
$parameters['%hours%'] = round($distance_in_minutes / 60);
}
else if ($distance_in_minutes >= 1440 && $distance_in_minutes <= 2879)
{
$string = '1 day';
}
else if ($distance_in_minutes >= 2880 && $distance_in_minutes <= 43199)
{
$string = '%days% days';
$parameters['%days%'] = round($distance_in_minutes / 1440);
}
else if ($distance_in_minutes >= 43200 && $distance_in_minutes <= 86399)
{
$string = 'about 1 month';
}
else if ($distance_in_minutes >= 86400 && $distance_in_minutes <= 525959)
{
$string = '%months% months';
$parameters['%months%'] = round($distance_in_minutes / 43200);
}
else if ($distance_in_minutes >= 525960 && $distance_in_minutes <= 1051919)
{
$string = 'about 1 year';
}
else
{
$string = 'over %years% years';
$parameters['%years%'] = round($distance_in_minutes / 525960);
}
if (sfConfig::get('sf_i18n'))
{
use_helper('I18N');
return __($string, $parameters);
}
else
{
return strtr($string, $parameters);
}
}
// Like distance_of_time_in_words, but where to_time is fixed to time()
function time_ago_in_words($from_time, $include_seconds = false)
{
return distance_of_time_in_words($from_time, time(), $include_seconds);
}

View File

@ -0,0 +1,17 @@
<?php
function debug_message($message)
{
if (sfConfig::get('sf_web_debug'))
{
sfWebDebug::getInstance()->logShortMessage($message);
}
}
function log_message($message, $priority = 'info')
{
if (sfConfig::get('sf_logging_enabled'))
{
sfContext::getInstance()->getLogger()->log($message, constant('SF_LOG_'.strtoupper($priority)));
}
}

View File

@ -0,0 +1,94 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* The functions are primarily used by the output escaping component.
*
* Each function specifies a way for applying a transformation to a string
* passed to it. The purpose is for the string to be "escaped" so it is
* suitable for the format it is being displayed in.
*
* For example, the string: "It's required that you enter a username & password.\n"
* If this were to be displayed as HTML it would be sensible to turn the
* ampersand into '&amp;' and the apostrophe into '&aps;'. However if it were
* going to be used as a string in JavaScript to be displayed in an alert box
* it would be right to leave the string as-is, but c-escape the apostrophe and
* the new line.
*
* For each function there is a define to avoid problems with strings being
* incorrectly specified.
*
* @package symfony
* @subpackage helper
* @author Mike Squire <mike@somosis.co.uk>
* @version SVN: $Id: EscapingHelper.php 2669 2006-11-13 17:06:36Z fabien $
*/
/**
* Runs the PHP function htmlentities on the value passed.
*
* @param string $value the value to escape
* @return string the escaped value
*/
function esc_entities($value)
{
// Numbers and boolean values get turned into strings which can cause problems
// with type comparisons (e.g. === or is_int() etc).
return is_string($value) ? htmlentities($value, ENT_QUOTES, sfConfig::get('sf_charset')) : $value;
}
define('ESC_ENTITIES', 'esc_entities');
/**
* An identity function that merely returns that which it is given, the purpose
* being to be able to specify that the value is not to be escaped in any way.
*
* @param string $value the value to escape
* @return string the escaped value
*/
function esc_raw($value)
{
return $value;
}
define('ESC_RAW', 'esc_raw');
/**
* A function that c-escapes a string after applying {@link esc_entities()}. The
* assumption is that the value will be used to generate dynamic HTML in some
* way and the safest way to prevent mishap is to assume the value should have
* HTML entities set properly.
*
* The {@link esc_js_no_entities()} method should be used to escape a string
* that is ultimately not going to end up as text in an HTML document.
*
* @param string $value the value to escape
* @return string the escaped value
*/
function esc_js($value)
{
return esc_js_no_entities(esc_entities($value));
}
define('ESC_JS', 'esc_js');
/**
* A function the c-escapes a string, making it suitable to be placed in a
* JavaScript string.
*
* @param string $value the value to escape
* @return string the escaped value
*/
function esc_js_no_entities($value)
{
return addcslashes($value, "\0..\37\\'\"\177..\377\/");
}
define('ESC_JS_NO_ENTITIES', 'esc_js_no_entities');

930
lib/symfony/helper/FormHelper.php Executable file
View File

@ -0,0 +1,930 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
* (c) 2004 David Heinemeier Hansson
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* FormHelper.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author David Heinemeier Hansson
* @version SVN: $Id: FormHelper.php 4387 2007-06-25 16:49:03Z fabien $
*/
/**
* Returns a formatted set of <option> tags based on optional <i>$options</i> array variable.
*
* The options_for_select helper is usually called in conjunction with the select_tag helper, as it is relatively
* useless on its own. By passing an array of <i>$options</i>, the helper will automatically generate <option> tags
* using the array key as the value and the array value as the display title. Additionally the options_for_select tag is
* smart enough to detect nested arrays as <optgroup> tags. If the helper detects that the array value is an array itself,
* it creates an <optgroup> tag with the name of the group being the key and the contents of the <optgroup> being the array.
*
* <b>Options:</b>
* - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value
* - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value
*
* <b>Examples:</b>
* <code>
* echo select_tag('person', options_for_select(array(1 => 'Larry', 2 => 'Moe', 3 => 'Curly')));
* </code>
*
* <code>
* $card_list = array('VISA' => 'Visa', 'MAST' => 'MasterCard', 'AMEX' => 'American Express', 'DISC' => 'Discover');
* echo select_tag('cc_type', options_for_select($card_list, 'AMEX', array('include_custom' => '-- Select Credit Card Type --')));
* </code>
*
* <code>
* $optgroup_array = array(1 => 'Joe', 2 => 'Sue', 'Group A' => array(3 => 'Mary', 4 => 'Tom'), 'Group B' => array(5 => 'Bill', 6 =>'Andy'));
* echo select_tag('employee', options_for_select($optgroup_array, null, array('include_blank' => true)), array('class' => 'mystyle'));
* </code>
*
* @param array dataset to create <option> tags and <optgroup> tags from
* @param string selected option value
* @param array additional HTML compliant <option> tag parameters
* @return string populated with <option> tags derived from the <i>$options</i> array variable
* @see select_tag
*/
function options_for_select($options = array(), $selected = '', $html_options = array())
{
$html_options = _parse_attributes($html_options);
if (is_array($selected))
{
$selected = array_map('strval', array_values($selected));
}
$html = '';
if ($value = _get_option($html_options, 'include_custom'))
{
$html .= content_tag('option', $value, array('value' => ''))."\n";
}
else if (_get_option($html_options, 'include_blank'))
{
$html .= content_tag('option', '', array('value' => ''))."\n";
}
foreach ($options as $key => $value)
{
if (is_array($value))
{
$html .= content_tag('optgroup', options_for_select($value, $selected, $html_options), array('label' => $key))."\n";
}
else
{
$option_options = array('value' => $key);
if (
(is_array($selected) && in_array(strval($key), $selected, true))
||
(strval($key) == strval($selected))
)
{
$option_options['selected'] = 'selected';
}
$html .= content_tag('option', $value, $option_options)."\n";
}
}
return $html;
}
/**
* Returns an HTML <form> tag that points to a valid action, route or URL as defined by <i>$url_for_options</i>.
*
* By default, the form tag is generated in POST format, but can easily be configured along with any additional
* HTML parameters via the optional <i>$options</i> parameter. If you are using file uploads, be sure to set the
* <i>multipart</i> option to true.
*
* <b>Options:</b>
* - multipart - When set to true, enctype is set to "multipart/form-data".
*
* <b>Examples:</b>
* <code><?php echo form_tag('@myroute'); ?></code>
* <code><?php echo form_tag('/module/action', array('name' => 'myformname', 'multipart' => true)); ?></code>
*
* @param string valid action, route or URL
* @param array optional HTML parameters for the <form> tag
* @return string opening HTML <form> tag with options
*/
function form_tag($url_for_options = '', $options = array())
{
$options = _parse_attributes($options);
$html_options = $options;
if (!isset($html_options['method']))
{
$html_options['method'] = 'post';
}
if (_get_option($html_options, 'multipart'))
{
$html_options['enctype'] = 'multipart/form-data';
}
$html_options['action'] = url_for($url_for_options);
return tag('form', $html_options, true);
}
/**
* Returns a <select> tag, optionally comprised of <option> tags.
*
* The select tag does not generate <option> tags by default.
* To do so, you must populate the <i>$option_tags</i> parameter with a string of valid HTML compliant <option> tags.
* Fortunately, Symfony provides a handy helper function to convert an array of data into option tags (see options_for_select).
* If you need to create a "multiple" select tag (ability to select multiple options), set the <i>multiple</i> option to true.
* Doing so will automatically convert the name field to an array type variable (i.e. name="name" becomes name="name[]").
*
* <b>Options:</b>
* - multiple - If set to true, the select tag will allow multiple options to be selected at once.
*
* <b>Examples:</b>
* <code>
* $person_list = array(1 => 'Larry', 2 => 'Moe', 3 => 'Curly');
* echo select_tag('person', options_for_select($person_list, $sf_params->get('person')), array('class' => 'full'));
* </code>
*
* <code>
* echo select_tag('department', options_for_select($department_list), array('multiple' => true));
* </code>
*
* <code>
* echo select_tag('url', options_for_select($url_list), array('onChange' => 'Javascript:this.form.submit();'));
* </code>
*
* @param string field name
* @param mixed contains a string of valid <option></option> tags, or an array of options that will be passed to options_for_select
* @param array additional HTML compliant <select> tag parameters
* @return string <select> tag optionally comprised of <option> tags.
* @see options_for_select, content_tag
*/
function select_tag($name, $option_tags = null, $options = array())
{
$options = _convert_options($options);
$id = $name;
if (isset($options['multiple']) && $options['multiple'] && substr($name, -2) !== '[]')
{
$name .= '[]';
}
if (is_array($option_tags))
{
$option_tags = options_for_select($option_tags);
}
return content_tag('select', $option_tags, array_merge(array('name' => $name, 'id' => get_id_from_name($id)), $options));
}
/**
* Returns a <select> tag populated with all the countries in the world.
*
* The select_country_tag builds off the traditional select_tag function, and is conveniently populated with
* all the countries in the world (sorted alphabetically). Each option in the list has a two-character country
* code for its value and the country's name as its display title. The country data is retrieved via the sfCultureInfo
* class, which stores a wide variety of i18n and i10n settings for various countries and cultures throughout the world.
* Here's an example of an <option> tag generated by the select_country_tag:
*
* <samp>
* <option value="US">United States</option>
* </samp>
*
* <b>Examples:</b>
* <code>
* echo select_country_tag('country', 'FR');
* </code>
*
* @param string field name
* @param string selected field value (two-character country code)
* @param array additional HTML compliant <select> tag parameters
* @return string <select> tag populated with all the countries in the world.
* @see select_tag, options_for_select, sfCultureInfo
*/
function select_country_tag($name, $selected = null, $options = array())
{
$c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
$countries = $c->getCountries();
if ($country_option = _get_option($options, 'countries'))
{
foreach ($countries as $key => $value)
{
if (!in_array($key, $country_option))
{
unset($countries[$key]);
}
}
}
asort($countries);
$option_tags = options_for_select($countries, $selected, $options);
return select_tag($name, $option_tags, $options);
}
/**
* Returns a <select> tag populated with all the languages in the world (or almost).
*
* The select_language_tag builds off the traditional select_tag function, and is conveniently populated with
* all the languages in the world (sorted alphabetically). Each option in the list has a two or three character
* language/culture code for its value and the language's name as its display title. The country data is
* retrieved via the sfCultureInfo class, which stores a wide variety of i18n and i10n settings for various
* countries and cultures throughout the world. Here's an example of an <option> tag generated by the select_country_tag:
*
* <samp>
* <option value="en">English</option>
* </samp>
*
* <b>Examples:</b>
* <code>
* echo select_language_tag('language', 'de');
* </code>
*
* @param string field name
* @param string selected field value (two or threecharacter language/culture code)
* @param array additional HTML compliant <select> tag parameters
* @return string <select> tag populated with all the languages in the world.
* @see select_tag, options_for_select, sfCultureInfo
*/
function select_language_tag($name, $selected = null, $options = array())
{
$c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
$languages = $c->getLanguages();
if ($language_option = _get_option($options, 'languages'))
{
foreach ($languages as $key => $value)
{
if (!in_array($key, $language_option))
{
unset($languages[$key]);
}
}
}
asort($languages);
$option_tags = options_for_select($languages, $selected, $options);
return select_tag($name, $option_tags, $options);
}
/**
* Returns an XHTML compliant <input> tag with type="text".
*
* The input_tag helper generates your basic XHTML <input> tag and can utilize any standard <input> tag parameters
* passed in the optional <i>$options</i> parameter.
*
* <b>Examples:</b>
* <code>
* echo input_tag('name');
* </code>
*
* <code>
* echo input_tag('amount', $sf_params->get('amount'), array('size' => 8, 'maxlength' => 8));
* </code>
*
* @param string field name
* @param string selected field value
* @param array additional HTML compliant <input> tag parameters
* @return string XHTML compliant <input> tag with type="text"
*/
function input_tag($name, $value = null, $options = array())
{
return tag('input', array_merge(array('type' => 'text', 'name' => $name, 'id' => get_id_from_name($name, $value), 'value' => $value), _convert_options($options)));
}
/**
* Returns an XHTML compliant <input> tag with type="hidden".
*
* Similar to the input_tag helper, the input_hidden_tag helper generates an XHTML <input> tag and can utilize
* any standard <input> tag parameters passed in the optional <i>$options</i> parameter. The only difference is
* that it creates the tag with type="hidden", meaning that is not visible on the page.
*
* <b>Examples:</b>
* <code>
* echo input_hidden_tag('id', $id);
* </code>
*
* @param string field name
* @param string populated field value
* @param array additional HTML compliant <input> tag parameters
* @return string XHTML compliant <input> tag with type="hidden"
*/
function input_hidden_tag($name, $value = null, $options = array())
{
$options = _parse_attributes($options);
$options['type'] = 'hidden';
return input_tag($name, $value, $options);
}
/**
* Returns an XHTML compliant <input> tag with type="file".
*
* Similar to the input_tag helper, the input_hidden_tag helper generates your basic XHTML <input> tag and can utilize
* any standard <input> tag parameters passed in the optional <i>$options</i> parameter. The only difference is that it
* creates the tag with type="file", meaning that next to the field will be a "browse" (or similar) button.
* This gives the user the ability to choose a file from there computer to upload to the web server. Remember, if you
* plan to upload files to your website, be sure to set the <i>multipart</i> option form_tag helper function to true
* or your files will not be properly uploaded to the web server.
*
* <b>Examples:</b>
* <code>
* echo input_file_tag('filename', array('size' => 30));
* </code>
*
* @param string field name
* @param array additional HTML compliant <input> tag parameters
* @return string XHTML compliant <input> tag with type="file"
* @see input_tag, form_tag
*/
function input_file_tag($name, $options = array())
{
$options = _parse_attributes($options);
$options['type'] = 'file';
return input_tag($name, null, $options);
}
/**
* Returns an XHTML compliant <input> tag with type="password".
*
* Similar to the input_tag helper, the input_hidden_tag helper generates your basic XHTML <input> tag and can utilize
* any standard <input> tag parameters passed in the optional <i>$options</i> parameter. The only difference is that it
* creates the tag with type="password", meaning that the text entered into this field will not be visible to the end user.
* In most cases it is replaced by * * * * * * * *. Even though this text is not readable, it is recommended that you do not
* populate the optional <i>$value</i> option with a plain-text password or any other sensitive information, as this is a
* potential security risk.
*
* <b>Examples:</b>
* <code>
* echo input_password_tag('password');
* echo input_password_tag('password_confirm');
* </code>
*
* @param string field name
* @param string populated field value
* @param array additional HTML compliant <input> tag parameters
* @return string XHTML compliant <input> tag with type="password"
* @see input_tag
*/
function input_password_tag($name = 'password', $value = null, $options = array())
{
$options = _parse_attributes($options);
$options['type'] = 'password';
return input_tag($name, $value, $options);
}
/**
* Returns a <textarea> tag, optionally wrapped with an inline rich-text JavaScript editor.
*
* The texarea_tag helper generates a standard HTML <textarea> tag and can be manipulated with
* any number of standard HTML parameters via the <i>$options</i> array variable. However, the
* textarea tag also has the unique capability of being transformed into a WYSIWYG rich-text editor
* such as TinyMCE (http://tinymce.moxiecode.com) very easily with the use of some specific options:
*
* <b>Options:</b>
* - rich: A rich text editor class (for example sfRichTextEditorTinyMCE for TinyMCE).
*
* <b>Examples:</b>
* <code>
* echo textarea_tag('notes');
* </code>
*
* <code>
* echo textarea_tag('description', 'This is a description', array('rows' => 10, 'cols' => 50));
* </code>
*
* @param string field name
* @param string populated field value
* @param array additional HTML compliant <textarea> tag parameters
*
* @return string <textarea> tag optionally wrapped with a rich-text WYSIWYG editor
*/
function textarea_tag($name, $content = null, $options = array())
{
$options = _parse_attributes($options);
if ($size = _get_option($options, 'size'))
{
list($options['cols'], $options['rows']) = split('x', $size, 2);
}
// rich control?
if ($rich = _get_option($options, 'rich', false))
{
if (true === $rich)
{
$rich = sfConfig::get('sf_rich_text_editor_class', 'TinyMCE');
}
// switch for backward compatibility
switch ($rich)
{
case 'tinymce':
$rich = 'TinyMCE';
break;
case 'fck':
$rich = 'FCK';
break;
}
$editorClass = 'sfRichTextEditor'.$rich;
if (!class_exists($editorClass))
{
throw new sfConfigurationException(sprintf('The rich text editor "%s" does not exist.', $editorClass));
}
$sfEditor = new $editorClass();
if (!in_array('sfRichTextEditor', class_parents($sfEditor)))
{
throw new sfConfigurationException(sprintf('The editor "%s" must extend sfRichTextEditor.', $editorClass));
}
$sfEditor->initialize($name, $content, $options);
return $sfEditor->toHTML();
}
return content_tag('textarea', escape_once((is_object($content)) ? $content->__toString() : $content), array_merge(array('name' => $name, 'id' => get_id_from_name(_get_option($options, 'id', $name), null)), _convert_options($options)));
}
/**
* Returns an XHTML compliant <input> tag with type="checkbox".
*
* When creating multiple checkboxes with the same name, be sure to use an array for the
* <i>$name</i> parameter (i.e. 'name[]'). The checkbox_tag is smart enough to create unique ID's
* based on the <i>$value</i> parameter like so:
*
* <samp>
* <input type="checkbox" name="status[]" id="status_3" value="3" />
* <input type="checkbox" name="status[]" id="status_4" value="4" />
* </samp>
*
* <b>Examples:</b>
* <code>
* echo checkbox_tag('newsletter', 1, $sf_params->get('newsletter'));
* </code>
*
* <code>
* echo checkbox_tag('option_a', 'yes', true, array('class' => 'style_a'));
* </code>
*
* <code>
* // one request variable with an array of checkbox values
* echo checkbox_tag('choice[]', 1);
* echo checkbox_tag('choice[]', 2);
* echo checkbox_tag('choice[]', 3);
* echo checkbox_tag('choice[]', 4);
* </code>
*
* <code>
* // assuming you have Prototype.js enabled, you could do this
* echo checkbox_tag('show_tos', 1, false, array('onclick' => "Element.toggle('tos'); return false;"));
* </code>
*
* @param string field name
* @param string checkbox value (if checked)
* @param bool is the checkbox checked? (1 or 0)
* @param array additional HTML compliant <input> tag parameters
* @return string XHTML compliant <input> tag with type="checkbox"
*/
function checkbox_tag($name, $value = '1', $checked = false, $options = array())
{
$html_options = array_merge(array('type' => 'checkbox', 'name' => $name, 'id' => get_id_from_name($name, $value), 'value' => $value), _convert_options($options));
if ($checked)
{
$html_options['checked'] = 'checked';
}
return tag('input', $html_options);
}
/**
* Returns an XHTML compliant <input> tag with type="radio".
*
* <b>Examples:</b>
* <code>
* echo ' Yes '.radiobutton_tag('newsletter', 1);
* echo ' No '.radiobutton_tag('newsletter', 0);
* </code>
*
* @param string field name
* @param string radio button value (if selected)
* @param bool is the radio button selected? (1 or 0)
* @param array additional HTML compliant <input> tag parameters
* @return string XHTML compliant <input> tag with type="radio"
*/
function radiobutton_tag($name, $value, $checked = false, $options = array())
{
$html_options = array_merge(array('type' => 'radio', 'name' => $name, 'id' => get_id_from_name($name, $value), 'value' => $value), _convert_options($options));
if ($checked)
{
$html_options['checked'] = 'checked';
}
return tag('input', $html_options);
}
/**
* Returns two XHTML compliant <input> tags to be used as a free-text date fields for a date range.
*
* Built on the input_date_tag, the input_date_range_tag combines two input tags that allow the user
* to specify a from and to date.
* You can easily implement a JavaScript calendar by enabling the 'rich' option in the
* <i>$options</i> parameter. This includes a button next to the field that when clicked,
* will open an inline JavaScript calendar. When a date is selected, it will automatically
* populate the <input> tag with the proper date, formatted to the user's culture setting.
*
* <b>Note:</b> The <i>$name</i> parameter will automatically converted to array names.
* For example, a <i>$name</i> of "date" becomes date[from] and date[to]
*
* <b>Options:</b>
* - rich - If set to true, includes an inline JavaScript calendar can auto-populate the date field with the chosen date
* - before - string to be displayed before the input_date_range_tag
* - middle - string to be displayed between the from and to tags
* - after - string to be displayed after the input_date_range_tag
*
* <b>Examples:</b>
* <code>
* $date = array('from' => '2006-05-15', 'to' => '2006-06-15');
* echo input_date_range_tag('date', $date, array('rich' => true));
* </code>
*
* <code>
* echo input_date_range_tag('date', null, array('middle' => ' through ', 'rich' => true));
* </code>
*
* @param string field name
* @param array dates: $value['from'] and $value['to']
* @param array additional HTML compliant <input> tag parameters
* @return string XHTML compliant <input> tag with optional JS calendar integration
* @see input_date_tag
*/
function input_date_range_tag($name, $value, $options = array())
{
$options = _parse_attributes($options);
$before = _get_option($options, 'before', '');
$middle = _get_option($options, 'middle', '');
$after = _get_option($options, 'after', '');
return $before.
input_date_tag($name.'[from]', $value['from'], $options).
$middle.
input_date_tag($name.'[to]', $value['to'], $options).
$after;
}
/**
* Returns an XHTML compliant <input> tag to be used as a free-text date field.
*
* You can easily implement a JavaScript calendar by enabling the 'rich' option in the
* <i>$options</i> parameter. This includes a button next to the field that when clicked,
* will open an inline JavaScript calendar. When a date is selected, it will automatically
* populate the <input> tag with the proper date, formatted to the user's culture setting.
* Symfony also conveniently offers the input_date_range_tag, that allows you to specify a to
* and from date.
*
* <b>Options:</b>
* - rich - If set to true, includes an inline JavaScript calendar can auto-populate the date field with the chosen date
*
* <b>Examples:</b>
* <code>
* echo input_date_tag('date', null, array('rich' => true));
* </code>
*
* @param string field name
* @param string date
* @param array additional HTML compliant <input> tag parameters
* @return string XHTML compliant <input> tag with optional JS calendar integration
* @see input_date_range_tag
*/
function input_date_tag($name, $value = null, $options = array())
{
$options = _parse_attributes($options);
$context = sfContext::getInstance();
$culture = _get_option($options, 'culture', $context->getUser()->getCulture());
$withTime = _get_option($options, 'withtime', false);
// rich control?
if (!_get_option($options, 'rich', false))
{
use_helper('DateForm');
// set culture for month tag
$options['culture'] = $culture;
if ($withTime)
{
return select_datetime_tag($name, $value, $options, isset($options['html']) ? $options['html'] : array());
}
else
{
return select_date_tag($name, $value, $options, isset($options['html']) ? $options['html'] : array());
}
}
$pattern = _get_option($options, 'format', $withTime ? 'g' : 'd');
$dateFormat = new sfDateFormat($culture);
$pattern = $dateFormat->getInputPattern($pattern);
// parse date
if ($value === null || $value === '')
{
$value = '';
}
else
{
$value = $dateFormat->format($value, $pattern);
}
// register our javascripts and stylesheets
$langFile = sfConfig::get('sf_calendar_web_dir').'/lang/calendar-'.strtolower(substr($culture, 0, 2));
$jss = array(
sfConfig::get('sf_calendar_web_dir').'/calendar',
is_readable(sfConfig::get('sf_symfony_data_dir').'/web/'.$langFile.'.js') || is_readable(sfConfig::get('sf_web_dir').'/'.$langFile.'.js') ? $langFile : sfConfig::get('sf_calendar_web_dir').'/lang/calendar-en',
sfConfig::get('sf_calendar_web_dir').'/calendar-setup',
);
foreach ($jss as $js)
{
$context->getResponse()->addJavascript($js);
}
// css
if ($calendar_style = _get_option($options, 'css', 'skins/aqua/theme'))
{
$context->getResponse()->addStylesheet(sfConfig::get('sf_calendar_web_dir').'/'.$calendar_style);
}
// date format
$date_format = $dateFormat->getPattern($pattern);
// calendar date format
$calendar_date_format = $date_format;
$calendar_date_format = strtr($date_format, array('yyyy' => 'Y', 'yy'=>'y', 'MM' => 'm', 'M'=>'m', 'dd'=>'d', 'd'=>'e', 'HH'=>'H', 'H'=>'k', 'hh'=>'I', 'h'=>'l', 'mm'=>'M', 'ss'=>'S', 'a'=>'p'));
$calendar_date_format = preg_replace('/([mdyhklspe])+/i', '%\\1', $calendar_date_format);
$id_inputField = isset($options['id']) ? $options['id'] : get_id_from_name($name);
$id_calendarButton = 'trigger_'.$id_inputField;
$js = '
document.getElementById("'.$id_calendarButton.'").disabled = false;
Calendar.setup({
inputField : "'.$id_inputField.'",
ifFormat : "'.$calendar_date_format.'",
daFormat : "'.$calendar_date_format.'",
button : "'.$id_calendarButton.'"';
if ($withTime)
{
$js .= ",\n showsTime : true";
}
// calendar options
if ($calendar_options = _get_option($options, 'calendar_options'))
{
$js .= ",\n".$calendar_options;
}
$js .= '
});
';
// calendar button
$calendar_button = '...';
$calendar_button_type = 'txt';
if ($calendar_button_img = _get_option($options, 'calendar_button_img'))
{
$calendar_button = $calendar_button_img;
$calendar_button_type = 'img';
}
else if ($calendar_button_txt = _get_option($options, 'calendar_button_txt'))
{
$calendar_button = $calendar_button_txt;
$calendar_button_type = 'txt';
}
// construct html
if (!isset($options['size']))
{
// educated guess about the size
$options['size'] = strlen($date_format)+2;
}
$html = input_tag($name, $value, $options);
if ($calendar_button_type == 'img')
{
$html .= image_tag($calendar_button, array('id' => $id_calendarButton, 'style' => 'cursor: pointer; vertical-align: middle'));
}
else
{
$html .= content_tag('button', $calendar_button, array('type' => 'button', 'disabled' => 'disabled', 'onclick' => 'return false', 'id' => $id_calendarButton));
}
if (_get_option($options, 'with_format'))
{
$html .= '('.$date_format.')';
}
// add javascript
$html .= content_tag('script', $js, array('type' => 'text/javascript'));
return $html;
}
/**
* Returns an XHTML compliant <input> tag with type="submit".
*
* By default, this helper creates a submit tag with a name of <em>commit</em> to avoid
* conflicts with other parts of the framework. It is recommended that you do not use the name
* "submit" for submit tags unless absolutely necessary. Also, the default <i>$value</i> parameter
* (title of the button) is set to "Save changes", which can be easily overwritten by passing a
* <i>$value</i> parameter.
*
* <b>Examples:</b>
* <code>
* echo submit_tag();
* </code>
*
* <code>
* echo submit_tag('Update Record');
* </code>
*
* @param string field value (title of submit button)
* @param array additional HTML compliant <input> tag parameters
* @return string XHTML compliant <input> tag with type="submit"
*/
function submit_tag($value = 'Save changes', $options = array())
{
return tag('input', array_merge(array('type' => 'submit', 'name' => 'commit', 'value' => $value), _convert_options_to_javascript(_convert_options($options))));
}
/**
* Returns an XHTML compliant <input> tag with type="reset".
*
* By default, this helper creates a submit tag with a name of <em>reset</em>. Also, the default
* <i>$value</i> parameter (title of the button) is set to "Reset" which can be easily overwritten
* by passing a <i>$value</i> parameter.
*
* <b>Examples:</b>
* <code>
* echo reset_tag();
* </code>
*
* <code>
* echo reset_tag('Start Over');
* </code>
*
* @param string field value (title of reset button)
* @param array additional HTML compliant <input> tag parameters
* @return string XHTML compliant <input> tag with type="reset"
*/
function reset_tag($value = 'Reset', $options = array())
{
return tag('input', array_merge(array('type' => 'reset', 'name' => 'reset', 'value' => $value), _convert_options($options)));
}
/**
* Returns an XHTML compliant <input> tag with type="image".
*
* The submit_image_tag is very similar to the submit_tag, the only difference being that it uses an image
* for the submit button instead of the browser-generated default button. The image is defined by the
* <i>$source</i> parameter and must be a valid image, either local or remote (URL). By default, this
* helper creates a submit tag with a name of <em>commit</em> to avoid conflicts with other parts of the
* framework. It is recommended that you do not use the name "submit" for submit tags unless absolutely necessary.
*
* <b>Examples:</b>
* <code>
* // Assuming your image is in the /web/images/ directory
* echo submit_image_tag('my_submit_button.gif');
* </code>
*
* <code>
* echo submit_image_tag('http://mydomain.com/my_submit_button.gif');
* </code>
*
* @param string path to image file
* @param array additional HTML compliant <input> tag parameters
* @return string XHTML compliant <input> tag with type="image"
*/
function submit_image_tag($source, $options = array())
{
if (!isset($options['alt']))
{
$path_pos = strrpos($source, '/');
$dot_pos = strrpos($source, '.');
$begin = $path_pos ? $path_pos + 1 : 0;
$nb_str = ($dot_pos ? $dot_pos : strlen($source)) - $begin;
$options['alt'] = ucfirst(substr($source, $begin, $nb_str));
}
return tag('input', array_merge(array('type' => 'image', 'name' => 'commit', 'src' => image_path($source)), _convert_options_to_javascript(_convert_options($options))));
}
/**
* Returns a <label> tag with <i>$label</i> for the specified <i>$id</i> parameter.
*
* @param string id
* @param string label or title
* @param array additional HTML compliant <label> tag parameters
* @return string <label> tag with <i>$label</i> for the specified <i>$id</i> parameter.
*/
function label_for($id, $label, $options = array())
{
$options = _parse_attributes($options);
return content_tag('label', $label, array_merge(array('for' => get_id_from_name($id, null)), $options));
}
/**
* Returns a formatted ID based on the <i>$name</i> parameter and optionally the <i>$value</i> parameter.
*
* This function determines the proper form field ID name based on the parameters. If a form field has an
* array value as a name we need to convert them to proper and unique IDs like so:
* <samp>
* name[] => name (if value == null)
* name[] => name_value (if value != null)
* name[bob] => name_bob
* name[item][total] => name_item_total
* </samp>
*
* <b>Examples:</b>
* <code>
* echo get_id_from_name('status[]', '1');
* </code>
*
* @param string field name
* @param string field value
* @return string <select> tag populated with all the languages in the world.
*/
function get_id_from_name($name, $value = null)
{
// check to see if we have an array variable for a field name
if (strstr($name, '['))
{
$name = str_replace(array('[]', '][', '[', ']'), array((($value != null) ? '_'.$value : ''), '_', '_', ''), $name);
}
return $name;
}
/**
* Converts specific <i>$options</i> to their correct HTML format
*
* @param array options
* @return array returns properly formatted options
*/
function _convert_options($options)
{
$options = _parse_attributes($options);
foreach (array('disabled', 'readonly', 'multiple') as $attribute)
{
if (array_key_exists($attribute, $options))
{
if ($options[$attribute])
{
$options[$attribute] = $attribute;
}
else
{
unset($options[$attribute]);
}
}
}
return $options;
}
function _convert_include_custom_for_select($options, &$select_options)
{
if (_get_option($options, 'include_blank'))
{
$select_options[''] = '';
}
else if ($include_custom = _get_option($options, 'include_custom'))
{
$select_options[''] = $include_custom;
}
}

View File

@ -0,0 +1,23 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* HelperHelper.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: HelperHelper.php 2165 2006-09-25 14:22:15Z fabien $
*/
function use_helper()
{
sfLoader::loadHelpers(func_get_args(), sfContext::getInstance()->getModuleName());
}

View File

@ -0,0 +1,84 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* I18NHelper.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: I18NHelper.php 5141 2007-09-16 14:37:58Z fabien $
*/
function __($text, $args = array(), $catalogue = 'messages')
{
static $i18n;
if (sfConfig::get('sf_i18n'))
{
if (!isset($i18n))
{
$i18n = sfContext::getInstance()->getI18N();
}
return $i18n->__($text, $args, $catalogue);
}
else
{
if (empty($args))
{
$args = array();
}
// replace object with strings
foreach ($args as $key => $value)
{
if (is_object($value) && method_exists($value, '__toString'))
{
$args[$key] = $value->__toString();
}
}
return strtr($text, $args);
}
}
function format_number_choice($text, $args = array(), $number, $catalogue = 'messages')
{
$translated = __($text, $args, $catalogue);
$choice = new sfChoiceFormat();
$retval = $choice->format($translated, $number);
if ($retval === false)
{
$error = sprintf('Unable to parse your choice "%s"', $translated);
throw new sfException($error);
}
return $retval;
}
function format_country($country_iso, $culture = null)
{
$c = new sfCultureInfo($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
$countries = $c->getCountries();
return isset($countries[$country_iso]) ? $countries[$country_iso] : '';
}
function format_language($language_iso, $culture = null)
{
$c = new sfCultureInfo($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
$languages = $c->getLanguages();
return isset($languages[$language_iso]) ? $languages[$language_iso] : '';
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,47 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* NumberHelper.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: NumberHelper.php 3495 2007-02-18 09:30:24Z fabien $
*/
function format_number($number, $culture = null)
{
if (is_null($number))
{
return null;
}
$numberFormat = new sfNumberFormat(_current_language($culture));
return $numberFormat->format($number);
}
function format_currency($amount, $currency = null, $culture = null)
{
if (is_null($amount))
{
return null;
}
$numberFormat = new sfNumberFormat(_current_language($culture));
return $numberFormat->format($amount, 'c', $currency);
}
function _current_language($culture)
{
return $culture ? $culture : sfContext::getInstance()->getUser()->getCulture();
}

View File

@ -0,0 +1,207 @@
<?php
use_helper('Form', 'Javascript', 'Helper');
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* ObjectHelper for admin generator.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: ObjectAdminHelper.php 3746 2007-04-11 08:08:38Z fabien $
*/
function object_admin_input_file_tag($object, $method, $options = array())
{
$options = _parse_attributes($options);
$name = _convert_method_to_name($method, $options);
$html = '';
$value = _get_object_value($object, $method);
if ($value)
{
if ($include_link = _get_option($options, 'include_link'))
{
$image_path = image_path('/'.sfConfig::get('sf_upload_dir_name').'/'.$include_link.'/'.$value);
$image_text = ($include_text = _get_option($options, 'include_text')) ? __($include_text) : __('[show file]');
$html .= sprintf('<a onclick="window.open(this.href);return false;" href="%s">%s</a>', $image_path, $image_text)."\n";
}
if ($include_remove = _get_option($options, 'include_remove'))
{
$html .= checkbox_tag(strpos($name, ']') !== false ? substr($name, 0, -1).'_remove]' : $name).' '.($include_remove != true ? __($include_remove) : __('remove file'))."\n";
}
}
return input_file_tag($name, $options)."\n<br />".$html;
}
function object_admin_double_list($object, $method, $options = array(), $callback = null)
{
$options = _parse_attributes($options);
$options['multiple'] = true;
$options['class'] = 'sf_admin_multiple';
if (!isset($options['size']))
{
$options['size'] = 10;
}
$label_all = __(isset($options['unassociated_label']) ? $options['unassociated_label'] : 'Unassociated');
$label_assoc = __(isset($options['associated_label']) ? $options['associated_label'] : 'Associated');
// get the lists of objects
list($all_objects, $objects_associated, $associated_ids) = _get_object_list($object, $method, $options, $callback);
$objects_unassociated = array();
foreach ($all_objects as $object)
{
if (!in_array($object->getPrimaryKey(), $associated_ids))
{
$objects_unassociated[] = $object;
}
}
// override field name
unset($options['control_name']);
$name = _convert_method_to_name($method, $options);
$name1 = 'unassociated_'.$name;
$name2 = 'associated_'.$name;
$select1 = select_tag($name1, options_for_select(_get_options_from_objects($objects_unassociated), '', $options), $options);
$options['class'] = 'sf_admin_multiple-selected';
$select2 = select_tag($name2, options_for_select(_get_options_from_objects($objects_associated), '', $options), $options);
$html =
'<div>
<div style="float: left">
<div style="font-weight: bold; padding-bottom: 0.5em">%s</div>
%s
</div>
<div style="float: left">
%s<br />
%s
</div>
<div style="float: left">
<div style="font-weight: bold; padding-bottom: 0.5em">%s</div>
%s
</div>
<br style="clear: both" />
</div>
';
$response = sfContext::getInstance()->getResponse();
$response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype');
$response->addJavascript(sfConfig::get('sf_admin_web_dir').'/js/double_list');
return sprintf($html,
$label_all,
$select1,
submit_image_tag(sfConfig::get('sf_admin_web_dir').'/images/next.png', "style=\"border: 0\" onclick=\"double_list_move(\$('{$name1}'), \$('{$name2}')); return false;\""),
submit_image_tag(sfConfig::get('sf_admin_web_dir').'/images/previous.png', "style=\"border: 0\" onclick=\"double_list_move(\$('{$name2}'), \$('{$name1}')); return false;\""),
$label_assoc,
$select2
);
}
function object_admin_select_list($object, $method, $options = array(), $callback = null)
{
$options = _parse_attributes($options);
$options['multiple'] = true;
$options['class'] = 'sf_admin_multiple';
if (!isset($options['size']))
{
$options['size'] = 10;
}
// get the lists of objects
list($objects, $objects_associated, $ids) = _get_object_list($object, $method, $options, $callback);
// override field name
unset($options['control_name']);
$name = 'associated_'._convert_method_to_name($method, $options);
return select_tag($name, options_for_select(_get_options_from_objects($objects), $ids, $options), $options);
}
function object_admin_check_list($object, $method, $options = array(), $callback = null)
{
$options = _parse_attributes($options);
// get the lists of objects
list($objects, $objects_associated, $assoc_ids) = _get_object_list($object, $method, $options, $callback);
// override field name
unset($options['control_name']);
$name = 'associated_'._convert_method_to_name($method, $options).'[]';
$html = '';
if (!empty($objects))
{
// which method to call?
$methodToCall = '__toString';
foreach (array('__toString', 'toString', 'getPrimaryKey') as $method)
{
if (method_exists($objects[0], $method))
{
$methodToCall = $method;
break;
}
}
$html .= "<ul class=\"sf_admin_checklist\">\n";
foreach ($objects as $related_object)
{
$relatedPrimaryKey = $related_object->getPrimaryKey();
// multi primary key handling
if (is_array($relatedPrimaryKey))
{
$relatedPrimaryKeyHtmlId = implode('/', $relatedPrimaryKey);
}
else
{
$relatedPrimaryKeyHtmlId = $relatedPrimaryKey;
}
$html .= '<li>'.checkbox_tag($name, $relatedPrimaryKeyHtmlId, in_array($relatedPrimaryKey, $assoc_ids)).' <label for="'.get_id_from_name($name, $relatedPrimaryKeyHtmlId).'">'.$related_object->$methodToCall()."</label></li>\n";
}
$html .= "</ul>\n";
}
return $html;
}
function _get_propel_object_list($object, $method, $options)
{
// get the lists of objects
$through_class = _get_option($options, 'through_class');
$objects = sfPropelManyToMany::getAllObjects($object, $through_class);
$objects_associated = sfPropelManyToMany::getRelatedObjects($object, $through_class);
$ids = array_map(create_function('$o', 'return $o->getPrimaryKey();'), $objects_associated);
return array($objects, $objects_associated, $ids);
}
function _get_object_list($object, $method, $options, $callback)
{
$object = $object instanceof sfOutputEscaper ? $object->getRawValue() : $object;
// the default callback is the propel one
if (!$callback)
{
$callback = '_get_propel_object_list';
}
return call_user_func($callback, $object, $method, $options);
}

View File

@ -0,0 +1,330 @@
<?php
use_helper('Form');
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* ObjectHelper.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: ObjectHelper.php 5149 2007-09-16 15:37:14Z fabien $
*/
/**
* Returns a html date control.
*
* @param object An object.
* @param string An object column.
* @param array Date options.
* @param bool Date default value.
*
* @return string An html string which represents a date control.
*
*/
function object_input_date_tag($object, $method, $options = array(), $default_value = null)
{
$options = _parse_attributes($options);
$value = _get_object_value($object, $method, $default_value, $param = 'Y-m-d G:i');
return input_date_tag(_convert_method_to_name($method, $options), $value, $options);
}
/**
* Returns a textarea html tag.
*
* @param object An object.
* @param string An object column.
* @param array Textarea options.
* @param bool Textarea default value.
*
* @return string An html string which represents a textarea tag.
*
*/
function object_textarea_tag($object, $method, $options = array(), $default_value = null)
{
$options = _parse_attributes($options);
$value = _get_object_value($object, $method, $default_value);
return textarea_tag(_convert_method_to_name($method, $options), $value, $options);
}
/**
* Accepts a container of objects, the method name to use for the value,
* and the method name to use for the display.
* It returns a string of option tags.
*
* NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
*/
function objects_for_select($options = array(), $value_method, $text_method = null, $selected = null, $html_options = array())
{
$select_options = array();
foreach ($options as $option)
{
// text method exists?
if ($text_method && !is_callable(array($option, $text_method)))
{
$error = sprintf('Method "%s" doesn\'t exist for object of class "%s"', $text_method, _get_class_decorated($option));
throw new sfViewException($error);
}
// value method exists?
if (!is_callable(array($option, $value_method)))
{
$error = sprintf('Method "%s" doesn\'t exist for object of class "%s"', $value_method, _get_class_decorated($option));
throw new sfViewException($error);
}
$value = $option->$value_method();
$key = ($text_method != null) ? $option->$text_method() : $value;
$select_options[$value] = $key;
}
return options_for_select($select_options, $selected, $html_options);
}
/**
* Returns a list html tag.
*
* @param object An object or the selected value
* @param string An object column.
* @param array Input options (related_class option is mandatory).
* @param bool Input default value.
*
* @return string A list string which represents an input tag.
*
*/
function object_select_tag($object, $method, $options = array(), $default_value = null)
{
$options = _parse_attributes($options);
$related_class = _get_option($options, 'related_class', false);
if (false === $related_class && preg_match('/^get(.+?)Id$/', $method, $match))
{
$related_class = $match[1];
}
$peer_method = _get_option($options, 'peer_method');
$text_method = _get_option($options, 'text_method');
$select_options = _get_options_from_objects(sfContext::getInstance()->retrieveObjects($related_class, $peer_method), $text_method);
if ($value = _get_option($options, 'include_custom'))
{
$select_options = array('' => $value) + $select_options;
}
else if (_get_option($options, 'include_title'))
{
$select_options = array('' => '-- '._convert_method_to_name($method, $options).' --') + $select_options;
}
else if (_get_option($options, 'include_blank'))
{
$select_options = array('' => '') + $select_options;
}
if (is_object($object))
{
$value = _get_object_value($object, $method, $default_value);
}
else
{
$value = $object;
}
$option_tags = options_for_select($select_options, $value, $options);
return select_tag(_convert_method_to_name($method, $options), $option_tags, $options);
}
function _get_options_from_objects($objects, $text_method = null)
{
$select_options = array();
if ($objects)
{
// construct select option list
$first = true;
foreach ($objects as $tmp_object)
{
if ($first)
{
// multi primary keys handling
$multi_primary_keys = is_array($tmp_object->getPrimaryKey()) ? true : false;
// which method to call?
$methodToCall = '';
foreach (array($text_method, '__toString', 'toString', 'getPrimaryKey') as $method)
{
if (is_callable(array($tmp_object, $method)))
{
$methodToCall = $method;
break;
}
}
$first = false;
}
$key = $multi_primary_keys ? implode('/', $tmp_object->getPrimaryKey()) : $tmp_object->getPrimaryKey();
$value = $tmp_object->$methodToCall();
$select_options[$key] = $value;
}
}
return $select_options;
}
function object_select_country_tag($object, $method, $options = array(), $default_value = null)
{
$options = _parse_attributes($options);
$value = _get_object_value($object, $method, $default_value);
return select_country_tag(_convert_method_to_name($method, $options), $value, $options);
}
function object_select_language_tag($object, $method, $options = array(), $default_value = null)
{
$options = _parse_attributes($options);
$value = _get_object_value($object, $method, $default_value);
return select_language_tag(_convert_method_to_name($method, $options), $value, $options);
}
/**
* Returns a hidden input html tag.
*
* @param object An object.
* @param string An object column.
* @param array Input options.
* @param bool Input default value.
*
* @return string An html string which represents a hidden input tag.
*
*/
function object_input_hidden_tag($object, $method, $options = array(), $default_value = null)
{
$options = _parse_attributes($options);
$value = _get_object_value($object, $method, $default_value);
return input_hidden_tag(_convert_method_to_name($method, $options), $value, $options);
}
/**
* Returns a input html tag.
*
* @param object An object.
* @param string An object column.
* @param array Input options.
* @param bool Input default value.
*
* @return string An html string which represents an input tag.
*
*/
function object_input_tag($object, $method, $options = array(), $default_value = null)
{
$options = _parse_attributes($options);
$value = _get_object_value($object, $method, $default_value);
return input_tag(_convert_method_to_name($method, $options), $value, $options);
}
/**
* Returns a checkbox html tag.
*
* @param object An object.
* @param string An object column.
* @param array Checkbox options.
* @param bool Checkbox value.
*
* @return string An html string which represents a checkbox tag.
*
*/
function object_checkbox_tag($object, $method, $options = array(), $default_value = null)
{
$options = _parse_attributes($options);
$checked = (boolean) _get_object_value($object, $method, $default_value);
return checkbox_tag(_convert_method_to_name($method, $options), isset($options['value']) ? $options['value'] : 1, $checked, $options);
}
function _convert_method_to_name($method, &$options)
{
$name = _get_option($options, 'control_name');
if (!$name)
{
if (is_array($method))
{
$name = implode('-',$method[1]);
}
else
{
$name = sfInflector::underscore($method);
$name = preg_replace('/^get_?/', '', $name);
}
}
return $name;
}
// returns default_value if object value is null
// method is either a string or: array('method',array('param1','param2'))
function _get_object_value($object, $method, $default_value = null, $param = null)
{
// compatibility with the array syntax
if (is_string($method))
{
$param = ($param == null ? array() : array($param));
$method = array($method, $param);
}
// method exists?
if (!is_callable(array($object, $method[0])))
{
$error = 'Method "%s" doesn\'t exist for object of class "%s"';
$error = sprintf($error, $method[0], _get_class_decorated($object));
throw new sfViewException($error);
}
$object_value = call_user_func_array(array($object, $method[0]), $method[1]);
return ($default_value !== null && $object_value === null) ? $default_value : $object_value;
}
/**
* Returns the name of the class of an decorated object
*
* @param object An object that might be wrapped in an sfOutputEscaperObjectDecorator(-derivative)
*
* @return string The name of the class of the object being decorated for escaping, or the class of the object if it isn't decorated
*/
function _get_class_decorated($object)
{
if ($object instanceof sfOutputEscaperObjectDecorator)
{
return sprintf('%s (decorated with %s)', get_class($object->getRawValue()), get_class($object));
}
else
{
return get_class($object);
}
}

View File

@ -0,0 +1,439 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* PartialHelper.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: PartialHelper.php 3265 2007-01-13 17:06:40Z fabien $
*/
/**
* Evaluates and echoes a component slot.
* The component name is deduced from the definition of the view.yml
* For a variable to be accessible to the component and its partial,
* it has to be passed in the second argument.
*
* <b>Example:</b>
* <code>
* include_component_slot('sidebar', array('myvar' => 12345));
* </code>
*
* @param string slot name
* @param array variables to be made accessible to the component
* @return void
* @see get_component_slot, include_partial, include_component
*/
function include_component_slot($name, $vars = array())
{
echo get_component_slot($name, $vars);
}
/**
* Evaluates and returns a component slot.
* The syntax is similar to the one of include_component_slot.
*
* <b>Example:</b>
* <code>
* echo get_component_slot('sidebar', array('myvar' => 12345));
* </code>
*
* @param string slot name
* @param array variables to be made accessible to the component
* @return string result of the component execution
* @see get_component_slot, include_partial, include_component
*/
function get_component_slot($name, $vars = array())
{
$context = sfContext::getInstance();
$actionStackEntry = $context->getController()->getActionStack()->getLastEntry();
$viewInstance = $actionStackEntry->getViewInstance();
if (!$viewInstance->hasComponentSlot($name))
{
// cannot find component slot
$error = 'The component slot "%s" is not set';
$error = sprintf($error, $name);
throw new sfConfigurationException($error);
}
if ($componentSlot = $viewInstance->getComponentSlot($name))
{
return get_component($componentSlot[0], $componentSlot[1], $vars);
}
}
/**
* Evaluates and echoes a component.
* For a variable to be accessible to the component and its partial,
* it has to be passed in the third argument.
*
* <b>Example:</b>
* <code>
* include_component('mymodule', 'mypartial', array('myvar' => 12345));
* </code>
*
* @param string module name
* @param string component name
* @param array variables to be made accessible to the component
* @return void
* @see get_component, include_partial, include_component_slot
*/
function include_component($moduleName, $componentName, $vars = array())
{
echo get_component($moduleName, $componentName, $vars);
}
/**
* Evaluates and returns a component.
* The syntax is similar to the one of include_component.
*
* <b>Example:</b>
* <code>
* echo get_component('mymodule', 'mypartial', array('myvar' => 12345));
* </code>
*
* @param string module name
* @param string component name
* @param array variables to be made accessible to the component
* @return string result of the component execution
* @see include_component
*/
function get_component($moduleName, $componentName, $vars = array())
{
$context = sfContext::getInstance();
$actionName = '_'.$componentName;
// check cache
if ($cacheManager = $context->getViewCacheManager())
{
$cacheManager->registerConfiguration($moduleName);
$uri = '@sf_cache_partial?module='.$moduleName.'&action='.$actionName.'&sf_cache_key='.(isset($vars['sf_cache_key']) ? $vars['sf_cache_key'] : md5(serialize($vars)));
if ($retval = _get_cache($cacheManager, $uri))
{
return $retval;
}
}
$controller = $context->getController();
if (!$controller->componentExists($moduleName, $componentName))
{
// cannot find component
$error = 'The component does not exist: "%s", "%s"';
$error = sprintf($error, $moduleName, $componentName);
throw new sfConfigurationException($error);
}
// create an instance of the action
$componentInstance = $controller->getComponent($moduleName, $componentName);
// initialize the action
if (!$componentInstance->initialize($context))
{
// component failed to initialize
$error = 'Component initialization failed for module "%s", component "%s"';
$error = sprintf($error, $moduleName, $componentName);
throw new sfInitializationException($error);
}
// load component's module config file
require(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$moduleName.'/'.sfConfig::get('sf_app_module_config_dir_name').'/module.yml'));
$componentInstance->getVarHolder()->add($vars);
// dispatch component
$componentToRun = 'execute'.ucfirst($componentName);
if (!method_exists($componentInstance, $componentToRun))
{
if (!method_exists($componentInstance, 'execute'))
{
// component not found
$error = 'sfComponent initialization failed for module "%s", component "%s"';
$error = sprintf($error, $moduleName, $componentName);
throw new sfInitializationException($error);
}
$componentToRun = 'execute';
}
if (sfConfig::get('sf_logging_enabled'))
{
$context->getLogger()->info('{PartialHelper} call "'.$moduleName.'->'.$componentToRun.'()'.'"');
}
// run component
if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled'))
{
$timer = sfTimerManager::getTimer(sprintf('Component "%s/%s"', $moduleName, $componentName));
}
$retval = $componentInstance->$componentToRun();
if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled'))
{
$timer->addTime();
}
if ($retval != sfView::NONE)
{
// render
$view = new sfPartialView();
$view->initialize($context, $moduleName, $actionName, '');
$retval = $view->render($componentInstance->getVarHolder()->getAll());
if ($cacheManager)
{
$retval = _set_cache($cacheManager, $uri, $retval);
}
return $retval;
}
}
/**
* Evaluates and echoes a partial.
* The partial name is composed as follows: 'mymodule/mypartial'.
* The partial file name is _mypartial.php and is looked for in modules/mymodule/templates/.
* If the partial name doesn't include a module name,
* then the partial file is searched for in the caller's template/ directory.
* If the module name is 'global', then the partial file is looked for in myapp/templates/.
* For a variable to be accessible to the partial, it has to be passed in the second argument.
*
* <b>Example:</b>
* <code>
* include_partial('mypartial', array('myvar' => 12345));
* </code>
*
* @param string partial name
* @param array variables to be made accessible to the partial
* @return void
* @see get_partial, include_component
*/
function include_partial($templateName, $vars = array())
{
echo get_partial($templateName, $vars);
}
/**
* Evaluates and returns a partial.
* The syntax is similar to the one of include_partial
*
* <b>Example:</b>
* <code>
* echo get_partial('mypartial', array('myvar' => 12345));
* </code>
*
* @param string partial name
* @param array variables to be made accessible to the partial
* @return string result of the partial execution
* @see include_partial
*/
function get_partial($templateName, $vars = array())
{
$context = sfContext::getInstance();
// partial is in another module?
if (false !== $sep = strpos($templateName, '/'))
{
$moduleName = substr($templateName, 0, $sep);
$templateName = substr($templateName, $sep + 1);
}
else
{
$moduleName = $context->getActionStack()->getLastEntry()->getModuleName();
}
$actionName = '_'.$templateName;
if ($cacheManager = $context->getViewCacheManager())
{
$cacheManager->registerConfiguration($moduleName);
$uri = '@sf_cache_partial?module='.$moduleName.'&action='.$actionName.'&sf_cache_key='.(isset($vars['sf_cache_key']) ? $vars['sf_cache_key'] : md5(serialize($vars)));
if ($retval = _get_cache($cacheManager, $uri))
{
return $retval;
}
}
$view = new sfPartialView();
$view->initialize($context, $moduleName, $actionName, '');
$retval = $view->render($vars);
if ($cacheManager)
{
$retval = _set_cache($cacheManager, $uri, $retval);
}
return $retval;
}
function _get_cache($cacheManager, $uri)
{
$retval = $cacheManager->get($uri);
if (sfConfig::get('sf_web_debug'))
{
$retval = sfWebDebug::getInstance()->decorateContentWithDebug($uri, $retval, false);
}
return $retval;
}
function _set_cache($cacheManager, $uri, $retval)
{
$saved = $cacheManager->set($retval, $uri);
if ($saved && sfConfig::get('sf_web_debug'))
{
$retval = sfWebDebug::getInstance()->decorateContentWithDebug($uri, $retval, true);
}
return $retval;
}
/**
* Begins the capturing of the slot.
*
* @param string slot name
* @return void
* @see end_slot
*/
function slot($name)
{
$context = sfContext::getInstance();
$response = $context->getResponse();
$slots = $response->getParameter('slots', array(), 'symfony/view/sfView/slot');
$slot_names = $response->getParameter('slot_names', array(), 'symfony/view/sfView/slot');
if (in_array($name, $slot_names))
{
throw new sfCacheException(sprintf('A slot named "%s" is already started.', $name));
}
$slot_names[] = $name;
$slots[$name] = '';
$response->setParameter('slots', $slots, 'symfony/view/sfView/slot');
$response->setParameter('slot_names', $slot_names, 'symfony/view/sfView/slot');
if (sfConfig::get('sf_logging_enabled'))
{
$context->getLogger()->info(sprintf('{PartialHelper} set slot "%s"', $name));
}
ob_start();
ob_implicit_flush(0);
}
/**
* Stops the content capture and save the content in the slot.
*
* @return void
* @see slot
*/
function end_slot()
{
$content = ob_get_clean();
$response = sfContext::getInstance()->getResponse();
$slots = $response->getParameter('slots', array(), 'symfony/view/sfView/slot');
$slot_names = $response->getParameter('slot_names', array(), 'symfony/view/sfView/slot');
if (!$slot_names)
{
throw new sfCacheException('No slot started.');
}
$name = array_pop($slot_names);
$slots[$name] = $content;
$response->setParameter('slots', $slots, 'symfony/view/sfView/slot');
$response->setParameter('slot_names', $slot_names, 'symfony/view/sfView/slot');
}
/**
* Returns true if the slot exists.
*
* @param string slot name
* @return boolean true, if the slot exists
* @see get_slot, include_slot
*/
function has_slot($name)
{
$response = sfContext::getInstance()->getResponse();
$slots = $response->getParameter('slots', array(), 'symfony/view/sfView/slot');
return array_key_exists($name, $slots);
}
/**
* Evaluates and echoes a slot.
*
* <b>Example:</b>
* <code>
* include_slot('navigation');
* </code>
*
* @param string slot name
* @return void
* @see has_slot, get_slot
*/
function include_slot($name)
{
$context = sfContext::getInstance();
$slots = $context->getResponse()->getParameter('slots', array(), 'symfony/view/sfView/slot');
if (sfConfig::get('sf_logging_enabled'))
{
$context->getLogger()->info(sprintf('{PartialHelper} get slot "%s"', $name));
}
if (isset($slots[$name]))
{
echo $slots[$name];
return true;
}
else
{
return false;
}
}
/**
* Evaluates and returns a slot.
*
* <b>Example:</b>
* <code>
* echo get_slot('navigation');
* </code>
*
* @param string slot name
* @return string content of the slot
* @see has_slot, include_slot
*/
function get_slot($name)
{
$context = sfContext::getInstance();
$slots = $context->getResponse()->getParameter('slots', array(), 'symfony/view/sfView/slot');
if (sfConfig::get('sf_logging_enabled'))
{
$context->getLogger()->info(sprintf('{PartialHelper} get slot "%s"', $name));
}
return isset($slots[$name]) ? $slots[$name] : '';
}

119
lib/symfony/helper/TagHelper.php Executable file
View File

@ -0,0 +1,119 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
* (c) 2004 David Heinemeier Hansson
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* TagHelper defines some base helpers to construct html tags.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author David Heinemeier Hansson
* @version SVN: $Id: TagHelper.php 3336 2007-01-23 21:05:10Z fabien $
*/
/**
* Constructs an html tag.
*
* @param $name string tag name
* @param $options array tag options
* @param $open boolean true to leave tag open
* @return string
*/
function tag($name, $options = array(), $open = false)
{
if (!$name)
{
return '';
}
return '<'.$name._tag_options($options).(($open) ? '>' : ' />');
}
function content_tag($name, $content = '', $options = array())
{
if (!$name)
{
return '';
}
return '<'.$name._tag_options($options).'>'.$content.'</'.$name.'>';
}
function cdata_section($content)
{
return "<![CDATA[$content]]>";
}
/**
* Escape carrier returns and single and double quotes for Javascript segments.
*/
function escape_javascript($javascript = '')
{
$javascript = preg_replace('/\r\n|\n|\r/', "\\n", $javascript);
$javascript = preg_replace('/(["\'])/', '\\\\\1', $javascript);
return $javascript;
}
/**
* Escapes an HTML string.
*
* @param string HTML string to escape
* @return string escaped string
*/
function escape_once($html)
{
return fix_double_escape(htmlspecialchars($html));
}
/**
* Fixes double escaped strings.
*
* @param string HTML string to fix
* @return string escaped string
*/
function fix_double_escape($escaped)
{
return preg_replace('/&amp;([a-z]+|(#\d+)|(#x[\da-f]+));/i', '&$1;', $escaped);
}
function _tag_options($options = array())
{
$options = _parse_attributes($options);
$html = '';
foreach ($options as $key => $value)
{
$html .= ' '.$key.'="'.escape_once($value).'"';
}
return $html;
}
function _parse_attributes($string)
{
return is_array($string) ? $string : sfToolkit::stringToArray($string);
}
function _get_option(&$options, $name, $default = null)
{
if (array_key_exists($name, $options))
{
$value = $options[$name];
unset($options[$name]);
}
else
{
$value = $default;
}
return $value;
}

205
lib/symfony/helper/TextHelper.php Executable file
View File

@ -0,0 +1,205 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
* (c) 2004 David Heinemeier Hansson
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* TextHelper.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author David Heinemeier Hansson
* @version SVN: $Id: TextHelper.php 3699 2007-04-02 11:47:32Z fabien $
*/
/**
* Truncates +text+ to the length of +length+ and replaces the last three characters with the +truncate_string+
* if the +text+ is longer than +length+.
*/
function truncate_text($text, $length = 30, $truncate_string = '...', $truncate_lastspace = false)
{
if ($text == '')
{
return '';
}
if (strlen($text) > $length)
{
$truncate_text = substr($text, 0, $length - strlen($truncate_string));
if ($truncate_lastspace)
{
$truncate_text = preg_replace('/\s+?(\S+)?$/', '', $truncate_text);
}
return $truncate_text.$truncate_string;
}
else
{
return $text;
}
}
/**
* Highlights the +phrase+ where it is found in the +text+ by surrounding it like
* <strong class="highlight">I'm a highlight phrase</strong>. The highlighter can be specialized by
* passing +highlighter+ as single-quoted string with \1 where the phrase is supposed to be inserted.
* N.B.: The +phrase+ is sanitized to include only letters, digits, and spaces before use.
*/
function highlight_text($text, $phrase, $highlighter = '<strong class="highlight">\\1</strong>')
{
if ($text == '')
{
return '';
}
if ($phrase == '')
{
return $text;
}
return preg_replace('/('.preg_quote($phrase, '/').')/i', $highlighter, $text);
}
/**
* Extracts an excerpt from the +text+ surrounding the +phrase+ with a number of characters on each side determined
* by +radius+. If the phrase isn't found, nil is returned. Ex:
* excerpt("hello my world", "my", 3) => "...lo my wo..."
*/
function excerpt_text($text, $phrase, $radius = 100, $excerpt_string = '...')
{
if ($text == '' || $phrase == '')
{
return '';
}
$found_pos = strpos(strtolower($text), strtolower($phrase));
if ($found_pos !== false)
{
$start_pos = max($found_pos - $radius, 0);
$end_pos = min($found_pos + strlen($phrase) + $radius, strlen($text));
$prefix = ($start_pos > 0) ? $excerpt_string : '';
$postfix = $end_pos < strlen($text) ? $excerpt_string : '';
return $prefix.substr($text, $start_pos, $end_pos - $start_pos).$postfix;
}
}
/**
* Word wrap long lines to line_width.
*/
function wrap_text($text, $line_width = 80)
{
return preg_replace('/(.{1,'.$line_width.'})(\s+|$)/s', "\\1\n", preg_replace("/\n/", "\n\n", $text));
}
/*
# Returns +text+ transformed into html using very simple formatting rules
# Surrounds paragraphs with <tt>&lt;p&gt;</tt> tags, and converts line breaks into <tt>&lt;br /&gt;</tt>
# Two consecutive newlines(<tt>\n\n</tt>) are considered as a paragraph, one newline (<tt>\n</tt>) is
# considered a linebreak, three or more consecutive newlines are turned into two newlines
*/
function simple_format_text($text, $options = array())
{
$css = (isset($options['class'])) ? ' class="'.$options['class'].'"' : '';
$text = sfToolkit::pregtr($text, array("/(\r\n|\r)/" => "\n", // lets make them newlines crossplatform
"/\n{3,}/" => "\n\n", // zap dupes
"/\n\n/" => "</p>\\0<p$css>", // turn two newlines into paragraph
"/([^\n])\n([^\n])/" => "\\1\n<br />\\2")); // turn single newline into <br/>
return '<p'.$css.'>'.$text.'</p>'; // wrap the first and last line in paragraphs before we're done
}
/**
* Turns all urls and email addresses into clickable links. The +link+ parameter can limit what should be linked.
* Options are :all (default), :email_addresses, and :urls.
*
* Example:
* auto_link("Go to http://www.symfony-project.com and say hello to fabien.potencier@example.com") =>
* Go to <a href="http://www.symfony-project.com">http://www.symfony-project.com</a> and
* say hello to <a href="mailto:fabien.potencier@example.com">fabien.potencier@example.com</a>
*/
function auto_link_text($text, $link = 'all', $href_options = array())
{
if ($link == 'all')
{
return _auto_link_urls(_auto_link_email_addresses($text), $href_options);
}
else if ($link == 'email_addresses')
{
return _auto_link_email_addresses($text);
}
else if ($link == 'urls')
{
return _auto_link_urls($text, $href_options);
}
}
/*
* Turns all links into words, like "<a href="something">else</a>" to "else".
*/
function strip_links_text($text)
{
return preg_replace('/<a.*>(.*)<\/a>/m', '\\1', $text);
}
if (!defined('SF_AUTO_LINK_RE'))
{
define('SF_AUTO_LINK_RE', '~
( # leading text
<\w+.*?>| # leading HTML tag, or
[^=!:\'"/]| # leading punctuation, or
^ # beginning of line
)
(
(?:https?://)| # protocol spec, or
(?:www\.) # www.*
)
(
[-\w]+ # subdomain or domain
(?:\.[-\w]+)* # remaining subdomains or domain
(?::\d+)? # port
(?:/(?:(?:[\~\w\+%-]|(?:[,.;:][^\s$]))+)?)* # path
(?:\?[\w\+%&=.;-]+)? # query string
(?:\#[\w\-]*)? # trailing anchor
)
([[:punct:]]|\s|<|$) # trailing text
~x');
}
/**
* Turns all urls into clickable links.
*/
function _auto_link_urls($text, $href_options = array())
{
$href_options = _tag_options($href_options);
return preg_replace_callback(
SF_AUTO_LINK_RE,
create_function('$matches', '
if (preg_match("/<a\s/i", $matches[1]))
{
return $matches[0];
}
else
{
return $matches[1].\'<a href="\'.($matches[2] == "www." ? "http://www." : $matches[2]).$matches[3].\'"'.$href_options.'>\'.$matches[2].$matches[3].\'</a>\'.$matches[4];
}
')
, $text);
}
/**
* Turns all email addresses into clickable links.
*/
function _auto_link_email_addresses($text)
{
return preg_replace('/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/', '<a href="mailto:\\1">\\1</a>', $text);
}

443
lib/symfony/helper/UrlHelper.php Executable file
View File

@ -0,0 +1,443 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* UrlHelper.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: UrlHelper.php 4195 2007-06-10 08:35:09Z fabien $
*/
/**
* Returns a routed URL based on the module/action passed as argument
* and the routing configuration.
*
* <b>Examples:</b>
* <code>
* echo url_for('my_module/my_action');
* => /path/to/my/action
* echo url_for('@my_rule');
* => /path/to/my/action
* echo url_for('@my_rule', true);
* => http://myapp.example.com/path/to/my/action
* </code>
*
* @param string 'module/action' or '@rule' of the action
* @param bool return absolute path?
* @return string routed URL
*/
function url_for($internal_uri, $absolute = false)
{
static $controller;
if (!isset($controller))
{
$controller = sfContext::getInstance()->getController();
}
return $controller->genUrl($internal_uri, $absolute);
}
/**
* Creates a <a> link tag of the given name using a routed URL
* based on the module/action passed as argument and the routing configuration.
* It's also possible to pass a string instead of a module/action pair to
* get a link tag that just points without consideration.
* If null is passed as a name, the link itself will become the name.
* If an object is passed as a name, the object string representation is used.
* One of the options serves for for creating javascript confirm alerts where
* if you pass 'confirm' => 'Are you sure?', the link will be guarded
* with a JS popup asking that question. If the user accepts, the link is processed,
* otherwise not.
*
* <b>Options:</b>
* - 'absolute' - if set to true, the helper outputs an absolute URL
* - 'query_string' - to append a query string (starting by ?) to the routed url
* - 'confirm' - displays a javascript confirmation alert when the link is clicked
* - 'popup' - if set to true, the link opens a new browser window
* - 'post' - if set to true, the link submits a POST request instead of GET (caution: do not use inside a form)
*
* <b>Note:</b> The 'popup' and 'post' options are not compatible with each other.
*
* <b>Examples:</b>
* <code>
* echo link_to('Delete this page', 'my_module/my_action');
* => <a href="/path/to/my/action">Delete this page</a>
* echo link_to('Visit Hoogle', 'http://www.hoogle.com');
* => <a href="http://www.hoogle.com">Visit Hoogle</a>
* echo link_to('Delete this page', 'my_module/my_action', array('id' => 'myid', 'confirm' => 'Are you sure?', 'absolute' => true));
* => <a href="http://myapp.example.com/path/to/my/action" id="myid" onclick="return confirm('Are you sure?');">Delete this page</a>
* </code>
*
* @param string name of the link, i.e. string to appear between the <a> tags
* @param string 'module/action' or '@rule' of the action
* @param array additional HTML compliant <a> tag parameters
* @return string XHTML compliant <a href> tag
* @see url_for
*/
function link_to($name = '', $internal_uri = '', $options = array())
{
$html_options = _parse_attributes($options);
$html_options = _convert_options_to_javascript($html_options);
$absolute = false;
if (isset($html_options['absolute_url']))
{
$html_options['absolute'] = $html_options['absolute_url'];
unset($html_options['absolute_url']);
}
if (isset($html_options['absolute']))
{
$absolute = (boolean) $html_options['absolute'];
unset($html_options['absolute']);
}
$html_options['href'] = url_for($internal_uri, $absolute);
if (isset($html_options['query_string']))
{
$html_options['href'] .= '?'.$html_options['query_string'];
unset($html_options['query_string']);
}
if (is_object($name))
{
if (method_exists($name, '__toString'))
{
$name = $name->__toString();
}
else
{
throw new sfException(sprintf('Object of class "%s" cannot be converted to string (Please create a __toString() method)', get_class($name)));
}
}
if (!strlen($name))
{
$name = $html_options['href'];
}
return content_tag('a', $name, $html_options);
}
/**
* If the condition passed as first argument is true,
* creates a <a> link tag of the given name using a routed URL
* based on the module/action passed as argument and the routing configuration.
* If the condition is false, the given name is returned between <span> tags
*
* <b>Options:</b>
* - 'tag' - the HTML tag that must enclose the name if the condition is false, defaults to <span>
* - 'absolute' - if set to true, the helper outputs an absolute URL
* - 'query_string' - to append a query string (starting by ?) to the routed url
* - 'confirm' - displays a javascript confirmation alert when the link is clicked
* - 'popup' - if set to true, the link opens a new browser window
* - 'post' - if set to true, the link submits a POST request instead of GET (caution: do not use inside a form)
*
* <b>Examples:</b>
* <code>
* echo link_to_if($user->isAdministrator(), 'Delete this page', 'my_module/my_action');
* => <a href="/path/to/my/action">Delete this page</a>
* echo link_to_if(!$user->isAdministrator(), 'Delete this page', 'my_module/my_action');
* => <span>Delete this page</span>
* </code>
*
* @param bool condition
* @param string name of the link, i.e. string to appear between the <a> tags
* @param string 'module/action' or '@rule' of the action
* @param array additional HTML compliant <a> tag parameters
* @return string XHTML compliant <a href> tag or name
* @see link_to
*/
function link_to_if($condition, $name = '', $internal_uri = '', $options = array())
{
if ($condition)
{
return link_to($name, $internal_uri, $options);
}
else
{
$html_options = _parse_attributes($options);
unset($html_options['query_string']);
unset($html_options['absolute_url']);
unset($html_options['absolute']);
$tag = _get_option($html_options, 'tag', 'span');
return content_tag($tag, $name, $html_options);
}
}
/**
* If the condition passed as first argument is false,
* creates a <a> link tag of the given name using a routed URL
* based on the module/action passed as argument and the routing configuration.
* If the condition is true, the given name is returned between <span> tags
*
* <b>Options:</b>
* - 'tag' - the HTML tag that must enclose the name if the condition is true, defaults to <span>
* - 'absolute' - if set to true, the helper outputs an absolute URL
* - 'query_string' - to append a query string (starting by ?) to the routed url
* - 'confirm' - displays a javascript confirmation alert when the link is clicked
* - 'popup' - if set to true, the link opens a new browser window
* - 'post' - if set to true, the link submits a POST request instead of GET (caution: do not use inside a form)
*
* <b>Examples:</b>
* <code>
* echo link_to_unless($user->isAdministrator(), 'Delete this page', 'my_module/my_action');
* => <span>Delete this page</span>
* echo link_to_unless(!$user->isAdministrator(), 'Delete this page', 'my_module/my_action');
* => <a href="/path/to/my/action">Delete this page</a>
* </code>
*
* @param bool condition
* @param string name of the link, i.e. string to appear between the <a> tags
* @param string 'module/action' or '@rule' of the action
* @param array additional HTML compliant <a> tag parameters
* @return string XHTML compliant <a href> tag or name
* @see link_to
*/
function link_to_unless($condition, $name = '', $url = '', $options = array())
{
return link_to_if(!$condition, $name, $url, $options);
}
/**
* Creates an <input> button tag of the given name pointing to a routed URL
* based on the module/action passed as argument and the routing configuration.
* The syntax is similar to the one of link_to.
*
* <b>Options:</b>
* - 'absolute' - if set to true, the helper outputs an absolute URL
* - 'query_string' - to append a query string (starting by ?) to the routed url
* - 'confirm' - displays a javascript confirmation alert when the button is clicked
* - 'popup' - if set to true, the button opens a new browser window
* - 'post' - if set to true, the button submits a POST request instead of GET (caution: do not use inside a form)
*
* <b>Examples:</b>
* <code>
* echo button_to('Delete this page', 'my_module/my_action');
* => <input value="Delete this page" type="button" onclick="document.location.href='/path/to/my/action';" />
* </code>
*
* @param string name of the button
* @param string 'module/action' or '@rule' of the action
* @param array additional HTML compliant <input> tag parameters
* @return string XHTML compliant <input> tag
* @see url_for, link_to
*/
function button_to($name, $internal_uri, $options = array())
{
$html_options = _convert_options($options);
$html_options['value'] = $name;
if (isset($html_options['post']) && $html_options['post'])
{
if (isset($html_options['popup']))
{
throw new sfConfigurationException('You can\'t use "popup" and "post" together');
}
$html_options['type'] = 'submit';
unset($html_options['post']);
$html_options = _convert_options_to_javascript($html_options);
return form_tag($internal_uri, array('method' => 'post', 'class' => 'button_to')).tag('input', $html_options).'</form>';
}
else if (isset($html_options['popup']))
{
$html_options['type'] = 'button';
$html_options = _convert_options_to_javascript($html_options, $internal_uri);
return tag('input', $html_options);
}
else
{
$html_options['type'] = 'button';
$html_options['onclick'] = "document.location.href='".url_for($internal_uri)."';";
$html_options = _convert_options_to_javascript($html_options);
return tag('input', $html_options);
}
}
/**
* Creates a <a> link tag to the given email (with href="mailto:...").
* If null is passed as a name, the email itself will become the name.
*
* <b>Options:</b>
* - 'encode' - if set to true, the email address appears with various random encoding for each letter.
* The mail link still works when encoded, but the address doesn't appear in clear
* in the source. Use it to prevent spam (efficiency not guaranteed).
*
* <b>Examples:</b>
* <code>
* echo mail_to('webmaster@example.com');
* => <a href="mailto:webmaster@example.com">webmaster@example.com</a>
* echo mail_to('webmaster@example.com', 'send us an email');
* => <a href="mailto:webmaster@example.com">send us an email</a>
* echo mail_to('webmaster@example.com', 'send us an email', array('encode' => true));
* => <a href="&#x6d;a&#x69;&#x6c;&#x74;&#111;&#58;&#x77;&#x65;b&#x6d;as&#116;&#x65;&#114;&#64;&#101;&#x78;&#x61;&#x6d;&#x70;&#108;&#x65;&#46;&#99;&#x6f;&#109;">send us an email</a>
* </code>
*
* @param string target email
* @param string name of the link, i.e. string to appear between the <a> tags
* @param array additional HTML compliant <a> tag parameters
* @return string XHTML compliant <a href> tag
* @see link_to
*/
function mail_to($email, $name = '', $options = array(), $default_value = array())
{
$html_options = _parse_attributes($options);
$html_options = _convert_options_to_javascript($html_options);
$default_tmp = _parse_attributes($default_value);
$default = array();
foreach ($default_tmp as $key => $value)
{
$default[] = urlencode($key).'='.urlencode($value);
}
$options = count($default) ? '?'.implode('&', $default) : '';
if (isset($html_options['encode']) && $html_options['encode'])
{
unset($html_options['encode']);
$html_options['href'] = _encodeText('mailto:'.$email.$options);
if (!$name)
{
$name = _encodeText($email);
}
}
else
{
$html_options['href'] = 'mailto:'.$email.$options;
if (!$name)
{
$name = $email;
}
}
return content_tag('a', $name, $html_options);
}
function _convert_options_to_javascript($html_options, $internal_uri = '')
{
// confirm
$confirm = isset($html_options['confirm']) ? $html_options['confirm'] : '';
unset($html_options['confirm']);
// popup
$popup = isset($html_options['popup']) ? $html_options['popup'] : '';
unset($html_options['popup']);
// post
$post = isset($html_options['post']) ? $html_options['post'] : '';
unset($html_options['post']);
$onclick = isset($html_options['onclick']) ? $html_options['onclick'] : '';
if ($popup && $post)
{
throw new sfConfigurationException('You can\'t use "popup" and "post" in the same link');
}
else if ($confirm && $popup)
{
$html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._popup_javascript_function($popup, $internal_uri).' };return false;';
}
else if ($confirm && $post)
{
$html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._post_javascript_function().' };return false;';
}
else if ($confirm)
{
if ($onclick)
{
$html_options['onclick'] = 'if ('._confirm_javascript_function($confirm).') {'.$onclick.'}';
}
else
{
$html_options['onclick'] = 'return '._confirm_javascript_function($confirm).';';
}
}
else if ($post)
{
$html_options['onclick'] = $onclick._post_javascript_function().'return false;';
}
else if ($popup)
{
$html_options['onclick'] = $onclick._popup_javascript_function($popup, $internal_uri).'return false;';
}
return $html_options;
}
function _confirm_javascript_function($confirm)
{
return "confirm('".escape_javascript($confirm)."')";
}
function _popup_javascript_function($popup, $internal_uri = '')
{
$url = $internal_uri == '' ? 'this.href' : "'".url_for($internal_uri)."'";
if (is_array($popup))
{
if (isset($popup[1]))
{
return "var w=window.open(".$url.",'".$popup[0]."','".$popup[1]."');w.focus();";
}
else
{
return "var w=window.open(".$url.",'".$popup[0]."');w.focus();";
}
}
else
{
return "var w=window.open(".$url.");w.focus();";
}
}
function _post_javascript_function()
{
return "f = document.createElement('form'); document.body.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit();";
}
function _encodeText($text)
{
$encoded_text = '';
for ($i = 0; $i < strlen($text); $i++)
{
$char = $text{$i};
$r = rand(0, 100);
# roughly 10% raw, 45% hex, 45% dec
# '@' *must* be encoded. I insist.
if ($r > 90 && $char != '@')
{
$encoded_text .= $char;
}
else if ($r < 45)
{
$encoded_text .= '&#x'.dechex(ord($char)).';';
}
else
{
$encoded_text .= '&#'.ord($char).';';
}
}
return $encoded_text;
}

View File

@ -0,0 +1,63 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* ValidationHelper.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: ValidationHelper.php 1553 2006-06-29 19:26:04Z fabien $
*/
function form_has_error($param)
{
return sfContext::getInstance()->getRequest()->hasError($param);
}
function form_error($param, $options = array(), $catalogue = 'messages')
{
$param_for_sf = str_replace(array('[', ']'), array('{', '}'), $param);
$param = str_replace(array('{', '}'), array('[', ']'), $param);
$options = _parse_attributes($options);
$request = sfContext::getInstance()->getRequest();
$style = $request->hasError($param_for_sf) ? '' : 'display:none;';
$options['style'] = $style.(isset($options['style']) ? $options['style']:'');
if (!isset($options['class']))
{
$options['class'] = sfConfig::get('sf_validation_error_class', 'form_error');
}
if (!isset($options['id']))
{
$options['id'] = sfConfig::get('sf_validation_error_id_prefix', 'error_for_').get_id_from_name($param);
}
$prefix = sfConfig::get('sf_validation_error_prefix', '');
if (isset($options['prefix']))
{
$prefix = $options['prefix'];
unset($options['prefix']);
}
$suffix = sfConfig::get('sf_validation_error_suffix', '');
if (isset($options['suffix']))
{
$suffix = $options['suffix'];
unset($options['suffix']);
}
$error = $request->getError($param_for_sf, $catalogue);
return content_tag('div', $prefix.$error.$suffix, $options)."\n";
}

View File

@ -0,0 +1,46 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* sfRichTextEditor is an abstract class for rich text editor classes.
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: sfRichTextEditor.class.php 3284 2007-01-15 19:05:48Z fabien $
*/
abstract class sfRichTextEditor
{
protected
$name = '',
$content = '',
$options = array();
/**
* Initializes this rich text editor.
*
* @param string The tag name
* @param string The rich text editor content
* @param array An array of options
*/
public function initialize($name, $content, $options = array())
{
$this->name = $name;
$this->content = $content;
$this->options = $options;
}
/**
* Returns the rich text editor as HTML.
*
* @return string Rich text editor HTML representation
*/
abstract public function toHTML();
}

View File

@ -0,0 +1,91 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* sfRichTextEditorFCK implements the FCK rich text editor.
*
* <b>Options:</b>
* - tool - Sets the FCKEditor toolbar style
* - config - Sets custom path to the FCKEditor configuration file
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: sfRichTextEditorFCK.class.php 3284 2007-01-15 19:05:48Z fabien $
*/
class sfRichTextEditorFCK extends sfRichTextEditor
{
/**
* Returns the rich text editor as HTML.
*
* @return string Rich text editor HTML representation
*/
public function toHTML()
{
$options = $this->options;
// we need to know the id for things the rich text editor
// in advance of building the tag
$id = _get_option($options, 'id', $this->name);
$php_file = sfConfig::get('sf_rich_text_fck_js_dir').DIRECTORY_SEPARATOR.'fckeditor.php';
if (!is_readable(sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.$php_file))
{
throw new sfConfigurationException('You must install FCKEditor to use this helper (see rich_text_fck_js_dir settings).');
}
// FCKEditor.php class is written with backward compatibility of PHP4.
// This reportings are to turn off errors with public properties and already declared constructor
$error_reporting = ini_get('error_reporting');
error_reporting(E_ALL);
require_once(sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.$php_file);
// turn error reporting back to your settings
error_reporting($error_reporting);
$fckeditor = new FCKeditor($this->name);
$fckeditor->BasePath = sfContext::getInstance()->getRequest()->getRelativeUrlRoot().'/'.sfConfig::get('sf_rich_text_fck_js_dir').'/';
$fckeditor->Value = $this->content;
if (isset($options['width']))
{
$fckeditor->Width = $options['width'];
}
elseif (isset($options['cols']))
{
$fckeditor->Width = (string)((int) $options['cols'] * 10).'px';
}
if (isset($options['height']))
{
$fckeditor->Height = $options['height'];
}
elseif (isset($options['rows']))
{
$fckeditor->Height = (string)((int) $options['rows'] * 10).'px';
}
if (isset($options['tool']))
{
$fckeditor->ToolbarSet = $options['tool'];
}
if (isset($options['config']))
{
$fckeditor->Config['CustomConfigurationsPath'] = javascript_path($options['config']);
}
$content = $fckeditor->CreateHtml();
return $content;
}
}

View File

@ -0,0 +1,114 @@
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* sfRichTextEditorTinyMCE implements the TinyMCE rich text editor.
*
* <b>Options:</b>
* - css - Path to the TinyMCE editor stylesheet
*
* <b>Css example:</b>
* <code>
* / * user: foo * / => without spaces. 'foo' is the name in the select box
* .foobar
* {
* color: #f00;
* }
* </code>
*
* @package symfony
* @subpackage helper
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: sfRichTextEditorTinyMCE.class.php 3284 2007-01-15 19:05:48Z fabien $
*/
class sfRichTextEditorTinyMCE extends sfRichTextEditor
{
/**
* Returns the rich text editor as HTML.
*
* @return string Rich text editor HTML representation
*/
public function toHTML()
{
$options = $this->options;
// we need to know the id for things the rich text editor
// in advance of building the tag
$id = _get_option($options, 'id', $this->name);
// use tinymce's gzipped js?
$tinymce_file = _get_option($options, 'tinymce_gzip') ? '/tiny_mce_gzip.php' : '/tiny_mce.js';
// tinymce installed?
$js_path = sfConfig::get('sf_rich_text_js_dir') ? '/'.sfConfig::get('sf_rich_text_js_dir').$tinymce_file : '/sf/tinymce/js'.$tinymce_file;
if (!is_readable(sfConfig::get('sf_web_dir').$js_path))
{
throw new sfConfigurationException('You must install TinyMCE to use this helper (see rich_text_js_dir settings).');
}
sfContext::getInstance()->getResponse()->addJavascript($js_path);
use_helper('Javascript');
$tinymce_options = '';
$style_selector = '';
// custom CSS file?
if ($css_file = _get_option($options, 'css'))
{
$css_path = stylesheet_path($css_file);
sfContext::getInstance()->getResponse()->addStylesheet($css_path);
$css = file_get_contents(sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.$css_path);
$styles = array();
preg_match_all('#^/\*\s*user:\s*(.+?)\s*\*/\s*\015?\012\s*\.([^\s]+)#Smi', $css, $matches, PREG_SET_ORDER);
foreach ($matches as $match)
{
$styles[] = $match[1].'='.$match[2];
}
$tinymce_options .= ' content_css: "'.$css_path.'",'."\n";
$tinymce_options .= ' theme_advanced_styles: "'.implode(';', $styles).'"'."\n";
$style_selector = 'styleselect,separator,';
}
$culture = sfContext::getInstance()->getUser()->getCulture();
$tinymce_js = '
tinyMCE.init({
mode: "exact",
language: "'.strtolower(substr($culture, 0, 2)).'",
elements: "'.$id.'",
plugins: "table,advimage,advlink,flash",
theme: "advanced",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_path_location: "bottom",
theme_advanced_buttons1: "'.$style_selector.'justifyleft,justifycenter,justifyright,justifyfull,separator,bold,italic,strikethrough,separator,sub,sup,separator,charmap",
theme_advanced_buttons2: "bullist,numlist,separator,outdent,indent,separator,undo,redo,separator,link,unlink,image,flash,separator,cleanup,removeformat,separator,code",
theme_advanced_buttons3: "tablecontrols",
extended_valid_elements: "img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name]",
relative_urls: false,
debug: false
'.($tinymce_options ? ','.$tinymce_options : '').'
'.(isset($options['tinymce_options']) ? ','.$options['tinymce_options'] : '').'
});';
if (isset($options['tinymce_options']))
{
unset($options['tinymce_options']);
}
return
content_tag('script', javascript_cdata_section($tinymce_js), array('type' => 'text/javascript')).
content_tag('textarea', $this->content, array_merge(array('name' => $this->name, 'id' => get_id_from_name($id, null)), _convert_options($options)));
}
}