return false;
}
-
-
-function filter_tags($tagstr) {
-
- $tags = array();
-
- # split on commas if using commas
- if (strstr($tagstr, ',')) {
- $tags = explode(",", $tagstr);
- # replace spaces with dashes
- $tags = array_map(function ($tag) {
- $tag = trim($tag);
- return strpos($tag, " ") ? str_replace(" ", "-", $tag) : $tag;
- }, $tags);
- }
-
- # else, split on spaces
- else {
- $tags = explode(" ", $tagstr);
- $tags = array_map(function ($tag) {
- return trim($tag);
- }, $tags);
- }
-
- #filter tag dupes
- return array_unique($tags);
-}
if ($user && $params['clump_id']) {
# get current clump
- $q = $dbh->prepare("SELECT *
+ $q = $dbh->prepare("SELECT *
FROM clumps
- JOIN users ON users.id = clumps.user_id
- WHERE user_id = ? AND clumps.id = ?
+ JOIN users ON users.id = clumps.user_id
+ WHERE user_id = ? AND clumps.id = ?
LIMIT 1");
$q->execute( array( $user['id'], $params['clump_id'] ));
$row = $q->fetch();
# decrement tag count in DB
# note: leaves tags in database with count of '0' if not used
- $tags = explode(" ", $row['tags']);
+ $tags = explode(",", $row['tags']);
if (count($tags) > 0) {
foreach($tags as $key => $tag) {
$sql = "UPDATE tags
$q = $dbh->prepare($sql);
$q->execute( array( $tag ));
}
- }
+ }
# delete clump
$sql = "DELETE FROM clumps WHERE id = ? AND user_id = ?";
$q = $dbh->prepare($sql);
$count = $q->execute( array( $params['clump_id'], $user['id'] ));
- echo json_encode(array('deleted' => true));
+ echo json_encode(array('deleted' => true));
} else {
echo json_encode(array('mssg' => 'must be logged in'));
}
$dbh = null;
- $q = null;
-
+ $q = null;
+
}
catch(PDOException $e)
{
<input type="text" name="url" value="<?php echo $clump['url']; ?>">
</p>
- <p>
- <label>tags</label>
- <input type="text" id="tag-input" name="tags" value="<?php echo str_replace(' ', ',', $clump['tags']); ?>">
- </p>
+
+ <label>tags <a href="#" class="ui tag-help" onClick="$('#tag-help').toggle();return false;">how to tag »</a></label>
+ <ul id="tag-help" style="display:none">
+ <li><span class="bull">•</span>combine "multiple words" with quotes</li>
+ <li><span class="bull">•</span>separate tags by space, comma, semicolon, or enter</li>
+ </ul>
+ <input type="text" id="tag-input" name="tags" value="<?php echo $clump['tags']; ?>">
+
<p>
<label>description</label>
- <input type="text" name="description" value="<?php echo $clump['description']; ?>">
+ <input type="text" name="description" value="<?php echo htmlentities($clump['description']); ?>">
</p>
<p>
- saved <?php echo date("Y-m-d", strtotime($clump['date'])) ?> by
- <a class="uname" href="/?user=<?php echo $clump['user'] ?>"><?php echo $clump['user'] ?></a>
+ <span class="meta" title="<?php echo date('r', strtotime($clump['date'])); ?>">
+ saved <?php echo approximate_time(date('U') - strtotime($clump['date'])) ?> ago</a> by
+ <a class="uname" href="/<?php echo $clump['user'] ?>"><?php echo $clump['user'] ?></a>
+ </span>
</p>
<br />
if ($params['user']) {
$user = get_users($dbh, array('user' => $params['user'] ));
if ($user) {
- $q = $dbh->prepare("SELECT *, clumps.id as clump_id
- FROM clumps
- JOIN users
- ON users.id = clumps.user_id
- WHERE user_id = ?
+ $q = $dbh->prepare("SELECT *, clumps.id as clump_id
+ FROM clumps
+ JOIN users
+ ON users.id = clumps.user_id
+ WHERE user_id = ?
ORDER BY date DESC");
$q->execute( array( $user['id'] ));
}
}
else 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 = ?
+ $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'] ));
+ $q->execute( array( $params['id'] ));
}
else if ($endpoint == 'tag' && isset($urlparts[1])) {
$tag = $urlparts[1];
- $q = $dbh->prepare("SELECT *, clumps.id as clump_id
- FROM clumps
- JOIN users
- ON users.id = clumps.user_id
- WHERE tags LIKE ?
+ $q = $dbh->prepare("SELECT *, clumps.id as clump_id
+ FROM clumps
+ JOIN users
+ ON users.id = clumps.user_id
+ WHERE tags LIKE ?
ORDER BY date DESC");
$q->execute( array('%'.$tag.'%') );
}
else {
- $q = $dbh->prepare("SELECT *, clumps.id as clump_id
- FROM clumps
- JOIN users
- ON users.id = clumps.user_id
+ $q = $dbh->prepare("SELECT *, clumps.id as clump_id
+ FROM clumps
+ JOIN users
+ ON users.id = clumps.user_id
ORDER BY date DESC");
$q->execute();
}
<ul class="links">
-<?php if ($q) : for($i = 0; $row = $q->fetch(); $i++ ):
+<?php if ($q) : for($i = 0; $row = $q->fetch(); $i++ ):
# process description
$hasDescription = $row['description'] || false;
if ($row['tags'] == '')
$row['tags'] = array();
else
- $row['tags'] = explode(" ", $row['tags']);
+ $row['tags'] = explode(",", $row['tags']);
?>
-
+
<li>
-
+
<span class="url">
<a href="<?php echo $row['url'] ?>">
<?php echo $row['title'] ? $row['title'] : "<title>" ?>
</a>
- </span>
+ </span>
<div class="expand">
<?php if ($hasDescription) : ?>
<span class="desc">
- <?php echo $row['description']; ?>
+ <?php echo htmlentities($row['description']); ?>
</span>
- <?php endif; ?>
- <?php if (count($row['tags']) > 0) : ?>
+ <?php endif; ?>
+ <?php if (count($row['tags']) > 0) : ?>
<ul class="tags">
<?php foreach($row['tags'] as $tag) : ?>
<li><a href="/tag/<?=$tag?>"><?=$tag?></a></li>
<? endforeach; ?>
- </ul>
+ </ul>
<?php endif; ?>
</div>
-
<span class="meta">
<span title="<?php echo date('r', strtotime($row['date'])); ?>">
- <?php echo approximate_time(date('U') - strtotime($row['date'])) ?> ago</a> by
+ <?php echo approximate_time(date('U') - strtotime($row['date'])) ?> ago</a> by
<a class="uname" href="/<?php echo $row['user'] ?>"><?php echo $row['user'] ?></a>
</span>
// for inputting multi-word tags.
allowSpaces: false,
- // replace spaces with this string if set to something other than space in _cleanedInput()
- spaceChar: " ",
-
// Whether to animate tag removals or not.
animate: true,
_cleanedInput: function() {
// Returns the contents of the tag input, cleaned and ready to be passed to createTag
-
- // replace spaces with spacechar if set
- var _tval = this.options.spaceChar != ' ' ?
- this._tagInput.val().replace(/\ /g, this.options.spaceChar) : this._tagInput.val();
-
- return $.trim(_tval.replace(/^"(.*)"$/, '$1'));
+ return $.trim(this._tagInput.val().replace(/^"(.*)"$/, '$1'));
},
_lastTag: function() {
$("#tag-input").tagit({
availableTags : userTags,
animate : false,
- spaceChar : '-',
tabIndex : 3
});
$('.tagit input')[0].focus();
<input type="text" name="url" tabindex="2" value="<?=$params['url']?>">
</p>
- <label>tags <!-- <a href="#" class="tag-help" onClick="$('#tag-help').toggle();return false;">how to tag »</a> --></label>
- <!--
+ <label>tags <a href="#" class="ui tag-help" onClick="$('#tag-help').toggle();return false;">how to tag »</a></label>
<ul id="tag-help" style="display:none">
- <li><span class="bull">•</span>tag characters: [a-z 0-9 + # - .]</li>
- <li><span class="bull">•</span>combine multiple words into single-words with dashes</li>
- <li><span class="bull">•</span>delimit tags by space, comma, semicolon, or the enter key</li>
+ <li><span class="bull">•</span>combine "multiple words" with quotes</li>
+ <li><span class="bull">•</span>separate tags by space, comma, semicolon, enter</li>
</ul>
- -->
<input type="text" id="tag-input" name="tags" tabindex="3" value="">
<p>
$params = array();
$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;
+$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';
$dbh = get_db_connection();
$dbh->beginTransaction();
- # filter tags
- $tags = filter_tags($params['tags']);
-
- #insert tags
+ # process tags
+ $tags = explode(',', $params['tags']);
if (count($tags) > 0) {
foreach($tags as $key => $tag) {
- $q = $dbh->prepare("INSERT INTO `clmpr`.`tags` (`tag`, `count`)
+ $q = $dbh->prepare("INSERT INTO `tags` (`tag`, `count`)
VALUES ( ?, 1 )
ON DUPLICATE KEY
- UPDATE `count` = `count` + 1");
+ UPDATE `count` = `count` + 1");
$q->execute(array($tag));
}
}
# insert clump
- $q = $dbh->prepare("INSERT INTO `clmpr`.`clumps`
- ( `user_id`,
- `title`,
- `url`,
- `tags`,
- `description`,
- `date` )
- VALUES ( ?, ?, ?, ?, ?, NOW() ) ");
+ $q = $dbh->prepare("INSERT INTO `clumps`
+ ( `user_id`, `title`, `url`,
+ `tags`, `description`, `date` )
+ VALUES ( ?, ?, ?, ?, ?, NOW() ) ");
$insert = $q->execute( array(
- $user['id'],
- $params['title'],
- $params['url'],
- implode(" ", $tags),
- htmlentities($params['description'])));
+ $user['id'], $params['title'], $params['url'],
+ $params['tags'], $params['description']));
echo "clumped.<br/><br/>";
echo '<a href="javascript:window.close();">ok</a>';
ul.links li span.url a:hover {
text-decoration:none;
}
-ul.links li span.meta {
- color:#bbb;
- font-style:italic;
- font-size:12px;
-}
-ul.links li span.meta a {
- color:#999;
-}
ul.links li .desc {
color:#00d;
}
display:block;
}
+.meta {
+ color:#bbb;
+ font-style:italic;
+ font-size:12px;
+}
+.meta a {
+ color:#999;
+}
+
.ui {
font-size:12px;
$params['tags'] = isset($_POST['tags']) ? $_POST['tags'] : null;
$params['description'] = isset($_POST['description']) ? $_POST['description'] : null;
+//print_r($_POST);
+//exit;
+
try {
if ($user = get_user() && $params['id']) {
$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 = ?
+ $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'] ));
+ $q->execute( array( $params['id'] ));
}
$clump = $q->fetch();
- $clump['tags'] = explode(" ", $clump['tags']);
-
+ $clump['tags'] = explode(",", $clump['tags']);
+
# process tags
- $tags = filter_tags($params['tags']);
+ $tags = explode(',', $params['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 )
+ $sql = "INSERT INTO `clmpr`.`tags` ( `tag`, `count` )
+ VALUES ( ?, 1 )
ON DUPLICATE KEY UPDATE
`count` = `count` + 1";
$q = $dbh->prepare($sql);
$q = $dbh->prepare($sql);
$q->execute( array( $tag ));
}
- }
+ }
# update clump
- $sql = "UPDATE `clumps`
- SET `url` = ?, `tags` = ?, `title` = ?, `description` = ?
+ $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']));
+ $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 '<script>window.close();</script>';
$dbh = null;
- $q = null;
+ $q = null;
} else {
include 'signin.php';