3 * Table Definition for message
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Message extends Memcached_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'message'; // table name
13 public $id; // int(4) primary_key not_null
14 public $uri; // varchar(255) unique_key
15 public $from_profile; // int(4) not_null
16 public $to_profile; // int(4) not_null
17 public $content; // text()
18 public $rendered; // text()
19 public $url; // varchar(255)
20 public $created; // datetime() not_null
21 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
22 public $source; // varchar(32)
25 function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Message',$k,$v); }
27 /* the code above is auto generated do not remove the tag below */
32 return Profile::staticGet('id', $this->from_profile);
37 return Profile::staticGet('id', $this->to_profile);
40 static function saveNew($from, $to, $content, $source) {
41 $sender = Profile::staticGet('id', $from);
43 if (!$sender->hasRight(Right::NEWMESSAGE)) {
44 // TRANS: Client exception thrown when a user tries to send a direct message while being banned from sending them.
45 throw new ClientException(_('You are banned from sending direct messages.'));
48 $user = User::staticGet('id', $sender->id);
52 $msg->from_profile = $from;
53 $msg->to_profile = $to;
55 // Use the sender's URL shortening options.
56 $msg->content = $user->shortenLinks($content);
58 $msg->content = common_shorten_links($content);
60 $msg->rendered = common_render_text($msg->content);
61 $msg->created = common_sql_now();
62 $msg->source = $source;
64 $result = $msg->insert();
67 common_log_db_error($msg, 'INSERT', __FILE__);
68 // TRANS: Message given when a message could not be stored on the server.
69 return _('Could not insert message.');
73 $msg->uri = common_local_url('showmessage', array('message' => $msg->id));
75 $result = $msg->update($orig);
78 common_log_db_error($msg, 'UPDATE', __FILE__);
79 // TRANS: Message given when a message could not be updated on the server.
80 return _('Could not update message with new URI.');
86 static function maxContent()
88 $desclimit = common_config('message', 'contentlimit');
89 // null => use global limit (distinct from 0!)
90 if (is_null($desclimit)) {
91 $desclimit = common_config('site', 'textlimit');
96 static function contentTooLong($content)
98 $contentlimit = self::maxContent();
99 return ($contentlimit > 0 && !empty($content) && (mb_strlen($content) > $contentlimit));
104 $from = User::staticGet('id', $this->from_profile);
105 $to = User::staticGet('id', $this->to_profile);
107 mail_notify_message($this, $from, $to);