Example #1
0
 public function appendAction()
 {
     $m = $this->getMashup();
     $title = $this->getParamString(ApiController::APPEND_TITLE_PARAM);
     $content = $this->getParamString(ApiController::APPEND_CONTENT_PARAM);
     $datestr = gmdate("Y-m-d\\TH:i:s\\Z");
     $f = new Fragment_text($this->getLA()->getURIForTitle($title, LOOMP::FRAGMENT()), $m->getCreatorId(), $datestr, $datestr, $title, $content, 'text');
     $m->addFragment($f);
     $this->getLA()->saveMashup($m) or $this->sendError("Failed to save Mashup " . $m->getUri());
     $this->getLog()->info("Append action on mashup " . $m->getUri());
     print "success";
 }
Example #2
0
 public function saveAction()
 {
     $userid = $this->getUserId();
     $datestr = gmdate("Y-m-d\\TH:i:s\\Z");
     $this->disableLayout();
     $mashupData = $this->getRequest()->getParam(MashupController::MASHUP_DATA, false);
     $mashupMeta = $this->getRequest()->getParam(MashupController::MASHUP_META, false);
     if (!$mashupData || !$mashupMeta) {
         $this->sendError("Usage: POST me some data in " . MashupController::MASHUP_META . " and " . MashupController::MASHUP_DATA);
     }
     $mashupUri = $mashupMeta['uri'];
     $updateMode = false;
     if (!empty($mashupUri)) {
         // existing mashup
         // load it
         $m = $this->getLA()->loadMashup($mashupUri);
         if ($m == null) {
             $this->sendError("Failed to load mashup " . $mashupUri);
         }
         $m->setTitle($mashupMeta['title']);
         // change title
         $m->setModifyDate($datestr);
         $updateMode = true;
     } else {
         // new mashup
         $m = new Mashup($this->getLA()->getURIForTitle($mashupMeta['title'], LOOMP::MASHUP()), $userid, $datestr, $datestr, $mashupMeta['title'], array());
     }
     // rights check
     if ($updateMode && $m->getCreatorId() != $this->getUserId() && $this->view->user['type'] != "admin") {
         $this->sendError("You have no rights to edit " . $m->getUri());
     }
     $fragments = array();
     // add fragments
     foreach ($mashupData as $fragment) {
         $fragmentUri = @$fragment['uri'];
         if (!empty($fragmentUri)) {
             // existing fragment
             $f = $this->getLA()->loadFragment($fragmentUri);
             if ($f == null) {
                 $this->sendError("Failed to find fragment " . $fragmentUri . " in mashup " . $mashupUri);
             }
             $f->setTitle($fragment['title']);
             $f->setContent($fragment['content']);
             $f->setModifyDate($datestr);
             //2002-05-30T09:30:10Z
         } else {
             // new fragment
             $class = "Fragment_" . $fragment['type'];
             $f = new $class($this->getLA()->getURIForTitle($fragment['title'], LOOMP::FRAGMENT()), $userid, $datestr, $datestr, $fragment['title'], $fragment['content'], $fragment['type']);
         }
         $fragments[$fragment['order']] = $f;
     }
     $deletedFragments = array();
     if ($updateMode) {
         $oldFragments = $m->getFragments();
         foreach ($oldFragments as $fragment) {
             if (!in_array($fragment, $fragments)) {
                 $deletedFragments[] = $fragment;
             }
         }
     }
     $m->setFragments($fragments);
     //print_r($m);
     $this->getLA()->saveMashup($m, $deletedFragments) or $this->sendError("Failed to save Mashup " . $mashupUri);
     foreach ($m->getFragments() as $fragment) {
         searchUpdateFragment($fragment);
     }
     // print preview link for usage in frontend
     if ($updateMode) {
         $this->getLog()->info("Mashup " . $m->getUri() . " updated");
     } else {
         $this->getLog()->info("Mashup " . $m->getUri() . " created");
     }
     print $m->getUri();
 }
Example #3
0
 /**
  * Currently, this method simply overwrites an existing fragment !!!
  * WARNING: this influences all mashups having integrated this fragment
  * Possible solution: create a new copy of the fragment, however fragment URIs are currently provided by the loomp client
  * therefore some modification in the loomp architecture are required
  *
  * @param  Fragment    $fragment          Fragment Object
  */
 private function _saveFragment($fragment)
 {
     $this->_removeFragment($fragment);
     $fragmentRes = new Resource($fragment->getUri());
     $this->rdfModel->add(new Statement($fragmentRes, RDF::TYPE(), LOOMP::FRAGMENT()));
     $this->rdfModel->add(new Statement($fragmentRes, DC::CREATOR(), new Resource($fragment->getCreatorId())));
     $this->rdfModel->add(new Statement($fragmentRes, DC::TITLE(), new Literal($fragment->getTitle())));
     $this->rdfModel->add(new Statement($fragmentRes, DC::CREATED(), new Literal($fragment->getCreateDate())));
     $this->rdfModel->add(new Statement($fragmentRes, DC::MODIFIED(), new Literal($fragment->getModifyDate())));
     $this->rdfModel->add(new Statement($fragmentRes, LOOMP::RDFA(), new Literal($fragment->getSaveContent())));
     $this->rdfModel->add(new Statement($fragmentRes, LOOMP::TYPE(), new Literal($fragment->getType())));
     $this->_saveResFromRDFa($fragmentRes, '<html xmlns="http://www.w3.org/1999/xhtml"><body about="' . $fragment->getURI() . '">' . $fragment->getSaveContent() . '</body></html>');
 }