示例#1
0
 public function add($parent_id = 1)
 {
     // check if trying to save
     if (get_request_method() == 'POST') {
         return $this->_add();
     }
     $data = Flash::get('post_data');
     $page = new Page($data);
     $page->parent_id = $parent_id;
     $page->status_id = Setting::get('default_status_id');
     $page->needs_login = Page::LOGIN_INHERIT;
     $page_parts = Flash::get('post_parts_data');
     if (empty($page_parts)) {
         // check if we have a big sister ...
         $big_sister = Record::findOneFrom('Page', 'parent_id=? ORDER BY id DESC', array($parent_id));
         if ($big_sister) {
             // get all is part and create the same for the new little sister
             $big_sister_parts = Record::findAllFrom('PagePart', 'page_id=? ORDER BY id', array($big_sister->id));
             $page_parts = array();
             foreach ($big_sister_parts as $parts) {
                 $page_parts[] = new PagePart(array('name' => $parts->name, 'filter_id' => Setting::get('default_filter_id')));
             }
         } else {
             $page_parts = array(new PagePart(array('filter_id' => Setting::get('default_filter_id'))));
         }
     }
     // display things ...
     $this->setLayout('backend');
     $this->display('page/edit', array('action' => 'add', 'page' => $page, 'tags' => array(), 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => $page_parts, 'layouts' => Record::findAllFrom('Layout')));
 }
示例#2
0
 /**
  * Action to add a page.
  *
  * @param int $parent_id The page id for the new page's parent. Defaults to page 1.
  * @return <type>
  */
 public function add($parent_id = 1)
 {
     // Check if trying to save.
     if (get_request_method() == 'POST') {
         return $this->_store('add');
     }
     // If not trying to save, display "Add page" view.
     $data = Flash::get('post_data');
     $page = new Page($data);
     $page->parent_id = $parent_id;
     $page->status_id = Setting::get('default_status_id');
     $page->needs_login = Page::LOGIN_INHERIT;
     $page_parts = Flash::get('post_parts_data');
     if (empty($page_parts)) {
         // Check if we have a big sister.
         $big_sister = Record::findOneFrom('Page', 'parent_id=? ORDER BY id DESC', array($parent_id));
         if ($big_sister) {
             // Get list of parts create the same for the new little sister
             $big_sister_parts = Record::findAllFrom('PagePart', 'page_id=? ORDER BY id', array($big_sister->id));
             $page_parts = array();
             foreach ($big_sister_parts as $parts) {
                 $page_parts[] = new PagePart(array('name' => $parts->name, 'filter_id' => Setting::get('default_filter_id')));
             }
         } else {
             $page_parts = array(new PagePart(array('filter_id' => Setting::get('default_filter_id'))));
         }
     }
     // Display actual view.
     $this->setLayout('backend');
     $this->display('page/edit', array('action' => 'add', 'csrf_token' => SecureToken::generateToken(BASE_URL . 'page/add'), 'page' => $page, 'tags' => array(), 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => $page_parts, 'layouts' => Record::findAllFrom('Layout')));
 }
示例#3
0
 function save()
 {
     $data = $_POST['redirect'];
     if (empty($data['url'])) {
         Flash::set('error', __('You have to specify a url!'));
         redirect(get_url('plugin/redirector/'));
     }
     if (empty($data['destination'])) {
         Flash::set('error', __('You have to specify a destination url!'));
         redirect(get_url('plugin/redirector/'));
     }
     if ($existing_redirect = Record::findOneFrom('RedirectorRedirects', 'url = \'' . ($data['url'] . '\''))) {
         Record::update('RedirectorRedirects', array('url' => $data['url'], 'destination' => $data['destination']), 'url = \'' . ($data['url'] . '\''));
     } else {
         $entry = new RedirectorRedirects($data);
         if (!$entry->save()) {
             Flash::set('error', __('There was a problem adding your redirect.'));
         } else {
             if ($error = Record::findOneFrom('Redirector404s', 'url = \'' . ($data['url'] . '\''))) {
                 $error->delete();
             }
             Flash::set('success', __('Redirect has been added!'));
         }
     }
     redirect(get_url('plugin/redirector/'));
 }
