示例#1
0
 /**
  * Добавление произвольных файлов в XML ноды.
  * @mcms_message ru.molinos.cms.node.xml
  */
 public static function on_get_node_xml(Node $node)
 {
     if ($node instanceof FileNode) {
         return;
     }
     return html::wrap('files', Node::findXML(array('class' => 'file', 'deleted' => 0, 'id' => $node->getDB()->getResultsV("nid", "SELECT `nid` FROM `node__rel` WHERE `tid` = ? AND `key` IS NULL", array($node->id))), $node->getDB()));
 }
 /**
  * @mcms_message ru.molinos.cms.hook.node
  */
 public static function hookNodeUpdate(Context $ctx, Node $node, $op)
 {
     switch ($op) {
         case 'delete':
             $node->onSave("UPDATE `node` SET `deleted` = 1 WHERE `class` = 'comment' AND `id` IN (SELECT `nid` FROM `node__rel` WHERE `tid` = %ID%");
             break;
         case 'erase':
             $node->onSave("DELETE FROM `node` WHERE `class` = 'comment' AND `id` IN (SELECT `nid` FROM `node__rel` WHERE `tid` = %ID%)");
             break;
         case 'create':
             if (!empty($node->doc) and is_numeric($nid = Node::_id($node->doc))) {
                 // Собираем прикреплённых пользователей.
                 $l1 = $node->getDB()->getResultsV("nid", "SELECT `nid` " . "FROM `node__rel` WHERE `tid` = ? AND `nid` IN (SELECT `id` " . "FROM `node` WHERE `class` = 'user')", array($nid));
                 // Собираем пользователей, комментировавших ранее
                 $l2 = $node->getDB()->getResultsV("uid", "SELECT `n`.`uid` " . "FROM `node` `n` " . "INNER JOIN `node__rel` `r` ON `r`.`nid` = `n`.`id` " . "WHERE `r`.`tid` = ? AND `n`.`class` = 'comment'", array($nid));
                 $uids = array_diff(array_unique(array_merge($l1, $l2)), array($ctx->user->id));
                 $body = mcms::render(__CLASS__, array('mode' => 'new', 'comment' => $node->getRaw()));
                 if (!empty($body) and !empty($uids)) {
                     foreach ($uids as $uid) {
                         if (empty($node->doc)) {
                             $subject = t('Новый комментарий');
                         } else {
                             $subject = t('Новый комментарий [%id]', array('%id' => Node::_id($node->doc)));
                         }
                         mcms::mail(null, $uid, $subject, $body);
                     }
                 }
             }
     }
 }
示例#3
0
 /**
  * Обновляет XML при изменении объекта.
  * @mcms_message ru.molinos.cms.hook.node
  */
 public static function on_node_change(Context $ctx, Node $node, $op)
 {
     if ($parents = Node::getNodeParentIds($node->getDB(), $node->id)) {
         $params = array();
         $node->getDB()->exec($sql = "UPDATE `node` SET `xmltree` = NULL WHERE `id` " . sql::in($parents, $params));
         $upd = $node->getDB()->prepare("UPDATE `node` SET `xmltree` = ? WHERE `id` = ?");
         while ($id = array_pop($parents)) {
             $upd->execute(array(Node::load($id, $node->getDB())->getTreeXML(false), $id));
         }
     }
 }
示例#4
0
 /**
  * Возвращает список меток для документа.
  */
 protected function getLabelsFor(Node $node)
 {
     if (!$node->id) {
         return array();
     }
     return array_unique((array) $node->getDB()->getResultsKV('id', 'name', "SELECT `id`, `name` FROM `node` " . "WHERE `class` = 'label' AND `deleted` = 0 AND `id` " . "IN (SELECT `tid` FROM `node__rel` WHERE `nid` = ? AND `key` = ?)", array($node->id, $this->value . '*')));
 }
示例#5
0
 /**
  * Сборщик мусора.
  *
  * При удалении документов удаляет информацию о ревизии, связях и доступе к
  * удаляемому объекту.  Это позволяет отказаться от требования InnoDB и других
  * типов БД, занимающихся каскадным удалением автоматически.
  *
  * @mcms_message ru.molinos.cms.hook.node
  *
  * @return void
  */
 public static function hookNodeUpdate(Context $ctx, Node $node, $op)
 {
     switch ($op) {
         case 'erase':
             // Удаляем связи.
             $node->getDB()->exec("DELETE FROM `node__rel` WHERE `nid` = :nid OR `tid` = :tid", array(':nid' => $node->id, ':tid' => $node->id));
             break;
     }
 }
