| 1 |
<?php
|
| 2 |
|
| 3 |
// $Id:
|
| 4 |
|
| 5 |
/**
|
| 6 |
* @file
|
| 7 |
* Fast Gallery allows you to build galleries based on your file
|
| 8 |
* system with folders and subfolders.
|
| 9 |
*
|
| 10 |
* This module is sponsored by Sch�r Webdesign.
|
| 11 |
* Visit www.schaerwebdesign.ch or the Drupal-related blog www.rapsli.ch.
|
| 12 |
*
|
| 13 |
* Original version by Raphael Sch�r - www.schaerwebdesign.ch.
|
| 14 |
*
|
| 15 |
* @author Raphael Sch�r - www.schaerwebdesign.ch
|
| 16 |
*/
|
| 17 |
|
| 18 |
define('FG_DEFAULT_STORAGE_ENGINE','default');
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Implementation of hook_menu
|
| 22 |
* @return array
|
| 23 |
*/
|
| 24 |
function fast_gallery_menu() {
|
| 25 |
$items['admin/config/fast_gallery'] = array(
|
| 26 |
'title' => 'Fast Gallery',
|
| 27 |
'description' => 'Configure the fast gallery module',
|
| 28 |
'page callback' => 'drupal_get_form',
|
| 29 |
'page arguments' => array('fast_gallery_general_settings_form'),
|
| 30 |
'access arguments' => array('administer fast gallery'),
|
| 31 |
'file' => 'fast_gallery.admin.inc',
|
| 32 |
'file path' => drupal_get_path('module', 'fast_gallery'),
|
| 33 |
);
|
| 34 |
|
| 35 |
$items['fast_gallery/ajax/%op'] = array(
|
| 36 |
'page callback' => 'fast_gallery_ajax_handler',
|
| 37 |
'page arguments' => array(2),
|
| 38 |
'access arguments' => array('administer fast gallery'),
|
| 39 |
'file' => 'fast_gallery.admin.inc',
|
| 40 |
'file path' => drupal_get_path('module', 'fast_gallery'),
|
| 41 |
);
|
| 42 |
|
| 43 |
$fg_galleries = variable_get('fg_galleries', array());
|
| 44 |
foreach ($fg_galleries as $gallery) {
|
| 45 |
//print_r($gallery['fg_alias']);
|
| 46 |
$items[$gallery['fg_alias']] = array(
|
| 47 |
'page callback' => 'fast_gallery_page_alias',
|
| 48 |
'page arguments' => array($gallery['fg_path']),
|
| 49 |
'access arguments' => array('access content'),
|
| 50 |
'title' => $gallery['fg_title'],
|
| 51 |
);
|
| 52 |
}
|
| 53 |
//exit();
|
| 54 |
return $items;
|
| 55 |
}
|
| 56 |
|
| 57 |
/**
|
| 58 |
* implementation of hook_fast_gallery_info()
|
| 59 |
* @return unknown_type
|
| 60 |
*/
|
| 61 |
function fast_gallery_fast_gallery_info() {
|
| 62 |
return array(
|
| 63 |
'fg_version' => 2,
|
| 64 |
'storageengine' => array(
|
| 65 |
'default' => array(
|
| 66 |
'name' => 'default',
|
| 67 |
'file' => 'default.storage.inc',
|
| 68 |
'path' => drupal_get_path('module', 'fast_gallery') . '/storageengine',
|
| 69 |
),
|
| 70 |
'node' => array(
|
| 71 |
'name' => 'name <not implemented!!!>',
|
| 72 |
'file' => 'node.storage.inc',
|
| 73 |
'path' => drupal_get_path('module', 'fast_gallery') . '/storageengine',
|
| 74 |
),
|
| 75 |
),
|
| 76 |
|
| 77 |
);
|
| 78 |
}
|
| 79 |
|
| 80 |
function _fast_gallery_get_alias_count($path) {
|
| 81 |
$ar = explode("/", $path);
|
| 82 |
if ($ar[count($ar)-1] == '') {
|
| 83 |
array_shift($ar);
|
| 84 |
}
|
| 85 |
return count($ar);
|
| 86 |
}
|
| 87 |
|
| 88 |
function fast_gallery_page_alias($path) {
|
| 89 |
$settings = variable_get('fg_galleries');
|
| 90 |
|
| 91 |
$current_path_alias = check_plain($_GET['q']);
|
| 92 |
|
| 93 |
$start = strlen($settings[$path]['fg_alias']);
|
| 94 |
$path_new = substr($current_path_alias, ++$start);
|
| 95 |
$path_new = $settings[$path]['fg_path'] . $path_new;
|
| 96 |
|
| 97 |
//fetching the needed objects
|
| 98 |
$fg = fast_gallery_get_FastGallery();
|
| 99 |
$storage = $fg->getStorageEngine();
|
| 100 |
|
| 101 |
drupal_set_breadcrumb($fg->buildBreadCrumbs());
|
| 102 |
$current_path = check_plain($_GET['q']);
|
| 103 |
|
| 104 |
$images = $storage->getImages($path_new);
|
| 105 |
|
| 106 |
$html = '';
|
| 107 |
foreach ($images as $image) {
|
| 108 |
if ($image->isDir()) {//incase of a subfolder -> make a different link
|
| 109 |
$image_html = l($image->renderHtml(), $current_path . '/' . $image->getName(), array('html' => TRUE));
|
| 110 |
}
|
| 111 |
else {
|
| 112 |
$image_html = l($image->renderHtml(), $image->getPath(), array('html' => TRUE));
|
| 113 |
|
| 114 |
}
|
| 115 |
|
| 116 |
//use .tpl file to output an image
|
| 117 |
$html .= theme('fast_gallery_image', array('image' => $image_html));
|
| 118 |
}
|
| 119 |
return $html;
|
| 120 |
}
|
| 121 |
|
| 122 |
/**
|
| 123 |
* Implementation of hook_cron() to keep gallery up-to-date.
|
| 124 |
*/
|
| 125 |
function fast_gallery_cron() {
|
| 126 |
$fg = fast_gallery_get_FastGallery();
|
| 127 |
$fg->rescanGallery();
|
| 128 |
}
|
| 129 |
|
| 130 |
/**
|
| 131 |
* Implementation of hook_theme
|
| 132 |
* @return array
|
| 133 |
*/
|
| 134 |
function fast_gallery_theme() {
|
| 135 |
return array(
|
| 136 |
'fast_gallery_image' => array(
|
| 137 |
'variables' => array(
|
| 138 |
'image' => NULL,
|
| 139 |
),
|
| 140 |
'template' => 'fast_gallery-image',
|
| 141 |
),
|
| 142 |
'fg_multiple_galleries' => array(
|
| 143 |
'render element' => 'form',
|
| 144 |
),
|
| 145 |
);
|
| 146 |
}
|
| 147 |
|
| 148 |
/**
|
| 149 |
* Implementation of hook_init
|
| 150 |
*/
|
| 151 |
function fast_gallery_init() {
|
| 152 |
drupal_add_css(drupal_get_path('module', 'fast_gallery') . '/fast_gallery.css');
|
| 153 |
}
|
| 154 |
|
| 155 |
|
| 156 |
/**
|
| 157 |
* helper function to return the controller class
|
| 158 |
* FastGallery
|
| 159 |
* @return FastGallery
|
| 160 |
*/
|
| 161 |
function fast_gallery_get_FastGallery() {
|
| 162 |
include_once('fast_gallery.class.php');
|
| 163 |
return FastGallery :: getInstance();
|
| 164 |
}
|
| 165 |
|
| 166 |
/**
|
| 167 |
* helper function to return the Cache
|
| 168 |
* @return FastGalleryCache
|
| 169 |
*/
|
| 170 |
function fast_gallery_get_cache() {
|
| 171 |
include_once('fast_gallery.cache.class.php');
|
| 172 |
return FastGalleryCache::getInstance();
|
| 173 |
}
|
| 174 |
|
| 175 |
|
| 176 |
/**
|
| 177 |
* Print a variable to the 'message' area of the page. Uses drupal_set_message()
|
| 178 |
*/
|
| 179 |
function d($str) {
|
| 180 |
print '<pre>';
|
| 181 |
print_r($str);
|
| 182 |
print '</pre>';
|
| 183 |
}
|