Skip to content
Permalink
Browse files

added private cache list sharing and cache list bookmarking; updates #…

  • Loading branch information...
following5 committed Jul 18, 2015
1 parent b771f91 commit 619f7ac924d41027d8c8fda6dac54c306c0476ad
@@ -503,6 +503,24 @@ function dbv_128() // see util2/gns/mksearchindex.php; fix for #175/3
}
function dbv_129() // cache list passwords & bookmarking
{
if (!sql_field_exists('cache_lists','password'))
sql("ALTER TABLE `cache_lists` ADD COLUMN `password` varchar(80) NOT NULL");
if (!sql_table_exists('cache_list_bookmarks'))
{
sql("
CREATE TABLE `cache_list_bookmarks` (
`cache_list_id` int(10) NOT NULL,
`user_id` int(10) NOT NULL,
`password` varchar(80) NOT NULL,
UNIQUE KEY `cache_list_id` (`cache_list_id`,`user_id`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
}
}
// When adding new mutations, take care that they behave well if run multiple
// times. This improves robustness of database versioning.
//
@@ -188,10 +188,11 @@ Icons
License : Creative Commons BY-SA 3.0
Author : Oxygen

4. 16x16 Icons 'flag-checker', 'footprints', 'clock select', lock, list
4. 16x16 Icons 'flag-checker', 'footprints', 'clock select', lock, list, offer
Path : htdocs/resource2/ocstyle/images/misc/
htdocs/resource2/ocstyle/images/map/caches2/
htdocs/resource2/ocstyle/images/cachestatus/
htdocs/resource2/ocstyle/images/action/
URI : http://www.softicons.com/free-icons/toolbar-icons/fugue-16px-additional-icons-2-by-yusuke-kamiyamane
License : Creative Commons BY 3.0
Author : Yusuke Kamiyamane
@@ -10,18 +10,27 @@
require('./lib2/web.inc.php');
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] + 0 : 0;
$password = isset($_REQUEST['key']) ? $_REQUEST['key'] : '';
$watch = isset($_REQUEST['watch']);
$dontwatch = isset($_REQUEST['dontwatch']);
$bookmark = isset($_REQUEST['bookmark']);
if ($id)
{
if ($watch || $dontwatch)
$login->verify();
$list = new cachelist($id);
if ($list->exist())
{
$list = new cachelist($id);
if ($list->exist())
if (($watch && $list->allowView($password)) || $dontwatch)
$list->watch($watch);
if ($bookmark)
$list->bookmark($password);
}
$tpl->redirect("search.php?searchto=searchbylist&listid=" . $id . "&showresult=1&f_disabled=0&f_inactive=0&f_ignored=1&sort=byname");
$tpl->redirect("search.php?searchto=searchbylist&listid=" . $id .
($password != "" ? "&listkey=" . urlencode($password) : "") .
"&showresult=1&f_disabled=0&f_inactive=0&f_ignored=1&sort=byname");
}
else
$tpl->redirect("cachelists.php");
@@ -36,6 +36,7 @@
$tpl->assign('name_filter', $name_filter);
$tpl->assign('by_filter', $by_filter);
$tpl->assign('cachelists', cachelist::getPublicLists($startat, $MAXITEMS, $name_filter, $by_filter));
$tpl->assign('show_bookmarks', true);
$tpl->assign('show_status', false);
$tpl->assign('show_user', true);
// Do not show watchers because this would allow conclusions on what the list owner watches.
@@ -2672,6 +2672,13 @@ INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2224', 'listing
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2225', 'without Geokrets', '2013-11-03 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2226', 'hidden[cachelist]', '2013-11-03 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2227', 'Coordinate changes', '2013-11-03 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2228', 'Password for sharing', '2013-11-03 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2229', 'list has password; copy this link to share it', '2013-11-03 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2230', 'Own lists', '2013-11-03 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2231', 'Bookmarked lists', '2013-11-03 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2232', 'Do you really want to unbookmark the list \\\'%1\\\'?', '2013-11-03 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2233', 'bookmark', '2013-11-03 10:09:14');
INSERT INTO `sys_trans` (`id`, `text`, `last_modified`) VALUES ('2234', 'I have bookmarked this list.', '2013-11-03 10:09:14');

-- Table sys_trans_ref
SET NAMES 'utf8';
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2225', 'DE', 'ohne Geokrets', '2013-11-03 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2226', 'DE', 'ausgeblendet', '2013-11-03 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2227', 'DE', 'Koordinatenänderungen', '2013-11-03 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2228', 'DE', 'Kennwort für Weitergabe', '2013-11-03 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2229', 'DE', 'Liste mit Kennwort; kopiere diesen Link, um sie weiterzugeben.', '2013-11-03 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2230', 'DE', 'Eigene Listen', '2013-11-03 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2231', 'DE', 'Gemerkte Listen (Favoriten)', '2013-11-03 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2232', 'DE', 'Möchtest du die Cacheliste \\\'%1\\\' wirklich aus den Favoriten entfernen?', '2013-11-03 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2233', 'DE', 'merken', '2013-11-03 10:09:14');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2234', 'DE', 'Diese Liste gehört zu meinen Favoriten.', '2013-11-03 10:09:14');

INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('1', 'EN', 'Reorder IDs', '2010-09-02 00:15:30');
INSERT INTO `sys_trans_text` (`trans_id`, `lang`, `text`, `last_modified`) VALUES ('2', 'EN', 'The database could not be reconnected.', '2010-08-28 11:48:07');
@@ -0,0 +1,9 @@
SET NAMES 'utf8';
DROP TABLE IF EXISTS `cache_list_bookmarks`;
CREATE TABLE `cache_list_bookmarks` (
`cache_list_id` int(10) NOT NULL,
`user_id` int(10) NOT NULL,
`password` varchar(80) NOT NULL,
UNIQUE KEY `cache_list_id` (`cache_list_id`,`user_id`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
@@ -13,6 +13,7 @@ CREATE TABLE `cache_lists` (
`is_public` tinyint(1) NOT NULL default '0',
`description` mediumtext NOT NULL,
`desc_htmledit` tinyint(1) unsigned NOT NULL default '1',
`password` varchar(80) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uuid` (`uuid`),
KEY `name` (`name`),
@@ -35,6 +35,7 @@ function __construct($nNewCachelistId=ID_NEW, $nUserId=0)
$this->reCachelist->addInt('is_public', 0, false);
$this->reCachelist->addString('description', '', false);
$this->reCachelist->addInt('desc_htmledit', 1, false);
$this->reCachelist->addString('password', '', false);
$this->nCachelistId = $nNewCachelistId + 0;
@@ -123,6 +124,16 @@ function setDescription($desc, $htmledit)
return $this->reCachelist->setValue('description', $desc);
}
function setPassword($pw)
{
$this->reCachelist->setValue('password', $pw);
}
function getPassword()
{
return $this->reCachelist->getValue('password');
}
function getCachesCount()
{
return sql_value("
@@ -141,6 +152,8 @@ function getWatchersCount()
function save()
{
if ($this->getVisibility() > 0)
$this->setPassword("");
sql_slave_exclude();
if ($this->reCachelist->save())
{
@@ -240,6 +253,9 @@ function removeCacheById($cache_id)
$this->nCachelistId, $cache_id);
}
// watching, bookmarking and access tests
function watch($watch)
{
global $login;
@@ -249,7 +265,7 @@ function watch($watch)
{
if ($watch)
{
if ($this->getVisibility() >= 2 || $this->getUserId() == $login->userid)
if ($this->allowView())
sql("
INSERT IGNORE INTO `cache_list_watches` (`cache_list_id`, `user_id`)
VALUES ('&1','&2')",
@@ -274,6 +290,50 @@ function isWatchedByMe()
0, $this->getId(), $login->userid) != 0;
}
function bookmark($pw)
{
global $login;
if ($login->userid != 0 &&
!$this->isMyList() &&
($this->getVisibility() >= 2 || ($this->getPassword() != "" && $pw == $this->getPassword()))
)
{
sql("INSERT IGNORE INTO `cache_list_bookmarks` (`cache_list_id`, `user_id`, `password`)
VALUES('&1','&2','&3')
ON DUPLICATE KEY UPDATE `password`='&3'",
$this->getId(), $login->userid, $pw);
}
}
function unbookmark()
{
global $login;
sql("DELETE FROM `cache_list_bookmarks`
WHERE `cache_list_id`='&1' AND `user_id`='&2'",
$this->getId(), $login->userid);
}
function allowView($pw='')
{
global $login;
if (!$this->exist())
return false;
return $this->isMyList() ||
$this->getVisibility() >= 2 ||
($this->getPassword() != '' && $pw == $this->getPassword()) ||
sql_value("
SELECT COUNT(*)
FROM `cache_lists` `cl`
LEFT JOIN `cache_list_bookmarks` `clb` ON `clb`.`cache_list_id`=`cl`.`id`
WHERE `cl`.`id`='&1' AND `cl`.`password`<>''
AND `clb`.`user_id`='&2' AND `clb`.`password`=`cl`.`password`",
0, $this->getId(), $login->userid);
}
// get list of lists -- static functions
@@ -289,6 +349,12 @@ static function getListsWatchedByMe()
return cachelist::getLists("`id` IN (SELECT `cache_list_id` FROM `cache_list_watches` WHERE `user_id`='" . sql_escape($login->userid) . "')");
}
static function getBookmarkedLists()
{
global $login;
return cachelist::getLists("`id` IN (SELECT `cache_list_id` FROM `cache_list_bookmarks` WHERE `user_id`='" . sql_escape($login->userid) . "')");
}
static function getPublicListCount($namelike='', $userlike='')
{
return sql_value("
@@ -362,16 +428,18 @@ private function getLists($condition, $prio=0, $startat=0, $maxitems=PHP_INT_MAX
$rs = sql("
SELECT `cache_lists`.`id`, `cache_lists`.`user_id`, `user`.`username`,
`cache_lists`.`name`, `cache_lists`.`is_public` `visibility`,
`cache_lists`.`description`, `cache_lists`.`desc_htmledit`,
`cache_lists`.`name`, `cache_lists`.`is_public` `visibility`, `cache_lists`.`password`,
`cache_lists`.`description`, `cache_lists`.`desc_htmledit`,
`cache_lists`.`user_id`='&1' `own_list`,
`stat_cache_lists`.`entries`, `stat_cache_lists`.`watchers`,
`w`.`user_id` IS NOT NULL `watched_by_me`,
`b`.`user_id` IS NOT NULL `bookmarked`,
$prio `prio`
FROM `cache_lists`
LEFT JOIN `stat_cache_lists` ON `stat_cache_lists`.`cache_list_id`=`cache_lists`.`id`
LEFT JOIN `user` ON `user`.`user_id`=`cache_lists`.`user_id`
LEFT JOIN `cache_list_watches` `w` ON `w`.`cache_list_id`=`cache_lists`.`id` AND `w`.`user_id`='&1'
LEFT JOIN `cache_list_bookmarks` `b` ON `b`.`cache_list_id`=`cache_lists`.`id` AND `b`.`user_id`='&1'
WHERE $condition
ORDER BY `prio`,`cache_lists`.`name`
LIMIT &2,&3",
@@ -140,7 +140,10 @@ function search_output()
// cachelist data
if (isset($options['cachelist']))
{
$tpl->assign('cachelist', $options['cachelist']);
$tpl->assign('cachelist_pw', $options['cachelist_pw']);
}
else
$tpl->assign('cachelist', false);
@@ -18,6 +18,7 @@
$list_name = isset($_REQUEST['list_name']) ? trim($_REQUEST['list_name']) : '';
$list_visibility = isset($_REQUEST['list_visibility']) ? $_REQUEST['list_visibility'] + 0 : 0;
$list_password = isset($_REQUEST['list_password']) ? $_REQUEST['list_password'] : '';
$list_caches = isset($_REQUEST['list_caches']) ? strtoupper(trim($_REQUEST['list_caches'])) : '';
$watch = isset($_REQUEST['watch']);
$desctext = isset($_REQUEST['desctext']) ? $_REQUEST['desctext'] : '';
@@ -35,6 +36,7 @@
$tpl->assign('show_editor', false);
$list_name = '';
$list_visibility = 0;
$list_password = '';
$watch = false;
$desctext = '';
// keep descMode of previous operation
@@ -50,8 +52,13 @@
$tpl->assign('newlist_mode', true);
else
{
<<<<<<< HEAD
$purifier = new OcHTMLPurifier($opt);
$list->setDescription($purifier->purify($desctext), $descMode == 3);
=======
$list->setPassword($list_password);
$list->setDescription($desctext, $descMode == 3);
>>>>>>> added private cache list sharing and cache list bookmarking; updates #748
if ($list->save())
{
if ($list_caches != '')
@@ -74,6 +81,7 @@
$edit_list = true;
$list_name = $list->getName();
$list_visibility = $list->getVisibility();
$list_password = $list->getPassword();
$watch = $list->isWatchedByMe();
$desctext = $list->getDescription();
$descMode = $list->getDescHtmledit() ? 3 : 2;
@@ -111,8 +119,13 @@
$name_error = $list->setNameAndVisibility($list_name, $list_visibility);
if ($name_error)
$edit_list = true;
<<<<<<< HEAD
$purifier = new OcHTMLPurifier($opt);
$list->setDescription($purifier->purify($desctext), $descMode == 3);
=======
$list->setPassword($list_password);
$list->setDescription($desctext, $descMode == 3);
>>>>>>> added private cache list sharing and cache list bookmarking; updates #748
$list->save();
$list->watch($watch);
@@ -136,6 +149,14 @@
// All dependent deletion and cleanup is done via trigger.
}
// unbookmark a list
if (isset($_REQUEST['unbookmark']))
{
$list = new cachelist($_REQUEST['unbookmark'] + 0);
if ($list->exist())
$list->unbookmark();
}
// redirect to list search output after editing a list from the search output page
if ($fromsearch && !$switchDescMode && !$name_error && isset($_REQUEST['listid']))
{
@@ -157,6 +178,8 @@
// prepare rest of template
$tpl->assign('cachelists', cachelist::getMyLists());
$tpl->assign('bookmarked_lists', cachelist::getBookmarkedLists());
$tpl->assign('show_status', true);
$tpl->assign('show_user', false);
$tpl->assign('show_watchers', true);
@@ -167,6 +190,7 @@
$tpl->assign('list_name', $list_name);
$tpl->assign('list_visibility', $list_visibility);
$tpl->assign('list_password', $list_password);
$tpl->assign('watch', $watch);
$tpl->assign('desctext', $desctext);
$tpl->assign('descMode', $descMode);
Binary file not shown.
Oops, something went wrong.

0 comments on commit 619f7ac

Please sign in to comment.
You can’t perform that action at this time.