<?php
/*
DocumentHandler.php, Base class for implementing new document handlers.
Copyright (C) 2004 Arend van Beelen, Auton Rijnsburg
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For any questions, comments or whatever, you may mail me at: hide@address.com
*/
require_once('Search.php');
require_once('URI.php');
/**
* @brief Base class for implementing new document handlers.
*
* To create a document handler you need to at least implement the view()
* to get a document handler which supports viewing, or re-implement the
* supportsViewing() function to return @p false if you want a document
* handler without viewer. To let your handler also support editing of
* documents you should implement the edit() and save() functions, and
* then you should also reimplement the * function supportsEditing() and
* let it return @p true. To support indexing of documents, implement the
* index() function and let supportsIndexing() return @p true.
*
* You should name your class like the MIME type of the documents it
* handles, with all non-alphanumeric characters replaced with an
* underscore and with "_DocumentHandler" appended, like for example:
* "text_plain_DocumentHandler". The class should then be stored in a
* file with the same name (with ".php" extension) in the
* "plugins/DocumentHandlers" directory. This way the handler can be
* automatically opened when needed.
*
* @p view(), edit(), save(), index(), supportsViewing(), supportsEditing(),
* supportsIndexing()
*/
class DocumentHandler
{
/**
* Returns whether the handler supports viewing of documents.
*
* Reimplement this function to return @p false if your handler does not
* implement the view() function.
*
* @return @p true if the handler supports viewing documents,
* @p false otherwise.
*
* @since Aukyla 1.1
*
* @sa view()
*/
public static function supportsViewing()
{
return true;
}
/**
* Opens a document for viewing.
*
* Your implementation should open the document specified with the given
* @p uri and should create the document viewer as a child widget,
* formatted as an Aukyla XML document.
*
* @param parent The parent widget to which the DocumentViewer is added.
* Any children you add to the parent are shown by the
* DocumentViewer.
* @param uri URI to the document to be opened.
*
* @sa supportsViewing()
*/
public static function view(Container $parent, $uri)
{
return;
}
/**
* Returns whether the handler supports editing of documents.
*
* Reimplement this function to return @p true if you have implemented
* both the edit() and save() functions.
*
* @return @p true if the handler supports editing of documents,
* @p false otherwise.
*
* @sa edit(), save()
*/
public static function supportsEditing()
{
return false;
}
/**
* Opens a document for editing.
*
* Your implementation should open the document specified with the given
* @p uri and should create an appropriate editor with the said document
* preloaded.
*
* @param parent The parent widget to which the DocumentEditor is added.
* Any children you add to the parent are shown by the
* DocumentEditor.
* @param id The ID of the editor.
* @param uri URI to the document to be opened. If the URI is empty,
* the editor should simply have no contents preloaded.
*
* @sa save(), supportsEditing()
*/
public static function edit(Container $parent, $id, $uri = '')
{
return;
}
/**
* Saves an edited document.
*
* Your implementation should take the contents of the document which
* was uploaded from the DocumentEditor specified with @p id and save it
* under the given @p uri.
*
* @param id The ID of the editor through which the document was
* edited.
* @param uri URI where the document should be saved.
*
* @return @p true if the document was successfully saved, @p false
* otherwise.
*
* @sa edit(), supportsEditing()
*/
public static function save($id, $uri)
{
return false;
}
/**
* Returns whether the handler supports indexing of documents for use
* with search functionality.
*
* Reimplement this function to return @p true if you have implemented
* the index() function.
*
* @note The default implementation of index() still indexes a
* document's meta-data as stored by the URI handler.
*
* @return @p true if the handler supports indexing of documents,
* @p false otherwise.
*
* @since Aukyla 1.1
*
* @sa index()
*/
public static function supportsIndexing()
{
return false;
}
/**
* Indexes a document.
*
* Your implementation should open the document specified with the given
* @p uri and index all (key)words found in the document. The document's
* contents should then be indexed with the Search::indexText()
* function.
*
* @note The default implementation of index() still indexes a
* document's meta-data as stored by the URI handler, making this
* function at least somewhat useful, even without a
* re-implemented indexer. The meta-data keys which are indexed
* are: @p name, @p comment, @p keywords and @p author.
*
* @param documentId ID in the search database of the document to index.
* @param uri URI of the document to be indexed.
*
* @since Aukyla 1.1
*
* @sa Search, supportsIndexing()
*/
public static function index($documentId, $uri)
{
$search = Search::instance();
$name = URI::metaData($uri, 'name');
$comment = URI::metaData($uri, 'comment');
$keywords = URI::metaData($uri, 'keywords');
$author = URI::metaData($uri, 'author');
if($name != '')
{
$search->indexText($documentId, $name, 50);
}
if($comment != '')
{
$search->indexText($documentId, $comment, 20);
}
if($keywords != '')
{
$search->indexText($documentId, $keywords, 30);
}
if($author != '')
{
$search->indexText($documentId, $author, 20);
}
}
}
?>