create server variable for bookmarklet
evaluate MVC architecture w/ template system
-add description field
+smart urls
+filter by tags
tags:
-
delimit tags with commas in db (?)
- need UNIQUE field in tags
- increment tag count on insert
- decrement tag count on delete
- if zero delete row
-
see: http://www.pui.ch/phred/archives/2005/05/tags-with-mysql-fulltext.html
\ No newline at end of file
$params = array();
$params['user'] = isset($_GET['user']) ? $_GET['user'] : null;
+$params['id'] = isset($_GET['id']) ? $_GET['id'] : null;
+
+$format = isset($pathinfo['extension']) ? $pathinfo['extension'] : null;
$dbh = get_db_connection();
$dbh->beginTransaction();
$q->execute( array( $user['id'] ));
}
}
+ if ($params['id']) {
+ $q = $dbh->prepare("SELECT *, clumps.id as clump_id
+ FROM clumps
+ JOIN users
+ ON users.id = clumps.user_id
+ WHERE clumps.id = ?
+ ORDER BY date DESC");
+ $q->execute( array( $params['id'] ));
+ }
else {
$q = $dbh->prepare("SELECT *, clumps.id as clump_id
FROM clumps
exit;
}
-
switch ($format) {
case 'xml' :
case 'rss' :
exit;
}
+
+?><!DOCTYPE html>
+
+<head>
+<title>clmpr</title>
+
+<?php include 'head.html'; ?>
+
+</head>
+<body>
+
+<?php include 'header.html'; ?>
+
+<p>
+bookmarklet:
+<?php
+ $js = file_get_contents('bookmarklet.js');
?>
+<a href="javascript:<?=$js?>">+</a>
+</p>
-<script>
+<hr />
- function deleteClump( id, elem ) {
- if (confirm("confirm delete")) {
- $.post('delete.php', { clump_id : id }, function(result) {
- $(elem).hide();
- }, 'json');
- return false;
- }
- }
+<script>
+function deleteClump( id, elem ) {
+ if (confirm("confirm delete")) {
+ $.post('delete.php', { clump_id : id }, function(result) {
+ $(elem).hide();
+ }, 'json');
+ return false;
+ }
+}
</script>
<ul class="links">
?>
<li>
-
- <?php if ($hasDescription) : ?>
+
+ <? /*
+ <?php if ($hasDescription || count($row['tags']) > 0 || $user['user'] == $row['user']) : ?>
<a href="#" class="more" onClick="$(this.parentNode).addClass('expand');">+</a>
<a href="#" class="less" onClick="$(this.parentNode).removeClass('expand');">-</a>
<?php else : ?>
<?php endif; ?>
+ */ ?>
+
<span class="url">
<a href="<?php echo $row['url'] ?>">
<?php echo $row['title'] ? $row['title'] : "<title>" ?>
</a>
- </span>
+ </span>
<span class="meta">
<?php echo date("Y-m-d", strtotime($row['date'])) ?> by
<a class="uname" href="/?user=<?php echo $row['user'] ?>"><?php echo $row['user'] ?></a>
- </span>
-
- <ul class="tags">
- <?php foreach($row['tags'] as $tag) : ?>
- <li><a href="/tags.php?tag=<?=$tag?>"><?=$tag?></a></li>
- <? endforeach; ?>
- </ul>
-
- <?php
- if ($user = get_user()):
- if ($user['user'] == $row['user']): ?>
- <!--
- <a href="" class="edit">✏</a> -->
- <a href="#" title="Delete" onClick="return deleteClump(<?php echo $row['clump_id']; ?>, this.parentNode);" class="delete">×</a>
- <?php
- endif;
- endif;
- ?>
+ </span>
+
+ <?php if ($user['user'] == $row['user']): ?>
+ <a href="/edit.php?id=<?php echo $row['clump_id'];?>" class="ui edit">✐</a>
+ <a href="#" title="Delete" onClick="return deleteClump(<?php echo $row['clump_id']; ?>, this.parentNode);" class="ui delete">×</a>
+ <?php endif; ?>
<div class="expand">
<?php if ($hasDescription) : ?>
- <p class="desc">
+ <span class="desc">
<?php echo $row['description']; ?>
- </p>
- <?php endif; ?>
+ </span>
+ <?php endif; ?>
+ <?php if (count($row['tags']) > 0) : ?>
+ <ul class="tags">
+ <?php foreach($row['tags'] as $tag) : ?>
+ <li><a href="/tags.php?tag=<?=$tag?>"><?=$tag?></a></li>
+ <? endforeach; ?>
+ </ul>
+ <?php endif; ?>
</div>
</li>
<?php endfor; ?>
</ul>
+
+
+<hr />
+
+<?php include 'footer.html' ?>
default :
if ($endpoint != '') {
-
$dbh = get_db_connection();
$dbh->beginTransaction();
$user = get_users($dbh, array( 'user' => $endpoint ));
}
}
-switch ($format) {
- case 'rss' :
- case 'xml' :
- include 'get.php';
- exit;
-}
-
-?><!DOCTYPE html>
-
-<head>
-<title>clmpr</title>
-
-<?php include 'head.html'; ?>
-
-</head>
-<body>
-
-<?php include 'header.html'; ?>
-
-<p>
-bookmarklet:
-<?php
- $js = file_get_contents('bookmarklet.js');
-?>
-<a href="javascript:<?=$js?>">+</a>
-</p>
-
-
-<hr />
-
-<?php include 'get.php'; ?>
-
-<hr />
-
-<?php include 'footer.html' ?>
+include 'get.php';
/*display:none;*/
}
ul.links li .expand {
- display:none;
- margin:0 0 1em 1em;
+ color:#aaa;
+ margin-bottom:1em;
}
ul.links li.expand .expand {
display:block;
}
-ul.links li.expand p.desc {
- /*display:block;*/
+ul.links li .desc {
+ display:inline-block;
+}
+ul.links li .tags {
+ display:inline-block;
}
ul.links li .less {
display:none;
display:inline;
}
-.delete {
- font-weight:bold;
- padding:0 3px;
- line-height:1em;
- background:#eee;
- color:#999;
+.ui {
+
+ color:#99f;
text-decoration:none;
}
-
-.delete:hover {
- text-decoration: none;
+.ui:hover {
+ text-decoration: none;
+}
+.ui.delete {
+ font-weight:bold;
+ color:#f9e;
+}
+.ui.edit {
}
form.new input[type="text"] {
}
else {
*/
- $q = $dbh->prepare("SELECT * FROM tags
- ORDER BY count DESC, tag ASC");
+ $q = $dbh->prepare("SELECT * FROM `tags`
+ WHERE `count` > 0
+ ORDER BY `count` DESC, `tag` ASC ");
$q->execute();
+
//}
}
<?php include 'header.html'; ?>
-
<p>tags</p>
+
<hr />
<ul class="tags">
-<?php for($i = 0; $row = $q->fetch(); $i++ ):
-?>
-
+<?php for($i = 0; $row = $q->fetch(); $i++ ): ?>
<li><span class="tag"><a href="<?php echo $row['tag'] ?>"><?php echo $row['tag'] ?></a> <?php echo $row['count'] ?></span></li>
-
<?php endfor; ?>
</ul>
<hr />
<?php include 'footer.html' ?>
-
-
-
--- /dev/null
+<?php
+
+include 'init.php';
+
+$params = array();
+$params['id'] = isset($_POST['id']) ? $_POST['id'] : null;
+$params['title'] = isset($_POST['title']) ? $_POST['title'] : null;
+$params['url'] = isset($_POST['url']) ? $_POST['url'] : null;
+$params['tags'] = isset($_POST['tags']) ? $_POST['tags'] : null;
+$params['description'] = isset($_POST['description']) ? $_POST['description'] : null;
+
+include 'head.html';
+
+try {
+
+ if ($user = get_user() && $params['id']) {
+
+ $dbh = get_db_connection();
+ $dbh->beginTransaction();
+
+ if ($params['id']) {
+ $q = $dbh->prepare("SELECT *, clumps.id as clump_id
+ FROM clumps
+ JOIN users
+ ON users.id = clumps.user_id
+ WHERE clumps.id = ?
+ ORDER BY date DESC");
+ $q->execute( array( $params['id'] ));
+ }
+ $clump = $q->fetch();
+ $clump['tags'] = explode(" ", $clump['tags']);
+
+ # process tags
+ $tags = explode(" ", $params['tags']);
+ $tags = array_unique($tags);
+ $tags_to_keep = array_intersect($tags, $clump['tags']);
+ $tags_to_delete = array_diff($clump['tags'], $tags_to_keep);
+ $tags_to_add = array_diff($tags, $tags_to_keep);
+
+ # add/increment new tags
+ if (count($tags_to_add) > 0) {
+ foreach($tags_to_add as $key => $tag) {
+ $sql = "INSERT INTO `clmpr`.`tags` ( `tag`, `count` )
+ VALUES ( ?, 1 )
+ ON DUPLICATE KEY UPDATE
+ `count` = `count` + 1";
+ $q = $dbh->prepare($sql);
+ $q->execute( array( $tag ));
+ }
+ }
+
+ # decrement old tags
+ # note: leaves tags in database with count of '0' if not used
+ if (count($tags_to_delete) > 0) {
+ foreach($tags_to_delete as $key => $tag) {
+ $sql = "UPDATE tags
+ SET count = count - 1
+ WHERE tag = ? AND count > 0";
+ $q = $dbh->prepare($sql);
+ $q->execute( array( $tag ));
+ }
+ }
+
+ # update clump
+ $sql = "UPDATE `clumps`
+ SET `url` = ?, `tags` = ?, `title` = ?, `description` = ?
+ WHERE `id` = ?";
+ $q = $dbh->prepare($sql);
+ $insert = $q->execute( array( $params['url'], implode(" ", $tags), $params['title'], $params['description'], $params['id']));
+
+ header('Location: /get.php?id=' . $params['id']);
+ //echo "clumped.<br/><br/>";
+ //echo '<a href="javascript:window.close();">ok</a>';
+ //echo '<script>window.close();</script>';
+
+ $dbh = null;
+ $q = null;
+
+ } else {
+ include 'signin.php';
+ }
+}
+catch(PDOException $e)
+{
+ echo $e->getMessage();
+}
+
+exit;