aboutsummaryrefslogtreecommitdiffstats
path: root/include/comanche.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/comanche.php')
-rw-r--r--include/comanche.php167
1 files changed, 95 insertions, 72 deletions
diff --git a/include/comanche.php b/include/comanche.php
index b181d415a..e0d3af985 100644
--- a/include/comanche.php
+++ b/include/comanche.php
@@ -15,23 +15,22 @@ require_once('include/widgets.php');
// page layout from the given description
-function pdl_selector($uid,$current="") {
-
+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' order by sid asc",
- intval($owner)
+ $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\" >";
+ $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" ' : '');
@@ -40,109 +39,131 @@ function pdl_selector($uid,$current="") {
$o .= '</select>';
return $o;
-}
+}
-function comanche_parser(&$a,$s) {
+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);
+ $s = str_replace($mtch[0], '', $s);
}
}
- $cnt = preg_match("/\[layout\](.*?)\[\/layout\]/ism", $s, $matches);
- if($cnt)
- $a->page['template'] = trim($matches[1]);
+ if($pass == 0) {
+ $cnt = preg_match("/\[layout\](.*?)\[\/layout\]/ism", $s, $matches);
+ if($cnt)
+ $a->page['template'] = trim($matches[1]);
- $cnt = preg_match("/\[template=(.*?)\](.*?)\[\/template\]/ism", $s, $matches);
- if($cnt) {
- $a->page['template'] = trim($matches[2]);
- $a->page['template_style'] = trim($matches[2]) . '_' . $matches[1];
- }
+ $cnt = preg_match("/\[template=(.*?)\](.*?)\[\/template\]/ism", $s, $matches);
+ if($cnt) {
+ $a->page['template'] = trim($matches[2]);
+ $a->page['template_style'] = trim($matches[2]) . '_' . $matches[1];
+ }
- $cnt = preg_match("/\[template\](.*?)\[\/template\]/ism", $s, $matches);
- if($cnt) {
- $a->page['template'] = trim($matches[1]);
- }
+ $cnt = preg_match("/\[template\](.*?)\[\/template\]/ism", $s, $matches);
+ if($cnt) {
+ $a->page['template'] = trim($matches[1]);
+ }
- $cnt = preg_match("/\[theme=(.*?)\](.*?)\[\/theme\]/ism", $s, $matches);
- if($cnt) {
- $a->layout['schema'] = trim($matches[1]);
- $a->layout['theme'] = trim($matches[2]);
- }
+ $cnt = preg_match("/\[theme=(.*?)\](.*?)\[\/theme\]/ism", $s, $matches);
+ if($cnt) {
+ $a->layout['schema'] = trim($matches[1]);
+ $a->layout['theme'] = trim($matches[2]);
+ }
- $cnt = preg_match("/\[theme\](.*?)\[\/theme\]/ism", $s, $matches);
- if($cnt)
- $a->layout['theme'] = trim($matches[1]);
+ $cnt = preg_match("/\[theme\](.*?)\[\/theme\]/ism", $s, $matches);
+ if($cnt)
+ $a->layout['theme'] = trim($matches[1]);
- $cnt = preg_match_all("/\[region=(.*?)\](.*?)\[\/region\]/ism", $s, $matches, PREG_SET_ORDER);
- if($cnt) {
- foreach($matches as $mtch) {
- $a->layout['region_' . $mtch[1]] = comanche_region($a,$mtch[2]);
+ $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) {
+ $a->layout['webpage'] = comanche_webpage($a,$mtch[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) {
- $a->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) {
+ $a->layout['region_' . $mtch[1]] = comanche_region($a,$mtch[2]);
+ }
}
+
}
}
-function comanche_menu($name,$class = '') {
+function comanche_menu($name, $class = '') {
$channel_id = comanche_get_channel_id();
if($channel_id) {
- $m = menu_fetch($name,$channel_id,get_observer_hash());
- return menu_render($m,$class);
+ $m = menu_fetch($name,$channel_id, get_observer_hash());
+ return menu_render($m, $class);
}
}
function comanche_replace_region($match) {
$a = get_app();
- if(array_key_exists($match[1],$a->page)) {
+ if (array_key_exists($match[1], $a->page)) {
return $a->page[$match[1]];
}
}
/**
- * @function comanche_get_channel_id()
- * Returns the channel_id of the profile owner of the page, or the local_channel if there is no profile owner.
- * Otherwise returns 0
- */
-
+ * @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(get_app()->profile)) ? get_app()->profile['profile_uid'] : 0);
- if((! $channel_id) && (local_channel()))
+
+ if ((! $channel_id) && (local_channel()))
$channel_id = local_channel();
+
return $channel_id;
}
-function comanche_block($name) {
+function comanche_block($s) {
+ $var = array();
+ $matches = array();
+ $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);
+ }
+ }
+
+ $o = '';
$channel_id = comanche_get_channel_id();
-
+
if($channel_id) {
- $o = '';
$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) {
- $o = '<div class="widget bblock">';
+ $o .= (($var['wrap'] == 'none') ? '' : '<div class="bblock">');
if($r[0]['title'])
$o .= '<h3>' . $r[0]['title'] . '</h3>';
- $o .= prepare_text($r[0]['body'],$r[0]['mimetype']);
- $o .= '</div>';
+ $o .= prepare_text($r[0]['body'], $r[0]['mimetype']);
+ $o .= (($var['wrap'] == 'none') ? '' : '</div>');
}
}
+
return $o;
}
@@ -154,8 +175,9 @@ function comanche_block($name) {
// 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) {
@@ -166,32 +188,37 @@ function comanche_webpage(&$a,$s) {
}
-// Widgets will have to get any operational arguments from the session,
-// the global app environment, or config storage until we implement argument passing
-
-
-function comanche_widget($name,$text) {
- $a = get_app();
+/**
+ * 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) {
+ if ($cnt) {
+ foreach ($matches as $mtch) {
$vars[$mtch[1]] = $mtch[2];
}
}
$func = 'widget_' . trim($name);
- if(function_exists($func))
+ if (function_exists($func))
return $func($vars);
}
-function comanche_region(&$a,$s) {
+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);
+ $s = str_replace($mtch[0], comanche_menu(trim($mtch[1])), $s);
}
}
@@ -244,7 +271,3 @@ function register_page_template($arr) {
get_app()->page_layouts[$arr['template']] = array($arr['variant']);
return;
}
-
-
-
-