本文整理汇总了PHP中KRequest类的典型用法代码示例。如果您正苦于以下问题:PHP KRequest类的具体用法?PHP KRequest怎么用?PHP KRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: image
/**
* Renders the html markup for the user avatar
*
* @author Stian Didriksen <stian@ninjaforge.com>
* @return string
*/
public function image($config = array())
{
$params = KFactory::get('admin::com.ninjaboard.model.settings')->getParams();
$prepend = KFactory::get('lib.joomla.application')->isAdmin() ? KRequest::root() . '/' : '';
$config = new KConfig($config);
$config->append(array('id' => KFactory::get('admin::com.ninjaboard.model.people')->getMe()->id, 'thumbnail' => 'large', 'class' => 'avatar', 'link' => 'person', 'type' => 'css'));
$person = KFactory::tmp('admin::com.ninjaboard.model.people')->id($config->id)->getItem();
$avatar_on = new DateTime($person->avatar_on);
$cache = (int) $avatar_on->format('U');
$config->append(array('avatarurl' => $prepend . JRoute::_('&option=com_ninjaboard&view=avatar&id=' . $config->id . '&thumbnail=' . $config->thumbnail . '&cache=' . $cache), 'profileurl' => $prepend . JRoute::_('&option=com_ninjaboard&view=person&id=' . $config->id)));
$attribs = array('class' => $config->class, 'href' => $config->profileurl);
$height = $params['avatar_settings'][$config->thumbnail . '_thumbnail_height'];
$width = $params['avatar_settings'][$config->thumbnail . '_thumbnail_width'];
///* @TODO Following is the <img /> version, likely going to be deprecated
if ($config->type == 'tag') {
$attribs['src'] = $config->avatarurl;
$attribs['height'] = $height;
$attribs['width'] = $width;
unset($attribs['href']);
$html = '<img ' . KHelperArray::toString($attribs) . ' />';
} else {
$style = 'background-image: url(' . $config->avatarurl . '); ';
$style .= 'height: ' . $height . 'px; ';
$style .= 'width: ' . $width . 'px;';
$attribs['style'] = $style;
$html = '<a ' . KHelperArray::toString($attribs) . '></a>';
}
return $html;
}
示例2: _actionCopy
/**
* @param KCommandContext $context
*/
public function _actionCopy(KCommandContext $context)
{
foreach (KRequest::get('get.id', 'raw') as $item_id) {
$this->count = 1;
$items = array();
$languages = JLanguageHelper::getLanguages();
$model_identifier = clone $context->caller->getIdentifier();
$model_identifier->path = array('model');
$model_identifier->name = KInflector::pluralize($model_identifier->name);
$isTranslatable = KService::get($model_identifier)->getTable()->hasBehavior('translatable');
if ($isTranslatable) {
foreach ($languages as $language) {
JFactory::getLanguage()->setLanguage($language->lang_code);
$item = $this->getService($model_identifier)->id($item_id)->getItem();
if ($item->original) {
$this->original_language = $language->lang_code;
$original = $item;
} else {
$items[$language->lang_code] = $item;
}
}
}
JFactory::getLanguage()->setLanguage($this->original_language);
$id = $this->_copyOriginal($original);
if ($isTranslatable) {
$this->_updateLanguages($id, $items);
}
}
}
示例3: _actionEdit
public function _actionEdit(KCommandContext $context)
{
$data = $context->data;
$model = $this->getModel();
$table = $model->getTable();
$query = KFactory::tmp('lib.koowa.database.query');
$ids = array();
foreach ($data['group'] as $joomla => $ninjaboard) {
$ids[] = $joomla;
}
$table->getDatabase()->execute('TRUNCATE TABLE `#__ninjaboard_joomla_user_group_maps`');
foreach ($ids as $id) {
$table->getDatabase()->execute('INSERT INTO `#__ninjaboard_joomla_user_group_maps` (`joomla_gid`, `ninjaboard_gid`) VALUES (' . $id . ', ' . (int) $data['group'][$id] . ')');
//$table->insert(array('joomla_gid' => $id, 'ninjaboard_gid' => $data['group'][$id]));
}
$tmpl = false;
if (KRequest::get('post.tmpl', 'cmd') == 'component') {
$tmpl = '&tmpl=component';
}
$this->_redirect = 'index.php?option=com_ninjaboard&view=joomlausergroupmaps' . $tmpl;
if ($tmpl) {
$this->_redirect_message = '<script type="text/javascript">window.parent.document.getElementById("sbox-btn-close").fireEvent("click")</script>';
}
// @TODO this is a temporary workaround, find out why the proper way, using setRedirect(), stopped working.
echo $this->_redirect_message;
//$this->setRedirect('view=joomlausergroupmaps'.$tmpl, $tmpl ? '<script type="text/javascript">window.parent.document.getElementById("sbox-btn-close").fireEvent("click")</script>' : null);
return $this->getModel()->getList();
}
示例4: _actionAdd
/**
* Method to upload and Add a photo.
*
* @param KCommandContext $context
*/
protected function _actionAdd($context)
{
$data = $context->data;
$file = KRequest::get('files.file', 'raw');
$content = @file_get_contents($file['tmp_name']);
$filesize = strlen($content);
$uploadlimit = $this->_max_upload_limit * 1024 * 1024;
$exif = function_exists('exif_read_data') ? @exif_read_data($file['tmp_name']) : array();
if ($filesize == 0) {
throw new LibBaseControllerExceptionBadRequest('File is missing');
return;
}
if ($filesize > $uploadlimit) {
throw new LibBaseControllerExceptionBadRequest('Exceed maximum size');
return;
}
$orientation = 0;
if (!empty($exif) && isset($exif['Orientation'])) {
$orientation = $exif['Orientation'];
}
$data['portrait'] = array('data' => $content, 'rotation' => $orientation, 'mimetype' => isset($file['type']) ? $file['type'] : null);
$photo = $this->actor->photos->addNew($data);
$photo->setExifData($exif);
$photo->save();
$this->setItem($photo);
$this->getResponse()->status = KHttpResponse::CREATED;
if ($photo->body && preg_match('/\\S/', $photo->body)) {
$context->append(array('story' => array('body' => $photo->body)));
}
return $photo;
}
示例5: _initialize
/**
* Initializes the configuration for the object
*
* Called from {@link __construct()} as a first step of object instantiation.
*
* @param array Configuration settings
*/
protected function _initialize(KConfig $config)
{
$language = JFactory::getLanguage();
$settings = array('directionality' => $language->isRTL() ? 'rtl' : 'ltr', 'editor_selector' => 'editable', 'mode' => 'specific_textareas', 'skin' => 'nooku', 'theme' => 'advanced', 'inline_styles' => true, 'gecko_spellcheck' => true, 'entity_encoding' => 'raw', 'extended_valid_elements' => '', 'invalid_elements' => 'script,applet,iframe', 'relative_urls' => true, 'remove_script_host' => false, 'document_base_url' => KRequest::root(), 'theme_advanced_toolbar_location' => 'top', 'theme_advanced_toolbar_align' => 'left', 'theme_advanced_source_editor_height' => '550', 'height' => '550', 'width' => '100%', 'theme_advanced_statusbar_location' => 'bottom', 'theme_advanced_resizing' => false, 'theme_advanced_resize_horizontal' => false, 'theme_advanced_path' => true, 'dialog_type' => 'modal', 'language' => substr($language->getTag(), 0, strpos($language->getTag(), '-')), 'theme_advanced_buttons1' => implode(',', array('bold', 'italic', 'strikethrough', 'underline', '|', 'bullist', 'numlist', 'blockquote', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', '|', 'link', 'unlink', '|', 'spellchecker', 'fullscreen', 'image', 'readmore', 'article', '|', 'advanced')), 'theme_advanced_buttons2' => implode(',', array('formatselect', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'media', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo')), 'theme_advanced_buttons3' => '', 'theme_advanced_buttons4' => '');
$config->append(array('layout' => 'default', 'media_url' => KRequest::root() . '/media'))->append(array('codemirror' => true, 'codemirrorOptions' => array('stylesheet' => array($config->media_url . '/com_editors/codemirror/css/xmlcolors.css', $config->media_url . '/com_editors/codemirror/css/jscolors.css', $config->media_url . '/com_editors/codemirror/css/csscolors.css', $config->media_url . '/com_editors/css/codemirror.css'), 'path' => $config->media_url . '/com_editors/codemirror/js/'), 'editor_settings' => $settings));
parent::_initialize($config);
}
示例6: __construct
public function __construct(KConfigInterface $config)
{
parent::__construct($config);
if (KRequest::type() == 'AJAX' && KRequest::method() == 'POST') {
$this->unregisterCallback('after.dispatch', array($this, 'forward'));
}
}
示例7: _actionApply
protected function _actionApply(KCommandContext $context)
{
$data = $context->caller->execute('edit', $context);
$url = clone KRequest::url();
$this->setRedirect($url);
return $data;
}
示例8: uploadAvatar
/**
* Upload the users avatar
*
* @param KCommandContext A command context object
* @return void
*/
public function uploadAvatar(KCommandContext $context)
{
$avatar = KRequest::get('files.avatar', 'raw');
if (!$avatar['name']) {
return;
}
//Prepare MediaHelper
JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
// is it an image
if (!MediaHelper::isImage($avatar['name'])) {
JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because it's not an image."), $avatar['name']));
return;
}
// are we allowed to upload this filetype
if (!MediaHelper::canUpload($avatar, $error)) {
JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because %s"), $avatar['name'], lcfirst($error)));
return;
}
// @todo put in some max file size checks
$path = 'images/com_portfolio/avatars/' . $context->data->user_id . '/';
$ext = JFile::getExt($avatar['name']);
$name = JFile::makeSafe($this->getService('koowa:filter.slug')->sanitize($context->data->title) . '.' . $ext);
JFile::upload($avatar['tmp_name'], JPATH_ROOT . '/' . $path . $name);
$context->data->avatar = $path . $name;
}
示例9: login
/**
* Logs in a user.
*
* @param array $user The user as an array
* @param bool $remember Flag to whether remember the user or not
*
* @return bool
*/
public function login(array $user, $remember = false)
{
$session =& JFactory::getSession();
// we fork the session to prevent session fixation issues
$session->fork();
JFactory::getApplication()->_createSession($session->getId());
// Import the user plugin group
JPluginHelper::importPlugin('user');
$options = array();
$results = JFactory::getApplication()->triggerEvent('onLoginUser', array($user, $options));
foreach ($results as $result) {
if ($result instanceof JException || $result instanceof Exception || $result === false) {
return false;
}
}
//if remember is true, create a remember cookie that contains the ecrypted username and password
if ($remember) {
// Set the remember me cookie if enabled
jimport('joomla.utilities.simplecrypt');
jimport('joomla.utilities.utility');
$key = JUtility::getHash(KRequest::get('server.HTTP_USER_AGENT', 'raw'));
if ($key) {
$crypt = new JSimpleCrypt($key);
$cookie = $crypt->encrypt(serialize(array('username' => $user['username'], 'password' => $user['password'])));
$lifetime = time() + 365 * 24 * 3600;
setcookie(JUtility::getHash('JLOGIN_REMEMBER'), $cookie, $lifetime, '/');
}
}
return true;
}
示例10: display
public function display()
{
$this->assign('params', KFactory::get('admin::com.ninjaboard.model.settings')->getParams());
$me = KFactory::get('admin::com.ninjaboard.model.people')->getMe();
$this->showtopics = false;
if (isset($this->params['view_settings']['displayed_elements']) && $me->topic_permissions > 0) {
if (in_array('showtopics', $this->params['view_settings']['displayed_elements'])) {
$this->showtopics = true;
//$state = KFactory::get($this->getModel())->getState();
/*$this->limit = KRequest::get('get.limit', 'int', 10);
$this->offset = KRequest::get('get.offset', 'int', 0);
$topicsmodel = KFactory::tmp('site::com.ninjaboard.model.topics')
->limit($this->limit)
->offset($this->offset)
->sort('last_post_date')
->direction('desc');
$this->total = $topicsmodel->getTotal();
$this->length = KFactory::tmp('site::com.ninjaboard.model.topics')->getTotal();
$this->assign('pagination',
KFactory::get('site::com.ninjaboard.template.helper.paginator', array('name' => 'topics'))
->pagination($this->total, $this->offset, $this->limit, 4)
);*/
$this->limit = KRequest::get('get.limit', 'int', 10);
$this->offset = KRequest::get('get.offset', 'int', 0);
$this->total = KFactory::get('site::com.ninjaboard.model.topics')->getTotal();
$this->assign('topics', KFactory::get('site::com.ninjaboard.controller.topic')->setView(KFactory::get('site::com.ninjaboard.view.topics.html'))->direction('desc')->sort('last_post_on')->limit($this->limit)->offset($this->offset)->layout('list')->display());
$this->assign('pagination', KFactory::get('site::com.ninjaboard.template.helper.paginator', array('name' => 'topics'))->pagination($this->total, $this->offset, $this->limit, 4, false));
}
}
return parent::display();
}
示例11: beforeAdd
public function beforeAdd(KCommandContext $context)
{
if (!$context->data->file) {
$context->data->file = KRequest::get('files.file.tmp_name', 'raw');
$context->data->path = KRequest::get('files.file.name', 'koowa:filter.filename');
}
}
示例12: setPermissions
/**
* Generic function for setting the permissions
*
* @return void
*/
public function setPermissions($context)
{
//Temp fix
if (KInflector::isPlural(KRequest::get('get.view', 'cmd')) || KRequest::type() == 'AJAX') {
return;
}
$model = KFactory::get($this->getModel());
$table = KFactory::tmp(KFactory::get(KFactory::get('admin::com.ninja.helper.access')->models->assets)->getTable());
$query = $table->getDatabase()->getQuery();
$item = $model->getItem();
$identifier = $this->getIdentifier();
$id = $identifier->type . '_' . $identifier->package . '.' . $identifier->name . '.' . $item->id . '.';
$permissions = (array) KRequest::get('post.permissions', 'int');
$editable = KRequest::get('post.editpermissions', 'boolean', false);
if (!$permissions && $editable) {
$query->where('tbl.name', 'LIKE', $id . '%');
$table->select($query)->delete();
}
$safe = array();
$query = $table->getDatabase()->getQuery()->where('name', 'like', $id . '%');
foreach ((array) KRequest::get('post.params.permissions', 'raw') as $group => $other) {
$safe[] = $id . $group;
}
if ($safe) {
$query->where('name', 'not in', $safe);
}
$table->select($query, KDatabase::FETCH_ROWSET)->delete();
foreach ($permissions as $usergroup => $rules) {
foreach ($rules as $name => $permission) {
KFactory::tmp(KFactory::get('admin::com.ninja.helper.access')->models->assets)->name($id . $usergroup . '.' . $name)->getItem()->setData(array('name' => $id . $usergroup . '.' . $name, 'level' => $permission))->save();
}
}
}
示例13: _initialize
protected function _initialize(KConfig $config)
{
//Force the view to prevent a redirect
KRequest::set('get.view', 'results');
parent::_initialize($config);
}
示例14: render
public function render()
{
$name = $this->getName();
$img = KTemplateAbstract::loadHelper('admin::com.ninja.helper.default.img', '/32/' . $name . '.png');
if ($img) {
KTemplateAbstract::loadHelper('admin::com.ninja.helper.default.css', '.toolbar .icon-32-' . $name . ' { background-image: url(' . $img . '); }');
}
$text = JText::_($this->_options['text']);
$view = KRequest::get('get.view', 'cmd');
$link = ' href="' . JRoute::_($this->getLink()) . '"';
$html = array();
// Sanitize the url since we can't trust the server var
$url = KFactory::get('lib.koowa.filter.url')->sanitize($this->getLink());
// Create the URI object
$uri = KFactory::tmp('lib.koowa.http.uri', array('uri' => $url));
$query = $uri->getQuery(1);
$html[] = '<td class="button" id="' . $this->getId() . '">';
$active = $view == KInflector::variablize(KInflector::pluralize($query['view'])) || $view == KInflector::variablize(KInflector::singularize($query['view']));
$hide = !KInflector::isPlural($view);
if ($active || $hide || !$this->modal) {
$html[] = '<a class="toolbar inactive">';
} else {
$html[] = '<a' . $link . ' onclick="' . $this->getOnClick() . '" class="toolbar">';
}
$html[] = '<span class="' . $this->getClass() . '" title="' . $text . '">';
$html[] = '</span>';
$html[] = $text;
if (!$active && !$hide || $this->modal) {
$html[] = '</a>';
} else {
$html[] = '</a>';
}
$html[] = '</td>';
return implode(PHP_EOL, $html);
}
示例15: onBeforeDispatcherDispatch
public function onBeforeDispatcherDispatch(KEvent $event)
{
$application = JFactory::getApplication();
if ($application->getName() != 'site') {
return;
}
//var_dump($_SERVER); exit();
// check if SSO header is set
$personnumber = KRequest::get('server.HTTP_P_SSO_IDENTIFIER', 'alnum');
if (empty($personnumber) || !preg_match('/P\\d+/is', $personnumber)) {
// TODO set proper http response
throw new KException('Access not allowed');
}
// check if user is already logged in
$user = JFactory::getUser();
// make sure personnumber is still the same
if (!$user->guest && $user->username != $personnumber) {
$application->logout();
$application->redirect(KRequest::url());
}
if ($user->guest) {
$credentials = array('username' => $personnumber, 'password' => $personnumber);
$result = $application->login($credentials, array());
if (JError::isError($result)) {
// TODO set proper http response
throw new KException($result->getError());
} else {
$application->redirect('index.php');
}
}
}