Example #1
0
 public function revert($fid, $rid)
 {
     $file = File::factory()->get_by_id((int) $fid);
     $revision = FileRevision::factory()->get_by_id((int) $rid);
     $old_html = $file->contents();
     $contents = $revision->contents;
     $old_editor = $file->editor_id;
     $old_ts = !empty($file->updated) ? $file->updated : $file->created;
     $succ = @file_put_contents($file->path, $contents);
     $file->editor_id = $this->user->id;
     if ($succ === FALSE) {
         $file->hash = md5($contents);
         $file->data = $contents;
     } else {
         $file->hash = md5_file($file->path);
     }
     $file->save();
     //create revision
     $rev = new FileRevision();
     $rev->contents = $old_html;
     $rev->user_id = $old_editor;
     $rev->created = $old_ts;
     $rev->save(array($file));
     //$revision->delete();
     $this->templatemanager->notify_next("Revision #{$revision->id} successfully reverted.", 'success');
     redirect('administration/templates/edit/' . $file->path);
 }
Example #2
0
 public function uri()
 {
     //get request uri
     $uri = $path = trim($this->uri->uri_string(), '/');
     if ($path == '.htaccess') {
         show_404($path);
     }
     //if uri is empty assign index.html or index.php (if index.html doesn't exist)
     if (empty($uri)) {
         $uri = $path = "index.htm";
         if (!is_file($path)) {
             $path = "index-original.htm";
         }
         if (!is_file($path)) {
             $uri = $path = "index.html";
         }
         if (!is_file($path)) {
             $path = "index-original.html";
         }
         if (!is_file($path)) {
             $uri = "index.php";
             $path = "index-original.php";
         }
     } elseif (is_dir($path)) {
         $p = rtrim($path, '/') . '/index.htm';
         if (!is_file($p)) {
             $p = rtrim($path, '/') . '/index.html';
         }
         if (!is_file($p)) {
             $p = rtrim($path, '/') . '/index.php';
         }
         $uri = $path = $p;
     }
     //fix for bad linking
     /*if (current_url() == site_url())
     		{
     			redirect(site_url($uri));
     			die;
     		}//*/
     //get page
     $this->page = $page = Page::factory()->get_by_uri($uri);
     //get file obj from db
     if (!$page->exists()) {
         $file = File::factory()->get_by_path($path);
     } else {
         $file = $page->file->get();
     }
     //if file doesn't exists in database, check if it needs to be saved in the
     // db and save it (if needed)
     if (!$file->exists()) {
         $file->path = $path;
         //if file doesn't exists on disk either, show 404
         if (!is_file($file->path)) {
             show_404($path);
         }
         $file->checksum = md5_file($file->path);
         //if user is logged in, add him as last editor
         if (!empty($this->user)) {
             $file->editor_id = $this->user->id;
         }
         //if html file, save it to the database
         if ($file->mime_type() == 'text/html') {
             $file->save();
         }
     }
     //if file exists in the database, check it and push it :)
     if ($file->mime_type() !== 'text/html') {
         $file->push();
     }
     $newpage = false;
     //if page doesn't exist
     if (!$page->exists()) {
         if (!$file->exists()) {
             //no page and no file!?
             show_404($uri);
         } else {
             $page->title = $file->get_title();
             $page->keywords = $file->get_meta('keywords');
             $page->description = $file->get_meta('description');
             $save2 = array($file);
             if (!empty($this->user)) {
                 $save2[] = $this->user;
             }
             $page->uri = $uri;
             $page->save($save2);
         }
         //new page!
         $newpage = true;
     } else {
         //check for file
         $f = $page->file->get();
         if ($f->exists()) {
             //if there is a file, assign it;
             $file = $f;
         } else {
             //assign default file
             if (is_file($page->uri)) {
                 $file = new File();
                 $file->path = $page->uri;
                 $file->checksum = md5_file($file->path);
                 if (!empty($this->user)) {
                     $file->editor_id = $this->user->id;
                 }
                 $file->save();
             } else {
                 $file = File::factory()->order_by('default DESC')->limit(1)->get();
             }
             $page->save(array($file));
         }
     }
     //write stats if not logged in
     if (empty($this->user)) {
         //read cookie and hit variables (ip address, user agent, etc)
         $cookie = $this->input->cookie('__iuvfc');
         $ip_address = $this->input->ip_address();
         $user_agent = $this->input->user_agent();
         $this->load->library('user_agent');
         //create and fill hit
         $hit = new Hit();
         $hit->os = BrowserOS::get_os($user_agent);
         $hit->browser = BrowserOS::get_browser_no_version($user_agent);
         $hit->ip_address = $ip_address;
         $hit->returning = !empty($cookie);
         //get page referer
         $referer = $this->agent->referrer();
         if (!empty($referer)) {
             //if referer is not coming from our site, write it to hit
             $domain = str_replace('www.', '', parse_url($referer, PHP_URL_HOST));
             $this_domain = str_replace('www.', '', parse_url(site_url(), PHP_URL_HOST));
             if ($domain != $this_domain) {
                 $hit->referer = $referer;
                 $hit->referer_domain = $domain;
             }
         }
         //set cookie for returning visitors
         $cookie = array('name' => '__iuvfc', 'value' => time(), 'expire' => 3600 * 24 * 30 * 12);
         $this->input->set_cookie($cookie);
         //define geoip database path
         $geoip_db_filename = './iu-resources/geoip/GeoIP.dat';
         //if geoip database exists
         if (is_file($geoip_db_filename)) {
             //we have a geoip db, store country
             $this->load->helper('geoip');
             $gi = @geoip_open($geoip_db_filename, GEOIP_STANDARD);
             $country_name = @geoip_country_name_by_addr($gi, $ip_address);
             if (empty($country_name)) {
                 $country_name = null;
             }
             $hit->country = $country_name;
         }
         if (!empty($hit->os) && !empty($hit->browser)) {
             $hit->save(array($page));
         }
     }
     //cache if logged out, not an ajax request and
     $this->load->library('cache');
     $this->cache->set_uri($page->uri);
     $cache_time = $page->cache_duration();
     if (empty($this->user) && !$this->is_ajax_request() && $file->mime_type() == 'text/html') {
         if ($cache_time > 0 && $this->cache->cache_exists($cache_time * 60)) {
             if (Setting::value('use_tidy', 'yes') == 'yes') {
                 die(html_tidy($this->cache->load_cache(false)));
             } else {
                 die($this->cache->load_cache(false));
             }
         }
     }
     /***** START PROCESSING HTML *****/
     if (!empty($page->title)) {
         $title = $page->title;
         $append_sitename = Setting::value('append_sitename_titles', 'yes') == 'yes';
         if ($append_sitename) {
             $title .= ' | ' . Setting::value('website_title');
         }
         $page->set_title($title);
     }
     //add meta tags
     if (!empty($page->keywords)) {
         $page->set_meta('keywords', $page->keywords);
     }
     if (!empty($page->description)) {
         $page->set_meta('description', $page->description);
     }
     //$page->set_meta('generator', 'Instant Update '.get_app_version());
     $page->set_encoding('utf-8');
     //$page->set_base_href();
     //embed jquery
     $page->embed('iu-resources/js/jquery.js');
     //embed jquery ui
     //$page->embed('iu-resources/js/jquery-ui.min.js');
     //$page->embed('iu-resources/css/bootstrap/bootstrap.css');
     $page->embed('iu-resources/min/?g=base-css', 'css');
     //dynamically define js variables
     $page->embed('iu-dynamic-js/init.js', null, false);
     //lightbox
     //$page->embed('http://fonts.googleapis.com/css?family=Mako', 'css');
     //$page->embed('iu-resources/lightbox/css/jackbox.css');
     //$page->embed_IE('iu-resources/lightbox/css/jackbox-ie8.css', 'lt', 9);
     $page->embed_IE('http://html5shiv.googlecode.com/svn/trunk/html5.js', 'lt', 9);
     /*$page->embed_IE('iu-resources/lightbox/css/jackbox-ie9.css', 'gt', 8);
     		$page->embed('iu-resources/lightbox/js/libs/Jacked.js');
     		$page->embed('iu-resources/lightbox/js/jackbox.js');*/
     $page->embed('iu-resources/min/?g=base-js', 'js');
     //load functions
     //$page->embed('iu-resources/js/phpjs.js');
     //$page->embed('iu-resources/js/functions.js');
     //embed webfont
     //$page->embed('http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js');
     //$page->embed('iu-resources/js/webfont.js');
     //embed jQ pagination
     //$page->embed('iu-resources/js/jquery.simplePagination.js');
     //$page->embed('iu-resources/css/simplePagination.css');
     //$page->embed('iu-resources/js/jquery.masonry.min.js');
     //$page->embed('iu-resources/js/jquery.scrollTo.min.js');
     //buttons
     //$page->embed('iu-resources/css/buttons.css');
     if (!empty($this->user)) {
         $page->embed('iu-application/views/administration/ckeditor/ckeditor.js');
         $page->embed('iu-resources/min/?g=user-js', 'js');
         //embed hallo (admin)
         //$page->embed('iu-resources/js/rangy/rangy-core.js');
         //$page->embed('iu-resources/js/hallo.js');
         //$page->embed('iu-resources/css/hallo.css');
         //$page->embed('iu-resources/css/image.css');
         //$page->embed('iu-resources/fontawesome/css/font-awesome.css');
         //$page->embed_IE('iu-resources/fontawesome/css/font-awesome-ie7.css', 'lt', 7);
         //splight
         //$page->embed('iu-resources/js/jquery.spotlight.pack.js');
         //embed jqconfigurator (admin only)
         //$page->embed('iu-resources/js/jqconfigurator.js');
         //msgbox
         //$page->embed('iu-resources/msgbox/jquery.msgbox.min.js');
         //$page->embed('iu-resources/msgbox/jquery.msgbox.css');
         //embed jgrowl (admin)
         //$page->embed('iu-resources/css/jquery.jgrowl.css');
         //$page->embed('iu-resources/js/jquery.jgrowl.min.js');
         //menu
         //$page->embed('iu-resources/css/pathmenu.min.css');
         //$page->embed('iu-resources/js/pathmenu.3.2.min.js');
         //embed header
         //$page->embed('iu-resources/css/iu-header.css');
     }
     //this loads at the end
     //$page->embed('iu-resources/css/style.css');
     //...if user is logged in
     //	if (!empty($this->user))
     //	$page->embed('iu-resources/js/instant.js', null, true);
     //$page->embed('iu-resources/js/domready.js', null, true);
     //process contents
     $blocks = $page->dom()->find('div[id],ol[id],ul[id],article[id],section[id],aside[id],content[id],menu[id],nav[id]');
     //load contentparser abstract class
     require_once "./iu-application/libraries/contentprocessor.php";
     foreach ($blocks as $block) {
         //skip div if it has class iu-skip
         if (stripos((string) $block->class, 'iu-skip') !== false) {
             continue;
         }
         //skip div if it contains other divs with id (except if it's marked with iu-content)
         $subdivs = $block->find('div[id],ol[id],ul[id],article[id],section[id],aside[id],content[id],menu[id],nav[id]');
         if ($subdivs != null && stripos((string) $block->class, 'iu-content') === false) {
             continue;
         }
         //*/
         $div_id = $block->id;
         $c = Content::factory()->where('div', $div_id)->group_start()->where_related_page('id', $page->id)->or_where('is_global', TRUE)->group_end()->limit(1)->get();
         //get classes
         if (empty($block->class)) {
             $classes = array();
         } else {
             $classes = explode(' ', $block->class);
         }
         //assume html type
         $ctype_class = 'Html';
         //if content exists in the database, get it's content type
         /*if ($c->exists())
         			{
         				$ctype_class = $c->contenttype->get()->classname;
         			}
         			//otherwise, guess content type from assigned class
         			else
         			{
         				//loop over all classes and process those starting with iu-content-
         				foreach ($classes as $classname)
         				{
         					$classname = strtolower($classname);
         					if (strpos($classname, 'iu-content-') === 0)
         					{
         						$parts = explode('-', $classname);
         						if (count($parts) != 3)
         							continue;
         
         						$ctype_class = ucfirst($parts[2]);
         						break;
         					}
         				}
         
         			}//*/
         //load class if it isn't loaded
         if (!class_exists($ctype_class)) {
             require_once "./iu-application/libraries/contents/{$ctype_class}.php";
         }
         //process block
         $instance =& get_instance();
         $ctype = new $ctype_class($instance);
         $block = call_user_func(array($ctype, 'process'), $block, $c, $page);
         //process via plugin
         //$block = PluginManager::do_actions('process.content', array($block, $c, $page));
         if (is_array($block)) {
             $block = $block[0];
         }
         //add DB ID if exists in DB
         if ($c->exists()) {
             $block->setAttribute('data-id', $c->id);
         }
         //get classes
         if (empty($block->class)) {
             $classes = array();
         } else {
             $classes = explode(' ', $block->class);
         }
         //if no classes starting with "iu-" - assume editable (StaticHTML)
         if (strpos($block->class, 'iu-content-') === false) {
             $classes[] = "iu-content-html";
         }
         //mark as global
         if (!empty($c->is_global)) {
             $classes[] = "iu-global";
         }
         $block->class = implode(' ', $classes);
         //if can edit
         if (!empty($this->user) && $this->user->can_edit_content($c)) {
             $block->setAttribute('data-canedit', 'true');
         }
     }
     //change title/desc for single item
     /*$single = $this->input->get('read');
     		if (!empty($single))
     		{
     			$parts = explode('-', $single);
     			$id = (int)$parts[0];
     			$item = RepeatableItem::factory($id);
     			$append_sitename = Setting::value('append_sitename_titles', 'yes') == 'yes';
     			$title = strip_tags($item->title);
     
     			if ($append_sitename)
     				$title .= ' | ' . Setting::value('website_title');
     
     			$page->set_title($title);
     			$page->set_meta('description', character_limiter(strip_tags($item->text), 150));
     			$page->set_meta('keywords', strip_tags($item->title));
     		}//*/
     $page->body()->setAttribute('data-uri', $page->uri);
     $page->body()->setAttribute('data-id', $page->id);
     $page->body()->setAttribute('data-template', $page->file->path);
     if ($newpage) {
         $page->body()->setAttribute('data-newpage', 'true');
     }
     //var_dump($page->body()->{'data-uri'}); die;
     if (!empty($this->user) && $this->user->can_edit_page($page)) {
         $page->body()->setAttribute('data-canedit', 'true');
     }
     /*$submenu = new AdminMenuItem('Page Summary', 'iu-icon-info', null, true);
     			$item2 = new AdminMenuItem(
     								"URI: <strong>/". $page->uri."</strong><br />\n"
     								. "Title: <strong>". character_limiter( $page->get_title(), 30 )."</strong><br />\n"
     								. "Last modified: <strong>".(empty($page->updated)? 'Never' : date('d.m.Y. \@ H:i', $page->updated))."</strong><br />\n"
     								. "File: <strong>/".$file->path."</strong><br />\n"
     								, null, null, false);
     			$item21 = new AdminMenuItem("Edit Page Settings", 'iu-icon-page-gear', site_url('administraton/pages/edit/'.$page->uri), false);
     
     		$submenu->add_item($item2);
     		$submenu->add_item($item21);
     
     		$item = new AdminMenuItem('Edit Source File', 'iu-icon-file-edit', site_url('administration/files/edit/'.$file->path), true);
     
     
     		$page->menu()->add_item($submenu);
     		$page->menu()->add_item($item);
     		$page->menu()->add_item(new AdminMenuItem('Administration Area', 'iu-icon-home', site_url('administration/dashboard'), true, 'iu-logout-icon'));
     		$page->menu()->add_item(new AdminMenuItem('Log Out', 'iu-icon-logout', site_url('administration/auth/logout'), true, 'iu-logout-icon'));
     //*/
     if (!empty($this->user)) {
         $page->body()->innertext = '<div id="fb-root" class="iu-skip"></div><div id="iu-menu" class="iu-skip"></div><div id="iu-jgrowl" class="iu-skip"></div>' . $page->body()->innertext;
     }
     //analytics
     $analytics_id = Setting::value('google_analytics_id', false);
     if (!empty($analytics_id)) {
         $page->body()->innertext .= "<script type=\"text/javascript\">\n\n  var _gaq = _gaq || [];\n  _gaq.push(['_setAccount', '{$analytics_id}']);\n  _gaq.push(['_trackPageview']);\n\n  (function() {\n    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n  })();\n\n</script>";
     }
     $page->prefix_relative_links();
     //$page = PluginManager::do_actions('process.page', $page);
     $html_code = $page->dom()->save();
     if (empty($this->user) && !$this->is_ajax_request() && $file->mime_type() == 'text/html' && $cache_time > 0) {
         $this->cache->save_cache($html_code);
     }
     if (Setting::value('use_tidy', 'yes') == 'yes') {
         $this->load->library('format');
         die($this->format->HTML($html_code));
         //die(html_tidy($html_code));
     } else {
         die($html_code);
     }
 }