示例#4
0
 public function findBy($column, $value)
 {
     //$where = "{$column} = '{$value}'";
     $where = $column . "='?'";
     $userinfo = Record::findOneFrom('User', $where, array($value));
     if ($userinfo) {
         $this->setFromData($userinfo);
     }
 }
示例#5
0
 public static function deletePageTagRelationship($page_id, $tag_id)
 {
     // get the id of the tag
     $tag = Record::findOneFrom('Tag', 'id=?', array($tag_id));
     Record::deleteWhere('PageTag', 'page_id=? AND tag_id=?', array($page_id, $tag->id));
     $tag->count--;
     $tag->save();
     return true;
 }
示例#6
0
 public function findBy($column, $value)
 {
     //$where = "{$column} = '{$value}'";
     //$where = "id='?'";
     $where = "{$column} = '?'";
     $category_info = Record::findOneFrom('Category', $where, array($value));
     if ($category_info) {
         $this->setFromData($category_info);
     }
 }
示例#7
0
文件: tag.php 项目: ZerGabriel/cms-1
 /**
  * 
  * @param integer|Model_Page_Front $page_id
  * @param array $tags
  */
 public static function save_by_page($page_id, $tags)
 {
     if (is_string($tags)) {
         $tags = explode(Model_Tag::SEPARATOR, $tags);
     }
     $tags = array_unique(array_map('trim', $tags));
     $current_tags = Model_Page_Tag::find_by_page($page_id);
     if ($page_id instanceof Model_Page_Front) {
         $page_id = $page_id->id();
     }
     // no tag before! no tag now! ... nothing to do!
     if (empty($tags) and empty($current_tags)) {
         return NULL;
     }
     // delete all tags
     if (empty($tags)) {
         // update count (-1) of those tags
         foreach ($current_tags as $tag) {
             DB::update(Model_Tag::tableName())->set(array('count' => DB::expr('count - 1')))->where('name', '=', $tag)->execute();
         }
         Record::deleteWhere(self::tableName(), array('where' => array(array('page_id', '=', (int) $page_id))));
         Cache::instance()->delete_tag('page_tags');
     } else {
         $old_tags = array_diff($current_tags, $tags);
         $new_tags = array_diff($tags, $current_tags);
         // insert all tags in the tag table and then populate the page_tag table
         foreach ($new_tags as $index => $tag_name) {
             if (empty($tag_name)) {
                 continue;
             }
             $tag = Record::findOneFrom('Model_Tag', array('where' => array(array('name', '=', $tag_name))));
             // try to get it from tag list, if not we add it to the list
             if (!$tag instanceof Model_Tag) {
                 $tag = new Model_Tag(array('name' => trim($tag_name)));
             }
             $tag->count++;
             $tag->save();
             // create the relation between the page and the tag
             $page_tag = new Model_Page_Tag(array('page_id' => (int) $page_id, 'tag_id' => $tag->id));
             $page_tag->save();
         }
         // remove all old tag
         foreach ($old_tags as $index => $tag_name) {
             // get the id of the tag
             $tag = Record::findOneFrom('Model_Tag', array('where' => array(array('name', '=', $tag_name))));
             Record::deleteWhere(self::tableName(), array('where' => array(array('page_id', '=', (int) $page_id), array('tag_id', '=', $tag->id))));
             $tag->count--;
             $tag->save();
         }
         Cache::instance()->delete_tag('page_tags');
     }
 }
 public static function getCurrentVersionFrom($page)
 {
     $page_id = null;
     if (is_numeric($page)) {
         $page_id = $page;
     } else {
         if ($page instanceof Page) {
             $page_id = $page->id;
         }
     }
     //$current_version = $page->children(array('where' => 'behavior_id="current_version"', 'limit' => 1), array(), true);
     $current_version = Record::findOneFrom("PageVersion", 'parent_id = ' . $page_id . ' and behavior_id="current_version"');
     return $current_version;
 }
示例#9
0
 public static function findBy($column, $value)
 {
     return Record::findOneFrom('ExperienceImage', $column . ' = ?', array($value));
 }
