/**
  * Constructor
  *
  * Prevent creating instances of this class by making the contructor private
  */
 private final function __construct(KConfig $config)
 {
     $content = self::content();
     if (self::type() == 'HTTP') {
         if (strpos(PHP_SAPI, 'cgi') !== false) {
             $authorization = KRequest::get('server.REDIRECT_HTTP_AUTHORIZATION', 'string');
         } else {
             $authorization = KRequest::get('server.HTTP_AUTHORIZATION', 'url');
         }
         if (strstr($authorization, "Basic")) {
             $parts = explode(':', base64_decode(substr($authorization, 6)));
             if (count($parts) == 2) {
                 KRequest::set('server.PHP_AUTH_USER', $parts[0]);
                 KRequest::set('server.PHP_AUTH_PW', $parts[1]);
             }
         }
     }
     if (!empty($content['data'])) {
         if ($content['type'] == 'application/x-www-form-urlencoded') {
             if (in_array(self::method(), array('PUT', 'DELETE'))) {
                 parse_str($content['data'], $GLOBALS['_' . self::method()]);
                 $GLOBALS['_REQUEST'] = array_merge($GLOBALS['_REQUEST'], $GLOBALS['_' . self::method()]);
             }
         }
         if ($content['type'] == 'application/json') {
             if (in_array(self::method(), array('POST', 'PUT', 'DELETE'))) {
                 $GLOBALS['_' . self::method()] = json_decode($content['data'], true);
                 $GLOBALS['_REQUEST'] = array_merge($GLOBALS['_REQUEST'], $GLOBALS['_' . self::method()]);
             }
         }
     }
 }
示例#2
0
 protected function _initialize(KConfig $config)
 {  
     //Force the view to prevent a redirect
     KRequest::set('get.view', 'results');
      
     parent::_initialize($config);
 }
