public function load_from_resultset($rs) { $main = $rs[0]; $this->id = $main->id; $this->website = $main->website; $this->type = $main->type; $this->date_published = empty($main->date_published) ? '' : $main->date_published; $this->date_unpublish = empty($main->date_unpublish) ? '' : $main->date_unpublish; $this->date_modified = empty($main->date_modified) ? '' : $main->date_modified; $this->access = $main->access; $this->enabled = $main->enabled; $this->trigger = mb_unserialize($main->trigger); if (is_array($this->trigger['trigger-html'])) { foreach ($this->trigger['trigger-html'] as $language => $code) { $this->trigger['trigger-html'][$language] = htmlspecialchars_decode($code); } } if (is_array($this->trigger['trigger-content'])) { foreach ($this->trigger['trigger-content'] as $language => $code) { $this->trigger['trigger-content'][$language] = stripslashes($code); } } $this->action = mb_unserialize($main->action); $this->notes = $main->notes; $this->dictionary = webdictionary::load_element_strings('block', $this->id); // title $this->position = $main->position; $this->fixed = $main->fixed; $this->categories = array_filter(explode(',', $main->categories)); $this->exclusions = array_filter(explode(',', $main->exclusions)); $this->elements = json_decode($main->elements, true); // to get the array of groups first we remove the "g" character $groups = str_replace('g', '', $main->groups); $this->groups = explode(',', $groups); if (!is_array($this->groups)) { $this->groups = array($groups); } $block_classes = block::types(); foreach ($block_classes as $bc) { if ($bc['code'] == $this->type) { $this->class = $bc['type']; } } }
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; }
public function load_from_resultset($rs) { $main = $rs[0]; $this->id = $main->id; $this->website = $main->website; $this->association = $main->association; $this->category = $main->category; $this->embedding = $main->embedding; $this->template = $main->template; $this->date_to_display = empty($main->date_to_display) ? '' : $main->date_to_display; $this->date_published = empty($main->date_published) ? '' : $main->date_published; $this->date_unpublish = empty($main->date_unpublish) ? '' : $main->date_unpublish; $this->date_created = $main->date_created; $this->date_modified = $main->date_modified; $this->galleries = mb_unserialize($main->galleries); $this->comments_enabled_to = $main->comments_enabled_to; $this->comments_moderator = $main->comments_moderator; $this->access = $main->access; $this->permission = $main->permission; $this->author = $main->author; $this->views = $main->views; $this->votes = $main->votes; $this->score = $main->score; $this->position = $main->position; $this->dictionary = webdictionary::load_element_strings('item', $this->id); $this->paths = path::loadElementPaths('item', $this->id); // to get the array of groups first we remove the "g" character $groups = str_replace('g', '', $main->groups); $this->groups = explode(',', $groups); if (!is_array($this->groups)) { $this->groups = array($groups); } if ($this->association == 'free') { $this->category = ''; } }
public static function load_properties($element, $template, $object_type, $object_id, $item_uid = null) { global $DB; global $website; global $theme; if ($object_type == 'block_group_block') { $block = block::block_group_block($template, $object_id); $e_properties = $block->properties; // we must find the block group ID to search the assigned property values // $object_id MUST BE the numeric ID of the block group if (!empty($template)) { $block_group_id = $DB->query_single('MAX(id)', 'nv_block_groups', ' code = ' . protect($template) . ' AND website = ' . $website->id); $object_id = $block_group_id; if (empty($block_group_id)) { $object_id = 0; } } } else { if ($object_type == 'extension_block') { // in this case, the parameters must match the following: // $element => (not used) // $template => type of the block in the extension definition // $object_type => "extension_block" // $object_id => type of the block_group (f.e. "sidebar" or the one defined in the theme definition); if null, we have to find the right value // $item_uid => the unique id assigned to the block in the block_group // find the extension block definition, to get the list of properties $extensions_blocks = extension::blocks(); for ($eb = 0; $eb < count($extensions_blocks); $eb++) { if ($extensions_blocks[$eb]->id == $template) { $e_properties = $extensions_blocks[$eb]->properties; break; } } if (empty($object_id)) { // we need to find the block_group ID by checking the block uid $block_group_id = $DB->query_single('id', 'nv_block_groups', ' blocks LIKE ' . protect('%' . $item_uid . '%') . ' AND website = ' . $website->id); $object_id = $block_group_id; if (empty($block_group_id)) { $object_id = 0; } } else { if (!empty($template)) { $block_group_id = $DB->query_single('MAX(id)', 'nv_block_groups', ' code = ' . protect($object_id) . ' AND website = ' . $website->id); $object_id = $block_group_id; if (empty($block_group_id)) { $object_id = 0; } } } $object_type = "block_group-extension-block"; } else { if ($object_type == 'webuser') { // the properties are set in the theme definition $e_properties = $theme->webusers['properties']; } else { // load properties associated with the element type $e_properties = property::elements($template, $object_type); } } } // load the values for multilanguage strings $dictionary = webdictionary::load_element_strings('property-' . $object_type, $object_id, $item_uid); // load the assigned (simple) properties values // check node_uid empty or NULL to mantain compatibility with Navigate CMS < 2.2 $DB->query(' SELECT * FROM nv_properties_items WHERE element = ' . protect($object_type) . ' AND node_id = ' . protect($object_id) . (empty($item_uid) ? '' : ' AND ( node_uid = ' . protect($item_uid) . ' OR node_uid = "" OR node_uid IS NULL )') . ' AND website = ' . $website->id, 'array'); $values = $DB->result(); if (!is_array($values)) { $values = array(); } $o_properties = array(); if (!is_array($e_properties)) { $e_properties = array(); } $p = 0; foreach ($e_properties as $e_property) { if (is_object($e_property)) { $o_properties[$p] = clone $e_property; } else { $o_properties[$p] = $e_property; } if (isset($o_properties[$p]->dvalue)) { $o_properties[$p]->value = $o_properties[$p]->dvalue; } foreach ($values as $value) { if ($value['property_id'] == $o_properties[$p]->id) { $o_properties[$p]->value = $value['value']; if ($value['value'] == '[dictionary]') { $o_properties[$p]->value = array(); foreach ($website->languages_list as $lang) { $o_properties[$p]->value[$lang] = $dictionary[$lang]['property-' . $o_properties[$p]->id . '-' . $lang]; } } } } if (substr($o_properties[$p]->name, 0, 1) == '@') { // get translation from theme dictionary $o_properties[$p]->name = $theme->t(substr($o_properties[$p]->name, 1)); } if (is_object($o_properties[$p]->value)) { $o_properties[$p]->value = (array) $o_properties[$p]->value; } $p++; } return $o_properties; }
/** * Parses a template looking for nv tags and replacing them with the generated HTML code * * @param $template string HTML code to parse * @return string HTML page generated */ function nvweb_template_parse($template) { global $dictionary; global $DB; global $current; global $website; global $structure; global $theme; global $idn; global $session; $html = $template; // now parse autoclosing tags $tags = nvweb_tags_extract($html, 'nv', true, true, 'UTF-8'); foreach ($tags as $tag) { $content = ''; switch ($tag['attributes']['object']) { // MAIN OBJECT TYPES case 'nvweb': case 'widget': case 'webget': case '': // webgets on lib/webgets have priority over private/webgets nvweb_webget_load($tag['attributes']['name']); $fname = 'nvweb_' . $tag['attributes']['name']; $tag['attributes']['nvweb_html'] = $html; // always pass the current buffered output to the webget if (function_exists($fname)) { $content = $fname($tag['attributes']); } break; case 'root': $content = NVWEB_ABSOLUTE; break; case 'nvajax': $content = NVWEB_AJAX; break; case 'url': $content = ''; if (!empty($tag['attributes']['lang'])) { $lang = $tag['attributes']['lang']; } else { $lang = $current['lang']; } if (!empty($tag['attributes']['type']) && !empty($tag['attributes']['id'])) { $url = nvweb_source_url($tag['attributes']['type'], $tag['attributes']['id'], $lang); if (!empty($url)) { $content .= $url; } } else { if (!empty($tag['attributes']['type']) && !empty($tag['attributes']['property'])) { $tag['attributes']['id'] = nvweb_properties(array('property' => $tag['attributes']['property'])); $url = nvweb_source_url($tag['attributes']['type'], $tag['attributes']['id'], $lang); if (!empty($url)) { $content .= $url; } } else { if (!empty($tag['attributes']['type']) && empty($tag['attributes']['id'])) { // get structure parent for this element and return its path if ($current['type'] == 'structure') { $category = $current['object']->parent; if (empty($category)) { $category = $current['object']->id; } } else { $category = $current['object']->category; } $url = nvweb_source_url($tag['attributes']['type'], $category, $lang); if (!empty($url)) { $content .= $url; } } else { $content .= '/' . $current['route']; } } } $content = nvweb_prepare_link($content); break; case 'd': case 'dict': case 'dictionary': if (!empty($tag['attributes']['type'])) { if ($tag['attributes']['type'] == 'structure' || $tag['attributes']['type'] == 'category') { // force loading dictionary for all elements in structure (for the current language) nvweb_menu_load_dictionary(); if (!is_numeric($tag['attributes']['id'])) { // maybe it's a property name instead of a category id $tag['attributes']['id'] = nvweb_properties(array('property' => $tag['attributes']['property'])); } $content = $structure['dictionary'][$tag['attributes']['id']]; } else { if ($tag['attributes']['type'] == 'item') { $tmp = webdictionary::load_element_strings('item', $tag['attributes']['id']); $content = $tmp[$current['lang']]['title']; } } } else { $content = $dictionary[$tag['attributes']['id']]; } if (empty($content)) { $content = $tag['attributes']['label']; } if (empty($content)) { $content = $tag['attributes']['default']; } break; case 'request': if (!empty($tag['attributes']['name'])) { $content = $_REQUEST[$tag['attributes']['name']]; } else { // deprecated: use "request" as attribute [will be removed on navigate cms 2.0] $content = $_REQUEST[$tag['attributes']['request']]; } if (is_array($content)) { $content = implode(',', $content); } break; case 'constant': case 'variable': switch ($tag['attributes']['name']) { case "structure": case "category": // retrieve the category ID from current session $tmp = NULL; if ($current['type'] == 'structure') { $tmp = $current['id']; } else { if (!empty($current['category'])) { $tmp = $current['category']; } else { if (!empty($current['object']->category)) { $tmp = $current['object']->category; } } } if (empty($tmp)) { $content = ''; } else { $content = $DB->query_single('text', 'nv_webdictionary', ' node_type = "structure" AND subtype = "title" AND node_id = ' . $tmp . ' AND lang = ' . protect($current['lang']) . ' AND website = ' . $website->id); } break; case "year": $content = date('Y'); break; case "website_name": $content = $website->name; break; case "website_description": $content = $website->metatag_description[$current['lang']]; break; case "lang_code": $content = $current['lang']; break; default: break; } break; case 'php': if (!empty($tag['attributes']['code'])) { eval('$content = ' . $tag['attributes']['code'] . ';'); } break; case 'theme': // compatibility with Navigate < 1.8.9 // deprecated! code will be removed in Navigate 2.0 if ($tag['attributes']['name'] == 'url') { $tag['attributes']['mode'] = 'url'; } else { if ($tag['attributes']['name'] == 'style') { $tag['attributes']['name'] = $tag['attributes']['mode']; $tag['attributes']['mode'] = 'style'; } } // new syntax ("mode" first) switch ($tag['attributes']['mode']) { case "style": $content = $website->theme_options->style; if (!empty($tag['attributes']['name'])) { switch ($tag['attributes']['name']) { case 'name': $content = $website->theme_options->style; break; case 'color': default: // return theme definition file location for the requested substyle if (!empty($website->theme_options->style)) { $content = $theme->styles->{$website->theme_options->style}->{$tag['attributes']['name']}; } if (empty($content)) { // return first available $theme_styles = array_keys(get_object_vars($theme->styles)); $content = $theme->styles->{$theme_styles[0]}->{$tag['attributes']['name']}; } break; } } break; case "url": $content = $idn->encode($website->absolute_path(false)); $content .= NAVIGATE_FOLDER . '/themes/' . $theme->name . '/'; break; } break; default: //var_dump($tag['attributes']['object']); break; } $html = str_replace($tag['full_tag'], $content, $html); } return $html; }
function nvweb_metatags($vars = array()) { global $website; global $current; global $DB; global $structure; global $events; // process page title and (to do: get specific metatags) $section = ''; $separator = ' | '; if (!empty($vars['title_separator'])) { $separator = $vars['title_separator']; } switch ($current['type']) { case 'item': $section = $DB->query_single('text', 'nv_webdictionary', ' node_type = ' . protect($current['type']) . ' AND node_id = ' . protect($current['object']->id) . ' AND subtype = ' . protect('title') . ' AND website = ' . $website->id . ' AND lang = ' . protect($current['lang'])); $section = $separator . $section; break; case 'structure': $breadcrumbs = nvweb_breadcrumbs(array('separator' => $separator, 'links' => 'false')); $section = $separator . $breadcrumbs; break; default: } // global website metatags $metatags = $website->metatags; if (is_array($metatags)) { $metatags = $metatags[$current['lang']]; } if (!empty($website->metatag_description[$current['lang']])) { $metatags .= "\n" . '<meta name="language" content="' . $current['lang'] . '" />' . "\n"; } if (!empty($website->metatag_description[$current['lang']])) { $metatags .= "\n" . '<meta name="description" content="' . $website->metatag_description[$current['lang']] . '" />' . "\n"; } // retrieve content tags and add it to the global metatags of the website $tags_website = str_replace(', ', ',', $website->metatag_keywords[$current['lang']]); $tags_website = explode(',', $tags_website); $tags_website = array_filter($tags_website); $tags_content = webdictionary::load_element_strings($current['type'], $current['object']->id); $tags_content = str_replace(', ', ',', @$tags_content[$current['lang']]['tags']); $tags_content = explode(',', $tags_content); $tags_content = array_filter($tags_content); $tags = array_merge($tags_website, $tags_content); $tags = implode(',', $tags); if (strpos($metatags, '<meta name="keywords" content="') !== FALSE) { $metatags = str_replace('<meta name="keywords" content="', '<meta name="keywords" content="' . $tags, $metatags); } else { $metatags .= '<meta name="keywords" content="' . $tags . '" />'; } if (@$vars['generator'] != 'false') { $current_version = update::latest_installed(); $metatags .= "\n" . '<meta name="generator" content="Navigate CMS ' . $current_version->version . '" />'; } if ($website->favicon > 0) { $favicon = NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . $website->favicon . '&disposition=inline'; $metatags .= "\n" . '<link rel="shortcut icon" href="' . $favicon . '" />'; } // website public feeds $DB->query('SELECT id FROM nv_feeds WHERE website = ' . $website->id . ' AND permission = 0 AND enabled = 1'); $feeds = $DB->result('id'); for ($f = 0; $f < count($feeds); $f++) { $feed = new feed(); $feed->load($feeds[$f]); if (strpos(strtolower($feed->format), 'rss') !== false) { $mime = 'application/rss+xml'; } else { if (strpos(strtolower($feed->format), 'atom') !== false) { $mime = 'application/atom+xml'; } else { $mime = 'text/xml'; } } $metatags .= "\n" . '<link rel="alternate" type="' . $mime . '" title="' . $feed->dictionary[$current['lang']]['title'] . '" href="' . $website->absolute_path() . $feed->paths[$current['lang']] . '" />'; } $out = '<title>' . $website->name . $section . '</title>' . "\n"; $out .= $metatags; if (!empty($website->additional_scripts) && empty($_SESSION['APP_USER#' . APP_UNIQUE])) { nvweb_after_body('html', $website->additional_scripts); } $events->trigger('metatags', 'render', array('out' => &$out, 'default_title' => $website->name . $section, 'section' => $section)); return $out; }
public static function hierarchy($id_parent = 0, $ws_id = null) { global $website; global $theme; if (empty($ws_id)) { $ws_id = $website->id; } $ws = new website(); $ws->load($ws_id); $flang = $ws->languages_list[0]; if (empty($flang)) { return array(); } $tree = array(); if ($id_parent == -1) { // create the virtual root structure entry (the website) $obj = new structure(); $obj->id = 0; $obj->label = $ws->name; $obj->_multilanguage_label = $ws->name; $obj->parent = -1; $obj->children = structure::hierarchy(0, $ws_id); $tree[] = $obj; } else { $tree = structure::loadTree($id_parent, $ws_id); $templates = template::elements('structure'); if (empty($templates)) { $templates = array(); } for ($i = 0; $i < count($tree); $i++) { $tree[$i]->dictionary = webdictionary::load_element_strings('structure', $tree[$i]->id); $tree[$i]->label = $tree[$i]->dictionary[$ws->languages_list[0]]['title']; $tree[$i]->template_title = $tree[$i]->template; foreach ($templates as $template_def) { if ($template_def->type == $tree[$i]->template) { $tree[$i]->template_title = $template_def->title; break; } } if (method_exists($theme, "t")) { $tree[$i]->template_title = $theme->t($tree[$i]->template_title); } for ($wl = 0; $wl < count($ws->languages_list); $wl++) { $lang = $ws->languages_list[$wl]; if (empty($tree[$i]->dictionary[$lang]['title'])) { $tree[$i]->dictionary[$lang]['title'] = '[ ? ]'; } $style = ''; if ($lang != $flang) { $style = 'display: none'; } $label[] = '<span class="structure-label" lang="' . $lang . '" style="' . $style . '">' . $tree[$i]->dictionary[$lang]['title'] . '</span>'; $bc[$tree[$i]->id][$lang] = $tree[$i]->dictionary[$lang]['title']; } $children = structure::hierarchy($tree[$i]->id, $ws_id); $tree[$i]->children = $children; } } return $tree; }
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; }