示例#1
0
    public function display()
    {
        // Display the toolbar
        $toolbar = $this->_createToolbar()->reset();
        $this->toolbar = KFactory::get($this->getToolbar(), array('isGrid' => false))->append(KFactory::get('admin::com.ninja.toolbar.button.apply', array('isGrid' => false)));
        KFactory::get('admin::com.ninja.helper.default')->css('/' . $this->getIdentifier()->application . '.' . $this->getName() . '.css');
        KFactory::get('admin::com.ninja.helper.default')->js('/raphael.js');
        KFactory::get('admin::com.ninja.helper.default')->js('/Mapper.js');
        $acl = JFactory::getACL();
        //die('<pre>'.print_r(get_class_methods($acl), true).'</pre>');
        $acltree = (array) $acl->get_group_children_tree(null, 'USERS', false);
        array_unshift($acltree, (object) array('value' => 0, 'text' => 'Unregistered', 'disabled' => false));
        $this->acltree = $acltree;
        $this->usergroups = KFactory::tmp('admin::com.ninjaboard.model.usergroups')->limit(0)->getList();
        $maps = array();
        foreach (KFactory::tmp($this->getModel()->getIdentifier())->limit(0)->getList() as $map) {
            $maps[$map->id] = $map->ninjaboard_gid;
        }
        $this->maps = $maps;
        $display = parent::display();
        if (KRequest::type() == 'AJAX') {
            echo '<script type="text/javascript">
			' . $this->_document->_script['text/javascript'] . '
			</script>';
        }
        return $display;
    }
示例#2
0
 /**
  * Renders a controller view.
  *
  * @return string
  */
 protected function _actionRender(KCommandContext $context)
 {
     if ($context->request->getFormat() == 'html' && KRequest::type() == 'HTTP') {
         $this->_setPageTitle();
     }
     return parent::_actionRender($context);
 }
示例#3
0
 /**
  * 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();
         }
     }
 }
 public function __construct(KConfigInterface $config)
 {
     parent::__construct($config);
     if (KRequest::type() == 'AJAX' && KRequest::method() == 'POST') {
         $this->unregisterCallback('after.dispatch', array($this, 'forward'));
     }
 }
示例#5
0
 /**
  * Import the sample content
  *
  * @return $this
  */
 public function convert()
 {
     $this->data = json_decode(file_get_contents(JPATH_COMPONENT_ADMINISTRATOR . '/data/demo.json'), true);
     parent::convert();
     if (KRequest::type() == 'AJAX') {
         echo json_encode(array('splittable' => false));
     }
     return $this;
 }
示例#6
0
 public function display()
 {
     $name = $this->getName();
     //Append enable and disbale button for all the list views
     if ($name != 'dashboard' && KInflector::isPlural($name) && KRequest::type() != 'AJAX') {
         KFactory::get('admin::com.error.toolbar.' . $name)->append('divider')->append('enable')->append('disable');
     }
     return parent::display();
 }
示例#7
0
 /**
  * Overloaded to comply with FancyUpload.
  * It doesn't let us pass AJAX headers so this is needed.
  */
 public function _actionForward(KCommandContext $context)
 {
     if (KRequest::type() == 'FLASH' || KRequest::format() == 'json') {
         $context->result = $this->getController()->execute('display', $context);
     } else {
         parent::_actionForward($context);
     }
     return $context->result;
 }
示例#8
0
 /**
  * Render script information
  * 
  * @param string    The script information
  * @param array     Associative array of attributes
  * @return string   
  */
 protected function _renderScript($link, $attribs = array())
 {
     if (KRequest::type() == 'AJAX') {
         return parent::_renderLink($script, $attribs);
     }
     $relType = 'rel';
     $relValue = $attribs['rel'];
     unset($attribs['rel']);
     JFactory::getDocument()->addHeadLink($link, $relValue, $relType, $attribs);
 }
