diff options
Diffstat (limited to 'include/comanche.php')
-rw-r--r-- | include/comanche.php | 75 |
1 files changed, 60 insertions, 15 deletions
diff --git a/include/comanche.php b/include/comanche.php index cf7ecd7c5..56a16fd3b 100644 --- a/include/comanche.php +++ b/include/comanche.php @@ -17,16 +17,10 @@ function pdl_selector($uid,$current="") { $o = ''; - // You can use anybody's Comanche layouts on this site that haven't been protected in some way - $sql_extra = item_permissions_sql($uid); - // By default order by title (therefore at this time pdl's need a unique title across this system), - // though future work may allow categorisation - // based on taxonomy terms - - $r = q("select title, mid from item where (item_restrict & %d) $sql_extra order by title", - intval(ITEM_PDL) + $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) ); $arr = array('channel_id' => $uid, 'current' => $current, 'entries' => $r); @@ -39,7 +33,7 @@ function pdl_selector($uid,$current="") { $entries[] = array('title' => t('Default'), 'mid' => ''); foreach($entries as $selection) { $selected = (($selection == $current) ? ' selected="selected" ' : ''); - $o .= "<option value=\"{$selection['mid']}\" $selected >{$selection['title']}</option>"; + $o .= "<option value=\"{$selection['mid']}\" $selected >{$selection['sid']}</option>"; } $o .= '</select>'; @@ -51,21 +45,29 @@ function pdl_selector($uid,$current="") { function comanche_parser(&$a,$s) { - $cnt = preg_match("/\[layout\](.*?)\[\/layout\]/ism", $matches, $s); + $cnt = preg_match("/\[layout\](.*?)\[\/layout\]/ism", $s, $matches); if($cnt) $a->page['template'] = trim($matches[1]); - $cnt = preg_match("/\[theme\](.*?)\[\/theme\]/ism", $matches, $s); + $cnt = preg_match("/\[theme\](.*?)\[\/theme\]/ism", $s, $matches); if($cnt) $a->layout['theme'] = trim($matches[1]); - $cnt = preg_match_all("/\[region=(.*?)\](.*?)\[\/region\]/ism", $matches, $s, PREG_SET_ORDER); + $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]); + } + } + } @@ -77,10 +79,47 @@ function comanche_menu($name) { 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_block($name) { + $o = ''; + $r = q("select * from item left join item_id on iid = item_id and item_id.uid = item.uid and service = 'BUILDBLOCK' and sid = '%s' limit 1", + dbesc($name) + ); + if($r) { + $o = '<div class="widget bblock">'; + if($r[0]['title']) + $o .= '<h3>' . $r[0]['title'] . '</h3>'; + $o .= prepare_text($r[0]['body'],$r[0]['mimetype']); + $o .= '</div>'; + + } + return $o; +} + +// 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(); + $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 @@ -96,16 +135,22 @@ function comanche_widget($name,$args = null) { function comanche_region(&$a,$s) { - $cnt = preg_match_all("/\[menu\](.*?)\[\/menu\]/ism", $matches, $s, PREG_SET_ORDER); + $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); } } + $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); + } + } // need to modify this to accept parameters - $cnt = preg_match_all("/\[widget\](.*?)\[\/widget\]/ism", $matches, $s, PREG_SET_ORDER); + $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])),$s); |