/** * 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; }
/** * Does any actions required to finish the stage, such as DB queries. * * @access public * @return bool|Jaws_Error Either true on success, or a Jaws_Error * containing the reason for failure. */ function Run() { //config string $configString = $this->BuildConfig(); $configMD5 = md5($configString); $existsConfig = @file_get_contents(JAWS_PATH . 'config/JawsConfig.php'); $existsMD5 = md5($existsConfig); if ($configMD5 !== $existsMD5) { if (!Jaws_Utils::is_writable(JAWS_PATH . 'config/')) { return Jaws_Error::raiseError(_t('UPGRADE_CONFIG_RESPONSE_MAKE_CONFIG', 'JawsConfig.php'), __FUNCTION__, JAWS_ERROR_WARNING); } // create/overwrite a new one if the dir is writeable $result = @file_put_contents(JAWS_PATH . 'config/JawsConfig.php', $configString); if ($result === false) { return Jaws_Error::raiseError(_t('UPGRADE_CONFIG_RESPONSE_WRITE_FAILED'), __FUNCTION__, JAWS_ERROR_WARNING); } } // Connect to database require_once JAWS_PATH . 'include/Jaws/DB.php'; $objDatabase = Jaws_DB::getInstance('default', $_SESSION['upgrade']['Database']); if (Jaws_Error::IsError($objDatabase)) { _log(JAWS_LOG_DEBUG, "There was a problem connecting to the database, please check the details and try again"); return new Jaws_Error(_t('UPGRADE_DB_RESPONSE_CONNECT_FAILED'), 0, JAWS_ERROR_WARNING); } // Create application include_once JAWS_PATH . 'include/Jaws.php'; $GLOBALS['app'] = jaws(); $GLOBALS['app']->Registry->Init(); _log(JAWS_LOG_DEBUG, "Setting " . JAWS_VERSION . " as the current installed version"); $GLOBALS['app']->Registry->update('version', JAWS_VERSION); //remove cache directory $path = JAWS_DATA . 'cache'; if (!Jaws_Utils::delete($path)) { _log(JAWS_LOG_DEBUG, "Can't delete {$path}"); } _log(JAWS_LOG_DEBUG, "Configuration file has been created/updated"); return true; }
/** * Delete an album and all its images * * @access public * @param int $id ID of the album * @return mixed Returns true if album was deleted without problems, Jaws_Error if not. */ function DeleteAlbum($id) { // Delete files // We do it this way because we don't want to use subqueries(some versions of mysql don't support it) $table = Jaws_ORM::getInstance()->table('phoo_image_album'); $table->select('phoo_image_id'); $table->where('phoo_album_id', $id); $result = $table->fetchAll(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_ERROR_ALBUM_NOT_DELETED'), RESPONSE_ERROR); return new Jaws_Error(_t('PHOO_ERROR_ALBUM_NOT_DELETED')); } if (!empty($result)) { $imgList = array(); foreach ($result as $i) { $imgList[] = $i['phoo_image_id']; } $table = Jaws_ORM::getInstance()->table('phoo_image'); $table->select('id', 'user_id', 'filename', 'phoo_album_id'); $table->join('phoo_image_album', 'id', 'phoo_image_id'); if (!empty($imgList)) { $table->where('id', $imgList, 'in'); } $table->groupBy('id', 'user_id', 'filename', 'phoo_album_id'); $table->having('count(phoo_image_id)', 1); $result = $table->fetchAll(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_ERROR_ALBUM_NOT_DELETED'), RESPONSE_ERROR); return new Jaws_Error(_t('PHOO_ERROR_ALBUM_NOT_DELETED')); } include_once JAWS_PATH . 'include/Jaws/Image.php'; foreach ($result as $r) { if (!empty($r['filename'])) { Jaws_Utils::delete(JAWS_DATA . 'phoo/' . $r['filename']); Jaws_Utils::delete(JAWS_DATA . 'phoo/' . $this->GetMediumPath($r['filename'])); Jaws_Utils::delete(JAWS_DATA . 'phoo/' . $this->GetThumbPath($r['filename'])); } } // Delete images from phoo_image if (!empty($imgList)) { $table = Jaws_ORM::getInstance()->table('phoo_image'); $table->delete()->where('id', $imgList, 'in'); $result = $table->exec(); } if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_ERROR_ALBUM_NOT_DELETED'), RESPONSE_ERROR); return new Jaws_Error(_t('PHOO_ERROR_ALBUM_NOT_DELETED')); } // Delete images from phoo_image_album $table = Jaws_ORM::getInstance()->table('phoo_image_album'); $table->delete()->where('phoo_album_id', $id); $result = $table->exec(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_ERROR_ALBUM_NOT_DELETED'), RESPONSE_ERROR); return new Jaws_Error(_t('PHOO_ERROR_ALBUM_NOT_DELETED')); } } // Delete album from phoo_album $table = Jaws_ORM::getInstance()->table('phoo_album'); $table->delete()->where('id', $id); $result = $table->exec(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_ERROR_ALBUM_NOT_DELETED'), RESPONSE_ERROR); return new Jaws_Error(_t('PHOO_ERROR_ALBUM_NOT_DELETED')); } $GLOBALS['app']->Session->PushLastResponse(_t('PHOO_ALBUM_DELETED'), RESPONSE_NOTICE); return true; }
/** * Adds a new emblem * * @access public * @see EmblemsModel->AddEmblem() */ function AddEmblem() { $post = jaws()->request->fetch(array('title', 'url', 'type', 'published'), 'post'); $post['url'] = Jaws_XSS::defilter($post['url']); $res = Jaws_Utils::UploadFiles($_FILES, JAWS_DATA . 'emblems/', 'jpg,gif,swf,png,jpeg,bmp,svg'); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse($res->getMessage(), RESPONSE_ERROR); } elseif (empty($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('EMBLEMS_ERROR_NO_IMAGE_UPLOADED'), RESPONSE_ERROR); } else { $post['image'] = $res['image'][0]['host_filename']; $post['published'] = (bool) $post['published']; $model = $this->gadget->model->loadAdmin('Emblems'); $res = $model->AddEmblem($post); if (Jaws_Error::IsError($res)) { Jaws_Utils::delete(JAWS_DATA . 'emblems/' . $post['image']); $GLOBALS['app']->Session->PushLastResponse(_t('EMBLEMS_ERROR_NOT_ADDED'), RESPONSE_ERROR); } else { $GLOBALS['app']->Session->PushLastResponse(_t('EMBLEMS_ADDED'), RESPONSE_NOTICE); } } Jaws_Header::Location(BASE_SCRIPT . '?gadget=Emblems'); }
/** * Delete directories and files * * @access public * @param string $path File/Directory path * @param bool $dirs_include * @param bool $self_include * @return bool Returns TRUE on success or FALSE on failure * @see http://www.php.net/rmdir & http://www.php.net/unlink */ static function delete($path, $dirs_include = true, $self_include = true) { if (!file_exists($path)) { return true; } if (is_file($path) || is_link($path)) { // unlink can't delete read-only files in windows os if (JAWS_OS_WIN) { @chmod($path, 0777); } return @unlink($path); } if (false !== ($files = @scandir($path))) { foreach ($files as $file) { if ($file == '.' || $file == '..') { continue; } if (!Jaws_Utils::delete($path . DIRECTORY_SEPARATOR . $file, $dirs_include)) { return false; } } } if ($dirs_include && $self_include) { return @rmdir($path); } return true; }
/** * Deletes file/directory * * @access public * @param int $id File ID * @return mixed Query result */ function Delete($data) { if ($data['is_dir']) { $files = $this->GetFiles(array('parent' => $data['id'])); if (Jaws_Error::IsError($files)) { return false; } foreach ($files as $file) { $this->Delete($file); } } // Delete file/folder and related shortcuts $table = Jaws_ORM::getInstance()->table('directory'); $table->delete()->where('id', $data['id']); $res = $table->exec(); if (Jaws_Error::IsError($res)) { return false; } // Delete from disk if (!$data['is_dir']) { $filename = JAWS_DATA . 'directory/' . $data['host_filename']; if (file_exists($filename)) { if (!Jaws_Utils::delete($filename)) { return false; } } } return true; }
/** * Delete the theme * * @access public * @param string $theme * @returns boolean */ function DeleteTheme($theme) { $this->gadget->CheckPermission('DeleteTheme'); @(list($theme, $locality) = explode(',', $theme)); $tInfo = Jaws_Utils::GetThemesInfo($locality, $theme); if (!empty($tInfo) && $locality == 0) { // get default theme $defaultTheme = unserialize($GLOBALS['app']->Registry->fetch('theme', 'Settings')); // Check is default theme? if ($defaultTheme['locality'] != 0 || $theme != $defaultTheme['name']) { return Jaws_Utils::delete(JAWS_THEMES . $theme); } } return false; }
/** * Uninstalls the plugin * * @access public * @return bool True */ function Uninstall() { Jaws_Utils::delete(JAWS_DATA . 'AlbumCover' . DIRECTORY_SEPARATOR); 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; }
/** * 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; }
/** * Deletes file/directory * * @access public * @param int $id File ID * @return mixed Query result */ function Delete($data) { if ($data['is_dir']) { $files = $this->GetFiles($data['id'], $data['user']); if (Jaws_Error::IsError($files)) { return false; } foreach ($files as $file) { $this->Delete($file); } } // Delete file/folder and related shortcuts $table = Jaws_ORM::getInstance()->table('directory'); $table->delete()->where('id', $data['id']); $table->or()->where('reference', $data['id']); $res = $table->exec(); if (Jaws_Error::IsError($res)) { return false; } // Delete from disk if (!$data['is_dir']) { $filename = $GLOBALS['app']->getDataURL('directory/' . $data['user'] . '/' . $data['filename']); if (file_exists($filename)) { if (!Jaws_Utils::delete($filename)) { return false; } } } return true; }