Author: skhudiky
Date: Wed Jun 13 20:50:35 2012
New Revision: 1350013
URL: http://svn.apache.org/viewvc?rev=1350013&view=rev
Log:
OODT-446: Addition of Puny module to Balance
Added:
oodt/trunk/balance/modules/puny/
oodt/trunk/balance/modules/puny/README.txt
oodt/trunk/balance/modules/puny/classes/
oodt/trunk/balance/modules/puny/classes/Puny.class.php
oodt/trunk/balance/modules/puny/classes/Puny_Container.class.php
oodt/trunk/balance/modules/puny/classes/Puny_Resource.class.php
oodt/trunk/balance/modules/puny/classes/data/
oodt/trunk/balance/modules/puny/classes/data/Puny_DataStore.class.php
oodt/trunk/balance/modules/puny/classes/data/Puny_LocalFileDataStore.class.php
oodt/trunk/balance/modules/puny/classes/data/Puny_MongoDataStore.class.php
oodt/trunk/balance/modules/puny/classes/data/Puny_PdoDataStore.class.php
oodt/trunk/balance/modules/puny/classes/parsers/
oodt/trunk/balance/modules/puny/classes/parsers/Puny_MarkdownParser.class.php
oodt/trunk/balance/modules/puny/classes/parsers/Puny_Parser.class.php
oodt/trunk/balance/modules/puny/config.ini
oodt/trunk/balance/modules/puny/data/
oodt/trunk/balance/modules/puny/data/resources/
oodt/trunk/balance/modules/puny/hooks.php
oodt/trunk/balance/modules/puny/libs/
oodt/trunk/balance/modules/puny/libs/markdown.php
oodt/trunk/balance/modules/puny/schemas/
oodt/trunk/balance/modules/puny/schemas/schema.pdo.mysql
oodt/trunk/balance/modules/puny/scripts/
oodt/trunk/balance/modules/puny/scripts/login.php
oodt/trunk/balance/modules/puny/scripts/logout.php
oodt/trunk/balance/modules/puny/scripts/store.php
oodt/trunk/balance/modules/puny/static/
oodt/trunk/balance/modules/puny/static/css/
oodt/trunk/balance/modules/puny/static/css/defaults.css
oodt/trunk/balance/modules/puny/static/css/dialog.css
oodt/trunk/balance/modules/puny/static/css/editor.css
oodt/trunk/balance/modules/puny/static/css/github.css
oodt/trunk/balance/modules/puny/static/css/puny.css
oodt/trunk/balance/modules/puny/static/img/
oodt/trunk/balance/modules/puny/static/img/icon-sprite.png (with props)
oodt/trunk/balance/modules/puny/static/js/
oodt/trunk/balance/modules/puny/static/js/editable.js
oodt/trunk/balance/modules/puny/static/js/editor/
oodt/trunk/balance/modules/puny/static/js/editor/gollum.editor.js
oodt/trunk/balance/modules/puny/static/js/editor/langs/
oodt/trunk/balance/modules/puny/static/js/editor/langs/markdown.js
oodt/trunk/balance/modules/puny/static/js/gollum.dialog.js
oodt/trunk/balance/modules/puny/static/js/gollum.js
oodt/trunk/balance/modules/puny/static/js/gollum.placeholder.js
oodt/trunk/balance/modules/puny/static/js/jquery-1.7.2.min.js
oodt/trunk/balance/modules/puny/static/js/puny.js
oodt/trunk/balance/modules/puny/views/
oodt/trunk/balance/modules/puny/views/edit.php
oodt/trunk/balance/modules/puny/views/error.php
oodt/trunk/balance/modules/puny/views/login.php
oodt/trunk/balance/modules/puny/views/logout.php
oodt/trunk/balance/modules/puny/views/preview.php
Modified:
oodt/trunk/CHANGES.txt
Modified: oodt/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1350013&r1=1350012&r2=1350013&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Wed Jun 13 20:50:35 2012
@@ -4,6 +4,8 @@ Apache OODT Change Log
Release 0.4: Current Development
--------------------------------------------
+* OODT-446 Addition of Puny module to Balance (skhudiky)
+
* OODT-462: Include support for special processing instructions in opendap-ps
configuration file (luca)
* OODT-463: Ignore container-type DAS attributes when parsing metadata in
opendap-ps module (luca)
Added: oodt/trunk/balance/modules/puny/README.txt
URL:
http://svn.apache.org/viewvc/oodt/trunk/balance/modules/puny/README.txt?rev=1350013&view=auto
==============================================================================
--- oodt/trunk/balance/modules/puny/README.txt (added)
+++ oodt/trunk/balance/modules/puny/README.txt Wed Jun 13 20:50:35 2012
@@ -0,0 +1,115 @@
+Puny - Lightweight content editor for Balance applications
+==========================================================
+
+Puny is a lightweight content editing module for Balance applications. Puny
makes
+it easy for developers to add user-editable sections of content to their
application
+views and supports real-time, in-place editing of the content.
+
+Overview
+--------
+
+Puny makes it easier to separate content from presentation and separate the
+role of the site developer and the content manager. As its name implies, it
+provides the bare minimum necessary to accomplish this -- based on the
+understanding that excellent, full-fledged Content Management System options
+are readily available and more appropriate for content-heavy sites. Puny
simply
+provides a way for sites that are not generally suited to a CMS to nevertheless
+reap the benefits of real-time, in-browser content editing by a user not
+intimately familiar with HTML.
+
+How it Works
+------------
+
+Developers embed 'containers' in their views, and content editors provide the
+content that get displayed in the containers. Puny loads up the most recent
+version of the content from the data store, renders it using the specified
+parser, and places the rendered text into the view container.
+
+By logging in with the editor credentials, a user can visually see the editable
+'containers' on the application views, and, using a javascript-enabled browser,
+can provide inline, real-time edits, creating a new version of the content.
+
+
+
+### Flexibility ###
+
+Puny has been designed so that it is easy to plug in custom back end data
+stores (MySql, MongoDB, SQLite, etc) and template engines (Markdown, Textile,
+bbcode, etc). If a driver for <insert data store or parser here> doesn't
exist,
+there are two primary extension points: Puny_DataStore (a base class for
developing
+drivers for data stores), and Puny_Parser (a base class for interfacing with
text
+parsers and template engines). Using the examples in the /classes/data and
+/classes/parsers, it should be relatively easy to develop additional drivers.
+
+
+Installation
+------------
+
+Copy the Puny module (this directory) to the /modules directory of
+your Balance application.
+
+
+Configuration
+-------------
+
+All configuration for Puny takes place in the module's 'config.ini' file. See
+the inline documentation in 'config.ini' for detailed information about each
+configuration option.
+
+
+Developer Guide
+---------------
+
+### Including Puny in your application
+
+In general, Puny needs to be available on each application view. To avoid
having to load
+the module at the top of each view, it is possible to include the module
once,in the
+Balance index.php at the root of your application. Simply add the following
lines to the
+'index.php' file where it says 'Initialize any globally required modules here':
+
+// Puny initialization
+App::Get()->loadModule('puny');
+require_once(App::Get()->settings['puny_module_path'] .
'/classes/Puny.class.php');
+
+
+### Installing your data store ###
+
+Look in the /schemas folder in the Puny module for a schema compatible with
your datastore
+driver. Install the schema using whatever method is most appropriate for the
technology. The
+default driver is the PDO driver implemented in
./classes/data/Puny_PdoDataStore.class.php.
+The MySQL schema compatible with this driver is in
./schemas/puny.pdo.mysql.sql. Copy this
+file and import it into the database you configured in the configuration step
above.
+
+
+### Including Puny containers in your application views ###
+
+The easiest way to include Puny containers in your application views is:
+
+<?php echo Puny::container()->load('resourceid');?>
+
+By default, container creates a '<div>' element and loads the content into it.
To use
+something other than a '<div>' simply specify the html element to the
container() function:
+
+<?php echo Puny::container('span')->load('resourceid');?>
+
+It is also possible to specify arbitrary attributes to attach to your
container. Examples
+include a DOM id, CSS class(es), style attribute, alt, rel, or anything else.
This is
+accomplished by passing an associative array as the second parameter to
container() where
+the array keys are the attribute names, and the values are the attribute
values.
+
+<?php echo Puny::container('div',array('id'=>'mydiv','class'=>'foo
bar'))->load('resourceid');?>
+
+
+### Allowing editors to log in and edit ###
+
+Somewhere in your application, there should be a login link that allows
editors to log in
+and make edits to content. This is easily accomplished by adding the following
line wherever
+you want the login link to appear:
+
+<?php echo Puny::status();?>
+
+This will display either a login or logout link, depending on whether or not
an editor
+is currently logged in.
+
+
+That's all there is to it, it lives up to its name.
\ No newline at end of file
Added: oodt/trunk/balance/modules/puny/classes/Puny.class.php
URL:
http://svn.apache.org/viewvc/oodt/trunk/balance/modules/puny/classes/Puny.class.php?rev=1350013&view=auto
==============================================================================
--- oodt/trunk/balance/modules/puny/classes/Puny.class.php (added)
+++ oodt/trunk/balance/modules/puny/classes/Puny.class.php Wed Jun 13 20:50:35
2012
@@ -0,0 +1,165 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+require_once( dirname(__FILE__) . '/Puny_Container.class.php');
+require_once( dirname(__FILE__) . '/Puny_Resource.class.php');
+
+/**
+ * Puny
+ *
+ * Light-weight content editing for Balance applications. Puny makes it easy
+ * to add editable sections of content to your application views and supports
+ * real-time, in-place editing.
+ *
+ * Puny has been designed so that it is easy to plug in custom back end data
+ * stores (MySql, MongoDB, SQLite, etc) and template engines (Markdown,
Textile,
+ * bbcode, etc). Use what makes sense for your project, and if what you want
+ * is not yet supported, writing a Puny driver for a datastore or template
+ * engine is a piece of cake. There are examples of each in the /classes/data
and
+ * /classes/parsers directories.
+ *
+ * @author ahart
+ */
+
+class Puny {
+
+ protected static $datastore = null;
+
+ protected static $commonResourcesLoaded = false;
+
+ protected static $editorResourcesLoaded = false;
+
+ protected static function init() {
+
+ // Only if the datastore has not yet been initialized...
+ if (!self::$datastore) {
+ try {
+ // Obtain datastore configuration details
+ $datastoreClass =
App::Get()->settings['puny_datastore_classname'];
+ require_once(
App::Get()->settings['puny_datastore_classpath'] );
+
+ // Create an instance of the datastore connector
+ self::$datastore = new $datastoreClass();
+
+ // Connect to the datastore
+ self::$datastore->connect();
+ } catch ( Exception $e ) {
+ throw new Exception("Error instantiating Puny. "
+ . "The underlying cause was: " .
$e->getMessage());
+ }
+ }
+
+ self::injectCommonResources();
+ self::injectEditorResources();
+ }
+
+ public static function load( $resourceId, $version = null,
$parseContent = true ) {
+
+ self::init();
+
+ // Load the raw data from the data store...
+ if (false !== ($resource = self::$datastore->load( $resourceId,
$version ))) {
+
+ // If a valid resource was found, return it
+ return ($parseContent) ? $resource->parse() : $resource;
+
+ } else {
+
+ // Otherwise, return an empty resource with the
requested id
+ return new Puny_Resource( array("resourceId" =>
$resourceId, "content" => $resourceId) );
+
+ }
+ }
+
+ public static function store (Puny_Resource $resource ) {
+
+ self::init();
+
+ // Persist the resource to the datastore
+ self::$datastore->store( $resource );
+
+ }
+
+ public static function isEditing() {
+ return ( isset($_SESSION['puny']) &&
$_SESSION['puny']['editing'] === true );
+ }
+
+ public function initializeEditorSession() {
+ $_SESSION['puny'] = array('editing' => true, 'sessionStart' =>
time());
+ }
+
+ public static function destroyEditorSession() {
+ unset($_SESSION['puny']);
+ }
+
+ public static function status() {
+ if (self::isEditing()) {
+ return "<a
href='".App::Get()->settings['puny_module_root']."/logout'>Logout</a>";
+ } else {
+ return "<a
href='".App::Get()->settings['puny_module_root']."/login'>Login</a>";
+ }
+ }
+
+ protected static function injectCommonResources() {
+ // Inject the environmental information needed for the javascript
libraries
+ // to function as expected...
+ if ( !self::$commonResourcesLoaded ) {
+ $js = "\r\n"
+ . "var puny_module_root = '" .
trim(App::Get()->settings['puny_module_root']) . "'\r\n"
+ . " puny_module_static = '" .
trim(App::Get()->settings['puny_module_static']) ."';\r\n";
+ App::Get()->response->addJavascript( $js, true ); // raw Javascript
+
+ // Add puny default styles
+ $staticPath = trim(App::Get()->settings['puny_module_static']);
+ App::Get()->response->addStylesheet($staticPath .
'/css/defaults.css');
+ App::Get()->response->addJavascript($staticPath .
'/js/jquery-1.7.2.min.js');
+ self::$commonResourcesLoaded = true;
+ }
+ }
+
+ protected static function injectEditorResources() {
+ // Only inject resources if we are editing and they have not
already been loaded...
+ $segments = App::Get()->request->uri;
+ $staticPath = trim(App::Get()->settings['puny_module_static']);
+ if ( self::isEditing() && strstr($segments,'edit') != false) {
+
+ App::Get()->response->addJavascript($staticPath .
'/js/gollum.js');
+ App::Get()->response->addJavascript($staticPath .
'/js/gollum.dialog.js');
+ App::Get()->response->addJavascript($staticPath .
'/js/gollum.placeholder.js');
+ App::Get()->response->addJavascript($staticPath .
'/js/editor/gollum.editor.js');
+
+ App::Get()->response->addStylesheet($staticPath .
'/css/github.css');
+ App::Get()->response->addStylesheet($staticPath .
'/css/editor.css');
+ App::Get()->response->addStylesheet($staticPath .
'/css/dialog.css');
+ }
+ if ( self::isEditing() && !self::$editorResourcesLoaded ) {
+
+ App::Get()->response->addJavascript($staticPath .
'/js/puny.js');
+ App::Get()->response->addStylesheet($staticPath .
'/css/puny.css');
+ self::$editorResourcesLoaded = true;
+ }
+ }
+
+ public static function container( $htmlElmt = 'div' , $extra = array())
{
+
+ self::init();
+
+ // Create a new Puny_Container object according to the provided
info
+ return new Puny_Container($htmlElmt, $extra);
+ }
+}
\ No newline at end of file
Added: oodt/trunk/balance/modules/puny/classes/Puny_Container.class.php
URL:
http://svn.apache.org/viewvc/oodt/trunk/balance/modules/puny/classes/Puny_Container.class.php?rev=1350013&view=auto
==============================================================================
--- oodt/trunk/balance/modules/puny/classes/Puny_Container.class.php (added)
+++ oodt/trunk/balance/modules/puny/classes/Puny_Container.class.php Wed Jun 13
20:50:35 2012
@@ -0,0 +1,85 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+require_once(dirname(__FILE__) . '/Puny.class.php');
+
+/**
+ * Puny_Container
+ *
+ * This class provides convenience methods for creating an HTML container
+ * around a Puny_Resource. Puny_Container removes the need for developers
+ * to manually annotate HTML with the puny="..." attribute (so that the
+ * Puny javascript in-place editor functions on the resource).
+ *
+ * @author ahart
+ */
+class Puny_Container {
+
+ protected $htmlElement;
+ protected $attributes;
+
+ /**
+ * Constructor
+ *
+ * @param string $elmt The html element to use as a container (e.g.:
'div','span')
+ * @param array $attributes (optional) an associative array of
attributes to
+ * attach to the html container element. e.g:
+ * array("id" => 'foo', "class" => "bar baz");
+ */
+ public function __construct( $elmt = 'div', $attributes = array() ) {
+
+ $this->htmlElement = $elmt;
+ $this->attributes = $attributes;
+ }
+
+ /**
+ * Load a resource into this container
+ *
+ * This function simply calls the Puny::load function and returns
+ * wraps the result in the container html
+ *
+ * @param string $resourceId The unique id of the resource to load
+ * @param int $version (optional) The version to load (default = latest)
+ * @returns string
+ */
+ public function load( $resourceId, $version = null ) {
+ return $this->render( Puny::load( $resourceId, $version, false
));
+ }
+
+
+ /**
+ * Helper function for rendering a resource inside this container
+ *
+ * @param unknown_type $resource
+ * @access protected
+ */
+ protected function render($resource) {
+
+ $html = "<{$this->htmlElement}";
+
+ foreach ($this->attributes as $k => $v) {
+ $html .= " {$k}=\"{$v}\"";
+ }
+
+ $html .= " puny=\"{$resource->getId()}\">"
+ . "{$resource->parse()->getContent()}"
+ . "</{$this->htmlElement}>";
+
+ return $html;
+ }
+}
\ No newline at end of file
Added: oodt/trunk/balance/modules/puny/classes/Puny_Resource.class.php
URL:
http://svn.apache.org/viewvc/oodt/trunk/balance/modules/puny/classes/Puny_Resource.class.php?rev=1350013&view=auto
==============================================================================
--- oodt/trunk/balance/modules/puny/classes/Puny_Resource.class.php (added)
+++ oodt/trunk/balance/modules/puny/classes/Puny_Resource.class.php Wed Jun 13
20:50:35 2012
@@ -0,0 +1,163 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Puny_Resource
+ *
+ * Represents a piece of content being managed by Puny.
+ *
+ * The Puny_Resource class is a wrapper around a piece of editable
+ * content (a resource). The class provides a number of convenience
+ * functions for interacting with content.
+ *
+ * @author ahart
+ */
+class Puny_Resource {
+
+ protected $id; // The unique
id for this resource
+ protected $version = 0; // The version number
for this resource
+ protected $content; // The resource
raw content
+ protected $parser = 'markdown'; // The parser label for this
resource
+ protected $parsedContent; // The resource parsed
content
+
+ /**
+ * Constructor
+ *
+ * Optionally provide an associative array containing
+ * the data to use when initializing this object.
+ *
+ * @param array $data (optional) data to use when initializing the
object
+ */
+ public function __construct($data = array()) {
+ $this->id = isset($data['resourceId']) ?
$data['resourceId'] : false;
+ $this->version = isset($data['version']) ? $data['version']
: 0;
+ $this->content = isset($data['content']) ? $data['content']
: '';
+ $this->parser = isset($data['parser']) ? $data['parser']
: 'markdown';
+ $this->parsedContent = isset($data['parsedContent']) ?
$data['parsedContent'] : '';
+ }
+
+ /**
+ * Get the unique id for this resource
+ * @returns String
+ */
+ public function getId() {
+ return $this->id;
+ }
+
+ /**
+ * Increment the version number for this resource
+ * @returns Puny_Resource
+ */
+ public function incrementVersion() {
+ $this->version += 1;
+ return $this; // allow method chaining
+ }
+
+ /**
+ * Return the version number for this resource
+ * @returns int
+ */
+ public function getVersion() {
+ return $this->version;
+ }
+
+ /**
+ * Get the parser label for this resource. The parser
+ * label is a text label which should correspond to
+ * one of the entries in the 'parsers' section of the
+ * Puny module's config.ini file.
+ */
+ public function getParser() {
+ return $this->parser;
+ }
+
+ /**
+ * Set the parser label for this resource.
+ *
+ * @param string $label The parser label to use
+ */
+ public function setParser( $label ) {
+ $this->parser = $label;
+ return $this; // allow method chaining
+ }
+
+ /**
+ * Get either the parsed or raw resource content.
+ *
+ * @param boolean $raw (default=false) return raw content?
+ * @returns string
+ */
+ public function getContent( $raw = false ) {
+ return ($raw) ? $this->content : $this->parsedContent;
+ }
+
+ /**
+ * set the raw content for this resource.
+ * @param string $val The raw content for this resource
+ * @returns Puny_Resource
+ */
+ public function setContent( $val ) {
+ $this->content = $val;
+ return $this; // allow method chaining
+ }
+
+ /**
+ * Parse the raw contents of this resourse
+ *
+ * This function uses the parser label associated with this
+ * resource to determine the parser to use, instantiates a
+ * parser instance, and parses the raw content. The result
+ * is stored in $this->parsedContent.
+ *
+ * @throws Exception
+ * @returns Puny_Resource
+ */
+ public function parse() {
+ // Determine the parser to use
+ $parserLabel = $this->getParser();
+
+ // Ensure the appropriate parser has been required
+ $parsers = App::Get()->settings['puny_parser'];
+ if ( !in_array( $parserLabel, array_keys( $parsers ) ) ) {
+ throw new Exception("Error instantiating parser: "
+ . "label '{$parserLabel}' not configured. ");
+ } else {
+ require_once( $parsers[$parserLabel] );
+ }
+
+ // Load the parser
+ $parserClassName = 'Puny_' . ucfirst($parserLabel) . 'Parser';
+ $parser = new $parserClassName();
+
+ // Expand Balance constants:
+ // ([SITE_ROOT], [MODULE_ROOT], [MODULE_PATH], [MODULE_STATIC])
+ $content = str_replace('[SITE_ROOT]',SITE_ROOT,
stripslashes($this->content));
+ $moduleInfo = App::Get()->loadModule();
+ if ($moduleInfo) {
+ $content =
str_replace('[MODULE_ROOT]',$moduleInfo->moduleRoot, $content);
+ $content =
str_replace('[MODULE_PATH]',$moduleInfo->modulePath, $content);
+ $content =
str_replace('[MODULE_STATIC]',$moduleInfo->moduleStatic, $content);
+ }
+
+ // Store the parsed contents
+ $this->parsedContent = $parser->parse( $content );
+
+ // Allow method chaining
+ return $this;
+ }
+}
\ No newline at end of file
Added: oodt/trunk/balance/modules/puny/classes/data/Puny_DataStore.class.php
URL:
http://svn.apache.org/viewvc/oodt/trunk/balance/modules/puny/classes/data/Puny_DataStore.class.php?rev=1350013&view=auto
==============================================================================
--- oodt/trunk/balance/modules/puny/classes/data/Puny_DataStore.class.php
(added)
+++ oodt/trunk/balance/modules/puny/classes/data/Puny_DataStore.class.php Wed
Jun 13 20:50:35 2012
@@ -0,0 +1,69 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Puny_DataStore
+ *
+ * Base class for Puny data store implementations
+ *
+ * @abstract
+ *
+ * @author ahart
+ */
+abstract class Puny_DataStore {
+
+ protected $host;
+ protected $username;
+ protected $password;
+ protected $dbname;
+
+ protected $link;
+
+ /**
+ * Connect to the data store
+ *
+ */
+ public abstract function connect();
+
+ /**
+ * Disconnect from the data store
+ */
+ public abstract function disconnect();
+
+ /**
+ * Request a resource from the data store. Optionally
+ * specify a particular version of the resource to fetch.
+ *
+ * @param string $resourceId The unique id of the resource
+ * @param integer $version (Optional) the version to retrieve.
Default = latest.
+ */
+ public abstract function load( $resourceId, $version = null );
+
+ /**
+ * Store a new version of a resource. For simplicity, versions are
+ * immutable. That is, every time a resource is stored, its version is
+ * first incremented and a new record is created. Implemenations should
+ * take care to automatically increment the version number of the
+ * resource before persisting to the datastore.
+ *
+ * @param string $resourceId The unique id of the resource
+ * @param string $content The content to store
+ */
+ public abstract function store( Puny_Resource $resource );
+
+}
\ No newline at end of file
Added:
oodt/trunk/balance/modules/puny/classes/data/Puny_LocalFileDataStore.class.php
URL:
http://svn.apache.org/viewvc/oodt/trunk/balance/modules/puny/classes/data/Puny_LocalFileDataStore.class.php?rev=1350013&view=auto
==============================================================================
---
oodt/trunk/balance/modules/puny/classes/data/Puny_LocalFileDataStore.class.php
(added)
+++
oodt/trunk/balance/modules/puny/classes/data/Puny_LocalFileDataStore.class.php
Wed Jun 13 20:50:35 2012
@@ -0,0 +1,79 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Require the abstract parent class definition
+require_once( dirname(__FILE__) . '/Puny_DataStore.class.php');
+
+/**
+ * An implementation of the Puny_DataStore class that persists
+ * content to ascii text files.
+ *
+ * @author ahart
+ */
+class Puny_LocalFileDataStore extends Puny_DataStore {
+
+ protected $dataDirectory;
+
+ public function connect() {
+ $this->dataDirectory =
App::Get()->settings['puny_datastore_localfile_dir'];
+
+ // Ensure we can write to the directory
+ if (!is_writeable($this->dataDirectory)) {
+ throw new Exception("Puny can not write to the specified data
directory");
+ }
+ }
+
+ public function disconnect() {
+ //noop
+ }
+
+ public function load( $resourceId, $version = null ) {
+
+ // The LocalFile data store does not currently support
+ // the concept of 'versions'. It could, but is the
+ // added complexity really worth it? This is really
+ // intended as a development tool, with the assumption
+ // that one of the more full-featured data store
+ // implementations (e.g.: PDO, Mongo) will ultimately
+ // be used.
+
+ // Build the full path from the resourceId
+ $path = $this->dataDirectory . '/' . $resourceId . ".txt";
+
+ if (file_exists( $path ) ) {
+ $content = file_get_contents($path);
+ $resource = array(
+ "resourceId" => $resourceId
+ , "content" => $content
+ );
+ return new Puny_Resource($resource);
+ } else {
+ return false;
+ }
+ }
+
+ public function store ( Puny_Resource $resource ) {
+
+ // Build the full path from the resourceId
+ $path = $this->dataDirectory . '/' . $resource->getId() . ".txt";
+
+ // Store the latest content
+ file_put_contents($path, $resource->getContent(true)); // raw, unparsed
content
+
+ }
+}
\ No newline at end of file
Added:
oodt/trunk/balance/modules/puny/classes/data/Puny_MongoDataStore.class.php
URL:
http://svn.apache.org/viewvc/oodt/trunk/balance/modules/puny/classes/data/Puny_MongoDataStore.class.php?rev=1350013&view=auto
==============================================================================
--- oodt/trunk/balance/modules/puny/classes/data/Puny_MongoDataStore.class.php
(added)
+++ oodt/trunk/balance/modules/puny/classes/data/Puny_MongoDataStore.class.php
Wed Jun 13 20:50:35 2012
@@ -0,0 +1,75 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Require the abstract parent class definition
+require_once( dirname(__FILE__) . '/Puny_DataStore.class.php');
+
+/**
+ * A MongoDB implementation of the Puny_DataStore class.
+ *
+ * @author ahart
+ */
+class Puny_MongoDataStore extends Puny_DataStore {
+
+ protected $collection;
+
+ public function connect() {
+ $dbname = App::Get()->settings['puny_datastore_mongo_db'];
+ $coll = App::Get()->settings['puny_datastore_mongo_collection'];
+ $this->link = new Mongo();
+ $this->dbname = $this->link->selectDB($dbname);
+ $this->collection = $this->dbname->$coll;
+ }
+
+ public function disconnect() {
+ if ($this->link) {
+ $this->link->close();
+ }
+ }
+
+ public function load( $resourceId, $version = null ) {
+ // Build criteria for loading...
+ $criteria = array("resourceId" => $resourceId);
+
+ // If a version is specified...
+ if ($version !== null) {
+ $criteria['version'] = $version;
+ $doc = $this->collection->findOne( $criteria );
+ }
+
+ // Otherwise...
+ else {
+ $cursor = $this->collection->find(array("resourceId" => $resourceId));
+ $cursor->sort(array('version' => -1));
+ $doc = $cursor->getNext();
+ }
+
+ // Return whatever was found...
+ return ($doc) ? new Puny_Resource( $doc ) : false;
+ }
+
+ public function store ( Puny_Resource $resource ) {
+ $doc = array(
+ "resourceId" => $resource->getId()
+ , "version" => time()
+ , "parser" => $resource->getParser()
+ , "content" => $resource->getContent( true )); // raw,
unparsed content
+
+ $this->collection->insert( $doc );
+ }
+}
\ No newline at end of file
Added: oodt/trunk/balance/modules/puny/classes/data/Puny_PdoDataStore.class.php
URL:
http://svn.apache.org/viewvc/oodt/trunk/balance/modules/puny/classes/data/Puny_PdoDataStore.class.php?rev=1350013&view=auto
==============================================================================
--- oodt/trunk/balance/modules/puny/classes/data/Puny_PdoDataStore.class.php
(added)
+++ oodt/trunk/balance/modules/puny/classes/data/Puny_PdoDataStore.class.php
Wed Jun 13 20:50:35 2012
@@ -0,0 +1,111 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Require the abstract parent class definition
+require_once( dirname(__FILE__) . '/Puny_DataStore.class.php');
+
+
+/**
+ * A PDO implementation of the Puny_DataStore class.
+ *
+ * @author ahart
+ */
+class Puny_PdoDataStore extends Puny_DataStore {
+
+ protected $driver = 'mysql';
+ protected $tablePrefix = 'puny_';
+
+ /**
+ * (non-PHPdoc)
+ * @see Puny_DataStore::connect()
+ * @throws PDOException
+ */
+ public function connect() {
+ $this->host = App::Get()->settings['puny_datastore_pdo_host'];
+ $this->username =
App::Get()->settings['puny_datastore_pdo_username'];
+ $this->password =
App::Get()->settings['puny_datastore_pdo_password'];
+ $this->dbname =
App::Get()->settings['puny_datastore_pdo_dbname'];
+ $this->driver =
App::Get()->settings['puny_datastore_pdo_driver'];
+ $this->tablePrefix =
App::Get()->settings['puny_datastore_pdo_tablePrefix'];
+
+ $dsn = $this->driver . ':host=' . $this->host . ';dbname=' .
$this->dbname;
+ $this->link = new PDO( $dsn, $this->username, $this->password );
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see Puny_DataStore::disconnect()
+ */
+ public function disconnect() {
+ if ($this->link)
+ $this->link = null;
+ }
+
+ public function load( $resourceId, $version = null) {
+
+ // Request the specified resource...
+ $sql = "SELECT * FROM `{$this->tablePrefix}resource` WHERE
`resourceId`=:resourceId ";
+ $data = array('resourceId' => $resourceId);
+
+ // If a version is specified, explicitly request that version...
+ if ($version != null) {
+ $sql .= " AND `version`=:version ";
+ $data['version'] = $version;
+ }
+
+ // Otherwise, simply get the latest version...
+ else {
+ $sql .= " ORDER BY `version` DESC ";
+ }
+
+ // Limit our results to at most one result...
+ $sql .= " LIMIT 1 ";
+
+ // Prepare and execute the query using the provided data...
+ $stmt = $this->link->prepare( $sql );
+ $stmt->execute( $data );
+
+ // Return the single result, or return false if no match...
+ if (false != ($resource = $stmt->fetch())) {
+ return new Puny_Resource($resource);
+ } else {
+ return false;
+ }
+ }
+
+ public function store( Puny_Resource $resource ) {
+
+ // Increment the resource version id... (see note in
Puny_DataStore.class.php)
+ $resource->incrementVersion();
+
+ // Create sql for storing this new resource version...
+ $sql = "INSERT INTO `{$this->tablePrefix}resource`
(`resourceId`,`version`,`parser`,`content`) "
+ . "VALUES (:resourceId, :version, :parser, :content) ";
+
+ // Prepare and execute the statement using the provided data
+ $stmt = $this->link->prepare($sql);
+ $stmt->execute ( array (
+ 'resourceId' => $resource->getId()
+ , 'version' => $resource->getVersion()
+ , 'parser' => $resource->getParser()
+ , 'content' => $resource->getContent(true) // raw,
unparsed content
+ ));
+
+ }
+
+}
\ No newline at end of file
Added:
oodt/trunk/balance/modules/puny/classes/parsers/Puny_MarkdownParser.class.php
URL:
http://svn.apache.org/viewvc/oodt/trunk/balance/modules/puny/classes/parsers/Puny_MarkdownParser.class.php?rev=1350013&view=auto
==============================================================================
---
oodt/trunk/balance/modules/puny/classes/parsers/Puny_MarkdownParser.class.php
(added)
+++
oodt/trunk/balance/modules/puny/classes/parsers/Puny_MarkdownParser.class.php
Wed Jun 13 20:50:35 2012
@@ -0,0 +1,36 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Require the markdown php library (https://github.com/michelf/php-markdown/)
+require_once( App::Get()->settings['puny_module_path'] . '/libs/markdown.php');
+
+/**
+ * Markdown implementation of the Puny_Parser class
+ *
+ * @author ahart
+ */
+
+class Puny_MarkdownParser {
+
+ public function parse ( $content ) {
+
+ return Markdown( $content );
+
+ }
+
+}
\ No newline at end of file
Added: oodt/trunk/balance/modules/puny/classes/parsers/Puny_Parser.class.php
URL:
http://svn.apache.org/viewvc/oodt/trunk/balance/modules/puny/classes/parsers/Puny_Parser.class.php?rev=1350013&view=auto
==============================================================================
--- oodt/trunk/balance/modules/puny/classes/parsers/Puny_Parser.class.php
(added)
+++ oodt/trunk/balance/modules/puny/classes/parsers/Puny_Parser.class.php Wed
Jun 13 20:50:35 2012
@@ -0,0 +1,40 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Puny_Parser
+ *
+ * Base class for Puny parser implementations.
+ *
+ * @abstract
+ *
+ * @author ahart
+ */
+abstract class Puny_Parser {
+
+ /**
+ * Implementations of this function should return the
+ * final (display-ready) version of the provided content.
+ *
+ * @param string $content The content to parse
+ * @returns string
+ * @abstract
+ */
+ public abstract function parse( $content );
+
+}
\ No newline at end of file
Added: oodt/trunk/balance/modules/puny/config.ini
URL:
http://svn.apache.org/viewvc/oodt/trunk/balance/modules/puny/config.ini?rev=1350013&view=auto
==============================================================================
--- oodt/trunk/balance/modules/puny/config.ini (added)
+++ oodt/trunk/balance/modules/puny/config.ini Wed Jun 13 20:50:35 2012
@@ -0,0 +1,75 @@
+ # Licensed to the Apache Software Foundation (ASF) under one or more
+ # contributor license agreements. See the NOTICE file distributed with
+ # this work for additional information regarding copyright ownership.
+ # The ASF licenses this file to You under the Apache License, Version 2.0
+ # (the "License"); you may not use this file except in compliance with
+ # the License. You may obtain a copy of the License at
+ #
+ # http://www.apache.org/licenses/LICENSE-2.0
+ #
+ # Unless required by applicable law or agreed to in writing, software
+ # distributed under the License is distributed on an "AS IS" BASIS,
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ # See the License for the specific language governing permissions and
+ # limitations under the License.
+
+#
+# Puny - Lightweight content editor for Balance applications
+#
+# ------------------------------------------------------------------------
+#
+
+[ADMINISTRATION CONFIGURATION]
+#
+# Editor login credentials
+# -------------------------------------
+# The editor is the user authorized to make content changes to the site
+#
+puny_editor_username = ''
+puny_editor_password = ''
+
+
+[DATASTORE CONFIGURATION]
+#
+# Which class will provide connection to the data store?
+puny_datastore_classname = Puny_LocalFileDataStore;
+
+# Where is this class in the filesystem?
+puny_datastore_classpath =
[MODULE_PATH]/classes/data/Puny_LocalFileDataStore.class.php;
+
+# Connection parameters specific to the Puny_LocalFileDataStore connector
+puny_datastore_localfile_dir = '[MODULE_PATH]/data/resources';
+
+# Connection parameters specific to the Puny_PdoDataStore connector
+puny_datastore_pdo_host = 'localhost';
+puny_datastore_pdo_username = '';
+puny_datastore_pdo_password = '';
+puny_datastore_pdo_dbname = '';
+puny_datastore_pdo_driver = 'mysql';
+puny_datastore_pdo_tablePrefix = 'puny_';
+
+# Connection parameters specific to the Puny_MongoDataStore connector
+puny_datastore_mongo_db = '';
+puny_datastore_mongo_collection = '';
+
+[PARSER CONFIGURATION]
+#
+# Puny supports an unlimited number of parsers. The only requirement is that
+# there be a driver that conforms to ./classes/parsers/Puny_Parser.class.php.
+#
+# This array provides a mapping between parser labels and the corresponding
+# parser class that will do the work.
+#
+puny_parser[ 'markdown' ] =
[MODULE_PATH]/classes/parsers/Puny_MarkdownParser.class.php
+
+
+
+[INTERNAL ROUTING]
+#
+# These variables are here to provide location independence (so that you can
+# install Puny in ./modules/puny or ./modules/somethingelse without having
+# to change any code. You should never have to edit these.
+#
+puny_module_path = [MODULE_PATH]
+puny_module_root = [MODULE_ROOT]
+puny_module_static = [MODULE_STATIC]
\ No newline at end of file
Added: oodt/trunk/balance/modules/puny/hooks.php
URL:
http://svn.apache.org/viewvc/oodt/trunk/balance/modules/puny/hooks.php?rev=1350013&view=auto
==============================================================================
--- oodt/trunk/balance/modules/puny/hooks.php (added)
+++ oodt/trunk/balance/modules/puny/hooks.php Wed Jun 13 20:50:35 2012
@@ -0,0 +1,17 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
\ No newline at end of file