Exemple #1
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();
 }
Exemple #2
0
 /**
  * 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();
 }
Exemple #3
0
 /**
  * Delete menu
  */
 public function delete()
 {
     $this->modified = false;
     CMS::getDB()->query("DELETE FROM `cms_menu` WHERE `id`=?", [$this->id]);
     self::clearCache();
 }
Exemple #4
0
 /**
  * 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;
 }
Exemple #5
0
 /**
  * Delete snippet
  * @throws Exception
  */
 public function del()
 {
     $this->isModified = false;
     CMS::getDB()->query('DELETE FROM `cms_snippets` WHERE `id`=?', [$this->id]);
 }