本文整理汇总了PHP中JUtility::getToken方法的典型用法代码示例。如果您正苦于以下问题:PHP JUtility::getToken方法的具体用法?PHP JUtility::getToken怎么用?PHP JUtility::getToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JUtility
的用法示例。
在下文中一共展示了JUtility::getToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOnClick
public function getOnClick()
{
$id = KRequest::get('get.id', 'int');
$token = JUtility::getToken();
$json = "{method:'post', url:'index.php?option=com_create&view=component&id={$id}', formelem:'adminForm', params:{action:'generate', _token:'{$token}'}}";
return 'new KForm(' . $json . ').submit();';
}
示例2: doSSOLogout
/**
* Method for logging out with Magento (Single Sign On)
*
* @param string $username
* @return bool|exit
*/
public static function doSSOLogout($username = null)
{
// Abort if the input is not valid
if (empty($username)) {
return false;
}
// Get system variables
$application = JFactory::getApplication();
$session = JFactory::getSession();
// Determine the application
$application_name = $application->isAdmin() ? 'admin' : 'frontend';
// Get the security token
$token = method_exists('JSession', 'getFormToken') ? JSession::getFormToken() : JUtility::getToken();
// Set the redirection URL
if ($application_name == 'admin') {
$redirect = JURI::current();
} else {
$redirect = MageBridgeUrlHelper::current();
}
// Construct the URL
$arguments = array('sso=logout', 'app=' . $application_name, 'redirect=' . base64_encode($redirect), 'userhash=' . MageBridgeEncryptionHelper::encrypt($username), 'token=' . $token);
$url = MageBridgeModelBridge::getInstance()->getMagentoBridgeUrl() . '?' . implode('&', $arguments);
// Redirect the browser to Magento
MageBridgeModelDebug::getInstance()->notice("SSO: Logout of '{$username}' from " . $application_name);
$application->redirect($url);
return true;
}
示例3: post
public function post()
{
// Set variables to be used
APIHelper::setSessionUser();
// Include dependencies
jimport('joomla.database.table');
$language = JFactory::getLanguage();
$language->load('joomla', JPATH_ADMINISTRATOR);
$language->load('com_categories', JPATH_ADMINISTRATOR);
require_once JPATH_ADMINISTRATOR . '/components/com_categories/models/category.php';
// Fake parameters
$_POST['task'] = 'apply';
$_REQUEST['task'] = 'apply';
$_REQUEST[JUtility::getToken()] = 1;
$_POST[JUtility::getToken()] = 1;
$data = JRequest::getVar('jform', array(), 'post', 'array');
$context = 'category';
// Clear userstate just in case
$model = APIodel::getInstance('Category', 'CategoriesModel');
$success = $model->save($data);
if ($model->getError()) {
$response = $this->getErrorResponse(400, $model->getError());
} elseif (!$success) {
$response = $this->getErrorResponse(400, JText::_('COM_API_ERROR_OCURRED'));
} else {
$response = $this->getSuccessResponse(201, JText::_('COM_CATEGORIES_SAVE_SUCCESS'));
// Get the ID of the category that was modified or inserted
$response->id = $model->get('state')->get($context . '.id');
// Checkin category
$model->checkin($response->id);
}
$this->plugin->setResponse($response);
}
示例4: view
/**
* Show the form in the admin
*
* @return null
*/
public function view()
{
$document = JFactory::getDocument();
$model = JModel::getInstance('Form', 'FabrikFEModel');
$viewType = $document->getType();
$this->setPath('view', COM_FABRIK_FRONTEND . '/views');
$viewLayout = JRequest::getCmd('layout', 'default');
$view = $this->getView('form', $viewType, '');
$view->setModel($model, true);
$view->isMambot = $this->isMambot;
// Set the layout
$view->setLayout($viewLayout);
// @TODO check for cached version
JToolBarHelper::title(JText::_('COM_FABRIK_MANAGER_FORMS'), 'forms.png');
if (in_array(JRequest::getCmd('format'), array('raw', 'csv', 'pdf'))) {
$view->display();
} else {
$user = JFactory::getUser();
$post = JRequest::get('post');
$cacheid = serialize(array(JRequest::getURI(), $post, $user->get('id'), get_class($view), 'display', $this->cacheId));
$cache = JFactory::getCache('com_fabrik', 'view');
ob_start();
$cache->get($view, 'display', $cacheid);
$contents = ob_get_contents();
ob_end_clean();
$token = JUtility::getToken();
$search = '#<input type="hidden" name="[0-9a-f]{32}" value="1" />#';
$replacement = '<input type="hidden" name="' . $token . '" value="1" />';
echo preg_replace($search, $replacement, $contents);
}
FabrikAdminHelper::addSubmenu(JRequest::getWord('view', 'lists'));
}
示例5: display
public function display()
{
$state = $this->getModel()->getState();
$folders = KFactory::get('com://admin/files.controller.folder')
->container($state->container)
->tree(true)
->browse();
$this->assign('folders', $folders);
$config = KFactory::get('com://admin/files.model.configs')->getItem();
// prepare an extensions array for fancyupload
$extensions = $config->upload_extensions;
$this->assign('allowed_extensions', $extensions);
$this->assign('maxsize' , $config->upload_maxsize);
$this->assign('path' , $state->container->relative_path);
$this->assign('sitebase' , ltrim(JURI::root(true), '/'));
$this->assign('token' , JUtility::getToken());
$this->assign('session' , JFactory::getSession());
if (!$this->editor) {
$this->assign('editor', '');
}
return parent::display();
}
示例6: display
function display($tpl=null)
{
$r = new JObject();
$r->token = JUtility::getToken(true);
echo json_encode($r);
}
示例7: getList
/**
* Get a list of logged users.
*
* @param JObject The module parameters.
* @return mixed An array of articles, or false on error.
*/
public static function getList($params)
{
// Initialise variables
$db = JFactory::getDbo();
$user = JFactory::getUser();
$query = $db->getQuery(true);
$query->select('s.time, s.client_id, u.id, u.name, u.username');
$query->from('#__session AS s');
$query->leftJoin('#__users AS u ON s.userid = u.id');
$query->where('s.guest = 0');
$db->setQuery($query, 0, $params->get('count', 5));
$results = $db->loadObjectList();
// Check for database errors
if ($error = $db->getErrorMsg()) {
JError::raiseError(500, $error);
return false;
}
foreach ($results as $k => $result) {
$results[$k]->logoutLink = '';
if ($user->authorise('core.manage', 'com_users')) {
$results[$k]->editLink = JRoute::_('index.php?option=com_users&task=user.edit&id=' . $result->id);
$results[$k]->logoutLink = JRoute::_('index.php?option=com_login&task=logout&uid=' . $result->id . '&' . JUtility::getToken() . '=1');
}
if ($params->get('name', 1) == 0) {
$results[$k]->name = $results[$k]->username;
}
}
return $results;
}
示例8: post
/**
* This is not the best example to follow
* Please see the category plugin for a better example
*/
public function post()
{
// Set variables to be used
APIHelper::setSessionUser();
// Include dependencies
jimport('joomla.database.table');
$language = JFactory::getLanguage();
$language->load('joomla', JPATH_ADMINISTRATOR);
$language->load('com_k2', JPATH_ADMINISTRATOR);
require_once JPATH_ADMINISTRATOR . '/components/com_k2/models/item.php';
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/tables');
// Fake parameters
$_REQUEST[JUtility::getToken()] = 1;
$_POST[JUtility::getToken()] = 1;
// Clear userstate just in case
$row = $this->save();
if ($this->getError()) {
$response = $this->getErrorResponse(400, $this->getError());
} elseif (!$row->id) {
$response = $this->getErrorResponse(400, JText::_('COM_API_ERROR_OCURRED'));
} else {
$response = $this->getSuccessResponse(201, JText::_('COM_API_SUCCESS'));
// Get the ID of the category that was modified or inserted
$response->id = $row->id;
}
$this->plugin->setResponse($response);
}
示例9: delete
public function delete($id = null)
{
// Include dependencies
jimport('joomla.application.component.controller');
jimport('joomla.form.form');
jimport('joomla.database.table');
require_once JPATH_ADMINISTRATOR . '/components/com_categories/controllers/categories.php';
require_once JPATH_ADMINISTRATOR . '/components/com_categories/models/category.php';
JForm::addFormPath(JPATH_ADMINISTRATOR . '/components/com_categories/models/forms/');
// Fake parameters
$_POST['task'] = 'trash';
$_REQUEST['task'] = 'trash';
$_REQUEST[JUtility::getToken()] = 1;
$_POST[JUtility::getToken()] = 1;
JFactory::getLanguage()->load('com_categories', JPATH_ADMINISTRATOR);
$controller = new CategoriesControllerCategories();
try {
$controller->execute('trash');
} catch (JException $e) {
$success = false;
$controller->set('messageType', 'error');
$controller->set('message', $e->getMessage());
}
if ($controller->getError()) {
$response = $this->getErrorResponse(400, $controller->getError());
} elseif ('error' == $controller->get('messageType')) {
$response = $this->getErrorResponse(400, $controller->get('message'));
} else {
$response = $this->getSuccessResponse(200, $controller->get('message'));
}
$this->plugin->setResponse($response);
}
示例10: display
/**
* Display the view
*/
public function display($tpl = null)
{
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->enabled = $this->state->params->get('enabled');
// Check for errors. @todo this has to be queed up and converted to JSON
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
$r = new JObject;
$r->token = JUtility::getToken(true);
$r->items = array();
foreach ($this->items as $i => $item) {
$rItem = new JObject;
$rItem->index = $i + 1 + $this->pagination->limitstart;
$rItem->search_term = $item->search_term;
if ($this->state->get('filter.results')) {
$rItem->results = (int) $item->returns;
} else {
$rItem->results = JText::_('COM_SEARCH_NO_RESULTS');
}
$r->items[$i] = $rItem;
}
echo json_encode($r);
}
示例11: onAfterRoute
public function onAfterRoute()
{
$application = JFactory::getApplication();
if($application->isSite())
{
switch(JRequest::getVar('option', null, 'method', 'cmd'))
{
case 'com_user':
JRequest::setVar('option', 'com_users', 'get');
switch(JRequest::getVar('view', null, 'method', 'cmd'))
{
case 'login':
if(!JFactory::getUser()->guest) {
JRequest::setVar('view', 'logout', 'get');
}
break;
case 'remind':
JRequest::setVar('view', 'remind', 'get');
break;
case 'register':
JRequest::setVar('view', 'user', 'get');
JRequest::setVar('layout', 'register', 'get');
break;
case 'user':
if(JRequest::getVar('task', null, 'get', 'cmd') == 'edit') {
JRequest::setVar('layout', 'form', 'get');
}
}
switch(JRequest::getVar('task', null, 'method', 'cmd'))
{
case 'login':
JRequest::setVar('view', 'login', 'get');
JRequest::setVar('action', 'login', 'post');
JRequest::setVar('password', JRequest::getVar('passwd', null, 'method', 'none'), 'post');
break;
}
break;
}
if(JRequest::getMethod() == 'POST')
{
$token = JUtility::getToken();
if(JRequest::getVar($token, null, 'post', 'alnum') == 1) {
JRequest::setVar('_token', $token, 'post');
}
}
}
}
示例12: onAfterInitialise
/**
* Converting the site URL to fit to the HTTP request
*
*/
function onAfterInitialise()
{
global $_PROFILER;
$app =& JFactory::getApplication();
$user =& JFactory::getUser();
if ($app->isAdmin() || JDEBUG) {
return;
}
if (!$user->get('guest') && $_SERVER['REQUEST_METHOD'] == 'GET') {
$this->_cache->setCaching(true);
}
$data = $this->_cache->get();
if ($data !== false) {
// the following code searches for a token in the cached page and replaces it with the
// proper token.
$token = JUtility::getToken();
$search = '#<input type="hidden" name="[0-9a-f]{32}" value="1" />#';
$replacement = '<input type="hidden" name="' . $token . '" value="1" />';
$data = preg_replace($search, $replacement, $data);
JResponse::setBody($data);
echo JResponse::toString($app->getCfg('gzip'));
if (JDEBUG) {
$_PROFILER->mark('afterCache');
echo implode('', $_PROFILER->getBuffer());
}
$app->close();
}
}
示例13: cria_html
function cria_html()
{
// adiciona a biblioteca juri
jimport('joomla.environment.uri');
// verifica se a urlbase foi adicionada
if (!is_null($this->url_base)) {
$u =& JURI::getInstance($this->url_base);
} else {
$u =& JURI::getInstance();
}
$links = '';
$paginas_adm_select = '';
$select = '';
// loop nas páginas
for ($i = 1; $i <= $this->total_paginas; $i++) {
// adiciona a var na url
$u->setVar($this->get_var_pagina, $i);
// retorna o html tag a
$class = $i == $this->pagina_atual ? ' class="atual"' : '';
$links .= sprintf('<a href="%s"%s>%d</a> ', JRoute::_($u->toString()), $class, $i);
// retorna o html select
$selected = $i == $this->pagina_atual ? ' selected="selected"' : '';
// cria o select para o site
$select .= sprintf('<option value="%s" %s>Página %d</option> ', JRoute::_($u->toString()), $selected, $i);
// cria o select para o adm
$paginas_adm_select .= sprintf('<option value="%s" %s>Página %d</option> ', $i, $selected, $i);
}
// paginas para o adm
$query = JRequest::get('post');
unset($query[JUtility::getToken()], $query['funcao'], $query['method'], $query['class'], $query['pagina'], $query['programa'], $query['template'], $query['processID']);
$u->setQuery($query);
$u->setVar($this->get_var_pagina, '');
$js = sprintf('<script type="text/javascript">$(function(){ $(\'select#%s\').change(function(){ eDesktop.dialog.load({programa: "%s", processID: "%s", pagina: "%s", query: "%s"+ $(this).val() }); });});</script>', $this->get_var_pagina, JRequest::getvar('programa'), JRequest::getvar('processID'), JRequest::getvar('pagina'), $u->getQuery());
$paginas_adm_select = sprintf('<select name="%s" id="%s">%s</select>%s ', $this->get_var_pagina, $this->get_var_pagina, $paginas_adm_select, $js);
$this->html['paginas.adm.select'] = $paginas_adm_select;
// páginas para o site
$js = sprintf('<script type="text/javascript">$(function(){ $(\'select#%s\').change(function(){window.location = $(this).val();});});</script>', $this->get_var_pagina);
$select = sprintf('<select name="%s" id="%s">%s</select>%s', $this->get_var_pagina, $this->get_var_pagina, $select, $js);
$this->html['paginas.links'] = $links;
$this->html['paginas.select'] = $select;
// ordem para site
$order = '';
$this->order_atual = JRequest::getVar($this->get_var_order);
if (count($this->orders)) {
foreach ($this->orders as $k => $v) {
$u->setVar($this->get_var_pagina, 1);
$u->setVar($this->get_var_order, $k);
$selected = $k == $this->order_atual ? ' selected="selected"' : '';
$order .= sprintf('<option value="%s" %s>%s</option> ', JRoute::_($u->toString()), $selected, $v['label']);
}
$js = sprintf('<script type="text/javascript">$(function(){ $(\'select#%s\').change(function(){window.location = $(this).val();});});</script>', $this->get_var_order);
$order = sprintf('<select name="%s" id="%s">%s</select>%s', $this->get_var_order, $this->get_var_order, $order, $js);
//
$this->html['order.select'] = $order;
}
foreach ($this->html as $k => $v) {
$key = str_replace('.', '_', $k);
$this->html[$key] = $v;
}
}
示例14: display
function display($tpl = null)
{
// Frontpage hack
$this->addTemplatePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'views' . DS . 'link' . DS . 'tmpl');
// Only allow "component" template
JRequest::setVar('tmpl', 'component');
// JFactory
$user =& JFactory::getUser();
$config =& JFactory::getConfig();
$doc =& JFactory::getDocument();
$lingo =& JFactory::getLanguage();
// Include styles
$doc->addStyleSheet(LINKR_ASSETS . 'css/modal.css?' . LINKR_VERSION_INC);
// Template override
global $mainframe;
$tmpl = $mainframe->getTemplate();
if (file_exists(JPATH_BASE . DS . 'templates' . DS . $tmpl . DS . 'linkr.css')) {
$doc->addStyleSheet(JURI::base() . 'templates/' . $tmpl . '/linkr.css');
} elseif (file_exists(JPATH_BASE . DS . 'templates' . DS . $tmpl . DS . 'css' . DS . 'linkr.css')) {
$doc->addStyleSheet(JURI::base() . 'templates/' . $tmpl . '/css/linkr.css');
}
// Editor name, request endpoint, document base
$editor = JRequest::getString('e_name', 'text');
$rUrl = JURI::base() . 'index.php?option=com_linkr&view=request&' . JUtility::getToken() . '=1';
// Include scripts
JHTML::_('behavior.mootools');
$unc = LinkrHelper::getParam('compress', 1) ? '.js' : '-UCP.js';
$doc->addScript(LINKR_ASSETS . 'js/helper' . $unc . '?' . LINKR_VERSION_INC);
$doc->addScriptDeclaration('var Linkr=new LinkrAPI(' . '[' . implode(',', explode('.', LINKR_VERSION_READ)) . '],' . '"' . $rUrl . '",' . '"' . $editor . '",' . '"' . JURI::root() . '",' . '[' . '"' . JRequest::getWord('mode', 'squeezebox') . '",' . '"' . $lingo->getTag() . '",' . '"' . LinkrHelper::UTF8Encode(JText::_('MISSING_TEXT', true)) . '",' . '"' . LinkrHelper::UTF8Encode(JText::_('IMG_ANCHOR', true)) . '",' . '"' . LINKR_ASSETS . 'img/",' . $user->get('aid') . ']' . ');' . 'var LinkrHelper=Linkr;');
// Frontend fix
if (LinkrHelper::isSite()) {
//$doc->setBase(LinkrHelper::getLinkrUrl($editor));
}
// References
$this->assign('links', $this->get('Links'));
$this->assign('tools', $this->get('ToolLinks'));
// Localize text
if ($text = $this->get('L18N')) {
$l18n = array();
foreach ($text as $k => $v) {
$l18n[] = '["' . $k . '","' . $v . '"]';
}
$doc->addScriptDeclaration('Linkr.setL18N([' . implode(',', $l18n) . ']);');
}
// 3rd party javascript
if ($js = $this->get('Scripts')) {
$doc->addScriptDeclaration($js);
}
// Load single link
$load = '';
$inc = $this->get('IncludedLinks');
if (!$this->tools['count'] && $this->links['count'] == 1) {
$load = 'Linkr.__fr=function(){' . $inc[$this->links['name'][0]] . '};';
} elseif (!$this->links['count'] && $this->tools['count'] == 1) {
$load = 'Linkr.__fr=function(){' . $inc[$this->tools['name'][0]] . '};';
}
// Fire "onLoad" event
$doc->addScriptDeclaration('window.addEvent("domready",function(){' . $load . 'Linkr.fireEvent("onLoad");' . '});');
parent::display($tpl);
}
示例15: display
public function display()
{
$this->assign('sitebase', trim(JURI::root(), '/'));
$this->assign('token', JUtility::getToken());
$this->assign('container', $this->getModel()->getState()->container);
return parent::display();
}