Example #1
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&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;
 }
Example #2
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, '&hellip;', $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;
}
Example #3
0
function nvweb_search($vars = array())
{
    global $website;
    global $webuser;
    global $DB;
    global $current;
    global $cache;
    global $structure;
    global $theme;
    $out = array();
    $search_what = $_REQUEST[$vars['request']];
    $search_archive = array();
    if (!empty($_REQUEST['archive'])) {
        $search_archive = explode("-", $_REQUEST['archive']);
    }
    // YEAR, MONTH, CATEGORIES (separated by commas)
    if (isset($_REQUEST[$vars['request']]) || !empty($search_archive[0]) && !empty($search_archive[1])) {
        // LOG search request
        $wu_id = 0;
        if (!empty($webuser->id)) {
            $wu_id = $webuser->id;
        }
        $DB->execute('
            INSERT INTO nv_search_log
              (id, website, date, webuser, origin, text)
            VALUES
              (0, :website, :date, :webuser, :origin, :text)
        ', array('website' => $website->id, 'date' => time(), 'webuser' => $wu_id, 'origin' => empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'], 'text' => $search_what));
        // prepare and execute the search
        $search_what = explode(' ', $search_what);
        $search_what = array_filter($search_what);
        if (empty($search_what)) {
            $search_what = array();
        }
        $likes = array();
        $likes[] = ' 1=1 ';
        foreach ($search_what as $what) {
            if (substr($what, 0, 1) == '-') {
                $likes[] = 'd.text NOT LIKE ' . protect('%' . substr($what, 1) . '%') . '    AND i.id IN( 
                                            SELECT p.node_id
                                             FROM   nv_properties_items p 
                                             WHERE  p.element = "item" AND 
                                                    p.website = ' . protect($website->id) . ' AND
                                                    p.value NOT LIKE ' . protect('%' . substr($what, 1) . '%') . '
                                        )';
            } else {
                $likes[] = 'd.text LIKE ' . protect('%' . $what . '%') . '    OR i.id IN( 
			                        SELECT  p.node_id
			                         FROM   nv_properties_items p 
			                         WHERE  p.element = "item" AND 
			                                p.website = ' . protect($website->id) . ' AND
			                                p.value LIKE ' . protect('%' . $what . '%') . '
                                )';
            }
        }
        if (!empty($search_archive)) {
            $start_date = gmmktime(0, 0, 0, $search_archive[1], 1, $search_archive[0]);
            $end_date = gmmktime(0, 0, 0, $search_archive[1] + 1, 1, $search_archive[0]);
            $likes[] = ' (i.date_to_display >= ' . $start_date . ')';
            $likes[] = ' (i.date_to_display <= ' . $end_date . ')';
        }
        if (!empty($search_archive[2])) {
            $vars['categories'] = $search_archive[2];
        }
        $categories = NULL;
        if (isset($vars['categories'])) {
            if ($vars['categories'] == 'all') {
                $categories = array(0);
                $vars['children'] = 'true';
            } else {
                if ($vars['categories'] == 'parent') {
                    $categories = array($current['object']->id);
                    $parent = $DB->query_single('parent', 'nv_structure', 'id = ' . intval($categories[0]));
                    $categories = array($parent);
                } else {
                    if ($vars['categories'] == 'nvlist_parent') {
                        if ($vars['nvlist_parent_type'] === 'structure') {
                            $categories = array($vars['nvlist_parent_item']->id);
                        }
                    } else {
                        if (!is_numeric($vars['categories'])) {
                            // if "categories" attribute has a comma, then we suppose it is a list of comma separated values
                            // if not, then maybe we want to get the categories from a specific property of the current page
                            if (strpos($vars['categories'], ',') === false) {
                                $categories = nvweb_properties(array('property' => $vars['categories']));
                            }
                            if (empty($categories) && @$vars['nvlist_parent_vars']['source'] == 'block_group') {
                                $categories = nvweb_properties(array('mode' => 'block_group_block', 'property' => $vars['categories']));
                            }
                            if (empty($categories)) {
                                $categories = $vars['categories'];
                            }
                            if (!is_array($categories)) {
                                $categories = explode(',', $categories);
                                $categories = array_filter($categories);
                                // remove empty elements
                            }
                        } else {
                            $categories = explode(',', $vars['categories']);
                            $categories = array_filter($categories);
                            // remove empty elements
                        }
                    }
                }
            }
        }
        if ($vars['children'] == 'true') {
            $categories = nvweb_menu_get_children($categories);
        }
        // if we have categories="x" children="true" [to get the children of a category, but not itself]
        if ($vars['children'] == 'only') {
            $children = nvweb_menu_get_children($categories);
            for ($c = 0; $c < count($categories); $c++) {
                array_shift($children);
            }
            $categories = $children;
        }
        if (!empty($vars['children']) && intval($vars['children']) > 0) {
            $children = nvweb_menu_get_children($categories, intval($vars['children']));
            for ($c = 0; $c < count($categories); $c++) {
                array_shift($children);
            }
            $categories = $children;
        }
        // apply a filter on categories, if given
        // example: request_categories="c" ... in the url &q=text&c=23,35
        if (!empty($vars['request_categories'])) {
            $categories_filter = explode(",", $_REQUEST[$vars['request_categories']]);
            if (empty($categories)) {
                // note: categories may be empty by the rules applies on categories + children;
                // in this case we give preference to the request_categories filter
                $categories = array_values($categories_filter);
            } else {
                for ($cf = 0; $cf < count($categories_filter); $cf++) {
                    if (!in_array($categories_filter[$cf], $categories)) {
                        unset($categories_filter[$cf]);
                    }
                    $categories_filter = array_filter($categories_filter);
                }
                $categories = $categories_filter;
            }
        }
        // retrieve entries
        $permission = !empty($_SESSION['APP_USER#' . APP_UNIQUE]) ? 1 : 0;
        $access = !empty($current['webuser']) ? 1 : 2;
        if (empty($_GET['page'])) {
            $_GET['page'] = 1;
        }
        $offset = intval($_GET['page'] - 1) * $vars['items'];
        // get order type: PARAMETER > NV TAG PROPERTY > DEFAULT (priority given in CMS)
        $order = @$_REQUEST['order'];
        if (empty($order)) {
            $order = @$vars['order'];
        }
        if (empty($order)) {
            // default order: latest
            $order = 'latest';
        }
        $orderby = nvweb_list_get_orderby($order);
        if (empty($vars['items']) || $vars['items'] == '0') {
            $vars['items'] = 500;
            //2147483647; // maximum integer
            // NOTE: having >500 items on a page without a paginator is probably a bad idea... disagree? Contact Navigate CMS team!
        } else {
            if (!is_numeric($vars['items'])) {
                $max_items = "";
                // the number of items is defined by a property
                $max_items = nvweb_properties(array('property' => $vars['items']));
                if (empty($max_items) && @$vars['nvlist_parent_vars']['source'] == 'block_group') {
                    $max_items = nvweb_properties(array('mode' => 'block_group_block', 'property' => $vars['items'], 'id' => $vars['nvlist_parent_item']->id, 'uid' => $vars['nvlist_parent_item']->uid));
                }
                if (!empty($max_items)) {
                    $vars['items'] = $max_items;
                } else {
                    $vars['items'] = 500;
                }
                // default maximum
            }
        }
        // TODO: try to optimize search to use less memory and increase the maximum number of items
        $DB->query('
            SELECT SQL_CALC_FOUND_ROWS rs.id
            FROM (
                SELECT  i.id as 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,
                        i.position as position, wd.text as title
                  FROM nv_items i, nv_webdictionary d
                  LEFT JOIN nv_webdictionary wd
                    ON wd.node_id = d.node_id
                   AND wd.lang =  ' . protect($current['lang']) . '
                   AND wd.node_type = "item"
                   AND wd.website = ' . protect($website->id) . '			  
                 WHERE i.website = ' . $website->id . '
                   AND i.permission <= ' . $permission . '
                   AND (i.date_published = 0 OR i.date_published < ' . core_time() . ')
                   AND (i.date_unpublish = 0 OR i.date_unpublish > ' . core_time() . ')
                   AND (i.access = 0 OR i.access = ' . $access . ')
                   AND d.website = ' . protect($website->id) . '
                   AND d.node_id = i.id
                   AND d.lang =  ' . protect($current['lang']) . '
                   AND (d.node_type = "item" OR d.node_type = "tags")
                   AND (
                    ' . implode(' AND ', $likes) . '
                   )
                   ' . (empty($categories) ? '' : 'AND category IN(' . implode(",", $categories) . ')') . '
                 ' . $orderby . '
             ) rs
             GROUP BY rs.id
			 LIMIT ' . $vars['items'] . '
			OFFSET ' . $offset);
        $rs = $DB->result();
        $total = $DB->foundRows();
        for ($i = 0; $i < count($rs); $i++) {
            if (empty($rs[$i]->id)) {
                break;
            }
            $item = new item();
            $item->load($rs[$i]->id);
            // get the nv list template
            $item_html = $vars['template'];
            // now, parse the nvlist_conditional tags (with html source code inside (and other nvlist tags))
            unset($nested_condition_fragments);
            list($item_html, $nested_conditional_fragments) = nvweb_list_isolate_conditionals($item_html);
            $conditional_placeholder_tags = nvweb_tags_extract($item_html, 'nvlist_conditional_placeholder', true, true, 'UTF-8');
            // selfclosing = true
            while (!empty($conditional_placeholder_tags)) {
                $tag = $conditional_placeholder_tags[0];
                $conditional = $nested_conditional_fragments[$tag["attributes"]["id"]];
                $conditional_html_output = nvweb_list_parse_conditional($conditional, $item, $conditional['nvlist_conditional_template'], $i, count($rs));
                $item_html = str_replace($tag["full_tag"], $conditional_html_output, $item_html);
                $conditional_placeholder_tags = nvweb_tags_extract($item_html, 'nvlist_conditional_placeholder', true, true, 'UTF-8');
                // selfclosing = true
            }
            // now parse the (remaining) common nvlist tags
            $template_tags = nvweb_tags_extract($item_html, 'nvlist', true, true, 'UTF-8');
            // selfclosing = true
            if (empty($item_html)) {
                $item_html = array();
                $item_html[] = '<div class="search-result-item">';
                $item_html[] = '	<div class="search-result-title"><a href="' . $website->absolute_path() . $item->paths[$current['lang']] . '">' . $item->dictionary[$current['lang']]['title'] . '</a></div>';
                $item_html[] = '	<div class="search-result-summary">' . core_string_cut($item->dictionary[$current['lang']]['section-main'], 300, '&hellip;') . '</div>';
                $item_html[] = '</div>';
                $item_html = implode("\n", $item_html);
                $out[] = $item_html;
            } else {
                // parse special template tags
                foreach ($template_tags as $tag) {
                    $content = nvweb_list_parse_tag($tag, $item, $vars['source'], $i, $i + $offset, $total);
                    $item_html = str_replace($tag['full_tag'], $content, $item_html);
                }
                $out[] = $item_html;
            }
        }
        if ($total == 0) {
            $search_results_empty_text = $theme->t("no_results_found");
            if (isset($vars['no_results_found'])) {
                $search_results_empty_text = $theme->t($vars["no_results_found"]);
            }
            if (empty($search_results_empty_text) || $search_results_empty_text == 'no_results_found') {
                $search_results_empty_text = t(645, "No results found");
            }
            // display the error message only if
            //  1) it's not empty
            //  2) the template is preventing the display of any error message in the search ( no_results_found="" )
            if (!empty($search_results_empty_text) && (!isset($vars['no_results_found']) || isset($vars['no_results_found']) && !empty($vars['no_results_found']))) {
                $out[] = '<div class="search-results-empty">';
                $out[] = $search_results_empty_text;
                $out[] = '</div>';
            }
        }
        $archive = $_REQUEST['archive'];
        if (!empty($archive)) {
            $archive = 'archive=' . $archive . '&';
        }
        if (isset($vars['paginator']) && $vars['paginator'] != 'false') {
            $search_url = '?' . $archive . $vars['request'] . '=' . $_REQUEST[$vars['request']] . '&page=';
            $out[] = nvweb_list_paginator($vars['paginator'], $_GET['page'], $total, $vars['items'], $vars, $search_url);
        }
    }
    return implode("\n", $out);
}
Example #4
0
function update_list()
{
    global $user;
    global $DB;
    global $website;
    global $layout;
    $navibars = new navibars();
    $naviforms = new naviforms();
    $navibars->title(t(285, 'Update'));
    $navibars->form('', 'fid=update&act=manual_update&debug');
    $navibars->add_tab(t(0, 'Navigate'));
    $updates_available = update::updates_available();
    $current_version = update::latest_installed();
    $latest_available = update::latest_available();
    if (empty($latest_available)) {
        $layout->navigate_notification(t(578, "Sorry, could not connect to check updates"), true);
        $latest_available->Version = $current_version->version;
        $latest_available->Revision = $current_version->revision;
    }
    if ($latest_available->Revision > $current_version->revision) {
        $navibars->add_actions(array('<a href="?fid=update&act=install_next_update&debug"><img height="16" align="absmiddle" width="16" src="img/icons/silk/asterisk_orange.png"> ' . t(289, 'Update Navigate') . ' <img src="img/icons/silk/bullet_go.png" align="absmiddle" /> ' . $updates_available[0]['Version'] . ' r' . $updates_available[0]['Revision'] . '</a>'));
    }
    $current = array();
    $current[] = '<div class="navigate-panels-summary ui-corner-all" style=" width: 234px; height: 118px; ">';
    $current[] = '	<h2><img src="img/navigate-logo-150x70.png" /><br />' . $current_version->version . ' r' . $current_version->revision . '</h2>';
    $current[] = '</div>';
    $navibars->add_tab_content_panel('<img src="img/navigate.png" width="16px" height="16px" align="absmiddle" /> ' . t(290, 'Current version'), $current, 'navigate-panel-current-version', '250px', '184px');
    // update list
    $updates = '';
    $elements_html = '';
    foreach ($updates_available as $update) {
        $update['text'] = base64_decode($update['text']);
        $elements_html .= '<div class="navigate-panel-recent-comments-username ui-corner-all items-comment-status-public">' . '<div class="navigate-panel-update-info" style=" cursor: pointer; " title="' . core_string_cut($update['text'], 200) . '">' . '<div style="display: none;">' . $update['text'] . '</div>' . '<strong>' . $update['Version'] . ' r' . $update['Revision'] . '</strong> <img align="absmiddle" src="img/icons/silk/bullet_green.png" align="absmiddle"> ' . $update['Cause'] . '</div>' . '</div>';
    }
    $layout->add_script('
        $(".navigate-panel-update-info").on("click", function()
        {
            if($(this).children().eq(0).html()!="")
            {
                var html = $(this).children().eq(0).html();
                $("<div>"+html+"</div>").dialog({
                    modal: true,
                    title: $(this).children().eq(1).text(),
                    width: 650,
                    height: 400
                });
            }
        });
    ');
    $navibars->add_tab_content_panel('<img src="img/icons/silk/asterisk_yellow.png" align="absmiddle" /> ' . t(292, 'Available updates'), $elements_html, 'navigate-panel-top-elements', '400px', '184px');
    $latest = array();
    $latest[] = '<div class="navigate-panels-summary ui-corner-all" style=" width: 234px; height: 118px; ">';
    $latest[] = '	<h2><img src="img/navigate-logo-150x70.png" /><br />' . $latest_available->Version . ' r' . $latest_available->Revision . '</h2>';
    $latest[] = '</div>';
    $navibars->add_tab_content_panel('<img src="img/icons/silk/asterisk_orange.png" align="absmiddle" /> ' . t(291, 'Latest version'), $latest, 'navigate-panel-latest-version', '250px', '184px');
    $manual_update = array();
    $manual_update[] = '<div class="navigate-panels-summary ui-corner-all" id="update_manual_dropbox" style=" width: 231px; line-height: 59px; ">';
    $manual_update[] = '	<h2><img src="img/icons/misc/dropbox.png" /></h2>';
    $manual_update[] = '</div>';
    $manual_update[] = '<input type="hidden" id="update_manual_file" name="update_manual_file" value="" />';
    /*
    $manual_update[] = '<div class="navigate-panels-summary ui-corner-all" style=" width: 231px; ">';
    $manual_update[] = '	<input type="file" />';		
    $manual_update[] = '</div>';	
    */
    $manual_update[] = '<div style=" float: right; margin-right: 8px; "><input type="submit" disabled="disabled" class="uibutton" id="update_manual_install" value="' . t(365, 'Install') . '" /></div>';
    $navibars->add_tab_content_panel('<img src="img/icons/silk/disk_upload.png" align="absmiddle" /> ' . t(303, 'Manual update'), $manual_update, 'navigate-panel-manual-update', '250px', '184px');
    $layout->add_script('
        $(".navigate-panel").css({
            "visibility": "visible",
            "float": "left",
            "margin-right": "12px" 
        });
        
        $(".navigate-panels-summary").css({
            "max-width": "239px",
            "width": "100%"
        });

		navigate_file_drop("#update_manual_dropbox", 0, 
			{ 
				afterOne: function(file)
				{
					if(file!=false)
					{
						$("#update_manual_dropbox").removeClass("ui-state-highlight");
						$("#update_manual_dropbox").html("<strong>" + file.name + "</strong>");
						$("#update_manual_file").val(file.id);
						$("#update_manual_install").button("enable");
					}
				},
				dragOver: function()
				{
					$("#update_manual_dropbox").addClass("ui-state-highlight");
				},
				dragLeave: function()
				{
					$("#update_manual_dropbox").removeClass("ui-state-highlight"); 
				}
			}
        );
	');
    return $navibars->generate();
}
Example #5
0
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'], '&hellip;');
                    }
                    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'], '&hellip;');
                    } 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'], '&hellip;');
                    }
                    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'], '&hellip;');
                    }
                    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'] . '&amp;disposition=inline';
                    break;
                case 'thumbnail':
                case 'thumbnail_url':
                    $thumbnail_url = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&amp;disposition=inline&amp;width=' . $tag['attributes']['width'] . '&amp;height=' . $tag['attributes']['height'] . '&amp;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'] . '&amp;disposition=inline">
                                <img src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&amp;disposition=inline&amp;width=' . $tag['attributes']['width'] . '&amp;height=' . $tag['attributes']['height'] . '&amp;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'], '&hellip;', $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'], '&hellip;', $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 . '&amp;disposition=inline&amp;width=' . $tag['attributes']['width'] . '&amp;height=' . $tag['attributes']['height'] . '&amp;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;
}
Example #6
0
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new comment();
    switch ($_REQUEST['act']) {
        case 'json':
        case 1:
            // json data retrieval & operations
            switch ($_REQUEST['oper']) {
                case 'del':
                    // remove rows
                    $ids = $_REQUEST['ids'];
                    foreach ($ids as $id) {
                        $item->load($id);
                        $item->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 .= $item->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']);
                            }
                        }
                    }
                    $DB->queryLimit('id,item,user,email,date_created,status,message', 'nv_comments', $where, $orderby, $offset, $max);
                    $dataset = $DB->result();
                    $total = $DB->foundRows();
                    //echo $DB->get_last_error();
                    $out = array();
                    $permissions = array(-1 => '<img src="img/icons/silk/new.png" align="absmiddle" /> ' . t(257, 'To review'), 0 => '<img src="img/icons/silk/world.png" align="absmiddle" /> ' . t(64, 'Published'), 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" /> ' . t(251, 'Private'), 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" /> ' . t(181, 'Hidden'), 3 => '<img src="img/icons/silk/error.png" align="absmiddle" /> ' . t(466, 'Spam'));
                    for ($i = 0; $i < count($dataset); $i++) {
                        if (empty($dataset[$i])) {
                            continue;
                        }
                        // retrieve webuser name
                        $webuser = $DB->query_single('username', 'nv_webusers', ' id = ' . $dataset[$i]['user']);
                        // retrieve item title
                        $item = new item();
                        $item->load($dataset[$i]['item']);
                        $title = $item->dictionary[$website->languages_list[0]]['title'];
                        $message = core_string_clean($dataset[$i]['message']);
                        $message = core_string_cut($message, 60, '&hellip;');
                        $out[$i] = array(0 => $dataset[$i]['id'], 1 => $title, 2 => core_ts2date($dataset[$i]['date_created'], true), 3 => empty($dataset[$i]['user']) ? $dataset[$i]['email'] : $webuser, 4 => strip_tags($message), 5 => $permissions[$dataset[$i]['status']]);
                    }
                    navitable::jqgridJson($out, $page, $offset, $max, $total);
                    break;
            }
            session_write_close();
            exit;
            break;
        case 2:
            // edit/new form
        // edit/new form
        case 'edit':
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
            }
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    property::save_properties_from_post('comment', $item->id);
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
                if (!empty($item->id)) {
                    users_log::action($_REQUEST['fid'], $item->id, 'save', $item->name, json_encode($_REQUEST));
                }
            } else {
                if (!empty($item->id)) {
                    users_log::action($_REQUEST['fid'], $item->id, 'load', $item->name);
                }
            }
            $out = comments_form($item);
            break;
        case 4:
            // remove
        // remove
        case 'remove':
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($item->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    $out = comments_list();
                    if (!empty($item->id)) {
                        users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->name, json_encode($_REQUEST));
                    }
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = comments_form($item);
                }
            }
            break;
        case 'remove_spam':
            $count = comment::remove_spam();
            $layout->navigate_notification(t(524, 'Items removed successfully') . ': <strong>' . $count . '</strong>', false);
            $out = comments_list();
            users_log::action($_REQUEST['fid'], $website->id, 'remove_spam', "", json_encode($_REQUEST));
            break;
        case 'json_find_webuser':
            // json find webuser by name (for "user" autocomplete)
            $DB->query('SELECT id, username as text
						  FROM nv_webusers
						 WHERE username LIKE ' . protect('%' . $_REQUEST['username'] . '%') . '
				      ORDER BY username ASC
					     LIMIT 30', 'array');
            $rows = $DB->result();
            $total = $DB->foundRows();
            echo json_encode(array('items' => $rows, 'totalCount' => $total));
            core_terminate();
            break;
        case 'json_find_comment':
            // json find comment by text search (for "in reply to" autocomplete)
            $DB->query('SELECT c.id, c.date_created, c.name, u.username, c.message
						  FROM nv_comments c
						  LEFT JOIN nv_webusers u ON c.user = u.id
						 WHERE
						    c.website = ' . $website->id . ' AND
						    c.item = ' . $_REQUEST['node_id'] . ' AND
						    c.date_created <= ' . $_REQUEST['maxdate'] . ' AND
						    c.id <> ' . $_REQUEST['exclude'] . ' AND						     
						    (   c.name LIKE ' . protect('%' . $_REQUEST['search'] . '%') . ' OR
						        c.message LIKE ' . protect('%' . $_REQUEST['search'] . '%') . ' OR
						        u.username LIKE ' . protect('%' . $_REQUEST['search'] . '%') . '
                            )                          
				      ORDER BY c.date_created DESC
					     LIMIT 30', 'array');
            $rows = $DB->result();
            $total = $DB->foundRows();
            for ($r = 0; $r < count($rows); $r++) {
                $rows[$r]['text'] = '<span title="' . core_string_cut($rows[$r]['message'], 100) . '"><i class="fa fa-user"></i> ' . $rows[$r]['name'] . $rows[$r]['username'] . ' <i class="fa fa-clock-o"></i> ' . core_ts2date($rows[$r]['date_created'], true) . '</span>';
            }
            echo json_encode(array('items' => $rows, 'totalCount' => $total));
            core_terminate();
            break;
        case 91:
            // json search title request (for "item" autocomplete)
            $DB->query('SELECT DISTINCT node_id as id, text as label, text as value
						  FROM nv_webdictionary
						 WHERE node_type = "item"
						   AND subtype = "title"
						   AND website = ' . $website->id . ' 
						   AND text LIKE ' . protect('%' . $_REQUEST['title'] . '%') . '
				      ORDER BY text ASC
					     LIMIT 30', 'array');
            // AND lang = '.protect($_REQUEST['lang']).'
            echo json_encode($DB->result());
            session_write_close();
            exit;
            break;
        case 0:
            // list / search result
        // list / search result
        default:
            $out = comments_list();
            break;
    }
    return $out;
}
Example #7
0
function run()
{
    global $user;
    switch (@$_REQUEST['act']) {
        case 'json':
            switch ($_REQUEST['oper']) {
                case 'settings_panels':
                    // save dashboard panels state
                    $dashboard_panels = $_REQUEST['dashboard_panels'];
                    $user->setting('dashboard-panels', json_encode($dashboard_panels));
                    echo json_encode(true);
                    core_terminate();
                    break;
                case 'feed':
                    $feed = new feed_parser();
                    $feed->set_cache(4 * 3600);
                    // once update each 4 hours
                    $feed->load($_REQUEST['url']);
                    list($channel, $articles, $count) = $feed->parse(0, $_REQUEST['limit'], 'newest');
                    $items = item::convert_from_rss($articles);
                    $display_language = $_REQUEST['language'];
                    if (!empty($items)) {
                        $feed_html = '';
                        for ($c = 0; $c < count($items); $c++) {
                            if (empty($items[$c])) {
                                break;
                            }
                            if (!isset($items[$c]->dictionary[$display_language])) {
                                // requested language not available, get the first available in the feed
                                $feed_languages = array_keys($items[$c]->dictionary);
                                $display_language = $feed_languages[0];
                            }
                            $tmp = array('<div class="navigate-panel-body-title ui-corner-all">' . '<a href="' . $items[$c]->paths[$display_language] . '" target="_blank">' . core_ts2date($items[$c]->date_to_display, true) . ' ' . '<strong>' . $items[$c]->dictionary[$display_language]['title'] . '</strong>' . '</a>' . '</div>', '<div id="navigatecms-feed-item-' . $items[$c]->id . '" class="navigate-panel-recent-feed-element">' . $items[$c]->dictionary[$display_language]['section-main'] . '</div>');
                            $feed_html .= implode("\n", $tmp);
                        }
                    }
                    echo $feed_html;
                    core_terminate();
                    break;
                default:
                    // list or search
            }
            break;
        case 'recent_items':
            $ri = users_log::recent_items(value_or_default($_REQUEST['limit']), 10);
            if (!is_array($ri)) {
                $ri = array();
            }
            for ($i = 0; $i < count($ri); $i++) {
                $action = $ri[$i];
                $ri[$i]->_url = '?fid=' . $action->function . '&wid=' . $action->website . '&act=load&id=' . $action->item;
                $ri[$i]->_link = '<a href="' . $ri[$i]->_url . '" title="' . htmlspecialchars($action->item_title) . ' | ' . htmlspecialchars(t($action->function_title, $action->function_title)) . '"><img src="' . $action->function_icon . '" align="absmiddle" /> ' . core_string_cut($action->item_title, 33) . '</a>';
            }
            echo json_encode($ri);
            core_terminate();
            break;
        default:
            $out = dashboard_create();
    }
    return $out;
}