/** * Open database connection and define collection * @param mixed string / boolean $collection */ public function __construct($collection = false) { // enable dynamic collections // this will help to create new collections even faster, without the need to create new classes if ($collection !== false) { $this->collectionName = $collection; } // if no collection is defined, use class name as collection name if ($this->collectionName === false) { $this->collectionName = get_class($this); } // if mongo object is already cached, use that instead of opening new connection if (self::$mongoObj !== false) { $mongo = self::$mongoObj; } else { $mongo = new Mongo(); // cache mongodb object self::$mongoObj = $mongo; } $this->mongo = $mongo->{$this->databaseName}; // authentication if ($this->username !== false && $this->password !== false) { $this->authenticate($this->username, $this->password); } $this->collection = $this->mongo->{$this->collectionName}; }
<?php include 'includes.php'; $all_langs = MongoHelper::getInstance()->find(Otable::DB_LANG, Otable::TABLE_LANGS, array()); $lang_arr = array(); foreach ($all_langs as $key => $value) { $lang_arr[$value['key']] = $value['value']; } $cur_lang = 'cs'; $cur_lang_str = $lang_arr[$cur_lang]; if (isset($_GET['lang'])) { $cur_lang = $_GET['lang']; $cur_lang_str = $lang_arr[$cur_lang]; } if (isset($_GET['key'])) { $need_translate_item = MongoHelper::getInstance()->findOne(Otable::DB_LANG, Otable::TABLE_ITEMS, array('key' => $_GET['key'])); } else { $find_condition = array('$or' => array(array($cur_lang => array('$exists' => false)), array($cur_lang => ''))); $need_translate_item = MongoHelper::getInstance()->findOne(Otable::DB_LANG, Otable::TABLE_ITEMS, $find_condition); } include 'templates/translate.html';
<?php //添加语言 include __DIR__ . '/includes.php'; $all_tags = MongoHelper::getInstance()->find(Otable::DB_LANG, Otable::TABLE_TAGS, array()); foreach ($all_tags as $key => $value) { $tags[$value['key']] = $value['value']; } include __DIR__ . '/templates/add_lang.html';
<?php include 'includes.php'; $search_key = $_GET['s']; $all_tags = MongoHelper::getInstance()->find(Otable::DB_LANG, Otable::TABLE_TAGS, array()); foreach ($all_tags as $key => $value) { $tags[$value['key']] = $value['value']; } $regexObj = new MongoRegex('/' . $search_key . '/'); $find_condition = array('$or' => array(array('key' => $regexObj), array('cs' => $regexObj), array('tags' => array('$in' => array($search_key))))); $langs = MongoHelper::getInstance()->find(Otable::DB_LANG, Otable::TABLE_ITEMS, $find_condition, array('sort' => array('la_id', 1))); include __DIR__ . '/templates/index.html'; //搜索,key和value都搜索
<?php include '../includes.php'; /** * 修改语言内容 */ $key = $_POST['key']; $lang = $_POST['lang']; $content = $_POST['content']; if (empty($key) || empty($lang) || empty($content)) { die(json_encode(array('result' => false, 'msg' => '提交参数不全'))); } MongoHelper::getInstance()->update(Otable::DB_LANG, Otable::TABLE_ITEMS, array('key' => $key), array('$set' => array($lang => $content))); echo json_encode(array('result' => true));
<?php include '../includes.php'; include '../model/ExportLang.php'; $tag = $_GET['tag']; $codetype = $_GET['codetype']; $zip_file_name = __DIR__ . '/../data/' . $tag . '.zip'; $all_langs = MongoHelper::getInstance()->find(Otable::DB_LANG, Otable::TABLE_LANGS, array()); $all_items = MongoHelper::getInstance()->find(Otable::DB_LANG, Otable::TABLE_ITEMS, array('tags' => array('$in' => array($tag))), array('sort' => array('la_id' => -1))); if (empty($all_items)) { exit('未找到'); } $zip = new ZipArchive(); $res = $zip->open($zip_file_name, ZipArchive::OVERWRITE); if ($res !== true) { die(json_encode(array('reuslt' => false, 'msg' => '创建zip文件失败'))); } $export = new ExportLang(); foreach ($all_langs as $key => $value) { $string = $export->export2String($codetype, $all_items, $value['key']); $filename = $export->file_name; $zip->addFromString($filename, $string); } $zip->close(); header('Content-Type: application/zip'); header('Content-disposition: attachment; filename=' . $tag . '-' . $codetype . '.zip'); header('Content-Length: ' . filesize($zip_file_name)); readfile($zip_file_name);
<?php include '../includes.php'; //修改某个语言的tagtou $key = $_POST['key']; $tags = trim($_POST['tags']); if (empty($tags)) { die(json_encode(array('result' => true))); } $tags = explode(',', $tags); if (!empty($tags)) { MongoHelper::getInstance()->update(Otable::DB_LANG, Otable::TABLE_ITEMS, array('key' => $key), array('$set' => array('tags' => $tags))); } echo json_encode(array('result' => true));
<?php include '../includes.php'; //显示指定key的语言所有语言版本 $key = $_GET['key']; $res = MongoHelper::getInstance()->findOne(Otable::DB_LANG, Otable::TABLE_ITEMS, array('key' => $key)); if (empty($res)) { exit(json_encode(array('result' => false, 'msg' => '不存在该记录'))); } echo json_encode($res);
public static function timeToStr($time) { $time = MongoHelper::timeToInt($time); return date("Y-m-d H:i:s", $time); }
<?php //添加语言 include './../includes.php'; header("Content-type:text/html;charset=utf-8"); //post参数 $cs = isset($_POST['cs']) ? $_POST['cs'] : ""; $tags = isset($_POST['tags']) ? $_POST['tags'] : ""; if (empty($cs) || empty($tags)) { $res = array('result' => false, 'msg' => 'cs and tags must post.'); echo json_encode($res); exit; } $tags_arr = explode(",", $tags); //获取最大的la_id $res_la = MongoHelper::getInstance()->find(Otable::DB_LANG, Otable::TABLE_ITEMS, array('la_id' => array('$exists' => true)), array('sort' => array('la_id' => -1), 'limit' => 1)); $last_id = $res_la[0]['la_id'] + 1; $key = 'la_' . $last_id; $record = array('la_id' => (int) $last_id, 'cs' => $cs, 'key' => $key, 'tags' => $tags_arr); MongoHelper::getInstance()->insert(Otable::DB_LANG, Otable::TABLE_ITEMS, $record); echo json_encode(array('result' => true));
public function __construct() { $this->database = MongoHelper::getInstance($this->dbName); $this->collection = $this->database->collection($this->collection); }
public static function serviceFolder($id) { $id = MongoHelper::standardId($id); return ['children' => URL::absolute('/service/' . $id . '/children')]; }
<?php include 'includes.php'; $all_tags = MongoHelper::getInstance()->find(Otable::DB_LANG, Otable::TABLE_TAGS, array()); foreach ($all_tags as $key => $value) { $tags[$value['key']] = $value['value']; } $langs = MongoHelper::getInstance()->find(Otable::DB_LANG, Otable::TABLE_ITEMS, array('la_id' => array('$gt' => 0)), array('limit' => 100, 'sort' => array('la_id', 1))); //列出前100条语言 include __DIR__ . '/templates/index.html'; //这是新分支添加的东西。。。