当前位置: 首页>>代码示例>>PHP>>正文


PHP Search::getInstance方法代码示例

本文整理汇总了PHP中Search::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Search::getInstance方法的具体用法?PHP Search::getInstance怎么用?PHP Search::getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Search的用法示例。


在下文中一共展示了Search::getInstance方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getSearch

 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;
 }
开发者ID:rasstroen,项目名称:metro,代码行数:34,代码来源:magazines_module.php

示例2: b_search_show

/**
 * 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;
}
开发者ID:RanLee,项目名称:XoopsCore,代码行数:24,代码来源:search_blocks.php

示例3: getSearchFrom

 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;
 }
开发者ID:RanLee,项目名称:XoopsCore,代码行数:45,代码来源:search.php

示例4: search

 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;
 }
开发者ID:rasstroen,项目名称:metro,代码行数:20,代码来源:Jsearch_module.php

示例5: del_relation

 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();
     }
 }
开发者ID:rasstroen,项目名称:metro,代码行数:21,代码来源:Jauthors_module.php

示例6: dirname

*/
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 <phppp@users.sourceforge.net>
 * @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 == "") {
开发者ID:ming-hai,项目名称:XoopsCore,代码行数:31,代码来源:index.php

示例7: del_author

 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;
 }
开发者ID:rasstroen,项目名称:metro,代码行数:27,代码来源:Jbooks_module.php

示例8: write

 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;
 }
开发者ID:rasstroen,项目名称:metro,代码行数:56,代码来源:MagazineWriteModule.php

示例9: getSearch

 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;
 }
开发者ID:rasstroen,项目名称:metro,代码行数:28,代码来源:authors_module.php

示例10: write

 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;
 }
开发者ID:rasstroen,项目名称:metro,代码行数:88,代码来源:AuthorWriteModule.php

示例11: alumni_getSearchFrom

 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;
 }
开发者ID:jlm69,项目名称:alumni-26x,代码行数:66,代码来源:search.php

示例12: write

 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);
 }
开发者ID:rasstroen,项目名称:metro,代码行数:56,代码来源:SeriesWriteModule.php

示例13: undo_repeat

 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 */
//.........这里部分代码省略.........
开发者ID:rasstroen,项目名称:metro,代码行数:101,代码来源:BiberLog.php

示例14: write

    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'];
//.........这里部分代码省略.........
开发者ID:rasstroen,项目名称:metro,代码行数:101,代码来源:BookWriteModule.php


注:本文中的Search::getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。