Exemplo n.º 1
0
 public static function factory($id = null)
 {
     $instance = new RepeatableItem();
     if (!empty($id)) {
         $instance->where('id', $id)->get();
     }
     return $instance;
 }
Exemplo n.º 2
0
 public function process($div, $content, $page)
 {
     //get first (and hopefully only one) item
     $domitem = $div->find('.iu-item', 0);
     //if no domitem, provide one
     if (empty($domitem)) {
         $tempdom = new htmldom();
         $tempdom->load('<html><body><div class="iu-item" style="float:left;width:100%;">' . "\n" . '<a class="iu-item-title" style="text-align: left;">Title</a><br />' . "\n" . '<img class="iu-item-image" width="150px" src="' . base_url() . '/iu-resources/images/no-image.png" /><br />' . "\n" . '<div style="width:100%; text-align: justify;" class="iu-item-text" data-limit="350">Text</div>' . "\n" . '<p style="text-align: left;">Posted by <span class="iu-item-author">' . (empty($this->_IU->user) ? 'author' : $this->_IU->user->name) . '</span>' . ' on <span class="iu-item-date">' . date('Y-m-d H:i') . '</span></p>' . "\n" . '<hr />' . "\n" . '</div></body></html>');
         $domitem = $tempdom->find('.iu-item', 0);
     }
     if ($content->exists()) {
         $single = $this->_IU->input->get($this->read_slug);
         $logged_in = !empty($this->_IU->user);
         if (!empty($single)) {
             //show only one
             $parts = explode('-', $single);
             $id = (int) $parts[0];
             $items = RepeatableItem::factory($id);
             //$page->set_title($items->title);
         } else {
             //read limit
             $limit = empty($div->{'data-per-page'}) ? 10 : (int) $div->{'data-per-page'};
             //var_dump($limit); die;
             $pagenr = (int) $this->_IU->input->get($this->page_slug);
             $pagenr = empty($pagenr) ? 1 : $pagenr;
             //find all items
             $items = RepeatableItem::factory()->where_related_content('id', $content->id)->where('timestamp <=', time())->order_by('timestamp DESC')->get_paged_iterated($pagenr, $limit);
         }
     }
     $div->innertext = '';
     if (!empty($domitem) && $content->exists() && !empty($items) && $items->result_count() > 0) {
         //if there are items, loop over them, create new repeatable item
         //and add it to the $div
         foreach ($items as $i) {
             $newdomitem = clone $domitem;
             //add new item to placeholder
             $div->innertext .= $this->process_template($newdomitem, $i, $page);
         }
         $hide_pagination = empty($div->{'data-hide-pagination'}) ? false : true;
         //add pagination
         if (empty($single) && !$hide_pagination && $items->paged->total_rows > $limit) {
             $paged = json_encode($items->paged);
             $div->innertext .= "<div class='iu-pagination' data-slug='" . $this->page_slug . "' data-paged='" . $paged . "'></div><img id='iu-pagination-loader' style='display: none; padding-left: 15px; padding-top: 5px' src='" . site_url('iu-resources/images/ajax-load.png') . "' alt='...' /><noscript><p>";
             $base_lnk = site_url($page->uri) . '?' . $this->page_slug . '=';
             //prev
             if ($items->paged->has_previous) {
                 $div->innertext .= '<span class="iu-paged-btn"><a href="' . $base_lnk . $items->paged->previous_page . '">' . __("&laquo; Prev") . '</a></span> ';
             }
             //pages
             for ($i = 1; $i <= $items->paged->total_pages; $i++) {
                 if ($i == $pagenr) {
                     $div->innertext .= '<span class="iu-paged-btn-disabled">' . $i . '</span> ';
                 } else {
                     $div->innertext .= '<span class="iu-paged-btn"><a href="' . $base_lnk . $i . '">' . $i . '</a></span> ';
                 }
             }
             //next
             if ($items->paged->has_next) {
                 $div->innertext .= '<span class="iu-paged-btn"><a href="' . $base_lnk . $items->paged->next_page . '">' . __("Next &raquo;") . '</a></span> ';
             }
             $div->innertext .= '</p></noscript>';
         }
     } else {
         //if there are no news items, apply other css to div
         if (empty($div->class)) {
             $classes2 = array();
         } else {
             $classes2 = explode(' ', $div->class);
         }
         if (!in_array("iu-empty", $classes2) && !empty($this->_IU->user)) {
             $classes2[] = "iu-empty";
         }
         $div->class = implode(' ', $classes2);
         if (empty($domitem) && !empty($this->_IU->user)) {
             $div->innertext .= __("Please define div with class \"iu-item\"");
         }
     }
     //apply iu-content-repeatable class if doesn't exist
     if (empty($div->class)) {
         $classes3 = array();
     } else {
         $classes3 = explode(' ', $div->class);
     }
     if (!in_array("iu-content-repeatable", $classes3)) {
         $classes3[] = "iu-content-repeatable";
     }
     $div->class = implode(' ', $classes3);
     //hide original news item
     if (!empty($domitem)) {
         if (empty($domitem->class)) {
             $classes = array();
         } else {
             $classes = explode(' ', $domitem->class);
         }
         if (!in_array("iu-invisible", $classes)) {
             $classes[] = "iu-invisible";
         }
         $domitem->class = implode(' ', $classes);
         $div->innertext .= "\n\n" . $domitem->outertext;
     }
     if (!empty($single)) {
         $parts = explode('-', $single);
         $id = (int) $parts[0];
         $item = RepeatableItem::factory($id);
         /*$page->set_title($item->title);
         		$page->set_meta('description', character_limiter(strip_tags($item->text), 350));
         		$page->set_meta('keywords', ''); //todo*/
     }
     return $div;
 }
Exemplo n.º 3
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');
 }
Exemplo n.º 4
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");
 }
Exemplo n.º 5
0
 public function remove($id)
 {
     $item = RepeatableItem::factory((int) $id);
     $title = $item->title;
     $content = $item->content->get();
     /*if ($item->exists() && (!empty($item->image)) && (trim($item->image) != 'iu-resources/images/no-image.png'))
     		{
     			$img = new Image($item->image);
     			$img->remove_thumbnails();
     			@unlink($item->image);
     		}//*/
     $item->remove();
     redirect('administration/contents/edit/' . $content->id . '/' . $content->div);
 }
Exemplo n.º 6
0
 public function repeatable_page($pid, $cid, $ppage, $pagenr)
 {
     $template = $this->input->post('template');
     $page = Page::factory((int) $pid);
     $content = Content::factory((int) $cid);
     $tempdom = new htmldom();
     $tempdom->load('<html><body>' . $template . '</body></html>');
     $domitem = $tempdom->find('.iu-item', 0);
     $items = RepeatableItem::factory()->where_related_content('id', (int) $cid)->where('timestamp <=', time())->order_by('timestamp DESC')->get_paged_iterated($pagenr, $ppage);
     require_once "./iu-application/libraries/contentprocessor.php";
     require_once "./iu-application/libraries/contents/Repeatable.php";
     $instance =& get_instance();
     $cp = new Repeatable($instance);
     $response = '';
     foreach ($items as $i) {
         $newdomitem = clone $domitem;
         //add new item to placeholder
         $response .= $cp->process_template($newdomitem, $i, $page);
     }
     echo json_encode(array('content' => $content->div, 'html' => $response));
 }