Example #1
0
 /**
  * Запуск периодических задач.
  *
  * Проверяется время последнего запуска, чаще установленного администратором
  * времени запуск производиться не будет (по умолчанию 15 минут).
  */
 public static function on_rpc(Context $ctx)
 {
     $status = "DELAYED";
     $lastrun = $ctx->config->get('modules/cron/lastrun');
     $delay = $ctx->config->get('modules/cron/delay', 15) * 60;
     if (time() >= $lastrun + $delay) {
         $ctx->config->set('modules/cron/lastrun', time());
         $ctx->config->save();
         @set_time_limit(0);
         ob_start();
         try {
             $ctx->registry->broadcast('ru.molinos.cms.cron', array($ctx));
             $status = "OK";
         } catch (Exception $e) {
             Logger::trace($e);
             $status = "ERROR: " . get_class($e) . '; ' . trim($e->getMessage(), '.') . '.';
         }
         ob_end_clean();
     }
     if ($ctx->get('destination')) {
         return $ctx->getRedirect();
     }
     if (!MCMS_CONSOLE) {
         header('Content-Type: text/plain; charset=utf-8');
         die($status);
     }
     die;
 }
Example #2
0
 /**
  * Вывод формы авторизации.
  * @route GET//login
  */
 public static function on_get_login_form(Context $ctx)
 {
     if ($ctx->user->id and !$ctx->get('stay')) {
         return $ctx->getRedirect();
     }
     if (class_exists('APIStream')) {
         APIStream::init($ctx);
     }
     $handler = array('theme' => $ctx->config->get('modules/auth/login_theme'));
     $content = '';
     foreach ((array) $ctx->registry->poll('ru.molinos.cms.page.head', array($ctx, $handler, null), true) as $block) {
         if (!empty($block['result'])) {
             $content .= $block['result'];
         }
     }
     $content .= self::getXML($ctx);
     $xml = html::em('page', array('status' => 401, 'base' => $ctx->url()->getBase($ctx), 'host' => MCMS_HOST_NAME, 'prefix' => os::webpath(MCMS_SITE_FOLDER, 'themes'), 'back' => urlencode(MCMS_REQUEST_URI), 'next' => $ctx->get('destination'), 'api' => APIStream::getPrefix(), 'query' => $ctx->query()), $content);
     if (file_exists($xsl = os::path(MCMS_SITE_FOLDER, 'themes', $handler['theme'], 'templates', 'login.xsl'))) {
         try {
             return xslt::transform($xml, $xsl);
         } catch (Exception $e) {
         }
     }
     return xslt::transform($xml, 'lib/modules/auth/xsl/login.xsl');
 }
Example #3
0
 /**
  * Открепление файлов от ноды.
  */
 public static function on_post_detach(Context $ctx)
 {
     if (is_array($ids = $ctx->post('remove'))) {
         $ctx->db->beginTransaction();
         $params = array();
         Node::load($ctx->get('id'), $ctx->db)->touch(ACL::UPDATE)->onSave('DELETE FROM `node__rel` WHERE `tid` = %ID% AND `key` IS NULL AND `nid` ' . sql::in($ids, $params), $params)->save();
         $ctx->db->commit();
     }
     return $ctx->getRedirect();
 }
Example #4
0
 private static function goNext(Context $ctx)
 {
     if ($ctx->method('post')) {
         foreach ($ctx->post('next', array()) as $k => $v) {
             if (!empty($v) and null !== $ctx->post($k)) {
                 return new Redirect($v);
             }
         }
     }
     return $ctx->getRedirect();
 }
