本文整理汇总了PHP中JSession::checkToken方法的典型用法代码示例。如果您正苦于以下问题:PHP JSession::checkToken方法的具体用法?PHP JSession::checkToken怎么用?PHP JSession::checkToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSession
的用法示例。
在下文中一共展示了JSession::checkToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: featured
/**
* Method to toggle the featured setting of a list of articles.
*
* @return void
* @since 1.6
*/
function featured()
{
// Check for request forgeries
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Initialise variables.
$user = JFactory::getUser();
$ids = JRequest::getVar('cid', array(), '', 'array');
$values = array('featured' => 1, 'unfeatured' => 0);
$task = $this->getTask();
$value = JArrayHelper::getValue($values, $task, 0, 'int');
// Access checks.
foreach ($ids as $i => $id) {
if (!$user->authorise('core.edit.state', 'com_content.article.' . (int) $id)) {
// Prune items that you can't change.
unset($ids[$i]);
JError::raiseNotice(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
}
}
if (empty($ids)) {
JError::raiseWarning(500, JText::_('JERROR_NO_ITEMS_SELECTED'));
} else {
// Get the model.
$model = $this->getModel();
// Publish the items.
if (!$model->featured($ids, $value)) {
JError::raiseWarning(500, $model->getError());
}
}
$this->setRedirect('index.php?option=com_content&view=articles');
}
示例2: switchAdminLanguage
/**
* Task to switch the administrator language.
*
* @return void
*/
public function switchAdminLanguage()
{
// Check for request forgeries.
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$cid = $this->input->get('cid', '');
$model = $this->getModel('installed');
// Fetching the language name from the xx-XX.xml
$file = JPATH_ADMINISTRATOR . '/language/' . $cid . '/' . $cid . '.xml';
$info = JInstaller::parseXMLInstallFile($file);
$languageName = $info['name'];
if ($model->switchAdminLanguage($cid)) {
// Switching to the new language for the message
$language = JFactory::getLanguage();
$newLang = JLanguage::getInstance($cid);
JFactory::$language = $newLang;
JFactory::getApplication()->loadLanguage($language = $newLang);
$newLang->load('com_languages', JPATH_ADMINISTRATOR);
$msg = JText::sprintf('COM_LANGUAGES_MSG_SWITCH_ADMIN_LANGUAGE_SUCCESS', $languageName);
$type = 'message';
} else {
$msg = $model->getError();
$type = 'error';
}
$this->setRedirect('index.php?option=com_languages&view=installed', $msg, $type);
}
示例3: delete
public function delete()
{
// Check for request forgeries
JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
// Get items to remove from the request.
$cid = JFactory::getApplication()->input->get('cid', array(), 'array');
if (!is_array($cid) || count($cid) < 1) {
JLog::add(JText::_($this->text_prefix . '_NO_ITEM_SELECTED'), JLog::WARNING, 'jerror');
} else {
// Get the model.
$model = $this->getModel();
// Make sure the item ids are integers
jimport('joomla.utilities.arrayhelper');
JArrayHelper::toInteger($cid);
// Remove the items.
if ($model->delete($cid)) {
$this->setMessage(JText::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid)));
} else {
$this->setMessage($model->getError());
}
}
$version = new JVersion();
if ($version->isCompatible('3.0')) {
// Invoke the postDelete method to allow for the child class to access the model.
$this->postDeleteHook($model, $cid);
}
$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false));
}
示例4: importData
public function importData()
{
// Check for request forgeries
JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
// check if import is allowed for this user.
$user = JFactory::getUser();
if ($user->authorise('help_document.import', 'com_costbenefitprojection') && $user->authorise('core.import', 'com_costbenefitprojection')) {
// Get the import model
$model = $this->getModel('Help_documents');
// get the headers to import
$headers = $model->getExImPortHeaders();
if (CostbenefitprojectionHelper::checkObject($headers)) {
// Load headers to session.
$session = JFactory::getSession();
$headers = json_encode($headers);
$session->set('help_document_VDM_IMPORTHEADERS', $headers);
$session->set('backto_VDM_IMPORT', 'help_documents');
$session->set('dataType_VDM_IMPORTINTO', 'help_document');
// Redirect to import view.
$message = JText::_('COM_COSTBENEFITPROJECTION_IMPORT_SELECT_FILE_FOR_HELP_DOCUMENTS');
$this->setRedirect(JRoute::_('index.php?option=com_costbenefitprojection&view=import', false), $message);
return;
}
}
// Redirect to the list screen with error.
$message = JText::_('COM_COSTBENEFITPROJECTION_IMPORT_FAILED');
$this->setRedirect(JRoute::_('index.php?option=com_costbenefitprojection&view=help_documents', false), $message, 'error');
return;
}
示例5: featured
/**
* Method to toggle the featured setting of a list of teamids.
*
* @return void
*
*/
public function featured()
{
// Check for request forgeries
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$user = JFactory::getUser();
$ids = $this->input->getVar('cid', array(), 'array');
$values = array('featured' => 1, 'unfeatured' => 0);
$task = $this->getTask();
$value = JArrayHelper::getValue($values, $task, 0, 'int');
// Get the model.
$model = $this->getModel();
// Access checks.
foreach ($ids as $i => $id) {
$item = $model->getItem($id);
if (!$user->authorise('core.edit.state', 'com_knvbapi2.teamid.' . $id)) {
// Prune items that you can't change.
unset($ids[$i]);
JError::raiseNotice(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
}
}
if (empty($ids)) {
JError::raiseWarning(500, JText::_('COM_KNVBAPI2_TEAMIDS_NO_ITEM_SELECTED'));
} else {
// Publish the items.
if (!$model->featured($ids, $value)) {
JError::raiseWarning(500, $model->getError());
}
if ($value == 1) {
$message = JText::plural('COM_KNVBAPI2_TEAMIDS_N_ITEMS_FEATURED', count($ids));
} else {
$message = JText::plural('COM_KNVBAPI2_TEAMIDS_N_ITEMS_UNFEATURED', count($ids));
}
}
$this->setRedirect(JRoute::_('index.php?option=com_knvbapi2&view=teamids', false), $message);
}
示例6: enableau
/**
* Enable auto-update.
*
* @throws Exception
* @return void
*/
public function enableau()
{
// Check for request forgeries
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$redirectOptions = array("view" => "urls");
$cid = $this->input->post->get("cid", array(), "array");
$cid = Joomla\Utilities\ArrayHelper::toInteger($cid);
$data = array('enableau' => 1, 'disableau' => 0);
$task = $this->getTask();
$value = JArrayHelper::getValue($data, $task, 0, 'int');
if (empty($cid)) {
$this->displayNotice(JText::_($this->text_prefix . '_ERROR_NO_ITEM_SELECTED'), $redirectOptions);
return;
}
try {
$model = $this->getModel();
$model->updateAutoupdate($cid, $value);
} catch (Exception $e) {
JLog::add($e->getMessage());
throw new Exception(JText::_('COM_ITPMETA_ERROR_SYSTEM'));
}
if ($value == 1) {
$msg = $this->text_prefix . '_N_ITEMS_AUTOUPDATE_ENABLED';
} else {
$msg = $this->text_prefix . '_N_ITEMS_AUTOUPDATE_DISABLED';
}
$this->displayMessage(JText::plural($msg, count($cid)), $redirectOptions);
}
示例7: __construct
} else {
require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_languages' . DS . 'helpers' . DS . 'jsonresponse.php';
}
/**
* Content controller class.
*/
class J2XMLControllerCategories extends JControllerAbstract
{
function __construct($default = array())
{
parent::__construct();
}
public function display($cachable = false, $urlparams = false)
{
JRequest::setVar('view', 'categories');
parent::display($cachable, $urlparams);
}
function send()
{
if (!JSession::checkToken('request')) {
// Check for a valid token. If invalid, send a 403 with the error message.
JError::raiseWarning(403, JText::_('JINVALID_TOKEN'));
echo version_compare(JPlatform::RELEASE, '12', 'ge') ? new JResponseJson() : new JJsonResponse();
return;
}
$cid = JRequest::getVar('cid', array(0), null, 'array');
$sid = JRequest::getVar('w_id', null, null, 'int');
示例8: execute
/**
* Execute the controller.
*
* @return void
*
* @since 3.1
*/
public function execute()
{
// Get the application
/* @var InstallationApplicationWeb $app */
$app = $this->getApplication();
// Check for request forgeries.
JSession::checkToken() or $app->sendJsonResponse(new Exception(JText::_('JINVALID_TOKEN'), 403));
// Get array of selected languages
$lids = $this->input->get('cid', array(), 'array');
JArrayHelper::toInteger($lids, array());
// Get the languages model.
$model = new InstallationModelLanguages();
if (!$lids) {
// No languages have been selected
$app->enqueueMessage(JText::_('INSTL_LANGUAGES_NO_LANGUAGE_SELECTED'), 'warning');
} else {
// Install selected languages
$model->install($lids);
// Publish the Content Languages.
$model->publishContentLanguages();
$app->enqueueMessage(JText::_('INSTL_LANGUAGES_MORE_LANGUAGES'), 'notice');
}
// Redirect to the page.
$r = new stdClass();
$r->view = 'defaultlanguage';
$app->sendJsonResponse($r);
}
示例9: execute
/**
* Return AJAX for the requested layout.
*
* @return string String in JSON or RAW.
*
* @throws RuntimeException
* @throws KunenaExceptionAuthorise
*/
public function execute()
{
$format = $this->input->getWord('format', 'html');
$function = 'display' . ucfirst($format);
if (!method_exists($this, $function)) {
// Invalid page request.
throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 404);
}
// Run before executing action.
$result = $this->before();
if ($result === false) {
$content = new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 404);
} elseif (!JSession::checkToken()) {
// Invalid access token.
$content = new KunenaExceptionAuthorise(JText::_('COM_KUNENA_ERROR_TOKEN'), 403);
} elseif ($this->config->board_offline && !$this->me->isAdmin()) {
// Forum is offline.
$content = new KunenaExceptionAuthorise(JText::_('COM_KUNENA_FORUM_IS_OFFLINE'), 503);
} elseif ($this->config->regonly && !$this->me->exists()) {
// Forum is for registered users only.
$content = new KunenaExceptionAuthorise(JText::_('COM_KUNENA_LOGIN_NOTIFICATION'), 401);
} else {
$display = $this->input->getCmd('display', 'Undefined') . '/Display';
try {
$content = KunenaRequest::factory($display, $this->input, $this->options)->setPrimary()->execute()->render();
} catch (Exception $e) {
$content = $e;
}
}
return $this->{$function}($content);
}
示例10: save
public function save()
{
die('Save in projectposition controller');
// Check for request forgeries
JSession::checkToken() or die('COM_JOOMLEAGUE_GLOBAL_INVALID_TOKEN');
echo '<br /><pre>2' . print_r($post, true) . '~</pre><br />';
$post = JRequest::get('post');
$cid = JRequest::getVar('cid', array(0), 'post', 'array');
$post['id'] = (int) $cid[0];
$model = $this->getModel('projectposition');
//if ($model->store($post))
if (1 == 2) {
$msg = JText::_('COM_JOOMLEAGUE_ADMIN_P_POSITION_CTRL_TEAM_SAVED');
} else {
$msg = JText::_('COM_JOOMLEAGUE_ADMIN_P_POSITION_CTRL_ERROR_SAVING_TEAM') . $model->getError();
}
// Check the table in so it can be edited.... we are done with it anyway
$model->checkin();
$task = $this->getTask();
if ($task == 'save') {
$link = 'index.php?option=com_joomleague&view=projectposition&task=projectposition.display';
} else {
$link = 'index.php?option=com_joomleague&task=projectposition.edit&cid[]=' . $post['id'];
}
//$this->setRedirect($link,$msg);
}
示例11: featured
/**
* Method to toggle the featured setting of a list of contacts.
*
* @return void
*
* @since 1.6
*/
public function featured()
{
// Check for request forgeries
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$ids = $this->input->get('cid', array(), 'array');
$values = array('featured' => 1, 'unfeatured' => 0);
$task = $this->getTask();
$value = ArrayHelper::getValue($values, $task, 0, 'int');
// Get the model.
/** @var ContactModelContact $model */
$model = $this->getModel();
// Access checks.
foreach ($ids as $i => $id) {
$item = $model->getItem($id);
if (!JFactory::getUser()->authorise('core.edit.state', 'com_contact.category.' . (int) $item->catid)) {
// Prune items that you can't change.
unset($ids[$i]);
JError::raiseNotice(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
}
}
if (empty($ids)) {
JError::raiseWarning(500, JText::_('COM_CONTACT_NO_ITEM_SELECTED'));
} else {
// Publish the items.
if (!$model->featured($ids, $value)) {
JError::raiseWarning(500, $model->getError());
}
}
$this->setRedirect('index.php?option=com_contact&view=contacts');
}
示例12: addFunders
/**
* Add funders to Acy Mailing list.
*
* @throws Exception
*/
public function addFunders()
{
// Check for request forgeries.
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$app = JFactory::getApplication();
/** @var $app JApplicationAdministrator */
$response = new Prism\Response\Json();
$projectId = $this->input->post->getInt('acy_pid');
$listId = $this->input->post->getInt('acy_lid');
$model = $this->getModel();
$numberOfAdded = 0;
try {
$numberOfAdded = $model->addFundersToAcyList($projectId, $listId);
} catch (Exception $e) {
JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding');
$response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure();
echo $response;
$app->close();
}
if (!$numberOfAdded) {
$response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_CANNOT_BE_ADDED_SUBSCRIBERS'))->failure();
} else {
$response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::sprintf('COM_CROWDFUNDING_ADDED_SUBSCRIBERS_D', $numberOfAdded))->success();
}
echo $response;
$app->close();
}
示例13: execute
/**
* Execute the controller.
*
* @return void
*
* @since 3.1
*/
public function execute()
{
// Get the application
/* @var InstallationApplicationWeb $app */
$app = $this->getApplication();
// Check for request forgeries.
JSession::checkToken() or $app->sendJsonResponse(new Exception(JText::_('JINVALID_TOKEN'), 403));
// Get the setup model.
$model = new InstallationModelSetup();
// Check the form
$vars = $model->checkForm('database');
// Determine if the configuration file path is writable.
$path = JPATH_CONFIGURATION . '/configuration.php';
$useftp = file_exists($path) ? !is_writable($path) : !is_writable(JPATH_CONFIGURATION . '/');
$r = new stdClass();
$r->view = $useftp ? 'ftp' : 'summary';
// Get the database model.
$db = new InstallationModelDatabase();
// Attempt to initialise the database.
$return = $db->createDatabase($vars);
// Check if the database was initialised
if (!$return) {
$r->view = 'database';
}
$app->sendJsonResponse($r);
}
示例14: getStatistics
public function getStatistics()
{
// Check for request forgeries
JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
// Get component parameters
$params = JComponentHelper::getParams('com_isbnregistry');
// Get statistics file format
$format = $params->get('statistics_format', 'XLS');
// Get form data
$data = $this->input->post->get('jform', array(), 'array');
// Get begin
$begin = $data['begin'];
// Get end
$end = $data['end'];
// Get type
$type = $data['type'];
// Redirect
if ($this->validateDate($begin) && $this->validateDate($end) && $this->validateType($type)) {
$this->setRedirect('index.php?option=com_isbnregistry&view=statistic&format=' . strtolower($format) . '&begin=' . $begin . '&end=' . $end . '&type=' . $type);
} else {
if (!$this->validateType($type)) {
$this->setMessage(JText::_('COM_ISBNREGISTRY_STATISTIC_INVALID_TYPE'), 'error');
} else {
$this->setMessage(JText::_('COM_ISBNREGISTRY_STATISTIC_INVALID_DATE'), 'error');
}
$this->setRedirect('index.php?option=com_isbnregistry&view=statistic&layout=popup&tmpl=component');
}
$this->redirect();
}
示例15: save
/**
* save a ad fields
*/
function save()
{
// Check for request forgeries
JSession::checkToken() or jexit('Invalid Token');
$input = JFactory::getApplication()->input;
$model = $this->getModel('settings');
$post = JRequest::get('post');
// allow name only to contain html
$model->setState('request', $post);
if ($model->store()) {
$msg = JText::_('C_SAVE_M_S');
} else {
$msg = JText::_('C_SAVE_M_NS');
}
$task = $input->get('task', '', 'STRING');
switch ($task) {
case 'cancel':
$cancelmsg = JText::_('FIELD_CANCEL_MSG');
$this->setRedirect('index.php?option=com_socialads', $msg);
break;
case 'save':
$this->setRedirect(JUri::base() . "index.php?option=com_socialads&view=settings", $msg);
break;
}
}