Revision: 538
Author: geof.glass
Date: Wed May 30 14:55:33 2012
Log: Update to match Marginalia M 2.0 beta 3 for Moodle 2.0
http://code.google.com/p/marginalia/source/detail?r=538
Modified:
/marginalia-php/trunk/marginalia-php/Annotation.php
/marginalia-php/trunk/marginalia-php/AnnotationService.php
/marginalia-php/trunk/marginalia-php/MarginaliaHelper.php
/marginalia-php/trunk/marginalia-php/XPathRange.php
/marginalia-php/trunk/marginalia-php/embed.php
=======================================
--- /marginalia-php/trunk/marginalia-php/Annotation.php Wed May 30 14:11:15
2012
+++ /marginalia-php/trunk/marginalia-php/Annotation.php Wed May 30 14:55:33
2012
@@ -49,7 +49,7 @@
$this->sequenceRange = null;
$this->xpathRange = null;
$this->note = null;
- $this->access = null;
+ $this->sheet = null;
$this->action = null;
$this->quote = null;
$this->quoteTitle = null;
@@ -60,6 +60,7 @@
$this->created = null;
$this->modified = null;
$this->version = 1;
+ $this->lastRead = null;
}
/** This method is intended to be called when an annotation is created via
@@ -127,14 +128,14 @@
function getAction( )
{ return $this->action; }
- function setAccess( $access )
- {
- if ( $this->isAccessValid( $access ) )
- $this->access = $access;
+ function setSheet( $sheet )
+ {
+ if ( $this->isSheetValid( $sheet ) )
+ $this->sheet = $sheet;
}
- function getAccess( )
- { return $this->access; }
+ function getSheet( )
+ { return $this->sheet; }
function setQuote( $quote )
{ $this->quote = $quote; }
@@ -192,6 +193,12 @@
function getVersion( )
{ return (int) $this->version; }
+
+ function setLastRead( $lastread )
+ { $this->lastRead = is_string( $lastread ) ? strtotime( $lastread ) :
$lastread; }
+
+ function getLastRead( )
+ { return $this->lastRead; }
/**
* Convert to an Atom entry
@@ -207,10 +214,10 @@
return null === $action || '' === $action || 'edit' == $action;
}
- /** Check whether an access value is valid (overrideable) */
- function isAccessValid( $access )
- {
- return ! $access || 'public' == $access || 'private' == $access;
+ /** Check whether a sheet value is valid (overrideable) */
+ function isSheetValid( $sheet )
+ {
+ return ! $sheet || 'public' == $sheet || 'private' == $sheet;
}
}
=======================================
--- /marginalia-php/trunk/marginalia-php/AnnotationService.php Wed May 30
14:11:15 2012
+++ /marginalia-php/trunk/marginalia-php/AnnotationService.php Wed May 30
14:55:33 2012
@@ -9,7 +9,7 @@
* Canada, the UNDESA Africa i-Parliaments Action Plan, and
* units and individuals within those organizations. Many
* thanks to all of them. See CREDITS.html for details.
- * Copyright (C) 2005-2007 Geoffrey Glass; the United Nations
+ * Copyright (C) 2005-2011 Geoffrey Glass; the United Nations
*
http://www.geof.net/code/annotation
*
* This program is free software; you can redistribute it and/or
@@ -71,7 +71,7 @@
// default for optional arguments
$this->baseUrl = null;
$this->niceUrls = False;
- $this->csrfCookie = null;
+ $this->csrfParam = null;
$this->csrfCookieValue = null;
$this->noPutDelete = False;
@@ -111,11 +111,11 @@
$this->noPutDelete = $value;
break;
- // The name of the session cookie and its value
+ // The name of the parameter containing the session cookie and its
expected value
// Used to prevent cross-site request forgeries
- // Client must also configure csrfCookie (but definitely *not*
csrfCookieValue)
- case 'csrfCookie':
- $this->csrfCookie = $value;
+ // Client must configure csrfCookie (but definitely *not*
csrfCookieValue)
+ case 'csrfParam':
+ $this->csrfParam = $value;
break;
case 'csrfCookieValue':
$this->csrfCookieValue = $value;
@@ -153,9 +153,14 @@
// Used to prevent cross-site request forgery
function verifySession( $params )
{
- return ! $this->csrfCookie ||
- ( array_key_exists( $this->csrfCookie, $params )
- && $this->csrfCookieValue == $params[ $this->csrfCookie ] );
+ $success = ! $this->csrfParam ||
+ ( array_key_exists( $this->csrfParam, $params )
+ && $this->csrfCookieValue == $params[ $this->csrfParam ] );
+/* if ( ! $success )
+ echo 'submit csrf: '.$params[$this->csrfParam]
+ .', cookie name: '.$this->csrfParam
+ .", correct csrf: ".$this->csrfCookieValue;
+*/ return $success;
}
function parseAnnotationId( )
@@ -291,16 +296,17 @@
{
$format = $this->getQueryParam( 'format', 'atom' );
$url = $this->getQueryParam( 'url', null );
- $userid = $this->getQueryParam( 'user', null );
+ $sheet = $this->getQueryParam( 'sheet', null );
$block = $this->getQueryParam( 'block', null );
$block = $block ? new SequencePoint( $block ) : null;
$all = $this->getQueryParam( 'all', 'no' ) == 'yes' ? true : false;
+ $mark = $this->getQueryParam( 'mark', null );
/* if ( $url == null || $url == '' )
$this->httpError( 400, 'Bad Request', 'Bad URL' );
else
{
-*/ $annotations = $this->doListAnnotations( $url, $userid, $block, $all
);
+*/ $annotations = $this->doListAnnotations( $url, $sheet, $block, $all,
$mark );
if ( null === $annotations )
$this->httpError( 500, 'Internal Service Error', 'Failed to list
annotations' );
@@ -309,8 +315,8 @@
$feedUrl = '';
if ( $url )
$feedUrl .= ( $feedUrl ? '&' : '?' ) . 'url=' . urlencode($url);
- if ( $userid )
- $feedUrl .= ( $feedUrl ? '&' : '?' ) . 'user=' . urlencode( $userid );
+ if ( $sheet )
+ $feedUrl .= ( $feedUrl ? '&' : '?' ) . 'sheet=' . urlencode( $sheet );
if ( $format )
$feedUrl .= ( $feedUrl ? '&' : '?' ) . 'format=' . urlencode( $format
);
if ( $block )
@@ -333,8 +339,9 @@
function getAnnotation( $id )
{
$format = (int) $this->getQueryParam( 'format', null );
-
- $annotation = $this->doGetAnnotation( $id );
+ $mark = $this->getQueryParam( 'mark', null );
+
+ $annotation = $this->doGetAnnotation( $id, $mark );
if ( null === $annotation )
$this->httpError( 404, 'Not Found Error', 'No such annotation' );
=======================================
--- /marginalia-php/trunk/marginalia-php/MarginaliaHelper.php Wed May 30
14:11:15 2012
+++ /marginalia-php/trunk/marginalia-php/MarginaliaHelper.php Wed May 30
14:55:33 2012
@@ -33,7 +33,7 @@
define( 'NO_ERROR', False );
define( 'XPATH_SECURITY_ERROR', 'xpath-security-error' );
define( 'URL_SCHEME_ERROR', 'url-error' );
-define( 'ACCESS_VALUE_ERROR', 'access-value-error' );
+define( 'SHEET_VALUE_ERROR', 'sheet-value-error' );
define( 'ACTION_VALUE_ERROR', 'action-value-error' );
class MarginaliaHelper
@@ -131,20 +131,20 @@
$annotation->setQuoteAuthorName( $quoteAuthorName );
}
- // Access
- if ( array_key_exists( 'access', $params ) )
- {
- $access = $params[ 'access' ];
- if ( ! Annotation::isAccessValid( $access ) )
- return ACCESS_VALUE_ERROR;
- $annotation->setAccess( $access );
+ // Sheet
+ if ( array_key_exists( 'sheet', $params ) )
+ {
+ $sheet = $params[ 'sheet' ];
+ if ( ! $annotation->isSheetValid( $sheet ) )
+ return SHEET_VALUE_ERROR;
+ $annotation->setSheet( $sheet );
}
// Action
if ( array_key_exists( 'action', $params ) )
{
$action = $params[ 'action' ];
- if ( ! Annotation::isActionValid( $action ) )
+ if ( ! $annotation->isActionValid( $action ) )
return ACTION_VALUE_ERROR;
$annotation->setAction( $action );
}
@@ -201,7 +201,7 @@
$NS_ATOM = '
http://www.w3.org/2005/Atom';
// About the feed ----
- echo "<feed xmlns:ptr='$NS_PTR' xmlns='$NS_ATOM'
ptr:annotation-version='0.7'";
+ echo "<feed xmlns:ptr='$NS_PTR' xmlns='$NS_ATOM'
ptr:annotation-version='0.8'";
if ( $baseUrl )
echo " xml:base='".htmlspecialchars($baseUrl)."'";
echo ">\n";
@@ -254,7 +254,7 @@
$sQuoteTitle = htmlspecialchars( $annotation->getQuoteTitle() );
$sQuoteAuthorId = htmlspecialchars( $annotation->getQuoteAuthorId() );
$sQuoteAuthorName = htmlspecialchars( $annotation->getQuoteAuthorName()
);
- $sAccess = htmlspecialchars( $annotation->getAccess() );
+ $sSheet = htmlspecialchars( $annotation->getSheet() );
$sAction = htmlspecialchars( $annotation->getAction() );
// title for display to reader
@@ -287,7 +287,7 @@
if ( $xpathRange && XPathPoint::isXPathSafe(
$xpathRange->start->getPathStr() ) && XPathPoint::isXPathSafe(
$xpathRange->end->getPathStr( ) ) )
$s .= " <ptr:range
format='xpath'>".htmlspecialchars($xpathRange->toString())."</ptr:range>\n";
- $s .= " <ptr:access>$sAccess</ptr:access>\n"
+ $s .= " <ptr:sheet>$sSheet</ptr:sheet>\n"
. " <ptr:action>$sAction</ptr:action>\n"
. " <title>$title</title>\n";
// Use double quotes for some attributes because it's easier than
passing ENT_QUOTES to
@@ -301,6 +301,8 @@
$s .= " <id>tag:$tagHost," . date( 'Y-m-d', $annotation->getCreated()
) . ':annotation/'.$annotation->getAnnotationId()."</id>\n"
. " <updated>" . MarginaliaHelper::timeToIso(
$annotation->getModified() ) . "</updated>\n"
. " <ptr:created>" . MarginaliaHelper::timeToIso(
$annotation->getCreated() ). "</ptr:created>\n";
+ if ( $annotation->getLastRead( ) )
+ $s .= " <ptr:lastread>" . MarginaliaHelper::timeToIso(
$annotation->getLastRead() ). "</ptr:lastread>\n";
// Selected text as summary
//echo " <summary>$summary</summary>\n";
// Author of the annotation
@@ -455,7 +457,7 @@
{
case URL_SCHEME_ERROR:
case XPATH_SECURITY_ERROR:
- case ACCESS_VALUE_ERROR:
+ case SHEET_VALUE_ERROR:
case ACTION_VALUE_ERROR:
return 400;
default:
=======================================
--- /marginalia-php/trunk/marginalia-php/XPathRange.php Wed May 30 14:11:15
2012
+++ /marginalia-php/trunk/marginalia-php/XPathRange.php Wed May 30 14:55:33
2012
@@ -173,7 +173,7 @@
{
if ( '' == $xpath )
return true;
- if ( preg_match( '/^.\/\/(.*)$/', $xpath, $matches ) )
+ if ( preg_match( '/^\.\/\/(.*)$/', $xpath, $matches ) )
$xpath = $matches[ 1 ];
$parts = split( '/', $xpath );
foreach ( $parts as $part )
@@ -193,7 +193,7 @@
if ( preg_match( '/^\d+$/', $test ) )
;
// Comparison of an attribute with a quoted value
- elseif (
preg_match( '/^@[a-zA-Z0-9_-]+\s*=\s*([\'"])[^\'"]+([\'"])$/', $test,
$matches ) )
+ elseif (
preg_match( '/^@[a-zA-Z0-9_-]+\s*=\s*([\'"])[a-zA-Z0-9:._-]+([\'"])$/',
$test, $matches ) )
{
if ( $matches[ 1 ] == $matches[ 2 ] ) // ensure quotes match
;
=======================================
--- /marginalia-php/trunk/marginalia-php/embed.php Wed May 30 14:11:15 2012
+++ /marginalia-php/trunk/marginalia-php/embed.php Wed May 30 14:55:33 2012
@@ -32,9 +32,10 @@
function listMarginaliaJavascript( )
{
return array (
- "3rd-party/cssQuery.js"
- ,"3rd-party/cssQuery-level2.js"
- ,"3rd-party/cssQuery-standard.js"
+ '3rd-party/jquery.js'
+ ,'3rd-party/jquery.url.js'
+ ,'3rd-party/date.js'
+ ,'3rd-party/jquery.dates.js'
,"3rd-party/shortcut.js"
,"3rd-party.js"
@@ -42,6 +43,7 @@
,"prefs.js"
,"html-model.js"
,"domutil.js"
+ ,"restutil.js"
,"ranges.js"
,"SequenceRange.js"
,"XPathRange.js"
@@ -61,7 +63,6 @@
,"rest-annotate.js"
,"rest-prefs.js"
,"rest-keywords.js"
- ,"marginalia-direct.js"
);
}