PageRenderTime 76ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/jfx-private/modules/imager/imager.module.php

http://jfxcms.googlecode.com/
PHP | 374 lines | 264 code | 85 blank | 25 comment | 24 complexity | c27e11824102ffe48ce8efc60a77fb73 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. ############### COPYLEFT GPLv3 LICENSE ###############
  3. ##
  4. ## JFX Version 0.2.9
  5. ## Website Management Software
  6. ## www.jfxcms.com
  7. ##
  8. ## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
  9. ##
  10. ## Anthony Gallon
  11. ## oi_antz@hotmail.com
  12. ##
  13. ## Permission is hereby granted to any person having a copy of this software
  14. ## to freely use and modify as required so long as the copyright notices
  15. ## and branding remain intact.
  16. ##
  17. ## Full license details available at http://www.jfxcms.com/license
  18. ##
  19. ############### COPYLEFT GPLv3 LICENSE ###############
  20. class JFX_Module_Imager extends JFX_Module
  21. {
  22. public $keyname = 'imager';
  23. public $title = 'Image Management';
  24. public $imager_config = array();
  25. public $dependencies = array(
  26. array(
  27. 'keyname' => 'iusers',
  28. 'version' => '0.1.0'
  29. )
  30. );
  31. public $version = '0.2.9';
  32. public function __construct(){
  33. parent::__construct();
  34. $this->title = $this->lang('module_title');
  35. $this->loadConfig();
  36. $this->garbageCollection();
  37. }
  38. function garbageCollection(){
  39. $tree = $this->getFolderHeirarchy();
  40. foreach($tree as $file){
  41. $this->doGarbageCollection($file);
  42. }
  43. }
  44. function doGarbageCollection($file){
  45. if(is_object($file) && $file instanceof JFX_Data_File){
  46. if(!file_exists($file->getAbsolutePath())){
  47. $file->delete();
  48. }
  49. }else{
  50. if(is_array($file)){
  51. // directory
  52. foreach($file['files'] as $newFile){
  53. $this->doGarbageCollection($newFile);
  54. }
  55. foreach($file['subfolders'] as $newFile){
  56. $this->doGarbageCollection($newFile);
  57. }
  58. }
  59. }
  60. }
  61. function makeTree(&$tree, &$moduleObj, $showFiles=false, $folderUrl='', $fileUrl='', $folderClick='', $fileClick=''){
  62. ob_start();
  63. if($folderUrl==''){
  64. $folderUrl = $moduleObj->adminUrl.'/browse/?folder=:|folder|:';
  65. }
  66. if($fileUrl==''){
  67. $fileUrl = ':|url|:';
  68. }
  69. foreach($tree as $branch){
  70. $url = str_replace(':|folder|:', $branch['id'], $folderUrl);
  71. echo '<li>';
  72. $click = '';
  73. if($folderClick!=''){
  74. $click = str_replace(':|folder|:', $branch['id'], ' onclick="'.$folderClick.'" ');
  75. }
  76. echo '<a href="'.$url.'" '.$click.'>'.$branch['title'].'</a>';
  77. if(is_array($branch['subfolders']) && count($branch['subfolders'])>0){
  78. echo '<ul>'.$moduleObj->makeTree($branch['subfolders'], $moduleObj, $showFiles, $folderUrl, $fileUrl, $folderClick, $fileClick).'</ul>';
  79. }
  80. if($showFiles){
  81. echo '<ul>';
  82. foreach($branch['files'] as $k=>$file){
  83. $click = '';
  84. if($fileClick!=''){
  85. $click = str_replace(':|url|:', $moduleObj->imageUrl.'/serve.php?absolutepath='.htmlentities($file->getAbsolutePath()), $fileClick);
  86. $click = str_replace(':|path|:', htmlentities($file->meta['filepath']), $click);
  87. $click = str_replace(':|filename|:', htmlentities($file->meta['filename']), $click);
  88. $click = ' onclick="'.$click.'" ';
  89. }
  90. $url = str_replace(':|url|:', $moduleObj->imageUrl.'/serve.php?absolutepath='.urlencode($file->getAbsolutePath()), $fileUrl);
  91. $url = str_replace(':|path|:', urlencode($file->meta['filepath']), $url);
  92. $url = str_replace(':|filename|:', urlencode($file->meta['filename']), $url);
  93. echo '<li><a href="'.$url.'" '.$click.'>'.urlencode($file->meta['friendly_name']).'</a></li>';
  94. }
  95. echo '</ul>';
  96. }
  97. echo '</li>';
  98. }
  99. $res = ob_get_contents();
  100. ob_end_clean();
  101. return $res;
  102. }
  103. function LoadConfig(){
  104. $DB = JFX::registry('db');
  105. $CONFIG = JFX::registry('config');
  106. // make sure we have been installed!
  107. if(!JFX_Module::isInstalled($this->keyname)) return;
  108. $config = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}imager_config");
  109. if($config === false) return;
  110. foreach($config as $k=>$v){
  111. $this->imager_config[$v['k']] = $v['v'];
  112. };
  113. }
  114. public function admin($url, $dirname){
  115. //$this->resetLanguages();
  116. $VIEW = JFX::registry('JFX_View');
  117. $SMARTY = JFX::registry('Smarty');
  118. $USER = JFX::registry('JFX_User');
  119. $CONFIG = JFX::registry('config');
  120. $DB = JFX::registry('db');
  121. $SMARTY->assign('actionUrl', $url);
  122. $LANG = JFX::registry('lang');
  123. $THEME = JFX::registry('JFX_Theme');
  124. $req = explode('imager', $url);
  125. $req = explode('/', trim($req[1], '/'));
  126. if(count($req)<0){
  127. $req[0] = 'browse';
  128. }
  129. $THEME->breadcrumbs[0]->set('icon', $this->imageUrl.'/camera-silver.png');
  130. $THEME->addBreadcrumb($this->adminUrl, $this->getTitle());
  131. $tabs = array(
  132. 'browse' => 'Browse',
  133. 'upload' => 'Upload',
  134. 'new-folder' => 'New Folder',
  135. 'import-export' => 'Import / Export'
  136. );
  137. $actionUrls = array(
  138. 'browse' => $this->adminUrl.'/browse/',
  139. 'upload' => $this->adminUrl.'/upload/',
  140. 'new-folder' => $this->adminUrl.'/new-folder/',
  141. 'import-export' => $this->adminUrl.'/import-export/'
  142. );
  143. $adminTabs = array();
  144. foreach($tabs as $k=>$title){
  145. if($k==$req[0]) $class = 'selected';
  146. else $class = '';
  147. $adminTabs[] = array(
  148. 'key'=>$k,
  149. 'title' => $title,
  150. 'url' => $actionUrls[$k],
  151. 'class' => $class
  152. );
  153. };
  154. $SMARTY->assign('adminTabs', $adminTabs);
  155. echo $this->fetchTemplate('/admin/tabs.tpl');
  156. echo '<div id="admin-content">';
  157. switch($req[0]){
  158. case 'upload':
  159. require($this->dirname.'/actions/upload.php');
  160. break;
  161. case 'browse':
  162. default:
  163. require($this->dirname.'/actions/browse.php');
  164. break;
  165. case 'new-folder':
  166. require($this->dirname.'/actions/new-folder.php');
  167. break;
  168. case 'import-export':
  169. require($this->dirname.'/actions/import-export.php');
  170. break;
  171. }
  172. echo '</div>';
  173. }
  174. function GetConfig($k){
  175. if(isset($this->imager_config[$k])) return $this->imager_config[$k];
  176. else if($this->ThrowConfigExceptions) throw new Exception($this->getTitle().'->GetConfig was asked to find a non-existing key: '.$k);
  177. else return false;
  178. }
  179. public function setFile($filepath){
  180. }
  181. public function getPageActionButtons($blockId, $page){
  182. }
  183. public function getBlockEditButtons($block){
  184. $CONFIG = JFX::registry('config');
  185. $allButtons = array();
  186. if($block->moduleKey!=$this->keyname){
  187. return array();
  188. }
  189. switch($block->moduleAction){//$block->moduleAction){
  190. case 'image':
  191. $button1 = new JFX_Page_Button;
  192. $button1->pageId = $block->pageid;
  193. $button1->alternativeText = $this->lang('block_edit_button_alt');
  194. $button1->moduleName = $this->keyname;
  195. $button1->moduleMethod = 'updateSettings';
  196. $button1->imageUrl = $CONFIG->imageUrl.'/admin/icons/camera-silver.png';
  197. $button1->title = $block->moduleAction.' '.$this->lang('block_edit_button_title');
  198. $button1->blockId = $block->id;
  199. $allButtons[] = $button1;
  200. break;
  201. }
  202. return $allButtons;
  203. }
  204. public function getBlockActionButtons($blockid, $pageId){
  205. $CONFIG = JFX::registry('config');
  206. $block = JFX_Block::getBlockById($blockid, $pageId);
  207. $allButtons = array();
  208. switch($block->moduleAction){
  209. case 'image':
  210. $button1 = new JFX_Block_Button;
  211. $button1->pageId = $pageId;
  212. $button1->alternativeText = $this->lang('block_edit_button_alt');
  213. $button1->moduleName = $this->keyname;
  214. $button1->moduleMethod = 'updateSettings';
  215. $button1->imageUrl = $this->imageUrl.'/camera-silver.png';
  216. $button1->title = $this->lang('block_edit_button_title');
  217. $button1->blockId = $blockid;
  218. $allButtons[] = $button1;
  219. break;
  220. }
  221. return $allButtons;
  222. }
  223. public function getBlockActions(){
  224. return array(
  225. array(
  226. 'keyname' => 'image',
  227. 'title' => $this->lang('block_action_content_image'),
  228. 'description' => ''
  229. )
  230. );
  231. }
  232. public function getContentTypeName($action){
  233. return $this->lang('block_action_content_'.$action);
  234. }
  235. public function updateSettings($block){
  236. if(false === ($block instanceof JFX_Block)){
  237. return;
  238. }
  239. $VIEW = JFX::registry('JFX_View');
  240. $DB = JFX::registry('db');
  241. $CONFIG = JFX::registry('config');
  242. $CORE = JFX::registry('JFX_Core');
  243. $SETTINGS = JFX::registry('JFX_Settings');
  244. $USER = JFX::registry('JFX_User');
  245. //$file = JFX_Data::newFile($this->keyname, '/home/antz/Pictures/antz.jpg', 'Antz', 'images/def');
  246. //return;
  247. //var_dump($_GET);
  248. //return;
  249. require($this->dirname.'/actions/filepicker.php');
  250. }
  251. public function getContent($blockid, $pageid){
  252. return $this->getContentRaw($blockid, $pageid);
  253. }
  254. public function getContentRaw($blockid, $pageid){
  255. $block = JFX_Block::getBlockById($blockid, $pageid);
  256. $file = @JFX_Data::getFile($block->getConfig('filepath'), $block->getConfig('filename'), $this->keyname);
  257. if(!is_object($file) || false==($file instanceof JFX_Data_File)){
  258. return '';
  259. }
  260. return '<img src="'.$this->imageUrl.'/serve.php?filepath='.$file->meta['filepath'].'&amp;filename='.$file->meta['filename'].'" style="width: 100%; height: 100%" />';
  261. }
  262. public function createDefaultBlock($action, $blockid, $workspaceid){
  263. }
  264. public function getDefaultContent($action){
  265. ob_start();
  266. require($this->dirname.'/actions/edit.php');
  267. $res = ob_get_contents();
  268. ob_end_clean();
  269. return $res;
  270. }
  271. public function install(){
  272. $VIEW = JFX::registry('JFX_View');
  273. $SMARTY = JFX::registry('Smarty');
  274. $USER = JFX::registry('JFX_User');
  275. $CONFIG = JFX::registry('config');
  276. $DB = JFX::registry('db');
  277. $dirname = str_replace(DIRECTORY_SEPARATOR, '/', dirname(__FILE__)).'/install';
  278. include('install/install.php');
  279. }
  280. public function uninstall(){
  281. $VIEW = JFX::registry('JFX_View');
  282. $SMARTY = JFX::registry('Smarty');
  283. $USER = JFX::registry('JFX_User');
  284. $CONFIG = JFX::registry('config');
  285. $DB = JFX::registry('db');
  286. $dirname = str_replace(DIRECTORY_SEPARATOR, '/', dirname(__FILE__)).'/install';
  287. include('install/uninstall.php');
  288. }
  289. }