Ejemplo n.º 1
0
 public function content_samples_parse($ws = null)
 {
     global $website;
     if (empty($ws) && !empty($website)) {
         $ws = $website;
     } else {
         $ws = new website();
     }
     $content_samples = array();
     $grid_samples = array('6,6', '4,4,4', '3,3,3,3', '9,3', '3,9', '8,4', '4,8', '7,5', '5,7', '6,3,3', '3,6,3', '3,3,6');
     $text = "Vis prodesset adolescens adipiscing te, usu mazim perfecto recteque at, assum putant erroribus mea in.\n";
     $text .= "Vel facete imperdiet id, cum an libris luptatum perfecto, vel fabellas inciderint ut.";
     if (!empty($this->content_samples)) {
         foreach ($this->content_samples as $cs) {
             switch ($cs->file) {
                 case 'foundation_grid':
                 case 'bootstrap_grid':
                 case 'grid':
                     $stylesheets = $ws->content_stylesheets('array', "content", false, $this);
                     $html_pre = '<html><head>';
                     if (!empty($stylesheets) && is_array($stylesheets)) {
                         foreach ($stylesheets as $ss) {
                             $html_pre .= '<link rel="stylesheet" type="text/css" href="' . $ss . '" />';
                         }
                     }
                     $html_pre .= '</head><body><div id="navigate-theme-content-sample" style=" width: 99%; ">';
                     foreach ($grid_samples as $gs) {
                         $cols = explode(',', $gs);
                         $name = "Grid &nbsp; [ ";
                         $html = $html_pre . '<div class="row">';
                         foreach ($cols as $col) {
                             $name .= $col . str_pad("", $col, "-");
                             $scol = $col * 2;
                             // set the small column to the closest step: 6 or 12
                             if ($scol >= 8) {
                                 $scol = 12;
                             }
                             if ($scol <= 7) {
                                 $scol = 6;
                             }
                             $html .= '<div class="col-md-' . $col . ' medium-' . $col . ' col-xs-' . $scol . ' small-' . $scol . ' columns">' . $text . '</div>';
                         }
                         $name .= " ]";
                         $html .= '</div>';
                         // close row
                         $html .= '<div><p>+</p></div>';
                         // add extra space under the row
                         $html .= '</div>';
                         // close copy enabled content
                         $html .= '</body></html>';
                         $content_samples[] = json_decode(json_encode(array('title' => $name, 'content' => $html)));
                     }
                     break;
                 case 'skeleton_grid':
                     $stylesheets = explode(",", $ws->content_stylesheets());
                     $translate = array(1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "fix", 6 => "six", 7 => "seven", 8 => "eight", 9 => "nine", 10 => "ten", 11 => "eleven", 12 => "twelve");
                     $html_pre = '<html><head>';
                     foreach ($stylesheets as $ss) {
                         $html_pre .= '<link rel="stylesheet" type="text/css" href="' . $ss . '" />';
                     }
                     $html_pre .= '</head><body><div id="navigate-theme-content-sample" style=" width: 99%; ">';
                     foreach ($grid_samples as $gs) {
                         $cols = explode(',', $gs);
                         $name = "Grid &nbsp; [ ";
                         $html = $html_pre . '<div class="row">';
                         foreach ($cols as $col) {
                             $name .= $col . str_pad("", $col, "-");
                             $scol = $col * 2;
                             // set the small column to the closest step: 6 or 12
                             if ($scol >= 8) {
                                 $scol = 12;
                             }
                             if ($scol <= 7) {
                                 $scol = 6;
                             }
                             $html .= '<div class="' . $translate[$col] . ' columns">' . $text . '</div>';
                         }
                         $name .= " ]";
                         $html .= '</div>';
                         // close row
                         $html .= '<div><p>+</p></div>';
                         // add extra space under the row
                         $html .= '</div>';
                         // close copy enabled content
                         $html .= '</body></html>';
                         $content_samples[] = json_decode(json_encode(array('title' => $name, 'content' => $html)));
                     }
                     break;
                 default:
                     $content_samples[] = $cs;
             }
         }
         $this->content_samples = $content_samples;
     }
 }
