/** * 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; }
/** * 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; }
/** * Installs the plugin * * @access public * @return mixed True on success and Jaws_Error on failure */ function Install() { $new_dir = JAWS_DATA . 'AlbumCover' . DIRECTORY_SEPARATOR; if (!Jaws_Utils::mkdir($new_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir), $this->_Name); } // Registry key $GLOBALS['app']->Registry->insert('devtag', 'MY DEV TAG', false, 'AlbumCover'); return true; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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 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; }
/** * 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 . $this->gadget->DataDirectory; 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', '', 'schema.xml', true); if (Jaws_Error::IsError($result)) { return $result; } //registry keys. return true; }
/** * Installs the gadget * * @access public * @return mixed True on successful installation, Jaws_Error otherwise */ function Install() { $variables = array(); $variables['logon_hours'] = str_pad('', 42, 'F'); $result = $this->installSchema('schema.xml', $variables); if (Jaws_Error::IsError($result)) { return $result; } $new_dir = JAWS_DATA . 'avatar'; if (!Jaws_Utils::mkdir($new_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir)); } // Create the group 'users' $userModel = new Jaws_User(); $result = $userModel->AddGroup(array('name' => 'users', 'title' => 'Users', 'description' => '', 'enabled' => true, 'removable' => false)); if (Jaws_Error::IsError($result) && MDB2_ERROR_CONSTRAINT != $result->getCode()) { return $result; } return true; }
/** * 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()) { $new_dir = JAWS_DATA . 'xml' . 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', '', '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; } } return true; }
/** * 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, Jaws_Error otherwise */ function Upgrade($old, $new) { if (version_compare($old, '0.9.0', '<')) { $result = $this->installSchema('schema.xml', '', '0.8.0.xml'); if (Jaws_Error::IsError($result)) { return $result; } $new_feed_dir = JAWS_DATA . 'feedcache' . DIRECTORY_SEPARATOR; $old_feed_dir = JAWS_DATA . 'rsscache' . DIRECTORY_SEPARATOR; if (!Jaws_Utils::mkdir($new_feed_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_feed_dir)); } Jaws_Utils::delete($old_feed_dir); // ACL keys $this->gadget->acl->delete('ManageRSSSite'); // Update layout actions $layoutModel = Jaws_Gadget::getInstance('Layout')->model->loadAdmin('Layout'); if (!Jaws_Error::isError($layoutModel)) { $layoutModel->EditGadgetLayoutAction('FeedReader', 'Display', 'DisplayFeeds', 'Feed'); } } return true; }
/** * Recursive copy * * Copies a file to another location or a complete directory * * @access public * @param string $source File source * @param string $dest Destination path * @return bool Returns TRUE on success, FALSE on failure */ function FullCopy($source, $dest) { // Simple copy for a file if (is_file($source)) { return copy($source, $dest); } // Make destination directory Jaws_Utils::mkdir($dest); // Loop through the folder $dir = @dir($source); while (false !== ($entry = $dir->read())) { // Skip pointers if ($entry == '.' || $entry == '..') { continue; } // Deep copy directories if ($dest !== $source . '/' . $entry) { Jaws_FileManagement::FullCopy($source . '/' . $entry, $dest . '/' . $entry); } } // Clean up $dir->close(); return true; }
/** * Generates Alexa Rank Html display Fragment * * @access public * @return string html fragment */ function AlexaSiteRank() { $cache_dir = JAWS_DATA . 'launcher' . DIRECTORY_SEPARATOR; if (!Jaws_Utils::mkdir($cache_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $cache_dir), __FUNCTION__); } $url = $GLOBALS['app']->GetSiteURL('/'); $file = $cache_dir . 'alexarank_' . md5($url); $timedif = time() - (file_exists($file) ? @filemtime($file) : 0); $objAlexaRank = new AlexaRank(); if ($timedif < 43200) { // a half day //cache file is fresh $ranks = $objAlexaRank->loadFile($file); } else { $ranks = $objAlexaRank->getRank($url); $objAlexaRank->saveFile($file, $ranks); } unset($objAlexaRank); $result = ''; foreach ($ranks as $key => $rank) { $result .= "<div><label>{$key}:</label> <span>{$rank}</span></div>"; } return "<div class=\"gadget launcher alexarank\">{$result}</div>"; }
/** * Insert New AddressBook Data to DB * * @access public * @returns array of Address Books or Jaws_Error on error */ function UpdateAddress($id, $data) { $data['public'] = (bool) $data['public']; $data['updatetime'] = time(); $targetDir = JAWS_DATA . 'addressbook' . DIRECTORY_SEPARATOR; if (array_key_exists('image', $data)) { // get address information $adr = $this->GetAddressInfo((int) $id); if (Jaws_Error::IsError($adr) || empty($adr)) { return false; } if (!empty($adr['image'])) { Jaws_Utils::Delete($targetDir . 'image' . DIRECTORY_SEPARATOR . $adr['image']); } if (!empty($data['image'])) { $fileinfo = pathinfo($data['image']); if (isset($fileinfo['extension']) && !empty($fileinfo['extension'])) { if (!in_array($fileinfo['extension'], array('gif', 'jpg', 'jpeg', 'png'))) { return false; } else { if (!is_dir($targetDir)) { Jaws_Utils::mkdir($targetDir); } $targetDir = $targetDir . 'image' . DIRECTORY_SEPARATOR; if (!is_dir($targetDir)) { Jaws_Utils::mkdir($targetDir); } $new_image = $adr['id'] . '.' . $fileinfo['extension']; rename(Jaws_Utils::upload_tmp_dir() . '/' . $data['image'], $targetDir . $new_image); $data['image'] = $new_image; } } } } $adrTable = Jaws_ORM::getInstance()->table('address_book'); return $adrTable->update($data)->where('id', (int) $id)->exec(); }
/** * Updates file * * @access public * @return array Response array */ function UpdateFile() { try { // Validate data $data = jaws()->request->fetch(array('id', 'title', 'description', 'parent', 'url', 'filename', 'filetype', 'filesize')); if (empty($data['title'])) { throw new Exception(_t('DIRECTORY_ERROR_INCOMPLETE_DATA')); } $data['title'] = Jaws_XSS::defilter($data['title']); $data['description'] = Jaws_XSS::defilter($data['description']); $model = $this->gadget->model->load('Files'); // Validate file $id = (int) $data['id']; $file = $model->GetFile($id); if (Jaws_Error::IsError($file)) { throw new Exception($file->getMessage()); } // Validate user $user = (int) $GLOBALS['app']->Session->GetAttribute('user'); if ($file['user'] != $user) { throw new Exception(_t('DIRECTORY_ERROR_FILE_UPDATE')); } // Upload file if ($file['user'] != $file['owner']) { // is shortcut unset($data['parent'], $data['url'], $data['filename']); unset($data['filetype'], $data['filesize']); } else { $path = $GLOBALS['app']->getDataURL('directory/' . $user); if (!is_dir($path)) { if (!Jaws_Utils::mkdir($path, 2)) { throw new Exception('DIRECTORY_ERROR_FILE_UPLOAD'); } } $res = Jaws_Utils::UploadFiles($_FILES, $path); if (Jaws_Error::IsError($res)) { throw new Exception($res->getMessage()); } else { if ($res !== false) { $data['filename'] = $res['file'][0]['host_filename']; $data['filetype'] = $res['file'][0]['host_filetype']; $data['filesize'] = $res['file'][0]['host_filesize']; } else { if ($data['filename'] === ':nochange:') { unset($data['filename']); } else { if (empty($data['filename'])) { throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD')); } else { $filename = Jaws_Utils::upload_tmp_dir() . '/' . $data['filename']; if (file_exists($filename)) { $target = $path . '/' . $data['filename']; $res = Jaws_Utils::rename($filename, $target, false); if ($res === false) { throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD')); } $data['filename'] = basename($res); } else { throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD')); } } } } } } // Update file in database $data['updatetime'] = time(); $model = $this->gadget->model->load('Files'); $res = $model->Update($id, $data); if (Jaws_Error::IsError($res)) { throw new Exception(_t('DIRECTORY_ERROR_FILE_UPDATE')); } // Update shortcuts if ($file['shared']) { $shortcut = array(); $shortcut['url'] = $data['url']; $shortcut['filename'] = $data['filename']; $shortcut['filetype'] = $data['filetype']; $shortcut['filesize'] = $data['filesize']; $shortcut['updatetime'] = $data['updatetime']; $model->UpdateShortcuts($id, $shortcut); } } catch (Exception $e) { return $GLOBALS['app']->Session->GetResponse($e->getMessage(), RESPONSE_ERROR); } return $GLOBALS['app']->Session->GetResponse(_t('DIRECTORY_NOTICE_FILE_UPDATED'), RESPONSE_NOTICE); }
/** * Extract archive Files * * @access public * @param array $files $_FILES array * @param string $dest Destination directory(include end directory separator) * @param bool $extractToDir Create separate directory for extracted files * @param bool $overwrite Overwrite directory if exist * @param int $max_size Max size of file * @return bool Returns TRUE on success or FALSE on failure */ static function ExtractFiles($files, $dest, $extractToDir = true, $overwrite = true, $max_size = null) { if (empty($files) || !is_array($files)) { return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD'), __FUNCTION__); } if (isset($files['name'])) { $files = array($files); } require_once PEAR_PATH . 'File/Archive.php'; foreach ($files as $key => $file) { if (isset($file['error']) && !empty($file['error']) || !isset($file['name'])) { return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_' . $file['error']), __FUNCTION__); } if (empty($file['tmp_name'])) { continue; } $ext = strrchr($file['name'], '.'); $filename = substr($file['name'], 0, -strlen($ext)); if (false !== stristr($filename, '.tar')) { $filename = substr($filename, 0, strrpos($filename, '.')); switch ($ext) { case '.gz': $ext = '.tgz'; break; case '.bz2': case '.bzip2': $ext = '.tbz'; break; default: $ext = '.tar' . $ext; } } $ext = strtolower(substr($ext, 1)); if (!File_Archive::isKnownExtension($ext)) { return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_INVALID_FORMAT', $file['name']), __FUNCTION__); } if ($extractToDir) { $dest = $dest . $filename; } if ($extractToDir && !Jaws_Utils::mkdir($dest)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $dest), __FUNCTION__); } if (!Jaws_Utils::is_writable($dest)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', $dest), __FUNCTION__); } $archive = File_Archive::readArchive($ext, $file['tmp_name']); if (PEAR::isError($archive)) { return new Jaws_Error($archive->getMessage(), __FUNCTION__); } $writer = File_Archive::_convertToWriter($dest); $result = $archive->extract($writer); if (PEAR::isError($result)) { return new Jaws_Error($result->getMessage(), __FUNCTION__); } //@unlink($file['tmp_name']); } return true; }
/** * 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, Jaws_Error on Failure */ function Upgrade($old, $new) { if (version_compare($old, '1.0.0', '<')) { $result = $this->installSchema('1.0.0.xml', '', '0.9.0.xml'); if (Jaws_Error::IsError($result)) { return $result; } // set dynamic ACLs of categories $catModel = $this->gadget->model->load('Categories'); $categories = $catModel->GetCategories(false); foreach ($categories as $category) { $this->gadget->acl->insert('CategoryAccess', $category['id'], true); $this->gadget->acl->insert('CategoryManage', $category['id'], true); } // filling categories filed $blogTable = Jaws_ORM::getInstance()->table('blog'); $blogTable->select('blog.id:integer', 'blog_entrycat.category_id'); $blogTable->join('blog_entrycat', 'blog.id', 'blog_entrycat.entry_id'); $result = $blogTable->orderBy('blog.id desc')->fetchAll(); if (Jaws_Error::IsError($result)) { return $result; } $posts = array(); foreach ($result as $post) { $posts[$post['id']] = (isset($posts[$post['id']]) ? $posts[$post['id']] . ',' : '') . $post['category_id']; } // update categories filed $blogTable = Jaws_ORM::getInstance()->table('blog'); foreach ($posts as $id => $categories) { $blogTable->update(array('categories' => $categories))->where('id', (int) $id)->exec(); } } if (version_compare($old, '1.1.0', '<')) { $result = $this->installSchema('schema.xml', '', '1.0.0.xml'); if (Jaws_Error::IsError($result)) { return $result; } } if (version_compare($old, '1.2.0', '<')) { $this->gadget->registry->delete('comment_status'); $this->gadget->registry->insert('recommended', ',Comments,Tags,'); $new_dir = JAWS_DATA . 'blog' . DIRECTORY_SEPARATOR . 'images'; if (!Jaws_Utils::mkdir($new_dir, 1)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir)); } } return true; }
/** * Sync sitemap data files * * @access public * @param string $gadget Gadget name * @return mixed Array of Tag info or Jaws_Error on failure */ function SyncSitemapData($gadget) { $objGadget = Jaws_Gadget::getInstance($gadget); if (Jaws_Error::IsError($objGadget)) { return ''; } $objHook = $objGadget->hook->load('Sitemap'); if (Jaws_Error::IsError($objHook)) { return ''; } $result[$gadget] = array(); $gResult = $objHook->Execute(1); if (Jaws_Error::IsError($gResult) || empty($gResult)) { return ''; } // Check gadget directory in sitemap $gadget_dir = JAWS_DATA . 'sitemap/' . strtolower($gadget); if (!Jaws_Utils::mkdir($gadget_dir, 1)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $gadget_dir)); } $cache_file = $gadget_dir . '/sitemap.bin'; if (!Jaws_Utils::file_put_contents($cache_file, serialize($gResult))) { return false; } return true; }
/** * Send message * * @access public * @param integer $user User id * @param array $messageData Message data * @return mixed Message Id or Jaws_Error on failure */ function SendMessage($user, $messageData) { $table = Jaws_ORM::getInstance(); // merge recipient users & groups to an array $recipient_users = array(); if (trim($messageData['recipient_users']) == '0' || !empty($messageData['recipient_users'])) { if (trim($messageData['recipient_users']) == '0') { $table = $table->table('users'); $recipient_users = $table->select('id:integer')->fetchColumn(); } else { $recipient_users = explode(",", $messageData['recipient_users']); } } if (!empty($messageData['recipient_groups'])) { $recipient_groups = explode(",", $messageData['recipient_groups']); $table = $table->table('users_groups'); $table->select('user_id:integer'); $table->join('groups', 'groups.id', 'users_groups.group_id'); $table->where('group_id', $recipient_groups, 'in'); $group_users = $table->and()->where('groups.owner', $user)->fetchColumn(); if (!empty($group_users) && count($group_users) > 0) { $recipient_users = array_merge($recipient_users, $group_users); } } $recipient_users = array_unique($recipient_users); // validation input fields if (empty($messageData['subject']) || $messageData['folder'] != PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_DRAFT && (empty($recipient_users) || count($recipient_users) <= 0)) { return Jaws_Error::raiseError(_t('PRIVATEMESSAGE_MESSAGE_INCOMPLETE_FIELDS'), __FUNCTION__, JAWS_ERROR_NOTICE); } $mTable = $table->table('pm_messages'); //Start Transaction $mTable->beginTransaction(); $messageIds = array(); $data = array(); $data['folder'] = $messageData['folder']; $data['subject'] = $messageData['subject']; $data['body'] = $messageData['body']; $data['attachments'] = isset($messageData['attachments']) ? count($messageData['attachments']) : 0; $data['recipient_users'] = $messageData['recipient_users']; $data['recipient_groups'] = isset($messageData['recipient_groups']) ? $messageData['recipient_groups'] : null; $data['update_time'] = time(); // Detect notification, draft or publish? $is_notification = $messageData['folder'] == PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_NOTIFICATIONS; if ($messageData['folder'] == PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_DRAFT) { if (empty($messageData['id'])) { // save new draft message $data['from'] = $user; $data['to'] = 0; $data['read'] = true; $data['insert_time'] = time(); $senderMessageId = $mTable->insert($data)->exec(); } else { // update old message info $senderMessageId = $messageData['id']; $mTable->update($data)->where('id', $senderMessageId)->exec(); } } else { // First insert a message in sender's outbox if (empty($messageData['id'])) { // new message if ($is_notification) { $senderMessageId = 0; } else { $data['folder'] = PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_OUTBOX; $data['from'] = $user; $data['to'] = 0; $data['read'] = true; $data['insert_time'] = time(); $senderMessageId = $mTable->insert($data)->exec(); } } else { // update message $mTable->update($data)->where('id', $messageData['id'])->exec(); $senderMessageId = $messageData['id']; } // Insert message for every recipient if (!empty($recipient_users) && count($recipient_users) > 0) { $table = $table->table('pm_messages'); $from = $is_notification ? 0 : $user; $data['folder'] = $messageData['folder']; foreach ($recipient_users as $recipient_user) { $data['insert_time'] = time(); $data['from'] = $from; $data['to'] = $recipient_user; $data['read'] = false; $messageId = $table->insert($data)->exec(); if (Jaws_Error::IsError($messageId)) { //Rollback Transaction $table->rollback(); return false; } $messageIds[] = $messageId; // send notification on new private message if (!$is_notification) { $params = array(); $params['key'] = crc32('PrivateMessage' . $senderMessageId); $params['title'] = _t('PRIVATEMESSAGE_NEW_MESSAGE_NOTIFICATION_TITLE'); $params['summary'] = _t('PRIVATEMESSAGE_NEW_MESSAGE_NOTIFICATION'); $params['description'] = _t('PRIVATEMESSAGE_NEW_MESSAGE_NOTIFICATION_DESC', $data['subject']); $params['user'] = (int) $recipient_user; $this->gadget->event->shout('Notify', $params); } } } } // Insert attachments info if (!empty($messageData['attachments']) && count($messageData['attachments']) > 0) { $maData = array(); $pm_dir = JAWS_DATA . 'pm' . DIRECTORY_SEPARATOR . 'attachments' . DIRECTORY_SEPARATOR; foreach ($messageData['attachments'] as $attachment) { // check new attachments file -- we must copy tmp files to correct location if (is_array($attachment)) { $src_filepath = Jaws_Utils::upload_tmp_dir() . '/' . $attachment['filename']; $dest_filepath = $pm_dir . $attachment['filename']; if (!file_exists($src_filepath)) { continue; } if (!file_exists($pm_dir)) { if (!Jaws_Utils::mkdir($pm_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', JAWS_DATA)); } } $cres = Jaws_Utils::rename($src_filepath, $dest_filepath); Jaws_Utils::delete($src_filepath); if ($cres) { $aData = array('title' => $attachment['title'], 'filename' => $attachment['filename'], 'filesize' => $attachment['filesize'], 'filetype' => $attachment['filetype']); $table = $table->table('pm_attachments'); $attachmentId = $table->insert($aData)->exec(); if (Jaws_Error::IsError($attachmentId)) { //Rollback Transaction $table->rollback(); return false; } // Add sender message Id to pm_message_attachment table $maData[] = array('message' => $senderMessageId, 'attachment' => $attachmentId); // Add recipient message Id to pm_message_attachment table foreach ($messageIds as $messageId) { $maData[] = array('message' => $messageId, 'attachment' => $attachmentId); } } } else { // Add sender message Id to pm_message_attachment table $maData[] = array('message' => $senderMessageId, 'attachment' => $attachment); // Add recipient message Id to pm_message_attachment table foreach ($messageIds as $messageId) { $maData[] = array('message' => $messageId, 'attachment' => $attachment); } } } if (!empty($maData) && count($maData) > 0) { $table = $table->table('pm_message_attachment'); $res = $table->insertAll(array('message', 'attachment'), $maData)->exec(); if (Jaws_Error::IsError($res)) { //Rollback Transaction $table->rollback(); return false; } } else { //Rollback Transaction $table->rollback(); return false; } } //Commit Transaction $mTable->commit(); return $senderMessageId; }
/** * Generates Google Rank Html display Fragment * * @access public * @return string html fragment */ function GooglePageRank() { $cache_dir = JAWS_DATA . 'launcher' . DIRECTORY_SEPARATOR; if (!Jaws_Utils::mkdir($cache_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $cache_dir), __FUNCTION__); } $url = $GLOBALS['app']->GetSiteURL('/'); $file = $cache_dir . 'rank_' . md5($url); $timedif = time() - (file_exists($file) ? @filemtime($file) : 0); $gRank = new PageRank(); if ($timedif < 604800) { // a week //cache file is fresh $rank = $gRank->loadFile($file); } else { $rank = $gRank->GetRank($url); $gRank->saveFile($file, $rank); } unset($gRank); $theme = $GLOBALS['app']->GetTheme(); if (is_dir($theme['path'] . 'PageRank')) { $pg_images = $theme['url'] . 'PageRank/'; } else { $pg_images = $GLOBALS['app']->getSiteURL('/gadgets/Launcher/Resources/images/PageRank/', true); } return "<img src='{$pg_images}pr{$rank}.gif' alt='{$rank}' />"; }
/** * Updates file * * @access public * @return array Response array */ function UpdateFile() { try { // Validate data $data = jaws()->request->fetch(array('id', 'title', 'description', 'parent', 'hidden', 'user_filename', 'host_filename', 'filetype', 'filesize')); if (empty($data['title'])) { throw new Exception(_t('DIRECTORY_ERROR_INCOMPLETE_DATA')); } $data['title'] = Jaws_XSS::defilter($data['title']); $data['description'] = Jaws_XSS::defilter($data['description']); $model = $this->gadget->model->loadAdmin('Files'); // Validate file $id = (int) $data['id']; $file = $model->GetFile($id); if (Jaws_Error::IsError($file)) { throw new Exception($file->getMessage()); } // Upload file $path = $GLOBALS['app']->getDataURL('directory'); if (!is_dir($path)) { if (!Jaws_Utils::mkdir($path, 2)) { throw new Exception('DIRECTORY_ERROR_FILE_UPLOAD'); } } $res = Jaws_Utils::UploadFiles($_FILES, $path, '', null); if (Jaws_Error::IsError($res)) { throw new Exception($res->getMessage()); } else { if ($res !== false) { $data['host_filename'] = $res['file'][0]['host_filename']; $data['user_filename'] = $res['file'][0]['user_filename']; $data['filetype'] = $res['file'][0]['host_filetype']; $data['filesize'] = $res['file'][0]['host_filesize']; } else { if ($data['host_filename'] === ':nochange:') { unset($data['host_filename']); } else { if (empty($data['host_filename'])) { throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD')); } else { $filename = Jaws_Utils::upload_tmp_dir() . '/' . $data['host_filename']; if (file_exists($filename)) { $target = $path . '/' . $data['host_filename']; $res = Jaws_Utils::rename($filename, $target, false); if ($res === false) { throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD')); } $data['host_filename'] = basename($res); } else { throw new Exception(_t('DIRECTORY_ERROR_FILE_UPLOAD')); } } } } } // Update file in database unset($data['user']); $data['updatetime'] = time(); $data['hidden'] = $data['hidden'] ? true : false; $model = $this->gadget->model->loadAdmin('Files'); $res = $model->Update($id, $data); if (Jaws_Error::IsError($res)) { throw new Exception(_t('DIRECTORY_ERROR_FILE_UPDATE')); } // Update Tags if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $tags = jaws()->request->fetch('tags'); $tModel = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags'); $tModel->UpdateReferenceTags('Directory', 'file', $id, !$data['hidden'], time(), $tags); } } catch (Exception $e) { return $GLOBALS['app']->Session->GetResponse($e->getMessage(), RESPONSE_ERROR); } return $GLOBALS['app']->Session->GetResponse(_t('DIRECTORY_NOTICE_FILE_UPDATED'), RESPONSE_NOTICE); }
/** * Save language data into file * * @access public * @param string $module * @param string $type * @param string $langTo * @param array $data * @return bool True on Success or False on failure */ function SetLangData($module, $type, $langTo, $data = null) { $module_name = $module; switch ($type) { case JAWS_COMPONENT_GADGET: if ($langTo == 'en') { $orig_file = JAWS_PATH . "gadgets/{$module}/Resources/translates.ini"; } else { $orig_file = JAWS_PATH . "languages/{$langTo}/gadgets/{$module}.ini"; } $data_file = JAWS_DATA . "languages/{$langTo}/gadgets/{$module}.ini"; break; case JAWS_COMPONENT_PLUGIN: if ($langTo == 'en') { $orig_file = JAWS_PATH . "plugins/{$module}/Resources/translates.ini"; } else { $orig_file = JAWS_PATH . "languages/{$langTo}/plugins/{$module}.ini"; } $data_file = JAWS_DATA . "languages/{$langTo}/plugins/{$module}.ini"; $from_file = JAWS_PATH . "plugins/{$module}/Resources/translates.ini"; $module_name = 'Plugins_' . $module; break; case JAWS_COMPONENT_INSTALL: if ($langTo == 'en') { $orig_file = JAWS_PATH . "install/Resources/translates.ini"; } else { $orig_file = JAWS_PATH . "languages/{$langTo}/Install.ini"; } $data_file = JAWS_DATA . "languages/{$langTo}/Install.ini"; break; case JAWS_COMPONENT_UPGRADE: if ($langTo == 'en') { $orig_file = JAWS_PATH . "upgrade/Resources/translates.ini"; } else { $orig_file = JAWS_PATH . "languages/{$langTo}/Upgrade.ini"; } $data_file = JAWS_DATA . "languages/{$langTo}/Upgrade.ini"; break; default: if ($langTo == 'en') { $orig_file = JAWS_PATH . "include/Jaws/Resources/translates.ini"; } else { $orig_file = JAWS_PATH . "languages/{$langTo}/Global.ini"; } $data_file = JAWS_DATA . "languages/{$langTo}/Global.ini"; } $update_default_lang = $this->gadget->registry->fetch('update_default_lang') == 'true'; $strings = array(); if (file_exists($orig_file)) { $strings = parse_ini_file($orig_file, false, INI_SCANNER_RAW); } // user translation $tpl = $this->gadget->template->loadAdmin('FileTemplate.html'); $tpl->SetBlock('template'); $tpl->SetVariable('project', $module_name); $tpl->SetVariable('language', strtoupper($langTo)); // orig translation $tpl2 = $this->gadget->template->loadAdmin('FileTemplate.html'); $tpl2->SetBlock('template'); $tpl2->SetVariable('project', $module_name); $tpl2->SetVariable('language', strtoupper($langTo)); // Meta foreach ($data['meta'] as $k => $v) { // user translation $tpl->SetBlock('template/meta'); $tpl->SetVariable('key', $k); $tpl->SetVariable('value', $v); $tpl->ParseBlock('template/meta'); // orig translation $tpl2->SetBlock('template/meta'); $tpl2->SetVariable('key', $k); $tpl2->SetVariable('value', $v); $tpl2->ParseBlock('template/meta'); } // Strings $change_detected = false; foreach ($data['strings'] as $k => $v) { if ($v == '') { continue; } elseif ($v === $this->_EMPTY_STRING) { $v = ''; } $v = preg_replace("\$\r\n|\n\$", '\\n', $v); $changed = !isset($strings[$k]) || $strings[$k] !== $v; if ($changed) { $change_detected = true; $tpl->SetBlock('template/string'); $tpl->SetVariable('key', $k); $tpl->SetVariable('value', $v); $tpl->ParseBlock('template/string'); } // orig translation $tpl2->SetBlock('template/string'); $tpl2->SetVariable('key', $k); $tpl2->SetVariable('value', $v); $tpl2->ParseBlock('template/string'); } $tpl->ParseBlock('template'); $tpl2->ParseBlock('template'); // update original translation if ($update_default_lang) { // update default language translation, // so we can delete customized language's file if (Jaws_Utils::file_put_contents($orig_file, $tpl2->Get())) { $change_detected = false; } } // Writable if (file_exists($data_file)) { $writeable = Jaws_Utils::is_writable($data_file); } else { Jaws_Utils::mkdir(dirname($data_file), 3); $writeable = Jaws_Utils::is_writable(dirname($data_file)); } if (!$writeable) { $GLOBALS['app']->Session->PushLastResponse(_t('LANGUAGES_NOT_PERMISSION'), RESPONSE_ERROR); return false; } if ($change_detected) { if (Jaws_Utils::file_put_contents($data_file, $tpl->Get())) { $GLOBALS['app']->Session->PushLastResponse(_t('LANGUAGES_UPDATED', $module), RESPONSE_NOTICE); return true; } else { $GLOBALS['app']->Session->PushLastResponse(_t('LANGUAGES_NOT_UPDATED', $module), RESPONSE_ERROR); return false; } } else { Jaws_Utils::Delete($data_file); $GLOBALS['app']->Session->PushLastResponse(_t('LANGUAGES_UPDATED', $module), RESPONSE_NOTICE); return true; } }
/** * Add a new entry * * @access public * @param string $user User who is adding the photo * @param array $files info like original name, tmp name and size * @param string $title Title of the image * @param string $description Description of the image * @param bool $fromControlPanel Is it called from ControlPanel? * @param array $album Array containing the required info about the album * @return mixed Returns the ID of the new entry and Jaws_Error on error */ function NewEntry($user, $files, $title, $description, $fromControlPanel = true, $album) { // check if it's really a uploaded file. /*if (is_uploaded_file($files['tmp_name'])) { $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_ERROR_CANT_UPLOAD_PHOTO'), RESPONSE_ERROR); return new Jaws_Error(_t('PHOO_ERROR_CANT_UPLOAD_PHOTO')); }*/ if (!preg_match("/\\.png\$|\\.jpg\$|\\.jpeg\$|\\.gif\$/i", $files['name'])) { $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_ERROR_CANT_UPLOAD_PHOTO_EXT'), RESPONSE_ERROR); return new Jaws_Error(_t('PHOO_ERROR_CANT_UPLOAD_PHOTO_EXT')); } // Create directories $uploaddir = JAWS_DATA . 'phoo/' . date('Y_m_d') . '/'; if (!is_dir($uploaddir)) { if (!Jaws_Utils::is_writable(JAWS_DATA . 'phoo/')) { $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_ERROR_CANT_UPLOAD_PHOTO'), RESPONSE_ERROR); return new Jaws_Error(_t('PHOO_ERROR_CANT_UPLOAD_PHOTO')); } $new_dirs = array(); $new_dirs[] = $uploaddir; $new_dirs[] = $uploaddir . 'thumb'; $new_dirs[] = $uploaddir . 'medium'; foreach ($new_dirs as $new_dir) { if (!Jaws_Utils::mkdir($new_dir)) { $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_ERROR_CANT_UPLOAD_PHOTO'), RESPONSE_ERROR); return new Jaws_Error(_t('PHOO_ERROR_CANT_UPLOAD_PHOTO')); } } } $filename = $files['name']; if (file_exists($uploaddir . $files['name'])) { $filename = time() . '_' . $files['name']; } $res = Jaws_Utils::UploadFiles($files, $uploaddir, 'jpg,gif,png,jpeg', false, !$fromControlPanel); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse($res->getMessage(), RESPONSE_ERROR); return new Jaws_Error($res->getMessage()); } elseif (empty($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_UPLOAD_4'), RESPONSE_ERROR); return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_4')); } $filename = $res[0][0]['host_filename']; $uploadfile = $uploaddir . $filename; // Resize Image include_once JAWS_PATH . 'include/Jaws/Image.php'; $objImage = Jaws_Image::factory(); if (Jaws_Error::IsError($objImage)) { return Jaws_Error::raiseError($objImage->getMessage()); } $thumbSize = explode('x', $this->gadget->registry->fetch('thumbsize')); $mediumSize = explode('x', $this->gadget->registry->fetch('mediumsize')); $objImage->load($uploadfile); $objImage->resize($thumbSize[0], $thumbSize[1]); $res = $objImage->save($this->GetThumbPath($uploadfile)); $objImage->free(); if (Jaws_Error::IsError($res)) { // Return an error if image can't be resized $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_ERROR_CANT_RESIZE_TO_THUMB'), RESPONSE_ERROR); return new Jaws_Error($res->getMessage()); } $objImage->load($uploadfile); $objImage->resize($mediumSize[0], $mediumSize[1]); $res = $objImage->save($this->GetMediumPath($uploadfile)); $objImage->free(); if (Jaws_Error::IsError($res)) { // Return an error if image can't be resized $GLOBALS['app']->Session->PushLastResponse($res->getMessage(), RESPONSE_ERROR); return new Jaws_Error(_t('PHOO_ERROR_CANT_RESIZE_TO_MEDIUM')); } $data = array(); $data['user_id'] = $user; $data['filename'] = date('Y_m_d') . '/' . $filename; $data['title'] = $title; $data['description'] = $description; if ($this->gadget->registry->fetch('allow_comments') === 'true' && $album['allow_comments']) { $data['allow_comments'] = true; } else { $data['allow_comments'] = false; } if ($this->gadget->registry->fetch('published') === 'true' && $this->gadget->GetPermission('ManageAlbums')) { $data['published'] = true; } else { $data['published'] = false; } $jDate = Jaws_Date::getInstance(); $createtime = Jaws_DB::getInstance()->date(); if (function_exists('exif_read_data') && preg_match("/\\.jpg\$|\\.jpeg\$/i", $files['name']) && ($exifData = @exif_read_data($uploadfile, 1, true)) && !empty($exifData['IFD0']['DateTime']) && $jDate->ValidDBDate($exifData['IFD0']['DateTime'])) { $aux = explode(' ', $exifData['IFD0']['DateTime']); $auxdate = str_replace(':', '-', $aux[0]); $auxtime = $aux[1]; $createtime = $auxdate . ' ' . $auxtime; } $data['createtime'] = $createtime; $table = Jaws_ORM::getInstance()->table('phoo_image'); $result = $table->insert($data)->exec(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_ERROR_CANT_UPLOAD_PHOTO'), RESPONSE_ERROR); return new Jaws_Error(_t('PHOO_ERROR_CANT_UPLOAD_PHOTO')); } // Lets remove the original if keep_original = false if ($this->gadget->registry->fetch('keep_original') == 'false') { if (!empty($data['filename'])) { Jaws_Utils::delete(JAWS_DATA . 'phoo/' . $data['filename']); } } // shout SiteActivity event $saParams = array(); $saParams['action'] = 'Photo'; $this->gadget->event->shout('SiteActivity', $saParams); $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_PHOTO_ADDED'), RESPONSE_NOTICE); return $result; }