Пример #1
0
 /**
  * The class is loaded either with an id (from the spine table) or the path to the file
  * In the first case, when it is beeing loaded from the Controller, $parent actually contains the alias
  * of the file itself.
  * The function cascades the __construct call to it's parent
  * @param mixed $fullpath Contains id or path
  * @param mixed $parent Contains (possibly) parent folder
  * @return void
  */
 function __construct($fullpath = false, $parent = false)
 {
     global $DB, $Controller, $CONFIG;
     $id = false;
     if (is_numeric($fullpath)) {
         $id = $fullpath;
     } else {
         if ($parent === false) {
             if ($fullpath === $this->rootDir()) {
                 $id = $Controller->fileRoot(OVERRIDE)->ID;
             } elseif (substr($fullpath, 0, strlen($this->rootDir())) == $this->rootDir()) {
                 $parent = Folder::open(dirname($fullpath));
             } else {
                 return false;
             }
             $this->_path = $fullpath;
         }
         if (!$id) {
             if (!($id = $DB->files->getCell(array('parent' => $parent === 0 ? 0 : $parent->ID, 'name' => pathinfo($fullpath, PATHINFO_BASENAME)), 'id'))) {
                 $id = $DB->spine->insert(array('class' => $this->Type));
                 $DB->files->insert(array('parent' => $parent === 0 ? 0 : $parent->ID, 'name' => pathinfo($fullpath, PATHINFO_BASENAME), 'id' => $id));
             }
         }
     }
     parent::__construct($id);
     if ($this->isImage()) {
         $this->editable['ImageEditor'] = EDIT;
     }
     Short::registerFilter(array(__CLASS__, 'contentFilter'));
 }