Changeset 598213
- Timestamp:
- 09/12/2012 10:38:01 PM (13 years ago)
- Location:
- geshi-source-colorer/trunk
- Files:
-
- 1 added
- 7 edited
-
css/layout.css (modified) (5 diffs)
-
filter.class.php (modified) (6 diffs)
-
geshi-source-colorer.php (modified) (4 diffs)
-
import.class.php (modified) (1 diff)
-
js/function.js (modified) (1 diff)
-
readme.txt (modified) (5 diffs)
-
render.class.php (modified) (4 diffs)
-
screenshot-4.jpg (added)
Legend:
- Unmodified
- Added
- Removed
-
geshi-source-colorer/trunk/css/layout.css
r596394 r598213 51 51 52 52 53 54 /* ==== global configuration eg toolbar images ============================================================ */ 53 /* ==== global configuration ============================================================================== */ 55 54 /** style of a code line **/ 56 55 .geshisourcecolorer-line … … 64 63 cursor: pointer; 65 64 } 66 65 /* ======================================================================================================== */ 66 67 68 /* ==== global tab layout ================================================================================= */ 69 /** style of the container div of the tab menu **/ 70 .geshisourcecolorer-tab .tabmenu 71 { 72 overflow: hidden; 73 } 74 75 /** style of the list within the tab container **/ 76 .geshisourcecolorer-tab .tabmenu ul 77 { 78 list-style-type: none; 79 margin: 0; 80 } 81 82 /** style of the code tab items **/ 83 .geshisourcecolorer-tab .tabmenu ul li 84 { 85 cursor: pointer; 86 display: inline; 87 text-align: center; 88 margin-right: 1em; 89 padding-left: 1em; 90 padding-right: 1em; 91 font-family: sans-serif; 92 font-size: small; 93 font-weight: bold; 94 } 95 /* ======================================================================================================== */ 96 97 98 /* ==== global code container layout ====================================================================== */ 67 99 /** define the main style of the code boxex **/ 68 100 .geshisourcecolorer … … 77 109 { 78 110 list-style-position: outside; 79 margin -left: 0;80 padding -left: 0;111 margin: 0; 112 padding: 0; 81 113 } 82 114 … … 87 119 margin-left: 3em; 88 120 } 89 90 121 /* ======================================================================================================== */ 122 123 124 /* ==== global toolbar layout ============================================================================= */ 91 125 /** style of the toolbar on each block **/ 92 126 .geshisourcecolorer .toolbar … … 172 206 background-color: #ababab; 173 207 } 208 209 .geshisourcecolorer-tab-default 210 { 211 border-width: 3px; 212 border-color: #ababab; 213 border-style: solid; 214 margin-top: 0.5em; 215 margin-bottom: 0.5em; 216 } 217 218 .geshisourcecolorer-tab-default .tabmenu { 219 background:-moz-linear-gradient(top, #efefef, #cfcfcf); 220 background:-webkit-linear-gradient(top, #efefef, #cfcfcf); 221 background:-o-linear-gradient(top, #efefef, #cfcfcf); 222 background:-ms-linear-gradient(top, #efefef, #cfcfcf); 223 background:linear-gradient(top, #efefef, #cfcfcf); 224 padding: 0.25em; 225 } 226 227 .geshisourcecolorer-tab-default .tabmenu ul 228 { 229 padding: 0.25em; 230 } 231 232 .geshisourcecolorer-tab-default .tabmenu .current 233 { 234 text-decoration:underline; 235 } 174 236 /* ======================================================================================================== */ 175 237 -
geshi-source-colorer/trunk/filter.class.php
r596394 r598213 111 111 * @return regular expression 112 112 **/ 113 privatestatic function createFilterRegEx($pcTag)113 static function createFilterRegEx($pcTag) 114 114 { 115 115 // set regular expression for filtering (mask all meta character, and replace the fragments %c% (code), %s% (spaces) and %p% (parameter) ) … … 143 143 $option["hoverhighlight"] = array(); 144 144 $option["highlight"] = array(); 145 $option["tab"] = array(); 145 146 146 147 // create GeSHi instance with code and remove an linebreaks of the source … … 174 175 if (empty($option["language"])) 175 176 return __("no source code language is set", "fpx_geshisourcecolorer"); 176 177 177 178 // create GeSHi instance with code 178 179 $source = self::convertWordpress2Code($pa[4]); 179 180 $id = "geshisourcecolorer-" . (empty($option["id"]) ? md5($source) : $option["id"]); 180 181 $class = $option["css"]["block"]; 181 $action = null; 182 183 if ($option["collapse"]) 182 $prefix = null; 183 $suffix = null; 184 185 // set collapse data 186 if ( ($option["collapse"]) && (empty($option["tab"])) ) 184 187 { 185 $class .= " geshisourcecolorer-collapse";186 $ action = "<div class=\"geshisourcecolorer-collapse-button\" id=\"".$id."-collapse-button\">".$option["collapsetext"]."</div>";188 $class .= " geshisourcecolorer-collapse"; 189 $prefix .= "<span class=\"geshisourcecolorer-collapse-button\" id=\"".$id."-collapse-button\">".$option["collapsetext"]."</span>"; 187 190 } 191 192 // set tab structure 193 if (!empty($option["tab"])) 194 { 195 $prefix .= "<div class=\"geshisourcecolorer-tab ".$option["css"]["tab"]." ".$option["tab"][0]."\" rel=\"".$option["tab"][1]."\">"; 196 $suffix .= "</div>"; 197 } 198 199 188 200 189 201 $geshi = new \GeSHi( $source, $option["language"] ); … … 194 206 $lc = $geshi->error(); 195 207 if (empty($lc)) 196 return " ".$action.$geshi->parse_code()." "; 208 return " ".$prefix.$geshi->parse_code().$suffix." "; 209 197 210 return " <strong>".$lc."</strong> "; 198 211 } 199 212 213 /** actin that is run before, for replacing all character to HTML elements 214 * @param $pa input array for format 215 * @return replaced data 216 **/ 200 217 static function actionBefore($pa) 201 218 { … … 434 451 // check if the style exists, if not, try to get a style that named equal to the 435 452 // language name 436 if ( (isset($param["style"])) && (is_string($param["style"])) ) 437 $param["style"] = isset($styles[ $param["style"] ]) ? $styles[ strtolower($param["style"]) ] : $styles["default"]; 453 if ( (isset($param["style"])) && (is_string($param["style"])) && (isset($styles[ strtolower($param["style"]) ])) ) 454 $param["style"] = $styles[ strtolower($param["style"]) ]; 455 elseif ( (isset($param["style"])) && (is_string($param["style"])) && (isset($styles[strtolower($param["language"]) ])) ) 456 $param["style"] = $styles[ strtolower($param["language"]) ]; 438 457 else 439 $param["style"] = isset($styles[ $param["language"] ]) ? $styles[ strtolower($param["language"]) ] :$styles["default"];458 $param["style"] = $styles["default"]; 440 459 441 460 … … 454 473 } else 455 474 $param["hoverhighlight"] = array(); 456 475 476 // check tabbed setting 477 if ( (isset($param["tab"])) && (is_string($param["tab"])) ) 478 $param["tab"] = preg_split("/\s+/", $param["tab"], 2, PREG_SPLIT_NO_EMPTY); 479 else 480 $param["tab"] = array(); 457 481 458 482 // check other options -
geshi-source-colorer/trunk/geshi-source-colorer.php
r596533 r598213 34 34 //define(__NAMESPACE__."\LOCALPLUGINFILE", __FILE__); 35 35 define(__NAMESPACE__."\LOCALPLUGINFILE", WP_PLUGIN_DIR."/geshi-source-colorer/".basename(__FILE__)); 36 define(__NAMESPACE__."\DEBUG", false);36 define(__NAMESPACE__."\DEBUG", true); 37 37 // ================================================================================================================================================= 38 38 … … 56 56 57 57 // ==== create Wordpress Hooks ===================================================================================================================== 58 add_action("wp_head", "de\\flashpixx\\geshisourcecolorer\\initHead"); 59 add_action("wp_enqueue_scripts", "de\\flashpixx\\geshisourcecolorer\\initScripts"); 60 add_action("admin_enqueue_scripts", "de\\flashpixx\\geshisourcecolorer\\initAdminScripts"); 58 add_action("init", "de\\flashpixx\\geshisourcecolorer\\initScripts"); 59 add_filter("the_posts", "de\\flashpixx\\geshisourcecolorer\\activateScripts"); 61 60 62 61 add_action("wp_ajax_geshisourcecolorer-preview", "de\\flashpixx\\geshisourcecolorer\\filter::preview"); 63 62 add_filter("the_content", "de\\flashpixx\\geshisourcecolorer\\filter::runListOfListings"); 64 add_filter("the_content", "de\\flashpixx\\geshisourcecolorer\\filter::runCode ",1000);63 add_filter("the_content", "de\\flashpixx\\geshisourcecolorer\\filter::runCodeLineBefore", -1000); 65 64 add_filter("the_content", "de\\flashpixx\\geshisourcecolorer\\filter::runCodeBefore", -1000); 66 add_filter("the_content", "de\\flashpixx\\geshisourcecolorer\\filter::runCodeLine", 1000); 67 add_filter("the_content", "de\\flashpixx\\geshisourcecolorer\\filter::runCodeLineBefore", -1000); 68 65 add_filter("the_content", "de\\flashpixx\\geshisourcecolorer\\filter::runCodeLine"); 66 add_filter("the_content", "de\\flashpixx\\geshisourcecolorer\\filter::runCode"); 67 68 add_action("admin_enqueue_scripts", "de\\flashpixx\\geshisourcecolorer\\initAdminScripts"); 69 69 add_action("admin_menu", "de\\flashpixx\\geshisourcecolorer\\render::adminmenu"); 70 70 add_action("admin_init", "de\\flashpixx\\geshisourcecolorer\\render::optionfields"); … … 85 85 wp_register_script( "geshisourcecolorer_zeroclipboard", plugins_url("external/zeroclipboard/ZeroClipboard.min.js", LOCALPLUGINFILE) ); 86 86 wp_register_script( "geshisourcecolorer_function", plugins_url("js/function".(DEBUG ? null : ".min").".js", LOCALPLUGINFILE), array("jquery", "geshisourcecolorer_zeroclipboard") ); 87 88 wp_enqueue_script( "jquery" ); 89 wp_enqueue_script( "geshisourcecolorer_zeroclipboard" ); 90 wp_enqueue_script( "geshisourcecolorer_function" ); 91 87 wp_register_style( "geshisourcecolorer_userstyle", get_template_directory_uri()."/geshi-source-colorer.css" ); 92 88 93 89 // CSS script 94 90 wp_register_style( "geshisourcecolorer_style", plugins_url("css/layout".(DEBUG ? null : ".min").".css", LOCALPLUGINFILE) ); 95 96 // include only this files, which are needed 91 wp_register_script( "geshisourcecolorer_userfunction", get_template_directory_uri()."/geshi-source-colorer.js", array("geshisourcecolorer_function" ) ); 92 } 93 94 95 /** set up the scripts only if needed 96 * @param $posts post array 97 **/ 98 function activateScripts($posts) 99 { 100 // disable scripts on admin pages or if post is empty 101 if ( (is_admin()) || (empty($posts)) ) 102 return $posts; 103 104 // check the posts if the filter shortcut it found 97 105 $option = get_option("fpx_geshisourcecolorer_option"); 98 if ($option["maincss"]) 99 wp_enqueue_style( "geshisourcecolorer_style" ); 100 101 102 // check theme files, if there is a "geshi-source-colorer.js" and/or a "geshi-source-colorer.css" within the theme directory, we include the files 103 wp_register_style( "geshisourcecolorer_userstyle", get_template_directory_uri()."/geshi-source-colorer.css" ); 104 $css = get_theme_root()."/".get_template()."/geshi-source-colorer.css"; 105 if (file_exists($css) && is_file($css)) 106 wp_enqueue_style( "geshisourcecolorer_userstyle" ); 107 108 wp_register_script( "geshisourcecolorer_userfunction", get_template_directory_uri()."/geshi-source-colorer.js", array("geshisourcecolorer_function" ) ); 109 $js = get_theme_root()."/".get_template()."/geshi-source-colorer.js"; 110 if (file_exists($js) && is_file($js)) 111 wp_enqueue_script( "geshisourcecolorer_userfunction" ); 112 } 113 114 115 /** plugin administration page initialization **/ 116 function initAdminScripts() 117 { 106 foreach($posts as $post) 107 if ( (preg_match( filter::createFilterRegEx($option["tag"]["code"]), $post->post_content )) || (preg_match( filter::createFilterRegEx($option["tag"]["line"]), $post->post_content )) ) 108 { 109 add_action("wp_head", "de\\flashpixx\\geshisourcecolorer\\initHead"); 110 111 wp_enqueue_script( "jquery" ); 112 wp_enqueue_script( "geshisourcecolorer_zeroclipboard" ); 113 wp_enqueue_script( "geshisourcecolorer_function" ); 114 115 if ($option["maincss"]) 116 wp_enqueue_style( "geshisourcecolorer_style" ); 117 118 // check theme files, if there is a "geshi-source-colorer.js" and/or a "geshi-source-colorer.css" within the theme directory, we include the files 119 $css = get_theme_root()."/".get_template()."/geshi-source-colorer.css"; 120 if (file_exists($css) && is_file($css)) 121 wp_enqueue_style( "geshisourcecolorer_userstyle" ); 122 123 $js = get_theme_root()."/".get_template()."/geshi-source-colorer.js"; 124 if (file_exists($js) && is_file($js)) 125 wp_enqueue_script( "geshisourcecolorer_userfunction" ); 126 127 break; 128 } 129 130 // return post array 131 return $posts; 132 } 133 134 135 /** plugin administration page initialization 136 * @param $hook hook name of the enquere call 137 **/ 138 function initAdminScripts($hook) 139 { 140 // CSS script 141 wp_register_style( "geshisourcecolorer_adminstyle", plugins_url("css/administration".(DEBUG ? null : ".min").".css", LOCALPLUGINFILE) ); 142 118 143 // jQuery and function script 119 144 wp_register_script( "geshisourcecolorer_administration", plugins_url("js/administration".(DEBUG ? null : ".min").".js", LOCALPLUGINFILE), array("jquery") ); 145 146 // scripts are only load if needed (injection error supress) 147 if ($hook == "settings_page_fpx_geshisourcecolorer_option") { 148 wp_enqueue_script( "geshisourcecolorer_administration" ); 149 150 wp_localize_script( "geshisourcecolorer_administration", "geshisourcecolorer_messages", array( 151 "defaultdelete" => __("default style can not be deleted", "fpx_geshisourcecolorer"), 152 "save" => __("save this style under a new name or use the same name for overriding", "fpx_geshisourcecolorer"), 153 "previewemptycode" => __("The preview code is empty. Please add some code lines", "fpx_geshisourcecolorer") 154 )); 120 155 121 wp_enqueue_script( "geshisourcecolorer_administration" ); 122 123 wp_localize_script( "geshisourcecolorer_administration", "geshisourcecolorer_messages", array( 124 "defaultdelete" => __("default style can not be deleted", "fpx_geshisourcecolorer"), 125 "save" => __("save this style under a new name or use the same name for overriding", "fpx_geshisourcecolorer"), 126 "previewemptycode" => __("The preview code is empty. Please add some code lines", "fpx_geshisourcecolorer") 127 )); 128 129 130 131 // CSS script 132 wp_register_style( "geshisourcecolorer_adminstyle", plugins_url("css/administration".(DEBUG ? null : ".min").".css", LOCALPLUGINFILE) ); 133 134 wp_enqueue_style( "geshisourcecolorer_adminstyle" ); 156 wp_enqueue_style( "geshisourcecolorer_adminstyle" ); 157 } 135 158 } 136 159 … … 190 213 191 214 "line" => "geshisourcecolorer-line", 192 "block" => "geshisourcecolorer-block" 193 215 "block" => "geshisourcecolorer-block", 216 "tab" => "geshisourcecolorer-tab-default" 217 194 218 ), 195 219 -
geshi-source-colorer/trunk/import.class.php
r596394 r598213 76 76 $options["css"]["line"] = $data["css"]["line"]; 77 77 $options["css"]["block"] = $data["css"]["block"]; 78 $options["css"]["tab"] = $data["css"]["tab"]; 78 79 } 79 80 switch ($pa["importstyles"]) -
geshi-source-colorer/trunk/js/function.js
r596275 r598213 29 29 // hide all collapsed code blocks 30 30 jQuery(".geshisourcecolorer-collapse").hide(); 31 32 33 // create code tabs 34 jQuery(".geshisourcecolorer-tab").each( function () { 35 var tabid = jQuery.trim(jQuery(this).attr("class").split(" ")[2]); 36 var first = jQuery("."+tabid+":first"); 37 var codeid = jQuery(this).find(".geshisourcecolorer:first").attr("id"); 38 var item = jQuery("<li/>").html( jQuery(this).attr("rel") ).attr("rel", codeid); 39 40 // copy content on each div, which is not the first into the first div 41 if (jQuery(this).get(0) === first.get(0)) 42 { 43 // on the first div create menu 44 var menu = jQuery("<div/>").addClass("tabmenu"); 45 menu.prepend( jQuery("<ul/>").append( item.addClass("current") ) ); 46 menu.data("code-show", codeid); 47 first.prepend( menu ); 48 first.removeAttr("rel"); 49 50 } else { 51 // add code to the tabmenu and the ID of the code block to the rel attribute of the menu entry 52 first.find(".tabmenu ul:first").append( item ); 53 jQuery(jQuery(this).html()).appendTo(first); 54 jQuery(this).remove(); 55 jQuery("#"+codeid).hide(); 56 } 57 }); 58 59 60 /** toggle action on tab click **/ 61 jQuery(".geshisourcecolorer-tab .tabmenu li").click( function() { 62 var active = jQuery(this).parent().find(".current"); 63 64 if ( active.get(0) !== jQuery(this).get(0) ) 65 { 66 jQuery("#"+active.attr("rel")).slideToggle("slow"); 67 jQuery("#"+jQuery(this).attr("rel")).slideToggle("slow"); 68 69 active.removeClass("current"); 70 jQuery(this).addClass("current"); 71 } 72 }); 31 73 32 74 -
geshi-source-colorer/trunk/readme.txt
r596533 r598213 68 68 <li>%s is a placeholder for any kind of spaces. You need this placeholder to create a space between the name of the tag and the parameter list. This placeholder represent one or more than one space</li> 69 69 </ul> 70 All meta characters are masked, so you can add a own tag struc utre. Take a look to the plugin's setting page, the defalut values are used within this documentation. Add to your post or page a tag70 All meta characters are masked, so you can add a own tag structure. Take a look to the plugin's setting page, the defalut values are used within this documentation. Add to your post or page a tag 71 71 <pre>[cc lang="source language"]your source code[/cc]</pre> or the call <pre>[cci lang="source language"]your source code[/cci]</pre> 72 72 You can change in the global plugin option this tags / options, so you don't need a change to your articles, if you update from another plugin. The layout of the code is stored in the plugin options … … 85 85 <ul> 86 86 <li>"geshisourcecolorer-collapse-button" is the class name of the div container, which is shown if a code block is marked with "collapse=true"</li> 87 <li>"geshisourcecolorer-tab" is the class name of the div, which is stored all div container of a tab view</li> 88 <li>"tabmenu" is the container div, which shows the tab menu, it is always stored within the geshisourcecolorer-tab</li> 87 89 <li>"geshisourcecolorer" is the global class name of each code block / line, so with this class you can set styles for all codes</li> 88 90 <li>"toolbar" is the class, which is always within a "geshisourcecolorer", which descripes the toolbar div container</li> … … 138 140 = 0.12 = 139 141 142 * scripts are loaded only on pages with code 140 143 * change translation 144 * language detected fixed 141 145 * add class definition for styles 142 146 * add themeable JavaScript and CSS file … … 167 171 <li>id : set the unique ID of the code block [allowed values: every string, default value: geshisourcecolorer-MD5 hash of the source] </li> 168 172 <li>style : sets the style of the code. If this option is not set, the plugin tries to find a style which is named with the language name (lower-case). If the style is not found, it uses the default style</li> 173 <li>tab : sets the information, which code blocks should be collected in one container. The option value of this field is a class name and a name, which is shown in the item [allowed value: string value in this structure "classname tabtext"]</li> 169 174 <li>lol : name of the source code that is shown within the list of listing (if this flag isn't set or empty, the code is not shown on the list) [allowed values: string value]</li> 170 175 <li>lolhead : shows the name, which is set by the list of listing option [allowed values: true | false]</li> … … 189 194 Yes, you can create a "list of listings" with the call <pre>[lol]</pre>. This will add a div to your page and a jQuery call fills the source data into the 190 195 the div after the page have been loaded. The layout of this list is stored in the main CSS file. Feel free to change your layout. 196 197 198 = Can I collecte different code blocks into one container ? = 199 Yes, use the tag option "tab", which create one container and add all other code blocks with the same name into this container. The value is "classname name of your code". 200 All code blocks with equal classnames are grouped and a tab menu is created, each item of the menu shows the text which is set after the first space in the tab option. 191 201 192 202 -
geshi-source-colorer/trunk/render.class.php
r596533 r598213 58 58 add_settings_field("blockcss", __("css class name of the code blocks container", "fpx_geshisourcecolorer")." <em>[css_block]</em>", get_class()."::render_codeblockcss", "fpx_geshisourcecolorer_optionmain", "fpx_geshisourcecolorer_option"); 59 59 add_settings_field("linecss", __("css class name of the code lines container", "fpx_geshisourcecolorer")." <em>[css_line]</em>", get_class()."::render_codelinecss", "fpx_geshisourcecolorer_optionmain", "fpx_geshisourcecolorer_option"); 60 add_settings_field("tabcss", __("css class name of the tab container", "fpx_geshisourcecolorer"), get_class()."::render_tabcss", "fpx_geshisourcecolorer_optionmain", "fpx_geshisourcecolorer_option"); 60 61 61 62 … … 111 112 if ( (!isset($pa["css_line"])) || (empty($pa["css_block"])) ) 112 113 add_settings_error( "geshisourcecolorer", "option_validate_cssline", __("css class name of the code block need not to be empty", "fpx_geshisourcecolorer"), "error"); 114 if ( (!isset($pa["css_tab"])) || (empty($pa["css_tab"])) ) 115 add_settings_error( "geshisourcecolorer", "option_validate_csstab", __("css class name of the tab container need not to be empty", "fpx_geshisourcecolorer"), "error"); 113 116 114 117 … … 132 135 $options["css"]["line"] = $pa["css_line"]; 133 136 $options["css"]["block"] = $pa["css_block"]; 137 $options["css"]["tab"] = $pa["css_tab"]; 134 138 135 139 $options["geshicss"] = isset($pa["geshicss"]) && (!empty($pa["geshicss"])); … … 339 343 } 340 344 345 static function render_tabcss() 346 { 347 $options = get_option("fpx_geshisourcecolorer_option"); 348 echo "<input name=\"fpx_geshisourcecolorer_option[css_tab]\" size=\"30\" type=\"text\" value=\"".$options["css"]["tab"]."\" />"; 349 } 350 341 351 342 352
Note: See TracChangeset
for help on using the changeset viewer.