public static function save_element_strings($node_type, $node_id, $dictionary, $autosave = false, $website_id = null) { global $DB; global $website; if (empty($website_id)) { $website_id = $website->id; } $changed = false; if (empty($node_id)) { throw new Exception('ERROR webdictionary: No ID!'); } if (!is_array($dictionary)) { $dictionary = array(); } foreach ($dictionary as $lang => $item) { foreach ($item as $subtype => $litem) { if (strpos($subtype, 'section-') === 0) { if ($litem == '<p><br _mce_bogus="1"></p>') { continue; } // tinymce empty contents, no need to save it // has the text been changed since last save? $last_litem = $DB->query_single('`text`', 'nv_webdictionary_history', ' node_id = ' . protect($node_id) . ' AND website = ' . protect($website_id) . ' AND lang = ' . protect($lang) . ' AND subtype = ' . protect($subtype) . ' AND node_type = ' . protect($node_type) . ' AND autosave = ' . protect($autosave ? '1' : '0') . ' ORDER BY date_created DESC '); if ($last_litem != $litem) { $changed = true; // autocleaning if ($autosave) { // remove previous autosaved elements $DB->execute(' DELETE FROM nv_webdictionary_history WHERE node_id = ' . protect($node_id) . ' AND website = ' . protect($website_id) . ' AND lang = ' . protect($lang) . ' AND subtype = ' . protect($subtype) . ' AND node_type = ' . protect($node_type) . ' AND autosave = 1 AND date_created < ' . (core_time() - 86400 * 7)); } $DB->execute(' INSERT INTO nv_webdictionary_history (id, website, node_type, node_id, subtype, lang, `text`, date_created, autosave) VALUES ( 0, :website, :node_type, :node_id, :subtype, :lang, :text, :date_created, :autosave) ', array(":website" => $website_id, ":node_type" => $node_type, ":node_id" => $node_id, ":subtype" => $subtype, ":lang" => $lang, ":text" => $litem, ":date_created" => core_time(), ":autosave" => $autosave ? '1' : '0')); } } } } return $changed; }
public static function recent_actions($function, $action, $limit = 8) { global $DB; global $user; global $website; // last month only! $DB->query(' SELECT DISTINCT nvul.website, nvul.function, nvul.item, nvul.date FROM nv_users_log nvul WHERE nvul.user = '******' AND nvul.function = ' . protect($function) . ' AND nvul.item > 0 AND nvul.action = ' . protect($action) . ' AND nvul.website = ' . protect($website->id) . ' AND nvul.date > ' . (core_time() - 30 * 86400) . ' AND nvul.date = ( SELECT MAX(nvulm.date) FROM nv_users_log nvulm WHERE nvulm.function = nvul.function AND nvulm.item = nvul.item AND nvulm.item_title = nvul.item_title AND nvulm.website = ' . protect($website->id) . ' AND nvulm.user = '******' ) ORDER BY nvul.date DESC LIMIT ' . $limit); $rows = $DB->result(); return $rows; }
public static function register_upload($tmp_name, $target_name, $parent, $mime = NULL, $move_uploaded_file = false) { global $website; global $user; global $DB; $file = NULL; if ($move_uploaded_file) { $uploaded_file_temp = uniqid('upload-'); move_uploaded_file($tmp_name, NAVIGATE_PRIVATE . '/' . $website->id . '/files/' . $uploaded_file_temp); $tmp_name = $uploaded_file_temp; } if (strpos($tmp_name, '/') === 0) { $tmp_file_path = $tmp_name; } else { $tmp_file_path = NAVIGATE_PRIVATE . '/' . $website->id . '/files/' . $tmp_name; } if (file_exists($tmp_file_path)) { if (empty($mime)) { $mime = file::getMime($target_name, $tmp_file_path); } $target_name = rawurldecode($target_name); // check if the parent folder given is valid in the current website if ($parent > 0) { $DB->query('SELECT id FROM nv_files WHERE website = ' . $website->id . ' AND id = ' . $parent); $rs = $DB->result('id'); if (empty($rs) || $rs[0] != $parent) { // parent folder invalid, put file in the root folder $parent = 0; } } $file = new file(); $file->id = 0; $file->website = $website->id; $file->mime = $mime[0]; $file->type = $mime[1]; $file->parent = intval($parent); $file->name = $target_name; $file->size = filesize($tmp_file_path); if ($file->type == 'image') { $dimensions = file::image_dimensions($tmp_file_path); $file->width = $dimensions['width']; $file->height = $dimensions['height']; } $file->date_added = core_time(); $file->uploaded_by = empty($user->id) ? '0' : $user->id; $file->permission = 0; $file->enabled = 1; $file->save(); rename($tmp_file_path, NAVIGATE_PRIVATE . '/' . $website->id . '/files/' . $file->id); if ($file->type == 'image') { $file->resize_uploaded_image(); } } return $file; }
function nvweb_sitemap($vars = array()) { global $website; global $DB; global $current; global $cache; global $structure; $out = array(); switch ($vars['mode']) { case 'xml': header('Content-Type: text/xml'); $out[] = '<?xml version="1.0" encoding="UTF-8"?>'; $out[] = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; // HOMEPAGE $out[] = ' <url>'; $out[] = ' <loc>' . NVWEB_ABSOLUTE . $website->homepage() . '</loc>'; $out[] = ' <lastmod>' . date(DATE_W3C, time()) . '</lastmod>'; $out[] = ' <changefreq>daily</changefreq>'; $out[] = ' <priority>1</priority>'; $out[] = ' </url>'; // STRUCTURE paths $DB->query(' SELECT p.object_id, p.lang, p.path, s.position FROM nv_paths p, nv_structure s WHERE p.type = "structure" AND p.website = ' . $website->id . ' AND s.website = ' . $website->id . ' AND s.id = p.object_id AND s.permission = 0 AND (s.date_published = 0 OR s.date_published < ' . core_time() . ') AND (s.date_unpublish = 0 OR s.date_unpublish > ' . core_time() . ') ORDER BY s.position ASC '); $data = $DB->result(); $structure_paths = array(); if (is_array($data)) { foreach ($data as $item) { $structure_paths[$item->position . '-' . $item->object_id . '-' . $item->lang] = $item->path; } } foreach ($structure_paths as $key => $value) { if (strpos($value, 'http') === false) { $value = NVWEB_ABSOLUTE . $value; } $out[] = ' <url>'; $out[] = ' <loc>' . $value . '</loc>'; $out[] = ' <lastmod>' . date(DATE_W3C, time()) . '</lastmod>'; $out[] = ' <changefreq>weekly</changefreq>'; $out[] = ' <priority>0.75</priority>'; $out[] = ' </url>'; } // ITEM paths $DB->query(' SELECT p.object_id, p.lang, p.path, i.date_modified FROM nv_paths p, nv_items i WHERE p.type = "item" AND p.website = ' . $website->id . ' AND i.website = ' . $website->id . ' AND i.id = p.object_id AND i.permission = 0 AND (i.association = "free" OR (i.association = "category" AND i.embedding=0)) AND (i.date_published = 0 OR i.date_published < ' . core_time() . ') AND (i.date_unpublish = 0 OR i.date_unpublish > ' . core_time() . ') ORDER BY i.position ASC '); $data = $DB->result(); $item_paths = array(); if (is_array($data)) { foreach ($data as $item) { $item_paths[$item->position . '-' . $item->object_id . '-' . $item->lang] = array($item->path, $item->date_modified); } } foreach ($item_paths as $key => $value) { $out[] = ' <url>'; $out[] = ' <loc>' . NVWEB_ABSOLUTE . $value[0] . '</loc>'; $out[] = ' <lastmod>' . date(DATE_W3C, $value[1]) . '</lastmod>'; $out[] = ' <changefreq>monthly</changefreq>'; $out[] = ' <priority>0.5</priority>'; $out[] = ' </url>'; } // TODO: call an extension event to add more paths generated by plugins (answers, etc.) $out[] = '</urlset>'; break; } return implode("\n", $out); }
function nvweb_content_items($categories = array(), $only_published = false, $max = NULL, $embedding = true, $order = 'date') { global $website; global $DB; global $current; global $webuser; if (!is_array($categories)) { $categories = array(intval($categories)); } $where = ' i.website = ' . $website->id . ' AND i.category IN (' . implode(",", $categories) . ') AND i.embedding = ' . ($embedding ? '1' : '0'); if ($only_published) { $where .= ' AND (i.date_published = 0 OR i.date_published < ' . core_time() . ') AND (i.date_unpublish = 0 OR i.date_unpublish > ' . core_time() . ')'; } // status (0 public, 1 private (navigate cms users), 2 hidden) $permission = !empty($_SESSION['APP_USER#' . APP_UNIQUE]) ? 1 : 0; $where .= ' AND i.permission <= ' . $permission; // access permission (0 public, 1 web users only, 2 unidentified users, 3 selected web user groups) $access = 2; $access_extra = ''; if (!empty($current['webuser'])) { $access = 1; if (!empty($webuser->groups)) { $access_groups = array(); foreach ($webuser->groups as $wg) { if (empty($wg)) { continue; } $access_groups[] = 'i.groups LIKE "%g' . $wg . '%"'; } if (!empty($access_groups)) { $access_extra = ' OR (i.access = 3 AND (' . implode(' OR ', $access_groups) . '))'; } } } $where .= ' AND (i.access = 0 OR i.access = ' . $access . $access_extra . ')'; if (!empty($max)) { $limit = 'LIMIT ' . $max; } $orderby = nvweb_list_get_orderby($order); $orderby = str_replace(", IFNULL(s.position,0) ASC", "", $orderby); // remove s. order used exclusively at nvweb_list $DB->query(' SELECT i.*, COALESCE(NULLIF(i.date_to_display, 0), i.date_created) as pdate, d.text as title FROM nv_items i LEFT JOIN nv_webdictionary d ON 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']) . ' WHERE ' . $where . ' ' . $orderby . ' ' . $limit); $rs = $DB->result(); return $rs; }
function nvweb_conditional($vars = array()) { global $website; global $DB; global $current; global $cache; global $structure; global $webgets; global $webuser; $out = array(); $webget = 'conditional'; $categories = array(); $item = new item(); if ($current['type'] == 'item') { $item->load($current['object']->id); $item_type = 'element'; } else { $item_type = 'structure'; if (isset($vars['scope']) && $vars['scope'] == 'element') { // the current path belongs to a structure category, but the template is asking for an element value, // so we try to find the first element assigned to the current category $categories = array(); if (!empty($current['object']->id)) { $categories = array($current['object']->id); } if (isset($vars['categories'])) { $categories = explode(',', $vars['categories']); $categories = array_filter($categories); // remove empty elements } $permission = !empty($_SESSION['APP_USER#' . APP_UNIQUE]) ? 1 : 0; // public access / webuser based / webuser groups based $access = 2; $access_extra = ''; if (!empty($current['webuser'])) { $access = 1; if (!empty($webuser->groups)) { $access_groups = array(); foreach ($webuser->groups as $wg) { if (empty($wg)) { continue; } $access_groups[] = 's.groups LIKE "%g' . $wg . '%"'; } if (!empty($access_groups)) { $access_extra = ' OR (s.access = 3 AND (' . implode(' OR ', $access_groups) . '))'; } } } // get order type: PARAMETER > NV TAG PROPERTY > DEFAULT (priority given in CMS) $order = @$_REQUEST['order']; if (empty($order)) { $order = @$vars['order']; } if (empty($order)) { // default order: latest $order = 'latest'; } $orderby = nvweb_list_get_orderby($order); $rs = NULL; $access_extra_items = str_replace('s.', 'i.', $access_extra); if (empty($categories)) { // force executing the query; search in all categories $categories = nvweb_menu_get_children(array(0)); } // default source for retrieving items $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 FROM nv_items i, nv_structure s, nv_webdictionary d WHERE i.category IN(' . implode(",", $categories) . ') AND i.website = ' . $website->id . ' AND i.permission <= ' . $permission . ' AND (i.date_published = 0 OR i.date_published < ' . core_time() . ') AND (i.date_unpublish = 0 OR i.date_unpublish > ' . core_time() . ') AND s.id = i.category AND (s.date_published = 0 OR s.date_published < ' . core_time() . ') AND (s.date_unpublish = 0 OR s.date_unpublish > ' . core_time() . ') AND s.permission <= ' . $permission . ' AND (s.access = 0 OR s.access = ' . $access . $access_extra . ') AND (i.access = 0 OR i.access = ' . $access . $access_extra_items . ') AND d.website = i.website AND d.node_type = "item" AND d.subtype = "title" AND d.node_id = i.id AND d.lang = ' . protect($current['lang']) . ' ' . $orderby . ' LIMIT 1 OFFSET 0'); $rs = $DB->result(); // now we have the element against which the condition will be checked $i = 0; $item->load($rs[$i]->id); $item_type = 'element'; } else { if (!isset($vars['scope']) || $vars['scope'] == 'structure') { $item = $current['object']; $item_type = 'structure'; } } } // get the template $item_html = $vars['_template']; // now, parse the conditional tags (with html source code inside) switch ($vars['by']) { case 'property': $property_value = NULL; $property_name = $vars['property_name']; if (empty($vars['property_name'])) { $property_name = $vars['property_id']; } if ($vars['property_scope'] == "element") { $property_value = $item->property($property_name); } else { if ($vars['property_scope'] == "structure") { $property = nvweb_properties(array('mode' => 'structure', 'property' => $property_name, 'return' => 'object')); if (!empty($property)) { $property_value = $property->value; } } else { if ($vars['property_scope'] == "website") { $property_value = $website->theme_options->{$property_name}; } else { // no scope defined, so we have to check ELEMENT > STRUCTURE > WEBSITE (the first with a property with the given name) // element $property_value = $item->property($property_name); if (!$item->property_exists($property_name) && $item_type == 'structure') { // get the first embedded element and check find the property $ci = nvweb_content_items(array($item->id), true, 1, true, 'priority'); $item = new item(); if (isset($ci[0])) { $item->load($ci[0]->id); $property_value = $item->property($property_name); } } if (!$item->property_exists($property_name)) { // structure $property = nvweb_properties(array('mode' => 'structure', 'property' => $property_name, 'return' => 'object')); if (!empty($property)) { $property_value = $property->value; } else { // website if (isset($website->theme_options->{$property_name})) { $property_value = $website->theme_options->{$property_name}; } else { $property_value = ''; } } } } } } // if the property is multilanguage, get the value for the current language if (is_array($property_value)) { $property_value = $property_value[$current['lang']]; } // check the given condition if (isset($vars['empty']) || isset($vars['property_empty'])) { if (@$vars['empty'] == 'true' || @$vars['property_empty'] == 'true') { if (empty($property_value)) { $out = $item_html; } else { $out = ''; } } else { if (@$vars['empty'] == 'false' || @$vars['property_empty'] == 'false') { if (!empty($property_value)) { $out = $item_html; } else { $out = ''; } } } } else { if (isset($vars['property_value'])) { $condition_value = $vars['property_value']; switch ($vars['property_compare']) { case '>': case 'gt': $condition = $property_value > $condition_value; break; case '<': case 'lt': $condition = $property_value < $condition_value; break; case '>=': case '=>': case 'gte': $condition = $property_value >= $condition_value; break; case '<=': case '=<': case 'lte': $condition = $property_value <= $condition_value; break; case 'in': $condition_values = explode(",", $condition_value); $condition = in_array($property_value, $condition_values); break; case 'nin': $condition_values = explode(",", $condition_value); $condition = !in_array($property_value, $condition_values); break; case '!=': case 'neq': if (is_numeric($property_value)) { if ($condition_value == 'true' || $condition_value === true) { $condition_value = '1'; } else { if ($condition_value == 'false' || $condition_value === false) { $condition_value = '0'; } } } $condition = $property_value != $condition_value; break; case '=': case '==': case 'eq': default: if (is_numeric($property_value)) { if ($condition_value == 'true' || $condition_value === true) { $condition_value = '1'; } else { if ($condition_value == 'false' || $condition_value === false) { $condition_value = '0'; } } } $condition = $property_value == $condition_value; break; } if ($condition) { $out = $item_html; } else { $out = ''; } } } break; case 'template': case 'templates': $templates = array(); if (isset($vars['templates'])) { $templates = explode(",", $vars['templates']); } else { if (isset($vars['template'])) { $templates = array($vars['template']); } } if (in_array($item->template, $templates)) { $out = $item_html; } else { $out = ''; } break; case 'section': $section_empty = empty($item->dictionary[$current['lang']]['section-' . $vars['section']]); if ($vars['empty'] == 'true' && $section_empty || $vars['empty'] == 'false' && !$section_empty) { $out = $item_html; } else { $out = ''; } break; case 'access': $access = 0; switch ($vars['access']) { case 3: case 'webuser_groups': $access = 3; break; case 2: case 'not_signed_in': $access = 2; break; case 1: case 'signed_in': $access = 1; break; case 0: case 'everyone': default: $access = 0; break; } if ($item->access == $access) { $out = $item_html; } else { $out = ''; } break; case 'webuser': if ($vars['signed_in'] == 'true' && !empty($webuser->id)) { $out = $item_html; } else { if ($vars['signed_in'] == 'false' && empty($webuser->id)) { $out = $item_html; } else { $out = ''; } } break; case 'languages': if (count($website->languages_published) >= $vars['min']) { $out = $item_html; } else { if (count($website->languages_published) <= $vars['max']) { $out = $item_html; } } break; case 'language': if ($current['lang'] == $vars['lang']) { $out = $item_html; } break; case 'gallery': if ($vars['empty'] == 'true') { if (empty($item->galleries[0])) { $out = $item_html; } } else { if ($vars['empty'] == 'false') { if (!empty($item->galleries[0])) { $out = $item_html; } } else { if (isset($vars['min']) && count($item->galleries[0]) >= intval($vars['min'])) { $out = $item_html; } else { if (isset($vars['max']) && count($item->galleries[0]) <= intval($vars['max'])) { $out = $item_html; } } } } break; case 'tags': if ($vars['empty'] == 'true') { if (empty($item->dictionary[$current['lang']]['tags'])) { $out = $item_html; } } else { if ($vars['empty'] == 'false') { if (!empty($item->dictionary[$current['lang']]['tags'])) { $out = $item_html; } } } break; case 'comments': $DB->query(' SELECT COUNT(*) as total FROM nv_comments WHERE website = ' . protect($website->id) . ' AND item = ' . protect($item->id) . ' AND status = 0 '); $rs = $DB->result(); $comments_count = $rs[0]->total + 0; if (isset($vars['allowed'])) { if ($vars['allowed'] == 'true' || $vars['allowed'] == '1' || empty($vars['allowed'])) { // comments allowed to everybody (2) or to registered users only (1) if ($item->comments_enabled_to == 2 || $item->comments_enabled_to == 1 && !empty($webuser->id)) { $out = $item_html; } } else { if ($vars['allowed'] == 'false') { // comments not allowed for anyone or for webusers but there is no webuser active right now if ($item->comments_enabled_to == 0 || $item->comments_enabled_to == 1 && empty($webuser->id)) { $out = $item_html; } } } } else { if (isset($vars['min']) && $comments_count >= intval($vars['min'])) { $out = $item_html; } else { if (isset($vars['max']) && $comments_count <= intval($vars['max'])) { $out = $item_html; } } } break; default: // unknown nvlist_conditional, discard $out = ''; } // return the new html code after applying the condition return $out; }
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, '…') . '</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); }
function nvweb_source_url($type, $id, $lang = '') { global $DB; global $website; global $current; global $theme; if (empty($lang)) { $lang = $current['lang']; } if ($type == 'theme') { // find the first PUBLIC & PUBLISHED article / element / structure category // that is using the template type given in $id $template_type = $id; $id = ''; //TODO: a) search products if (empty($id)) { // $DB->query_single('id', 'nv_products') if (!empty($id)) { $type = 'product'; } } // b) search items if (empty($id)) { $id = $DB->query_single('id', 'nv_items', 'website = ' . protect($website->id) . ' AND template = ' . protect($template_type) . ' AND permission = 0 AND access = 0 AND (date_published = 0 OR date_published < ' . core_time() . ') AND (date_unpublish = 0 OR date_unpublish > ' . core_time() . ')'); if (!empty($id)) { $type = 'item'; } } // c) search structure elements if (empty($id)) { $id = $DB->query_single('id', 'nv_structure', 'website = ' . protect($website->id) . ' AND template = ' . protect($template_type) . ' AND permission = 0 AND access = 0 AND (date_published = 0 OR date_published < ' . core_time() . ') AND (date_unpublish = 0 OR date_unpublish > ' . core_time() . ')'); if (!empty($id)) { $type = 'structure'; } } if (empty($id)) { return ""; } } if ($type == 'element') { $type = 'item'; } $url = $DB->query_single('path', 'nv_paths', ' type = ' . protect($type) . ' AND object_id = ' . protect($id) . ' AND lang = ' . protect($lang) . ' AND website = ' . $website->id); if (empty($url)) { if ($type == 'item') { $url = '/node/' . $id; } } $url = nvweb_prepare_link($url); return $url; }
function nvweb_list_parse_conditional($tag, $item, $item_html, $position, $total) { global $current; $out = ''; if ($tag['attributes']['by'] == 'property') { if (empty($item)) { return ''; } // can't parse values of empty objects $property_name = $tag['attributes']['property_id']; if (empty($property_name)) { $property_name = $tag['attributes']['property_name']; } if (!method_exists($item, 'property')) { return ""; } $property_value = $item->property($property_name); $property_definition = $item->property_definition($property_name); $condition_value = $tag['attributes']['property_value']; if (in_array($property_definition->type, array('image', "file"))) { if ($property_value == '0') { $property_value = ""; } } // process special comparing values switch ($property_definition->type) { case 'date': if ($condition_value == 'today') { $now = getdate(core_time()); $condition_value = mktime(0, 0, 0, $now['mon'], $now['mday'], $now['year']); } else { if ($condition_value == 'now') { $condition_value = core_time(); } } break; case 'boolean': if ($property_value == "" && isset($property_definition->dvalue)) { $property_value = $property_definition->dvalue; } break; } $condition = false; if (isset($tag['attributes']['property_empty'])) { // special case: for multilanguage properties check the active language if ($property_definition->type == 'text' && is_array($property_value)) { $property_value = $property_value[$current['lang']]; } if ($tag['attributes']['property_empty'] == 'true' && empty($property_value) || $tag['attributes']['property_empty'] == 'false' && !empty($property_value)) { $condition = true; } } else { switch ($tag['attributes']['property_compare']) { case '>': case 'gt': $condition = $property_value > $condition_value; break; case '<': case 'lt': $condition = $property_value < $condition_value; break; case '>=': case '=>': case 'gte': $condition = $property_value >= $condition_value; break; case '<=': case '=<': case 'lte': $condition = $property_value <= $condition_value; break; case 'in': $condition_values = explode(",", $condition_value); $condition = in_array($property_value, $condition_values); break; case 'nin': $condition_values = explode(",", $condition_value); $condition = !in_array($property_value, $condition_values); break; case '!=': case 'neq': if (is_numeric($property_value)) { if ($condition_value == 'true' || $condition_value === true) { $condition_value = '1'; } else { if ($condition_value == 'false' || $condition_value === false) { $condition_value = '0'; } } } $condition = $property_value != $condition_value; break; case '=': case '==': case 'eq': default: if (is_numeric($property_value)) { if ($condition_value == 'true' || $condition_value === true) { $condition_value = '1'; } else { if ($condition_value == 'false' || $condition_value === false) { $condition_value = '0'; } } } $condition = $property_value == $condition_value; break; } } if ($condition) { // parse the contents of this condition on this round $out = $item_html; } else { // remove this conditional html code on this round $out = ''; } } else { if ($tag['attributes']['by'] == 'template' || $tag['attributes']['by'] == 'templates') { if (empty($item)) { return ''; } // can't parse values of empty objects $templates = array(); if (isset($tag['attributes']['templates'])) { $templates = explode(",", $tag['attributes']['templates']); } else { if (isset($tag['attributes']['template'])) { $templates = array($tag['attributes']['template']); } } if (empty($item->template)) { // check if the item is embedded in a category, so we have to get the template from the category, not the item if (get_class($item) == 'item' && $item->association == 'category' && $item->embedding == 1) { // assign template from its category $item_category = new structure(); $item_category->load($item->category); $item->template = $item_category->template; } } if (in_array($item->template, $templates)) { // the template matches the condition, apply $out = $item_html; } else { // remove this conditional html code on this round $out = ''; } } else { if ($tag['attributes']['by'] == 'position') { if (empty($item)) { return ''; } // can't parse values of empty objects if (isset($tag['attributes']['each'])) { if ($position % $tag['attributes']['each'] == 0) { // condition applies $out = $item_html; } else { // remove the full nvlist_conditional tag, doesn't apply here $out = ''; } } else { if (isset($tag['attributes']['range'])) { list($pos_min, $pos_max) = explode('-', $tag['attributes']['range']); if ($position + 1 >= $pos_min && $position + 1 <= $pos_max) { $out = $item_html; } else { $out = ''; } } else { if (isset($tag['attributes']['position'])) { switch ($tag['attributes']['position']) { case 'first': if ($position == 0) { $out = $item_html; } else { $out = ''; } break; case 'not_first': if ($position > 0) { $out = $item_html; } else { $out = ''; } break; case 'last': if ($position == $total - 1) { $out = $item_html; } else { $out = ''; } break; case 'not_last': if ($position != $total - 1) { $out = $item_html; } else { $out = ''; } break; default: // position "x"? if ($tag['attributes']['position'] === '0') { $tag['attributes']['position'] = 1; } if ($position + 1 == $tag['attributes']['position']) { $out = $item_html; } else { $out = ''; } break; } } } } } else { if ($tag['attributes']['by'] == 'block') { if (empty($item)) { return ''; } // can't parse values of empty objects // $item may be a block object or a block group block type if (isset($tag['attributes']['type'])) { if ($tag['attributes']['type'] == $item->type || $tag['attributes']['type'] == $item->id) { $out = $item_html; } else { // no match, discard this conditional $out = ''; } } // does the block have a link defined? if (isset($tag['attributes']['linked'])) { $block_has_link = in_array($item->action['action-type'][$current['lang']], array("web", "web-n", "file", "image", "javascript")); if ($tag['attributes']['linked'] == "true" && $block_has_link) { $out = $item_html; } else { if ($tag['attributes']['linked'] == "false" && !$block_has_link) { $out = $item_html; } else { // no match, discard this conditional $out = ''; } } } } else { if ($tag['attributes']['by'] == 'block_type') { if (empty($item)) { return ''; } // can't parse values of empty objects // $item is a block type defined in a block group (to add a title before listing blocks of that kind) if (isset($tag['attributes']['type']) && $item->_object_type == "block_group_block_type") { if ($tag['attributes']['type'] == $item->type || $tag['attributes']['type'] == $item->id) { $out = $item_html; } else { // no match, discard this conditional $out = ''; } } else { $out = ''; } } else { if ($tag['attributes']['by'] == 'access') { if (empty($item)) { return ''; } // can't parse values of empty objects $access = 0; switch ($tag['attributes']['access']) { case 3: case 'webuser_groups': $access = 3; break; case 2: case 'not_signed_in': $access = 2; break; case 1: case 'signed_in': $access = 1; break; case 0: case 'everyone': default: $access = 0; break; } if ($item->access == $access) { $out = $item_html; } else { $out = ''; } } else { if ($tag['attributes']['by'] == 'gallery') { if (empty($item)) { return ''; } // can't parse values of empty objects if ($tag['attributes']['empty'] == 'true') { if (empty($item->galleries[0])) { $out = $item_html; } } else { if ($tag['attributes']['empty'] == 'false') { if (!empty($item->galleries[0])) { $out = $item_html; } } } } else { if ($tag['attributes']['by'] == 'tags') { if (empty($item)) { return ''; } // can't parse values of empty objects if ($tag['attributes']['empty'] == 'true') { if (empty($item->dictionary[$current['lang']]['tags'])) { $out = $item_html; } } else { if ($tag['attributes']['empty'] == 'false') { if (!empty($item->dictionary[$current['lang']]['tags'])) { $out = $item_html; } } } } else { if ($tag['attributes']['by'] == 'structure') { if (empty($item)) { return ''; } // can't parse values of empty objects if (isset($tag['attributes']['show_in_menus']) && isset($item->visible)) { if ($item->visible == 1 && in_array($tag['attributes']['show_in_menus'], array(1, true, "true"))) { $out = $item_html; } else { if ($item->visible != 1 && !in_array($tag['attributes']['show_in_menus'], array(1, true, "true"))) { $out = $item_html; } else { $out = ""; } } } else { // no match, discard this conditional $out = ''; } } else { if ($tag['attributes']['by'] == 'count') { // check the number of results found // note: this is called also WHEN resultset is empty if ($tag['attributes']['value'] == $total || $tag['attributes']['value'] == "empty" && $total == 0) { $out = $item_html; } else { $out = ''; } } else { $out = ''; } } } } } } } } } } return $out; }
$webuser->load($session['webuser']); } else { if (!empty($_COOKIE["webuser"])) { $webuser->load_by_hash($_COOKIE['webuser']); } } // if the webuser was removed, it doesn't exist anymore, // $session/$_COOKIE may have obsolete data, force a log out // also check date range access if (empty($webuser->id) && (!empty($session['webuser']) || !empty($_COOKIE['webuser'])) || !$webuser->access_allowed()) { $webuser->unset_cookie(); unset($webuser); $webuser = new webuser(); } if (!empty($webuser->id)) { $webuser->lastseen = core_time(); $webuser->save(false); // don't trigger the webuser_modified event } // check if the webuser wants to sign out if (isset($_REQUEST['webuser_signout'])) { $webuser->unset_cookie(); unset($webuser); $webuser = new webuser(); } $current['webuser'] = $session['webuser']; setlocale(LC_ALL, $website->languages[$session['lang']]['system_locale']); date_default_timezone_set($webuser->timezone ? $webuser->timezone : $website->default_timezone); // help developers to find problems if ($current['navigate_session'] == 1 && APP_DEBUG) { error_reporting(E_ALL ^ E_NOTICE);
public static function update_object_votes($webuser, $object, $object_id, $value, $replace = false) { global $DB; global $website; global $events; $status = false; $voted = false; $webuser_vote_id = null; // user has voted in the past? if ($DB->query(' SELECT * FROM nv_webuser_votes WHERE webuser = '******' AND object = ' . protect($object) . ' AND object_id = ' . protect($object_id))) { $data = $DB->result(); $data = $data[0]; $voted = $data->webuser == $webuser; $webuser_vote_id = $data->id; } if ($voted && $replace) { $ok = $DB->execute(' UPDATE nv_webuser_votes SET `value` = ' . protect($value) . ', date = ' . protect(core_time()) . ' WHERE id = ' . $webuser_vote_id); if (!$ok) { throw new Exception($DB->get_last_error()); } else { $status = true; } } else { if ($voted) { $status = 'already_voted'; } else { $wv = new webuser_vote(); $wv->website = $website->id; $wv->webuser = $webuser; $wv->object = $object; $wv->object_id = $object_id; $wv->value = $value; $wv->insert(); $webuser_vote_id = $wv->id; $status = true; } } // now update the object score if ($status === true) { webuser_vote::update_object_score($object, $object_id); } $events->trigger('webuser', 'vote', array('status' => $status, 'webuser_vote_id' => $webuser_vote_id, 'webuser' => $webuser, 'object' => $object, 'object_id' => $object_id, 'value' => $value, 'replace' => $replace)); return $status; }
function files_item_properties($item) { global $user; global $website; global $layout; global $user; $navibars = new navibars(); $naviforms = new naviforms(); $navibars->title(t(89, 'Files')); $layout->navigate_media_browser(); // we can use media browser in this function //$navibars->add_actions( array( '<a href="?fid='.$_REQUEST['fid'].'&act=0&parent='.$item->parent.'"><img height="16" align="absmiddle" width="16" src="img/icons/silk/clipboard.png"> NaviM+</a>')); $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(1);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>', $user->permission("files.delete") == "true" ? '<a href="#" onclick="navigate_delete_dialog();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '</a>' : '')); $navibars->add_actions(array('<a href="?fid=' . $_REQUEST['fid'] . '&act=0&parent=' . $item->parent . '"><img height="16" align="absmiddle" width="16" src="img/icons/silk/folder_up.png"> ' . t(139, 'Back') . '</a>', 'search_form')); $delete_html = array(); $delete_html[] = '<script language="javascript" type="text/javascript">'; $delete_html[] = 'function navigate_delete_dialog()'; $delete_html[] = '{'; $delete_html[] = '$("<div id=\\"navigate-delete-dialog\\" class=\\"hidden\\">' . t(57, 'Do you really want to delete this item?') . '</div>").dialog( { resizable: true, height: 150, width: 300, modal: true, title: "' . t(59, 'Confirmation') . '", buttons: { "' . t(35, 'Delete') . '": function() { $.ajax( { async: false, url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=json&op=delete&id=' . $item->id . '", success: function(data) { if(data=="true" || data=="1") window.location.href = "?fid=' . $_REQUEST['fid'] . '&act=0&parent=' . $item->parent . '"; else navigate_notification(data); } }); $(this).dialog("close"); $("#navigate-delete-dialog").remove(); }, "' . t(58, 'Cancel') . '": function() { $(this).dialog("close"); $("#navigate-delete-dialog").remove(); } } }); }'; $delete_html[] = '</script>'; $navibars->add_content(implode("\n", $delete_html)); $navibars->form(); $navibars->add_tab(t(43, "Main")); $navibars->add_tab_content($naviforms->hidden('form-sent', 'true')); $navibars->add_tab_content($naviforms->hidden('id', $item->id)); $navibars->add_tab_content_row(array('<label>ID</label>', '<span>' . $item->id . '</span>')); $navibars->add_tab_content_row(array('<label>' . t(144, 'Filename') . '</label>', $naviforms->textfield('name', $item->name))); $navibars->add_tab_content_row(array('<label>' . t(145, 'Size') . '</label>', '<span>' . core_bytes($item->size) . '</span>')); $navibars->add_tab_content_row(array('<label>' . t(160, 'Type') . '</label>', $naviforms->selectfield('type', array(0 => 'image', 1 => 'video', 2 => 'audio', 3 => 'document', 4 => 'flash', 5 => 'file'), array(0 => t(157, 'Image'), 1 => t(272, 'Video'), 2 => t(31, 'Audio'), 3 => t(539, 'Document'), 4 => 'Flash', 5 => t(82, 'File')), $item->type, false))); // retrieve a full list of mimetypes by extension $mimetypes = array_values(file::mimetypes()); // remove duplicate entries $mimetypes = array_unique($mimetypes); sort($mimetypes); $mimetypes = array_filter($mimetypes); $navibars->add_tab_content_row(array('<label>MIME</label>', $naviforms->selectfield('mime', $mimetypes, $mimetypes, $item->mime, false))); $navibars->add_tab_content_row(array('<label>' . t(364, 'Access') . '</label>', $naviforms->selectfield('access', array(0 => 0, 1 => 2, 2 => 1, 3 => 3), array(0 => t(254, 'Everybody'), 1 => t(362, 'Not signed in'), 2 => t(361, 'Web users only'), 3 => t(512, 'Selected web user groups')), $item->access, 'navigate_webuser_groups_visibility($(this).val());', false, array(1 => t(363, 'Users who have not yet signed in'))))); $webuser_groups = webuser_group::all_in_array(); $navibars->add_tab_content_row(array('<label>' . t(506, "Groups") . '</label>', $naviforms->multiselect('groups', array_keys($webuser_groups), array_values($webuser_groups), $item->groups)), 'webuser-groups-field'); $layout->add_script(' function navigate_webuser_groups_visibility(access_value) { if(access_value==3) $("#webuser-groups-field").show(); else $("#webuser-groups-field").hide(); } navigate_webuser_groups_visibility(' . $item->access . '); '); $navibars->add_tab_content_row(array('<label>' . t(80, 'Permission') . '</label>', $naviforms->selectfield('permission', array(0 => 0, 1 => 1, 2 => 2), array(0 => t(69, 'Published'), 1 => t(70, 'Private'), 2 => t(81, 'Hidden')), $item->permission))); $navibars->add_tab_content_row(array('<label>' . t(65, 'Enabled') . '</label>', $naviforms->checkbox('enabled', $item->enabled))); /* $navibars->add_tab_content_row(array( '<label>'.t(153, 'Embed link').'</label>', '<a href="'.NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$item->id.'&disposition=inline" target="_blank">'.NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$item->id.'&disposition=inline</a>')); $navibars->add_tab_content_row(array( '<label>'.t(154, 'Download link').'</label>', '<a href="'.NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$item->id.'&disposition=attachment">'.NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$item->id.'&disposition=attachment</a>')); */ $website_root = $website->absolute_path(true) . '/object'; if (empty($website_root)) { $website_root = NVWEB_OBJECT; } $navibars->add_tab_content_row(array('<label>' . t(153, 'Embed link') . '</label>', '<a href="' . $website_root . '?id=' . $item->id . '&disposition=inline" target="_blank">' . $website_root . '?id=' . $item->id . '&disposition=inline</a>')); $navibars->add_tab_content_row(array('<label>' . t(154, 'Download link') . '</label>', '<a href="' . $website_root . '?id=' . $item->id . '&disposition=attachment">' . $website_root . '?id=' . $item->id . '&disposition=attachment</a>')); if ($item->type == 'image') { $navibars->add_tab(t(157, "Image")); $navibars->add_tab_content_row(array('<label>' . t(155, 'Width') . ' / ' . t(156, 'Height') . '</label>', $naviforms->textfield('width', $item->width, '50px'), 'x', $naviforms->textfield('height', $item->height, '50px'), 'px')); $navibars->add_tab_content_row(array('<label>' . t(170, 'Edit') . '</label>', ' <script language="javascript" type="text/javascript"> function navigate_pixlr_edit() { pixlr.overlay.show({ service: "editor", loc: "' . $user->language . '", image:"' . NAVIGATE_DOWNLOAD . '?id=' . $item->id . '&disposition=inline&sid=' . session_id() . '&seed=" + new Date().getTime(), title: "' . $item->name . '", target: "' . NAVIGATE_URL . '/navigate_upload.php?wid=' . $website->id . '&engine=pixlr&id=' . $item->id . '&session_id=' . session_id() . '&seed=" + + new Date().getTime(), exit: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=pixlr_exit&id=' . $item->id . '&ts=" + + new Date().getTime(), credentials: true, method: "GET", referrer: "Navigate CMS", icon: "' . NAVIGATE_URL . '/img/navigate-isotype-16x16.png", locktitle: true, locktype: "png", redirect: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=pixlr_exit&id=' . $item->id . '&ts=" + + new Date().getTime() }); // add a close button var close_button = $(\'<a href="#"><span class="fa-stack"><i class="fa fa-circle fa-stack-2x"></i><i class="fa fa-close fa-stack-1x fa-inverse"></i></span></a>\'); close_button.css({ "position": "absolute", "right": "-20px", "top": "-20px", "font-size": "20px", "color": "#222" }); close_button.on("click", function() { pixlr.overlay.hide(); $("#image-preview").attr("src", $("#image-preview").attr("src") + "&refresh=" + new Date().getTime()); }); $("div:last").prepend(close_button); } </script> <a href="#" class="button" onclick="navigate_pixlr_edit();"><img src="' . NAVIGATE_URL . '/img/logos/pixlr.png" width="100px" height="42px" /></a> ')); $navibars->add_tab_content_row(array('<label>' . t(274, 'Preview') . '</label>', '<div><img id="image-preview" src="' . $website_root . '?id=' . $item->id . '&disposition=inline&seed=' . core_time() . '" width="400px" /></div>')); $navibars->add_tab_content_row(array('<label> </label>' . '<button onclick="navigate_media_browser_focalpoint(' . $item->id . '); return false;"><img src="img/icons/silk/picture-measurement.png" align="absmiddle"> ' . t(540, 'Focal point') . '</button>')); $navibars->add_tab(t(334, 'Description')); $website_languages_selector = $website->languages(); $website_languages_selector = array_merge(array('' => '(' . t(443, 'All') . ')'), $website_languages_selector); $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('files_description_language_selector', $website_languages_selector, '', "navigate_tabform_language_selector(this);"))); foreach ($website->languages_list as $lang) { $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>'; $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . ' ' . $language_info . '</label>', $naviforms->textfield('title-' . $lang, @$item->title[$lang])), '', 'lang="' . $lang . '"'); $navibars->add_tab_content_row(array('<label>' . t(334, 'Description') . ' ' . $language_info . '</label>', $naviforms->textfield('description-' . $lang, @$item->description[$lang])), '', 'lang="' . $lang . '"'); } } else { if ($item->type == 'video') { $navibars->add_tab(t(272, "Video")); /* $navibars->add_tab_content_row(array( '<label>'.t(272, 'Video').'</label>', '<div id="video_'.$item->id.'" style="display:block;width:640px;height:360px;float:left;" class="video">', '<video controls="controls">', ' <source src="'.NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$item->id.'&disposition=inline" type="'.$item->mime.'" />', '</video>', '</div>' )); $layout->add_script(' $("#video_'.$item->id.' video").mediaelementplayer( { pluginPath: "'.NAVIGATE_URL.'/lib/external/mediaelement/" }); '); */ $navibars->add_tab_content_row(array('<label>' . t(272, 'Video') . '</label>', '<div id="video_' . $item->id . '" style="display:block;width:640px;height:360px;float:left;" class="video"> <a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a> </div>', '<script language="javascript" type="text/javascript" src="http://bitcast-b.bitgravity.com/player/6/functions.js"></script>')); $layout->add_script(' var flashvars = {}; flashvars.AutoPlay = "false"; flashvars.File = "' . urlencode(NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . $item->id . '&disposition=inline') . '"; flashvars.Mode = "ondemand"; var params = {}; params.allowFullScreen = "true"; params.allowScriptAccess = "always"; var attributes = {}; attributes.id = "bitgravity_player_6"; swfobject.embedSWF(stablerelease, "video_' . $item->id . '", "640", "360", "9.0.115", "http://bitcast-b.bitgravity.com/player/expressInstall.swf", flashvars, params, attributes); '); } else { if ($item->type == 'audio') { $navibars->add_tab(t(31, "Audio")); $navibars->add_tab_content_row(array('<label>' . t(31, 'Audio') . '</label>', '<div id="audio_' . $item->id . '" style="display:block;float:left;" class="audio">', '<audio controls="controls">', ' <source src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . $item->id . '&disposition=inline" type="' . $item->mime . '" />', '</audio>', '</div>')); $layout->add_script(' $("#audio_' . $item->id . ' audio").mediaelementplayer( { pluginPath: "' . NAVIGATE_URL . '/lib/external/mediaelement/" }); $("#audio_' . $item->id . '").addClass("ui-state-default"); '); } } } return $navibars->generate(); }
function nvweb_comments($vars = array()) { global $website; global $DB; global $current; global $webgets; global $dictionary; global $webuser; global $theme; global $events; global $session; $webget = 'comments'; if (!isset($webgets[$webget])) { $webgets[$webget] = array(); global $lang; if (empty($lang)) { $lang = new language(); $lang->load($current['lang']); } // default translations $webgets[$webget]['translations'] = array('post_a_comment' => t(379, 'Post a comment'), 'name' => t(159, 'Name'), 'email' => t(44, 'E-Mail'), 'website' => t(177, 'Website'), 'message' => t(380, 'Message'), 'email_will_not_be_published' => t(381, 'E-Mail will not be published'), 'submit' => t(382, 'Submit'), 'sign_in_or_sign_up_to_post_a_comment' => t(383, 'Sign in or Sign up to post a comment'), 'comments_on_this_entry_are_closed' => t(384, 'Comments on this entry are closed'), 'please_dont_leave_any_field_blank' => t(385, 'Please don\'t leave any field blank'), 'your_comment_has_been_received_and_will_be_published_shortly' => t(386, 'Your comment has been received and will be published shortly'), 'new_comment' => t(387, 'New comment'), 'review_comments' => t(388, 'Review comments')); // theme translations // if the web theme has custom translations for this string subtypes, use it (for the user selected language) /* just add the following translations to your json theme dictionary: "post_a_comment": "Post a comment", "name": "Name", "email": "E-Mail", "website": "Website", "message": "Message", "email_will_not_be_published": "E-Mail will not be published", "submit": "Submit", "sign_in_or_sign_up_to_post_a_comment": "Sign in or Sign up to post a comment", "comments_on_this_entry_are_closed": "Comments on this entry are closed", "please_dont_leave_any_field_blank": "Please don't leave any field blank", "your_comment_has_been_received_and_will_be_published_shortly": "Your comment has been received and will be published shortly", "new_comment": "New comment", "review_comments": "Review comments" */ if (!empty($website->theme) && method_exists($theme, 't')) { foreach ($webgets[$webget]['translations'] as $code => $text) { $theme_translation = $theme->t($code); if (!empty($theme_translation) && $theme_translation != $code) { $webgets[$webget]['translations'][$code] = $theme_translation; } } } } // set default callback if (empty($vars['callback'])) { $vars['callback'] = 'alert'; } // check callback attributes $callback = $vars['callback']; if (!empty($vars['alert_callback'])) { $callback = $vars['alert_callback']; } else { if (!empty($vars['callback_alert'])) { $callback = $vars['callback_alert']; } } $callback_error = $callback; if (!empty($vars['error_callback'])) { $callback_error = $vars['error_callback']; } else { if (!empty($vars['callback_error'])) { $callback_error = $vars['callback_error']; } } $out = ''; // if the current page belongs to a structure entry // we need to get the associated elements to retrieve and post its comments // (because structure entry pages can't have associated comments) // so, ONLY the FIRST element associated to a category can have comments in a structure entry page // (of course if the element has its own page, it can have its own comments) $element = $current['object']; if ($current['type'] == 'structure') { if (empty($current['structure_elements'])) { $current['structure_elements'] = $element->elements(); } $element = $current['structure_elements'][0]; } switch (@$vars['mode']) { case 'process': if (isset($_GET['nv_approve_comment'])) { // process 1-click comment approval $comment = new comment(); $comment->load($_GET['id']); if (!empty($comment->id) && $comment->status == -1) { $hash = $_GET['hash']; if ($hash == sha1($comment->id . $comment->email . APP_UNIQUE . serialize($website->contact_emails))) { // hash check passed $comment->status = 0; $comment->save(); $response = t(555, "Item has been successfully published."); if ($vars['notify'] == 'inline' || $callback == 'inline') { $out = '<div class="comment-success">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback . '("' . $response . '");'); } } } else { $response = t(344, "Security error"); if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-error">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback_error . '("' . $response . '");'); } } } } else { $response = t(56, "Unexpected error"); if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-error">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback_error . '("' . $response . '");'); } } } } if (isset($_GET['nv_remove_comment'])) { // process 1-click comment removal $comment = new comment(); $comment->load($_GET['id']); if (!empty($comment->id) && $comment->status == -1) { $hash = $_GET['hash']; if ($hash == sha1($comment->id . $comment->email . APP_UNIQUE . serialize($website->contact_emails))) { // hash check passed $comment->delete(); $response = t(55, "Item successfully deleted"); if ($vars['notify'] == 'inline' || $callback == 'inline') { $out = '<div class="comment-success">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback . '("' . $response . '");'); } } } else { $response = t(344, "Security error"); if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-error">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback_error . '("' . $response . '");'); } } } } else { $response = t(56, "Unexpected error"); if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-error">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback_error . '("' . $response . '");'); } } } } if ($_REQUEST['form-type'] == 'comment-reply' || isset($_POST[$vars['field-message']])) { // add comment if (empty($vars['field-name'])) { $vars['field-name'] = 'reply-name'; } if (empty($vars['field-email'])) { $vars['field-email'] = 'reply-email'; } if (empty($vars['field-url'])) { $vars['field-url'] = 'reply-url'; } if (empty($vars['field-message'])) { $vars['field-message'] = 'reply-message'; } if (!empty($vars['element'])) { $element = $vars['element']; } $comment_name = @$_REQUEST[$vars['field-name']]; $comment_email = @$_REQUEST[$vars['field-email']]; $comment_url = @$_REQUEST[$vars['field-url']]; $comment_message = @$_REQUEST[$vars['field-message']]; if ((empty($comment_name) || empty($comment_email)) && empty($webuser->id) || empty($comment_message)) { $response = $webgets[$webget]['translations']['please_dont_leave_any_field_blank']; if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-error">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback_error . '("' . $response . '");'); } } return $out; } $status = -1; // new comment, not approved if (empty($element->comments_moderator)) { $status = 0; } // all comments auto-approved // remove any <nv /> or {{nv}} tag $comment_name = core_remove_nvtags($comment_name); $comment_name = strip_tags($comment_name); $comment_message = core_remove_nvtags($comment_message); $comment = new comment(); $comment->id = 0; $comment->website = $website->id; $comment->item = $element->id; $comment->user = empty($webuser->id) ? 0 : $webuser->id; $comment->name = $comment_name; $comment->email = filter_var($comment_email, FILTER_SANITIZE_EMAIL); $comment->url = filter_var($comment_url, FILTER_SANITIZE_URL); $comment->ip = core_ip(); $comment->date_created = core_time(); $comment->date_modified = 0; $comment->status = $status; $comment->message = $comment_message; $properties = array(); // check if there are comment properties values if (isset($vars['field-properties-prefix'])) { // check every possible property $e_properties = property::elements($element->template, 'comment'); for ($ep = 0; $ep < count($e_properties); $ep++) { if (isset($_POST[$vars['field-properties-prefix'] . $e_properties[$ep]->id])) { $properties[$e_properties[$ep]->id] = $_POST[$vars['field-properties-prefix'] . $e_properties[$ep]->id]; } } } // trigger the "new_comment" event through the extensions system before inserting it! $extensions_messages = $events->trigger('comment', 'before_insert', array('comment' => $comment, 'properties' => $properties)); foreach ($extensions_messages as $ext_name => $ext_result) { if (isset($ext_result['error'])) { $response = $ext_result['error']; if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-error">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback_error . '("' . $response . '");'); } } return $out; } } $comment->insert(); if (!empty($properties)) { property::save_properties_from_array('comment', $comment->id, $element->template, $properties); } // reload the element to retrieve the new comments $element = new item(); $element->load($comment->item); if ($current['type'] == 'item' && !isset($vars['element'])) { $current['object'] = $element; } // trigger the "new_comment" event through the extensions system $events->trigger('comment', 'after_insert', array('comment' => &$comment, 'properties' => $properties)); if (!empty($comment->id)) { if ($status == -1) { $response = $webgets[$webget]['translations']['your_comment_has_been_received_and_will_be_published_shortly']; if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-success">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback . '("' . $response . '");'); } } } else { $response = $webgets[$webget]['translations']['your_comment_has_been_received_and_will_be_published_shortly']; if ($vars['notify'] == 'inline' || $callback_error == 'inline') { $out = '<div class="comment-success">' . $response . '</div>'; } else { if (!isset($vars['notify']) || $vars['notify'] == 'callback') { nvweb_after_body("js", $callback . '("' . $response . '");'); } } } } $notify_addresses = $website->contact_emails; if (!empty($element->comments_moderator)) { $notify_addresses[] = user::email_of($element->comments_moderator); } $hash = sha1($comment->id . $comment->email . APP_UNIQUE . serialize($website->contact_emails)); $base_url = nvweb_source_url('element', $element->id); // default colors $background_color = '#E5F1FF'; $text_color = '#595959'; $title_color = '#595959'; $background_color_db = $DB->query_single('value', 'nv_permissions', 'name = ' . protect("nvweb.comments.background_color") . ' AND website = ' . protect($website->id), 'id DESC'); $text_color_db = $DB->query_single('value', 'nv_permissions', 'name = ' . protect("nvweb.comments.text_color") . ' AND website = ' . protect($website->id), 'id DESC'); $title_color_db = $DB->query_single('value', 'nv_permissions', 'name = ' . protect("nvweb.comments.titles_color") . ' AND website = ' . protect($website->id), 'id DESC'); if (!empty($background_color_db)) { $background_color = str_replace('"', '', $background_color_db); } if (!empty($text_color_db)) { $text_color = str_replace('"', '', $text_color_db); } if (!empty($title_color_db)) { $title_color = str_replace('"', '', $title_color_db); } $message = navigate_compose_email(array(array('title' => t(9, 'Content'), 'content' => $element->dictionary[$current['lang']]['title']), array('title' => $webgets[$webget]['translations']['name'], 'content' => $comment_name . @$webuser->username), array('title' => $webgets[$webget]['translations']['email'], 'content' => $comment_email . @$webuser->email), array('title' => $webgets[$webget]['translations']['website'], 'content' => $comment_url . @$webuser->social_website), array('title' => $webgets[$webget]['translations']['message'], 'content' => nl2br($comment_message)), array('footer' => '<a href="' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?wid=' . $website->id . '&fid=10&act=2&tab=5&id=' . $element->id . '"><strong>' . $webgets[$webget]['translations']['review_comments'] . '</strong></a>' . ' | ' . '<a style=" color: #008830" href="' . $base_url . '?nv_approve_comment&id=' . $comment->id . '&hash=' . $hash . '">' . t(258, "Publish") . '</a>' . ' | ' . '<a style=" color: #FF0090" href="' . $base_url . '?nv_remove_comment&id=' . $comment->id . '&hash=' . $hash . '">' . t(525, "Remove comment (without confirmation)") . '</a>')), array('background' => $background_color, 'title-color' => $title_color, 'content-color' => $text_color)); // trying to implement One-Click actions (used in Google GMail) // You need to be registered with Google first: https://developers.google.com/gmail/markup/registering-with-google $one_click_actions = ' <script type="application/ld+json"> { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "name": "' . $webgets[$webget]['translations']['review_comments'] . '", "url": "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?wid=' . $website->id . '&fid=10&act=2&tab=5&id=' . $element->id . '" } } </script> '; $message = '<html><head>' . $one_click_actions . '</head><body>' . $message . '</body></html>'; foreach ($website->contact_emails as $contact_address) { @nvweb_send_email($website->name . ' | ' . $webgets[$webget]['translations']['new_comment'], $message, $contact_address, null, true); } } break; case 'reply': if ($element->comments_enabled_to == 2 && empty($webuser->id)) { // Post a comment form (unsigned users) $out = ' <div class="comments-reply"> <div><div class="comments-reply-info">' . $webgets[$webget]['translations']['post_a_comment'] . '</div></div> <br /> <form action="' . NVWEB_ABSOLUTE . '/' . $current['route'] . '" method="post"> <input type="hidden" name="form-type" value="comment-reply" /> <div class="comments-reply-field"><label>' . $webgets[$webget]['translations']['name'] . '</label> <input type="text" name="reply-name" value="" /></div> <div class="comments-reply-field"><label>' . $webgets[$webget]['translations']['email'] . ' *</label> <input type="text" name="reply-email" value="" /></div> <div class="comments-reply-field"><label>' . $webgets[$webget]['translations']['message'] . '</label> <textarea name="reply-message"></textarea></div> <!-- {{navigate-comments-reply-extra-fields-placeholder}} --> <div class="comments-reply-field comments-reply-field-info-email"><label> </label> * ' . $webgets[$webget]['translations']['email_will_not_be_published'] . '</div> <div class="comments-reply-field comments-reply-field-submit"><input class="comments-reply-submit" type="submit" value="' . $webgets[$webget]['translations']['submit'] . '" /></div> </form> </div> '; $extensions_messages = $events->trigger('comment', 'reply_extra_fields', array('html' => &$out)); // add any extra field generated if (!empty($extensions_messages)) { $extra_fields = array_map(function ($v) { return $v; }, array_values($extensions_messages)); $out = str_replace('<!-- {{navigate-comments-reply-extra-fields-placeholder}} -->', implode("\n", $extra_fields), $out); } } else { if ($element->comments_enabled_to > 0 && !empty($webuser->id)) { // Post a comment form (signed in users) if (empty($vars['avatar_size'])) { $vars['avatar_size'] = 32; } $avatar_url = NVWEB_OBJECT . '?type=blank'; if (!empty($webuser->avatar)) { $avatar_url = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $webuser->avatar . '&disposition=inline&width=' . $vars['avatar_size'] . '&height=' . $vars['avatar_size']; } $out = ' <div class="comments-reply"> <div><div class="comments-reply-info">' . $webgets[$webget]['translations']['post_a_comment'] . '</div></div> <br /> <form action="' . NVWEB_ABSOLUTE . '/' . $current['route'] . '" method="post"> <input type="hidden" name="form-type" value="comment-reply" /> <div class="comments-reply-field"><label style="display: none;"> </label> <img src="' . $avatar_url . '" width="' . $vars['avatar_size'] . '" height="' . $vars['avatar_size'] . '" align="absmiddle" /> <span class="comments-reply-username">' . $webuser->username . '</span><a class="comments-reply-signout" href="?webuser_signout">(x)</a></div> <br /> <div class="comments-reply-field"><label>' . $webgets[$webget]['translations']['message'] . '</label> <textarea name="reply-message"></textarea></div> <!-- {{navigate-comments-reply-extra-fields-placeholder}} --> <div class="comments-reply-field-submit"><input class="comments-reply-submit" type="submit" value="' . $webgets[$webget]['translations']['submit'] . '" /></div> </form> </div> '; $extensions_messages = $events->trigger('comment', 'reply_extra_fields', array('html' => $out)); // add any extra field generated if (!empty($extensions_messages)) { $extra_fields = array_map(function ($v) { return $v; }, array_values($extensions_messages)); $out = str_replace('<!-- {{navigate-comments-reply-extra-fields-placeholder}} -->', implode("\n", $extra_fields), $out); } } else { if ($element->comments_enabled_to == 1) { $out = '<div class="comments-reply"> <div class="comments-reply-info">' . $webgets[$webget]['translations']['sign_in_or_sign_up_to_post_a_comment'] . '</div> </div>'; } else { $out = '<div class="comments-reply"> <div class="comments-reply-info">' . $webgets[$webget]['translations']['comments_on_this_entry_are_closed'] . '</div> </div>'; } } } break; case 'comments': setlocale(LC_ALL, $website->languages[$session['lang']]['system_locale']); list($comments, $comments_total) = nvweb_comments_list(0, NULL, NULL, $vars['order']); // get all comments of the current entry if (empty($vars['avatar_size'])) { $vars['avatar_size'] = '48'; } if (empty($vars['date_format'])) { $vars['date_format'] = '%d %B %Y %H:%M'; } for ($c = 0; $c < $comments_total; $c++) { $avatar = $comments[$c]->avatar; if (!empty($avatar)) { $avatar = '<img src="' . NVWEB_OBJECT . '?type=image&id=' . $avatar . '" width="' . $vars['avatar_size'] . 'px" height="' . $vars['avatar_size'] . 'px"/>'; } else { $avatar = '<img src="data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="' . $vars['avatar_size'] . 'px" height="' . $vars['avatar_size'] . 'px"/>'; } $comment = new comment(); $comment->load_from_resultset(array($comments[$c])); $depth = 'data-depth="' . $comment->depth() . '"'; $out .= ' <div class="comment"' . $depth . '> <div class="comment-avatar">' . $avatar . '</div> <div class="comment-username">' . (!empty($comments[$c]->username) ? $comments[$c]->username : $comments[$c]->name) . '</div> <div class="comment-date">' . Encoding::toUTF8(strftime($vars['date_format'], $comments[$c]->date_created)) . '</div> <div class="comment-message">' . nl2br($comments[$c]->message) . '</div> <div style="clear:both"></div> </div> '; } break; } return $out; }
function items_form($item) { global $user; global $DB; global $website; global $layout; global $theme; global $events; global $current_version; $navibars = new navibars(); $naviforms = new naviforms(); $layout->navigate_media_browser(); // we can use media browser in this function $extra_actions = array(); if (empty($item->id)) { $navibars->title(t(22, 'Items') . ' / ' . t(38, 'Create')); } else { $navibars->title(t(22, 'Items') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']'); } $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_media_browser();" title="Ctrl+M"> <img height="16" align="absmiddle" width="16" src="img/icons/silk/images.png"> ' . t(36, 'Media') . ' </a>')); if (empty($item->id)) { $navibars->add_actions(array($user->permission('items.create') == 'true' ? '<a href="#" onclick="navigate_items_tabform_submit(1);" title="Ctrl+S"> <img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . ' </a>' : "")); } else { $navibars->add_actions(array($user->permission('items.edit') == 'true' || $item->author == $user->id ? '<a href="#" onclick="navigate_items_tabform_submit(1);" title="Ctrl+S"> <img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . ' </a>' : "", $user->permission("items.delete") == 'true' ? '<a href="#" onclick="navigate_delete_dialog();"> <img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . ' </a>' : "")); $extra_actions[] = '<a href="#" onclick="navigate_items_preview();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/monitor.png"> ' . t(274, 'Preview') . '</a>'; if ($user->permission("items.create") != 'false') { $extra_actions[] = '<a href="?fid=items&act=duplicate&id=' . $item->id . '"><img height="16" align="absmiddle" width="16" src="img/icons/silk/page_copy.png"> ' . t(477, 'Duplicate') . '</a>'; } $layout->add_script(' function navigate_delete_dialog() { navigate_confirmation_dialog( function() { window.location.href = "?fid=items&act=delete&id=' . $item->id . '"; }, null, null, "' . t(35, 'Delete') . '" ); } '); } if (!empty($item->id)) { $notes = grid_notes::comments('item', $item->id); $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_display_notes_dialog();"> <span class="navigate_grid_notes_span" style=" width: 20px; line-height: 16px; ">' . count($notes) . '</span> <img src="img/skins/badge.png" width="20px" height="18px" style="margin-top: -2px;" class="grid_note_edit" align="absmiddle" /> ' . t(168, 'Notes') . ' </a>')); } if (!empty($item->id)) { // we attach an event to "items" which will be fired by navibars to put an extra button $events->add_actions('items', array('item' => &$item, 'navibars' => &$navibars), $extra_actions); } if (!empty($item->id)) { $layout->navigate_notes_dialog('item', $item->id); } $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=items&act=edit"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=items&act=list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>', 'search_form')); // languages $ws_languages = $website->languages(); $navibars->form('', 'fid=items&act=edit&id=' . $item->id); $layout->add_script("\r\n \$(document).on('keydown.ctrl_s', function (evt) { navigate_items_tabform_submit(1); return false; } );\r\n \$(document).on('keydown.ctrl_m', function (evt) { navigate_media_browser(); return false; } );\r\n "); $layout->add_script(' var template_sections = []; '); $navibars->add_tab(t(43, "Main")); // tab #0 $navibars->add_tab_content($naviforms->hidden('form-sent', 'true')); $navibars->add_tab_content($naviforms->hidden('id', $item->id)); $navibars->add_tab_content_row(array('<label>ID</label>', '<span>' . (!empty($item->id) ? $item->id : t(52, '(new)')) . '</span>')); if (empty($item->id)) { $item->date_to_display = core_time(); } $navibars->add_tab_content_row(array('<label>' . t(551, 'Date to display') . '</label>', $naviforms->datefield('date_to_display', $item->date_to_display, true))); $navibars->add_tab_content_row(array('<label>' . t(85, 'Date published') . '</label>', $naviforms->datefield('date_published', $item->date_published, true))); $navibars->add_tab_content_row(array('<label>' . t(90, 'Date unpublished') . '</label>', $naviforms->datefield('date_unpublish', $item->date_unpublish, true))); $navibars->add_tab_content_row(array('<label>' . t(364, 'Access') . '</label>', $naviforms->selectfield('access', array(0 => 0, 1 => 2, 2 => 1, 3 => 3), array(0 => t(254, 'Everybody'), 1 => t(362, 'Not signed in'), 2 => t(361, 'Web users only'), 3 => t(512, 'Selected web user groups')), $item->access, 'navigate_webuser_groups_visibility($(this).val());', false, array(1 => t(363, 'Users who have not yet signed in'))))); $webuser_groups = webuser_group::all_in_array(); $navibars->add_tab_content_row(array('<label>' . t(506, "Groups") . '</label>', $naviforms->multiselect('groups', array_keys($webuser_groups), array_values($webuser_groups), $item->groups)), 'webuser-groups-field'); $layout->add_script(' function navigate_webuser_groups_visibility(access_value) { if(access_value==3) $("#webuser-groups-field").show(); else $("#webuser-groups-field").hide(); } navigate_webuser_groups_visibility(' . $item->access . '); '); $permission_options = array(0 => t(69, 'Published'), 1 => t(70, 'Private'), 2 => t(81, 'Hidden')); if ($user->permission("items.publish") == 'false') { if (!isset($item->permission)) { $item->permission = 1; } $navibars->add_tab_content_row(array('<label>' . t(68, 'Status') . '</label>', $permission_options[$item->permission], $naviforms->hidden("permission", $item->permission))); } else { $navibars->add_tab_content_row(array('<label>' . t(68, 'Status') . '</label>', $naviforms->selectfield('permission', array_keys($permission_options), array_values($permission_options), $item->permission, '', false, array(0 => t(360, 'Visible to everybody'), 1 => t(359, 'Visible only to Navigate CMS users'), 2 => t(358, 'Hidden to everybody'))), '<span id="status_info" class="ui-icon ui-icon-alert" data-message="' . t(618, 'Change the status to Published to see the item on the future publication date currently assigned', false, true) . '" style="display: none; float: none; vertical-align: middle; "></span>')); } if (empty($item->id)) { $item->author = $user->id; } $author_webuser = $DB->query_single('username', 'nv_users', ' id = ' . $item->author); $navibars->add_tab_content($naviforms->hidden('item-author', $item->author)); $navibars->add_tab_content_row(array('<label>' . t(266, 'Author') . '</label>', $naviforms->textfield('item-author-text', $author_webuser))); // script#1 if ($item->date_modified > 0) { $navibars->add_tab_content_row(array('<label>' . t(227, 'Date modified') . '</label>', core_ts2date($item->date_modified, true))); } if ($item->date_created > 0) { $navibars->add_tab_content_row(array('<label>' . t(226, 'Date created') . '</label>', core_ts2date($item->date_created, true))); } $navibars->add_tab_content_row(array('<label>' . t(280, 'Page views') . '</label>', $item->views), "div_page_views"); $navibars->add_tab(t(87, "Association")); // tab #1 $navibars->add_tab_content_row(array('<label>' . t(87, "Association") . '</label>', $naviforms->buttonset('association', array('free' => t(100, 'Free'), 'category' => t(78, 'Category')), empty($item->id) ? 'category' : $item->association, "navigate_change_association(this);"))); $hierarchy = structure::hierarchy(0); $categories_list = structure::hierarchyList($hierarchy, $item->category); if (empty($categories_list)) { $categories_list = '<ul><li value="0">' . t(428, '(no category)') . '</li></ul>'; } $navibars->add_tab_content_row(array('<label>' . t(78, 'Category') . '</label>', $naviforms->dropdown_tree('category', $categories_list, $item->category, 'navigate_item_category_change')), 'div_category_tree'); $layout->add_script(' function navigate_item_category_change(id) { $.ajax( { url: NAVIGATE_APP + "?fid=" + navigate_query_parameter("fid") + "&act=96&id=" + id, dataType: "json", data: {}, success: function(data, textStatus, xhr) { item_category_path = data; } }); } '); $navibars->add_tab_content_row(array('<label>' . t(162, 'Embedding') . '</label>', $naviforms->buttonset('embedding', array('1' => t(163, 'Embedded'), '0' => t(164, 'Own path')), empty($item->id) ? '1' : intval($item->embedding), "navigate_change_association();"), '<span id="embedding_info" class="ui-icon ui-icon-info" data-message-title-1="' . t(163, 'Embedded', false, true) . '" data-message-content-1="' . t(165, 'Full content is shown on category page. Ex. "Who we are?"', false, true) . '" data-message-title-2="' . t(164, 'Own path', false, true) . '" data-message-content-2="' . t(166, 'The content is accessed through its own url. Ex. "News"', false, true) . '" style="float: left; margin-left: -4px;"> </span>'), 'div_category_embedded'); $navibars->add_tab_content_row(array('<label>' . t(22, 'Elements') . '</label>', '<button style="float: left;">' . t(171, 'Order') . '</button>', '<span id="order_info" class="ui-icon ui-icon-info" data-message="' . t(425, 'Order elements of a category (unless the template forces other sorting)', false, true) . '" style="float: left; margin-left: 2px;"> </span>', '<div id="items_order_window" style="display: none;"></div>'), 'div_category_order'); $layout->add_script(' $("#div_category_order button").button( { icons: { primary: "ui-icon-arrowthick-2-n-s" } }).on("click", function(e) { e.stopPropagation(); e.preventDefault(); navigate_status(navigate_t(6, "Loading") + "...", "loader"); $("#items_order_window").load("?fid=items&act=items_order&category=" + $("#category").val() + "&_bogus=" + new Date().getTime(), function() { navigate_status(navigate_t(42, "Ready"), "ready"); $("#items_order_window").dialog({ modal: true, title: "' . t(171, 'Order') . '", width: 600, height: 500, buttons: { "' . t(58, 'Cancel') . '": function() { $(this).dialog("destroy"); }, "' . t(190, 'Ok') . '": function() { var dialog = this; // save $.post( "?fid=items&act=items_order&category=" + $("#category").val() + "&_bogus=" + new Date().getTime(), { "items-order": $("#items-order").val() }, function(response) { if(response=="true") { $(dialog).dialog("destroy"); } else { $("<div>"+response+"</div>").dialog({ modal: true, title: "' . t(56, "Unexpected error") . '" }); } } ); } } }); }); }); '); $templates = template::elements('element'); $template_select = $naviforms->select_from_object_array('template', $templates, 'id', 'title', $item->template); $navibars->add_tab_content_row(array('<label>' . t(79, 'Template') . '</label>', $template_select, '<span id="template_info" class="ui-icon ui-icon-alert" data-message="' . t(619, "Template changed, please Save now to see the changes in the next tabs", false, true) . '" style="display: none; float: none; vertical-align: middle; "></span>'), 'div_template_select'); $layout->add_script(' var last_check = []; var active_languages = ["' . implode('", "', array_keys($ws_languages)) . '"]; $("#div_template_select").hide(); '); // script#3 if (!empty($item->id)) { $navibars->add_tab(t(9, "Content")); // tab #2 $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('language_selector', $ws_languages, $website->languages_list[0], "navigate_items_select_language(this);"))); $template = $item->load_template(); $translate_extensions = extension::list_installed('translate', false); foreach ($website->languages_list as $lang) { $navibars->add_tab_content('<div class="language_fields" id="language_fields_' . $lang . '" style=" display: none; ">'); $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . '</label>', $naviforms->textfield('title-' . $lang, @$item->dictionary[$lang]['title']))); $open_live_site = ''; if (!empty($item->paths[$lang])) { $open_live_site = ' <a target="_blank" href="' . $website->absolute_path(true) . $item->paths[$lang] . '"><img src="img/icons/silk/world_go.png" align="absmiddle" /></a>'; } $navibars->add_tab_content_row(array('<label>' . t(75, 'Path') . $open_live_site . '</label>', $naviforms->textfield('path-' . $lang, @$item->paths[$lang], NULL, 'navigate_items_path_check(this, event);'), '<span> </span>'), 'div_path_' . $lang); if (!isset($template->sections)) { $template->sections[] = array(0 => array('id' => 'main', 'name' => '#main#', 'editor' => 'tinymce', 'width' => '960px')); } if (!is_array($template->sections)) { $template->sections = array(); } // compatibility fix: auto-correct template sections with missing ID (only "code" provided) for ($s = 0; $s < count($template->sections); $s++) { if (!isset($template->sections[$s]['id'])) { $template->sections[$s]['id'] = $template->sections[$s]['code']; } } foreach ($template->sections as $section) { if (is_object($section)) { $section = (array) $section; } // ignore empty sections if (empty($section)) { continue; } if ($section['editor'] == 'tinymce') { $translate_menu = ''; if (!empty($translate_extensions)) { $translate_extensions_titles = array(); $translate_extensions_actions = array(); foreach ($translate_extensions as $te) { if ($te['enabled'] == '0') { continue; } $translate_extensions_titles[] = $te['title']; $translate_extensions_actions[] = 'javascript: navigate_tinymce_translate_' . $te['code'] . '(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $lang . '\');'; } if (!empty($translate_extensions_actions)) { $translate_menu = $naviforms->splitbutton('translate_' . $lang, '<img src="img/icons/silk/comment.png" align="absmiddle"> ' . t(188, 'Translate'), $translate_extensions_actions, $translate_extensions_titles); } } $navibars->add_tab_content_row(array('<label>' . template::section_name($section['name']) . '<span class="editor_selector" for="section-' . $section['id'] . '-' . $lang . '">' . '<i class="fa fa-border fa-fw fa-lg fa-file-text-o active" data-action="tinymce" title="' . t(614, "Edit with TinyMCE") . '"></i> ' . '<i class="fa fa-border fa-fw fa-lg fa-code" data-action="html" title="' . t(615, "Edit as source code") . '"></i> ' . '<i class="fa fa-border fa-fw fa-lg fa-eraser" data-action="clear" title="' . t(208, "Remove all content") . '"></i>' . '</span>' . '</label>', $naviforms->editorfield('section-' . $section['id'] . '-' . $lang, @$item->dictionary[$lang]['section-' . $section['id']], $section['width'] + 48 . 'px', $lang), '<div style="clear:both; margin-top:5px; float:left; margin-bottom: 10px;">', '<label> </label>', $translate_menu, '<button onclick="navigate_items_copy_from_dialog(\'section-' . $section['id'] . '-' . $lang . '\'); return false;"><img src="img/icons/silk/page_white_copy.png" align="absmiddle"> ' . t(189, 'Copy from') . '...</button> ', '<button onclick="navigate_items_copy_from_history_dialog(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/time_green.png" align="absmiddle"> ' . t(40, 'History') . '</button> ', !empty($theme->content_samples) ? '<button onclick="navigate_items_copy_from_theme_samples(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/rainbow.png" align="absmiddle"> ' . t(553, 'Fragments') . ' | ' . $theme->title . '</button> ' : '', '</div>', '<br />'), '', 'lang="' . $lang . '"'); } else { if ($section['editor'] == 'html') { $navibars->add_tab_content_row(array('<label>' . template::section_name($section['name']) . '</label>', $naviforms->scriptarea('section-' . $section['id'] . '-' . $lang, @$item->dictionary[$lang]['section-' . $section['id']], 'html', ' width: ' . $section['width'] . 'px'), '<div style="clear:both; margin-top:5px; float:left; margin-bottom: 10px;">', '<label> </label>', '<button onclick="navigate_items_copy_from_history_dialog(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/time_green.png" align="absmiddle"> ' . t(40, 'History') . '</button> ', !empty($theme->content_samples) ? '<button onclick="navigate_items_copy_from_theme_samples(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/rainbow.png" align="absmiddle"> ' . t(553, 'Fragments') . ' | ' . $theme->title . '</button> ' : '', '</div>', '<br />'), '', 'lang="' . $lang . '"'); } else { $translate_menu = ''; if (!empty($translate_extensions)) { $translate_extensions_titles = array(); $translate_extensions_actions = array(); foreach ($translate_extensions as $te) { if ($te['enabled'] == '0') { continue; } $translate_extensions_titles[] = $te['title']; $translate_extensions_actions[] = 'javascript: navigate_textarea_translate_' . $te['code'] . '(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $lang . '\');'; } if (!empty($translate_extensions_actions)) { $translate_menu = $naviforms->splitbutton('translate_' . $lang, '<img src="img/icons/silk/comment.png" align="absmiddle"> ' . t(188, 'Translate'), $translate_extensions_actions, $translate_extensions_titles); } } $navibars->add_tab_content_row(array('<label>' . template::section_name($section['name']) . '</label>', $naviforms->textarea('section-' . $section['id'] . '-' . $lang, @$item->dictionary[$lang]['section-' . $section['id']], 8, 48, ' width: ' . $section['width'] . 'px'), '<div style="clear:both; margin-top:5px; margin-bottom: 10px; ">', '<label> </label>', $translate_menu, '<button onclick="navigate_items_copy_from_history_dialog(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/time_green.png" align="absmiddle"> ' . t(40, 'History') . '</button> ', !empty($theme->content_samples) ? '<button onclick="navigate_items_copy_from_theme_samples(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/rainbow.png" align="absmiddle"> ' . t(553, 'Fragments') . ' | ' . $theme->title . '</button> ' : '', '</div>'), '', 'lang="' . $lang . '"'); } } } if ($template->tags == 1 || $template->tags == 'true') { $tags_copy_select = ''; $tags_copy_select_pre = ''; $tags_copy_select_after = ''; // allow copying tags between languages? if (count($website->languages_list) > 1) { $tags_copy_select = $naviforms->selectfield('', array_keys($ws_languages), array_values($ws_languages), '', '', false, '', ' width: auto; position: absolute; margin-top: 1px; ', false); $tags_copy_select = ' <div style=" position: relative; margin-left: 600px; margin-top: -57px; width: 200px; height: 68px; "> <a href="#" class="uibutton" title="' . t(189, "Copy from") . '…" onclick=" navigate_items_tags_copy_from_language($(this).next().val(), \'' . $lang . '\'); return false; "> <img src="img/icons/silk/page_white_copy.png" width="16" height="16" align="absmiddle" style=" cursor: pointer; " /> </a> ' . $tags_copy_select . ' </div> '; } $tags_top_list = ' <div style=" position: relative; margin-left: 600px; margin-top: -93px; width: 200px; height: 92px; "> <a href="#" class="uibutton" onclick=" navigate_items_tags_ranking(\'' . $lang . '\', this); return false; "> <img src="img/icons/silk/award_star_gold_3.png" width="16" height="16" align="absmiddle" style=" cursor: pointer; " /> ' . t(613, "Most used") . ' </a> </div> '; $navibars->add_tab_content_row(array('<label>' . t(265, 'Tags') . '</label>', $naviforms->textfield('tags-' . $lang, @$item->dictionary[$lang]['tags']), $tags_top_list, $tags_copy_select)); } $layout->add_script(' $("#tags-' . $lang . '").tagit({ removeConfirmation: true, allowSpaces: true, singleField: true, singleFieldDelimiter: ",", placeholderText: "+", autocomplete: { delay: 0, minLength: 1, source: "?fid=items&act=json_tags_search&lang=' . $lang . '" }, afterTagAdded: function(event, ui) { var tags = $(this).tagit("assignedTags"); if(tags.length > 0) tags = tags.join(","); else tags = ""; $("#tags-' . $lang . '") .val(tags) .trigger("change"); }, afterTagRemoved: function(event, ui) { var tags = $(this).tagit("assignedTags"); if(tags.length > 0) tags = tags.join(","); else tags = ""; $("#tags-' . $lang . '") .val(tags) .trigger("change"); } }); $("#tags-' . $lang . '").next().sortable({ items: ">li:not(.tagit-new)", update: function(ui, event) { var tags = []; $("#tags-' . $lang . '").next().find("span.tagit-label").each(function() { if($(this).text() != "") tags.push($(this).text()); }); if(tags.length > 0) tags = tags.join(","); else tags = ""; $("#tags-' . $lang . '").val(tags); $("#tags-' . $lang . '").trigger("change"); } }); '); // script#4 $navibars->add_tab_content('</div>'); } // translate content_samples titles if (is_array($theme->content_samples)) { for ($i = 0; $i < count($theme->content_samples); $i++) { $theme->content_samples[$i]->title = $theme->t($theme->content_samples[$i]->title); } } $layout->add_script(' var template_sections = ' . json_encode($template->sections) . '; var theme_content_samples = ' . json_encode($theme->content_samples) . '; var website_theme = "' . $website->theme . '"; '); $category = new structure(); $category->paths = array(); if (!empty($item->category)) { $category->load($item->category); } $layout->add_script(' var item_category_path = ' . json_encode($category->paths) . '; var item_id = "' . $item->id . '"; '); // script#5 // select the first language of the website as the default origin when copying content $default_language = array_keys($ws_languages); $default_language = $default_language[0]; $layout->add_content(' <div id="navigate_items_copy_from" style=" display: none; "> <div class="navigate-form-row"> <label>' . t(191, 'Source') . '</label> ' . $naviforms->buttonset('navigate_items_copy_from_type', array('language' => t(46, 'Language'), 'item' => t(180, 'Item')), '0', "navigate_items_copy_from_change_origin(this);") . ' </div> <div class="navigate-form-row" style=" display: none; "> <label>' . t(46, 'Language') . '</label> ' . $naviforms->selectfield('navigate_items_copy_from_language_selector', array_keys($ws_languages), array_values($ws_languages), $default_language) . ' </div> <div class="navigate-form-row" style=" display: none; "> <label>' . t(79, 'Template') . '</label> ' . $naviforms->select_from_object_array('navigate_items_copy_from_template', $templates, 'id', 'title', '', '') . ' </div> <div class="navigate-form-row" style=" display: none; "> <label>' . t(67, 'Title') . '</label> ' . $naviforms->textfield('navigate_items_copy_from_title') . ' ' . $naviforms->hidden('navigate_items_copy_from_item_id', '') . ' </div> <div class="navigate-form-row" style=" display: none; "> <label>' . t(239, 'Section') . '</label> ' . $naviforms->select_from_object_array('navigate_items_copy_from_section', array(), 'id', 'name', '') . ' </div> </div> <div id="navigate_items_copy_from_history" style=" display: none; "> <div class="navigate-form-row"> <label>' . t(196, 'Date & time') . '</label> <select id="navigate_items_copy_from_history_options" name="navigate_items_copy_from_history_options" onchange="navigate_items_copy_from_history_preview(this.value, $(this).attr(\'type\'));"> </select> <a href="#" onclick="navigate_items_copy_from_history_remove();"><img src="img/icons/silk/cancel.png" align="absmiddle"></a> </div> <div class="navigate-form-row"> <!--<div id="navigate_items_copy_from_history_text" name="navigate_items_copy_from_history_text" style="border: 1px solid #CCCCCC; float: left; height: auto; min-height: 20px; overflow: auto; width: 97%; padding: 3px; background: #f7f7f7;"> </div> --> <textarea style="display: none;" id="navigate_items_copy_from_history_stylesheets">' . $website->content_stylesheets('link_tag') . '</textarea> <iframe id="navigate_items_copy_from_history_text" name="navigate_items_copy_from_history_text" src="about:blank" style="border: 1px solid #CCCCCC; float: left; height: 300px; min-height: 20px; overflow: auto; width: 97%; padding: 3px; "> </iframe> <div id="navigate_items_copy_from_history_text_raw" style=" display: none; "></div> </div> </div> <div id="navigate_items_copy_from_theme_samples" style=" display: none; "> <div class="navigate-form-row"> <label>' . t(79, 'Template') . '</label> <select id="navigate_items_copy_from_theme_samples_options" name="navigate_items_copy_from_theme_samples_options" onchange="navigate_items_copy_from_theme_samples_preview(this.value, $(this).attr(\'type\'), $(this).find(\'option:selected\').attr(\'source\'));"> </select> </div> <div class="navigate-form-row"> <div id="navigate_items_copy_from_theme_samples_text" name="navigate_items_copy_from_theme_samples_text" style="border: 1px solid #CCCCCC; float: left; height: auto; min-height: 20px; overflow: auto; width: 97%; padding: 3px; background: #f7f7f7;"> </div> <div id="navigate_items_copy_from_theme_samples_text_raw" style=" display: none; "></div> </div> </div> '); // script will be bound to onload event at the end of this php function (after getScript is done) $onload_language = $_REQUEST['tab_language']; if (empty($onload_language)) { $onload_language = $website->languages_list[0]; } $layout->add_script(' function navigate_items_onload() { navigate_items_select_language("' . $onload_language . '"); navigate_change_association("' . (empty($item->id) ? 'category' : $item->association) . '"); setTimeout(function() { $(navigate_codemirror_instances).each(function() { this.refresh(); } ); }, 500); }; '); /* IMAGE GALLERIES */ if ($template->gallery === 'true' || $template->gallery > 0) { $navibars->add_tab(t(210, "Gallery")); // tab #3 $access = array(0 => '', 1 => '<img src="img/icons/silk/lock.png" align="absmiddle" title="' . t(361, 'Web users only') . '" />', 2 => '<img src="img/icons/silk/user_gray.png" align="absmiddle" title="' . t(363, 'Users who have not yet signed up or signed in') . '" />', 3 => '<img src="img/icons/silk/group_key.png" align="absmiddle" title="' . t(512, "Selected web user groups") . '" />'); $permissions = array(0 => '', 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" title="' . t(70, 'Private') . '" />', 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" title="' . t(81, 'Hidden') . '" />'); if (!is_array($item->galleries[0])) { $item->galleries[0] = array(); } $gallery_elements_order = implode('#', array_keys($item->galleries[0])); $navibars->add_tab_content($naviforms->hidden('items-gallery-elements-order', $gallery_elements_order)); $gallery = '<ul id="items-gallery-elements" class="items-gallery">'; $ids = array_keys($item->galleries[0]); //$default_img = 'data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='; // transparent pixel $default_img = 'img/icons/ricebowl/mimetypes/image.png'; for ($g = 0; $g < count($ids); $g++) { $f = new file(); $f->load($ids[$g]); $gallery .= ' <li> <div id="items-gallery-item-' . $ids[$g] . '-droppable" class="navigate-droppable ui-corner-all" data-file-id="' . $f->id . '"> <div class="file-access-icons">' . $access[$f->access] . $permissions[$f->permission] . '</div> <img title="' . $ids[$g] . '" src="' . $default_img . '" data-src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . $ids[$g] . '&disposition=inline&width=75&height=75" width="75" height="75" /> </div> <div class="navigate-droppable-cancel" style="display: block;"><img src="img/icons/silk/cancel.png" /></div> </li> '; } // empty element $gallery .= ' <li class="gallery-item-empty-droppable"> <div id="items-gallery-item-empty-droppable" class="navigate-droppable ui-corner-all"> <img src="img/icons/misc/dropbox.png" vspace="18" /> </div> </li> '; $gallery .= '</ul>'; // now the image captions foreach ($item->galleries[0] as $image_id => $image_dictionary) { if (!is_array($image_dictionary)) { $image_dictionary = array(); } foreach ($website->languages_list as $lang) { $gallery .= $naviforms->hidden('items-gallery-item-' . $image_id . '-dictionary-' . $lang, $image_dictionary[$lang]); } } $navibars->add_tab_content_row(array('<label>' . t(210, 'Gallery') . '</label>', '<div>' . $gallery . '</div>')); $layout->add_content(' <ul id="contextmenu-gallery-items" style="display: none" class="ui-corner-all"> <li id="contextmenu-gallery-items-properties"><a href="#"><span class="ui-icon ui-icon-contact"></span>' . t(213, "Image caption") . '</a></li> <li id="contextmenu-gallery-items-permissions"><a href="#"><span class="ui-icon ui-icon-key"></span>' . t(17, "Permissions") . '</a></li> <li id="contextmenu-gallery-items-focalpoint"><a href="#"><span class="ui-icon ui-icon-image"></span>' . t(540, "Focal point") . '</a></li> <li id="contextmenu-gallery-items-description"><a href="#"><span class="ui-icon ui-icon-comment"></span>' . t(334, 'Description') . '</a></li> <li><!--divider--></li> <li id="contextmenu-gallery-items-remove"><a href="#"><span class="ui-icon ui-icon-minus"></span>' . t(627, 'Remove') . '</a></li> <li id="contextmenu-gallery-items-move-beginning"><a href="#"><span class="ui-icon ui-icon-arrowthickstop-1-n"></span>' . t(628, 'Move to the beginning') . '</a></li> <li id="contextmenu-gallery-items-move-end"><a href="#"><span class="ui-icon ui-icon-arrowthickstop-1-s"></span>' . t(629, 'Move to the end') . '</a></li> </ul> '); // script#6 $layout->add_script(' $(window).on("load", function() { new LazyLoad({ threshold: 200, container: $("#items-gallery-elements-order").parent()[0], elements_selector: "#items-gallery-elements img", throttle: 40, data_src: "src", show_while_loading: true }); }); '); $captions_form = ' <div id="navigate_items_gallery_captions_form" style=" display: none; "> <div class="navigate-form-row"> <label>' . t(157, 'Image') . '</label> ' . $naviforms->dropbox('navigate_items_gallery_captions_form_image', '', 'image', true) . ' </div> '; $caption_langs = array_values($website->languages_list); foreach ($caption_langs as $caption_language) { $captions_form .= ' <div class="navigate-form-row"> <label>' . language::name_by_code($caption_language) . '</label> ' . $naviforms->textfield('navigate_items_gallery_captions_form_image_' . $caption_language, '') . ' </div> '; } $captions_form .= ' </div> '; $layout->add_content($captions_form); } // Properties TAB (only if needed) $properties_html = ''; if ($item->association == 'free' && !empty($item->template) && $item->template != '0') { // we already know the properties to show: template is set on item $properties_html = navigate_property_layout_form('item', $item->template, 'item', $item->id); } else { if ($item->association == 'category' && $item->embedding == 0 && !empty($item->template)) { // we already know the properties to show: template is set on item $properties_html = navigate_property_layout_form('item', $item->template, 'item', $item->id); } else { if ($item->association == 'category' && $item->category > 0) { // we have to get the template set in the category of the item $template_id = $DB->query_single('template', 'nv_structure', ' id = ' . protect($item->category) . ' AND website = ' . $website->id); $properties_html = navigate_property_layout_form('item', $template_id, 'item', $item->id); } } } if (!empty($properties_html)) { $navibars->add_tab(t(77, "Properties")); // tab #4 $navibars->add_tab_content($properties_html); } if ($template->comments > 0 || $template->comments == 'true' || $template->comments === true || is_object($template->comments)) { $navibars->add_tab(t(250, "Comments")); // tab #5 $navibars->add_tab_content_row(array('<label>' . t(252, 'Comments enabled to') . '</label>', $naviforms->selectfield('item-comments_enabled_to', array(0 => 0, 1 => 1, 2 => 2), array(0 => t(253, 'Nobody'), 1 => t(24, 'Registered users'), 2 => t(254, 'Everyone')), $item->comments_enabled_to))); $moderator_id = ''; if (!empty($item->comments_moderator)) { $moderator_username = $DB->query_single('username', 'nv_users', ' id = ' . $item->comments_moderator); if (!empty($moderator_username)) { $moderator_username = array($moderator_username); $moderator_id = array($item->comments_moderator); } } $navibars->add_tab_content_row(array('<label>' . t(255, 'Moderator') . '</label>', $naviforms->selectfield('item-comments_moderator', $moderator_id, $moderator_username, $item->comments_moderator, null, false, null, null, false), '<span style="display: none;" id="item-comments_moderator-helper">' . t(535, "Find user by name") . '</span>', '<div class="subcomment"><img align="absmiddle" src="' . NAVIGATE_URL . '/img/icons/silk/information.png" /> ' . t(256, 'Leave blank to accept all comments') . '</div>')); // script#7 // comments list // removed filter: AND nvwu.website = nvc.website ... reason: the webuser could be from another website if sharing webusers is enabled // TODO: retrieve comments by AJAX call to avoid memory issues. right now we just retrieve the first 500 comments $DB->query('SELECT nvc.*, nvwu.username, nvwu.avatar FROM nv_comments nvc LEFT OUTER JOIN nv_webusers nvwu ON nvwu.id = nvc.user WHERE nvc.website = ' . protect($website->id) . ' AND nvc.item = ' . protect($item->id) . ' ORDER BY nvc.date_created ASC LIMIT 500'); $comments = $DB->result(); $comments_total = count($comments); for ($c = 0; $c < $comments_total; $c++) { if ($comments[$c]->status == 2) { $comment_status = 'hidden'; } else { if ($comments[$c]->status == 1) { $comment_status = 'private'; } else { if ($comments[$c]->status == -1) { $comment_status = 'new'; } else { $comment_status = 'public'; } } } $navibars->add_tab_content_row(array('<span class="items-comment-label">' . core_ts2date($comments[$c]->date_created, true) . '<br />' . '<strong>' . (empty($comments[$c]->username) ? $comments[$c]->name : $comments[$c]->username) . '</strong>' . '<br />' . $comments[$c]->ip . '</span>', '<div id="items-comment-' . $comments[$c]->id . '" class="items-comment-message items-comment-status-' . $comment_status . '">' . nl2br($comments[$c]->message) . '</div>', empty($comments[$c]->avatar) ? '' : '<img style=" margin-left: 5px; " src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . $comments[$c]->avatar . '&disposition=inline&width=46&height=46" />')); } $navibars->add_tab_content(' <div id="items-comments-toolbar"> <img id="items-comments-toolbar-publish" src="' . NAVIGATE_URL . '/img/icons/silk/accept.png" title="' . t(258, 'Publish') . '" /> <img id="items-comments-toolbar-unpublish" src="' . NAVIGATE_URL . '/img/icons/silk/delete.png" title="' . t(259, 'Unpublish') . '" /> <img id="items-comments-toolbar-delete" src="' . NAVIGATE_URL . '/img/icons/silk/decline.png" title="' . t(35, 'Delete') . '" /> </div> '); // script#8 // comments moderation } if ($item->votes > 0) { $navibars->add_tab(t(352, "Votes")); // tab #6 $score = $item->score / $item->votes; $navibars->add_tab_content_panel('<img src="img/icons/silk/chart_pie.png" align="absmiddle" /> ' . t(337, 'Summary'), array('<div class="navigate-panels-summary ui-corner-all"><h2>' . $item->votes . '</h2><br />' . t(352, 'Votes') . '</div>', '<div class="navigate-panels-summary ui-corner-all""><h2>' . $score . '</h2><br />' . t(353, 'Score') . '</div>', '<div style=" float: left; margin-left: 8px; "><a href="#" class="uibutton" id="items_votes_webuser">' . t(15, 'Users') . '</a></div>', '<div style=" float: right; margin-right: 8px; "><a href="#" class="uibutton" id="items_votes_reset">' . t(354, 'Reset') . '</a></div>', '<div id="items_votes_webuser_window" style=" display: none; width: 600px; height: 350px; "></div>'), 'navigate-panel-web-summary', '385px', '200px'); $layout->add_script(' $("#items_votes_reset").on("click", function() { navigate_confirmation_dialog( function() { $.post("?fid=items&act=votes_reset&id=' . $item->id . '", function(data) { $("#navigate-panel-web-summary").addClass("ui-state-disabled"); navigate_notification("' . t(355, 'Votes reset') . '"); }); }, "' . t(497, "Do you really want to erase this data?") . '", null, "' . t(354, 'Reset') . '" ); }); $("#items_votes_webuser").on("click", function() { $( "#items_votes_webuser_window" ).dialog( { title: "' . t(357, 'User votes') . '", width: 700, height: 400, modal: true, open: function() { $( "#items_votes_webuser_window" ).html("<table id=\\"items_votes_webuser_grid\\"></table>"); $( "#items_votes_webuser_window" ).append("<div id=\\"items_votes_webuser_grid_pager\\"></div>"); jQuery("#items_votes_webuser_grid").jqGrid( { url: "?fid=' . $_REQUEST['fid'] . '&act=votes_by_webuser&id=' . $item->id . '", editurl: "?fid=' . $_REQUEST['fid'] . '&act=votes_by_webuser&id=' . $item->id . '", datatype: "json", mtype: "GET", pager: "#items_votes_webuser_grid_pager", colNames:["ID", "' . t(86, 'Date') . '", "' . t(1, 'Username') . '"], colModel:[ {name:"id", index:"id", width: 75, align: "left", sortable:true, editable:false, hidden: true}, {name:"date",index:"date", width: 180, align: "center", sortable:true, editable:false}, {name:"username", index:"username", align: "left", width: 380, sortable:true, editable:false} ], scroll: 1, loadonce: false, autowidth: true, forceFit: true, rowNum: 12, rowList: [12], viewrecords: true, multiselect: true, sortname: "date", sortorder: "desc" }); $("#items_votes_webuser_grid").jqGrid( "navGrid", "#items_votes_webuser_grid_pager", { add: false, edit: false, del: true, search: false } ); } }); }); '); $navibars->add_tab_content_panel('<img src="img/icons/silk/chart_line.png" align="absmiddle" /> ' . t(353, 'Score'), array('<div id="navigate-panel-web-score-graph" style=" margin: 8px; height: 150px; width: 360px; "></div>'), 'navigate-panel-web-score', '385px', '200px'); $votes_by_score = webuser_vote::object_votes_by_score('item', $item->id); $gdata = array(); $colors = array('#0a2f42', '#62bbe8', '#1d8ec7', '#44aee4', '#bbe1f5'); foreach ($votes_by_score as $vscore) { $gdata[] = (object) array('label' => $vscore->value, 'data' => (int) $vscore->votes, 'color' => $colors[$vscore->value % count($colors)]); } $navibars->add_tab_content(' <div class="hidden" id="navigate-panel-web-data-score">' . json_encode($gdata) . '</div> '); $navibars->add_tab_content_panel('<img src="img/icons/silk/chart_line.png" align="absmiddle" /> ' . t(352, 'Votes') . ' (' . t(356, 'last 90 days') . ')', array('<div id="navigate-panel-web-votes-graph" style=" margin: 8px; height: 150px; width: 360px; "></div>'), 'navigate-panel-web-votes', '385px', '200px'); $votes_by_date = webuser_vote::object_votes_by_date('item', $item->id, 90); $navibars->add_tab_content(' <div class="hidden" id="navigate-panel-web-data-votes_by_date">' . json_encode($votes_by_date) . '</div> '); // script#9 } $nvweb_preview = NAVIGATE_PARENT . NAVIGATE_FOLDER . '/web/nvweb.php?preview=true&wid=' . $website->id . '&route='; $layout->add_script(' function navigate_items_preview() { // navigate_items_disable_spellcheck(); not needed in tinymce 4? navigate_periodic_event_delegate(); // force saving current data in history var url = "' . $nvweb_preview . '"; var active_language = $("input[name=\'language_selector[]\']:checked").val(); if($("#template").parent().css("display")=="block") url = url + "node/' . $item->id . '&lang=" + active_language + "&template=" + $("#template").val(); else // category URL url = url + item_category_path[active_language].slice(1); setTimeout(function() { window.open(url); }, 1000); } '); $events->trigger('items', 'edit', array('item' => &$item, 'navibars' => &$navibars, 'naviforms' => &$naviforms)); } $layout->add_script(' $.getScript("lib/packages/items/items.js?r=' . $current_version->revision . '", function() { if(typeof navigate_items_onload == "function") navigate_items_onload(); }); '); return $navibars->generate(); }
function nvweb_block_enabled($object) { global $current; $enabled = $object->enabled == '1'; $enabled = $enabled && (empty($object->date_published) || $object->date_published < core_time()); $enabled = $enabled && (empty($object->date_unpublish) || $object->date_unpublish > core_time()); // check access if (isset($object->access)) { $access = true; switch ($object->access) { case 2: // accessible to NOT SIGNED IN visitors $access = empty($current['webuser']); break; case 1: // accessible to WEB USERS ONLY $access = !empty($current['webuser']); break; case 0: // accessible to EVERYBODY // accessible to EVERYBODY default: $access = true; } $enabled = $enabled && $access; } // selection/exclusion of free association items (category filter is already integrated in the query) if ($current['type'] == 'item' && $current['object']->association == "free") { $elements = @json_decode($object->elements, true); if (!empty($elements)) { if (!empty($elements['selection'])) { if (!in_array($current['id'], $elements['selection'])) { $enabled = false; } } if (!empty($elements['exclusions'])) { if (in_array($current['id'], $elements['exclusions'])) { $enabled = false; } } } } return $enabled; }
public static function social_network_profile_update($network, $network_user_id, $extra = '', $data = array()) { global $DB; global $webuser; global $website; if (is_array($extra)) { $extra = serialize($extra); } // the profile exists? $swuser = $DB->query_single('webuser', 'nv_webuser_profiles', ' network = ' . protect($network) . ' AND ' . ' network_user_id = ' . protect($network_user_id)); // the webuser already exists/is logged in? $wuser = new webuser(); if (!empty($webuser->id)) { // an existing webuser is already signed in, but we don't have his/her social profile if (empty($swuser)) { $DB->execute(' INSERT nv_webuser_profiles (id, network, network_user_id, webuser, extra) VALUES ( 0, :network, :network_user_id, :webuser, :extra )', array('network' => $network, 'network_user_id' => $network_user_id, 'webuser' => $webuser->id, 'extra' => $extra)); } $wuser->load($webuser->id); } else { // there is no webuser logged in if (empty($swuser)) { // and we don't have any social profile that matches the one used to sign in // Ex. Signed in with Facebook without having a previous webuser account in the current website $wuser->website = $website->id; $wuser->joindate = core_time(); $wuser->lastseen = core_time(); $wuser->access = 0; $wuser->insert(); $DB->execute(' INSERT nv_webuser_profiles (id, network, network_user_id, webuser, extra) VALUES ( 0, :network, :network_user_id, :webuser, :extra )', array('network' => $network, 'network_user_id' => $network_user_id, 'webuser' => $wuser->id, 'extra' => $extra)); } else { // BUT we have a social profile matching a previous webuser in database // Ex. Signed in with Facebook having a webuser account previously $wuser->load($swuser); } } // either way, now we have a webuser account that we need to update foreach ($data as $field => $value) { $wuser->{$field} = $value; } $wuser->update(); return $wuser->id; }
public static function generate_feed($id = NULL) { global $current; global $website; global $DB; if (empty($id)) { $id = $current['id']; } $item = new feed(); $item->load($id); $permission = nvweb_object_enabled($item); if (!$permission) { return; } $feed = new UniversalFeedCreator(); $feed->encoding = 'UTF-8'; $feed->title = $item->dictionary[$current['lang']]['title']; $feed->description = $item->dictionary[$current['lang']]['description']; $feed->link = $website->absolute_path(); $feed->syndicationURL = $website->absolute_path() . $item->paths[$current['lang']]; if (!empty($item->image)) { $image = new FeedImage(); $image->url = $website->absolute_path() . '/object?type=image&id=' . $item->image; $image->link = $website->absolute_path(); //$image->description = $vars['dictionary_description']; $feed->image = $image; } if (!empty($item->categories[0])) { $limit = intval($item->entries); if ($limit <= 0) { $limit = 10; } $DB->query(' SELECT SQL_CALC_FOUND_ROWS i.id, i.permission, i.date_published, i.date_unpublish, i.date_to_display, COALESCE(NULLIF(i.date_to_display, 0), i.date_created) as pdate, d.text as title, i.position as position, i.galleries as galleries, i.template as template FROM nv_items i, nv_structure s, nv_webdictionary d WHERE i.category IN(' . implode(",", $item->categories) . ') AND i.website = ' . $website->id . ' AND i.permission = 0 AND (i.date_published = 0 OR i.date_published < ' . core_time() . ') AND (i.date_unpublish = 0 OR i.date_unpublish > ' . core_time() . ') AND s.id = i.category AND (s.date_published = 0 OR s.date_published < ' . core_time() . ') AND (s.date_unpublish = 0 OR s.date_unpublish > ' . core_time() . ') AND s.permission = 0 AND (s.access = 0) AND (i.access = 0) AND d.website = i.website AND d.node_type = "item" AND d.subtype = "title" AND d.node_id = i.id AND d.lang = ' . protect($current['lang']) . ' ORDER BY pdate DESC LIMIT ' . $limit . ' OFFSET 0'); $rs = $DB->result(); for ($x = 0; $x < count($rs); $x++) { if (nvweb_object_enabled($rs[$x])) { $texts = webdictionary::load_element_strings('item', $rs[$x]->id); $paths = path::loadElementPaths('item', $rs[$x]->id); $fitem = new FeedItem(); $fitem->title = $texts[$current['lang']]['title']; $fitem->link = $website->absolute_path() . $paths[$current['lang']]; switch ($item->content) { case 'title': // no description break; case 'content': $fitem->description = $texts[$current['lang']]['section-main']; break; case 'summary': default: $fitem->description = $texts[$current['lang']]['section-main']; $fitem->description = str_replace(array('</p>', '<br />', '<br/>', '<br>'), array('</p>' . "\n", '<br />' . "\n", '<br/>' . "\n", '<br>' . "\n"), $fitem->description); $fitem->description = core_string_cut($fitem->description, 500, '…'); break; } $fitem->date = $rs[$x]->date_to_display; // find an image to attach to the item // A) first enabled image in item gallery // B) first image on properties $image = ''; if (!empty($rs[$x]->galleries)) { $galleries = mb_unserialize($rs[$x]->galleries); $photo = @array_shift(array_keys($galleries[0])); if (!empty($photo)) { $image = $website->absolute_path(false) . '/object?type=image&id=' . $photo; } } if (empty($image)) { // no image found on galleries, look for image properties $properties = property::load_properties("item", $rs[$x]->template, "item", $rs[$x]->id); for ($p = 0; $p < count($properties); $p++) { if ($properties[$p]->type == 'image') { if (!empty($properties[$p]->value)) { $image = $properties[$p]->value; } else { if (!empty($properties[$p]->dvalue)) { $image = $properties[$p]->dvalue; } } if (is_array($image)) { $image = array_values($image); $image = $image[0]; } if (!empty($image)) { $image = $website->absolute_path(false) . '/object?type=image&id=' . $image; } } // we only need the first image if (!empty($image)) { break; } } } if (!empty($image)) { $fitem->image = $image; // feedly will only display images of >450px --> http://blog.feedly.com/2015/07/31/10-ways-to-optimize-your-feed-for-feedly/ if (strpos($item->format, 'RSS') !== false) { $fitem->description = '<img src="' . $image . '&width=640"><br />' . $fitem->description; } } //$item->author = $contents->rows[$x]->author_name; $feed->addItem($fitem); } } // valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1 (deprecated), // MBOX, OPML, ATOM, ATOM10, ATOM0.3, HTML, JS //echo $rss->saveFeed("RSS1.0", "news/feed.xml"); } $xml = $feed->createFeed($item->format); if ($item->format == "RSS2.0") { // add extra tweaks to improve the feed $xml = str_replace('<rss ', '<rss xmlns:webfeeds="http://webfeeds.org/rss/1.0" ', $xml); // also available: // <webfeeds:cover image="http://yoursite.com/a-large-cover-image.png" />\n // <webfeeds:accentColor>00FF00</webfeeds:accentColor> $xml = str_replace('<channel>', '<channel>' . "\n\t\t" . '<webfeeds:related layout="card" target="browser" />', $xml); $xml = str_replace('<channel>', '<channel>' . "\n\t\t" . '<webfeeds:logo>' . file::file_url($item->image) . '</webfeeds:logo>', $xml); $xml = str_replace('<channel>', '<channel>' . "\n\t\t" . '<webfeeds:icon>' . file::file_url($website->favicon) . '</webfeeds:icon>', $xml); } return $xml; }
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; }
public function update() { global $DB; global $user; $message = htmlentities($this->message, ENT_COMPAT, 'UTF-8', true); $ok = $DB->execute(' UPDATE nv_comments SET item = :item, user = :user, name = :name, email = :email, url = :url, date_created = :date_created, date_modified = :date_modified, last_modified_by = :last_modified_by, reply_to = :reply_to, status = :status, message = :message WHERE id = :id ', array(":item" => value_or_default($this->item, 0), ":user" => value_or_default($this->user, 0), ":name" => empty($this->name) ? "" : $this->name, ":email" => empty($this->email) ? "" : $this->email, ":url" => empty($this->url) ? "" : $this->url, ":date_created" => $this->date_created, ":date_modified" => core_time(), ":last_modified_by" => value_or_default($user->id, 0), ":reply_to" => value_or_default($this->reply_to, 0), ":status" => value_or_default($this->status, 0), ":message" => $message, ":id" => $this->id)); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
function current_time() { $utc = core_time(); $utc_timezone = new DateTimeZone('UTC'); $utc_time = new DateTime('now', $utc_timezone); $website_timezone = new DateTimeZone($this->default_timezone); $website_time = new DateTime('now', $website_timezone); $offset = $website_timezone->getOffset($utc_time); $ts = $utc + $offset; return $ts; }
function nvweb_archive($vars = array()) { global $website; global $DB; global $current; global $webgets; $webget = "archive"; $out = array(); $permission = !empty($_SESSION['APP_USER#' . APP_UNIQUE]) ? 1 : 0; $access = !empty($current['webuser']) ? 1 : 2; if (empty($vars['categories'])) { if ($current['type'] == 'structure') { $categories = array($current['id']); } else { $categories = array($current['object']->category); } $categories = nvweb_menu_get_children($categories); } else { if (!empty($vars['categories'])) { if (!is_numeric($vars['categories']) && strpos($vars['categories'], ',') === false) { // we want to get the categories from a specific property of the current page $categories = nvweb_properties(array('property' => $vars['categories'])); if (empty($categories) && @$vars['nvlist_parent_vars']['source'] == 'block_group') { $categories = nvweb_properties(array('mode' => 'block_group_block', 'property' => $vars['categories'], 'id' => $vars['nvlist_parent_item']->id, 'uid' => $vars['nvlist_parent_item']->uid)); } if (!is_array($categories)) { $categories = explode(',', $categories); $categories = array_filter($categories); // remove empty elements } } else { $categories = explode(',', $vars['categories']); $categories = array_filter($categories); // remove empty elements } if ($vars['children'] == 'true') { $categories = nvweb_menu_get_children($categories); } } } if ($vars['search_page_type'] == 'theme') { $archive_url = $website->absolute_path() . '/nvsearch'; } else { $archive_url = nvweb_source_url($vars['search_page_type'], $vars['search_page_id']); } if (strpos($vars['nvweb_html'], 'jquery') === false) { $out[] = '<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>'; } // retrieve posts number by year, month, and... // checking if there are available in the current language (items must have custom paths assigned) $DB->query(' SELECT COUNT(i.id) AS total, MONTH(FROM_UNIXTIME(COALESCE(NULLIF(i.date_to_display, 0), i.date_created))) as month, YEAR(FROM_UNIXTIME(COALESCE(NULLIF(i.date_to_display, 0), i.date_created))) as year FROM nv_items i 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.category IN(' . implode(",", $categories) . ') AND (i.access = 0 OR i.access = ' . $access . ') AND 0 < ( SELECT COUNT(p.id) FROM nv_paths p WHERE p.website = ' . $website->id . ' AND p.type = "item" AND p.object_id = i.id AND p.lang = "' . $current['lang'] . '" ) GROUP BY year, month ORDER BY year DESC, month DESC '); $dataset = $DB->result(); switch (@$vars['mode']) { case 'month': $out[] = nvweb_archive_render('month', $dataset, $archive_url, $categories); break; case 'year': $type = 'year'; if ($vars['collapsed'] == 'true') { $type = 'year-collapsed'; } $out[] = nvweb_archive_render($type, $dataset, $archive_url, $categories); break; case 'adaptive': default: // let the webget decide the render type // ---> less or equal than 12 months in the list: month view if (count($dataset) <= 12) { $out[] = nvweb_archive_render('month', $dataset, $archive_url, $categories); } else { // year view $out[] = nvweb_archive_render('year', $dataset, $archive_url, $categories); } break; } $out = implode("\n", $out); return $out; }