/** * Uploads attachment file * * @access public * @return string javascript script segment */ function UploadFile() { $file_num = jaws()->request->fetch('attachment_number', 'post'); $file = Jaws_Utils::UploadFiles($_FILES, Jaws_Utils::upload_tmp_dir(), '', null); if (Jaws_Error::IsError($file)) { $response = array('type' => 'error', 'message' => $file->getMessage()); } else { $response = array('type' => 'notice', 'file_info' => array('title' => $file['attachment' . $file_num][0]['user_filename'], 'filename' => $file['attachment' . $file_num][0]['host_filename'], 'filesize_format' => Jaws_Utils::FormatSize($file['attachment' . $file_num][0]['host_filesize']), 'filesize' => $file['attachment' . $file_num][0]['host_filesize'], 'filetype' => $file['attachment' . $file_num][0]['host_filetype'])); } $response = Jaws_UTF8::json_encode($response); return "<script type='text/javascript'>parent.onUpload({$response});</script>"; }
/** * Uploads the avatar * * @access public * @return string XHTML content */ function UploadAvatar() { $this->gadget->CheckPermission('EditUserPersonal'); $res = Jaws_Utils::UploadFiles($_FILES, Jaws_Utils::upload_tmp_dir(), 'gif,jpg,jpeg,png'); if (Jaws_Error::IsError($res)) { $response = array('type' => 'error', 'message' => $res->getMessage()); } elseif (empty($res)) { $response = array('type' => 'error', 'message' => _t('GLOBAL_ERROR_UPLOAD_4')); } else { $response = array('type' => 'notice', 'message' => $res['upload_avatar'][0]['host_filename']); } $response = Jaws_UTF8::json_encode($response); return "<script type='text/javascript'>parent.onUpload({$response});</script>"; }
/** * Uploads attachment file * * @access public * @return string javascript script segment */ function UploadFile() { $res = Jaws_Utils::UploadFiles($_FILES, Jaws_Utils::upload_tmp_dir()); if (Jaws_Error::IsError($res)) { $response = array('type' => 'error', 'message' => $res->getMessage()); } elseif (empty($res)) { $response = array('type' => 'error', 'message' => _t('GLOBAL_ERROR_UPLOAD_4')); } else { $response = array('type' => 'notice', 'filename' => $res['attachment'][0]['host_filename'], 'filesize' => Jaws_Utils::FormatSize($_FILES['attachment']['size'])); } $response = Jaws_UTF8::json_encode($response); return "<script type='text/javascript'>parent.onUpload({$response});</script>"; }
/** * Uploads file to system temp directory * * @access public * @return string JavaScript snippet */ function UploadFile() { $res = Jaws_Utils::UploadFiles($_FILES, Jaws_Utils::upload_tmp_dir(), '', null); if (Jaws_Error::IsError($res)) { $response = array('type' => 'error', 'message' => $res->getMessage()); } else { $response = array('type' => 'notice', 'user_filename' => $res['file'][0]['user_filename'], 'host_filename' => $res['file'][0]['host_filename'], 'filetype' => $res['file'][0]['host_filetype'], 'filesize' => $res['file'][0]['host_filesize']); } $response = Jaws_UTF8::json_encode($response); return "<script>parent.onUpload({$response});</script>"; }
/** * Build the XHTML * * @access public * @return string XHTML content */ function buildXHTML() { $label = $this->_Label->GetValue(); if (!empty($label)) { $this->_Container->PackStart($this->_Label); } $this->_Container->PackStart($this->TextArea); $this->_Container->SetWidth($this->_Width); $this->_XHTML .= $this->_Container->Get(); $extraPlugins = array(); $pluginDir = JAWS_PATH . 'libraries/ckeditor/plugins/'; if (is_dir($pluginDir)) { $dirs = scandir($pluginDir); foreach ($dirs as $dir) { if ($dir[0] != '.' && is_dir($pluginDir . $dir)) { if (!in_array($dir, $this->_DefaultPlugins)) { $extraPlugins[] = $dir; } } } } $GLOBALS['app']->Layout->AddScriptLink('libraries/ckeditor/ckeditor.js'); $tpl = new Jaws_Template(); $tpl->Load('CKEditor.html', 'include/Jaws/Resources'); $block = JAWS_SCRIPT == 'admin' ? 'ckeditor_backend' : 'ckeditor_frontend'; $tpl->SetBlock($block); $tpl->SetVariable('name', $this->_Name); $tpl->SetVariable('baseUrl', Jaws_Utils::getBaseURL('/', true)); $tpl->SetVariable('contentsLangDirection', $this->_Direction); $tpl->SetVariable('language', $this->_Language); $tpl->SetVariable('AutoDetectLanguage', 'false'); $tpl->SetVariable('autoParagraph', 'false'); $tpl->SetVariable('height', $this->_Height); $tpl->SetVariable('skin', $this->_Skin); $tpl->SetVariable('theme', $this->_Theme); $tpl->SetVariable('readOnly', $this->_IsEnabled ? 'false' : 'true'); $tpl->SetVariable('resize_enabled', $this->_IsResizable ? 'true' : 'false'); $tpl->SetVariable('toolbar', Jaws_UTF8::json_encode($this->toolbars)); if (!empty($extraPlugins)) { $tpl->SetBlock("{$block}/extra"); $tpl->SetVariable('extraPlugins', implode(',', $extraPlugins)); $tpl->ParseBlock("{$block}/extra"); } // removed plugins $tpl->SetVariable('removePlugins', $this->_RemovePlugins); // direction if ('rtl' == $this->_Direction) { $tpl->SetVariable('contentsCss', 'gadgets/ControlPanel/Resources/ckeditor.rtl.css'); } else { $tpl->SetVariable('contentsCss', 'gadgets/ControlPanel/Resources/ckeditor.css'); } // FileBrowser if (Jaws_Gadget::IsGadgetInstalled('FileBrowser')) { $tpl->SetBlock("{$block}/filebrowser"); $tpl->SetVariable('filebrowserBrowseUrl', BASE_SCRIPT . '?gadget=FileBrowser&action=BrowseFile'); $tpl->SetVariable('filebrowserFlashBrowseUrl', BASE_SCRIPT . '?gadget=FileBrowser&action=BrowseFile'); $tpl->ParseBlock("{$block}/filebrowser"); } // Phoo if (Jaws_Gadget::IsGadgetInstalled('Phoo')) { $tpl->SetBlock("{$block}/phoo"); $tpl->SetVariable('filebrowserImageBrowseUrl', BASE_SCRIPT . '?gadget=Phoo&action=BrowsePhoo'); $tpl->ParseBlock("{$block}/phoo"); } $tpl->ParseBlock($block); $this->_XHTML .= $tpl->Get(); }
/** * Terminate script * * @param mixed $data Response data * @param bool $sync Synchronize session * @return void */ function terminate(&$data = null, $status_code = 200, $next_location = '', $sync = true) { // Send content to client $resType = jaws()->request->fetch('restype'); // Event logging if (isset($GLOBALS['app'])) { $gadget = $GLOBALS['app']->mainGadget; $action = $GLOBALS['app']->mainAction; $sync = isset($GLOBALS['app']->Session) ? $sync : false; $loglevel = 0; if (!empty($gadget) && !empty($action)) { $loglevel = @Jaws_Gadget::getInstance($gadget)->actions[JAWS_SCRIPT][$action]['loglevel']; } // shout log event $GLOBALS['app']->Listener->Shout('Action', 'Log', array($gadget, $action, $loglevel, null, http_response_code())); } else { $gadget = ''; $action = ''; $sync = false; } switch ($resType) { case 'json': header('Content-Type: application/json; charset=utf-8'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); if (in_array($status_code, array(301, 302))) { $data = $GLOBALS['app']->Session->PopResponse($data); } // Sync session if ($sync) { $GLOBALS['app']->Session->update(); } echo Jaws_UTF8::json_encode($data); break; case 'gzip': case 'x-gzip': $data = gzencode($data, COMPRESS_LEVEL, FORCE_GZIP); header('Content-Length: ' . strlen($data)); header('Content-Encoding: ' . $resType); default: // Sync session if ($sync) { $GLOBALS['app']->Session->update(); } switch ($status_code) { case 301: http_response_code(301); header('Location: ' . $next_location); break; case 302: http_response_code(302); header('Location: ' . $next_location); break; default: } echo $data; } if (isset($GLOBALS['log'])) { $GLOBALS['log']->End(); } exit; }
/** * Returns the JSON representation of a value * @see http://www.php.net/json_encode */ static function json_encode($value = false) { if (is_null($value)) { return 'null'; } if ($value === false) { return 'false'; } if ($value === true) { return 'true'; } if (is_scalar($value)) { if (is_float($value)) { // Always use "." for floats. return floatval(str_replace(",", ".", strval($value))); } if (is_string($value)) { static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\\"')); return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $value) . '"'; } else { return $value; } } $isList = true; for ($i = 0, reset($value); $i < count($value); $i++, next($value)) { if (key($value) !== $i) { $isList = false; break; } } $result = array(); if ($isList) { foreach ($value as $v) { $result[] = Jaws_UTF8::json_encode($v); } return '[' . implode(',', $result) . ']'; } else { foreach ($value as $k => $v) { $result[] = Jaws_UTF8::json_encode($k) . ':' . Jaws_UTF8::json_encode($v); } return '{' . implode(',', $result) . '}'; } }
/** * Uploads the personal image * * @access public * @return string XHTML content */ function UploadImage() { if (!$GLOBALS['app']->Session->Logged()) { return Jaws_HTTPError::Get(403); } $res = Jaws_Utils::UploadFiles($_FILES, Jaws_Utils::upload_tmp_dir(), 'gif,jpg,jpeg,png'); if (Jaws_Error::IsError($res)) { $response = array('type' => 'error', 'message' => $res->getMessage()); } else { $response = array('type' => 'notice', 'message' => $res['upload_image'][0]['host_filename']); } $response = Jaws_UTF8::json_encode($response); return "<script type='text/javascript'>parent.onUpload({$response});</script>"; }