Revision [14379]
This is an old revision of BookmarkManager made by BrianKoontz on 2006-05-29 13:22:20.
Bookmark Manager
An integrated bookmark manager in the spirit of de.lirio.us.Design ideas
- Allow both user-specific and site-wide bookmark access (other than those tagged as "private")
- Allow tagging of objects other than URIs (such as pages)
- Implement as both a handler and an action
Progress reports
- Beta test announcement: Well, after hacking around with Scuttle, I decided it was much too complex for what I had in mind. Nils suggested another project, Freetag, that seems to provide the basic functionality needed without all of the formatting/presentation overhead. I have a beta up and running here, and would appreciate your comments and suggestions! Keep in mind this is still quite rough around the edges, but I was aiming more towards proof-of-concept. I think something like this would be a cool addition (as a 100% modular plugin) to Wikka...
TODO
Indicates issues that have been addressed- This code is most likely not yet safe for a production environment! There is still some user data validation that needs to be done.
- As a general consideration it would be nice to provide this functionality as a handler.
- it would be nice to have a link for the add-form near list yours.
- how about something like my tags / all tags? (List all/list yours provides this functionality)
- what would be usefull: If I tag a link with the name of an existing wiki-page, this link could show up at the end of the page.
- Need to fix logic so "your" tags only display "your" links (also, identify tag cloud as "all" or "yours")
- Optional logic to display tags in a right-justified vertical list instead of a cloud
- Paging, user prefs
- Tag pages as well as links
- 1. please put the wikka_freetag class in a file like Wikka.freetag.class.php in the new \libs directory. 2. $freetag_options -> why not use the params provided by wikka ($this->mysql_host, etc.)?
- Create bookmarklets such as these (borrowed from de.lirio.us):
post bookmarklet: javascript:location.href='http://de.lirio.us/rubric/post?uri='+escape(location.href)+'&title='+encodeURIComponent(document.title)+'&when_done=go_back' post bookmarklet (with popup): javascript:void(open('http://de.lirio.us/rubric/post?uri='+escape(location.href)+'&title='+encodeURIComponent(document.title)+'&when_done=close','Rubric','toolbar=no,width=700,height=325,scrollbars'));
- Provide edit/delete functionality
Installation
- Install a copy of Freetag in 3rdparty/plugins Check for freetag library
include_once('Wikka.freetag.class.php');
$freetag_options = array(
'db_user' => 'root',
'db_pass' => ,
'db_host' => 'localhost',
'db_name' => 'freetag',
'PCONNECT' => true,
);
function wikka_id_to_tagger_id ($wikka_id, $obj, $freetag_options) {
if(!isset($wikka_id)) {
return NULL;
}
$res = $obj->LoadSingle("select tagger_id from ".$freetag_options['db_name'].".freetag_wikka_id_map where wikka_id = '".$wikka_id."';");
$tagger_id = $res['tagger_id'];
if(!$tagger_id) {
$obj->Query("insert ".$freetag_options['db_name'].".freetag_wikka_id_map set "."wikka_id = '".$wikka_id."';");
$res = $obj->LoadSingle("select last_insert_id();");
$tagger_id = $res['last_insert_id()'];
}
return $tagger_id;
}
function output_tag_cloud($freetag,$tag_page_url,$tagger_id=NULL,$header=NULL) {
Output tag cloud
print "<div class='floatr'>";
if($header) {
print $header."<br/>";
}
print $freetag->get_tag_cloud_html(100,10,20,'px','cloud_tag',$tag_page_url,$tagger_id);
print "</div>";
print "<div class=\"clear\"> </div>";
}
echo "<h1>BookmarkTest</h1>";
echo "<a href=\.$this->href()."&action=list_all"."\">List all | ".
".$this->href()."&action=list_yours"."\">List yours</a> | ".
"<a href=\.$this->href()."&action=add"."\">Add
"; $wikka_id = $this->GetUserName(); $tagger_id = wikka_id_to_tagger_id($wikka_id, $this, $freetag_options); $freetag = new wikka_freetag($freetag_options); if(!isset($_REQUEST['action'])) { // Display all tags at start of session $this->Redirect($this->href()."&action=list_all"); } // Add new entry to DB if(isset($_REQUEST['action']) && ($_REQUEST['action']=="add")) { if(trim($_REQUEST['tags']) != ) {
"; $wikka_id = $this->GetUserName(); $tagger_id = wikka_id_to_tagger_id($wikka_id, $this, $freetag_options); $freetag = new wikka_freetag($freetag_options); if(!isset($_REQUEST['action'])) { // Display all tags at start of session $this->Redirect($this->href()."&action=list_all"); } // Add new entry to DB if(isset($_REQUEST['action']) && ($_REQUEST['action']=="add")) { if(trim($_REQUEST['tags']) != ) {
Private bookmark?
$private = 0;
if(strpos(trim($_REQUEST['tags']), "@private") ! false)
false)
$private = 1;
$this->Query("insert ".$freetag_options['db_name'].".freetag_bookmarks set ".
"title = '".mysql_real_escape_string($_REQUEST['title'])."', ".
"uri = '".mysql_real_escape_string($this->cleanUrl($_REQUEST['uri']))."', ".
"wikka_id = '".$wikka_id."', ".
"private = '".$private."', ".
"description = '".mysql_real_escape_string($_REQUEST['desc'])."';");
$last_id = $this->LoadSingle("select last_insert_id();");
$freetag->tag_object($tagger_id, $last_id['last_insert_id()'], $_REQUEST['tags']);
$this->Redirect($this->href()."&action=list_yours");
} else {
Display add form
?>
<input type="hidden" name="action" value="add" />
<table>
<tr>
<td align="right">Title:</td>
<td><input name="title" size="40"/></td>
</tr>
<tr>
<td align="right">URI:
<td><input name="uri" size="40"/></td>
</tr>
<tr>
<td align="right">Description:</td>
<td><input name="desc" size="40"/></td>
</tr>
<tr>
<td align="right"></td>
<td><?php echo $this->Format("Use blank space between tags, include \"@private\" for private bookmark"); ?></td>
</tr>
<tr>
<td align="right">Tags:</td>
<td><input name="tags" size="40"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Add" size="40" /></td>
</tr>
</table>
<?php
}
}
Edit entry
if(isset($_REQUEST['action']) && ($_REQUEST['action']
"edit") && ($object_id = mysql_real_escape_string($_REQUEST['object_id']))) {
$obj = $this->LoadSingle("select bookmark_id,title,uri,description,wikka_id from ".$freetag_options['db_name'].".freetag_bookmarks where bookmark_id = ".$object_id.";");
Is the logged-in user the owner?
if($wikka_id != $obj['wikka_id']) {
$this->Redirect($this->href()."&action=list_all");
}
if(isset($_REQUEST['modify']) && trim($_REQUEST['tags']) != ) {
// Delete all tags, then re-tag
$freetag->delete_all_object_tags_for_user($tagger_id,$object_id);
// Private bookmark?
$private = 0;
if(strpos(trim($_REQUEST['tags']), "@private") !== false)
$private = 1;
$this->Query("update ".$freetag_options['db_name'].".freetag_bookmarks set ".
"title = '".mysql_real_escape_string($_REQUEST['title'])."', ".
"uri = '".mysql_real_escape_string($this->cleanUrl($_REQUEST['uri']))."', ".
"wikka_id = '".$wikka_id."', ".
"private = '".$private."', ".
"description = '".mysql_real_escape_string($_REQUEST['desc'])."' ".
"where bookmark_id = ".$object_id." ".
"limit 1;");
$freetag->tag_object($tagger_id, $obj['bookmark_id'], $_REQUEST['tags']);
$this->Redirect($this->href()."&action=list_yours");
}
// Display add form
print($this->FormOpen());
?>
;
Title: | |
URI: | |
Description: | |
Format("Use blank space between tags, include \"@private\" for private bookmark"); ?> | |
Tags: | get_tags_on_object($object_id); $taglist =
foreach($tags as $idx=>$res) {
$taglist .= trim($res['raw_tag'])." ";
}
?>
<td><input name="tags" size="40" value="<?php print $taglist?>"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Edit" size="40" /></td>
</tr>
</table>
<?php
print($this->FormClose());
}
Delete entry
if(isset($_REQUEST['action']) && $_REQUEST['action']"delete") {
"delete") {
$object_id = mysql_real_escape_string($_REQUEST['object_id']);
Is the logged-in user the owner?
if($wikka_id != $obj['wikka_id']) {
$this->Redirect($this->href()."&action=list_all");
}
Delete all tags first...
$freetag->delete_all_object_tags_for_user($tagger_id,$object_id);
...then delete object
$this->Query("delete from ".$freetag_options['db_name'].".freetag_bookmarks where bookmark_id = ".$object_id." limit 1;");
$this->Redirect($this->href()."&action=list_yours");
}
List all bookmarks (ordered by most recent)
if(isset($_REQUEST['action']) && ($_REQUEST['action']
"list_all")) {
Output tag cloud
$url_opts = $this->href()."&action=list_all&tag=";
output_tag_cloud($freetag,$url_opts,NULL,"All tags:");
$ids = ;
if(isset($_REQUEST['tag']) && $_REQUEST['tag'] != ) {
$ids = $freetag->get_most_recent_objects(NULL,$_REQUEST['tag']);
} else {
$ids = $freetag->get_most_recent_objects();
}
foreach($ids as $key=>$val) {
$tags = $freetag->get_tags_on_object($val['object_id']);
$objs = $this->LoadAll("select title,uri,description,wikka_id from ".$freetag_options['db_name'].".freetag_bookmarks where bookmark_id = ".$val['object_id']." and private = 0;");
foreach($objs as $idx=>$obj) {
print "<a href=\.$obj['uri']."\">".$obj['title']."
"; print "
"; print "
foreach($tags as $idx=>$res) {
$taglist .= trim($res['tag'])." ";
}
print $taglist."by ".$obj['wikka_id']." (created: ".$val['tagged_on'].")";
print "</div><div class=\"clear\"> </div>";
}
}
}
List user bookmarks (ordered by most recent)
if(isset($_REQUEST['action']) && ($_REQUEST['action']"list_yours")) {
"list_yours")) {
Output tag cloud
$url_opts = $this->href()."&action=list_yours&tag=";
output_tag_cloud($freetag,$url_opts,$tagger_id,"Your tags:");
$ids = ;
if(isset($_REQUEST['tag']) && $_REQUEST['tag'] != ) {
$ids = $freetag->get_most_recent_objects($tagger_id,$_REQUEST['tag']);
} else {
$ids = $freetag->get_most_recent_objects($tagger_id);
}
foreach($ids as $key=>$val) {
$tags = $freetag->get_tags_on_object($val['object_id']);
foreach($objs as $idx=>$obj) {
print "|";
print "<a href=\.$this->href()."&action=delete&object_id=".$val['object_id']."\">delete";
print "
"; $taglist = ;
"; $taglist = ;
foreach($tags as $idx=>$res) {
$taglist .= trim($res['raw_tag'])." ";
}
print $taglist."by ".$obj['wikka_id']." (created: ".$val['tagged_on'].")</div>";
print "<div class=\"clear\"> </div>";
}
}
}
?>- Save the following file as ##actions/Wikka.freetag.class.php## (needs to be moved to libs/ eventually): **Wikka.freetag.class.php**
<?php
Check for freetag library
$freetag_lib = '3rdparty/plugins/freetag/freetag.class.php';
if(!is_file($freetag_lib)) {
print("<br/><br/><div class=\"error\">".$this->Format("Can't find $freetag_lib!")."<br/><br/>\n");
die();
}
include_once($freetag_lib);
class wikka_freetag extends freetag {
function wikka_freetag($freetag_options) {
parent::freetag($freetag_options);
}
function get_most_recent_objects($tagger_id = NULL, $tag = NULL, $offset = 0, $limit = 25) {
$db = $this->db;
if(isset($tagger_id)) {
$tagger_sql = "AND tagger_id = $tagger_id";
} else {
$tagger_sql = ;
}
$prefix = $this->_table_prefix;
$sql = ;
if(!$tag) {
$sql = "SELECT DISTINCT object_id, tagged_on FROM
${prefix}freetagged_objects
WHERE 1
$tagger_sql
ORDER BY tagged_on DESC
LIMIT $offset, $limit ";
} else {
$tag = $db->qstr($tag, get_magic_quotes_gpc());
$sql = "SELECT DISTINCT object_id, tagged_on
FROM ${prefix}freetagged_objects INNER JOIN ${prefix}freetags ON (tag_id = id)
WHERE tag = $tag
$tagger_sql
ORDER BY tagged_on DESC
LIMIT $offset, $limit ";
}
$rs = $db->Execute($sql) or die("Syntax Error: $sql");
$retarr = array();
while(!$rs->EOF) {
$retarr[] = array(
'object_id' => $rs->fields['object_id'],
'tagged_on' => $rs->fields['tagged_on']
);
}
return $retarr;
}
}
- Adjust the DB connection parameters for your own installation - (Optional) After line 918 in ##freetag.class.php##, add the following line to prevent @private tags from cluttering up the landscape:
foreach ($tag_list as $tag => $qty) {
Add the following line:
if(strpos($tag, "private") !
false) continue;
$size = $min_font_size + ($qty - $min_qty) * $step;
- Add the {{bookmarks}} handler code to a new page
"; $taglist =