PluginProbe
Document Gallery / 1.4.2
Document Gallery v1.4.2
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 / models / class-document.php

class-document.php in Document Gallery 1.4.2, at models/class-document.php

82 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Description of Document
5 *
6 * @author drossiter
7 */
8 class DG_Document {
9 // templates for HTML output
10 private static $doc_icon = false;
11 private static $img_string = '<img src="%s" title="%s" alt="%s" />';
12
13 // general document data
14 private $description, $gallery, $ID, $link, $title, $title_attribute;
15
16 /**
17 * Constructs instance of Document.
18 * @param type $attachment Attachment object used to initalize fields.
19 * @param type $gallery Instance of Gallery class.
20 */
21 public function __construct($attachment, $gallery) {
22 include_once(DG_PATH . 'util/class-thumber.php');
23
24 // init template for HTML output
25 if(self::$doc_icon === false)
26 {
27 self::$doc_icon =
28 ' <div class="document-icon">' . PHP_EOL .
29 ' <a href="%s">%s<br>%s</a>' . PHP_EOL .
30 ' </div>' . PHP_EOL;
31 }
32
33 // init general document data
34 $this->gallery = $gallery;
35 $this->description = $attachment->post_content;
36 $this->ID = $attachment->ID;
37 $this->link = $gallery->linkToAttachmentPg()
38 ? get_attachment_link($attachment->ID)
39 : wp_get_attachment_url($attachment->ID);
40 $this->title = get_the_title($attachment->ID);
41 $this->title_attribute = esc_attr(strip_tags($this->title));
42 }
43
44 /**
45 * Returns associative array of filetype to icon mapping.
46 * @return array
47 */
48 public static function getFiletypeMapping() {
49 return self::$exts;
50 }
51
52 /**
53 * Takes associative array of filetype to icon mapping.
54 *
55 * NOTE: This is foundation work for allowing users to add their own
56 * filetypes in the future.
57 * @param array $new
58 */
59 public static function setFiletypeMapping($new) {
60 self::$exts = $new;
61 }
62
63 /**
64 * Returns HTML representing this Document.
65 * @return string
66 */
67 public function __toString() {
68 $icon = sprintf(self::$img_string, DG_Thumber::getDefaultThumbnail($this->ID),
69 $this->title_attribute, $this->title_attribute);
70 $core = sprintf(self::$doc_icon, $this->link, $icon, $this->title);
71
72 if($this->gallery->useDescriptions()) {
73 $core .= " <p>$this->description</p>" . PHP_EOL;
74 }
75
76 // users may filter icon here
77 return apply_filters('dg_doc_icon', $core, $this->ID);
78 }
79 }
80
81 ?>
82