Revision [14464]

This is an old revision of BookmarkManager made by BrianKoontz on 2006-06-04 23:40:30.

 

Bookmark Manager

An integrated bookmark manager in the spirit of de.lirio.us.

Try it out! Beta version with latest code here.
 


Design ideas

Progress reports

TODO
Indicates issues that have been addressed

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'));


Installation
include_once('Wikka.freetag.class.php');

$freetag_options = array(
'db_user' => 'root',
'db_pass' => ,
'db_host' => 'localhost',
'db_name' => 'freetag',
'PCONNECT' => true,
);
$freetag = new wikka_freetag($freetag_options);

function wikka_id_to_tagger_id ($wikka_id, $obj, $freetag_options) {
if(!isset($wikka_id)) {
return NULL;
}
$wikka_id = mysql_real_escape_string($wikka_id);
$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,$tag_offset=0,$tag_limit=100) {
Output tag cloud
$tag_count = $freetag->count_unique_tags($tagger_id);
print "<div class='floatr'>";
if($header) {
print $header." (".$tag_count."):<br/>";
}
print $freetag->get_tag_cloud_html_with_limits($tag_offset,$tag_limit,10,20,'px','cloud_tag',$tag_page_url."&tag_offset=".$tag_offset."&tag_limit=".$tag_limit."&tag=",$tagger_id);

Display pagination links
$tag_url = ; $prev_offset = $tag_offset - $tag_limit; $prev_url = ;
if($prev_offset < 0) {
$prev_offset = 0;
}
if($tag_offset > 0) {
$prev_url = "<a href=\.$tag_page_url."&tag_offset=".$prev_offset."&tag_limit=".$tag_limit."\"><<"; } $next_offset = $tag_offset + $tag_limit; $next_url = ;
if($next_offset < $tag_count - 1) {
$next_url = "<a href=\.$tag_page_url."&tag_offset=".$next_offset."&tag_limit=".$tag_limit.$tag_url."\">>>"; } print "

"; print "

"; print $prev_url." ".$next_url; print "
"; print ""; print "
 
"; } /********************************************************************/ /* count_objects * * Returns a count of objects (bookmarks, links, etc.) * * NOTE: Set $wikka_id to NULL for all objects (except those marked * private) */ function count_objects($wikka_id, $obj, $freetag_options) { if(isset($wikka_id)) { $wikka_sql = "AND wikka_id = '".mysql_real_escape_string($wikka_id)."'"; } else { $wikka_sql = "AND private = 0"; } $res = $obj->LoadSingle("select COUNT(*) as count from ".$freetag_options['db_name'].".freetag_bookmarks where 1 ".$wikka_sql.";"); $count = $res['count']; return $count; } /********************************************************************/ /* count_tagged_objects * * Returns a count of tagged objects (bookmarks, links, etc.) * * NOTE: Set $wikka_id to NULL for all taggedobjects regardless of * owner (except those marked private) */ function count_tagged_objects($wikka_id, $tag, $obj, $freetag_options, $freetag) { $num_objs = count_objects($wikka_id, $obj, $freetag_options); $tagger_id = wikka_id_to_tagger_id($wikka_id, $obj, $freetag_options); $ids = $freetag->get_most_recent_objects($tagger_id, $tag, 0, $num_objs); return count($ids); } /********************************************************************/ $wikka_id = $this->GetUserName(); $tagger_id = wikka_id_to_tagger_id($wikka_id, $this, $freetag_options); $all_obj_count = count_objects(NULL, $this, $freetag_options); $your_obj_count = count_objects($wikka_id, $this, $freetag_options); echo "

BookmarkTest

"; echo ".$this->href()."&action=list_all"."\">List all</a> (".$all_obj_count.") | ".
"<a href=\.$this->href()."&action=list_yours"."\">List yours (".$your_obj_count.") | ". ".$this->href()."&action=add"."\">Add</a><br/>";


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) $private = 1; // Converts numeric tag "123" to "123_" to facilitate // alphanumeric sorting (otherwise, PHP converts string to // true integer). $tags = preg_split('/\s+/', $_REQUEST['tags'], -1, PREG_SPLIT_NO_EMPTY); $tags = preg_replace('/^([0-9]+)$/', "$1_", $tags); $tags = implode(" ", $tags); $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 = '".mysql_real_escape_string($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()'], $tags); $this->Redirect($this->href()."&action=list_yours"); } else { // Display add form print($this->FormOpen()); ?>
Title:
URI:
Description:
Format("Use blank space between tags, include \"@private\" for private bookmark"); ?>
Tags:
FormClose()); } } // Edit entry if(isset($_REQUEST['action']) && ($_REQUEST['action']=="edit") && (isset($_REQUEST['object_id']))) { $object_id = $_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;
$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 = '".mysql_real_escape_string($wikka_id)."', ".
"private = '".$private."', ".
"description = '".mysql_real_escape_string($_REQUEST['desc'])."' ".
"where bookmark_id = ".mysql_real_escape_string($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());
?>
<input type="hidden" name="action" value="edit" />
<input type="hidden" name="modify" value="yes" />
<input type="hidden" name="object_id" value="<?php print $object_id ?>" />
<table>
<tr>
<td align="right">Title:</td>
<td><input name="title" size="40" value="<?php print $obj['title']; ?>"/></td>
</tr>
<tr>
<td align="right">URI:
<td><input name="uri" size="40" value="<?php print $obj['uri']; ?>"/></td>
</tr>
<tr>
<td align="right">Description:</td>
<td><input name="desc" size="40" value="<?php print $obj['description']; ?>"/></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>
<?php
$tags = $freetag->get_tags_on_object($object_id);
$taglist = ; foreach($tags as $idx=>$res) { $taglist .= trim($res['raw_tag'])." "; } ?> FormClose()); } // Delete entry if(isset($_REQUEST['action']) && $_REQUEST['action']=="delete") { $object_id = $_REQUEST['object_id']; $obj = $this->LoadSingle("select bookmark_id,wikka_id from ".$freetag_options['db_name'].".freetag_bookmarks where bookmark_id = ".mysql_real_escape_string($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 = ".mysql_real_escape_string($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")) { $offset = 0; if(isset($_REQUEST['offset'])) { $offset = $_REQUEST['offset']; } $limit = 25; if(isset($_REQUEST['limit'])) { $limit = $_REQUEST['limit']; } $tag_offset = 0; if(isset($_REQUEST['tag_offset'])) { $tag_offset = $_REQUEST['tag_offset']; } $tag_limit = 100; if(isset($_REQUEST['tag_limit'])) { $tag_limit = $_REQUEST['tag_limit']; } // Output tag cloud $url_opts = $this->href()."&action=list_all"; output_tag_cloud($freetag,$url_opts,NULL,"All tags",$tag_offset,$tag_limit); $ids = ;
$tag = ; if(isset($_REQUEST['tag']) && $_REQUEST['tag'] != ) {
$ids = $freetag->get_most_recent_objects(NULL,$_REQUEST['tag'],$offset,$limit);
$tag = $_REQUEST['tag'];
} else {
$ids = $freetag->get_most_recent_objects(NULL,NULL,$offset,$limit);
}

