From 22391a24378cae317cdf62dc4be4b31b68e8191f Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 5 Mar 2015 18:24:49 -0800 Subject: straighten out some directory stuff, which required some Comanche structural changes --- boot.php | 22 +++++++++++++-- include/comanche.php | 66 ++++++++++++++++++++++++--------------------- include/dir_fns.php | 26 ++++++++++++++++-- include/widgets.php | 3 --- mod/directory.php | 22 +++++++++++++++ view/pdl/mod_directory.pdl | 1 - view/tpl/dir_sort_links.tpl | 5 ++++ 7 files changed, 106 insertions(+), 39 deletions(-) diff --git a/boot.php b/boot.php index 5f8dd20fd..d89b1bd41 100755 --- a/boot.php +++ b/boot.php @@ -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) { diff --git a/include/comanche.php b/include/comanche.php index e8d3ca5a1..1ddabb693 100644 --- a/include/comanche.php +++ b/include/comanche.php @@ -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[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]); - } } + 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]); + $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]); + } } } diff --git a/include/dir_fns.php b/include/dir_fns.php index 37a7c04e7..468e28ae5 100644 --- a/include/dir_fns.php +++ b/include/dir_fns.php @@ -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; } diff --git a/include/widgets.php b/include/widgets.php index fbbc74224..17c740967 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -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(); diff --git a/mod/directory.php b/mod/directory.php index bc5aa41e2..dfc60b190 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -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,'@')) diff --git a/view/pdl/mod_directory.pdl b/view/pdl/mod_directory.pdl index 0bc8ed936..452ab66c7 100644 --- a/view/pdl/mod_directory.pdl +++ b/view/pdl/mod_directory.pdl @@ -1,6 +1,5 @@ [region=aside] [widget=findpeople][/widget] -[widget=dirsafemode][/widget] [widget=dirsort][/widget] [widget=dirtags][/widget] [widget=suggestions][/widget] diff --git a/view/tpl/dir_sort_links.tpl b/view/tpl/dir_sort_links.tpl index d9ecd22c6..62cf7ff1b 100644 --- a/view/tpl/dir_sort_links.tpl +++ b/view/tpl/dir_sort_links.tpl @@ -1,5 +1,8 @@ -- cgit v1.2.3