function getRightholders() { $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 : 1; $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p'; $where = ''; $order = 'ORDER BY `id` DESC '; $group_by = ''; $query = 'SELECT COUNT(1) FROM `rightholders` ' . $where . ' ' . $group_by . ''; $count = Database::sql2single($query); $cond->setPaging($count, $per_page, $pagingName); $limit = $cond->getLimit(); $limit = ' LIMIT ' . $limit; $query = 'SELECT * FROM `rightholders`' . $where . ' ' . $group_by . ' ' . $order . ' ' . $limit; $data = Database::sql2array($query); foreach ($data as &$row) { $row['path'] = Config::need('www_path') . '/admin/rightholders/' . $row['id']; } $this->data['rightholders'] = $data; $this->data['rightholders']['title'] = 'Правообладатели'; $this->data['rightholders']['count'] = $count; $this->data['conditions'] = $cond->getConditions(); }
function write() { global $current_user; /*@var $current_user CurrentUser*/ $current_user->can_throw('books_edit'); $id = isset(Request::$post['id']) ? Request::$post['id'] : 0; $id = max(0, (int) $id); $row = Database::sql2row('SELECT * FROM genre WHERE `id`=' . $id); if (!$row) { return; } if (!$id) { throw new Exception('Illegal id'); } $description = prepare_review(isset(Request::$post['description']) ? Request::$post['description'] : ''); if (!$description) { throw new Exception('Empty description'); } $description = prepare_review($description); $query = 'UPDATE `genre` SET `description`=' . Database::escape($description) . ' WHERE `id`=' . $id; Database::query($query); ob_end_clean(); header('Location:' . Config::need('www_path') . '/genres/' . $row['name']); $current_user->gainActionPoints('genres_edit', $id, BiberLog::TargetType_genre); exit; }
function __construct() { $link = mysql_connect(Config::need('dbserver'), Config::need('dbuser'), Config::need('dbpass')); mysql_select_db(Config::need('dbname'), $link); mysql_query('SET NAMES utf8', $link); $this->link = $link; }
public function _create($data) { $item = new $this->className(0); $createdId = $item->_create($data); header('Location:' . Config::need('www_path') . '/banners/' . $createdId); exit; }
public static function process($moduleName) { $filename = Config::need('writemodules_path') . '/' . $moduleName . '.php'; if (!is_readable($filename)) { throw new Exception('no module#' . $moduleName . ' can accept writing', Error::E_WRITEMODULE_MISSED); } $module = new $moduleName; $module->write(); }
public static function getInstance() { if (!self::$instance) { $s = new Mongo(Config::need('mongohost')); self::$instance = $s->ls2; //self::getInstance()->events->remove(); //self::getInstance()->walls->remove(); } return self::$instance; }
public function process() { global $current_user; /* @var $current_user CurrentUser */ XMLClass::$pageNode = XMLClass::createNodeFromObject($this->pageSettings, false, 'page', false); XMLClass::appendNode(XMLClass::$pageNode, $this->pageName); XMLClass::$pageNode->setAttribute('current_url', Request::$url); XMLClass::$pageNode->setAttribute('page_url', Config::need('www_path') . '/' . Request::$pageName . '/'); XMLClass::$pageNode->setAttribute('prefix', Config::need('www_path') . '/'); if ($current_user->authorized) { XMLClass::$CurrentUserNode = XMLClass::createNodeFromObject($current_user->getXMLInfo(), false, 'current_user', false); } else { XMLClass::$CurrentUserNode = XMLClass::createNodeFromObject(array(), false, 'current_user', false); } XMLClass::$pageNode->appendChild(XMLClass::$CurrentUserNode); // втыкаем модули страницы $role = $current_user->getRole(); if (isset($this->pageSettings['modules']) && is_array($this->pageSettings['modules'])) { foreach ($this->pageSettings['modules'] as $moduleName => $additionalSettings) { if (isset($additionalSettings['roles'][$role])) { $this->processModule($moduleName, $additionalSettings); } } } // xml дерево создано, теперь генерируем xslt шаблон // выдаем html //Request::$responseType = 'xml'; switch (Request::$responseType) { case 'xml': case 'xmlc': return XMLClass::dumpToBrowser(); break; case 'xsl': case 'xslc': $xslTemplateClass = new XSLClass($this->pageSettings['xslt']); $xslTemplateClass->setTemplates($this->xsltFiles); return $xslTemplateClass->dumpToBrowser(); break; case 'html': $xslTemplateClass = new XSLClass($this->pageSettings['xslt']); $xslTemplateClass->setTemplates($this->xsltFiles); $html = $xslTemplateClass->getHTML(XMLClass::$xml); if ($xslTemplateClass->fetched_from_cache) { // чтобы знать, что файл из кеша Log::logHtml('xslt template GOT from cache'); } if ($xslTemplateClass->puted_into_cache) { // чтобы знать, что файл из кеша Log::logHtml('xslt template PUT to cache'); } return $html; break; default: return XMLClass::dumpToBrowser(); break; } }
function getShort() { $avatar = Config::need('www_path') . '/static/upload/author_images/' . ceil($this->data['id'] / 500) . '/' . $this->data['id'] . '.jpg'; $avatar_small = Config::need('www_path') . '/static/upload/author_images/' . ceil($this->data['id'] / 500) . '/' . $this->data['id'] . '_small.jpg'; if (!$this->data['has_pic']) { $avatar = Config::need('www_path') . '/static/default/img/avatar.jpg'; $avatar_small = Config::need('www_path') . '/static/default/img/avatar_small.jpg'; } return array('id' => $this->data['id'], 'username' => $this->data['username'], 'path' => Config::need('www_path') . '/profile/' . $this->data['username'], 'avatar' => $avatar, 'avatar_small' => $avatar_small); }
public static function prepareTemplates() { $arr = array('body', 'body_plain', 'footer', 'footer_plain', 'header', 'header_plain'); $templates = array(); foreach ($arr as $template) { $template_body = file_get_contents(Config::need('base_path') . 'email_templates' . DIRECTORY_SEPARATOR . $template . '.php'); $templates[$template] = $template_body; } self::$templates = $templates; }
public function getPeriodItem($year, $j, $period) { $out['n'] = $j; if (isset($this->books[$year][$j])) { $out['bid'] = $this->books[$year][$j]; $out['path'] = Config::need('www_path') . '/book/' . $this->books[$year][$j]; } else { $out['path'] = Config::need('www_path') . '/book/new?year=' . $year . '&n=' . $j . '&m=' . $this->id; } return $out; }
function getContentFilePath($id, $pf = '') { if ($pf == 'medium') { $ext = 'gif'; } else { $ext = 'gif'; } if ($pf) $pf = '_' . $pf; $filename = Config::need('static_path') . DIRECTORY_SEPARATOR . 'upload/pictures/' . $id . $pf . '.' . $ext; return $filename; }
public function getHTML($xml) { global $current_user; Log::timingplus('XSLTProcessor'); $xslTemplate = new DOMDocument(); $xslProcessor = new XSLTProcessor(); $filename = Config::need('xslt_files_path') . DIRECTORY_SEPARATOR . $current_user->getTheme() . DIRECTORY_SEPARATOR . $this->xsltFileName; $xslTemplate->load($filename, LIBXML_NOENT | LIBXML_DTDLOAD); $xslProcessor->importStyleSheet($xslTemplate); $html = $xslProcessor->transformToXML($xml); Log::timingplus('XSLTProcessor'); return $html; }
function _upsert($data) { $q = array(); foreach ($data as $field => $value) { $q[] = '`' . $field . '`=' . Database::escape($value); } if (count($q)) { Database::query('INSERT INTO `feature_groups` SET ' . implode(',', $q) . ' ON DUPLICATE KEY UPDATE ' . implode(',', $q)); } @ob_end_clean(); header('Location: ' . Config::need('www_path') . '/features'); exit(0); }
function saveSettings() { require_once $filename = dirname(Config::need('xslt_files_path')) . '/localconfig.php'; global $local_config; $query = 'SELECT * FROM `settings`'; $arr = Database::sql2array($query); $local_config['-----------------'] = '-----------------'; foreach ($arr as $setting) { $local_config[$setting['name']] = $setting['value']; } $s = var_export($local_config, true); file_put_contents($filename, '<?php $local_config = ' . $s . ";\n" . '//some settings generated by setting module'); }
function add_album_relation_link() { $album_id = $_POST['album_id']; $role = $_POST['role']; Database::query('INSERT INTO `album_invites` SET `album_id`=' . $album_id . ', `inviter_user_id `=' . CurrentUser::$id . ', `family_role`=' . $role); $uniqid = Database::lastInsertId(); $data = array(); $data['link'] = 'http://' . Config::need('www_domain') . '/invite/' . $album_id . '/' . $role . '/' . md5($uniqid); return $data; }
public function process() { global $current_user; /* @var $current_user CurrentUser */ XMLClass::$pageNode = XMLClass::createNodeFromObject(array(), false, 'page', false); XMLClass::appendNode(XMLClass::$pageNode, ''); XMLClass::$pageNode->setAttribute('current_url', Request::$url); XMLClass::$pageNode->setAttribute('prefix', Config::need('www_path') . '/'); XMLClass::$varNode = XMLClass::$xml->createElement('variables'); foreach (Request::$get_normal as $f => $v) { XMLClass::$varNode->setAttribute($f, $v); } XMLClass::$pageNode->appendChild(XMLClass::$varNode); XMLClass::$rootNode->appendChild(XMLClass::$xml->importNode(StructureParser::toXML(), 1)); if ($current_user->authorized) { XMLClass::$CurrentUserNode = XMLClass::createNodeFromObject($current_user->getXMLInfo(), false, 'current_user', false); } else XMLClass::$CurrentUserNode = XMLClass::createNodeFromObject(array(), false, 'current_user', false); XMLClass::$pageNode->appendChild(XMLClass::$CurrentUserNode); // втыкаем модули страницы $role = $current_user->getRole(); foreach ($this->modules as $module) { $this->processModule($module['name'], $module); } if ($pageTitle = StructureParser::getTitle()) { $this->buildPageTitle($pageTitle); } switch (Request::$responseType) { case 'xml':case 'xmlc': return XMLClass::dumpToBrowser(); break; case 'xsl':case 'xslc': $xslTemplateClass = new XSLClass($this->xsltFileName); return $xslTemplateClass->dumpToBrowser(); break; case 'html': $xslTemplateClass = new XSLClass($this->xsltFileName); $html = $xslTemplateClass->getHTML(XMLClass::$xml); return $html; break; default: return XMLClass::dumpToBrowser(); break; } }
public function authorize_cookie() { $auth_cookie_name = Config::need('auth_cookie_hash_name'); $auth_uid_name = Config::need('auth_cookie_id_name'); if (isset($_COOKIE[$auth_cookie_name]) && isset($_COOKIE[$auth_uid_name])) { $query = 'SELECT `session`,`expires` FROM `users_session` WHERE `user_id`=' . (int) $_COOKIE[$auth_uid_name]; $row = Database::sql2row($query); if ($row) { if ($row['session'] == $_COOKIE[$auth_cookie_name] && $row['expires'] > time()) { $this->id = (int) $_COOKIE[$auth_uid_name]; $this->load(); $this->authorized = true; } } }else return false; }
function getRatingMenu() { $current_sf = Request::$structureFile; if ($current_sf == 'main.xml') { $current_sf = 'rating/synthesis.xml'; } $menu = array(array('name' => 'synthesis', 'title' => 'Сводный рейтинг', 'path' => Config::need('www_path') . '/synthesis/', 'xml' => 'rating/synthesis.xml'), array('name' => 'visits', 'title' => 'По посещаемости', 'path' => Config::need('www_path') . '/visits/', 'xml' => 'rating/visits.xml'), array('name' => 'comments', 'title' => 'По комментариям', 'path' => Config::need('www_path') . '/comments/', 'xml' => 'rating/comments.xml'), array('name' => 'links', 'title' => 'По ссылкам', 'path' => Config::need('www_path') . '/links/', 'xml' => 'rating/links.xml')); foreach ($menu as &$item) { if ($current_sf == $item['xml']) { $item['class'] = 'selected'; } else { $item['class'] = ''; } } $this->data['menu'] = $menu; }
public static function setPartnerCookie($id_partner) { global $current_user; /* @var $current_user CurrentUser */ if ($id_partner) { $query = 'SELECT `id` FROM `partners` WHERE `pid`=' . Database::escape($id_partner); $pid = Database::sql2single($query); if ($pid) { if ($current_user) { $time = Config::need('cookie_lifetime_partner', 5 * 60 * 60 * 24); $current_user->setCookie('partner_id', $pid, time() + $time); } header('Location: ' . Request::$url, true, 302); } } }
public static function findLastEventByType($user_id, $type, $additionalCriteria = array()) { $time = time() - Config::need('event_freeze_time', 10 * 60 * 60); $attributes = array('user_id' => (int) $user_id, 'type' => $type, 'time' => array('$gt' => $time)); foreach ($additionalCriteria as $f => $v) { $attributes[$f] = $v; } $order = array('time' => -1); $result = self::getInstance()->events->find($attributes)->sort($order)->limit(1); if ($result) { foreach ($result as $res) { return array($res['_id']->{'$id'}, $res); } } else { return array(false, false); } }
function upload_post_main_image($data) { try { $cover_sizes = array(array(150, 150, false), array(400, 400, true)); $content = $data['text']; $urls = array(); preg_match_all("/(<img )(.+?)( \\/)?(>)/", $content, $images); foreach ($images[2] as $val) { if (preg_match("/(src=)('|\")(.+?)('|\")/", $val, $matches) == 1) { $urls[$matches[3]] = $matches[3]; } } if (count($urls)) { foreach ($urls as $url) { $imgdata = grab($url); $tmp_name = '/tmp/image.jpg'; file_put_contents($tmp_name, $imgdata); $size = getimagesize($tmp_name); if ($size) { if ($size[0] >= 150) { if ($size[1] >= 150) { $folder = Config::need('static_path') . 'upload/post_images/' . $data['id']; $filename = $folder . '/' . $data['id'] . '_' . $data['id_author'] . '.jpg'; $filename_o = $folder . '/' . $data['id'] . '_' . $data['id_author'] . '_big.jpg'; mkdir($folder); $thumb = new Thumb(); try { $thumb->createThumbnails($tmp_name, array($filename, $filename_o), $cover_sizes); } catch (Exception $e) { return false; } unlink($tmp_name); return true; } } } else { unlink($tmp_name); } } } return false; } catch (Exception $e) { return false; } }
/** * Создаем тело письма из массива переменных и XSL шаблона * * @param array $data any data * @param string $template filename from xslt/theme/mail/ folder * @return text тело письма */ private static function createBody($data, $template) { global $current_user; $xml = new DOMDocument(); $xml->loadXML("<xml version=\"1.0\" encoding=\"utf-8\" >" . "<root></root></xml>"); $rootNode = $xml->getElementsByTagName("root")->item(0); $dataNode = $xml->createElement('data'); foreach ($data as $f => $v) { $dataNode->setAttribute($f, $v); } $rootNode->appendChild($dataNode); $template = file_get_contents(Config::need('xslt_files_path') . '/' . $current_user->getTheme() . '/mail/' . $template); $doc = new DOMDocument(); $xsl = new XSLTProcessor(); $doc->loadXML($template); $xsl->importStyleSheet($doc); // кладем в кеш xslt return $xsl->transformToXML($xml); }
function write() { global $current_user; /* @var $current_user CurrentUser */ if ($current_user->authorized) { $mask = array('id' => 'int', 'bday' => 'string', 'city_id' => 'int', 'link_fb' => array('type' => 'string', '*' => true), 'link_vk' => array('type' => 'string', '*' => true), 'link_lj' => array('type' => 'string', '*' => true), 'link_tw' => array('type' => 'string', '*' => true), 'quote' => array('type' => 'string', '*' => true), 'about' => array('type' => 'string', '*' => true)); $params = Request::checkPostParameters($mask); if ($current_user->id == $params['id']) { //avatar if (isset($_FILES['picture']) && $_FILES['picture']['tmp_name']) { $filename = Config::need('avatar_upload_path') . '/' . $current_user->id . '.jpg'; $upload = new UploadAvatar($_FILES['picture']['tmp_name'], 100, 100, "simple", $filename); if ($upload->out) { $current_user->setProperty('picture', 1); } else { throw new Exception('cant copy file to ' . $filename, 100); } } //bday $current_user->setProperty('bday', max(0, (int) @strtotime($params['bday']))); // city $current_user->setProperty('city_id', $params['city_id']); // facebook etc $current_user->setPropertySerialized('link_fb', $params['link_fb']); $current_user->setPropertySerialized('link_vk', $params['link_vk']); $current_user->setPropertySerialized('link_tw', $params['link_tw']); $current_user->setPropertySerialized('link_lj', $params['link_lj']); $params['quote'] = htmlspecialchars($params['quote']); $params['about'] = htmlspecialchars($params['about']); $current_user->setPropertySerialized('quote', $params['quote']); $current_user->setPropertySerialized('about', $params['about']); $current_user->save(); // после редактирования профиля надо посбрасывать кеш со страницы профиля // и со страницы редактирования профиля // кеш в остальных модулях истечет сам Cache::drop(Request::$pageName . '_ProfileModule_' . $current_user->id, Cache::DATA_TYPE_XML); //xmlthemeDefault_ru_user_ProfileModule Cache::drop(Request::$pageName . '_ProfileModule_' . $current_user->id . 'edit', Cache::DATA_TYPE_XML); //xmlthemeDefault_ru_user_ProfileModule_19 } } }
function getPicture($id = false) { if (!$id) $id = isset($this->params['id']) ? (int) $this->params['id'] : false; if (!$id) { throw new Exception('illegal picture id #' . $id); } $query = 'SELECT * FROM `content_pictures` WHERE `id`=' . $id; $data = Database::sql2row($query); if (!$data) return; $data['time'] = date('Y/m/d H:i', $data['time']); $this->data['picture'] = $data; $this->data['picture']['source'] = $this->getPicUrl($data['id'], 'medium'); $this->data['picture']['link_url'] = Config::need('www_path') . '/pictures/' . $data['id']; $tags = Database::sql2array('SELECT `id_tag`,`title` FROM `content_pictures_tags` CPT LEFT JOIN `tags` T ON T.id = CPT.id_tag WHERE CPT.`id_content_picture`=' . $id); $this->data['picture']['tags'] = $tags; $this->setPageTitle($data['title'] . ' — Жмячне картинки'); }
public static function authorize_cookie() { $cookie_key = Config::need('COOKIE_KEY', 'u'); $hash_coookie_key = $cookie_key . '_sh'; $uid_coookie_key = $cookie_key . '_id'; if (isset($_COOKIE[$uid_coookie_key]) && isset($_COOKIE[$hash_coookie_key])) { $user_id = $_COOKIE[$uid_coookie_key]; $user = Users::getByIdLoaded($user_id); if (!$user) { return false; } if ($user->data['session'] == $_COOKIE[$hash_coookie_key]) { self::$id = $user_id; Database::query('UPDATE `user` SET `lastAccessTime`=' . time() . ' WHERE `id`=' . $user_id); self::$authorized = true; return true; } } else { return false; } }
function th_process_block($block) { global $data; global $write; if (isset($data[$block])) { echo "\n<!--block " . $block . '-->' . "\n"; foreach ($data[$block] as $module) { echo "\n<!--" . $module['module'] . '/' . $module['action'] . '/' . $module['mode'] . '-->' . "\n"; $funcName = 'tp_' . $module['module'] . '_' . $module['action'] . '_' . $module['mode']; Log::timing('template [' . $funcName . ']'); require_once Config::need('templates_root') . '/modules/' . $module['module'] . '.php'; if (function_exists($funcName)) { th_before_process_block($module['result'], $write); eval('echo ' . $funcName . '($module[\'result\']);'); th_after_process_block($module['result']); } else { echo 'missed function ' . $funcName . '($data) '; } Log::timing('template [' . $funcName . ']'); } } }
function newThread() { global $current_user; /* @var $current_user CurrentUser */ $title = Request::post('title'); $message = Request::post('message'); $message = prepare_review($message); $forum_id = Request::post('tid'); if (!$message || !$title) { throw new Exception('fill all fields properly'); } if (!$forum_id) { throw new Exception('illegal forum id'); } if ($current_user->can_throw('books_edit')) { $nid = $this->doNewThread($title, $message, $current_user->id, $forum_id, time()); if ($nid) { @ob_end_clean(); header('Location:' . Config::need('www_path') . '/forum/' . $forum_id . '/' . $nid); } } }
function addPost() { global $current_user; if (!$current_user->id) { return; } $body = isset(Request::$post['body']) ? Request::$post['body'] : false; $subject = isset(Request::$post['subject']) ? Request::$post['subject'] : false; $body = prepare_review($body); $subject = prepare_review($subject, ''); if (!$body) { throw new Exception('post body missed'); } if ($body) { $event = new Event(); $event->event_PostAdd($current_user->id, $body, $subject); $event->push(); ob_end_clean(); header('Location: ' . Config::need('www_path') . '/me/wall/self'); exit; } }
function _update() { $data = array('id' => isset(Request::$post['id']) ? prepare_review(Request::$post['id'], '') : false, 'title' => isset(Request::$post['title']) ? prepare_review(Request::$post['title'], '') : false, 'description' => isset(Request::$post['description']) ? prepare_review(Request::$post['description']) : false, 'filepath' => isset(Request::$post['filepath']) ? prepare_review(Request::$post['filepath'], '') : false, 'group_id' => isset(Request::$post['group_id']) ? (int) Request::$post['group_id'] : false, 'db_modify' => time()); if ($data['title'] && $data['id']) { Features::getInstance()->getByIdLoaded($data['id'])->_update($data); } if ($data['description']) { // пишем в файл $f = '../features/' . Features::getInstance()->getByIdLoaded($data['id'])->getFilePath(); if (!file_exists($f)) { @mkdir('../features/' . Features::getInstance()->getByIdLoaded($data['id'])->getFolder()); file_put_contents($f, $data['description']); $file_modify = @filemtime($f); clearstatcache(); $query = 'UPDATE `features` SET `file_modify` = ' . $file_modify . ' WHERE `id`=' . $data['id']; Database::query($query); } else { $file_modify = @filemtime($f); if ($file_modify > Request::post('file_modify')) { // файл новее чем в базе $query = 'UPDATE `features` SET `file_modify` = ' . $file_modify . ' WHERE `id`=' . $data['id']; Database::query($query); throw new Exception(date('Y-m-d H:i:s') . ' File was modified at ' . date('Y-m-d H:i:s', $file_modify) . ', fetched version is ' . date('Y-m-d H:i:s', Request::post('file_modify')) . '. Please refresh page'); } else { file_put_contents($f, $data['description']); clearstatcache(); $file_modify = @filemtime($f); clearstatcache(); $query = 'UPDATE `features` SET `file_modify` = ' . $file_modify . ' WHERE `id`=' . $data['id']; Database::query($query); } } } @ob_end_clean(); header('Location: ' . Config::need('www_path') . '/features'); exit(0); }
<?php $root = Config::need('base_path'); require_once $root . '/functions/functions.php'; $includePathes = array($root, $root . 'core', $root . 'modules', $root . 'modules/write', $root . 'jmodules', $root . 'classes/User', $root . 'classes/Book', $root . 'classes', $root . 'functions', $root . 'phplib'); set_include_path(get_include_path() . PATH_SEPARATOR . implode(PATH_SEPARATOR, $includePathes)); function __autoload($className) { require_once $className . '.php'; }