arrHxMappings[] = array('1','h2'); } function parse($strUbbalisedPseudoHtml='') { $this->strParseSource = $strUbbalisedPseudoHtml; $this->strParseResult = $strUbbalisedPseudoHtml; $strParsing = $this->strParseSource; // html-zutt omzetten in &aap; if ($this->blnConvertToSpecialChars) $strParsing = htmlspecialchars($strParsing); // line-breaks naar
omzetten if ($this->blnConvertNl2Br) $strParsing = nl2br($strParsing); if ($this->blnParseB) $strParsing = $this->parse_b($strParsing); if ($this->blnParseI) $strParsing = $this->parse_i($strParsing); if ($this->blnParseU) $strParsing = $this->parse_u($strParsing); if ($this->blnParseUl) $strParsing = $this->parse_list($strParsing,'ul'); if ($this->blnParseOl) $strParsing = $this->parse_list($strParsing,'ol'); if ($this->blnParseHr) $strParsing = $this->parse_hr($strParsing); if ($this->blnParseHx) $strParsing = $this->parse_hx($strParsing); if ($this->blnParseUrl) $strParsing = $this->parse_url($strParsing); if ($this->blnParseEmail) $strParsing = $this->parse_email($strParsing); foreach ($this->arrExtraParsingObjectHandlers as $arrObjectHandler) { $arrFunction = Array($arrObjectHandler[0],$arrObjectHandler[1]); $arrParam = Array($strParsing); $strParsing = call_user_func_array($arrFunction,$arrParam); } $this->strParseResult = $strParsing; return $this->strParseResult; } function addParserFunction(& $objParserObject, $strMethodName) { $this->arrExtraParsingObjectHandlers[] = Array($objParserObject,$strMethodName); } /* -- parse functions -- */ function parse_b($strInput='') { return preg_replace('/\[[bB]\]((.|\n|\r)*?)\[\/[bB]\]/','\\1',$strInput); } function parse_i($strInput='') { return preg_replace('/\[[iI]\]((.|\n|\r)*?)\[\/[iI]\]/','\\1',$strInput); } function parse_u($strInput='') { return preg_replace('/\[[uU]\]((.|\n|\r)*?)\[\/[uU]\]/','\\1',$strInput); } function parse_hr($strInput='') { return eregi_replace('\[hr\]','
',$strInput); } function parse_list($strInput='',$strType='ul') { switch($strType) { case 'ul': // $strPattern = '/\[[uU][lL]\]((.|\n|\r)*?)\[\/[uU][lL]\]/'; $strPattern = '/\[[uU][lL]\]([\w\W]*?)\[\/[uU][lL]\]/'; $strHtmlListTag = 'ul'; break; case 'ol': $strPattern = '/\[[oO][lL]\]((.|\n|\r)*?)\[\/[oO][lL]\]/'; $strHtmlListTag = 'ol'; break; default: return $strInput; break; } $arrMatchData = array(); $strOutput = $strInput; $blnCont = true; while (preg_match($strPattern,$strOutput,$arrResults) && $blnCont) { $strTotalUbbString = $arrResults[0]; $strUlContents = $arrResults[1]; $strTotalHtmlString = ''; $strHtmlListItems = ''; $strWorking = ereg_replace('\[[lL][iI]\]','[li]',$strUlContents); $arrListItems = explode('[li]',$strWorking); for ($i=0;$i $strItemText = trim($arrListItems[$i]); $strItemText = preg_replace('/^<[bB][rR]\s?\/?>/','',$strItemText); $strItemText = preg_replace('/<[bB][rR]\s?\/?>$/','',$strItemText); if (strlen($strItemText)>0) { $strHtmlListItems .= "\t".'
  • '.$strItemText.'
  • '."\n"; } } $strTotalHtmlString = '<'.$strHtmlListTag.'>'."\n".$strHtmlListItems.''."\n"; $strOutput = str_replace($strTotalUbbString,$strTotalHtmlString,$strOutput); } return $strOutput; } function parse_hx($strInput='') { $strOutput = $strInput; for ($i=0;$iarrHxMappings);$i++) { $arrRow = $this->arrHxMappings[$i]; $strUbbNumber = (string) $arrRow[0]; $strHtmlTagPart = $arrRow[1]; $strPattern = '/\[[hH]'.$strUbbNumber.'\](.*?)\[\/[hH]'.$strUbbNumber.'\]/'; $strReplace = '<'.$strHtmlTagPart.'>\\1'; $strOutput = "\n".preg_replace($strPattern,$strReplace,$strOutput)."\n"; } return $strOutput; } function parse_url($strInput='') { $arrMatchData = array(); $strOutput = $strInput; while (preg_match('/\[[uU][rR][lL]\=((.|\n|\r)*?)\]((.|\n|\r)*?)\[\/[uU][rR][lL]\]/',$strOutput,$arrResults)) { $blnNew = false; $strTotalUbbString = $arrResults[0]; $strTotalHtmlString = ''; $strHrefPart = $arrResults[1]; $strHrefCleaned = $arrResults[1]; $strHrefChecked = ''; $strHrefTarget = ''; $strTextPart = $arrResults[3]; // href part analyseren if ( (strtolower(trim(substr($strHrefPart,-4)))=='new') ) { $blnNew = true; $strHrefTarget = ' target="_blank" '; $strHrefCleaned = trim(substr($strHrefPart,0,-4)); } // tags uit hrefPart filteren $strHrefCleaned = $this->strip_tags($strHrefCleaned); // zeker zorgen dat http:// er voor staat $strHrefCleaned = trim(str_replace('http://','',$strHrefCleaned)); $strHrefChecked = 'http://'.$strHrefCleaned; // TB 20060131 url_encode? // indien geen tekst dan href als tekst if (strlen(trim($strTextPart))==0) $strTextPart = $strHrefCleaned; $strTotalHtmlString = ''.$strTextPart.''; // do the actual replace, belangrijk dat dat goed gaat maar dat zou wel moeten aangezien // het deel dat vervangen wordt exact de 'match' is die de ereg-functie terug geeft. $strOutput = str_replace($strTotalUbbString,$strTotalHtmlString,$strOutput); } return $strOutput; } function parse_email($strInput='') { $arrMatchData = array(); $strOutput = $strInput; while (preg_match('/\[[eE][mM][aA][iI][lL]\=((.|\n|\r)*?)\]((.|\n|\r)*?)\[\/[eE][mM][aA][iI][lL]\]/',$strOutput,$arrResults)) { $blnNew = false; $strTotalUbbString = $arrResults[0]; $strTotalHtmlString = ''; $strEmailPart = $arrResults[1]; $strEmailCleaned = $arrResults[1]; $strEmailChecked = ''; $strTextPart = $arrResults[3]; // tags uit email filteren $strEmailCleaned = $this->strip_tags($strEmailCleaned); // zeker zorgen dat mailto:// er voor staat $strEmailCleaned = trim(str_replace('mailto:','',$strEmailCleaned)); $strEmailChecked = 'mailto:'.$strEmailCleaned; // indien geen tekst dan href als tekst if (strlen(trim($strTextPart))==0) $strTextPart = $strEmailCleaned; $strTotalHtmlString = ''.$strTextPart.''; // do the actual replace, belangrijk dat dat goed gaat maar dat zou wel moeten aangezien // het deel dat vervangen wordt exact de 'match' is die de ereg-functie terug geeft. $strOutput = str_replace($strTotalUbbString,$strTotalHtmlString,$strOutput); } return $strOutput; } /* -- other functions -- */ function make_paragraphs($strInput='') { // nothing yet return $strInput; } function strip_tags($strInput='') { $strOutput = preg_replace('/<([\w\W]*?)>/','',$strInput); return $strOutput; } } ?>objDatabase = $objDatabase; $this->arrConfig = $arrConfig; } function getJsCatsItems($strArrCatsName='arrCats',$strArrItemsName='arrItems') { $strJsChunk = <<arrConfig as $arrConfigItem) { $strUbbLink = '[link '.$arrConfigItem['code'].']'; $strJsChunk .= "{$strArrCatsName}[{$intCatsCount}] = Array('{$arrConfigItem['name_cat']}','{$arrConfigItem['code']}','{$strUbbLink}');"; if ($arrConfigItem['enable_item']==true) { if (isset($arrConfigItem['dbCustomQueryPublic']) && strlen($arrConfigItem['dbCustomQueryPublic'])>0) { $strQuery = $arrConfigItem['dbCustomQueryPublic']; } else { $strQuery = <<objDatabase->query_result($strQuery); $strJsItems = "{$strArrItemsName}[$intCatsCount] = new Array();\n"; // ook een item '[geen specifiek item]' toevoegen indien enable_cat==true $intAddValue = 0; if ($arrConfigItem['enable_cat']==true) { $strUbbLink = '[link '.$arrConfigItem['code'].']'; $strNoItemText = (isset($arrConfigItem['no_item_text'])) ? $arrConfigItem['no_item_text'] : '[geen specifiek item]'; $strJsItems .= "{$strArrItemsName}[$intCatsCount][0] = Array('{$strNoItemText}',0,'{$strUbbLink}');\n"; $intAddValue = 1; } for ($i=0;$iarrConfig as $arrConfigItem) { // hele categorie vetalen naar link if ($arrConfigItem['enable_cat']==true) { $strPattern = '/\[link\s+'.$arrConfigItem['code'].'](.*?)\[\/link]/'; $strReplace = '\\1'; $strWorking = preg_replace($strPattern,$strReplace,$strWorking); } // specifieke items vetalen naar link if ($arrConfigItem['enable_item']==true) { $strPattern = '/\[link\s+'.$arrConfigItem['code'].'\s([0-9]+)](.*?)\[\/link]/'; $strReplace = '\\2'; $strReplace = str_replace('##id##','\\1',$strReplace); $strWorking = preg_replace($strPattern,$strReplace,$strWorking); } } return $strWorking; } function buildPublicIds() { $arrIds = array(); foreach($this->arrConfig as $arrConfigItem) { $strCode = $arrConfigItem['code']; if (isset($arrConfigItem['dbCustomQueryPublic']) && strlen($arrConfigItem['dbCustomQueryPublic'])>0) { $strQuery = $arrConfigItem['dbCustomQueryPublic']; } else { $strQuery = <<objDatabase->query_result($strQuery); $arrCurrentIds = array(); foreach($arrResult as $arrResultItem) { $arrCurrentIds[] = (int) $arrResultItem['id']; } $arrIds[$strCode] = $arrCurrentIds; } $this->arrIdsPublic = $arrIds; } function buildEditingIds() { $arrIds = array(); foreach($this->arrConfig as $arrConfigItem) { $strCode = $arrConfigItem['code']; if (isset($arrConfigItem['dbCustomQueryEditing']) && strlen($arrConfigItem['dbCustomQueryEditing'])>0) { $strQuery = $arrConfigItem['dbCustomQueryEditing']; } else { $strQuery = <<objDatabase->query_result($strQuery); $arrCurrentIds = array(); foreach($arrResult as $arrResultItem) { $arrCurrentIds[] = (int) $arrResultItem['id']; } $arrIds[$strCode] = $arrCurrentIds; } $this->arrIdsEditing = $arrIds; } /** * call this to check for broken links, feed with dataset with fields id, title and data * * returns array[line][index]: * index = : * 0 - id * 1 - title * 2 - links found, array[index] * index = : * 0 - id's found in public (array[strCode][] = intId) * 1 - id's found in editing (array[strCode][] = intId) * 2 - id's not found (array[strCode][] = intId) * * @param array (recordset) $arrSourceData * @return array */ function examineLinks($arrSourceData = array()) { $this->buildPublicIds(); $this->buildEditingIds(); $arrTotalResult = array(); foreach($arrSourceData as $arrItem) { $intId = $arrItem['id']; $strTitle = $arrItem['title']; $strData = $arrItem['data']; $arrResult = $this->searchForBrokenLinks($strData); $arrResultLine = array($intId, $strTitle, $arrResult); $arrTotalResult[] = $arrResultLine; } return $arrTotalResult; } /** * Searches the given string for ubb-style internal links and checks if they exist * * returns array[index] * 0 - array with ids found in public (=OK) $arrIds[strCode][] = intId * 1 - array with ids found in editing $arrIds[strCode][] = intId * 2 - array with ids not found $arrIds[strCode][] = intId * * @param string $strText * @return array */ function searchForBrokenLinks($strText = '') { // 1. links zoeken // 2. voor alle links kijken of ie bestaat adhv this->arrIdsPublic & this->arrIdsEditing $blnLinksBrokenFound = false; $blnLinksEditingFound = false; $strPattern = '/\[link\s+(\w+)\s([0-9]+)](.*?)\[\/link]/'; $arrIdsFound = array(); $arrIdsEditing = array(); // arrIdsEditing[strCode][] = id $arrIdsNotFound = array(); if (preg_match_all($strPattern,$strText,$arrResults)>0) { $arrTotalUbbStrings = $arrResults[0]; $arrCodes = $arrResults[1]; $arrIds = $arrResults[2]; for($i=0;$ifindIdInPublic($intId, $strCode); $blnFoundInEditing = $this->findIdInEditing($intId, $strCode); if ($blnFoundInPublic==true) { $arrIdsFound[$strCode][] = $intId; } elseif ($blnFoundInEditing==true) { $arrIdsEditing[$strCode][] = $intId; } else { $arrIdsNotFound[$strCode][] = $intId; } } } $arrReturn = array($arrIdsFound,$arrIdsEditing,$arrIdsNotFound); return $arrReturn; } /** * Searches the array with exisiting public articles for the combination of code and id * * @access private * @param integer $intId * @param string $strCode * @return boolean */ function findIdInPublic($intId,$strCode) { $blnFound = false; if (isset($this->arrIdsPublic[$strCode])) { if (in_array($intId, $this->arrIdsPublic[$strCode])) { $blnFound = true; } } return $blnFound; } /** * Searches the array with exisiting editing articles for the combination of code and id * * @access private * @param integer $intId * @param string $strCode * @return boolean */ function findIdInEditing($intId,$strCode) { $blnFound = false; if (isset($this->arrIdsEditing[$strCode])) { if (in_array($intId, $this->arrIdsEditing[$strCode])) { $blnFound = true; } } return $blnFound; } } ?>