straighten out some directory stuff, which required some Comanche structural changes

This commit is contained in:
friendica 2015-03-05 18:24:49 -08:00
parent e73d0ee418
commit 22391a2437
7 changed files with 110 additions and 43 deletions

View file

@ -654,7 +654,7 @@ class App {
public $profile_uid = 0; // If applicable, the channel_id of the "page owner"
public $poi = null; // "person of interest", generally a referenced connection
public $layout = array(); // Comanche parsed template
public $pdl = null;
private $perms = null; // observer permissions
private $widgets = array(); // widgets for this page
//private $widgetlist = null; // widget ordering and inclusion directives
@ -2047,11 +2047,24 @@ function load_pdl(&$a) {
if((! $s) && (($p = theme_include($n)) != ''))
$s = @file_get_contents($p);
if($s)
if($s) {
comanche_parser($a, $s);
$a->pdl = $s;
}
}
}
function exec_pdl(&$a) {
require_once('include/comanche.php');
if($a->pdl) {
comanche_parser($a, $a->pdl,1);
}
}
/**
* @brief build the page.
*
@ -2061,6 +2074,9 @@ function load_pdl(&$a) {
*/
function construct_page(&$a) {
exec_pdl($a);
$comanche = ((count($a->layout)) ? true : false);
require_once(theme_include('theme_init.php'));
@ -2074,6 +2090,7 @@ function construct_page(&$a) {
}
if($comanche) {
if($a->layout['nav']) {
$a->page['nav'] = get_custom_nav($a, $a->layout['nav']);
}
@ -2124,6 +2141,7 @@ function construct_page(&$a) {
call_hooks('construct_page', $arr);
$a->layout = $arr['layout'];
foreach($a->layout as $k => $v) {
if((strpos($k, 'region_') === 0) && strlen($v)) {
if(strpos($v, '$region_') !== false) {

View file

@ -43,7 +43,7 @@ function pdl_selector($uid, $current="") {
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);
@ -53,43 +53,47 @@ function comanche_parser(&$a, $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[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['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("/\[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_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("/\[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['theme'] = trim($matches[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]);
}
}
$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]);
}
}
}

View file

@ -74,7 +74,26 @@ function check_upstream_directory() {
function dir_sort_links() {
// Build urls without order and pubforums so it's easy to tack on the changed value
$safe_mode = 1;
$observer = get_observer_hash();
if ($observer)
$safe_mode = get_xconfig($observer,'directory','safe_mode');
if($safe_mode === false)
$safe_mode = 1;
if(! $safe_mode)
$toggle = t('Enable Safe Search');
else
$toggle = t('Disable Safe Search');
if($observer)
$globaldir = get_xconfig($observer,'directory','globaldir');
else
$globaldir = ((array_key_exists('globaldir',$_SESSION)) ? intval($_SESSION['globaldir']) : false);
// Build urls without order and pubforums so it's easy to tack on the changed value
// Probably there's an easier way to do this
$current_order = (($_REQUEST['order']) ? $_REQUEST['order'] : 'normal');
@ -104,7 +123,10 @@ function dir_sort_links() {
'$selected_sort' => $current_order,
'$sorturl' => $sorturl,
'$forumsurl' => $forumsurl,
'$safemode' => t('Safe Mode'),
'$toggle' => $toggle,
'$globaldir' => $globaldir,
'$localdir' => t('This Website Only'),
));
return $o;
}

View file

@ -605,9 +605,6 @@ function widget_vcard($arr) {
* The following directory widgets are only useful on the directory page
*/
function widget_dirsafemode($arr) {
return dir_safe_mode();
}
function widget_dirsort($arr) {
return dir_sort_links();

View file

@ -14,6 +14,20 @@ function directory_init(&$a) {
dbesc($_GET['ignore'])
);
}
$observer = get_observer_hash();
$global_changed = false;
if(array_key_exists('global',$_REQUEST)) {
$globaldir = intval($_REQUEST['global']);
$global_changed = true;
}
if($global_changed) {
$_SESSION['globaldir'] = $globaldir;
if($observer)
set_xconfig($observer,'directory','globaldir',$globaldir);
}
}
function directory_content(&$a) {
@ -26,6 +40,11 @@ function directory_content(&$a) {
$safe_mode = 1;
$observer = get_observer_hash();
if($observer)
$globaldir = get_xconfig($observer,'directory','globaldir');
else
$globaldir = ((array_key_exists('globaldir',$_SESSION)) ? intval($_SESSION['globaldir']) : false);
if($observer) {
$safe_mode = get_xconfig($observer,'directory','safe_mode');
@ -120,6 +139,9 @@ function directory_content(&$a) {
if($token)
$query .= '&t=' . $token;
if(! $globaldir)
$query .= '&hub=' . get_app()->get_hostname();
if($search)
$query .= '&name=' . urlencode($search) . '&keywords=' . urlencode($search);
if(strpos($search,'@'))

View file

@ -1,6 +1,5 @@
[region=aside]
[widget=findpeople][/widget]
[widget=dirsafemode][/widget]
[widget=dirsort][/widget]
[widget=dirtags][/widget]
[widget=suggestions][/widget]

View file

@ -1,5 +1,8 @@
<div class="widget" id="dir_sort_links">
<h3>{{$header}}</h3>
<ul class="nav nav-pills nav-stacked">
<li><a href="toggle_safesearch">{{$toggle}}</a></li>
</ul>
{{$sort}}: <select onchange='window.location.href="{{$sorturl}}&order="+this.value'>
<option value='normal' {{if $selected_sort == 'normal'}}selected='selected'{{/if}}>{{$normal}}</option>
<option value='reverse' {{if $selected_sort == 'reverse'}}selected='selected'{{/if}}>{{$reverse}}</option>
@ -7,4 +10,6 @@
<option value='reversedate' {{if $selected_sort == 'reversedate'}}selected='selected'{{/if}}>{{$reversedate}}</option>
</select><br />
<input type='checkbox' {{if $pubforumsonly}}checked='checked'{{/if}} onchange='window.location.href="{{$forumsurl}}&pubforums="+(this.checked ? 1 : 0)'/> {{$pubforums}}<br />
<input type='checkbox' {{if $globaldir}}{{else}}checked='checked'{{/if}} onchange='window.location.href="{{$forumsurl}}&global="+(this.checked ? 0 : 1)'/> {{$localdir}}<br />
</div>