Skip to content

Commit

Permalink
Fixed issue #07159: PHP notice for arabic graph in statistics
Browse files Browse the repository at this point in the history
Dev: this time REALLY update to ar-php 3.6.0
Dev: add fix for php notice ONLY
  • Loading branch information
Shnoulle committed Jan 22, 2014
1 parent 076d51d commit f5e791d
Show file tree
Hide file tree
Showing 29 changed files with 1,249 additions and 894 deletions.
126 changes: 40 additions & 86 deletions application/third_party/ar-php/Arabic.php
Expand Up @@ -2,7 +2,7 @@
/**
* ----------------------------------------------------------------------
*
* Copyright (c) 2006-2012 Khaled Al-Shamaa.
* Copyright (c) 2006-2013 Khaled Al-Shamaa.
*
* http://www.ar-php.org
*
Expand Down Expand Up @@ -50,10 +50,10 @@
* @category I18N
* @package I18N_Arabic
* @author Khaled Al-Shamaa <khaled@ar-php.org>
* @copyright 2006-2012 Khaled Al-Shamaa
* @copyright 2006-2013 Khaled Al-Shamaa
*
* @license LGPL <http://www.gnu.org/licenses/lgpl.txt>
* @version 3.0.0 released in Feb 5, 2012 with {@link http://bugs.limesurvey.org/view.php?id=7159 LimeSurvey fix}
* @version 3.6.0 released in Jan 20, 2013 with {@link http://bugs.limesurvey.org/view.php?id=7159 LimeSurvey fix}
* @link http://www.ar-php.org
*/

