public static function save_properties_from_array($object_type, $object_id, $template, $properties_assoc = array(), $ws = null, $node_uid = "")
    {
        global $DB;
        global $website;
        global $theme;
        if (empty($ws)) {
            $ws = $website;
        }
        $dictionary = array();
        $property_object_type = $object_type;
        // object_type: item, structure, block, block_group_block
        if ($object_type == 'block_group_block') {
            // we have to identify the block subtype: block, block_type, block_group_block or extension_block
            // so we can get its properties definition
            if (!is_numeric($object_id)) {
                // assume there can only be one block group of the same type
                $block_group_id = $DB->query_single('MAX(id)', 'nv_block_groups', ' code = ' . protect($template) . ' AND website = ' . $ws->id);
                $object_id = $block_group_id;
                if (empty($block_group_id)) {
                    $object_id = 0;
                }
            }
            if (!empty($node_uid)) {
                $bg = new block_group();
                $bg->load($object_id);
                for ($b = 0; $b < count($bg->blocks); $b++) {
                    if ($bg->blocks[$b]['uid'] == $node_uid) {
                        $block_id = $bg->blocks[$b]['id'];
                        if ($bg->blocks[$b]['type'] == 'extension') {
                            // an extension block
                            $property_object_type = 'block_group-extension-block';
                            // load the extension, if installed in this instance
                            $extension = new extension();
                            $extension->load($bg->blocks[$b]['extension']);
                            // find the property declaration in the extension definition
                            if (isset($extension->definition->blocks)) {
                                for ($eb = 0; $eb < count($extension->definition->blocks); $eb++) {
                                    if ($extension->definition->blocks[$eb]->id == $block_id) {
                                        $block = $extension->definition->blocks[$eb];
                                        break;
                                    }
                                }
                            } else {
                                // ignore this property, extension is not installed or it does not have the requested block definition
                                continue;
                            }
                        } else {
                            // a block group block
                            $property_object_type = 'block_group_block';
                            $block = block::block_group_block($template, $block_id);
                        }
                        // note: standard blocks don't "embed" their properties in a block group,
                        // they have their own separate values
                        break;
                    }
                }
            } else {
                // compatibility with < Navigate 2.1 themes (to be removed)
                $properties_names = array_keys($properties_assoc);
                $block = block::block_group_block_by_property($properties_names[0]);
            }
            if (!isset($block->properties) || empty($block->properties)) {
                return false;
            }
            $properties = $block->properties;
        } else {
            $properties = property::elements($template, $object_type);
        }
        if (!is_array($properties)) {
            $properties = array();
        }
        foreach ($properties as $property) {
            if (!isset($properties_assoc[$property->name]) && !isset($properties_assoc[$property->id])) {
                continue;
            }
            $values_dict = array();
            $value = '';
            // we try to find the property value by "property name", if empty then we try to find it via "property id"
            if (isset($properties_assoc[$property->name])) {
                $value = $properties_assoc[$property->name];
            }
            if (empty($value)) {
                $value = $properties_assoc[$property->id];
            }
            // multilanguage property?
            if (in_array($property->type, array('text', 'textarea', 'link', 'rich_textarea')) || @$property->multilanguage == 'true' || @$property->multilanguage === true) {
                if (isset($properties_assoc[$property->name])) {
                    $values_dict = $properties_assoc[$property->name];
                }
                if (empty($values_dict)) {
                    $values_dict = $properties_assoc[$property->id];
                }
                $value = '[dictionary]';
            }
            if ($property->type == 'coordinates') {
                if (is_array($value)) {
                    $value = $value['latitude'] . '#' . $value['longitude'];
                }
                // if it isn't an array, then we suppose it already has the right format
            }
            // property->type "decimal"; we don't need to reconvert, it should already be in the right format
            if ($property->type == 'webuser_groups' && !empty($value)) {
                $value = 'g' . implode(',g', $value);
            }
            // boolean (checkbox): if not checked,  form does not send the value
            if ($property->type == 'boolean' && empty($value)) {
                $value = 0;
            }
            if (is_null($value)) {
                $value = "";
            }
            // should not be needed because of value_or_default, but doing this here fixes some warnings
            // remove the old property value row
            $DB->execute('
				DELETE FROM nv_properties_items
                	  WHERE property_id = ' . protect($property->id) . '
                        AND element = ' . protect($property_object_type) . '
                        AND node_id = ' . protect($object_id) . (empty($node_uid) ? '' : ' AND node_uid = ' . protect($node_uid)) . '
                        AND website = ' . $ws->id);
            // now we insert a new row
            $DB->execute('
			    INSERT INTO nv_properties_items
				    (id, website, property_id, element, node_id, node_uid, name, value)
				VALUES
				    (   0,
						:website,
						:property_id,
						:type,
						:object_id,
						:node_uid,
						:name,
						:value
                    )', array(':website' => $ws->id, ':property_id' => $property->id, ':type' => $property_object_type, ':object_id' => value_or_default($object_id, 0), ':node_uid' => value_or_default($node_uid, ""), ':name' => $property->name, ':value' => value_or_default($value, "")));
            // $error = $DB->get_last_error();
            // set the dictionary for the multilanguage properties
            $default_language = '';
            if (isset($property->multilanguage) && ($property->multilanguage === 'false' || $property->multilanguage === false)) {
                $default_language = $ws->languages_list[0];
            }
            if (in_array($property->type, array('text', 'textarea', 'rich_textarea', 'link')) || @$property->multilanguage == 'true' || @$property->multilanguage === true) {
                foreach ($ws->languages_list as $lang) {
                    if (!empty($default_language)) {
                        // property is NOT multilanguage, use the first value for all languages
                        $dictionary[$lang]['property-' . $property->id . '-' . $lang] = $values_dict[$default_language];
                    } else {
                        $dictionary[$lang]['property-' . $property->id . '-' . $lang] = $values_dict[$lang];
                    }
                }
            }
        }
        if (!empty($dictionary)) {
            webdictionary::save_element_strings('property-' . $property_object_type, $object_id, $dictionary, $ws->id, $node_uid);
        }
        return true;
    }
Example #2
0
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>' . '&nbsp;&nbsp;|&nbsp;&nbsp;' . '<a style=" color: #008830" href="' . $base_url . '?nv_approve_comment&id=' . $comment->id . '&hash=' . $hash . '">' . t(258, "Publish") . '</a>' . '&nbsp;&nbsp;|&nbsp;&nbsp;' . '<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>&nbsp;</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 . '&amp;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;">&nbsp;</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;
}
Example #3
0
function blocks_type_form($item)
{
    global $user;
    global $DB;
    global $website;
    global $layout;
    global $events;
    $navibars = new navibars();
    $naviforms = new naviforms();
    if (empty($item['id'])) {
        $navibars->title(t(23, 'Blocks') . ' / ' . t(167, 'Types') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(23, 'Blocks') . ' / ' . t(167, 'Types') . ' / ' . t(170, 'Edit') . ' [' . $item['id'] . ']');
    }
    $readonly = false;
    if (empty($item['id'])) {
        $navibars->add_actions(array('<a href="#" onclick="$(\'#navigate-content\').find(\'form\').eq(0).submit();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>'));
    } else {
        if (!empty($item['id']) && !is_numeric($item['id'])) {
            $layout->navigate_notification(t(432, "Read only mode"), false, true);
            $readonly = true;
        } else {
            $navibars->add_actions(array('<a href="#" onclick="$(\'#navigate-content\').find(\'form\').eq(0).submit();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>', '<a href="#" onclick="navigate_delete_dialog();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '</a>'));
            $layout->add_script('
            function navigate_delete_dialog()
            {
                navigate_confirmation_dialog(
                    function() { window.location.href = "?fid=blocks&act=block_type_delete&id=' . $item['id'] . '"; }, 
                    null, null, "' . t(35, 'Delete') . '"
                );
            }
        ');
        }
    }
    $group_blocks_links = array();
    list($bg_rs, $bg_total) = block_group::paginated_list(0, 10, 'title', 'desc');
    if ($bg_total > 0 && $bg_total <= 10) {
        foreach ($bg_rs as $bg) {
            $group_blocks_links[] = '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_group_edit&id=' . $bg['id'] . '"><i class="fa fa-fw fa-caret-right"></i> ' . $bg['title'] . '</a>';
        }
        $events->add_actions('blocks', array('item' => null, 'navibars' => &$navibars), $group_blocks_links, '<a class="content-actions-submenu-trigger" href="?fid=' . $_REQUEST['fid'] . '&act=block_groups_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/bricks.png"> ' . t(506, 'Groups') . ' &#9662;</a>');
    }
    $navibars->add_actions(array('<a href="?fid=' . $_REQUEST['fid'] . '&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/brick.png"> ' . t(23, 'Blocks') . '</a>', !empty($group_blocks_links) ? '' : '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_groups_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/bricks.png"> ' . t(506, 'Groups') . '</a>'));
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_type_edit"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_types_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>'));
    $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>' . (!empty($item['id']) ? $item['id'] : t(52, '(new)')) . '</span>'));
    // TODO: in Navigate CMS 2.0+ add several block types (p.e. Ad (Google adsense, ...), Map (Bing, Yahoo, Google, ...))
    $block_modes = block::modes();
    $navibars->add_tab_content_row(array('<label>' . t(491, 'Class') . '</label>', $naviforms->selectfield('type', array_keys($block_modes), array_values($block_modes), $item['type'], '', false)));
    $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . '</label>', $naviforms->textfield('title', $item['title'])));
    $navibars->add_tab_content_row(array('<label>' . t(237, 'Code') . '</label>', $naviforms->textfield('code', $item['code']), '<div class="subcomment">
            <span style=" float: left; margin-left: -3px; " class="ui-icon ui-icon-lightbulb"></span>' . t(436, 'Used as a class in HTML elements') . '</div>'));
    $navibars->add_tab_content_row(array('<label>' . t(168, 'Notes') . '</label>', $naviforms->textarea('notes', $item['notes'])));
    $navibars->add_tab(t(145, "Size") . ' & ' . t(438, "Order"));
    $navibars->add_tab_content_row(array('<label>' . t(155, 'Width') . '<sup>*</sup></label>', $naviforms->textfield('width', $item['width']), 'px'));
    $navibars->add_tab_content_row(array('<label>' . t(156, 'Height') . '<sup>*</sup></label>', $naviforms->textfield('height', $item['height']), 'px'));
    $navibars->add_tab_content_row(array('<div class="subcomment italic">* ' . t(169, 'You can leave blank a field to not limit the size') . '</div>'));
    $navibars->add_tab_content_row(array('<label>&nbsp;</label>', '<a id="wikipedia_web_banner_entry" class="italic" href="http://en.wikipedia.org/wiki/Web_banner" target="_blank"><span class="ui-icon ui-icon-info" style=" float: left;"></span> ' . t(393, 'Standard banner sizes') . ' (Wikipedia)</a>'));
    $navibars->add_tab_content_row(array('<label>' . t(404, 'Order by') . '</label>', $naviforms->selectfield('order', array('theme', 'priority', 'random'), array(t('368', 'Theme'), t('66', 'Priority'), t('399', 'Random')), $item['order'])));
    $navibars->add_tab_content_row(array('<label>' . t(397, 'Maximum') . '</label>', $naviforms->textfield('maximum', $item['maximum']), '<div class="subcomment"><span class="ui-icon ui-icon-lightbulb" style=" float: left; margin-left: -3px; "></span> ' . t(400, 'Enter 0 to display all') . '</div>'));
    $layout->add_script('
        function navigate_blocks_code_generate(el)
        {
            if($("#code").val()!="")
                return;
            var title = $("#title").val();
			title = title.replace(/([\'"“”«»?:\\+\\&!¿#\\\\])/g, "");
			title = title.replace(/[.\\s]+/g, navigate["word_separator"]);
            $("#code").val(title.toLowerCase());
        }

        $("#code").on("focus", function()
        {
            if($(this).val() == "")
                navigate_blocks_code_generate();
        });
        ');
    if (!empty($item['id'])) {
        $navibars->add_tab(t(77, "Properties"));
        $table = new naviorderedtable("block_properties_table");
        $table->setWidth("550px");
        $table->setHiddenInput("block-properties-order");
        $table->setDblclickCallback("navigate_block_edit_property");
        $navibars->add_tab_content($naviforms->hidden('block-properties-order', ""));
        $table->addHeaderColumn(t(159, 'Name'), 350, true);
        $table->addHeaderColumn(t(160, 'Type'), 150);
        $table->addHeaderColumn(t(65, 'Enabled'), 50);
        $properties = property::elements($item['id'], 'block');
        $types = property::types();
        for ($p = 0; $p < count($properties); $p++) {
            $table->addRow($properties[$p]->id, array(array('content' => $properties[$p]->name, 'align' => 'left'), array('content' => $types[$properties[$p]->type], 'align' => 'left'), array('content' => '<input type="checkbox" name="property-enabled[]" value="' . $properties[$p]->id . '" disabled="disabled" id="block-type-property-enabled-' . $properties[$p]->id . '" ' . ($properties[$p]->enabled == '1' ? ' checked=checked ' : '') . ' />
                                    <label for="block-type-property-enabled-' . $properties[$p]->id . '"></label>', 'align' => 'center')));
        }
        if ($readonly) {
            $navibars->add_tab_content_row(array('<label>' . t(77, 'Properties') . '</label>', '<div>' . $table->generate() . '</div>'));
        } else {
            $navibars->add_tab_content_row(array('<label>' . t(77, 'Properties') . '</label>', '<div>' . $table->generate() . '</div>', '<div class="subcomment">
                    <img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(72, 'Drag any row to assign priorities') . '.
                     ' . t(192, 'Double click any row to edit') . '
                </div>'));
            $navibars->add_tab_content_row(array('<label>&nbsp;</label>', '<button id="block-properties-create"><img src="img/icons/silk/add.png" align="absmiddle" /> ' . t(38, 'Create') . '</button>'));
        }
        $navibars->add_content('
		<form id="block-properties-edit-dialog" style="display: none;">
			<div class="navigate-form-row">
				<label>ID</label>
				<span id="property-id-span">' . t(52, '(new)') . '</span>
				' . $naviforms->hidden('property-id', '') . '
				' . $naviforms->hidden('property-template', $item->id) . '
				' . $naviforms->hidden('property-element', "block") . '
			</div>
			<div class="navigate-form-row">
				<label>' . t(67, 'Title') . '</label>
				' . $naviforms->textfield('property-name', '') . '
			</div>
			<div class="navigate-form-row">
				<label>' . t(160, 'Type') . '</label>
				' . $naviforms->selectfield('property-type', array_keys($types), array_values($types), 'value', 'navigate_block_property_type_change()') . '
			</div>
			<div class="navigate-form-row">
				<label>' . t(200, 'Options') . '</label>
				' . $naviforms->textarea('property-options', '') . '
				<div class="subcomment">
					' . t(201, 'One line per option, formatted like this: value#title') . '
				</div>
			</div>
			<div class="navigate-form-row">
				<label>' . t(199, 'Default value') . '</label>
				' . $naviforms->textfield('property-dvalue', '') . '
				<div class="subcomment">
				    <span id="property-comment-boolean">' . t(426, 'Enter "1" for true, "0" for false') . '</span>
					<span id="property-comment-option">' . t(202, 'Enter only the value') . '</span>
					<span id="property-comment-moption">' . t(212, 'Enter the selected values separated by commas') . ': 3,5,8</span>
					<span id="property-comment-text">' . t(203, 'Same value for all languages') . '</span>
					<span id="property-comment-rating">' . t(223, 'Default is 5 stars, if you want a different number: default_value#number_of_stars') . ' 5#10</span>
					<span id="property-comment-date">' . t(50, 'Date format') . ': ' . date($user->date_format) . '</span>
					<span id="property-comment-color">' . t(442, 'Hexadecimal color code') . ': #ffffff</span>
					<span id="property-comment-country">' . t(225, 'Alpha-2 country code') . ' (es, us, uk...)</span>
					<span id="property-comment-file">' . t(204, 'ID of the file') . '</span>
					<span id="property-comment-coordinates">' . t(298, 'Latitude') . '#' . t(299, 'Longitude') . ': 40.689231#-74.044505</span>
				</div>
			</div>
			<div class="navigate-form-row">
				<label>' . t(65, 'Enabled') . '</label>
				' . $naviforms->checkbox('property-enabled', 1) . '
			</div>
		</form>');
        $layout->add_script('
			$("#block-properties-create").bind("click", function()
			{
				navigate_block_edit_property();
				return false;
			});

			function navigate_block_edit_property(el)
			{
				if(!el)	// new property
				{
					$("#property-id").val("");
					$("#property-id-span").html("' . t(52, '(new)') . '");
					$("#property-template").val("' . $item['id'] . '");
					$("#property-name").val("");
					$("#property-type").val("value");
					$("#property-element").val("block");
					$("#property-options").val("");
					$("#property-dvalue").val("");
				    $("#property-enabled").attr("checked", "checked");
				}
				else
				{
					$.ajax({
					   type: "GET",
					   async: false,
					   dateType: "json",
					   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=block_property_load&block=' . $item->id . '&id=" + $(el).attr("id"),
					   success: function(data)
					   {
						   $("#property-id-span").html(data.id);
						   $("#property-id").val(data.id);
						   $("#property-template").val(data.template);
						   $("#property-name").val(data.name);
						   $("#property-type").val(data.type);
						   $("#property-element").val("block");
						   $("#property-options").val(data.options);
						   $("#property-dvalue").val(data.dvalue);
						   if(data.enabled=="1")
							   $("#property-enabled").attr("checked", "checked");
							else
							   $("#property-enabled").removeAttr("checked");

						   var options = "";
						   for(var o in data.options)
						   {
							   options += o + "#" + data.options[o] + "\\n";
						   }
						   $("#property-options").val(options);

					   }
					 });
				}

				navigate_block_property_type_change();

				if(' . ($readonly ? 'true' : 'false') . ')
				{
                    $("#block-properties-edit-dialog").dialog(
                    {
                        title: \'<img src="img/icons/silk/pencil.png" align="absmiddle" /> ' . t(170, 'Edit') . '\',
                        resizable: true,
                        height: 360,
                        width: 650,
                        modal: true,
                    });
				}
				else // show dialog with action buttons
				{
                    $("#block-properties-edit-dialog").dialog(
                    {
                        title: \'<img src="img/icons/silk/pencil.png" align="absmiddle" /> ' . t(170, 'Edit') . '\',
                        resizable: true,
                        height: 410,
                        width: 650,
                        modal: true,
                        buttons: {
                            "' . t(58, 'Cancel') . '": function() {
                                $(this).dialog("close");
                            },
                            "' . t(35, 'Delete') . '": function() {
                                $.ajax({
                                   type: "POST",
                                   async: false,
                                   dateType: "text",
                                   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=block_property_remove",
                                   data: $("#block-properties-edit-dialog").serialize(),
                                   success: function(msg)
                                   {
                                     $("#block_properties_table").find("#" + $("#property-id").val()).remove();
                                     navigate_naviorderedtable_block_properties_table_reorder();
                                     $("#block-properties-edit-dialog").dialog("close");
                                   }
                                 });
                            },
                            "' . t(190, 'Ok') . '": function()
                            {
                                $.ajax({
                                   type: "POST",
                                   async: false,
                                   dateType: "text",
                                   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=block_property_save",
                                   data: $("#block-properties-edit-dialog").serialize(),
                                   success: function(data)
                                   {
                                       if($("#property-id").val() > 0)
                                       {
                                           // update
                                           var tr = $("#block_properties_table").find("#" + $("#property-id").val());
                                           tr.find("td").eq(0).html(data.name);
                                           tr.find("td").eq(1).html(data.type_text);
                                           tr.find("input[type=checkbox]").attr("checked", (data.enabled==1));
                                       }
                                       else
                                       {
                                           // insert
                                           var checked = "";

                                           if(data.enabled) checked = \' checked="checked" \';
                                           var tr = \'<tr id="\'+data.id+\'"><td>\'+data.name+\'</td><td>\'+data.type_text+\'</td><td align="center"><input name="property-enabled[]" id="block-type-property-enabled-\'+data.id+\'" type="checkbox" disabled="disabled" value="\'+data.id+\'" \'+checked+\' /><label for="block-type-property-enabled-\'+data.id+\'"></label></td></tr>\';
                                           $("#block_properties_table").find("tbody:last").append(tr);
                                           $("#block_properties_table").find("tr:last").on("dblclick", function() { navigate_block_edit_property(this); });
                                           $("#block_properties_table").tableDnD(
                                            {
                                                onDrop: function(table, row)
                                                {		navigate_naviorderedtable_block_properties_table_reorder();		}
                                            });
                                       }
                                       navigate_naviorderedtable_block_properties_table_reorder();
                                       $("#block-properties-edit-dialog").dialog("close");
                                   }
                                 });
                            }
                        }
                    });
                }
			}

			function navigate_block_property_type_change()
			{
				$("#property-options").parent().hide();
				$("#property-dvalue").next().find("span").hide();

				switch($("#property-type").val())
				{
					case "option":
						$("#property-options").parent().show();
						$("#property-comment-option").show();
						break;

					case "moption":
						$("#property-options").parent().show();
						$("#property-comment-moption").show();
						break;

					case "text":
					case "textarea":
					case "link":
						$("#property-comment-text").show();
						break;

					case "date":
					case "datetime":
						$("#property-comment-date").show();
						break;

					case "image":
					case "file":
						$("#property-comment-file").show();
						break;

					case "rating":
						$("#property-comment-rating").show();
						break;

                    case "color":
						$("#property-comment-color").show();
						break;

					case "coordinates":
						$("#property-comment-coordinates").show();
						break;

					case "country":
						$("#property-comment-country").show();
						break;

                    case "boolean":
						$("#property-comment-boolean").show();
						break;

					case "comment":
					case "value":
					default:
				}
			}

			navigate_naviorderedtable_block_properties_table_reorder();
		');
    }
    return $navibars->generate();
}
Example #4
0
function templates_form($item)
{
    global $user;
    global $DB;
    global $website;
    global $layout;
    $navibars = new navibars();
    $naviforms = new naviforms();
    if (empty($item->id)) {
        $navibars->title(t(20, 'Templates') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(20, 'Templates') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']');
    }
    $readonly = false;
    if (!empty($item->id) && !is_numeric($item->id)) {
        $layout->navigate_notification(t(432, "Read only mode"), false, true);
        $readonly = true;
    } else {
        if (empty($item->id)) {
            $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>'));
        } else {
            $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>', '<a href="#" onclick="navigate_delete_dialog();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '</a>'));
            $delete_html = array();
            $delete_html[] = '<div id="navigate-delete-dialog" class="hidden">' . t(57, 'Do you really want to delete this item?') . '</div>';
            $delete_html[] = '<script language="javascript" type="text/javascript">';
            $delete_html[] = 'function navigate_delete_dialog()';
            $delete_html[] = '{';
            $delete_html[] = '$("#navigate-delete-dialog").removeClass("hidden");';
            $delete_html[] = '$("#navigate-delete-dialog").dialog({
							resizable: true,
							height: 150,
							width: 300,
							modal: true,
							title: "' . t(59, 'Confirmation') . '",
							buttons: {
								"' . t(58, 'Cancel') . '": function() {
									$(this).dialog("close");
								},
								"' . t(35, 'Delete') . '": function() {
									$(this).dialog("close");
									window.location.href = "?fid=' . $_REQUEST['fid'] . '&act=4&id=' . $item->id . '";
								}
							}
						});';
            $delete_html[] = '}';
            $delete_html[] = '</script>';
            $navibars->add_content(implode("\n", $delete_html));
        }
    }
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=templates&act=2"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=templates&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>', 'search_form'));
    $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>' . (!empty($item->id) ? $item->id : t(52, '(new)')) . '</span>'));
    $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . '</label>', $naviforms->textfield('title', $item->title)));
    if ($readonly) {
        $navibars->add_tab_content_row(array('<label>' . t(82, 'File') . '</label>', '<span>' . $item->file . '</span>'));
    } else {
        $navibars->add_tab_content_row(array('<label>' . t(82, 'File') . '</label>', '<span>' . NAVIGATE_PRIVATE . '/' . $website->id . '/templates/</span>', $naviforms->textfield('file', $item->file, '236px'), empty($item->file) ? '' : '<a href="#" onclick="navigate_templates_editor();"><img src="' . NAVIGATE_URL . '/img/icons/silk/pencil.png" /></a>'));
    }
    $navibars->add_content('
		<div id="templates-file-edit-dialog" style=" display: none; ">
			<textarea name="templates-file-edit-area" id="templates-file-edit-area" style=" width: 99%; height: 98%; ">' . htmlentities(@file_get_contents(NAVIGATE_PRIVATE . '/' . $website->id . '/templates/' . $item->file), ENT_COMPAT, 'UTF-8') . '</textarea>
		</div>
	');
    $layout->add_script('
		var current_template_editor = null;
		function navigate_templates_editor()
		{
			var file = $("#file").val();

			$("#templates-file-edit-dialog").dialog(
			{
				title: \'<img src="' . NAVIGATE_URL . '/img/icons/silk/pencil.png" align="absmiddle" /> ' . t(170, 'Edit') . ' \' + file,
				resizable: true,
				draggable: true,
				width: $(window).width() - 60,
				height: $(window).height() - 50,
				position: { my: "center", at: "center", of: window },
				modal: true,
				open: function()
				{
                    current_template_editor = CodeMirror.fromTextArea(
                        $("#templates-file-edit-area")[0],
                        {
                            mode: "text/html",
                            tabMode: "indent",
                            lineNumbers: true,
                            matchBrackets: true
                        }
                    );

					$(".CodeMirror").css({ width: "99%", height: "98%"});
					$(".CodeMirror-scroll").css({ width: "100%", height: "100%"});
				},
				beforeClose: function() {
				    // dialog may be closed by clicking on a footer button or clicking the close "x" icon on top
				    if(current_template_editor)
				    {
				        current_template_editor.toTextArea();
					    current_template_editor = null;
                    }
				},
				buttons: {
					"' . t(58, 'Cancel') . '": function() {
						$("#templates-file-edit-dialog").dialog("close");
					},
					"' . t(34, 'Save') . '": function()
					{ 					
						current_template_editor.toTextArea();					
						current_template_editor = null;
						
						$.ajax({
						   type: "POST",
						   async: false,
						   dateType: "text",
						   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&id=' . $item->id . '&act=save_template_file",
						   data: $("#templates-file-edit-area").serialize(),
						   success: function(data)
						   {			
							   	if(data=="true")
								{						
									$("#templates-file-edit-dialog").dialog("close"); 
									navigate_notification("' . t(235, 'File saved successfully.') . '");
								}
								else
								{
									$("#templates-file-edit-dialog").dialog("close"); 
									navigate_notification("' . t(56, 'Unexpected error.') . '");
								}
						   }
						 });
					}					
				}				
			}).dialogExtend(
			{
				maximizable: true
			});
		}
	');
    $navibars->add_tab_content_row(array('<label>' . t(68, 'Status') . '</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, '', false, array(0 => t(360, 'Visible to everybody'), 1 => t(359, 'Visible only to Navigate CMS users'), 2 => t(358, 'Hidden to everybody')))));
    $navibars->add_tab_content_row(array('<label>' . t(62, 'Statistics') . '</label>', $naviforms->checkbox('statistics', $item->statistics)));
    $navibars->add_tab_content_row(array('<label>' . t(65, 'Enabled') . '</label>', $naviforms->checkbox('enabled', $item->enabled)));
    if (!empty($item->id)) {
        $navibars->add_tab(t(236, "Sections"));
        $table = new naviorderedtable("template_sections_table");
        $table->setWidth("600px");
        $table->setHiddenInput("template-sections-order");
        $navibars->add_tab_content($naviforms->hidden('template-sections-order', ""));
        $table->addHeaderColumn(t(237, 'Code'), 100);
        $table->addHeaderColumn(t(159, 'Name'), 250);
        $table->addHeaderColumn(t(267, 'Editor'), 100);
        $table->addHeaderColumn(t(155, 'Width'), 100);
        $table->addHeaderColumn(t(35, 'Remove'), 100);
        for ($p = 0; $p < count($item->sections); $p++) {
            $disabled = $item->sections[$p]['code'] == 'main';
            unset($selected);
            $selected = array();
            $selected[$item->sections[$p]['editor']] = ' selected="selected" ';
            $select_editor = '<select name="template-sections-editor[]" style=" width: 125px; ">';
            $select_editor .= '	<option value="tinymce" ' . $selected['tinymce'] . '>TinyMCE</option>';
            $select_editor .= '	<option value="html" ' . $selected['html'] . '>' . t(269, 'HTML code') . '</option>';
            $select_editor .= '	<option value="raw" ' . $selected['raw'] . '>' . t(268, 'Raw') . '</option>';
            $select_editor .= '</select>';
            $table->addRow($p, array(array('content' => '<input type="text" name="template-sections-code[]" value="' . $item->sections[$p]['code'] . '" style="width: 140px;" />', 'align' => 'left'), array('content' => '<input type="text" name="template-sections-name[]" value="' . template::section_name($item->sections[$p]['name']) . '" style="width: 290px;" />', 'align' => 'left'), array('content' => $select_editor, 'align' => 'left'), array('content' => '<div style=" white-space: nowrap; "><input type="text" name="template-sections-width[]" value="' . template::section_name($item->sections[$p]['width']) . '" style="width: 40px;" /> px</div>', 'align' => 'left'), array('content' => !empty($disabled) || $readonly ? '' : '<img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" onclick="navigate_templates_sections_remove(this);" />', 'align' => 'center')));
        }
        if ($readonly) {
            $navibars->add_tab_content_row(array('<label>' . t(236, 'Sections') . '</label>', '<div>' . $table->generate() . '</div>'));
        } else {
            $navibars->add_tab_content_row(array('<label>' . t(236, 'Sections') . '</label>', '<div>' . $table->generate() . '</div>', '<div class="subcomment">
                                                        <img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(72, 'Drag any row to assign priorities') . '.
                                                         ' . t(192, 'Double click any row to edit') . '
                                                    </div>'));
            $navibars->add_tab_content_row(array('<label>&nbsp;</label>', '<button id="templates-sections-create"><img src="img/icons/silk/add.png" align="absmiddle" style="cursor:pointer;" /> ' . t(38, 'Create') . '</button>'));
        }
        $navibars->add_content('
			<form id="templates-sections-edit-dialog" style="display: none;">
				' . $naviforms->hidden('section-id', '') . '
				<div class="navigate-form-row">
					<label>' . t(67, 'Title') . '</label>
					' . $naviforms->textfield('section-name', '') . '
				</div>
				<div class="navigate-form-row">
					<label>' . t(237, 'Code') . '</label>
					' . $naviforms->textfield('section-code', '') . '					
				</div>			
			</form>');
        $section_widths = templates_section_widths();
        $layout->add_script('
			$("#templates-sections-create").on("click", function() {
				var tr = \'<tr id="\'+(new Date().getTime())+\'">\';
				tr += \'<td><input type="text" name="template-sections-code[]" value="" style="width: 140px;" /></td>\';
				tr += \'<td><input type="text" name="template-sections-name[]" value="" style="width: 290px;" /></td>\';
				tr += \'<td><select style="width: 125px;" name="template-sections-editor[]"><option selected="selected" value="tinymce">TinyMCE</option><option value="html">' . t(269, 'HTML code') . '</option><option value="raw">' . t(268, 'Raw') . '</option></select></td>\';
				tr += \'<td><div style="white-space: nowrap;"><input type="text" style="width: 40px;" value="950" name="template-sections-width[]"> px</div></td>\';
				tr += \'<td align="center"><img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" onclick="navigate_templates_sections_remove(this);" style="cursor:pointer;" /></td>\';				
				tr += \'</tr>\';
				
				$("#template_sections_table").find("tbody:last").append(tr);
				$("#template_sections_table").tableDnD(
				{
					onDrop: function(table, row) 
					{		navigate_naviorderedtable_template_sections_table_reorder();		}
				});			

				$(\'input[name="template-sections-width[]"]\').autocomplete(
				{
					source: function(request, response) { response(' . json_encode($section_widths) . '); },
					minLength: 0			
				});				

				return false;
			});
			
			function navigate_templates_sections_remove(el)
			{				
				$(el).parent().parent().remove();
			}
			
			$(\'input[name="template-sections-width[]"]\').autocomplete(
			{
				source: function(request, response) { response(' . json_encode($section_widths) . '); },
				minLength: 0			
			});
			
			$(document).on(\'click\', \'input[name="template-sections-width[]"]\', function()			
			{
				$(this).autocomplete( "search" , $(this).val());
			});
		');
        $navibars->add_tab_content_row(array('<label>' . t(210, 'Gallery') . '</label>', $naviforms->checkbox('gallery', $item->gallery)));
        $navibars->add_tab_content_row(array('<label>' . t(250, 'Comments') . '</label>', $naviforms->checkbox('comments', $item->comments)));
        $navibars->add_tab_content_row(array('<label>' . t(265, 'Tags') . '</label>', $naviforms->checkbox('tags', $item->tags)));
        $navibars->add_tab(t(77, "Properties"));
        $table = new naviorderedtable("template_properties_table");
        $table->setWidth("550px");
        $table->setHiddenInput("template-properties-order");
        $table->setDblclickCallback("navigate_templates_edit_property");
        $navibars->add_tab_content($naviforms->hidden('template-properties-order', ""));
        $table->addHeaderColumn(t(159, 'Name'), 250, true);
        $table->addHeaderColumn(t(160, 'Type'), 150);
        $table->addHeaderColumn(t(87, 'Association'), 100);
        $table->addHeaderColumn(t(65, 'Enabled'), 50);
        $properties = property::elements($item->id);
        $types = property::types();
        $element_types = array('item' => t(180, 'Item'), 'structure' => t(16, 'Structure'));
        for ($p = 0; $p < count($properties); $p++) {
            $table->addRow($properties[$p]->id, array(array('content' => $properties[$p]->name, 'align' => 'left'), array('content' => $types[$properties[$p]->type], 'align' => 'left'), array('content' => $element_types[$properties[$p]->element], 'align' => 'left'), array('content' => '<input type="checkbox" name="property-enabled[]" class="raw-checkbox" value="' . $properties[$p]->id . '" ' . ($properties[$p]->enabled == '1' ? ' checked=checked ' : '') . ' />', 'align' => 'center')));
        }
        if ($readonly) {
            $navibars->add_tab_content_row(array('<label>' . t(77, 'Properties') . '</label>', '<div>' . $table->generate() . '</div>'));
        } else {
            $navibars->add_tab_content_row(array('<label>' . t(77, 'Properties') . '</label>', '<div>' . $table->generate() . '</div>', '<div class="subcomment">
                                                        <img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(72, 'Drag any row to assign priorities') . '.
                                                         ' . t(192, 'Double click any row to edit') . '
                                                    </div>'));
            $navibars->add_tab_content_row(array('<label>&nbsp;</label>', '<button id="templates-properties-create"><img src="img/icons/silk/add.png" align="absmiddle" /> ' . t(38, 'Create') . '</button>'));
        }
        $navibars->add_content('
		<form id="templates-properties-edit-dialog" style="display: none;">
			<div class="navigate-form-row">
				<label>ID</label>
				<span id="property-id-span">' . t(52, '(new)') . '</span>
				' . $naviforms->hidden('property-id', '') . '
				' . $naviforms->hidden('property-template', $item->id) . '			
			</div>	
			<div class="navigate-form-row">
				<label>' . t(67, 'Title') . '</label>
				' . $naviforms->textfield('property-name', '') . '
			</div>
			<div class="navigate-form-row">
				<label>' . t(87, 'Association') . '</label>
				' . $naviforms->selectfield('property-element', array_keys($element_types), array_values($element_types), 'value') . '
			</div>			
			<div class="navigate-form-row">
				<label>' . t(160, 'Type') . '</label>
				' . $naviforms->selectfield('property-type', array_keys($types), array_values($types), 'value', 'navigate_templates_property_type_change()') . '
			</div>
			<div class="navigate-form-row">
				<label>' . t(200, 'Options') . '</label>
				' . $naviforms->textarea('property-options', '') . '
				<div class="subcomment">
					' . t(201, 'One line per option, formatted like this: value#title') . '
				</div>				
			</div>
			<div class="navigate-form-row">
				<label>' . t(547, 'Multilanguage') . '</label>
				' . $naviforms->checkbox('property-multilanguage', false) . '
			</div>
			<div class="navigate-form-row">
				<label>' . t(199, 'Default value') . '</label>
				' . $naviforms->textfield('property-dvalue', '') . '	
				<div class="subcomment">
				    <span id="property-comment-boolean">' . t(426, 'Enter "1" for true, "0" for false') . '</span>
					<span id="property-comment-option">' . t(202, 'Enter only the value') . '</span>
					<span id="property-comment-moption">' . t(212, 'Enter the selected values separated by commas') . ': 3,5,8</span>
					<span id="property-comment-text">' . t(203, 'Same value for all languages') . '</span>
					<span id="property-comment-rating">' . t(223, 'Default is 5 stars, if you want a different number: default_value#number_of_stars') . ' 5#10</span>
					<span id="property-comment-date">' . t(50, 'Date format') . ': ' . date($user->date_format) . '</span>										
					<span id="property-comment-color">' . t(442, 'Hexadecimal color code') . ': #ffffff</span>
					<span id="property-comment-country">' . t(225, 'Alpha-2 country code') . ' (es, us, uk...)</span>
					<span id="property-comment-file">' . t(204, 'ID of the file') . '</span>
					<span id="property-comment-video">' . t(490, 'ID of the file or public video URL') . '</span>
					<span id="property-comment-coordinates">' . t(298, 'Latitude') . '#' . t(299, 'Longitude') . ': 40.689231#-74.044505</span>
				</div>
			</div>
			<div class="navigate-form-row">
				<label>' . t(65, 'Enabled') . '</label>
				' . $naviforms->checkbox('property-enabled', 1) . '
			</div>
            <div class="navigate-form-row">
				<label>' . t(550, 'Help text') . '</label>
				' . $naviforms->textfield('property-helper', '') . '
			</div>
		</form>');
        $layout->add_script('
			$("#templates-properties-create").bind("click", function()
			{
				navigate_templates_edit_property();
				return false;
			});
		
			function navigate_templates_edit_property(el)
			{
				if(!el)	// new property
				{
					$("#property-id").val("");
					$("#property-id-span").html("' . t(52, '(new)') . '");
					$("#property-element").val("template");
					$("#property-template").val("' . $item->id . '");
					$("#property-name").val("");
					$("#property-type").val("value");
					$("#property-options").val("");
					$("#property-dvalue").val("");
					$("#property-helper").val("");
					$("#property-multilanguage").removeAttr("checked");
				    $("#property-enabled").attr("checked", "checked");
				}
				else
				{
					$.ajax({
					   type: "GET",
					   async: false,
					   dateType: "json",
					   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=template_property_load&template=' . $item->id . '&id=" + $(el).attr("id"),
					   success: function(data)
					   {
						   $("#property-id-span").html(data.id);
						   $("#property-id").val(data.id);
						   $("#property-element").val(data.element);
						   $("#property-template").val(data.template);
						   $("#property-name").val(data.name);
						   $("#property-type").val(data.type);
						   $("#property-options").val(data.options);
						   $("#property-dvalue").val(data.dvalue);
						   $("#property-helper").val(data.helper);

						   if(data.multilanguage=="true")
							   $("#property-multilanguage").attr("checked", "checked");
							else
							   $("#property-multilanguage").removeAttr("checked");

						   if(data.enabled=="1")
							   $("#property-enabled").attr("checked", "checked");
							else
							   $("#property-enabled").removeAttr("checked");
							   
						   var options = "";
						   for(var o in data.options)
						   {
							   options += o + "#" + data.options[o] + "\\n";
						   }
						   $("#property-options").val(options);

					   }
					 });					
				}
				
				navigate_templates_property_type_change();
				
				var navigate_templates_element_types = new Array();
				navigate_templates_element_types["item"] = "' . t(180, 'Item') . '";
				navigate_templates_element_types["structure"] = "' . t(16, 'Structure') . '";
				//navigate_templates_element_types["product"] = "' . t(214, 'Product') . '";

				if(' . ($readonly ? 'true' : 'false') . ')
				{
                    $("#templates-properties-edit-dialog").dialog(
                    {
                        title: \'<img src="img/icons/silk/pencil.png" align="absmiddle" /> ' . t(170, 'Edit') . '\',
                        resizable: true,
                        height: 360,
                        width: 650,
                        modal: true,
                    });
				}
				else // show dialog with action buttons
				{
                    $("#templates-properties-edit-dialog").dialog(
                    {
                        title: \'<img src="img/icons/silk/pencil.png" align="absmiddle" /> ' . t(170, 'Edit') . '\',
                        resizable: true,
                        height: 410,
                        width: 650,
                        modal: true,
                        buttons: {
                            "' . t(58, 'Cancel') . '": function() {
                                $(this).dialog("close");
                            },
                            "' . t(35, 'Delete') . '": function() {
                                $.ajax({
                                   type: "POST",
                                   async: false,
                                   dateType: "text",
                                   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=template_property_remove",
                                   data: $("#templates-properties-edit-dialog").serialize(),
                                   success: function(msg)
                                   {
                                     $("#template_properties_table").find("#" + $("#property-id").val()).remove();
                                     navigate_naviorderedtable_template_properties_table_reorder();
                                     $("#templates-properties-edit-dialog").dialog("close");
                                   }
                                 });
                            },
                            "' . t(190, 'Ok') . '": function()
                            {
                                $.ajax({
                                   type: "POST",
                                   async: false,
                                   dateType: "text",
                                   url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=template_property_save",
                                   data: $("#templates-properties-edit-dialog").serialize(),
                                   success: function(data)
                                   {
                                       if($("#property-id").val() > 0)
                                       {
                                           // update
                                           var tr = $("#template_properties_table").find("#" + $("#property-id").val());
                                           tr.find("td").eq(0).html(data.name);
                                           tr.find("td").eq(1).html(data.type_text);
                                           tr.find("td").eq(2).html(navigate_templates_element_types[data.element]);
                                           tr.find("input[type=checkbox]").attr("checked", (data.enabled==1));
                                       }
                                       else
                                       {
                                           // insert
                                           var checked = "";
                                           if(data.enabled) checked = \' checked="checked" \';
                                           var tr = \'<tr id="\'+data.id+\'"><td>\'+data.name+\'</td><td>\'+data.type_text+\'</td><td>\'+navigate_templates_element_types[data.element]+\'</td><td align="center"><input name="property-enabled[]" class="raw-checkbox" type="checkbox" value="\'+data.id+\'" \'+checked+\' /></td></tr>\';
                                           $("#template_properties_table").find("tbody:last").append(tr);
                                           $("#template_properties_table").find("tr:last").bind("dblclick", function() { navigate_templates_edit_property(this); });
                                           $("#template_properties_table").tableDnD(
                                            {
                                                onDrop: function(table, row)
                                                {		navigate_naviorderedtable_template_properties_table_reorder();		}
                                            });
                                       }
                                       navigate_naviorderedtable_template_properties_table_reorder();
                                       $("#templates-properties-edit-dialog").dialog("close");
                                   }
                                 });
                            }
                        }
                    });
                }
			}
			
			function navigate_templates_property_type_change()
			{
				$("#property-options").parent().hide();
				$("#property-multilanguage").parent().hide();
				$("#property-dvalue").next().find("span").hide();
				
				switch($("#property-type").val())
				{						
					case "option":
						$("#property-options").parent().show();
						$("#property-comment-option").show();
						break;
						
					case "moption":
						$("#property-options").parent().show();
						$("#property-comment-moption").show();
						break;						
						
					case "text":
					case "textarea":
					case "link":
					case "rich_textarea":
					case "source_code":
						$("#property-comment-text").show();
						break;
						
					case "date":
					case "datetime":
						$("#property-comment-date").show();
						break;
						
					case "image":
					case "file":
						$("#property-comment-file").show();
						$("#property-multilanguage").parent().show();
						break;

                    case "video":
						$("#property-comment-video").show();
						break;

					case "rating":
						$("#property-comment-rating").show();
						break;	

                    case "color":
						$("#property-comment-color").show();
						break;

					case "coordinates":
						$("#property-comment-coordinates").show();
						break;							
						
					case "country":
						$("#property-comment-country").show();
						break;

                    case "boolean":
						$("#property-comment-boolean").show();
						break;
					
					case "comment":
					case "value":
					default:
				}
			}
			
			navigate_naviorderedtable_template_properties_table_reorder();	
		');
    }
    return $navibars->generate();
}