本文整理汇总了PHP中iaUtil::generateToken方法的典型用法代码示例。如果您正苦于以下问题:PHP iaUtil::generateToken方法的具体用法?PHP iaUtil::generateToken怎么用?PHP iaUtil::generateToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iaUtil
的用法示例。
在下文中一共展示了iaUtil::generateToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smarty_function_preventCsrf
function smarty_function_preventCsrf($params, &$smarty)
{
// support several post forms in the page
$calledTimes = 0;
if (!isset($_SESSION['prevent_csrf']) || !is_array($_SESSION['prevent_csrf'])) {
$_SESSION['prevent_csrf'] = array();
}
$count = count($_SESSION['prevent_csrf']);
if ($count > 30) {
$_SESSION['prevent_csrf'] = isset($_SESSION['prevent_csrf'][$count - 1]) ? array($_SESSION['prevent_csrf'][$count - 1]) : array();
}
$_SESSION['prevent_csrf'][] = $token = iaUtil::generateToken();
$calledTimes++;
return '<input type="hidden" name="prevent_csrf" value="' . $token . '" />';
}
示例2: array
if (!iaValidate::isEmail($email)) {
$error = true;
$messages[] = iaLanguage::get('error_email_incorrect');
}
if (!$error) {
$member = $iaDb->row_bind(iaDb::ALL_COLUMNS_SELECTION, '`email` = :email', array('email' => $email));
if (empty($member)) {
$error = true;
$messages[] = iaLanguage::get('error_no_member_email');
}
if (false !== $code && $member['sec_key'] != $code) {
$error = true;
$messages[] = iaLanguage::get('confirmation_code_incorrect');
}
if (!$error && false === $code) {
$token = iaUtil::generateToken();
$confirmationUrl = IA_URL . 'forgot/?email=' . $email . '&code=' . $token;
$iaMailer = $iaCore->factory('mailer');
$iaMailer->loadTemplate('password_restoration');
$iaMailer->addAddress($member['email'], $member['fullname']);
$iaMailer->setReplacements(array('fullname' => $member['fullname'], 'url' => $confirmationUrl, 'code' => $token, 'email' => $member['email']));
$iaMailer->send();
$messages[] = iaLanguage::get('restore_pass_confirm');
$iaDb->update(array('id' => $member['id'], 'sec_key' => $token), 0, 0, iaUsers::getTable());
$form = 'confirm';
} elseif (!$error && $code) {
$error = false;
$messages[] = iaLanguage::get('new_password_sent');
$iaUsers->changePassword($member);
$form = false;
}
示例3: _preSaveEntry
protected function _preSaveEntry(array &$entry, array $data, $action)
{
parent::_preSaveEntry($entry, $data, $action);
iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii');
if (!utf8_is_valid($entry['title'])) {
$entry['title'] = utf8_bad_replace($entry['title']);
}
if (empty($entry['title'])) {
$this->addMessage('title_is_empty');
}
if (!utf8_is_valid($entry['body'])) {
$entry['body'] = utf8_bad_replace($entry['body']);
}
if (empty($entry['body'])) {
$this->addMessage(iaLanguage::getf('field_is_empty', array('field' => iaLanguage::get('body'))), false);
}
if (empty($entry['date_added'])) {
$entry['date_added'] = date(iaDb::DATETIME_FORMAT);
}
$entry['alias'] = $this->getHelper()->titleAlias(empty($entry['alias']) ? $entry['title'] : $entry['alias']);
if ($this->getMessages()) {
return false;
}
unset($entry['owner'], $entry['tags']);
if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) {
$iaPicture = $this->_iaCore->factory('picture');
$info = array('image_width' => 1000, 'image_height' => 750, 'thumb_width' => 250, 'thumb_height' => 250, 'resize_mode' => iaPicture::CROP);
if ($image = $iaPicture->processImage($_FILES['image'], iaUtil::getAccountDir(), iaUtil::generateToken(), $info)) {
empty($entry['image']) || $iaPicture->delete($entry['image']);
// already has an assigned image
$entry['image'] = $image;
}
}
return true;
}
示例4: utf8_is_valid
$entry['title'] = $_POST['title'];
utf8_is_valid($entry['title']) || ($entry['title'] = utf8_bad_replace($entry['title']));
if (empty($entry['title'])) {
$messages[] = iaLanguage::get('title_is_empty');
}
$entry['body'] = $_POST['body'];
utf8_is_valid($entry['body']) || ($entry['body'] = utf8_bad_replace($entry['body']));
if (empty($entry['body'])) {
$messages[] = iaLanguage::getf('field_is_empty', array('field' => iaLanguage::get('body')));
}
$entry['alias'] = $iaBlog->titleAlias(empty($_POST['alias']) ? $entry['title'] : $_POST['alias']);
if (!$messages) {
if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) {
$iaPicture = $iaCore->factory('picture');
$info = array('image_width' => 1000, 'image_height' => 750, 'thumb_width' => 250, 'thumb_height' => 250, 'resize_mode' => iaPicture::CROP);
if ($image = $iaPicture->processImage($_FILES['image'], iaUtil::getAccountDir(), iaUtil::generateToken(), $info)) {
if ($entry['image']) {
$iaPicture = $iaCore->factory('picture');
$iaPicture->delete($entry['image']);
}
$entry['image'] = $image;
}
}
$result = iaCore::ACTION_ADD == $pageAction ? $iaBlog->insert($entry) : $iaBlog->update($entry, $id);
if ($result) {
$id = iaCore::ACTION_ADD == $pageAction ? $result : $id;
$iaBlog->saveTags($id, $_POST['tags']);
$iaView->setMessages(iaLanguage::get('saved'), iaView::SUCCESS);
iaUtil::go_to($baseUrl . sprintf('%d-%s', $id, $entry['alias']));
} else {
$messages[] = iaLanguage::get('db_error');
示例5: _setDefaultValues
protected function _setDefaultValues(array &$entry)
{
$entry = array('name' => 'menu_' . iaUtil::generateToken(5), 'position' => '', 'classname' => '', 'status' => iaCore::STATUS_ACTIVE, 'sticky' => false, 'title' => '', 'tpl' => iaBlock::DEFAULT_MENU_TEMPLATE, 'type' => iaBlock::TYPE_MENU);
$entry['header'] = $entry['collapsible'] = $entry['collapsed'] = false;
}
示例6: _generateFileName
protected static function _generateFileName($filename = '', $prefix = '', $glue = true)
{
if (empty($filename)) {
return $prefix . iaUtil::generateToken();
}
$extension = '';
if (false !== strpos($filename, '.')) {
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$filename = $prefix . pathinfo($filename, PATHINFO_FILENAME);
if (false !== strpos($filename, '.')) {
$filename = str_replace(array('.', '~'), '-', $filename);
}
}
$filename = iaSanitize::alias($filename) . '_' . iaUtil::generateToken(5);
return $glue ? $filename . '.' . $extension : array($filename, $extension);
}
示例7: _parserStart
public function _parserStart($parser, $name, $attributes)
{
$this->_inTag = $name;
$this->_attributes = $attributes;
$this->_currentPath[] = $name;
if (in_array($this->_inTag, array(self::TYPE_PACKAGE, self::TYPE_PLUGIN)) && isset($attributes['name'])) {
$this->itemData['name'] = $attributes['name'];
$this->itemData['type'] = $name == self::TYPE_PLUGIN ? self::TYPE_PLUGIN : self::TYPE_PACKAGE;
}
if ('usergroup' == $name) {
$this->itemData['usergroups'][] = array('extras' => $this->itemData['name'], 'name' => $this->itemData['name'] . '_' . $this->_attr('name', iaUtil::generateToken()), 'title' => $attributes['title'], 'assignable' => $this->_attr('assignable', false), 'visible' => $this->_attr('visible', true), 'configs' => array(), 'permissions' => array());
}
}
示例8: _preSaveEntry
protected function _preSaveEntry(array &$entry, array $data, $action)
{
parent::_preSaveEntry($entry, $data, $action);
iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii');
if (!utf8_is_valid($entry['title'])) {
$entry['title'] = utf8_bad_replace($entry['title']);
}
if (empty($entry['title'])) {
$this->addMessage('title_is_empty');
}
if (!utf8_is_valid($entry['body'])) {
$entry['body'] = utf8_bad_replace($entry['body']);
}
if (empty($entry['body'])) {
$this->addMessage('body_is_empty');
}
if (empty($entry['date_added'])) {
$entry['date_added'] = date(iaDb::DATETIME_FORMAT);
}
$entry['alias'] = $this->getHelper()->titleAlias(empty($entry['alias']) ? $entry['title'] : $entry['alias']);
if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) {
$this->_iaCore->loadClass(iaCore::CORE, 'picture');
$iaImage = $this->_iaCore->factoryPlugin($this->getPluginName(), iaCore::ADMIN, 'image');
$imageData = json_decode($entry['image-data'], true);
$path = iaUtil::getAccountDir();
$file = $_FILES['image'];
$token = iaUtil::generateToken();
$info = array('image_width' => $this->_iaCore->get('portfolio_image_width'), 'image_height' => $this->_iaCore->get('portfolio_image_height'), 'crop_width' => $imageData['width'], 'crop_height' => $imageData['height'], 'thumb_width' => $this->_iaCore->get('portfolio_thumbnail_width'), 'thumb_height' => $this->_iaCore->get('portfolio_thumbnail_height'), 'positionX' => $imageData['x'], 'positionY' => $imageData['y'], 'position' => 'LT', 'resize' => 'after_crop', 'resize_mode' => iaImage::CROP);
if ($image = $iaImage->processFolioImage($file, $path, $token, $info)) {
if ($entry['image']) {
$iaImage = $this->_iaCore->factory('picture');
$iaImage->delete($entry['image']);
}
$entry['image'] = $image;
}
}
if (empty($entry['image'])) {
$this->addMessage('invalid_image_file');
}
if ($this->getMessages()) {
return false;
}
unset($entry['image-src']);
unset($entry['image-data']);
return true;
}
示例9: _preSaveEntry
protected function _preSaveEntry(array &$entry, array $data, $action)
{
parent::_preSaveEntry($entry, $data, $action);
iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii');
if (!utf8_is_valid($entry['title'])) {
$entry['title'] = utf8_bad_replace($entry['title']);
}
if (empty($entry['title'])) {
$this->addMessage('title_is_empty');
}
if (!utf8_is_valid($entry['body'])) {
$entry['body'] = utf8_bad_replace($entry['body']);
}
if (empty($entry['body'])) {
$this->addMessage(iaLanguage::getf('field_is_empty', array('field' => iaLanguage::get('body'))));
}
if (empty($entry['date_added'])) {
$entry['date_added'] = date(iaDb::DATETIME_FORMAT);
}
$entry['alias'] = $this->getHelper()->titleAlias(empty($entry['alias']) ? $entry['title'] : $entry['alias']);
if (!empty($data['owner'])) {
if ($memberId = $this->_iaCore->iaDb->one_bind('id', '`username` = :name OR `fullname` = :name', array('name' => iaSanitize::sql($_POST['owner'])), iaUsers::getTable())) {
$entry['member_id'] = $memberId;
} else {
$this->addMessage('incorrect_owner_specified');
}
} else {
$entry['member_id'] = iaUsers::getIdentity()->id;
}
if ($this->getMessages()) {
return false;
}
unset($entry['owner']);
if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) {
$iaPicture = $this->_iaCore->factory('picture');
$info = array('image_width' => 1000, 'image_height' => 750, 'thumb_width' => 250, 'thumb_height' => 250, 'resize_mode' => iaPicture::CROP);
if ($image = $iaPicture->processImage($_FILES['image'], iaUtil::getAccountDir(), iaUtil::generateToken(), $info)) {
empty($entry['image']) || $iaPicture->delete($entry['image']);
// already has an assigned image
$entry['image'] = $image;
}
}
unset($entry['tags']);
return true;
}
示例10: _generateUserName
private function _generateUserName(array $memberInfo)
{
$email = $memberInfo['email'];
// here we can be pretty sure that email contains @
$result = substr($email, 0, strpos($email, '@'));
if ($this->getInfo($result, 'username')) {
$this->iaCore->factory('util');
$result = $result . '_' . iaUtil::generateToken(5);
}
return $result;
}
示例11: _processAdminPages
protected function _processAdminPages(array $entries)
{
$this->iaDb->setTable('admin_pages');
$this->iaDb->delete(iaDb::convertIds($this->itemData['name'], 'extras'));
foreach ($entries as $title => $entry) {
$entry['group'] = $this->_lookupGroupId($entry['group']);
$entry['order'] = (int) (is_null($entry['order']) ? $this->iaDb->one_bind('MAX(`order`) + 5', '`group` = :group', $entry) : $entry['order']);
empty($entry['group']) || ($this->_menuGroups[] = $entry['group']);
empty($entry['name']) && ($entry['attr'] = iaUtil::generateToken(8));
$this->iaDb->insert($entry);
$this->_addPhrase('page_title_' . ($entry['name'] ? $entry['name'] : $entry['attr']), $title, iaLanguage::CATEGORY_ADMIN);
}
$this->iaDb->resetTable();
}
示例12: _saveMenus
private function _saveMenus($entryName, $menus)
{
$iaAcl = $this->_iaCore->factory('acl');
if ($iaAcl->checkAccess('admin_page:add', 'menus')) {
$iaDb =& $this->_iaDb;
$iaBlock = $this->_iaCore->factory('block', iaCore::ADMIN);
$iaDb->setTable($iaBlock::getMenusTable());
$menusList = $iaDb->all(array('id'), iaDb::convertIds('menu', 'type'), null, null, $iaBlock::getTable());
foreach ($menusList as $item) {
$items = array();
$add = false;
if (in_array($item['id'], $menus)) {
if (!$iaDb->exists('`menu_id` = :menu AND `page_name` = :page', array('menu' => $item['id'], 'page' => $entryName))) {
$items[] = array('parent_id' => 0, 'menu_id' => $item['id'], 'el_id' => $this->getEntryId() . '_' . iaUtil::generateToken(5), 'level' => 0, 'page_name' => $entryName);
$add = true;
}
} else {
$iaDb->delete('`menu_id` = :menu AND `page_name` = :page', null, array('menu' => $item['id'], 'page' => $entryName));
}
if ($add) {
$iaDb->insert($items);
}
$this->_iaCore->iaCache->remove('menu_' . $item['id'] . '.inc');
}
$iaDb->resetTable();
}
}
示例13: install
//.........这里部分代码省略.........
$iaDb->resetTable();
}
$title = isset($page['title']) && $page['title'] ? $page['title'] : false;
$blocks = isset($page['blocks']) && $page['blocks'] ? $page['blocks'] : false;
$menus = isset($page['menus']) && $page['menus'] ? explode(',', $page['menus']) : array();
$contents = isset($page['contents']) && $page['contents'] ? $page['contents'] : false;
unset($page['title'], $page['blocks'], $page['menus'], $page['contents']);
$page['group'] = $pageGroups[$page['group']];
$pageId = $iaDb->insert($page, array('order' => ++$maxOrder, 'last_updated' => iaDb::FUNCTION_NOW));
if ($title) {
foreach ($this->iaCore->languages as $code => $value) {
iaLanguage::addPhrase('page_title_' . $page['name'], $title, $code, $this->itemData['name'], iaLanguage::CATEGORY_PAGE, false);
}
}
// TODO: should be handled by iaBlock
if ($blocks) {
$blocks = $iaDb->keyvalue(array('name', 'id'), "`name` IN ('" . implode("','", $blocks) . "')", iaBlock::getTable(), 0, 1);
foreach ($blocks as $blockId) {
$iaDb->insert(array('object_type' => 'blocks', 'object' => $blockId, 'page_name' => $page['name']), null, 'objects_pages');
}
}
if (!is_int($page['group'])) {
$page['group'] = $this->_lookupGroupId($page['group']);
}
if ($menus) {
$iaDb->setTable(iaBlock::getTable());
$added = array();
$items = array();
$menusData = $iaDb->keyvalue(array('id', 'name'), "`type` = 'menu'");
$db = false;
foreach ($menusData as $id => $name) {
if (in_array($name, $menus)) {
$added[] = $name;
$items[] = array('parent_id' => 0, 'menu_id' => $id, 'el_id' => $pageId . '_' . iaUtil::generateToken(4), 'level' => 0, 'page_name' => $page['name']);
$db = true;
$this->iaCore->iaCache->remove('menu_' . $id . '.inc');
}
}
if ($db) {
$iaDb->insert($items, null, iaBlock::getMenusTable());
}
foreach ($menus as $val) {
if (!in_array($val, $added)) {
$menuItem = array('type' => iaBlock::TYPE_MENU, 'status' => iaCore::STATUS_ACTIVE, 'position' => 'left', 'collapsible' => true, 'title' => $this->itemData['info']['title'], 'extras' => $this->itemData['name'], 'name' => $this->itemData['name'], 'sticky' => true, 'removable' => false);
$menuItem['id'] = $iaBlock->insert($menuItem);
$contents = array('parent_id' => 0, 'menu_id' => $menuItem['id'], 'el_id' => $pageId . '_' . iaUtil::generateToken(5), 'level' => 0, 'page_name' => $page['name']);
$iaDb->insert($contents, null, iaBlock::getMenusTable());
}
}
$iaDb->resetTable();
}
if ($contents) {
foreach ($this->iaCore->languages as $code => $value) {
iaLanguage::addPhrase('page_content_' . $page['name'], $contents, $code, $this->itemData['name'], iaLanguage::CATEGORY_PAGE, false);
}
}
$extraPages[] = $page['name'];
}
}
$iaDb->resetTable();
}
if ($this->itemData['blocks']) {
$iaBlock = $this->iaCore->factory('block', iaCore::ADMIN);
foreach ($this->itemData['blocks'] as $block) {
$iaBlock->insert($block);
}
示例14: isset
<?php
//##copyright##
if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
// affiliate member id
$memberId = isset($iaCore->requestPath[0]) ? (int) $iaCore->requestPath[0] : 0;
// affiliate product id used for tracking
$productId = isset($iaCore->requestPath[1]) ? (int) $iaCore->requestPath[1] : 0;
// check referer
$visitorReferrer = getenv('HTTP_REFERER');
if ($memberId) {
$iaVisitor = $iaCore->factoryPackage('visitor', IA_CURRENT_PACKAGE);
// get unique tracking ID for a visitor in case it's not set
$trackingSalt = isset($_COOKIE['IA_AFF_TRACKING']) ? $_COOKIE['IA_AFF_TRACKING'] : $memberId . iaUtil::generateToken(20);
// update tracking record
$iaVisitor->updateTrackingRecords($trackingSalt, $memberId, $productId, $visitorReferrer);
}
// redirect to the page
$redirectUrl = $iaCore->get('aff_incoming_page', IA_URL);
if ($productId) {
$redirectUrl = $iaDb->one('`url`', iaDb::convertIds($productId), 'affiliates_products');
}
iaUtil::go_to($redirectUrl);
}
示例15: array
$entry = array('date' => date(iaDb::DATETIME_FORMAT), 'ip' => iaUtil::getIp(), 'member_id' => iaUsers::getIdentity()->id, 'item' => $itemName, 'item_id' => $itemId, 'item_title' => $itemData['title'] ? $itemData['title'] : $itemData['venue_title'], 'item_url' => $itemUrl, 'type' => $_POST['type'], 'status' => 'pending', 'notes' => null);
$message = null;
switch ($_POST['type']) {
case 'manual':
$entry['name'] = empty($_POST['name']) ? null : $_POST['name'];
$entry['email'] = empty($_POST['email']) ? null : $_POST['email'];
$entry['phone'] = empty($_POST['phone']) ? null : $_POST['phone'];
$entry['job_title'] = empty($_POST['job_title']) ? null : $_POST['job_title'];
$message = iaLanguage::get('your_request_saved');
break;
case 'email':
if (!$iaCore->get('cl_enable_email_approval')) {
return;
}
if (!empty($itemData['email'])) {
$key = iaUtil::generateToken();
$iaDb->setTable('claim_pending_email_keys');
if ($rowId = $iaDb->one_bind(iaDb::ID_COLUMN_SELECTION, '`item` = :item AND `item_id` = :id', array('item' => $itemName, 'id' => $itemId))) {
$iaDb->update(array('date' => date(iaDb::DATETIME_FORMAT), 'key' => $key, 'member_id' => iaUsers::getIdentity()->id), iaDb::convertIds($rowId));
} else {
$keyEntry = array('date' => date(iaDb::DATETIME_FORMAT), 'item' => $itemName, 'item_id' => $itemId, 'key' => $key, 'member_id' => iaUsers::getIdentity()->id);
$iaDb->insert($keyEntry);
}
$iaDb->resetTable();
$link = $itemUrl . '?ownership-key=' . $key;
$iaMailer = $iaCore->factory('mailer');
$iaMailer->addAddress($itemData['email']);
$iaMailer->loadTemplate('ownership_email_approval');
$iaMailer->setReplacements(array('email' => $itemData['email'], 'url' => $link));
$result = $iaMailer->send();
$message = $result ? iaLanguage::getf('confirmation_link_sent_with_email', array('email' => $itemData['email'])) : iaLanguage::get('unable_to_send_confirmation_link');