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_parts = Flash::get('post_parts_data');
     if (empty($page_parts)) {
         // check if we have a big sister ...
         $big_sister = Page::findBigSister($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' => Layout::find()));
 }
 function index()
 {
     // load redirects and logged 404 errors
     $data['current_redirects'] = Record::findAllFrom('RedirectorRedirects', 'true ORDER BY destination, url');
     $data['current_404s'] = Record::findAllFrom('Redirector404s', 'true ORDER BY hits DESC');
     $this->display('redirector/views/index', $data);
 }
 function clear()
 {
     $log_entry = Record::findAllFrom('DashboardLogEntry');
     foreach ($log_entry as $entry) {
         $entry->delete();
     }
     redirect(get_url('plugin/dashboard/'));
 }
Exemple #4
0
 public static function findAll($limit = null)
 {
     $where = 'AND count > 0';
     if (isset($limit)) {
         $where .= " order by count desc LIMIT {$limit} ";
     }
     return Record::findAllFrom('Tag', $where);
 }
Exemple #5
0
function redirector_log_404()
{
    $redirect = Record::findAllFrom('Redirector404s', 'url = \'' . $_SERVER['REQUEST_URI'] . '\'');
    if (sizeof($redirect) > 0) {
        Record::update('Redirector404s', array('hits' => $redirect[0]->hits + 1), 'id = ' . $redirect[0]->id);
    } else {
        Record::insert('Redirector404s', array('url' => $_SERVER['REQUEST_URI']));
    }
}
Exemple #6
0
 public static function init()
 {
     $settings = Record::findAllFrom('PageSetting');
     $pagesetting = new stdClass();
     foreach ($settings as $setting) {
         $name = $setting->name;
         $pagesetting->{$name} = $setting->value;
     }
     return $pagesetting;
 }
Exemple #7
0
 public static function init()
 {
     if (!self::$is_loaded) {
         $settings = Record::findAllFrom('Setting');
         foreach ($settings as $setting) {
             self::$settings[$setting->name] = $setting->value;
         }
         self::$is_loaded = true;
     }
 }
 public function __construct()
 {
     AuthUser::load();
     if (!AuthUser::isLoggedIn()) {
         echo 'Please Login';
         header('location:index.php?job=login');
     }
     //首页最近文章
     //$this->recent_post = Article::getPost(5, true);
     //侧栏分类
     $this->categories = Category::findAll();
     if (is_array($this->categories) && count($this->categories) > 0) {
         $temp = array();
         foreach ($this->categories as $k => $v) {
             $temp[$v->id] = get_object_vars($v);
         }
         $this->cahce_categories = $temp;
         $temp = array();
     }
     //Tags 后期改进为热词形式
     $hot_tags = Tag::findAll(20);
     //mprint_r($hot_tags, '$hot_tags');
     if (count($hot_tags) > 0) {
         $first = current($hot_tags);
         $last = end($hot_tags);
         foreach ($hot_tags as $k => $v) {
             $tags_list[$k]['word'] = $v->name;
             $tags_list[$k]['size'] = tagClouds($v->count, $first->count, $last->count);
         }
     }
     $this->tags_list = $tags_list;
     $tags = Tag::findAll();
     //var_dump($tags);
     $content_tag = Record::findAllFrom('ContentTag');
     //var_dump($content_tag);
     //关系表中存在的文章ID以及tag集合到一个数组中tag_cache  避免在遍历生成文章静态页时重复读取数据库
     //遍历所有tag 组合出方便调用的形式
     if (is_array($tags) && count($tags) > 0) {
         $temp_tags = array();
         foreach ($tags as $k => $v) {
             $temp_tags[$v->id] = $v->name;
         }
     }
     //遍历关系表
     if (is_array($content_tag) && count($content_tag) > 0) {
         $this->cahce_tags = array();
         foreach ($content_tag as $k => $v) {
             if (isset($temp_tags[$v->tag_id])) {
                 $this->cahce_tags[$v->content_id][] = $temp_tags[$v->tag_id];
             }
         }
     }
     //清空临时数据
     $tags = $content_tag = $temp_tags = array();
 }
 function edit($id)
 {
     if (AuthUser::getId() != $id && !AuthUser::hasPermission('administrator')) {
         Flash::set('error', __('You do not have permission to access the requested page!'));
         redirect(get_url());
     }
     // check if trying to save
     if (get_request_method() == 'POST') {
         return $this->_edit($id);
     }
     if ($user = User::findById($id)) {
         $this->display('user/edit', array('action' => 'edit', 'user' => $user, 'permissions' => Record::findAllFrom('Permission')));
     } else {
         Flash::set('error', __('User not found!'));
     }
     redirect(get_url('user'));
 }
 function clear()
 {
     $error = false;
     // We need to delete them one by one to make sure the filesystem is cleaned too.
     $pages = Record::findAllFrom('FunkyCachePage');
     foreach ($pages as $page) {
         if (!$page->delete()) {
             $error = true;
         }
     }
     if ($error === false) {
         Flash::set('success', 'Cache cleared successfully.');
     } else {
         Flash::set('error', 'One or more cached pages could not be deleted. Try manually from the commandline.');
     }
     $message = sprintf('Cache was cleared by :username.');
     Observer::notify('log_event', $message, 'funky_cache', 5);
     redirect(get_url('plugin/funky_cache/'));
 }
Exemple #11
0
 /**
  * Runs checks and stores a page.
  *
  * @param string $action   What kind of action this is: add or edit.
  * @param mixed $id        Page to edit if any.
  */
 private function _store($action, $id = false)
 {
     // Sanity checks
     if ($action == 'edit' && !$id) {
         throw new Exception('Trying to edit page when $id is false.');
     }
     use_helper('Validate');
     $data = $_POST['page'];
     $data['is_protected'] = !empty($data['is_protected']) ? 1 : 0;
     Flash::set('post_data', (object) $data);
     // Add pre-save checks here
     $errors = false;
     // CSRF checks
     if (isset($_POST['csrf_token'])) {
         $csrf_token = $_POST['csrf_token'];
         if (!SecureToken::validateToken($csrf_token, BASE_URL . 'page/' . $action)) {
             $errors[] = __('Invalid CSRF token found!');
         }
     } else {
         $errors[] = __('No CSRF token found!');
     }
     $data['title'] = trim($data['title']);
     if (empty($data['title'])) {
         $errors[] = __('You have to specify a title!');
     }
     $data['slug'] = trim($data['slug']);
     if (empty($data['slug']) && $id != '1') {
         $errors[] = __('You have to specify a slug!');
     } else {
         if ($data['slug'] == ADMIN_DIR) {
             $errors[] = __('You cannot have a slug named :slug!', array(':slug' => ADMIN_DIR));
         }
         if (!Validate::slug($data['slug']) && (!empty($data['slug']) && $id == '1')) {
             $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'slug'));
         }
     }
     // Check all numerical fields for a page
     $fields = array('parent_id', 'layout_id', 'needs_login');
     foreach ($fields as $field) {
         if (!Validate::digit($data[$field])) {
             $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
         }
     }
     // Check all date fields for a page
     $fields = array('created_on', 'published_on', 'valid_until');
     foreach ($fields as $field) {
         if (isset($data[$field])) {
             $data[$field] = trim($data[$field]);
             if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/D', (string) $data[$field])) {
                 $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
             }
         }
     }
     // Check all time fields for a page
     $fields = array('created_on_time', 'published_on_time', 'valid_until_time');
     foreach ($fields as $field) {
         if (isset($data[$field])) {
             $data[$field] = trim($data[$field]);
             if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{2}:[0-9]{2}:[0-9]{2}$/D', (string) $data[$field])) {
                 $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
             }
         }
     }
     // Check alphanumerical fields
     $fields = array('keywords', 'description');
     foreach ($fields as $field) {
         use_helper('Kses');
         $data[$field] = kses(trim($data[$field]), array());
         /*
                     if (!empty($data[$field]) && !Validate::alpha_comma($data[$field])) {
            $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
                     }
         * 
         */
     }
     // Check behaviour_id field
     if (!empty($data['behaviour_id']) && !Validate::slug($data['behaviour_id'])) {
         $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'behaviour_id'));
     }
     // Make sure the title doesn't contain HTML
     if (Setting::get('allow_html_title') == 'off') {
         use_helper('Kses');
         $data['title'] = kses(trim($data['title']), array());
     }
     // Create the page object to be manipulated and populate data
     if ($action == 'add') {
         $page = new Page($data);
     } else {
         $page = Record::findByIdFrom('Page', $id);
         $page->setFromData($data);
     }
     // Upon errors, rebuild original page and return to screen with errors
     if (false !== $errors) {
         $tags = $_POST['page_tag'];
         // Rebuild time fields
         if (isset($page->created_on)) {
             $page->created_on = $page->created_on . ' ' . $page->created_on_time;
         }
         if (isset($page->published_on)) {
             $page->published_on = $page->published_on . ' ' . $page->published_on_time;
         }
         if (isset($page->valid_until)) {
             $page->valid_until = $page->valid_until . ' ' . $page->valid_until_time;
         }
         // Rebuild parts
         $part = $_POST['part'];
         if (!empty($part)) {
             $tmp = false;
             foreach ($part as $key => $val) {
                 $tmp[$key] = (object) $val;
             }
             $part = $tmp;
         }
         // Set the errors to be displayed.
         Flash::setNow('error', implode('<br/>', $errors));
         // display things ...
         $this->setLayout('backend');
         $this->display('page/edit', array('action' => $action, 'csrf_token' => SecureToken::generateToken(BASE_URL . 'page/' . $action), 'page' => (object) $page, 'tags' => $tags, 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => (object) $part, 'layouts' => Record::findAllFrom('Layout')));
     }
     // Notify
     if ($action == 'add') {
         Observer::notify('page_add_before_save', $page);
     } else {
         Observer::notify('page_edit_before_save', $page);
     }
     // Time to actually save the page
     // @todo rebuild this so parts are already set before save?
     // @todo determine lazy init impact
     if ($page->save()) {
         // Get data for parts of this page
         $data_parts = $_POST['part'];
         Flash::set('post_parts_data', (object) $data_parts);
         if ($action == 'edit') {
             $old_parts = PagePart::findByPageId($id);
             // check if all old page part are passed in POST
             // if not ... we need to delete it!
             foreach ($old_parts as $old_part) {
                 $not_in = true;
                 foreach ($data_parts as $part_id => $data) {
                     $data['name'] = trim($data['name']);
                     if ($old_part->name == $data['name']) {
                         $not_in = false;
                         // this will not really create a new page part because
                         // the id of the part is passed in $data
                         $part = new PagePart($data);
                         $part->page_id = $id;
                         Observer::notify('part_edit_before_save', $part);
                         $part->save();
                         Observer::notify('part_edit_after_save', $part);
                         unset($data_parts[$part_id]);
                         break;
                     }
                 }
                 if ($not_in) {
                     $old_part->delete();
                 }
             }
         }
         // add the new parts
         foreach ($data_parts as $data) {
             $data['name'] = trim($data['name']);
             $part = new PagePart($data);
             $part->page_id = $page->id;
             Observer::notify('part_add_before_save', $part);
             $part->save();
             Observer::notify('part_add_after_save', $part);
         }
         // save tags
         $page->saveTags($_POST['page_tag']['tags']);
         Flash::set('success', __('Page has been saved!'));
     } else {
         Flash::set('error', __('Page has not been saved!'));
         $url = 'page/';
         $url .= $action == 'edit' ? 'edit/' . $id : 'add/';
         redirect(get_url($url));
     }
     if ($action == 'add') {
         Observer::notify('page_add_after_save', $page);
     } else {
         Observer::notify('page_edit_after_save', $page);
     }
     // save and quit or save and continue editing ?
     if (isset($_POST['commit'])) {
         redirect(get_url('page'));
     } else {
         redirect(get_url('page/edit/' . $page->id));
     }
 }