示例#10
0
文件: Page.php 项目: chaobj001/tt
 public function saveTags($tags)
 {
     if (is_string($tags)) {
         $tags = explode(',', $tags);
     }
     $tags = array_map('trim', $tags);
     $current_tags = $this->getTags();
     // no tag before! no tag now! ... nothing to do!
     if (count($tags) == 0 && count($current_tags) == 0) {
         return;
     }
     // delete all tags
     if (count($tags) == 0) {
         $tablename = self::tableNameFromClassName('Tag');
         // update count (-1) of those tags
         foreach ($current_tags as $tag) {
             self::$__CONN__->exec("UPDATE {$tablename} SET count = count - 1 WHERE name = '{$tag}'");
         }
         return Record::deleteWhere('PageTag', 'page_id=?', array($this->id));
     } else {
         $old_tags = array_diff($current_tags, $tags);
         $new_tags = array_diff($tags, $current_tags);
         // insert all tags in the tag table and then populate the page_tag table
         foreach ($new_tags as $index => $tag_name) {
             if (!empty($tag_name)) {
                 // try to get it from tag list, if not we add it to the list
                 if (!($tag = Record::findOneFrom('Tag', 'name=?', array($tag_name)))) {
                     $tag = new Tag(array('name' => trim($tag_name)));
                 }
                 $tag->count++;
                 $tag->save();
                 // create the relation between the page and the tag
                 $tag = new PageTag(array('page_id' => $this->id, 'tag_id' => $tag->id));
                 $tag->save();
             }
         }
         // remove all old tag
         foreach ($old_tags as $index => $tag_name) {
             // get the id of the tag
             $tag = Record::findOneFrom('Tag', 'name=?', array($tag_name));
             Record::deleteWhere('PageTag', 'page_id=? AND tag_id=?', array($this->id, $tag->id));
             $tag->count--;
             $tag->save();
         }
     }
 }
