Example #1
0
function exception_handler($exception) {

  if(is_a($exception, "DataServerException")) {
    $error_query = "code=data&url=" . urlencode($_SERVER['REQUEST_URI']);
  } else if(is_a($exception, "DeviceNotSupported")) {
    $error_query = "code=device_notsupported";
  } else {
    $error_query = "code=internal";
  }
  $error_url = "../error-page/?{$error_query}";

  // a text representation of the exception
  ob_start();
    var_dump($exception);
  $text = ob_get_contents();
  ob_end_clean();

  if(!Page::factory()->is_spider()) {
    mail(
      DEVELOPER_EMAIL, 
      "mobile web page experiencing problems",
      "the following url is throwing exceptions: http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}\n" .
      "Exception:\n" . 
      "$text\n" .
      "The User-Agent: \"{$_SERVER['HTTP_USER_AGENT']}\"\n" .
      "The referer URL: \"{$_SERVER['HTTP_REFERER']}\""
    );
  }

  header("Location: {$error_url}");
  die(0);
}
Example #2
0
 public function new_content($cname, $pid)
 {
     $page = Page::factory((int) $pid);
     $ctype = ContentType::factory()->where('classname', "Gallery")->limit(1)->get();
     $content = Content::factory();
     $content->div = $cname;
     $content->editor_id = $this->user->id;
     $content->page_id = $page->id;
     $content->contenttype_id = $ctype->id;
     $content->save();
     $redir = site_url('administration/images/gallery_add_new/' . $content->id . '/' . $cname . '/' . $pid) . '?iu-popup';
     redirect($redir);
 }
Example #3
0
 public function ajax_save()
 {
     $id = (int) $this->input->post('id');
     $pid = (int) $this->input->post('page_id');
     $div = $this->input->post('div');
     $title = $this->input->post('title');
     $text = $this->input->post('text');
     $img = $this->input->post('image');
     //file_put_contents('post', json_encode($_POST));die;
     $page = Page::factory($pid);
     $content = Content::factory()->where('div', $div)->where_related_page('id', $pid)->limit(1)->get();
     if (!$content->exists()) {
         $content = new Content();
         $content->div = $div;
         $ctype = ContentType::factory()->where('classname', 'Repeatable')->limit(1)->get();
         $content->editor_id = $this->user->id;
         $content->save(array($page, $ctype));
     } else {
         $content->editor_id = $this->user->id;
         $content->save();
     }
     if (empty($id)) {
         $item = new RepeatableItem();
         $item->timestamp = time();
     } else {
         $item = RepeatableItem::factory($id);
     }
     $item->title = $title;
     $item->text = $text;
     $item->image = trim($img, '/');
     if (empty($id)) {
         $item->save(array($content, $this->user));
     } else {
         $item->save();
     }
     if (empty($id)) {
         $msg = __("New item published: \"%s\"", $title);
     } else {
         $msg = __("Changes saved in \"%s\"", $title);
     }
     echo json_encode(array('status' => 'OK', 'message' => $msg, 'id' => $item->id));
 }
Example #4
0
File: js.php Project: jotavejv/CMS
 public function init()
 {
     header("Content-Type: application/x-javascript");
     echo "var IU_SITE_URL = '" . str_replace("'", "\\'", rtrim(site_url(), '/')) . "';\n";
     echo "var IU_BASE_URL = '" . str_replace("'", "\\'", base_url()) . "';\n";
     echo "var IU_GLOBALS = {}; //throw anything in here\n";
     $pages = Page::factory()->get();
     $pages_arr = array();
     foreach ($pages as $p) {
         $page = new stdClass();
         $page->uri = $p->uri;
         $page->label = $p->title . ' ' . $p->uri;
         $page->url = site_url($p->uri);
         $page->title = character_limiter($p->title, 50);
         $page->id = $p->id;
         $pages_arr[] = $page;
     }
     echo "var IU_PAGES = " . json_encode($pages_arr) . ";\n";
     $settings = Setting::factory()->where('group !=', 'hidden')->where('group !=', 'branding')->get();
     $setts = array();
     foreach ($settings as $s) {
         $setts[$s->name] = $s->value;
     }
     echo "var IU_SETTINGS = " . json_encode($setts) . ";\n";
     if (!empty($this->user)) {
         $juser = $this->user->stored;
         unset($juser->salt);
         unset($juser->password);
         unset($juser->key);
         unset($juser->active);
         echo "var IU_USER = "******";\n";
         $perms = Permission::factory()->where_related_user('id', $this->user->id)->get();
         $permarr = array();
         foreach ($perms as $p) {
             $permarr[] = $p->key;
         }
         echo "var IU_USER_PERMISSIONS = " . json_encode($permarr) . ";\n";
     }
 }