示例#3
0
 public function display()
 {
     $topic = $this->getModel()->getItem();
     $this->forum = KFactory::get('site::com.ninjaboard.model.forums')->id($topic->forum_id)->getItem();
     $this->user = KFactory::get('lib.joomla.user');
     $me = KFactory::get('admin::com.ninjaboard.model.people')->getMe();
     $this->watch_button = $me->id && $this->forum->params['email_notification_settings']['enable_email_notification'];
     //Assign forum permissions to topic
     $topic->forum_permissions = $this->forum->forum_permissions;
     $topic->topic_permissions = $this->forum->topic_permissions;
     $topic->post_permissions = $this->forum->post_permissions;
     $topic->attachment_permissions = $this->forum->attachment_permissions;
     if ((!$this->forum->id || !$topic->id || $topic->topic_permissions < 1) && KFactory::tmp('lib.joomla.user')->guest) {
         $this->mixin(KFactory::get('admin::com.ninja.view.user.mixin'));
         $this->setLoginLayout();
         return parent::display();
     } elseif (!$topic->id) {
         JError::raiseError(404, JText::_("Topic not found."));
         return;
     } elseif (!$this->forum->id) {
         JError::raiseError(404, JText::_("Forum not found."));
         return;
     }
     $this->_subtitle = $topic->title;
     //if($topic->id && !KRequest::get('get.layout', 'cmd', false)) $this->setLayout('default');
     $state = $this->getModel()->getState();
     $limit = $state->limit ? $state->limit : 6;
     $offset = KFactory::tmp('site::com.ninjaboard.model.posts')->topic($topic->id)->post($state->post)->limit($limit)->getOffset();
     $offset = KRequest::get('get.offset', 'int', $offset);
     //This is used to set the canonical link correctly in the topic controller after.read
     //@TODO move all this logic out of the view in 1.2
     $this->getModel()->set(array('limit' => $limit, 'offset' => $offset));
     $this->assign('posts', KFactory::tmp('site::com.ninjaboard.controller.post')->setView(KFactory::tmp('site::com.ninjaboard.view.posts.html'))->setModel(KFactory::get('site::com.ninjaboard.model.posts')->setAcl(false))->sort('created_on')->limit($limit)->offset($offset)->post(false)->topic($topic->id)->layout('default')->display());
     if ($this->forum->params['view_settings']['new_topic_button'] == 'topic') {
         $this->new_topic_button = '<div class="new-topic">' . str_replace(array('$title', '$link'), array(JText::_('New Topic'), $this->createRoute('view=post&forum=' . $this->forum->id)), $this->forum->params['tmpl']['new_topic_button']) . '</div>';
     }
     $button = false;
     if (KFactory::get('lib.joomla.user')->guest || $this->forum->post_permissions > 1) {
         $button = str_replace(array('$title', '$link'), array(JText::_('Reply topic'), $this->createRoute('view=post&topic=' . $topic->id)), $this->forum->params['tmpl']['new_topic_button']);
     }
     //$this->reply_topic_button = $this->forum->post_permissions > 1 ? $button : null;
     $this->reply_topic_button = $button;
     $this->lock_topic_button = null;
     $this->move_topic_button = null;
     $this->delete_topic_button = null;
     if ($this->forum->topic_permissions > 2) {
         $this->lock_topic_button = $this->_createActionButton('lock', 'Lock topic', $topic->id, 'lock');
         $this->move_topic_button = str_replace(array('$title', '$link'), array(JText::_('Move topic'), $this->createRoute('view=topic&layout=move&id=' . $topic->id)), $this->forum->params['tmpl']['new_topic_button']);
         $this->delete_topic_button = $this->_createActionButton('delete', 'Delete topic', $topic->id, 'trash');
     }
     $output = parent::display();
     //@TODO move this to the controller
     $hit = KRequest::get('session.' . KFactory::get('admin::com.ninja.helper.default')->formid($topic->id), 'boolean');
     if (!$hit && $topic->created_user_id != $me->id) {
         $topic->hit();
         KRequest::set('session.' . KFactory::get('admin::com.ninja.helper.default')->formid($topic->id), true);
     }
     return $output;
 }
示例#4
0
 /**
  * Restores a state for an action
  * 
  * @param  string $action
  * @return void
  */
 public function persistState($action)
 {
     $state = $this->getRequest();
     // Built the session identifier based on the action
     $identifier = $this->_mixer->getIdentifier() . '.' . $action;
     //Set the state in the session
     KRequest::set('session.' . $identifier, KConfig::unbox($state));
 }
示例#5
0
 /**
  * Saves the model state in the session
  *
  * @param 	KCommandContext		The active command context
  * @return 	void
  */
 protected function _afterBrowse(KCommandContext $context)
 {
     $model = $this->getModel();
     $state = $model->get();
     // Built the session identifier based on the action
     $identifier = $model->getIdentifier() . '.' . $this->_action . '.' . $this->getModel()->get('section');
     //Set the state in the session
     KRequest::set('session.' . $identifier, $state);
 }
示例#6
0
 /**
  * Authorize an oauth profile to an actor. It needs to authorize 
  * 
  * @param  KCommandContext $context
  * @return void
  */
 protected function _actionOauthorize($context)
 {
     $data = $context->data;
     KRequest::set('session.return', (string) $data->return);
     KRequest::set('session.oauth', null);
     $view = $this->_mixer->getIdentifier()->name;
     $this->getAPI()->setToken(null);
     $context->response->setRedirect($this->getAPI()->getAuthorizationURL());
 }
