Caravel CMS PHP Cross Reference Content Management Systems

Source: /apps/Editor/Editor.php - 1472 lines - 73458 bytes - Summary - Text - Print

   1  <?php
   2  
   3  require_once(T_WIDGET_BASE . 'FormWidget/FormWidget.php');
   4  require_once(T_CODE_BASE . 'File/FileTypeTable.php');
   5  require_once (T_CODE_BASE . 'File/oFile.php');
   6  require_once (T_CODE_BASE . 'File/File.php');
   7  
   8  class Editor extends App
   9      {
  10      var $mode;
  11      var $edoc = '';
  12  
  13      /**
  14      * override default dispatcher method so we can handle Editors not associated with blocks
  15      * (i.e., for files selected to edit in File Manager or Folder Editor)
  16      *
  17      * first saves if needed, then calls getContent or getConfig depending on
  18      * whether we're in edit mode or not
  19      */
  20      function dispatch()
  21          {
  22          if ($this->can('config') || $this->can('file'))
  23              {
  24              // raise onSave event if a button named 'cv_submit' was pressed
  25              if ( isset($this->httpVars['cv_submit']) && $this->httpVars['cv_submit'] != "")
  26                  {
  27                  Editor::onSave();
  28  
  29                  // close window if necessary
  30                  $submit = str_replace('&amp;', '&', $this->httpVars['cv_submit']);
  31  
  32                  if (T_SINGLE_BLOCK and ($submit == 'Save & Preview' or $submit == 'Save & Close'))
  33                      return Utility::getCloseRefreshJavascript();
  34                  }
  35                  
  36              // return configuration/editing screen if we're in that mode
  37              if ($this->edit)
  38                  {
  39                  return Editor::getConfig();
  40                  }
  41              }
  42  
  43          // return normal view if user isn't logged in or we're in preview mode
  44          return Editor::getContent();
  45          }
  46           
  47      function onInit() {
  48          if (!isset($this->mode)) $this->mode = isset($this->httpVars['mode']) ? $this->httpVars['mode'] : ((strpos($this->blockID, "tmp") !== false) ? 'nonCB' : 'CB');
  49          if (!isset($this->editorVars['defaultExtension'])) $this->editorVars['defaultExtension'] = 'html';
  50          if (!isset($this->editorVars['defaultType'])) $this->editorVars['defaultType'] = FileTypeTable::extensionToType($this->editorVars['defaultExtension'], false);
  51          if (!isset($this->editorVars['defaultFolder'])) {
  52              $this->editorVars['defaultFolder'] = FileTypeTable::typeToDefaultFolder($this->editorVars['defaultType']);
  53              $this->noDefaultSet = true;
  54          }
  55          if (!$this->ldap->dnExists($this->editorVars['defaultFolder'] . ',' . T_ORG_DN)) $this->editorVars['defaultFolder'] = C_LDAP_BASE_FOLDER;
  56          if (!isset($this->editorVars['defaultContents'])) $this->editorVars['defaultContents'] = '';
  57          if (ereg('^' .C_LDAP_FILE. '=', $this->editorVars['defaultContents'])) {
  58              $obj = oFile::load($this->ldap, $this->editorVars['defaultContents']); 
  59              if (!mnError::isError($obj))
  60                  $this->editorVars['defaultContents'] = $obj->read('edit');
  61              else
  62                  $this->editorVars['defaultContents'] = '';
  63          }
  64          if (!isset($this->editorVars['promptForFilename'])) $this->editorVars['promptForFilename'] = ($this->mode == 'blog_post' ? false : true);
  65      }
  66          
  67      /**
  68      * displays the editor
  69      *
  70      * Called by the default app dispatch method in App.php
  71      * Displayed...
  72      *  1. after user clicks Edit button on CB Edit Bar
  73      *  2. after user clicks Save & Edit while editing a document (in this case the onSave event is called before getConfig)
  74      *  3. after user selects a file to edit in either the Folder Editor or File Manager
  75      *
  76      * Either loads the settingsVars['fileDN'] or creates a tmp.* file and displays
  77      * the editor.  The tmp.* file is always empty (Save doesn't look at
  78      * it at all) and is deleted every so often using File::clearTemp called from Editor::getContent.
  79      **/
  80      function getConfig()
  81          {
  82          // clear temp files, 1 out of 10 times
  83          if (rand(0,100) > 90)
  84              {
  85              mnDebug("Editor::getContent(): Random chance met.  Clearing temp.");
  86              $res = File::clearTemp(T_ORG_DN);
  87              if(mnError::isError($res))
  88                  { return new mnError('Editor::getContents(): ' . $res->getMessage(), __FILE__, __LINE__); }
  89              }
  90          
  91          if($this->httpVars['edmode'] == 1)
  92              {
  93              return Editor::savePopup($this->httpVars['fileDN']);
  94              }
  95          else if($this->httpVars['mode'] == 'thumbs')
  96              {
  97              if(isset($this->httpVars['thumbclick']) && $this->httpVars['thumbclick'] != "")
  98                  return Editor::saveThumb();
  99              else
 100                  return Editor::thumbsPopup(); 
 101              }
 102          
 103          if (!@$this->edoc)
 104              {
 105              $fileDN = Editor::getFileDN();
 106              if (mnError::isError($fileDN))
 107                  return new mnError("Editor::getConfig: " . $fileDN->getMessage(), __FILE__, __LINE__);
 108  
 109              if (DN::dnToType($fileDN) == C_LDAP_SHORTCUT)
 110                  return new mnError('Cannot edit a shortcut.');
 111              
 112              if ($this->setNewFile)
 113                  {
 114                  // no file exists -- not even a temp one -- so make a new one
 115                  $oldfile = oFile::load($this->ldap, $fileDN);
 116                  $fileDN = DN::tmpDN($this->httpVars['folderDN'], DN::dnToExtension($fileDN, false));
 117  
 118                  $newfile = $oldfile->copy($fileDN);
 119                  Editor::_update($fileDN);
 120  
 121                  if(mnError::isError($res))
 122                      { return new mnError('Editor::getContent(): ' . $res->getMessage(), __FILE__, __LINE__); }
 123                  $this->edoc =& $newfile;
 124                  $newBlock = $this->mode == 'CB' ? $this->nonDelete != true : false;
 125                  return Editor::getHtml($this->edoc, $newBlock);
 126                  }
 127              else if (!$this->ldap->dnExists($fileDN))
 128                  {
 129                  // no file exists -- not even a temp one -- so make a new one
 130                  require_once(T_APP_BASE . 'PersonalProfile/PersonalProfile.php');
 131                  $author_name = PersonalProfile::getRealName(T_USER);
 132                  $fileAttrs = array($GLOBALS['CV_CURR_LANG'] => array('author' => $author_name));
 133                  $this->edoc = oFile::create($this->ldap, $fileDN, isset($this->httpVars[$this->blockID.'duplicateText']) ? $this->httpVars[$this->blockID.'duplicateText'] : $this->templateText, $this->editorVars['defaultType'], $fileAttrs);
 134                  if(mnError::isError($this->edoc))
 135                      { return new mnError('Editor::getContent(): ' . $this->edoc->getMessage(), __FILE__, __LINE__); }
 136                  $newBlock = $this->mode == 'CB' ? true : false;
 137                  return Editor::getHtml($this->edoc, $newBlock);
 138                  }
 139              else
 140                  {
 141                  $res = oFile::load($this->ldap, $fileDN);
 142                  if(mnError::isError($res))
 143                      { return new mnError('Editor::getContent(): ' . $res->getMessage(), __FILE__, __LINE__); }     
 144                  $this->edoc =& $res;
 145                  }
 146              
 147              }
 148              
 149          return Editor::getHtml($this->edoc);
 150          }
 151          
 152      function getContent()
 153          {
 154          //print "<br>";
 155          //print_r($this->getSettingsVars());
 156          //print "<br>";
 157          $fileDN = isset($this->params['fileDN']) ? $this->params['fileDN'] : false;
 158          $folderDN = isset($this->settingsVars['folderDN']) ? $this->settingsVars['folderDN'] : false;
 159          if($this->dynamic_content)
 160              {
 161              $file_path = @$GLOBALS['caravel']['dynamic_info']['params'];
 162                 $dn = $file_path ? DN::file_path_to_dn($file_path) : $this->params['fileDN'];
 163              if (!$this->ldap->dnExists($dn))
 164                  return 'File not found.';
 165              require_once(T_APP_BASE . 'FileViewer/FileViewer.php');
 166              return FileViewer::getHtml($dn);
 167              }    
 168          else if ($fileDN)
 169              {
 170              require_once(T_APP_BASE . 'FileViewer/FileViewer.php');
 171              return FileViewer::submitSwitch('View');
 172              }
 173          else if ($folderDN)
 174              {
 175              require_once(T_APP_BASE . 'FolderViewer/FolderViewer.php');
 176              //return FolderViewer::submitSwitch('View');    
 177              return '';
 178              }
 179          else
 180              return '';
 181          }
 182          
 183      function getFileDN()
 184          {
 185          // check settingsVars['fileDN'] and if this is empty also
 186          // then set it to a new .tmp file so that $this->ldap->dnExists()
 187          // doesn't find it and forces us to create a completely new document
 188  
 189          if (isset($this->httpVars['fileDN']))
 190              $fileDN = $this->httpVars['fileDN'];
 191          else if (isset($this->settingsVars['fileDN']))
 192              $fileDN = $this->settingsVars['fileDN'];
 193          else
 194              {
 195              if($this->noDefaultSet)
 196                  {
 197                  // choose a default folder based on the current page
 198                  $htmlfolders = substr(str_replace(',mnT=index,' . T_ORG_DN, '', $this->section->ldapDN), 5);
 199                  $folders = array_reverse(explode(',mnTS=', $htmlfolders));
 200                  
 201                  $base = $this->editorVars['defaultFolder'] . "," . T_ORG_DN;
 202                  foreach($folders as $key => $fname)
 203                      {
 204                      $base = 'mnOD=' . $fname . ',' . $base;
 205                      if(!$this->ldap->dnExists($base))
 206                          oDirectory::create($this->ldap, $base);
 207                      }
 208                  
 209                  $defaultFolder = $base;
 210                  $fileDN = DN::tmpDN($defaultFolder, $this->editorVars['defaultExtension']);
 211                  }
 212              else
 213                  {
 214                  //handles cases of A. when filemanager has first been opened and a new document is created
 215                  //B. when a folder has just been selected within FileManager and then a new document is created
 216                  //C. when a new document is created outside of the FileManager
 217                  // 7/31/2006 Jason Yoder
 218                  if ($this->editorVars['defaultFolder'] == '' && $this->httpVars['folderDn'] == '')
 219                    $fileDN = DN::tmpDN(  $_SESSION['last_opened_dir'], 'html') ;
 220                  else if ( $this->editorVars['defaultFolder'] == '' )
 221                    $fileDN = DN::tmpDN($this->httpVars['folderDn'], 'html') ;
 222                  else
 223                    $fileDN = DN::tmpDN($this->editorVars['defaultFolder'] . "," . T_ORG_DN , $this->editorVars['defaultExtension']) ;
 224                  }
 225              }
 226  
 227          return $fileDN;
 228          }
 229  
 230      /**
 231      * onSave() event
 232      *
 233      * Called by the app dispatch method     
 234      *   (after user selects Save & View or Save & Close while editing a document)
 235      *
 236      * If settingsVars['fileDN'] has something set, then it will delete this file/dn (transferring 
 237      * relevant information, such as type and attrs) and create a new file/dn based on 
 238      * httpVars['filename'].  
 239      * If there is no settingsVars['fileDN'] we simply do the latter, namely, create a new file/dn 
 240      * based on httpVars['filename'].
 241      * Also, ensures that any settingsVars[] (File View Properties) are saved.
 242      * Also, links the file/dn to the current CB.
 243      **/
 244      function onSave()
 245          {                
 246          mnDebug("Editor::onSave() called in ". $this->mode ." mode...");
 247          // don't run if App::init already called us
 248          if (@$this->edoc)
 249                return;
 250  
 251          $fileDN = Editor::getFileDN();
 252          $folderDN = $this->httpVars['folderDN'];
 253  
 254          mnDebug("Editor::onSave(): got $fileDN as the original filedn.");                                              
 255          // make filename New File X.html if no filename is provided
 256        
 257          $suggested_filename_base = (@$this->httpVars['title'] ? $this->httpVars['title'] : $this->httpVars['text']);
 258          $filename = @$this->httpVars['filename'] ? $this->httpVars['filename'] : Editor::_get_suggested_filename($fileDN, $suggested_filename_base);
 259          $extension = DN::dnToExtension($fileDN, false);
 260          // clean up any bad characters in the filename
 261          $filename = mnLDAP::dnSafe($filename .'.'. $extension);
 262        
 263          // set the new fileDN based on the filename they provided
 264          $newDocDN = C_LDAP_FILE .'='. $filename .','. $folderDN;
 265          mnDebug("Editor::onSave(): got $newDocDN as the new filedn.");
 266  
 267          $this->httpVars['fileDN'] = $newDocDN;
 268  
 269          if($this->ldap->dnExists($newDocDN) && $fileDN != $newDocDN)
 270            {
 271            //$fileDN = DN::tmpDN($folderDN, DN::dnToExtension($fileDN, false));
 272            $this->httpVars['fileDN'] = $fileDN;
 273            $this->setNewFile = true;
 274            if(isset($this->httpVars['text']))
 275              $this->httpVars[$this->blockID.'duplicateText'] = $this->httpVars['text'];
 276  
 277            unset($this->httpVars['cv_submit']);
 278            $this->edit = 1;
 279            $this->section->blocks[$this->blockID]->edit = 1;
 280            $this->nonDelete = 1;
 281            new mnAlert("File already exists. A new name has been suggested, please try to save the file again.");
 282            return 0;
 283            }
 284  
 285          if ($fileDN == $newDocDN)
 286              {
 287              $edoc = Editor::_update($fileDN);
 288              if(mnError::isError($edoc))
 289                  { return new mnError('Editor::onSave(): ' . $edoc->getMessage(), __FILE__, __LINE__); }
 290              }
 291          else // filedn and newfiledn are different
 292              {
 293                 // if user clicked Save, then make our own copy
 294                 $edoc = Editor::_replace($fileDN, $newDocDN);
 295              if(mnError::isError($edoc))
 296                  { return new mnError('Editor::onSave(): ' . $edoc->getMessage(), __FILE__, __LINE__); }
 297              }
 298  
 299          // settingsVars
 300          if ($this->mode == 'CB')
 301              {
 302              mnDebug("Editor::onSave(): Adding this block ". $this->ldapDN ." to links array.");
 303              // if we are in content block, then add this content block's link 
 304              // and also save the content block view properties
 305              $res = $edoc->addLink($this->ldapDN);
 306              if(mnError::isError($res))
 307                  { return new mnError('Editor::onSave(): ' . $res->getMessage(), __FILE__, __LINE__); }
 308              mnDebug("Editor::onSave(): Saving view properties of this content block.");
 309              Editor::saveBlockAttributes($edoc);
 310              }    
 311              
 312          if($this->httpVars['tmpName'] != '')
 313              {
 314              // this means that there is a temp file with changes that needs to be copied over the current $edoc
 315              $tmpfile = oFile::load($this->ldap, $this->httpVars['tmpName']);
 316              // make sure we mark the file as XML if needed
 317              if (isset($_REQUEST['editing_xml']))
 318                  $edoc->is_xml = $_REQUEST['editing_xml'];
 319              $edoc->write($tmpfile->read());
 320              
 321              if(DN::dnToExtension($edoc->ldapDN, false) != DN::dnToExtension($tmpfile->ldapDN, false))
 322                  {
 323                  $newdn = str_replace("." . DN::dnToExtension($edoc->ldapDN, false), "." . DN::dnToExtension($tmpfile->ldapDN, false), $edoc->ldapDN);
 324                  $edoc->move($newdn);
 325                  $edoc->ldapDN = $newdn;
 326                  }
 327                  
 328              $edoc = oFile::load($this->ldap, $edoc->ldapDN);
 329              $this->settingsVars['fileDN'] = $edoc->ldapDN;
 330              }    
 331  
 332          $this->edoc =& $edoc;
 333          }
 334          
 335      /**
 336      *
 337      * takes httpVars and updates a file dn
 338      *
 339      * option httpVars:
 340      * text
 341      * keywords
 342      * description
 343      * author
 344      * title
 345      *
 346      * @param    $dn dn  the dn of the file to update
 347      * 
 348      **/
 349      function _update($dn)
 350          {
 351          mnDebug("Editor::_update() called on $dn...");
 352          $obj = oFile::load($this->ldap, $dn, false, true);
 353          if(mnError::isError($obj))
 354              { return new mnError('Editor::_update(): ' . $obj->getMessage(), __FILE__, __LINE__); }
 355   
 356          $attrs = Editor::getFileAttributes($obj);    
 357          mnDebug("Editor::_update() new attrs is: ". Utility::getVal($attrs));
 358          
 359          $attrs['lastmod'] = time();
 360          $attrs_final = Utility::processParams($obj->get(C_LDAP_ATTRIBUTES_ATTR, true));
 361          $attrs_final[$GLOBALS['CV_CURR_LANG']] = $attrs;
 362          $a[C_LDAP_ATTRIBUTES_ATTR] = Utility::packageParams($attrs_final);
 363  
 364          $res = $obj->update($a);
 365          if(mnError::isError($res))
 366              { return new mnError('Editor::_update(): ' . $res->getMessage(), __FILE__, __LINE__); }
 367          unset($attrs);
 368          // if we had a text editor, save the changes to disk        
 369          if (isset($this->httpVars['text']))
 370              {
 371              mnDebug("Editor::_update(): updating text...");
 372              // make sure we mark the file as XML if needed
 373              if (isset($_REQUEST['editing_xml']))
 374                  $obj->is_xml = $_REQUEST['editing_xml'];
 375              $res = $obj->write($this->httpVars['text']);
 376              if(mnError::isError($res))
 377                  { return new mnError('Editor::_update(): ' . $res->getMessage(), __FILE__, __LINE__); }
 378              }
 379              
 380          // reload the file after the update
 381          $obj = oFile::load($this->ldap, $dn);
 382      
 383          return $obj;
 384          }
 385  
 386      /**
 387      * replaces olddn with newdn ... or creates a newdn if olddn is 0
 388      **/
 389      function _replace($olddn = 0, $newdn)
 390          {
 391          // first delete the newdn if one exists
 392          // if the new dn exists (and its not the same as the olddn), delete it here
 393          // TODO should I mark a javascript warning of some sort?
 394          if ($this->ldap->dnExists($newdn))
 395              {
 396              mnDebug("Editor::_replace(): Found $newdn so deleting it.");
 397              $obj = oFile::load($this->ldap, $newdn);
 398              if(mnError::isError($obj))
 399                  { return new mnError('Editor::_replace(): ' . $obj->getMessage(), __FILE__, __LINE__); }
 400              $res = $obj->delete();
 401              if(mnError::isError($res))
 402                  { return new mnError('Editor::_replace(): ' . $res->getMessage(), __FILE__, __LINE__); }
 403              }
 404  
 405          // if the old dn existed, grab its links, attrs, and mimetype 
 406          if ($this->ldap->dnExists($olddn))
 407              {
 408              mnDebug("Editor::_replace(): old $olddn exists so slurping its attributes, links, and mimetype.");
 409              $oldedoc = oFile::load($this->ldap, $olddn);
 410              if(mnError::isError($oldedoc))
 411                  { return new mnError('Editor::_replace(): ' . $oldedoc->getMessage(), __FILE__, __LINE__); }
 412              }
 413          else
 414              {
 415              $oldedoc = '';
 416              }
 417          $mimetype = FileTypeTable::extensionToType($newdn);
 418  
 419          $attrs = Editor::getFileAttributes($oldedoc);
 420          if(isset($oldedoc) && $oldedoc != "")
 421              {
 422              $attrs_final = Utility::processParams($oldedoc->get(C_LDAP_ATTRIBUTES_ATTR, true));
 423              $attrs_final[$GLOBALS['CV_CURR_LANG']] = $attrs;
 424              $attrs = array();
 425              $attrs = $attrs_final;
 426              }
 427          else
 428              {
 429              $attrs_final[$GLOBALS['CV_CURR_LANG']] = $attrs;
 430              $attrs = array();
 431              $attrs = $attrs_final;
 432              }
 433          $attrs['lastmod'] = time();
 434  
 435          // send ofile either the old filename or text, depending on the mimetype        
 436          // pjh August 26th, 2004 -- actually, send it the text in both cases
 437          if (isset($this->httpVars['text']))
 438              $contents = $this->httpVars['text'];
 439          else
 440              $contents = $oldedoc->read(); // file->getName();
 441  
 442          // call create: NB $contents is either a filename (if binary) or a string
 443          // mimetype is the mimetype of the file
 444          mnDebug("Editor::_replace(): calling create with $contents and $mimetype on $newdn.");
 445          $newedoc = oFile::create($this->ldap, $newdn, $contents, $mimetype, $attrs);
 446          if(mnError::isError($newedoc))
 447              { return new mnError('Editor::_replace(): ' . $newedoc->getMessage(), __FILE__, __LINE__); }
 448          
 449          // finally delete the old dn (note that it will only be successfully deleted as long as it is
 450          // not currently open in any content block
 451          if (isset($oldedoc))
 452              {
 453              if (is_object($oldedoc))
 454                  {
 455                  mnDebug("Editor::_replace(): deleting old $olddn");
 456  
 457                  if ($this->mode == 'CB')
 458                      $oldedoc->removeLink($this->ldapDN); //remove link to this block, so old file will get
 459                                                           //deleted if no other block has it open
 460                  // removed the delete that was here, since it really does not make sense in save as --reuvenmh Oct 30th, 2007
 461                  }
 462              }
 463  
 464          return $newedoc; 
 465          }
 466         
 467      /**
 468      * fetch the attributes of this file that are not being overridden, for saving in _update or _replace
 469      **/ 
 470  	function getFileAttributes(&$edoc)
 471          {
 472          if ($edoc)
 473              {
 474              $attrs = Utility::processParams($edoc->get(C_LDAP_ATTRIBUTES_ATTR, true));
 475              $attrs = $attrs[$GLOBALS['CV_CURR_LANG']];
 476              }
 477          else
 478              $attrs = array();
 479              
 480          // special handling of categories setting -- because it's stored in keywords behind the scenes
 481          if ($this->mode == 'blog_post') {
 482              // update the blog's count of how many posts are in each category
 483              $old_cats = $attrs['keywords'] ? explode(',', $attrs['keywords']) : array();
 484              $new_cats = isset($this->httpVars['categories']) ? $this->httpVars['categories'] : array();
 485              $this->updateCategories($old_cats, $new_cats); // '$this' is the Blog app that called the editor
 486          
 487              sort($new_cats);
 488              $this->httpVars['keywords'] = implode(',', $new_cats);
 489          }
 490              
 491          if (method_exists($edoc, 'getAttributes'))
 492              {
 493              $typeAttrs = $edoc->getAttributes();
 494              foreach($typeAttrs as $attrName => $attr)
 495                  {
 496                  if (!isset($this->httpVars[$attrName . '_o']))
 497                      {
 498                      if ($attr[1] == 'checkbox')
 499                          $attrs[$attrName] = isset($this->httpVars[$attrName]) ? 1 : 0;
 500                      else
 501                          $attrs[$attrName] = $this->httpVars[$attrName];
 502                      }
 503                  }
 504              }
 505          
 506          $defaultAttrs = array('title', 'author', 'createdate', 'expDate', 'keywords', 'description');
 507          foreach($defaultAttrs as $attrName)
 508              {
 509              if (!isset($this->httpVars[$attrName . '_o']))
 510                  {
 511                  if ($attrName == 'createdate')
 512                      {
 513                      if($edoc)
 514                          $this->httpVars['createdate'] .= date(' H:i:s', $edoc->getAttr('createdate'));
 515                      $this->httpVars['createdate'] = strtotime($this->httpVars['createdate']);
 516                      if ($this->httpVars['createdate'] > mktime())
 517                          $this->httpVars['createdate'] = mktime();
 518                      }
 519                  $attrs[$attrName] = $this->httpVars[$attrName];
 520                  }
 521              }
 522          return $attrs;
 523          }
 524  
 525      /**
 526      * save the attributes of this file that are block-specific / overriding the file default
 527      **/
 528  	function saveBlockAttributes(&$edoc)
 529          {
 530          $fullattrs = $this->getSettingsVars();
 531          $attrs = $fullattrs['metadata'][$GLOBALS['CV_CURR_LANG']];
 532          
 533          if (method_exists($edoc, 'getAttributes'))
 534              {
 535              $fileAttrs = $edoc->getAttributes();
 536              foreach($fileAttrs as $attrName => $attr)
 537                  {
 538                  if ($attr[1] == 'checkbox' && isset($this->httpVars[$attrName . '_o']))
 539                      $attrs[$attrName] = isset($this->httpVars[$attrName]) ? '1' : '0';
 540                  else if (isset($this->httpVars[$attrName . '_o']))
 541                      $attrs[$attrName] = $this->httpVars[$attrName];
 542                  else
 543                      unset($attrs[$attrName]);
 544                  }
 545              }
 546              
 547          $defaultAttrs = array('title', 'expDate');
 548          foreach($defaultAttrs as $attrName)
 549              {
 550              if (isset($this->httpVars[$attrName . '_o']))
 551                  $attrs[$attrName] = $this->httpVars[$attrName];
 552              else
 553                  unset($attrs[$attrName]);
 554              }
 555              
 556          $fullattrs['metadata'][$GLOBALS['CV_CURR_LANG']] = $attrs;
 557          $this->saveSettings($fullattrs);
 558          }
 559  
 560      function getAttributesHtml(&$edoc)
 561          {
 562             $attrs = $this->mode == 'blog_post' ? array() : array('keywords' => array('', 'Keywords:', 'textarea', $edoc->getAttr('keywords'), 2));
 563             $empty = array();
 564             
 565             if($edoc == "")
 566                 return '';
 567             
 568             $edoc->setAttrOverride($empty);
 569  
 570          if (method_exists($edoc, 'getAttributes'))
 571              {
 572              // fetch the attribute list and add an 'override' checkbox to all the per-filetype ones 
 573              $attrs =& $edoc->getAttributes();
 574              foreach($attrs as $attrName => $attr)
 575                  {
 576                  if ($this->mode == 'CB')
 577                      {
 578                      $field = $this->paramName($attrName);
 579                      $defVal = addslashes($edoc->getAttr($attrName));
 580                      if ($attr[1] == 'checkbox')
 581                          $js = isset($this->settingsVars['metadata'][$GLOBALS['CV_CURR_LANG']][$attrName]) ? "if(this.checked){ this.form.$field.checked={$field}_old }else { {$field}_old=this.form.$field.checked;this.form.$field.checked='$defVal'; }" : '';
 582                      else
 583                          $js = isset($this->settingsVars['metadata'][$GLOBALS['CV_CURR_LANG']][$attrName]) ? "if(this.checked){ this.form.$field.value={$field}_old }else { {$field}_old=this.form.$field.value;this.form.$field.value='$defVal'; }" : '';
 584                      array_unshift($attrs[$attrName], FormWidget::checkbox($attrName . '_o', isset($this->settingsVars['metadata'][$GLOBALS['CV_CURR_LANG']][$attrName]), '', $js ? array('onclick' => $js) : array()));
 585                      }
 586                  else
 587                      array_unshift($attrs[$attrName], '');                    
 588                  }
 589              }
 590              
 591          // fetch the current settings -- from settingsVars if overridden, or from the mnF attributes if not
 592          $edoc->setAttrOverride($this->settingsVars['metadata'][$GLOBALS['CV_CURR_LANG']]);
 593          foreach($attrs as $attrName => $attr)
 594              {
 595              if (is_array($attr))
 596                  $attrs[$attrName][3] = $edoc->getAttr($attrName);
 597              }
 598              
 599          return FormWidget::quickForm($attrs, '', 'form.noformtagdivonly.tpl.html');
 600          }    // end function getAttributes
 601  
 602      /**
 603      * gets the editor html
 604      * 
 605      * @param    object  edoc: a loaded oFile
 606      * @param    boolean newBlock: true if we're editing a file in a new block (so Cancel should delete the block)
 607      * @return   string  the html of the editor
 608      *
 609      **/
 610      function getHtml(&$edoc, $newBlock = false)
 611          {
 612          if($edoc == "")
 613              return '';
 614          if(T_SINGLE_BLOCK)
 615            define('T_DONT_PARSE', 1);
 616          $newFile = false;
 617          $tpl = new Template_PHPLIB(T_APP_BASE .'Editor', 'keep');
 618          $tpl->setFile(array('main' => 'Editor.tpl.html'));
 619          $tpl->setVar('formName', 'main');       
 620          if($this->forceSingle)
 621              $extra = "&forceSingle=1";
 622          else
 623              $extra = "";    
 624          $tpl->setVar('linkToSelf', $this->linkToSelf(array('fileDN' => $edoc->ldapDN, 'mode' => $this->mode)) . $extra);
 625  
 626          // file ID for title
 627          $name = DN::dnToName($edoc->ldapDN);
 628          if (ereg('tmp.', $name))
 629              {
 630              include_once(T_CODE_BASE . "File/File.php");
 631              $newFile = true;
 632              $name = File::getNewFileName(DN::dnToBase($edoc->ldapDN), 'New File', $this->editorVars['defaultExtension']);
 633              }
 634          
 635          $fileID = DN::dnToFolderID($edoc->ldapDN);
 636          $fileID .= ($fileID{strlen($fileID)-1} == '/' ? '' : '/') . $name;
 637          if ($this->colWidth < 300 && strlen($fileID) > 33)
 638              $fileID = substr($fileID, 0, 5) ."... ". substr($fileID, -25);
 639          $tpl->setVar('fileID', $fileID);
 640  
 641          $htmlarea = isset($this->section->blocks[$this->blockID]->blockStyle['htmlarea']) ? $this->section->blocks[$this->blockID]->blockStyle['htmlarea'] : 'on';
 642          if ($htmlarea == 'off')
 643              $this->editorVars['useHtmlArea'] = false;
 644              
 645          if (method_exists($edoc, 'getEditor'))
 646              $editorhtml = $edoc->getEditor($this);
 647          
 648          if(isset($this->httpVars['cv_submit']) && $this->httpVars['cv_submit'] == "clean")
 649              {
 650              require_once (T_BASE . 'plugins/HtmlTidyBody/HtmlTidyBody.php');
 651              
 652              $matches = array();
 653              $first_text = preg_match("/<textarea[^>]+>/",$editorhtml, $matches);
 654              $first_index = strpos($editorhtml, $matches[0]) + strlen($matches[0]);
 655              $begin = substr($editorhtml, 0, $first_index);
 656  
 657              // *sigh* strrpos does not work with strings in php4 so we get to implement this manually - thanks php.net comments for this code segment (which I might note is brilliant)
 658              $second_index        = strpos(strrev($editorhtml), strrev("</textarea>"));
 659              $second_index        = strlen($editorhtml) - strlen("</textarea>") - $second_index;
 660              $end = substr($editorhtml, $second_index);
 661  
 662              $content = substr($editorhtml, $first_index, $second_index - $first_index);
 663  
 664              $content = HtmlTidyBody::doHtmlTidy($content, 1);
 665  
 666              $editorhtml = $begin . "\n" . $content . "\n" . $end;
 667              }    
 668              
 669          if (method_exists($edoc, 'getPreview'))
 670              $previewhtml = $edoc->getPreview($this);    
 671          
 672          // get rid of the override so we can construct the js
 673          $empty = array();
 674          $edoc->setAttrOverride($empty);    
 675          
 676          $field = $this->paramName('title');
 677          $defVal = addslashes($edoc->getAttr('title'));
 678          $js = isset($this->settingsVars['metadata'][$GLOBALS['CV_CURR_LANG']]['title']) ? "if(this.checked){ this.form.$field.value={$field}_old; }else { {$field}_old=this.form.$field.value;this.form.$field.value='$defVal'; }" : '';
 679          $field = $this->paramName('expDate');
 680           $defVal = $edoc->getAttr('expDate');
 681          $js2 = isset($this->settingsVars['metadata'][$GLOBALS['CV_CURR_LANG']]['expDate'])
 682              ? "if(this.checked) { document.getElementById('{$field}_disp').innerHTML=this.form.$field.value={$field}_old; }
 683                else { {$field}_old=this.form.$field.value;this.form.$field.value='$defVal';d=new Date('$defVal');document.getElementById('{$field}_disp').innerHTML="
 684                . (($defVal == '' or $defVal == 'never') ? "'never'" : "month_names[d.getMonth()] + ' ' + d.getDate() + ', ' + d.getFullYear()")
 685                . "; } }"
 686              : '';
 687  
 688          //re-enable the override
 689          $edoc->setAttrOverride($this->settingsVars['metadata'][$GLOBALS['CV_CURR_LANG']]);
 690          $attrshtml = Editor::getAttributesHtml($edoc);
 691          
 692          // take care of the standard attribs
 693          if ($this->mode == 'blog_post') {
 694              // don't allow changing the author in blog mode
 695              $author = $edoc->getAttr('author');
 696              $tpl->setVar('author', FormWidget::hidden('author', $author) . '<span style="padding: 3px; font-size: 11pt;">' . $author . '</span>');
 697  
 698              // hide the keywords field in Blog mode (because we provide access to it under the Categories selector)
 699              $tpl->setVar('keywords', '');
 700              
 701              // show the categories selector instead of the description field
 702              $tpl->setVar('3rdattr_label', 'Categories:');
 703               $selected_categories = explode(',', $edoc->getAttr('keywords'));
 704               $blog_dn = DN::dnToBase($edoc->ldapDN);
 705               $all_categories = array_keys($this->getCategories()); // '$this' is the Blog app that is calling us
 706               $categories = array();
 707               foreach ($all_categories as $cat)
 708                   $categories[$cat] = $cat;
 709              $tpl->setVar('3rdattr', FormWidget::multi_select('categories', $categories, $selected_categories, 'uncategorized', 3, true, array('style' => 'width: 300px;')));
 710          } else {
 711              $tpl->setVar('author', FormWidget::text('author',$edoc->getAttr('author') , 10 ));
 712              $tpl->setVar('keywords', FormWidget::textarea('keywords', $edoc->getAttr('keywords') , 2, '', array('style' => 'width: 90%;')));
 713              $tpl->setVar('3rdattr_label', 'Description:');
 714              $tpl->setVar('3rdattr', FormWidget::textarea('description', $edoc->getAttr('description') , 2, '', array('style' => 'width: 90%;')));
 715          }
 716          $tpl->setVar('titlecheck', $this->mode == 'CB' ? FormWidget::checkbox('title_o', isset($this->settingsVars['metadata'][$GLOBALS['CV_CURR_LANG']]['title']), '', $js ? array('onclick' => $js) : array()) : '&nbsp;');
 717          $tpl->setVar('title', FormWidget::text( 'title', $edoc->getAttr('title') , 30, ($js ? array('onclick' => $js, 'style' => 'width: 200px;') : array('style' => 'width: 300px;'))));
 718          $tpl->setVar('createdate', FormWidget::date('createdate', $edoc->getAttr('createdate')));
 719          $tpl->setVar('expdate', FormWidget::date('expDate', $edoc->getAttr('expDate'), 1));
 720          $tpl->setVar('expdatecheck', $this->mode == 'CB' ? FormWidget::checkbox('expDate_o', isset($this->settingsVars['metadata'][$GLOBALS['CV_CURR_LANG']]['expDate']), '', $js2 ? array('onclick' => $js2) : array())  : '&nbsp;');
 721          $tpl->setVar('extraAttrs', FormWidget::hidden('cv_submit', '') . FormWidget::hidden('folderDN', '') . FormWidget::hidden('filename', '') . $attrshtml);
 722          
 723          $fileMime = $edoc->file->getMimeType();
 724          if($this->httpVars['imgAction'] == 'undo')
 725              {
 726              if($this->httpVars['oldtmpName'] !== '')
 727                  {
 728                  $tmpName = $this->httpVars['oldtmpName'];
 729                  $tmpfile = oFile::load($this->ldap, $tmpName);
 730                  $oldtmpName = $tmpName;
 731                  $this->httpVars['tmpName'] = $tmpName;
 732  
 733                  $fileMime = $tmpfile->file->getMimeType();
 734                  $previewhtml = $tmpfile->getPreview($this);
 735                  }
 736              }
 737          if($this->httpVars['imgAction'] == 'preview')    
 738              {
 739              if($this->httpVars['tmpName'] !== '')
 740                   {
 741                   $tmpName = $this->httpVars['tmpName'];
 742                   $tmpfile = oFile::load($this->ldap, $tmpName);
 743                   $oldtmpName = $tmpName;
 744                   
 745                   $tmpName = DN::tmpDN(DN::dnToBase($edoc->ldapDN), DN::dnToExtension($tmpfile->ldapDN, false));
 746                   $tmpfile->copy($tmpName);
 747                   $tmpfile = oFile::load($this->ldap, $tmpName);
 748                   }
 749               else
 750                   {
 751                   $tmpName = DN::tmpDN(DN::dnToBase($edoc->ldapDN), DN::dnToExtension($edoc->ldapDN, false));
 752                   $edoc->copy($tmpName);
 753                   $tmpfile = oFile::load($this->ldap, $tmpName);
 754                   }
 755  
 756              $fileMime = $tmpfile->file->getMimeType();
 757  
 758              $fullpath = DN::dnToFullPath($tmpName);
 759              switch ($fileMime) {
 760                      case "image/gif":
 761                          $img       =  imageCreateFromGIF($fullpath);
 762                          $oldExt = ".gif";
 763                          break;
 764                      case "image/jpeg":
 765                      case "image/jpg":
 766                          $img       =  imageCreateFromJPEG($fullpath);
 767                          $oldExt = ".jpg";
 768                          break;
 769                      case "image/png":
 770                          $img       =  imageCreateFromPNG($fullpath);
 771                          $oldExt = ".png";
 772                          break;
 773                      }
 774  
 775              //now we do the modifications
 776              if(isset($this->httpVars['modType']) && $fileMime != $this->httpVars['imagetype'])
 777                  {
 778                  $fileMime = $this->httpVars['imagetype'];
 779                  $newName = Editor::imageChangeType($img, $tmpName, $fileMime, $oldExt);
 780  
 781                  $tmpfile = oFile::load($this->ldap, $newName);
 782                  $tmpName = $newName;
 783                  $fullpath = DN::dnToFullPath($tmpName);
 784                  }
 785                  
 786              if(isset($this->httpVars['modCrop']))
 787                  {
 788                  
 789  
 790                  
 791                  $img = Editor::imageCrop($img, $this->httpVars['imagecropwidth'], $this->httpVars['imagecropheight'], $this->httpVars['imagecropxo'], $this->httpVars['imagecropyo']);
 792  
 793                  switch ($fileMime) {
 794                      case "image/gif": 
 795                          imageGIF($img, $fullpath);
 796                          break;
 797                      case "image/jpeg":
 798                      case "image/jpg":
 799                          imageJPEG($img, $fullpath, 95);
 800                          break;
 801                      case "image/png":
 802                          imagePNG($img, $fullpath);
 803                          break;
 804                      }
 805                  }
 806                 
 807              if(isset($this->httpVars['modScale']) && ($this->httpVars['imagescalewidth'] != "" || $this->httpVars['imagescaleheight'] != ""))    
 808                  {
 809                  $img = Editor::imageScale($img, $this->httpVars['imagescaleheight'], $this->httpVars['imagescalewidth']);
 810  
 811                  switch ($fileMime) {
 812                      case "image/gif":
 813                          imageGIF($img, $fullpath);
 814                          break;
 815                      case "image/jpeg":
 816                      case "image/jpg":
 817                          imageJPEG($img, $fullpath, 95);
 818                          break;
 819                      case "image/png":
 820                          imagePNG($img, $fullpath);
 821                          break;
 822                      }
 823                  }
 824                  
 825              if(isset($this->httpVars['modTransform']))
 826                  {
 827                  if($this->httpVars['imagerotationamount'] != "")
 828                      {
 829                      $img = Editor::imageRotateColored($img, $this->httpVars['imagerotationamount'], $this->httpVars['rotatedir'], $this->httpVars['imagerotatecolor']);
 830                      }
 831                  if($this->httpVars['imagefliph'] != "")
 832                      {
 833                      $img = Editor::imageFlip($img, 0);
 834                      }                    
 835                  if($this->httpVars['imageflipv'] != "")
 836                      {
 837                      $img = Editor::imageFlip($img, 1);
 838                      }
 839  
 840                  switch ($fileMime) {
 841                      case "image/gif":
 842                          imageGIF($img, $fullpath);
 843                          break;
 844                      case "image/jpeg":
 845                      case "image/jpg":
 846                          imageJPEG($img, $fullpath, 95);
 847                          break;
 848                      case "image/png":
 849                          imagePNG($img, $fullpath);
 850                          break;
 851                      }                
 852                  }    
 853  
 854              $fileMime = $tmpfile->file->getMimeType();
 855              $previewhtml = $tmpfile->getPreview($this);
 856              }
 857  
 858          //cancel button
 859          $paramsToPass = array();
 860          $paramsToPass[ 'admin[block;' . $this->blockID . ']' ] = $newBlock ? 'delcont' : 'preview';
 861          $link = Utility::link($this->sectionPathArray, $paramsToPass);
 862  
 863          //save button  
 864          if(strpos($this->blockID, "tmp") !== false || T_SINGLE_BLOCK)
 865              {
 866              $popupUrl = Utility::link($this->section->pathArray, array()) . '&amp;block__tmpEditor__tmpName=' . urlencode($tmpName) . '&amp;block__tmpEditor__edit=1&amp;block__tmpEditor__edmode=1&amp;block__tmpEditor__fileDN=' . $edoc->ldapDN . '&amp;_single=tmpEditor&amp;block__tmpEditor__parentPrefix=' . $this->paramName('');        
 867              $cancel = FormWidget::submit('cv_cancel', 'Cancel', array('onclick' => "self.close();"));
 868              }
 869          else
 870              {               
 871              $popupUrl = Utility::link($this->section->pathArray, array($this->paramName('tmpName') => $tmpName, $this->paramName('parentPrefix') => $this->paramName(''), $this->paramName('edit') => 1, $this->paramName('edmode') => 1, $this->paramName('fileDN') => $edoc->ldapDN)) . '&amp;_single='. $this->blockID;
 872              $cancel = FormWidget::submit('cv_cancel', 'Cancel', array('onclick' => "form.action='" . $link . "';"));
 873              }
 874  
 875          if(strpos($edoc->ldapDN, "mnF=tmp.") !== false)
 876              {
 877              if ($this->mode != 'blog_post')
 878                  $savebuttons = FormWidget::button('save', 'Save As', "try {var suggested = tinyMCE.getContent(tinyMCE.getWindowArg('editor_id')); suggested = suggested.substring(0, 100);} catch(e){} popup('$popupUrl&amp;suggested=' + suggested, 'Editor', 400, 150);");
 879              else
 880                   $savebuttons = FormWidget::button('save', 'Save' , "document.main." . $this->paramName('folderDN') . ".value = '" . addslashes(DN::dnToParent($edoc->ldapDN)) . "'; document.main." . $this->paramName('filename') . ".value = ''; document.main." . $this->paramName('cv_submit') . ".value = 'Save &amp; Preview'; document.main.action = document.main.action.replace('_edit=1', '_edit=0');document.main.submit();");
 881              }
 882          else
 883              {
 884              // this is a already existing doc that is being modified - so we want a "Save and Preview" and "Cancel" button with "Save and Edit" and "Save As" as link buttons
 885              $savebuttons = "&nbsp;&nbsp;" . FormWidget::button('savepv', $this->mode == 'CB' ? 'Save & Preview' : 'Save & Close' , "document.main." . $this->paramName('folderDN') . ".value = '" . DN::dnToParent($edoc->ldapDN) . "'; document.main." . $this->paramName('filename') . ".value = '" . substr(DN::dnToName($edoc->ldapDN), 0, strrpos(DN::dnToName($edoc->ldapDN), ".")) . "'; document.main." . $this->paramName('cv_submit') . ".value = 'Save &amp; Preview'; document.main.action = document.main.action.replace('_edit=1', '_edit=0');document.main.submit();");
 886  
 887              $cancel .= '<br />';
 888              if ($this->mode != 'blog_post') // skip the Save As link for blog posts, because they are named automatically
 889                  $cancel .= '<a style="font-size: 11px;" href="#" onclick="' . "try {var suggested = tinyMCE.getContent(tinyMCE.getWindowArg('editor_id')); suggested = suggested.substring(0, 100);} catch(e){} popup('$popupUrl&amp;suggested=' + suggested, 'Editor', 400, 150);"  . '">Save As</a>';
 890              $cancel .= "&nbsp;&nbsp;" . '<a style="font-size: 11px;" href="#" onclick="' . "document.main." . $this->paramName('folderDN') . ".value = '" . DN::dnToParent($edoc->ldapDN) . "'; document.main." . $this->paramName('filename') . ".value = '" . substr(DN::dnToName($edoc->ldapDN), 0, strrpos(DN::dnToName($edoc->ldapDN), ".")) . "'; document.main." . $this->paramName('cv_submit') . ".value = 'Save &amp; Edit'; document.main.submit();" . '">Save & Edit</a>';
 891              //if the doc is html then allow htmltidy to be run on it
 892              if(strpos($edoc->ldapDN, ".html") != false && function_exists('tidy_parse_string'))
 893                  $cancel .= "&nbsp;&nbsp;" . '<a style="font-size: 11px;" href="#" onclick="' . "document.main." . $this->paramName('folderDN') . ".value = '" . DN::dnToParent($edoc->ldapDN) . "'; document.main." . $this->paramName('filename') . ".value = '" . substr(DN::dnToName($edoc->ldapDN), 0, strrpos(DN::dnToName($edoc->ldapDN), ".")) . "'; document.main." . $this->paramName('cv_submit') . ".value = 'clean'; document.main.submit();" . '">Save & Clean up HTML</a>';
 894              }     
 895  
 896          if ($this->mode == 'CB')
 897              $tpl->setVar('instructions', 'Click the checkbox to apply title, expiration, etc. to this block only.');
 898          else
 899              $tpl->setVar('instructions', '');
 900  
 901          //display the buttons
 902          $tpl->setVar('savebuttons',  $savebuttons . "&nbsp;&nbsp;" . $cancel . "&nbsp;&nbsp;");
 903              
 904          $tpl->setVar('standard_meta', $this->paramName('standard_meta'));
 905          $tpl->setVar('advanced_meta', $this->paramName('advanced_meta'));
 906              
 907          if($editorhtml != "")
 908              $finalhtml = $editorhtml;
 909          else
 910              $finalhtml = $previewhtml;    
 911              
 912          $tpl->setVar('tabs', $finalhtml);
 913          if($fileMime == 'image/jpeg' || $fileMime == 'image/gif' || $fileMime == 'image/png')
 914               {
 915               if($this->ldap->dnExists(DN::dnToThumbDN($edoc->ldapDN)))
 916                   {
 917                   $tfile = oFile::load($this->ldap, DN::dnToThumbDN($edoc->ldapDN));            
 918                   $tpreview = $tfile->getPreview($this);
 919                   }
 920               
 921               $itype = substr($fileMime, strpos($fileMime, "/") + 1);
 922               if(!isset($fullpath))
 923                   $fullpath = DN::dnToFullPath($edoc->ldapDN);
 924               
 925               list($owidth, $oheight) = getimagesize($fullpath);
 926               if(strpos($this->blockID, "tmp") !== false || T_SINGLE_BLOCK)
 927                   $thumbslink = Utility::link($this->section->pathArray, array()) . '&amp;block__tmpEditor__tmpName=' . urlencode($tmpName) . '&amp;block__tmpEditor__edit=1&amp;block__tmpEditor__mode=thumbs&amp;block__tmpEditor__fileDN=' . $edoc->ldapDN . '&amp;_single=tmpEditor';        
 928               else    
 929                   $thumbslink = Utility::link($this->section->pathArray, array($this->paramName('tmpName') => $tmpName, $this->paramName('edit') => 1, $this->paramName('mode') => 'thumbs'))  . '&amp;_single='. $this->blockID;
 930               
 931               $text = '<div style="position: relative; height: 100%; background-color: #F1F1F1; border: solid 1px #ddd;border-top:none;border-bottom: none; color: #333; width: 100%;padding-left: 8px;">' .
 932                        FormWidget::hidden('imgAction', '') . FormWidget::hidden('tmpName', $tmpName) . FormWidget::hidden('oldtmpName', $oldtmpName);
 933                        
 934               $text .= '<div style="position:absolute; top: 0px; right: 0px; float:right;clear: both;width: 150px; margin-left: -2px; border: solid 1px #dddddd;padding-bottom: 5px;">
 935                         <div style="border-bottom: solid 1px #cccccc; font-size: 10px;padding: 1px 3px 1px 3px;">Image stats</div>
 936                         <div style="font-size: 10px;padding: 2px 5px 2px 5px;">' . $owidth . 'x' . $oheight . ' px <span style="font-weight: bold;">' . $itype . '</span> image<br />Current Thumbnail:</div>
 937                         ' . $tpreview . '
 938                         </div>';
 939               $text .= '<div style="font-size: 10px;padding: 2px 5px 2px 5px;"><a href="#" onclick="popup(\'' . $thumbslink . '\', \'Editor\', 400, 500); return false;">Set up this images thumbnail</a>
 940                         </div>';                   
 941               $text .= '<div style="float:left;clear: both;width: 100%; margin-left: -2px; font-size: 12px;font-weight: bold;">
 942                         ' . FormWidget::checkbox('modType', '', '') . ' Image Type
 943                         </div>';                                    
 944               $text .= '<div style="float:left;clear: both;width: 100%;">
 945                        <div style="margin-top: 3px;float:left;width: 65px;">Image Type:</div>' . 
 946                        '<div style="margin-top: 3px;float:left;width: 75%;">' . FormWidget::dropdown('imagetype', array('image/jpeg' => 'Jpeg', 'image/gif' => 'GIF', 'image/png' => 'PNG'), '', $fileMime, array('onchange' => 'this.form.' . $this->paramName('modType') . '.checked = true;'))
 947                        //<div style="margin-top: 3px;float:left;width: 75%;">' . FormWidget::dropdown('imagetype', array('image/jpeg' => 'Jpeg', 'image/gif' => 'GIF', 'image/png' => 'PNG'), '', $fileMime, array('onchange' => 'if(this.value == \'image/jpeg\') { this.form.' . $this->paramName('imagetypequality') . '.disabled = false; } else { this.form.' . $this->paramName('imagetypequality') . '.disabled = true; } this.form.' . $this->paramName('modType') . '.checked = true;'))
 948                        // . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quality:&nbsp;&nbsp;&nbsp;&nbsp;' . FormWidget::dropdown('imagetypequality', array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10'), '', '9')  . 
 949                        . '</div></div>';
 950               $text .= '<div style="float:left;clear: both;width: 100%; margin-left: -2px; font-size: 12px;font-weight: bold;">
 951                         ' . FormWidget::checkbox('modCrop', '', '') . ' Cropping
 952                         </div>';                  
 953               $text .= '<div style="float:left;clear: both;width: 100%;">
 954                        <div style="margin-top: 3px;float:left;width: 65px;">X Origin:</div>
 955                        <div style="margin-top: 3px;float:left;width: 50px;">' . FormWidget::text('imagecropxo', '', 4, array('onkeyup' => 'this.form.' . $this->paramName('modCrop') . '.checked = true;')) . '</div>
 956                        <div style="margin-top: 3px;float:left;width: 65px;">Y Origin:</div>
 957                        <div style="margin-top: 3px;float:left;width: 50px;">' . FormWidget::text('imagecropyo', '', 4, array('onkeyup' => 'this.form.' . $this->paramName('modCrop') . '.checked = true;')) . '</div>
 958                        </div>'; 
 959               $text .= '<div style="float:left;clear: both;width: 100%;">
 960                        <div style="margin-top: 3px;float:left;width: 65px;">Height:</div>
 961                        <div style="margin-top: 3px;float:left;width: 50px;">' . FormWidget::text('imagecropheight', '', 4, array('onkeyup' => 'this.form.' . $this->paramName('modCrop') . '.checked = true;')) . '</div>
 962                        <div style="margin-top: 3px;float:left;width: 65px;">Width:</div>
 963                        <div style="margin-top: 3px;float:left;width: 50px;">' . FormWidget::text('imagecropwidth', '', 4, array('onkeyup' => 'this.form.' . $this->paramName('modCrop') . '.checked = true;')) . '</div>
 964                        </div>';
 965               $text .= '<div style="float:left;clear: both;width: 100%; margin-left: -2px; font-size: 12px;font-weight: bold;">
 966                         ' . FormWidget::checkbox('modScale', '', '') . ' Scaling
 967                         </div>';
 968               $text .= '<div style="float:left;clear: both;width: 100%;">
 969                        <div style="margin-top: 3px;float:left;width: 65px;">Height:</div>
 970                        <div style="margin-top: 3px;float:left;width: 50px;">' . FormWidget::text('imagescaleheight', '', 4, array('onkeyup' => 'this.form.' . $this->paramName('modScale') . '.checked = true;')) . '</div>
 971                        <div style="margin-top: 3px;float:left;width: 65px;">Width:</div>
 972                        <div style="margin-top: 3px;float:left;width: 50px;">' . FormWidget::text('imagescalewidth', '', 4, array('onkeyup' => 'this.form.' . $this->paramName('modScale') . '.checked = true;')) . '</div>
 973                        </div>';   
 974               $text .= '<div style="float:left;clear: both;width: 100%; margin-left: -2px; font-size: 12px;font-weight: bold;">
 975                         ' . FormWidget::checkbox('modTransform', '', '') . ' Transforms
 976                         </div>';       
 977               $text .= '<div style="float:left;clear: both;width: 100%;">
 978                        <div style="margin-top: 3px;float:left;width: 65px;">Rotate:</div>
 979                        <div style="margin-top: 3px;float:left;width: 95px;">' . FormWidget::dropdown('rotatedir', array('clockwise' => '+', 'counterclockwise' => '-'), '', '+') . FormWidget::text('imagerotationamount', '', 4, array('onkeyup' => 'this.form.' . $this->paramName('modTransform') . '.checked = true;')) . '</div>
 980                        <div style="margin-top: 3px;float:left;width: 65px;">Fill color:</div>
 981                        <div style="margin-top: 3px;float:left;width: 50px;">' . FormWidget::color('imagerotatecolor', 'FFFFFF', 'Background color') . '</div>
 982                        </div>';      
 983               $text .= '<div style="float:left;clear: both;width: 100%;">
 984                        <div style="margin-top: 3px;float:left;width: 65px;">Flip:</div>
 985                        <div style="margin-top: 3px;float:left;width: 230px;">' . FormWidget::checkbox('imagefliph', 0, 'Flip Horizontally', array('onclick' => 'this.form.' . $this->paramName('modTransform') . '.checked = true;'))
 986                        . FormWidget::checkbox('imageflipv', 0, 'Flip Vertically', array('onclick' => 'this.form.' . $this->paramName('modTransform') . '.checked = true;')) . '</div>
 987                        </div>';                                  
 988               $text .= '<div style="float:left;clear: both;width: 100%;">
 989                        <div style="padding: 4px;margin-top: 9px;margin-bottom: 9px;float:left;">Enter the changes you would like to make and the hit preview image to see the effect. Once you have made all the changes you wish to you must save the image for them to be permanent. <br /></div>
 990                        <div style="margin-top: 3px; margin-right: 20px;float:right;width: 330px;text-align: right;">' . FormWidget::button('resetImage', 'Reset to Original', 'this.form.' . $this->paramName('imgAction') . '.value = \'reset\'; this.form.submit();')
 991                         . '&nbsp;&nbsp;' . ($this->httpVars['imgAction'] == 'undo' ? '' : FormWidget::button('undoImage', 'Undo Last', 'this.form.' . $this->paramName('imgAction') . '.value = \'undo\'; this.form.submit();'))
 992                         . '&nbsp;&nbsp;' . FormWidget::button('previewImage', 'Preview Image', 'this.form.' . $this->paramName('imgAction') . '.value = \'preview\'; this.form.submit();') . '</div>
 993                        </div>';
 994               $text .= '<div style="clear: both;">&nbsp;</div></div>'; 
 995               
 996               $tpl->setVar('bottomOpts', $text);
 997               }
 998           else
 999               $tpl->setVar('bottomOpts', '');
1000          
1001          if (T_SINGLE_BLOCK)
1002              return '<div style="padding:7px;">' . $tpl->subst('main') . '</div><div style="clear: both;font-size: 1px;">&nbsp;</div>';
1003          else
1004              return $tpl->subst('main').'<div style="clear: both;font-size: 1px;">&nbsp;</div>';
1005          }
1006  
1007      function saveThumb()
1008          {
1009          $file = oFile::load($this->ldap, $this->httpVars['thumbclick']);
1010          if(isset($this->httpVars['fileDN']) && $this->httpVars['fileDN'] != '')
1011              $this->settingsVars['fileDN'] = $this->httpVars['fileDN'];
1012          
1013          if($this->ldap->dnExists(DN::dnToThumbDn($this->settingsVars['fileDN'])))
1014              {
1015              $tfile = oFile::load($this->ldap, DN::dnToThumbDn($this->settingsVars['fileDN']));
1016              $tfile->delete(true);
1017              unset($tfile);
1018              }
1019          
1020          $file->move(DN::dnToThumbDn($this->settingsVars['fileDN']));
1021          
1022          return "This window should automatically close.<script type=\"text/javascript\">window.onload=function() {self.close();}</script>";
1023          }
1024  
1025          
1026      function thumbsPopup()
1027          {
1028          print "......";
1029          if($this->httpVars['tmpName'] !== '')
1030              {
1031              $file = oFile::load($this->ldap, $this->httpVars['tmpName']);
1032              $dn = $this->httpVars['tmpName'];
1033              }
1034          else
1035              {
1036              if(isset($this->httpVars['fileDN']) && $this->httpVars['fileDN'] != '')
1037                  $this->settingsVars['fileDN'] = $this->httpVars['fileDN'];        
1038              $file = oFile::load($this->ldap, $this->settingsVars['fileDN']);
1039              $dn = $this->settingsVars['fileDN'];
1040              }
1041  
1042          if(isset($this->httpVars['thumbsize']))
1043              $tsize = $this->httpVars['thumbsize'];
1044          else
1045              $tsize = 80;
1046               
1047          $file->getThumbnail($tsize);
1048          $thumb = oFile::load($this->ldap, DN::dnToThumbDn($dn));
1049          print "......";
1050          $fileMime = $file->file->getMimeType();
1051          $fullpath = DN::dnToFullPath($dn);
1052          switch ($fileMime) {
1053               case "image/gif":
1054                    $img       =  imageCreateFromGIF($fullpath);
1055                    $ext = "gif";
1056               break;
1057               case "image/jpeg":
1058               case "image/jpg":
1059                    $img       =  imageCreateFromJPEG($fullpath);
1060                    $ext = "jpg";
1061                    break;
1062               case "image/png":
1063                    $img       =  imageCreateFromPNG($fullpath);
1064                    $ext = "png";
1065                    break;
1066               }
1067          $halfx = round(imagesx($img)/2) - 1;
1068          $halfy = round(imagesy($img)/2) - 1;
1069  
1070          $minimg1 = Editor::imageThumbnail(Editor::imageCrop($img, $halfx, $halfy, 0, 0), $tsize);
1071          $minimg2 = Editor::imageThumbnail(Editor::imageCrop($img, $halfx, $halfy, $halfx, 0), $tsize);
1072          $minimg3 = Editor::imageThumbnail(Editor::imageCrop($img, $halfx, $halfy, 0, $halfy), $tsize);
1073          $minimg4 = Editor::imageThumbnail(Editor::imageCrop($img, $halfx, $halfy, $halfx, $halfy), $tsize);  
1074          $minimgmain = Editor::imageThumbnail($img, $tsize);      
1075          
1076          
1077          $tmpdn1  = DN::tmpDN(DN::dnToThumbDn(DN::dnToBase($dn)), $ext);  
1078          $tmpdn2 = DN::tmpDN(DN::dnToThumbDn(DN::dnToBase($dn)), $ext);
1079          $tmpdn3 = DN::tmpDN(DN::dnToThumbDn(DN::dnToBase($dn)), $ext);
1080          $tmpdn4 = DN::tmpDN(DN::dnToThumbDn(DN::dnToBase($dn)), $ext);  
1081          $tmpdnmain = DN::tmpDN(DN::dnToThumbDn(DN::dnToBase($dn)), $ext);
1082          
1083          $thumb->copy($tmpdn1);
1084          $thumb->copy($tmpdn2);
1085          $thumb->copy($tmpdn3);
1086          $thumb->copy($tmpdn4);   
1087          $thumb->copy($tmpdnmain);
1088  
1089          switch ($fileMime) {
1090              case "image/gif":
1091                  imageGIF($minimg1, DN::dnToFullPath($tmpdn1));
1092                  imageGIF($minimg2, DN::dnToFullPath($tmpdn2));
1093                  imageGIF($minimg3, DN::dnToFullPath($tmpdn3));
1094                  imageGIF($minimg4, DN::dnToFullPath($tmpdn4));
1095                  imageGIF($minimgmain, DN::dnToFullPath($tmpdnmain));
1096                  break;
1097              case "image/jpeg":
1098              case "image/jpg":
1099                  imageJPEG($minimg1, DN::dnToFullPath($tmpdn1), 95);
1100                  imageJPEG($minimg2, DN::dnToFullPath($tmpdn2), 95);
1101                  imageJPEG($minimg3, DN::dnToFullPath($tmpdn3), 95);
1102                  imageJPEG($minimg4, DN::dnToFullPath($tmpdn4), 95);
1103                  imageJPEG($minimgmain, DN::dnToFullPath($tmpdnmain), 95);
1104                  break;
1105              case "image/png":
1106                  imagePNG($minimg1, DN::dnToFullPath($tmpdn1));
1107                  imagePNG($minimg2, DN::dnToFullPath($tmpdn2));
1108                  imagePNG($minimg3, DN::dnToFullPath($tmpdn3));
1109                  imagePNG($minimg4, DN::dnToFullPath($tmpdn4));
1110                  imagePNG($minimgmain, DN::dnToFullPath($tmpdnmain));
1111                  break;
1112              }
1113   
1114          $thumb1 = oFile::load($this->ldap, $tmpdn1);
1115          $thumb2 = oFile::load($this->ldap, $tmpdn2);
1116          $thumb3 = oFile::load($this->ldap, $tmpdn3);
1117          $thumb4 = oFile::load($this->ldap, $tmpdn4);
1118          $thumbmain = oFile::load($this->ldap, $tmpdnmain);
1119          
1120          $width = $tsize . "px";
1121          $contwidth = $tsize + 20 . "px";
1122          $marginwidth = 60 + round($tsize / 2) . "px";
1123          $flwidth = (110 + (2 * $tsize)) . "px";
1124  
1125          $mainthumbhtml  =  "<div style='background-color: #f1f1f1; border: solid 1px #ddd; color: #333; font-size: 10px; width: 365px; height: 485px; text-align: center;'>
1126                              <div style='height: 430px; width: $flwidth;border: solid 1px #ddd; margin: auto;'>";
1127          $mainthumbhtml .=  "<div style='cursor: pointer;border: solid 1px #ddd;width: $width;margin-left: $marginwidth;' onclick='document.getElementById(\"" . $this->paramName('thumbclick') . "\").value = \"" . $tmpdnmain . "\"; document.thumbmain.submit();'>
1128                             " . $thumbmain->getPreview($this) . "</div>";
1129          $mainthumbhtml .=  "<div style='margin-left: 50px; margin-top: 10px; float: left; width: $contwidth;'>
1130                              <div style='cursor: pointer;border: solid 1px #ddd;width: $width;' onclick='document.getElementById(\"" . $this->paramName('thumbclick') . "\").value = \"" . $tmpdn1 . "\"; document.thumbmain.submit();'>
1131                             " . $thumb1->getPreview($this) . "</div></div>";
1132          $mainthumbhtml .=  "<div style='float: left; width: 100px;margin-top: 10px;'>
1133                              <div style='cursor: pointer;border: solid 1px #ddd;width: $width;' onclick='document.getElementById(\"" . $this->paramName('thumbclick') . "\").value = \"" . $tmpdn2 . "\"; document.thumbmain.submit();'>
1134                             " . $thumb2->getPreview($this) . "</div></div>";
1135          $mainthumbhtml .=  "<div style='margin-left: 50px; margin-top: 10px; float: left; width: $contwidth;clear: both;'>
1136                              <div style='cursor: pointer;border: solid 1px #ddd;width: $width;' onclick='document.getElementById(\"" . $this->paramName('thumbclick') . "\").value = \"" . $tmpdn3 . "\"; document.thumbmain.submit();'>
1137                             " . $thumb3->getPreview($this) . "</div></div>";
1138          $mainthumbhtml .=  "<div style='float: left; width: 100px;margin-top: 10px;'>
1139                              <div style='cursor: pointer;border: solid 1px #ddd;width: $width;' onclick='document.getElementById(\"" . $this->paramName('thumbclick') . "\").value = \"" . $tmpdn4 . "\"; document.thumbmain.submit();'>
1140                             " . $thumb4->getPreview($this) . "</div></div>";
1141          $mainthumbhtml .=  "</div><div style='clear: both;'>Please click on one of these options to make it this pictures thumbnail.<br /> Or change the size: " . FormWidget::dropdown('thumbsize', array('80' => '80', '90' => '90', '100' => '100', '110' => '110', '120' => '120'), '', $tsize, array('onchange' => 'this.form.submit();'))  . "</div></div>";
1142  
1143          $tmpName = $this->httpVars['tmpName'];
1144          $filedn = $this->settingsVars['fileDN'];
1145          if(strpos($this->blockID, "tmp") !== false)
1146              $thumbslink = Utility::link($this->section->pathArray, array()) . '&amp;block__tmpEditor__tmpName=' . urlencode($tmpName) . '&amp;block__tmpEditor__edit=1&amp;block__tmpEditor__mode=thumbs&amp;block__tmpEditor__fileDN=' . urlencode($filedn) . '&amp;_single=tmpEditor';        
1147          else    
1148              $thumbslink = Utility::link($this->section->pathArray, array($this->paramName('tmpName') => $tmpName, $this->paramName('edit') => 1, $this->paramName('mode') => 'thumbs'))  . '&amp;_single='. $this->blockID;
1149  
1150          $z = FormWidget::init('', 'form.nonsettings.tpl.html');
1151          $z->name('thumbmain');
1152          $z->action = $thumbslink;
1153          $z->hidden('thumbclick', '', array('id' => $this->paramName('thumbclick')));
1154          $z->html($mainthumbhtml);
1155  
1156          return $z->get();
1157          }    
1158          
1159          
1160      function savePopup($filedn)
1161          {
1162          $folder = DN::dnToBase($filedn);
1163          $suggested_name = Editor::_get_suggested_filename($filedn, $_GET['suggested']);
1164          $previewParams = array('admin[block;' . $this->blockID . ']' => 'preview', 'fileDN' => $this->httpVars['fileDN']);
1165          $link = Utility::link($this->sectionPathArray, $previewParams);
1166  
1167          //create the form
1168          $f = FormWidget::init();
1169   
1170          $f->html("<div style='margin-bottom: 5px;font-size: 14px;color: #333;'>Please choose the folder you would like to save this file in as well as a name.<br /></div>");
1171  
1172          if(strpos($folder, C_LDAP_CARAVEL_PUBLIC_FOLDER) != false)
1173              $f->folderList('folderDN', $folder, '', array('style' => 'width:47%;'), C_LDAP_CARAVEL_PUBLIC_FOLDER);
1174          else
1175              $f->folderList('folderDN', $folder, '', array('style' => 'width:47%;'));    
1176  
1177          $f->text('filename', $suggested_name, null, array('style' => 'width:38%;'));
1178          
1179          if($this->httpVars['tmpName'] != '')
1180              $f->html("<span style='font-size: 14px;color: #333;font-weight: bold;'>." . DN::dnToExtension($this->httpVars['tmpName'], false) . "</span>");
1181          else
1182              $f->html("<span style='font-size: 14px;color: #333;font-weight: bold;'>." . DN::dnToExtension($filedn, false) . "</span>");    
1183          
1184          $f->html("<div style='float: right;margin-top: 20px;'>");
1185          if($this->mode == 'CB')
1186              $f->button('savepv', 'Save & Preview', "if(this.form." . $this->paramName('filename') . ".value == '') { alert('The file name can not be blank.'); return false; } self.opener.document.main." . $this->httpVars['parentPrefix'] . "folderDN.value = this.form." . $this->paramName('folderDN') . ".value; self.opener.document.main." . $this->httpVars['parentPrefix'] . "filename.value = this.form." . $this->paramName('filename') . ".value; self.opener.document.main." . $this->httpVars['parentPrefix'] . "cv_submit.value = 'Save &amp; Preview'; self.opener.document.main.action='$link'; self.opener.document.main.submit();self.close();");
1187          else
1188              $f->button('savecls', 'Save & Edit', "if(this.form." . $this->paramName('filename') . ".value == '') { alert('The file name can not be blank.'); return false; } self.opener.document.main." . $this->httpVars['parentPrefix'] . "folderDN.value = this.form." . $this->paramName('folderDN') . ".value; self.opener.document.main." . $this->httpVars['parentPrefix'] . "filename.value = this.form." . $this->paramName('filename') . ".value; self.opener.document.main." . $this->httpVars['parentPrefix'] . "cv_submit.value = '" . 'Save & Edit' . "'; self.opener.document.main.submit();self.close();");
1189          
1190          $f->button('saveed', $this->mode == 'CB' ? 'Save & Edit' : 'Save & Close', "if(this.form." . $this->paramName('filename') . ".value == '') { alert('The file name can not be blank.'); return false; } self.opener.document.main." . $this->httpVars['parentPrefix'] . "folderDN.value = this.form." . $this->paramName('folderDN') . ".value; self.opener.document.main." . $this->httpVars['parentPrefix'] . "filename.value = this.form." . $this->paramName('filename') . ".value; self.opener.document.main." . $this->httpVars['parentPrefix'] . "cv_submit.value = '" . ($this->mode == 'CB' ? 'Save & Edit' : 'Save & Close') . "'; self.opener.document.main.submit();self.close();");
1191          
1192          $f->html("</div>");
1193          return $f->get();
1194          }
1195          
1196  	function _get_suggested_filename($cur_filedn, $contents) {
1197          $folder = DN::dnToBase($cur_filedn);
1198          $name = DN::dnToName($cur_filedn);
1199          $name = explode('.', $name);
1200          array_pop($name);
1201          
1202          if (ereg('tmp.', DN::dnToName($cur_filedn)))
1203              {
1204              $suggested = preg_replace(array('/<[^>]*>/', '/[^0-9a-zA-Z\040]/'), array('', ''), $contents);
1205  
1206              $pieces = explode(" ", $suggested);
1207              $pos = 0;
1208              foreach($pieces as $pnum => $pval)
1209                  {
1210                  $length += strlen($pval);
1211                  if($length < 26)
1212                      $pos = $pnum;
1213                  }
1214              if($pos == 0)
1215                  $pos = 1;
1216              array_splice($pieces, $pos);
1217  
1218              $suggested_name = array(implode(" ", $pieces));
1219  
1220              // we now need to make sure this name is not taken and if it is add onto it till it is not
1221              $num = 1;
1222              $suggested_dn = 'mnF=' . $suggested_name[0] . '.html,' . $folder;
1223              $orignewfiledn = $suggested_dn;
1224              while(($this->ldap->dnExists($suggested_dn) || ((strpos(DN::dnToName($suggested_dn), DN::dnToName($orignewfiledn)) !== false) && $num != 1)) && $num < 25)
1225                  {
1226                  $suggested_dn = $orignewfiledn;
1227                  $tmpnme = substr(DN::dnToName($suggested_dn), 0, strpos(DN::dnToName($suggested_dn), "."));
1228                  $tmpext = substr(DN::dnToName($suggested_dn), strpos(DN::dnToName($suggested_dn), "."));
1229                  $tmpnme .= $num;
1230                  $suggested_dn = "mnF=" . $tmpnme . $tmpext . "," . DN::dnToParent($suggested_dn);
1231                  $num++;
1232                  }
1233              $suggested_name = array(substr(DN::dnToName($suggested_dn), 0, strpos(DN::dnToName($suggested_dn), ".")));
1234              }
1235          else
1236              $suggested_name = $name;
1237          return implode('.', $suggested_name);
1238      } 
1239  
1240  	function copySite(&$ldap, $srcdn, $destdn, &$cbs, $init = 0, $olddn)
1241          {
1242          mnDebug("Editor::copySite('$srcdn', '$destdn', ". Utility::getVal($cbs) .", $init, '$olddn'): begin...");
1243  
1244          // go through each content block and update either fileDN or folderSettings['files']
1245          foreach ($cbs as $cb)
1246              {
1247              $res = $ldap->search('(objectclass=*)', array('mnappparam', 'mnappparam2'), $cb, LDAP_SCOPE_BASE);
1248              if(mnError::isError($res))
1249                  { return new mnError('Editor::copySite(): ' . $res->getMessage(), __FILE__, __LINE__); }
1250              $param = isset($res[0]['mnappparam']) ? $res[0]['mnappparam'] : array();
1251              array_shift($param);
1252              if (isset($res[0]['mnappparam2']))
1253                  {
1254                  array_shift($res[0]['mnappparam2']);
1255                  $param = array_merge($param, $res[0]['mnappparam2']);
1256                  }
1257              $param = @Utility::processParams($param);
1258              if (isset($param['fileDN']))
1259                  {
1260                  if ($olddn)
1261                      $param['fileDN'] = str_replace($olddn, $destdn, $param['fileDN']);
1262                  else
1263                      $param['fileDN'] = str_replace($srcdn, $destdn, $param['fileDN']);
1264                  if (!$ldap->dnExists($param['fileDN']))
1265                      {
1266                      mnDebug("Editor::copySite(): NOTICE! ". $param['fileDN'] ." doesn't exist.  Content Block ($cb) set to nothing.");
1267                      $param['fileDN'] = '';
1268                      }
1269                  }     
1270              mnDebug("Editor::copySite(): param now : ". Utility::getVal($param));
1271              $attrs = array();
1272              $attrs['mnappparam'] = Utility::packageParams($param);
1273              $res = $ldap->replace($cb, $attrs);
1274              if(mnError::isError($res))
1275                  { return new mnError('Editor::copySite(): ' . $res->getMessage(), __FILE__, __LINE__); }
1276              }
1277          }
1278  
1279      function getBlockInfo($mnAppParam)
1280          {
1281          $tpl = new Template_PHPLIB(T_APP_BASE .'Editor/');
1282          $tpl->setFile(array('main' => 'Editor.blockInfo.tpl.html'));
1283          
1284          $tpl->setBlock('main', 'imageBlock', 'imageB');
1285          $tpl->setVar('imageB','');
1286          $param = Utility::processParams($mnAppParam);
1287          $tpl->setVar('file', DN::dnToName($param['fileDN']));
1288          $expDateNever = isset($param['expDateNever']) ? $param['expDateNever'] : 'NONE';
1289          if ($expDateNever == 'never')
1290              $tpl->setVar('expDate', 'Never');
1291          else
1292              {
1293              $tpl->setVar('expDate', $param['expDate']);
1294              }
1295          
1296          $alttext = isset($param['alttext']) ? $param['alttext'] : '';
1297  
1298          if ($alttext != '')
1299              {
1300              $caption = isset($param['caption']) ? $param['caption'] : '';
1301              $url = isset($param['url']) ? $param['url'] : '';
1302              $just = isset($param['justification']) ? $param['justification'] : '';
1303              $tpl->setVar('caption', $caption);
1304              $tpl->setVar('url', $url);
1305              $tpl->setVar('alttext', $alttext);
1306              $tpl->setVar('just', $just);
1307              $tpl->parse('imageB', 'imageBlock');
1308              }
1309  
1310          return $tpl->subst('main');
1311          } 
1312        
1313      function getKeywords()
1314          {
1315          return Utility::getKeywords($this->settingsVars['fileDN']);  
1316          }
1317          
1318      function export($ldap, $blockdn, $blockattrs, $mode)
1319          {
1320          $mnappparams = Utility::processparams($blockattrs[0]['mnappparam']);
1321  
1322          switch($mode)
1323              {
1324              case 'files':
1325              $ret = array(0 => $mnappparams['fileDN']);
1326              break;
1327              case 'sql':
1328              $ret = "";
1329              break;
1330              }
1331  
1332          return $ret;
1333          }
1334          
1335      // image flip code taken from the comments on imagecopy at php.net
1336      function imageFlip($image, $mode) 
1337          {
1338          $w = imagesx($image);
1339          $h = imagesy($image);
1340          $flipped = imagecreatetruecolor($w, $h);
1341          if ($mode) {
1342                 for ($y = 0; $y < $h; $y++) {
1343                         imagecopy($flipped, $image, 0, $y, 0, $h - $y - 1, $w, 1);
1344                 }
1345          } else {
1346                 for ($x = 0; $x < $w; $x++) {
1347                         imagecopy($flipped, $image, $x, 0, $w - $x - 1, 0, 1, $h);
1348                 }
1349          }
1350          return $flipped;
1351          }        
1352      
1353      function imageChangeType($img, $dn, $fileMime, $oldExt)
1354          {
1355          $fullpath = DN::dnToFullPath($dn);
1356          switch ($fileMime) {
1357              case "image/gif":
1358                  imageGIF($img, $fullpath);
1359                  $newExt = ".gif";
1360                  break;
1361              case "image/jpeg":
1362              case "image/jpg":
1363                  imageJPEG($img, $fullpath, 95);
1364                  $newExt = ".jpg";
1365                  break;
1366              case "image/png":
1367                  imagePNG($img, $fullpath);
1368                  $newExt = ".png";
1369                  break;
1370              }
1371  
1372          $file = oFile::load($this->ldap, $dn);
1373          $newdn = str_replace($oldExt, $newExt, $dn);
1374          $file->move($newdn);
1375          return $newdn;
1376          }
1377  
1378      function imageCrop($img, $width, $height, $xo, $yo)
1379          {
1380          if($xo == "")
1381              $xo = 0;
1382          if($yo == "")
1383              $yo = 0;    
1384          
1385          $owidth = imagesx($img);
1386          $oheight = imagesy($img);
1387          if($width == "" && $height == "")
1388              {
1389              $width = $owidth;
1390              $height = $oheight;
1391              } 
1392              
1393          if($width == "")  
1394             $width = round(($owidth * $height) / $oheight);  
1395          
1396          if($height == "")   
1397             $height = round(($oheight * $width) / $owidth);
1398          
1399          $crop = imagecreatetruecolor($width, $height);
1400          imagecopy ( $crop, $img, 0, 0, $xo, $yo, $width, $height);
1401   
1402          return $crop;
1403          }
1404  
1405      function imageRotateColored($img, $amount, $direction, $color)
1406          {
1407          $amount = $amount % 360;
1408          if($direction == 'clockwise')
1409              $amount = 360 - $amount;
1410  
1411          $color = str_replace('#', '', $color);
1412          if($fileMime == 'image/gif')
1413              $color = '000000';
1414  
1415          $img = imagerotate($img, $amount, hexdec($color));
1416          return $img;
1417          }
1418  
1419      function imageScale($img, $height, $width)
1420          {
1421          $owidth = imagesx($img);
1422          $oheight = imagesy($img);
1423          if($height == "")
1424              {
1425              $h = round(($oheight * $width) / $owidth);
1426              $w = $width;
1427              }
1428          else if($width == "")
1429              {
1430              $h = $height;
1431              $w = round(($owidth * $height) / $oheight);
1432              }
1433          else
1434              {
1435              // they are both set
1436              $h = $height;
1437              $w = $width;
1438              }
1439  
1440          $scale = imagecreatetruecolor($w, $h);
1441          imagecopyresampled($scale, $img, 0, 0, 0, 0, $w, $h, $owidth, $oheight);
1442  
1443          return $scale;
1444          }
1445          
1446      function imageThumbnail($src_img, $size, $enlarge = false)
1447          {
1448          // for now just assume gd2, if it would be useful to someone we can figure out how to make this work with gd1
1449          $gd2 = true;
1450          
1451          $width = $size;
1452          $height = $size;
1453          $width_orig  = imagesx($src_img);
1454          $height_orig = imagesy($src_img);
1455  
1456          if($width_orig < $size && $height_orig < $size && !$enlarge)
1457            return $src_img;              
1458  
1459          if($height && ($height_orig < $width_orig))
1460            $height = ($width / $width_orig) * $height_orig;
1461          else
1462            $width = ($height / $height_orig) * $width_orig;
1463  
1464          // create the image in memory
1465          $dst_img = ImageCreateTrueColor($width, $height);
1466          imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
1467  
1468          return $dst_img;
1469          }    
1470  
1471      } // end class
1472  ?>

title

Description

title

Description

title

Description

title

title

Body