| 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 |
// general document data |
| 16 |
private $description, $gallery, $ID, $link, $title, $title_attribute; |
| 17 |
|
| 18 |
/*========================================================================== |
| 19 |
* INIT GALLERY |
| 20 |
*=========================================================================*/ |
| 21 |
|
| 22 |
/** |
| 23 |
* Constructs instance of Document. |
| 24 |
* @param type $attachment Attachment object used to initalize fields. |
| 25 |
* @param type $gallery Instance of Gallery class. |
| 26 |
*/ |
| 27 |
public function __construct($attachment, $gallery) { |
| 28 |
include_once DG_PATH . 'inc/class-thumber.php'; |
| 29 |
|
| 30 |
// init general document data |
| 31 |
$this->gallery = $gallery; |
| 32 |
$this->description = wptexturize($attachment->post_content); |
| 33 |
$this->ID = $attachment->ID; |
| 34 |
$this->link = $gallery->linkToAttachmentPg() |
| 35 |
? get_attachment_link($attachment->ID) |
| 36 |
: wp_get_attachment_url($attachment->ID); |
| 37 |
$this->title = wptexturize($attachment->post_title); |
| 38 |
$this->title_attribute = esc_attr(strip_tags($this->title)); |
| 39 |
} |
| 40 |
|
| 41 |
/*========================================================================== |
| 42 |
* OUTPUT HTML STRING |
| 43 |
*=========================================================================*/ |
| 44 |
|
| 45 |
/** |
| 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 |
* @return string |
| 50 |
*/ |
| 51 |
public function __toString() { |
| 52 |
$thumb = $this->gallery->useFancyThumbs() |
| 53 |
? DG_Thumber::getThumbnail($this->ID) |
| 54 |
: DG_Thumber::getDefaultThumbnail($this->ID); |
| 55 |
|
| 56 |
$repl = array($this->link, $thumb, $this->title_attribute, $this->title); |
| 57 |
$find = array('%link%', '%img%', '%title_attribute%', '%title%'); |
| 58 |
$description = ''; |
| 59 |
|
| 60 |
// if descriptions then add filterable tag and value to replaced tag |
| 61 |
if ($this->gallery->useDescriptions()) { |
| 62 |
$repl[] = $this->description; |
| 63 |
$find[] = '%description%'; |
| 64 |
$description = ' <p>%description%</p>'; |
| 65 |
} |
| 66 |
|
| 67 |
$doc_icon = |
| 68 |
' <div class="document-icon">' . PHP_EOL . |
| 69 |
' <a href="%link%"><img src="%img%" title="%title_attribute%" alt="%title_attribute%" /><br>%title%</a>' . PHP_EOL . |
| 70 |
' </div>' . PHP_EOL . |
| 71 |
$description; |
| 72 |
|
| 73 |
// allow developers to filter icon output |
| 74 |
$doc_icon = apply_filters( |
| 75 |
'dg_icon_template', |
| 76 |
$doc_icon, |
| 77 |
$this->gallery->useDescriptions(), |
| 78 |
$this->ID); |
| 79 |
|
| 80 |
return str_replace($find, $repl, $doc_icon); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
?> |