This commit is contained in:
marijus 2014-02-05 13:43:16 +01:00
commit 9e993bb4fd
23 changed files with 244 additions and 26 deletions

View File

@ -46,7 +46,7 @@ define ( 'RED_PLATFORM', 'Red Matrix' );
define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'R');
define ( 'ZOT_REVISION', 1 );
define ( 'DB_UPDATE_VERSION', 1095 );
define ( 'DB_UPDATE_VERSION', 1096 );
define ( 'EOL', '<br />' . "\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
@ -270,6 +270,7 @@ define ( 'PERMS_W_STORAGE', 0x02000);
define ( 'PERMS_R_PAGES', 0x04000);
define ( 'PERMS_W_PAGES', 0x08000);
define ( 'PERMS_A_REPUBLISH', 0x10000);
define ( 'PERMS_A_BOOKMARK', 0x20000);
// General channel permissions

View File

@ -171,6 +171,15 @@ class Item extends BaseObject {
);
}
$has_bookmarks = false;
if(is_array($item['term'])) {
foreach($item['term'] as $t) {
if($t['type'] == TERM_BOOKMARK)
$has_bookmarks = true;
}
}
if($this->is_commentable()) {
$like = array( t("I like this \x28toggle\x29"), t("like"));
$dislike = array( t("I don't like this \x28toggle\x29"), t("dislike"));
@ -237,6 +246,7 @@ class Item extends BaseObject {
'star' => ((feature_enabled($conv->get_profile_owner(),'star_posts')) ? $star : ''),
'tagger' => ((feature_enabled($conv->get_profile_owner(),'commtag')) ? $tagger : ''),
'filer' => ((feature_enabled($conv->get_profile_owner(),'filing')) ? $filer : ''),
'bookmark' => (($conv->get_profile_owner() == local_user() && $has_bookmarks) ? t('Bookmark Links') : ''),
'drop' => $drop,
'multidrop' => ((feature_enabled($conv->get_profile_owner(),'multi_delete')) ? $multidrop : ''),
// end toolbar buttons

55
include/bookmarks.php Normal file
View File

@ -0,0 +1,55 @@
<?php /** @file */
require_once('include/menu.php');
function bookmark_add($channel,$sender,$taxonomy,$private) {
$iarr = array();
$channel_id = $channel['channel_id'];
if($private)
$iarr['contact_allow'] = array($channel['channel_hash']);
$iarr['mitem_link'] = $taxonomy['url'];
$iarr['mitem_desc'] = $taxonomy['term'];
$iarr['mitem_flags'] = 0;
$m = @parse_url($taxonomy['url']);
$zrl = false;
if($m['host']) {
$r = q("select hubloc_url from hubloc where hubloc_host = '%s' limit 1",
dbesc($m['host'])
);
if($r)
$zrl = true;
}
if($zrl)
$iarr['mitem_flags'] |= MENU_ITEM_ZID;
$arr = array();
$arr['menu_name'] = substr($sender['xchan_hash'],0,16) . ' ' . $sender['xchan_name'];
$arr['menu_desc'] = sprintf( t('%1$s\'s bookmarks'), $sender['xchan_name']);
$arr['menu_flags'] = (($sender['xchan_hash'] === $channel['channel_hash']) ? MENU_BOOKMARK : MENU_SYSTEM|MENU_BOOKMARK);
$arr['menu_channel_id'] = $channel_id;
$x = menu_list($arr['menu_channel_id'],$arr['menu_name'],$arr['menu_flags']);
if($x)
$menu_id = $x[0]['menu_id'];
else
$menu_id = menu_create($arr);
if(! $menu_id) {
logger('bookmark_add: unable to create menu ' . $arr['menu_name']);
return;
}
logger('add_bookmark: menu_id ' . $menu_id);
$r = q("select * from menu_item where mitem_link = '%s' and mitem_menu_id = %d and mitem_channel_id = %d limit 1",
dbesc($iarr['mitem_link']),
intval($menu_id),
intval($channel_id)
);
if($r)
logger('add_bookmark: duplicate menu entry', LOGGER_DEBUG);
if(! $r)
$r = menu_add_item($menu_id,$channel_id,$iarr);
return $r;
}

View File

@ -1496,6 +1496,14 @@ function profile_tabs($a, $is_owner=False, $nickname=Null){
'title' => t('Events and Calendar'),
'id' => 'events-tab',
);
$tabs[] = array(
'label' => t('Bookmarks'),
'url' => $a->get_baseurl() . '/bookmarks',
'sel' => ((argv(0) == 'bookmarks') ? 'active' : ''),
'title' => t('Saved Bookmarks'),
'id' => 'bookmarks-tab',
);
}
if($is_owner && feature_enabled($a->profile['profile_uid'],'webpages')) {

View File

@ -2169,6 +2169,21 @@ function tag_deliver($uid,$item_id) {
$item = $i[0];
$terms = get_terms_oftype($item['term'],TERM_BOOKMARK);
if($terms && (! $i[0]['item_restrict'])) {
logger('tag_deliver: found bookmark');
if(perm_is_allowed($u[0]['channel_id'],$i[0]['author_xchan'],'bookmark') && ($i[0]['author_xchan'] != $u[0]['channel_hash'])) {
require_once('include/bookmarks.php');
require_once('include/Contact.php');
$s = channelx_by_hash($i[0]['author_xchan']);
foreach($terms as $t) {
bookmark_add($u[0],$s[0],$t,$i[0]['item_private']);
}
}
}
if(($item['source_xchan']) && ($item['item_flags'] & ITEM_UPLINK) && ($item['item_flags'] & ITEM_THREAD_TOP) && ($item['edited'] != $item['created'])) {
// this is an update to a post which was already processed by us and has a second delivery chain
// Just start the second delivery chain to deliver the updated post

View File

@ -26,11 +26,12 @@ function menu_fetch($name,$uid,$observer_xchan) {
function menu_render($menu) {
if(! $menu)
return '';
for($x = 0; $x < count($menu['items']); $x ++)
if($menu['items']['mitem_flags'] & MENU_ITEM_ZID)
$menu['items']['mitem_link'] = zid($menu['items']['mitem_link']);
if($menu['items']['mitem_flags'] & MENU_ITEM_NEWWIN)
$menu['items']['newwin'] = '1';
if($menu['items'][$x]['mitem_flags'] & MENU_ITEM_ZID)
$menu['items'][$x]['mitem_link'] = zid($menu['items'][$x]['mitem_link']);
if($menu['items'][$x]['mitem_flags'] & MENU_ITEM_NEWWIN)
$menu['items'][$x]['newwin'] = '1';
return replace_macros(get_markup_template('usermenu.tpl'),array(
'$menu' => $menu['menu'],
@ -74,8 +75,7 @@ function menu_create($arr) {
$r = q("select * from menu where menu_name = '%s' and menu_channel_id = %d limit 1",
dbesc($menu_name),
intval($menu_channel_id),
intval($menu_flags)
intval($menu_channel_id)
);
if($r)
@ -101,9 +101,17 @@ function menu_create($arr) {
}
function menu_list($channel_id, $flags = 0) {
/**
* If $flags is present, check that all the bits in $flags are set
* so that MENU_SYSTEM|MENU_BOOKMARK will return entries with both
* bits set. We will use this to find system generated bookmarks.
*/
$sel_options = (($flags) ? " and ( menu_flags & " . intval($flags) . " ) " : '');
function menu_list($channel_id, $name = '', $flags = 0) {
$sel_options = '';
$sel_options .= (($name) ? " and menu_name = '" . protect_sprintf(dbesc($name)) . "' " : '');
$sel_options .= (($flags) ? " and menu_flags = " . intval($flags) . " " : '');
$r = q("select * from menu where menu_channel_id = %d $sel_options order by menu_name",
intval($channel_id)
@ -204,7 +212,8 @@ function menu_add_item($menu_id, $uid, $arr) {
$channel = get_app()->get_channel();
}
if ((! $arr['contact_allow'])
if (($channel)
&& (! $arr['contact_allow'])
&& (! $arr['group_allow'])
&& (! $arr['contact_deny'])
&& (! $arr['group_deny'])) {
@ -223,11 +232,11 @@ function menu_add_item($menu_id, $uid, $arr) {
$str_contact_deny = perms2str($arr['contact_deny']);
}
$allow_cid = perms2str($arr['allow_cid']);
$allow_gid = perms2str($arr['allow_gid']);
$deny_cid = perms2str($arr['deny_cid']);
$deny_gid = perms2str($arr['deny_gid']);
// unused
// $allow_cid = perms2str($arr['allow_cid']);
// $allow_gid = perms2str($arr['allow_gid']);
// $deny_cid = perms2str($arr['deny_cid']);
// $deny_gid = perms2str($arr['deny_gid']);
$r = q("insert into menu_item ( mitem_link, mitem_desc, mitem_flags, allow_cid, allow_gid, deny_cid, deny_gid, mitem_channel_id, mitem_menu_id, mitem_order ) values ( '%s', '%s', %d, '%s', '%s', '%s', '%s', %d, %d, %d ) ",
dbesc($mitem_link),

View File

@ -29,6 +29,7 @@ function get_perms() {
'write_pages' => array('channel_w_pages', intval(PERMS_W_PAGES), false, t('Can edit my "public" pages'), ''),
'republish' => array('channel_a_republish', intval(PERMS_A_REPUBLISH), false, t('Can source my "public" posts in derived channels'), t('Somewhat advanced - very useful in open communities')),
'bookmark' => array('channel_a_bookmark', intval(PERMS_A_BOOKMARK), false, t('Can send me bookmarks'), 'Bookmarks from this person will automatically be saved'),
'delegate' => array('channel_a_delegate', intval(PERMS_A_DELEGATE), false, t('Can administer my channel resources'), t('Extremely advanced. Leave this alone unless you know what you are doing')),
);
$ret = array('global_permissions' => $global_perms);

View File

@ -604,7 +604,7 @@ function get_tags($s) {
// bookmarks
if(preg_match_all('/#\^\[(url|zrl)=(.*?)\](.*?)\[\/(url|zrl)\]/',$s,$match,PREG_SET_ORDER)) {
if(preg_match_all('/#\^\[(url|zrl)(.*?)\](.*?)\[\/(url|zrl)\]/',$s,$match,PREG_SET_ORDER)) {
foreach($match as $mtch) {
$ret[] = $mtch[0];
}

View File

@ -177,6 +177,7 @@ CREATE TABLE IF NOT EXISTS `channel` (
`channel_r_pages` int(10) unsigned NOT NULL DEFAULT '128',
`channel_w_pages` int(10) unsigned NOT NULL DEFAULT '128',
`channel_a_republish` int(10) unsigned NOT NULL DEFAULT '128',
`channel_a_bookmark` int(10) unsigned NOT NULL DEFAULT '128',
PRIMARY KEY (`channel_id`),
UNIQUE KEY `channel_address_unique` (`channel_address`),
KEY `channel_account_id` (`channel_account_id`),
@ -211,6 +212,7 @@ CREATE TABLE IF NOT EXISTS `channel` (
KEY `channel_w_pages` (`channel_w_pages`),
KEY `channel_deleted` (`channel_deleted`),
KEY `channel_a_republish` (`channel_a_republish`),
KEY `channel_a_bookmark` (`channel_a_bookmark`),
KEY `channel_dirdate` (`channel_dirdate`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

View File

@ -1,6 +1,6 @@
<?php
define( 'UPDATE_VERSION' , 1095 );
define( 'UPDATE_VERSION' , 1096 );
/**
*
@ -1069,3 +1069,11 @@ ADD INDEX ( `cr_expire` )");
return UPDATE_FAILED;
}
function update_r1095() {
$r = q("ALTER TABLE `channel` ADD `channel_a_bookmark` INT UNSIGNED NOT NULL DEFAULT '128',
ADD INDEX ( `channel_a_bookmark` )");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}

81
mod/bookmarks.php Normal file
View File

@ -0,0 +1,81 @@
<?php
function bookmarks_init(&$a) {
if(! local_user())
return;
$item_id = intval($_REQUEST['item']);
if(! $item_id)
return;
$u = $a->get_channel();
$i = q("select * from item where id = %d and uid = %d limit 1",
intval($item_id),
intval(local_user())
);
if(! $i)
return;
$i = fetch_post_tags($i);
$item = $i[0];
$terms = get_terms_oftype($item['term'],TERM_BOOKMARK);
if($terms && (! $item['item_restrict'])) {
require_once('include/bookmarks.php');
$s = q("select * from xchan where xchan_hash = '%s' limit 1",
dbesc($item['author_xchan'])
);
if(! $s) {
logger('mod_bookmarks: author lookup failed.');
killme();
}
foreach($terms as $t) {
bookmark_add($u,$s[0],$t,$item['item_private']);
notice( t('Bookmark added') . EOL);
}
}
killme();
}
function bookmarks_content(&$a) {
if(! local_user()) {
notice( t('Permission denied.') . EOL);
return;
}
require_once('include/menu.php');
$o = '<h3>' . t('My Bookmarks') . '</h3>';
$x = menu_list(local_user(),'',MENU_BOOKMARK);
if($x) {
foreach($x as $xx) {
$y = menu_fetch($xx['menu_name'],local_user(),get_observer_hash());
$o .= menu_render($y);
}
}
$o .= '<h3>' . t('My Connections Bookmarks') . '</h3>';
$x = menu_list(local_user(),'',MENU_SYSTEM|MENU_BOOKMARK);
if($x) {
foreach($x as $xx) {
$y = menu_fetch($xx['menu_name'],local_user(),get_observer_hash());
$o .= menu_render($y);
}
}
return $o;
}

View File

@ -896,9 +896,9 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag) {
//is it a hash tag?
if(strpos($tag,'#') === 0) {
if(strpos($tag,'#^[') === 0) {
if(preg_match('/#\^\[(url|zrl)=(.*?)\](.*?)\[\/(url|zrl)\]/',$tag,$match)) {
if(preg_match('/#\^\[(url|zrl)(.*?)\](.*?)\[\/(url|zrl)\]/',$tag,$match)) {
$basetag = $match[3];
$url = $match[2];
$url = ((substr($match[2],0,1) === '=') ? substr($match[2],1) : $match[3]);
$replaced = true;
}

View File

@ -9,7 +9,9 @@ function menu_post(&$a) {
$_REQUEST['menu_channel_id'] = local_user();
if($_REQUEST['menu_bookmark'])
$_REQUEST['menu_flags'] = MENU_BOOKMARK;
$_REQUEST['menu_flags'] |= MENU_BOOKMARK;
if($_REQUEST['menu_system'])
$_REQUEST['menu_flags'] |= MENU_SYSTEM;
$menu_id = ((argc() > 1) ? intval(argv(1)) : 0);
if($menu_id) {
@ -108,6 +110,7 @@ function menu_content(&$a) {
'$menu_name' => array('menu_name', t('Menu name'), $m['menu_name'], t('Must be unique, only seen by you'), '*'),
'$menu_desc' => array('menu_desc', t('Menu title'), $m['menu_desc'], t('Menu title as seen by others'), ''),
'$menu_bookmark' => array('menu_bookmark', t('Allow bookmarks'), (($m['menu_flags'] & MENU_BOOKMARK) ? 1 : 0), t('Menu may be used to store saved bookmarks'), ''),
'$menu_system' => (($m['menu_flags'] & MENU_SYSTEM) ? 1 : 0),
'$submit' => t('Modify')
));
return $o;

View File

@ -252,7 +252,7 @@ function parse_url_content(&$a) {
logger('parse_url: ' . $url);
$template = $br . '[url=%s]%s[/url]%s' . $br;
$template = $br . '#^[url=%s]%s[/url]%s' . $br;
$arr = array('url' => $url, 'text' => '');

View File

@ -306,6 +306,7 @@ function settings_post(&$a) {
$arr['channel_r_pages'] = (($_POST['view_pages']) ? $_POST['view_pages'] : 0);
$arr['channel_w_pages'] = (($_POST['write_pages']) ? $_POST['write_pages'] : 0);
$arr['channel_a_republish'] = (($_POST['republish']) ? $_POST['republish'] : 0);
$arr['channel_a_bookmark'] = (($_POST['bookmark']) ? $_POST['bookmark'] : 0);
$defperms = 0;
if(x($_POST['def_view_stream']))
@ -342,6 +343,8 @@ function settings_post(&$a) {
$defperms += $_POST['def_write_pages'];
if(x($_POST['def_republish']))
$defperms += $_POST['def_republish'];
if(x($_POST['def_bookmark']))
$defperms += $_POST['def_bookmark'];
$notify = 0;
@ -399,7 +402,7 @@ function settings_post(&$a) {
set_pconfig(local_user(),'system','hide_online_status',$hide_presence);
$r = q("update channel set channel_name = '%s', channel_pageflags = %d, channel_timezone = '%s', channel_location = '%s', channel_notifyflags = %d, channel_max_anon_mail = %d, channel_max_friend_req = %d, channel_expire_days = %d, channel_default_group = '%s', channel_r_stream = %d, channel_r_profile = %d, channel_r_photos = %d, channel_r_abook = %d, channel_w_stream = %d, channel_w_wall = %d, channel_w_tagwall = %d, channel_w_comment = %d, channel_w_mail = %d, channel_w_photos = %d, channel_w_chat = %d, channel_a_delegate = %d, channel_r_storage = %d, channel_w_storage = %d, channel_r_pages = %d, channel_w_pages = %d, channel_a_republish = %d, channel_allow_cid = '%s', channel_allow_gid = '%s', channel_deny_cid = '%s', channel_deny_gid = '%s' where channel_id = %d limit 1",
$r = q("update channel set channel_name = '%s', channel_pageflags = %d, channel_timezone = '%s', channel_location = '%s', channel_notifyflags = %d, channel_max_anon_mail = %d, channel_max_friend_req = %d, channel_expire_days = %d, channel_default_group = '%s', channel_r_stream = %d, channel_r_profile = %d, channel_r_photos = %d, channel_r_abook = %d, channel_w_stream = %d, channel_w_wall = %d, channel_w_tagwall = %d, channel_w_comment = %d, channel_w_mail = %d, channel_w_photos = %d, channel_w_chat = %d, channel_a_delegate = %d, channel_r_storage = %d, channel_w_storage = %d, channel_r_pages = %d, channel_w_pages = %d, channel_a_republish = %d, channel_a_bookmark = %d, channel_allow_cid = '%s', channel_allow_gid = '%s', channel_deny_cid = '%s', channel_deny_gid = '%s' where channel_id = %d limit 1",
dbesc($username),
intval($pageflags),
dbesc($timezone),
@ -426,6 +429,7 @@ function settings_post(&$a) {
intval($arr['channel_r_pages']),
intval($arr['channel_w_pages']),
intval($arr['channel_a_republish']),
intval($arr['channel_a_bookmark']),
dbesc($str_contact_allow),
dbesc($str_group_allow),
dbesc($str_contact_deny),

View File

@ -1 +1 @@
2014-02-03.577
2014-02-05.579

View File

@ -51,4 +51,5 @@ $(document).ready(function() {
$('.icon-globe').addClass('');
$('.icon-circle-blank').addClass('');
$('.icon-circle').addClass('');
$('.icon-bookmark').addClass('');
});

View File

@ -55,6 +55,8 @@
if(typeof(insertFormatting) != 'undefined')
return(insertFormatting(comment,BBcode,id));
var urlprefix = ((BBcode == 'url') ? '#^' : '');
var tmpStr = $("#comment-edit-text-" + id).val();
if(tmpStr == comment) {
tmpStr = "";
@ -68,11 +70,11 @@
if (document.selection) {
textarea.focus();
selected = document.selection.createRange();
selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
selected.text = urlprefix+"["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
} else if (textarea.selectionStart || textarea.selectionStart == "0") {
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
textarea.value = textarea.value.substring(0, start) + urlprefix+"["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
}
return true;
}

View File

@ -17,6 +17,7 @@ function connectFullShare() {
$('#me_id_perms_chat').attr('checked','checked');
$('#me_id_perms_view_storage').attr('checked','checked');
$('#me_id_perms_republish').attr('checked','checked');
}
function connectCautiousShare() {

View File

@ -43,6 +43,7 @@ function channel_privacy_macro(n) {
$('#id_write_pages option').eq(0).attr('selected','selected');
$('#id_delegate option').eq(0).attr('selected','selected');
$('#id_republish option').eq(0).attr('selected','selected');
$('#id_bookmark option').eq(0).attr('selected','selected');
$('#id_profile_in_directory_onoff .off').removeClass('hidden');
$('#id_profile_in_directory_onoff .on').addClass('hidden');
$('#id_profile_in_directory').val(0);
@ -65,6 +66,7 @@ function channel_privacy_macro(n) {
$('#id_write_pages option').eq(1).attr('selected','selected');
$('#id_delegate option').eq(0).attr('selected','selected');
$('#id_republish option').eq(0).attr('selected','selected');
$('#id_bookmark option').eq(1).attr('selected','selected');
$('#id_profile_in_directory_onoff .off').removeClass('hidden');
$('#id_profile_in_directory_onoff .on').addClass('hidden');
$('#id_profile_in_directory').val(0);
@ -87,6 +89,7 @@ function channel_privacy_macro(n) {
$('#id_write_pages option').eq(0).attr('selected','selected');
$('#id_delegate option').eq(0).attr('selected','selected');
$('#id_republish option').eq(1).attr('selected','selected');
$('#id_bookmark option').eq(1).attr('selected','selected');
$('#id_profile_in_directory_onoff .on').removeClass('hidden');
$('#id_profile_in_directory_onoff .off').addClass('hidden');
$('#id_profile_in_directory').val(1);
@ -109,6 +112,7 @@ function channel_privacy_macro(n) {
$('#id_write_pages option').eq(2).attr('selected','selected');
$('#id_delegate option').eq(0).attr('selected','selected');
$('#id_republish option').eq(4).attr('selected','selected');
$('#id_bookmark option').eq(4).attr('selected','selected');
$('#id_profile_in_directory_onoff .on').removeClass('hidden');
$('#id_profile_in_directory_onoff .off').addClass('hidden');
$('#id_profile_in_directory').val(1);

View File

@ -85,6 +85,9 @@
{{/if}}
{{if $item.filer}}
<i id="filer-{{$item.id}}" onclick="itemFiler({{$item.id}}); return false;" class="filer-item icon-folder-open item-tool" title="{{$item.filer}}"></i>
{{/if}}
{{if $item.bookmark}}
<i id="bookmarker-{{$item.id}}" onclick="itemBookmark({{$item.id}}); return false;" class="bookmark-item icon-bookmark item-tool" title="{{$item.bookmark}}"></i>
{{/if}}
<div id="like-rotator-{{$item.id}}" class="like-rotator"></div>

View File

@ -185,7 +185,6 @@ function enableOnUser(){
}
}
function jotGetLocation() {
reply = prompt("{{$whereareu}}", $('#jot-location').val());
if(reply && reply.length) {
@ -295,6 +294,13 @@ function enableOnUser(){
}
function itemBookmark(id) {
$.get('{{$baseurl}}/bookmarks?f=&item=' + id);
if(timer) clearTimeout(timer);
timer = setTimeout(NavUpdate,1000);
}
function jotClearLocation() {
$('#jot-coord').val('');
$('#profile-nolocation-wrapper').hide();

View File

@ -10,6 +10,10 @@
{{if $menu_id}}
<input type="hidden" name="menu_id" value="{{$menu_id}}" />
{{/if}}
{{if $menu_system}}
<input type="hidden" name="menu_system" value="{{$menu_system}}" />
{{/if}}
{{include file="field_input.tpl" field=$menu_name}}
{{include file="field_input.tpl" field=$menu_desc}}