Example #5
0
 public static function on_post_manage(Context $ctx)
 {
     if (!($nid = $ctx->get('id'))) {
         throw new BadRequestException(t('Не указан идентификатор метки (GET-параметр id).'));
     }
     $params = array($nid);
     $sql = "DELETE FROM `node__rel` WHERE `tid` = ? AND `nid` " . sql::notin($ctx->post('apply'), $params);
     $ctx->db->beginTransaction();
     $ctx->db->exec($sql, $params);
     $ctx->db->commit();
     return $ctx->getRedirect();
 }
 /**
  * Изменяет список разделов, разрешённых для ноды.
  */
 public static function on_post_setup(Context $ctx)
 {
     if (!($node = $ctx->get('node'))) {
         throw new BadRequestException();
     }
     $ctx->db->beginTransaction();
     $ctx->db->exec("DELETE FROM `node__rel` WHERE `nid` = ? AND `tid` IN (SELECT `id` FROM `node` WHERE `class` = 'tag')", array($node));
     $params = array($node);
     $sql = "INSERT INTO `node__rel` (`tid`, `nid`) SELECT `id`, ? FROM `node` WHERE `id` " . sql::in($ctx->post('selected'), $params);
     $ctx->db->exec($sql, $params);
     $ctx->db->commit();
     return $ctx->getRedirect();
 }
Example #7
0
 /**
  * Сброс кэша.
  */
 public static function rpc_get_reload(Context $ctx)
 {
     $tmpdir = $ctx->config->getPath('main/tmpdir');
     $files = glob(os::path($tmpdir, 'mcms-fetch.*'));
     if (!empty($files)) {
         foreach ($files as $tmp) {
             unlink($tmp);
         }
     }
     $ctx->registry->broadcast('ru.molinos.cms.reload', array($ctx));
     $ctx->registry->rebuild();
     unset(cache::getInstance()->route);
     return $ctx->getRedirect();
 }
 protected static function rpc_get_remove(Context $ctx)
 {
     $name = $ctx->get('name');
     try {
         $node = Node::load(array('class' => 'subscription', 'name' => $name, 'deleted' => 0, 'published' => 1));
         if (empty($node) or $node->id != $ctx->get('id')) {
             throw new PageNotFoundException();
         }
         $ctx->db->beginTransaction();
         $node->delete();
         $ctx->db->commit();
     } catch (ObjectNotFoundException $e) {
     }
     return $ctx->getRedirect('?unsubscribed=' . urlencode($name));
 }
Example #9
0
 /**
  * Перемещает файл в S3.
  */
 public static function on_move_to_s3(Context $ctx)
 {
     $node = Node::load($ctx->get('node'), $ctx->db);
     if (file_exists($fileName = $node->getRealURL())) {
         if ($url = self::moveFileToS3($fileName, null, $node->id . '/' . $node->filename)) {
             $ctx->db->beginTransaction();
             $node->remoteurl = $url;
             $node->save();
             $ctx->db->commit();
             unlink($fileName);
         }
     } else {
         Logger::log('file not found: ' . $fileName, 's3');
     }
     return $ctx->getRedirect();
 }
Example #10
0
 public static function on_vote(Context $ctx)
 {
     if (!$ctx->get('id')) {
         throw new InvalidArgumentException(t('Не указан номер опроса (GET-параметр nid).'));
     }
     $votes = $ctx->post('vote');
     $ctx->db->beginTransaction();
     if (is_array($votes)) {
         foreach ($votes as $i => $vote) {
             $ctx->db->exec("INSERT INTO `node__poll` (`nid`, `uid`, `ip`, `option`) VALUES (:nid, :uid, :ip, :option)", array(':nid' => $ctx->get('id'), ':uid' => $ctx->user->id, ':ip' => $_SERVER['REMOTE_ADDR'], ':option' => $vote));
         }
     } else {
         $ctx->db->exec("INSERT INTO `node__poll` (`nid`, `uid`, `ip`, `option`) VALUES (:nid, :uid, :ip, :option)", array(':nid' => $ctx->get('id'), ':uid' => $ctx->user->id, ':ip' => $_SERVER['REMOTE_ADDR'], ':option' => $votes));
     }
     $ctx->db->commit();
     return $ctx->getRedirect();
 }
 public static function on_post_sendto(Context $ctx)
 {
     if ($pick = $ctx->post('selected')) {
         if (false === strpos($ctx->post('sendto'), '.')) {
             list($nid, $fieldName) = array($ctx->post('sendto'), null);
         } else {
             list($nid, $fieldName) = explode('.', $ctx->post('sendto'));
         }
         $params = array($fieldName);
         $sql = "REPLACE INTO `node__rel` (`tid`, `nid`, `key`) SELECT %ID%, `id`, ? FROM `node` WHERE `deleted` = 0 AND `id` " . sql::in($pick, $params);
         $ctx->db->beginTransaction();
         $node = Node::load($nid)->knock(ACL::UPDATE);
         if (isset($node->{$fieldName})) {
             unset($node->{$fieldName});
         }
         $node->onSave("DELETE FROM `node__rel` WHERE `tid` = %ID% AND `key` = ?", array($fieldName))->onSave($sql, $params)->save();
         $ctx->db->commit();
         // destiantion сейчас указывает на список, а нам надо
         // вернуться на уровень выше.
         $url = new url($ctx->get('destination'));
         if ($next = $url->arg('destination')) {
             $ctx->redirect($next);
         }
     }
     return $ctx->getRedirect();
 }
