/**
  * Function that will look for any grouped
  * parent for the given path, returning it if found,
  * false if not
  */
 protected function grouped_parent_exists($path)
 {
     $parentpath = progressive_parser::dirname($path);
     while ($parentpath != '/') {
         if ($this->path_is_grouped($parentpath)) {
             return $parentpath;
         }
         $parentpath = progressive_parser::dirname($parentpath);
     }
     return false;
 }
Exemplo n.º 2
0
 protected function end_tag($parser, $tag)
 {
     // Ending rencently started tag, add value to current tag
     if ($this->level == $this->prevlevel) {
         $this->currtag['cdata'] = $this->postprocess_cdata($this->accum);
         $this->topush['tags'][$this->currtag['name']] = $this->currtag;
         $this->currtag = array();
     }
     // Leaving one level, publish all the information available
     if ($this->level < $this->prevlevel) {
         if (!empty($this->topush['tags'])) {
             $this->publish($this->topush);
         }
         $this->currtag = array();
         $this->topush = array();
     }
     // For the records
     $this->prevlevel = $this->level;
     // Inform processor we have finished one tag
     $this->inform_end($this->path);
     // Normal update of parser internals
     $this->level--;
     $this->path = progressive_parser::dirname($this->path);
 }
Exemplo n.º 3
0
 protected function end_tag($parser, $tag)
 {
     // Ending rencently started tag, add value to current tag
     if ($this->level == $this->prevlevel) {
         $this->currtag['cdata'] = $this->postprocess_cdata($this->accum);
         // We always add the last not-empty repetition. Empty ones are ignored.
         if (isset($this->topush['tags'][$this->currtag['name']]) && trim($this->currtag['cdata']) === '') {
             // Do nothing, the tag already exists and the repetition is empty
         } else {
             $this->topush['tags'][$this->currtag['name']] = $this->currtag;
         }
         $this->currtag = array();
     }
     // Leaving one level, publish all the information available
     if ($this->level < $this->prevlevel) {
         if (!empty($this->topush['tags'])) {
             $this->publish($this->topush);
         }
         $this->currtag = array();
         $this->topush = array();
     }
     // For the records
     $this->prevlevel = $this->level;
     // Inform processor we have finished one tag
     $this->inform_end($this->path);
     // Normal update of parser internals
     $this->level--;
     $this->path = progressive_parser::dirname($this->path);
 }
 /**
  * Get one chunk of parsed data and make it simpler
  * adding attributes as tags and delegating to
  * dispatch_chunk() the procesing of the resulting chunk
  */
 public function process_chunk($data)
 {
     // Precalculate some vars for readability
     $path = $data['path'];
     $parentpath = progressive_parser::dirname($path);
     $tag = basename($path);
     // If the path is a registered parent one, store all its tags
     // so, we'll be able to find attributes later when processing
     // (child) registered paths (to get attributes if present)
     if ($this->path_is_selected_parent($path)) {
         // if path is parent
         if (isset($data['tags'])) {
             // and has tags, save them
             $this->parentsinfo[$path] = $data['tags'];
         }
     }
     // If the path is a registered one, let's process it
     if ($this->path_is_selected($path)) {
         // First of all, look for attributes available at parentsinfo
         // in order to get them available as normal tags
         if (isset($this->parentsinfo[$parentpath][$tag]['attrs'])) {
             $data['tags'] = array_merge($this->parentsinfo[$parentpath][$tag]['attrs'], $data['tags']);
             unset($this->parentsinfo[$parentpath][$tag]['attrs']);
         }
         // Now, let's simplify the tags array, ignoring tag attributtes and
         // reconverting to simpler name => value array. At the same time,
         // check for all the tag values being whitespace-string values, if all them
         // are whitespace strings, we aren't going to postprocess/dispatch the chunk
         $alltagswhitespace = true;
         foreach ($data['tags'] as $key => $value) {
             // If the value is already a single value, do nothing
             // surely was added above from parentsinfo attributes,
             // so we'll process the chunk always
             if (!is_array($value)) {
                 $alltagswhitespace = false;
                 continue;
             }
             // If the path including the tag name matches another selected path
             // (registered or parent) and is null or begins with linefeed, we know it's part
             // of another chunk, delete it, another chunk will contain that info
             if ($this->path_is_selected($path . '/' . $key) || $this->path_is_selected_parent($path . '/' . $key)) {
                 if (!isset($value['cdata']) || substr($value['cdata'], 0, 1) === "\n") {
                     unset($data['tags'][$key]);
                     continue;
                 }
             }
             // Convert to simple name => value array
             $data['tags'][$key] = isset($value['cdata']) ? $value['cdata'] : null;
             // Check $alltagswhitespace continues being true
             if ($alltagswhitespace && strlen($data['tags'][$key]) !== 0 && trim($data['tags'][$key]) !== '') {
                 $alltagswhitespace = false;
                 // Found non-whitespace value
             }
         }
         // Arrived here, if the chunk has tags and not all tags are whitespace,
         // send it to postprocess filter that will decide about dispatching. Else
         // skip the chunk completely
         if (!empty($data['tags']) && !$alltagswhitespace) {
             return $this->postprocess_chunk($data);
         } else {
             $this->chunks--;
             // Chunk skipped
         }
     } else {
         $this->chunks--;
         // Chunk skipped
     }
     return true;
 }
 /**
  * Get the parent path using a local cache for performance.
  *
  * @param $path string The pathname you wish to obtain the parent name for.
  * @return string The parent pathname.
  */
 protected function get_parent_path($path)
 {
     if (!isset($this->parentcache[$path])) {
         $this->parentcache[$path] = progressive_parser::dirname($path);
         $this->parentcacheavailablesize--;
         if ($this->parentcacheavailablesize < 0) {
             // Older first is cheaper than LRU.  We use 10% as items are grouped together and the large quiz
             // restore from MDL-40585 used only 600 parent paths. This is an XML heirarchy, so common paths
             // are grouped near each other. eg; /question_bank/question_category/question/element. After keeping
             // question_bank paths in the cache when we move to another area and the question_bank cache is not
             // useful any longer.
             $this->parentcache = array_slice($this->parentcache, 200, null, true);
             $this->parentcacheavailablesize += 200;
         }
     }
     return $this->parentcache[$path];
 }