示例#1
0
文件: menu.php 项目: difra-org/difra
 /**
  * @param \DOMNode|\DOMElement $node
  * @param int $menuId
  */
 private function getEditXML($node, $menuId)
 {
     $menu = \Difra\Plugins\CMS\Menu::get($menuId);
     $node->setAttribute('depth', $menu->getDepth());
     $parentsNode = $node->appendChild($this->xml->createElement('parents'));
     \Difra\Plugins\CMS::getInstance()->getMenuItemsXML($parentsNode, $menu->getId());
 }
示例#2
0
 /**
  * Move element down
  */
 public function moveDown()
 {
     $this->load();
     $db = CMS::getDB();
     $values = ['menu' => $this->menu];
     if ($this->parent) {
         $parentCondition = '`parent`=:parent';
         $values['parent'] = $this->parent;
     } else {
         $parentCondition = '`parent` IS NULL';
     }
     $items = CMS::getDB()->fetch("SELECT `id`,`position` FROM `cms_menu_items`\n              WHERE `menu`=:menu AND {$parentCondition}\n              ORDER BY `position`", $values);
     $newSort = [];
     $pos = 1;
     $next = false;
     foreach ($items as $item) {
         if ($item['id'] != $this->id) {
             $newSort[$item['id']] = $pos++;
             if ($next) {
                 $newSort[$next['id']] = $pos++;
                 $next = false;
             }
         } else {
             $next = $item;
         }
     }
     if ($next) {
         $newSort[$next['id']] = $pos;
     }
     $db->beginTransaction();
     try {
         foreach ($newSort as $id => $pos) {
             $db->query("UPDATE `cms_menu_items` SET `position`=:pos WHERE `id`=:id", ['id' => $id, 'pos' => $pos]);
         }
     } catch (\PDOException $e) {
         $db->rollBack();
         throw new Exception('PDO Exception: ' . $e->getMessage());
     }
     $db->commit();
     $this->clearCache();
 }
示例#3
0
文件: pages.php 项目: difra-org/difra
 /**
  * Pages list
  */
 public function indexAction()
 {
     $listNode = $this->root->appendChild($this->xml->createElement('CMSList'));
     \Difra\Plugins\CMS::getInstance()->getListXML($listNode);
 }
示例#4
0
 /**
  * @return array|bool
  */
 public function getSitemap()
 {
     return CMS::getSitemap();
 }
示例#5
0
文件: Page.php 项目: difra-org/difra
 /**
  * Delete page
  */
 public function delete()
 {
     $this->loaded = true;
     $this->modified = false;
     if ($this->id) {
         $path = DIR_DATA . 'cms/img/' . $this->id;
         if (is_dir($path)) {
             $dir = opendir($path);
             while (false !== ($file = readdir($dir))) {
                 if ($file[0] == '.') {
                     continue;
                 }
                 /** @noinspection PhpUsageOfSilenceOperatorInspection */
                 @unlink("{$path}/{$file}");
             }
             rmdir($path);
         }
     }
     CMS::getDB()->query("DELETE FROM `cms` WHERE `id`=?", [$this->id]);
     self::cleanCache();
 }
示例#6
0
文件: CMS.php 项目: difra-org/difra
 /**
  * Get URL list for sitemap
  * @return array|false
  */
 public static function getSitemap()
 {
     $data = CMS::getDB()->fetch('SELECT `tag`,date_format(`modified`,\'%Y-%m-%d\') AS `modified` FROM `cms` WHERE `hidden`=0');
     $res = [];
     if (empty($data)) {
         return false;
     }
     foreach ($data as $t) {
         $rec = ['loc' => $t['tag']];
         if (!empty($t['modified'])) {
             $rec['lastmod'] = $t['modified'];
         }
         $res[] = $rec;
     }
     return $res;
 }
示例#7
0
文件: Menu.php 项目: difra-org/difra
 /**
  * Delete menu
  */
 public function delete()
 {
     $this->modified = false;
     CMS::getDB()->query("DELETE FROM `cms_menu` WHERE `id`=?", [$this->id]);
     self::clearCache();
 }
示例#8
0
 /**
  * Delete snippet
  * @throws Exception
  */
 public function del()
 {
     $this->isModified = false;
     CMS::getDB()->query('DELETE FROM `cms_snippets` WHERE `id`=?', [$this->id]);
 }