Example #3
0
 public static function get_templates()
 {
     $files = File::factory()->get();
     $files_arr = array();
     foreach ($files as $f) {
         $ext = end(explode('.', $f->path));
         if (preg_match('/php[1-9]?|p?html?/si', $ext)) {
             $files_arr[] = $f;
         }
     }
     return $files_arr;
 }
Example #4
0
 /**
  * @param $template
  * @param array $values
  * @return string
  */
 public function render($template, $values = [])
 {
     return File::factory("{$this->path}/{$template}.php", $values + $this->predefinedValues)->render();
 }
Example #5
0
 public function save($id = NULL)
 {
     if (!empty($id)) {
         $page = Page::factory((int) $id);
     } else {
         $page = new Page();
         $page->uri = $this->input->post('uri', true);
     }
     $page->title = $this->input->post('title', true);
     $page->keywords = $this->input->post('keywords', true);
     $page->description = $this->input->post('description', true);
     $page->editor_id = $this->user->id;
     //caching?
     $page->custom_caching = $this->input->post('custom_caching') == 'yes';
     if ($page->custom_caching) {
         $page->custom_caching_duration = (int) str_replace(array(',', '.'), '', $this->input->post('cache_duration'));
     }
     //save editors
     $editors = $this->input->post('editors');
     $editors_users = User::factory()->where_in('id', $editors)->get();
     $not_editors_users = User::factory()->where_not_in('id', $editors)->get();
     //file
     $fid = $this->input->post('template', true);
     $save2 = array();
     if (!empty($fid)) {
         if (is_numeric($fid)) {
             $file = File::factory()->get_by_id((int) $fid);
         } else {
             $file = File::factory()->get_by_path($fid);
             if (!$file->exists()) {
                 $file->path = $fid;
                 $file->checksum = md5_file($fid);
                 $file->editor_id = $this->user->id;
                 $file->save();
             }
         }
         $tpl = $file->path;
         if (empty($tpl) && !empty($id)) {
             $tpl = $page->file->path;
         }
         if (!$file->exists()) {
             if (is_file($tpl)) {
                 $file->path = $tpl;
                 $file->save();
             } else {
                 show_error("Template file does not exist!");
             }
         }
         $save2[] = $file;
     }
     if ($this->user->can_edit_page($page)) {
         $owner_id = (int) $this->input->post('user');
         if (!empty($owner_id)) {
             $save2[] = User::factory($owner_id);
         } else {
             $save2[] = $this->user;
         }
     }
     $page->save($save2);
     if ($this->user->can_edit_page($page)) {
         //remove non editors, save editors
         $page->delete_editor($not_editors_users->all);
         $page->save_editor($editors_users->all);
     }
     $basename = basename($page->uri);
     $this->templatemanager->notify_next("Page {$basename} is successfully saved!", 'success');
     redirect('administration/pages/edit/' . $page->uri);
 }