aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Module/Page.php10
-rw-r--r--Zotlabs/Render/Comanche.php404
-rwxr-xr-xboot.php18
-rw-r--r--include/comanche.php422
-rw-r--r--include/text.php39
5 files changed, 459 insertions, 434 deletions
diff --git a/Zotlabs/Module/Page.php b/Zotlabs/Module/Page.php
index 64b940b0f..8a8bc7a49 100644
--- a/Zotlabs/Module/Page.php
+++ b/Zotlabs/Module/Page.php
@@ -99,9 +99,9 @@ class Page extends \Zotlabs\Web\Controller {
\App::$page['title'] = escape_tags($r[0]['title']);
if($r[0]['item_type'] == ITEM_TYPE_PDL) {
- require_once('include/comanche.php');
- comanche_parser(get_app(),$r[0]['body']);
- \App::$pdl = $r[0]['body'];
+ \App::$comanche = new \Zotlabs\Render\Comanche();
+ \App::$comanche->parse($r[0]['body']);
+ \App::$pdl = $r[0]['body'];
}
elseif($r[0]['layout_mid']) {
$l = q("select body from item where mid = '%s' and uid = %d limit 1",
@@ -110,8 +110,8 @@ class Page extends \Zotlabs\Web\Controller {
);
if($l) {
- require_once('include/comanche.php');
- comanche_parser(get_app(),$l[0]['body']);
+ \App::$comanche = new \Zotlabs\Render\Comanche();
+ \App::$comanche->parse($l[0]['body']);
\App::$pdl = $l[0]['body'];
}
}
diff --git a/Zotlabs/Render/Comanche.php b/Zotlabs/Render/Comanche.php
new file mode 100644
index 000000000..776874e35
--- /dev/null
+++ b/Zotlabs/Render/Comanche.php
@@ -0,0 +1,404 @@
+<?php /** @file */
+
+namespace Zotlabs\Render;
+
+require_once('include/security.php');
+require_once('include/menu.php');
+require_once('include/widgets.php');
+
+
+
+
+class Comanche {
+
+
+ function parse($s, $pass = 0) {
+ $matches = array();
+
+ $cnt = preg_match_all("/\[comment\](.*?)\[\/comment\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $s = str_replace($mtch[0], '', $s);
+ }
+ }
+
+ $cnt = preg_match_all("/\[if (.*?)\](.*?)\[else\](.*?)\[\/if\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ if($this->test_condition($mtch[1])) {
+ $s = str_replace($mtch[0], $mtch[2], $s);
+ }
+ else {
+ $s = str_replace($mtch[0], $mtch[3], $s);
+ }
+ }
+ }
+ else {
+ $cnt = preg_match_all("/\[if (.*?)\](.*?)\[\/if\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ if($this->test_condition($mtch[1])) {
+ $s = str_replace($mtch[0], $mtch[2], $s);
+ }
+ else {
+ $s = str_replace($mtch[0], '', $s);
+ }
+ }
+ }
+ }
+ if($pass == 0)
+ $this->parse_pass0($s);
+ else
+ $this->parse_pass1($s);
+
+ }
+
+ function parse_pass0($s) {
+
+ $matches = null;
+
+ $cnt = preg_match("/\[layout\](.*?)\[\/layout\]/ism", $s, $matches);
+ if($cnt)
+ \App::$page['template'] = trim($matches[1]);
+
+ $cnt = preg_match("/\[template=(.*?)\](.*?)\[\/template\]/ism", $s, $matches);
+ if($cnt) {
+ \App::$page['template'] = trim($matches[2]);
+ \App::$page['template_style'] = trim($matches[2]) . '_' . $matches[1];
+ }
+
+ $cnt = preg_match("/\[template\](.*?)\[\/template\]/ism", $s, $matches);
+ if($cnt) {
+ \App::$page['template'] = trim($matches[1]);
+ }
+
+ $cnt = preg_match("/\[theme=(.*?)\](.*?)\[\/theme\]/ism", $s, $matches);
+ if($cnt) {
+ \App::$layout['schema'] = trim($matches[1]);
+ \App::$layout['theme'] = trim($matches[2]);
+ }
+
+ $cnt = preg_match("/\[theme\](.*?)\[\/theme\]/ism", $s, $matches);
+ if($cnt)
+ \App::$layout['theme'] = trim($matches[1]);
+
+ $cnt = preg_match_all("/\[webpage\](.*?)\[\/webpage\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ // only the last webpage definition is used if there is more than one
+ foreach($matches as $mtch) {
+ \App::$layout['webpage'] = $this->webpage($a,$mtch[1]);
+ }
+ }
+ }
+
+ function parse_pass1($s) {
+ $cnt = preg_match_all("/\[region=(.*?)\](.*?)\[\/region\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ \App::$layout['region_' . $mtch[1]] = $this->region($mtch[2]);
+ }
+ }
+ }
+
+
+
+ function test_condition($s) {
+
+ // This is extensible. The first version of variable testing supports tests of the form
+ // [if $config.system.foo] which will check for a return of a true condition for get_config('system','foo');
+ // The values 0, '', an empty array, and an unset value will all evaluate to false.
+
+ if(preg_match("/[\$]config[\.](.*?)/",$s,$matches)) {
+ $x = explode('.',$s);
+ if(get_config($x[1],$x[2]))
+ return true;
+ }
+ return false;
+
+ }
+
+
+ function menu($s, $class = '') {
+
+ $channel_id = $this->get_channel_id();
+ $name = $s;
+
+ $cnt = preg_match_all("/\[var=(.*?)\](.*?)\[\/var\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $var[$mtch[1]] = $mtch[2];
+ $name = str_replace($mtch[0], '', $name);
+ }
+ }
+
+ if($channel_id) {
+ $m = menu_fetch($name,$channel_id, get_observer_hash());
+ return menu_render($m, $class, $edit = false, $var);
+ }
+ }
+
+
+ function replace_region($match) {
+ if (array_key_exists($match[1], \App::$page)) {
+ return \App::$page[$match[1]];
+ }
+ }
+
+ /**
+ * @brief Returns the channel_id of the profile owner of the page.
+ *
+ * Returns the channel_id of the profile owner of the page, or the local_channel
+ * if there is no profile owner. Otherwise returns 0.
+ *
+ * @return channel_id
+ */
+
+ function get_channel_id() {
+ $channel_id = ((is_array(\App::$profile)) ? \App::$profile['profile_uid'] : 0);
+
+ if ((! $channel_id) && (local_channel()))
+ $channel_id = local_channel();
+
+ return $channel_id;
+ }
+
+ function block($s, $class = '') {
+ $var = array();
+ $matches = array();
+ $name = $s;
+ $class = (($class) ? $class : 'bblock widget');
+
+ $cnt = preg_match_all("/\[var=(.*?)\](.*?)\[\/var\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $var[$mtch[1]] = $mtch[2];
+ $name = str_replace($mtch[0], '', $name);
+ }
+ }
+
+ $o = '';
+ $channel_id = $this->get_channel_id();
+
+ if($channel_id) {
+ $r = q("select * from item inner join item_id on iid = item.id and item_id.uid = item.uid and item.uid = %d and service = 'BUILDBLOCK' and sid = '%s' limit 1",
+ intval($channel_id),
+ dbesc($name)
+ );
+
+ if($r) {
+ //check for eventual menus in the block and parse them
+ $cnt = preg_match_all("/\[menu\](.*?)\[\/menu\]/ism", $r[0]['body'], $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $r[0]['body'] = str_replace($mtch[0], $this->menu(trim($mtch[1])), $r[0]['body']);
+ }
+ }
+ $cnt = preg_match_all("/\[menu=(.*?)\](.*?)\[\/menu\]/ism", $r[0]['body'], $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $r[0]['body'] = str_replace($mtch[0],$this->menu(trim($mtch[2]),$mtch[1]),$r[0]['body']);
+ }
+ }
+
+ //emit the block
+ $o .= (($var['wrap'] == 'none') ? '' : '<div class="' . $class . '">');
+
+ if($r[0]['title'] && trim($r[0]['body']) != '$content') {
+ $o .= '<h3>' . $r[0]['title'] . '</h3>';
+ }
+
+ if(trim($r[0]['body']) === '$content') {
+ $o .= \App::$page['content'];
+ }
+ else {
+ $o .= prepare_text($r[0]['body'], $r[0]['mimetype']);
+ }
+
+ $o .= (($var['wrap'] == 'none') ? '' : '</div>');
+ }
+ }
+
+ return $o;
+ }
+
+ function js($s) {
+
+ switch($s) {
+ case 'jquery':
+ $path = 'view/js/jquery.js';
+ break;
+ case 'bootstrap':
+ $path = 'library/bootstrap/js/bootstrap.min.js';
+ break;
+ case 'foundation':
+ $path = 'library/foundation/js/foundation.min.js';
+ $init = "\r\n" . '<script>$(document).ready(function() { $(document).foundation(); });</script>';
+ break;
+ }
+
+ $ret = '<script src="' . z_root() . '/' . $path . '" ></script>';
+ if($init)
+ $ret .= $init;
+
+ return $ret;
+
+ }
+
+ function css($s) {
+
+ switch($s) {
+ case 'bootstrap':
+ $path = 'library/bootstrap/css/bootstrap.min.css';
+ break;
+ case 'foundation':
+ $path = 'library/foundation/css/foundation.min.css';
+ break;
+ }
+
+ $ret = '<link rel="stylesheet" href="' . z_root() . '/' . $path . '" type="text/css" media="screen">';
+
+ return $ret;
+
+ }
+
+ // This doesn't really belong in Comanche, but it could also be argued that it is the perfect place.
+ // We need to be able to select what kind of template and decoration to use for the webpage at the heart of our content.
+ // For now we'll allow an '[authored]' element which defaults to name and date, or 'none' to remove these, and perhaps
+ // 'full' to provide a social network style profile photo.
+ // But leave it open to have richer templating options and perhaps ultimately discard this one, once we have a better idea
+ // of what template and webpage options we might desire.
+
+ function webpage(&$a,$s) {
+ $ret = array();
+ $matches = array();
+
+ $cnt = preg_match_all("/\[authored\](.*?)\[\/authored\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $ret['authored'] = $mtch[1];
+ }
+ }
+ return $ret;
+ }
+
+
+ /**
+ * Widgets will have to get any operational arguments from the session, the
+ * global app environment, or config storage until we implement argument passing
+ *
+ * @param string $name
+ * @param string $text
+ */
+ function widget($name, $text) {
+ $vars = array();
+ $matches = array();
+
+
+ $cnt = preg_match_all("/\[var=(.*?)\](.*?)\[\/var\]/ism", $text, $matches, PREG_SET_ORDER);
+ if ($cnt) {
+ foreach ($matches as $mtch) {
+ $vars[$mtch[1]] = $mtch[2];
+ }
+ }
+
+ $func = 'widget_' . trim($name);
+
+ if(! function_exists($func)) {
+ if(file_exists('widget/' . trim($name) . '.php'))
+ require_once('widget/' . trim($name) . '.php');
+ elseif(file_exists('widget/' . trim($name) . '/' . trim($name) . '.php'))
+ require_once('widget/' . trim($name) . '/' . trim($name) . '.php');
+ }
+ else {
+ $theme_widget = $func . '.php';
+ if((! function_exists($func)) && theme_include($theme_widget))
+ require_once(theme_include($theme_widget));
+ }
+
+ if (function_exists($func))
+ return $func($vars);
+ }
+
+
+ function region($s) {
+
+ $matches = array();
+
+ $cnt = preg_match_all("/\[menu\](.*?)\[\/menu\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $s = str_replace($mtch[0], $this->menu(trim($mtch[1])), $s);
+ }
+ }
+
+ // menu class e.g. [menu=horizontal]my_menu[/menu] or [menu=tabbed]my_menu[/menu]
+ // allows different menu renderings to be applied
+
+ $cnt = preg_match_all("/\[menu=(.*?)\](.*?)\[\/menu\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $s = str_replace($mtch[0],$this->menu(trim($mtch[2]),$mtch[1]),$s);
+ }
+ }
+ $cnt = preg_match_all("/\[block\](.*?)\[\/block\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $s = str_replace($mtch[0],$this->block(trim($mtch[1])),$s);
+ }
+ }
+
+ $cnt = preg_match_all("/\[block=(.*?)\](.*?)\[\/block\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $s = str_replace($mtch[0],$this->block(trim($mtch[2]),trim($mtch[1])),$s);
+ }
+ }
+
+ $cnt = preg_match_all("/\[js\](.*?)\[\/js\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $s = str_replace($mtch[0],$this->js(trim($mtch[1])),$s);
+ }
+ }
+
+ $cnt = preg_match_all("/\[css\](.*?)\[\/css\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $s = str_replace($mtch[0],$this->css(trim($mtch[1])),$s);
+ }
+ }
+ // need to modify this to accept parameters
+
+ $cnt = preg_match_all("/\[widget=(.*?)\](.*?)\[\/widget\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $s = str_replace($mtch[0],$this->widget(trim($mtch[1]),$mtch[2]),$s);
+ }
+ }
+
+ return $s;
+ }
+
+
+ /*
+ * @function register_page_template($arr)
+ * Registers a page template/variant for use by Comanche selectors
+ * @param array $arr
+ * 'template' => template name
+ * 'variant' => array(
+ * 'name' => variant name
+ * 'desc' => text description
+ * 'regions' => array(
+ * 'name' => name
+ * 'desc' => text description
+ * )
+ * )
+ */
+
+
+ function register_page_template($arr) {
+ \App::$page_layouts[$arr['template']] = array($arr['variant']);
+ return;
+ }
+
+} \ No newline at end of file
diff --git a/boot.php b/boot.php
index dab90f0a1..bc92778d4 100755
--- a/boot.php
+++ b/boot.php
@@ -724,6 +724,7 @@ class App {
public static $nav_sel;
public static $is_mobile = false;
public static $is_tablet = false;
+ public static $comanche;
public static $category;
@@ -2111,7 +2112,10 @@ function get_custom_nav(&$a, $navname) {
* @param App &$a global application object
*/
function load_pdl(&$a) {
- require_once('include/comanche.php');
+
+ App::$comanche = new Zotlabs\Render\Comanche();
+
+ // require_once('include/comanche.php');
if (! count(App::$layout)) {
@@ -2120,7 +2124,7 @@ function load_pdl(&$a) {
$layout = $arr['layout'];
$n = 'mod_' . App::$module . '.pdl' ;
- $u = comanche_get_channel_id();
+ $u = App::$comanche->get_channel_id();
if($u)
$s = get_pconfig($u, 'system', $n);
if(! $s)
@@ -2129,7 +2133,7 @@ function load_pdl(&$a) {
if((! $s) && (($p = theme_include($n)) != ''))
$s = @file_get_contents($p);
if($s) {
- comanche_parser($a, $s);
+ App::$comanche->parse($s);
App::$pdl = $s;
}
}
@@ -2138,10 +2142,10 @@ function load_pdl(&$a) {
function exec_pdl(&$a) {
- require_once('include/comanche.php');
+// require_once('include/comanche.php');
if(App::$pdl) {
- comanche_parser($a, App::$pdl,1);
+ App::$comanche->parse(App::$pdl,1);
}
}
@@ -2196,7 +2200,7 @@ function construct_page(&$a) {
App::build_pagehead();
if(App::$page['pdl_content']) {
- App::$page['content'] = comanche_region($a,App::$page['content']);
+ App::$page['content'] = App::$comanche->region(App::$page['content']);
}
// Let's say we have a comanche declaration '[region=nav][/region][region=content]$nav $content[/region]'.
@@ -2217,7 +2221,7 @@ function construct_page(&$a) {
foreach(App::$layout as $k => $v) {
if((strpos($k, 'region_') === 0) && strlen($v)) {
if(strpos($v, '$region_') !== false) {
- $v = preg_replace_callback('/\$region_([a-zA-Z0-9]+)/ism', 'comanche_replace_region', $v);
+ $v = preg_replace_callback('/\$region_([a-zA-Z0-9]+)/ism', array(App::$comanche,'replace_region'), $v);
}
// And a couple of convenience macros
diff --git a/include/comanche.php b/include/comanche.php
deleted file mode 100644
index 97d5d665a..000000000
--- a/include/comanche.php
+++ /dev/null
@@ -1,422 +0,0 @@
-<?php /** @file */
-
-require_once('include/security.php');
-require_once('include/menu.php');
-require_once('include/widgets.php');
-
-// When editing a webpage - a dropdown is needed to select a page layout
-// On submit, the pdl_select value (which is the mid of an item with item_type = ITEM_TYPE_PDL) is stored in
-// the webpage's resource_id, with resource_type 'pdl'.
-
-// Then when displaying a webpage, we can see if it has a pdl attached. If not we'll
-// use the default site/page layout.
-
-// If it has a pdl we'll load it as we know the mid and pass the body through comanche_parser() which will generate the
-// page layout from the given description
-
-
-function pdl_selector($uid, $current="") {
- $o = '';
-
- $sql_extra = item_permissions_sql($uid);
-
- $r = q("select item_id.*, mid from item_id left join item on iid = item.id where item_id.uid = %d and item_id.uid = item.uid and service = 'PDL' $sql_extra order by sid asc",
- intval($uid)
- );
-
- $arr = array('channel_id' => $uid, 'current' => $current, 'entries' => $r);
- call_hooks('pdl_selector',$arr);
-
- $entries = $arr['entries'];
- $current = $arr['current'];
-
- $o .= '<select name="pdl_select" id="pdl_select" size="1">';
- $entries[] = array('title' => t('Default'), 'mid' => '');
- foreach($entries as $selection) {
- $selected = (($selection == $current) ? ' selected="selected" ' : '');
- $o .= "<option value=\"{$selection['mid']}\" $selected >{$selection['sid']}</option>";
- }
-
- $o .= '</select>';
- return $o;
-}
-
-
-
-function comanche_parser(&$a, $s, $pass = 0) {
- $matches = array();
-
- $cnt = preg_match_all("/\[comment\](.*?)\[\/comment\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $s = str_replace($mtch[0], '', $s);
- }
- }
-
- $cnt = preg_match_all("/\[if (.*?)\](.*?)\[else\](.*?)\[\/if\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- if(comanche_test_condition($mtch[1])) {
- $s = str_replace($mtch[0], $mtch[2], $s);
- }
- else {
- $s = str_replace($mtch[0], $mtch[3], $s);
- }
- }
- }
- else {
- $cnt = preg_match_all("/\[if (.*?)\](.*?)\[\/if\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- if(comanche_test_condition($mtch[1])) {
- $s = str_replace($mtch[0], $mtch[2], $s);
- }
- else {
- $s = str_replace($mtch[0], '', $s);
- }
- }
- }
- }
-
- if($pass == 0) {
- $cnt = preg_match("/\[layout\](.*?)\[\/layout\]/ism", $s, $matches);
- if($cnt)
- App::$page['template'] = trim($matches[1]);
-
- $cnt = preg_match("/\[template=(.*?)\](.*?)\[\/template\]/ism", $s, $matches);
- if($cnt) {
- App::$page['template'] = trim($matches[2]);
- App::$page['template_style'] = trim($matches[2]) . '_' . $matches[1];
- }
-
- $cnt = preg_match("/\[template\](.*?)\[\/template\]/ism", $s, $matches);
- if($cnt) {
- App::$page['template'] = trim($matches[1]);
- }
-
- $cnt = preg_match("/\[theme=(.*?)\](.*?)\[\/theme\]/ism", $s, $matches);
- if($cnt) {
- App::$layout['schema'] = trim($matches[1]);
- App::$layout['theme'] = trim($matches[2]);
- }
-
- $cnt = preg_match("/\[theme\](.*?)\[\/theme\]/ism", $s, $matches);
- if($cnt)
- App::$layout['theme'] = trim($matches[1]);
-
- $cnt = preg_match_all("/\[webpage\](.*?)\[\/webpage\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- // only the last webpage definition is used if there is more than one
- foreach($matches as $mtch) {
- App::$layout['webpage'] = comanche_webpage($a,$mtch[1]);
- }
- }
- }
- else {
- $cnt = preg_match_all("/\[region=(.*?)\](.*?)\[\/region\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- App::$layout['region_' . $mtch[1]] = comanche_region($a,$mtch[2]);
- }
- }
-
- }
-
-}
-
-function comanche_test_condition($s) {
-
- // This is extensible. The first version of variable testing supports tests of the form
- // [if $config.system.foo] which will check for a return of a true condition for get_config('system','foo');
- // The values 0, '', an empty array, and an unset value will all evaluate to false.
-
- if(preg_match("/[\$]config[\.](.*?)/",$s,$matches)) {
- $x = explode('.',$s);
- if(get_config($x[1],$x[2]))
- return true;
- }
- return false;
-
-}
-
-
-function comanche_menu($s, $class = '') {
-
- $channel_id = comanche_get_channel_id();
- $name = $s;
-
- $cnt = preg_match_all("/\[var=(.*?)\](.*?)\[\/var\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $var[$mtch[1]] = $mtch[2];
- $name = str_replace($mtch[0], '', $name);
- }
- }
-
- if($channel_id) {
- $m = menu_fetch($name,$channel_id, get_observer_hash());
- return menu_render($m, $class, $edit = false, $var);
- }
-}
-
-function comanche_replace_region($match) {
- $a = get_app();
- if (array_key_exists($match[1], App::$page)) {
- return App::$page[$match[1]];
- }
-}
-
-/**
- * @brief Returns the channel_id of the profile owner of the page.
- *
- * Returns the channel_id of the profile owner of the page, or the local_channel
- * if there is no profile owner. Otherwise returns 0.
- *
- * @return channel_id
- */
-function comanche_get_channel_id() {
- $channel_id = ((is_array(App::$profile)) ? App::$profile['profile_uid'] : 0);
-
- if ((! $channel_id) && (local_channel()))
- $channel_id = local_channel();
-
- return $channel_id;
-}
-
-function comanche_block($s, $class = '') {
- $var = array();
- $matches = array();
- $name = $s;
- $class = (($class) ? $class : 'bblock widget');
-
- $cnt = preg_match_all("/\[var=(.*?)\](.*?)\[\/var\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $var[$mtch[1]] = $mtch[2];
- $name = str_replace($mtch[0], '', $name);
- }
- }
-
- $o = '';
- $channel_id = comanche_get_channel_id();
-
- if($channel_id) {
- $r = q("select * from item inner join item_id on iid = item.id and item_id.uid = item.uid and item.uid = %d and service = 'BUILDBLOCK' and sid = '%s' limit 1",
- intval($channel_id),
- dbesc($name)
- );
-
- if($r) {
- //check for eventual menus in the block and parse them
- $cnt = preg_match_all("/\[menu\](.*?)\[\/menu\]/ism", $r[0]['body'], $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $r[0]['body'] = str_replace($mtch[0], comanche_menu(trim($mtch[1])), $r[0]['body']);
- }
- }
- $cnt = preg_match_all("/\[menu=(.*?)\](.*?)\[\/menu\]/ism", $r[0]['body'], $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $r[0]['body'] = str_replace($mtch[0],comanche_menu(trim($mtch[2]),$mtch[1]),$r[0]['body']);
- }
- }
-
- //emit the block
- $o .= (($var['wrap'] == 'none') ? '' : '<div class="' . $class . '">');
-
- if($r[0]['title'] && trim($r[0]['body']) != '$content') {
- $o .= '<h3>' . $r[0]['title'] . '</h3>';
- }
-
- if(trim($r[0]['body']) === '$content') {
- $o .= App::$page['content'];
- }
- else {
- $o .= prepare_text($r[0]['body'], $r[0]['mimetype']);
- }
-
- $o .= (($var['wrap'] == 'none') ? '' : '</div>');
- }
- }
-
- return $o;
-}
-
-function comanche_js($s) {
-
- switch($s) {
- case 'jquery':
- $path = 'view/js/jquery.js';
- break;
- case 'bootstrap':
- $path = 'library/bootstrap/js/bootstrap.min.js';
- break;
- case 'foundation':
- $path = 'library/foundation/js/foundation.min.js';
- $init = "\r\n" . '<script>$(document).ready(function() { $(document).foundation(); });</script>';
- break;
- }
-
- $ret = '<script src="' . z_root() . '/' . $path . '" ></script>';
- if($init)
- $ret .= $init;
-
- return $ret;
-
-}
-
-function comanche_css($s) {
-
- switch($s) {
- case 'bootstrap':
- $path = 'library/bootstrap/css/bootstrap.min.css';
- break;
- case 'foundation':
- $path = 'library/foundation/css/foundation.min.css';
- break;
- }
-
- $ret = '<link rel="stylesheet" href="' . z_root() . '/' . $path . '" type="text/css" media="screen">';
-
- return $ret;
-
-}
-
-// This doesn't really belong in Comanche, but it could also be argued that it is the perfect place.
-// We need to be able to select what kind of template and decoration to use for the webpage at the heart of our content.
-// For now we'll allow an '[authored]' element which defaults to name and date, or 'none' to remove these, and perhaps
-// 'full' to provide a social network style profile photo.
-// But leave it open to have richer templating options and perhaps ultimately discard this one, once we have a better idea
-// of what template and webpage options we might desire.
-
-function comanche_webpage(&$a,$s) {
- $ret = array();
- $matches = array();
-
- $cnt = preg_match_all("/\[authored\](.*?)\[\/authored\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $ret['authored'] = $mtch[1];
- }
- }
- return $ret;
-}
-
-
-/**
- * Widgets will have to get any operational arguments from the session, the
- * global app environment, or config storage until we implement argument passing
- *
- * @param string $name
- * @param string $text
- */
-function comanche_widget($name, $text) {
- $vars = array();
- $matches = array();
-
-
- $cnt = preg_match_all("/\[var=(.*?)\](.*?)\[\/var\]/ism", $text, $matches, PREG_SET_ORDER);
- if ($cnt) {
- foreach ($matches as $mtch) {
- $vars[$mtch[1]] = $mtch[2];
- }
- }
-
- $func = 'widget_' . trim($name);
-
- if(! function_exists($func)) {
- if(file_exists('widget/' . trim($name) . '.php'))
- require_once('widget/' . trim($name) . '.php');
- elseif(file_exists('widget/' . trim($name) . '/' . trim($name) . '.php'))
- require_once('widget/' . trim($name) . '/' . trim($name) . '.php');
- }
- else {
- $theme_widget = $func . '.php';
- if((! function_exists($func)) && theme_include($theme_widget))
- require_once(theme_include($theme_widget));
- }
-
- if (function_exists($func))
- return $func($vars);
-}
-
-
-function comanche_region(&$a, $s) {
- $matches = array();
-
- $cnt = preg_match_all("/\[menu\](.*?)\[\/menu\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $s = str_replace($mtch[0], comanche_menu(trim($mtch[1])), $s);
- }
- }
-
- // menu class e.g. [menu=horizontal]my_menu[/menu] or [menu=tabbed]my_menu[/menu]
- // allows different menu renderings to be applied
-
- $cnt = preg_match_all("/\[menu=(.*?)\](.*?)\[\/menu\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $s = str_replace($mtch[0],comanche_menu(trim($mtch[2]),$mtch[1]),$s);
- }
- }
- $cnt = preg_match_all("/\[block\](.*?)\[\/block\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $s = str_replace($mtch[0],comanche_block(trim($mtch[1])),$s);
- }
- }
-
- $cnt = preg_match_all("/\[block=(.*?)\](.*?)\[\/block\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $s = str_replace($mtch[0],comanche_block(trim($mtch[2]),trim($mtch[1])),$s);
- }
- }
-
- $cnt = preg_match_all("/\[js\](.*?)\[\/js\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $s = str_replace($mtch[0],comanche_js(trim($mtch[1])),$s);
- }
- }
-
- $cnt = preg_match_all("/\[css\](.*?)\[\/css\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $s = str_replace($mtch[0],comanche_css(trim($mtch[1])),$s);
- }
- }
- // need to modify this to accept parameters
-
- $cnt = preg_match_all("/\[widget=(.*?)\](.*?)\[\/widget\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $s = str_replace($mtch[0],comanche_widget(trim($mtch[1]),$mtch[2]),$s);
- }
- }
-
- return $s;
-}
-
-
-/*
- * @function register_page_template($arr)
- * Registers a page template/variant for use by Comanche selectors
- * @param array $arr
- * 'template' => template name
- * 'variant' => array(
- * 'name' => variant name
- * 'desc' => text description
- * 'regions' => array(
- * 'name' => name
- * 'desc' => text description
- * )
- * )
- */
-
-
-function register_page_template($arr) {
- App::$page_layouts[$arr['template']] = array($arr['variant']);
- return;
-}
diff --git a/include/text.php b/include/text.php
index 66a49d4b5..a3826de49 100644
--- a/include/text.php
+++ b/include/text.php
@@ -2824,3 +2824,42 @@ function expand_acl($s) {
return $ret;
}
+
+
+// When editing a webpage - a dropdown is needed to select a page layout
+// On submit, the pdl_select value (which is the mid of an item with item_type = ITEM_TYPE_PDL) is stored in
+// the webpage's resource_id, with resource_type 'pdl'.
+
+// Then when displaying a webpage, we can see if it has a pdl attached. If not we'll
+// use the default site/page layout.
+
+// If it has a pdl we'll load it as we know the mid and pass the body through comanche_parser() which will generate the
+// page layout from the given description
+
+
+function pdl_selector($uid, $current="") {
+ $o = '';
+
+ $sql_extra = item_permissions_sql($uid);
+
+ $r = q("select item_id.*, mid from item_id left join item on iid = item.id where item_id.uid = %d and item_id.uid = item.uid and service = 'PDL' $sql_extra order by sid asc",
+ intval($uid)
+ );
+
+ $arr = array('channel_id' => $uid, 'current' => $current, 'entries' => $r);
+ call_hooks('pdl_selector',$arr);
+
+ $entries = $arr['entries'];
+ $current = $arr['current'];
+
+ $o .= '<select name="pdl_select" id="pdl_select" size="1">';
+ $entries[] = array('title' => t('Default'), 'mid' => '');
+ foreach($entries as $selection) {
+ $selected = (($selection == $current) ? ' selected="selected" ' : '');
+ $o .= "<option value=\"{$selection['mid']}\" $selected >{$selection['sid']}</option>";
+ }
+
+ $o .= '</select>';
+ return $o;
+}
+