示例#7
0
 protected function _actionGet(KCommandContext $context)
 {
     //Force the application template
     KRequest::set('get.tmpl', 'login');
     //Set the status
     $context->status = KHttpResponse::UNAUTHORIZED;
     //Set the authentciation header
     //$context->headers = array('WWW-Authenticate', 'Basic Realm="'.KRequest::base().'"');
     return parent::_actionGet($context);
 }
 /**
  * Saves the model state in the session
  *
  * @param 	KCommandContext		The active command context
  * @return 	void
  */
 protected function _afterBrowse(KCommandContext $context)
 {
     $model = $this->getModel();
     $state = $model->get();
     // Built the session identifier based on the action
     $identifier = $model->getIdentifier() . '.' . $context->action;
     //Prevent unused state information from being persisted
     KRequest::set('session.' . $identifier, null);
     //Set the state in the session
     KRequest::set('session.' . $identifier, $state);
 }
 protected function _initialize(KConfig $config)
 {
     if (JFactory::getUser()->guest) {
         if (KRequest::method() == KHttpRequest::GET) {
             //Force the view to prevent a redirect
             KRequest::set('get.view', 'login');
             $config->controller = 'login';
         }
     }
     parent::_initialize($config);
 }
示例#10
0
 /**
  * Constructor
  *
  * @param 	object 	An optional KConfig object with configuration options
  */
 public function __construct(KConfig $config)
 {
     KRequest::set('get.format', 'file');
     //When no id is set in the url, then we should assume the user wants to see his own profile
     $me = KFactory::get('site::com.ninjaboard.model.people')->getMe();
     $config->append(array('request' => array('id' => $me->id)));
     parent::__construct($config);
     //@TOD To prevent errors like on profile edit screen, remember to remove this line if we add layouts
     $this->_request->layout = 'default';
     $this->_request->format = 'file';
 }
示例#11
0
 /**
  * store user method.
  *
  * Method is called after user data is stored in the database
  *
  * @param 	array		holds the new user data
  * @param 	bool		true if a new user is stored
  * @param	bool		true if user was succesfully stored in the database
  * @param	string		message
  */
 public function onAfterStoreUser($user, $isnew, $succes, $msg)
 {
     if (!$isnew) {
         return;
     }
     $invite_token = KRequest::get('session.invite_token', 'string', null);
     if (!$invite_token) {
         return;
     }
     KRequest::set('session.invite_token', null);
     $token = KService::get('repos:invites.token')->fetch(array('value' => $invite_token));
     $token->incrementUsed()->save();
 }
示例#12
0
 /**
  * Store the referrer in the session
  *
  * @param 	KCommandContext		The active command context
  * @return void
  */
 public function saveReferrer(KCommandContext $context)
 {
     $referrer = KRequest::referrer();
     if (isset($referrer) && KRequest::type() == 'HTTP') {
         $request = KRequest::url();
         $request->get(KHttpUri::PART_PATH | KHttpUri::PART_QUERY);
         $referrer->get(KHttpUri::PART_PATH | KHttpUri::PART_QUERY);
         //Compare request url and referrer
         if ($request != $referrer) {
             KRequest::set('session.com.controller.referrer', (string) $referrer);
         }
     }
 }
示例#13
0
 /**
  * Draw the toolbar
  *
  * @param KCommandContext $context The command context
  *
  * @return string
  */
 protected function _actionRender(KCommandContext $context)
 {
     if ($context->result !== false) {
         $view = $this->getController()->getView();
         //Set the document mimetype
         JFactory::getDocument()->setMimeEncoding($view->mimetype);
         //Disabled the application menubar
         if (!KInflector::isPlural($view->getName()) && !KRequest::has('get.hidemainmenu')) {
             KRequest::set('get.hidemainmenu', 1);
         }
     }
     return parent::_actionRender($context);
 }
示例#14
0
 /**
  * Saves the current row and redirects to a new edit form
  *
  * @param KCommandContext $context
  *
  * @return KDatabaseRowInterface A row object containing the saved data
  */
 protected function _actionSave2new(KCommandContext $context)
 {
     // Cache and lock the referrer since _ActionSave would unset it
     $referrer = $this->getReferrer();
     $this->lockReferrer();
     $result = $this->save($context);
     // Re-set the referrer
     KRequest::set('cookie.referrer', (string) $referrer);
     $identifier = $this->getMixer()->getIdentifier();
     $view = KInflector::singularize($identifier->name);
     $url = sprintf('index.php?option=com_%s&view=%s', $identifier->package, $view);
     $this->setRedirect($this->getService('koowa:http.url', array('url' => $url)));
     return $result;
 }
