static function protectForm(&$string, $tags = array(), $protected = array()) { if (!NNFrameworkFunctions::isEditPage()) { return; } if (!is_array($tags)) { $tags = array($tags); } if (empty($protected)) { $protected = array(); foreach ($tags as $i => $tag) { $protected[$i] = base64_encode($tag); } } $string = preg_replace(NNFrameworkFunctions::getFormRegex(1), '<!-- TMP_START_EDITOR -->\\1', $string); $string = explode('<!-- TMP_START_EDITOR -->', $string); foreach ($string as $i => $str) { if (!empty($str) != '' && fmod($i, 2)) { $pass = 0; foreach ($tags as $tag) { if (!(strpos($str, $tag) === false)) { $pass = 1; break; } } if ($pass) { $str = explode('</form>', $str, 2); // protect tags only inside form fields if (preg_match_all('#(<textarea[^>]*>.*?<\\/textarea>|<input[^>]*>)#si', $str['0'], $matches, PREG_SET_ORDER) > 0) { foreach ($matches as $match) { $field = str_replace($tags, $protected, $match['0']); $str['0'] = str_replace($match['0'], $field, $str['0']); } } $string[$i] = implode('</form>', $str); } } } $string = implode('', $string); }
function protect( &$string ) { if ( NNFrameworkFunctions::isEditPage() ) { // Protect complete adminForm (to prevent articles from being created when editing articles and such) $unprotected = '{'.$this->params->module_tag; $protected = $this->protectStr( $unprotected ); $string = preg_replace( '#(<'.'form [^>]*(id|name)="(adminForm|postform)")#si', '<!-- TMP_START_EDITOR -->\1', $string ); $string = explode( '<!-- TMP_START_EDITOR -->', $string ); foreach ( $string as $i => $str ) { if ( !empty( $str ) != '' && fmod( $i, 2 ) ) { if ( !( strpos( $str, $unprotected ) === false ) ) { $str = explode( '</form>', $str, 2 ); $str['0'] = str_replace( $unprotected, $protected, $str['0'] ); $string[$i] = implode( '</form>', $str ); } } } $string = implode( '', $string ); } }
static function protectForm(&$string, $tags = array(), $protected = array()) { if (!NNFrameworkFunctions::isEditPage()) { return; } if (!is_array($tags)) { $tags = array($tags); } if (empty($protected)) { $protected = array(); foreach ($tags as $i => $tag) { $protected[$i] = base64_encode($tag); } } $string = preg_replace(NNFrameworkFunctions::getFormRegex(1), '<!-- TMP_START_EDITOR -->\\1', $string); $string = explode('<!-- TMP_START_EDITOR -->', $string); foreach ($string as $i => $str) { if (!empty($str) != '' && fmod($i, 2)) { $pass = 0; foreach ($tags as $tag) { if (!(strpos($str, $tag) === false)) { $pass = 1; break; } } if ($pass) { $str = explode('</form>', $str, 2); $str['0'] = str_replace($tags, $protected, $str['0']); $string[$i] = implode('</form>', $str); } } } $string = implode('', $string); }