예제 #1
0
 /**
  * @param string   $model
  * @param string   $action
  * @param array    $params
  *
  * @throws RokCommon_Ajax_Exception
  * @return string
  */
 public static function run($model, $action, $params, $encoding = self::JSON_ENCODING)
 {
     // Set up an independent AJAX error handler
     set_error_handler(array('RokCommon_Ajax', 'error_handler'));
     set_exception_handler(array('RokCommon_Ajax', 'exception_handler'));
     while (@ob_end_clean()) {
     }
     // clean any pending output buffers
     ob_start();
     // start a fresh one
     $result = null;
     try {
         // get a model class instance
         $modelInstance = self::getModel($model);
         if ($encoding == self::JSON_ENCODING) {
             $decoded_params = json_decode($params);
             if (null == $decoded_params && strlen($params) > 0) {
                 throw new RokCommon_Ajax_Exception('Invalid JSON for params');
             }
             $params = $decoded_params;
         }
         // set the result to the run
         $result = $modelInstance->run($action, $params);
     } catch (Exception $ae) {
         $result = new RokCommon_Ajax_Result();
         $result->setAsError();
         $result->setMessage($ae->getMessage());
     }
     $encoded_result = json_encode($result);
     // restore normal error handling;
     restore_error_handler();
     restore_exception_handler();
     return $encoded_result;
 }
예제 #2
0
 /**
  *
  */
 public function ajax()
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     try {
         $container = RokCommon_Service::getContainer();
         foreach ($container['roksprocket.layouts'] as $layout) {
             if (isset($layout->paths) && isset($layout->ajax->dir)) {
                 $paths = $layout->paths;
                 $ajax_dir = $layout->ajax->dir;
                 foreach ($paths as $priority => $path) {
                     $ajax_path = $path . '/' . $ajax_dir;
                     if (is_dir($ajax_path)) {
                         RokCommon_Ajax::addModelPath($ajax_path, 'RokSprocketSiteLayoutAjaxModel', $priority);
                     }
                 }
             }
         }
         $model = $input->get('model', null, 'word');
         $action = $input->get('model_action', $input->get('action', null, 'word'), 'word');
         if (isset($_REQUEST['params'])) {
             $params = RokCommon_Ajax::smartStripSlashes($_REQUEST['params']);
         }
         echo RokCommon_Ajax::run($model, $action, $params);
     } catch (Exception $e) {
         $result = new RokCommon_Ajax_Result();
         $result->setAsError();
         $result->setMessage($e->getMessage());
         echo json_encode($result);
     }
 }
예제 #3
0
 public function ajax()
 {
     try {
         RokCommon_Ajax::addModelPath(JPATH_SITE . '/components/com_rokgallery/lib/RokGallery/Site/Ajax/Model', 'RokGallerySiteAjaxModel');
         $model = JRequest::getString('model');
         $action = JRequest::getString('action');
         $params = JRequest::getString('params');
         echo RokCommon_Ajax::run($model, $action, $params);
     } catch (Exception $e) {
         $result = new RokCommon_Ajax_Result();
         $result->setAsError();
         $result->setMessage($e->getMessage());
         echo json_encode($result);
     }
 }
예제 #4
0
 public function ajax()
 {
     try {
         RokCommon_Ajax::addModelPath(JPATH_SITE . '/components/com_rokgallery/lib/RokGallery/Admin/Ajax/Model', 'RokGalleryAdminAjaxModel');
         $model = JRequest::getString('model');
         $action = JRequest::getString('action');
         if (isset($_REQUEST['params'])) {
             $params = $this->smartstripslashes($_REQUEST['params']);
         }
         echo RokCommon_Ajax::run($model, $action, $params);
     } catch (Exception $e) {
         $result = new RokCommon_Ajax_Result();
         $result->setAsError();
         $result->setMessage($e->getMessage());
         echo json_encode($result);
     }
 }
예제 #5
0
 /**
  *
  */
 public function ajax()
 {
     try {
         $app = JFactory::getApplication();
         $input = $app->input;
         RokCommon_Ajax::addModelPath(JPATH_SITE . '/components/com_roksprocket/lib/RokSprocket/Admin/Ajax/Model', 'RokSprocketAdminAjaxModel');
         $model = $input->get('model', null, 'word');
         $action = $input->get('action', null, 'word');
         if (isset($_REQUEST['params'])) {
             $params = $this->smartstripslashes($_REQUEST['params']);
         }
         echo RokCommon_Ajax::run($model, $action, $params);
     } catch (Exception $e) {
         $result = new RokCommon_Ajax_Result();
         $result->setAsError();
         $result->setMessage($e->getMessage());
         echo json_encode($result);
     }
 }
예제 #6
0
 public function save($key = null)
 {
     $ret = true;
     $app = JFactory::getApplication();
     $input = $app->input;
     $task = $input->get('task', null, 'CMD');
     if ($task == 'apply') {
         // Set up an independent AJAX error handler
         set_error_handler(array('RokCommon_Ajax', 'error_handler'));
         set_exception_handler(array('RokCommon_Ajax', 'exception_handler'));
     }
     $ret = parent::save($key);
     if ($task == 'apply') {
         $result = new RokCommon_Ajax_Result();
         if (!$ret) {
             $errors = $app->getMessageQueue();
             $result->setAsError();
             foreach ($errors as $error) {
                 $result->setMessage($error['message']);
             }
         } else {
             $result->setPayload(array('module_id' => $app->getUserState('com_roksprocket.module_id', 0)));
             $app->setUserState('com_roksprocket.module_id', null);
         }
         $encoded_result = json_encode($result);
         // restore normal error handling;
         restore_error_handler();
         restore_exception_handler();
         echo $encoded_result;
     }
     return true;
 }
예제 #7
0
파일: ajax.php 프로젝트: ppantilla/bbninja
jimport('joomla.utilities.date');
jimport('joomla.utilities.utility');
jimport('joomla.event.dispatcher');
jimport('joomla.utilities.arrayhelper');
jimport('joomla.user.user');
//It's an application, so let's get the application helper.
jimport('joomla.application.helper');
$app = JFactory::getApplication('administrator');
$app->initialise();
// no direct access
defined('_JEXEC') or die('Restricted access');
require_once dirname(__FILE__) . '/lib/include.php';
$container = RokUpdater_ServiceProvider::getInstance();
/** @var RokUpdater_Ajax $ajax_handler */
$ajax_handler = $container->ajax_handler;
$input = $app->input;
try {
    $model = $input->get('ajax_model', null, 'word');
    if (null == $model) {
        throw new RokUpdater_Exception('No Ajax Model passed.');
    }
    $results = $ajax_handler->run($model);
    if ($results !== false) {
        echo $results;
    }
} catch (Exception $e) {
    $result = new RokCommon_Ajax_Result();
    $result->setAsError();
    $result->setMessage($e->getMessage());
    echo json_encode($result);
}