Exemple #12
0
 public static function findAllLike($tag)
 {
     return Record::findAllFrom(static::calledClass(), array('or_where' => array(array('name', 'like', '%:query%')), 'order_by' => array(array('count', 'desc'))), array(':query' => DB::expr($tag)));
 }
 public function create()
 {
     $this->_checkPermission();
     $paths = func_get_args();
     $this->display('sidebarlink/create', array('pages' => Record::findAllFrom('Page', 'parent_id=1 OR parent_id=0 order by parent_id,position')));
 }
 function index()
 {
     $this->display('layout/index', array('layouts' => Record::findAllFrom('Layout', '1=1 ORDER BY position')));
 }
 /**
  * Select page part forms for metadata.
  *
  * @param metadata metadata entries for this page
  */
 public static function callback_view_page_page_metadata($metadata)
 {
     $selected = "";
     $children_selected = "";
     // Search for metadat for this plugin
     foreach ($metadata as $m) {
         if ($m->keyword == self::PLUGIN_ID) {
             $selected = $m->value;
         }
         if ($m->keyword == self::PLUGIN_ID . '_children') {
             $children_selected = $m->value;
         }
     }
     self::Get_instance()->create_view('observers/form_type', array('page_part_forms' => Record::findAllFrom('PagePartForm', '1=1 ORDER BY name DESC'), 'selected' => $selected, 'children_selected' => $children_selected))->display();
 }
