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 registerprocessAction()
 {
     $request = $this->getRequest();
     // Check if we have a POST request
     if (!$request->isPost()) {
         return $this->_helper->redirector('register');
     }
     // Get our form and validate it
     $form = $this->getRegisterForm();
     if (!$form->isValid($request->getPost())) {
         // Invalid entries
         $this->view->form = $form;
         $this->getLog()->warn("Registration attempt failed");
         return $this->render('register');
         // re-render the login form
     }
     $values = $form->getValues();
     // generate user uri
     $fullname = $values['firstname'] . " " . $values['lastname'];
     $uri = $this->getLA()->getUriForTitle($fullname, LOOMP::User());
     $activationkey = md5(microtime() . $uri);
     // create user account in db
     $user = new Model_User();
     $user->setEmail($values['mail'])->setPassword($values['password'])->setActivation($activationkey)->setActive(false)->setUserlevel(Model_User::USER_LEVEL_USER)->setUri($uri)->setFirstname($values['firstname'])->setLastname($values['lastname'])->setOrganisation($values['organisation']);
     if (!$user->save()) {
         $this->getLog()->err("Registration for {$user} failed - " . $user->ErrorMsg());
         return $this->render('register');
     }
     $this->getLog()->info("Registration for {$user} succeeded");
     $server_config = Zend_Registry::getInstance()->configuration->server;
     $activation_link = LOOMP_BASE_PATH . $this->view->url(array('controller' => 'login', 'action' => 'activate'), 'default', true) . "?key=" . $activationkey;
     // send e-mail to user
     $mail = new Zend_Mail('UTF-8');
     $mail->setBodyHTML("Welcome to LOOMP!\n <a href='{$activation_link}'>Activate your account by clicking here</a>.");
     $mail->setFrom('loomp@' . $server_config->host, 'LOOMP Registration');
     $mail->addTo($user->getEmail(), $user->getFullname());
     $mail->setSubject("Account Activation for " . $user->getFullname());
     $mail->send();
     $this->getLog()->info("Registration mail sent to " . $user->getEmail());
     // display thanks page
     $this->view->mail = $user->getEmail();
     // do nothing, thank you page will be rendered
 }
Example #3
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 #4
0
 private function _getAnnotations(&$m, $lang)
 {
     $ann = array();
     $it = $m->findAsIterator(NULL, RDF::TYPE(), LOOMP::ANNOTATION());
     while ($it->hasNext()) {
         $s = $it->next()->getSubject();
         $uri = $this->_getPropValue($m, $s, LOOMP::REFERS_TO());
         $label = $this->_getLiteralInLang($m->find($s, RDFS::LABEL(), NULL), $lang);
         $description = $this->_getLiteralInLang($m->find($s, RDFS::COMMENT(), NULL), $lang);
         $type = $this->_getPropValue($m, $s, LOOMP::ANNOTATION_TYPE());
         $annDomain = $this->_getPropValue($m, $s, LOOMP::ANNOTATION_DOMAIN());
         if ($annDomain == '') {
             $annDomain = RDF::RESOURCE()->getURI();
         }
         $annRange = $this->_getPropValue($m, $s, LOOMP::ANNOTATION_RANGE());
         $ann[] = new Annotation($uri, $label, $description, $type, $annDomain, $annRange);
     }
     return $ann;
 }