getSitegroup(); if ($sitegroup) { $this->whereAdd("sitegroup in (0,$sitegroup)"); } } function staticList($k,$v) { $t = new DataObjects_Article; $t->$k = $v; $t->orderBy('created DESC'); $t->find(); return $t; } function staticGetByPath($request) { if (!$request) { return; } //echo "REQUEST: $request"; $topicname = dirname($request); $articlename = rawurldecode(basename($request)); //echo "GET TOPIC $topicname"; //echo "GET ARTICLE $articlename"; if ($topic = DataObjects_Topic::staticGetByPath($topicname)) { $article = DataObjects_Article::staticGetTopicArticle($topic->id,'name',$articlename); } return $article; } function staticGetTopicArticle($up,$key,$val) { $article = new DataObjects_Article; $article->topic = $up; $article->get($key,$val); if (!$article->N) { return; } return $article; } function buildIconBlob() { //return; //echo " {$this->view} "; $this->iconBlob = ""; if ($this->view) { $this->iconBlob = DataObjects_Blobs::staticGet( $this->view); //echo "{$this->iconBlob->name} "; $this->iconBlob->getUrl(); $this->iconBlob->hspace = (int) ((100- $this->iconBlob->sizex) /2) + 5; return; } //echo "LOOKING FOR IMG"; $atts = $this->listattachments(); //echo "GOT?";print_r($atts); if (!$atts) { return; } while ($atts->fetch()) { //echo "tESTING {$atts->name}
"; if (!preg_match("/00x100\.([a-z]+)$/i",$atts->name)) continue; //echo "returning /attachment/{$sg_guid}{$guid}/.".urlencode($atts->name); $atts->getUrl(); $atts->hspace = (int) ((100- $atts->sizex) /2) + 5; $this->iconBlob = $atts; $t = DataObjects_Article::staticGet($this->id); $t->view = $atts->id; $t->update(); //echo "
";print_r($atts);echo "
"; return; } } function listattachments() { return DataObjects_Blobs::staticList(get_class($this),$this->id); } function getSortedAttachments() { return DataObjects_Blobs::staticGetSortedAttachments(get_class($this),$this->id); } function getAttachment($k,$v=NULL) { $t = new DataObjects_Blobs; $t->ptable = substr(get_class($this),strlen('dataobjects_')); $t->pid = $this->id; $t->get($k,$v); if (!$t->N) { return; } return $t; } function createAttachment(&$attachment, $data,$size) { $attachment->ptable = substr(get_class($this),strlen('dataobjects_')); $attachment->pid = $this->id; $attachment->insert(); $attachment->updateData($data,$size); } function findChildren($id) { $this->topic = $id; $this->find(); } function getParent() { return DataObjects_Topic::staticGet($this->topic); } /* can methods - can delete can create etc. */ function canEdit() { $parent = $this->getParent(); if (!$parent) { echo "
"; print_r($this);
        }
        return $parent->canEdit();
    }
    function canCreate() {
        return $this->canEdit();
    }
    function canDelete() {
        return $this->canEdit();
    }
    /* overrides */
    function insert() {
        //$this->_setSitegroup(); not at present!
        $this->_setAuthor();
        $this->_setCreated();
        $this->_setRevised();
        if (!$this->title) {
            $this->title = $this->name;
        }
        return parent::insert();
    }
    function update() {
        $this->_setAuthor();
        $this->_setRevised();
        return parent::update();
    }
    
    /* set author */
    function _setAuthor() {
        //$auth = PEAR::getStaticProperty('Auth','singleton');
        //$this->author = $auth->getUserId();
    }
    /* set created/creator */
    function _setCreated() {
        //$auth = PEAR::getStaticProperty('Auth','singleton');
        //$this->creator = $auth->getUserId();
        $date = new Date(time());
        $this->created = $date->format('%Y-%m-%d %H:%M:%S');
    }
    /* set revised/revisor */
    function _setRevised() {
        //$auth = PEAR::getStaticProperty('Auth','singleton');
        //$this->revisor = $auth->getUserId();
        $date = new Date(time());
        $this->revised = $date->format('%Y-%m-%d %H:%M:%S');
        $this->revision++; 
    }
 
   
   
    function getLinkUrl() {
        $parent = $this->getParent();
        $base = $parent->getLinkUrl('');
        return $base . '/'.$this->name;
    }
    
    
    function getContent() {
        echo "LINK URL = ". $this->getLinkUrl();
        return $this->content;
    
    
    }
    
    
    
     
    function dumptoFs($dir) {
        
        $thisname = "{$dir}/{$this->name}";
        //print_r($this);
        $title = $this->title;
        if (!strlen($this->title)) $title = $this->name;
        $out = "".htmlspecialchars($title)."";
        
        
        $out .= $this->abstract . "
"; if (strlen(trim($this->content))) { $out .= "\n\n\n
__BODY__
\n\n" . $this->content; } $out .= ''; $this->file_write_contents("{$thisname}.html",$out); $blobs = $this->listAttachments(); if (!$blobs) { return; } while ($blobs->fetch()) { $blobs->dumptoFs($thisname); } } function file_write_contents($file,$cont) { //echo 'mkdir -p '. escapeshellarg(dirname($file)); if (file_exists($file)) { return; } mkdir(dirname($file)); $fh = fopen($file, 'w'); fwrite($fh,$cont); fclose($fh); } function listTopic($id) { $ret = new DataObjects_Article; $ret->topic = $id; $ret->find(); return $ret; } } ?>