示例#15
0
 public function setTitle()
 {
     $title = KRequest::get('post.title', 'string', 'Untitled');
     $id = KRequest::get('get.id', 'int', 0);
     $table = KFactory::get(KFactory::get($this->getModel())->getTable());
     $primaryKey = current($table->getPrimaryKey())->name;
     $query = $table->getDatabase()->getQuery()->where('title', '=', $title)->where($primaryKey, '!=', $id);
     if ($table->count($query)) {
         KRequest::set('post.title', $title . ' ' . JText::_('copy'), 'string');
         if ((bool) $table->count($table->getDatabase()->getQuery()->where('title', '=', KRequest::get('post.title', 'string'))->where($primaryKey, '!=', $id))) {
             self::setTitle();
         }
     }
     return $this;
 }
示例#16
0
 /**
  * Store a token for a service.
  *
  * @param KCommandContext $context
  */
 protected function _actionAdd(KCommandContext $context)
 {
     $data = $context->data;
     $value = KRequest::get('session.invite_token', 'string', null);
     if (empty($data->value) || $value != $data->value) {
         throw new LibBaseControllerExceptionBadRequest('Invalid token signature');
         return;
     }
     KRequest::set('session.invite_token', null);
     $token = $this->getRepository()->getEntity(array('data' => array('value' => $value, 'inviter' => get_viewer(), 'serviceName' => 'facebook')));
     if (!$token->save()) {
         throw new LibBaseControllerExceptionInternal();
         return;
     }
 }
示例#17
0
 protected function _beforeGet(KCommandContext $context)
 {
     $request = $this->getRequest();
     if ($request->format == 'file' && $request->export) {
         $file = KRequest::get($this->_getSessionContainer(), 'raw', null);
         if (!is_null($file)) {
             $view = $this->getView();
             // Set the view.
             $view->path = $file;
             $view->filename = basename($file);
             // Clear session info.
             KRequest::set($this->_getSessionContainer(), null);
         }
     }
     parent::_beforeGet($context);
 }
示例#18
0
 /**
  * Saves the model state in the session
  *
  * @param 	KCommandContext		The active command context
  * @return 	void
  */
 protected function _afterControllerBrowse(KCommandContext $context)
 {
     $model = $this->getModel();
     $state = $model->getState();
     $vars = array();
     foreach ($state->toArray(false) as $var) {
         if (!$var->unique) {
             $vars[$var->name] = $var->value;
         }
     }
     // Built the session identifier based on the action
     $identifier = $model->getIdentifier() . '.' . $context->action;
     //Prevent unused state information from being persisted
     KRequest::set('session.' . $identifier, null);
     //Set the state in the session
     KRequest::set('session.' . $identifier, $vars);
 }
