本文整理汇总了PHP中JInput类的典型用法代码示例。如果您正苦于以下问题:PHP JInput类的具体用法?PHP JInput怎么用?PHP JInput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onContentBeforeSave
/**
* Example before save content method
*
* Method is called right before content is saved into the database.
* Article object is passed by reference, so any changes will be saved!
* NOTE: Returning false will abort the save with an error.
*You can set the error by calling $article->setError($message)
*
* @param string The context of the content passed to the plugin.
* @param object A JTableContent object
* @param bool If the content is just about to be created
* @return bool If false, abort the save
* @since 1.6
*/
public function onContentBeforeSave($context, $article, $isNew)
{
//error_log("plgContentArticlesubmit::onContentBeforeSave") ;
$app = JFactory::getApplication();
// run this plugin only for com_content
$parts = explode(".", $context);
if ($parts[0] != 'com_content') {
return true;
}
// dont do anything is it is not frontend
if (!$app->isSite()) {
return true;
}
$jinput = $app->input;
$formData = new JInput($jinput->get('jform', '', 'array'));
//error_log("jinput == " . print_r($jinput,true));
$introtext = $formData->get('article_introtext', '', 'html');
//error_log("introtext == " . $introtext);
$fulltext = $formData->get('article_fulltext', '', 'raw');
//error_log("fulltext == " . $fulltext);
$article->introtext = $introtext;
$article->fulltext = $fulltext;
$savedImage = $this->saveImage($article);
if ($savedImage) {
$images = array();
$images['image_fulltext'] = $savedImage;
$images['image_intro'] = $savedImage;
$article->images = json_encode($images);
return true;
} else {
$article->setError("Could not process the uploaded image. Please try again with a different (smaller) image.");
return false;
}
return true;
}
示例2: validate
function validate()
{
$return = array('error' => 0, 'msg' => array());
$input = new JInput();
$ajax = $input->getInt('ajax', 0);
$email = $input->getString('email', '');
$name = $input->getString('name', '');
$username = $input->getString('username', '');
if ($email && !$this->validateEmail($email)) {
$return['error'] = +1;
$return['msg'][] = JText::_('COM_SLOGIN_ERROR_VALIDATE_MAIL');
}
if ($email && !$this->checkUniqueEmail($email)) {
$return['error'] = +1;
$return['msg'][] = JText::_('COM_SLOGIN_ERROR_NOT_UNIQUE_MAIL');
}
if ($name && !$this->validateName($name)) {
$return['error'] = +1;
$return['msg'][] = JText::_('COM_SLOGIN_ERROR_VALIATE_NAME');
}
if ($username && !$this->validateUserName($username)) {
$return['error'] = +1;
$return['msg'][] = JText::_('COM_SLOGIN_ERROR_VALIATE_USERNAME');
}
if ($ajax) {
echo json_encode($return);
die;
}
return $return;
}
示例3: detectRemoteUser
/**
* This method checks if a value for remote user is present inside
* the $_SERVER array. If so then replace any domain related stuff
* to get the username and return it.
*
* @return mixed Username of detected user or False.
*
* @since 1.0
*/
public function detectRemoteUser()
{
/*
* When legacy flag is true, it ensures compatibility with JSSOMySite 1.x by
* only returning a string username or false can be returned. This also means
* keeping compatibility with Joomla 1.6.
* When it is set to False, it can return an array and compatible with Joomla 2.5.
*/
$legacy = $this->params->get('use_legacy', false);
// Get the array key of $_SERVER where the user can be located
$serverKey = strtoupper($this->params->get('userkey', 'REMOTE_USER'));
// Get the $_SERVER key and ensure its lowercase and doesn't filter
if ($legacy) {
// Get the $_SERVER value which should contain the SSO username
$remoteUser = JRequest::getVar($serverKey, null, 'server', 'string', JREQUEST_ALLOWRAW);
} else {
// Get the $_SERVER value which should contain the SSO username
$input = new JInput($_SERVER);
$remoteUser = $input->get($serverKey, null, 'USERNAME');
unset($input);
}
// Ensures the returned user is lowercased
$remoteUser = strtolower($remoteUser);
// Get a username replacement parameter in lowercase and split by semi-colons
$replace_set = explode(';', strtolower($this->params->get('username_replacement', '')));
foreach ($replace_set as $replacement) {
$remoteUser = str_replace(trim($replacement), '', $remoteUser);
}
// Returns the username
return $remoteUser;
}
示例4: build
function build()
{
$jinput = new JInput();
//Initialize default form
$keys = array('option' => $this->getExtension(), 'view' => $this->getView(), 'layout' => $jinput->get('layout', null, 'CMD'), 'task' => "");
//For item layout
if (isset($this->dataObject)) {
$keys['id'] = isset($this->dataObject->id) ? $this->dataObject->id : 0;
//Deprecated
$keys['cid[]'] = isset($this->dataObject->id) ? $this->dataObject->id : 0;
}
//Specifics values or overrides
if (isset($this->values)) {
foreach ($this->values as $key => $value) {
$keys[$key] = $value;
}
}
//Reproduce current query in the form
$followers = array('lang', 'Itemid', 'tmpl');
//Cmd types only for the moment
foreach ($followers as $follower) {
$val = $jinput->get($follower, null, 'CMD');
if ($val) {
$keys[$follower] = $val;
}
}
$html = "";
foreach ($keys as $key => $value) {
$html .= JDom::_('html.form.input.hidden', array('dataKey' => $key, 'dataValue' => $value));
}
//Token
$html .= JHTML::_('form.token');
return $html;
}
示例5: onAfterInitialise
public function onAfterInitialise()
{
// Make sure this is the back-end
$app = JFactory::getApplication();
if (!in_array($app->getName(), array('administrator', 'admin'))) {
return;
}
if (version_compare(JVERSION, '2.5.0', 'lt')) {
$this->autoDisable();
return;
}
// Get the input variables
$ji = new JInput();
$component = $ji->getCmd('option', '');
$task = $ji->getCmd('task', '');
$view = $ji->getCmd('view', '');
$backedup = $ji->getInt('is_backed_up', 0);
// Perform a redirection on Joomla! Update download or install task, unless we have already backed up the site
if ($component == 'com_joomlaupdate' && $task == 'update.install' && !$backedup) {
// Get the backup profile ID
$profileId = (int) $this->params->get('profileid', 1);
if ($profileId <= 0) {
$profileId = 1;
}
// Get the return URL
$return_url = JUri::base() . 'index.php?option=com_joomlaupdate&task=update.install&is_backed_up=1';
// Get the redirect URL
$token = JFactory::getSession()->getToken();
$redirect_url = JUri::base() . 'index.php?option=com_akeeba&view=backup&autostart=1&returnurl=' . urlencode($return_url) . '&profileid=' . $profileId . "&{$token}=1";
// Perform the redirection
$app = JFactory::getApplication();
$app->redirect($redirect_url);
}
}
示例6: upload
/**
* upload
*
* @param \JInput $input
*/
public static function upload(\JInput $input)
{
try {
$editorPlugin = \JPluginHelper::getPlugin('editors', 'akmarkdown');
if (!$editorPlugin) {
throw new \Exception('Editor Akmarkdown not exists');
}
$params = new Registry($editorPlugin->params);
$files = $input->files;
$field = $input->get('field', 'file');
$type = $input->get('type', 'post');
$allows = $params->get('Upload_AllowExtension', '');
$allows = array_map('strtolower', array_map('trim', explode(',', $allows)));
$file = $files->getVar($field);
$src = $file['tmp_name'];
$name = $file['name'];
$tmp = new \SplFileInfo(JPATH_ROOT . '/tmp/ak-upload/' . $name);
if (empty($file['tmp_name'])) {
throw new \Exception('File not upload');
}
$ext = pathinfo($name, PATHINFO_EXTENSION);
if (!in_array($ext, $allows)) {
throw new \Exception('File extension now allowed.');
}
// Move file to tmp
if (!is_dir($tmp->getPath())) {
\JFolder::create($tmp->getPath());
}
if (is_file($tmp->getPathname())) {
\JFile::delete($tmp->getPathname());
}
\JFile::upload($src, $tmp->getPathname());
$src = $tmp;
$dest = static::getDest($name, $params->get('Upload_S3_Subfolder', 'ak-upload'));
$s3 = new \S3($params->get('Upload_S3_Key'), $params->get('Upload_S3_SecretKey'));
$bucket = $params->get('Upload_S3_Bucket');
$result = $s3::putObject(\S3::inputFile($src->getPathname(), false), $bucket, $dest, \S3::ACL_PUBLIC_READ);
if (is_file($tmp->getPathname())) {
\JFile::delete($tmp->getPathname());
}
if (!$result) {
throw new \Exception('Upload fail.');
}
} catch (\Exception $e) {
$response = new Response();
$response->setBody(json_encode(['error' => $e->getMessage()]));
$response->setMimeType('text/json');
$response->respond();
exit;
}
$return = new \JRegistry();
$return['filename'] = 'https://' . $bucket . '.s3.amazonaws.com/' . $dest;
$return['file'] = 'https://' . $bucket . '.s3.amazonaws.com/' . $dest;
$response = new Response();
$response->setBody((string) $return);
$response->setMimeType('text/json');
$response->respond();
}
示例7: testGetArrayNested
/**
* Test the JInput::get method using a nested data set.
*/
public function testGetArrayNested()
{
$filterMock = new JFilterInputMockTracker();
$input = new JInput(array('var2' => 34, 'var3' => array('var2' => 'test'), 'var4' => array('var1' => array('var2' => 'test'))), array('filter' => $filterMock));
$this->assertThat($input->getArray(array('var2' => 'filter2', 'var3' => array('var2' => 'filter3'))), $this->equalTo(array('var2' => 34, 'var3' => array('var2' => 'test'))), 'Line: ' . __LINE__ . '.');
$this->assertThat($input->getArray(array('var4' => array('var1' => array('var2' => 'filter1')))), $this->equalTo(array('var4' => array('var1' => array('var2' => 'test')))), 'Line: ' . __LINE__ . '.');
$this->assertThat($filterMock->calls['clean'][0], $this->equalTo(array(34, 'filter2')), 'Line: ' . __LINE__ . '.');
$this->assertThat($filterMock->calls['clean'][1], $this->equalTo(array(array('var2' => 'test'), 'array')), 'Line: ' . __LINE__ . '.');
}
示例8: display
/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return JController This object to support chaining.
* @since 1.5
*/
public function display($cachable = false, $urlparams = false)
{
// TemplateckHelper::addSubmenu(JRequest::getCmd('view', 'templates'));
$input = new JInput();
$view = $input->get('view', 'Modulesmanagerck');
$input->set('view', $view);
parent::display();
return $this;
}
示例9: detectRemoteUser
/**
* Gets the IP address of the client machine, translates it to a compatiable
* eDirectory netadress and queries it against the LDAP server using a filter.
*
* @return mixed Username of detected user or False.
*
* @since 1.0
*/
public function detectRemoteUser()
{
// Import languages for frontend errors
$this->loadLanguage();
/*
* When legacy flag is true, it ensures compatibility with JSSOMySite 1.x by
* only returning a string username or false can be returned. This also means
* keeping compatibility with Joomla 1.6.
* When it is set to False, it can return an array and compatible with Joomla 2.5.
*/
$legacy = $this->params->get('use_legacy', false);
if ($legacy) {
// Use legacy way of getting paramters
$authParams = new JRegistry();
$authName = $this->params->get('auth_plugin', 'jmapmyldap');
$authPlugin = JPluginHelper::getPlugin('authentication', $authName);
$authParams->loadString($authPlugin->params);
$ldapUid = $authParams->get('ldap_uid', 'uid');
// Attempt to load up a LDAP instance using the legacy method
jimport('shmanic.jldap2');
$ldap = new JLDAP2($authParams);
// Lets try to bind using proxy user
if (!$ldap->connect() || !$ldap->bind($ldap->connect_username, $ldap->connect_password)) {
JError::raiseWarning('SOME_ERROR_CODE', JText::_('PLG_EDIR_ERROR_LDAP_BIND'));
return;
}
// Get IP of client machine
$myip = JRequest::getVar('REMOTE_ADDR', 0, 'server');
// Convert this to some net address thing that edir likes
$na = JLDAPHelper::ipToNetAddress($myip);
// Find the network address and return the uid for it
$filter = "(networkAddress={$na})";
$dn = $authParams->get('base_dn');
// Do the LDAP filter search now
$result = new JLDAPResult($ldap->search($dn, $filter, array($ldapUid)));
$ldap->close();
} else {
try {
// We will only check the first LDAP config
$ldap = SHLdap::getInstance();
$ldap->proxyBind();
$ldapUid = $ldap->getUid;
// Get the IP address of this client and convert to netaddress for LDAP searching
$input = new JInput($_SERVER);
$myIp = $input->get('REMOTE_ADDR', false, 'string');
$na = SHLdapHelper::ipToNetAddress($myIp);
$result = $ldap->search(null, "(networkAddress={$na})", array($ldapUid));
} catch (Exception $e) {
SHLog::add($e, 16010, JLog::ERROR, 'sso');
return;
}
}
if ($value = $result->getValue(0, $ldapuid, 0)) {
// Username was found logged in on this client machine
return $value;
}
}
示例10: start
/**
* Starts the session
*
* @return boolean True if started
*
* @since 3.5
* @throws RuntimeException If something goes wrong starting the session.
*/
public function start()
{
$session_name = $this->getName();
// Get the JInputCookie object
$cookie = $this->input->cookie;
if (is_null($cookie->get($session_name))) {
$session_clean = $this->input->get($session_name, false, 'string');
if ($session_clean) {
$this->setId($session_clean);
$cookie->set($session_name, '', time() - 3600);
}
}
return parent::start();
}
示例11: confirmDelivered
public function confirmDelivered($post)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$delivered = array();
if (!empty($post['delivered'])) {
$delivered = $post['delivered'];
}
foreach ($delivered as $d) {
$query->clear();
$query->update('#__hp_order_items')->set('delivered = 1')->where('id = ' . $d)->where('business_id = ' . JFactory::getUser()->id);
$db->setQuery($query);
$db->query();
if ($db->getErrorMsg()) {
die($db->getErrorMsg());
}
}
// Upload file
$jFileInput = new JInput($_FILES);
$file = $jFileInput->get('jform', array(), 'array');
$filepath = JPATH_ROOT . DS . 'upload' . DS . 'orders' . DS . $post['order_id'] . DS;
@mkdir($filepath, 0777, true);
$uploadResult = false;
if (!empty($file['name']['file_upload'])) {
$uploadResult = JFile::upload($file['tmp_name']['file_upload'], $filepath . $file['name']['file_upload']);
}
if ($uploadResult) {
// Update to files
$fileName = $file['name']['file_upload'];
$query->clear()->insert('#__files')->columns('item_id, item_type, file_upload, description, created')->values($post['order_id'] . ', "order", ' . $db->quote($fileName) . ', ' . $db->quote($post['description']) . ', ' . $db->quote(date('Y-m-d H:i:s')));
$db->setQuery($query);
$db->query();
if ($db->getErrorMsg()) {
die($db->getErrorMsg());
}
}
// Update note
$note = trim($post['business_note']);
if (!empty($note)) {
$query->clear()->insert('#__hp_order_notes')->columns('order_id, business_id, note, created')->values($post['order_id'] . ',' . JFactory::getUser()->id . ',' . $db->quote($note) . ',' . $db->quote(date('Y-m-d H:i:s')));
$db->setQuery($query);
$db->query();
if ($db->getErrorMsg()) {
die($db->getErrorMsg());
}
}
return true;
}
示例12: _start
/**
* Start a session.
*
* Creates a session (or resumes the current one based on the state of the session)
*
* @return boolean true on success
*
* @since 11.1
*/
protected function _start()
{
// Start session if not started
if ($this->_state === 'restart') {
session_regenerate_id(true);
} else {
$session_name = session_name();
// Get the JInputCookie object
$cookie = $this->_input->cookie;
if (is_null($cookie->get($session_name))) {
$session_clean = $this->_input->get($session_name, false, 'string');
if ($session_clean) {
session_id($session_clean);
$cookie->set($session_name, '', time() - 3600);
}
}
}
/**
* Write and Close handlers are called after destructing objects since PHP 5.0.5.
* Thus destructors can use sessions but session handler can't use objects.
* So we are moving session closure before destructing objects.
*
* Replace with session_register_shutdown() when dropping compatibility with PHP 5.3
*/
register_shutdown_function('session_write_close');
session_cache_limiter('none');
session_start();
return true;
}
示例13: populateState
protected function populateState($ordering = null, $direction = null)
{
// Initialise variables.
$app = JFactory::getApplication();
$input = new JInput();
// Adjust the context to support modal layouts.
if ($layout = $input->getString('layout', 'default')) {
$this->context .= '.' . $layout;
}
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);
$provider = $this->getUserStateFromRequest($this->context . '.filter.provider', 'filter_provider', 0, 'string');
$this->setState('filter.provider', $provider);
// List state information.
parent::populateState('su.id', 'desc');
}
示例14: getOrderId
public function getOrderId()
{
$user = JFactory::getUser();
$user_id = $user->id;
$jinput = new JInput();
$post = $jinput->get('jform', '', 'array');
$order_sum = $post['order_sum'];
$row = array();
$row['user_id'] = $user_id;
$row['sum'] = $order_sum;
$payments =& JTable::getInstance('payments', 'VideoTranslationTable');
if (!$payments->bind($row)) {
return JError::raiseWarning(500, $row->getError());
}
if (!$payments->store()) {
JError::raiseError(500, $row->getError());
}
return $payments->id;
}
示例15: testSerialize
/**
* Test the JInput::serialize method.
*
* @return void
*
* @since 12.1
*/
public function testSerialize()
{
// Load the inputs so that the static $loaded is set to true.
TestReflection::invoke($this->class, 'loadAllInputs');
// Adjust the values so they are easier to handle.
TestReflection::setValue($this->class, 'inputs', array('server' => 'remove', 'env' => 'remove', 'request' => 'keep'));
TestReflection::setValue($this->class, 'options', 'options');
TestReflection::setValue($this->class, 'data', 'data');
$this->assertThat($this->class->serialize(), $this->equalTo('a:3:{i:0;s:7:"options";i:1;s:4:"data";i:2;a:1:{s:7:"request";s:4:"keep";}}'));
}