Exemple #16
0
function dashboard_events_widget_render()
{
    global $dashboardEvents;
    if (get_request_method() == "POST") {
        if (isset($_POST["dashboard_events"]) && $_POST["dashboard_events"] == "clear_all") {
            $dashboardEvents->clear();
            redirect(get_url("plugin/dashboard/"));
            die;
        }
    }
    $log_entries = Record::findAllFrom("DashboardLogEntry", "created_on=created_on ORDER BY created_on DESC");
    $path = WOLF_PATH_WIDGETS . "events/";
    ?>
			<form method="post" action="">
				<table class="dashboardTable" cellpadding="0" cellspacing="0" border="0">
					<thead>
						<tr>
							<th colspan="2"></th>
							<th><?php 
    echo __("Event");
    ?>
</th>
							<th class="moment"><?php 
    echo __("Time");
    ?>
 <img src="<?php 
    echo $path;
    ?>
img/sort.png" /></th>
						</tr>
					</thead>
					
					<tbody>
						<?php 
    $entrynum = 0;
    foreach ($log_entries as $entry) {
        ?>
									<tr class="<?php 
        echo odd_even();
        ?>
">
										<td class="hidden"><?php 
        echo $entrynum;
        ?>
</td>
										<td class="priority">
											<img src="<?php 
        echo $path;
        ?>
img/<?php 
        echo $entry->priority("string");
        ?>
.png" title="<?php 
        echo $entry->priority("string");
        ?>
" />
										</td>
										<td class="dashboardMessage"><?php 
        echo $entry->message;
        ?>
</td>
										<td class="date">
											<a title="<?php 
        echo $entry->created_on;
        ?>
"><?php 
        echo DateDifference::getString(new DateTime($entry->created_on));
        ?>
</a>
										</td>
									</tr>
								<?php 
        $entrynum++;
    }
    ?>
          
					</tbody>
				</table>

				<p class="buttons">
					<input type="hidden" name="dashboard_events" value="clear_all" />
					<input type="submit" name="dashboard_action" value="<?php 
    echo __("Clear all");
    ?>
" class="button" />
				</p>
			</form>
		<?php 
}
Exemple #17
0
 public static function findAll($arg = false)
 {
     $where = $arg ? 'AND ' . $arg . ' ORDER BY path' : 'ORDER BY path';
     //$where = 'ORDER BY path';
     return Record::findAllFrom('Category', $where);
 }
 function delete($id)
 {
     $experience = Record::findByIdFrom('Experience', $id);
     // find the experience to delete
     if ($experience) {
         //Remove folders and all images
         $dir = FILES_DIR . '/experience/images/' . $experience->filename;
         unlink($dir);
         // End remove folders and all images
         //Delete all experience galleries
         $experienceimages = Record::findAllFrom('ExperienceImage', 'experienceid=' . $id);
         if ($experienceimages) {
             foreach ($experienceimages as $img) {
                 //Remove folders and all images
                 $imagedir = FILES_DIR . '/experience/gallery/' . $img->filename;
                 unlink($imagedir);
                 // End remove folders and all images
             }
         }
         //Delete all experience galleries
         if ($experience->delete()) {
             Flash::set('success', __('This experience has been deleted.'));
         } else {
             Flash::set('error', __('This experience has not been deleted!'));
         }
     } else {
         Flash::set('error', __('Experience not found!'));
     }
     redirect(get_url('experience'));
 }
 function delete($id)
 {
     $offer = Record::findByIdFrom('Offer', $id);
     // find the offer to delete
     if ($offer) {
         //Remove folders and all images
         $dir = FILES_DIR . '/offer/images/' . $offer->filename;
         unlink($dir);
         // End remove folders and all images
         //Delete all offer galleries
         $offerimages = Record::findAllFrom('OfferImage', 'offerid=' . $id);
         if ($offerimages) {
             foreach ($offerimages as $img) {
                 //Remove folders and all images
                 $imagedir = FILES_DIR . '/offer/gallery/' . $img->filename;
                 unlink($imagedir);
                 // End remove folders and all images
             }
         }
         //Delete all offer galleries
         if ($offer->delete()) {
             Flash::set('success', __('This offer has been deleted.'));
         } else {
             Flash::set('error', __('This offer has not been deleted!'));
         }
     } else {
         Flash::set('error', __('Offer not found!'));
     }
     redirect(get_url('offer'));
 }