foreach($ids as $key=>$val) {
$tags = $freetag->get_tags_on_object($val['object_id']);
$obj = $this->LoadSingle("select title,uri,description,wikka_id from ".$freetag_options['db_name'].".freetag_bookmarks where bookmark_id = ".$val['object_id']." and private = 0;");
if(!isset($obj)) {
continue;
}
print "<a href=\.$obj['uri']."\">".$obj['title']."
"; print "
".$obj['description'].""; print "
"; $taglist =
;
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>";
}

Display pagination links
$obj_count = 0;
$tag_url = ; if($tag != ) {
$obj_count = count_tagged_objects(NULL, $tag, $this, $freetag_options, $freetag);
$tag_url = "&tag=".$tag;
} else {
$obj_count = count_objects(NULL, $this, $freetag_options);
}
$prev_offset = $offset - $limit;
$prev_url = ; if($prev_offset < 0) { $prev_offset = 0; } if($offset > 0) { $prev_url = ".$this->href()."&action=list_all&offset=".$prev_offset."&limit=".$limit.$tag_url."\"><<</a>";
}
$next_offset = $offset + $limit;
$next_url = ; if($next_offset < $obj_count - 1) { $next_url = ".$this->href()."&action=list_all&offset=".$next_offset."&limit=".$limit.$tag_url."\">>></a>";
}
print "<p><p>";
print "<div class=\"center\">";
print $prev_url." ".$next_url;
print "</div>";
}