<?php

require_once "config/mobi_web_constants.php";
require "page_builder/Page.php";
$page = Page::factory();
if ($page->is_computer() || $page->is_spider()) {
    header("Location: ./about/");
} else {
    header("Location: ./home/");
}
Example #6
0
<?php

/**
 * Copyright (c) 2008 Massachusetts Institute of Technology
 * 
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 * 
 */
require "../page_builder/Page.php";
require "../page_builder/counter.php";
$phone = Page::classify_phone();
$page = Page::factory($phone);
$prefix = $page->requirePrefix();
require_once "../../config.gen.inc.php";
require "../templates/{$prefix}/help.html";
# including this section screws w/ jQTouch
if ($prefix != 'webkit') {
    $page->cache();
    $page->output();
}
<?php

/**
 * Copyright (c) 2008 Massachusetts Institute of Technology
 * 
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 * 
 */
require_once "Page.php";
require_once "detection.php";
require_once "adapter.php";
require_once "page_tools.php";
require_once "counter.php";
$prefix = Device::templates();
$page = Page::factory($prefix);
// check to see if this is a deep link, if so redirect
// must be a webkit classified browser and missing the interal request [ir] var
// ir var is defined in jqtouch for GETs and as a hidden var in forms
if ($prefix == 'webkit' && (!$_REQUEST['ir'] || $_REQUEST['ir'] == '')) {
    header("location:/?redirect=" . $_SERVER['REQUEST_URI']);
}
// record stats for the section in the database
$section = Page::getSection($_SERVER['REQUEST_URI']);
PageViews::increment($section);
class DataServerException extends Exception
{
}
// use php default error handler for the dev version of the web site
// unccmment the line below to use the custom exception handler
// set_exception_handler("exception_handler");
Example #8
0
 public function page($uri = null)
 {
     if (empty($uri)) {
         return $this->page != null ? $this->page->stored : null;
     } elseif (is_numeric($uri)) {
         return Page::factory((int) $uri)->stored;
     } else {
         return Page::factory()->get_by_uri($uri)->stored;
     }
 }