Exemple #20
0
 public function view()
 {
     $this->_checkPermission();
     $params = func_get_args();
     $content = '';
     $id = urldecode(join('/', $params));
     $about = Record::findByIdFrom('About', $id);
     $file = FILES_DIR . '/about/' . $about->filename;
     if (!$this->_isImage($file) && file_exists($file) && $about->filename != "") {
         $content = file_get_contents($file);
     }
     $this->display('about/view', array('about' => $about, 'pages' => Record::findAllFrom('Page', 'parent_id=1 OR parent_id=0 order by parent_id,position')));
 }
 function delete($id)
 {
     $event = Record::findByIdFrom('Event', $id);
     // find the event to delete
     if ($event) {
         //Remove folders and all images
         $dir = FILES_DIR . '/event/images/' . $event->filename;
         unlink($dir);
         // End remove folders and all images
         //Delete all event galleries
         $eventimages = Record::findAllFrom('EventImage', 'eventid=' . $id);
         if ($eventimages) {
             foreach ($eventimages as $img) {
                 //Remove folders and all images
                 $imagedir = FILES_DIR . '/event/gallery/' . $img->filename;
                 unlink($imagedir);
                 // End remove folders and all images
             }
         }
         //Delete all event galleries
         if ($event->delete()) {
             Flash::set('success', __('This event has been deleted.'));
         } else {
             Flash::set('error', __('This event has not been deleted!'));
         }
     } else {
         Flash::set('error', __('Event not found!'));
     }
     redirect(get_url('event'));
 }
 public function browse()
 {
     $this->_checkPermission();
     $params = func_get_args();
     $this->path = join('/', $params);
     // make sure there's a / at the end
     if (substr($this->path, -1, 1) != '/') {
         $this->path .= '/';
     }
     //security
     // we dont allow back link
     if (strpos($this->path, '..') !== false) {
         if (Plugin::isEnabled('statistics_api')) {
             $user = null;
             if (AuthUser::isLoggedIn()) {
                 $user = AuthUser::getUserName();
             }
             $ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
             $event = array('event_type' => 'hack_attempt', 'description' => __('A possible hack attempt was detected.'), 'ipaddress' => $ip, 'username' => $user);
             Observer::notify('stats_file_manager_hack_attempt', $event);
         }
     }
     $this->display('testimonial/index', array('testimonials' => Record::query('select * from ' . TABLE_PREFIX . 'testimonial ORDER BY ' . TABLE_PREFIX . 'testimonial.sequence, ' . TABLE_PREFIX . 'testimonial.id desc'), 'pages' => Record::findAllFrom('Page', 'parent_id=1 order by parent_id,position')));
 }
Exemple #23
0
 public function edit($id = null)
 {
     if (is_null($id)) {
         redirect(get_url('page'));
     }
     $page = Page::findById($id);
     if (!$page) {
         Flash::set('error', __('Page not found!'));
         redirect(get_url('page'));
     }
     // check for protected page and editor user
     if (!AuthUser::hasPermission('administrator') && !AuthUser::hasPermission('developer') && $page->is_protected) {
         Flash::set('error', __('You do not have permission to access the requested page!'));
         redirect(get_url('page'));
     }
     // check if trying to save
     if (get_request_method() == 'POST') {
         return $this->_edit($id);
     }
     // find all page_part of this pages
     $page_parts = PagePart::findByPageId($id);
     if (empty($page_parts)) {
         $page_parts = array(new PagePart());
     }
     // display things ...
     $this->setLayout('backend');
     $this->display('page/edit', array('action' => 'edit', 'page' => $page, 'tags' => $page->getTags(), 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => $page_parts, 'layouts' => Record::findAllFrom('Layout', '1=1 ORDER BY position')));
 }
