|
From: <bi...@us...> - 2013-03-02 05:08:56
|
Revision: 11139
http://sourceforge.net/p/xoops/svn/11139
Author: bitc3r0
Date: 2013-03-02 05:08:50 +0000 (Sat, 02 Mar 2013)
Log Message:
-----------
Modified Paths:
--------------
RMC/rmcommon/trunk/rmcommon/class/form.class.php
RMC/rmcommon/trunk/rmcommon/class/textcleaner.php
RMC/rmcommon/trunk/rmcommon/loader.php
RMC/rmcommon/trunk/rmcommon/themes/twop6/css/2.6.css
RMC/rmcommon/trunk/rmcommon/themes/twop6/js/2.6.js
Added Paths:
-----------
RMC/rmcommon/trunk/rmcommon/api/customcode.php
Added: RMC/rmcommon/trunk/rmcommon/api/customcode.php
===================================================================
--- RMC/rmcommon/trunk/rmcommon/api/customcode.php (rev 0)
+++ RMC/rmcommon/trunk/rmcommon/api/customcode.php 2013-03-02 05:08:50 UTC (rev 11139)
@@ -0,0 +1,312 @@
+<?php
+/**
+ * This code is a modified fragment toaken from Wordpress.
+ * The idea is to provide the functionallity of shortcodes
+ * directly on XOOPS using rmcommon
+ */
+
+class RMCustomCode
+{
+ /**
+ * Contains all custom codes registered
+ */
+ private $custom_codes = array();
+
+ static function get(){
+ static $instance;
+
+ if (isset($instance))
+ return $instance;
+
+ $instance = new RMCustomCode();
+ return $instance;
+ }
+
+ /**
+ * Add hook for customcode tag.
+ *
+ * There can only be one hook for each customcode. Which means that if another
+ * plugin has a similar customcode, it will override yours or yours will override
+ * theirs depending on which order the plugins are included and/or ran.
+ *
+ * Simplest example of a customcode tag using the API:
+ *
+ * <code>
+ * // [footag foo="bar"]
+ * function footag_func($atts) {
+ * return "foo = {$atts[foo]}";
+ * }
+ * add_customcode('footag', 'footag_func');
+ * </code>
+ *
+ * Example with nice attribute defaults:
+ *
+ * <code>
+ * // [bartag foo="bar"]
+ * function bartag_func($atts) {
+ * extract(customcode_atts(array(
+ * 'foo' => 'no foo',
+ * 'baz' => 'default baz',
+ * ), $atts));
+ *
+ * return "foo = {$foo}";
+ * }
+ * add_customcode('bartag', 'bartag_func');
+ * </code>
+ *
+ * Example with enclosed content:
+ *
+ * <code>
+ * // [baztag]content[/baztag]
+ * function baztag_func($atts, $content='') {
+ * return "content = $content";
+ * }
+ * add_customcode('baztag', 'baztag_func');
+ * </code>
+ *
+ * @since 2.5
+ * @uses $customcode_tags
+ *
+ * @param string $tag customcode tag to be searched in post content.
+ * @param callable $func Hook to run when customcode is found.
+ */
+ function add($tag, $func) {
+
+ if ( is_callable($func) )
+ $this->custom_codes[$tag] = $func;
+
+ }
+
+ /**
+ * Removes hook for customcode.
+ *
+ * @since 2.5
+ * @uses $customcode_tags
+ *
+ * @param string $tag customcode tag to remove hook for.
+ */
+ function remove($tag) {
+
+ unset($this->custom_codes[$tag]);
+ }
+
+ /**
+ * Clear all customcodes.
+ *
+ * This function is simple, it clears all of the customcode tags by replacing the
+ * customcodes global by a empty array. This is actually a very efficient method
+ * for removing all customcodes.
+ *
+ * @since 2.5
+ * @uses $customcode_tags
+ */
+ function removeAll() {
+
+ $this->custom_codes = array();
+
+ }
+
+ /**
+ * Search content for customcodes and filter customcodes through their hooks.
+ *
+ * If there are no customcode tags defined, then the content will be returned
+ * without any filtering. This might cause issues when plugins are disabled but
+ * the customcode will still show up in the post or content.
+ *
+ * @since 2.5
+ * @uses $customcode_tags
+ * @uses get_customcode_regex() Gets the search pattern for searching customcodes.
+ *
+ * @param string $content Content to search for customcodes
+ * @return string Content with customcodes filtered out.
+ */
+ function doCode($content) {
+
+ if (empty($this->custom_codes) || !is_array($this->custom_codes))
+ return $content;
+
+ $pattern = $this->getRegex();
+ return preg_replace_callback( "/$pattern/s", array($this, 'doTag'), $content );
+ }
+
+ /**
+ * Retrieve the customcode regular expression for searching.
+ *
+ * The regular expression combines the customcode tags in the regular expression
+ * in a regex class.
+ *
+ * The regular expression contains 6 different sub matches to help with parsing.
+ *
+ * 1 - An extra [ to allow for escaping customcodes with double [[]]
+ * 2 - The customcode name
+ * 3 - The customcode argument list
+ * 4 - The self closing /
+ * 5 - The content of a customcode when it wraps some content.
+ * 6 - An extra ] to allow for escaping customcodes with double [[]]
+ *
+ * @since 2.5
+ * @uses $customcode_tags
+ *
+ * @return string The customcode search regular expression
+ */
+ function getRegex() {
+
+ $tagnames = array_keys($this->custom_codes);
+ $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
+
+ // WARNING! Do not change this regex without changing do_customcode_tag() and strip_customcode_tag()
+ // Also, see customcode_unautop() and customcode.js.
+ return
+ '\\[' // Opening bracket
+ . '(\\[?)' // 1: Optional second opening bracket for escaping customcodes: [[tag]]
+ . "($tagregexp)" // 2: customcode name
+ . '(?![\\w-])' // Not followed by word character or hyphen
+ . '(' // 3: Unroll the loop: Inside the opening customcode tag
+ . '[^\\]\\/]*' // Not a closing bracket or forward slash
+ . '(?:'
+ . '\\/(?!\\])' // A forward slash not followed by a closing bracket
+ . '[^\\]\\/]*' // Not a closing bracket or forward slash
+ . ')*?'
+ . ')'
+ . '(?:'
+ . '(\\/)' // 4: Self closing tag ...
+ . '\\]' // ... and closing bracket
+ . '|'
+ . '\\]' // Closing bracket
+ . '(?:'
+ . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing customcode tags
+ . '[^\\[]*+' // Not an opening bracket
+ . '(?:'
+ . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing customcode tag
+ . '[^\\[]*+' // Not an opening bracket
+ . ')*+'
+ . ')'
+ . '\\[\\/\\2\\]' // Closing customcode tag
+ . ')?'
+ . ')'
+ . '(\\]?)'; // 6: Optional second closing brocket for escaping customcodes: [[tag]]
+ }
+
+ /**
+ * Regular Expression callable for do_customcode() for calling customcode hook.
+ * @see get_customcode_regex for details of the match array contents.
+ *
+ * @since 2.5
+ * @access private
+ * @uses $customcode_tags
+ *
+ * @param array $m Regular expression match array
+ * @return mixed False on failure.
+ */
+ function doTag( $m ) {
+
+ // allow [[foo]] syntax for escaping a tag
+ if ( $m[1] == '[' && $m[6] == ']' ) {
+ return substr($m[0], 1, -1);
+ }
+
+ $tag = $m[2];
+ $attr = $this->parseAtts( $m[3] );
+
+ if ( isset( $m[5] ) ) {
+ // enclosing tag - extra parameter
+ return $m[1] . call_user_func( $this->custom_codes[$tag], $attr, $m[5], $tag ) . $m[6];
+ } else {
+ // self-closing tag
+ return $m[1] . call_user_func( $this->custom_codes[$tag], $attr, null, $tag ) . $m[6];
+ }
+ }
+
+ /**
+ * Retrieve all attributes from the customcodes tag.
+ *
+ * The attributes list has the attribute name as the key and the value of the
+ * attribute as the value in the key/value pair. This allows for easier
+ * retrieval of the attributes, since all attributes have to be known.
+ *
+ * @since 2.5
+ *
+ * @param string $text
+ * @return array List of attributes and their value.
+ */
+ function parseAtts($text) {
+ $atts = array();
+ $pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
+ $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
+ if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) {
+ foreach ($match as $m) {
+ if (!empty($m[1]))
+ $atts[strtolower($m[1])] = stripcslashes($m[2]);
+ elseif (!empty($m[3]))
+ $atts[strtolower($m[3])] = stripcslashes($m[4]);
+ elseif (!empty($m[5]))
+ $atts[strtolower($m[5])] = stripcslashes($m[6]);
+ elseif (isset($m[7]) and strlen($m[7]))
+ $atts[] = stripcslashes($m[7]);
+ elseif (isset($m[8]))
+ $atts[] = stripcslashes($m[8]);
+ }
+ } else {
+ $atts = ltrim($text);
+ }
+ return $atts;
+ }
+
+ /**
+ * Combine user attributes with known attributes and fill in defaults when needed.
+ *
+ * The pairs should be considered to be all of the attributes which are
+ * supported by the caller and given as a list. The returned attributes will
+ * only contain the attributes in the $pairs list.
+ *
+ * If the $atts list has unsupported attributes, then they will be ignored and
+ * removed from the final returned list.
+ *
+ * @since 2.5
+ *
+ * @param array $pairs Entire list of supported attributes and their defaults.
+ * @param array $atts User defined attributes in customcode tag.
+ * @return array Combined and filtered attribute list.
+ */
+ function atts($pairs, $atts) {
+ $atts = (array)$atts;
+ $out = array();
+ foreach($pairs as $name => $default) {
+ if ( array_key_exists($name, $atts) )
+ $out[$name] = $atts[$name];
+ else
+ $out[$name] = $default;
+ }
+ return $out;
+ }
+
+ /**
+ * Remove all customcode tags from the given content.
+ *
+ * @since 2.5
+ * @uses $customcode_tags
+ *
+ * @param string $content Content to remove customcode tags.
+ * @return string Content without customcode tags.
+ */
+ function strip( $content ) {
+
+ if (empty($this->custom_codes) || !is_array($this->custom_codes))
+ return $content;
+
+ $pattern = $this->getRegex();
+
+ return preg_replace_callback( "/$pattern/s", array($this, 'strip'), $content );
+ }
+
+ function stripTag( $m ) {
+ // allow [[foo]] syntax for escaping a tag
+ if ( $m[1] == '[' && $m[6] == ']' ) {
+ return substr($m[0], 1, -1);
+ }
+
+ return $m[1] . $m[6];
+ }
+
+}
+
Modified: RMC/rmcommon/trunk/rmcommon/class/form.class.php
===================================================================
--- RMC/rmcommon/trunk/rmcommon/class/form.class.php 2013-03-02 02:34:12 UTC (rev 11138)
+++ RMC/rmcommon/trunk/rmcommon/class/form.class.php 2013-03-02 05:08:50 UTC (rev 11139)
@@ -44,7 +44,7 @@
'skin'=>"exm_theme",
'inlinepopups_skin'=>'exm',
//'plugins'=>"inlinepopups,spellchecker,media,fullscreen,exmsystem",
- 'plugins' => $rmEvents->run_event('rmcommon.tiny.plugins.editor',"exmsystem,autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template"),
+ 'plugins' => $rmEvents->run_event('rmcommon.tiny.plugins.editor',"exmsystem,autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template"),
'theme_advanced_buttons1'=>RMEvents::get()->run_event('rmcommon.tinybuttons.toolbar1', "bold,italic,strikethrough,|,bullist,numlist,blockquote,|,justifyleft,justifycenter,justifyright,|,link,unlink,|,image,fullscreen,|,exm_more,exm_adv"),
'theme_advanced_buttons2'=>RMEvents::get()->run_event('rmcommon.tinybuttons.toolbar2', "underline,justifyfull,forecolor,|,removeformat,|,media,charmap,|,outdent,indent,|,undo,redo,|,exm_page,exm_img,exm_icons"),
'theme_advanced_buttons3'=>RMEvents::get()->run_event('rmcommon.tinybuttons.toolbar3', "styleselect,formatselect,insertimage,|,tablecontrols"),
Modified: RMC/rmcommon/trunk/rmcommon/class/textcleaner.php
===================================================================
--- RMC/rmcommon/trunk/rmcommon/class/textcleaner.php 2013-03-02 02:34:12 UTC (rev 11138)
+++ RMC/rmcommon/trunk/rmcommon/class/textcleaner.php 2013-03-02 05:08:50 UTC (rev 11139)
@@ -621,6 +621,10 @@
$text = $this->codeConv($text, $rmc_config['doxcode']); // Ryuji_edit(2003-11-18)
if($paragraph) $text = $this->double_br($text);
+ // Custom Codes
+ global $rmCodes;
+ $text = $rmCodes->doCode($text);
+
// Before to send the formatted string we send it to interceptor methods
return RMEvents::get()->run_event('rmcommon.text.todisplay', $text, $original_text);
}
Modified: RMC/rmcommon/trunk/rmcommon/loader.php
===================================================================
--- RMC/rmcommon/trunk/rmcommon/loader.php 2013-03-02 02:34:12 UTC (rev 11138)
+++ RMC/rmcommon/trunk/rmcommon/loader.php 2013-03-02 05:08:50 UTC (rev 11139)
@@ -157,8 +157,9 @@
// Base classes
$GLOBALS['rmEvents'] = RMEvents::get();
$GLOBALS['rmTpl'] = RMTemplate::get();
+$GLOBALS['rmCodes'] = RMCustomCode::get();
-global $rmEvents, $rmTpl;
+global $rmEvents, $rmTpl, $rmCodes;
define('RMCLANG', $rmEvents->run_event('rmcommon.set.language', $rmc_config['lang']));
Modified: RMC/rmcommon/trunk/rmcommon/themes/twop6/css/2.6.css
===================================================================
--- RMC/rmcommon/trunk/rmcommon/themes/twop6/css/2.6.css 2013-03-02 02:34:12 UTC (rev 11138)
+++ RMC/rmcommon/trunk/rmcommon/themes/twop6/css/2.6.css 2013-03-02 05:08:50 UTC (rev 11139)
@@ -320,6 +320,13 @@
table{
width: 100%;
}
+.outer{
+ border: 1px solid #DDD;
+ border-radius: 3px;
+ -webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
+ margin-bottom: 20px;
+}
th, .th, .table th{
background-color: #ebebeb;
background-image: -moz-linear-gradient(top, #f2f2f2, #ebebeb);
Modified: RMC/rmcommon/trunk/rmcommon/themes/twop6/js/2.6.js
===================================================================
--- RMC/rmcommon/trunk/rmcommon/themes/twop6/js/2.6.js 2013-03-02 02:34:12 UTC (rev 11138)
+++ RMC/rmcommon/trunk/rmcommon/themes/twop6/js/2.6.js 2013-03-02 05:08:50 UTC (rev 11139)
@@ -20,7 +20,7 @@
$("input[type='button']").addClass('btn');
$("input[type='submit']").addClass('btn').addClass('btn-primary');
- $(".outer").addClass("table").addClass("table-hover").addClass('table-bordered');
+ $("table.outer").addClass("table").addClass("table-hover").addClass('table-bordered');
$("#xo-contents").css('min-height', $(window).height()-290+'px');
$("#xo-menubar .search-query").typeahead({
@@ -70,6 +70,7 @@
$(".box-collapse .control").click(function(){
$(this).parent().parent().children(".collapsable").slideToggle('fast');
+
if($(this).hasClass("icon-caret-down"))
$(this).removeClass("icon-caret-down").addClass('icon-caret-up');
else
|