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)); }
} else { ?> <div> <?php } ?> <div class="widget"> <div class="title"><h6>Images in gallery "<?php echo $content->div; ?> " (drag and drop to re-order)</h6><div class="num"><a class="greyNum" id="status" style="display:none"></a></div></div> <!-- gallery --> <div class="gallery"> <ul id="sortable"> <?php $images = GalleryItem::factory()->where_related_content('id', $content->id)->get(); ?> <?php foreach ($images as $img) { ?> <li id="image_<?php echo $img->id; ?> "><img src="<?php echo Image::factory($img->image)->thumbnail(101, 101)->url; ?> " alt="<?php echo $img->title; ?> " title="<?php echo $img->title;
public function process($div, $content, $page) { //get first (and hopefully only one) item $domitem = $div->find('.iu-gallery-item', 0); //if no domitem, provide one if (empty($domitem)) { $tempdom = new htmldom(); $tempdom->load('<html><body><div class="iu-gallery-item" style="float:left;width:150px;">' . "\n" . '<img class="iu-gallery-image" width="150px" src="' . base_url() . '/iu-resources/images/no-image.png" />' . "\n" . '</div></body></html>'); $domitem = $tempdom->find('.iu-gallery-item', 0); } if ($content->exists()) { //$single = $this->_IU->input->get($this->read_slug); $logged_in = !empty($this->_IU->user); //read limit $limit = empty($div->{'data-per-page'}) ? 0 : (int) $div->{'data-per-page'}; $order = empty($div->{'data-order-by'}) ? 'order ASC, id DESC' : $div->{'data-order-by'}; //var_dump($limit); die; $pagenr = (int) $this->_IU->input->get($this->page_slug); $pagenr = empty($pagenr) ? 1 : $pagenr; //get images for current content $items = GalleryItem::factory()->where_related_content('id', $content->id)->order_by($order); if (empty($limit)) { $items->get(); } else { $items->get_paged_iterated($pagenr, $limit); } //get all images for this gallery $all_images = GalleryItem::factory()->where_related_content('id', $content->id)->order_by($order)->get(); } $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 $item) { $newdomitem = clone $domitem; //add new item to placeholder $div->innertext .= $this->process_template($newdomitem, $item, $page, $content); } $hide_pagination = empty($div->{'data-hide-pagination'}) ? false : true; //add pagination and hidden images (from other pages) if (!$hide_pagination && (isset($items->paged) && $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 . '">' . __("« 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 »") . '</a></span> '; } $div->innertext .= '</p></noscript>'; } /*else { $newdomitem = clone $domitem; $placeholder = new GalleryItem(); $placeholder->image = 'iu-resources/images/sample.png'; $placeholder->title = __('Sample Image'); $placeholder->text = __('This is a sample image. It will disappear once you upload first image!'); $div->innertext .= $this->process_template($newdomitem, $placeholder, $page, $content); } //*/ //hidden images and descriptions $jackbox = empty($newdomitem->{'data-no-lightbox'}) ? true : false; if ($jackbox && $content->exists() && isset($all_images) && $all_images->result_count() > 0) { $div->innertext .= '<ul rel="' . $content->div . '" class="iu-invisible">'; foreach ($all_images as $im) { $thumb = new Image($im->image); $thumb_url = $thumb->thumbnail(100)->url; $div->innertext .= '<li id="iu_gallery_el_' . $im->id . '" class="iu-gallery-member" data-group="' . $content->div . '" data-title="' . $im->title . '" data-description="#iu_gallery_desc_' . $im->id . '" data-href="' . $im->image . '" data-thumbnail="' . $thumb_url . '"></li>'; $div->innertext .= '<li id="iu_gallery_desc_' . $im->id . '"><h3>' . $im->title . '</h3> ' . $im->text . '</li>'; } $div->innertext .= '</ul>'; } } 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-gallery-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-gallery", $classes3)) { $classes3[] = "iu-content-gallery"; } $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; } return $div; }