Exemple #24
0
 /**
  * Runs checks and stores a page.
  *
  * @param string $action   What kind of action this is: add or edit.
  * @param mixed $id        Page to edit if any.
  */
 private function _store($action, $id = false)
 {
     // Sanity checks
     if ($action == 'edit' && !$id) {
         throw new Exception('Trying to edit page when $id is false.');
     }
     use_helper('Validate');
     $data = $_POST['page'];
     $data['is_protected'] = !empty($data['is_protected']) ? 1 : 0;
     Flash::set('post_data', (object) $data);
     $pagesetting = array();
     //For homepage info & about page info okstmtcc
     if ($id == 1 || $id == 4) {
         $upload = $_POST['upload'];
         $pagesetting = $_POST['pagesetting'];
         //Flash::set('post_settingdata', (object) $pagesetting);
     }
     // Add pre-save checks here
     $errors = false;
     $error_fields = false;
     // CSRF checks
     if (isset($_POST['csrf_token'])) {
         $csrf_token = $_POST['csrf_token'];
         $csrf_id = '';
         if ($action === 'edit') {
             $csrf_id = '/' . $id;
         }
         if (!SecureToken::validateToken($csrf_token, BASE_URL . 'page/' . $action . $csrf_id)) {
             $errors[] = __('Invalid CSRF token found!');
         }
     } else {
         $errors[] = __('No CSRF token found!');
     }
     $data['title'] = trim($data['title']);
     if (empty($data['title'])) {
         $error_fields[] = __('Page Title');
     }
     /** homepage setting check okstmtcc **/
     if ($id == 1) {
         /** homepage page title **/
         if (empty($pagesetting['homepage_discover_title'])) {
             $error_fields[] = __('Homepage Title');
         }
         if (empty($pagesetting['homepage_discover_teaser'])) {
             $error_fields[] = __('Homepage Teaser');
         }
         /** highlight 1 **/
         // if (empty($pagesetting['highlight_title'])){
         //     $error_fields[] = __('Highlight 1&acute;s Title');
         // }
         // if (empty($pagesetting['highlight_text1'])){
         //     $error_fields[] = __('Highlight 1&acute;s Text 1');
         // }
         // if (empty($pagesetting['highlight_url'])){
         //     $error_fields[] = __('Highlight 1&acute;s Read More URL');
         // }
         // $pagesetting_ori = PageSetting::init();
         // if (isset($_FILES)) {
         //     if(empty($_FILES['upload_highlight_image']['name'])){
         //         $pagesetting['highlight_image'] =  $pagesetting_ori->highlight_image;
         //     } else {
         //         $pagesetting['highlight_image'] = $_FILES['upload_highlight_image']['name'];
         //     }
         // } else {
         //     $pagesetting['highlight_image'] =  $pagesetting_ori->highlight_image;
         // }
         // if (empty($pagesetting['highlight_image'])){
         //     $error_fields[] = __('Highlight 1&acute;s Image');
         // }
         // /** highlight 2 **/
         // if (empty($pagesetting['highlight2_title'])){
         //     $error_fields[] = __('Highlight 2&acute;s Title');
         // }
         // if (empty($pagesetting['highlight2_text1'])){
         //     $error_fields[] = __('Highlight 2&acute;s Text 1');
         // }
         // if (empty($pagesetting['highlight2_url'])){
         //     $error_fields[] = __('Highlight 2&acute;s Read More URL');
         // }
         // if (isset($_FILES)) {
         //     if(empty($_FILES['upload_highlight2_image']['name'])){
         //         $pagesetting['highlight2_image'] =  $pagesetting_ori->highlight2_image;
         //     } else {
         //         $pagesetting['highlight2_image'] = $_FILES['upload_highlight2_image']['name'];
         //     }
         // } else {
         //     $pagesetting['highlight2_image'] =  $pagesetting_ori->highlight2_image;
         // }
         // if (empty($pagesetting['highlight2_image'])){
         //     $error_fields[] = __('Highlight 2&acute;s Image');
         // }
         // if (isset($_FILES)) {
         //     if(empty($_FILES['upload_newdev_image']['name'])){
         //         $pagesetting['newdev_image'] =  $pagesetting_ori->newdev_image;
         //     } else {
         //         $pagesetting['newdev_image'] = $_FILES['upload_newdev_image']['name'];
         //     }
         // } else {
         //     $pagesetting['newdev_image'] =  $pagesetting_ori->newdev_image;
         // }
         // if (empty($pagesetting['newdev_image'])){
         //     $error_fields[] = __('New Development Image');
         // }
     }
     /** homepage setting check okstmtcc **/
     $data['slug'] = !empty($data['slug']) ? trim($data['slug']) : '';
     if (empty($data['slug']) && $id != '1') {
         $error_fields[] = __('Slug');
     } else {
         if ($data['slug'] == ADMIN_DIR) {
             $errors[] = __('You cannot have a slug named :slug!', array(':slug' => ADMIN_DIR));
         }
         if (!Validate::slug($data['slug']) && (!empty($data['slug']) && $id == '1')) {
             $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'slug'));
         }
     }
     // Check all numerical fields for a page
     $fields = array('parent_id', 'layout_id', 'needs_login');
     foreach ($fields as $field) {
         if (!Validate::digit($data[$field])) {
             $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
         }
     }
     // Check all date fields for a page
     $fields = array('created_on', 'published_on', 'valid_until');
     foreach ($fields as $field) {
         if (isset($data[$field])) {
             $data[$field] = trim($data[$field]);
             if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/D', (string) $data[$field])) {
                 $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
             }
         }
     }
     // Check all time fields for a page
     $fields = array('created_on_time', 'published_on_time', 'valid_until_time');
     foreach ($fields as $field) {
         if (isset($data[$field])) {
             $data[$field] = trim($data[$field]);
             if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{2}:[0-9]{2}:[0-9]{2}$/D', (string) $data[$field])) {
                 $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
             }
         }
     }
     // Check alphanumerical fields
     $fields = array('keywords', 'description');
     foreach ($fields as $field) {
         use_helper('Kses');
         $data[$field] = kses(trim($data[$field]), array());
         /*
                     if (!empty($data[$field]) && !Validate::alpha_comma($data[$field])) {
            $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field));
                     }
         *
         */
     }
     // Check behaviour_id field
     if (!empty($data['behaviour_id']) && !Validate::slug($data['behaviour_id'])) {
         $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'behaviour_id'));
     }
     // Make sure the title doesn't contain HTML
     if (Setting::get('allow_html_title') == 'off') {
         use_helper('Kses');
         $data['title'] = kses(trim($data['title']), array());
     }
     // Create the page object to be manipulated and populate data
     if ($action == 'add') {
         $page = new Page($data);
     } else {
         $page = Record::findByIdFrom('Page', $id);
         $page->setFromData($data);
     }
     // Upon errors, rebuild original page and return to screen with errors
     if (false !== $errors || $error_fields !== false) {
         $tags = $_POST['page_tag'];
         // Rebuild time fields
         if (isset($page->created_on) && isset($page->created_on_time)) {
             $page->created_on = $page->created_on . ' ' . $page->created_on_time;
         }
         if (isset($page->published_on) && isset($page->published_on_time)) {
             $page->published_on = $page->published_on . ' ' . $page->published_on_time;
         }
         if (isset($page->valid_until)) {
             $page->valid_until = $page->valid_until . ' ' . $page->valid_until_time;
         }
         // Rebuild parts
         $part = '';
         if (!empty($_POST['part'])) {
             $part = $_POST['part'];
             $tmp = false;
             foreach ($part as $key => $val) {
                 $tmp[$key] = (object) $val;
             }
             $part = $tmp;
         }
         // Set the errors to be displayed.
         $err_msg = $errors != false ? implode('<br/>', $errors) : '';
         $err_msg .= $error_fields != false ? '<br />Please specify these fields: ' . implode(', ', $error_fields) : '';
         Flash::setNow('error', $err_msg);
         //$settingdata = 'aaa';
         // display things ...
         $this->setLayout('backend');
         $pagesettingobj = new stdClass();
         foreach ($pagesetting as $name => $value) {
             $pagesettingobj->{$name} = $value;
         }
         $this->display('page/edit', array('action' => $action, 'csrf_token' => SecureToken::generateToken(BASE_URL . 'page/' . $action), 'page' => (object) $page, 'pagesetting' => $pagesettingobj, 'tags' => $tags, 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => $part, 'layouts' => Record::findAllFrom('Layout')));
     }
     // Notify
     if ($action == 'add') {
         Observer::notify('page_add_before_save', $page);
     } else {
         Observer::notify('page_edit_before_save', $page);
     }
     // Time to actually save the page
     // @todo rebuild this so parts are already set before save?
     // @todo determine lazy init impact
     $page->newwindow = !empty($data['newwindow']) ? '1' : '0';
     if ($page->save()) {
         // Get data for parts of this page
         $data_parts = $_POST['part'];
         Flash::set('post_parts_data', (object) $data_parts);
         if ($action == 'edit') {
             $old_parts = PagePart::findByPageId($id);
             // check if all old page part are passed in POST
             // if not ... we need to delete it!
             foreach ($old_parts as $old_part) {
                 $not_in = true;
                 foreach ($data_parts as $part_id => $data) {
                     $data['name'] = trim($data['name']);
                     if ($old_part->name == $data['name']) {
                         $not_in = false;
                         // this will not really create a new page part because
                         // the id of the part is passed in $data
                         $part = new PagePart($data);
                         $part->page_id = $id;
                         Observer::notify('part_edit_before_save', $part);
                         $part->save();
                         Observer::notify('part_edit_after_save', $part);
                         unset($data_parts[$part_id]);
                         break;
                     }
                 }
                 if ($not_in) {
                     $old_part->delete();
                 }
             }
         }
         // add the new parts
         foreach ($data_parts as $data) {
             $data['name'] = trim($data['name']);
             $part = new PagePart($data);
             $part->page_id = $page->id;
             Observer::notify('part_add_before_save', $part);
             $part->save();
             Observer::notify('part_add_after_save', $part);
         }
         // save tags
         $page->saveTags($_POST['page_tag']['tags']);
         // save homepage banner info okstmtcc
         if ($id == 1) {
             // upload home banner image 1, 2
             if (isset($_FILES) && !empty($_FILES['upload_banner_image1']['name'])) {
                 //okstmtcc 20150827 Replace image filename spaces
                 $_FILES['upload_banner_image1']['name'] = str_replace(array(" ", "(", ")"), array("_", "", ""), $_FILES['upload_banner_image1']['name']);
                 $file = $this->upload_file($_FILES['upload_banner_image1']['name'], FILES_DIR . '/pagesetting/images/', $_FILES['upload_banner_image1']['tmp_name'], $overwrite);
                 if ($file === false) {
                     Flash::set('error', __('Home banner could not be uploaded!'));
                     redirect(get_url('page/edit/1'));
                 } else {
                     $pagesetting['banner_image1'] = $file;
                 }
             }
             if (isset($_FILES) && !empty($_FILES['upload_banner_image2']['name'])) {
                 //okstmtcc 20150827 Replace image filename spaces
                 $_FILES['upload_banner_image2']['name'] = str_replace(array(" ", "(", ")"), array("_", "", ""), $_FILES['upload_banner_image2']['name']);
                 $file = $this->upload_file($_FILES['upload_banner_image2']['name'], FILES_DIR . '/pagesetting/images/', $_FILES['upload_banner_image2']['tmp_name'], $overwrite);
                 if ($file === false) {
                     Flash::set('error', __('Home banner could not be uploaded!'));
                     redirect(get_url('page/edit/1'));
                 } else {
                     $pagesetting['banner_image2'] = $file;
                 }
             }
             PageSetting::saveFromData($pagesetting);
         }
         // save homepage banner info okstmtcc
         // save about banner info okstmtcc
         if ($id == 4) {
             // upload about page image 1
             if (isset($_FILES) && !empty($_FILES['upload_about_image1']['name'])) {
                 //okstmtcc 20150827 Replace image filename spaces
                 $_FILES['upload_about_image1']['name'] = str_replace(array(" ", "(", ")"), array("_", "", ""), $_FILES['upload_about_image1']['name']);
                 $file = $this->upload_file($_FILES['upload_about_image1']['name'], FILES_DIR . '/pagesetting/images/', $_FILES['upload_about_image1']['tmp_name'], $overwrite);
                 if ($file === false) {
                     Flash::set('error', __('Home banner could not be uploaded!'));
                     redirect(get_url('page/edit/1'));
                 } else {
                     $pagesetting['about_image1'] = $file;
                 }
             }
             PageSetting::saveFromData($pagesetting);
         }
         // save about banner info okstmtcc
         Flash::set('success', __('Page has been saved.'));
     } else {
         Flash::set('error', __('Page has not been saved!'));
         $url = 'page/';
         $url .= $action == 'edit' ? 'edit/' . $id : 'add/';
         redirect(get_url($url));
     }
     if ($action == 'add') {
         Observer::notify('page_add_after_save', $page);
     } else {
         Observer::notify('page_edit_after_save', $page);
     }
     // save and quit or save and continue editing ?
     if (isset($_POST['commit'])) {
         redirect(get_url('page'));
     } else {
         redirect(get_url('page/edit/' . $page->id));
     }
 }
