/** * Executes the application. Normally this means to get some data. We usually return in json format. * * @return bool * @throws vB_Exception_Api */ public function execute() { if (!isset($this->application)) { throw new vB_Exception_Api('invalid_request'); } $serverData = array_merge($_GET, $_POST); if (!empty($this->application['handler']) and method_exists($this, $this->application['handler'])) { $app = $this->application['handler']; call_user_func(array($this, $app)); return true; } else { if ($this->application['static']) { //BEWARE- NOT YET TESTED $result = Api_InterfaceAbstract::instance()->callApiStatic($this->application['controller'], $this->application['method'], $serverData, true); } else { if ($this->application['callcontroller']) { $response = $this->callController($this->application['controller'], $this->application['method']); // using an array will let us have more control on the response. // we can easily extend to support printing different kind of outputs. echo $response['response']; return true; } else { //We need to create a session $result = Api_InterfaceAbstract::instance()->callApi($this->application['controller'], $this->application['method'], $serverData, true); } } } $controller = new vB5_Frontend_Controller(); $controller->sendAsJson($result); return true; }
function __construct() { parent::__construct(); }
public function post() { $upload = isset($_FILES[$this->options['param_name']]) ? $_FILES[$this->options['param_name']] : array('tmp_name' => null, 'name' => null, 'size' => null, 'type' => null, 'error' => 'no_file_to_upload'); $info = array(); if (is_array($upload['tmp_name'])) { foreach ($upload['tmp_name'] as $index => $value) { $info[] = $this->handle_file_upload($upload['tmp_name'][$index], isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'][$index], isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'][$index], isset($_SERVER['HTTP_X_FILE_TYPE']) ? $_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'][$index], $upload['error'][$index]); } } else { $info[] = $this->handle_file_upload($upload['tmp_name'], isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'], isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'], isset($_SERVER['HTTP_X_FILE_TYPE']) ? $_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'], $upload['error']); } foreach ($info as $file) { unset($file->contents); } header('Vary: Accept'); if (isset($this->options['uploadFrom']) and $this->options['uploadFrom'] == 'CKEditorInsertImage') { header('Content-type: text/html'); $funcNum = $_GET['CKEditorFuncNum']; $editorId = $_GET['CKEditor']; $url = ''; $api = Api_InterfaceAbstract::instance(); if (!empty($info)) { $url = isset($info[0]->url) ? $info[0]->url : ''; $error = isset($info[0]->error) ? $info[0]->error : ''; if (is_array($error)) { $errorphrase = array_shift($error); $phrases = $api->callApi('phrase', 'fetch', array(array($errorphrase))); $error = vsprintf($phrases[$errorphrase], $error); } else { if (!empty($error)) { $phrases = $api->callApi('phrase', 'fetch', array(array($error))); $error = $phrases[$error]; } } } else { $phrases = $api->callApi('phrase', 'fetch', array(array('error_uploading_image'))); $error = $phrases['error_uploading_image']; } //encode to ensure we don't encounter js syntax error $errorEncode = json_encode($error); echo "<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction({$funcNum}, '{$url}', {$errorEncode});"; $havefile = false; foreach ($info as $file) { if (!empty($file->filedataid)) { // vBulletin.ckeditor.insertImageAttachment() is now called downstream of vBulletin.ckeditor.closeFileDialog() //echo "window.parent.vBulletin.ckeditor.insertImageAttachment('$editorId', {$file->filedataid}, '{$file->name}');"; $havefile = true; break; } } if ($havefile and empty($error)) { // the image inserts (<img> element in the editor body & hidden inputs in the form) are handled as part of closeFileDialog() (normally would be handled by the onOk handler of the dialog) echo "window.parent.vBulletin.ckeditor.closeFileDialog('{$editorId}', " . json_encode($info) . ");"; } echo "</script>"; exit; } if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) { header('Content-type: application/json'); } else { header('Content-type: text/plain'); } $controller = new vB5_Frontend_Controller(); $controller->sendAsJson($info); }