Merge pull request #1213 from annando/1410-keyword-blacklist

Blacklist for generating hashtags from keywords
This commit is contained in:
fabrixxm 2014-10-31 14:40:27 +01:00
commit a818ed2d49
6 changed files with 26 additions and 7 deletions

View File

@ -18,7 +18,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Ginger');
define ( 'FRIENDICA_VERSION', '3.3' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1173 );
define ( 'DB_UPDATE_VERSION', 1174 );
define ( 'EOL', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );

View File

@ -462,6 +462,7 @@ function db_definition() {
"bd" => array("type" => "date", "not null" => "1"),
"notify_new_posts" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"fetch_further_information" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"ffi_keyword_blacklist" => array("type" => "mediumtext", "not null" => "1"),
),
"indexes" => array(
"PRIMARY" => array("id"),

View File

@ -872,7 +872,7 @@ function get_atom_elements($feed, $item, $contact = array()) {
}
if (isset($contact["network"]) AND ($contact["network"] == NETWORK_FEED) AND $contact['fetch_further_information']) {
$res["body"] = $res["title"].add_page_info($res['plink'], false, "", ($contact['fetch_further_information'] == 2));
$res["body"] = $res["title"].add_page_info($res['plink'], false, "", ($contact['fetch_further_information'] == 2), $contact['ffi_keyword_blacklist']);
$res["title"] = "";
$res["object-type"] = ACTIVITY_OBJ_BOOKMARK;
} elseif (isset($contact["network"]) AND ($contact["network"] == NETWORK_OSTATUS))
@ -921,7 +921,8 @@ function add_page_info_data($data) {
$a = get_app();
$hashtags = "\n";
foreach ($data["keywords"] AS $keyword) {
$hashtag = str_replace(" ", "", $keyword);
$hashtag = str_replace(array(" ", "+", "/", ".", "#", "'"),
array("","", "", "", "", ""), $keyword);
$hashtags .= "#[url=".$a->get_baseurl()."/search?tag=".rawurlencode($hashtag)."]".$hashtag."[/url] ";
}
}
@ -929,7 +930,7 @@ function add_page_info_data($data) {
return("\n[class=type-".$data["type"]."]".$text."[/class]".$hashtags);
}
function add_page_info($url, $no_photos = false, $photo = "", $keywords = false) {
function add_page_info($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "") {
require_once("mod/parse_url.php");
$data = parseurl_getsiteinfo($url, true);
@ -939,6 +940,16 @@ function add_page_info($url, $no_photos = false, $photo = "", $keywords = false)
if (!$keywords AND isset($data["keywords"]))
unset($data["keywords"]);
if (($keyword_blacklist != "") AND isset($data["keywords"])) {
$list = explode(",", $keyword_blacklist);
foreach ($list AS $keyword) {
$keyword = trim($keyword);
$index = array_search($keyword, $data["keywords"]);
if ($index !== false)
unset($data["keywords"][$index]);
}
}
$text = add_page_info_data($data);
return($text);

View File

@ -160,6 +160,8 @@ function contacts_post(&$a) {
$fetch_further_information = intval($_POST['fetch_further_information']);
$ffi_keyword_blacklist = fix_mce_lf(escape_tags(trim($_POST['ffi_keyword_blacklist'])));
$priority = intval($_POST['poll']);
if($priority > 5 || $priority < 0)
$priority = 0;
@ -167,13 +169,15 @@ function contacts_post(&$a) {
$info = fix_mce_lf(escape_tags(trim($_POST['info'])));
$r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
`hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d WHERE `id` = %d AND `uid` = %d",
`hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
`ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
intval($profile_id),
intval($priority),
dbesc($info),
intval($hidden),
intval($notify),
intval($fetch_further_information),
dbesc($ffi_keyword_blacklist),
intval($contact_id),
intval(local_user())
);
@ -388,7 +392,7 @@ function contacts_content(&$a) {
$dir_icon = 'images/larrow.gif';
$relation_text = t('You are sharing with %s');
break;
case CONTACT_IS_SHARING;
$dir_icon = 'images/rarrow.gif';
$relation_text = t('%s is sharing with you');
@ -504,6 +508,8 @@ function contacts_content(&$a) {
'$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
'$fetch_further_information' => array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords'))),
'$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
'$ffi_keyword_blacklist' => array('ffi_keyword_blacklist', t('Blacklisted keywords'), $contact['ffi_keyword_blacklist'], t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')),
'$photo' => $contact['photo'],
'$name' => $contact['name'],
'$dir_icon' => $dir_icon,

View File

@ -1,6 +1,6 @@
<?php
define( 'UPDATE_VERSION' , 1173 );
define( 'UPDATE_VERSION' , 1174 );
/**
*

View File

@ -67,6 +67,7 @@
<div id="contact-edit-end" ></div>
{{include file="field_checkbox.tpl" field=$notify}}
{{include file="field_select.tpl" field=$fetch_further_information}}
{{if $fetch_further_information.2 == 2 }} {{include file="field_textarea.tpl" field=$ffi_keyword_blacklist}} {{/if}}
{{include file="field_checkbox.tpl" field=$hidden}}
<div id="contact-edit-info-wrapper">