示例#19
0
 /**
  * Render item pagination
  *
  * @param	array $config	Configuration array
  * @return	string	Html
  * @see  	http://developer.yahoo.com/ypatterns/navigation/pagination/
  */
 public function pagination($config = array())
 {
     $config = new KConfig($config);
     $config->append(array('total' => 0, 'display' => 5, 'ajax' => false, 'name' => $this->name));
     $this->_ajax = (bool) $config->ajax;
     if (is_string($config->ajax)) {
         $this->_ajax_layout = $config->ajax;
     }
     KFactory::get('admin::com.ninja.helper.default')->css('/pagination.css');
     // Paginator object
     $paginator = KFactory::tmp('lib.koowa.model.paginator')->setData(array('total' => $config->total, 'offset' => $config->offset, 'limit' => $config->limit, 'dispay' => $config->display));
     $view = $config->name;
     $items = (int) $config->total === 1 ? KInflector::singularize($view) : $view;
     if ($config->total <= 10) {
         return '<div class="pagination"><div class="limit">' . sprintf(JText::_('Listing %s ' . KInflector::humanize($items)), $config->total) . '</div></div>';
     }
     // Get the paginator data
     $list = $paginator->getList();
     $limitlist = $config->total > 10 ? $this->limit($config->toArray()) : $config->total;
     $html = '<div class="pagination">';
     $html .= '<div class="limit">' . sprintf(JText::_('Listing %s ' . KInflector::humanize($items)), $limitlist) . '</div>';
     $html .= $this->pages($list);
     $html .= '<div class="count"> ' . JText::_('Pages') . ' ' . $paginator->current . ' ' . JText::_('of') . ' ' . $paginator->count . '</div>';
     $html .= '</div>';
     if ($this->_ajax) {
         jimport('joomla.environment.browser');
         $uagent = JBrowser::getInstance()->getAgentString();
         $windoze = strpos($uagent, 'Windows') ? true : false;
         $url = clone KRequest::url();
         $url->fragment = 'offset=@{offset}';
         $formid = KFactory::tmp('admin::com.ninja.helper.default')->formid();
         $cookie = KRequest::get('cookie.' . $formid, 'string', false);
         $states = array('total' => $total, 'offset' => $offset, 'limit' => $limit, 'display' => $display);
         if ($cookie) {
             $merge = KHelperArray::merge(json_decode($cookie, true), $states);
             KRequest::set('cookie.' . $formid, json_encode($merge), 'string');
         }
         //Temp fix
         $cookie = false;
         $states = $cookie ? array() : array('state' => $states);
         KFactory::get('admin::com.ninja.helper.default')->js('/pagination.js');
         KFactory::get('admin::com.ninja.helper.default')->js('window.addEvent(\'domready\', function(){ $$(\'div.pagination\')[0].paginator(' . json_encode(array_merge(array('identificator' => $formid, 'text' => array('count' => sprintf(JText::_('Pages %s of %s'), '@{current}', '@{total}'), 'first' => sprintf(JText::_('%s First'), $windoze ? '<<' : '&#10094;&#10094;'), 'previous' => sprintf(JText::_('%s Previous'), $windoze ? '<' : '&#10094;'), 'next' => sprintf(JText::_('Next %s'), $windoze ? '>' : '&#10095;'), 'last' => sprintf(JText::_('Last %s'), $windoze ? '>>' : '&#10095;&#10095;'))), $states)) . '); });');
     }
     return $html;
 }
示例#20
0
 /**
  * Redners the login form
  * 
  * @return void
  */
 protected function _actionRead($context)
 {
     if (!$this->getAPI()) {
         $context->response->setRedirect(JRoute::_('option=com_people&view=person&get=settings&edit=connect'));
         return false;
     }
     $service = $this->getAPI()->getName();
     $userid = $this->getAPI()->getUser()->id;
     $token = $this->getService('repos://site/connect.session')->find(array('profileId' => $userid, 'api' => $service));
     $return_url = KRequest::get('session.return', 'raw');
     if ($token) {
         $person = $token->owner;
         KRequest::set('session.oauth', null);
         $this->getService('com://site/people.controller.person', array('response' => $context->response))->setItem($person)->login();
         return false;
     }
     $this->return_url = base64_encode($return_url);
 }
