Esempio n. 1
0
 /**
  * Подсчёт кол-ва контента в данном месяце и в данном году
  * @param int $month данный месяц
  * @param int $year данный год
  * @return string JS массив кол-ва торрентов по дням
  */
 public function count_content($month = null, $year = null)
 {
     $month = !$month ? date("n") : $month;
     $year = !$year ? date("Y") : $year;
     if (!($r = cache::o()->read('calendar/c' . $month . '-' . $year))) {
         $year_after = $month == 12 ? $year + 1 : $year;
         $month_after = $month < 12 ? $month + 1 : 1;
         $from = mktime(null, null, null, $month, 1, $year);
         $to = mktime(null, null, null, $month_after, 1, $year_after);
         $datas = db::o()->p($from, $to)->query('SELECT posted_time FROM content 
             WHERE posted_time BETWEEN ? AND ?');
         //$count = count($datas);
         $content = array();
         while ($data = db::o()->fetch_assoc($datas)) {
             $day = date("j", $data["posted_time"]);
             $content[$day]++;
         }
         $ncontent = "";
         for ($i = 0; $i <= 31; $i++) {
             $ncontent .= ($ncontent !== "" ? ", " : "") . longval($content[$i]);
         }
         $r = array("new Array(" . $ncontent . ")");
         cache::o()->write($r);
     }
     return $r[0];
 }
Esempio n. 2
0
 /**
  * Конструктор категорий
  * @return null
  */
 public function __construct()
 {
     if (!self::$c && (self::$c = cache::o()->read('categories')) === false) {
         self::cats2array();
         cache::o()->write(self::$c);
     }
     tpl::o()->register_modifier("print_cats", array($this, 'print_selected'));
 }
Esempio n. 3
0
 /**
  * Инициализация AJAX-части модуля
  * @return null
  */
 public function init()
 {
     lang::o()->get('admin/pages/main');
     if (!users::o()->perm('system')) {
         return;
     }
     $act = $_GET["act"];
     users::o()->admin_mode();
     /* @var $etc etc */
     $etc = n("etc");
     $all = false;
     switch ($act) {
         case "attachments":
             $all = true;
         case "unattachments":
             /* @var $attach attachments */
             $attach = n("attachments");
             $attach->clear(0, $all);
             break;
         case "sitemap":
             $this->sitemap();
             ok();
             break;
         case "cleanup":
             /* @var $cleanup cleanup */
             $cleanup = n("cleanup");
             $cleanup->execute(true);
             break;
         case "cache":
             cache::o()->clear();
             break;
         case "cache_tpl":
             cache::o()->clear_tpl();
             break;
         case "stats":
             $st = stats::o()->read();
             foreach ($st as $s => $v) {
                 stats::o()->write($s, 0);
             }
             break;
         case "logs":
             /* @var $logs logs_man_ajax */
             $logs = plugins::o()->get_module('logs', 1, true);
             $logs->clear();
             break;
         case "peers":
             db::o()->truncate_table('content_peers');
             db::o()->update(array('leechers' => 0, 'seeders' => 0), 'content_torrents');
             break;
         case "downloaded":
             db::o()->truncate_table('content_downloaded');
             db::o()->update(array('downloaded' => 0), 'content_torrents');
             break;
         case "chat":
             /* @var $chat chat */
             $chat = plugins::o()->get_module('chat');
             $chat->truncate();
             break;
         case "pm":
             /* @var $pm messages_ajax */
             $pm = plugins::o()->get_module('messages', false, true);
             $pm->clear();
             break;
         case "ratings":
             $r = db::o()->query('SELECT toid, type FROM ratings GROUP BY toid, type');
             /* @var $rating rating */
             $rating = n("rating");
             while ($row = db::o()->fetch_assoc($r)) {
                 $rating->change_type($row['type'])->clear($row['toid']);
             }
             break;
             // Далее: Важная часть сайта, да
         // Далее: Важная часть сайта, да
         case "content":
             $r = db::o()->query('SELECT id FROM content');
             while (list($id) = db::o()->fetch_row($r)) {
                 try {
                     $etc->delete_content($id);
                 } catch (EngineException $e) {
                 }
             }
             break;
         case "comments":
             /* @var $comments comments */
             $comments = n("comments");
             $comments->clear(null, true);
             break;
         case "polls":
             /* @var $polls polls */
             $polls = n("polls");
             $polls->clear();
             break;
         case "news":
             /* @var $news news_ajax */
             $news = plugins::o()->get_module('news', false, true);
             $news->clear();
             break;
         case "bans":
             $r = db::o()->query('SELECT id FROM bans');
             while (list($id) = db::o()->fetch_row($r)) {
                 $etc->unban_user(null, $id);
             }
             break;
         case "warnings":
             $r = db::o()->query('SELECT id FROM warnings');
             while (list($id) = db::o()->fetch_row($r)) {
                 $etc->unwarn_user(null, null, $id);
             }
             break;
     }
     log_add('system_clean', 'admin', array(lang::o()->v('main_page_clear_' . $act), $act));
     ok();
 }
Esempio n. 4
0
 /**
  * Удаление контента
  * @param int $id ID контента
  * @return null
  * @throws EngineException 
  */
 public function delete($id)
 {
     check_formkey();
     $id = (int) $id;
     $lj = $cols = "";
     if ($this->tstate) {
         $cols = ", t.screenshots";
         $lj = ' LEFT JOIN content_torrents AS t ON t.cid=c.id';
     }
     $row = db::o()->p($id)->query('SELECT c.poster_id, c.title, c.posted_time, 
         p.id AS poll_id ' . $cols . ' FROM content AS c ' . $lj . '
             LEFT JOIN polls AS p ON p.type="content" AND p.toid=c.id
             WHERE c.id=? LIMIT 1');
     list($poster_id, $title, $posted_time, $pid, $screenshots) = db::o()->fetch_row($row);
     if ($row) {
         if (users::o()->v('id') == $poster_id) {
             users::o()->check_perms('del_content');
         } else {
             users::o()->check_perms('del_content', '2');
         }
     } else {
         throw new EngineException('content_not_exists');
     }
     db::o()->p($id)->delete('content', 'WHERE id=? LIMIT 1');
     if ($this->tstate) {
         db::o()->p($id)->delete('content_torrents', 'WHERE cid=? LIMIT 1');
         db::o()->p($id)->delete('content_downloaded', 'WHERE tid=? LIMIT 1');
         db::o()->p($id)->delete('content_peers', 'WHERE tid=? LIMIT 1');
         cache::o()->remove("details/l-id" . $id);
         $this->delete_files($posted_time, $poster_id, $screenshots);
     }
     try {
         plugins::o()->pass_data(array('id' => $id), true)->run_hook('content_delete');
     } catch (PReturn $e) {
         return $e->r();
     }
     db::o()->p($id)->delete('content_readed', 'WHERE content_id=? LIMIT 1');
     /* @var $etc etc */
     $etc = n("etc");
     $etc->add_res('content', -1, '', $poster_id);
     log_add("deleted_content", "user", array($title));
     users::o()->admin_mode();
     n("comments")->change_type('content')->clear($id);
     n("rating")->change_type('content')->clear($id);
     n("mailer")->change_type('content')->remove($id);
     if ($pid) {
         n("polls")->delete($pid);
     }
     users::o()->admin_mode(false);
 }
Esempio n. 5
0
 /**
  * Конструктор? А где конструктор? А нет его.
  * @return null 
  */
 private function __construct()
 {
     if (!class_exists('cache')) {
         return;
     }
     $this->cached = cache::o()->read(self::cachefile);
     if ($this->cached === false) {
         cache::o()->pop_readed();
     }
 }
Esempio n. 6
0
 /**
  * Инициализация сессии пользователя
  * @return null
  */
 public function write_session()
 {
     if (!cache::o()->query_delay('usessions', config::o()->v('delay_userupdates'))) {
         return;
     }
     $ip = $this->get_ip();
     $url = $_SERVER['REQUEST_URI'];
     $ctime = time();
     $agent = $_SERVER["HTTP_USER_AGENT"];
     if (!$this->vars) {
         $uid = 0;
         $userdata = '';
     } else {
         $uid = $this->vars['id'];
         $userdata = array('username' => $this->vars['username'], 'group' => $this->vars['group'], 'hidden' => $this->vars['hidden'], 'useragent' => $agent, 'url' => $url);
         if ($this->vars['bot']) {
             $userdata['bot'] = true;
             $this->vars = array();
         }
         $userdata = serialize($userdata);
     }
     //$past = time() - 300;
     $sid = session_id();
     $updateset = array("sid" => $sid, "uid" => $uid, "userdata" => $userdata, "ip" => $ip, "time" => $ctime);
     $users_updateset = array("ip" => $ip, "last_visited" => time());
     try {
         plugins::o()->pass_data(array('update_sess' => &$updateset, 'update_user' => &$users_updateset), true)->run_hook('users_sessions');
     } catch (PReturn $e) {
         return $e->r();
     }
     if ($this->vars) {
         db::o()->p($uid)->update($users_updateset, "users", "WHERE id=? LIMIT 1");
     }
     db::o()->p($sid)->update($updateset, "sessions", "WHERE sid=? LIMIT 1");
     if (db::o()->affected_rows() < 1) {
         db::o()->insert($updateset, "sessions");
     }
 }
Esempio n. 7
0
if (!defined('INSITE')) {
    die("Remote access denied!");
}
$allowed = "acp_modules";
$allowed_admin_pages = "acp_pages";
if (!($admin_modules = cache::o()->read('admin_modules'))) {
    $admin_modules = array();
    $r = db::o()->query('SELECT ai.name AS ai_name, ac.name AS ac_name, am.name AS am_name, am.link 
    FROM admin_items AS ai 
    LEFT JOIN admin_cats AS ac ON ac.item=ai.id
    LEFT JOIN admin_modules AS am ON am.cat=ac.id
    ORDER BY am.id');
    while ($row = db::o()->fetch_assoc($r)) {
        $admin_modules[$row['ai_name']][$row['ac_name']][$row['am_name']] = $row['link'];
    }
    cache::o()->write($admin_modules);
}
users::o()->check_perms('acp');
$item_mainpage = false;
/**
 * Узнаём, в какой вкладке сейчас находимся
 */
if ($_GET['item'] && $admin_modules[$_GET['item']]) {
    $item = $_GET['item'];
    $item_mainpage = true;
} else {
    $item = "main";
    $item_mainpage = true;
}
/**
 * Узнаём, какой модуль затребован
Esempio n. 8
0
 /**
  * Удаление новости
  * @param int $id ID новости
  * @return null
  * @throws EngineException 
  */
 public function delete($id)
 {
     $id = (int) $id;
     check_formkey();
     list($pid, $title) = db::o()->fetch_row(db::o()->p($id)->query('SELECT poster_id, title FROM news
             WHERE id=? LIMIT 1'));
     if ($pid) {
         if (users::o()->v('id') == $pid) {
             users::o()->check_perms('del_news');
         } else {
             users::o()->check_perms('del_news', '2');
         }
     } else {
         throw new EngineException('news_are_not_exists');
     }
     db::o()->p($id)->delete('news', 'WHERE id=? LIMIT 1');
     cache::o()->remove('news');
     log_add("deleted_news", "user", array($title));
 }
Esempio n. 9
0
 /**
  * Парсинг таблицы конвертации
  * @param int $toffset позиция таблицы для конвертации
  * @param int $loffset позиция значений
  * @return null
  */
 private function parse($toffset = 0, $loffset = 0)
 {
     $toffset = (int) $toffset;
     $loffset = (int) $loffset;
     if (!$toffset && !$loffset) {
         $this->truncate_tables();
     }
     @mb_internal_encoding('UTF-8');
     $a = array();
     $finish = "<script type='text/javascript'>continue_convert(0, 0, true);</script>";
     $cachefile = 'convert/cparse-off' . $toffset;
     if (!($a = cache::o()->read($cachefile))) {
         $content = $this->convert_tables();
         $tpos = utf8_preg_offset($content, $toffset, true);
         $c = preg_match_all('/(^)\\s*?(\\@?)table\\s+(\\w+)\\/([\\w\\s,]+?)(?:\\s*?\\:\\s*?(\\w+))?(?:\\s*?\\?(.*?))?\\s*?($)/miu', $content, $matches, PREG_OFFSET_CAPTURE, $tpos);
         $i = 0;
         if (!$matches) {
             die($finish);
         }
         $noerr = $matches[2][$i][0];
         $table = $matches[3][$i][0];
         $orderby = $matches[4][$i][0];
         $ftable = $matches[5][$i][0];
         if (!$ftable) {
             $ftable = $table;
         }
         $cond = trim($matches[6][$i][0]);
         $pos = utf8_preg_offset($content, $matches[7][$i][1]);
         $i++;
         if ($matches[1][$i]) {
             $ntoffset = utf8_preg_offset($content, $matches[1][$i][1]);
             $len = $ntoffset - $pos;
         }
         $data = trim($len ? mb_substr($content, $pos, $len) : mb_substr($content, $pos));
         $this->parse_columns($data);
         $a = array($table, $orderby, $ftable, $cond, $ntoffset, $this->columns, $this->insert, $noerr);
         cache::o()->write($a, $cachefile);
     } else {
         list($table, $orderby, $ftable, $cond, $ntoffset, $this->columns, $this->insert, $noerr) = $a;
     }
     $s = $this->select4insert($table, $orderby, $ftable, $cond, $loffset, $noerr);
     $c = db::o()->prepend_db($this->db)->no_parse()->no_prefix()->count_rows($this->prefix . $ftable, $cond);
     if ($c <= $loffset + $this->peronce || !$s) {
         if (!$ntoffset) {
             die($finish);
         } else {
             die("<script type='text/javascript'>continue_convert(" . $ntoffset . ", '0');</script>");
         }
     } else {
         die("<script type='text/javascript'>continue_convert(" . $toffset . ", " . ($loffset + $this->peronce) . ");</script>");
     }
 }
Esempio n. 10
0
 /**
  * Очистка кеша
  * @param int $id ID опроса
  * @param bool $onvotes очистка при голосовании?
  * @return null 
  */
 protected function uncache($id, $onvotes = false)
 {
     if ($onvotes && !config::o()->v('clearonvote_pollcache')) {
         return;
     }
     cache::o()->remove('polls/v-id' . $id);
 }
Esempio n. 11
0
 /**
  * Парсинг шаблона
  * @param int $id ID шаблона
  * @return array массив данного шаблона
  */
 protected function parse_pattern($id)
 {
     $id = (int) $id;
     if (!($row = cache::o()->read('patterns/pattern-id' . $id))) {
         $r = db::o()->p($id)->query('SELECT * FROM patterns WHERE id=? LIMIT 1');
         $row = db::o()->fetch_assoc($r);
         if (!$row) {
             return;
         }
         $row['pattern'] = unserialize($row['pattern']);
         foreach ($row['pattern'] as $k => $e) {
             if ($e['type'] == 'radio' || $e['type'] == 'select') {
                 $vals =& $e['values'];
                 $vals = explode(';', $vals);
                 $c = count($vals);
                 for ($i = 0; $i < $c; $i++) {
                     $vals[$i] = trim($vals[$i]);
                     $p = mb_strpos($vals[$i], ':');
                     if (!$p) {
                         continue;
                     }
                     $f = mb_substr($vals[$i], 0, $p);
                     $s = mb_substr($vals[$i], $p + 1);
                     $vals[$i] = array(trim($f), trim($s));
                 }
             }
             $fd =& $e['formdata'];
             $r = preg_split('/^\\{form\\.([a-z0-9\\_\\-]+)\\}/msiu', $fd, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
             $fd = array();
             $c = count($r);
             $key = null;
             for ($i = 0; $i < $c; $i++) {
                 if ($i % 2 == 0) {
                     $key = $r[$i];
                 } else {
                     $fd[$key] = preg_replace('/\\{this\\.\\$value\\}/siu', '{this.' . $e['rname'] . '}', $r[$i]);
                 }
             }
             $row['pattern'][$k] = $e;
         }
         cache::o()->write($row);
     }
     return $row;
 }
Esempio n. 12
0
 /**
  * Удаление шаблона
  * @param int $id ID шаблона
  * @return null
  */
 public function delete($id)
 {
     $id = (int) $id;
     db::o()->p($id)->delete('patterns', 'WHERE id=? LIMIT 1');
     cache::o()->remove('patterns/pattern-id' . $id);
     log_add('deleted_pattern', 'admin', $id);
 }
Esempio n. 13
0
 /**
  * Получение объекта класса
  * @return cache $this
  */
 public static function o()
 {
     if (!self::$o) {
         self::$o = new self();
     }
     return self::$o;
 }
Esempio n. 14
0
 /**
  * Инициализация AJAX-части модуля
  * @return null
  */
 public function init()
 {
     $act = $_GET["act"];
     $id = (int) $_POST["id"];
     switch ($act) {
         case "edit":
             $this->edit($id);
             break;
         case "delete":
             $this->delete($id);
             break;
         case "switch":
             $this->switch_state((int) $_POST['id']);
             break;
         case "order":
             $this->save_order($_POST['smilieid']);
             break;
     }
     cache::o()->remove('smilies');
     ok();
 }
Esempio n. 15
0
 /**
  * Настройка сайта
  * @param array $data массив данных
  * @param array $error массив ошибок
  * @return null
  */
 protected function config($data, &$error)
 {
     include_once ROOT . 'include/classes/class.cache.php';
     include_once ROOT . 'include/classes/class.users.php';
     include_once ROOT . 'include/classes/class.config.php';
     cache::o()->clear();
     $params = array('site_title', 'baseurl', 'contact_email', 'furl', 'cache_on');
     $upd = rex($data, $params);
     // предустановка параметров, если не заданы
     if (!$upd['baseurl']) {
         $upd['baseurl'] = preg_replace('/^(.*)(\\/|\\\\)(.*?)$/siu', '\\1', $_SERVER['PHP_SELF']);
     }
     if (!$upd['contact_email']) {
         $upd['contact_email'] = 'admin@' . $_SERVER['SERVER_NAME'];
     }
     if (!isset($data['furl'])) {
         $upd['furl'] = (bool) $_SERVER['HTTP_FURL_AVALIABLE'];
     } else {
         $upd['furl'] = (bool) $upd['furl'];
     }
     if (!isset($data['cache_on'])) {
         $upd['cache_on'] = true;
     } else {
         $upd['cache_on'] = (bool) $upd['cache_on'];
     }
     $upd['secret_key'] = users::o()->generate_salt();
     foreach ($upd as $k => $v) {
         config::o()->set($k, $v);
     }
 }
Esempio n. 16
0
 /**
  * Удаление кеша
  * @param string $plugin имя плагина
  * @return null
  */
 public function uncache($plugin = null)
 {
     cache::o()->remove('plugins');
     if ($plugin) {
         modsettings::o()->change_type('plugins')->uncache($plugin);
     }
 }
Esempio n. 17
0
 /**
  * Инициализация AJAX-части модуля
  * @return null
  */
 public function init()
 {
     $act = $_GET['act'];
     switch ($act) {
         case "delete":
             $this->delete((int) $_POST['id']);
             break;
         case "switch":
             $this->switch_state((int) $_POST['id']);
             break;
         case "order":
             $this->save_order($_POST['catid']);
             break;
     }
     cache::o()->remove('categories');
     ok();
 }
Esempio n. 18
0
 /**
  * Удаление кеша настроек
  * @param int|string $id ID модуля
  * @return null
  */
 public function uncache($id)
 {
     if (!$this->check_id($id)) {
         return;
     }
     $type = $this->type;
     cache::o()->remove('modsettings/' . $type . '-id' . $id);
 }
Esempio n. 19
0
 /**
  * Выполнение запроса к БД
  * @param string $query строка запроса
  * @return resid|array ID запроса или, если запрос кешируется,
  * массив из всех row|assoc, в зависимости от последнего параметра,
  * для данного запроса.
  */
 public function query($query)
 {
     $query = trim($query);
     $cparams = $this->cache_params;
     $this->cache_params = null;
     if ($cparams && class_exists('cache')) {
         $cached = true;
         if (is_array($cparams)) {
             $my_cache_name = $cparams['n'];
             $pathto = $cparams['p'];
             $mytime = $cparams['t'];
             $k_v = $cparams['k'];
             $function = $cparams['f'];
         } elseif (is_string($cparams)) {
             $my_cache_name = $cparams;
         }
     } else {
         $cached = false;
     }
     if (!$function || $function != 'row' && $function != 'assoc') {
         $function = 'assoc';
     }
     if ($cached) {
         if (!$my_cache_name) {
             $name = $pathto . 'sql_' . md5($query);
         } else {
             $name = $pathto . $my_cache_name;
         }
         $result = cache::o()->read($name, $mytime);
     }
     if (!is_array($result)) {
         $this->query_timer("", false);
         $this->parse_query($query);
         $result = parent::query($query);
         if (!$result && !$this->no_error) {
             $this->err($query);
         }
         $this->last_resource = $result;
         if ($cached) {
             $rows = $this->fetch2array($result, $function, $k_v);
             $result = $rows;
             cache::o()->write($rows);
         }
         $this->query_timer($query, false);
     }
     if (!$this->no_reset) {
         $this->no_error = false;
     }
     return $result;
 }
Esempio n. 20
0
 /**
  * Инициализация AJAX-части модуля
  * @return null
  */
 public function init()
 {
     lang::o()->get('admin/userfields');
     $act = $_GET["act"];
     $id = $_POST["id"];
     switch ($act) {
         case "switch":
             $this->switch_state($id, $_POST['type']);
             break;
         case "order":
             $this->save_order($_POST['ufid']);
             break;
         case "delete":
             $this->delete($id);
             break;
     }
     cache::o()->remove('userfields');
     ok();
 }