2008-09-26 04:22:51 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Parses text in a variety of ways.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2008-09-26 04:22:51 +02:00
|
|
|
* Called from a template by $Content.Parse(SubClassName), similar to $Content.XML.
|
2014-08-15 08:53:05 +02:00
|
|
|
* This will work on any Text database field (Or a sub-class, such as HTMLText,
|
2008-09-26 04:22:51 +02:00
|
|
|
* although it's usefulness in this situation is more limited).
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
|
|
|
* Any sub-classes of TextParser must implement a parse() method.
|
2008-09-26 04:22:51 +02:00
|
|
|
* This should take $this->content and parse it however you want. For an example
|
|
|
|
* of the implementation, @see BBCodeParser.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2008-09-26 04:22:51 +02:00
|
|
|
* Your sub-class will be initialized with a string of text, then parse() will be called.
|
|
|
|
* parse() should (after processing) return the formatted string.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
|
|
|
* Note: $this->content will have NO conversions applied to it.
|
|
|
|
* You should run Covert::raw2xml or whatever is appropriate before using it.
|
|
|
|
*
|
|
|
|
* Optionally (but recommended), is creating a static usable_tags method,
|
2011-10-26 08:09:04 +02:00
|
|
|
* which will return a SS_List of all the usable tags that can be parsed.
|
2008-09-26 04:22:51 +02:00
|
|
|
* This will (mostly) be used to create helper blocks - telling users what things will be parsed.
|
|
|
|
* Again, @see BBCodeParser for an example of the syntax
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2008-09-26 04:22:51 +02:00
|
|
|
* @todo Define a proper syntax for (or refactor) usable_tags that can be extended as needed.
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-09-26 04:22:51 +02:00
|
|
|
* @subpackage misc
|
|
|
|
*/
|
|
|
|
abstract class TextParser extends Object {
|
2016-06-03 10:51:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2008-09-26 04:22:51 +02:00
|
|
|
protected $content;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-09-26 04:22:51 +02:00
|
|
|
/**
|
|
|
|
* Creates a new TextParser object.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2008-09-26 04:22:51 +02:00
|
|
|
* @param string $content The contents of the dbfield
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __construct($content = "") {
|
2016-06-03 10:51:02 +02:00
|
|
|
parent::__construct();
|
2008-09-26 04:22:51 +02:00
|
|
|
$this->content = $content;
|
2016-06-13 02:43:25 +02:00
|
|
|
parent::__construct();
|
2008-09-26 04:22:51 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-09-26 04:22:51 +02:00
|
|
|
/**
|
|
|
|
* Convenience method, shouldn't really be used, but it's here if you want it
|
2016-06-03 10:51:02 +02:00
|
|
|
*
|
|
|
|
* @param string $content
|
2008-09-26 04:22:51 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setContent($content = "") {
|
2008-09-26 04:22:51 +02:00
|
|
|
$this->content = $content;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-09-26 04:22:51 +02:00
|
|
|
/**
|
|
|
|
* Define your own parse method to parse $this->content appropriately.
|
|
|
|
* See the class doc-block for more implementation details.
|
2016-06-03 10:51:02 +02:00
|
|
|
*
|
|
|
|
* @return DBField
|
2008-09-26 04:22:51 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
abstract public function parse();
|
2008-09-26 04:22:51 +02:00
|
|
|
}
|