示例#9
0
 public function __construct(KConfig $config)
 {
     parent::__construct($config);
     $this->registerCallback('after.add', array($this, 'notify'));
     //Lock the referrer to prevent it from being overridden for read requests
     if ($this->isDispatched() && KRequest::type() == 'HTTP') {
         if ($this->isEditable()) {
             $this->registerCallback('after.logout', array($this, 'lockReferrer'));
         }
     }
 }
示例#10
0
 /**
  * Initializes the default configuration 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)
 {
     /* 
      * Disable controller persistency on non-HTTP requests, e.g. AJAX, and requests containing 
      * the tmpl variable set to component, e.g. requests using modal boxes. This avoids 
      * changing the model state session variable of the requested model, which is often 
      * undesirable under these circumstances. 
      */
     $config->append(array('persistable' => KRequest::type() == 'HTTP' && KRequest::get('get.tmpl', 'cmd') != 'component', 'limit' => array('max' => 100, 'default' => JFactory::getApplication()->getCfg('list_limit'))));
     parent::_initialize($config);
 }
示例#11
0
 /**
  * Render script information
  * 
  * @param string    The script information
  * @param boolean   True, if the script information is a URL.
  * @param array     Associative array of attributes
  * @return string   
  */
 protected function _renderScript($script, $link, $attribs = array())
 {
     if (KRequest::type() == 'AJAX') {
         return parent::_renderScript($script, $link, $attribs);
     }
     $document = JFactory::getDocument();
     if ($link) {
         $document->addScript($script, 'text/javascript');
     } else {
         $document->addScriptDeclaration($script);
     }
 }
示例#12
0
 /**
  * Render style information
  * 
  * @param string    The style information
  * @param boolean   True, if the style information is a URL
  * @param array     Associative array of attributes
  * @return string
  */
 protected function _renderStyle($style, $link, $attribs = array())
 {
     if (KRequest::type() == 'AJAX') {
         return parent::_renderStyle($style, $link, $attribs);
     }
     $document = KFactory::get('lib.joomla.document');
     if ($link) {
         $document->addStyleSheet($style, 'text/css', null, $attribs);
     } else {
         $document->addStyleDeclaration($style);
     }
 }
示例#13
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);
         }
     }
 }
示例#14
0
 protected function _actionDisplay(KCommandContext $context)
 {
     /*
     	    //This is used for xdebug to profile imports
     	    $this->_request->import = 'kunena';
     	    KRequest::set('post.offset', 'int', 0);
     	    $this->execute('import');
     	    //*/
     if (KRequest::type() != 'AJAX') {
         $view = $this->getView();
         return $view->display();
     }
     return '';
 }
示例#15
0
 protected function _actionLogout(KCommandContext $context)
 {
     $user = JFactory::getUser();
     if ($user->id) {
         $app = JFactory::getApplication();
         $error = $app->logout();
         if (!$error instanceof Exception) {
         } else {
             $context->status = KHttpResponse::OK;
         }
     }
     if (KRequest::type() != 'AJAX') {
         $this->_redirect = KRequest::referrer();
         //			return $rowset;
     }
 }
示例#16
0
 public function display()
 {
     $this->js('/site.js');
     $this->assign('dateformat', str_replace(array('%A', '%B'), array('%a', '%b'), JText::_('DATE_FORMAT_LC2')));
     $timezone = KFactory::tmp('lib.joomla.user')->getParam('timezone');
     if (is_null($timezone)) {
         $timezone = KFactory::get('lib.joomla.config')->getValue('offset');
     }
     $this->assign('timezone', $timezone);
     //Autoload breadcrumbs module when needed
     //@TODO optimize so it's not made available all the time, only when needed
     if (KRequest::type() != 'AJAX' && KRequest::get('get.format', 'cmd', 'html') == 'html') {
         $this->_loadModBreadcrumbs();
     }
     return parent::display();
 }
