示例#1
0
 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);
 }
示例#2
0
 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);
 }