Exemple #25
0
 public function __construct()
 {
     /*
             $cache = new FileCache();
             $cache->cachePath = DATA_DIR.'cache/';
     
             //侧栏分类
             $categories = $cache->get('categories');
             if($categories === false) {
                 $categories = array();
                 //获得所有分类
                 $categories[0] = Category::findAll();
                 if(is_array($categories[0]) && count($categories[0]) > 0) {
                     foreach($categories[0] as $k => $v) {
                         //$this->categories[$v->id] = get_object_vars($v);
                         $categories[1][$v->id] = $v;
                         $categories[1][$v->slug] = $v;
                     }
                 }
     
                 $cache->set('categories', $categories, 7200);//缓存2小时
                 del_cache();
             }
     
             //Tags 热词
             $hot_tags = $cache->get('hot_tags');
             if($hot_tags === false) {
                 $hot_tags = Tag::findAll(30);
                 $cache->set('hot_tags', $hot_tags, 7200);
             }
     */
     //--------------------------------
     //首页最近文章
     $this->recent_post = Article::getPost(5, true);
     //侧栏分类
     $this->categories = Category::findAll();
     if (is_array($this->categories) && count($this->categories) > 0) {
         $temp = array();
         foreach ($this->categories as $k => $v) {
             $temp[$v->id] = get_object_vars($v);
         }
         $this->cahce_categories = $temp;
         $temp = array();
     }
     //Tags 后期改进为热词形式
     $this->tags_list = Tag::findAll(30);
     $tags = Tag::findAll();
     $content_tag = Record::findAllFrom('ContentTag');
     //遍历所有tag 组合出方便调用的形式
     if (is_array($tags) && count($tags) > 0) {
         $temp_tags = array();
         foreach ($tags as $k => $v) {
             $temp_tags[$v->id] = $v->name;
         }
     }
     //遍历关系表
     if (is_array($content_tag) && count($content_tag) > 0) {
         $this->cahce_tags = array();
         foreach ($content_tag as $k => $v) {
             if (isset($temp_tags[$v->tag_id])) {
                 $this->cahce_tags[$v->content_id][] = $temp_tags[$v->tag_id];
             }
         }
     }
     //清空临时数据
     $tags = $content_tag = $temp_tags = array();
 }
 function delete($id)
 {
     $villa = Record::findByIdFrom('Villa', $id);
     // find the villa to delete
     if ($villa) {
         //Remove folders and all images
         $dir = FILES_DIR . '/villa/images/' . $villa->filename;
         unlink($dir);
         // End remove folders and all images
         //Delete all villa galleries
         $villaimages = Record::findAllFrom('VillaImage', 'villaid=' . $id);
         if ($villaimages) {
             foreach ($villaimages as $img) {
                 //Remove folders and all images
                 $imagedir = FILES_DIR . '/villa/gallery/' . $img->filename;
                 unlink($imagedir);
                 // End remove folders and all images
             }
         }
         //Delete all villa galleries
         if ($villa->delete()) {
             Flash::set('success', __('This villa has been deleted.'));
         } else {
             Flash::set('error', __('This villa has not been deleted!'));
         }
     } else {
         Flash::set('error', __('Villa not found!'));
     }
     redirect(get_url('villa'));
 }
 public function view_album()
 {
     $this->_checkPermission();
     $paths = func_get_args();
     $id = urldecode(join('/', $paths));
     $albums = Record::query('select * from ' . TABLE_PREFIX . 'album where id="' . $id . '"');
     $album = $albums->fetchObject();
     /* Pagination */
     if (isset($_GET['page'])) {
         $CurPage = $_GET['page'];
     } else {
         $CurPage = 0;
     }
     $rowspage = 20;
     $start = $CurPage * $rowspage;
     $totalrecords = Record::countFrom('Gallery', 'album_id="' . $id . '"');
     $galleries = Record::query('select * from ' . TABLE_PREFIX . 'gallery g where g.album_id = "' . $id . '" ORDER BY g.sequence LIMIT ' . $start . ',' . $rowspage);
     $lastpage = ceil($totalrecords / $rowspage);
     if ($totalrecords <= $rowspage) {
         $lastpage = 0;
     } else {
         $lastpage = abs($lastpage - 1);
     }
     /* End Pagination */
     $this->display('gallery/view_album', array('album' => $album, 'CurPage' => $CurPage, 'lastpage' => $lastpage, 'galleries' => $galleries, 'pages' => Record::findAllFrom('Page', 'parent_id=1 order by parent_id,position')));
 }
 public function product_update($id = null)
 {
     if (is_null($id)) {
         redirect(get_url('plugin/ecommerce'));
     }
     if (!($product = Product::findById($id))) {
         Flash::set('error', __('Product not found!'));
         redirect(get_url('plugin/ecommerce'));
     }
     if (get_request_method() == 'POST') {
         //get new type id if a new one was created
         if ($_POST['product_type']['title']) {
             //save type
             $type_id = $this->_product_save(null, 'product_type', 'ProductType');
             $_POST['product']['type_id'] = $type_id;
             //add new type page
             $page_data = array("is_protected" => 1, "parent_id" => 87, "title" => $_POST['product_type']['title'], "slug" => $_POST['product_type']['slug'], "breadcrumb" => $_POST['product_type']['title']);
             $page = new Page($page_data);
             $page->save();
         }
         //get new vendor id if a new one was created
         if ($_POST['product_vendor']['title']) {
             //save vendor
             $vendor_id = $this->_product_save(null, 'product_vendor', 'ProductVendor');
             $_POST['product']['vendor_id'] = $vendor_id;
             //add new vendor page
             $page_data = array("is_protected" => 1, "parent_id" => 86, "title" => $_POST['product_vendor']['title'], "slug" => $_POST['product_vendor']['slug'], "breadcrumb" => $_POST['product_vendor']['title']);
             $page = new Page($page_data);
             $page->save();
         }
         //save product
         $product_id = $this->_product_save($id, 'product', 'Product');
         //insert log
         $this->_insert_log('Product <a href="' . get_url('plugin/ecommerce/product_update/' . $product_id) . '">' . $_POST['product']['title'] . '</a> was updated.');
         //save images
         if (isset($_SESSION['product_images'])) {
             $this->_images_save($product_id, $_SESSION['product_images']);
         }
         //save product page
         $product = Product::findById($id);
         if ($product) {
             $page = Record::findByIdFrom('Page', $product->page_id);
             $page_data = array("is_protected" => 1, "title" => $_POST['product']['title'], "slug" => $_POST['product']['slug'], "breadcrumb" => $_POST['product']['title'], "created_on_time" => null, "published_on_time" => null);
             $page->setFromData($page_data);
             $page->save();
         }
         redirect(get_url('plugin/ecommerce/product'));
     }
     $types = ProductType::findAll();
     $vendors = ProductVendor::findAll();
     $images = Record::findAllFrom('ProductImage', 'product_id=? order by position', array($id));
     $variants = Record::findAllFrom('ProductVariant', 'product_id=? order by position', array($id));
     $files = Record::findAllFrom('ProductFile', 'product_id=? order by position', array($id));
     $videos = Record::findAllFrom('ProductVideo', 'product_id=? order by position', array($id));
     $this->display('ecommerce/views/products/update', array('action' => 'update', 'product' => $product, 'types' => $types, 'vendors' => $vendors, 'images' => $images, 'variants' => $variants, 'files' => $files, 'videos' => $videos));
 }
Exemple #29
0
 public function index()
 {
     $this->display('snippet/index', array('snippets' => Record::findAllFrom('Snippet', '1=1 ORDER BY position')));
 }
Exemple #30
0
 public static function findAll()
 {
     return Record::findAllFrom('User');
 }