示例#6
0
 private static function get_ids(Node $node)
 {
     $ids = array($node->id);
     while (true) {
         $params = array();
         $sql = "SELECT DISTINCT `id` FROM `node` WHERE `deleted` = 0 AND `id` IN " . "(SELECT `tid` FROM `node__rel` WHERE `nid` " . sql::in($ids, $params) . ")" . " AND `id` " . sql::notIn($ids, $params);
         $rows = $node->getDB()->getResultsV("id", $sql, $params);
         if (empty($rows)) {
             break;
         }
         foreach ($rows as $id) {
             $ids[] = $id;
         }
     }
     $params = array();
     $ids = (array) $node->getDB()->getResultsV("id", "SELECT `id` FROM `node` WHERE `class` NOT IN ('tag', 'label') AND `id` " . sql::in($ids, $params), $params);
     return array_reverse($ids);
 }
 private static function reindexNode(Node $node)
 {
     return;
     $html = '';
     $schema = Schema::load($node->getDB(), $node->class);
     foreach ($schema['fields'] as $k => $v) {
         if (isset($node->{$k})) {
             $html .= '<strong>' . html::plain($v['label']) . '</strong>';
             $html .= '<div class=\'data\'>' . $node->{$k} . '</div>';
         }
     }
     $lang = empty($node->lang) ? 'en' : $node->lang;
     $html = "HTTP/1.0 200 OK\n" . "Content-Type: text/html; charset=utf-8\n" . "Content-Language: {$lang}\n\n" . "<html><head><title>{$node->name}</title></head>" . "<body><h1>{$node->name}</h1>{$html}</body></html>";
     try {
         $node->getDB()->exec('DELETE FROM `node__searchindex` WHERE `nid` = :nid', array(':nid' => $node->id));
         $node->getDB()->exec('INSERT INTO `node__searchindex` (`nid`, `url`, `html`) ' . 'VALUES (:nid, :url, :html)', array(':nid' => $node->id, ':url' => self::getNodeUrl($node), ':html' => $html));
     } catch (TableNotFoundException $e) {
     }
 }
示例#8
0
 /**
  * Добавляет в XML нод информацию о разделах.
  * @mcms_message ru.molinos.cms.node.xml
  */
 public static function on_node_xml(Node $node)
 {
     list($sql, $params) = Query::build(array('class' => 'tag', 'deleted' => 0, 'tagged' => $node->id))->getSelect(array('id', 'published', 'name', 'class'));
     $data = $node->getDB()->getResults($sql, $params);
     $result = '';
     foreach ($data as $row) {
         $result .= html::em('node', $row);
     }
     return html::wrap('taxonomy', $result);
 }
 /**
  * @mcms_message ru.molinos.cms.hook.node
  */
 public static function hookNodeUpdate(Context $ctx, Node $node, $op)
 {
     if ($op == 'erase') {
         $db = $node->getDB();
         if ('user' == $node->class) {
             $db->exec("DELETE FROM `node_rating` WHERE `nid` = :nid OR `uid` = :uid", array(':nid' => $node->id, ':uid' => $node->id));
         } else {
             $db->exec("DELETE FROM `node_rating` WHERE `nid` = :nid", array(':nid' => $node->id));
         }
     }
 }
示例#10
0
 /**
  * Добавляет информацию о разделах в предварительный просмотр.
  * @mcms_message ru.molinos.cms.hook.preview.xml
  */
 public static function on_preview_tags(Node $node)
 {
     if (!$node->checkPermission(ACL::UPDATE)) {
         return;
     }
     if ($data = $node->getDB()->getResultsKV("id", "name", "SELECT `id`, `name` FROM `node` WHERE `deleted` = 0 AND `class` = 'tag' AND `id` IN (SELECT `tid` FROM `node__rel` WHERE `nid` = ?)", array($node->id))) {
         $result = array();
         foreach ($data as $k => $v) {
             $result[] = html::em('a', array('href' => "admin/node/{$k}?destination=CURRENT"), html::plain($v));
         }
         $result = html::em('value', html::cdata(implode(', ', $result)));
         return html::em('field', array('html' => true, 'title' => t('Находится в разделах'), 'editurl' => "admin/structure/taxonomy/setup?node={$node->id}&destination=" . urlencode(MCMS_REQUEST_URI)), $result);
     }
 }
示例#11
0
 /**
  * Удаление прав при удалении объектов.
  * @mcms_message ru.molinos.cms.hook.node
  */
 public static function on_node_hook(Context $ctx, Node $node, $op)
 {
     if ('erase' == $op) {
         $node->getDB()->exec("DELETE FROM `node__access` WHERE `nid` = ? OR `uid` = ?", array($node->id, $node->id));
         self::flush();
     }
 }
示例#12
0
 private static function getNodeUrl(Node $node)
 {
     return 'http://' . $_SERVER['HTTP_HOST'] . '/node/' . $node->id . '/';
     $tag = $node->getDB()->getResults("SELECT `id`, `code` FROM `node` `n` " . "INNER JOIN `node__rel` `r` ON `r`.`tid` = `n`.`id` " . "WHERE `r`.`nid` = :nid AND `n`.`class` = 'tag' AND `n`.`deleted` = 0 AND `n`.`published` = 1", array(':nid' => $node->id));
     $tag = $tag[0]['id'];
     $url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $tag . '/' . $node->id . '/';
     return $url;
 }