Ejemplo n.º 2
0
    public function editorfield($name, $value, $width = "80%", $lang = "es", $website_id = NULL)
    {
        global $layout;
        global $website;
        global $user;
        $height = 400;
        $ws = $website;
        if (!empty($website_id) && $website_id != $website->id) {
            $ws = new website();
            $ws->load($website_id);
        }
        $text = htmlentities($value, ENT_HTML5 | ENT_NOQUOTES, 'UTF-8', true);
        // remove unneeded new lines (to fix a problem of extra spaces in pre/code tags)
        $text = str_replace('&NewLine;', '', $text);
        $out = '<textarea name="' . $name . '" id="' . $name . '" style=" width: ' . $width . '; height: ' . $height . 'px; ">' . $text . '</textarea>';
        $content_css = $ws->content_stylesheets('tinymce', 'content');
        $content_css_selectable = $ws->content_stylesheets('tinymce', 'content_selectable');
        /* disabled for tiny mce 4.x, problems with the compressor
                // remove cache if the server address has changed
                $tinymce_gz = glob(NAVIGATE_PATH.'/lib/external/tinymce4/*.gz');
        
                if(!empty($tinymce_gz))
                {
                    if(file_exists(NAVIGATE_PATH.'/lib/external/tinymce4/server_name'))
                    {
                        $server_name = file_get_contents(NAVIGATE_PATH.'/lib/external/tinymce4/server_name');
                        if($server_name != md5($_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']))
                            @unlink($tinymce_gz[0]);
                    }
                    file_put_contents(NAVIGATE_PATH.'/lib/external/tinymce4/server_name', md5($_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']));
                }
        		*/
        $tinymce_language = $user->language;
        $layout->add_script('    
            tinyMCE.baseURL = "' . NAVIGATE_URL . '/lib/external/tinymce4";
            $("#' . $name . '").tinymce(
            {
                language: "' . $tinymce_language . '",
                
                width: ($("#' . $name . '").width()) + "px",
                height: $("#' . $name . '").height() + "px",
                resize: "both",
                
                menubar: false,
                theme: "modern",
                skin: "navigatecms-cupertino",
                			    
			    plugins: [
				    "compat3x noneditable",
				    "advlist autolink nv_link image lists charmap print preview hr anchor pagebreak",
				    "searchreplace wordcount visualblocks visualchars fullscreen media nonbreaking",
				    "table directionality template textcolor paste textcolor colorpicker textpattern",
				    "codesample codemirror imagetools importcss paste magicline fontawesome nv_rollups" // add fullpage to edit full HTML code with head and body tags
				],
				
				external_plugins: {
				    "loremipsum": "' . NAVIGATE_URL . '/lib/external/tinymce4/plugins/loremipsum/editor_plugin.js",
				    "imgmap": "' . NAVIGATE_URL . '/lib/external/tinymce4/plugins/imgmap/editor_plugin.js",
				    "style": "' . NAVIGATE_URL . '/lib/external/tinymce4/plugins/style/editor_plugin.js",
				    "xhtmlxtras": "' . NAVIGATE_URL . '/lib/external/tinymce4/plugins/xhtmlxtras/editor_plugin.js"
				},
				
				toolbar: [
					"formatselect fontselect fontsizeselect | forecolor | backcolor | removeformat | searchreplace code",
                    "bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | outdent indent blockquote | bullist numlist | nv_rollup_special_char",
                    "styleselect | styleprops attribs | table | nv_rollup_links | image imgmap media codesample | magicline | undo redo"
                ],

				toolbar_items_size: "small",
				
				// forced fix to avoid tinymce adding <p> element on non block elements (span, i, etc)
				// needed mainly for Codemirror plugin, but force_p_newlines is deprecated by the TinyMCE team
				forced_root_block: "",
				force_br_newlines : true,
                force_p_newlines : true,
				
			    browser_spellcheck: true,
                spellchecker_language: "' . $lang . '",
                
                noneditable_noneditable_class: "fa",    // without this, TinyMCE removes the Font Awesome icons when editing the content
                
                media_live_embeds: false, // disable iframe loading (like videos) to allow resizing
                
                magicline_color: "#0070a3",
                magicline_targetedItems: ["DIV", "IMG", "IFRAME", "PRE", "TABLE", "ARTICLE", "UL", "OL", "BLOCKQUOTE"],
                magicline_triggerMargin: 16,
			    
			    codemirror: {
					path:  "' . NAVIGATE_URL . '/lib/external/codemirror",
				    indentOnInit: true,
                    config: {
                        mode: "htmlmixed",
                        lineNumbers: true
                    },
                    jsFiles: [
                        "mode/htmlmixed/htmlmixed.js"
                    ]
				},
				
				image_advtab: true,
				
				automatic_uploads: true,
			    paste_data_images: true,
				images_upload_url: "navigate_upload.php?engine=tinymce&session_id=' . session_id() . '&debug",
				
				fontsize_formats: "8px 9px 10px 11px 12px 13px 14px 15px 16px 17px 18px 20px 24px 26px 28px 30px 32px 36px", 
                
                content_css: "' . $content_css . '",
                
				style_formats_merge: true,
                importcss_append: false,
                importcss_file_filter: function(value) 
                {
                    var files = "' . $content_css_selectable . '";
                    
                    if(files.indexOf(",") > -1)
                    {
                        files = files.split(",");
	                    for(var i=0; i<files.length; i++)
	                    {
	                        if(value.indexOf(files[i]) !== -1)
	                        {
	                            return true;
	                        }
	                    }
	                    return false;
                    }
                    else
                    {
                        return (value==files);
                    }
                },               
                                
                //  https://www.tinymce.com/docs/configure/url-handling
                convert_urls: false,
                relative_urls: true,
                remove_script_host: false,
                
                // https://www.tinymce.com/docs/configure/content-filtering/
                valid_elements: "*[*],+a[*],+p[*],#i",
                custom_elements: "nv,code,pre,nvlist,nvlist_conditional,figure,article,header,footer,post,nav",
                extended_valid_elements: "+nv[*],+pre[*],+code[*],+nvlist[*],+nvlist_conditional[*],+figure[*],+article[*],+nav[*],+i[*],+span[*],+em[*],+b[*],*[*]",
                valid_children: "+a[div|p|li],+body[style|script|nv|nvlist|nvlist_conditional],+code[nv|nvlist|nvlist_conditional]",
                
                paste_as_text: true,
                
                // https://www.tinymce.com/docs/configure/content-filtering/#allow_html_in_named_anchor
                allow_html_in_named_anchor: true,          
                
                // events
                handle_event_callback : "navigate_tinymce_event",
                
                // before rendering this tinymce
                setup: function(editor)
                {
	                editor.on("init", function() 
	                { 
				        $(editor.getWin()).bind("scroll blur focus", function(e)
				        {
                            navigate_tinymce_event(e, "' . $name . '");
				        });
				        
				        // restore last known iframe scroll position
				        navigate_tinymce_event({type: "focus"}, "' . $name . '", true);
	                    setTimeout(function()
	                    {
	                        navigate_tinymce_event({type: "focus"}, "' . $name . '", true);
	                    }, 25);
				    });			    				    
                },
                
                // just after rendering this tinymce 
                init_instance_callback: function(editor)
                {                           
					// find missing images
					$("#' . $name . '").parent().find("iframe").contents().find("img").each(function()
					{
						if( (typeof this.naturalWidth != "undefined" && this.naturalWidth == 0 ) 
					        || this.readyState == "uninitialized" )					         
				        {
					        $(this).addClass("nomagicline");
					    }
					});
                
                    $("#' . $name . '").parent().find("iframe").droppable(
                    {
                        drop: function(event, ui)
                        {
                            if(!$(ui.draggable).attr("id")) // not a file!
                            {
                                $("#' . $name . '_tbl").css("opacity", 1);
                                return;
                            }

                            var file_id = $(ui.draggable).attr("id").substring(5);
                            if(!file_id || file_id=="" || file_id==0) return;
                            var media = $(ui.draggable).attr("mediatype");
                            var mime = $(ui.draggable).attr("mimetype");
                            var web_id = "' . $ws->id . '";
                            navigate_tinymce_add_content($("#' . $name . ':tinymce").attr("id"), file_id, media, mime, web_id, ui.draggable);
                            $("#' . $name . '").parent().find("> .mce-tinymce").css("opacity", 1);
                        },
                        over: function(event, ui)
                        {
                            if(!$(ui.draggable).attr("id")) // not a file!
                                return;

                            $("#' . $name . '").parent().find("> .mce-tinymce").css("opacity", 0.75);
                        },
                        out: function(event, ui)
                        {
                            $("#' . $name . '").parent().find("> .mce-tinymce").css("opacity", 1);
                        }
                    });
                    
                    // deprecated, but the only way we found to set the button on on init
	                tinyMCE.get("' . $name . '").controlManager.setActive("magicline", true);	                
                }
            });
        ');
        $layout->navigate_editorfield_link_dialog();
        return $out;
    }