return;
}
- common_save_replies($notice);
+ common_save_replies($notice);
+ $notice->saveTags();
common_broadcast_notice($notice);
$returnto = $this->trimmed('returnto');
common_server_error(_('Error inserting notice'), 500);
return false;
}
- common_save_replies($notice);
+ common_save_replies($notice);
+ $notice->saveTags();
common_broadcast_notice($notice, true);
}
return true;
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;
+ }
}
--- /dev/null
+<?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
+}
profile_id integer not null comment 'profile replied to' references profile (id),
modified timestamp not null comment 'date this record was modified',
replied_id integer comment 'notice replied to (not used, see notice.reply_to)',
-
+
constraint primary key (notice_id, profile_id),
index reply_notice_id_idx (notice_id),
index reply_profile_id_idx (profile_id),
) 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;
--- /dev/null
+#!/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__);
+ }
+}
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');
}
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) {
$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);
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);
}
function common_date_rfc2822($dt) {
$t = strtotime($dt);
- return date("r", $t);
+ return date("r", $t);
}
function common_date_iso8601($dt) {
$t = strtotime($dt);
- return date("c", $t);
+ return date("c", $t);
}
function common_redirect($url, $code=307) {
if ($user) {
return $user->uri;
}
-
+
$remote = Remote_profile::staticGet($profile->id);
if ($remote) {
return $remote->uri;
echo "Aborting...\n";
exit(1);
break;
-
+
case E_USER_WARNING:
echo "WARNING [$errno] $errstr\n";
break;
-
+
case E_USER_NOTICE:
echo "My NOTICE [$errno] $errstr\n";
break;
-
+
default:
echo "Unknown error type: [$errno] $errstr\n";
break;
}
-
+
/* Don't execute PHP internal error handler */
return true;
}
if (!$this->conn) {
return false;
}
-
+
return !$this->conn->isDisconnected();
}
$this->confirmation_queue();
}
}
-
+
function handle_session($pl) {
# XXX what to do here?
return true;
}
-
+
function get_user($from) {
$user = User::staticGet('jabber', jabber_normalize_jid($from));
return $user;
return false;
}
}
-
+
function from_site($address, $msg) {
$text = '['.common_config('site', 'name') . '] ' . $msg;
jabber_send_message($address, $text);
return;
}
$notice->query('COMMIT');
- common_save_replies($notice);
+ common_save_replies($notice);
+ $notice->saveTags();
common_real_broadcast($notice);
$this->log(LOG_INFO,
'Added notice ' . $notice->id . ' from user ' . $user->nickname);
$user = User::staticGet($notice->profile_id);
return !$user;
}
-
+
function confirmation_queue() {
# $this->clear_old_confirm_claims();
$this->log(LOG_INFO, 'checking for queued confirmations');
}
} while ($confirm);
}
-
+
function next_confirm() {
$confirm = new Confirm_address();
$confirm->whereAdd('claimed IS NULL');
}
return NULL;
}
-
+
function clear_old_confirm_claims() {
$confirm = new Confirm();
$confirm->claimed = NULL;
$confirm->whereAdd('now() - claimed > '.CLAIM_TIMEOUT);
$confirm->update(DB_DATAOBJECT_WHEREADD_ONLY);
}
-
+
}
$resource = ($argc > 1) ? $argv[1] : NULL;