You are here

function ueditor_block_save_form_submit in UEditor - 百度编辑器 7.2

support block when create a custom block with use ueditor.

1 string reference to 'ueditor_block_save_form_submit'
ueditor_form_alter in ./ueditor.module
Implementation of hook_form_alter().

File

./ueditor.module, line 825
Integration ueditor for wysiwyg.

Code

function ueditor_block_save_form_submit($form, &$form_state) {
  if (!empty($form_state['values']['body']['value'])) {
    preg_match_all('/(.*?(src|href)=["|\'])(.*?)["|\']/ms', $form_state['values']['body']['value'], $matchs['body']);
  }
  else {
    $matchs['body'][3] = array();
  }
  if (isset($form_state['values']['old_body'])) {
    if (!empty($form_state['values']['old_body'])) {
      preg_match_all('/(.*?(src|href)=["|\'])(.*?)["|\']/ms', $form_state['values']['old_body'], $old_matchs['body']);
    }
    else {
      $old_matchs['body'][3] = array();
    }
    if (!empty($matchs) && !empty($old_matchs)) {
      $diff_new_images = array();
      $diff_old_images = array();
      foreach ($matchs as $k => $match) {
        $intersect = array_intersect_assoc($matchs[$k][3], $old_matchs[$k][3]);
        foreach ($intersect as $i => $item) {
          unset($matchs[$k][3][$i]);
          unset($old_matchs[$k][3][$i]);
        }
        $diff_new_images[$k] = $matchs[$k][3];
        $diff_old_images[$k] = $old_matchs[$k][3];
      }
    }
    if (count(array_filter($diff_new_images))) {
      ueditor_file_register(array_filter($diff_new_images), 'block', 'body', '');
    }
    if (count(array_filter($diff_old_images))) {
      ueditor_delete_file(array_filter($diff_old_images), 'block', 'body', '');
    }
  }
  else {
    if (!empty($matchs['body'][3])) {
      ueditor_file_register($matchs['body'][3], 'block', 'body', '');
    }
  }
}