本文整理汇总了PHP中SpoonFilter::getValue方法的典型用法代码示例。如果您正苦于以下问题:PHP SpoonFilter::getValue方法的具体用法?PHP SpoonFilter::getValue怎么用?PHP SpoonFilter::getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpoonFilter
的用法示例。
在下文中一共展示了SpoonFilter::getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getData
/**
* Load the data, don't forget to validate the incoming data
*
* @return void
*/
private function getData()
{
// get categories
$categories = FrontendBlogModel::getAllCategories();
$possibleCategories = array();
foreach ($categories as $category) {
$possibleCategories[$category['url']] = $category['id'];
}
// requested category
$requestedCategory = SpoonFilter::getValue($this->URL->getParameter(1, 'string'), array_keys($possibleCategories), 'false');
// requested page
$requestedPage = $this->URL->getParameter('page', 'int', 1);
// validate category
if ($requestedCategory == 'false') {
$this->redirect(FrontendNavigation::getURL(404));
}
// set category
$this->category = $categories[$possibleCategories[$requestedCategory]];
// set URL and limit
$this->pagination['url'] = FrontendNavigation::getURLForBlock('blog', 'category') . '/' . $requestedCategory;
$this->pagination['limit'] = FrontendModel::getModuleSetting('blog', 'overview_num_items', 10);
// populate count fields in pagination
$this->pagination['num_items'] = FrontendBlogModel::getAllForCategoryCount($requestedCategory);
$this->pagination['num_pages'] = (int) ceil($this->pagination['num_items'] / $this->pagination['limit']);
// redirect if the request page doesn't exists
if ($requestedPage > $this->pagination['num_pages'] || $requestedPage < 1) {
$this->redirect(FrontendNavigation::getURL(404));
}
// populate calculated fields in pagination
$this->pagination['requested_page'] = $requestedPage;
$this->pagination['offset'] = $this->pagination['requested_page'] * $this->pagination['limit'] - $this->pagination['limit'];
// get articles
$this->items = FrontendBlogModel::getAllForCategory($requestedCategory, $this->pagination['limit'], $this->pagination['offset']);
}
示例2: loadData
/**
* Load necessary data.
*
* @return void.
*/
private function loadData()
{
// get data
$this->selectedTheme = $this->getParameter('theme', 'string');
// build available themes
$this->availableThemes = BackendModel::getThemes();
// determine selected theme, based upon submitted form or default theme
$this->selectedTheme = SpoonFilter::getValue($this->selectedTheme, array_keys($this->availableThemes), BackendModel::getModuleSetting('core', 'theme', 'core'));
}
示例3: loadData
/**
* Load the selected theme, falling back to default if none specified.
*/
private function loadData()
{
// get data
$this->selectedTheme = $this->getParameter('theme', 'string');
// build available themes
foreach (Model::getThemes() as $theme) {
$this->availableThemes[$theme['value']] = $theme['label'];
}
// determine selected theme, based upon submitted form or default theme
$this->selectedTheme = \SpoonFilter::getValue($this->selectedTheme, array_keys($this->availableThemes), $this->get('fork.settings')->get('Core', 'theme', 'core'));
}
示例4: redirect
/**
* Redirect the browser with an optional delay and stop script execution.
*
* @return void
* @param string $URL The URL.
* @param int[optional] $code The redirect code.
* @param int[optional] $delay A delay, expressed in seconds.
*/
public static function redirect($URL, $code = 302, $delay = null)
{
// redefine url
$URL = (string) $URL;
$code = SpoonFilter::getValue($code, array(301, 302), 302, 'int');
// redirect headers
self::setHeadersByCode($code);
// delay execution
if ($delay !== null) {
sleep((int) $delay);
}
// redirect
self::setHeaders("Location: {$URL}");
// stop execution
exit;
}
示例5: testGetValue
public function testGetValue()
{
// setup
$id = '1337';
$type = 'web';
$animal = 'donkey';
$animals = array('1337', 'web', 'donkey');
// perform tests
$this->assertEquals(1337, SpoonFilter::getValue($id, null, 0, 'int'));
$this->assertEquals('web', SpoonFilter::getValue($type, array('web', 'print'), 'print'));
$this->assertEquals('whale', SpoonFilter::getValue($animal, array('whale', 'horse'), 'whale'));
$this->assertEquals('donkey', SpoonFilter::getValue($animal, null, 'whale'));
$this->assertEquals(array('1337', 'web', 'donkey'), SpoonFilter::getValue($animals, null, null, 'array'));
$this->assertEquals(array('1337', 'web'), SpoonFilter::getValue($animals, array('1337', 'web'), array('soep'), 'array'));
$this->assertEquals(array('soep'), SpoonFilter::getValue(array('blikken doos'), array('1337', 'web'), array('soep'), 'array'));
}
示例6: write
/**
* Write an error/custom message to the log.
*
* @return void
* @param string $message The messages that should be logged.
* @param string[optional] $type The type of message you want to log, possible values are: error, custom.
*/
public static function write($message, $type = 'error')
{
// milliseconds
list($milliseconds) = explode(' ', microtime());
$milliseconds = round($milliseconds * 1000, 0);
// redefine var
$message = date('Y-m-d H:i:s') . ' ' . $milliseconds . 'ms | ' . $message . "\n";
$type = SpoonFilter::getValue($type, array('error', 'custom'), 'error');
// file
$file = self::getPath() . '/' . $type . '.log';
// rename if needed
if ((int) @filesize($file) >= self::MAX_FILE_SIZE * 1024) {
// start new log file
SpoonDirectory::move($file, $file . '.' . date('Ymdhis'));
}
// write content
SpoonFile::setContent($file, $message, true, true);
}
示例7: isFilesize
/**
* Checks of the filesize is greater, equal or smaller than the given number + units.
*
* @return bool
* @param int $size The size to use in the check.
* @param string[optional] $unit The unit to use.
* @param string[optional] $operator The operator to use, possible values are: smaller, equal, greater.
* @param string[optional] $error The error message to set.
*/
public function isFilesize($size, $unit = 'kb', $operator = 'smaller', $error = null)
{
// file has been uploaded
if ($this->isFilled()) {
// define size
$actualSize = $this->getFileSize($unit, 0);
// operator
$operator = SpoonFilter::getValue(strtolower($operator), array('smaller', 'equal', 'greater'), 'smaller');
// smaller
if ($operator == 'smaller' && $actualSize < $size) {
return true;
}
// equal
if ($operator == 'equal' && $actualSize == $size) {
return true;
}
// greater
if ($operator == 'greater' && $actualSize > $size) {
return true;
}
}
// has error
if ($error !== null) {
$this->setError($error);
}
return false;
}
示例8: getWeekDays
/**
* Retrieve the days of the week in a specified language.
*
* @return array An array with all the days in the requested language.
* @param string[optional] $language The language to use (available languages can be found in SpoonLocale).
* @param bool[optional] $abbreviated Should the days be abbreviated?
* @param string[optional] $firstDay First day of the week (available options: monday, sunday).
*/
public static function getWeekDays($language = 'en', $abbreviated = false, $firstDay = 'monday')
{
// init vars
$language = SpoonFilter::getValue($language, self::$languages, 'en');
$firstDay = SpoonFilter::getValue($firstDay, array('monday', 'sunday'), 'monday');
$locale = array();
// fetch file
require 'data/' . $language . '.php';
// data array
$days = $abbreviated ? $locale['date']['days']['abbreviated'] : $locale['date']['days']['full'];
// in some regions monday is not the first day of the week.
if ($firstDay == 'monday') {
$sunday = $days['sun'];
unset($days['sun']);
$days['sun'] = $sunday;
}
return $days;
}
示例9: setColumn
/**
* Set column for the widget
*
* @param string $column Possible values are: left, middle, right.
*/
protected function setColumn($column)
{
$allowedColumns = array('left', 'middle', 'right');
$this->column = \SpoonFilter::getValue((string) $column, $allowedColumns, 'left');
}
示例10: setSortingMethod
/**
* Set the sorting method.
*
* @param string[optional] $sortingMethod Set the sorting method that should be used, possible values are: desc, asc.
*/
public function setSortingMethod($sortingMethod = 'desc')
{
$aAllowedSortingMethods = array('asc', 'desc');
// set sorting method
self::$sortingMethod = SpoonFilter::getValue($sortingMethod, $aAllowedSortingMethods, 'desc');
}
示例11: processQueryString
/**
* Process the querystring
*/
private function processQueryString()
{
// store the querystring local, so we don't alter it.
$queryString = $this->getQueryString();
// find the position of ? (which separates real URL and GET-parameters)
$positionQuestionMark = mb_strpos($queryString, '?');
// separate the GET-chunk from the parameters
$getParameters = '';
if ($positionQuestionMark === false) {
$processedQueryString = $queryString;
} else {
$processedQueryString = mb_substr($queryString, 0, $positionQuestionMark);
$getParameters = mb_substr($queryString, $positionQuestionMark);
}
// split into chunks, a Backend URL will always look like /<lang>/<module>/<action>(?GET)
$chunks = (array) explode('/', trim($processedQueryString, '/'));
// check if this is a request for a AJAX-file
$isAJAX = isset($chunks[1]) && $chunks[1] == 'ajax';
// get the language, this will always be in front
$language = '';
if (isset($chunks[1]) && $chunks[1] != '') {
$language = \SpoonFilter::getValue($chunks[1], array_keys(BackendLanguage::getWorkingLanguages()), '');
}
// no language provided?
if ($language == '' && !$isAJAX) {
// remove first element
array_shift($chunks);
// redirect to login
$this->redirect('/' . NAMED_APPLICATION . '/' . SITE_DEFAULT_LANGUAGE . (empty($chunks) ? '' : '/') . implode('/', $chunks) . $getParameters);
}
// get the module, null will be the default
$module = isset($chunks[2]) && $chunks[2] != '' ? $chunks[2] : 'Dashboard';
$module = \SpoonFilter::toCamelCase($module);
// get the requested action, if it is passed
if (isset($chunks[3]) && $chunks[3] != '') {
$action = \SpoonFilter::toCamelCase($chunks[3]);
} elseif (!$isAJAX) {
// Check if we can load the config file
$configClass = 'Backend\\Modules\\' . $module . '\\Config';
if ($module == 'Core') {
$configClass = 'Backend\\Core\\Config';
}
try {
// when loading a backend url for a module that doesn't exist, without
// providing an action, a FatalErrorException occurs, because the config
// class we're trying to load doesn't exist. Let's just throw instead,
// and catch it immediately.
if (!class_exists($configClass)) {
throw new Exception('The config class does not exist');
}
/** @var BackendBaseConfig $config */
$config = new $configClass($this->getKernel(), $module);
// set action
$action = $config->getDefaultAction() !== null ? $config->getDefaultAction() : 'Index';
} catch (Exception $ex) {
if (BackendModel::getContainer()->getParameter('kernel.debug')) {
throw new Exception('The config file for the module (' . $module . ') can\'t be found.');
} else {
// @todo don't use redirects for error, we should have something like an invoke method.
// build the url
$errorUrl = '/' . NAMED_APPLICATION . '/' . $language . '/error?type=action-not-allowed';
// add the querystring, it will be processed by the error-handler
$errorUrl .= '&querystring=' . rawurlencode('/' . $this->getQueryString());
// redirect to the error page
$this->redirect($errorUrl, 307);
}
}
}
// AJAX parameters are passed via GET or POST
if ($isAJAX) {
$module = isset($_GET['fork']['module']) ? $_GET['fork']['module'] : '';
$action = isset($_GET['fork']['action']) ? $_GET['fork']['action'] : '';
$language = isset($_GET['fork']['language']) ? $_GET['fork']['language'] : SITE_DEFAULT_LANGUAGE;
$module = isset($_POST['fork']['module']) ? $_POST['fork']['module'] : $module;
$action = isset($_POST['fork']['action']) ? $_POST['fork']['action'] : $action;
$language = isset($_POST['fork']['language']) ? $_POST['fork']['language'] : $language;
$this->setModule($module);
$this->setAction($action);
BackendLanguage::setWorkingLanguage($language);
} else {
$this->processRegularRequest($module, $action, $language);
}
}
示例12: getTemplates
/**
* Get templates
*
* @param string[optional] $theme The theme we want to fetch the templates from.
* @return array
*/
public static function getTemplates($theme = null)
{
// get db
$db = BackendModel::getDB();
// validate input
$theme = SpoonFilter::getValue((string) $theme, null, BackendModel::getModuleSetting('core', 'theme', 'core'));
// get templates
$templates = (array) $db->getRecords('SELECT i.id, i.label, i.path, i.data
FROM themes_templates AS i
WHERE i.theme = ? AND i.active = ?
ORDER BY i.label ASC', array($theme, 'Y'), 'id');
// get extras
$extras = (array) self::getExtras();
// init var
$half = (int) ceil(count($templates) / 2);
$i = 0;
// loop templates to unserialize the data
foreach ($templates as $key => &$row) {
// unserialize
$row['data'] = unserialize($row['data']);
$row['has_block'] = false;
// reset
if (isset($row['data']['default_extras_' . BL::getWorkingLanguage()])) {
$row['data']['default_extras'] = $row['data']['default_extras_' . BL::getWorkingLanguage()];
}
// any extras?
if (isset($row['data']['default_extras'])) {
// loop extras
foreach ($row['data']['default_extras'] as $value) {
// store if the module has blocks
if (SpoonFilter::isInteger($value) && isset($extras[$value]) && $extras[$value]['type'] == 'block') {
$row['has_block'] = true;
}
}
}
// validate
if (!isset($row['data']['format'])) {
throw new BackendException('Invalid template-format.');
}
// build template HTML
$row['html'] = self::buildTemplateHTML($row['data']['format']);
$row['htmlLarge'] = self::buildTemplateHTML($row['data']['format'], true);
// add all data as json
$row['json'] = json_encode($row);
// add the break-element so the templates can be split in 2 columns in the templatechooser
if ($i == $half) {
$row['break'] = true;
}
// increment
$i++;
}
return (array) $templates;
}
示例13: insertCampaignMonitorID
/**
* Inserts a record into the mailmotor_campaignmonitor_ids table
*
* @param string $type The type of the record.
* @param string $id The id in CampaignMonitor.
* @param string $otherId The id in our tables.
* @return string
*/
public static function insertCampaignMonitorID($type, $id, $otherId)
{
$type = \SpoonFilter::getValue($type, array('campaign', 'list', 'template'), '');
if ($type == '') {
throw new \CampaignMonitorException('No valid CM ID type given (only campaign, list, template).');
}
BackendModel::getContainer()->get('database')->insert('mailmotor_campaignmonitor_ids', array('type' => $type, 'cm_id' => $id, 'other_id' => $otherId));
}
示例14: getMailingPreviewURL
/**
* Get a preview URL to the specific mailing
*
* @param int $id The id of the mailing.
* @param string $contentType The content-type to set.
* @param bool $forCM Will this URL be used in Campaign Monitor?
* @return string
*/
public static function getMailingPreviewURL($id, $contentType = 'html', $forCM = false)
{
// check input
$contentType = \SpoonFilter::getValue($contentType, array('html', 'plain'), 'html');
$forCM = \SpoonFilter::getValue($forCM, array(false, true), false, 'int');
// return the URL
return SITE_URL . FrontendNavigation::getURLForBlock('Mailmotor', 'Detail') . '/' . $id . '?type=' . $contentType . ($forCM == 1 ? '&cm=' . $forCM : '');
}
示例15: getTimeAgo
/**
* Fetch the time ago as a language dependant sentence.
*
* @return string String containing a sentence like 'x minutes ago'
* @param int $timestamp Timestamp you want to make a sentence of.
* @param string[optional] $language Language to use, check SpoonLocale::getAvailableLanguages().
* @param string[optional] $format The format to return if the time passed is greather then a week.
*/
public static function getTimeAgo($timestamp, $language = 'en', $format = null)
{
// init vars
$timestamp = (int) $timestamp;
$language = SpoonFilter::getValue($language, SpoonLocale::getAvailableLanguages(), 'en', 'string');
$locale = array();
// fetch language
if (!isset(self::$locales[$language])) {
require 'spoon/locale/data/' . $language . '.php';
self::$locales[$language] = $locale;
}
$locale = self::$locales[$language];
// get seconds between given timestamp and current timestamp
$secondsBetween = time() - $timestamp;
// calculate years ago
$yearsAgo = floor($secondsBetween / (365.242199 * 24 * 60 * 60));
if ($yearsAgo > 1 && $format === null) {
return sprintf($locale['time']['YearsAgo'], $yearsAgo);
}
if ($yearsAgo == 1 && $format === null) {
return $locale['time']['YearAgo'];
}
if ($yearsAgo >= 1 && $format !== null) {
return self::getDate($format, $timestamp, $language);
}
// calculate months ago
$monthsAgo = floor($secondsBetween / (365.242199 / 12 * 24 * 60 * 60));
if ($monthsAgo > 1 && $format === null) {
return sprintf($locale['time']['MonthsAgo'], $monthsAgo);
}
if ($monthsAgo == 1 && $format === null) {
return $locale['time']['MonthAgo'];
}
if ($monthsAgo >= 1 && $format !== null) {
return self::getDate($format, $timestamp, $language);
}
// calculate weeks ago
$weeksAgo = floor($secondsBetween / (7 * 24 * 60 * 60));
if ($weeksAgo > 1 && $format === null) {
return sprintf($locale['time']['WeeksAgo'], $weeksAgo);
}
if ($weeksAgo == 1 && $format === null) {
return $locale['time']['WeekAgo'];
}
if ($weeksAgo >= 1 && $format !== null) {
return self::getDate($format, $timestamp, $language);
}
// calculate days ago
$daysAgo = floor($secondsBetween / (24 * 60 * 60));
if ($daysAgo > 1) {
return sprintf($locale['time']['DaysAgo'], $daysAgo);
}
if ($daysAgo == 1) {
return $locale['time']['DayAgo'];
}
// calculate hours ago
$hoursAgo = floor($secondsBetween / (60 * 60));
if ($hoursAgo > 1) {
return sprintf($locale['time']['HoursAgo'], $hoursAgo);
}
if ($hoursAgo == 1) {
return $locale['time']['HourAgo'];
}
// calculate minutes ago
$minutesAgo = floor($secondsBetween / 60);
if ($minutesAgo > 1) {
return sprintf($locale['time']['MinutesAgo'], $minutesAgo);
}
if ($minutesAgo == 1) {
return $locale['time']['MinuteAgo'];
}
// calculate seconds ago
$secondsAgo = floor($secondsBetween);
if ($secondsAgo > 1) {
return sprintf($locale['time']['SecondsAgo'], $secondsAgo);
}
if ($secondsAgo <= 1) {
return $locale['time']['SecondAgo'];
}
}