List user bookmarks (ordered by most recent)
if(isset($_REQUEST['action']) && ($_REQUEST['action']
$offset = 0;
if(isset($_REQUEST['offset'])) {
$offset = $_REQUEST['offset'];
}
$limit = 25;
if(isset($_REQUEST['limit'])) {
$limit = $_REQUEST['limit'];
}
$tag_offset = 0;
if(isset($_REQUEST['tag_offset'])) {
$tag_offset = $_REQUEST['tag_offset'];
}
$tag_limit = 100;
if(isset($_REQUEST['tag_limit'])) {
$tag_limit = $_REQUEST['tag_limit'];
}

Output tag cloud
$url_opts = $this->href()."&action=list_yours";
output_tag_cloud($freetag,$url_opts,$tagger_id,"Your tags",$tag_offset,$tag_limit);

$ids = ; $tag = ;
print "<div class=\"commentsheader\"><b>".$obj['description']."</b>";
print "<br/>";
$taglist = ; foreach($tags as $idx=>$res) { $taglist .= trim($res['raw_tag'])." "; } print $taglist."by ".$obj['wikka_id']." (created: ".$val['tagged_on'].")"; print "
 
"; } // Display pagination links $obj_count = 0; $tag_url = ;
if($tag != ) { $obj_count = count_tagged_objects($wikka_id, $tag, $this, $freetag_options, $freetag); $tag_url = "&tag=".$tag; } else { $obj_count = count_objects($wikka_id, $this, $freetag_options); } $prev_offset = $offset - $limit; $prev_url = ;
if($prev_offset < 0) {
$prev_offset = 0;
}
if($offset > 0) {
$prev_url = "<a href=\.$this->href()."&action=list_yours&offset=".$prev_offset."&limit=".$limit.$tag_url."\"><<"; } $next_offset = $offset + $limit; $next_url = ;
if($next_offset < $obj_count - 1) {
$next_url = "<a href=\.$this->href()."&action=list_yours&offset=".$next_offset."&limit=".$limit.$tag_url."\">>>"; } print "

"; print "

"; print $prev_url." ".$next_url; print "
"; } ?> %% - Save the following file as ##actions/Wikka.freetag.class.php## (needs to be moved to libs/ eventually): **Wikka.freetag.class.php** %%(php) * * 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 Licence for more details: * * http://www.gnu.org/copyleft/gpl.html * *********************************************************************/ // Check for freetag library $freetag_lib = '3rdparty/plugins/freetag/freetag.class.php'; if(!is_file($freetag_lib)) { print("

".$this->Format("Can't find $freetag_lib!")."

\n"); die(); } include_once($freetag_lib); /********************************************************************/ /* Freetag subclass (defines additional support methods) */ /********************************************************************/ class wikka_freetag extends freetag { function wikka_freetag($freetag_options) { parent::freetag($freetag_options); } /** * get_most_recent_objects * * This function returns the most recent object ids in the * freetag system, with offset and limit support for * pagination. It also supports restricting to an individual * user. Call it with no parameters for a list of 25 most * recent tags. * * @param int The unique ID of the person to restrict results to. * @param string Tag to filter by * @param int The offset of the object to start at. * @param int The number of object ids to return in the result set. * * @return array Returns a PHP array with object ids ordered by * timestamp descending. * Each element is an associative array with the following elements: * - 'object_id' => Object id * - 'tagged_on' => The timestamp of each object id */ 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'] ); $rs->MoveNext(); } 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: %%(php) 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 Unknown action ""bookmarks"""" handler code to a new page

Other stuff Category
CategoryDevelopmentDiscussion
There are 39 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki