function nvweb_menu_generate($mode = 'ul', $levels = 0, $parent = 0, $level = 0, $option = -1, $class = '') { global $structure; global $current; $out = ''; if ($level >= $levels && $levels > 0) { return ''; } nvweb_menu_load_structure($parent); if (!empty($structure['cat-' . $parent])) { switch ($mode) { case 'category_title': case 'current_title': if ($current['type'] == 'structure') { $out = $structure['dictionary'][$current['category']]; } else { if ($current['type'] == 'item') { $out = $structure['dictionary'][$current['object']->category]; } } break; case 'category_link': case 'category_url': if ($current['type'] == 'structure') { $out = nvweb_source_url('structure', $current['category']); } else { if ($current['type'] == 'item') { $out = nvweb_source_url('structure', $current['object']->category); } else { $out = '#'; } } break; case 'a': $out[] = '<div class="menu_level_' . $level . ' ' . $class . '">'; for ($m = 0; $m < count($structure['cat-' . $parent]); $m++) { if (!nvweb_object_enabled($structure['cat-' . $parent][$m])) { continue; } if ($structure['cat-' . $parent][$m]->visible == 0) { continue; } $mid = $structure['cat-' . $parent][$m]->id; // hide menu items without a title if (empty($structure['dictionary'][$mid])) { continue; } $aclass = ''; if (in_array($mid, $current['hierarchy'])) { $aclass = ' class="menu_option_active"'; } $out[] = '<a' . $aclass . ' ' . nvweb_menu_action($mid) . '>' . $structure['dictionary'][$mid] . '</a>'; if ($option == $m) { return array_pop($out); } $out[] = nvweb_menu_generate($mode, $levels, $mid, $level + 1); } $out[] = '</div>'; $out = implode("\n", $out); break; case 'select': $out[] = '<select class="menu_level_' . $level . ' ' . $class . '">'; for ($m = 0; $m < count($structure['cat-' . $parent]); $m++) { if (!nvweb_object_enabled($structure['cat-' . $parent][$m])) { continue; } if ($structure['cat-' . $parent][$m]->visible == 0) { continue; } $mid = $structure['cat-' . $parent][$m]->id; // hide menu items without a title if (empty($structure['dictionary'][$mid])) { continue; } $aclass = ''; if (in_array($mid, $current['hierarchy'])) { $aclass = ' class="menu_option_active" selected="selected"'; } $target = ''; $act = nvweb_menu_action($mid, NULL, false, false); if (strpos($act, 'target="_blank"') !== false) { $target = 'target="_blank"'; } if (strpos($act, 'onclick') !== false) { $act = '#'; } $act = str_replace('target="_blank"', '', $act); $act = str_replace('data-sid', 'data_sid', $act); $act = str_replace('href="', '', $act); $act = str_replace('"', '', $act); $act = trim($act); $out[] = '<option' . $aclass . ' value="' . $mid . '" href="' . $act . '" ' . $target . '>' . $structure['dictionary'][$mid] . '</option>'; if ($option == $m) { return array_pop($out); } $submenu = nvweb_menu_generate($mode, $levels, $mid, $level + 1); $submenu = strip_tags($submenu, '<option>'); $parts = explode('>', $submenu); $submenu = ''; for ($p = 0; $p < count($parts); $p++) { if (strpos($parts[$p], '</option') !== false) { $parts[$p] = '– ' . $parts[$p]; } } $submenu = implode('>', $parts); $out[] = $submenu; } $out[] = '</select>'; $out = implode("\n", $out); break; default: case 'ul': $ul_items = 0; $out[] = '<ul class="menu_level_' . $level . ' ' . $class . '">'; for ($m = 0; $m < count($structure['cat-' . $parent]); $m++) { if (!nvweb_object_enabled($structure['cat-' . $parent][$m])) { continue; } if ($structure['cat-' . $parent][$m]->visible == 0) { continue; } $mid = $structure['cat-' . $parent][$m]->id; // hide menu items without a title if (empty($structure['dictionary'][$mid])) { continue; } $aclass = ''; if (in_array($mid, $current['hierarchy'])) { $aclass = ' class="menu_option_active"'; } $out[] = '<li' . $aclass . '>'; $out[] = '<a' . $aclass . ' ' . nvweb_menu_action($mid) . '>' . $structure['dictionary'][$mid] . '</a>'; if ($option == $m) { return array_pop($out); } $out[] = nvweb_menu_generate($mode, $levels, $mid, $level + 1); $out[] = '</li>'; $ul_items++; } $out[] = '</ul>'; if ($ul_items == 0) { array_pop($out); array_pop($out); } $out = implode("\n", $out); break; } } return $out; }
function nvweb_content($vars = array()) { global $website; global $DB; global $current; global $template; global $structure; $out = ''; switch (@$vars['mode']) { case 'title': if ($current['type'] == 'structure') { $rs = nvweb_content_items($current['object']->id, true, 1); $texts = webdictionary::load_element_strings('item', $rs[0]->id); $out = $texts[$current['lang']]['title']; } else { $texts = webdictionary::load_element_strings($current['type'], $current['object']->id); $out = $texts[$current['lang']]['title']; } if (!empty($vars['function'])) { eval('$out = ' . $vars['function'] . '("' . $out . '");'); } break; case 'date': case 'date_post': $ts = $current['object']->date_to_display; // if no date, return nothing if (!empty($ts)) { $out = nvweb_content_date_format(@$vars['format'], $ts); } break; case 'date_created': $ts = $current['object']->date_created; $out = $vars['format']; $out = nvweb_content_date_format($out, $ts); break; case 'comments': // display published comments number for the current item $out = nvweb_content_comments_count(); break; case 'views': $out = $current['object']->views; break; case 'summary': $length = 300; $allowed_tags = array(); if (!empty($vars['length'])) { $length = intval($vars['length']); } $texts = webdictionary::load_element_strings('item', $current['object']->id); $text = $texts[$current['lang']]['main']; if (!empty($vars['allowed_tags'])) { $allowed_tags = explode(',', $vars['allowed_tags']); } $out = core_string_cut($text, 300, '…', $allowed_tags); break; case 'author': if (!empty($current['object']->author)) { $nu = new user(); $nu->load($current['object']->author); $out = $nu->username; unset($nu); } if (empty($out)) { $out = $website->name; } break; case 'structure': // force loading structure data nvweb_menu(); $structure_id = 0; if ($current['type'] == 'item') { $structure_id = $current['object']->category; } else { if ($current['type'] == 'structure') { $structure_id = $current['object']->id; } } switch ($vars['return']) { case 'path': $out = $structure['routes'][$structure_id]; break; case 'title': $out = $structure['dictionary'][$structure_id]; break; case 'action': $out = nvweb_menu_action($structure_id); break; default: } break; case 'tags': $tags = array(); $search_url = nvweb_source_url('theme', 'search'); if (!empty($search_url)) { $search_url .= '?q='; } else { $search_url = NVWEB_ABSOLUTE . '/nvtags?q='; } $ids = array(); if (empty($vars['separator'])) { $vars['separator'] = ' '; } $class = 'item-tag'; if (!empty($vars['class'])) { $class = $vars['class']; } if (!empty($vars['id'])) { $itm = new item(); $itm->load($vars['id']); $enabled = nvweb_object_enabled($itm); if ($enabled) { $texts = webdictionary::load_element_strings('item', $itm->id); $itags = explode(',', $texts[$current['lang']]['tags']); if (!empty($itags)) { for ($i = 0; $i < count($itags); $i++) { if (empty($itags[$i])) { continue; } $tags[$i] = '<a class="' . $class . '" href="' . $search_url . $itags[$i] . '">' . $itags[$i] . '</a>'; } } } } else { if ($current['type'] == 'item') { // check publishing is enabled $enabled = nvweb_object_enabled($current['object']); if ($enabled) { $texts = webdictionary::load_element_strings('item', $current['object']->id); $itags = explode(',', $texts[$current['lang']]['tags']); if (!empty($itags)) { for ($i = 0; $i < count($itags); $i++) { if (empty($itags[$i])) { continue; } $tags[$i] = '<a class="' . $class . '" href="' . $search_url . $itags[$i] . '">' . $itags[$i] . '</a>'; } } } } else { if ($current['type'] == 'structure') { $rs = nvweb_content_items($current['object']->id); foreach ($rs as $category_item) { $enabled = nvweb_object_enabled($category_item); if ($enabled) { $texts = webdictionary::load_element_strings('item', $current['object']->id); $itags = explode(',', $texts[$current['lang']]['tags']); if (!empty($itags)) { for ($i = 0; $i < count($itags); $i++) { $tags[$i] = '<a class="' . $class . '" href="' . $search_url . $itags[$i] . '">' . $itags[$i] . '</a>'; } } } } } } } $out = implode($vars['separator'], $tags); break; case 'section': case 'body': default: if (empty($vars['section'])) { $vars['section'] = 'main'; } $section = "section-" . $vars['section']; if ($current['type'] == 'item') { // check publishing is enabled $enabled = nvweb_object_enabled($current['object']); $texts = NULL; // retrieve last saved text (is a preview request from navigate) if ($_REQUEST['preview'] == 'true' && $current['navigate_session'] == 1) { $texts = webdictionary_history::load_element_strings('item', $current['object']->id, 'latest'); } else { if ($enabled) { $texts = webdictionary::load_element_strings('item', $current['object']->id); } } // have we found any content? if (!empty($texts)) { foreach ($template->sections as $tsection) { if ($tsection['id'] == $vars['section'] || $tsection['code'] == $vars['section']) { switch ($tsection['editor']) { case 'raw': $out = nl2br($texts[$current['lang']][$section]); break; case 'html': case 'tinymce': default: $out = $texts[$current['lang']][$section]; break; } break; } } } } else { if ($current['type'] == 'structure') { $rs = nvweb_content_items($current['object']->id); foreach ($rs as $category_item) { $enabled = nvweb_object_enabled($category_item); if (!$enabled) { continue; } else { $texts = webdictionary::load_element_strings('item', $category_item->id); foreach ($template->sections as $tsection) { if ($tsection['id'] == $vars['section'] || $tsection['code'] == $vars['section']) { switch ($tsection['editor']) { case 'raw': $texts[$current['lang']][$section] = nl2br($texts[$current['lang']][$section]); break; case 'html': case 'tinymce': default: // we don't need to change a thing // $texts[$current['lang']][$section] = $texts[$current['lang']][$section]; break; } break; } } $out .= '<div id="navigate-content-' . $category_item->id . '-' . $section . '">' . $texts[$current['lang']][$section] . '</div>'; } } } } break; } return $out; }
function nvweb_gallery($vars = array()) { global $website; global $DB; global $current; global $webgets; $out = ''; $webget = 'gallery'; // the request can come from a free item or from a category, so we have to load the first element available $item = NULL; $border = ''; if (!empty($vars['border'])) { $border = '&border=' . $vars['border']; } $items = PHP_INT_MAX; // number of images shown, 0 => all gallery photos if (!empty($vars['items']) && $vars['items'] != '0') { $items = intval($vars['items']); } $order = 'priority'; // display images using the assigned priority if (!empty($vars['order'])) { $order = $vars['order']; } if (!empty($vars['item'])) { if (is_object($vars['item'])) { $item = $vars['item']; } else { if (is_numeric($vars['item'])) { $item = new item(); $item->load($vars['item']); } } } else { if ($current['type'] == 'item') { // check publishing is enabled $enabled = nvweb_object_enabled($current['object']); if ($enabled || $_REQUEST['preview'] == 'true' && $current['navigate_session'] == 1) { $item = $current['object']; } } else { if ($current['type'] == 'structure') { $DB->query(' SELECT id, permission, date_published, date_unpublish FROM nv_items WHERE category = ' . protect($current['object']->id) . ' AND website = ' . $website->id . ' '); $rs = $DB->first(); $enabled = nvweb_object_enabled($rs); if ($enabled || $_REQUEST['preview'] == 'true' && $current['navigate_session'] == 1) { $item = new item(); $item->load($rs->id); } } } } if ($item == NULL) { return ''; } if (empty($vars['width']) && empty($vars['height'])) { $vars['width'] = 120; $vars['height'] = 90; } else { if (empty($vars['height'])) { $vars['height'] = ''; } else { if (empty($vars['width'])) { $vars['width'] = ''; } } } // which gallery model? $out = array(); switch (@$vars['mode']) { case 'image': if (is_array($item->galleries)) { $gallery = $item->galleries[0]; } if (is_string($item->galleries)) { $gallery = mb_unserialize($item->galleries); $gallery = $gallery[0]; } // no images in the gallery? if (!is_array($gallery)) { return ''; } $gallery = nvweb_gallery_reorder($gallery, $order); $image_ids = array_keys($gallery); $position = intval($vars['position']); $image_selected = $image_ids[$position]; // no image found at the requested position if (empty($image_selected)) { return ''; } list($image_title, $image_description) = nvweb_gallery_image_caption($image_selected, $gallery); if (!empty($vars['return']) && $vars['return'] == 'url') { $out[] = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image_selected . '&disposition=inline'; } else { if (!empty($vars['return']) && $vars['return'] == 'thumbnail') { $out[] = '<img src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image_selected . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" alt="' . $image_description . '" title="' . $image_title . '" />'; } else { if (!empty($vars['return']) && $vars['return'] == 'thumbnail_url') { $out[] = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image_selected . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border; } else { $out[] = '<div class="nv_gallery_item"> <a class="nv_gallery_a" href="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image_selected . '&disposition=inline" rel="gallery[item-' . $item->id . ']"> <img class="nv_gallery_image" src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image_selected . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" alt="' . $image_description . '" title="' . $image_title . '" /> </a> </div>'; } } } break; case 'greybox': /* var image_set = [{'caption': 'Flower', 'url': 'http://static.flickr.com/119/294309231_a3d2a339b9.jpg'}, {'caption': 'Nice waterfall', 'url': 'http://www.widerange.org/images/large/plitvicka.jpg'}]; */ $out[] = '<div class="nv_gallery">'; $gallery = mb_unserialize($item->galleries); $gallery = $gallery[0]; $gallery = nvweb_gallery_reorder($gallery, $order); $first = true; $jsout = "var image_set_" . $item->id . " = ["; $preload = array(); foreach ($gallery as $image => $dictionary) { list($image_title, $image_description) = nvweb_gallery_image_caption($image, $gallery); if ($first) { $out[] = '<a href="#" onclick="return GB_showImageSet(image_set_' . $item->id . ', 1);"> <img class="nv_gallery_image" src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" alt="' . $image_description . '" title="' . $image_title . '" /> </a>'; } if (!$first) { $jsout .= ',' . "\n"; } $jsout .= '{"caption": "' . $image_title . '", "url": "' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image . '&disposition=inline"}'; $preload[] = "'" . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image . '&disposition=inline'; $first = false; $items--; if ($items <= 0) { break; } } $jsout .= "];"; nvweb_after_body('js', $jsout); nvweb_after_body('js', 'AJS.preloadImages(' . implode(',', $preload) . ')'); $out[] = '<div style=" clear: both; "></div>'; $out[] = '</div>'; break; case 'piecemaker': $gallery = mb_unserialize($item->galleries); $gallery = nvweb_gallery_reorder($gallery[0], $order); foreach ($gallery as $image => $dictionary) { list($image_title, $image_description) = nvweb_gallery_image_caption($image, $gallery); $out[] = '<Image Source="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" Title="' . $image_title . '"></Image>'; $items--; if ($items <= 0) { break; } } break; case 'images': // plain IMG without links or divs // TO DO: add alt and title to the image if (is_array($item->galleries)) { $gallery = $item->galleries[0]; } if (is_string($item->galleries)) { $gallery = mb_unserialize($item->galleries); $gallery = $gallery[0]; } $gallery = nvweb_gallery_reorder($gallery, $order); $images = array_keys($gallery); if (empty($images)) { return ''; } foreach ($images as $img) { list($image_title, $image_description) = nvweb_gallery_image_caption($img, $gallery); $out[] = '<img class="nv_gallery_image" src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $img . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" alt="' . $image_description . '" title="' . $image_title . '" />'; $items--; if ($items <= 0) { break; } } break; case 'image_links': // IMG wrapped by a link // TO DO: add alt and title to the image if (is_array($item->galleries)) { $gallery = $item->galleries[0]; } if (is_string($item->galleries)) { $gallery = mb_unserialize($item->galleries); $gallery = $gallery[0]; } $gallery = nvweb_gallery_reorder($gallery, $order); $images = array_keys($gallery); if (empty($images)) { return ''; } foreach ($images as $img) { list($image_title, $image_description) = nvweb_gallery_image_caption($img, $gallery); $out[] = ' <a class="nv_gallery_a" href="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $img . '&disposition=inline"> <img class="nv_gallery_image" src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $img . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" alt="' . $image_description . '" title="' . $image_title . '" /> </a>'; $items--; if ($items <= 0) { break; } } break; case 'prettyphoto': case 'prettyPhoto': default: $out[] = '<div class="nv_gallery">'; if (is_array($item->galleries)) { $gallery = $item->galleries[0]; } if (is_string($item->galleries)) { $gallery = mb_unserialize($item->galleries); $gallery = $gallery[0]; } $gallery = nvweb_gallery_reorder($gallery, $order); $first = true; foreach ($gallery as $image => $dictionary) { if ($vars['only_first'] == 'true') { $style = ' style="display: none;" '; if ($first) { $style = ' style="display: block;" '; } $first = false; } list($image_title, $image_description) = nvweb_gallery_image_caption($img, $gallery); $out[] = '<div class="nv_gallery_item" ' . $style . '> <a class="nv_gallery_a" href="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image . '&disposition=inline" rel="gallery[item-' . $item->id . ']"> <img class="nv_gallery_image" src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $image . '&disposition=inline&width=' . $vars['width'] . '&height=' . $vars['height'] . $border . '" alt="' . $image_description . '" title="' . $image_title . '" /> </a> </div>'; $items--; if ($items <= 0) { break; } } $out[] = '<div style=" clear: both; "></div>'; $out[] = '</div>'; break; } $out = implode("\n", $out); return $out; }
public static function generate_feed($id = NULL) { global $current; global $website; global $DB; if (empty($id)) { $id = $current['id']; } $item = new feed(); $item->load($id); $permission = nvweb_object_enabled($item); if (!$permission) { return; } $feed = new UniversalFeedCreator(); $feed->encoding = 'UTF-8'; $feed->title = $item->dictionary[$current['lang']]['title']; $feed->description = $item->dictionary[$current['lang']]['description']; $feed->link = $website->absolute_path(); $feed->syndicationURL = $website->absolute_path() . $item->paths[$current['lang']]; if (!empty($item->image)) { $image = new FeedImage(); $image->url = $website->absolute_path() . '/object?type=image&id=' . $item->image; $image->link = $website->absolute_path(); //$image->description = $vars['dictionary_description']; $feed->image = $image; } if (!empty($item->categories[0])) { $limit = intval($item->entries); if ($limit <= 0) { $limit = 10; } $DB->query(' SELECT SQL_CALC_FOUND_ROWS i.id, i.permission, i.date_published, i.date_unpublish, i.date_to_display, COALESCE(NULLIF(i.date_to_display, 0), i.date_created) as pdate, d.text as title, i.position as position, i.galleries as galleries, i.template as template FROM nv_items i, nv_structure s, nv_webdictionary d WHERE i.category IN(' . implode(",", $item->categories) . ') AND i.website = ' . $website->id . ' AND i.permission = 0 AND (i.date_published = 0 OR i.date_published < ' . core_time() . ') AND (i.date_unpublish = 0 OR i.date_unpublish > ' . core_time() . ') AND s.id = i.category AND (s.date_published = 0 OR s.date_published < ' . core_time() . ') AND (s.date_unpublish = 0 OR s.date_unpublish > ' . core_time() . ') AND s.permission = 0 AND (s.access = 0) AND (i.access = 0) AND d.website = i.website AND d.node_type = "item" AND d.subtype = "title" AND d.node_id = i.id AND d.lang = ' . protect($current['lang']) . ' ORDER BY pdate DESC LIMIT ' . $limit . ' OFFSET 0'); $rs = $DB->result(); for ($x = 0; $x < count($rs); $x++) { if (nvweb_object_enabled($rs[$x])) { $texts = webdictionary::load_element_strings('item', $rs[$x]->id); $paths = path::loadElementPaths('item', $rs[$x]->id); $fitem = new FeedItem(); $fitem->title = $texts[$current['lang']]['title']; $fitem->link = $website->absolute_path() . $paths[$current['lang']]; switch ($item->content) { case 'title': // no description break; case 'content': $fitem->description = $texts[$current['lang']]['section-main']; break; case 'summary': default: $fitem->description = $texts[$current['lang']]['section-main']; $fitem->description = str_replace(array('</p>', '<br />', '<br/>', '<br>'), array('</p>' . "\n", '<br />' . "\n", '<br/>' . "\n", '<br>' . "\n"), $fitem->description); $fitem->description = core_string_cut($fitem->description, 500, '…'); break; } $fitem->date = $rs[$x]->date_to_display; // find an image to attach to the item // A) first enabled image in item gallery // B) first image on properties $image = ''; if (!empty($rs[$x]->galleries)) { $galleries = mb_unserialize($rs[$x]->galleries); $photo = @array_shift(array_keys($galleries[0])); if (!empty($photo)) { $image = $website->absolute_path(false) . '/object?type=image&id=' . $photo; } } if (empty($image)) { // no image found on galleries, look for image properties $properties = property::load_properties("item", $rs[$x]->template, "item", $rs[$x]->id); for ($p = 0; $p < count($properties); $p++) { if ($properties[$p]->type == 'image') { if (!empty($properties[$p]->value)) { $image = $properties[$p]->value; } else { if (!empty($properties[$p]->dvalue)) { $image = $properties[$p]->dvalue; } } if (is_array($image)) { $image = array_values($image); $image = $image[0]; } if (!empty($image)) { $image = $website->absolute_path(false) . '/object?type=image&id=' . $image; } } // we only need the first image if (!empty($image)) { break; } } } if (!empty($image)) { $fitem->image = $image; // feedly will only display images of >450px --> http://blog.feedly.com/2015/07/31/10-ways-to-optimize-your-feed-for-feedly/ if (strpos($item->format, 'RSS') !== false) { $fitem->description = '<img src="' . $image . '&width=640"><br />' . $fitem->description; } } //$item->author = $contents->rows[$x]->author_name; $feed->addItem($fitem); } } // valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1 (deprecated), // MBOX, OPML, ATOM, ATOM10, ATOM0.3, HTML, JS //echo $rss->saveFeed("RSS1.0", "news/feed.xml"); } $xml = $feed->createFeed($item->format); if ($item->format == "RSS2.0") { // add extra tweaks to improve the feed $xml = str_replace('<rss ', '<rss xmlns:webfeeds="http://webfeeds.org/rss/1.0" ', $xml); // also available: // <webfeeds:cover image="http://yoursite.com/a-large-cover-image.png" />\n // <webfeeds:accentColor>00FF00</webfeeds:accentColor> $xml = str_replace('<channel>', '<channel>' . "\n\t\t" . '<webfeeds:related layout="card" target="browser" />', $xml); $xml = str_replace('<channel>', '<channel>' . "\n\t\t" . '<webfeeds:logo>' . file::file_url($item->image) . '</webfeeds:logo>', $xml); $xml = str_replace('<channel>', '<channel>' . "\n\t\t" . '<webfeeds:icon>' . file::file_url($website->favicon) . '</webfeeds:icon>', $xml); } return $xml; }
function nvweb_list($vars = array()) { global $website; global $DB; global $current; global $cache; global $structure; global $webgets; global $theme; global $webuser; $out = array(); $webget = 'list'; $categories = array(); $exclude = ''; if ($current['type'] == 'item') { $categories = array($current['object']->category); } else { $categories = array($current['object']->id); } if (isset($vars['categories'])) { if ($vars['categories'] == 'all') { $categories = array(0); $vars['children'] = 'true'; } else { if ($vars['categories'] == 'parent') { $parent = $DB->query_single('parent', 'nv_structure', 'id = ' . intval($categories[0])); $categories = array($parent); } else { if ($vars['categories'] == 'nvlist_parent') { if ($vars['nvlist_parent_type'] === 'structure') { $categories = array($vars['nvlist_parent_item']->id); } } else { if (!is_numeric($vars['categories'])) { // if "categories" attribute has a comma, then we suppose it is a list of comma separated values // if not, then maybe we want to get the categories from a specific property of the current page if (strpos($vars['categories'], ',') === false) { $categories = nvweb_properties(array('property' => $vars['categories'])); } if (empty($categories) && @$vars['nvlist_parent_vars']['source'] == 'block_group') { $categories = nvweb_properties(array('mode' => 'block_group_block', 'property' => $vars['categories'], 'id' => $vars['nvlist_parent_item']->id, 'uid' => $vars['nvlist_parent_item']->uid)); } if (!is_array($categories)) { $categories = explode(',', $categories); $categories = array_filter($categories); // remove empty elements } } else { $categories = explode(',', $vars['categories']); $categories = array_filter($categories); // remove empty elements } } } } } if ($vars['children'] == 'true') { $categories = nvweb_menu_get_children($categories); } // if we have categories="x" children="true" [to get the children of a category, but not itself] if ($vars['children'] == 'only') { $children = nvweb_menu_get_children($categories); for ($c = 0; $c < count($categories); $c++) { array_shift($children); } $categories = $children; } if (!empty($vars['children']) && intval($vars['children']) > 0) { $children = nvweb_menu_get_children($categories, intval($vars['children'])); for ($c = 0; $c < count($categories); $c++) { array_shift($children); } $categories = $children; } if (empty($vars['items']) || $vars['items'] == '0') { $vars['items'] = 5000; //2147483647; // maximum integer // NOTE: having >5000 items on a page without a paginator is probably a bad idea... disagree? Contact Navigate CMS team! } else { if (!is_numeric($vars['items'])) { $max_items = ""; // the number of items is defined by a property $max_items = nvweb_properties(array('property' => $vars['items'])); if (empty($max_items) && @$vars['nvlist_parent_vars']['source'] == 'block_group') { $max_items = nvweb_properties(array('mode' => 'block_group_block', 'property' => $vars['items'], 'id' => $vars['nvlist_parent_item']->id, 'uid' => $vars['nvlist_parent_item']->uid)); } if (!empty($max_items)) { $vars['items'] = $max_items; } else { $vars['items'] = 500; } // default maximum } } if (!empty($vars['exclude'])) { $exclude = str_replace('current', $current['object']->id, $vars['exclude']); $exclude = explode(',', $exclude); $exclude = array_filter($exclude); if (!empty($exclude)) { if ($vars['source'] == 'structure' || $vars['source'] == 'category') { $exclude = 'AND s.id NOT IN(' . implode(',', $exclude) . ')'; } else { // item $exclude = 'AND i.id NOT IN(' . implode(',', $exclude) . ')'; } } else { $exclude = ''; } } // retrieve entries // calculate the offset of the first element to retrieve // Warning: the paginator applies on all paginated lists on a page (so right now there can only be one in a page) if (empty($_GET['page'])) { $_GET['page'] = 1; } $offset = intval($_GET['page'] - 1) * $vars['items']; // this list does not use paginator, so offset must be always zero if (!isset($vars['paginator']) || $vars['paginator'] == 'false') { $offset = 0; } $permission = !empty($_SESSION['APP_USER#' . APP_UNIQUE]) ? 1 : 0; // public access / webuser based / webuser groups based $access = 2; $access_extra = ''; if (!empty($current['webuser'])) { $access = 1; if (!empty($webuser->groups)) { $access_groups = array(); foreach ($webuser->groups as $wg) { if (empty($wg)) { continue; } $access_groups[] = 's.groups LIKE "%g' . $wg . '%"'; } if (!empty($access_groups)) { $access_extra = ' OR (s.access = 3 AND (' . implode(' OR ', $access_groups) . '))'; } } } // get order type: PARAMETER > NV TAG PROPERTY > DEFAULT (priority given in CMS) $order = @$_REQUEST['order']; if (empty($order)) { $order = @$vars['order']; } if (empty($order)) { // default order: latest $order = 'latest'; } $orderby = nvweb_list_get_orderby($order); $rs = NULL; // TODO: try to optimize nvlist generation to use less memory and increase the maximum number of items if (($vars['source'] == 'structure' || $vars['source'] == 'category') && !empty($categories)) { $orderby = str_replace('i.', 's.', $orderby); $visible = ''; if ($vars['filter'] == 'menu') { $visible = ' AND s.visible = 1 '; } $templates = ""; if (!empty($vars['templates'])) { $templates = explode(",", $vars['templates']); $templates = array_filter($templates); $templates = ' AND s.template IN ("' . implode('","', $templates) . '")'; } $DB->query(' SELECT SQL_CALC_FOUND_ROWS s.id, s.permission, s.date_published, s.date_unpublish, s.date_published as pdate, d.text as title, s.position as position FROM nv_structure s, nv_webdictionary d WHERE s.id IN(' . implode(",", $categories) . ') AND s.website = ' . $website->id . ' AND s.permission <= ' . $permission . ' AND (s.date_published = 0 OR s.date_published < ' . core_time() . ') AND (s.date_unpublish = 0 OR s.date_unpublish > ' . core_time() . ') AND (s.access = 0 OR s.access = ' . $access . $access_extra . ') AND d.website = s.website AND d.node_type = "structure" AND d.subtype = "title" AND d.node_id = s.id AND d.lang = ' . protect($current['lang']) . ' ' . $templates . ' ' . $visible . ' ' . $exclude . ' ' . $orderby . ' LIMIT ' . $vars['items'] . ' OFFSET ' . $offset); $rs = $DB->result(); $total = $DB->foundRows(); } else { if ($vars['source'] == 'block') { list($rs, $total) = nvweb_blocks(array('type' => $vars['type'], 'number' => $vars['items'], 'mode' => $order == 'random' ? 'random' : 'ordered', 'zone' => 'object')); } else { if ($vars['source'] == 'block_link') { // only useful if this nvlist is inside another nv list of source="block" $block_links = $vars['nvlist_parent_item']->trigger['trigger-links'][$current['lang']]; $rs = array(); if (!is_array($block_links)) { $block_links = array(); } foreach ($block_links as $b_key => $b_data) { if (!is_array($b_data)) { $b_data = array(); } $b_i = 0; foreach ($b_data as $b_ref => $b_value) { if (!isset($rs[$b_i])) { $rs[$b_i] = new stdClass(); } if (!isset($rs[$b_i]->id)) { $rs[$b_i]->id = $b_ref; } $rs[$b_i]->{$b_key} = $b_value; $b_i++; } } $total = count($rs); } else { if ($vars['source'] == 'block_group') { $bg = new block_group(); if (!empty($vars['type'])) { $bg->load_by_code($vars['type']); } if (!empty($bg) && !empty($bg->blocks)) { $rs = array(); foreach ($bg->blocks as $bgb) { unset($bgbo); switch ($bgb['type']) { case 'block': $bgbo = new block(); $bgbo->load($bgb['id']); if (empty($bgbo) || empty($bgbo->type)) { continue; } // check if we can display this block if (nvweb_object_enabled($bgbo)) { // check categories / exclusions if (!empty($bgbo->categories)) { $bgbo_cat_found = false; foreach ($categories as $list_cat) { if (in_array($list_cat, $bgbo->categories)) { $bgbo_cat_found = true; } } if (!$bgbo_cat_found) { // block categories don't match the current list categories, skip this block continue; } } if (!empty($bgbo->exclusions)) { foreach ($categories as $list_cat) { if (in_array($list_cat, $bgbo->exclusions)) { continue; } // skip this block } } $rs[] = $bgbo; } break; case 'block_group_block': $bgba = $theme->block_group_blocks($vars['type']); if (!empty($bgba[$bgb['id']])) { $bgbo = $bgba[$bgb['id']]; $bgbo->uid = $bgb['uid']; $rs[] = clone $bgbo; } break; case 'block_type': // a collection of blocks of the same type list($bgbos, $foo) = nvweb_blocks(array('type' => $bgb['id'], 'mode' => $order == 'random' ? 'random' : 'ordered', 'zone' => 'object')); // add the block type definition, with its title if (count($bgbos) > 0 && isset($bgb['title']) && !empty($bgb['title'])) { $bgb['_object_type'] = 'block_group_block_type'; $rs[] = (object) $bgb; } for ($i = 0; $i < count($bgbos); $i++) { $rs[] = $bgbos[$i]; } break; case 'extension': $rs[] = (object) $bgb; break; } } $total = count($rs); } } else { if ($vars['source'] == 'gallery') { if (!isset($vars['nvlist_parent_type'])) { // get gallery of the current item if ($current['type'] == 'item') { $galleries = $current['object']->galleries; if (!is_array($galleries)) { $galleries = mb_unserialize($galleries); } $rs = $galleries[0]; $total = count($rs); } else { if ($current['type'] == 'structure') { // we need the first item assigned to the structure $access_extra_items = str_replace('s.', 'i.', $access_extra); $templates = ""; if (!empty($vars['templates'])) { $templates = explode(",", $vars['templates']); $templates = array_filter($templates); $templates = ' AND i.template IN ("' . implode('","', $templates) . '")'; } // default source for retrieving items (embedded or not) $DB->query(' SELECT SQL_CALC_FOUND_ROWS i.id FROM nv_items i, nv_structure s, nv_webdictionary d WHERE i.category IN(' . implode(",", $categories) . ') AND i.website = ' . $website->id . ' AND i.permission <= ' . $permission . ' AND (i.date_published = 0 OR i.date_published < ' . core_time() . ') AND (i.date_unpublish = 0 OR i.date_unpublish > ' . core_time() . ') AND s.id = i.category AND (s.date_published = 0 OR s.date_published < ' . core_time() . ') AND (s.date_unpublish = 0 OR s.date_unpublish > ' . core_time() . ') AND s.permission <= ' . $permission . ' AND (s.access = 0 OR s.access = ' . $access . $access_extra . ') AND (i.access = 0 OR i.access = ' . $access . $access_extra_items . ') AND d.website = i.website AND d.node_type = "item" AND d.subtype = "title" AND d.node_id = i.id AND d.lang = ' . protect($current['lang']) . ' ' . $templates . ' ' . $exclude . ' ORDER BY i.position ASC LIMIT 1 '); $rs = $DB->result(); $tmp = new item(); $tmp->load($rs[0]->id); $rs = $tmp->galleries[0]; $total = count($rs); } } } else { if ($vars['nvlist_parent_type'] == 'item') { $pitem = $vars['nvlist_parent_item']; $rs = $pitem->galleries[0]; $total = count($rs); } } if ($total > 0) { $order = 'priority'; // display images using the assigned priority if (!empty($vars['order'])) { $order = $vars['order']; } $rs = nvweb_gallery_reorder($rs, $order); // prepare format to be parsed by nv list iterator $rs = array_map(function ($k, $v) { $v['file'] = $k; return $v; }, array_keys($rs), array_values($rs)); } } else { if ($vars['source'] == 'rss') { // url may be a property $rss_url = $vars['url']; if (strpos($vars['url'], "http") !== 0) { $rss_url = nvweb_properties(array('property' => $vars['url'])); } list($rs, $total) = nvweb_list_get_from_rss($rss_url, @$vars['cache'], $offset, $vars['items'], $permission, $order); } else { if ($vars['source'] == 'twitter') { list($rs, $total) = nvweb_list_get_from_twitter($vars['username'], @$vars['cache'], $offset, $vars['items'], $permission, $order); } else { if (!empty($vars['source'])) { // CUSTOM data source if ($vars['source'] == 'comment') { $vars['source'] = 'comments'; } $fname = 'nvweb_' . $vars['source'] . '_list'; if ($vars['source'] == 'website_comments') { $vars['source'] = 'comments'; } nvweb_webget_load($vars['source']); if (function_exists($fname)) { list($rs, $total) = $fname($offset, $vars['items'], $permission, $order, $vars); } } } } } } } } } $categories = array_filter($categories); // DATA SOURCE not given or ERROR ===> items if ((empty($vars['source']) || !is_numeric($total)) && !empty($categories)) { /* * TO DO: design decision ... lists should show items from published categories which has unpublished parent? * * Navigate CMS 1.6.7: NO * // we have to check all website UNPUBLISHED categories to keep the list query efficient // there are some cases: // a) Permission is beyond user's level [0=>public, 1=>private, 2=>hidden] // b) Date published is set and the value is before the current time (not yet published) // c) Date unpublish is set and the value is before the current time (no more published) // d) User account level not allowed [0=>everyone, 1=>signed in users, 2=>users NOT signed in] $DB->query(' SELECT id FROM nv_structure WHERE website = '.protect($website->id).' AND ( permission > '.$permission.' OR (date_published > 0 AND '.$website->current_time().' > date_published) OR (date_unpublish > 0 AND '.$website->current_time().' > date_unpublish) OR (access <> 0 AND access <> '.$access.') ) '); $hidden_categories = $DB->result('id'); // now we would have to mark the children categories also as unpublished */ $filters = ''; if (!empty($vars['filter'])) { $filters = nvweb_list_parse_filters($vars['filter'], 'items'); } // reuse structure.access permission $access_extra_items = str_replace('s.', 'i.', $access_extra); $embedded = $vars['embedded'] == 'true' ? '1' : '0'; $templates = ""; if (!empty($vars['templates'])) { $templates = explode(",", $vars['templates']); $templates = array_filter($templates); if ($embedded == '1') { $templates = ' AND s.template IN ("' . implode('","', $templates) . '")'; } else { $templates = ' AND i.template IN ("' . implode('","', $templates) . '")'; } } $columns_extra = ''; if ($vars['order'] == 'comments') { // we need to retrieve the number of comments to apply the order by clause $columns_extra = ', (SELECT COUNT(c.id) FROM nv_comments c WHERE i.id = c.item AND c.website = i.website AND c.status = 0) AS comments_published'; } // default source for retrieving items $query = ' SELECT SQL_CALC_FOUND_ROWS i.id, i.permission, i.date_published, i.date_unpublish, i.date_to_display, COALESCE(NULLIF(i.date_to_display, 0), i.date_created) as pdate, d.text as title, i.position as position, s.position ' . $columns_extra . ' FROM nv_items i, nv_structure s, nv_webdictionary d WHERE i.category IN(' . implode(",", $categories) . ') AND i.website = ' . $website->id . ' AND i.permission <= ' . $permission . ' AND i.embedding = ' . $embedded . ' AND (i.date_published = 0 OR i.date_published < ' . core_time() . ') AND (i.date_unpublish = 0 OR i.date_unpublish > ' . core_time() . ') AND s.id = i.category AND (s.date_published = 0 OR s.date_published < ' . core_time() . ') AND (s.date_unpublish = 0 OR s.date_unpublish > ' . core_time() . ') AND s.permission <= ' . $permission . ' AND (s.access = 0 OR s.access = ' . $access . $access_extra . ') AND (i.access = 0 OR i.access = ' . $access . $access_extra_items . ') AND d.website = i.website AND d.node_type = "item" AND d.subtype = "title" AND d.node_id = i.id AND d.lang = ' . protect($current['lang']) . ' ' . $filters . ' ' . $templates . ' ' . $exclude . ' ' . $orderby . ' LIMIT ' . $vars['items'] . ' OFFSET ' . $offset; $DB->query($query); $rs = $DB->result(); $total = $DB->foundRows(); } // now we have all elements that will be shown in the list // let's apply the nvlist template to each one for ($i = 0; $i < count($rs); $i++) { // ignore empty objects if ($vars['source'] != 'gallery' && empty($rs[$i]->id) || $vars['source'] == 'gallery' && empty($rs[$i]['file'])) { continue; } // prepare a standard $item with the current element if ($vars['source'] == 'comments' || $vars['source'] == 'comment') { $item = $rs[$i]; } else { if ($vars['source'] == 'structure' || $vars['source'] == 'category') { $item = new structure(); $item->load($rs[$i]->id); $item->date_to_display = $rs[$i]->pdate; } else { if ($vars['source'] == 'rss' || $vars['source'] == 'twitter' || $vars['source'] == 'block_link') { // item is virtually created $item = $rs[$i]; } else { if ($vars['source'] == 'block' || $vars['source'] == 'block_group') { if (get_class($rs[$i]) == 'block') { // standard block $item = $rs[$i]; } else { if (isset($rs[$i]->_object_type) && $rs[$i]->_object_type == "block_group_block_type") { // block type definition (mainly used to add a title before a list of blocks of the same type) $item = $rs[$i]; } else { if (isset($rs[$i]->extension)) { // extension block $item = block::extension_block($rs[$i]->extension, $rs[$i]->id); $item->type = "extension"; $item->extension = $rs[$i]->extension; $item->uid = $rs[$i]->uid; } else { // block from block group $item = new block(); $item->load_from_block_group($vars['type'], $rs[$i]->id, $rs[$i]->uid); } } } } else { if ($vars['source'] == 'gallery') { $item = $rs[$i]; } else { $item = new item(); $item->load($rs[$i]->id); // if the item comes from a custom source, save the original query result // this allows getting a special field without extra work ;) $item->_query = $rs[$i]; } } } } } // get the nv list template $item_html = $vars['template']; // first we need to isolate the nested nv lists/searches unset($nested_lists_fragments); list($item_html, $nested_lists_fragments) = nvweb_list_isolate_lists($item_html); // now, parse the nvlist_conditional tags (with html source code inside (and other nvlist tags)) unset($nested_condition_fragments); list($item_html, $nested_conditional_fragments) = nvweb_list_isolate_conditionals($item_html); $conditional_placeholder_tags = nvweb_tags_extract($item_html, 'nvlist_conditional_placeholder', true, true, 'UTF-8'); // selfclosing = true while (!empty($conditional_placeholder_tags)) { $tag = $conditional_placeholder_tags[0]; $conditional = $nested_conditional_fragments[$tag["attributes"]["id"]]; $conditional_html_output = nvweb_list_parse_conditional($conditional, $item, $conditional['nvlist_conditional_template'], $i, count($rs)); $item_html = str_replace($tag["full_tag"], $conditional_html_output, $item_html); $conditional_placeholder_tags = nvweb_tags_extract($item_html, 'nvlist_conditional_placeholder', true, true, 'UTF-8'); // selfclosing = true } // now, parse the (remaining) common nvlist tags (selfclosing tags) $template_tags_processed = 0; $template_tags = nvweb_tags_extract($item_html, 'nvlist', true, true, 'UTF-8'); // selfclosing = true while (!empty($template_tags)) { $tag = $template_tags[0]; // protect the "while" loop, maximum 500 nvlist tags parsed! $template_tags_processed++; if ($template_tags_processed > 500) { break; } $content = nvweb_list_parse_tag($tag, $item, $vars['source'], $i, $i + $offset, $total); $item_html = str_replace($tag['full_tag'], $content, $item_html); // html template has changed, the nvlist tags may have changed its positions $template_tags = nvweb_tags_extract($item_html, 'nvlist', true, true, 'UTF-8'); } // restore & process nested lists (if any) foreach ($nested_lists_fragments as $nested_list_uid => $nested_list_vars) { $nested_list_vars['nvlist_parent_vars'] = $vars; $nested_list_vars['nvlist_parent_type'] = $vars['source']; $nested_list_vars['nvlist_parent_item'] = $item; $content = nvweb_list($nested_list_vars); $item_html = str_replace('<!--#' . $nested_list_uid . '#-->', $content, $item_html); } $out[] = $item_html; } if (count($rs) == 0) { // special case, no results found // get the nv list template and parse only the conditional: <nvlist_conditional by="count" value="empty"> (or value=0) $item_html = $vars['template']; // now, parse the nvlist_conditional tags (with html source code inside (and other nvlist tags)) unset($nested_condition_fragments); list($item_html, $nested_conditional_fragments) = nvweb_list_isolate_conditionals($item_html); // remove all tags except (selfclosing) nvlist_conditional_placeholder $item_html = strip_tags($item_html, '<nvlist_conditional_placeholder>'); $conditional_placeholder_tags = nvweb_tags_extract($item_html, 'nvlist_conditional_placeholder', true, true, 'UTF-8'); // selfclosing=true while (!empty($conditional_placeholder_tags)) { $tag = $conditional_placeholder_tags[0]; $conditional = $nested_conditional_fragments[$tag["attributes"]["id"]]; $conditional_html_output = nvweb_list_parse_conditional($conditional, NULL, $conditional['nvlist_conditional_template'], $i, count($rs)); $item_html = str_replace($tag["full_tag"], $conditional_html_output, $item_html); $conditional_placeholder_tags = nvweb_tags_extract($item_html, 'nvlist_conditional_placeholder', true, true, 'UTF-8'); // selfclosing = true } $out[] = $item_html; } if (isset($vars['paginator']) && $vars['paginator'] != 'false') { $out[] = nvweb_list_paginator($vars['paginator'], $_GET['page'], $total, $vars['items'], $vars); } return implode("\n", $out); }
function nvweb_object($ignoreEnabled = false, $ignorePermissions = false) { global $website; global $DB; session_write_close(); ob_end_clean(); $item = new file(); header('Cache-Control: private'); header('Pragma: private'); $type = @$_REQUEST['type']; $id = @$_REQUEST['id']; if (!empty($id)) { if (is_numeric($id)) { $item->load($id); } else { $item->load($_REQUEST['id']); } } if (empty($type) && !empty($item->type)) { $type = $item->type; } // if the type requested is not a special type, check its access permissions if (!in_array($type, array("blank", "transparent", "flag"))) { $enabled = nvweb_object_enabled($item); if (!$enabled && !$ignorePermissions) { $type = 'not_allowed'; } } switch ($type) { case 'not_allowed': header("HTTP/1.0 405 Method Not Allowed"); break; case 'blank': case 'transparent': $path = NAVIGATE_PATH . '/img/transparent.gif'; header('Content-Disposition: attachment; filename="transparent.gif"'); header('Content-Type: image/gif'); header('Content-Disposition: inline; filename="transparent.gif"'); header("Content-Transfer-Encoding: binary\n"); $etag = base64_encode($path . filemtime($path)); header('ETag: "' . $etag . '"'); // check the browser cache and stop downloading again the file $cached = file::cacheHeaders(filemtime($path), $etag); if (!$cached) { readfile($path); } break; case 'flag': if ($_REQUEST['code'] == 'ca') { $_REQUEST['code'] = 'catalonia'; } header('Content-Disposition: attachment; filename="' . $_REQUEST['code'] . '.png"'); header('Content-Type: image/png'); header('Content-Disposition: inline; filename="' . $_REQUEST['code'] . '.png"'); header("Content-Transfer-Encoding: binary\n"); $path = NAVIGATE_PATH . '/img/icons/flags/' . $_REQUEST['code'] . '.png'; if (!file_exists($path)) { $path = NAVIGATE_PATH . '/img/transparent.gif'; } $etag = base64_encode($path . filemtime($path)); header('ETag: "' . $etag . '"'); // check the browser cache and stop downloading again the file $cached = file::cacheHeaders(filemtime($path), $etag); if (!$cached) { readfile($path); } break; case 'image': case 'img': if (!$item->enabled && !$ignoreEnabled) { nvweb_clean_exit(); } $path = $item->absolute_path(); $etag_add = ''; // calculate aspect ratio if width or height are given... $width = intval(@$_REQUEST['width']) + 0; $height = intval(@$_REQUEST['height']) + 0; // check size requested and ignore the empty values (or equal to zero) if (empty($width)) { $width = ""; } if (empty($height)) { $height = ""; } // get target quality (only for jpeg thumbnails!) $quality = $_REQUEST['quality']; if (empty($quality)) { $quality = 95; } $resizable = true; if ($item->mime == 'image/gif') { $resizable = !file::is_animated_gif($path); } if ((!empty($width) || !empty($height)) && ($resizable || @$_REQUEST['force_resize'] == 'true')) { $border = $_REQUEST['border'] == 'false' ? false : true; $path = file::thumbnail($item, $width, $height, $border, NULL, $quality); if (empty($path)) { die; } $etag_add = '-' . $width . '-' . $height . '-' . $border . '-' . $quality; $item->name = $width . 'x' . $height . '-' . $item->name; $item->size = filesize($path); $item->mime = 'image/png'; if (strpos(basename($path), '.jpg') !== false) { $item->mime = 'image/jpeg'; } } $etag = base64_encode($item->id . '-' . $item->name . '-' . $item->date_added . '-' . filesize($path) . '-' . filemtime($path) . '-' . $item->permission . $etag_add); header('ETag: "' . $etag . '"'); header('Content-type: ' . $item->mime); header("Content-Length: " . $item->size); if (empty($_REQUEST['disposition'])) { $_REQUEST['disposition'] = 'inline'; } header('Content-Disposition: ' . $_REQUEST['disposition'] . '; filename="' . $item->name . '"'); // check the browser cache and stop downloading again the file $cached = file::cacheHeaders(filemtime($path), $etag); if (!$cached) { readfile($path); } break; case 'archive': case 'video': case 'file': default: if (!$item->enabled && !$ignoreEnabled) { nvweb_clean_exit(); } $path = NAVIGATE_PRIVATE . '/' . $website->id . '/files/' . $item->id; $etag_add = ''; clearstatcache(); $etag = base64_encode($item->id . '-' . $item->name . '-' . $item->date_added . '-' . filemtime($path) . '-' . $item->permission . $etag_add); header('ETag: "' . $etag . '"'); header('Content-type: ' . $item->mime); header("Accept-Ranges: bytes"); if (empty($_REQUEST['disposition'])) { $_REQUEST['disposition'] = 'attachment'; } header('Content-Disposition: ' . $_REQUEST['disposition'] . '; filename="' . $item->name . '"'); // check the browser cache and stop downloading again the file $cached = file::cacheHeaders(filemtime($path), $etag); if (!$cached) { $range = 0; $size = filesize($path); if (isset($_SERVER['HTTP_RANGE'])) { list($a, $range) = explode("=", $_SERVER['HTTP_RANGE']); str_replace($range, "-", $range); $size2 = $size - 1; $new_length = $size - $range; header("HTTP/1.1 206 Partial Content"); header("Content-Length: {$new_length}"); header("Content-Range: bytes {$range}{$size2}/{$size}"); } else { $size2 = $size - 1; header("Content-Range: bytes 0-{$size2}/{$size}"); header("Content-Length: " . $size); } $fp = fopen($path, "rb"); if (is_resource($fp)) { @fseek($fp, $range); while (!@feof($fp) && connection_status() == 0) { set_time_limit(0); print @fread($fp, 1024 * 1024); // 1 MB per second flush(); ob_flush(); sleep(1); } fclose($fp); } } break; } session_write_close(); if ($DB) { $DB->disconnect(); } exit; }