示例#11
0
} else {
    $isRoot = 0;
}
$oGallery = new Gallery();
$count = 0;
if ($isRoot == 1) {
    // album cover
    $albums = Record::query("select a.page_id, a.id, a.name as album_name from wolf_album a,wolf_page p where a.id=p.id AND a.status='1' group by a.id order by p.position asc");
} else {
    // loop photos
    $albums = Record::query("select a.page_id, a.id, a.name as album_name,g.* from wolf_gallery g inner join wolf_album a on a.id=g.album_id AND a.status='1' AND a.page_id='" . $this->id . "' where g.status='1' order by g.sequence asc, g.id desc");
}
while ($album = $albums->fetchObject()) {
    $count++;
    //Album cover
    $cover = Record::findOneFrom("Gallery", "status='1' and album_id='" . $album->id . "' order by sequence asc LIMIT 1");
    if ($isRoot == 1) {
        $url = Page::urlById((int) $album->page_id);
        $img_src = $cover->filename != "" ? URL_PUBLIC . 'public/gallery/images/' . $album->id . '/' . $cover->filename : THEME_PATH . 'js/gallery/broken_image.jpg';
        echo '<div class="album-cover">
					<div><a href="' . $url . '">
						<img id="cover' . $album->id . '" src="' . $img_src . '" border=0>
					</a></div>
					<p>' . $album->album_name . '</p>
				</div>
			';
    } else {
        //Link that triggers the popup
        $img_src = $album->filename != "" ? URL_PUBLIC . 'public/gallery/images/' . $album->album_id . '/' . $album->filename : THEME_PATH . 'js/gallery/broken_image.jpg';
        echo '<div class="album-cover">
				<div><a href="' . URL_PUBLIC . 'public/gallery/images/' . $album->album_id . '/' . $album->filename . '" rel="photo[' . $album->album_id . ']">
示例#12
0
 public static function isInstalled($theme_id)
 {
     $theme = Record::findOneFrom('Themr', 'name=?', array($theme_id));
     if (isset($theme->id)) {
         return true;
     }
     return false;
 }
示例#13
0
 public function findBy($column, $value)
 {
     //$where = "{$column} = '{$value}'";
     //$where = "id='?'";
     $where = "{$column} = '?'";
     $article_info = Record::findOneFrom('Article', $where, array($value));
     if ($article_info) {
         $this->setFromData($article_info);
     }
     return $article_info;
 }
示例#14
0
 /**
  * Uninstall a theme along with snippets that came with it.
  *
  * @since 0.1.0
  *
  */
 public function uninstall($id)
 {
     $layoutUsed = 0;
     $theme = Record::findOneFrom('Themr', 'name=?', array($id));
     // Get Current Theme Info
     $theme_info = Themr::findTheme($id);
     foreach (unserialize($theme->layout) as $layouts) {
         // find the user to delete
         if ($layout = Record::findOneFrom('Layout', 'name=?', array(Themr::theme_name($layouts)))) {
             if ($layout->isUsed()) {
                 Flash::set('error', __('Theme <b>:theme</b> CANNOT be deleted because layout <b>:name</b> is being used!', array(':name' => $layout->name, ':theme' => $theme_info['name'])));
                 $layoutUsed = 1;
             } else {
                 if ($layout->delete()) {
                     Flash::set('success', __('Layout <b>:name</b> has been deleted!', array(':name' => $layout->name)));
                 } else {
                     Flash::set('error', __('Layout <b>:name</b> has not been deleted!', array(':name' => $layout->name)));
                 }
             }
         } else {
             Flash::set('error', __('Layout not found!'));
         }
     }
     if ($layoutUsed !== 1) {
         foreach (unserialize($theme->snippet) as $snippets) {
             // find the snippet to delete
             if ($snippet = Record::findOneFrom('Snippet', 'name=?', array($snippets))) {
                 if ($snippet->delete()) {
                     Flash::set('success', __('Snippet <b>:name</b> has been deleted!', array(':name' => $snippet->name)));
                 } else {
                     Flash::set('error', __('Snippet <b>:name</b> has not been deleted!', array(':name' => $snippet->name)));
                 }
             } else {
                 Flash::set('error', __('Snippet not found!'));
             }
         }
         if ($theme->delete()) {
             Flash::set('success', __('Theme <b>:name</b> has been uninstalled!', array(':name' => $theme_info['name'])));
             redirect(get_url('plugin/themr'));
         } else {
             Flash::set('error', __('Theme <b>:name</b> has not been uninstalled!', array(':name' => $theme_info['name'])));
             redirect(get_url('plugin/themr'));
         }
     } else {
         redirect(get_url('plugin/themr'));
     }
 }
示例#15
0
 public static function findBy($column, $value)
 {
     return Record::findOneFrom('FacilitiesImage', $column . ' = ?', array($value));
 }
示例#16
0
 private static final function getTokenTime($username, $url)
 {
     use_helper('Hash');
     $hash = new Crypt_Hash('sha256');
     $time = 0;
     if ($token = Record::findOneFrom('SecureToken', "username = ? AND url = ?", array($username, bin2hex($hash->hash($url))))) {
         $time = $token->time;
     }
     return $time;
 }
示例#17
0
文件: User.php 项目: sindotnet/cona
 public static function findBy($column, $value)
 {
     return Record::findOneFrom('User', $column . ' = ?', array($value));
 }
示例#18
0
}
if ($driver === 'sqlite') {
    // Adding date_format function to SQLite 3 'mysql date_format function'
    if (!function_exists('mysql_date_format_function')) {
        function mysql_function_date_format($date, $format)
        {
            return strftime($format, strtotime($date));
        }
    }
    $__CMS_CONN__->sqliteCreateFunction('date_format', 'mysql_function_date_format', 2);
}
Record::connection($__CMS_CONN__);
Record::getConnection()->exec("set names 'utf8'");
// START PRE-UPGRADE STUFF
// Get the user from the DB
$user = Record::findOneFrom('User', 'username=?', array($data['username']));
if (!$user) {
    die('<strong>Upgrade failed!</strong> Administrative user not correct...');
}
echo '<li>Administrative user found.</li>';
// Get the user's permissions from the DB
$perms = array();
$sql = 'SELECT name FROM ' . TABLE_PREFIX . 'permission AS permission, ' . TABLE_PREFIX . 'user_permission' . ' WHERE permission_id = permission.id AND user_id=' . $user->id;
$PDO = Record::getConnection();
$stmt = $PDO->prepare($sql);
$stmt->execute();
while ($perm = $stmt->fetchObject()) {
    $perms[] = $perm->name;
}
if (!in_array('administrator', $perms)) {
    die('<strong>Upgrade failed!</strong> Administrative permissions not correct.');