2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Merging the Limesurvey 1.91+ branch of queXS in to the trunk

This commit is contained in:
azammitdcarf
2011-09-08 01:58:41 +00:00
parent dfa55a3b9e
commit eaa9578ab8
2312 changed files with 811461 additions and 597534 deletions

View File

@@ -0,0 +1,506 @@
<?php
/**
* ----------------------------------------------------------------------
*
* Copyright (C) 2009 by Khaled Al-Shamaa.
*
* http://www.ar-php.org
*
* ----------------------------------------------------------------------
*
* LICENSE
*
* This program is open source product; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License (LGPL)
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/lgpl.txt>.
*
* ----------------------------------------------------------------------
*
* Class Name: Arabic Glyphs is a simple class to render Arabic text
*
* Filename: ArGlyphs.class.php
*
* Original Author(s): Khaled Al-Sham'aa <khaled.alshamaa@gmail.com>
*
* Purpose: This class takes Arabic text (encoded in Windows-1256 character
* set) as input and performs Arabic glyph joining on it and outputs
* a UTF-8 hexadecimals stream that is no longer logically arranged
* but in a visual order which gives readable results when formatted
* with a simple Unicode rendering just like GD and UFPDF libraries
* that does not handle basic connecting glyphs of Arabic language
* yet but simply outputs all stand alone glyphs in left-to-right
* order.
*
* ----------------------------------------------------------------------
*
* Arabic Glyphs is class to render Arabic text
*
* PHP class to render Arabic text by performs Arabic glyph joining on it,
* then output a UTF-8 hexadecimals stream gives readable results on PHP
* libraries supports UTF-8.
*
* Example:
* <code>
* include('./Arabic.php');
* $Arabic = new Arabic('ArGlyphs');
*
* $text = $Arabic->utf8Glyphs($text);
*
* imagettftext($im, 20, 0, 200, 100, $black, $font, $text);
* </code>
*
* @category Text
* @package Arabic
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
* @copyright 2009 Khaled Al-Shamaa
*
* @license LGPL <http://www.gnu.org/licenses/lgpl.txt>
* @link http://www.ar-php.org
*/
// New in PHP V5.3: Namespaces
// namespace Arabic/ArGlyphs;
/**
* This PHP class render Arabic text by performs Arabic glyph joining on it
*
* @category Text
* @package Arabic
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
* @copyright 2009 Khaled Al-Shamaa
*
* @license LGPL <http://www.gnu.org/licenses/lgpl.txt>
* @link http://www.ar-php.org
*/
class ArGlyphs
{
protected $_glyphs = null;
protected $_hex = null;
protected $_prevLink;
protected $_nextLink;
/**
* Loads initialize values
*/
public function __construct()
{
$this->_prevLink = '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
$this->_nextLink = '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
$this->vowel = '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
/*
$this->_glyphs['<27>'] = array('FE70','FE71');
$this->_glyphs['<27>'] = array('FE72','FE72');
$this->_glyphs['<27>'] = array('FE74','FE74');
$this->_glyphs['<27>'] = array('FE76','FE77');
$this->_glyphs['<27>'] = array('FE78','FE79');
$this->_glyphs['<27>'] = array('FE7A','FE7B');
$this->_glyphs['<27>'] = array('FE7C','FE7D');
$this->_glyphs['<27>'] = array('FE7E','FE7E');
*/
$this->_glyphs = '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
$this->_hex = '064B064B064B064B064C064C064C064C064D064D064D064D064E064E064E064E064F064F064F064F065006500650065006510651065106510652065206520652';
$this->_glyphs .= '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
$this->_hex .= 'FE80FE80FE80FE80FE81FE82FE81FE82FE83FE84FE83FE84FE85FE86FE85FE86FE87FE88FE87FE88FE89FE8AFE8BFE8CFE8DFE8EFE8DFE8EFE8FFE90FE91FE92';
$this->_glyphs .= '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
$this->_hex .= 'FE93FE94FE93FE94FE95FE96FE97FE98FE99FE9AFE9BFE9CFE9DFE9EFE9FFEA0FEA1FEA2FEA3FEA4FEA5FEA6FEA7FEA8FEA9FEAAFEA9FEAAFEABFEACFEABFEAC';
$this->_glyphs .= '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
$this->_hex .= 'FEADFEAEFEADFEAEFEAFFEB0FEAFFEB0FEB1FEB2FEB3FEB4FEB5FEB6FEB7FEB8FEB9FEBAFEBBFEBCFEBDFEBEFEBFFEC0FEC1FEC2FEC3FEC4FEC5FEC6FEC7FEC8';
$this->_glyphs .= '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
$this->_hex .= 'FEC9FECAFECBFECCFECDFECEFECFFED0FED1FED2FED3FED4FED5FED6FED7FED8FED9FEDAFEDBFEDCFEDDFEDEFEDFFEE0FEE1FEE2FEE3FEE4FEE5FEE6FEE7FEE8';
$this->_glyphs .= '<27><><EFBFBD><EFBFBD>ܡ<EFBFBD><DCA1>';
$this->_hex .= 'FEE9FEEAFEEBFEECFEEDFEEEFEEDFEEEFEEFFEF0FEEFFEF0FEF1FEF2FEF3FEF40640064006400640060C060C060C060C061F061F061F061F061B061B061B061B';
$this->_glyphs .= '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
$this->_hex .= 'FEF5FEF6FEF5FEF6FEF7FEF8FEF7FEF8FEF9FEFAFEF9FEFAFEFBFEFCFEFBFEFC';
}
/**
* Get glyphs
*
* @param string $char Char
* @param integer $type Type
*
* @return string
*/
protected function _getGlyphs($char, $type)
{
$pos = strpos($this->_glyphs, $char);
if ($pos > 48) {
$pos = ($pos-48)/2 + 48;
}
$pos = $pos*16 + $type*4;
return substr($this->_hex, $pos, 4);
}
/**
* Convert Arabic Windows-1256 charset string into glyph joining in UTF-8
* hexadecimals stream
*
* @param string $str Arabic string in Windows-1256 charset
*
* @return string Arabic glyph joining in UTF-8 hexadecimals stream
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
*/
protected function _preConvert($str)
{
$crntChar = null;
$prevChar = null;
$nextChar = null;
$output = '';
$chars = preg_split('//', $str);
$max = count($chars);
for ($i = $max - 1; $i >= 0; $i--) {
$crntChar = $chars[$i];
if ($i > 0) {
$prevChar = $chars[$i - 1];
} else {
$prevChar = null;
}
if ($prevChar && strpos($this->vowel, $prevChar) !== false) {
$prevChar = $chars[$i - 2];
if ($prevChar && strpos($this->vowel, $prevChar) !== false) {
$prevChar = $chars[$i - 3];
}
}
$Reversed = false;
$flip_arr = ')]>}';
$ReversedChr = '([<{';
if ($crntChar && strpos($flip_arr, $crntChar) !== false) {
$crntChar = substr($ReversedChr, strpos($flip_arr, $crntChar), 1);
$Reversed = true;
} else {
$Reversed = false;
}
if ($crntChar && (strpos($ReversedChr, $crntChar) !== false) && !$Reversed) {
$crntChar = substr($flip_arr, strpos($ReversedChr, $crntChar), 1);
}
if ($crntChar && strpos($this->vowel, $crntChar) !== false) {
if ((strpos($this->_nextLink, $chars[$i + 1]) !== false) && (strpos($this->_prevLink, $prevChar) !== false)) {
$output .= '&#x' . $this->_getGlyphs($crntChar, 1) . ';';
} else {
$output .= '&#x' . $this->_getGlyphs($crntChar, 0) . ';';
}
continue;
}
if (isset($chars[$i + 1]) && in_array($chars[$i + 1], array('<27>', '<27>', '<27>', '<27>')) && $crntChar == '<27>') {
continue;
}
if (ord($crntChar) < 128) {
$output .= $crntChar;
$nextChar = $crntChar;
continue;
}
$form = 0;
if (in_array($crntChar, array('<27>', '<27>', '<27>', '<27>')) && $prevChar == '<27>') {
if (strpos($this->_prevLink, $chars[$i - 2]) !== false) {
$form++;
}
$output .= '&#x' . $this->_getGlyphs($prevChar . $crntChar, $form) . ';';
$nextChar = $prevChar;
continue;
}
if ($prevChar && strpos($this->_prevLink, $prevChar) !== false) {
$form++;
}
if ($nextChar && strpos($this->_nextLink, $nextChar) !== false) {
$form += 2;
}
$output .= '&#x' . $this->_getGlyphs($crntChar, $form) . ';';
$nextChar = $crntChar;
}
$output = $this->_decodeEntities($output, $exclude = array('&'));
return $output;
}
/**
* Regression analysis calculate roughly the max number of character fit in
* one A4 page line for a given font size.
*
* @param integer $font Font size
*
* @return integer Maximum number of characters per line
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
*/
public function a4_max_chars($font)
{
$x = 381.6 - 31.57 * $font + 1.182 * pow($font, 2) - 0.02052 * pow($font, 3) + 0.0001342 * pow($font, 4);
return floor($x - 2);
}
/**
* Calculate the lines number of given Arabic text and font size that will
* fit in A4 page size
*
* @param string $str Arabic string you would like to split it into lines
* @param integer $font Font size
* @param string $inputCharset (optional) Input charset [utf-8|windows-1256|iso-8859-6]
* default value is NULL (use set input charset)
* @param object $main Main Ar-PHP object to access charset converter options
*
* @return integer Number of lines for a given Arabic string in A4 page size
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
*/
public function a4_lines($str, $font, $inputCharset = null, $main = null)
{
if ($main) {
if ($inputCharset == null) $inputCharset = $main->getInputCharset();
$str = $main->coreConvert($str, $inputCharset, 'windows-1256');
}
$str = str_replace(array("\r\n", "\n", "\r"), "\n", $str);
$lines = 0;
$chars = 0;
$words = explode(' ', $str);
$w_count = count($words);
$max_chars = $this->a4_max_chars($font);
for ($i = 0; $i < $w_count; $i++) {
$w_len = strlen($words[$i]) + 1;
if ($chars + $w_len < $max_chars) {
if (preg_match("/\n/i", $words[$i])) {
$words_nl = split("\n", $words[$i]);
$nl_num = count($words_nl) - 1;
for ($j = 1; $j < $nl_num; $j++) {
$lines++;
}
$chars = strlen($words_nl[$nl_num]) + 1;
} else {
$chars += $w_len;
}
} else {
$lines++;
$chars = $w_len;
}
}
$lines++;
return $lines;
}
/**
* Convert Arabic Windows-1256 charset string into glyph joining in UTF-8
* hexadecimals stream (take care of whole the document including English
* sections as well as numbers and arcs etc...)
*
* @param string $str Arabic string in Windows-1256 charset
* @param integer $max_chars Max number of chars you can fit in one line
* @param boolean $hindo If true use Hindo digits else use Arabic digits
* @param string $inputCharset (optional) Input charset [utf-8|windows-1256|iso-8859-6]
* default value is NULL (use set input charset)
* @param object $main Main Ar-PHP object to access charset converter options
*
* @return string Arabic glyph joining in UTF-8 hexadecimals stream (take
* care of whole document including English sections as well
* as numbers and arcs etc...)
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
*/
public function utf8Glyphs($str, $max_chars = 50, $hindo = true, $inputCharset = null, $main = null)
{
if ($main) {
if ($inputCharset == null) $inputCharset = $main->getInputCharset();
$str = $main->coreConvert($str, $inputCharset, 'windows-1256');
}
$str = str_replace(array("\r\n", "\n", "\r"), "\n", $str);
$lines = array();
$words = explode(' ', $str);
$w_count = count($words);
$c_chars = 0;
$c_words = array();
$english = array();
$en_index = -1;
for ($i = 0; $i < $w_count; $i++) {
if (preg_match("/^[a-z\d\\/\@\#\$\%\^\&\*\(\)\_\~\"\'\[\]\{\}\;\,\|]*([\.\:\+\=\-\!<21><>]?)$/i", $words[$i], $matches)) {
if ($matches[1]) $words[$i] = $matches[1].substr($words[$i], 0, -1);
$words[$i] = strrev($words[$i]);
array_push($english, $words[$i]);
if ($en_index == -1) {
$en_index = $i;
}
} elseif ($en_index != -1) {
$en_count = count($english);
for ($j = 0; $j < $en_count; $j++) {
$words[$en_index + $j] = $english[$en_count - 1 - $j];
}
$en_index = -1;
$english = array();
}
$en_count = count($english);
for ($j = 0; $j < $en_count; $j++) {
$words[$en_index + $j] = $english[$en_count - 1 - $j];
}
}
for ($i = 0; $i < $w_count; $i++) {
$w_len = strlen($words[$i]) + 1;
if ($c_chars + $w_len < $max_chars) {
if (preg_match("/\n/i", $words[$i])) {
$words_nl = explode("\n", $words[$i]);
array_push($c_words, $words_nl[0]);
array_push($lines, implode(' ', $c_words));
$nl_num = count($words_nl) - 1;
for ($j = 1; $j < $nl_num; $j++) {
array_push($lines, $words_nl[$j]);
}
$c_words = array($words_nl[$nl_num]);
$c_chars = strlen($words_nl[$nl_num]) + 1;
} else {
array_push($c_words, $words[$i]);
$c_chars += $w_len;
}
} else {
array_push($lines, implode(' ', $c_words));
$c_words = array($words[$i]);
$c_chars = $w_len;
}
}
array_push($lines, implode(' ', $c_words));
$max_line = count($lines);
$output = '';
for ($j = $max_line - 1; $j >= 0; $j--) {
$output .= $lines[$j] . "\n";
}
$output = rtrim($output);
$output = $this->_preConvert($output);
if ($hindo) {
$Nums = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
$arNums = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩');
$output = str_replace($Nums, $arNums, $output);
}
return $output;
}
/**
* Decode all HTML entities (including numerical ones) to regular UTF-8 bytes.
* Double-escaped entities will only be decoded once ("&amp;lt;" becomes "&lt;", not "<").
*
* @param string $text The text to decode entities in.
* @param array $exclude An array of characters which should not be decoded.
* For example, array('<', '&', '"'). This affects
* both named and numerical entities.
*
* @return string
*/
protected function _decodeEntities($text, $exclude = array())
{
static $table;
// We store named entities in a table for quick processing.
if (!isset($table)) {
// Get all named HTML entities.
$table = array_flip(get_html_translation_table(HTML_ENTITIES));
// PHP gives us ISO-8859-1 data, we need UTF-8.
$table = array_map('utf8_encode', $table);
// Add apostrophe (XML)
$table['&apos;'] = "'";
}
$newtable = array_diff($table, $exclude);
// Use a regexp to select all entities in one pass, to avoid decoding
// double-escaped entities twice.
return preg_replace('/&(#x?)?([A-Za-z0-9]+);/e', '$this
->_decodeEntities2("$1", "$2", "$0", $newtable, $exclude)', $text);
}
/**
* Helper function for _decodeEntities
*
* @param string $prefix Prefix
* @param string $codepoint Codepoint
* @param string $original Original
* @param array &$table Store named entities in a table
* @param array &$exclude An array of characters which should not be decoded
*
* @return string
*/
protected function _decodeEntities2($prefix, $codepoint, $original, &$table, &$exclude)
{
// Named entity
if (!$prefix) {
if (isset($table[$original])) {
return $table[$original];
} else {
return $original;
}
}
// Hexadecimal numerical entity
if ($prefix == '#x') {
$codepoint = base_convert($codepoint, 16, 10);
}
// Encode codepoint as UTF-8 bytes
if ($codepoint < 0x80) {
$str = chr($codepoint);
} elseif ($codepoint < 0x800) {
$str = chr(0xC0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3F));
} elseif ($codepoint < 0x10000) {
$str = chr(0xE0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3F)) . chr(0x80 | ($codepoint & 0x3F));
} elseif ($codepoint < 0x200000) {
$str = chr(0xF0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3F)) . chr(0x80 | (($codepoint >> 6) & 0x3F)) . chr(0x80 | ($codepoint & 0x3F));
}
// Check for excluded characters
if (in_array($str, $exclude)) {
return $original;
} else {
return $str;
}
}
}
?>

View File

@@ -0,0 +1,340 @@
<?php
/**
* ----------------------------------------------------------------------
*
* Copyright (C) 2009 by Khaled Al-Shamaa.
*
* http://www.ar-php.org
*
* ----------------------------------------------------------------------
*
* LICENSE
*
* This program is open source product; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License (LGPL)
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/lgpl.txt>.
*
* ----------------------------------------------------------------------
*
* Class Name: PHP and Arabic Language
*
* Filename: Arabic.php
*
* Original Author(s): Khaled Al-Sham'aa <khaled.alshamaa@gmail.com>
*
* Purpose: Set of PHP classes developed to enhance Arabic web
* applications by providing set of tools includes stem-based searching,
* translitiration, soundex, Hijri calendar, charset detection and
* converter, spell numbers, keyboard language, Muslim prayer time,
* auto-summarization, and more...
*
* ----------------------------------------------------------------------
*
* @desc Set of PHP classes developed to enhance Arabic web
* applications by providing set of tools includes stem-based searching,
* translitiration, soundex, Hijri calendar, charset detection and
* converter, spell numbers, keyboard language, Muslim prayer time,
* auto-summarization, and more...
* @category Text
* @package Arabic
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
* @copyright 2009 Khaled Al-Shamaa
*
* @license LGPL <http://www.gnu.org/licenses/lgpl.txt>
* @version 2.5.2 released in Sep 16, 2009
* @link http://www.ar-php.org
*/
// New in PHP V5.3: Namespaces
// namespace Arabic;
//error_reporting(E_STRICT);
$use_exception = false;
$use_autoload = false;
/**
* Error handler function
*
* @param int $errno The level of the error raised
* @param string $errstr The error message
* @param string $errfile The filename that the error was raised in
* @param int $errline The line number the error was raised at
*
* @return boolean FALSE
*/
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
if ($errfile == __FILE__ || file_exists(dirname(__FILE__).'/'.basename($errfile))) {
$msg = '<b>Arabic Class Exception:</b> ';
$msg .= $errstr;
$msg .= " in <b>$errfile</b>";
$msg .= " on line <b>$errline</b><br />";
throw new ArabicException($msg, $errno);
}
// If the function returns false then the normal error handler continues
return false;
}
if ($use_exception) {
set_error_handler('myErrorHandler');
}
/**
* Core PHP and Arabic language class
*
* @category Text
* @package Arabic
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
* @copyright 2009 Khaled Al-Shamaa
*
* @license LGPL <http://www.gnu.org/licenses/lgpl.txt>
* @link http://www.ar-php.org
*/
class Arabic
{
protected $_inputCharset = 'utf-8';
protected $_outputCharset = 'utf-8';
protected $_path;
public $myObject;
public $myClass;
/**
* Load selected library/sub class you would like to use its functionality
*
* @param string $library [ArAutoSummarize|ArCharsetC|ArCharsetD|ArDate|
* ArGender|ArGlyphs|ArIdentifier|ArKeySwap|ArMktime|ArNumbers|
* ArQuery|ArSoundex|ArStrToTime|ArTransliteration|ArWordTag|
* EnTransliteration|Salat|ArCompressStr|ArStandard|ArStemmer]
*
* @desc Load selected library/sub class you would like to use its functionality
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
*/
public function __construct($library)
{
if($library) $this->load($library);
}
public function load($library)
{
global $use_autoload;
$this->myClass = $library;
if (!$use_autoload) {
$this->_path = strtr(__FILE__, '\\', '/');
$this->_path = substr($this->_path, 0, strrpos($this->_path, '/'));
include_once $this->_path.'/'.$this->myClass.'.class.php';
}
$this->myObject = new $library();
$this->{$library} = &$this->myObject;
}
/**
* The magic method __call() allows to capture invocation of non existing methods.
* That way __call() can be used to implement user defined method handling that
* depends on the name of the actual method being called.
*
* @param string $methodName Method name
* @param array $arguments Array of arguments
*
* @return The value returned from the __call() method will be returned to
* the caller of the method.
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
*/
public function __call($methodName, $arguments)
{
// Create an instance of the ReflectionMethod class
$method = new ReflectionMethod($this->myClass, $methodName);
$params = array();
$parameters = $method->getParameters();
foreach ($parameters as $parameter) {
$name = $parameter->getName();
$value = array_shift($arguments);
if (is_null($value) && $parameter->isDefaultValueAvailable()) $value = $parameter->getDefaultValue();
if ($name == 'main') $value = $this;
$params[$name] = $value;
}
return call_user_func_array(array(&$this->myObject, $methodName), $params);
}
/**
* Garbage collection, release child objects directly
*
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
*/
public function __destruct()
{
$this->_inputCharset = null;
$this->_outputCharset = null;
$this->_path = null;
$this->myObject = null;
$this->myClass = null;
}
/**
* Set charset used in class input Arabic strings
*
* @param string $charset Input charset [utf-8|windows-1256|iso-8859-6]
*
* @return TRUE if success, or FALSE if fail
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
*/
public function setInputCharset($charset)
{
$flag = true;
$charset = strtolower($charset);
if (in_array($charset, array('utf-8', 'windows-1256', 'iso-8859-6'))) {
$this->_inputCharset = $charset;
} else {
$flag = false;
}
return $flag;
}
/**
* Set charset used in class output Arabic strings
*
* @param string $charset Output charset [utf-8|windows-1256|iso-8859-6]
*
* @return boolean TRUE if success, or FALSE if fail
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
*/
public function setOutputCharset($charset)
{
$flag = true;
$charset = strtolower($charset);
if (in_array($charset, array('utf-8', 'windows-1256', 'iso-8859-6'))) {
$this->_outputCharset = $charset;
} else {
$flag = false;
}
return $flag;
}
/**
* Get the charset used in the input Arabic strings
*
* @return string return current setting for class input Arabic charset
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
*/
public function getInputCharset()
{
return $this->_inputCharset;
}
/**
* Get the charset used in the output Arabic strings
*
* @return string return current setting for class output Arabic charset
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
*/
public function getOutputCharset()
{
return $this->_outputCharset;
}
/**
* Convert Arabic string from one charset to another
*
* @param string $str Original Arabic string that you wouldliketo convert
* @param string $inputCharset Input charset
* @param string $outputCharset Output charset
*
* @return string Converted Arabic string in defined charset
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
*/
public function coreConvert($str, $inputCharset, $outputCharset)
{
if ($inputCharset != $outputCharset) {
if ($inputCharset == 'windows-1256') $inputCharset = 'cp1256';
if ($outputCharset == 'windows-1256') $outputCharset = 'cp1256';
$conv_str = iconv($inputCharset, "$outputCharset//TRANSLIT", $str);
if($conv_str == '' && $str != '') {
include_once($this->_path.'/ArCharsetC.class.php');
$c = ArCharsetC::singleton();
if ($inputCharset == 'cp1256') {
$conv_str = $c->win2utf($str);
} else {
$conv_str = $c->utf2win($str);
}
}
} else {
$conv_str = $str;
}
return $conv_str;
}
/**
* Convert Arabic string from one format to another
*
* @param string $str Arabic string in the format set by setInputCharset
* @param string $inputCharset (optional) Input charset [utf-8|windows-1256|iso-8859-6]
* default value is NULL (use set input charset)
* @param string $outputCharset (optional) Output charset [utf-8|windows-1256|iso-8859-6]
* default value is NULL (use set output charset)
*
* @return string Arabic string in the format set by method setOutputCharset
* @author Khaled Al-Shamaa <khaled.alshamaa@gmail.com>
*/
public function convert($str, $inputCharset = null, $outputCharset = null)
{
if ($inputCharset == null) $inputCharset = $this->_inputCharset;
if ($outputCharset == null) $outputCharset = $this->_outputCharset;
$str = $this->coreConvert($str, $inputCharset, $outputCharset);
return $str;
}
}
/**
* Arabic Exception class defined by extending the built-in Exception class.
*
* @category Text
* @package Arabic
* @author Khaled Al-Shamaa <khaled@ar-php.org>
* @copyright 2009 Khaled Al-Shamaa
*
* @license LGPL <http://www.gnu.org/licenses/lgpl.txt>
* @link http://www.ar-php.org
*/
class ArabicException extends Exception
{
/**
* Make sure everything is assigned properly
*
* @param string $message Exception message
* @param int $code User defined exception code
*/
public function __construct($message, $code=0)
{
parent::__construct($message, $code);
}
}
?>