Example #9
0
 public function days($days = 30)
 {
     //hits
     $hits = Hit::factory()->fetch(time() - 3600 * 24 * $days)->cnt();
     $hitsflow = Hit::timeflow(time() - 3600 * 24 * $days, null, 30, false);
     $unique = Hit::factory()->fetch(time() - 3600 * 24 * $days)->unique()->cnt();
     $uniqueflow = Hit::timeflow(time() - 3600 * 24 * $days, null, 30, true);
     $this->templatemanager->assign('hits', $hits);
     $this->templatemanager->assign('hitsflow', $hitsflow);
     $this->templatemanager->assign('unique', $unique);
     $this->templatemanager->assign('uniqueflow', $uniqueflow);
     $this->templatemanager->assign('days', $days);
     //pages
     $pagehits = Hit::factory()->select('*')->select_func('COUNT', '@id', 'cnt')->include_related('page', null, TRUE, TRUE)->where('page_id >', 0)->fetch(time() - 3600 * 24 * $days)->unique('page_id')->limit(100)->get();
     for ($i = 0; $i < count($pagehits->all); $i++) {
         $pagehits->all[$i]->timeflow = Hit::timeflow(time() - 3600 * 24 * $days, null, 30, false, $pagehits->all[$i]->page_id);
     }
     $this->templatemanager->assign('pagehits', $pagehits);
     //sasa
     $returning = Hit::factory()->fetch(time() - 3600 * 24 * $days)->unique()->where('returning', true)->cnt();
     $returningflow = Hit::timeflow(time() - 3600 * 24 * $days, null, 30, true, null, true);
     $this->templatemanager->assign('returning', $returning);
     $this->templatemanager->assign('returningflow', $returningflow);
     //contents edited
     $cnt_edits = ContentRevision::factory()->where('created >=', time() - 3600 * 24 * $days)->get()->result_count();
     $new_users = User::factory()->where('created >=', time() - 3600 * 24 * $days)->get();
     $new_users = $new_users->result_count();
     $new_pages = Page::factory()->where('created >=', time() - 3600 * 24 * $days)->get()->result_count();
     $repeats = RepeatableItem::factory()->where('timestamp >=', time() - 3600 * 24 * $days)->get()->result_count();
     $this->templatemanager->assign('cnt_edits', $cnt_edits);
     $this->templatemanager->assign('new_users', $new_users);
     $this->templatemanager->assign('new_pages', $new_pages);
     $this->templatemanager->assign('repeatables', $repeats);
     //get stats for browsers
     $browsers = Hit::factory()->select('browser')->select_func('COUNT', '@id', 'cnt')->fetch(time() - 3600 * 24 * $days)->unique('browser')->order_by('cnt DESC')->get();
     $browsersarr = array();
     $browsers->iu_total = 0;
     foreach ($browsers as $bro) {
         $browsers->iu_total += $bro->cnt;
     }
     $limit = $browsers->result_count() > 10 ? 10 : $browsers->result_count();
     for ($i = 0; $i < $limit; $i++) {
         $br = $browsers->all[$i];
         $obj = new stdClass();
         $obj->label = str_replace("'", "\\'", $br->browser) . ' (' . percent($br->cnt, $browsers->iu_total) . '%)';
         $obj->data = (int) $br->cnt;
         $browsersarr[] = $obj;
     }
     //usort($browsersarr, array($this, 'compare_series'));
     $this->templatemanager->assign('browsers', $browsers);
     $this->templatemanager->assign('browsers_series', $browsersarr);
     //get stats for operating systems
     $oses = Hit::factory()->select('os')->select_func('COUNT', '@id', 'cnt')->fetch(time() - 3600 * 24 * $days)->unique('os')->order_by('cnt DESC')->get();
     $osarr = array();
     $oses->iu_total = 0;
     foreach ($oses as $osi) {
         $oses->iu_total += $osi->cnt;
     }
     $limit = $oses->result_count() > 10 ? 10 : $oses->result_count();
     for ($i = 0; $i < $limit; $i++) {
         $os = $oses->all[$i];
         $obj = new stdClass();
         $obj->label = str_replace("'", "\\'", $os->os) . ' (' . percent($os->cnt, $oses->iu_total) . '%)';
         $obj->data = (int) $os->cnt;
         $osarr[] = $obj;
     }
     //usort($osarr, array($this, 'compare_series'));
     $this->templatemanager->assign('oses', $oses);
     $this->templatemanager->assign('oses_series', $osarr);
     //get stats for countries
     $geoip_db_filename = './iu-resources/geoip/GeoIP.dat';
     if (is_file($geoip_db_filename)) {
         $countries = Hit::factory()->select('country')->select_func('COUNT', '@id', 'cnt')->fetch(time() - 3600 * 24 * $days)->unique('country')->order_by('cnt DESC')->get();
         $conarr = array();
         $countries->iu_total = 0;
         foreach ($countries as $cou) {
             $countries->iu_total += $cou->cnt;
         }
         //var_dump(percent(20,100));
         $limit = $countries->result_count() > 10 ? 10 : $countries->result_count();
         for ($i = 0; $i < $limit; $i++) {
             $c = $countries->all[$i];
             $obj = new stdClass();
             $obj->label = str_replace("'", "\\'", empty($c->country) ? __("(unknown)") : $c->country) . ' (' . percent($c->cnt, $countries->iu_total) . '%)';
             $obj->data = (int) $c->cnt;
             $conarr[] = $obj;
         }
         //usort($conarr, array($this, 'compare_series'));
         $this->templatemanager->assign('countries', $countries);
         $this->templatemanager->assign('countries_series', $conarr);
     }
     $this->templatemanager->show_template('statistics');
 }
