function getSearch() { $query_string = isset(Request::$get_normal['q']) ? trim(Request::$get_normal['q']) : false; $search = Search::getInstance(); /* @var $search Search */ $cond = new Conditions(); $per_page = 0; if (isset($this->params['per_page'])) { $per_page = (int) $this->params['per_page']; } $per_page = $per_page > 0 ? $per_page : 5; $cond->setPaging(1000, $per_page); $offset = $cond->getMongoLimit(); list($sids, $count, $hl) = $search->searchMagazinesByString($query_string, $offset, $per_page); $cond = new Conditions(); $cond->setPaging($count, $per_page); if ($count) { $query = 'SELECT * FROM `magazines` WHERE `id` IN(' . implode(',', $sids) . ')'; $series = Database::sql2array($query); $this->data['magazines'] = $series; } else { $this->data['magazines'] = array(); } $this->data['conditions'] = $cond->getConditions(); foreach ($this->data['magazines'] as &$m) { if (isset($hl[$m['id']])) { $m['path'] = Config::need('www_path') . '/m/' . $m['id'] . '#hl=' . implode(' ', $hl[$m['id']]); } else { $m['path'] = Config::need('www_path') . '/m/' . $m['id'] . '#hl=' . Request::$get_normal['q']; } } $this->data['magazines']['title'] = 'Журналы по запросу «' . $query_string . '»'; $this->data['magazines']['count'] = $count; }
/** * Blocks functions * * @copyright XOOPS Project (http://xoops.org) * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) * @author Laurent JEN (aka DuGris) * @package system * @version $Id$ */ function b_search_show() { $search = Search::getInstance(); $search->loadLanguage('main', 'search'); $form = new Xoops\Form\SimpleForm('', 'search', $search->url('index.php'), 'get', false, 'inline'); // create form elements $form->addElement(new Xoops\Form\Text('', 'query', 2, 100, '', _MD_SEARCH_KEYWORDS), true); $form->addElement(new Xoops\Form\Hidden('action', 'results')); $form->addElement(new Xoops\Form\Token('id')); $button = new Xoops\Form\Button('', 'submit', _MD_SEARCH, 'submit'); $button->setClass('btn btn-primary'); $form->addElement($button); $block['form'] = $form->render(); return $block; }
public function getSearchFrom($andor, $queries, $mids, $mid) { $xoops = Xoops::getInstance(); $search = Search::getInstance(); // create form parent::__construct(_MD_SEARCH, 'search', 'index.php', 'get'); // create form elements $this->addElement(new Xoops\Form\Text(_MD_SEARCH_KEYWORDS, 'query', 30, 255, htmlspecialchars(stripslashes($this->queryArrayToString($queries)), ENT_QUOTES)), true); $type_select = new Xoops\Form\Select(_MD_SEARCH_TYPE, 'andor', $andor); $type_select->addOptionArray(array('AND' => _MD_SEARCH_ALL, 'OR' => _MD_SEARCH_ANY)); $this->addElement($type_select); if (!empty($mids)) { $mods_checkbox = new Xoops\Form\Checkbox(_MD_SEARCH_SEARCHIN, 'mids[]', $mids); } else { $mods_checkbox = new Xoops\Form\Checkbox(_MD_SEARCH_SEARCHIN, 'mids[]', $mid); } if (empty($modules)) { $gperm_handler = $xoops->getHandlerGroupperm(); $available_modules = $gperm_handler->getItemIds('module_read', $xoops->getUserGroups()); $available_plugins = \Xoops\Module\Plugin::getPlugins('search'); //todo, would be nice to have the module ids availabe also $criteria = new CriteriaCompo(); $criteria->add(new Criteria('dirname', "('" . implode("','", array_keys($available_plugins)) . "')", 'IN')); if (isset($available_modules) && !empty($available_modules)) { $criteria->add(new Criteria('mid', '(' . implode(',', $available_modules) . ')', 'IN')); } $module_handler = $xoops->getHandlerModule(); $mods_checkbox->addOptionArray($module_handler->getNameList($criteria)); } else { /* @var $module XoopsModule */ $module_array = array(); foreach ($modules as $mid => $module) { $module_array[$mid] = $module->getVar('name'); } $mods_checkbox->addOptionArray($module_array); } $this->addElement($mods_checkbox); if ($search->getConfig('keyword_min') > 0) { $this->addElement(new Xoops\Form\Label(_MD_SEARCH_SEARCHRULE, sprintf(_MD_SEARCH_KEYIGNORE, $search->getConfig('keyword_min')))); } $this->addElement(new Xoops\Form\Hidden('action', 'results')); $this->addElement(new Xoops\Form\Token('id')); $this->addElement(new Xoops\Form\Button('', 'submit', _MD_SEARCH, 'submit')); return $this; }
function search() { global $current_user; $result = array(); //$this->ca(); $string = trim($_POST['s']); if ($string) { if ($this->cache_time && ($result = Cache::get('autocomp_' . $string))) { $this->data['cached'] = true; } else { $result = Search::getInstance()->searchAutoComplete($string); if ($this->cache_time) { Cache::set('autocomp_' . $string, $result, $this->cache_time); } $this->data['cached'] = false; } } $this->data['result'] = $result; $this->data['success'] = 1; }
function del_relation() { global $current_user; $this->ca(); $id1 = isset($_POST['id']) ? (int) $_POST['id'] : false; $id2 = isset($_POST['item_id']) ? (int) $_POST['item_id'] : false; if (!$id1 || !$id2) { throw new Exception('id or item_id missed'); } if (PersonRelations::delRelation($id1, $id2)) { $this->data['success'] = 1; $this->data['item_id'] = $id2; $search = Search::getInstance(); /* @var $search Search */ $search->setAuthorToFullUpdate($id1); $search->setAuthorToFullUpdate($id2); } else { $this->data['success'] = 0; $this->data['error'] = 'ошибочка:' . PersonRelations::getLastError(); } }
*/ use Xoops\Core\Request; use Xoops\Core\Kernel\Handlers\XoopsUser; /** * XOOPS global search * * @copyright XOOPS Project (http://xoops.org) * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) * @package core * @since 2.0.0 * @author Kazumi Ono (AKA onokazu) * @author Taiwen Jiang <*****@*****.**> * @version $Id$ */ include dirname(dirname(__DIR__)) . '/mainfile.php'; $search = Search::getInstance(); if (!$search->getConfig('enable_search')) { header('Location: ' . XOOPS_URL . '/index.php'); exit; } $xoops = Xoops::getInstance(); $action = Request::getCmd('action', 'search'); $query = Request::getString('query', ''); $andor = Request::getWord('andor', 'AND'); $mid = Request::getInt('mid', 0); $uid = Request::getInt('uid', 0); $start = Request::getInt('start', 0); $mids = Request::getArray('mids', array()); $queries = array(); if ($action === "results") { if ($query == "") {
function del_author() { global $current_user; $this->ca(); $id_person = (int) $_POST['item_id']; $id_book = (int) $_POST['id']; $query = 'SELECT `person_role` FROM `book_persons` WHERE `id_book`=' . $id_book . ' AND `id_person`=' . $id_person; $old_role = Database::sql2single($query); if ($old_role) { if ($id_person && $id_book) { $query = 'DELETE FROM `book_persons` WHERE `id_book`=' . $id_book . ' AND `id_person`=' . $id_person; Database::query($query); $this->data['success'] = 1; $this->data['item_id'] = $id_person; BookLog::addLog(array('id_person' => 0, 'person_role' => 0), array('id_person' => $id_person, 'person_role' => $old_role), $id_book); BookLog::saveLog($id_book, BookLog::TargetType_book, $current_user->id, BiberLog::BiberLogType_bookEditPerson); $search = Search::getInstance(); /* @var $search Search */ $search->updateBook(new Book($id_book)); return; } } else { $this->data['error'] = 'Нет такого автора'; } $this->data['item_id'] = $id_person; $this->data['success'] = 0; }
function write() { global $current_user; if (!$current_user->authorized) { throw new Exception('Access Denied'); } $id = isset(Request::$post['id']) ? (int) Request::$post['id'] : false; if (!$id) { $this->_new(); return; } $magazine = new Magazine($id); $magazine->load(); Request::$post['lang_code'] = Config::$langs[Request::$post['lang_code']]; $fields = array('title' => 'title', 'isbn' => 'ISBN', 'lang_code' => 'id_lang', 'annotation' => 'annotation'); $to_update = array(); if (isset($_FILES['cover']) && $_FILES['cover']['tmp_name']) { $folder = Config::need('static_path') . '/upload/mcovers/' . ceil($magazine->id / 5000); @mkdir($folder); chmod($folder, 755); $filename = $folder . '/' . $magazine->id . '.jpg'; $upload = new UploadAvatar($_FILES['cover']['tmp_name'], 100, 100, "simple", $filename); if ($upload->out) { $to_update['is_cover'] = 1; } else { throw new Exception('cant copy file to ' . $filename, 100); } } foreach ($fields as $field => $magazinefield) { if (!isset(Request::$post[$field])) { throw new Exception('field missed #' . $field); } if ($magazine->data[$magazinefield] !== Request::$post[$field]) { $to_update[$magazinefield] = Request::$post[$field]; } } $q = array(); foreach ($to_update as $field => &$value) { if (in_array($field, array('ISBN', 'year'))) { $value = is_numeric($value) ? $value : 0; } $q[] = '`' . $field . '`=' . Database::escape($value) . ''; } if (count($q)) { $query = 'UPDATE `magazines` SET ' . implode(',', $q) . ' WHERE `id`=' . $magazine->id; Database::query($query); MagazineLog::addLog($to_update, $magazine->data, $magazine->id); MagazineLog::saveLog($magazine->id, BookLog::TargetType_magazine, $current_user->id, BiberLog::BiberLogType_magazineEdit); $search = Search::getInstance(); /* @var $search Search */ $search->setMagazineToFullUpdate($magazine->id); } ob_end_clean(); header('Location:' . Config::need('www_path') . '/m/' . $magazine->id); exit; }
function getSearch() { $query_string = isset(Request::$get_normal['q']) ? trim(Request::$get_normal['q']) : false; $search = Search::getInstance(); /* @var $search Search */ $cond = new Conditions(); $per_page = 0; if (isset($this->params['per_page'])) { $per_page = (int) $this->params['per_page']; } $per_page = $per_page > 0 ? $per_page : 5; $cond->setPaging(1000, $per_page); $offset = $cond->getMongoLimit(); list($aids, $count, $hl) = $search->searchAuthorsByString($query_string, $offset, $per_page); $cond = new Conditions(); $cond->setPaging($count, $per_page); $this->data = $this->_idsToData($aids); $this->data['conditions'] = $cond->getConditions(); foreach ($this->data['authors'] as &$a) { if (isset($hl[$a['id']])) { $a['path'] .= '#hl=' . implode(' ', $hl[$a['id']]); } else { $a['path'] .= '#hl=' . Request::$get_normal['q']; } } $this->data['authors']['title'] = 'Авторы по запросу «' . $query_string . '»'; $this->data['authors']['count'] = $count; }
function write() { global $current_user; $current_user->can_throw('books_edit'); $id = isset(Request::$post['id']) ? (int) Request::$post['id'] : false; if (!$id) { $this->newAuthor(); return; } $person = Persons::getInstance()->getByIdLoaded($id); if (!$person) { return; } $savedData = $person->data; /* @var $book Book */ $fields = array('lang_code' => 'author_lang', 'bio' => 'bio', 'first_name' => 'first_name', 'middle_name' => 'middle_name', 'last_name' => 'last_name', 'homepage' => 'homepage', 'wiki_url' => 'wiki_url', 'date_birth' => 'date_birth', 'date_death' => 'date_death'); if (!Request::$post['first_name'] || !Request::$post['last_name']) { throw new Exception('no author\'s name'); } if (!Request::$post['lang_code']) { throw new Exception('no author\'s language'); } Request::$post['lang_code'] = Config::$langs[Request::$post['lang_code']]; $to_update = array(); if (isset($_FILES['picture']) && $_FILES['picture']['tmp_name']) { $folder = Config::need('static_path') . '/upload/authors/' . ceil($person->id / 5000); @mkdir($folder); // inserting new cover $query = 'INSERT INTO `person_covers` SET `id_person`=' . $person->id; Database::query($query); $cover_id = Database::lastInsertId(); // generating file names $filename_normal = $folder . '/default_' . $person->id . '_' . $cover_id . '.jpg'; $filename_small = $folder . '/small_' . $person->id . '_' . $cover_id . '.jpg'; $filename_big = $folder . '/big_' . $person->id . '_' . $cover_id . '.jpg'; $filename_orig = $folder . '/orig_' . $person->id . '_' . $cover_id . '.jpg'; $to_update['has_cover'] = $cover_id; $thumb = new Thumb(); $thumb->createThumbnails($_FILES['picture']['tmp_name'], array($filename_small, $filename_normal, $filename_big, $filename_orig), self::$cover_sizes); if ($savedData['has_cover']) { $current_user->gainActionPoints('authors_add_cover', $person->id, BiberLog::TargetType_person); } else { $current_user->gainActionPoints('authors_edit_cover', $person->id, BiberLog::TargetType_person); } } foreach ($fields as $field => $personfield) { if (!isset(Request::$post[$field])) { throw new Exception('field missed #' . $field); } if ($person->data[$personfield] != Request::$post[$field]) { $to_update[$personfield] = Request::$post[$field]; } } $q = array(); if (count($to_update)) { $to_update['authorlastSave'] = time(); } foreach ($to_update as $field => &$value) { if ($field == 'date_birth' || $field == 'date_death') { $value = getDateFromString($value); } if ($field == 'bio') { list($full, $short) = $person->processBio($value); $q[] = '`bio`=' . Database::escape($full) . ''; $q[] = '`short_bio`=' . Database::escape($short) . ''; $value = $person->data['bio'] = $full; $person->data['short_bio'] = $short; } else { $q[] = '`' . $field . '`=' . Database::escape($value) . ''; $person->data[$field] = $value; } } if (count($q)) { $query = 'UPDATE `persons` SET ' . implode(',', $q) . ' WHERE `id`=' . $person->id; Database::query($query); unset($to_update['authorlastSave']); PersonLog::addLog($to_update, $savedData, $person->id); PersonLog::saveLog($person->id, BiberLog::TargetType_person, $current_user->id, BiberLog::BiberLogType_personEdit); Persons::getInstance()->dropCache($person->id); $current_user->gainActionPoints(BiberLog::$actionTypes[BiberLog::BiberLogType_personEdit], $person->id, BiberLog::TargetType_person); $search = Search::getInstance(); /* @var $search Search */ $search->setAuthorToFullUpdate($person->id); } ob_end_clean(); header('Location:' . Config::need('www_path') . '/a/' . $person->id); exit; }
public function alumni_getSearchFrom($andor, $queries, $mids, $mid, $bycat) { $xoops = Xoops::getInstance(); $alumni = Alumni::getInstance(); // create form parent::__construct(XoopsLocale::SEARCH, 'alumni', 'search.php', 'get'); // create form elements $this->addElement(new XoopsFormText(XoopsLocale::KEYWORDS, 'query', 30, 255, htmlspecialchars(stripslashes(implode(' ', $queries)), ENT_QUOTES)), true); $type_select = new XoopsFormSelect(XoopsLocale::TYPE, 'andor', $andor); $type_select->addOptionArray(array('AND' => XoopsLocale::ALL_AND, 'OR' => XoopsLocale::ANY_OR, 'exact' => XoopsLocale::EXACT_MATCH)); $this->addElement($type_select); $by_cat = Request::getInt('by_cat', 0); $categoriesHandler = $xoops->getModuleHandler('category', 'alumni'); $search = Search::getInstance(); $module_id = $xoops->module->getVar('mid'); $groups = $xoops->isUser() ? $xoops->user->getGroups() : '3'; $alumni_ids = $alumni->getGrouppermHandler()->getItemIds('alumni_view', $groups, $module_id); $criteria = new CriteriaCompo(); $criteria->add(new Criteria('cid', '(' . implode(', ', $alumni_ids) . ')', 'IN')); $criteria->setOrder($xoops->getModuleConfig('alumni_csortorder')); $category_arr = $categoriesHandler->getall($criteria); foreach (array_keys($category_arr) as $i) { $cid = $category_arr[$i]->getVar('cid'); $pid = $category_arr[$i]->getVar('pid'); $title = $category_arr[$i]->getVar('title'); } $categories = $alumni->getCategoryHandler()->getCategoriesForSearch(); $category_select = new XoopsFormSelect(AlumniLocale::L_ALUMNI_CATEGORIES, 'by_cat', $by_cat); foreach ($categories as $cid => $title) { $category_select->addOption('0', XoopsLocale::ALL); $category_select->addOptionArray(array($cid => $title)); } $this->addElement($category_select); if (!empty($mids)) { $mods_checkbox = new XoopsFormCheckBox(XoopsLocale::SEARCH_IN, 'mids[]', $mids); } else { $mods_checkbox = new XoopsFormCheckBox(XoopsLocale::SEARCH_IN, 'mids[]', $mid); } if (empty($modules)) { $gperm_handler = $xoops->getHandlerGroupPermission(); $available_modules = $gperm_handler->getItemIds('module_read', $xoops->getUserGroups()); $available_plugins = Xoops\Module\Plugin::getPlugins('search'); $criteria = new CriteriaCompo(); $criteria->add(new Criteria('dirname', '(\'' . implode('\',\'', array_keys($available_plugins)) . '\')', 'IN')); if (isset($available_modules) && !empty($available_modules)) { $criteria->add(new Criteria('mid', '(' . implode(',', $available_modules) . ')', 'IN')); } $module_handler = $xoops->getHandlerModule(); $mods_checkbox->addOptionArray($module_handler->getNameList($criteria)); } else { /* @var $module XoopsModule */ $module_array = array(); foreach ($modules as $mid => $module) { $module_array[$mid] = $module->getVar('name'); } $mods_checkbox->addOptionArray($module_array); } $this->addElement($mods_checkbox); if ($search->getConfig('keyword_min') > 0) { $this->addElement(new XoopsFormLabel(XoopsLocale::SEARCH_RULE, sprintf(XoopsLocale::EF_KEYWORDS_MUST_BE_GREATER_THAN, $search->getConfig('keyword_min')))); } $this->addElement(new XoopsFormHidden('action', 'results')); $this->addElement(new XoopsFormHiddenToken('id')); $this->addElement(new XoopsFormButton('', 'submit', XoopsLocale::SEARCH, 'submit')); return $this; }
function write() { global $current_user; if (!$current_user->authorized) { throw new Exception('Access Denied'); } $id = isset(Request::$post['id']) ? Request::$post['id'] : 0; $id = max(0, (int) $id); if (isset(Request::$post['serie1_id'])) { $this->_glue(); return; } if (!$id) { $this->_new(); return; } $query = 'SELECT * FROM `series` WHERE `id`=' . $id; $old = Database::sql2row($query); if (!$old || !$old['id']) { throw new Exception('no such serie #' . $id); } $parent_id = isset(Request::$post['id_parent']) ? Request::$post['id_parent'] : false; $parent_id = max(0, (int) $parent_id); if (!$id) { throw new Exception('Illegal id'); } $title = isset(Request::$post['title']) ? Request::$post['title'] : false; $description = isset(Request::$post['description']) ? Request::$post['description'] : false; if ($parent_id == $id) { throw new Exception('Illegal parent'); } if ($parent_id) { $query = 'SELECT `id` FROM `series` WHERE `id`=' . $parent_id; if (!Database::sql2single($query)) { throw new Exception('No such parent'); } } if (!$title) { throw new Exception('Empty title'); } $description = prepare_review($description); $title = prepare_review($title, ''); $new = array('description' => $description, 'title' => $title, 'id_parent' => (int) $id_parent); Database::query('START TRANSACTION'); SerieLog::addLog($new, $old, $id); SerieLog::saveLog($id, BookLog::TargetType_serie, $current_user->id, BiberLog::BiberLogType_serieEdit); $query = 'UPDATE `series` SET `id_parent`=' . $parent_id . ',`title`=' . Database::escape($title) . ', `description`=' . Database::escape($description) . ' WHERE `id`=' . $id; Database::query($query); Database::query('COMMIT'); $event = new Event(); $event->event_SeriesEdit($current_user->id, $id); $event->push(); $search = Search::getInstance(); /* @var $search Search */ $search->setSerieToFullUpdate($id); }
private static function undo_repeat($logdata) { $query = 'UPDATE `biber_log` SET `undo`=0 WHERE `id`=' . $logdata['id']; Database::query($query); switch ($logdata['action_type']) { case BiberLog::BiberLogType_bookEdit: self::undo_repeat_bookEdit($logdata); break; case BiberLog::BiberLogType_bookEditPerson: self::undo_repeat_bookEditPerson($logdata); break; case BiberLog::BiberLogType_bookEditGenre: self::undo_repeat_bookEditGenre($logdata); break; case BiberLog::BiberLogType_bookEditSerie: self::undo_repeat_bookEditSerie($logdata); break; case BiberLog::BiberLogType_bookAddRelation: self::undo_repeat_bookAddRelation($logdata); break; case BiberLog::BiberLogType_bookDelRelation: self::undo_repeat_bookDelRelation($logdata); break; case BiberLog::BiberLogType_personAddRelation: self::undo_repeat_personAddRelation($logdata); break; case BiberLog::BiberLogType_personDelRelation: self::undo_repeat_personDelRelation($logdata); break; case BiberLog::BiberLogType_personEdit: self::undo_repeat_personEdit($logdata); break; case BiberLog::BiberLogType_serieEdit: self::undo_repeat_serieEdit($logdata); break; case BiberLog::BiberLogType_magazineEdit: self::undo_repeat_magazineEdit($logdata); break; case BiberLog::BiberLogType_bookSetDuplicate: self::undo_repeat_bookSetDuplicate($logdata); break; case BiberLog::BiberLogType_bookSetNoDuplicate: self::undo_repeat_bookSetNoDuplicate($logdata); break; case BiberLog::BiberLogType_personSetDuplicate: self::undo_repeat_authorSetDuplicate($logdata); break; case BiberLog::BiberLogType_personSetNoDuplicate: self::undo_repeat_authorSetNoDuplicate($logdata); break; case BiberLog::BiberLogType_bookNew: self::undo_repeat_bookNew($logdata); break; case BiberLog::BiberLogType_personNew: self::undo_repeat_personNew($logdata); break; case BiberLog::BiberLogType_serieNew: self::undo_repeat_serieNew($logdata); break; case BiberLog::BiberLogType_serieGlue: self::undo_repeat_serieGlue($logdata); break; default: throw new Exception('log action #' . self::$actionTypes[$logdata['action_type']] . ' cant be repeat yet'); break; } switch ($logdata['action_type']) { case BiberLog::BiberLogType_bookEdit: case BiberLog::BiberLogType_bookEditPerson: case BiberLog::BiberLogType_bookEditGenre: case BiberLog::BiberLogType_bookEditSerie: case BiberLog::BiberLogType_bookAddRelation: case BiberLog::BiberLogType_bookDelRelation: case BiberLog::BiberLogType_bookNew: $data = unserialize($logdata['data']); if (isset($data['id_book'])) { Search::getInstance()->setBookToFullUpdate(new Book($data['id_book'])); } break; case BiberLog::BiberLogType_personAddRelation: case BiberLog::BiberLogType_personDelRelation: case BiberLog::BiberLogType_personEdit: case BiberLog::BiberLogType_personNew: case BiberLog::BiberLogType_personSetDuplicate: case BiberLog::BiberLogType_personSetNoDuplicate: $search = Search::getInstance(); /* @var $search Search */ $search->setAuthorToFullUpdate($data['id_person']); break; case BiberLog::BiberLogType_magazineEdit: case BiberLog::BiberLogType_magazineNew: $search = Search::getInstance(); /* @var $search Search */ $search->setMagazineToFullUpdate($data['id_magazine']); break; case BiberLog::BiberLogType_serieEdit: case BiberLog::BiberLogType_serieGlue: case BiberLog::BiberLogType_serieNew: $search = Search::getInstance(); /* @var $search Search */ $search->setSerieToFullUpdate($data['id_serie']); break; } return true; }
function write() { global $current_user; $points_gained = false; /* @var $current_user CurrentUser */ Database::query('START TRANSACTION'); $current_user->can_throw('books_edit'); if (!isset(Request::$post['lang_code']) || !Request::$post['lang_code']) { throw new Exception('field missed #lang_code'); } $id = isset(Request::$post['id']) ? (int) Request::$post['id'] : false; if (Request::post('isbn')) { Request::$post['isbn'] = extractISBN(Request::$post['isbn']); } if (!$id) { $this->newBook(); return; } $books = Books::getInstance()->getByIdsLoaded(array($id)); $book = is_array($books) ? $books[$id] : false; if (!$book) { return; } /* @var $book Book */ $fields = array('title' => 'title', 'subtitle' => 'subtitle', 'isbn' => 'ISBN', 'year' => 'year', 'lang_code' => 'id_lang', 'annotation' => 'description', 'rightholder' => 'id_rightholder'); Request::$post['lang_code'] = Config::$langs[Request::$post['lang_code']]; Request::$post['annotation'] = trim(prepare_review(Request::$post['annotation'], false, '<img>')); Request::$post['title'] = trim(prepare_review(Request::$post['title'], '')); Request::$post['year'] = (int) Request::$post['year']; $magazineData = array(); if ($book->data['book_type'] == Book::BOOK_TYPE_MAGAZINE) { $magazineData = Database::sql2row('SELECT * FROM `magazines` M LEFT JOIN book_magazines BM ON BM.id_magazine=M.id WHERE BM.id_book=' . $book->id); $book->data['n'] = max(0, $magazineData['n']); $book->data['year'] = $magazineData['year']; Request::$post['n'] = isset(Request::$post['n']) && Request::$post['n'] ? Request::$post['n'] : $magazineData['n']; } $to_update_m = array(); $to_update = array(); if (isset(Request::$post['quality'])) { if ($book->data['quality'] != (int) Request::$post['quality']) { $to_update['quality'] = (int) Request::$post['quality']; } } if (isset(Request::$post['n'])) { if (isset($book->data['n']) && $book->data['n'] != (int) Request::$post['n']) { $to_update_m['n'] = (int) Request::$post['n']; Request::$post['title'] = $magazineData['title']; Request::$post['subtitle'] = '№ ' . $to_update_m['n'] . ' за ' . Request::$post['year'] . ' год'; } if (isset($book->data['year']) && $book->data['year'] != (int) Request::$post['year']) { $to_update_m['n'] = (int) Request::$post['n']; Request::$post['title'] = $magazineData['title']; Request::$post['subtitle'] = '№ ' . $to_update_m['n'] . ' за ' . Request::$post['year'] . ' год'; } } if (isset($_FILES['cover']) && $_FILES['cover']['tmp_name']) { $folder = Config::need('static_path') . '/upload/covers/' . ceil($book->id / 5000); @mkdir($folder); // inserting new cover $query = 'INSERT INTO `book_covers` SET `id_book`=' . $book->id; Database::query($query); $cover_id = Database::lastInsertId(); // generating file names $filename_normal = $folder . '/default_' . $book->id . '_' . $cover_id . '.jpg'; $filename_small = $folder . '/small_' . $book->id . '_' . $cover_id . '.jpg'; $filename_big = $folder . '/big_' . $book->id . '_' . $cover_id . '.jpg'; $filename_orig = $folder . '/orig_' . $book->id . '_' . $cover_id . '.jpg'; $to_update['is_cover'] = $cover_id; $thumb = new Thumb(); $thumb->createThumbnails($_FILES['cover']['tmp_name'], array($filename_small, $filename_normal, $filename_big, $filename_orig), self::$cover_sizes); if ($book->data['is_cover']) { $current_user->gainActionPoints('books_edit_cover', $book->id, BiberLog::TargetType_book); } else { $current_user->gainActionPoints('books_add_cover', $book->id, BiberLog::TargetType_book); } $points_gained = true; } // file loading if (isset($_FILES['file']) && isset($_FILES['file']['tmp_name']) && $_FILES['file']['tmp_name']) { $filetype_ = explode('.', $_FILES['file']['name']); $filetype_ = isset($filetype_[count($filetype_) - 1]) ? $filetype_[count($filetype_) - 1] : ''; $fts = Config::need('filetypes'); $filetype = false; foreach ($fts as $ftid => $ftname) { if ($ftname == $filetype_) { $filetype = $ftid; } } if (!$filetype) { throw new Exception('wrong filetype:' . $filetype_); } $destinationDir = Config::need('files_path') . DIRECTORY_SEPARATOR . getBookFileDirectory($book->id, $filetype); @mkdir($destinationDir, 0755); // добавляем запись в базу $filesize = $_FILES['file']['size']; $query = 'SELECT * FROM `book_files` WHERE `id_book`=' . $book->id; $files = Database::sql2array($query, 'filetype'); // replacing file if (isset($files[$filetype])) { $old_id_file = $files[$filetype]['id']; $old_id_file_author = $files[$filetype]['id_file_author']; $old_filesize = $files[$filetype]['filesize']; $query = 'DELETE FROM `book_files` WHERE `id`=' . $old_id_file; Database::query($query); $query = 'INSERT IGNORE INTO `book_files` SET `id_book`=' . $book->id . ', `filetype`=' . $filetype . ', `id_file_author`=' . $current_user->id . ', `modify_time`=' . time() . ', `filesize`=' . $filesize; Database::query($query); $id_file = Database::lastInsertId(); BookLog::addLog(array('id_file' => $id_file, 'filetype' => $filetype, 'id_file_author' => $current_user->id, 'filesize' => $filesize), array('id_file' => $old_id_file, 'filetype' => 0, 'id_file_author' => $old_id_file_author, 'filesize' => $old_filesize), $book->id); Database::query($query); $current_user->gainActionPoints('books_edit_file', $book->id, BiberLog::TargetType_book); } else { $query = 'INSERT INTO `book_files` SET `id_book`=' . $book->id . ', `filetype`=' . $filetype . ', `id_file_author`=' . $current_user->id . ', `modify_time`=' . time() . ', `filesize`=' . $filesize; Database::query($query); $id_file = Database::lastInsertId(); BookLog::addLog(array('id_file' => $id_file, 'filetype' => $filetype, 'id_file_author' => $current_user->id, 'filesize' => $filesize), array('id_file' => 0, 'filetype' => 0, 'id_file_author' => 0, 'filesize' => 0), $book->id); $current_user->gainActionPoints('books_add_file', $book->id, BiberLog::TargetType_book); } if ($id_file) { $points_gained = true; if (!$book->data['id_main_file'] || isset($files[$filetype])) { $to_update['id_main_file'] = $id_file; } $destinationFile = getBookFilePath($id_file, $book->id, $filetype, Config::need('files_path')); if (!move_uploaded_file($_FILES['file']['tmp_name'], $destinationFile)) { throw new Exception('Cant save file to ' . $destinationFile); } // event for new File $event = new Event(); $event->event_BooksAddFile($current_user->id, $book->id); $event->push(); if ($filetype == 1) { // FB2 $parser = new FB2Parser($destinationFile); $parser->parseDescription(); $toc = $parser->getTOCHTML(); Request::$post['annotation'] = $parser->getProperty('annotation'); Request::$post['title'] = $parser->getProperty('book-title'); $to_update['table_of_contents'] = $toc; } } } foreach ($fields as $field => $bookfield) { if (!isset(Request::$post[$field])) { throw new Exception('field missed #[' . $field . ']'); } if ($book->data[$bookfield] != Request::$post[$field]) { $to_update[$bookfield] = Request::$post[$field]; } } $q = array(); foreach ($to_update as $field => &$value) { $q[] = '`' . $field . '`=' . Database::escape($value) . ''; } $push_event = true; if (count($q)) { if (count($to_update) == 1) { foreach ($to_update as $kk => $vv) { if ($kk == 'id_main_file') { $push_event = false; } } } $query = 'UPDATE `book` SET ' . implode(',', $q) . ' WHERE `id`=' . $book->id; Database::query($query); if (count($to_update_m)) { $to_update['n'] = $to_update_m['n']; } BookLog::addLog($to_update, $book->data, $book->id); foreach ($to_update as $f => $v) { $book->data[$f] = $v; } $search = Search::getInstance(); /* @var $search Search */ $search->updateBook($book); if ($push_event) { $event = new Event(); $event->event_BooksEdit($current_user->id, $book->id); $event->push(); } if (!$points_gained) { $current_user->gainActionPoints('books_edit', $book->id, BiberLog::TargetType_book); } } BookLog::saveLog($book->id, BookLog::TargetType_book, $current_user->id, BiberLog::BiberLogType_bookEdit); Books::getInstance()->dropCache($book->id); if (count($to_update_m)) { if ($to_update_m['n'] && $book->data['book_type'] == Book::BOOK_TYPE_MAGAZINE) { Database::query('UPDATE `book_magazines` SET `n`=' . $to_update_m['n'] . ',`year`=' . (int) $book->data['year'] . ' WHERE `id_book`=' . $book->id); } } ob_end_clean(); header('Location:' . Config::need('www_path') . '/b/' . $book->id); Database::query('COMMIT'); exit; }