Example #12
0
 public static function on_reload(Context $ctx)
 {
     modman::updateDB();
     return $ctx->getRedirect();
 }
Example #13
0
 /**
  * Выход, завершение сеанса.
  * 
  * @param Context $ctx 
  * @return Response
  */
 public static function rpc_get_logout(Context $ctx)
 {
     $uid = null;
     $stack = (array) mcms::session('uidstack');
     $uid = array_pop($stack);
     mcms::session('uidstack', $stack);
     if (empty($uid)) {
         $ctx->user->logout();
     } else {
         self::login($uid);
     }
     $next = $uid ? $ctx->get('from', '') : '';
     return $ctx->getRedirect($next);
 }
 /**
  * Открепляет файл от документа.
  */
 public static function on_unlink_from_node(Context $ctx)
 {
     $ctx->db->beginTransaction();
     $ctx->db->exec("DELETE FROM `node__rel` WHERE `tid` = ? AND `nid` = ? AND `key` = ?", array($ctx->get('node'), $ctx->get('file'), $ctx->get('field')));
     // Пересохраняем ноду, чтобы сработали обработчики изменения, вроде индексатора.
     Node::load($ctx->get('node'), $ctx->db)->touch()->save();
     $ctx->db->commit();
     return $ctx->getRedirect();
 }
Example #15
0
 /**
  * Изменение прав на разделы.
  * @route POST//api/taxonomy/access.rpc
  */
 public static function on_post_access(Context $ctx)
 {
     $ctx->user->checkAccess(ACL::UPDATE, 'tag');
     if ($sections = (array) $ctx->post('sections')) {
         $publishers = $ctx->post('publishers');
         $owners = $ctx->post('owners');
         $ctx->db->beginTransaction();
         ACL::resetNode($sections);
         foreach ($sections as $nid) {
             if ($publishers == $owners) {
                 ACL::set($nid, $owners, ACL::CREATE | ACL::READ | ACL::UPDATE | ACL::DELETE | ACL::PUBLISH);
             } else {
                 ACL::set($nid, $publishers, ACL::PUBLISH);
                 ACL::set($nid, $owners, ACL::CREATE | ACL::READ | ACL::UPDATE | ACL::DELETE);
             }
         }
         $ctx->db->commit();
     }
     return $ctx->getRedirect('admin/access/taxonomy');
 }
Example #16
0
 /**
  * Изменение прав.
  * @route POST//admin/structure/access
  */
 public static function on_post_access(Context $ctx)
 {
     if (!Node::create('type')->checkPermission(ACL::UPDATE)) {
         throw new ForbiddenException();
     }
     // Если объект не существует, выбросится 404.
     $node = Node::load(array('class' => 'type', 'name' => $ctx->get('type'), 'deleted' => 0));
     $ctx->db->beginTransaction();
     foreach ($ctx->post as $gid => $data) {
         ACL::set($node->id, intval($gid), ACL::asint($data));
     }
     $ctx->db->commit();
     return $ctx->getRedirect();
 }