| [ Index ] | PHP Cross Reference of Mambo 4.6.5 |
|
| [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Mambo 4 * @subpackage Content 5 * @author Mambo Foundation Inc see README.php 6 * @copyright (C) 2000 - 2009 Mambo Foundation Inc. 7 * See COPYRIGHT.php for copyright notices and details. 8 * @license GNU/GPL Version 2, see LICENSE.php 9 * 10 * Redistributions of files must retain the above copyright notice. 11 * 12 * Mambo is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; version 2 of the License. 15 */ 16 17 /** ensure this file is being included by a parent file */ 18 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 19 20 $mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path'); 21 $mosConfig_secret = mamboCore::get('mosConfig_secret'); 22 23 require ($mosConfig_absolute_path.'/mambots/editors/mostlyce/jscripts/tiny_mce/auth_check.php'); 24 $result = externalCallCheck($mosConfig_absolute_path, $mosConfig_secret); 25 if (!$result) { 26 die(T_('Direct Access to this location is not allowed.')); 27 } 28 29 $task = trim(mosGetParam($_GET, 'task', '')); 30 switch (strtolower($task)) { 31 case 'imagelist': 32 getImageList(); 33 break; 34 35 case 'contentlist': 36 getContentList(); 37 break; 38 39 default: 40 die(T_('Direct Access to this location is not allowed.')); 41 break; 42 } 43 44 /** 45 * Purpose: This function creates a list of images to be displayed as a dropdown in all image dialogs 46 * if the "external_link_image_url" option is defined in TinyMCE init. 47 * 48 * Expected output: 49 * var tinyMCEImageList = new Array( 50 * // Name, URL 51 * ["Logo 1", "media/logo.jpg"], 52 * ["Logo 2 Over", "media/logo_over.jpg"] 53 * ); 54 **/ 55 function getImageList() { 56 global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_secret; 57 $pathToImages = $mosConfig_absolute_path.'images/stories'; 58 $imageList = scan_directory_recursively($pathToImages); 59 60 $validExtensions = array('jpeg', 'jpg', 'png', 'gif'); 61 $count = 0; 62 63 $jsCode = 'var tinyMCEImageList = new Array('; 64 foreach ($imageList as $image) { 65 $count++; 66 $crtExtension = substr(strrchr($image, '.'), 1); 67 if (in_array($crtExtension, $validExtensions)) { 68 $urlImagePath = str_replace($mosConfig_absolute_path, $mosConfig_live_site.'/', $image); 69 $postAbsolutePath = str_replace($mosConfig_absolute_path, '', $image); 70 if ($count < count($imageList )) { 71 $jsCode .= "[\"$postAbsolutePath\", \"$urlImagePath\"],"; 72 } else { 73 $jsCode .= "[\"$postAbsolutePath\", \"$urlImagePath\"]"; //no comma on the last line 74 } 75 } 76 } 77 $jsCode .= ");"; 78 79 //Dump out the newly assembled list of images for MOStlyCE 80 echo $jsCode; 81 } 82 83 /** 84 * Purpose: This function creates a list of content items to be displayed as a dropdown in all link dialogs if 85 * the "external_link_list_url" option is defined in TinyMCE init. 86 * 87 * var tinyMCELinkList = new Array( 88 * // Name, URL 89 * ["Moxiecode", "http://www.moxiecode.com"], 90 * ["Freshmeat", "http://www.freshmeat.com"], 91 * ["Sourceforge", "http://www.sourceforge.com"] 92 * ); 93 **/ 94 function getContentList() { 95 global $database, $mosConfig_absolute_path, $mosConfig_offset, $mosConfig_secret; 96 97 $now = date('Y-m-d H:i:s', time() + $mosConfig_offset * 60 * 60); 98 99 /* Build an array to hold the content items. We need to combine the results from a 100 a number of queries to build the full map */ 101 $jsCode = 'var tinyMCELinkList = new Array('; 102 103 /* Section Query */ 104 $section_query = "select id as secid, title as sec_title 105 from #__sections 106 order by ordering"; 107 $database->setQuery($section_query); 108 $section_rows = $database->loadObjectList(); 109 110 //Start the list 111 foreach($section_rows as $section_row) { 112 //Start the section 113 $section_link = sefRelToAbs("index.php?option=com_content&task=section&id=$section_row->secid"); 114 $title_keyword = T_('Section'); 115 $jsCode .= "[\"$title_keyword: $section_row->sec_title\", \"$section_link\"],"; 116 117 /* Category Query */ 118 $cat_query = "select id as catid, title as cat_title 119 from #__categories 120 where section = $section_row->secid 121 order by ordering"; 122 $database->setQuery($cat_query); 123 $cat_rows = $database->loadObjectList(); 124 125 if (count($cat_rows)>0) { // count arrary first to prevent foreach() error when array is empty 126 foreach($cat_rows as $cat_row) { 127 //Start the category 128 //Find the correct ItemID 129 $itemid_query = "select id 130 from #__menu 131 where name = '$cat_row->cat_title' 132 and type='content_category'"; 133 $database->setQuery($itemid_query); 134 $ItemID = $database->loadResult(); 135 //Since we must have an ItemID default to 1 if not found to prevent "You are not authorized" errors 136 if (empty($ItemID)) { 137 $ItemID=1; 138 } 139 140 $cat_link = sefRelToAbs("index.php?option=com_content&task=category§ionid=$section_row->secid&id=$cat_row->catid&Itemid=$ItemID"); 141 $cat_keyword = T_('Category'); 142 $jsCode .= "[\"|_$cat_keyword: $cat_row->cat_title\", \"$cat_link\"],"; 143 144 /* Content Query */ 145 $content_query = "select id as content_id, title as content_title 146 from #__content 147 where sectionid = $section_row->secid 148 and catid = $cat_row->catid 149 order by ordering"; 150 151 $database->setQuery($content_query); 152 $content_rows = $database->loadObjectList(); 153 154 if (count($content_rows)>0) { // count arrary first to prevent foreach() error when array is empty 155 foreach($content_rows as $content_row) { 156 //Generate content items 157 $content_link = sefRelToAbs("index.php?option=com_content&task=view&id=$content_row->content_id"); 158 $content_keyword = T_('Content Item'); 159 $jsCode .= "[\"|__$content_keyword: $content_row->content_title\", \"$content_link\"],"; 160 } // End content_rows foreach 161 162 } // End content_rows if 163 } //End cat_rows foreach 164 165 } //End cat_rows if 166 } //End section_rows 167 168 /* Static Content Query */ 169 $static_query = "select id as content_id, title as content_title 170 from #__content 171 where sectionid = 0 172 and catid = 0 173 order by ordering"; 174 $database->setQuery($static_query); 175 $static_rows = $database->loadObjectList(); 176 177 if (count($static_rows)>0) { // count arrary first to prevent foreach() error when arrary is empty 178 foreach($static_rows as $static_row) { 179 //Start the section 180 $static_link = sefRelToAbs("index.php?option=com_content&task=view&id=$static_row->content_id"); 181 $scontent_keyword = T_('Static Content Item'); 182 $jsCode .= "[\"|_$scontent_keyword: $static_row->content_title\", \"$static_link\"],"; 183 } //End static_rows foreach 184 185 } //End static_rows if 186 187 $jsCode = substr($jsCode, 0, strlen($jsCode)-1); //remove final comma 188 $jsCode .= ");"; //end the js array 189 190 //Dump out the newly assembled list of images for MOStlyCE 191 echo $jsCode; 192 } 193 194 /** 195 * Purpose: Used to recurse through the images dir/sub-dir structure and build a 196 * list that can be used to hand back a JS array to TinyMCE's image list parameter 197 * 198 * Note: Based on lixlpixel recursive PHP function (http://lixlpixel.org/recursive_function/php/recursive_directory_scan/) 199 **/ 200 function scan_directory_recursively($directory, $filter=FALSE) { 201 $imagesArray = array(); 202 203 if (substr($directory,-1) == '/') { 204 $directory = substr($directory,0,-1); 205 } 206 if (!file_exists($directory) || !is_dir($directory)) { 207 return FALSE; 208 } else if (is_readable($directory)) { 209 $directory_list = opendir($directory); 210 while ($file = readdir($directory_list)) { 211 if ($file != '.' && $file != '..') { 212 $path = $directory.'/'.$file; 213 if (is_readable($path)) { 214 $subdirectories = explode('/',$path); 215 if (is_dir($path)) { 216 $directory_tree[] = array( 217 'path' => $path, 218 'name' => end($subdirectories), 219 'kind' => 'directory', 220 'content' => scan_directory_recursively($path, $filter)); 221 } else if (is_file($path)) { 222 $imagesArray[] = $path; 223 224 $extension = end(explode('.',end($subdirectories))); 225 if ($filter === FALSE || $filter == $extension) { 226 $directory_tree[] = array( 227 'path' => $path, 228 'name' => end($subdirectories), 229 'extension' => $extension, 230 'size' => filesize($path), 231 'kind' => 'file'); 232 } 233 } 234 } 235 } 236 } 237 closedir($directory_list); 238 } else { 239 return FALSE; 240 } 241 242 return $imagesArray; 243 } 244 245 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Feb 8 00:05:01 2012 | Cross-referenced by PHPXref 0.7 |
| Mambo API: Mambo is Free software released under the GNU/General Public License, Version 2 |