PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/4.6/components/com_mostlyce_frontend/mostlyce_frontend.php

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