aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--boot.php2
-rw-r--r--include/dir_fns.php3
-rw-r--r--include/zot.php111
-rw-r--r--install/database.sql1
-rw-r--r--install/update.php11
-rw-r--r--mod/directory.php74
-rw-r--r--mod/dirsearch.php116
7 files changed, 177 insertions, 141 deletions
diff --git a/boot.php b/boot.php
index bc5c19dc1..01e518535 100644
--- a/boot.php
+++ b/boot.php
@@ -16,7 +16,7 @@ require_once('include/features.php');
define ( 'FRIENDICA_PLATFORM', 'Friendica Red');
define ( 'FRIENDICA_VERSION', trim(file_get_contents('version.inc')) . 'R');
define ( 'ZOT_REVISION', 1 );
-define ( 'DB_UPDATE_VERSION', 1009 );
+define ( 'DB_UPDATE_VERSION', 1010 );
define ( 'EOL', '<br />' . "\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
diff --git a/include/dir_fns.php b/include/dir_fns.php
index 2ed9b0280..2c2694782 100644
--- a/include/dir_fns.php
+++ b/include/dir_fns.php
@@ -46,9 +46,6 @@ function syncdirs($uid) {
$r = q("delete from xprof where xprof_hash = '%s' limit 1",
dbesc($hash)
);
- $r = q("delete from xtag where xtag_hash = '%s'",
- dbesc($hash)
- );
}
}
diff --git a/include/zot.php b/include/zot.php
index 4d3817a4f..0bd575b94 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -313,12 +313,8 @@ function zot_refresh($them,$channel = null) {
$r = q("delete from xprof where xprof_hash = '%s' limit 1",
dbesc($x['hash'])
);
- $r = q("delete from xtag where xtag_hash = '%s'",
- dbesc($x['hash'])
- );
}
}
-
}
return true;
}
@@ -930,65 +926,8 @@ function process_mail_delivery($sender,$arr,$deliveries) {
}
function process_profile_delivery($sender,$arr,$deliveries) {
-
// deliveries is irrelevant
-
- $r = q("select * from xprof where xprof_hash = '%s' limit 1",
- dbesc($sender['hash'])
- );
- if(! $r) {
- $x = q("insert into xprof ( xprof_hash, xprof_desc, xprof_dob, xprof_gender, xprof_marital, xprof_sexual,
- xprof_locale, xprof_region, xprof_postcode, xprof_country ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
- dbesc($sender['hash']),
- dbesc($arr['desc']),
- dbesc($arr['dob']),
- dbesc($arr['gender']),
- dbesc($arr['marital']),
- dbesc($arr['sexual']),
- dbesc($arr['locale']),
- dbesc($arr['region']),
- dbesc($arr['postcode']),
- dbesc($arr['country'])
- );
- }
- else {
- $x = q("update xprof set
- xprof_desc = '%s'
- xprof_dob = '%s',
- xprof_gender = '%s',
- xprof_marital = '%s',
- xprof_sexual = '%s',
- xprof_locale = '%s',
- xprof_region = '%s',
- xprof_postcode = '%s',
- xprof_country = '%s'
- where xprof_hash = '%s' limit 1",
- dbesc($arr['desc']),
- dbesc($arr['dob']),
- dbesc($arr['gender']),
- dbesc($arr['marital']),
- dbesc($arr['sexual']),
- dbesc($arr['locale']),
- dbesc($arr['region']),
- dbesc($arr['postcode']),
- dbesc($arr['country']),
- dbesc($sender['hash'])
- );
- }
-
- // optimise this, get existing tags and check which still exist and which don't!!!
-
- $x = q("delete from xtag where xtag_hash = '%s'");
- if($arr['keywords']) {
- foreach($arr['keywords'] as $tag) {
- $r = q("insert into xtag ( xtag_hash, xtag_term ) values ( '%s', '%s' )",
- dbesc($sender['hash']),
- dbesc($tag)
- );
- }
- }
-
-
+ import_directory_profile($sender['hash'],$arr);
}
function import_directory_profile($hash,$profile) {
@@ -1009,10 +948,16 @@ function import_directory_profile($hash,$profile) {
$arr['xprof_postcode'] = (($profile['postcode']) ? htmlentities($profile['postcode'], ENT_COMPAT,'UTF-8') : '');
$arr['xprof_country'] = (($profile['country']) ? htmlentities($profile['country'], ENT_COMPAT,'UTF-8') : '');
+ $clean = array();
if(array_key_exists('keywords',$profile) and is_array($profile['keywords'])) {
- import_directory_keywords($hash,$profile['keywords']);
+ foreach($profile['keywords'] as $kw) {
+ $kw = trim(htmlentities($kw,ENT_COMPAT,'UTF-8'));
+ }
+ $clean[] = $kw;
}
+ $arr['xprof_keywords'] = implode(' ',$clean);
+
$r = q("select * from xprof where xprof_hash = '%s' limit 1",
dbesc($hash)
@@ -1027,7 +972,8 @@ function import_directory_profile($hash,$profile) {
xprof_locale = '%s',
xprof_region = '%s',
xprof_postcode = '%s',
- xprof_country = '%s'
+ xprof_country = '%s',
+ xprof_keywords = '%s'
where xprof_hash = '%s' limit 1",
dbesc($arr['xprof_desc']),
dbesc($arr['xprof_dob']),
@@ -1038,11 +984,12 @@ function import_directory_profile($hash,$profile) {
dbesc($arr['xprof_region']),
dbesc($arr['xprof_postcode']),
dbesc($arr['xprof_country']),
+ dbesc($arr['xprof_keywords']),
dbesc($arr['xprof_hash'])
);
}
else {
- $x = q("insert into xprof (xprof_hash, xprof_desc, xprof_dob, xprof_gender, xprof_marital, xprof_sexual, xprof_locale, xprof_region, xprof_postcode, xprof_country) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
+ $x = q("insert into xprof (xprof_hash, xprof_desc, xprof_dob, xprof_gender, xprof_marital, xprof_sexual, xprof_locale, xprof_region, xprof_postcode, xprof_country, xprof_keywords) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
dbesc($arr['xprof_hash']),
dbesc($arr['xprof_desc']),
dbesc($arr['xprof_dob']),
@@ -1052,41 +999,11 @@ function import_directory_profile($hash,$profile) {
dbesc($arr['xprof_locale']),
dbesc($arr['xprof_region']),
dbesc($arr['xprof_postcode']),
- dbesc($arr['xprof_country'])
+ dbesc($arr['xprof_country']),
+ dbesc($arr['xprof_keywords'])
);
}
return;
}
-
-function import_directory_keywords($hash,$keywords) {
- $existing = array();
- $r = q("select * from xtag where xtag_hash = '%s'",
- dbesc($hash)
- );
- if($r) {
- foreach($r as $rr)
- $existing[] = $rr['xtag_term'];
- }
- $clean = array();
- foreach($keywords as $kw) {
- $kw = trim(htmlentities($kw,ENT_COMPAT,'UTF-8'));
- $clean[] = $kw;
- }
- foreach($existing as $x) {
- if(! in_array($x,$clean))
- $r = q("delete from xtag where xtag_hash = '%s' and xtag_term = '%s' limit 1",
- dbesc($hash),
- dbesc($x)
- );
- }
- foreach($clean as $x) {
- if(! in_array($x,$existing))
- $r = q("insert int xtag ( xtag_hash, xtag_term) values ( '%s' ,'%s' )",
- dbesc($hash),
- dbesc($x)
- );
- }
-
-} \ No newline at end of file
diff --git a/install/database.sql b/install/database.sql
index 990399bc4..817091df5 100644
--- a/install/database.sql
+++ b/install/database.sql
@@ -853,6 +853,7 @@ CREATE TABLE IF NOT EXISTS `xprof` (
`xprof_region` char(255) NOT NULL DEFAULT '',
`xprof_postcode` char(32) NOT NULL DEFAULT '',
`xprof_country` char(255) NOT NULL DEFAULT '',
+ `xprof_keywords` text NOT NULL,
PRIMARY KEY (`xprof_hash`),
KEY `xprof_desc` (`xprof_desc`),
KEY `xprof_dob` (`xprof_dob`),
diff --git a/install/update.php b/install/update.php
index 144a972f9..4c5e4d3a6 100644
--- a/install/update.php
+++ b/install/update.php
@@ -1,6 +1,6 @@
<?php
-define( 'UPDATE_VERSION' , 1009 );
+define( 'UPDATE_VERSION' , 1010 );
/**
*
@@ -160,3 +160,12 @@ function update_r1008() {
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
+
+function update_r1009() {
+ $r = q("ALTER TABLE `xprof` ADD `xprof_keywords` TEXT NOT NULL");
+ if($r)
+ return UPDATE_SUCCESS;
+ return UPDATE_FAILED;
+}
+
+
diff --git a/mod/directory.php b/mod/directory.php
index 2ab1db108..c9332f447 100644
--- a/mod/directory.php
+++ b/mod/directory.php
@@ -36,14 +36,12 @@ function directory_content(&$a) {
$tpl = get_markup_template('directory_header.tpl');
- $dirmode = get_config('system','directory_mode');
- if($dirmode === false)
- $dirmode = DIRECTORY_MODE_NORMAL;
+ $dirmode = intval(get_config('system','directory_mode'));
- if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) {
- $localdir = true;
- return;
- }
+// if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) {
+// $localdir = true;
+// return;
+// }
// FIXME
$localdir = true;
@@ -65,23 +63,22 @@ $localdir = true;
if($localdir) {
if($search)
$search = dbesc($search);
- $sql_extra = ((strlen($search)) ? " AND MATCH (`profile`.`name`, channel.channel_address, `pdesc`, `locality`,`region`,`country_name`,`gender`,`marital`,`sexual`,`about`,`romance`,`work`,`education`,`keywords` ) AGAINST ('$search' IN BOOLEAN MODE) " : "");
+ $sql_extra = ((strlen($search)) ? " AND MATCH ( xchan_name, xchan_addr, xprof_desc, xprof_locale, xprof_region, xprof_country, xprof_gender, xprof_marital ) AGAINST ('$search' IN BOOLEAN MODE) " : "");
-
- $r = q("SELECT COUNT(channel_id) AS `total` FROM channel left join profile on channel.channel_id = profile.uid WHERE `is_default` = 1 and not ( channel_pageflags & %d ) $sql_extra ",
- intval(PAGE_HIDDEN)
- );
+ // group_concat(xtag_term separator ', ') as tags
+ $r = q("SELECT COUNT(xchan_hash) AS `total` FROM xchan left join xprof on xchan_hash = xprof_hash $sql_extra");
if($r)
$a->set_pager_total($r[0]['total']);
- $order = " ORDER BY `name` ASC ";
+ $order = " ORDER BY `xchan_name` ASC ";
- $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, channel_name, channel_address, channel_hash, channel_timezone, channel_pageflags FROM `profile` LEFT JOIN channel ON channel_id = `profile`.`uid` WHERE `is_default` = 1 and not ( channel_pageflags & %d ) $sql_extra $order LIMIT %d , %d ",
- intval(PAGE_HIDDEN),
+ $r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash $sql_extra $order LIMIT %d , %d ",
intval($a->pager['start']),
intval($a->pager['itemspage'])
);
+
+
if($r) {
$entries = array();
@@ -90,42 +87,41 @@ $localdir = true;
foreach($r as $rr) {
- $profile_link = chanlink_hash($rr['channel_hash']);
+ $profile_link = chanlink_hash($rr['xchan_hash']);
- $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
+ $pdesc = (($rr['xprof_desc']) ? $rr['xprof_desc'] . '<br />' : '');
$details = '';
- if(strlen($rr['locality']))
- $details .= $rr['locality'];
- if(strlen($rr['region'])) {
- if(strlen($rr['locality']))
+ if(strlen($rr['xprof_locale']))
+ $details .= $rr['xprof_locale'];
+ if(strlen($rr['xprof_region'])) {
+ if(strlen($rr['xprof_locale']))
$details .= ', ';
- $details .= $rr['region'];
+ $details .= $rr['xprof_region'];
}
- if(strlen($rr['country_name'])) {
+ if(strlen($rr['xprof_country'])) {
if(strlen($details))
$details .= ', ';
- $details .= $rr['country_name'];
+ $details .= $rr['xprof_country'];
}
- if(strlen($rr['dob'])) {
- if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
+ if(strlen($rr['xprof_dob'])) {
+ if(($years = age($rr['xprof_dob'],'UTC','')) != 0)
$details .= '<br />' . t('Age: ') . $years ;
}
- if(strlen($rr['gender']))
- $details .= '<br />' . t('Gender: ') . $rr['gender'];
+ if(strlen($rr['xprof_gender']))
+ $details .= '<br />' . t('Gender: ') . $rr['xprof_gender'];
$page_type = '';
$profile = $rr;
- if((x($profile,'address') == 1)
- || (x($profile,'locality') == 1)
- || (x($profile,'region') == 1)
- || (x($profile,'postal_code') == 1)
- || (x($profile,'country_name') == 1))
+ if ((x($profile,'xprof_locale') == 1)
+ || (x($profile,'xprof_region') == 1)
+ || (x($profile,'xprof_postcode') == 1)
+ || (x($profile,'xprof_country') == 1))
$location = t('Location:');
- $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
+ $gender = ((x($profile,'xprof_gender') == 1) ? t('Gender:') : False);
$marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
@@ -133,14 +129,14 @@ $localdir = true;
$about = ((x($profile,'about') == 1) ? t('About:') : False);
-
+ $t = 0;
$entry = array(
- 'id' => $rr['id'],
+ 'id' => ++$t,
'profile_link' => $profile_link,
- 'photo' => $rr[$photo],
- 'alttext' => $rr['channel_name'],
- 'name' => $rr['channel_name'],
+ 'photo' => $rr[xchan_photo_m],
+ 'alttext' => $rr['xchan_name'],
+ 'name' => $rr['xchan_name'],
'details' => $pdesc . $details,
'profile' => $profile,
'location' => $location,
diff --git a/mod/dirsearch.php b/mod/dirsearch.php
new file mode 100644
index 000000000..30a1fadae
--- /dev/null
+++ b/mod/dirsearch.php
@@ -0,0 +1,116 @@
+<?php
+
+require_once('include/dir_fns.php');
+
+
+function dirsearch_init(&$a) {
+ $a->set_pager_itemspage(60);
+
+}
+
+function dirsearch_content(&$a) {
+
+ $ret = array('success' => false);
+
+ // If you've got a public directory server, you probably shouldn't block public access
+
+ if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
+ $ret['message'] = t('Public access denied.');
+ return;
+ }
+
+ $dirmode = intval(get_config('system','directory_mode'));
+
+ if($dirmode == DIRECTORY_MODE_NORMAL) {
+ $ret['message'] = t('This site is not a directory server');
+ return;
+ }
+
+ $name = ((x($_REQUEST,'name')) ? $_REQUEST['name'] : '');
+ $address = ((x($_REQUEST,'address')) ? $_REQUEST['address'] : '');
+ $locale = ((x($_REQUEST,'locale')) ? $_REQUEST['locale'] : '');
+ $region = ((x($_REQUEST,'region')) ? $_REQUEST['region'] : '');
+ $postcode = ((x($_REQUEST,'postcode')) ? $_REQUEST['postcode'] : '');
+ $country = ((x($_REQUEST,'country')) ? $_REQUEST['country'] : '');
+ $gender = ((x($_REQUEST,'gender')) ? $_REQUEST['gender'] : '');
+ $marital = ((x($_REQUEST,'marital')) ? $_REQUEST['marital'] : '');
+ $keywords = ((x($_REQUEST,'keywords')) ? $_REQUEST['keywords'] : '');
+
+
+ $sql_extra = '';
+
+ if($name)
+ $sql_extra .= " AND xchan_name like '" . protect_sprintf( '%' . dbesc($name) . '%' ) . "' ";
+ if($addr)
+ $sql_extra .= " AND xchan_addr like '" . protect_sprintf( '%' . dbesc($addr) . '%' ) . "' ";
+ if($city)
+ $sql_extra .= " AND xprof_locale like '" . protect_sprintf( '%' . dbesc($city) . '%' ) . "' ";
+ if($region)
+ $sql_extra .= " AND xprof_region like '" . protect_sprintf( '%' . dbesc($region) . '%' ) . "' ";
+ if($post)
+ $sql_extra .= " AND xprof_postcode like '" . protect_sprintf( '%' . dbesc($post) . '%' ) . "' ";
+ if($country)
+ $sql_extra .= " AND xprof_country like '" . protect_sprintf( '%' . dbesc($country) . '%' ) . "' ";
+ if($gender)
+ $sql_extra .= " AND xprof_gender like '" . protect_sprintf( '%' . dbesc($gender) . '%' ) . "' ";
+ if($marital)
+ $sql_extra .= " AND xprof_marital like '" . protect_sprintf( '%' . dbesc($marital) . '%' ) . "' ";
+ if($keywords)
+ $sql_extra .= " AND xprof_keywords like '" . protect_sprintf( '%' . dbesc($keywords) . '%' ) . "' ";
+
+ $perpage = (($_REQUEST['n']) ? $_REQUEST['n'] : 80);
+ $page = (($_REQUEST['p']) ? intval($_REQUEST['p'] - 1) : 0);
+ $startrec = (($page+1) * $perpage) - $perpage;
+
+ // ok a separate tag table won't work.
+ // merge them into xprof
+
+ $ret['success'] = true;
+
+ $r = q("SELECT COUNT(xchan_hash) AS `total` FROM xchan left join xprof on xchan_hash = xprof_hash where 1 $sql_extra");
+ if($r) {
+ $ret['total_items'] = $r[0]['total'];
+ }
+
+ $order = " ORDER BY `xchan_name` ASC ";
+
+ $r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash where 1 $sql_extra $order LIMIT %d , %d ",
+ intval($startrec),
+ intval($perpage)
+ );
+
+ $ret['page'] = $page + 1;
+ $ret['records'] = count($r);
+
+ if($r) {
+
+ $entries = array();
+
+
+ foreach($r as $rr) {
+ $entry = array();
+
+ $entry['name'] = $rr['xchan_name'];
+ $entry['url'] = $rr['xchan_url'];
+ $entry['photo'] = $rr['xchan_photo_m'];
+ $entry['address'] = $rr['xchan_addr'];
+ $entry['description'] = $rr['xprof_desc'];
+ $entry['locale'] = $rr['xprof_locale'];
+ $entry['region'] = $rr['xprof_region'];
+ $entry['postcode'] = $rr['xprof_postcode'];
+ $entry['country'] = $rr['xprof_country'];
+ $entry['birthday'] = $rr['xprof_dob'];
+ $entry['gender'] = $rr['xprof_gender'];
+ $entry['marital'] = $rr['xprof_marital'];
+ $entry['keywords'] = $rr['xprof_keywords'];
+
+ $entries[] = $entry;
+
+ }
+
+ $ret['results'] = $entries;
+
+ }
+ json_return_and_die($ret);
+
+}