Example #10
0
 public function save($id)
 {
     $relations = array();
     //file_put_contents('post', json_encode($_POST));
     $pid = $this->input->post('pid');
     //$div_id = $this->input->post('div');
     $html = $this->input->post('html');
     if (!empty($pid)) {
         $page = Page::factory()->get_by_id((int) $pid);
         $relations[] = $page;
     }
     $content = Content::factory()->get_by_id($id);
     if (!$this->user->can_edit_content($content)) {
         if ($this->is_ajax_request()) {
             die(json_encode(array('status' => 'Error', 'message' => __("You don't have enough permissions to edit this content!"))));
         } else {
             $this->templatemanager->notify_next("You don't have enough permissions to edit this content!", 'failure');
             redirect('administration/dashboard');
         }
     }
     $old_html = $content->contents;
     $old_editor = $content->editor_id;
     $old_ts = !empty($content->updated) ? $content->updated : $content->created;
     //set/unset editors
     $editors = $this->input->post('editors');
     if (!empty($editors)) {
         $editors_users = User::factory()->where_in('id', $editors)->get();
         $not_editors_users = User::factory()->where_not_in('id', $editors)->get();
     }
     //set page and content editor
     $page->editor_id = $this->user->id;
     $content->editor_id = $this->user->id;
     //set contents
     $content->contents = empty($html) ? '' : $html;
     //save page and contents
     $page->save();
     //set content type
     $ctype_id = (int) $this->input->post('type');
     if ($ctype_id > 0 && $this->user->owns_page($page)) {
         $relations[] = ContentType::factory($ctype_id);
     }
     if ($this->user->owns_page($page)) {
         $content->is_global = $this->input->post('global') == 'yes';
     }
     //remove non and save editors
     if (!empty($editors) && $this->user->owns_page($page)) {
         $content->delete_editor($not_editors_users->all);
         $content->save_editor($editors_users->all);
     }
     $content->save($relations);
     //create revision
     $rev = new ContentRevision();
     $rev->contents = $old_html;
     $rev->user_id = $old_editor;
     $rev->created = $old_ts;
     $rev->save(array($content, $this->user));
     $this->templatemanager->notify_next(__("Content \"%s\" is saved!", $content->div), 'success');
     if ($this->is_ajax_request()) {
         echo json_encode(array('status' => 'OK', 'message' => __("Content \"%s\" is saved!", $div_id)));
     } else {
         redirect('administration/contents/edit/' . $content->id . '/' . $content->div);
     }
 }
Example #11
0
/**
 * Copyright (c) 2008 Massachusetts Institute of Technology
 * 
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 * 
 */
// various copy includes
require_once "../../config.gen.inc.php";
// records stats
require_once "../page_builder/page_header.php";
// include YAML loader
require $install_path . "lib/spyc-0.4.5/spyc.php";
// force basic templates & methods for all requests
$page = Page::factory('basic');
// shared functions
function f($count)
{
    $count_str = (string) $count;
    if (strlen($count_str) <= 3) {
        return $count_str;
    } else {
        return f(substr($count_str, 0, -3)) . ',' . substr($count_str, -3);
    }
}
function per_cent($part, $total)
{
    return round(100 * $part / $total);
}
// set-up search dates
Example #12
0
 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");
 }
Example #13
0
 public function owns_page($page)
 {
     if (empty($page)) {
         return false;
     }
     if (is_numeric($page)) {
         $page = Page::factory($page);
     }
     //if page doesn't exist, return false
     if (!$page->exists()) {
         return false;
     }
     return $page->user_id == $this->id;
 }
Example #14
0
 public function linkdialog_choose()
 {
     $pages = Page::factory()->get();
     $this->templatemanager->assign('pages', $pages);
     $this->templatemanager->load_template('pages_linkdialog');
 }
Example #15
0
 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));
 }