1: <?php
2:
3: require_once $config->get('app.root').'alpha/util/codehighlight/AlphaHighlightProviderInterface.inc';
4:
5: /**
6: *
7: * Wraps Luminous in the standard API defined in AlphaHighlightProviderInterface,
8: * for use in the Alpha CMS module. Note that Luminous is not included in Alpha,
9: * so you will need to download it from here:
10: *
11: * (PHP 5.3)
12: *
13: * http://luminous.asgaard.co.uk/index.php/page/index
14: *
15: * (PHP 5.2, you will need to use the older version)
16: *
17: * http://code.google.com/p/luminous/
18: *
19: * Once downloaded, place in the [application]/lib/luminous directory which is where this class
20: * will attempt to load it from.
21: *
22: * Also note that Luminous requires it's own .css file to be loaded in the page that is displaying
23: * the highlighted code. The following callback in your controller will inject the desired .css
24: * file:
25: *
26: * public function during_displayPageHead_callback() {
27: * global $config;
28: *
29: * $html = '<link type="text/css" rel="StyleSheet" href="'.$config->get('app.url').'lib/luminous/style/luminous.css">';
30: *
31: * return $html;
32: * }
33: *
34: * @package alpha::util::codehighlight
35: * @since 1.2
36: * @author John Collins <dev@alphaframework.org>
37: * @version $Id: AlphaHighlightProviderLuminous.inc 1548 2012-07-29 17:07:07Z alphadevx $
38: * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
39: * @copyright Copyright (c) 2012, John Collins (founder of Alpha Framework).
40: * All rights reserved.
41: *
42: * <pre>
43: * Redistribution and use in source and binary forms, with or
44: * without modification, are permitted provided that the
45: * following conditions are met:
46: *
47: * * Redistributions of source code must retain the above
48: * copyright notice, this list of conditions and the
49: * following disclaimer.
50: * * Redistributions in binary form must reproduce the above
51: * copyright notice, this list of conditions and the
52: * following disclaimer in the documentation and/or other
53: * materials provided with the distribution.
54: * * Neither the name of the Alpha Framework nor the names
55: * of its contributors may be used to endorse or promote
56: * products derived from this software without specific
57: * prior written permission.
58: *
59: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
60: * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
61: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
62: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
63: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
64: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
65: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
66: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
67: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
69: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
70: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
71: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72: * </pre>
73: *
74: */
75: class AlphaHighlightProviderLuminous implements AlphaHighlightProviderInterface {
76: /**
77: * (non-PHPdoc)
78: * @see alpha/util/codehighlight/AlphaHighlightProviderInterface::highlight()
79: * @since 1.2
80: */
81: public function highlight($source, $language) {
82: global $config;
83:
84: $codeBlock = '';
85:
86: try {
87: AlphaAutoLoader::loadLib('luminous.php');
88:
89: $codeblock = luminous($language, $source, false);
90: }catch(LibraryNotInstalledException $e) {
91: $codeblock = $source;
92: }
93:
94: return $codeblock;
95: }
96: }
97: ?>