本文整理汇总了PHP中Sintattica\Atk\Core\Tools类的典型用法代码示例。如果您正苦于以下问题:PHP Tools类的具体用法?PHP Tools怎么用?PHP Tools使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tools类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: nodeCopy
/**
* Copies a record, based on parameters passed in the url.
*/
public function nodeCopy()
{
Tools::atkdebug('CopyHandler::nodeCopy()');
$recordset = $this->m_node->select($this->m_postvars['atkselector'])->mode('copy')->getAllRows();
$db = $this->m_node->getDb();
if (count($recordset) > 0) {
// allowed to copy record?
if (!$this->allowed($recordset[0])) {
$this->renderAccessDeniedPage();
return;
}
if (!$this->m_node->copyDb($recordset[0])) {
Tools::atkdebug('node::action_copy() -> Error');
$db->rollback();
$location = $this->m_node->feedbackUrl('save', self::ACTION_FAILED, $recordset[0], $db->getErrorMsg());
Tools::atkdebug('node::action_copy() -> Redirect');
$this->m_node->redirect($location);
} else {
$db->commit();
$this->notify('copy', $recordset[0]);
$this->clearCache();
}
}
$this->m_node->redirect();
}
示例2: registerChangeHandler
/**
* Register change handler.
*
* @param string $mode
* @param string $prefix
*/
protected function registerChangeHandler($mode, $prefix)
{
$mode = $mode == 'add' ? 'add' : 'edit';
$url = addslashes(Tools::partial_url($this->m_shuttle->m_ownerInstance->atkNodeUri(), $mode, 'attribute.' . $this->m_shuttle->getHtmlId($prefix) . '.filter', array('atkfieldprefix' => $prefix)));
$page = $this->m_shuttle->m_ownerInstance->getPage();
$page->register_scriptcode('function ' . $this->getChangeHandlerName($prefix) . "(el)\n {\n shuttle_refresh('" . $url . "', '" . $this->m_shuttle->getHtmlId($prefix) . '[cselected][][' . $this->m_shuttle->getRemoteKey() . ']' . "', '" . $prefix . $this->m_shuttle->fieldName() . "[section]', '" . $this->m_section . "')\n }\n");
}
示例3: smarty_function_atktext
/**
* function to get multilanguage strings.
*
* This is actually a wrapper for ATK's Tools::atktext() method, for
* use in templates.
*
* @author Ivo Jansch <ivo@achievo.org>
*
* Example: {atktext id="users.userinfo.description"}
* {atktext id="userinfo.description" module="users"}
* {atktext id="description" module="users" node="userinfo"}
*/
function smarty_function_atktext($params, $smarty)
{
if (!isset($params['id'])) {
$params['id'] = $params[0];
}
switch (substr_count($params['id'], '.')) {
case 1:
list($module, $id) = explode('.', $params['id']);
$str = Tools::atktext($id, $module, isset($params['node']) ? $params['node'] : '');
break;
case 2:
list($module, $node, $id) = explode('.', $params['id']);
$str = Tools::atktext($id, $module, $node);
break;
default:
$str = Tools::atktext($params['id'], Tools::atkArrayNvl($params, 'module', ''), Tools::atkArrayNvl($params, 'node', ''), Tools::atkArrayNvl($params, 'lng', ''));
}
if (isset($params['filter'])) {
$fn = $params['filter'];
$str = $fn($str);
}
// parse the rest of the params in the string
$parser = new StringParser($str);
return $parser->parse($params);
}
示例4: smarty_function_atkdatefield
/**
* Function for embedding a date control in html.
*
* @author Peter C. Verhage <peter@ibuildings.nl>
*/
function smarty_function_atkdatefield($params, $smarty)
{
$name = isset($params['name']) ? $params['name'] : 'date';
$format = isset($params['format']) ? $params['format'] : Tools::atktext('date_format_edit', 'atk', '', '', '', true);
$mandatory = isset($params['mandatory']) && $params['mandatory'] || isset($params['obligatory']) && $params['obligatory'];
$noweekday = isset($params['noweekday']) && $params['noweekday'];
$calendar = isset($params['calendar']) && $params['calendar'];
$time = isset($params['time']) ? $params['time'] : ($mandatory ? mktime() : null);
$min = isset($params['min']) ? $params['min'] : 0;
$max = isset($params['max']) ? $params['max'] : 0;
if (is_array($time)) {
$date = $time;
} else {
if ($time == null) {
$date = null;
} else {
if (is_numeric($time)) {
$date = getdate($time);
$date = array('day' => $date['mday'], 'month' => $date['mon'], 'year' => $date['year']);
} else {
if (preg_match('/([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})/', $time, $matches)) {
$date = array('day' => (int) $matches[1], 'month' => (int) $matches[2], 'year' => $matches[3]);
} else {
$date = getdate(strtotime($time));
$date = array('day' => $date['mday'], 'month' => $date['mon'], 'year' => $date['year']);
}
}
}
}
$attr = new DateAttribute($name, $format, '', $min, $max, ($noweekday ? DateAttribute::AF_DATE_EDIT_NO_DAY : 0) | ($mandatory ? Attribute::AF_OBLIGATORY : 0) | ($calendar ? 0 : DateAttribute::AF_DATE_NO_CALENDAR));
$html = $attr->edit(array($name => $date), '', '');
return $html;
}
示例5: getMenuTranslation
/**
* Translates a menuitem with the menu_ prefix, or if not found without.
*
* @param string $menuitem Menuitem to translate
* @param string $modname Module to which the menuitem belongs
*
* @return string Translation of the given menuitem
*/
public function getMenuTranslation($menuitem, $modname = 'atk')
{
$s = Tools::atktext("menu_{$menuitem}", $modname, '', '', '', true);
if (!$s) {
$s = Tools::atktext($menuitem, $modname);
}
return $s;
}
示例6: getInstance
/**
* get a singleton instance of the Ui class.
*
* @return Ui
*/
public static function getInstance()
{
static $s_instance = null;
if ($s_instance == null) {
Tools::atkdebug('Creating a new Ui instance');
$s_instance = new self();
}
return $s_instance;
}
示例7: convertFlags
/**
* Converts the given node flags to recordlist flags where possible.
*
* @param int $flags
* @static
*
* @return int
*/
public function convertFlags($flags)
{
$result = Tools::hasFlag($flags, Node::NF_MRA) ? self::RL_MRA : 0;
$result |= Tools::hasFlag($flags, Node::NF_MRPA) ? self::RL_MRPA : 0;
$result |= Tools::hasFlag($flags, Node::NF_NO_SEARCH) ? self::RL_NO_SEARCH : 0;
$result |= Tools::hasFlag($flags, Node::NF_NO_EXTENDED_SEARCH) ? self::RL_NO_EXTENDED_SEARCH : 0;
$result |= Tools::hasFlag($flags, Node::NF_EXT_SORT) ? self::RL_EXT_SORT : 0;
return $result;
}
示例8: notify
/**
* Notify the listener of any action on a record.
*
* This method is called by the framework for each action called on a
* node. Depending on the actionfilter passed in the constructor, the
* call is forwarded to the actionPerformed($action, $record) method.
*
* @param string $trigger The trigger being performed
* @param array $record The record on which the trigger is performed
* @param string $mode The mode (add/update)
*
* @return bool Result of operation.
*/
public function notify($trigger, &$record, $mode = null)
{
if (method_exists($this, $trigger)) {
Tools::atkdebug('Call listener ' . get_class($this) . " for trigger {$trigger} on " . $this->m_node->atkNodeUri() . ' (' . $this->m_node->primaryKey($record) . ')');
return $this->{$trigger}($record, $mode);
} else {
return true;
}
}
示例9: __construct
/**
* Constructor.
*
* @param string $name The name of the attribute
* @param int $flags The flags for this attribute
* @param string $text The text to display
*/
public function __construct($name, $flags = 0, $text = '')
{
// A Dummy attrikbute should not be searchable and sortable
$flags |= self::AF_HIDE_SEARCH | self::AF_NO_SORT;
// Add the self::AF_BLANKLABEL flag unless the self::AF_DUMMY_SHOW_LABEL flag wasn't present
if (!Tools::hasFlag($flags, self::AF_DUMMY_SHOW_LABEL)) {
$flags |= self::AF_BLANKLABEL;
}
parent::__construct($name, $flags);
// base class constructor
$this->m_text = $text;
}
示例10: __construct
/**
* Constructor.
*
* @param string $name Name of the attribute
* @param int $flags Flags for this attribute
* @param string $currencysymbol The symbol which is printed in front of the value.
* @param int $decimals The number of decimals (default 2)
* @param string $decimalseparator The separator which is printed for the decimals.
* @param string $thousandsseparator The separator which is printed for the thousands.
*/
public function __construct($name, $flags = 0, $currencysymbol = '', $decimals = 2, $decimalseparator = '', $thousandsseparator = '')
{
parent::__construct($name, $flags, $decimals);
$this->setAttribSize(10);
if ($currencysymbol == '') {
$currencysymbol = Tools::atktext('currencysymbol', 'atk', '', '', '', true);
}
$this->m_currencysymbol = $currencysymbol;
$this->m_decimalseparator = $decimalseparator != '' ? $decimalseparator : '.';
$this->m_thousandsseparator = $thousandsseparator != '' ? $thousandsseparator : ',';
$this->setUseThousandsSeparator(true);
}
示例11: getCopyRecord
/**
* Get the selected record from.
*
* @return array the record to be copied
*/
protected function getCopyRecord()
{
$selector = $this->m_postvars['atkselector'];
$recordset = $this->m_node->select($selector)->mode('copy')->getAllRows();
if (count($recordset) > 0) {
return $recordset[0];
} else {
Tools::atkdebug("Geen records gevonden met selector: {$selector}");
$this->m_node->redirect();
}
return;
}
示例12: ipLongFormat
/**
* Converts an ip (in number or string format) to a long number.
*
* The supplied ip must be a valid ip. If the given ip is not
* valid, then atkerror will be called.
*
* @static This function may be used statically
*
* @param mixed $ip String or long numeric IP address.
*
* @return bool True if the ip is valid, False if not.
*/
public static function ipLongFormat($ip)
{
if (!self::ipValidate($ip)) {
Tools::atkdebug('IpUtils::ipLongFormat() Invalid ip given');
return;
}
if (is_numeric($ip)) {
return $ip;
}
$array = explode('.', $ip);
return $array[3] + 256 * $array[2] + 256 * 256 * $array[1] + 256 * 256 * 256 * $array[0];
}
示例13: _bindParams
/**
* Replace the bind parameters in the parsed query with their escaped values.
*
* @param array $params parameters
*
* @return string query
*/
protected function _bindParams($params)
{
$query = $this->_getParsedQuery();
Tools::atkdebug('Binding parameters for query: ' . $this->_getParsedQuery());
foreach (array_values($this->_getBindPositions()) as $i => $param) {
Tools::atkdebug("Bind param {$i}: " . ($params[$param] === null ? 'NULL' : $params[$param]));
}
foreach (array_reverse($this->_getBindPositions(), true) as $position => $param) {
$query = substr($query, 0, $position) . ($params[$param] === null ? 'NULL' : "'" . $this->getDb()->escapeSQL($params[$param]) . "'") . substr($query, $position + 1);
}
return $query;
}
示例14: export
/**
* Export data to a download file.
*
* BROWSER BUG:
* IE has problems with the use of attachment; needs atachment (someone at MS can't spell) or none.
* however ns under version 6 accepts this also.
* NS 6+ has problems with the absense of attachment; and the misspelling of attachment;
* at present ie 5 on mac gives wrong filename and NS 6+ gives wrong filename.
*
* @todo Currently supports only csv/excel mimetypes.
*
* @param string $data The content
* @param string $fileName Filename for the download
* @param string $type The type (csv / excel / xml)
* @param string $ext Extension of the file
* @param string $compression Compression method (bzip / gzip)
*/
public function export($data, $fileName, $type, $ext = '', $compression = '')
{
ob_end_clean();
if ($compression == 'bzip') {
$mime_type = 'application/x-bzip';
$ext = 'bz2';
} elseif ($compression == 'gzip') {
$mime_type = 'application/x-gzip';
$ext = 'gz';
} elseif ($type == 'csv') {
$mime_type = 'text/x-csv';
$ext = 'csv';
} elseif ($type == 'excel') {
$mime_type = 'application/octet-stream';
$ext = 'xls';
} elseif ($type == 'xml') {
$mime_type = 'text/xml';
$ext = 'xml';
} else {
$mime_type = 'application/octet-stream';
}
header('Content-Type: ' . $mime_type);
header('Content-Disposition: filename="' . $fileName . '.' . $ext . '"');
// Fix for downloading (Office) documents using an SSL connection in
// combination with MSIE.
if (($_SERVER['SERVER_PORT'] == '443' || Tools::atkArrayNvl($_SERVER, 'HTTP_X_FORWARDED_PROTO') == 'https') && preg_match('/msie/i', $_SERVER['HTTP_USER_AGENT'])) {
header('Pragma: public');
} else {
header('Pragma: no-cache');
}
header('Expires: 0');
// 1. as a bzipped file
if ($compression == 'bzip') {
if (@function_exists('bzcompress')) {
echo bzcompress($data);
}
} else {
if ($compression == 'gzip') {
if (@function_exists('gzencode')) {
// without the optional parameter level because it bug
echo gzencode($data);
}
} else {
if ($type == 'csv' || $type == 'excel') {
// in order to output UTF-8 content that Excel both on Windows and OS X will be able to successfully read
echo mb_convert_encoding($data, 'Windows-1252', 'UTF-8');
}
}
}
flush();
exit;
}
示例15: smarty_function_atkmessages
/**
* Implements the {atkmessages} plugin for use in templates.
*
* The {atkmessages} tag does not output anything. Instead, it loads
* the messages into the template variable {$atkmessages}, which is
* an array of elements, each with a single message.
*
* <b>Example:</b>
* <code>
* {atkmessages}
*
* {foreach from=$atkmessages item=message}
* {$message.message}<br>
* {/foreach}
* </code>
*
* @author Patrick van der Velden <patrick@ibuildings.nl>
*/
function smarty_function_atkmessages($params, $smarty)
{
$sessionManager = SessionManager::getInstance();
if (is_object($sessionManager)) {
$msgs = MessageQueue::getMessages();
$smarty->assign('atkmessages', $msgs);
if (empty($msgs)) {
Tools::atkdebug('No messages in MessageQueue');
}
return '';
}
return '';
}