| 1 |
<?php
|
| 2 |
// $Id:
|
| 3 |
|
| 4 |
/**
|
| 5 |
*
|
| 6 |
* @author rschaer
|
| 7 |
*
|
| 8 |
*/
|
| 9 |
|
| 10 |
|
| 11 |
class FGImage {
|
| 12 |
private $path, $name, $folder, $parent, $fid, $isDir;
|
| 13 |
|
| 14 |
/**
|
| 15 |
* Constructor
|
| 16 |
* @param $path
|
| 17 |
* The path to the image
|
| 18 |
* @param $options
|
| 19 |
* an assoziative array containing some options. The following options are possible:
|
| 20 |
* - dir: can be true or false. If set to true the image behaves as a dir! Default is set to false
|
| 21 |
*/
|
| 22 |
public function __construct($path, $options = array()) {
|
| 23 |
$this->setPath($path);
|
| 24 |
|
| 25 |
$fid = db_query("SELECT fid FROM {file} WHERE uri = :uri", array(':uri' => $path))->fetchField();
|
| 26 |
$this->setFid($fid);
|
| 27 |
|
| 28 |
if (isset($options['dir'])) {
|
| 29 |
$this->setIsDir($options['dir']);
|
| 30 |
}
|
| 31 |
else {
|
| 32 |
$this->setIsDir(FALSE);
|
| 33 |
}
|
| 34 |
|
| 35 |
// Split up the Image Path, so we can work on it
|
| 36 |
$arPath = explode('/', $path);
|
| 37 |
|
| 38 |
$this->setFolder($arPath);
|
| 39 |
$this->setParent($arPath);
|
| 40 |
$this->setName($arPath);
|
| 41 |
}
|
| 42 |
|
| 43 |
/**
|
| 44 |
* Render the html for displaying the image
|
| 45 |
* @return string html
|
| 46 |
*/
|
| 47 |
public function renderHtml() {
|
| 48 |
$cache = fast_gallery_get_cache();
|
| 49 |
$path = $this->getPath();
|
| 50 |
if ($this->isDir) { //incase a dir we return a special image
|
| 51 |
$path = drupal_get_path('module', 'fast_gallery') . '/images/doc.screenshot.jpg';
|
| 52 |
}
|
| 53 |
$cache->createthumb($path, 150, 100);
|
| 54 |
return theme('image', array('path' => $path . '.thumb'));
|
| 55 |
}
|
| 56 |
/**
|
| 57 |
* Given a path and index n, removes n number of elements from the end of
|
| 58 |
* the path (delimited by '/').
|
| 59 |
*
|
| 60 |
* @param path_ar
|
| 61 |
* Path.
|
| 62 |
* @param n
|
| 63 |
* Number of elements to remove from end of the path.
|
| 64 |
*/
|
| 65 |
private function substractFromPath($path_ar, $n) {
|
| 66 |
$path_ar = array_slice($path_ar, 0, - $n);
|
| 67 |
return implode('/', $path_ar);
|
| 68 |
}
|
| 69 |
|
| 70 |
|
| 71 |
// All the accessor mehtods
|
| 72 |
// -------------------------
|
| 73 |
|
| 74 |
public function setIsDir($isDir) {
|
| 75 |
if ($isDir) {
|
| 76 |
$this->isDir = TRUE;
|
| 77 |
}
|
| 78 |
else {
|
| 79 |
$this->isDir = FALSE;
|
| 80 |
}
|
| 81 |
}
|
| 82 |
|
| 83 |
public function isDir() {
|
| 84 |
return $this->isDir;
|
| 85 |
}
|
| 86 |
|
| 87 |
public function getFid() {
|
| 88 |
return $this->fid;
|
| 89 |
}
|
| 90 |
|
| 91 |
public function setFid($fid) {
|
| 92 |
$this->fid = $fid;
|
| 93 |
}
|
| 94 |
|
| 95 |
public function getFolder() {
|
| 96 |
return $this->folder;
|
| 97 |
}
|
| 98 |
|
| 99 |
public function setFolder($arPath) {
|
| 100 |
if (!$this->isDir()) {
|
| 101 |
$this->folder = $this->substractFromPath($arPath, 1);
|
| 102 |
}
|
| 103 |
else {
|
| 104 |
$this->folder = implode("/", $arPath);
|
| 105 |
}
|
| 106 |
}
|
| 107 |
|
| 108 |
public function getParent() {
|
| 109 |
return $this->parent;
|
| 110 |
}
|
| 111 |
|
| 112 |
public function setParent($arPath) {
|
| 113 |
$this->parent = $this->substractFromPath($arPath, 2);
|
| 114 |
}
|
| 115 |
/**
|
| 116 |
* Getter method
|
| 117 |
* @return string $path
|
| 118 |
*/
|
| 119 |
public function getPath() {
|
| 120 |
return $this->path;
|
| 121 |
}
|
| 122 |
|
| 123 |
/**
|
| 124 |
* Setter method
|
| 125 |
* @param $path string
|
| 126 |
*/
|
| 127 |
public function setPath($path) {
|
| 128 |
$this->path = $path;
|
| 129 |
}
|
| 130 |
|
| 131 |
/**
|
| 132 |
* Getter method
|
| 133 |
* @return string $path
|
| 134 |
*/
|
| 135 |
public function getName() {
|
| 136 |
return $this->name;
|
| 137 |
}
|
| 138 |
|
| 139 |
/**
|
| 140 |
* Setter method
|
| 141 |
* @param $name string
|
| 142 |
*/
|
| 143 |
public function setName($arPath) {
|
| 144 |
$this->name = $arPath[count($arPath)-1];
|
| 145 |
}
|
| 146 |
|
| 147 |
}
|