| @@ -11,12 +11,8 @@ | ||
| 11 | 11 | /*========================================================================== |
| 12 | 12 | * PRIVATE FIELDS |
| 13 | 13 | *=========================================================================*/ |
| 14 | 14 | |
| 15 | - // templates for HTML output | |
| 16 | - private static $doc_icon = false; | |
| 17 | - private static $img_string = '<img src="%s" title="%s" alt="%s" />'; | |
| 18 | - | |
| 19 | 15 | // general document data |
| 20 | 16 | private $description, $gallery, $ID, $link, $title, $title_attribute; |
| 21 | 17 | |
| 22 | 18 | /*========================================================================== |
| @@ -29,18 +25,9 @@ | ||
| 29 | 25 | * @param type $gallery Instance of Gallery class. |
| 30 | 26 | */ |
| 31 | 27 | public function __construct($attachment, $gallery) { |
| 32 | 28 | include_once DG_PATH . 'inc/class-thumber.php'; |
| 33 | - | |
| 34 | - // init template for HTML output | |
| 35 | - if(false === self::$doc_icon) | |
| 36 | - { | |
| 37 | - self::$doc_icon = | |
| 38 | - ' <div class="document-icon">' . PHP_EOL . | |
| 39 | - ' <a href="%s">%s<br>%s</a>' . PHP_EOL . | |
| 40 | - ' </div>' . PHP_EOL; | |
| 41 | - } | |
| 42 | - | |
| 29 | + | |
| 43 | 30 | // init general document data |
| 44 | 31 | $this->gallery = $gallery; |
| 45 | 32 | $this->description = $attachment->post_content; |
| 46 | 33 | $this->ID = $attachment->ID; |
| @@ -56,8 +43,11 @@ | ||
| 56 | 43 | *=========================================================================*/ |
| 57 | 44 | |
| 58 | 45 | /** |
| 59 | 46 | * Returns HTML representing this Document. |
| 47 | + * @filter dg_icon_template Filters the DG icon HTML. Passes a single | |
| 48 | + * bool value indicating whether the gallery is using descriptions or not. | |
| 49 | + * @filter dg_doc_icon Deprecated. To be removed in a future relesase. | |
| 60 | 50 | * @return string |
| 61 | 51 | */ |
| 62 | 52 | public function __toString() { |
| 63 | 53 | $thumb = $this->gallery->useFancyThumbs() |
| @@ -62,18 +52,34 @@ | ||
| 62 | 52 | public function __toString() { |
| 63 | 53 | $thumb = $this->gallery->useFancyThumbs() |
| 64 | 54 | ? DG_Thumber::getThumbnail($this->ID) |
| 65 | 55 | : DG_Thumber::getDefaultThumbnail($this->ID); |
| 66 | - $icon = sprintf(self::$img_string, $thumb, | |
| 67 | - $this->title_attribute, $this->title_attribute); | |
| 68 | - $core = sprintf(self::$doc_icon, $this->link, $icon, $this->title); | |
| 69 | 56 | |
| 70 | - if($this->gallery->useDescriptions()) { | |
| 71 | - $core .= " <p>$this->description</p>" . PHP_EOL; | |
| 57 | + $repl = array($this->link, $thumb, $this->title_attribute, $this->title); | |
| 58 | + $find = array('%link%', '%img%', '%title_attribute%', '%title%'); | |
| 59 | + $description = ''; | |
| 60 | + | |
| 61 | + // if descriptions then add filterable tag and value to replaced tag | |
| 62 | + if ($this->gallery->useDescriptions()) { | |
| 63 | + $repl[] = $this->description; | |
| 64 | + $find[] = '%description%'; | |
| 65 | + $description = ' <p>%description%</p>'; | |
| 72 | 66 | } |
| 67 | + | |
| 68 | + // allow developers to filter icon output | |
| 69 | + $doc_icon = apply_filters( | |
| 70 | + 'dg_icon_template', | |
| 71 | + ' <div class="document-icon">' . PHP_EOL . | |
| 72 | + ' <a href="%link%"><img src="%img%" title="%title_attribute%" alt="%title_attribute%" /><br>%title%</a>' . PHP_EOL . | |
| 73 | + $description . | |
| 74 | + ' </div>' . PHP_EOL, | |
| 75 | + $this->gallery->useDescriptions(), | |
| 76 | + $this->ID); | |
| 73 | 77 | |
| 74 | - // users may filter icon here | |
| 75 | - return apply_filters('dg_doc_icon', $core, $this->ID); | |
| 78 | + $core = str_replace($find, $repl, $doc_icon); | |
| 79 | + | |
| 80 | + // deprecated: users may filter icon here | |
| 81 | + return apply_filters('dg_doc_icon', $core, $this->ID, $this->gallery->useDescriptions()); | |
| 76 | 82 | } |
| 77 | 83 | } |
| 78 | 84 | |
| 79 | 85 | ?> |