View File

@@ -1,25 +1,25 @@
<?php
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: language.php 4524 2008-03-21 23:01:41Z lemeur $
*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: language.php 9648 2011-01-07 13:06:39Z c_schmitz $
*
Wrapper to use phpgettext as a class and omit having an english translation
USAGE:
require_once($rootdir.'classes/core/language.php');
$locale = new limesurvey_lang('en'); // Char code
print $locale->getTranslation("Hello World!");
*/
Wrapper to use phpgettext as a class and omit having an english translation
USAGE:
require_once($rootdir.'classes/core/language.php');
$locale = new limesurvey_lang('en'); // Char code
print $locale->getTranslation("Hello World!");
*/
if (!isset($rootdir) || isset($_REQUEST['rootdir'])) {die("Cannot run this script directly");}
@@ -30,69 +30,127 @@ class limesurvey_lang {
var $gettextclass;
var $langcode;
function limesurvey_lang($langcode){
global $rootdir;
$langcode=sanitize_languagecode($langcode);
$streamer = new FileReader($rootdir.'/locale/'.$langcode.'/LC_MESSAGES/'.$langcode.'.mo');
$this->gettextclass = new gettext_reader($streamer);
$this->langcode = $langcode;
global $rootdir;
$langcode=sanitize_languagecode($langcode);
$streamer = new FileReader($rootdir.'/locale/'.$langcode.'/LC_MESSAGES/'.$langcode.'.mo');
$this->gettextclass = new gettext_reader($streamer);
$this->langcode = $langcode;
}
function getlangcode()
{
return $this->langcode;
}
function gTview($string, $escapemode = 'html')
{
global $addTitleToLinks;
if ( $addTitleToLinks === true)
{
return $this->gT($string, $escapemode = 'html');
}
else
{
return '';
}
return $this->langcode;
}
function gTview($string, $escapemode = 'html')
{
global $addTitleToLinks;
if ( $addTitleToLinks === true)
{
return $this->gT($string, $escapemode = 'html');
}
else
{
return '';
}
}
/**
* This function translates plural strings to their according language
*
* @param $single $string The single form of the string to translate
* @param $plural $string The plural form to translate
* @param $number $integer Depending on the number of items the right plural form is taken
* @param mixed $escapemode Different uses require the string to be escaped accordinlgy. Possible values are 'html'(default),'js' and 'unescaped'
* @return string Translated string
*/
function ngT($single, $plural, $number, $escapemode = 'html')
{
if ($this->gettextclass)
{
$basestring=str_replace('&lsquo;','\'',$this->gettextclass->ngettext($single, $plural, $number));
switch ($escapemode)
{
case 'html':
return html_escape($basestring);
break;
case 'js':
return javascript_escape($basestring);
break;
case 'unescaped':
return $basestring;
break;
default:
return "Unsupported EscapeMode in gT method";
break;
}
} else {
switch ($escapemode)
{
case 'html':
return html_escape($string);
break;
case 'js':
return javascript_escape($string);
break;
case 'unescaped':
return $string;
break;
default:
return "Unsupported EscapeMode in gT method";
break;
}
}
}
/**
* This function translates strings to their according language
*
* @param string $string The string to translate
* @param mixed $escapemode Different uses require the string to be escaped accordinlgy. Possible values are 'html'(default),'js' and 'unescaped'
* @return string Translated string
*/
function gT($string, $escapemode = 'html')
{
if ($this->gettextclass)
if ($this->gettextclass)
{
$basestring=str_replace('&lsquo;','\'',$this->gettextclass->translate($string));
switch ($escapemode)
{
case 'html':
return html_escape($basestring);
break;
case 'js':
return javascript_escape($basestring);
break;
case 'unescaped':
return $basestring;
break;
default:
return "Unsupported EscapeMode in gT method";
break;
}
$basestring=str_replace('&lsquo;','\'',$this->gettextclass->translate($string));
switch ($escapemode)
{
case 'html':
return html_escape($basestring);
break;
case 'js':
return javascript_escape($basestring);
break;
case 'unescaped':
return $basestring;
break;
default:
return "Unsupported EscapeMode in gT method";
break;
}
} else {
switch ($escapemode)
{
case 'html':
return html_escape($string);
break;
case 'js':
return javascript_escape($string);
break;
case 'unescaped':
return $string;
break;
default:
return "Unsupported EscapeMode in gT method";
break;
}
switch ($escapemode)
{
case 'html':
return html_escape($string);
break;
case 'js':
return javascript_escape($string);
break;
case 'unescaped':
return $string;
break;
default:
return "Unsupported EscapeMode in gT method";
break;
}
}
}

View File

@@ -1,30 +1,30 @@
<?php
/*
* $Id: sanitize.php 7497 2009-08-19 17:12:48Z c_schmitz $
*
* Copyright (c) 2002,2003 Free Software Foundation
* developed under the custody of the
* Open Web Application Security Project
* (http://www.owasp.org)
*
* This file is part of the PHP Filters.
* PHP Filters is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PHP Filters is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* If you are not able to view the LICENSE, which should
* always be possible within a valid and working PHP Filters release,
* please write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* to get a copy of the GNU General Public License or to report a
* possible license violation.
*/
* $Id: sanitize.php 9998 2011-04-12 11:34:43Z c_schmitz $
*
* Copyright (c) 2002,2003 Free Software Foundation
* developed under the custody of the
* Open Web Application Security Project
* (http://www.owasp.org)
*
* This file is part of the PHP Filters.
* PHP Filters is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PHP Filters is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* If you are not able to view the LICENSE, which should
* always be possible within a valid and working PHP Filters release,
* please write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* to get a copy of the GNU General Public License or to report a
* possible license violation.
*/
///////////////////////////////////////
// sanitize.inc.php
// Sanitization functions for PHP
@@ -74,96 +74,81 @@ define("FLOAT", 32);
define("LDAP", 64);
define("UTF8", 128);
// get register_globals ini setting - jp
$register_globals = (bool) ini_get('register_globals');
if ($register_globals == TRUE) { define("REGISTER_GLOBALS", 1); } else { define("REGISTER_GLOBALS", 0); }
// get magic_quotes_gpc ini setting - jp
$magic_quotes = (bool) ini_get('magic_quotes_gpc');
$magic_quotes = (bool) @ini_get('magic_quotes_gpc');
if ($magic_quotes == TRUE) { define("MAGIC_QUOTES", 1); } else { define("MAGIC_QUOTES", 0); }
// addslashes wrapper to check for gpc_magic_quotes - gz
function nice_addslashes($string)
{
// if magic quotes is on the string is already quoted, just return it
if(MAGIC_QUOTES)
return $string;
else
return addslashes($string);
// if magic quotes is on the string is already quoted, just return it
if(MAGIC_QUOTES)
return $string;
else
return addslashes($string);
}
/**
* 1. Remove leading and trailing dots
* 2. Remove dodgy characters from filename, including spaces and dots except last.
* 3. Force extension if specified..
*
* @param mixed $filename
* @param mixed $forceextension
* @return string
*/
function sanitize_filename($filename, $forceextension="")
{
$defaultfilename = "none";
$dodgychars = "[^0-9a-zA-z()_-]"; // allow only alphanumeric, underscore, parentheses and hyphen
* Function: sanitize_filename
* Returns a sanitized string, typically for URLs.
*
* Parameters:
* $string - The string to sanitize.
* $force_lowercase - Force the string to lowercase?
* $alphanumeric - If set to *true*, will remove all non-alphanumeric characters.
*/
$filename = preg_replace("/^[.]*/","",$filename); // lose any leading dots
$filename = preg_replace("/[.]*$/","",$filename); // lose any trailing dots
$filename = $filename?$filename:$defaultfilename; // if filename is blank, provide default
$lastdotpos=strrpos($filename, "."); // save last dot position
$filename = preg_replace("/$dodgychars/","_",$filename); // replace dodgy characters
$afterdot = "";
if ($lastdotpos !== false) { // Split into name and extension, if any.
$beforedot = substr($filename, 0, $lastdotpos);
if ($lastdotpos < (strlen($filename) - 1))
$afterdot = substr($filename, $lastdotpos + 1);
function sanitize_filename($string, $force_lowercase = true, $alphanumeric = false) {
$strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]",
"}", "\\", "|", ";", ":", "\"", "'", "&#8216;", "&#8217;", "&#8220;", "&#8221;", "&#8211;", "&#8212;",
"", "", ",", "<", ".", ">", "/", "?");
$lastdot=strrpos($string, ".");
$clean = trim(str_replace($strip, "_", strip_tags($string)));
$clean = preg_replace('/\s+/', "-", $clean);
$clean = ($alphanumeric) ? preg_replace("/[^a-zA-Z0-9]/", "", $clean) : $clean ;
if ($lastdot !== false) {
$clean= substr_replace ( $clean , '.' , $lastdot , 1 );
}
else // no extension
$beforedot = $filename;
if ($forceextension)
$filename = $beforedot . "." . $forceextension;
elseif ($afterdot)
$filename = $beforedot . "." . $afterdot;
else
$filename = $beforedot;
return $filename;
return ($force_lowercase) ?
(function_exists('mb_strtolower')) ?
mb_strtolower($clean, 'UTF-8') :
strtolower($clean) :
$clean;
}
// paranoid sanitization -- only let the alphanumeric set through
function sanitize_paranoid_string($string, $min='', $max='')
{
if (isset($string))
{
$string = preg_replace("/[^_.a-zA-Z0-9]/", "", $string);
$len = strlen($string);
if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max)))
return FALSE;
return $string;
}
if (isset($string))
{
$string = preg_replace("/[^_.a-zA-Z0-9]/", "", $string);
$len = strlen($string);
if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max)))
return FALSE;
return $string;
}
}
function sanitize_cquestions($string, $min='', $max='')
{
if (isset($string))
{
$string = preg_replace("/[^_.a-zA-Z0-9+#]/", "", $string);
$len = strlen($string);
if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max)))
return FALSE;
return $string;
}
if (isset($string))
{
$string = preg_replace("/[^_.a-zA-Z0-9+#]/", "", $string);
$len = strlen($string);
if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max)))
return FALSE;
return $string;
}
}
function sanitize_email($email) {
// Handles now emails separated with a semikolon
// Handles now emails separated with a semikolon
$emailarray=explode(';',$email);
for ($i = 0; $i <= count($emailarray)-1; $i++)
{
$emailarray[$i]=preg_replace('/[^a-zA-Z0-9;+_.@-]/i', '', $emailarray[$i]);
$emailarray[$i]=preg_replace("/[^`'a-zA-Z0-9;+_=|.$%&#!{*~?}^@-]/i", "", $emailarray[$i]);
}
return implode(';',$emailarray);
}
@@ -171,23 +156,23 @@ function sanitize_email($email) {
// sanitize a string in prep for passing a single argument to system() (or similar)
function sanitize_system_string($string, $min='', $max='')
{
if (isset($string))
{
$pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i'; // no piping, passing possible environment variables ($),
// seperate commands, nested execution, file redirection,
// background processing, special commands (backspace, etc.), quotes
// newlines, or some other special characters
$string = preg_replace($pattern, '', $string);
$string = '"'.preg_replace('/\$/', '\\\$', $string).'"'; //make sure this is only interpretted as ONE argument
$len = strlen($string);
if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max))) return FALSE;
return $string;
}
if (isset($string))
{
$pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i'; // no piping, passing possible environment variables ($),
// seperate commands, nested execution, file redirection,
// background processing, special commands (backspace, etc.), quotes
// newlines, or some other special characters
$string = preg_replace($pattern, '', $string);
$string = '"'.preg_replace('/\$/', '\\\$', $string).'"'; //make sure this is only interpretted as ONE argument
$len = strlen($string);
if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max))) return FALSE;
return $string;
}
}
function sanitize_xss_string($string)
{
if (isset($string))
if (isset($string))
{
$bad = array ('*','^','&','\'','-',';','\"','(',')','%','$','?');
return str_replace($bad, '',$string);
@@ -199,62 +184,62 @@ function sanitize_xss_string($string)
// sanitize a string for SQL input (simple slash out quotes and slashes)
function sanitize_sql_db_tablename($string)
{
$bad = array ('*','^','&','\'','-',';','\"','(',')','%','$','?');
return str_replace($bad, "",$string);
$bad = array ('*','^','&','\'','-',';','\"','(',')','%','$','?');
return str_replace($bad, "",$string);
}
// sanitize a string for SQL input (simple slash out quotes and slashes)
function sanitize_ldap_string($string, $min='', $max='')
{
$pattern = '/(\)|\(|\||&)/';
$len = strlen($string);
if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max)))
return FALSE;
return preg_replace($pattern, '', $string);
$pattern = '/(\)|\(|\||&)/';
$len = strlen($string);
if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max)))
return FALSE;
return preg_replace($pattern, '', $string);
}
// sanitize a string for HTML (make sure nothing gets interpretted!)
function sanitize_html_string($string)
{
$pattern[0] = '/\&/';
$pattern[1] = '/</';
$pattern[2] = "/>/";
$pattern[3] = '/\n/';
$pattern[4] = '/"/';
$pattern[5] = "/'/";
$pattern[6] = "/%/";
$pattern[7] = '/\(/';
$pattern[8] = '/\)/';
$pattern[9] = '/\+/';
$pattern[10] = '/-/';
$replacement[0] = '&amp;';
$replacement[1] = '&lt;';
$replacement[2] = '&gt;';
$replacement[3] = '<br />';
$replacement[4] = '&quot;';
$replacement[5] = '&#39;';
$replacement[6] = '&#37;';
$replacement[7] = '&#40;';
$replacement[8] = '&#41;';
$replacement[9] = '&#43;';
$replacement[10] = '&#45;';
return preg_replace($pattern, $replacement, $string);
$pattern[0] = '/\&/';
$pattern[1] = '/</';
$pattern[2] = "/>/";
$pattern[3] = '/\n/';
$pattern[4] = '/"/';
$pattern[5] = "/'/";
$pattern[6] = "/%/";
$pattern[7] = '/\(/';
$pattern[8] = '/\)/';
$pattern[9] = '/\+/';
$pattern[10] = '/-/';
$replacement[0] = '&amp;';
$replacement[1] = '&lt;';
$replacement[2] = '&gt;';
$replacement[3] = '<br />';
$replacement[4] = '&quot;';
$replacement[5] = '&#39;';
$replacement[6] = '&#37;';
$replacement[7] = '&#40;';
$replacement[8] = '&#41;';
$replacement[9] = '&#43;';
$replacement[10] = '&#45;';
return preg_replace($pattern, $replacement, $string);
}
// make int int!
function sanitize_int($integer, $min='', $max='')
{
$int = preg_replace("#[^0-9]#", "", $integer);
if((($min != '') && ($int < $min)) || (($max != '') && ($int > $max)))
$int = preg_replace("#[^0-9]#", "", $integer);
if((($min != '') && ($int < $min)) || (($max != '') && ($int > $max)))
{
return FALSE;
return FALSE;
}
if ($int=='')
if ($int=='')
{
return null;
}
return $int;
return $int;
}
// sanitize a username
@@ -262,9 +247,9 @@ function sanitize_int($integer, $min='', $max='')
// allow for instance 0-9a-zA-Z@_-.
function sanitize_user($string)
{
$username_length=64;
$string=mb_substr($string,0,$username_length);
return $string;
$username_length=64;
$string=mb_substr($string,0,$username_length);
return $string;
}
// sanitize a username
@@ -272,119 +257,121 @@ function sanitize_user($string)
// allow for instance 0-9a-zA-Z@_-.
function sanitize_userfullname($string)
{
$username_length=50;
$string=mb_substr($string,0,$username_length);
return $string;
$username_length=50;
$string=mb_substr($string,0,$username_length);
return $string;
}
function sanitize_labelname($string)
{
$username_length=100;
$string=mb_substr($string,0,$username_length);
return $string;
$labelname_length=100;
$string=mb_substr($string,0,$labelname_length);
return $string;
}
// make float float!
function sanitize_float($float, $min='', $max='')
{
$float = floatval($float);
if((($min != '') && ($float < $min)) || (($max != '') && ($float > $max)))
return FALSE;
return $float;
$float = str_replace(',','.',$float);
$float = floatval($float);
if((($min != '') && ($float < $min)) || (($max != '') && ($float > $max)))
return FALSE;
return $float;
}
// glue together all the other functions
function sanitize($input, $flags, $min='', $max='')
{
if($flags & PARANOID) $input = sanitize_paranoid_string($input, $min, $max);
if($flags & INT) $input = sanitize_int($input, $min, $max);
if($flags & FLOAT) $input = sanitize_float($input, $min, $max);
if($flags & HTML) $input = sanitize_html_string($input, $min, $max);
if($flags & LDAP) $input = sanitize_ldap_string($input, $min, $max);
if($flags & SYSTEM) $input = sanitize_system_string($input, $min, $max);
return $input;
if($flags & PARANOID) $input = sanitize_paranoid_string($input, $min, $max);
if($flags & INT) $input = sanitize_int($input, $min, $max);
if($flags & FLOAT) $input = sanitize_float($input, $min, $max);
if($flags & HTML) $input = sanitize_html_string($input, $min, $max);
if($flags & LDAP) $input = sanitize_ldap_string($input, $min, $max);
if($flags & SYSTEM) $input = sanitize_system_string($input, $min, $max);
return $input;
}
function check_paranoid_string($input, $min='', $max='')
{
if($input != sanitize_paranoid_string($input, $min, $max))
return FALSE;
return TRUE;
if($input != sanitize_paranoid_string($input, $min, $max))
return FALSE;
return TRUE;
}
function check_int($input, $min='', $max='')
{
if($input != sanitize_int($input, $min, $max))
return FALSE;
return TRUE;
if($input != sanitize_int($input, $min, $max))
return FALSE;
return TRUE;
}
function check_float($input, $min='', $max='')
{
if($input != sanitize_float($input, $min, $max))
return FALSE;
return TRUE;
if($input != sanitize_float($input, $min, $max))
return FALSE;
return TRUE;
}
function check_html_string($input, $min='', $max='')
{
if($input != sanitize_html_string($input, $min, $max))
return FALSE;
return TRUE;
if($input != sanitize_html_string($input, $min, $max))
return FALSE;
return TRUE;
}
function check_ldap_string($input, $min='', $max='')
{
if($input != sanitize_string($input, $min, $max))
return FALSE;
return TRUE;
if($input != sanitize_string($input, $min, $max))
return FALSE;
return TRUE;
}
function check_system_string($input, $min='', $max='')
{
if($input != sanitize_system_string($input, $min, $max, TRUE))
return FALSE;
return TRUE;
if($input != sanitize_system_string($input, $min, $max, TRUE))
return FALSE;
return TRUE;
}
// glue together all the other functions
function check($input, $flags, $min='', $max='')
{
$oldput = $input;
if($flags & UTF8) $input = my_utf8_decode($input);
if($flags & PARANOID) $input = sanitize_paranoid_string($input, $min, $max);
if($flags & INT) $input = sanitize_int($input, $min, $max);
if($flags & FLOAT) $input = sanitize_float($input, $min, $max);
if($flags & HTML) $input = sanitize_html_string($input, $min, $max);
if($flags & LDAP) $input = sanitize_ldap_string($input, $min, $max);
if($flags & SYSTEM) $input = sanitize_system_string($input, $min, $max, TRUE);
if($input != $oldput)
return FALSE;
return TRUE;
$oldput = $input;
if($flags & UTF8) $input = my_utf8_decode($input);
if($flags & PARANOID) $input = sanitize_paranoid_string($input, $min, $max);
if($flags & INT) $input = sanitize_int($input, $min, $max);
if($flags & FLOAT) $input = sanitize_float($input, $min, $max);
if($flags & HTML) $input = sanitize_html_string($input, $min, $max);
if($flags & LDAP) $input = sanitize_ldap_string($input, $min, $max);
if($flags & SYSTEM) $input = sanitize_system_string($input, $min, $max, TRUE);
if($input != $oldput)
return FALSE;
return TRUE;
}
function sanitize_languagecode($codetosanitize) {
return preg_replace('/[^a-z0-9-]/i', '', $codetosanitize);
return preg_replace('/[^a-z0-9-]/i', '', $codetosanitize);
}
function sanitize_languagecodeS($codestringtosanitize) {
$codearray=explode(" ",trim($codestringtosanitize));
$codearray=array_map("sanitize_languagecode",$codearray);
return implode(" ",$codearray);
$codearray=explode(" ",trim($codestringtosanitize));
$codearray=array_map("sanitize_languagecode",$codearray);
return implode(" ",$codearray);
}
function sanitize_token($codetosanitize) {
return preg_replace('/[^_a-z0-9]/i', '', $codetosanitize);
}
function sanitize_signedint($integer, $min='', $max='')
{
$int = (int) $integer;
$int = (int) $integer;
if((($min != '') && ($int < $min)) || (($max != '') && ($int > $max)))
{
{
return FALSE; // Oops! Outside limits.
}
return $int;
};
?>

View File

@@ -1,5 +1,10 @@
<?php
if(ob_get_contents() !== false)
{
ob_clean();
};
ob_start();
@ini_set("session.bug_compat_warn", 0); //Turn this off until first "Next" warning is worked out
@@ -10,9 +15,9 @@ if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals
/*
* Remove variables created by register_globals from the global scope
* Thanks to Matt Kavanagh
*/
* Remove variables created by register_globals from the global scope
* Thanks to Matt Kavanagh
*/
function deregister_globals()
{
$not_unset = array(
@@ -37,13 +42,13 @@ function deregister_globals()
// Merge all into one extremely huge array; unset this later
$input = array_merge(
array_keys($_GET),
array_keys($_POST),
array_keys($_COOKIE),
array_keys($_SERVER),
array_keys($_SESSION),
array_keys($_ENV),
array_keys($_FILES)
array_keys($_GET),
array_keys($_POST),
array_keys($_COOKIE),
array_keys($_SERVER),
array_keys($_SESSION),
array_keys($_ENV),
array_keys($_FILES)
);
foreach ($input as $varname)
@@ -60,6 +65,33 @@ function deregister_globals()
unset($input);
}
/**
* This function converts a standard # array to a PHP array without having to resort to JSON_decode which is available from 5.2x and up only
*
* @param string $json String with JSON data
* @return array
*/
if ( !function_exists('json_decode') ){
function json_decode($content, $assoc=false){
global $homedir;
require_once($homedir."/classes/json/JSON.php");
if ( $assoc ){
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
} else {
$json = new Services_JSON;
}
return $json->decode($content);
}
}
if ( !function_exists('json_encode') ){
function json_encode($content){
global $homedir;
require_once($homedir."/classes/json/JSON.php");
$json = new Services_JSON;
return $json->encode($content);
}
}
?>

File diff suppressed because it is too large Load Diff