" . $suggestions[$i] . "
";
}
if ($usePersonalDict) {
$retVal .= " because we don't want the links to be clickable
//but we want the html to be rendered in the div for preview purposes.
$string = preg_replace("//i", "
", $string);
$string = preg_replace("//i", "", $string);
$string = preg_replace("//i", "
", $string);
$string = preg_replace("//i", "", $string);
$string = preg_replace("//i", "", $string);
$string = preg_replace("//i", "", $string);
$string = preg_replace("//i", "", $string);
$string = preg_replace("//i", "", $string);
$string = preg_replace("//i", "", $string);
$string = preg_replace("//i", "", $string);
$string = preg_replace("//i", "", $string);
$string = preg_replace("//i", "", $string);
$string = preg_replace("//i", "
", $string);
$string = preg_replace("//i", "", $string);
$string = preg_replace("//i", "", $string);
$string = preg_replace("//i", "", $string);
$cp->set_data($string); //return value - string containing all the markup for the misspelled words.
} //end spellCheck function
/*************************************************************
* addWord($str)
*
* This function adds a word to the custom dictionary
*
* @param $str The word to be added
*************************************************************/
function addWord($str)
{
global $pspell_link; //the global link to the pspell module
global $cp; //the CPAINT object
$retVal = "";
pspell_add_to_personal($pspell_link, $str);
if (pspell_save_wordlist($pspell_link)) {
$retVal = "Save successful!";
} else {
$retVal = "Save Failed!";
}
$cp->set_data($retVal);
} //end addWord function
/*************************************************************
* flattenArray($array)
*
* The flattenArray function is a recursive function that takes a
* multidimensional array and flattens it to be a one-dimensional
* array. The one-dimensional flattened array is returned.
*
* $array - The array to be flattened.
*
*************************************************************/
function flattenArray($array)
{
$flatArray = array();
foreach ($array as $subElement) {
if (is_array($subElement)) {
$flatArray = array_merge($flatArray, flattenArray($subElement));
} else {
$flatArray[] = $subElement;
}
}
return $flatArray;
} //end flattenArray function
/*************************************************************
* stripslashes_custom($string)
*
* This is a custom stripslashes function that only strips
* the slashes if magic quotes are on. This is written for
* compatibility with other servers in the event someone doesn't
* have magic quotes on.
*
* $string - The string that might need the slashes stripped.
*
*************************************************************/
function stripslashes_custom($string)
{
if (get_magic_quotes_gpc()) {
return stripslashes($string);
} else {
return $string;
}
}
/*************************************************************
* addslashes_custom($string)
*
* This is a custom addslashes function that only adds
* the slashes if magic quotes are off. This is written for
* compatibility with other servers in the event someone doesn't
* have magic quotes on.
*
* $string - The string that might need the slashes added.
*
*************************************************************/
function addslashes_custom($string)
{
if (!get_magic_quotes_gpc()) {
return addslashes($string);
} else {
return $string;
}
}
/*************************************************************
* remove_word_junk($t)
*
* This function strips out all the crap that Word tries to
* add to it's text in the even someone pastes in code from
* Word.
*
* $t - The text to be cleaned
*
*************************************************************/
function remove_word_junk($t)
{
$a=array(
"\xe2\x80\x9c"=>'"',
"\xe2\x80\x9d"=>'"',
"\xe2\x80\x99"=>"'",
"\xe2\x80\xa6"=>"...",
"\xe2\x80\x98"=>"'",
"\xe2\x80\x94"=>"---",
"\xe2\x80\x93"=>"--",
"\x85"=>"...",
"\221"=>"'",
"\222"=>"'",
"\223"=>'"',
"\224"=>'"',
"\x97"=>"---",
"\x96"=>"--"
);
foreach ($a as $k=>$v) {
$oa[]=$k;
$ra[]=$v;
}
//debug_log(implode(",",$oa));
$t=trim(str_replace($oa, $ra, $t));
return $t;
}//end remove_word_junk function
/*************************************************************
* switchText($string)
*
* This function prepares the text to be sent back to the text
* box from the div. The comments are removed and breaks are
* converted back into \n's. All the html tags that the user
* might have entered that aren't on the approved list:
*
- are stripped out.
* The user-entered returns have already been replaced with
* $u2026 so that they can be preserved. I replace all the
* \n's that might have been added by the browser (Firefox does
* this in trying to pretty up the HTML) with " " so that
* everything will look the way it did when the user typed it
* in the box the first time.
*
* $string - The string of html from the div that will be sent
* back to the text box.
*
*************************************************************/
function switchText($string)
{
global $allowed_html;
global $cp; //the CPAINT object
$string = remove_word_junk($string);
$string = preg_replace("//", "", $string);
$string = preg_replace("/\r?\n/", " ", $string);
$string = stripslashes_custom($string); //we only need to strip slashes if magic quotes are on
$string = strip_tags_advanced($string, $allowed_html);
$string = preg_replace('{</?span.*?>}i', '', $string);
$string = html_entity_decode($string);
$cp->set_data($string); //the return value
} //end switchText function
//============================
// strip_tags_advanced
//============================
//
// Works like strip_tags, but disallowed tags are converted
// to escaped html, rather than being removed. This function
// also escapes tags with unsupported attributes (such as
// onmouseover).
//
// $str: The string to strip tags on.
// $valid_tags: A string of valid tags. For attributes valid
// on a tag, they should be comma-delimited, without
// spaces after the commas.
//
// Thanks to kip for this function!!
//====================================================
function strip_tags_advanced($str, $valid_tags)
{
//validate input
if (0 == preg_match('/^(<\\w+(\\s+(\\w+,)*\\w+)?>)*$/', $valid_tags)) {
return '';
}
//----------------------------------------------------------
//Convert $valid_tags into a regular expression
//For example:
//
// becomes
// (b)|(i)|(u)|(a(\s+((href)(=(["][^"<>]+["]|['][^'<>]+[']))?))*)|(img(\s+((src|alt)(=(["][^"<>]+["]|['][^'<>]+[']))?))*)
//----------------------------------------------------------
$valid_tag_exp = $valid_tags;
//first covert <>'s to (), with ORs between tags
$valid_tag_exp = preg_replace('/>', ')|(', $valid_tag_exp);
$valid_tag_exp = preg_replace('/>/', ')', $valid_tag_exp);
$valid_tag_exp = preg_replace('/', '(', $valid_tag_exp);
//now append the expression to the attributes within the tag, so that they can match something like ''
$valid_tag_exp = preg_replace('/\\s+((\\w+,)*\\w+)/', '(\\s+(($1)(=(["][^"<>]+["]|[\'][^\'<>]+[\']))?))*', $valid_tag_exp);
$valid_tag_exp = preg_replace('/,/', '|', $valid_tag_exp);
//----------------------------------------------------------
// Get the number of parenthesis in the expression.
//----------------------------------------------------------
$paren_count = substr_count($valid_tag_exp, '(');
//----------------------------------------------------------
// Now format the string
//----------------------------------------------------------
$result = $str;
//first convert any <'s not followed by a letter or / to <
$result = preg_replace('{<([^a-z/])}i', '<$1', $result);
//now, convert any <'s or >'s that don't have a partner
$result = preg_replace('/<([^<>]*)(?=<)/', '<$1', $result);
$result = preg_replace('/(?<=>)([^<>]*)>/', '$1>', $result);
//now, convert any leading >'s or trailing <'s, which the previous expressions wouldn't pick up
$result = preg_replace('/^([^<>]*)>/', '$1>', $result);
$result = preg_replace('/<([^<>]*)$/', '<$1', $result);
//finally, convert any tags that do not match $valid_tag_pattern to <$tag>
$result = preg_replace('{<(?!/?(' . $valid_tag_exp . ')\\s*/?(?=>))([^>]*)>}i', '<$' . ($paren_count + 2) . '>', $result);
return $result;
}