示例#17
0
	/**
     * Initializes the default configuration 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)
    {
    	/* 
         * Disable controller persistency on non-HTTP requests, e.g. AJAX, and requests containing 
         * the tmpl variable set to component, e.g. requests using modal boxes. This avoids 
         * changing the model state session variable of the requested model, which is often 
         * undesirable under these circumstances. 
         */  
        
        $config->append(array(
    		'persistable'  => (KRequest::type() == 'HTTP' && KRequest::get('get.tmpl','cmd') != 'component'),
            //'behaviors'  =>  array('cacheable')
        ));

        parent::_initialize($config);
    }
示例#18
0
 /**
  * Constructor
  *
  * @param   object  An optional KConfig object with configuration options
  */
 public function __construct(KConfig $config)
 {
     parent::__construct($config);
     if ($this->isDispatched() && KRequest::type() == 'HTTP') {
         $this->registerCallback('before.read', array($this, 'setReferrer'));
         $this->registerCallback('after.apply', array($this, 'lockReferrer'));
         $this->registerCallback('after.read', array($this, 'unlockReferrer'));
         $this->registerCallback('after.save', array($this, 'unsetReferrer'));
         $this->registerCallback('after.cancel', array($this, 'unsetReferrer'));
     }
     $this->registerCallback('after.read', array($this, 'lockResource'));
     $this->registerCallback('after.save', array($this, 'unlockResource'));
     $this->registerCallback('after.cancel', array($this, 'unlockResource'));
     //Set the default redirect.
     $this->setRedirect(KRequest::referrer());
 }
示例#19
0
 /**
  * Render script information.
  * 
  * @param string    The script information
  * @param bool   True, if the script information is a URL.
  * @param array     Associative array of attributes
  *
  * @return string
  */
 protected function _renderScript($script, $link, $attribs = array())
 {
     if ($link) {
         $script = pick($this->getService('com://site/base.template.asset')->getURL($script), $script);
     }
     //if ajax try to get the content of the file
     if (KRequest::type() == 'AJAX') {
         if ($link) {
             $file = $this->getService('com://site/base.template.asset')->getFilePath($script);
             if ($file) {
                 $script = file_get_contents($file);
                 $link = false;
             }
         }
     }
     return parent::_renderScript($script, $link, $attribs);
 }
示例#20
0
 /**
  * Forward after a post request
  *
  * Either do a redirect or a execute a browse or read action in the controller
  * depending on the request method and type
  *
  * @return mixed
  */
 public function _actionForward(KCommandContext $context)
 {
     if (KRequest::type() == 'HTTP') {
         if ($redirect = KFactory::get($this->getController())->getRedirect()) {
             KFactory::get('lib.joomla.application')->redirect($redirect['url'], $redirect['message'], $redirect['type']);
         }
     }
     if (KRequest::type() == 'AJAX') {
         $view = KRequest::get('get.view', 'cmd');
         $context->result = KFactory::get($this->getController())->execute('display', $context);
         return $context->result;
     }
 }
示例#21
0
 /**
  * Push the request data into the model state
  *
  * @param	string		The action to execute
  * @return	mixed|false The value returned by the called method, false in error case.
  * @throws 	KControllerException
  */
 public function execute($action, $data = NULL)
 {
     //Create a context object
     if (!$data instanceof KCommandContext) {
         $context = $this->getCommandContext();
         $context->data = $data;
         $context->result = false;
     } else {
         $context = $data;
     }
     $result = parent::execute($action, $context);
     $return_json = array(KRequest::type() == 'AJAX', KRequest::get('get.format', 'cmd') == 'json', !is_string($result), $this->_redirect_message, $this->_auto_json_result);
     if (count($return_json) === count(array_filter($return_json))) {
         $data = is_object($result) && method_exists($result, 'getData') ? $result->getData() : $result;
         //@TODO get rid of msg legacy, use message in the future
         $result = json_encode(array('msg' => $this->_redirect_message, 'message' => $this->_redirect_message, 'result' => $data));
         //@TODO workaround for preventing 404 response headers
         //$context->status = KHttpRequest::OK;
         //Workaround for KDispatcherAbstract::_actionForward
         //@TODO submit patch, or similar for this limitation
         //@see KDispatcheAbstract line 43 - 45 where the forward is made if request isn't POST
         if (KRequest::method() != 'GET') {
             $identifier = clone $this->getIdentifier();
             $identifier->path = array();
             $identifier->name = 'dispatcher';
             $dispatcher = KFactory::get($identifier)->unregisterCallback('after.dispatch', 'forward');
         }
     }
     return $result;
 }
