/** * @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; }
/** * */ 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); } }
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); } }
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); } }
/** * */ 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); } }
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; }
function foo($params) { try { $result = new RokCommon_Ajax_Result(); // // $tags = array(); // // $query = Doctrine_Query::create() // ->select('ft.tag as tag') // ->from('RokGallery_Model_FileTags ft') // ->groupBy('tag') // ->orderBy('tag'); // // $file_tags = $query->execute(array(), Doctrine_Core::HYDRATE_ARRAY); // foreach($file_tags as $tag){ // $tags[$tag['tag']]=$tag['tag']; // } // // $query = Doctrine_Query::create() // ->select('st.tag as tag') // ->from('RokGallery_Model_SliceTags st') // ->groupBy('tag') // ->orderBy('tag'); // // $slice_tags = $query->execute(array(), Doctrine_Core::HYDRATE_ARRAY); // foreach($slice_tags as $tag){ // $tags[$tag['tag']]=$tag['tag']; // } // // $tags = array_keys($tags); // sort($tags); // $result->setPayload($tags); // // } // catch (Exception $e) // { // throw $e; // } // $original_h = $image->getHeight(); // $original_w = $image->getWidth(); // $target_h = 180; // $target_w = 300; // // $new_h = ($original_h/$original_w)*$target_w; // $new_w = $target_h/($original_h/$original_w); // $image = WideImage::loadFromFile(JPATH_SITE . "/media/rokgallery/7/332d3a82dc6227309a120493476f0fc/7332d3a82dc6227309a120493476f0fc-1.png"); // $outimage = $image->resize(300,180); // $outimage->saveToFile(JPATH_SITE . "/media/rokgallery/7/332d3a82dc6227309a120493476f0fc/7332d3a82dc6227309a120493476f0fc-1-thumb.png"); // // $result->setPayload($outimage->getHeight()); $result = new RokCommon_Ajax_Result(); try { $result->setMessage('Starting'); $this->sendDisconnectingReturn($result); sleep(30); die; } catch (Exception $e) { throw $e; } } catch (Exception $e) { throw $e; } }
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); }
/** * resume a paused job * $params object should be a json like * <code> * { * 'id': 'xxxx-x-x-x-x-x-x' * } * </code> * * @param $params * @return RokCommon_Ajax_Result */ public function resume($params) { $result = new RokCommon_Ajax_Result(); try { $job = RokGallery_Job::get($params->id); if ($job === false) { throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_JOB_ID_N', $params->id)); } $result->setMessage(rc__('ROKGALLERY_STARTING_N_JOB', ucfirst($job->getType()))); $this->sendDisconnectingReturn($result); $job->Resume('Resuming Processing'); $job->process(); die; } catch (Exception $e) { throw $e; } }