Expand All @@ -68,7 +68,7 @@
* @category I18N
* @package I18N_Arabic
* @author Khaled Al-Shamaa <khaled@ar-php.org>
* @copyright 2006-2012 Khaled Al-Shamaa
* @copyright 2006-2013 Khaled Al-Shamaa
*
* @license LGPL <http://www.gnu.org/licenses/lgpl.txt>
* @link http://www.ar-php.org
Expand Down Expand Up @@ -136,9 +136,9 @@ class I18N_Arabic
* @desc Load selected library/class you would like to use its functionality
* @author Khaled Al-Shamaa <khaled@ar-php.org>
*/
public function __construct($library, $useAutoload=false,
$useException=false, $compatibleMode=true)
{
public function __construct(
$library, $useAutoload=false, $useException=false, $compatibleMode=true
) {
$this->_useAutoload = $useAutoload;
$this->_useException = $useException;
$this->_compatibleMode = $compatibleMode;
Expand All @@ -165,9 +165,9 @@ public function __construct($library, $useAutoload=false,
}

if ($library) {
if ($this->_compatibleMode &&
array_key_exists($library, $this->_compatible)) {
if ($this->_compatibleMode
&& array_key_exists($library, $this->_compatible)
) {
$library = $this->_compatible[$library];
}

Expand Down Expand Up @@ -201,9 +201,12 @@ public static function autoload($className)
*/
public static function myErrorHandler($errno, $errstr, $errfile, $errline)
{
if ($errfile == __FILE__ ||
file_exists(dirname(__FILE__).DIRECTORY_SEPARATOR.'Arabic'.
DIRECTORY_SEPARATOR.basename($errfile))) {
if ($errfile == __FILE__
|| file_exists(
dirname(__FILE__).DIRECTORY_SEPARATOR.'Arabic'.
DIRECTORY_SEPARATOR.basename($errfile)
)
) {
$msg = '<b>Arabic Class Exception:</b> ';
$msg .= $errstr;
$msg .= " in <b>$errfile</b>";
Expand All @@ -226,8 +229,9 @@ public static function myErrorHandler($errno, $errstr, $errfile, $errline)
*/
public function load($library)
{
if ($this->_compatibleMode &&
array_key_exists($library, $this->_compatible)) {
if ($this->_compatibleMode
&& array_key_exists($library, $this->_compatible)
) {

$library = $this->_compatible[$library];
}
Expand Down Expand Up @@ -261,8 +265,9 @@ public function load($library)
*/
public function __call($methodName, $arguments)
{
if ($this->_compatibleMode &&
array_key_exists($methodName, $this->_compatible)) {
if ($this->_compatibleMode
&& array_key_exists($methodName, $this->_compatible)
) {

$methodName = $this->_compatible[$methodName];
}
Expand All @@ -281,17 +286,20 @@ public function __call($methodName, $arguments)
$value = $parameter->getDefaultValue();
}

$params[$name] = $this->coreConvert($value,
$this->getInputCharset(),
'utf-8');
$params[$name] = $this->coreConvert(
$value,
$this->getInputCharset(),
'utf-8'
);
}

$value = call_user_func_array(array(&$this->myObject, $methodName), $params);

if ($methodName == 'tagText') {
foreach ($value as $key=>$text) {
$value[$key][0] = $this->coreConvert($text[0], 'utf-8',
$this->getOutputCharset());
$value[$key][0] = $this->coreConvert(
$text[0], 'utf-8', $this->getOutputCharset()
);
}
} else {
$value = $this->coreConvert($value, 'utf-8', $this->getOutputCharset());
Expand Down Expand Up @@ -476,7 +484,8 @@ protected static function getClassFile($class)
* @param string $mode [http|html|mysql|mysqli|pdo|text_email|html_email]
* @param resource $conn The MySQL connection handler/the link identifier
*
* @return string header formula if there is any (in cases of html, text_email, and html_email)
* @return string header formula if there is any (in cases of html,
* text_email, and html_email)
* @author Khaled Al-Shamaa <khaled@ar-php.org>
*/
public static function header($mode = 'http', $conn = null)
Expand Down Expand Up @@ -532,7 +541,6 @@ public static function header($mode = 'http', $conn = null)
return $head;
}


/**
* Get web browser chosen/default language using ISO 639-1 codes (2-letter)
*
Expand All @@ -547,75 +555,21 @@ public static function getBrowserLang()
}

/**
* Renders regular expression pattern using an enhanced version of syntax and semantics
* to support arabic version of some specifying generic character types
*
* @param string $pattern The pattern to search for, as a string using syntax and
* semantics of the regular expressions enhanced by arabic
* version of some specifying generic character types:
* \[ar]w any Arabic letter (including Harakat and Tatweel if $vowels is true)
* \[ar]d any decimal Arabic-Indic digit
* \[ar]v any Arabic vowel character (i.e. Harakat including Tatweel)
* \[ar]p any Arabic puncation character
* \[ar]W any character that is not an Arabic letter (including Harakat and Tatweel if $vowels is true)
* \[ar]D any character that is not a decimal Arabic-Indic digit
* \[ar]V any character that is not an Arabic vowel character (i.e. Harakat including Tatweel)
* \[ar]P any character that is not an Arabic puncation character
* @param boolean $vowels True will include Harakat and Tatweel to the Arabic
* letters set (default is true)
*
* @return string Rendered regular expression pattern
* @author Khaled Al-Shamaa <khaled@ar-php.org>
*/
public static function pregPattern($pattern, $vowels=true)
{
/**
* PCRE Patterns - Pattern Modifiers: u (PCRE8)
* This modifier turns on additional functionality of PCRE that is
* incompatible with Perl. Pattern strings are treated as UTF-8.
* This modifier is available from PHP 4.1.0 or greater on Unix and
* from PHP 4.2.3 on win32. UTF-8 validity of the pattern is checked
* since PHP 4.3.5
*/

$arDigits = '\x{0660}-\x{0669}'; // Arabic-Indic digits
$arVowels = '\x{0640}\x{064B}-\x{0652}'; // Harakat including Tatweel
$arLetters = '\x{0621}-\x{063A}\x{0641}-\x{064A}'; // Arabic letters
$arPuncation = '\x{060C}\x{060D}\x{061B}-\x{061F}\x{2E2E}\x{066A}-\x{066D}'; // Puncation

if ($vowels === true) {
$arLetters .= $arVowels;
}

$pattern = str_replace('\[ar]w', $arLetters, $pattern);
$pattern = str_replace('\[ar]d', $arDigits, $pattern);
$pattern = str_replace('\[ar]v', $arVowels, $pattern);
$pattern = str_replace('\[ar]p', $arPuncation, $pattern);

$pattern = str_replace('\[ar]W', "[^$arLetters]", $pattern);
$pattern = str_replace('\[ar]D', "[^$arDigits]", $pattern);
$pattern = str_replace('\[ar]V', "[^$arVowels]", $pattern);
$pattern = str_replace('\[ar]P', "[^$arPuncation]", $pattern);

return $pattern;
}

/**
* There is still a lack of original, localized, high-quality content and well-structured
* Arabic websites; This method help in tag HTML result pages from Arabic forum to enable
* filter it in/out.
* There is still a lack of original, localized, high-quality content and
* well-structured Arabic websites; This method help in tag HTML result pages
* from Arabic forum to enable filter it in/out.
*
* @param string $html The HTML content of the page in question
* @param string $html The HTML content of the page in question
*
* @return boolean True if the input HTML is belong to a forum page
* @author Khaled Al-Shamaa <khaled@ar-php.org>
*/
public static function isForum($html)
{
$forum = FALSE;
$forum = false;

if (strpos($html, 'vBulletin_init();') !== FALSE) {
$forum = TRUE;
if (strpos($html, 'vBulletin_init();') !== false) {
$forum = true;
}

return $forum;
Expand All @@ -628,7 +582,7 @@ public static function isForum($html)
* @category I18N
* @package I18N_Arabic
* @author Khaled Al-Shamaa <khaled@ar-php.org>
* @copyright 2006-2012 Khaled Al-Shamaa
* @copyright 2006-2013 Khaled Al-Shamaa
*
* @license LGPL <http://www.gnu.org/licenses/lgpl.txt>
* @link http://www.ar-php.org
Expand Down
54 changes: 35 additions & 19 deletions application/third_party/ar-php/Arabic/AutoSummarize.php
Expand Up @@ -2,7 +2,7 @@
/**
* ----------------------------------------------------------------------
*
* Copyright (c) 2006-2012 Khaled Al-Sham'aa.
* Copyright (c) 2006-2013 Khaled Al-Sham'aa.
*
* http://www.ar-php.org
*
Expand Down Expand Up @@ -122,7 +122,7 @@
* @category I18N
* @package I18N_Arabic
* @author Khaled Al-Sham'aa <khaled@ar-php.org>
* @copyright 2006-2012 Khaled Al-Sham'aa
* @copyright 2006-2013 Khaled Al-Sham'aa
*
* @license LGPL <http://www.gnu.org/licenses/lgpl.txt>
* @link http://www.ar-php.org
Expand All @@ -147,7 +147,7 @@
* @category I18N
* @package I18N_Arabic
* @author Khaled Al-Sham'aa <khaled@ar-php.org>
* @copyright 2006-2012 Khaled Al-Sham'aa
* @copyright 2006-2013 Khaled Al-Sham'aa
*
* @license LGPL <http://www.gnu.org/licenses/lgpl.txt>
* @link http://www.ar-php.org
Expand Down Expand Up @@ -216,7 +216,11 @@ public function loadExtra()
*/
protected function summarize($str, $keywords, $int, $mode, $output, $style=null)
{
preg_match_all("/[^\.\n\،\؛\,\;](.+?)[\.\n\،\؛\,\;]/u", $str, $sentences);
preg_match_all(
"/[^\.\n\،\؛\,\;](.+?)[\.\n\،\؛\,\;]/u",
$str,
$sentences
);
$_sentences = $sentences[0];

if ($mode == 'rate') {
Expand All @@ -237,7 +241,11 @@ protected function summarize($str, $keywords, $int, $mode, $output, $style=null)
$cleanedStr = $this->cleanCommon($normalizedStr);
$stemStr = $this->draftStem($cleanedStr);

preg_match_all("/[^\.\n\،\؛\,\;](.+?)[\.\n\،\؛\,\;]/u", $stemStr, $sentences);
preg_match_all(
"/[^\.\n\،\؛\,\;](.+?)[\.\n\،\؛\,\;]/u",
$stemStr,
$sentences
);
$_stemmedSentences = $sentences[0];

$wordRanks = $this->rankWords($stemStr);
Expand All @@ -252,9 +260,11 @@ protected function summarize($str, $keywords, $int, $mode, $output, $style=null)
}
}

$sentencesRanks = $this->rankSentences($_sentences,
$_stemmedSentences,
$wordRanks);
$sentencesRanks = $this->rankSentences(
$_sentences,
$_stemmedSentences,
$wordRanks
);

list($sentences, $ranks) = $sentencesRanks;

Expand Down Expand Up @@ -297,8 +307,9 @@ protected function summarize($str, $keywords, $int, $mode, $output, $style=null)
*/
public function doSummarize($str, $int, $keywords)
{
$summary = $this->summarize($str, $keywords, $int,
'number', 'summary', $style);
$summary = $this->summarize(
$str, $keywords, $int, 'number', 'summary', $style
);

return $summary;
}
Expand All @@ -317,8 +328,9 @@ public function doSummarize($str, $int, $keywords)
*/
public function doRateSummarize($str, $rate, $keywords)
{
$summary = $this->summarize($str, $keywords, $rate,
'rate', 'summary', $style);
$summary = $this->summarize(
$str, $keywords, $rate, 'rate', 'summary', $style
);

return $summary;
}
Expand All @@ -339,8 +351,9 @@ public function doRateSummarize($str, $rate, $keywords)
*/
public function highlightSummary($str, $int, $keywords, $style)
{
$summary = $this->summarize($str, $keywords, $int,
'number', 'highlight', $style);
$summary = $this->summarize(
$str, $keywords, $int, 'number', 'highlight', $style
);

return $summary;
}
Expand All @@ -361,8 +374,9 @@ public function highlightSummary($str, $int, $keywords, $style)
*/
public function highlightRateSummary($str, $rate, $keywords, $style)
{
$summary = $this->summarize($str, $keywords, $rate,
'rate', 'highlight', $style);
$summary = $this->summarize(
$str, $keywords, $rate, 'rate', 'highlight', $style
);

return $summary;
}
Expand Down Expand Up @@ -447,9 +461,11 @@ protected function doNormalize($str)
{
$str = str_replace($this->_normalizeAlef, 'ا', $str);
$str = str_replace($this->_normalizeDiacritics, '', $str);
$str = strtr($str,
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz');
$str = strtr(
$str,
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz'
);

return $str;
}
Expand Down

0 comments on commit f5e791d

Please sign in to comment.