示例#21
0
 protected function _actionContact(KCommandContext $context)
 {
     $app = JFactory::getApplication();
     $failed = false;
     KRequest::set('session.portfolio.name', $context->data->name);
     KRequest::set('session.portfolio.email', $context->data->email);
     KRequest::set('session.portfolio.company', $context->data->company);
     KRequest::set('session.portfolio.phone', $context->data->phone);
     KRequest::set('session.portfolio.message', $context->data->message);
     if (!$context->data->name) {
         $app->enqueueMessage(JText::_('COM_PORTFOLIO_NAME_REQUIRED'));
         return;
     }
     if (!$context->data->email || !$this->getService('koowa:filter.email')->validate($context->data->email)) {
         $app->enqueueMessage(JText::_('COM_PORTFOLIO_VALID_EMAIL_REQUIRED'));
         return;
     }
     if (!$context->data->message) {
         $app->enqueueMessage(JText::_('COM_PORTFOLIO_MESSAGE_TEXT_REQUIRED'));
         return;
     }
     $contact = $this->getModel()->id($context->data->person)->getItem();
     $mailer = JFactory::getMailer();
     $subject = sprintf(JText::_('COM_PORTFOLIO_SOMEONE_CONTACTED_YOU_ON'), $app->getCfg('sitename'));
     $bodytext = "\n" . JText::_('COM_PORTFOLIO_CONTACT_NAME') . ': ' . $context->data->name;
     $bodytext .= "\n" . JText::_('COM_PORTFOLIO_CONTACT_COMPANY') . ': ' . $context->data->company;
     $bodytext .= "\n" . JText::_('COM_PORTFOLIO_CONTACT_EMAIL') . ': ' . $context->data->email;
     $bodytext .= "\n" . JText::_('COM_PORTFOLIO_CONTACT_PHONE') . ': ' . $context->data->phone;
     $bodytext .= "\n" . $context->data->message;
     $mailer->setSender(array($app->getCfg('mailfrom'), $app->getCfg('fromname')));
     $mailer->setSubject($subject);
     $mailer->setBody($bodytext);
     $mailer->addRecipient($contact->email);
     $mailer->send();
     $this->setRedirect('/');
     KRequest::set('session.portfolio.name', null);
     KRequest::set('session.portfolio.email', null);
     KRequest::set('session.portfolio.company', null);
     KRequest::set('session.portfolio.phone', null);
     KRequest::set('session.portfolio.message', null);
     $app->enqueueMessage(sprintf(JText::_('COM_PORTFOLIO_CONTACT_THANKS'), $contact->title));
 }
示例#22
0
文件: login.php 项目: stonyyi/anahita
 /**
  * Redners the login form.
  */
 protected function _actionRead(KCommandContext $context)
 {
     if (!$this->getAPI()) {
         $context->response->setRedirect(JRoute::_('option=com_people&view=person&get=settings&edit=connect'));
         return false;
     }
     $service = $this->getAPI()->getName();
     $userid = $this->getAPI()->getUser()->id;
     $token = $this->getService('repos://site/connect.session')->find(array('profileId' => $userid, 'api' => $service));
     $return_url = KRequest::get('session.return', 'raw');
     if ($token) {
         $person = $token->owner;
         KRequest::set('session.oauth', null);
         $credentials = array('username' => $person->username, 'password' => $person->getPassword(true));
         if ($this->getService('com:people.helper.person')->login($credentials, true)) {
             $context->response->setRedirect(base64_decode($return_url));
         }
         return false;
     }
     $this->return_url = base64_encode($return_url);
 }
示例#23
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   object  An optional KConfig object with configuration options.
  * @return  void
  */
 protected function _initialize(KConfig $config)
 {
     /*
      * Re-run the routing and add returned keys to the $_GET request
      * This is done because Joomla 3 sets the results of the router in $_REQUEST and not in $_GET
      */
     if (JFactory::getApplication()->getCfg('sef')) {
         $uri = clone JURI::getInstance();
         $router = JFactory::getApplication()->getRouter();
         $result = $router->parse($uri);
         foreach ($result as $key => $value) {
             if (!KRequest::has('get.' . $key)) {
                 KRequest::set('get.' . $key, $value);
             }
         }
     }
     parent::_initialize($config);
     //Force the controller to the information found in the request
     if ($config->request->view) {
         $config->controller = $config->request->view;
     }
 }
