function navigate_property_layout_form($element, $template, $object, $object_id) { global $website; global $layout; $out = array(); $property_rows = array(); // load the property values of the object $properties = property::load_properties($element, $template, $object, $object_id); // generate the form for ($p = 0; $p < count($properties); $p++) { if ($properties[$p]->enabled === '0' || $properties[$p]->enabled === 0 || $properties[$p]->enabled === "false" || $properties[$p]->enabled === false) { continue; } $property_rows[] = navigate_property_layout_field($properties[$p]); } if (!empty($property_rows) && !empty($property_rows[0])) { $out[] = '<div id="navigate-properties-form">'; $out[] = '<input type="hidden" name="property-element" value="' . $element . '" />'; $out[] = '<input type="hidden" name="property-template" value="' . $template . '" />'; $property_rows = implode("\n", $property_rows); // language selector (only if it's a multilanguage website and we have almost one multilanguage property) if (count($website->languages) > 1 && strpos($property_rows, 'lang="' . $website->languages_list[1] . '"') !== false) { $website_languages_selector = $website->languages(); $website_languages_selector = array_merge(array('' => '(' . t(443, 'All') . ')'), $website_languages_selector); $naviforms = new naviforms(); $out[] = '<div class="navigate-form-row">'; $out[] = '<label>' . t(63, 'Languages') . '</label>'; $out[] = $naviforms->buttonset('properties_language_selector', $website_languages_selector, '', "navigate_tabform_language_selector(this);"); $out[] = '</div>'; } $out[] = $property_rows; $out[] = '</div>'; navigate_property_layout_scripts(); } return implode("\n", $out); }
public function property_definition($property_name) { global $DB; // load properties if not already done if (empty($this->properties)) { // check if this is an embedded item or it is a free element if ($this->embedding == 1 && $this->association == 'category') { // properties are given in structure definition $structure_template = @$DB->query_single('template', 'nv_structure', 'id = ' . intval($this->category)); $this->properties = property::load_properties('structure', $structure_template, 'item', $this->id); } else { $this->properties = property::load_properties('item', $this->template, 'item', $this->id); } } for ($p = 0; $p < count($this->properties); $p++) { if ($this->properties[$p]->name == $property_name || $this->properties[$p]->id == $property_name) { $out = $this->properties[$p]; break; } } return $out; }
public function property_exists($property_name) { global $theme; // load properties if not already done if (empty($this->properties)) { $this->properties = property::load_properties('webuser', $theme->name, 'webuser', $this->id); } for ($p = 0; $p < count($this->properties); $p++) { if ($this->properties[$p]->name == $property_name || $this->properties[$p]->id == $property_name) { return true; } } return false; }
public static function load_properties_associative($element, $template, $object_type, $object_id) { // maybe we have cache of the current website? global $properties; if (isset($properties[$object_type . '-' . $object_id])) { $props = $properties[$object_type . '-' . $object_id]; } else { $props = property::load_properties($element, $template, $object_type, $object_id); } // now create the associative array by property name => value $associative_properties = array(); if (!is_array($props)) { $props = array(); } foreach ($props as $property) { if (is_numeric($property->id)) { $associative_properties[$property->name] = $property->value; } else { $associative_properties[$property->id] = $property->value; } } return $associative_properties; }
public static function export_sample($a_categories, $a_items, $a_block_groups, $a_blocks, $a_comments, $folder) { global $website; global $theme; global $DB; @set_time_limit(0); $categories = array(); $items = array(); $blocks = array(); $block_groups = array(); $comments = array(); $properties = array(); $files = array(); $settings = array(); // structure for ($c = 0; $c < count($a_categories); $c++) { $tmp = new structure(); $tmp->load($a_categories[$c]); //$properties['structure'][$tmp->id] = property::load_properties_associative('structure', $tmp->template, 'structure', $tmp->id); $properties['structure'][$tmp->id] = property::load_properties('structure', $tmp->template, 'structure', $tmp->id); $categories[$tmp->id] = $tmp; // add files referenced in properties if (is_array($properties['structure'][$tmp->id])) { foreach ($properties['structure'][$tmp->id] as $property) { if ($property->type == 'image' || $property->type == 'file') { $files[] = $property->value; } } } } // comments for ($c = 0; $c < count($a_comments); $c++) { $tmp = new comment(); $tmp->load($a_comments[$c]); $comments[$tmp->id] = $tmp; } // items for ($i = 0; $i < count($a_items); $i++) { $tmp = new item(); $tmp->load($a_items[$i]); $template_id = $tmp->template; if ($tmp->association != "free" && $tmp->embedding == 1) { // we have to get the template set in the category of the item $template_id = $DB->query_single('template', 'nv_structure', ' id = ' . protect($tmp->category) . ' AND website = ' . $website->id); } $properties['item'][$tmp->id] = property::load_properties('item', $template_id, 'item', $tmp->id); list($tmp->dictionary, $files) = theme::export_sample_parse_dictionary($tmp->dictionary, $files); // add files referenced in properties if (is_array($properties['item'][$tmp->id])) { foreach ($properties['item'][$tmp->id] as $property) { if ($property->type == 'image' || $property->type == 'file') { $files[] = $property->value; } } } // add files referenced in gallery if (is_array($tmp->galleries[0])) { $gallery_images = array_keys($tmp->galleries[0]); $files = array_merge($files, $gallery_images); } $items[$tmp->id] = $tmp; } // block_groups for ($i = 0; $i < count($a_block_groups); $i++) { $tmp = new block_group(); $tmp->load($a_block_groups[$i]); $block_groups[$tmp->id] = $tmp; if (is_array($tmp->blocks)) { foreach ($tmp->blocks as $bgb) { if ($bgb['type'] == 'block_group_block') { $properties['block_group_block'][$a_block_groups[$i]][$bgb['uid']] = property::load_properties($bgb['id'], $tmp->code, 'block_group_block', $bgb['id'], $bgb['uid']); } else { if ($bgb['type'] == 'extension') { $properties['block_group_block'][$a_block_groups[$i]][$bgb['uid']] = property::load_properties(NULL, $bgb['id'], "extension_block", NULL, $bgb['uid']); } } } } // note: maybe not all blocks in the group have been selected in the "blocks" tab // here we only export the block group definition, the block group blocks properties and the extension blocks properties, not adding anything else to export } // blocks for ($i = 0; $i < count($a_blocks); $i++) { $tmp = new block(); $tmp->load($a_blocks[$i]); $properties['block'][$tmp->id] = property::load_properties('block', $tmp->type, 'block', $tmp->id); list($tmp->dictionary, $files) = theme::export_sample_parse_dictionary($tmp->dictionary, $files); list($tmp->trigger['trigger-content'], $files) = theme::export_sample_parse_array($tmp->trigger['trigger-content'], $files); list($tmp->trigger['trigger-html'], $files) = theme::export_sample_parse_array($tmp->trigger['trigger-html'], $files); if (!empty($tmp->trigger['trigger-image'])) { $files = array_merge($files, array_values($tmp->trigger['trigger-image'])); } if (!empty($tmp->trigger['trigger-rollover'])) { $files = array_merge($files, array_values($tmp->trigger['trigger-rollover'])); } if (!empty($tmp->trigger['trigger-rollover-active'])) { $files = array_merge($files, array_values($tmp->trigger['trigger-rollover-active'])); } if (!empty($tmp->trigger['trigger-flash'])) { $files = array_merge($files, array_values($tmp->trigger['trigger-flash'])); } if (!empty($tmp->action['action-image'])) { $files = array_merge($files, array_values($tmp->action['action-image'])); } if (!empty($tmp->action['action-file'])) { $files = array_merge($files, array_values($tmp->action['action-file'])); } // add files referenced in properties if (is_array($properties['block'][$tmp->id])) { foreach ($properties['block'][$tmp->id] as $property) { if ($property->type == 'image' || $property->type == 'file') { $files[] = $property->value; } } } $blocks[$tmp->id] = $tmp; } // folders // save references and get their files list $folders = array(); $folders_to_check = array(); if (!empty($folder)) { array_push($folders_to_check, $folder); while (!empty($folders_to_check)) { $f = array_shift($folders_to_check); $f = file::filesOnPath($f); foreach ($f as $file) { if ($file->type == 'folder') { array_push($folders_to_check, $file->id); array_push($folders, $file); } else { $files[] = $file->id; } } } } // add files selected as theme_options foreach ($theme->options as $to) { if ($to->type == 'image' || $to->type == 'file') { $to_value = $website->theme_options->{$to->id}; if (is_array($to_value)) { $files = array_merge($files, $to_value); } else { $files[] = $to_value; } } } // include favicon in file list if (!empty($website->favicon)) { $files[] = $website->favicon; } // files $files = array_unique($files); for ($f = 0; $f < count($files); $f++) { $file = new file(); $file->load($files[$f]); $files[$f] = $file; } // settings $settings['homepage'] = $website->homepage; $settings['favicon'] = $website->favicon; $zip = new zipfile(); $zip->addFile(var_export($website->languages, true), 'languages.var_export'); $zip->addFile(var_export($website->theme_options, true), 'theme_options.var_export'); $zip->addFile(var_export($categories, true), 'structure.var_export'); $zip->addFile(var_export($items, true), 'items.var_export'); $zip->addFile(var_export($block_groups, true), 'block_groups.var_export'); $zip->addFile(var_export($blocks, true), 'blocks.var_export'); $zip->addFile(var_export($comments, true), 'comments.var_export'); $zip->addFile(var_export($files, true), 'files.var_export'); $zip->addFile(var_export($folders, true), 'folders.var_export'); $zip->addFile(var_export($properties, true), 'properties.var_export'); $zip->addFile(var_export($settings, true), 'settings.var_export'); foreach ($files as $file) { $zip->addFile(file_get_contents($file->absolute_path()), 'files/' . $file->id); } $contents = $zip->file(); header('Content-Disposition: attachment; filename="' . $website->theme . '_sample.zip"'); header("Content-type: application/octet-stream"); header('Content-Length: ' . strlen($contents)); echo $contents; }
function block_group_extension_block_options($block_group, $block_extension, $block_id, $block_uid, $status) { global $layout; global $website; global $theme; if (empty($block_extension)) { throw new Exception("Unknown extension: {" . $block_extension . "} for block with uid:" . $block_uid); } $extension = new extension(); $extension->load($block_extension); $block = block::extension_block($extension, $block_id); $properties = $block->properties; if (empty($properties)) { return; } $layout = null; $layout = new layout('navigate'); if ($status !== null) { if ($status) { $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); } else { $layout->navigate_notification(t(56, "Unexpected error"), true, true); } } $navibars = new navibars(); $naviforms = new naviforms(); $navibars->title(t(437, 'Block') . ' [' . $block_extension . ' / ' . $block_id . ']'); $layout->navigate_media_browser(); // we can use media browser in this function $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_media_browser();"> <img height="16" align="absmiddle" width="16" src="img/icons/silk/images.png"> ' . t(36, 'Media') . '</a>')); $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(0);"> <img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>')); $navibars->form(); $navibars->add_tab(t(200, 'Options')); $navibars->add_tab_content($naviforms->hidden('form-sent', 'true')); // show a language selector (only if it's a multi language website) if (count($website->languages) > 1) { $website_languages_selector = $website->languages(); $website_languages_selector = array_merge(array('' => '(' . t(443, 'All') . ')'), $website_languages_selector); $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('language_selector', $website_languages_selector, '', "navigate_tabform_language_selector(this);"))); } $properties_values = property::load_properties(NULL, $block_id, "extension_block", $block_group, $block_uid); foreach ($properties as $option) { $property = new property(); $property_value = ''; foreach ($properties_values as $pv) { if ($pv->id == $option->id) { $property_value = $pv->value; } } $property->load_from_object($option, $property_value, $extension); if ($property->type == 'tab') { $navibars->add_tab($property->name); if (count($website->languages) > 1) { $website_languages_selector = $website->languages(); $website_languages_selector = array_merge(array('' => '(' . t(443, 'All') . ')'), $website_languages_selector); $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('language_selector', $website_languages_selector, '', "navigate_tabform_language_selector(this);"))); } } $navibars->add_tab_content(navigate_property_layout_field($property, $extension)); } $layout->add_content('<div id="navigate-content" class="navigate-content ui-corner-all">' . $navibars->generate() . '</div>'); navigate_property_layout_scripts(); $layout->navigate_additional_scripts(); $layout->add_script(' $("html").css("background", "transparent"); '); $out = $layout->generate(); return $out; }
public function property_definition($property_name) { // load properties if not already done if (empty($this->properties)) { if ($this->class == 'block_group_block') { $this->properties = property::load_properties('block_group_block', $this->_block_group_id, 'block_group_block', $this->id); } else { $this->properties = property::load_properties('block', $this->type, 'block', $this->id); } } for ($p = 0; $p < count($this->properties); $p++) { if ($this->properties[$p]->name == $property_name || $this->properties[$p]->id == $property_name) { $out = $this->properties[$p]; break; } } 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_parse_tag($tag, $item, $source = 'item', $item_relative_position, $item_absolute_position, $total) { global $current; global $website; global $structure; global $DB; $out = ''; switch ($tag['attributes']['source']) { // special condition, return direct query result values case 'query': $out = $item->_query->{$tag}['attributes']['value']; break; // special: return element position in list // special: return element position in list case 'position': $position = $item_relative_position; if ($tag['attributes']['absolute'] == 'true') { $position = $item_absolute_position; } switch ($tag['attributes']['type']) { case 'alphabetic': $out = number2alphabet($position); break; case 'numeric': default: $out = $position + 1; // first element is 1, but in list is zero break; } break; // NOTE: the following refers to structure information of an ITEM, useless if the source are categories! // NOTE: the following refers to structure information of an ITEM, useless if the source are categories! case 'structure': case 'category': nvweb_menu_load_dictionary(); // load menu translations if not already done nvweb_menu_load_routes(); // load menu paths if not already done switch ($tag['attributes']['value']) { case 'title': if ($source == 'structure' || $source == 'category') { $out = $structure['dictionary'][$item->id]; } else { $out = $structure['dictionary'][$item->category]; } if (!empty($tag['attributes']['length'])) { $out = core_string_cut($out, $tag['attributes']['length'], '…'); } break; case 'slug': if ($source == 'structure' || $source == 'category') { $out = $structure['dictionary'][$item->id]; } else { $out = $structure['dictionary'][$item->category]; } // remove spaces, special chars, etc. $out = core_string_clean($out); $out = slug($out); break; case 'property': $id = $item->id; if ($source != 'structure' && $source != 'category') { $id = $item->category; } $nvweb_properties_parameters = array_replace($tag['attributes'], array('mode' => !isset($tag['attributes']['mode']) ? 'structure' : $tag['attributes']['mode'], 'id' => $id, 'property' => !empty($tag['attributes']['property']) ? $tag['attributes']['property'] : $tag['attributes']['name'])); $out = nvweb_properties($nvweb_properties_parameters); break; case 'url': case 'path': if ($source == 'structure' || $source == 'category') { $out = $structure['routes'][$item->id]; } else { $out = $structure['routes'][$item->category]; } $out = nvweb_prepare_link($out); break; case 'id': if ($source == 'structure' || $source == 'category') { $out = $item->id; } else { // source = 'item'? $out = $item->category; } break; default: break; } break; // ITEM comments // ITEM comments case 'comment': case 'comments': switch ($tag['attributes']['value']) { case 'id': $out = $item->id; break; case 'avatar': $size = '48'; $extra = ''; if (!empty($tag['attributes']['size'])) { $size = intval($tag['attributes']['size']); } if (!empty($tag['attributes']['border'])) { $extra .= '&border=' . $tag['attributes']['border']; } if (!empty($item->avatar)) { $out = '<img class="' . $tag['attributes']['class'] . '" src="' . NVWEB_OBJECT . '?type=image' . $extra . '&id=' . $item->avatar . '" width="' . $size . 'px" height="' . $size . 'px"/>'; } else { if (!empty($tag['attributes']['default'])) { // the comment creator has not an avatar, but the template wants to show a default one // 3 cases: // numerical -> ID of the avatar image file in Navigate CMS // absolute path (http://www...) // relative path (/img/avatar.png) -> path to the avatar file included in the THEME used if (is_numeric($tag['attributes']['default'])) { $out = '<img class="' . $tag['attributes']['class'] . '" src="' . NVWEB_OBJECT . '?type=image' . $extra . '&id=' . $tag['attributes']['default'] . '" width="' . $size . 'px" height="' . $size . 'px"/>'; } else { if (strpos($tag['attributes']['default'], 'http://') === 0) { $out = '<img class="' . $tag['attributes']['class'] . '" src="' . $tag['attributes']['default'] . '" width="' . $size . 'px" height="' . $size . 'px"/>'; } else { if ($tag['attributes']['default'] == 'none') { $out = ''; } else { $out = '<img class="' . $tag['attributes']['class'] . '"src="' . NAVIGATE_URL . '/themes/' . $website->theme . '/' . $tag['attributes']['default'] . '" width="' . $size . 'px" height="' . $size . 'px"/>'; } } } } else { $gravatar_hash = ""; $gravatar_default = 'blank'; if (!empty($tag['attributes']['gravatar_default'])) { $gravatar_default = $tag['attributes']['gravatar_default']; } if (!empty($item->email)) { $gravatar_hash = md5(strtolower(trim($item->email))); } else { if (!empty($item->user)) { $email = $DB->query_single('email', 'nv_webusers', 'id = ' . protect($item->user)); if (!empty($email)) { $gravatar_hash = md5(strtolower(trim($item->email))); } } } if (!empty($gravatar_hash) && $gravatar_default != 'none') { // gravatar real url: https://www.gravatar.com/avatar/ // we use libravatar to get more userbase $gravatar_url = 'https://seccdn.libravatar.org/avatar/' . $gravatar_hash . '?s=' . $size . '&d=' . $gravatar_default; $out = '<img class="' . $tag['attributes']['class'] . '" src="' . $gravatar_url . '" width="' . $size . 'px" height="' . $size . 'px"/>'; } else { $out = '<img class="' . $tag['attributes']['class'] . '" src="data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="' . $size . 'px" height="' . $size . 'px"/>'; } } } if ($tag['attributes']['linked'] == 'true' && !empty($out)) { if (!empty($item->url)) { $comment_link = $item->url; } else { if (!empty($item->user)) { $wu = new webuser(); $wu->load($item->user); $comment_link = $wu->social_website; } } if (!empty($comment_link)) { $out = '<a href="' . $comment_link . '" target="_blank">' . $out . '</a>'; } } break; case 'username': $out = !empty($item->username) ? $item->username : $item->name; if ($tag['attributes']['linked'] == 'true' && !empty($out)) { if (!empty($item->url)) { $comment_link = $item->url; } else { if (!empty($item->user)) { $wu = new webuser(); $wu->load($item->user); $comment_link = $wu->social_website; } } if (!empty($comment_link)) { $out = '<a href="' . $comment_link . '" target="_blank">' . $out . '</a>'; } } break; case 'website': if (!empty($item->url)) { $out = $item->url; } else { if (!empty($item->user)) { $wu = new webuser(); $wu->load($item->user); $out = $wu->social_website; } } if (empty($out)) { $out = '#'; } break; case 'message': if (!empty($tag['attributes']['length'])) { $out = core_string_cut($item->message, $tag['attributes']['length'], '…'); } else { $out = nl2br($item->message); } break; case 'date': // Navigate CMS 1.6.6 compatibility if (empty($tag['attributes']['format']) && !empty($tag['attributes']['date_format'])) { $tag['attributes']['format'] = $tag['attributes']['date_format']; } if (!empty($tag['attributes']['format'])) { // custom date format $out = nvweb_content_date_format($tag['attributes']['format'], $item->date_created); } else { $out = date($website->date_format . ' H:i', $item->date_created); } break; case 'item_url': $out = nvweb_source_url('item', $item->item, $current['lang']); break; case 'item_title': $out = $item->item_title; break; case 'reply_to': $out = $item->reply_to; break; case 'depth': $c = new comment(); $c->load_from_resultset(array($item)); $out = $c->depth(); break; case 'property': $c = new comment(); $c->load_from_resultset(array($item)); // pass all nvlist tag parameters to properties nvweb, but some attribute/values take preference $nvweb_properties_parameters = array_replace($tag['attributes'], array('mode' => 'comment', 'id' => $c->id, 'template' => $c->element_template(), 'property' => !empty($tag['attributes']['property']) ? $tag['attributes']['property'] : $tag['attributes']['name'])); $out = nvweb_properties($nvweb_properties_parameters); break; } break; case 'block': switch ($tag['attributes']['value']) { case 'id': $out = $item->id; break; // only for blocks in a block group! // only for blocks in a block group! case 'uid': $out = $item->uid; break; case 'block': // generate the full block code if ($item->type == "extension") { if (function_exists('nvweb_' . $item->extension . '_' . $item->id)) { // load extension block property values $item->properties = property::load_properties(NULL, $item->id, "extension_block", NULL, $item->uid); $out = call_user_func('nvweb_' . $item->extension . '_' . $item->id, $item); } } else { $out = nvweb_blocks_render($item->type, $item->trigger, $item->action, NULL, NULL, $tag['attributes']); } break; // not for extension_blocks // not for extension_blocks case 'title': $out = $item->dictionary[$current['lang']]['title']; if (!empty($tag['attributes']['length'])) { $out = core_string_cut($out, $tag['attributes']['length'], '…'); } break; case 'content': if ($item->type == "extension") { if (function_exists('nvweb_' . $item->extension . '_' . $item->id)) { // load extension block property values $item->properties = property::load_properties(NULL, $item->id, "extension_block", NULL, $item->uid); $out = call_user_func('nvweb_' . $item->extension . '_' . $item->id, $item); } } else { $out = nvweb_blocks_render($item->type, $item->trigger, $item->action, 'content', $item, $tag['attributes']); } break; // not for extension_blocks // not for extension_blocks case 'url': case 'path': $out = nvweb_blocks_render_action($item->action, '', $current['lang'], true); if (empty($out)) { $out = '#'; } else { $out = nvweb_prepare_link($out); } break; // not for extension_blocks // not for extension_blocks case 'target': if ($item->action['action-type'][$current['lang']] == 'web-n') { $out = '_blank'; } else { $out = '_self'; } break; // not for extension_blocks (only for standard blocks and block group blocks) // not for extension_blocks (only for standard blocks and block group blocks) case 'property': $properties_mode = 'block'; if (!is_numeric($item->id)) { $properties_mode = 'block_group_block'; } $nvweb_properties_parameters = array_replace($tag['attributes'], array('mode' => !isset($tag['attributes']['mode']) ? $properties_mode : $tag['attributes']['mode'], 'id' => $item->id, 'property' => !empty($tag['attributes']['property']) ? $tag['attributes']['property'] : $tag['attributes']['name'], 'uid' => @$item->uid)); $out = nvweb_properties($nvweb_properties_parameters); break; // not for extension_blocks // not for extension_blocks case 'poll_answers': $out = nvweb_blocks_render_poll($item); break; default: break; } break; case 'block_link': switch ($tag['attributes']['value']) { case 'id': $out = $item->id; break; case 'title': $out = $item->title; if (!empty($tag['attributes']['length'])) { $out = core_string_cut($out, $tag['attributes']['length'], '…'); } break; case 'url': case 'path': $out = $item->link; if (empty($out)) { $out = '#'; } else { $out = nvweb_prepare_link($out); } break; case 'target': if ($item->new_window == 1) { $out = '_blank'; } else { $out = '_self'; } break; case 'icon': $out = @$item->icon; break; default: break; } break; case 'block_type': switch ($tag['attributes']['value']) { case 'title': $title_obj = json_decode($item->title, true); if (empty($title_obj)) { // not json $out = $item->title; } else { $out = $title_obj[$current['lang']]; } break; } break; case 'gallery': switch ($tag['attributes']['value']) { case 'url': case 'path': $out = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&disposition=inline'; break; case 'thumbnail': case 'thumbnail_url': $thumbnail_url = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&disposition=inline&width=' . $tag['attributes']['width'] . '&height=' . $tag['attributes']['height'] . '&border=' . $tag['attributes']['border']; if ($tag['attributes']['value'] == 'thumbnail_url' || @$tag['attributes']['return'] == 'url') { $out = $thumbnail_url; } else { $out = '<img src="' . $thumbnail_url . '" alt="' . $item[$current['lang']] . '" title="' . $item[$current['lang']] . '" />'; } break; case 'title': $f = new file(); $f->load($item['file']); $out = $f->title[$current['lang']]; break; case 'alt': case 'description': $f = new file(); $f->load($item['file']); $out = $f->description[$current['lang']]; break; default: $out = '<a href="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&disposition=inline"> <img src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&disposition=inline&width=' . $tag['attributes']['width'] . '&height=' . $tag['attributes']['height'] . '&border=' . $tag['attributes']['border'] . '" alt="' . $item[$current['lang']] . '" title="' . $item[$current['lang']] . '" /> </a>'; break; } break; case 'item': // useful also for source="structure" (but some are nonsense: title, comments, etc) // useful also for source="structure" (but some are nonsense: title, comments, etc) default: switch ($tag['attributes']['value']) { case 'id': $out = $item->id; break; case 'slug': $lang = $current['lang']; if (!empty($tag['attributes']['lang'])) { $lang = $tag['attributes']['lang']; } $out = $item->dictionary[$lang]['title']; // remove spaces, special chars, etc. $out = core_string_clean($out); $out = slug($out); break; case 'title': $lang = $current['lang']; if (!empty($tag['attributes']['lang'])) { $lang = $tag['attributes']['lang']; } $out = $item->dictionary[$lang]['title']; if (!empty($tag['attributes']['length'])) { $out = core_string_cut($out, $tag['attributes']['length'], '…', $tag['attributes']['length']); } break; case 'author': if (!empty($item->author)) { $nu = new user(); $nu->load($item->author); $out = $nu->username; unset($nu); } if (empty($out)) { $out = $website->name; } break; case 'date': case 'date_post': if (!empty($tag['attributes']['format'])) { // custom date format $out = nvweb_content_date_format($tag['attributes']['format'], $item->date_to_display); } else { $out = date($website->date_format, $item->date_to_display); } break; case 'content': case 'section': if ($source == 'structure' && $tag['attributes']['source'] == 'item') { $items = nvweb_content_items($item->id, true, 1, false, 'priority'); // we force finding the first non-embedded item ordered by priority if (empty($items)) { $items = nvweb_content_items($item->id, true, 1, true, 'priority'); } // find the first embedded item ordered by priority $item = $items[0]; } $section = $tag['attributes']['section']; if (empty($section)) { $section = 'main'; } $out = $item->dictionary[$current['lang']]['section-' . $section]; if (!empty($tag['attributes']['length'])) { $allowed_tags = ''; if (!empty($tag['attributes']['allowed_tags'])) { $allowed_tags = explode(',', $tag['attributes']['allowed_tags']); } $out = core_string_cut($out, $tag['attributes']['length'], '…', $allowed_tags); } break; case 'comments': $out = nvweb_content_comments_count($item->id); break; case 'gallery': $params = array('item' => $item->id); $params = array_merge($params, $tag['attributes']); $out = nvweb_gallery($params); break; case 'image': case 'photo': $photo = @array_shift(array_keys($item->galleries[0])); if (empty($photo)) { $out = NVWEB_OBJECT . '?type=transparent'; } else { $out = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $photo . '&disposition=inline&width=' . $tag['attributes']['width'] . '&height=' . $tag['attributes']['height'] . '&border=' . $tag['attributes']['border']; } break; case 'url': case 'path': // rss -> full url // item -> relative url // embedded item -> category url if ($item->embedding == 1 && $item->association == 'category') { nvweb_menu_load_routes(); // load menu paths if not already done $out = nvweb_prepare_link($structure['routes'][$item->category]); } else { $path = $item->paths[$current['lang']]; if (empty($path)) { $path = '/node/' . $item->id; } $out = nvweb_prepare_link($path); } break; case 'tags': // pass all nvlist tag parameters to the content nvweb, but some attribute/values take preference $nvweb_parameters = array_replace($tag['attributes'], array('mode' => 'tags', 'id' => $item->id)); $out = nvweb_content($nvweb_parameters); break; case 'score': $out = nvweb_votes_calc($item, $tag['attributes']['round'], $tag['attributes']['half'], $tag['attributes']['min'], $tag['attributes']['max']); break; case 'votes': $out = intval($item->votes); break; case 'views': $out = intval($item->views); break; case 'property': if ($source == 'structure' && $tag['attributes']['source'] == 'item') { $items = nvweb_content_items($item->id, true, 1, false, 'priority'); // we force finding the first non-embedded item ordered by priority if (empty($items)) { $items = nvweb_content_items($item->id, true, 1, true, 'priority'); } // find the first embedded item ordered by priority $item = $items[0]; $source = "item"; } // pass all nvlist tag parameters to properties nvweb, but some attribute/values take preference $nvweb_properties_parameters = array_replace($tag['attributes'], array('mode' => $source == 'structure' || $source == 'category' ? 'structure' : 'item', 'id' => $item->id, 'template' => $item->template, 'property' => !empty($tag['attributes']['property']) ? $tag['attributes']['property'] : $tag['attributes']['name'])); $out = nvweb_properties($nvweb_properties_parameters); break; default: // maybe a special tag not related to a source? (unimplemented) } break; } return $out; }
function nvweb_properties($vars = array()) { global $website; global $DB; global $current; global $cache; global $properties; global $webuser; $out = ''; switch (@$vars['mode']) { case 'website': $wproperty = new property(); $wproperty->load_from_theme($vars['property']); if (!empty($wproperty)) { $out = nvweb_properties_render($wproperty, $vars); } break; case 'webuser': $wuproperty = new property(); $wuproperty->load_from_webuser($vars['property']); if (!empty($wuproperty)) { $out = nvweb_properties_render($wuproperty, $vars); } break; case 'element': case 'item': // deprecated, may be removed in a future version // if item ID is not given and the current object an element or a structure category? if (empty($vars['id']) && $current['type'] == 'structure') { // find the first embedded element for the current category // (because the template code has requested specifically to return the property from an element!) $itm = nvweb_content_items($current['object']->id, true, 1, true, 'priority'); if (!empty($itm) && isset($itm[0])) { $vars['id'] = $itm[0]->id; } else { $vars['id'] = 0; } } if (!isset($properties['item-' . $vars['id']]) && !empty($vars['id'])) { // load item template if (empty($vars['template'])) { $vars['template'] = $DB->query_single('template', 'nv_items', ' id = ' . protect($vars['id'])); } // if template is not defined (embedded element), take its category template if (empty($vars['template'])) { $vars['template'] = $DB->query_single('template', 'nv_structure', ' id = ( SELECT category FROM nv_items WHERE id = ' . intval($vars['id']) . ' )'); } $properties['item-' . $vars['id']] = property::load_properties("item", $vars['template'], 'item', $vars['id']); } else { if (empty($vars['id'])) { $vars['type'] = $current['object']->template; if ($current['type'] == "item") { $vars['id'] = $current['object']->id; } else { if ($current['type'] == "structure") { // find the first embedded content associated with this structure entry // (because the template code has requested specifically to return the property from an element!) $itm = nvweb_content_items($current['object']->id, true, 1, true, 'priority'); if (!empty($itm) && isset($itm[0])) { $vars['id'] = $itm[0]->id; } else { $vars['id'] = 0; } } } if (!isset($properties['item-' . $vars['id']])) { $properties['item-' . $current['object']->id] = property::load_properties("item", $vars['type'], 'item', $vars['id']); } } } $current_properties = $properties['item-' . $vars['id']]; // now we find the property requested if (!is_array($current_properties)) { $current_properties = array(); } foreach ($current_properties as $property) { if ($property->id == $vars['property'] || $property->name == $vars['property']) { $out = nvweb_properties_render($property, $vars); break; } } break; case 'block': if (!isset($properties['block-' . $vars['id']])) { // load item type if (empty($vars['type'])) { $vars['type'] = $DB->query_single('type', 'nv_blocks', ' id = ' . protect($vars['id'])); if (empty($cache['block_types'])) { $cache['block_types'] = block::types(); } // we need to know if the block is defined in the active theme or in the database (numeric ID) foreach ($cache['block_types'] as $bt) { if ($bt['code'] == $vars['type']) { $vars['type'] = $bt['id']; break; } } } $properties['block-' . $vars['id']] = property::load_properties("block", $vars['type'], 'block', $vars['id']); } $current_properties = $properties['block-' . $vars['id']]; // now we find the property requested if (!is_array($current_properties)) { $current_properties = array(); } foreach ($current_properties as $property) { if ($property->id == $vars['property'] || $property->name == $vars['property']) { $out = nvweb_properties_render($property, $vars); break; } } break; case 'block_group_block': // find block_group block definition $block_group = null; // unknown $block_code = $vars['id']; $block_uid = $vars['uid']; if (empty($block_code)) { $block = block::block_group_block_by_property($vars['property']); $block_code = $block->type; } else { // find the block group block by its type $block = block::block_group_block($block_group, $block_code); } $properties = $block->properties; $current_properties = property::load_properties($block_code, $block->_block_group_id, 'block_group_block', $block_code, $block_uid); // now we find the property requested if (!is_array($current_properties)) { $current_properties = array(); } foreach ($current_properties as $property) { if ($property->id == $vars['property'] || $property->name == $vars['property']) { $out = nvweb_properties_render($property, $vars); break; } } break; case 'structure': if (empty($vars['id'])) { if ($current['type'] == 'structure') { $vars['id'] = $current['id']; } else { $vars['id'] = $current['object']->category; } } if (!isset($properties['structure-' . $vars['id']])) { // load category template $category_template = $DB->query_single('template', 'nv_structure', ' id = ' . protect($vars['id'])); if (!empty($category_template)) { $properties['structure-' . $vars['id']] = property::load_properties("structure", $category_template, 'structure', $vars['id']); } } $current_properties = $properties['structure-' . $vars['id']]; // now we find the property requested if (!is_array($current_properties)) { $current_properties = array(); } foreach ($current_properties as $property) { if ($property->id == $vars['property'] || $property->name == $vars['property']) { if ($vars['return'] == 'object') { $out = $property; } else { $out = nvweb_properties_render($property, $vars); } break; } } break; case 'comment': if (!isset($properties['comment-' . $vars['id']])) { $properties['comment-' . $vars['id']] = property::load_properties("comment", $vars['template'], 'comment', $vars['id']); } $current_properties = $properties['comment-' . $vars['id']]; // now we find the property requested if (!is_array($current_properties)) { $current_properties = array(); } foreach ($current_properties as $property) { if ($property->id == $vars['property'] || $property->name == $vars['property']) { if ($vars['return'] == 'object') { $out = $property; } else { $out = nvweb_properties_render($property, $vars); } break; } } break; default: // find the property source by its name $current_properties = array(); // get website theme property $current_properties[] = new property(); $current_properties[0]->load_from_theme($vars['property']); if ($current['type'] == 'item') { if (!isset($properties['item-' . $current['object']->id])) { $properties['item-' . $current['object']->id] = property::load_properties("item", $current['object']->template, 'item', $current['object']->id); } $current_properties = array_merge($current_properties, $properties['item-' . $current['object']->id]); } else { if ($current['type'] == 'structure') { if (!isset($properties['structure-' . $current['object']->id])) { $properties['structure-' . $current['object']->id] = property::load_properties("structure", $current['object']->template, 'structure', $current['object']->id); } $current_properties = array_merge($current_properties, $properties['structure-' . $current['object']->id]); // the property could also be in the first item associated to this structure element $structure_items = nvweb_content_items($current['object']->id, true, 1); if (!empty($structure_items)) { if (empty($structure_items[0]->template)) { $structure_items[0]->template = $current['template']; } $properties['item-' . $structure_items[0]->id] = property::load_properties("item", $structure_items[0]->template, 'item', $structure_items[0]->id); } if (!empty($properties['item-' . $structure_items[0]->id])) { $current_properties = array_merge($current_properties, $properties['item-' . $structure_items[0]->id]); } } else { if ($current['type'] == 'article') { // TO DO } else { // unknown object type, maybe is an object managed by an extension? if (!isset($properties[$current['type'] . '-' . $current['object']->id])) { $properties[$current['type'] . '-' . $current['object']->id] = property::load_properties($current['type'], $current['object']->template, $current['type'], $current['object']->id); } $current_properties = array_merge($current_properties, $properties[$current['type'] . '-' . $current['object']->id]); } } } // now we find the property requested if (!is_array($current_properties)) { $current_properties = array(); } foreach ($current_properties as $property) { if ($property->id == $vars['property'] || $property->name == $vars['property']) { $out = nvweb_properties_render($property, $vars); break; } } break; } return $out; }