Example #1
0
 /**
  * Replaces matched regular expressions with appropriate data
  * 
  * @param array $matches An array of matches from preg_replace.  $matches[1]=type, $matches[2]=ID, $matches[3]=command, $matches[4]=arguments
  * @return string New text with replaced tags
  **/
 function tags($matches)
 {
     $type = $matches[1];
     $id = intval($matches[2]);
     $cmd = $matches[3];
     $args = $matches[4];
     $options = $this->get_options();
     if ($type == 'hole') {
         $hole = DH_Hole::get($id);
         if ($hole) {
             if ($cmd == 'hits') {
                 return number_format($hole->hits);
             } else {
                 if ($cmd == 'recent') {
                     if ($args == 0) {
                         $args = 1;
                     }
                     $files = DH_File::get_recent($hole->id, $args);
                     return $this->capture('show_hole', array('files' => $files, 'hole' => $hole));
                 } else {
                     if ($cmd == 'show' && !$this->excerpt) {
                         if ($args == '') {
                             $args = 'show_hole';
                         }
                         $files = DH_File::get_all($hole->id);
                         return $this->capture($args, array('files' => $files, 'hole' => $hole));
                     }
                 }
             }
         }
     } else {
         if ($type == 'file') {
             $file = DH_File::get($id);
             if ($file) {
                 $hole = DH_Hole::get($file->hole_id);
                 if ($cmd == 'show' && !$this->excerpt) {
                     if ($args == '') {
                         $args = 'default_show';
                     }
                     return $this->tags_inline($this->capture($args, array('file' => $file, 'hole' => $hole)), $hole, $file);
                 } else {
                     if ($cmd == 'versions') {
                         $limit = 5;
                         if ($args) {
                             $limit = intval($args);
                         }
                         $versions = DH_Version::get_history($file->id, $file->version_id, $limit);
                         if (count($versions) > 0 && $options['tracker']) {
                             foreach ($versions as $pos => $version) {
                                 $versions[$pos]->reason = preg_replace('@\\#(\\d*)@', '<a href="' . $options['tracker'] . '$1">#$1</a>', $version->reason);
                             }
                         }
                         return $this->capture('versions', array('versions' => $versions, 'file' => $file, 'hole' => $hole));
                     } else {
                         if ($cmd == 'version') {
                             return $file->version;
                         } else {
                             if ($cmd == 'hits') {
                                 return number_format($file->hits);
                             } else {
                                 if ($cmd == 'name') {
                                     return $file->name();
                                 } else {
                                     if ($cmd == 'md5') {
                                         return md5($file->file($hole));
                                     } else {
                                         if ($cmd == 'url') {
                                             return $file->url($hole, $args == '' ? basename($file->file) : $args, $options['google']);
                                         } else {
                                             if ($cmd == 'href') {
                                                 return $file->url_ref($hole);
                                             } else {
                                                 if ($cmd == 'svn') {
                                                     return $file->svn();
                                                 } else {
                                                     if ($cmd == 'updated') {
                                                         return date(get_option('date_format'), $file->updated_at);
                                                     } else {
                                                         if ($cmd == 'size') {
                                                             return $file->bytes($file->filesize($hole));
                                                         } else {
                                                             if ($cmd == 'icon') {
                                                                 return $file->icon($hole, $this->url(), $options['google']);
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }