本文整理汇总了PHP中JApplication::getHash方法的典型用法代码示例。如果您正苦于以下问题:PHP JApplication::getHash方法的具体用法?PHP JApplication::getHash怎么用?PHP JApplication::getHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JApplication
的用法示例。
在下文中一共展示了JApplication::getHash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getHash
public function getHash($seed = '')
{
if (DiscussHelper::getJoomlaVersion() >= '2.5') {
return JApplication::getHash($seed);
}
return JUtility::getHash($seed);
}
示例2: createNewUser
public function createNewUser($params)
{
$user = new JUser(0);
JLoader::import('joomla.application.component.helper');
$usersConfig = JComponentHelper::getParams('com_users');
$newUsertype = $usersConfig->get('new_usertype');
// get the New User Group from com_users' settings
if (empty($newUsertype)) {
$newUsertype = 2;
}
$params['groups'] = array($newUsertype);
$params['sendEmail'] = 0;
// Set the user's default language to whatever the site's current language is
if (version_compare(JVERSION, '3.0', 'ge')) {
$params['params'] = array('language' => JFactory::getConfig()->get('language'));
} else {
$params['params'] = array('language' => JFactory::getConfig()->getValue('config.language'));
}
JLoader::import('joomla.user.helper');
$params['block'] = 0;
$randomString = JUserHelper::genRandomPassword();
if (version_compare(JVERSION, '3.2', 'ge')) {
$hash = JApplication::getHash($randomString);
} else {
$hash = JFactory::getApplication()->getHash($randomString);
}
$params['activation'] = $hash;
$user->bind($params);
$userIsSaved = $user->save();
if ($userIsSaved) {
return $user->id;
} else {
return false;
}
}
示例3: onAfterInitialise
/**
* Event onAfterInitialise
*
* @access public
* @param null
* @return null
*/
public function onAfterInitialise()
{
// If this is the Administrator-application, or if debugging is set, do nothing
$application = JFactory::getApplication();
if ($application->isAdmin()) {
return;
}
// Disable browser-detection
$application->setDetectBrowser(false);
// Detect the language
$languageTag = JFactory::getLanguage()->getTag();
$languageInput = JRequest::getString('language');
// Get the bindings
$bindings = $this->getBindings();
// Check for the binding of the current language
if (!empty($languageInput)) {
if (isset($bindings[$languageTag])) {
$domain = $bindings[$languageTag];
if (stristr(JURI::current(), $domain) == false) {
// Add URL-elements to the domain
$domain = $this->getUrlFromDomain($domain);
// Replace the current domain with the new domain
$currentUrl = JURI::current();
$newUrl = str_replace(JURI::base(), $domain, $currentUrl);
// Strip out the sef-language-part
$languages = JLanguageHelper::getLanguages('sef');
foreach ($languages as $languageSef => $language) {
if ($language->lang_code == $languageTag) {
//$newUrl = str_replace('/'.$languageSef.'/', '/', $newUrl); // @todo: This d
break;
}
}
// Set the cookie
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('config.cookie_domain', '');
$cookie_path = $conf->get('config.cookie_path', '/');
setcookie(JApplication::getHash('language'), $languageTag, time() + 365 * 86400, $cookie_path, $cookie_domain);
// Redirect
$application->redirect($newUrl);
$application->close();
}
}
} else {
// Check if the current default language is correct
foreach ($bindings as $languageCode => $domain) {
if (stristr(JURI::current(), $domain) == true) {
// Set the cookie
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('config.cookie_domain', '');
$cookie_path = $conf->get('config.cookie_path', '/');
setcookie(JApplication::getHash('language'), $languageCode, time() + 365 * 86400, $cookie_path, $cookie_domain);
// Change the current default language
JRequest::setVar('language', $languageCode);
JFactory::getLanguage()->setDefault($languageCode);
JFactory::getLanguage()->setLanguage($languageCode);
break;
}
}
}
}
示例4: loginSite
private function loginSite()
{
$app = JFactory::getApplication();
$db = JFactory::getDbo();
// already logedin
if (JFactory::getUser()->id) {
return;
}
$query = $db->getQuery(true)->select('userid')->from('#__session')->where('session_id = ' . $db->quote($app->input->cookie->get(md5(JApplication::getHash('administrator')))))->where('client_id = 1')->where('guest = 0');
$db->setQuery($query);
$userid = $db->loadResult();
// no backend session found;
if (!$userid) {
return;
}
$user = JFactory::getUser($userid);
// user load failed
if ($user instanceof Exception || $user->get('block') == 1) {
return;
}
$session = JFactory::getSession();
$session->set('user', $user);
$app->checkSession();
$query = $db->getQuery(true)->update($db->quoteName('#__session'))->set($db->quoteName('guest') . ' = ' . $db->quote($user->get('guest')))->set($db->quoteName('username') . ' = ' . $db->quote($user->get('username')))->set($db->quoteName('userid') . ' = ' . (int) $user->get('id'))->where($db->quoteName('session_id') . ' = ' . $db->quote($session->getId()));
$db->setQuery($query);
$db->execute();
$app->redirect('index.php');
}
示例5: requestReset
/**
* Verifies the validity of a username/e-mail address
* combination and creates a token to verify the request
* was initiated by the account owner. The token is
* sent to the account owner by e-mail
*
* @since 1.5
* @param string Username string
* @param string E-mail address
* @return bool True on success/false on failure
*/
function requestReset($email)
{
jimport('joomla.mail.helper');
jimport('joomla.user.helper');
$db = JFactory::getDBO();
// Make sure the e-mail address is valid
if (!JMailHelper::isEmailAddress($email)) {
$this->setError(JText::_('COM_CITRUSCART_EMAIL_ADDRESS_IS_INVALID'));
return false;
}
// Build a query to find the user
$query = 'SELECT id FROM #__users' . ' WHERE email = ' . $db->q($email) . ' AND block = 0';
$db->setQuery($query);
// Check the results
if (!($id = $db->loadResult())) {
$this->setError(JText::_('COM_CITRUSCART_COULD_NOT_FIND_USER'));
return false;
}
// Generate a new token
$token = JApplication::getHash(JUserHelper::genRandomPassword());
$query = 'UPDATE #__users' . ' SET activation = ' . $db->q($token) . ' WHERE id = ' . (int) $id . ' AND block = 0';
$db->setQuery($query);
// Save the token
if (!$db->query()) {
$this->setError(JText::_('COM_CITRUSCART_DATABASE_ERROR'));
return false;
}
// Send the token to the user via e-mail
if (!$this->_sendConfirmationMail($email, $token)) {
return false;
}
return true;
}
示例6: prepareDisplay
protected function prepareDisplay($preconfig)
{
if (JCck::getConfig_Param('debug', 0)) {
jimport('joomla.error.profiler');
$profiler = new JProfiler();
}
$app = JFactory::getApplication();
$this->form = $this->get('Form');
$this->option = $app->input->get('option', '');
$this->item = $this->get('Item');
$this->state = $this->get('State');
$option = $this->option;
$params = new JRegistry();
$view = $this->getName();
$isNew = 1;
$live = '';
$lives = array();
$variation = '';
jimport('cck.base.form.form');
include_once JPATH_LIBRARIES_CCK . '/base/form/form_inc.php';
if (isset($config['id'])) {
JFactory::getSession()->set('cck_hash_seblod_form', JApplication::getHash($id . '|' . $type->name . '|' . $config['id']));
}
$this->config =& $config;
$this->data =& $data;
$this->id =& $id;
$this->isNew =& $isNew;
$this->params =& $params;
$this->stage =& $stage;
$this->type =& $type;
$title = isset($type->title) ? $type->title : '';
$name = isset($type->name) ? $type->name : '';
$this->addToolbar($title, $name);
}
示例7: populateState
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
*/
protected function populateState()
{
$basename = JRequest::getString(JApplication::getHash($this->_context . '.basename'), '__SITE__', 'cookie');
$this->setState('basename', $basename);
$compressed = JRequest::getInt(JApplication::getHash($this->_context . '.compressed'), 1, 'cookie');
$this->setState('compressed', $compressed);
}
示例8: onAfterInitialise
function onAfterInitialise()
{
$app = JFactory::getApplication();
// No remember me for admin
if ($app->isAdmin()) {
return;
}
$user = JFactory::getUser();
if ($user->get('guest')) {
$hash = JApplication::getHash('JLOGIN_REMEMBER');
if ($str = JRequest::getString($hash, '', 'cookie', JREQUEST_ALLOWRAW | JREQUEST_NOTRIM)) {
jimport('joomla.utilities.simplecrypt');
$credentials = array();
$goodCookie = true;
$filter = JFilterInput::getInstance();
// Create the encryption key, apply extra hardening using the user agent string.
// Since we're decoding, no UA validity check is required.
$privateKey = JApplication::getHash(@$_SERVER['HTTP_USER_AGENT']);
$key = new JCryptKey('simple', $privateKey, $privateKey);
$crypt = new JCrypt(new JCryptCipherSimple(), $key);
try {
$str = $crypt->decrypt($str);
if (!is_string($str)) {
throw new Exception('Decoded cookie is not a string.');
}
$cookieData = json_decode($str);
if (null === $cookieData) {
throw new Exception('JSON could not be docoded.');
}
if (!is_object($cookieData)) {
throw new Exception('Decoded JSON is not an object.');
}
// json_decoded cookie could be any object structure, so make sure the
// credentials are well structured and only have user and password.
if (isset($cookieData->username) && is_string($cookieData->username)) {
$credentials['username'] = $filter->clean($cookieData->username, 'username');
} else {
throw new Exception('Malformed username.');
}
if (isset($cookieData->password) && is_string($cookieData->password)) {
$credentials['password'] = $filter->clean($cookieData->password, 'string');
} else {
throw new Exception('Malformed password.');
}
$return = $app->login($credentials, array('silent' => true));
if (!$return) {
throw new Exception('Log-in failed.');
}
} catch (Exception $e) {
$config = JFactory::getConfig();
$cookie_domain = $config->get('cookie_domain', '');
$cookie_path = $config->get('cookie_path', '/');
// Clear the remember me cookie
setcookie(JApplication::getHash('JLOGIN_REMEMBER'), false, time() - 86400, $cookie_path, $cookie_domain);
JLog::add('A remember me cookie was unset for the following reason: ' . $e->getMessage(), JLog::WARNING, 'security');
}
}
}
}
示例9: populateState
/**
* Auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
*
* @since 1.6
*/
protected function populateState()
{
$input = JFactory::getApplication()->input;
$basename = $input->cookie->getString(JApplication::getHash($this->_context . '.basename'), '__SITE__');
$this->setState('basename', $basename);
$compressed = $input->cookie->getInt(JApplication::getHash($this->_context . '.compressed'), 1);
$this->setState('compressed', $compressed);
}
示例10: testGetHash
/**
* Testing JApplication::getHash
*
* @return void
*/
public function testGetHash()
{
// Temporarily override the config cache in JFactory.
$temp = JFactory::$config;
JFactory::$config = new JObject(array('secret' => 'foo'));
$this->assertThat(JApplication::getHash('This is a test'), $this->equalTo(md5('foo' . 'This is a test')), 'Tests that the secret string is added to the hash.');
JFactory::$config = $temp;
}
示例11: getUrl
public function getUrl()
{
if (!isset($this->url)) {
$application = JFactory::getApplication();
$hash = JApplication::getHash($this->id);
$this->url = JRoute::_('index.php?option=com_k2&view=attachments&task=download&id=' . $this->id . '&hash=' . $hash, true, -1);
}
return $this->url;
}
示例12: cartEnter
public static function cartEnter()
{
require_once JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'helpers' . DS . 'opctracking.php';
$hash2 = uniqid('opc', true);
$hashn = JApplication::getHash('opctracking');
$hash = JRequest::getVar($hashn, $hash2, 'COOKIE');
if ($hash2 == $hash) {
OPCtrackingHelper::setCookie($hash);
}
}
示例13: alreadyVoted
function alreadyVoted($id)
{
$mainframe = JFactory::getApplication();
if (MijopollsHelper::is30()) {
$cookieName = JApplication::getHash($mainframe->getName() . 'poll' . $id);
} else {
$cookieName = JUtility::getHash($mainframe->getName() . 'poll' . $id);
}
$voted = JRequest::getVar($cookieName, '0', 'COOKIE', 'INT');
return $voted;
}
示例14: onUserLogout
/**
* This method should handle any logout logic and report back to the subject
*
* @param array $user Holds the user data.
* @param array $options Array holding options (client, ...).
*
* @return object True on success
* @since 1.5
*/
public function onUserLogout($user, $options = array())
{
if (JFactory::getApplication()->isSite()) {
// Create the cookie
$hash = JApplication::getHash('plgSystemLogout');
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('config.cookie_domain', '');
$cookie_path = $conf->get('config.cookie_path', '/');
setcookie($hash, true, time() + 86400, $cookie_path, $cookie_domain);
}
return true;
}
示例15: getName
static function getName()
{
$clientId = JRequest::getInt('client', 0, 'get');
$client = $clientId ? 'administrator' : 'site';
$hash = '';
if (method_exists('JUtility', 'getHash')) {
$hash = JUtility::getHash($client);
} else {
$hash = JApplication::getHash($client);
}
return $hash;
}