First cut at hastags support.
darcs-hash:20080720055702-533db-193ed842b0d0a952bef71a3c5287213ada0ef15c.gz
This commit is contained in:
parent
e4f1d6f504
commit
5d84485001
@ -72,6 +72,7 @@ class NewnoticeAction extends Action {
|
||||
}
|
||||
|
||||
common_save_replies($notice);
|
||||
$notice->saveTags();
|
||||
common_broadcast_notice($notice);
|
||||
|
||||
$returnto = $this->trimmed('returnto');
|
||||
|
@ -90,6 +90,7 @@ class PostnoticeAction extends Action {
|
||||
return false;
|
||||
}
|
||||
common_save_replies($notice);
|
||||
$notice->saveTags();
|
||||
common_broadcast_notice($notice, true);
|
||||
}
|
||||
return true;
|
||||
|
@ -51,4 +51,28 @@ class Notice extends DB_DataObject
|
||||
function getProfile() {
|
||||
return Profile::staticGet($this->profile_id);
|
||||
}
|
||||
|
||||
function saveTags() {
|
||||
/* extract all #hastags */
|
||||
$count = preg_match_all('/(?:^|\s)#([a-z0-9]{1,64})/', strtolower($this->content), $match);
|
||||
if (!$count) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Add them to the database */
|
||||
foreach(array_unique($match[1]) as $hashtag) {
|
||||
$tag = DB_DataObject::factory('Notice_tag');
|
||||
$tag->notice_id = $this->id;
|
||||
$tag->tag = $hashtag;
|
||||
$tag->created = $this->created;
|
||||
$id = $tag->insert();
|
||||
if (!$id) {
|
||||
$last_error = PEAR::getStaticProperty('DB_DataObject','lastError');
|
||||
common_log(LOG_ERROR, 'DB error inserting hashtag: ' . $last_error->message);
|
||||
common_server_error(sprintf(_('DB error inserting hashtag: %s'), $last_error->message));
|
||||
return;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
22
classes/Notice_tag.php
Normal file
22
classes/Notice_tag.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Table Definition for notice_tag
|
||||
*/
|
||||
require_once 'DB/DataObject.php';
|
||||
|
||||
class Notice_tag extends DB_DataObject
|
||||
{
|
||||
###START_AUTOCODE
|
||||
/* the code below is auto generated do not remove the above tag */
|
||||
|
||||
public $__table = 'notice_tag'; // table name
|
||||
public $tag; // varchar(64) primary_key not_null
|
||||
public $notice_id; // int(4) primary_key not_null
|
||||
public $created; // datetime() not_null
|
||||
|
||||
/* Static get */
|
||||
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Notice_tag',$k,$v); }
|
||||
|
||||
/* the code above is auto generated do not remove the tag below */
|
||||
###END_AUTOCODE
|
||||
}
|
@ -226,3 +226,12 @@ create table queue_item (
|
||||
|
||||
) ENGINE=MyISAM;
|
||||
|
||||
/* Hash tags */
|
||||
create table notice_tag (
|
||||
tag varchar( 64 ) not null comment 'hash tag associated with this notice',
|
||||
notice_id integer not null comment 'notice tagged' references notice (id),
|
||||
created datetime not null comment 'date this record was created',
|
||||
|
||||
constraint primary key (tag, notice_id),
|
||||
index notice_tag_created_idx (created)
|
||||
) ENGINE=MyISAM;
|
||||
|
46
fixup_hashtags.php
Executable file
46
fixup_hashtags.php
Executable file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/*
|
||||
* Laconica - a distributed open-source microblogging tool
|
||||
* Copyright (C) 2008, Controlez-Vous, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
# Abort if called from a web server
|
||||
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
|
||||
print "This script must be run from the command line\n";
|
||||
exit();
|
||||
}
|
||||
|
||||
define('INSTALLDIR', dirname(__FILE__));
|
||||
define('LACONICA', true);
|
||||
|
||||
require_once(INSTALLDIR . '/lib/common.php');
|
||||
|
||||
common_log(LOG_INFO, 'Starting to do old notices.');
|
||||
|
||||
$notice = new Notice();
|
||||
$cnt = $notice->find();
|
||||
|
||||
while ($notice->fetch()) {
|
||||
common_log(LOG_INFO, 'Getting replies for notice #' . $notice->id);
|
||||
$notice->saveTags();
|
||||
$original = clone($notice);
|
||||
$notice->rendered = common_render_content($notice->content, $notice);
|
||||
$result = $notice->update($original);
|
||||
if (!$result) {
|
||||
common_log_db_error($notice, 'UPDATE', __FILE__);
|
||||
}
|
||||
}
|
@ -115,6 +115,5 @@ require_once(INSTALLDIR.'/classes/Confirm_address.php');
|
||||
require_once(INSTALLDIR.'/classes/Remember_me.php');
|
||||
require_once(INSTALLDIR.'/classes/Queue_item.php');
|
||||
require_once(INSTALLDIR.'/classes/Reply.php');
|
||||
require_once(INSTALLDIR.'/classes/Sms_carrier.php');
|
||||
|
||||
require_once('markdown.php');
|
||||
|
17
lib/util.php
17
lib/util.php
@ -275,6 +275,7 @@ function common_nav_menu() {
|
||||
}
|
||||
common_menu_item(common_local_url('public'), _('Public'));
|
||||
common_menu_item(common_local_url('peoplesearch'), _('Search'));
|
||||
common_menu_item(common_local_url('tags'), _('Tags'));
|
||||
common_menu_item(common_local_url('doc', array('title' => 'help')),
|
||||
_('Help'));
|
||||
if ($user) {
|
||||
@ -603,11 +604,15 @@ function common_render_content($text, $notice) {
|
||||
$r = preg_replace('@https?://[^)\]>\s]+@', '<a href="\0" class="extlink">\0</a>', $r);
|
||||
$r = preg_replace('/(^|\s+)@([a-z0-9]{1,64})/e', "'\\1@'.common_at_link($id, '\\2')", $r);
|
||||
$r = preg_replace('/^T ([A-Z0-9]{1,64}) /e', "'T '.common_at_link($id, '\\1').' '", $r);
|
||||
# XXX: # tags
|
||||
$r = preg_replace('/(^|\s+)#([a-z0-9]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r);
|
||||
# XXX: machine tags
|
||||
return $r;
|
||||
}
|
||||
|
||||
function common_tag_link($tag) {
|
||||
return '<a href="' . htmlspecialchars(common_path('tag/' . $tag)) . '" class="hashlink">' . $tag . '</a>';
|
||||
}
|
||||
|
||||
function common_at_link($sender_id, $nickname) {
|
||||
$sender = Profile::staticGet($sender_id);
|
||||
$recipient = common_relative_profile($sender, $nickname);
|
||||
@ -790,6 +795,16 @@ function common_fancy_url($action, $args=NULL) {
|
||||
return common_path('search/notice/rss' . (($args) ? ('?' . http_build_query($args)) : ''));
|
||||
case 'avatarbynickname':
|
||||
return common_path($args['nickname'].'/avatar/'.$args['size']);
|
||||
case 'tag':
|
||||
if (isset($args['tag']) && $args['tag']) {
|
||||
$path = 'tag/' . $args['tag'];
|
||||
unset($args['tag']);
|
||||
} else {
|
||||
$path = 'tags';
|
||||
}
|
||||
return common_path($path . (($args) ? ('?' . http_build_query($args)) : ''));
|
||||
case 'tags':
|
||||
return common_path('tags' . (($args) ? ('?' . http_build_query($args)) : ''));
|
||||
default:
|
||||
return common_simple_url($action, $args);
|
||||
}
|
||||
|
@ -252,6 +252,7 @@ class XMPPDaemon {
|
||||
}
|
||||
$notice->query('COMMIT');
|
||||
common_save_replies($notice);
|
||||
$notice->saveTags();
|
||||
common_real_broadcast($notice);
|
||||
$this->log(LOG_INFO,
|
||||
'Added notice ' . $notice->id . ' from user ' . $user->nickname);
|
||||
|
Loading…
Reference in New Issue
Block a user