public function page($page_id = NULL) { valid::id_key($page_id); ob_start(); #TODO: if any tools are protected on this page, search for a possible # theme template and load that within the page css. # Is page_name protected? #$page_config_value = yaml::does_key_exist($this->site_name, 'pages_config', $page_name); # parse custom page sass file if it exists. $page_sass = $this->assets->themes_dir("{$this->theme}/pages/{$page_id}.sass"); if (file_exists($page_sass)) { echo Kosass::factory('compact')->compile(file($page_sass)); } # load custom tool css files $db = new Database(); # get all tools that are added to this page. $tool_data = $db->query("\n SELECT *, LOWER(system_tools.name) AS name, tools.id AS guid\n FROM pages_tools \n JOIN tools ON pages_tools.tool_id = tools.id\n JOIN system_tools ON tools.system_tool_id = system_tools.id\n WHERE (page_id BETWEEN 1 AND 5 OR page_id = '{$page_id}')\n AND pages_tools.fk_site = '{$this->site_id}'\n ORDER BY pages_tools.container, pages_tools.position\n "); $tool_dir = $this->assets->themes_dir("{$this->theme}/tools"); foreach ($tool_data as $tool) { # get the type and the view from the system. # TODO: try and optimize this later. $table = ORM::factory($tool->name)->where('fk_site', $this->site_id)->find($tool->parent_id); $custom_file = "{$tool_dir}/{$tool->name}/{$tool->parent_id}/{$table->type}_{$table->view}.css"; if (file_exists($custom_file)) { readfile($custom_file); } } # cache the full result as the live global css file. file_put_contents("{$this->cache_dir}/{$page_id}.css", ob_get_clean()); return TRUE; }
public function get_item($table, $id = FALSE) { $id = $id ? $id : valid::id_key($this->item_id); $item = ORM::factory($table)->where('fk_site', $this->site_id)->find($id); if (!$item->loaded) { die("invalid item for {$table}"); } return $item; }
public function tool() { if (empty($_GET['tool_id'])) { die('invalid tool_id'); } $tool_id = valid::id_key($_GET['tool_id']); $tool = ORM::factory('tool', $tool_id); if (!$tool->loaded) { die('invalid tool'); } $toolname = strtolower($tool->system_tool->name); # load the tool parent $parent = ORM::factory($toolname, $tool->parent_id); if (!$parent->loaded) { die('invalid parent table'); } # build the object. $export = new stdClass(); $export->name = $toolname; # export the parent table. $parent_table = new stdClass(); foreach ($parent->table_columns as $key => $value) { $parent_table->{$key} = $parent->{$key}; } $export->parent_table = $parent_table; # export any child tables. $child_tables = new stdClass(); # loop through data from available child tables. foreach ($parent->has_many as $table_name) { $table_name = inflector::singular($table_name); $child_tables->{$table_name} = array(); # get the child table model so we can iterate through the fields. $table = ORM::factory($table_name); # get any rows beloning to the parent. $rows = ORM::factory($table_name)->where(array('fk_site' => $this->site_id, "{$toolname}_id" => $parent->id))->find_all(); foreach ($rows as $row) { $object = new stdClass(); foreach ($table->table_columns as $key => $value) { $object->{$key} = $row->{$key}; } array_push($child_tables->{$table_name}, $object); } } $export->child_tables = $child_tables; # get the css file. $export->css = file_get_contents($this->assets->themes_dir("{$this->theme}/tools/{$toolname}/_created/{$parent->id}/{$parent->type}_{$parent->view}.css")); $json = json_encode($export); echo '<h2>Copy this exactly and place into the importer=)</h2>'; echo "<textarea style='width:99%;height:400px;'>{$json}</textarea>"; die; echo kohana::debug($export); die; # just testing ... echo self::import($json); die; }
private function get_tag() { valid::id_key($this->tag_id); $tag = ORM::factory('tag')->where('owner_id', $this->owner->id)->find($this->tag_id); if (!$tag->loaded) { $this->rsp->msg = 'Tag does not exist'; $this->rsp->send(); } return $tag; }
function save_tree() { if ($_POST) { valid::id_key($this->pid); $json = json_decode($_POST['json']); if (NULL === $json or !is_array($json)) { die('invalid json'); } echo Tree::save_tree('navigation', 'navigation_item', $this->pid, $this->site_id, $json); } die; }
private function get_testimonial() { if (0 == $this->testimonial_id) { $new = ORM::factory('testimonial'); $new->owner_id = $this->owner->id; return $new; } valid::id_key($this->testimonial_id); $testimonial = ORM::factory('testimonial')->where('owner_id', $this->owner->id)->find($this->testimonial_id); if (!$testimonial->loaded) { $this->rsp->msg = 'Testimonial does not exist'; $this->rsp->send(); } return $testimonial; }
public function add_access() { if (!isset($_POST['password']) or 'supausah' !== $_POST['password']) { die('invalid password'); } $user_id = valid::id_key($_POST['user_id']); $site_id = valid::id_key($_POST['site_id']); # Create access row for the master account (jade) $user = ORM::factory('account_user', $user_id); if (!$user->loaded) { die('invalid user'); } $user->add(ORM::factory('site', $site_id)); $user->save(); echo 'Access Granted! Remember to delete when finished'; die; }
public function css($system_tool_id = NULL, $parent_id = NULL) { valid::id_key($system_tool_id); valid::id_key($parent_id); $system_tool = ORM::factory('system_tool')->select('*, LOWER(name) AS name')->find($system_tool_id); $tool = ORM::factory($system_tool->name)->where('fk_site', $this->site_id)->find($parent_id); # Overwrite old file with new file contents; if ($_POST) { #$tool->attributes = $_POST['attributes']; #$tool->save(); if (isset($_POST['save_template'])) { #NOT WORKING. $contents = preg_replace("/_(\\d+)/", '_++', $_POST['contents']); $theme_template = $this->assets->themes_dir("{$this->theme}/tools/{$system_tool->name}/{$tool->type}/{$tool->view}_template.css"); if (file_put_contents($theme_template, $contents)) { die('Template Saved'); } die('The was a problem saving the file.'); } # save the css $custom_file = $this->assets->themes_dir("{$this->theme}/tools/{$system_tool->name}/{$tool->id}/{$tool->type}_{$tool->view}.css"); if (file_put_contents($custom_file, $_POST['output'])) { die('CSS Changes Saved.'); } die('The was a problem saving the file.'); } # get stock css? #$stock = self::get_sass($system_tool->name, $tool_id, $tool->type, $tool->view, 'stock'); #echo kohana::debug($stock); die(); $theme_sass = self::get_sass($system_tool->name, $tool->id, $tool->type, $tool->view, 'theme'); # testing ! $custom_sass = self::get_css($system_tool->name, $tool->id, $tool->type, $tool->view); # $custom_sass = self::get_sass($system_tool->name, $tool_id, $tool->type, $tool->view, 'custom'); #echo kohana::debug($custom_sass); die(); $view = new View('tool/edit_css'); $view->custom_sass = $custom_sass; $view->tool = $tool; $view->theme_sass = $theme_sass; $view->name_id = $system_tool_id; $view->toolname = $system_tool->name; $view->js_rel_command = "update-{$system_tool->name}-{$tool->id}"; die($view); }
public function delete_user() { valid::id_key($this->item_id); ORM::factory('account_user')->where('fk_site', $this->site_id)->delete($this->item_id); die('User deleted'); }
public function settings($tool_id = NULL) { die('Showroom settings are currently disabled while we update our code. Thanks!'); valid::id_key($tool_id); }
public function hide($page_id = NULL) { valid::id_key($page_id); $page = ORM::factory('page')->where('fk_site', $this->site_id)->find($page_id); $page->menu = 'no'; $page->save(); die('Page is hidden'); # success }
public function settings($tool_id = NULL) { valid::id_key($tool_id); $review = ORM::factory('review')->where('fk_site', $this->site_id)->find($tool_id); if (FALSE === $review->loaded) { die('invalid review'); } if ($_POST) { $review->name = $_POST['name']; $review->view = $_POST['view']; #$review->params = $_POST['params']; $review->save(); die('review Settings Saved.'); } switch ($review->type) { case 'people': $type_views = array('list', 'filmstrip'); break; case 'contacts': $type_views = array('list'); break; case 'faqs': $type_views = array('simple'); break; case 'tabs': $type_views = array('stock'); break; default: $type_views = array(); break; } $view = new View('edit_review/settings'); $view->review = $review; $view->type_views = $type_views; $view->js_rel_command = "update-review-{$tool_id}"; die($view); }
public function event($id = NULL) { die('offline'); valid::id_key($id); $db = new Database(); $event = $db->query("\n SELECT * FROM calendar_items \n WHERE id = '{$id}' \n AND fk_site = '{$this->site_id}'\n ")->current(); if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == "XMLHttpRequest") { $primary = new View('public_calendar/small/event'); $primary->event = $event; echo $primary; } else { echo 'nice formatted page'; die; $view = new View('shell'); $primary = new View('public_calendar/small/event'); $primary->event = $event; echo $view; } }
public function delete() { valid::id_key($this->item_id); ORM::factory('calendar_item')->where('fk_site', $this->site_id)->delete($this->item_id); die('Calendar item deleted.'); }
public function delete_comment($id = NULL) { valid::id_key($id); ORM::factory('blog_post_comment')->where(array('fk_site' => $this->site_id))->delete($id); die('Comment deleted!'); #status }
public function delete() { valid::id_key($this->item_id); ORM::factory('format_item')->where('fk_site', $this->site_id)->delete($this->item_id); die('format item deleted'); }
private function edit($page_name, $tool_id, $type, $id) { valid::id_key($id); if (!$this->account_user->logged_in($this->site_id)) { die('Please Login'); } if (!empty($_POST['body'])) { if ('post' == $type) { $post = ORM::Factory('forum_cat_post', $id); $post->title = $_POST['title']; $id = $post->forum_cat_post_comment_id; $post->save(); } $comment = ORM::Factory('forum_cat_post_comment', $id); $comment->body = $_POST['body']; $comment->save(); # output a success message. $status = new View('public_forum/forums/status'); $status->success = true; $status->message = 'Edits Saved!!'; return $status; } $primary = new View('public_forum/forums/edit'); $primary->page_name = $page_name; switch ($type) { case 'post': $post = ORM::Factory('forum_cat_post')->find($id); if (!$post->loaded) { return 'invalid post id'; } $primary->post = TRUE == $post->loaded ? $post : FALSE; $comment_id = $post->forum_cat_post_comment_id; break; case 'comment': $primary->post = FALSE; $comment_id = $id; break; default: Event::run('system.404'); } $comment = ORM::Factory('forum_cat_post_comment')->where('account_user_id', $this->account_user->get_user()->id)->find($comment_id); if (!$comment->loaded) { return 'invalid comment id'; } $primary->comment = $comment; $primary->type = $type; $primary->id = $id; return $primary; }
private function edit() { if (!$this->owner->logged_in()) { return new View('public_forum/login'); } $type = $this->filter; $id = valid::id_key($this->filter2); if (!empty($_POST['body'])) { if ('post' == $type) { $post = ORM::Factory('forum_cat_post', $id); $post->title = $_POST['title']; $id = $post->forum_cat_post_comment_id; $post->save(); } $comment = ORM::Factory('forum_cat_post_comment', $id); $comment->body = $_POST['body']; $comment->save(); # output a success message. $status = new View('public_forum/status'); $status->success = true; $status->message = 'Edits Saved!!'; return $status; } $view = new View('public_forum/edit'); switch ($type) { case 'post': $post = ORM::Factory('forum_cat_post')->find($id); if (!$post->loaded) { return 'invalid post id'; } $view->post = TRUE == $post->loaded ? $post : FALSE; $comment_id = $post->forum_cat_post_comment_id; break; case 'comment': $view->post = FALSE; $comment_id = $id; break; default: Event::run('system.404'); } $comment = ORM::Factory('forum_cat_post_comment')->where('owner_id', $this->owner->get_user()->id)->find($comment_id); if (!$comment->loaded) { return 'invalid comment id'; } $view->comment = $comment; $view->type = $type; $view->id = $id; return $view; }