/** * Returns downloadable backup file * * @access public * @return void */ function Backup() { $this->gadget->CheckPermission('Backup'); $tmpDir = sys_get_temp_dir(); $domain = preg_replace("/^(www.)|(:{$_SERVER['SERVER_PORT']})\$|[^a-z0-9\\-\\.]/", '', strtolower($_SERVER['HTTP_HOST'])); $nameArchive = $domain . '-' . date('Y-m-d') . '.tar.gz'; $pathArchive = $tmpDir . DIRECTORY_SEPARATOR . $nameArchive; //Dump database data $dbFileName = 'dbdump.xml'; $dbFilePath = $tmpDir . DIRECTORY_SEPARATOR . $dbFileName; Jaws_DB::getInstance()->Dump($dbFilePath); $files = array(); require_once PEAR_PATH . 'File/Archive.php'; $files[] = File_Archive::read(JAWS_DATA); $files[] = File_Archive::read($dbFilePath, $dbFileName); File_Archive::extract($files, File_Archive::toArchive($pathArchive, File_Archive::toFiles())); Jaws_Utils::Delete($dbFilePath); // browser must download file from server instead of cache header("Expires: 0"); header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); // force download dialog header("Content-Type: application/force-download"); // set data type, size and filename header("Content-Disposition: attachment; filename=\"{$nameArchive}\""); header("Content-Transfer-Encoding: binary"); header('Content-Length: ' . @filesize($pathArchive)); @readfile($pathArchive); Jaws_Utils::Delete($pathArchive); }
/** * Displays the captcha image * * @access public * @param int $key Captcha key * @return mixed Captcha raw image data */ function image($key) { $value = Jaws_Utils::RandomText(); $result = $this->update($key, $value); if (Jaws_Error::IsError($result)) { $value = ''; } $bg = dirname(__FILE__) . '/resources/simple.bg.png'; $im = imagecreatefrompng($bg); imagecolortransparent($im, imagecolorallocate($im, 255, 255, 255)); // Write it in a random position.. $darkgray = imagecolorallocate($im, 0x10, 0x70, 0x70); $x = 5; $y = 20; $text_length = strlen($value); for ($i = 0; $i < $text_length; $i++) { $fnt = rand(7, 10); $y = rand(6, 10); imagestring($im, $fnt, $x, $y, $value[$i], $darkgray); $x = $x + rand(15, 25); } header("Content-Type: image/png"); ob_start(); imagepng($im); $content = ob_get_contents(); ob_end_clean(); imagedestroy($im); return $content; }
/** * Does any actions required to finish the stage. * * @access public * @return bool|Jaws_Error Either true on success, or a Jaws_Error * containing the reason for failure. */ function Run() { $cleanup_error = false; $cleanup_items = @file_get_contents(JAWS_PATH . 'upgrade/stages/Cleanup/folders.txt'); $cleanup_items = array_filter(explode("\n", $cleanup_items)); foreach ($cleanup_items as $item) { if (file_exists(JAWS_PATH . $item)) { if (!Jaws_Utils::Delete(JAWS_PATH . $item)) { $cleanup_error = true; } } } $cleanup_items = @file_get_contents(JAWS_PATH . 'upgrade/stages/Cleanup/files.txt'); $cleanup_items = array_filter(explode("\n", $cleanup_items)); foreach ($cleanup_items as $item) { if (file_exists(JAWS_PATH . $item)) { if (!Jaws_Utils::Delete(JAWS_PATH . $item)) { $cleanup_error = true; } } } if ($cleanup_error) { return Jaws_Error::raiseError(_t('UPGRADE_CLEANUP_ERROR_PERMISSION'), 0, JAWS_ERROR_WARNING); } return true; }
/** * Builds the NoPermission UI * * @access public * @param string $user Username * @param string $gadget The Gadget user is requesting * @param string $action The 'denied' action * @return string XHTML content */ function ShowNoPermission($user, $gadget, $action) { // Load the template $tpl = $this->gadget->template->load('NoPermission.html'); $tpl->SetBlock('NoPermission'); $tpl->SetVariable('nopermission', _t('USERS_NO_PERMISSION_TITLE')); $tpl->SetVariable('description', _t('USERS_NO_PERMISSION_DESC', $gadget, $action)); $tpl->SetVariable('admin_script', BASE_SCRIPT); $tpl->SetVariable('site-name', $this->gadget->registry->fetch('site_name', 'Settings')); $tpl->SetVariable('site-slogan', $this->gadget->registry->fetch('site_slogan', 'Settings')); $tpl->SetVariable('BASE_URL', $GLOBALS['app']->GetSiteURL('/')); $tpl->SetVariable('.dir', _t('GLOBAL_LANG_DIRECTION') == 'rtl' ? '.rtl' : ''); if ($GLOBALS['app']->Session->Logged()) { $tpl->SetBlock('NoPermission/known'); $logoutLink = $this->gadget->urlMap('Logout'); $referLink = empty($_SERVER['HTTP_REFERER']) ? $GLOBALS['app']->getSiteURL('/') : Jaws_XSS::filter($_SERVER['HTTP_REFERER']); $tpl->SetVariable('known_description', _t('USERS_NO_PERMISSION_KNOWN_DESC', $logoutLink, $referLink)); $tpl->ParseBlock('NoPermission/known'); } else { $tpl->SetBlock('NoPermission/anon'); $loginLink = $this->gadget->urlMap('LoginBox', array('referrer' => bin2hex(Jaws_Utils::getRequestURL(false)))); $referLink = empty($_SERVER['HTTP_REFERER']) ? $GLOBALS['app']->getSiteURL('/') : Jaws_XSS::filter($_SERVER['HTTP_REFERER']); $tpl->SetVariable('anon_description', _t('USERS_NO_PERMISSION_ANON_DESC', $loginLink, $referLink)); $tpl->ParseBlock('NoPermission/anon'); } $tpl->ParseBlock('NoPermission'); return $tpl->Get(); }
/** * Install the gadget * * @access public * @param string $input_schema Schema file path * @param array $input_variables Schema variables * @return mixed True on success or Jaws_Error on failure */ function Install($input_schema = '', $input_variables = array()) { if (!Jaws_Utils::is_writable(JAWS_DATA)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', JAWS_DATA)); } $new_dir = JAWS_DATA . 'phoo' . DIRECTORY_SEPARATOR; if (!Jaws_Utils::mkdir($new_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir)); } $result = $this->installSchema('schema.xml'); if (Jaws_Error::IsError($result)) { return $result; } $result = $this->installSchema('insert.xml', null, 'schema.xml', true); if (Jaws_Error::IsError($result)) { return $result; } if (!empty($input_schema)) { $result = $this->installSchema($input_schema, $input_variables, 'schema.xml', true); if (Jaws_Error::IsError($result)) { return $result; } } // Install listener for update comment $this->gadget->event->insert('UpdateComment'); return true; }
/** * Builds the upgader page. * * @access public * @return string A block of valid XHTML to display an introduction and form. */ function Display() { $tpl = new Jaws_Template(false, false); $tpl->Load('display.html', 'stages/Introduction/templates'); $tpl->SetBlock('Introduction'); $tpl->SetVariable('welcome', _t('UPGRADE_INTRO_WELCOME')); $tpl->SetVariable('title_info', _t('UPGRADE_INTRO_UPGRADER')); $tpl->SetVariable('db_info', _t('UPGRADE_INTRO_DATABASE')); $tpl->SetVariable('ftp_info', _t('UPGRADE_INTRO_FTP')); $tpl->SetVariable('language', _t('GLOBAL_LANGUAGE')); $tpl->SetVariable('next', _t('GLOBAL_NEXT')); if (is_writable(JAWS_PATH . 'data/logs') && is_dir(JAWS_PATH . 'data/logs')) { $tpl->SetVariable('log_use', _t('UPGRADE_INTRO_LOG', 'data/logs/upgrade.txt')); $tpl->SetBlock('Introduction/logcheckbox'); $tpl->ParseBlock('Introduction/logcheckbox'); } else { $tpl->SetVariable('log_use', _t('UPGRADE_INTRO_LOG_ERROR', 'data/logs')); } $langs = Jaws_Utils::GetLanguagesList(); $selected_lang = isset($_SESSION['upgrade']['language']) ? $_SESSION['upgrade']['language'] : 'en'; foreach ($langs as $code => $fullname) { $tpl->SetBlock('Introduction/lang'); $tpl->SetVariable('selected', $code == $selected_lang ? 'selected="selected"' : ''); $tpl->SetVariable('code', $code); $tpl->SetVariable('fullname', $fullname); $tpl->ParseBlock('Introduction/lang'); } $tpl->ParseBlock('Introduction'); return $tpl->Get(); }
/** * Class constructor * * @access public * @param bool $loadFromTheme Try to load template from theme * @param bool $loadGlobalVariables Fetch and set global variables * @return void */ function Jaws_Template($loadFromTheme = false, $loadGlobalVariables = true) { $this->IdentifierRegExp = '[\\.[:digit:][:lower:]_-]+'; $this->BlockRegExp = '@<!--\\s+begin\\s+(' . $this->IdentifierRegExp . ')\\s+([^>]*)-->(.*)<!--\\s+end\\s+\\1\\s+-->@sim'; $this->VarsRegExp = '@{{\\s*(' . $this->IdentifierRegExp . ')\\s*}}@sim'; $this->IsBlockRegExp = '@##\\s*(' . $this->IdentifierRegExp . ')\\s*##@sim'; $namexp = '[[:digit:][:lower:]_]+'; $this->NewBlockRegExp = '@<!--\\s+begin\\s+(' . $namexp . ')\\s+' . '(?:if\\((!)?(' . $namexp . ')\\)\\s+|)' . '(?:loop\\((' . $namexp . ')\\)\\s+|)' . '-->(.*)<!--\\s+end\\s+\\1\\s+-->@sim'; $this->globalVariables['theme_url'] = ''; $this->globalVariables['.dir'] = _t('GLOBAL_LANG_DIRECTION') == 'rtl' ? '.rtl' : ''; $this->globalVariables['base_url'] = Jaws_Utils::getBaseURL('/'); $this->globalVariables['requested_url'] = Jaws_Utils::getRequestURL(); $this->globalVariables['base_script'] = BASE_SCRIPT; if ($loadGlobalVariables) { $this->loadFromTheme = $loadFromTheme; $this->theme = $GLOBALS['app']->GetTheme(); $layout = $GLOBALS['app']->Layout->GetLayoutName() . '/'; $this->layout = @is_dir($this->theme['path'] . $layout) ? $layout : ''; $browser = $GLOBALS['app']->GetBrowserFlag(); $this->globalVariables['theme_url'] = $this->theme['url']; $this->globalVariables['data_url'] = $GLOBALS['app']->getDataURL(); $this->globalVariables['.browser'] = empty($browser) ? '' : ".{$browser}"; $this->globalVariables['main_index'] = $GLOBALS['app']->mainIndex ? 'index' : ''; $this->globalVariables['main_gadget'] = strtolower($GLOBALS['app']->mainGadget); $this->globalVariables['main_action'] = strtolower($GLOBALS['app']->mainAction); } else { $this->loadFromTheme = false; } }
/** * Installs the gadget * * @access public * @return mixed True on successful installation, Jaws_Error otherwise */ function Install() { if (!Jaws_Utils::is_writable(JAWS_DATA)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', JAWS_DATA)); } $new_dir = JAWS_DATA . 'emblems' . DIRECTORY_SEPARATOR; if (!Jaws_Utils::mkdir($new_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir)); } $result = $this->installSchema('schema.xml'); if (Jaws_Error::IsError($result)) { return $result; } // If you are here, then copy the default jaws and feeds images $emblems = array('jaws', 'php', 'apache', 'mysql', 'pgsql', 'xhtml', 'css', 'atom', 'rss'); foreach ($emblems as $emblem) { copy(JAWS_PATH . "gadgets/Emblems/Resources/images/{$emblem}.png", $new_dir . "{$emblem}.png"); Jaws_Utils::chmod($new_dir . "{$emblem}.png"); } $variables = array(); $variables['timestamp'] = Jaws_DB::getInstance()->date(); // Dump database data $result = $this->installSchema('insert.xml', $variables, 'schema.xml', true); if (Jaws_Error::IsError($result)) { return $result; } return true; }
/** * */ function Get($email, $name) { $ap_dir = JAWS_DATA . 'cache' . DIRECTORY_SEPARATOR . 'addressprotector'; if (file_exists($ap_dir . DIRECTORY_SEPARATOR . md5($email . $name))) { $contents = file_get_contents($ap_dir . DIRECTORY_SEPARATOR . md5($email . $name)); $contents = '<a href="http://address-protector.com/' . $contents . '">' . $name . '</a>'; return $contents; } Jaws_Utils::mkdir($ap_dir); if (!is_dir($ap_dir) || !Jaws_Utils::is_writable($ap_dir) || !(bool) ini_get('allow_url_fopen')) { $contents = str_replace(array('@', '.'), array('(at)', 'dot'), $email); return $contents; } $url = "http://address-protector.com/?mode=textencrypt&name=<name>&email=<email>"; $url = str_replace('<name>', urlencode($name), $url); $url = str_replace('<email>', $email, $url); $contents = $this->getURL($url); if (empty($contents)) { $contents = str_replace(array('@', '.'), array('(at)', 'dot'), $email); } if (substr($contents, -1, 1) == "\n") { $contents = substr($contents, 0, -1); } file_put_contents($ap_dir . DIRECTORY_SEPARATOR . md5($email . $name), $contents); $contents = '<a href="http://address-protector.com/' . $contents . '">' . $name . '</a>'; return $contents; }
/** * Download post attachment * * @access public * @return string Requested file content or HTML error page */ function Attachment() { $rqst = jaws()->request->fetch(array('fid', 'tid', 'pid', 'attach'), 'get'); $pModel = $this->gadget->model->load('Posts'); $post = $pModel->GetPost($rqst['pid'], $rqst['tid'], $rqst['fid']); if (Jaws_Error::IsError($post)) { $this->SetActionMode('Attachment', 'normal', 'standalone'); return Jaws_HTTPError::Get(500); } $aModel = $this->gadget->model->load('Attachments'); $attachment = $aModel->GetAttachmentInfo($rqst['attach']); if (Jaws_Error::IsError($attachment)) { $this->SetActionMode('Attachment', 'normal', 'standalone'); return Jaws_HTTPError::Get(500); } if (!empty($attachment)) { $filepath = JAWS_DATA . 'forums/' . $attachment['filename']; if (file_exists($filepath)) { // increase download hits $result = $aModel->HitAttachmentDownload($rqst['attach']); if (Jaws_Error::IsError($result)) { // do nothing } if (Jaws_Utils::Download($filepath, $attachment['title'])) { return; } $this->SetActionMode('Attachment', 'normal', 'standalone'); return Jaws_HTTPError::Get(500); } } $this->SetActionMode('Attachment', 'normal', 'standalone'); return Jaws_HTTPError::Get(404); }
/** * Creates a .zip file of the theme in themes/ directory * * @access public * @param string $theme Name of the theme * @param string $srcDir Source directory * @param string $destDir Target directory * @param bool $copy_example_to_repository If copy example.png too or not * @return bool Returns true if: * - Theme exists * - Theme exists and could be packed * Returns false if: * - Theme doesn't exist * - Theme doesn't exists and couldn't be packed */ function packTheme($theme, $srcDir, $destDir, $copy_example_to_repository = true) { $themeSrc = $srcDir . '/' . $theme; if (!is_dir($themeSrc)) { return new Jaws_Error(_t('TMS_ERROR_THEME_DOES_NOT_EXISTS', $theme)); } if (!Jaws_Utils::is_writable($destDir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', $destDir), $this->gadget->name); } $themeDest = $destDir . '/' . $theme . '.zip'; //If file exists.. delete it if (file_exists($themeDest)) { @unlink($themeDest); } require_once PEAR_PATH . 'File/Archive.php'; $reader = File_Archive::read($themeSrc, $theme); $innerWriter = File_Archive::toFiles(); $writer = File_Archive::toArchive($themeDest, $innerWriter); $res = File_Archive::extract($reader, $writer); if (PEAR::isError($res)) { return new Jaws_Error(_t('TMS_ERROR_COULD_NOT_PACK_THEME')); } Jaws_Utils::chmod($themeDest); if ($copy_example_to_repository) { //Copy image to repository/images if (file_exists($srcDir . '/example.png')) { @copy($srcDir . '/example.png', JAWS_DATA . "themes/repository/Resources/images/{$theme}.png"); Jaws_Utils::chmod(JAWS_DATA . 'themes/repository/Resources/images/' . $theme . '.png'); } } return $themeDest; }
/** * Displays the emblems * * @access public * @return string XHTML UI */ function Display() { $tpl = $this->gadget->template->load('Emblems.html'); $tpl->SetBlock('emblems'); $tpl->SetVariable('title', _t('EMBLEMS_ACTION_TITLE')); $model = $this->gadget->model->load('Emblems'); $emblems = $model->GetEmblems(true); if (!Jaws_Error::IsError($emblems)) { $site = urlencode(Jaws_Utils::getBaseURL('/', false)); $page = urlencode(Jaws_Utils::getRequestURL(false)); $name = urlencode($this->gadget->registry->fetch('site_name', 'Settings')); $slogan = urlencode($this->gadget->registry->fetch('site_slogan', 'Settings')); $title = $GLOBALS['app']->Layout->GetTitle(); foreach ($emblems as $e) { $e['url'] = str_replace(array('{url}', '{base_url}', '{requested_url}', '{site_name}', '{site_slogan}', '{title}'), array($page, $site, $page, $name, $slogan, $title), $e['url']); $tpl->SetBlock('emblems/emblem'); $tpl->SetVariable('id', $e['id']); $tpl->SetVariable('title', _t('EMBLEMS_TYPE_' . $e['type'], $e['title'])); $tpl->SetVariable('image', $GLOBALS['app']->getDataURL('emblems/' . $e['image'])); $tpl->SetVariable('url', $e['url']); $tpl->ParseBlock('emblems/emblem'); } } $tpl->ParseBlock('emblems'); return $tpl->Get(); }
/** * Saves data into the file * * @access public * @param string $cache_file * @param string $data * @return mixed True on success and PEAR error on failure */ function saveFile($cache_file, $data) { if (!Jaws_Utils::file_put_contents($cache_file, serialize($data))) { return PEAR::raiseError("Fail to save stream with file_put_contents('{$cache_file}',...)."); } return true; }
/** * Event execute method * */ function Execute($shouter, $code) { $reqURL = Jaws_Utils::getRequestURL(true); $uModel = $this->gadget->model->loadAdmin('ErrorMaps'); $res = $uModel->GetHTTPError($reqURL, $code); if (!Jaws_Error::IsError($res) && !empty($res) && ($res['code'] == 301 || $res['code'] == 302)) { Jaws_Header::Location($res['url'], $res['code']); } return $res; }
/** * Updates user account information * * @access public * @return void */ function UpdateAccount() { if (!$GLOBALS['app']->Session->Logged()) { Jaws_Header::Location($this->gadget->urlMap('LoginBox', array('referrer' => bin2hex(Jaws_Utils::getRequestURL(true))))); } $this->gadget->CheckPermission('EditUserName,EditUserNickname,EditUserEmail,EditUserPassword', '', false); $post = jaws()->request->fetch(array('username', 'nickname', 'email', 'password', 'chkpassword'), 'post'); if ($post['password'] === $post['chkpassword']) { // check edit username permission if (empty($post['username']) || !$this->gadget->GetPermission('EditUserName')) { $post['username'] = $GLOBALS['app']->Session->GetAttribute('username'); } // check edit nickname permission if (empty($post['nickname']) || !$this->gadget->GetPermission('EditUserNickname')) { $post['nickname'] = $GLOBALS['app']->Session->GetAttribute('nickname'); } // check edit email permission if (empty($post['email']) || !$this->gadget->GetPermission('EditUserEmail')) { $post['email'] = $GLOBALS['app']->Session->GetAttribute('email'); } // set new email $post['new_email'] = ''; if ($post['email'] != $GLOBALS['app']->Session->GetAttribute('email')) { $post['new_email'] = $post['email']; $post['email'] = $GLOBALS['app']->Session->GetAttribute('email'); } // check edit password permission if (empty($post['password']) || !$this->gadget->GetPermission('EditUserPassword')) { $post['password'] = null; } $model = $this->gadget->model->load('Account'); $result = $model->UpdateAccount($GLOBALS['app']->Session->GetAttribute('user'), $post['username'], $post['nickname'], $post['email'], $post['new_email'], $post['password']); // unset unnecessary account data unset($post['password'], $post['chkpassword']); if (!Jaws_Error::IsError($result)) { $message = _t('USERS_MYACCOUNT_UPDATED'); if (!empty($post['new_email'])) { $mResult = $this->ReplaceEmailNotification($GLOBALS['app']->Session->GetAttribute('user'), $post['username'], $post['nickname'], $post['new_email'], $post['email']); if (Jaws_Error::IsError($mResult)) { $message = $message . "\n" . $mResult->getMessage(); } else { $message = $message . "\n" . _t('USERS_EMAIL_REPLACEMENT_SENT'); } } $GLOBALS['app']->Session->PushResponse($message, 'Users.Account.Response'); } else { $GLOBALS['app']->Session->PushResponse($result->GetMessage(), 'Users.Account.Response', RESPONSE_ERROR, $post); } } else { // unset unnecessary account data unset($post['password'], $post['chkpassword']); $GLOBALS['app']->Session->PushResponse(_t('USERS_USERS_PASSWORDS_DONT_MATCH'), 'Users.Account.Response', RESPONSE_ERROR, $post); } Jaws_Header::Location($this->gadget->urlMap('Account')); }
/** * Installs the gadget * * @access public * @return mixed True on successful installation, Jaws_Error otherwise */ function Install() { $result = $this->installSchema('schema.xml'); if (Jaws_Error::IsError($result)) { return $result; } $new_dir = JAWS_DATA . 'directory'; if (!Jaws_Utils::mkdir($new_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir)); } return true; }
/** * 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>"; }
/** * Install the gadget * * @access public * @return mixed True on successful installation, Jaws_Error otherwise */ function Install() { if (!Jaws_Utils::is_writable(JAWS_DATA)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', JAWS_DATA)); } $new_dir = JAWS_DATA . 'files' . DIRECTORY_SEPARATOR; if (!Jaws_Utils::mkdir($new_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir)); } $result = $this->installSchema('schema.xml'); if (Jaws_Error::IsError($result)) { return $result; } return true; }
/** * Builds the installer page. * * @access public * @return string A block of valid XHTML to display an introduction and form. */ function Display() { $tpl = new Jaws_Template(false, false); $tpl->Load('display.html', 'stages/Finished/templates'); $tpl->SetBlock('Finished'); $base_url = Jaws_Utils::getBaseURL('', true); $tpl->setVariable('lbl_info', _t('INSTALL_FINISH_INFO')); $tpl->setVariable('lbl_choices', _t('INSTALL_FINISH_CHOICES', "{$base_url}/", "{$base_url}/admin.php")); $tpl->setVariable('lbl_thanks', _t('INSTALL_FINISH_THANKS')); $tpl->SetVariable('move_log', _t('INSTALL_FINISH_MOVE_LOG')); $tpl->ParseBlock('Finished'); // Kill the session session_destroy(); return $tpl->Get(); }
/** * Installs the gadget * * @access public * @return mixed True on successful installation, Jaws_Error otherwise */ function Install() { if (!Jaws_Utils::is_writable(JAWS_DATA)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', JAWS_DATA)); } $theme_dir = JAWS_DATA . 'themes' . DIRECTORY_SEPARATOR; if (!Jaws_Utils::mkdir($theme_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $theme_dir)); } //Ok, maybe user has data/themes dir but is not writable, Tms requires that dir to be writable if (!Jaws_Utils::is_writable(JAWS_DATA . 'themes')) { return new Jaws_Error(_t('TMS_ERROR_DESTINATION_THEMES_NOT_WRITABLE')); } return true; }
/** * Creates a directory * * @access public * @param string $path Where to create it * @param string $dir_name Which name * @return bool Returns true if the directory was created, if not, returns false */ function MakeDir($path, $dir_name) { $path = trim($path, '/'); $path = str_replace('..', '', $path); $fModel = $this->gadget->model->load('Files'); $dir = $fModel->GetFileBrowserRootDir() . $path . '/' . $dir_name; require_once PEAR_PATH . 'File/Util.php'; $realpath = File_Util::realpath($dir); $blackList = explode(',', $this->gadget->registry->fetch('black_list')); $blackList = array_map('strtolower', $blackList); if (!File_Util::pathInRoot($realpath, $fModel->GetFileBrowserRootDir()) || in_array(strtolower(basename($realpath)), $blackList) || !Jaws_Utils::mkdir($realpath)) { $GLOBALS['app']->Session->PushLastResponse(_t('FILEBROWSER_ERROR_CANT_CREATE_DIRECTORY', $realpath), RESPONSE_ERROR); return false; } return true; }
/** * * @access public * @return string HTML content with menu and menu items */ function LoadUserInfo() { $uid = (int) jaws()->request->fetch('uid'); $uModel = new Jaws_User(); $userInfo = $uModel->GetUser($uid, true, true); $userInfo['avatar_file_name'] = ''; if (empty($userInfo['avatar'])) { $userInfo['avatar'] = $GLOBALS['app']->getSiteURL('/gadgets/AddressBook/Resources/images/photo128px.png'); } else { $userAvatar = $GLOBALS['app']->getDataURL() . 'avatar/' . $userInfo['avatar']; copy($userAvatar, Jaws_Utils::upload_tmp_dir() . '/' . $userInfo['avatar']); $userInfo['avatar_file_name'] = $userInfo['avatar']; $userInfo['avatar'] = $GLOBALS['app']->getDataURL() . 'avatar/' . $userInfo['avatar']; } return $userInfo; }
/** * Upgrades the gadget * * @access public * @param string $old Current version (in registry) * @param string $new New version (in the $gadgetInfo file) * @return mixed True on Success or Jaws_Error on Failure */ function Upgrade($old, $new) { if (!Jaws_Utils::is_writable(JAWS_DATA)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', JAWS_DATA)); } $new_dir = JAWS_DATA . 'languages' . DIRECTORY_SEPARATOR; if (!Jaws_Utils::mkdir($new_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir)); } // Registry keys $this->gadget->registry->delete('use_data_lang'); $this->gadget->registry->insert('update_default_lang', 'false'); // ACL keys $this->gadget->acl->insert('ModifyLanguageProperties'); return true; }
/** * Installs the gadget * * @access public * @return mixed True on success and Jaws_Error on failure */ function Install() { if (!Jaws_Utils::is_writable(JAWS_DATA)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', JAWS_DATA)); } $new_dir = JAWS_DATA . 'sitemap' . DIRECTORY_SEPARATOR; if (!Jaws_Utils::mkdir($new_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir)); } $result = $this->installSchema('schema.xml'); if (Jaws_Error::IsError($result)) { return $result; } $this->gadget->registry->update('robots.txt', @file_get_contents(JAWS_PATH . 'gadgets/Sitemap/Resources/robots.txt')); return true; }
/** * Export language * * @access public * @return void */ function Export() { $lang = jaws()->request->fetch('lang', 'get'); require_once PEAR_PATH . 'File/Archive.php'; $tmpDir = sys_get_temp_dir(); $tmpFileName = "{$lang}.tar"; $tmpArchiveName = $tmpDir . DIRECTORY_SEPARATOR . $tmpFileName; $writerObj = File_Archive::toFiles(); $src = File_Archive::read(JAWS_DATA . "languages/{$lang}", $lang); $dst = File_Archive::toArchive($tmpArchiveName, $writerObj); $res = File_Archive::extract($src, $dst); if (!PEAR::isError($res)) { return Jaws_Utils::Download($tmpArchiveName, $tmpFileName); } Jaws_Header::Referrer(); }
/** * Installs the gadget * * @access public * @return mixed True on successful installation, Jaws_Error otherwise */ function Install() { $result = $this->installSchema('schema.xml'); if (Jaws_Error::IsError($result)) { return $result; } $new_dir = JAWS_DATA . 'pm'; if (!Jaws_Utils::mkdir($new_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir)); } $new_dir = JAWS_DATA . 'pm' . DIRECTORY_SEPARATOR . 'attachments'; if (!Jaws_Utils::mkdir($new_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir)); } $this->gadget->event->insert('Notify'); return true; }
/** * Get user's preferences of this gadget * * @access public * @return array Formatted array for using in Users Preferences action */ function Execute() { $result = array(); $languages = Jaws_Utils::GetLanguagesList(); $objSettings = $this->gadget->model->loadAdmin('Settings'); $objComponents = Jaws_Gadget::getInstance('Components')->model->load('Gadgets'); $gadgets = $objComponents->GetGadgetsList(null, true, true, null, true); $gadgets = array_column(array_values($gadgets), 'title', 'name'); array_unshift($gadgets, _t('GLOBAL_NOGADGET')); $result['admin_language'] = array('title' => _t('SETTINGS_ADMIN_LANGUAGE'), 'values' => $languages, 'ltr' => true); $result['site_language'] = array('title' => _t('SETTINGS_DEFAULT_SITE_LANGUAGE'), 'values' => $languages, 'ltr' => true); $result['calendar'] = array('title' => _t('SETTINGS_CALENDAR'), 'values' => $objSettings->GetCalendarList()); $result['date_format'] = array('title' => _t('SETTINGS_DATE_FORMAT'), 'values' => $objSettings->GetDateFormatList()); $result['main_gadget'] = array('title' => _t('SETTINGS_MAIN_GADGET'), 'values' => $gadgets); $result['editor'] = array('title' => _t('SETTINGS_EDITOR'), 'values' => $objSettings->GetEditorList()); $result['timezone'] = array('title' => _t('GLOBAL_TIMEZONE'), 'values' => $objSettings->GetTimeZonesList(), 'ltr' => true); return $result; }
/** * Returns avatar as stream data * * @access public * @return bool True on success, false otherwise */ function LoadAvatar() { $file = jaws()->request->fetch('file', 'get'); $objImage = Jaws_Image::factory(); if (!Jaws_Error::IsError($objImage)) { if (!empty($file)) { $file = preg_replace("/[^[:alnum:]_\\.\\-]*/i", "", $file); $result = $objImage->load(Jaws_Utils::upload_tmp_dir() . '/' . $file, true); if (!Jaws_Error::IsError($result)) { $result = $objImage->display(); if (!Jaws_Error::IsError($result)) { return $result; } } } } return false; }
/** * Deletes the emblem * * @access public * @return array Response array (notice or error) */ function DeleteEmblem() { @(list($id) = jaws()->request->fetchAll('post')); $model = $this->gadget->model->load('Emblems'); $emblem = $model->GetEmblem($id); $model = $this->gadget->model->loadAdmin('Emblems'); $res = $model->DeleteEmblem($id); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR); return new Jaws_Error($res->getMessage()); } // delete the file if (!empty($emblem['image'])) { Jaws_Utils::Delete(JAWS_DATA . 'emblems/' . $emblem['image']); } $GLOBALS['app']->Session->PushLastResponse(_t('EMBLEMS_DELETED'), RESPONSE_NOTICE); return $GLOBALS['app']->Session->PopLastResponse(); }
/** * Displays or writes a RDF feed for the link group * * @access public * @return string xml with RDF feed on display mode, nothing otherwise */ function RSS() { header('Content-type: application/rss+xml'); $gid = jaws()->request->fetch('id', 'get'); $rss_path = JAWS_DATA . 'xml/link-' . $gid . '.rss'; if (file_exists($rss_path)) { ///FIXME we need to do more error checking over here $rss = @file_get_contents($rss_path); return $rss; } $rss = $this->GenerateFeed($gid); if (Jaws_Error::IsError($rss)) { return ''; } ///FIXME we need to do more error checking over here @file_put_contents($rss_path, $rss); Jaws_Utils::chmod($rss_path); return $rss; }