Exemplo n.º 1
0
function str_get_html($str, $lowercase = true, $forceTagsClosed = true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN = true, $defaultBRText = DEFAULT_BR_TEXT)
{
    $dom = new htmldom(null, $lowercase, $forceTagsClosed, $target_charset, $defaultBRText);
    if (empty($str)) {
        $dom->clear();
        return false;
    }
    $dom->load($str, $lowercase, $stripRN);
    return $dom;
}
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 get_meta($name)
 {
     if ($this->mime_type() != 'text/html') {
         return NULL;
     }
     $html = $this->html();
     $dom = new htmldom();
     $dom->load($html);
     $titleD = $dom->find('head meta[name=' . $name . ']', 0);
     if (!empty($titleD)) {
         return $titleD->content;
     } else {
         return '';
     }
 }
Exemplo n.º 4
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));
 }
Exemplo n.º 5
0
 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 . '">' . __("&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
         			{
         				$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;
 }