Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

- added /xml/bookmarks/posts/add_p.xml - security fix to /xml/bookmarks/posts/delete_p.xml - YaCy-UI: added 'add' and 'delete' bookmarks

apfelmaennchenbbacf86fe86a
diff --git a/htroot/xml/bookmarks/posts/add_p.java b/htroot/xml/bookmarks/posts/add_p.java
new file mode 100644
index 000000000..c5e5aeea6
--- /dev/null
+++ b/htroot/xml/bookmarks/posts/add_p.java
@@ -0,0 +1,111 @@
+// /xml/bookmarks/posts/add_p.java
+// -------------------------------
+// part of the AnomicHTTPD caching proxy
+// (C) by Michael Peter Christen; [email protected]
+// first published on http://www.anomic.de
+// Frankfurt, Germany, 2004, 2005
+//
+// last major change: 16.09.2008
+// this file is contributed by Stefan Förster
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+package xml.bookmarks.posts;
+import java.util.HashMap;
+import java.util.Set;
+
+import de.anomic.data.bookmarksDB;
+import de.anomic.data.listManager;
+import de.anomic.data.userDB;
+import de.anomic.http.httpRequestHeader;
+import de.anomic.plasma.plasmaSwitchboard;
+import de.anomic.server.serverObjects;
+import de.anomic.server.serverSwitch;
+import de.anomic.yacy.yacyNewsPool;
+import de.anomic.yacy.yacyNewsRecord;
+
+
+public class add_p {
+
+ private static final serverObjects prop = new serverObjects();
+ private static plasmaSwitchboard sb = null;
+ private static userDB.Entry user = null;
+ private static boolean isAdmin = false;
+
+ public static serverObjects respond(final httpRequestHeader header, final serverObjects post, final serverSwitch<?> env) {
+
+ sb = (plasmaSwitchboard) env;
+ isAdmin=sb.verifyAuthentication(header, true);
+ user = sb.userDB.getUser(header);
+
+ // set user name
+ String username="";
+ if(user != null) username=user.getUserName();
+ else if(isAdmin) username="admin";
+
+ if(post!= null){
+ if(!isAdmin){
+ // force authentication if desired
+ if(post.containsKey("login")){
+ prop.put("AUTHENTICATE","admin log-in");
+ }
+ return prop;
+ }
+ final String url=post.get("url","");
+ final String title=post.get("title",url);
+ final String description=post.get("description","");
+ String tagsString = post.get("tags","");
+ String pathString = post.get("path","/unsorted");
+ tagsString=tagsString+","+pathString;
+ final Set<String> tags=listManager.string2set(bookmarksDB.cleanTagsString(tagsString));
+ final bookmarksDB.Bookmark bookmark = sb.bookmarksDB.createBookmark(url, username);
+ if(bookmark != null){
+ bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_TITLE, title);
+ bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_DESCRIPTION, description);
+ if(user!=null){
+ bookmark.setOwner(user.getUserName());
+ }
+ if((post.get("public")).equals("public")){
+ bookmark.setPublic(true);
+ publishNews(url, title, description, tagsString);
+ }else{
+ bookmark.setPublic(false);
+ }
+ if(post.containsKey("feed") && (post.get("feed")).equals("feed")){
+ bookmark.setFeed(true);
+ }else{
+ bookmark.setFeed(false);
+ }
+ bookmark.setTags(tags, true);
+ sb.bookmarksDB.saveBookmark(bookmark);
+ prop.put("result", "1");
+ } else {
+ // ERROR
+ prop.put("result", "0");
+ }
+ }
+ // return rewrite properties
+ return prop;
+ }
+ private static void publishNews(final String url, final String title, final String description, final String tagsString) {
+ // create a news message
+ final HashMap<String, String> map = new HashMap<String, String>();
+ map.put("url", url.replace(',', '|'));
+ map.put("title", title.replace(',', ' '));
+ map.put("description", description.replace(',', ' '));
+ map.put("tags", tagsString.replace(',', ' '));
+ sb.webIndex.newsPool.publishMyNews(yacyNewsRecord.newRecord(sb.webIndex.seedDB.mySeed(), yacyNewsPool.CATEGORY_BOOKMARK_ADD, map));
+ }
+}
\ No newline at end of file
diff --git a/htroot/xml/bookmarks/posts/add_p.xml b/htroot/xml/bookmarks/posts/add_p.xml
new file mode 100644
index 000000000..d6880fb21
--- /dev/null
+++ b/htroot/xml/bookmarks/posts/add_p.xml
@@ -0,0 +1,2 @@
+<?xml version='1.0' encoding="UTF-8" standalone='yes'?>
+<result code="#(result)#something went wrong::done#(/result)#" />
\ No newline at end of file
diff --git a/htroot/xml/bookmarks/posts/delete_p.java b/htroot/xml/bookmarks/posts/delete_p.java
index 8f1a29969..284df2091 100644
--- a/htroot/xml/bookmarks/posts/delete_p.java
+++ b/htroot/xml/bookmarks/posts/delete_p.java
@@ -36,7 +36,15 @@ public class delete_p {
// return variable that accumulates replacements
final plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
final serverObjects prop = new serverObjects();
+ final boolean isAdmin=switchboard.verifyAuthentication(header, true);
if(post!= null){
+ if(!isAdmin){
+ // force authentication if desired
+ if(post.containsKey("login")){
+ prop.put("AUTHENTICATE","admin log-in");
+ }
+ return prop;
+ }
try {
if( post.containsKey("url") && switchboard.bookmarksDB.removeBookmark((new yacyURL(post.get("url", "nourl"), null)).hash())) {
prop.put("result", "1");
@@ -50,11 +58,10 @@ public class delete_p {
}
}else{
prop.put("result", "0");
- }
+ }
// return rewrite properties
return prop;
- }
-
+ }
}
diff --git a/htroot/yacy/ui/css/jquery.dialog.css b/htroot/yacy/ui/css/jquery.dialog.css
new file mode 100644
index 000000000..e3a1bacec
--- /dev/null
+++ b/htroot/yacy/ui/css/jquery.dialog.css
@@ -0,0 +1,97 @@
+/* This file skins dialog */
+
+.bmdialog .ui-dialog,
+.bmdialog.ui-dialog {
+ background-color: white;
+ font-family: "Trebuchet MS", Trebuchet, Verdana, Helvetica, Arial, sans-serif;
+ font-size: 12px;
+}
+
+.bmdialog .ui-dialog .ui-dialog-titlebar,
+.bmdialog.ui-dialog .ui-dialog-titlebar {
+ background: url(../img/tab.png) no-repeat;
+ padding: 2px;
+ height: 28px;
+ _height: 29px;
+}
+
+.bmdialog .ui-dialog.ui-draggable .ui-dialog-titlebar,
+.bmdialog.ui-dialog.ui-draggable .ui-dialog-titlebar {
+ cursor: move;
+}
+
+.bmdialog .ui-dialog .ui-dialog-titlebar-close,
+.bmdialog.ui-dialog .ui-dialog-titlebar-close {
+ width: 16px;
+ height: 16px;
+ background: url(../img-2/cancel.png) no-repeat;
+ position:absolute;
+ top: 6px;
+ right: 7px;
+ cursor: default;
+}
+
+.bmdialog .ui-dialog .ui-dialog-titlebar-close span,
+.bmdialog.ui-dialog .ui-dialog-titlebar-close span {
+ display: none;
+}
+
+.bmdialog .ui-dialog .ui-dialog-titlebar-close-hover,
+.bmdialog.ui-dialog .ui-dialog-titlebar-close-hover {
+ background: url(../img-2/cancel.png) no-repeat;
+}
+
+.bmdialog .ui-dialog .ui-dialog-title,
+.bmdialog.ui-dialog .ui-dialog-title {
+ margin-left: 5px;
+ color: #27537a;
+ font-weight: bold;
+ line-height: 1.2;
+ position: relative;
+ top: 7px;
+ left: 4px;
+}
+
+.bmdialog .ui-dialog .ui-dialog-content,
+.bmdialog.ui-dialog .ui-dialog-content {
+ margin: 1.2em;
+}
+
+.bmdialog .ui-dialog .ui-dialog-buttonpane,
+.bmdialog.ui-dialog .ui-dialog-buttonpane {
+ position: absolute;
+ bottom: 8px;
+ right: 12px;
+ width: 100%;
+ text-align: right;
+}
+
+.bmdialog .ui-dialog .ui-dialog-buttonpane button,
+.bmdialog.ui-dialog .ui-dialog-buttonpane button {
+ margin: 6px;
+}
+
+/* Dialog handle styles */
+.bmdialog .ui-dialog .ui-resizable-n,
+.bmdialog.ui-dialog .ui-resizable-n { cursor: n-resize; height: 6px; width: 100%; top: 0px; left: 0px; background: transparent url(i/dialog-n.gif) repeat scroll center top; }
+
+.bmdialog .ui-dialog .ui-resizable-s,
+.bmdialog.ui-dialog .ui-resizable-s { cursor: s-resize; height: 8px; width: 100%; bottom: 0px; left: 0px; background: transparent url(i/dialog-s.gif) repeat scroll center top; }
+
+.bmdialog .ui-dialog .ui-resizable-e,
+.bmdialog.ui-dialog .ui-resizable-e { cursor: e-resize; width: 7px; right: 0px; top: 0px; height: 100%; background: transparent url(i/dialog-e.gif) repeat scroll right center; }
+
+.bmdialog .ui-dialog .ui-resizable-w,
+.bmdialog.ui-dialog .ui-resizable-w { cursor: w-resize; width: 7px; left: 0px; top: 0px; height: 100%; background: transparent url(i/dialog-w.gif) repeat scroll right center; }
+
+.bmdialog .ui-dialog .ui-resizable-se,
+.bmdialog.ui-dialog .ui-resizable-se { cursor: se-resize; width: 9px; height: 9px; right: 0px; bottom: 0px; background: transparent url(i/dialog-se.gif); }
+
+.bmdialog .ui-dialog .ui-resizable-sw,
+.bmdialog.ui-dialog .ui-resizable-sw { cursor: sw-resize; width: 9px; height: 9px; left: 0px; bottom: 0px; background: transparent url(i/dialog-sw.gif); }
+
+.bmdialog .ui-dialog .ui-resizable-nw,
+.bmdialog.ui-dialog .ui-resizable-nw { cursor: nw-resize; width: 9px; height: 29px; left: 0px; top: 0px; background: transparent url(i/dialog-nw.gif); }
+
+.bmdialog .ui-dialog .ui-resizable-ne,
+.bmdialog.ui-dialog .ui-resizable-ne { cursor: ne-resize; width: 9px; height: 29px; right: 0px; top: 0px; background: transparent url(i/dialog-ne.gif); }
diff --git a/htroot/yacy/ui/index.html b/htroot/yacy/ui/index.html
index 671bcc68f..4ecbfb8c1 100644
--- a/htroot/yacy/ui/index.html
+++ b/htroot/yacy/ui/index.html
@@ -13,7 +13,8 @@
<link media="screen" type="text/css" href="css/jquery.tabs.css" rel="stylesheet" />
<link media="screen" type="text/css" href="css/jquery.accordion.css" rel="stylesheet" />
<link media="screen" type="text/css" href="css/jquery.pagination.css" rel="stylesheet" />
- <link media="screen" type="text/css" href="css/jquery.flexigrid.css" rel="stylesheet" />
+ <link media="screen" type="text/css" href="css/jquery.flexigrid.css" rel="stylesheet" />
+ <link media="screen" type="text/css" href="css/jquery.dialog.css" rel="stylesheet" />
<script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
<script src="js/jquery.ui.all.min.js" type="text/javascript"></script>
diff --git a/htroot/yacy/ui/yacyui-bookmarks.html b/htroot/yacy/ui/yacyui-bookmarks.html
index 7349146ea..2a2ab21e3 100644
--- a/htroot/yacy/ui/yacyui-bookmarks.html
+++ b/htroot/yacy/ui/yacyui-bookmarks.html
@@ -1,11 +1,57 @@
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
-
$("#side1").accordion("activate", 0);
$("#side2").accordion("activate", 1);
// $('#yoptions').resetForm();
-
+ $("#bmadd").dialog({
+ autoOpen: false,
+ height: 350,
+ width: 250,
+ resizable: false,
+ buttons: {
+ "Add": function() {
+ var url = $("input[@name='bm_url']").getValue();
+ var title = $("input[@name='bm_title']").getValue();
+ var desc = $("input[@name='bm_desc']").getValue();
+ var tags = $("input[@name='bm_tags']").getValue()
+ var path = $("input[@name='bm_path']").getValue();
+ var pub = $("select[@name='bm_public']").getValue();
+ var query = "&url="+url+"&title="+title+"&description="+desc+"&tags="+tags+"&path="+path+"&public="+pub+"&add=create";
+ $.ajax({
+ type: "POST",
+ url: "/xml/bookmarks/posts/add_p.xml?login="+query,
+ dataType: "xml",
+ success: function(xml) {
+ $("#bmadd").dialog("close");
+ $tabs.tabs("load", 3);
+ }
+ });
+ },
+ "Cancel": function() {
+ $(this).dialog("close");
+ }
+ }
+ });
+ function bm_action(com,grid) {
+ if (com=='Delete') {
+ confirm('Delete ' + $('.trSelected',grid).length + ' bookmark(s)?')
+ $('.trSelected',grid).each(function(){
+ var url = "/xml/bookmarks/posts/delete_p.xml?login=&urlhash="+$(this).find('td :first').text();
+ $.ajax({
+ type: 'POST',
+ url: url,
+ dataType: 'xml',
+ success: function(xml) {
+ $tabs.tabs("load", 3);
+ }
+ }); // close $.ajax(
+ }); //close each(
+ }
+ else if (com=='Add') {
+ $("#bmadd").dialog('open');
+ }
+ }
counter = 0;
$.ajax({
type: "GET",
@@ -16,7 +62,7 @@
var link = $(this).attr('href');
var hash = $(this).attr('id');
var title = $(this).find('title').text();
- var date = $(this).attr('added');;
+ var date = $(this).attr('added');
var desc = $(this).find('desc').text();
var pub = $(this).find('metadata[owner=YaCy][public]').attr('public');
var tags = $(this).find('metadata[owner=Mozilla][ShortcutURL]').attr('ShortcutURL');
@@ -31,22 +77,22 @@
var icon = '<img src="img-2/lock.png" alt="private bookmark" title="private bookmark"/>'
}
$('<tr></tr')
- .html('<td><input type="checkbox" value="true" /></td><td>' +icon+ '</td><td><h3 class="linktitle">' +title+ '</h3><p class="desc">' +desc+ '</p><p class="url"><a href="' +link+ '">' +link+ '</a></p><td>' +tags+ ' </td><td>' +date+ '</td>')
+ .html('<td>' +hash+ '</td><td>' +icon+ '</td><td><h3 class="linktitle">' +title+ '</h3><p class="desc">' +desc+ '</p><p class="url"><a href="' +link+ '">' +link+ '</a></p><td>' +tags+ ' </td><td>' +date+ '</td>')
.appendTo('#ymarks tbody');
counter++;
}); //close each(
var height=document.documentElement.clientHeight - 205;
$('#ymarks').flexigrid({
colModel: [
- {display: '', name : 'select', width : 25, sortable : false, align: 'center'},
+ {display: 'Hash', name : 'hash', width : 50, sortable : false, align: 'center', hide: true},
{display: '', name : 'public', width : 25, sortable : true, align: 'center'},
{display: 'Title', name : 'title', width : 450, sortable : true, align: 'left'},
- {display: 'Tags', name : 'tags', width : 215, sortable : false, align: 'left'},
+ {display: 'Tags', name : 'tags', width : 240, sortable : false, align: 'left'},
{display: 'Date', name : 'date', width : 130, sortable : true, align: 'left'}
],
buttons: [
- {name: 'Add', bclass: 'add', onpress: test},
- {name: 'Delete', bclass: 'delete', onpress: test},
+ {name: 'Add', bclass: 'add', onpress: bm_action},
+ {name: 'Delete', bclass: 'delete', onpress: bm_action},
{separator: true}
],
striped: true,
@@ -55,31 +101,47 @@
title: 'YaCy Bookmarks: '+qtag
});
}
- }); //close $.ajax(
- function test(com,grid) {
- if (com=='Delete') {
- confirm('Delete ' + $('.trSelected',grid).length + ' items?')
- }
- else if (com=='Add') {
- alert('Add New Item');
- }
- }
+ }); //close $.ajax(
});
//]]>
</script>
<!-- Display Bookmarks Table -->
<table id="ymarks" summary="YaCy Bookmarks">
- <colgroup>
- <col width="25"/>
- <col width="25"/>
- <col width="450"/>
- <col width="215"/>
- <col width="130"/>
- </colgroup>
<tbody>
</tbody>
</table>
+<!-- Display Bookmarks Edit Dialog -->
+<div id="bmadd" class="bmdialog" title="Add bookmark">
+ <form id="bmaddform" class="small" method="get" accept-charset="UTF-8" action="">
+ <label for="url">URL:</label>
+ <br />
+ <input type="text" name="bm_url" id="bm_url" class="filter" onblur="loadTitle()" size="80" />
+ <br />
+ <label for="bm_title">Title:</label>
+ <br />
+ <input type="text" name="bm_title" id="bm_title" class="filter" size="80" />
+ <br />
+ <label for="bm_desc">Description:</label>
+ <br />
+ <input type="text" name="bm_desc" id="bm_desc" class="filter" size="80" />
+ <br />
+ <label for="bm_path">Folder (/folder/subfolder):</label>
+ <br />
+ <input type="text" name="bm_path" id="bm_path" class="filter" size="80" />
+ <br />
+ <label for="bm_tags">Tags (comma separated):</label>
+ <br />
+ <input type="text" name="bm_tags" id="bm_tags" class="filter" size="80" />
+ <br />
+ <label for="bm_public">Public:</label>
+ <br />
+ <select name="bm_public" id="bm_public" class="selector">
+ <option value="public" selected="selected">yes</option>
+ <option value="private">no</option>
+ </select>
+ </form>
+</div>