public function index() { $reps = Content::factory()->where_related_contenttype('classname', 'Gallery')->order_by('updated DESC, created DESC')->get(); $this->templatemanager->assign("galleries", $reps); $this->templatemanager->set_title("Manage Galleries"); $this->templatemanager->show_template("galleries_list"); }
public function gallery_add_new($id, $cname, $pid) { $id = (int) $id; $pid = (int) $pid; $content = Content::factory()->get_by_id($id); $this->templatemanager->set_title("Add images"); $this->templatemanager->assign("content", $content); $this->templatemanager->show_template("gallery_images_upload"); }
<thead> <tr> <th class="sortCol"><div>ID<span></span></div></th> <th class="sortCol"><div>Last modified<span></span></div></th> <th class="">Actions</th> </tr> </thead> <tbody> <?php foreach ($divs as $div_id) { ?> <?php if ($div_id == $content->div) { continue; } $contentO = Content::factory()->where('div', $div_id)->group_start()->where_related_page('id', $page->id)->or_where('is_global', true)->group_end()->limit(1)->get(); if (!$user->can_edit_content($contentO)) { continue; } ?> <tr class="grade<?php echo !$contentO->exists() ? 'X' : (!empty($contentO->is_global) ? 'C' : 'A'); ?> "> <td class="center"><?php echo $div_id; ?> </td> <td class="center"><?php echo empty($contentO->updated) ? "—" : '<span class="tipN" title="' . date(Setting::value('datetime_format', 'F j, Y @ H:i'), $contentO->updated) . '">' . relative_time($contentO->updated) . '</span> ' . __('by %s', User::factory($contentO->editor_id)->name); ?>
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); } }
public function remove($cid, $back_to = 'pages') { $c = Content::factory((int) $cid); if ($c->exists()) { $page = $c->page->get(); $name = $c->div; $revs = $c->contentrevision->get(); $revs->delete_all(); $repeatables = $c->repeatableitem->get(); $repswimg = $c->repeatableitem->where('image !=', null); foreach ($repswimg as $r) { $im = new Image($r->image); $im->remove_thumbnails(); @unlink($r->image); } $repeatables->delete_all(); $c->delete(); $this->templatemanager->notify_next("Content \"{$name}\" is successfully removed!", 'success'); if (empty($back_to)) { redirect('administration/pages/edit/' . $page->uri); } else { redirect('administration/' . str_replace('-', '/', $back_to)); } } else { $this->templatemanager->notify_next("Content is already deleted!", 'failure'); redirect('administration/' . str_replace('-', '/', $back_to)); } }
public function index() { //get stats $last15 = Hit::factory()->fetch(time() - 60 * 15)->unique()->cnt(); $last15bymin = Hit::timeflow(time() - 60 * 15, null, 15); $last4hrs = Hit::factory()->fetch(time() - 3600 * 4)->unique()->cnt(); $last4hrsbymin = Hit::timeflow(time() - 3600 * 4, null, 16); $today = Hit::factory()->fetch(mktime(0, 0, 0))->unique()->cnt(); $todaybymin = Hit::timeflow(mktime(0, 0, 0), null, 24); $yesterday = Hit::factory()->fetch(mktime(0, 0, 0) - 3600 * 24, mktime(0, 0, 0))->unique()->cnt(); $yesterdaybymin = Hit::timeflow(mktime(0, 0, 0) - 3600 * 24, mktime(0, 0, 0), 24); $lastweek = Hit::factory()->fetch(mktime(0, 0, 0) - 3600 * 24 * 7)->unique()->cnt(); $lastweekbymin = Hit::timeflow(mktime(0, 0, 0) - 3600 * 24 * 7, null, 14); $lastmonth = Hit::factory()->fetch(mktime(0, 0, 0) - 3600 * 24 * 30)->unique()->cnt(); $lastmonthbymin = Hit::timeflow(mktime(0, 0, 0) - 3600 * 24 * 7, null, 30); $returning = Hit::factory()->fetch(time() - 3600 * 24 * 30)->unique()->where('returning', true)->cnt(); $new_pages = Page::factory()->where('created >=', time() - 3600 * 24 * 30)->get()->result_count(); $countries = Hit::factory()->fetch(time() - 3600 * 24 * 30)->group_by('country')->cnt(); $pagehits = Hit::factory()->select('*,count(page_id) as cnt')->include_related('page', null, TRUE, TRUE)->where('page_id >', 0)->fetch(time() - 3600 * 24 * 7)->group_by('page_id')->limit(1)->get(); $this->templatemanager->assign('pagehits', $pagehits); $ping = false; $pingset = Setting::factory('last_ping'); $lastping = (int) $pingset->value; if (time() - $lastping > 3600 * 24 * 7) { $ping = true; } $pingset->value = time(); $pingset->save(); $this->templatemanager->assign('last15', $last15); $this->templatemanager->assign('last15bymin', $last15bymin); $this->templatemanager->assign('last4hrs', $last4hrs); $this->templatemanager->assign('last4hrsbymin', $last4hrsbymin); $this->templatemanager->assign('today', $today); $this->templatemanager->assign('todaybymin', $todaybymin); $this->templatemanager->assign('yesterday', $yesterday); $this->templatemanager->assign('yesterdaybymin', $yesterdaybymin); $this->templatemanager->assign('lastweek', $lastweek); $this->templatemanager->assign('lastweekbymin', $lastweekbymin); $this->templatemanager->assign('lastmonth', $lastmonth); $this->templatemanager->assign('lastmonthbymin', $lastmonthbymin); $this->templatemanager->assign('returning', $returning); $this->templatemanager->assign('new_pages', $new_pages); $this->templatemanager->assign('countries', $countries); $this->templatemanager->assign('ping', $ping); //latest repeatables $last_repeatables = RepeatableItem::factory()->order_by('timestamp DESC')->limit(5)->get(); $this->templatemanager->assign('last_repeatables', $last_repeatables); //latest contents updated $last_contents = Content::factory()->where_related_contenttype('classname', 'Html')->order_by('updated DESC, created DESC')->limit(10)->get(); $this->templatemanager->assign('last_contents', $last_contents); //count content updates (revisions) $revs = ContentRevision::factory()->count(); $this->templatemanager->assign('revisions', $revs); //if geoip is old, notify $geoip_db_filename = './iu-resources/geoip/GeoIP.dat'; if (is_file($geoip_db_filename)) { $month_earlier = time() - 3600 * 24 * 30; $filemtime = filemtime($geoip_db_filename); if ($this->user->can('edit_settings') && $filemtime <= $month_earlier) { $lnk = site_url('administration/maintenance'); $this->templatemanager->notify(__("Your GeoIP database is now older than one month! Consider <a href='{$lnk}'>updating it</a>!"), 'information'); } } //get latest users $users = User::factory()->order_by('created DESC')->limit(5)->get(); $this->templatemanager->assign('users', $users); $this->templatemanager->show_template("dashboard"); }
public function can_edit_content($content) { //admin can edit all if ($this->is_admin()) { return true; } if (is_numeric($content)) { $content = Content::factory($content); } //if content does not exist, assume we can edit it if (empty($content) || !$content->exists()) { return true; } //if user can edit page, he can edit all contents if ($this->can_edit_page($content->page_id)) { return true; } //if user is editor of a content, return true if ($this->is_related_to('assigned_contents', $content->id)) { return true; } //by default, return false return false; }
public function save($id = null) { if (empty($id)) { $item = new RepeatableItem(); } else { $item = RepeatableItem::factory((int) $id); } if ($item->exists() && !$this->user->can_edit_content($item->content->get())) { $this->templatemanager->notify_next("You don't have enough permissions to edit this item's content!", 'failure'); redirect('administration/dashboard'); } $item->title = $this->input->post('title'); $item->text = $this->input->post('text'); $uid = (int) $this->input->post('user_id'); if ($this->user->is_admin()) { $item->user_id = empty($uid) ? $this->user->id : $uid; } else { $item->user_id = empty($id) ? $this->user->id : $item->user_id; } $date = $this->input->post('date'); $time = $this->input->post('time'); $cid = (int) $this->input->post('cid'); $dateparts = parse_datepicker($date); $timeparts = explode(':', $time); $ts = mktime($timeparts[0], $timeparts[1], 0, $dateparts['m'], $dateparts['d'], $dateparts['y']); $item->timestamp = $ts; //prepare for upload $config['upload_path'] = $this->user->assets_path(); $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = '512'; $config['max_width'] = '1024'; $config['max_height'] = '1024'; $config['encrypt_name'] = true; $this->load->library('upload', $config); //upload picture if (!empty($_FILES['image']['name'])) { if (!$this->upload->do_upload('image')) { show_error($this->upload->display_errors()); } else { $data = $this->upload->data(); $item->image = $config['upload_path'] . $data['file_name']; } } if ($item->exists()) { $item->save(); } else { $content = Content::factory($cid); $item->save(array($content)); } redirect('administration/repeatables/edit/' . $item->id); }
public function gallery_page($pid, $cid, $ppage, $pagenr) { $template = $this->input->post('template'); $page = Page::factory((int) $pid); $content = Content::factory((int) $cid); $ppage = (int) $ppage; $tempdom = new htmldom(); $tempdom->load('<html><body>' . $template . '</body></html>'); $domitem = $tempdom->find('.iu-gallery-item', 0); $content = Content::factory((int) $cid); $items = GalleryItem::factory()->where_related_content('id', (int) $cid); if (empty($ppage)) { $items->get(); } else { $items->get_paged_iterated($pagenr, $ppage); } require_once "./iu-application/libraries/contentprocessor.php"; require_once "./iu-application/libraries/contents/Gallery.php"; $instance =& get_instance(); $cp = new Gallery($instance); $response = ''; foreach ($items as $i) { $newdomitem = clone $domitem; //add new item to placeholder $response .= $cp->process_template($newdomitem, $i, $page, $content); } echo json_encode(array('content' => $content->div, 'html' => $response)); }