示例#24
0
 /**
  * Push the controller data into the document
  * 
  * This function divert the standard behavior and will push specific controller data
  * into the document
  *
  * @return  KDispatcherDefault
  */
 protected function _actionRender(KCommandContext $context)
 {
     $controller = KFactory::get($this->getController());
     $view = $controller->getView();
     $document = KFactory::get('lib.joomla.document');
     $document->setMimeEncoding($view->mimetype);
     if ($view instanceof ComDefaultViewHtml) {
         $document->setBuffer($view->getToolbar()->render(), 'modules', 'toolbar');
         $document->setBuffer($view->getToolbar()->renderTitle(), 'modules', 'title');
         if (KInflector::isSingular($view->getName()) && !KRequest::has('get.hidemainmenu')) {
             KRequest::set('get.hidemainmenu', 1);
         }
         if (isset($view->views)) {
             foreach ($view->views as $name => $title) {
                 $active = $name == strtolower($view->getName());
                 $component = $this->_identifier->package;
                 JSubMenuHelper::addEntry(JText::_($title), 'index.php?option=com_' . $component . '&view=' . $name, $active);
             }
         }
     }
     return parent::_actionRender($context);
 }
示例#25
0
 /**
  * Method for uploading files on save
  * 
  * @param   KCommandContext A command context object
  * @return  void
  */
 public function _afterSave(KCommandContext $context)
 {
     //Prepare MediaHelper
     JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
     $item = $this->getModel()->getItem();
     KRequest::set('files.icon', null);
     foreach (KRequest::get('files', 'raw') as $key => $file) {
         if ($file['error'] != UPLOAD_ERR_OK || !$file) {
             continue;
         }
         // are we allowed to upload this filetype
         if (!MediaHelper::canUpload($file, $error)) {
             JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because %s"), $file['name'], lcfirst($error)));
             return;
         }
         $slug = $this->getService('koowa:filter.slug');
         $ext = JFile::getExt($file['name']);
         $name = $slug->sanitize(JFile::stripExt($file['name'])) . '-' . time() . '.' . $ext;
         $name = JFile::makeSafe($name);
         $path = 'images/com_portfolio/work/' . $slug->sanitize($context->data->title) . '/';
         // if this is an image, check we are allowed to upload it
         if (strpos($key, 'image') === false) {
             $path .= 'files/';
             $row = $this->getService('com://admin/portfolio.database.row.file');
         } else {
             if (!MediaHelper::isImage($file['name'])) {
                 JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because it's not an image."), $file['name']));
                 return;
             }
             $path .= 'images/';
             $row = $this->getService('com://admin/portfolio.database.row.image');
             $this->generateThumb($file, JPATH_ROOT . '/' . $path . 'thumb-' . $name);
         }
         JFile::upload($file['tmp_name'], JPATH_ROOT . '/' . $path . $name);
         $row->setData(array('directory' => $path, 'filename' => $name, 'work_id' => $item->id))->save();
     }
 }
