aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-12-09 21:20:55 -0800
committerfriendica <info@friendica.com>2013-12-09 21:20:55 -0800
commited9f10872240231125007cf32b95007281558cac (patch)
tree06686896c308c5ad30becb62f3e236b311ab238b /include
parent251720bfd32541901b9e845651dbc037b34065e2 (diff)
downloadvolse-hubzilla-ed9f10872240231125007cf32b95007281558cac.tar.gz
volse-hubzilla-ed9f10872240231125007cf32b95007281558cac.tar.bz2
volse-hubzilla-ed9f10872240231125007cf32b95007281558cac.zip
comanchify the savedsearch widget
Diffstat (limited to 'include')
-rwxr-xr-xinclude/text.php14
-rw-r--r--include/widgets.php83
2 files changed, 97 insertions, 0 deletions
diff --git a/include/text.php b/include/text.php
index f425690ba..aa23f96b0 100755
--- a/include/text.php
+++ b/include/text.php
@@ -741,6 +741,20 @@ function search($s,$id='search-box',$url='/search',$save = false) {
}
+function searchbox($s,$id='search-box',$url='/search',$save = false) {
+ $a = get_app();
+ $o = '<div id="' . $id . '">';
+ $o .= '<form action="' . z_root() . '/' . $url . '" method="get" >';
+ $o .= '<input type="hidden" name="f" value="" />';
+ $o .= '<input type="text" class="icon-search" name="search" id="search-text" placeholder="&#xf002;" value="' . $s .'" onclick="this.submit();" />';
+ $o .= '<input type="submit" name="submit" id="search-submit" value="' . t('Search') . '" />';
+ if(feature_enabled(local_user(),'savedsearch'))
+ $o .= '<input type="submit" name="searchsave" id="search-save" value="' . t('Save') . '" />';
+ $o .= '</form></div>';
+ return $o;
+}
+
+
function valid_email($x){
if(get_config('system','disable_email_validation'))
diff --git a/include/widgets.php b/include/widgets.php
index 3534c3978..e64920cdc 100644
--- a/include/widgets.php
+++ b/include/widgets.php
@@ -152,3 +152,86 @@ function widget_notes($arr) {
));
return $o;
}
+
+
+function widget_savedsearch($arr) {
+ if((! local_user()) || (! feature_enabled(local_user(),'savedsearch')))
+ return '';
+
+ $a = get_app();
+
+ $search = ((x($_GET,'search')) ? $_GET['search'] : '');
+
+ if(x($_GET,'searchsave') && $search) {
+ $r = q("select * from `term` where `uid` = %d and `type` = %d and `term` = '%s' limit 1",
+ intval(local_user()),
+ intval(TERM_SAVEDSEARCH),
+ dbesc($search)
+ );
+ if(! $r) {
+ q("insert into `term` ( `uid`,`type`,`term` ) values ( %d, %d, '%s') ",
+ intval(local_user()),
+ intval(TERM_SAVEDSEARCH),
+ dbesc($search)
+ );
+ }
+ }
+
+ if(x($_GET,'searchremove') && $search) {
+ q("delete from `term` where `uid` = %d and `type` = %d and `term` = '%s' limit 1",
+ intval(local_user()),
+ intval(TERM_SAVEDSEARCH),
+ dbesc($search)
+ );
+ $search = '';
+ }
+
+
+
+ $srchurl = $a->query_string;
+
+ $srchurl = rtrim(preg_replace('/searchsave\=[^\&].*?(\&|$)/is','',$srchurl),'&');
+ $hasq = ((strpos($srchurl,'?') !== false) ? true : false);
+ $srchurl = rtrim(preg_replace('/searchremove\=[^\&].*?(\&|$)/is','',$srchurl),'&');
+ $hasq = ((strpos($srchurl,'?') !== false) ? true : false);
+
+ $srchurl = rtrim(preg_replace('/search\=[^\&].*?(\&|$)/is','',$srchurl),'&');
+ $hasq = ((strpos($srchurl,'?') !== false) ? true : false);
+
+ $o = '';
+
+ $r = q("select `tid`,`term` from `term` WHERE `uid` = %d and `type` = %d ",
+ intval(local_user()),
+ intval(TERM_SAVEDSEARCH)
+ );
+
+ $saved = array();
+
+ if(count($r)) {
+ foreach($r as $rr) {
+
+ $saved[] = array(
+ 'id' => $rr['tid'],
+ 'term' => $rr['term'],
+ 'dellink' => z_root() . '/' . $srchurl . (($hasq) ? '' : '?f=') . '&amp;searchremove=1&amp;search=' . urlencode($rr['term']),
+ 'srchlink' => z_root() . '/' . $srchurl . (($hasq) ? '' : '?f=') . '&amp;search=' . urlencode($rr['term']),
+ 'displayterm' => htmlspecialchars($rr['term']),
+ 'encodedterm' => urlencode($rr['term']),
+ 'delete' => t('Remove term'),
+ 'selected' => ($search==$rr['term']),
+ );
+ }
+ }
+
+
+ $tpl = get_markup_template("saved_searches.tpl");
+ $o = replace_macros($tpl, array(
+ '$title' => t('Saved Searches'),
+ '$add' => t('add'),
+ '$searchbox' => searchbox('','netsearch-box',$srchurl . (($hasq) ? '' : '?f='),true),
+ '$saved' => $saved,
+ ));
+
+ return $o;
+
+}