[geeklog-hg] geeklog: Added gltext.class.php containing the new GLText class....
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Mon Jul 15 05:03:40 EDT 2013
changeset 9199:f285dfa9b171
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/f285dfa9b171
user: dengen <taharaxp at gmail.com>
date: Mon Jul 15 18:01:23 2013 +0900
description:
Added gltext.class.php containing the new GLText class. In addition, introduced a new text processing method.
As a result, handling of special characters was improved.
Except advanced editor mode, the text in the input forms is not changed anymore.
diffstat:
public_html/lib-common.php | 164 +----------
sql/mssql_tableanddata.php | 2 +
sql/mysql_tableanddata.php | 2 +
sql/pgsql_tableanddata.php | 2 +
sql/updates/mssql_2.0.0_to_2.0.1.php | 6 +
sql/updates/mysql_2.0.0_to_2.0.1.php | 6 +
sql/updates/pgsql_2.0.0_to_2.0.1.php | 6 +
system/classes/gltext.class.php | 416 ++++++++++++++++++++++++++++
system/classes/story.class.php | 510 ++++++++++++----------------------
9 files changed, 637 insertions(+), 477 deletions(-)
diffs (truncated from 1614 to 300 lines):
diff -r 432d88da0a1e -r f285dfa9b171 public_html/lib-common.php
--- a/public_html/lib-common.php Mon Jul 15 16:51:40 2013 +0900
+++ b/public_html/lib-common.php Mon Jul 15 18:01:23 2013 +0900
@@ -3793,152 +3793,11 @@
*/
function COM_checkHTML( $str, $permissions = 'story.edit' )
{
- global $_CONF, $_USER;
-
- $str = COM_stripslashes($str);
-
- // Get rid of any newline characters
- $str = str_replace("\n", '', $str);
-
- // handle [code] ... [/code]
- do
- {
- $start_pos = MBYTE_strpos( MBYTE_strtolower( $str ), '[code]' );
- if( $start_pos !== false )
- {
- $end_pos = MBYTE_strpos( MBYTE_strtolower( $str ), '[/code]' );
- if( $end_pos !== false )
- {
- $encoded = COM_handleCode( MBYTE_substr( $str, $start_pos + 6,
- $end_pos - ( $start_pos + 6 )));
- $encoded = '<pre><code>' . $encoded . '</code></pre>';
- $str = MBYTE_substr( $str, 0, $start_pos ) . $encoded
- . MBYTE_substr( $str, $end_pos + 7 );
- }
- else // missing [/code]
- {
- // Treat the rest of the text as code (so as not to lose any
- // special characters). However, the calling entity should
- // better be checking for missing [/code] before calling this
- // function ...
- $encoded = COM_handleCode( MBYTE_substr( $str, $start_pos + 6 ));
- $encoded = '<pre><code>' . $encoded . '</code></pre>';
- $str = MBYTE_substr( $str, 0, $start_pos ) . $encoded;
- }
- }
- }
- while( $start_pos !== false );
-
- // handle [raw] ... [/raw]
- do
- {
- $start_pos = MBYTE_strpos( MBYTE_strtolower( $str ), '[raw]' );
- if( $start_pos !== false )
- {
- $end_pos = MBYTE_strpos( MBYTE_strtolower( $str ), '[/raw]' );
- if( $end_pos !== false )
- {
- $encoded = COM_handleCode( MBYTE_substr( $str, $start_pos + 5,
- $end_pos - ( $start_pos + 5 )));
- // [raw2] to avoid infinite loop. Not HTML comment as we strip
- // them later.
- $encoded = '[raw2]' . $encoded . '[/raw2]';
- $str = MBYTE_substr( $str, 0, $start_pos ) . $encoded
- . MBYTE_substr( $str, $end_pos + 6 );
- }
- else // missing [/raw]
- {
- // Treat the rest of the text as raw (so as not to lose any
- // special characters). However, the calling entity should
- // better be checking for missing [/raw] before calling this
- // function ...
- $encoded = COM_handleCode( MBYTE_substr( $str, $start_pos + 5 ));
- // [raw2] to avoid infinite loop. Not HTML comment as we strip
- // them later.
- $encoded = '[raw2]' . $encoded . '[/raw2]';
- $str = MBYTE_substr( $str, 0, $start_pos ) . $encoded;
- }
- }
- }
- while( $start_pos !== false );
-
- // replace any \ with \ (HTML equiv)
- $str = str_replace( '\\', '\', $str );
-
- // Replace any $ with $ (HTML equiv)
- $str = str_replace( '$', '$', $str );
-
- $has_skiphtmlfilterPermissions = SEC_hasRights ('htmlfilter.skip');
-
- if ($has_skiphtmlfilterPermissions || (isset( $_CONF['skip_html_filter_for_root'] ) &&
- ( $_CONF['skip_html_filter_for_root'] == 1 ) &&
- SEC_inGroup( 'Root' ))) {
- return $str;
- }
-
- require_once $_CONF['path_system'] . 'classes/htmlawed/htmLawed.php';
-
- // Sets config options for htmLawed. See http://www.bioinformatics.org/
- // phplabware/internal_utilities/htmLawed/htmLawed_README.htm
- $config = array(
- 'balance' => 1, // Balance tags for well-formedness and proper nesting
- 'comment' => 3, // Allow HTML comment
- 'css_expression' => 1, // Allow dynamic CSS expression in "style" attributes
- 'keep_bad' => 1, // Neutralize both tags and element content
- 'tidy' => 0, // Don't beautify or compact HTML code
- 'unique_ids' => 1, // Remove duplicate and/or invalid ids
- 'valid_xhtml' => 1, // Magic parameter to make input the most valid XHTML
- );
-
- if (isset($_CONF['allowed_protocols']) &&
- is_array($_CONF['allowed_protocols']) &&
- (count($_CONF['allowed_protocols']) > 0)) {
- $schemes = $_CONF['allowed_protocols'];
- } else {
- $schemes = array('http:', 'https:', 'ftp:');
- }
-
- $schemes = str_replace(':', '', implode(', ', $schemes));
- $config['schemes'] = 'href: ' . $schemes . '; *: ' . $schemes;
-
- if( empty( $permissions) || !SEC_hasRights( $permissions ) ||
- empty( $_CONF['admin_html'] ))
- {
- $html = $_CONF['user_html'];
- }
- else
- {
- if ($_CONF['advanced_editor'] && $_USER['advanced_editor']) {
- $html = array_merge_recursive($_CONF['user_html'],
- $_CONF['admin_html'],
- $_CONF['advanced_html']);
- } else {
- $html = array_merge_recursive($_CONF['user_html'],
- $_CONF['admin_html']);
- }
- }
-
- foreach ($html as $tag => $attr) {
- if (is_array($attr) && (count($attr) > 0)) {
- $spec[] = $tag . '=' . implode(', ', array_keys($attr));
- } else {
- $spec[] = $tag . '=-*';
- }
-
- $elements[] = $tag;
- }
-
- $config['elements'] = implode(', ', $elements);
- $spec = implode('; ', $spec);
-
- /* Replace [raw][/raw] with <!--raw--><!--/raw-->, note done "late" because
- * of the above noted // strip_tags() gets confused by HTML comments ...
- */
- $str = htmLawed($str, $config, $spec);
- $str = str_replace('[raw2]','<!--raw--><span class="raw">', $str);
- $str = str_replace('[/raw2]','</span><!--/raw-->', $str);
-
- return $str;
+ global $_CONF;
+
+ require_once $_CONF['path_system'] . 'classes/gltext.class.php';
+
+ return GLText::checkHTML($str, $permissions);
}
/**
@@ -8303,16 +8162,9 @@
return $wikitext;
}
- require_once 'Text/Wiki.php';
-
- $wiki = new Text_Wiki();
- $wiki->setFormatConf('Xhtml', 'translate', HTML_SPECIALCHARS);
- $wiki->setRenderConf('Xhtml', 'charset', COM_getCharset());
- $wiki->disableRule('wikilink');
- $wiki->disableRule('freelink');
- $wiki->disableRule('interwiki');
-
- return $wiki->transform($wikitext, 'Xhtml');
+ require_once $_CONF['path_system'] . 'classes/gltext.class.php';
+
+ return GLText::renderWikiText($wikitext);
}
/**
diff -r 432d88da0a1e -r f285dfa9b171 sql/mssql_tableanddata.php
--- a/sql/mssql_tableanddata.php Mon Jul 15 16:51:40 2013 +0900
+++ b/sql/mssql_tableanddata.php Mon Jul 15 18:01:23 2013 +0900
@@ -299,6 +299,7 @@
[page_title] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[introtext] [varchar] (5000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[bodytext] [varchar] (5000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+ [text_version] [tinyint] NOT NULL DEFAULT (1),
[hits] [numeric](8, 0) NOT NULL ,
[numemails] [numeric](8, 0) NOT NULL ,
[comments] [numeric](8, 0) NOT NULL ,
@@ -333,6 +334,7 @@
[title] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[introtext] [varchar] (5000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[bodytext] [varchar] (5000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
+ [text_version] [tinyint] NOT NULL DEFAULT (1),
[date] [datetime] NULL ,
[postmode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
diff -r 432d88da0a1e -r f285dfa9b171 sql/mysql_tableanddata.php
--- a/sql/mysql_tableanddata.php Mon Jul 15 16:51:40 2013 +0900
+++ b/sql/mysql_tableanddata.php Mon Jul 15 18:01:23 2013 +0900
@@ -304,6 +304,7 @@
page_title varchar(128) default NULL,
introtext text,
bodytext text,
+ text_version tinyint(2) NOT NULL default '1',
hits mediumint(8) unsigned NOT NULL default '0',
numemails mediumint(8) unsigned NOT NULL default '0',
comments mediumint(8) unsigned NOT NULL default '0',
@@ -346,6 +347,7 @@
title varchar(128) default NULL,
introtext text,
bodytext text,
+ text_version tinyint(2) NOT NULL default '1',
date datetime default NULL,
postmode varchar(10) NOT NULL default 'html',
PRIMARY KEY (sid)
diff -r 432d88da0a1e -r f285dfa9b171 sql/pgsql_tableanddata.php
--- a/sql/pgsql_tableanddata.php Mon Jul 15 16:51:40 2013 +0900
+++ b/sql/pgsql_tableanddata.php Mon Jul 15 18:01:23 2013 +0900
@@ -302,6 +302,7 @@
page_title varchar(128) default NULL,
introtext text,
bodytext text,
+ text_version smallint NOT NULL default '1',
hits smallint NOT NULL default '0',
numemails smallint NOT NULL default '0',
comments smallint NOT NULL default '0',
@@ -344,6 +345,7 @@
title varchar(128) default NULL,
introtext text,
bodytext text,
+ text_version smallint NOT NULL default '1',
date timestamp default NULL,
postmode varchar(10) NOT NULL default 'html',
PRIMARY KEY (sid)
diff -r 432d88da0a1e -r f285dfa9b171 sql/updates/mssql_2.0.0_to_2.0.1.php
--- a/sql/updates/mssql_2.0.0_to_2.0.1.php Mon Jul 15 16:51:40 2013 +0900
+++ b/sql/updates/mssql_2.0.0_to_2.0.1.php Mon Jul 15 18:01:23 2013 +0900
@@ -9,6 +9,12 @@
// Remove unused columns in Comments table
$_SQL[] = "ALTER TABLE {$_TABLES['comments']} DROP `score`, DROP `reason`";
+// Add version of GLText engine to stories table
+$_SQL[] = "ALTER TABLE {$_TABLES['stories']} ADD [text_version] [tinyint] NOT NULL DEFAULT (1) AFTER [bodytext]";
+
+// Add version of GLText engine to storysubmission table
+$_SQL[] = "ALTER TABLE {$_TABLES['storysubmission']} ADD [text_version] [tinyint] NOT NULL DEFAULT (1) AFTER [bodytext]";
+
/**
* Add new config options
*
diff -r 432d88da0a1e -r f285dfa9b171 sql/updates/mysql_2.0.0_to_2.0.1.php
--- a/sql/updates/mysql_2.0.0_to_2.0.1.php Mon Jul 15 16:51:40 2013 +0900
+++ b/sql/updates/mysql_2.0.0_to_2.0.1.php Mon Jul 15 18:01:23 2013 +0900
@@ -9,6 +9,12 @@
// Remove unused columns in Comments table
$_SQL[] = "ALTER TABLE {$_TABLES['comments']} DROP `score`, DROP `reason`";
+// Add version of GLText engine to stories table
+$_SQL[] = "ALTER TABLE {$_TABLES['stories']} ADD `text_version` tinyint(2) unsigned NOT NULL DEFAULT '1' AFTER `bodytext`";
+
+// Add version of GLText engine to storysubmission table
+$_SQL[] = "ALTER TABLE {$_TABLES['storysubmission']} ADD `text_version` tinyint(2) unsigned NOT NULL DEFAULT '1' AFTER `bodytext`";
+
/**
* Add new config options
*
diff -r 432d88da0a1e -r f285dfa9b171 sql/updates/pgsql_2.0.0_to_2.0.1.php
--- a/sql/updates/pgsql_2.0.0_to_2.0.1.php Mon Jul 15 16:51:40 2013 +0900
+++ b/sql/updates/pgsql_2.0.0_to_2.0.1.php Mon Jul 15 18:01:23 2013 +0900
@@ -9,6 +9,12 @@
// Remove unused columns in Comments table
$_SQL[] = "ALTER TABLE {$_TABLES['comments']} DROP `score`, DROP `reason`";
+// Add version of GLText engine to stories table
+$_SQL[] = "ALTER TABLE {$_TABLES['stories']} ADD `text_version` smallint NOT NULL DEFAULT '1' AFTER `bodytext`";
+
+// Add version of GLText engine to storysubmission table
+$_SQL[] = "ALTER TABLE {$_TABLES['storysubmission']} ADD `text_version` smallint NOT NULL DEFAULT '1' AFTER `bodytext`";
+
/**
* Add new config options
*
diff -r 432d88da0a1e -r f285dfa9b171 system/classes/gltext.class.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/system/classes/gltext.class.php Mon Jul 15 18:01:23 2013 +0900
@@ -0,0 +1,416 @@
+<?php
+
+/* Reminder: always indent with 4 spaces (no tabs). */
+// +---------------------------------------------------------------------------+
+// | Geeklog 2.0 |
+// +---------------------------------------------------------------------------+
+// | gltext.class.php |
+// | |
+// | Geeklog Text Abstraction. |
+// +---------------------------------------------------------------------------+
More information about the geeklog-cvs
mailing list