示例#22
0
	/**
	 * On after intitialse event handler
	 * 
	 * This functions implements HTTP Basic authentication support
	 * 
	 * @return void
	 */
	public function onAfterInitialise()
	{  
	     /*
	     * Try to log the user in 
	     * 
	     * If the request contains authorization information we try to log the user in
	     */
	    if($this->params->get('auth_basic', 1) && KFactory::get('joomla:user')->get('guest')) {
	        $this->_authenticateUser();
	    }
	    
	    /*
	     * Special handling for AJAX requests
	     * 
	     * If the format is AJAX and the format is 'html' or the tmpl is empty we re-create 
	     * a 'raw' document rendered and force it's type to the active format
	     */
        if(KRequest::type() == 'AJAX') 
        {
        	if(KRequest::get('get.format', 'cmd', 'html') != 'html' || KRequest::get('get.tmpl', 'cmd') === '')
        	{
        		$format = JRequest::getWord('format', 'html');
        	
        		JRequest::setVar('format', 'raw');   //force format to raw
        		
        		$document =& JFactory::getDocument();
        		$document = null;
        		JFactory::getDocument()->setType($format);
        		
        		JRequest::setVar('format', $format); //revert format to original
        	}
        }
	}
示例#23
0
 protected function _actionCheckversion()
 {
     $path = KFactory::get('admin::com.ninja.helper.application')->getPath('com_xml');
     //load the file, and save it to our object
     $xml = simplexml_load_file($path);
     if (!isset($xml->updateurl)) {
         return false;
     }
     $url = (string) $xml->updateurl;
     // Prepare curl
     $curl = KFactory::get('admin::com.ninja.helper.curl');
     $opt = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array("Expect:"), CURLOPT_HEADERFUNCTION => array($curl, 'readHeader'));
     $curl->addSession($url, $opt);
     // @TODO in NEC2, let's have a api for this, so it's way faster
     $curl->exec();
     $info = $curl->info();
     $filename = $info[0]['content_disposition'];
     $revision = $this->extractRevisionFromFilename($filename);
     $status = $this->extractStatusFromFilename($filename);
     $version = $this->extractVersionFromFilename($filename);
     $version_compare = version_compare((string) $xml->version, $version, '<');
     $revision_compare = (int) $xml->revision < $revision;
     if ($version_compare || version_compare((string) $xml->version, $version, '=') && $revision_compare) {
         $msg = array('text' => sprintf(JText::_('%1$s %2$s %3$s rev%4$s available for download.'), JText::_($this->getIdentifier()->package), $version, JText::_($status), $revision), 'update' => true);
         if (KRequest::type() == 'AJAX') {
             die(json_encode($msg));
         }
         return true;
     } else {
         $msg = array('text' => sprintf(JText::_('This is the newest version of %1$s.'), JText::_($this->getIdentifier()->package), $version, JText::_($status), $revision), 'update' => false);
         if (KRequest::type() == 'AJAX') {
             die(json_encode($msg));
         }
         return false;
     }
 }
