original_string: public function text_field($text) {
          $data = array();
          // Step one, find all file refs then add to array.
          preg_match_all('|<img[^>]+src="([^"]*)"|i', $text, $out); // Find all src refs.
          $filepaths = array();
          foreach ($out[1] as $path) {
              $fullpath = $this->filebase . '/' . $path;
  
              if (is_readable($fullpath) && !in_array($path, $filepaths)) {
                  $dirpath = dirname($path);
                  $filename = basename($path);
                  $newfilename = $this->store_file_for_text_field($data, $this->filebase, $dirpath, $filename);
                  $text = preg_replace("|{$path}|", "@@PLUGINFILE@@/" . $newfilename, $text);
                  $filepaths[] = $path;
              }
  
          }
          $data['text'] = $text;
          $data['format'] = FORMAT_HTML;
          return $data;
      }
code: public function text_field($text) {
          $data = array();
          // Step one, find all file refs then add to array.
          preg_match_all('|<img[^>]+src="([^"]*)"|i', $text, $out); // Find all src refs.
          $filepaths = array();
          foreach ($out[1] as $path) {
              $fullpath = $this->filebase . '/' . $path;
  
              if (is_readable($fullpath) && !in_array($path, $filepaths)) {
                  $dirpath = dirname($path);
                  $filename = basename($path);
                  $newfilename = $this->store_file_for_text_field($data, $this->filebase, $dirpath, $filename);
                  $text = preg_replace("|{$path}|", "@@PLUGINFILE@@/" . $newfilename, $text);
                  $filepaths[] = $path;
              }
  
          }
          $data['text'] = $text;
          $data['format'] = FORMAT_HTML;
          return $data;
      }
code_tokens: public function text_field ( $ text ) { $ data = array ( ) ; // Step one, find all file refs then add to array. preg_match_all ( '|<img[^>]+src="([^"]*)"|i' , $ text , $ out ) ; // Find all src refs. $ filepaths = array ( ) ; foreach ( $ out [ 1 ] as $ path ) { $ fullpath = $ this -> filebase . '/' . $ path ; if ( is_readable ( $ fullpath ) && ! in_array ( $ path , $ filepaths ) ) { $ dirpath = dirname ( $ path ) ; $ filename = basename ( $ path ) ; $ newfilename = $ this -> store_file_for_text_field ( $ data , $ this -> filebase , $ dirpath , $ filename ) ; $ text = preg_replace ( "|{$path}|" , "@@PLUGINFILE@@/" . $ newfilename , $ text ) ; $ filepaths [ ] = $ path ; } } $ data [ 'text' ] = $ text ; $ data [ 'format' ] = FORMAT_HTML ; return $ data ; }
docstring: Given an HTML text with references to images files,
  store all images in a draft filearea,
  and return an array with all urls in text recoded,
  format set to FORMAT_HTML, and itemid set to filearea itemid
  @param string $text text to parse and recode
  @return array with keys text, format, itemid.
docstring_tokens: Given an HTML text with references to images files store all images in a draft filearea and return an array with all urls in text recoded format set to FORMAT_HTML and itemid set to filearea itemid