PluginProbe
Document Gallery / 3.0
Document Gallery v3.0
trunk 0.8 0.8.5 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 2.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 94 releases
document-gallery / inc / class-document.php

class-document.php in Document Gallery 3.0, at inc/class-document.php

84 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 ?>