[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/plugins/editors/xstandard/ -> attachmentlibrary.php (source)

   1  <?php
   2  /*************************************************************************************
   3  ** - Copyright (c) 2006 Belus Technology Inc.
   4  ** -
   5  ** - By using the software and documentation, the user expressly agrees that
   6  ** - the use of the software documentation is at its sole risk. The software
   7  ** - and documentation is made available on an "as is" basis. Copyright owner
   8  ** - does not warrant that the software and documentation will meet the user's
   9  ** - requirements, or that the operation of the software will be uninterrupted
  10  ** - or error-free and does not make any warranty whatsoever regarding the
  11  ** - software and documentation, any information, services or products provided
  12  ** - through or in connection with the software and documentation, or any
  13  ** - results to be obtained through the use thereof, and hereby expressly
  14  ** - disclaims on behalf of itself and all suppliers any and all warranties,
  15  ** - including without limitation: any express or implied warranties of:
  16  ** - 1) merchantability; 2) fitness for a particular purpose; 3) effort to
  17  ** - achieve purpose; 4) quality; 5) accuracy; 6) non-infringement. Copyright
  18  ** - owner shall not be liable to the user, or to any third party, for any loss
  19  ** - of data, profits, loss of use, interruption of business, error, omission,
  20  ** - deletion, defect, delay in operation or transmission, computer virus,
  21  ** - communications line failure, theft or destruction or unauthorized access to,
  22  ** - alteration of, or use of records, whether for breach of contract, tortious
  23  ** - behavior, negligence, or under any other cause of action.
  24  ** -
  25  ** - All right, title and interest including, but not limited to, copyright and
  26  ** - other intellectual property rights in and to the software and documentation
  27  ** - are owned by Copyright owner and the use of or modification to the software
  28  ** - and documentation does not pass to the user any title to or any proprietary
  29  ** - rights in the software and documentation.
  30  ** -
  31  ** - Permission is granted to copy, modify and distribute the software and
  32  ** - documentation for any purpose and royalty-free, subject to the following:
  33  ** - copyright and other intellectual property rights in and to the software and
  34  ** - documentation must not be misrepresented and this notice may not be removed
  35  ** - from any source distribution of the software or documentation.
  36  *************************************************************************************/
  37  
  38  /****************************************************************************************
  39  ** - Purpose: Attachment/Link Library
  40  ** - Version: 1.00
  41  ** - Date: 2006-01-30
  42  ** - Documentation: http://xstandard.com/xstandard-lite-for-partner-cms/
  43  ****************************************************************************************/
  44  
  45  // Do not allow direct access
  46  defined( '_JEXEC' ) or die( 'Restricted access' );
  47  
  48  $base_path = "../../../";
  49  require_once( $base_path . 'configuration.php' );
  50  
  51  /*************************** OPTIONAL - CHANGE THESE SETTINGS **************************/
  52  define("XS_LIBRARY_FOLDER",  $base_path . 'images/stories/'); // Root library folder
  53  define("XS_BASE_URL", 'images/stories/'); // Base URL to create for files. Relative URLs are okay, for example: "docs/".
  54  define("XS_ACCEPTED_FILE_TYPES", "txt zip pdf doc rtf tar ppt xls xml xsl xslt swf gif jpeg jpg png bmp"); // A list of accepted file extensions.
  55  define("XS_GET_DATE_LAST_MODIFIED", true); //Provide the last modified date for files.  For large libraries, turning this off can improve performance.
  56  define("XS_GET_FILE_SIZE", true); //Provide file size. For large libraries, turning this off can improve performance.
  57  define("XS_HIDDEN_FOLDERS", "CVS,_vti_cnf"); //Comma delimited list of hidden folders
  58  define("XS_HIDDEN_FILES", ""); //Comma delimited list of hidden files
  59  /*************************** OPTIONAL - CHANGE THESE SETTINGS ***************************/
  60  
  61  
  62  function xs_build_path($path, $name) {
  63      $p = str_replace("\\", "/", trim($path));
  64      $n = trim($name);
  65  
  66      $return = '';
  67      if (strlen($p) > 0 and strlen($n) > 0) {
  68          if (substr($p, strlen($p) - 1, 1) == "/") {
  69              $return = $p . $n;
  70          } else {
  71              $return = $p . "/" . $n;
  72          }
  73      } else {
  74          $return = $p . $n;
  75      }
  76  
  77      //make sure return is above $path
  78      $realreturn = realpath($return);
  79      $realpath = realpath($path);
  80      if(strpos($realreturn, $realpath) !== 0) {
  81          //the returned path does not start with the given path.  Default to path
  82          return $realpath;
  83      } else {
  84          return $realreturn;
  85      }
  86  }
  87  
  88  function xs_is_accepted_file_type($file_name) {
  89      $pos = strrpos($file_name, ".");
  90      $ext = "";
  91      if ($pos !== false) {
  92          $ext = strtolower(substr($file_name, $pos + 1));
  93      }
  94  
  95      $accepted_file_types = explode(" ", strtolower(XS_ACCEPTED_FILE_TYPES));
  96      foreach ($accepted_file_types as $accepted_file_type) {
  97          if ($accepted_file_type == $ext or $accepted_file_type == "*") {
  98              return true;
  99          }
 100      }
 101  
 102      return false;
 103  }
 104  
 105  
 106  function xs_xhtml_escape($text) {
 107      return str_replace(array("&", "<", ">", "\""), array("&amp;", "&lt;", "&gt;", "&quot;"), $text);
 108  }
 109  
 110  function xs_urlencode($text) {
 111      $parts = explode("/", $text);
 112      $count = count($parts);
 113  
 114      for($i = 0; $i < $count; $i++) {
 115          $parts[$i] = str_replace("+", "%20", urlencode($parts[$i]));
 116      }
 117  
 118      return implode("/", $parts);
 119  }
 120  
 121  
 122  
 123  //Process request
 124  $rootFolderPath = "";
 125  $rootFilePath = "";
 126  
 127  //Get sub-folder to browse
 128  if (isset($_SERVER["HTTP_X_CMS_LIBRARY_PATH"])) {
 129      if ($_SERVER["HTTP_X_CMS_LIBRARY_PATH"] == "") {
 130          $rootFolderPath = XS_LIBRARY_FOLDER;
 131          $rootFilePath = XS_LIBRARY_FOLDER;
 132      } else {
 133          $rootFolderPath = xs_build_path(XS_LIBRARY_FOLDER, $_SERVER["HTTP_X_CMS_LIBRARY_PATH"]);
 134          $rootFilePath = xs_build_path(XS_LIBRARY_FOLDER, $_SERVER["HTTP_X_CMS_LIBRARY_PATH"]);
 135      }
 136  } else {
 137      $rootFolderPath = XS_LIBRARY_FOLDER;
 138      $rootFilePath = XS_LIBRARY_FOLDER;
 139  }
 140  
 141  
 142  $hidden_folders = explode(",", XS_HIDDEN_FOLDERS);
 143  $hidden_files = explode(",", XS_HIDDEN_FILES);
 144  
 145  
 146  
 147  // Respond
 148  if (get_magic_quotes_runtime() != 0) {
 149      set_magic_quotes_runtime(0);
 150  }
 151  
 152  header("Content-Type: text/xml");
 153  echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
 154  echo "<library>";
 155      echo "<containers>";
 156          // Process folders
 157          $folder_list = array();
 158          if (file_exists($rootFolderPath)) {
 159              if (false !== ($handle = @opendir($rootFolderPath))) {
 160                  while (false !== ($fs_object = readdir($handle))) {
 161                      if ($fs_object != "." && $fs_object != "..") {
 162                          $found = false;
 163                          foreach($hidden_folders as $hidden_folder) {
 164                              if(strtolower($fs_object) == strtolower(trim($hidden_folder))) {
 165                                  $found = true;
 166                              }
 167                          }
 168  
 169                          if (is_dir(xs_build_path($rootFolderPath, $fs_object))) {
 170                              if ($found === false) {
 171                                  $folder_list[] = $fs_object;
 172                              }
 173                          }
 174                      }
 175                  }
 176                  closedir($handle);
 177              }
 178          }
 179          natcasesort($folder_list);
 180          reset($folder_list);
 181          foreach ($folder_list as $key => $fs_object) {
 182              echo "<container>";
 183                  //Folder name
 184                  echo "<objectName>" . xs_xhtml_escape($fs_object) . "</objectName>";
 185  
 186                  //Path to parent folder
 187                  echo "<path>";
 188                      if (isset($_SERVER["HTTP_X_CMS_LIBRARY_PATH"])) {
 189                          if ($_SERVER["HTTP_X_CMS_LIBRARY_PATH"] != "") {
 190                              echo xs_xhtml_escape($_SERVER["HTTP_X_CMS_LIBRARY_PATH"]);
 191                          }
 192                      }
 193                  echo "</path>";
 194  
 195                  //Display label
 196                  echo "<label>" . xs_xhtml_escape($fs_object) . "</label>";
 197  
 198                  //Base URL to this folder
 199                  echo "<baseURL>";
 200                          $temp = $fs_object;
 201  
 202                          if (isset($_SERVER["HTTP_X_CMS_LIBRARY_PATH"])) {
 203                              if ($_SERVER["HTTP_X_CMS_LIBRARY_PATH"] != "") {
 204                                  $temp = $_SERVER["HTTP_X_CMS_LIBRARY_PATH"] . "/" . $fs_object;
 205                              }
 206                          }
 207  
 208                          $url = xs_build_path(XS_BASE_URL, xs_urlencode($temp)) . "/";
 209  
 210                          echo $url;
 211                  echo "</baseURL>";
 212  
 213                  //Is folder empty (not implemented yet)
 214                  echo "<empty>false</empty>";
 215  
 216                  //Icon ID defined in icons.xml
 217                  echo "<icon>folder</icon>";
 218  
 219                  //Reserved for future use
 220                  echo "<metadata></metadata>";
 221  
 222                  //Reserved for future use
 223                  echo "<options>0</options>";
 224              echo "</container>";
 225          }
 226      echo "</containers>";
 227      echo "<objects>";
 228          // Process files
 229          $file_list = array();
 230          if (file_exists($rootFilePath)) {
 231              if (false !== ($handle = @opendir($rootFilePath))) {
 232                  while (false !== ($fs_object = readdir($handle))) {
 233                      if ($fs_object != "." && $fs_object != "..") {
 234                          $found = false;
 235                          foreach($hidden_files as $hidden_file) {
 236                              if(strtolower($fs_object) == strtolower(trim($hidden_file))) {
 237                                  $found = true;
 238                              }
 239                          }
 240  
 241                          if (is_file(xs_build_path($rootFilePath, $fs_object))) {
 242                              if (xs_is_accepted_file_type($fs_object)) {
 243                                  if ($found === false) {
 244                                      $file_list[] = $fs_object;
 245                                  }
 246                              }
 247                          }
 248                      }
 249                  }
 250                  closedir($handle);
 251              }
 252          }
 253          natcasesort($file_list);
 254          reset($file_list);
 255          foreach ($file_list as $key => $fs_object) {
 256              echo "<object>";
 257                  //Folder name
 258                  echo "<objectName>" . xs_xhtml_escape($fs_object) . "</objectName>";
 259  
 260                  //Path to parent folder
 261                  echo "<path>";
 262                      if (isset($_SERVER["HTTP_X_CMS_LIBRARY_PATH"])) {
 263                          if ($_SERVER["HTTP_X_CMS_LIBRARY_PATH"] != "") {
 264                              echo xs_xhtml_escape($_SERVER["HTTP_X_CMS_LIBRARY_PATH"]);
 265                          }
 266                      }
 267                  echo "</path>";
 268  
 269                  //Display label
 270                  echo "<label>" . xs_xhtml_escape($fs_object) . "</label>";
 271  
 272                  //Icon ID defined in icons.xml
 273                  echo "<icon>document</icon>";
 274  
 275                  //Reserved for future use
 276                  echo "<metadata></metadata>";
 277  
 278                  //Reserved for future use
 279                  echo "<options>0</options>";
 280  
 281                  //Attributes
 282                  echo "<attrs>";
 283                      //src attribute
 284                      echo "<attr>";
 285                          echo "<name>href</name>";
 286                          echo "<value>";
 287                              if (isset($_SERVER["HTTP_X_CMS_LIBRARY_PATH"])) {
 288                                  if ($_SERVER["HTTP_X_CMS_LIBRARY_PATH"] == "") {
 289                                      echo xs_build_path(XS_BASE_URL, xs_urlencode($fs_object));
 290                                  } else {
 291                                      echo xs_build_path(xs_build_path(XS_BASE_URL, $_SERVER["HTTP_X_CMS_LIBRARY_PATH"]), xs_urlencode($fs_object));
 292                                  }
 293                              } else {
 294                                  echo xs_build_path(XS_BASE_URL, xs_urlencode($fs_object));
 295                              }
 296                          echo "</value>";
 297                      echo "</attr>";
 298                  echo "</attrs>";
 299  
 300                  //Properties
 301                  echo "<props>";
 302                      //File size
 303                      if (XS_GET_FILE_SIZE) {
 304                          echo "<prop>";
 305                              echo "<name>size</name>";
 306                              echo "<value>" . filesize(xs_build_path($rootFilePath, $fs_object)) . "</value>";
 307                          echo "</prop>";
 308                      }
 309  
 310                      //Last modified date
 311                      if (XS_GET_DATE_LAST_MODIFIED) {
 312                          echo "<prop>";
 313                              echo "<name>date</name>";
 314                              echo "<value>" . date("Y-m-d H:i:s", filemtime(xs_build_path($rootFilePath, $fs_object))) . "</value>";
 315                          echo "</prop>";
 316                      }
 317                  echo "</props>";
 318              echo "</object>";
 319          }
 320      echo "</objects>";
 321  echo "</library>";
 322  ?>


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1