示例#24
0
 /**
  * On after intitialse event handler
  * 
  * This functions implements HTTP Basic authentication support
  * 
  * @return void
  */
 public function onAfterInitialise()
 {
     /*
      * Try to log the user in
      * 
      * If the request contains authorization information we try to log the user in
      */
     if ($this->params->get('auth_basic', 0) && KFactory::get('lib.joomla.user')->get('guest')) {
         $this->_authenticateUser();
     }
     /*
      * Reset the user and token
      *
      * In case another plugin have logged in after we initialized we need to reset the token and user object
      * One plugin that could cause that, are the Remember Me plugin
      */
     if (KFactory::get('lib.joomla.user')->get('guest') && !JFactory::getUser()->get('guest')) {
         //Reset the user object in the factory
         KFactory::set('lib.koowa.user', JFactory::getUser());
         //Force the token
         KRequest::set('request._token', JUtility::getToken());
     }
     /*
      * Special handling for AJAX requests
      * 
      * If the format is AJAX and the format is 'html' or the tmpl is empty we re-create 
      * a 'raw' document rendered and force it's type to the active format
      */
     if (KRequest::type() == 'AJAX') {
         if (KRequest::get('get.format', 'cmd', 'html') != 'html' || KRequest::get('get.tmpl', 'cmd') === '') {
             $format = JRequest::getWord('format', 'html');
             JRequest::setVar('format', 'raw');
             //force format to raw
             $document =& JFactory::getDocument();
             $document = null;
             JFactory::getDocument()->setType($format);
             JRequest::setVar('format', $format);
             //revert format to original
         }
     }
 }
示例#25
0
文件: form.php 项目: stonyyi/anahita
echo @text('LIB-AN-PRIVACY-FORM-LABEL');
?>
</label>
			<div class="controls">
				<?php 
echo @helper('ui.privacy', array('entity' => $todo, 'auto_submit' => false, 'options' => $actor));
?>
			</div>
		</div>
		
		<div class="form-actions">
			<?php 
if ($todo->persisted()) {
    ?>
				<?php 
    if (KRequest::type() == 'AJAX') {
        ?>
				<a data-action="cancel" class="btn" href="<?php 
        echo @route($url . '&layout=list');
        ?>
">
					<?php 
        echo @text('LIB-AN-ACTION-CANCEL');
        ?>
				</a> 
				<?php 
    } else {
        ?>
				<a class="btn" href="<?php 
        echo @route($url);
        ?>
 /**
  * On after route event handler
  *
  * @return void
  */
 public function onAfterRoute()
 {
     /*
      * Special handling for AJAX requests
      *
      * If the format is AJAX and the format is 'html' or the tmpl is empty we re-create
      * a 'raw' document rendered and force it's type to the active format
      */
     if (KRequest::type() == 'AJAX') {
         if (KRequest::get('get.format', 'cmd', 'html') != 'html' || KRequest::get('get.tmpl', 'cmd') === '') {
             $format = JRequest::getWord('format', 'html');
             JRequest::setVar('format', 'raw');
             //force format to raw
             @($document =& JFactory::getDocument());
             $document = null;
             JFactory::getDocument()->setType($format);
             JRequest::setVar('format', $format);
             //revert format to original
         }
     }
     //Set the request format
     if (!KRequest::has('request.format')) {
         KRequest::set('request.format', KRequest::format());
     }
 }
示例#27
0
 /**
  * Return if the request is ajax.
  * 
  * @return bool
  */
 public function isAjax()
 {
     return KRequest::type() == 'AJAX';
 }
示例#28
0
 /**
  * Forward after a post request
  *
  * Either do a redirect or a execute a browse or read action in the controller
  * depending on the request method and type
  *
  * @return mixed
  */
 public function _actionForward(KCommandContext $context)
 {
     if (KRequest::type() == 'HTTP') {
         if ($redirect = $this->getController()->getRedirect()) {
             JFactory::getApplication()->redirect($redirect['url'], $redirect['message'], $redirect['type']);
         }
     }
     if (KRequest::type() == 'AJAX') {
         $context->result = $this->getController()->execute('display', $context);
         return $context->result;
     }
 }