예제 #1
0
 function setAction($action)
 {
     if (Annotation::isActionValid($action)) {
         $this->action = $action;
     }
 }
예제 #2
0
 /**
  * Set annotation fields based on parameters (e.g. from $_POST)
  * For updates, first retrieve the stored annotation, then update it here.
  * If this fails, the passed annotation object may have already been altered.
  * Different implementations may have different annotation objects.  All should
  * be compatible with this code if they have the appropriate getters and setters.
  */
 function annotationFromParams(&$annotation, &$params)
 {
     // ID
     // must be setAnnotationId, not setId, because of a conflict with a base class method in OJS
     if (array_key_exists('id', $params)) {
         $id = $params['id'];
         $annotation->setAnnotationId($id);
     }
     // UserId
     if (array_key_exists('userid', $params)) {
         $userid = $params['userid'];
         $annotation->setUserId($userid);
     }
     // UserName
     if (array_key_exists('username', $params)) {
         $userName = $params['username'];
         $annotation->setUserName($userName);
     }
     // Sequence Range
     if (array_key_exists('sequence-range', $params)) {
         $sequenceRange = new SequenceRange();
         $sequenceRange->fromString($params['sequence-range']);
         $annotation->setSequenceRange($sequenceRange);
     }
     // XPath Range
     if (array_key_exists('xpath-range', $params)) {
         $xpathRange = new XPathRange();
         $xpathRange->fromString($params['xpath-range']);
         if (!XPathPoint::isXPathSafe($xpathRange->start->getPathStr()) || !XPathPoint::isXPathSafe($xpathRange->end->getPathStr())) {
             return XPATH_SECURITY_ERROR;
         }
         $annotation->setXPathRange($xpathRange);
     }
     // URL
     if (array_key_exists('url', $params)) {
         $url = $params['url'];
         if (!$url || !MarginaliaHelper::isUrlSafe($url)) {
             return URL_SCHEME_ERROR;
         }
         $annotation->setUrl($url);
     }
     // Note
     if (array_key_exists('note', $params)) {
         $note = $params['note'];
         $annotation->setNote($note);
     }
     // Quote
     if (array_key_exists('quote', $params)) {
         $quote = $params['quote'];
         $annotation->setQuote($quote);
     }
     // QuoteTitle
     if (array_key_exists('quote_title', $params)) {
         $quoteTitle = $params['quote_title'];
         $annotation->setQuoteTitle($quoteTitle);
     }
     // QuoteAuthorId
     if (array_key_exists('quote_author_id', $params)) {
         $quoteAuthorId = $params['quote_author_id'];
         $annotation->setQuoteAuthorId($quoteAuthorId);
     }
     // QuoteAuthorName
     if (array_key_exists('quote_author_name', $params)) {
         $quoteAuthorName = $params['quote_author_name'];
         $annotation->setQuoteAuthorName($quoteAuthorName);
     }
     // Access
     if (array_key_exists('access', $params)) {
         $access = $params['access'];
         if (!Annotation::isAccessValid($access)) {
             return ACCESS_VALUE_ERROR;
         }
         $annotation->setAccess($access);
     }
     // Action
     if (array_key_exists('action', $params)) {
         $action = $params['action'];
         if (!Annotation::isActionValid($action)) {
             return ACTION_VALUE_ERROR;
         }
         $annotation->setAction($action);
     }
     // Link
     if (array_key_exists('link', $params)) {
         $link = $params['link'];
         if ($link && !MarginaliaHelper::isUrlSafe($link)) {
             return URL_SCHEME_ERROR;
         }
         $annotation->setLink($link);
     }
     // Link Title
     if (array_key_exists('link_title', $params)) {
         $title = $params['link_title'];
         $annotation->setLinkTitle($title);
     }
     // Created
     if (array_key_exists('created', $params)) {
         $created = $params['created'];
         // TODO: verify date format
         $this->setCreated($created);
     }
     // Modified
     if (array_key_exists('modified', $params)) {
         $modified = $params['modified'];
         $this->setModified($modified);
     }
     // Version
     if (array_key_exists('version', $params)) {
         $version = $params['version'];
         $this->setVersion($version);
     }
     // Ok, I know in PHP it's traditional to return True for success,
     // but that requires the triple === which drives me nuts and is
     // easy to forget (and if ( f() ) won't work), so I'll go with the
     // old C / Unix tradition and return 0.
     return 0;
 }
예제 #3
0
 function setAction($action)
 {
     if (Annotation::isActionValid($action)) {
         $this->setData('action', $action);
     }
 }