示例#26
0
    unset($_GET['layout']);
}
$document = KFactory::get('lib.joomla.document');
$config = KFactory::get('lib.joomla.config');
$debug = $config->getValue('config.debug');
if ($debug && false) {
    try {
        //Init plug
        KFactory::get('plg.koowa.debug');
    } catch (KFactoryAdapterException $e) {
    }
    $profile = microtime(true);
}
//@TODO this is pretty dirty, we need to find a better solution to set the offset in our views that currently use KRequest for it
if (KRequest::has('get.limitstart')) {
    KRequest::set('get.offset', KRequest::get('get.limitstart', 'int'));
}
// Create the component dispatcher
echo KFactory::get('site::com.ninjaboard.dispatcher')->dispatch(KRequest::get('get.view', 'cmd', 'forums'));
if ($debug && false) {
    try {
        //Init plug
        $queries = KFactory::get('plg.koowa.debug')->queries;
        $document->addScriptDeclaration('if(console) { console.group("Ninjaboard SQL queries (' . count($queries) . ')");' . PHP_EOL);
        foreach ($queries as $query) {
            $document->addScriptDeclaration('console.log(' . json_encode((string) $query) . ');' . PHP_EOL);
        }
        $document->addScriptDeclaration('console.groupEnd(); }' . PHP_EOL);
    } catch (KFactoryAdapterException $e) {
    }
    $time = number_format(microtime(true) - $profile, 4);
示例#27
0
 /**
  * Constructor
  *
  * @param 	object 	An optional KConfig object with configuration options
  */
 public function __construct(KConfig $config)
 {
     KRequest::set('get.format', 'file');
     parent::__construct($config);
 }
 /**
  * Set the mimetype of the document and hide the menu if required
  *
  * @return  KDispatcherDefault
  */
 protected function _actionRender(KCommandContext $context)
 {
     $view = $this->getController()->getView();
     //Set the document mimetype
     JFactory::getDocument()->setMimeEncoding($view->mimetype);
     //Disabled the application menubar
     if ($this->getController()->isEditable() && KInflector::isSingular($view->getName())) {
         KRequest::set('get.hidemainmenu', 1);
     }
     return parent::_actionRender($context);
 }
示例#29
0
	/**
	 * Basic authentication support
	 *
	 * This functions tries to log the user in if authentication credentials are
	 * present in the request.
	 *
	 * @return boolean	Returns TRUE is basic authentication was successful
	 */
	protected function _authenticateUser()
	{
	    if(KRequest::has('server.PHP_AUTH_USER') && KRequest::has('server.PHP_AUTH_PW')) 
	    {
	        $credentials = array(
	            'username' => KRequest::get('server.PHP_AUTH_USER', 'url'),
	            'password' => KRequest::get('server.PHP_AUTH_PW'  , 'url'),
	        );
	        
	        if(KFactory::get('joomla:application')->login($credentials) !== true) 
	        {  
	            throw new KException('Login failed', KHttpResponse::UNAUTHORIZED);
        	    return false;      
	        }
	        
	        //Reset the user object in the factory
	        KFactory::set('joomla:user', JFactory::getUser());
	         
	        //Force the token
	        KRequest::set('request._token', JUtility::getToken());
	        
	        return true;
	    }
	    
	    return false;
	}
示例#30
0
    protected function _actionComplete(KCommandContext $context)
    {
        $password        = KRequest::get('post.password', 'raw');
        $password_verify = KRequest::get('post.password_verify', 'raw');

        if(!$password)
        {
            $this->setRedirect(KRequest::referrer(), JText::_('MUST_SUPPLY_PASSWORD'), 'error');
            return false;
        }

        if($password != $password_verify)
        {
            $this->setRedirect(KRequest::referrer(), JText::_('PASSWORDS_DO_NOT_MATCH_LOW'), 'error');
            return false;
        }

        $user     = KFactory::get('joomla:user', array(KRequest::get('session.com.users.id', 'int')));

        JPluginHelper::importPlugin('user');
        $dispatcher = JDispatcher::getInstance();
        $dispatcher->trigger('onBeforeStoreUser', array($user->getProperties(), false));

        KFactory::get('com://site/users.model.users')
            ->set('id', $user->id)
            ->getItem()
            ->set('password', $password)
           	->set('password_verify', $password_verify)
            ->set('activation', '')
            ->save();

        $user->password         = $password;
        $user->activation       = '';
        $user->password_clear   = $password_verify;

        $dispatcher->trigger('onAfterStoreUser', array($user->getProperties(), false, $result));

        KRequest::set('session.com.users.id', null);
        KRequest::set('session.com.users.token', null);

        $this->setRedirect('index.php?option=com_users&view=login', JText::_('PASSWORD_RESET_SUCCESS'));
    }