Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $wtext = new webdictionary();
    switch ($_REQUEST['act']) {
        case 'json':
            // json data retrieval & operations
            switch ($_REQUEST['oper']) {
                case 'del':
                    // remove rows
                    $ids = $_REQUEST['ids'];
                    foreach ($ids as $id) {
                        $wtext->load($id);
                        $wtext->delete();
                    }
                    echo json_encode(true);
                    break;
                default:
                    // list or search
                    $page = intval($_REQUEST['page']);
                    $max = intval($_REQUEST['rows']);
                    $offset = ($page - 1) * $max;
                    $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'];
                    $where = ' website = ' . $website->id;
                    if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) {
                        if (isset($_REQUEST['quicksearch'])) {
                            $where .= $wtext->quicksearch($_REQUEST['quicksearch']);
                        } else {
                            if (isset($_REQUEST['filters'])) {
                                $where .= navitable::jqgridsearch($_REQUEST['filters']);
                            } else {
                                // single search
                                $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']);
                            }
                        }
                    }
                    list($dataset, $total) = webdictionary_search($where, $orderby, $offset, $max);
                    for ($i = 0; $i < count($dataset); $i++) {
                        $origin = "";
                        if (!empty($dataset[$i]['theme'])) {
                            $origin = '<i class="fa fa-fw fa-paint-brush ui-text-light" title="' . t(368, "Theme") . '"></i> ' . $dataset[$i]['theme'];
                        } else {
                            if (!empty($dataset[$i]['extension'])) {
                                $origin = '<i class="fa fa-fw fa-puzzle-piece ui-text-light" title="' . t(617, "Extension") . '"></i> ' . $dataset[$i]['extension'];
                            }
                        }
                        if (empty($dataset[$i])) {
                            continue;
                        }
                        $out[$i] = array(0 => $dataset[$i]['theme'] . $dataset[$i]['extension'] . '.' . $dataset[$i]['id'], 1 => $dataset[$i]['node_id'], 2 => $origin, 3 => language::name_by_code($dataset[$i]['lang']), 4 => $dataset[$i]['text'], 5 => $dataset[$i]['source']);
                    }
                    navitable::jqgridJson($out, $page, $offset, $max, $total, 0);
                    // 0 is the index of the ghost ID column
                    break;
            }
            session_write_close();
            exit;
            break;
        case 'edit':
            // edit/new form
            if (!empty($_REQUEST['path']) && !is_numeric($_REQUEST['id'])) {
                $wtext->load($_REQUEST['path']);
            } else {
                if (!empty($_REQUEST['id'])) {
                    $wtext->load($_REQUEST['id']);
                }
            }
            if (isset($_REQUEST['form-sent'])) {
                $wtext->load_from_post();
                try {
                    $wtext->save();
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
            }
            $out = webdictionary_form($wtext);
            break;
        case 'remove':
            // remove
            if (!empty($_REQUEST['id'])) {
                $wtext->load($_REQUEST['id']);
                if ($wtext->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    $out = webdictionary_list();
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = webdictionary_form($wtext);
                }
            }
            break;
        case 'edit_language':
            if ($_REQUEST['form-sent'] == 'true') {
                $status = webdictionary::save_translations_post($_REQUEST['code']);
                if ($status == 'true') {
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } else {
                    $layout->navigate_notification(implode('<br />', $status), true, true);
                }
            }
            $out = webdictionary_edit_language_form($_REQUEST['code']);
            break;
        case 0:
            // list / search result
        // list / search result
        default:
            $out = webdictionary_list();
            break;
    }
    return $out;
}
Exemplo n.º 3
0
 public static function remove_properties($element_type, $element_id)
 {
     global $DB;
     global $website;
     webdictionary::save_element_strings('property-' . $element_type, $element_id, array());
     $DB->execute('
         DELETE FROM nv_properties_items
               WHERE website = ' . $website->id . '
                 AND element = ' . protect($element_type) . '
                 AND node_id = ' . intval($element_id) . '
     ');
 }
Exemplo n.º 4
0
 public function update()
 {
     global $DB;
     global $website;
     global $events;
     global $user;
     if (!is_null($user)) {
         if ($user->permission("items.edit") == 'false' && $this->author != $user->id) {
             throw new Exception(t(610, "Sorry, you are not allowed to execute this function."));
         }
         if (!structure::category_allowed($this->category)) {
             throw new Exception(t(610, "Sorry, you are not allowed to execute this function."));
         }
     }
     $this->date_modified = core_time();
     $groups = '';
     if (is_array($this->groups)) {
         $this->groups = array_unique($this->groups);
         // remove duplicates
         $this->groups = array_filter($this->groups);
         // remove empty
         if (!empty($this->groups)) {
             $groups = 'g' . implode(',g', $this->groups);
         }
     }
     if ($groups == 'g') {
         $groups = '';
     }
     $ok = $DB->execute(' 
         UPDATE nv_items
         SET 
             association	= :association,
             category	=   :category,
             embedding	= 	:embedding,
             template	=   :template,
             date_to_display	=  :date_to_display,
             date_published	=  :date_published,
             date_unpublish	=  :date_unpublish,
             date_modified	=  :date_modified,
             author		=   :author,
             galleries	=  :galleries,
             comments_enabled_to = :comments_enabled_to,
             comments_moderator = :comments_moderator,
             access	 	=  :access,
             groups      =  :groups,
             permission 	=  :permission,
             views 	=  :views,
             votes 	=  :votes,
             score 	=  :score,
             position = :position
         WHERE id = :id
           AND website = :website', array(":association" => $this->association, ":category" => $this->category, ":embedding" => $this->embedding, ":template" => $this->template, ":date_to_display" => value_or_default($this->date_to_display, 0), ":date_published" => value_or_default($this->date_published, 0), ":date_unpublish" => value_or_default($this->date_unpublish, 0), ":date_modified" => $this->date_modified, ":author" => $this->author, ":galleries" => serialize($this->galleries), ":comments_enabled_to" => value_or_default($this->comments_enabled_to, 0), ":comments_moderator" => value_or_default($this->comments_moderator, 0), ":access" => $this->access, ":groups" => $groups, ":permission" => $this->permission, ":views" => $this->views, ":votes" => $this->votes, ":score" => $this->score, ":position" => value_or_default($this->position, 0), ":id" => $this->id, ":website" => $this->website));
     if (!$ok) {
         throw new Exception($DB->get_last_error());
     }
     webdictionary::save_element_strings('item', $this->id, $this->dictionary, $this->website);
     webdictionary_history::save_element_strings('item', $this->id, $this->dictionary, false, $this->website);
     path::saveElementPaths('item', $this->id, $this->paths, $this->website);
     $events->trigger('item', 'save', array('item' => $this));
     return true;
 }
Exemplo n.º 5
0
/**
 * 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;
}
Exemplo n.º 6
0
 public function update()
 {
     global $DB;
     global $user;
     if (!is_array($this->categories)) {
         $this->categories = array();
     }
     if (!is_array($this->exclusions)) {
         $this->exclusions = array();
     }
     if (!empty($user->id)) {
         if ($user->permission("blocks.edit") == 'false') {
             throw new Exception(t(610, "Sorry, you are not allowed to execute this function."));
         }
     }
     $groups = '';
     if (is_array($this->groups)) {
         $this->groups = array_unique($this->groups);
         // remove duplicates
         $this->groups = array_filter($this->groups);
         // remove empty
         if (!empty($this->groups)) {
             $groups = 'g' . implode(',g', $this->groups);
         }
     }
     if ($groups == 'g') {
         $groups = '';
     }
     $ok = $DB->execute('UPDATE nv_blocks
          SET
             `type`			= :type,
             date_published 	= :date_published,
             date_unpublish  = :date_unpublish,
             `position` 		= :position,
             fixed	        = :fixed,
             categories		= :categories,
             exclusions		= :exclusions,
             elements        = :elements,
             `trigger` 		= :trigger,
             `action` 		= :action,
             access 			= :access,
             groups          = :groups,
             enabled 		= :enabled,
             notes	 		= :notes,
             date_modified	= :date_modified
          WHERE id = :id
            AND website = :website
         ', array(':id' => $this->id, ':website' => $this->website, ':type' => $this->type, ':date_published' => value_or_default($this->date_published, 0), ':date_unpublish' => value_or_default($this->date_unpublish, 0), ':position' => value_or_default($this->position, 0), ':fixed' => value_or_default($this->fixed, 0), ':categories' => implode(',', $this->categories), ':exclusions' => implode(',', $this->exclusions), ':elements' => json_encode($this->elements), ':access' => value_or_default($this->access, 0), ':groups' => $groups, ':enabled' => value_or_default($this->enabled, 0), ':trigger' => serialize($this->trigger), ':action' => serialize($this->action), ':notes' => value_or_default($this->notes, ""), ':date_modified' => time()));
     if (!$ok) {
         throw new Exception($DB->get_last_error());
     }
     webdictionary::save_element_strings('block', $this->id, $this->dictionary, $this->website);
     return true;
 }
Exemplo n.º 7
0
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 . '&amp;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;
}
Exemplo n.º 8
0
 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;
 }
Exemplo n.º 9
0
 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&amp;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, '&hellip;');
                         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;
 }