| 1 |
<?php |
| 2 |
defined('WPINC') OR exit; |
| 3 |
|
| 4 |
/** |
| 5 |
* Holds data specific to a given document. |
| 6 |
* |
| 7 |
* @author drossiter |
| 8 |
*/ |
| 9 |
class DG_Document { |
| 10 |
|
| 11 |
/*========================================================================== |
| 12 |
* PRIVATE FIELDS |
| 13 |
*=========================================================================*/ |
| 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 |
// general document data |
| 20 |
private $description, $gallery, $ID, $link, $title, $title_attribute; |
| 21 |
|
| 22 |
/*========================================================================== |
| 23 |
* INIT GALLERY |
| 24 |
*=========================================================================*/ |
| 25 |
|
| 26 |
/** |
| 27 |
* Constructs instance of Document. |
| 28 |
* @param type $attachment Attachment object used to initalize fields. |
| 29 |
* @param type $gallery Instance of Gallery class. |
| 30 |
*/ |
| 31 |
public function __construct($attachment, $gallery) { |
| 32 |
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 |
|
| 43 |
// init general document data |
| 44 |
$this->gallery = $gallery; |
| 45 |
$this->description = $attachment->post_content; |
| 46 |
$this->ID = $attachment->ID; |
| 47 |
$this->link = $gallery->linkToAttachmentPg() |
| 48 |
? get_attachment_link($attachment->ID) |
| 49 |
: wp_get_attachment_url($attachment->ID); |
| 50 |
$this->title = get_the_title($attachment->ID); |
| 51 |
$this->title_attribute = esc_attr(strip_tags($this->title)); |
| 52 |
} |
| 53 |
|
| 54 |
/*========================================================================== |
| 55 |
* OUTPUT HTML STRING |
| 56 |
*=========================================================================*/ |
| 57 |
|
| 58 |
/** |
| 59 |
* Returns HTML representing this Document. |
| 60 |
* @return string |
| 61 |
*/ |
| 62 |
public function __toString() { |
| 63 |
$thumb = $this->gallery->useFancyThumbs() |
| 64 |
? DG_Thumber::getThumbnail($this->ID) |
| 65 |
: 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 |
|
| 70 |
if($this->gallery->useDescriptions()) { |
| 71 |
$core .= " <p>$this->description</p>" . PHP_EOL; |
| 72 |
} |
| 73 |
|
| 74 |
// users may filter icon here |
| 75 |
return apply_filters('dg_doc_icon', $core, $this->ID); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
?> |