summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/File.php8
-rw-r--r--classes/Group_alias.php2
-rw-r--r--classes/Notice.php26
-rw-r--r--classes/Profile.php3
-rw-r--r--classes/Profile_role.php1
-rw-r--r--classes/Subscription.php64
-rw-r--r--classes/User.php28
-rw-r--r--classes/User_group.php19
-rw-r--r--classes/User_username.php2
9 files changed, 89 insertions, 64 deletions
diff --git a/classes/File.php b/classes/File.php
index ba8332841..33273bbdc 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -194,7 +194,11 @@ class File extends Memcached_DataObject
{
require_once 'MIME/Type/Extension.php';
$mte = new MIME_Type_Extension();
- $ext = $mte->getExtension($mimetype);
+ try {
+ $ext = $mte->getExtension($mimetype);
+ } catch ( Exception $e) {
+ $ext = strtolower(preg_replace('/\W/', '', $mimetype));
+ }
$nickname = $profile->nickname;
$datestamp = strftime('%Y%m%dT%H%M%S', time());
$random = strtolower(common_confirmation_code(32));
@@ -281,7 +285,7 @@ class File extends Memcached_DataObject
$enclosure->mimetype=$this->mimetype;
if(! isset($this->filename)){
- $notEnclosureMimeTypes = array('text/html','application/xhtml+xml');
+ $notEnclosureMimeTypes = array(null,'text/html','application/xhtml+xml');
$mimetype = strtolower($this->mimetype);
$semicolon = strpos($mimetype,';');
if($semicolon){
diff --git a/classes/Group_alias.php b/classes/Group_alias.php
index be3d0a6c6..c5a1895a1 100644
--- a/classes/Group_alias.php
+++ b/classes/Group_alias.php
@@ -34,7 +34,7 @@ class Group_alias extends Memcached_DataObject
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Group_alias',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Group_alias',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
diff --git a/classes/Notice.php b/classes/Notice.php
index 4c7e6ab4b..f7194e339 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -119,6 +119,9 @@ class Notice extends Memcached_DataObject
// NOTE: we don't clear queue items
$result = parent::delete();
+
+ $this->blowOnDelete();
+ return $result;
}
/**
@@ -421,6 +424,18 @@ class Notice extends Memcached_DataObject
$profile->blowNoticeCount();
}
+ /**
+ * Clear cache entries related to this notice at delete time.
+ * Necessary to avoid breaking paging on public, profile timelines.
+ */
+ function blowOnDelete()
+ {
+ $this->blowOnInsert();
+
+ self::blow('profile:notice_ids:%d;last', $this->profile_id);
+ self::blow('public;last');
+ }
+
/** save all urls in the notice to the db
*
* follow redirects and save all available file information
@@ -589,7 +604,6 @@ class Notice extends Memcached_DataObject
array(),
'public',
$offset, $limit, $since_id, $max_id);
-
return Notice::getStreamByIds($ids);
}
@@ -1128,6 +1142,7 @@ class Notice extends Memcached_DataObject
if ($source) {
$xs->elementStart('source');
+ $xs->element('id', null, $profile->profileurl);
$xs->element('title', null, $profile->nickname . " - " . common_config('site', 'name'));
$xs->element('link', array('href' => $profile->profileurl));
$user = User::staticGet('id', $profile->id);
@@ -1143,13 +1158,14 @@ class Notice extends Memcached_DataObject
}
$xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE));
+ $xs->element('updated', null, common_date_w3dtf($this->created));
}
if ($source) {
$xs->elementEnd('source');
}
- $xs->element('title', null, $this->content);
+ $xs->element('title', null, common_xml_safe_str($this->content));
if ($author) {
$xs->raw($profile->asAtomAuthor());
@@ -1225,7 +1241,11 @@ class Notice extends Memcached_DataObject
}
}
- $xs->element('content', array('type' => 'html'), $this->rendered);
+ $xs->element(
+ 'content',
+ array('type' => 'html'),
+ common_xml_safe_str($this->rendered)
+ );
$tag = new Notice_tag();
$tag->notice_id = $this->id;
diff --git a/classes/Profile.php b/classes/Profile.php
index 91f6e4692..eded1ff71 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -732,6 +732,9 @@ class Profile extends Memcached_DataObject
function hasRight($right)
{
$result = false;
+ if ($this->hasRole(Profile_role::DELETED)) {
+ return false;
+ }
if (Event::handle('UserRightsCheck', array($this, $right, &$result))) {
switch ($right)
{
diff --git a/classes/Profile_role.php b/classes/Profile_role.php
index d0a0b31f0..e7aa1f0f0 100644
--- a/classes/Profile_role.php
+++ b/classes/Profile_role.php
@@ -53,6 +53,7 @@ class Profile_role extends Memcached_DataObject
const ADMINISTRATOR = 'administrator';
const SANDBOXED = 'sandboxed';
const SILENCED = 'silenced';
+ const DELETED = 'deleted'; // Pending final deletion of notices...
public static function isValid($role)
{
diff --git a/classes/Subscription.php b/classes/Subscription.php
index 5ac95f922..60c12cccc 100644
--- a/classes/Subscription.php
+++ b/classes/Subscription.php
@@ -62,6 +62,14 @@ class Subscription extends Memcached_DataObject
static function start($subscriber, $other)
{
+ // @fixme should we enforce this as profiles in callers instead?
+ if ($subscriber instanceof User) {
+ $subscriber = $subscriber->getProfile();
+ }
+ if ($other instanceof User) {
+ $other = $other->getProfile();
+ }
+
if (!$subscriber->hasRight(Right::SUBSCRIBE)) {
throw new Exception(_('You have been banned from subscribing.'));
}
@@ -75,20 +83,7 @@ class Subscription extends Memcached_DataObject
}
if (Event::handle('StartSubscribe', array($subscriber, $other))) {
-
- $sub = new Subscription();
-
- $sub->subscriber = $subscriber->id;
- $sub->subscribed = $other->id;
- $sub->created = common_sql_now();
-
- $result = $sub->insert();
-
- if (!$result) {
- common_log_db_error($sub, 'INSERT', __FILE__);
- throw new Exception(_('Could not save subscription.'));
- }
-
+ $sub = self::saveNew($subscriber->id, $other->id);
$sub->notify();
self::blow('user:notices_with_friends:%d', $subscriber->id);
@@ -103,20 +98,11 @@ class Subscription extends Memcached_DataObject
!self::exists($other, $subscriber) &&
!$subscriber->hasBlocked($other)) {
- $auto = new Subscription();
-
- $auto->subscriber = $other->id;
- $auto->subscribed = $subscriber->id;
- $auto->created = common_sql_now();
-
- $result = $auto->insert();
-
- if (!$result) {
- common_log_db_error($auto, 'INSERT', __FILE__);
- throw new Exception(_('Could not save subscription.'));
+ try {
+ self::start($other, $subscriber);
+ } catch (Exception $e) {
+ common_log(LOG_ERR, "Exception during autosubscribe of {$other->nickname} to profile {$subscriber->id}: {$e->getMessage()}");
}
-
- $auto->notify();
}
Event::handle('EndSubscribe', array($subscriber, $other));
@@ -125,6 +111,30 @@ class Subscription extends Memcached_DataObject
return true;
}
+ /**
+ * Low-level subscription save.
+ * Outside callers should use Subscription::start()
+ */
+ protected function saveNew($subscriber_id, $other_id)
+ {
+ $sub = new Subscription();
+
+ $sub->subscriber = $subscriber_id;
+ $sub->subscribed = $other_id;
+ $sub->jabber = 1;
+ $sub->sms = 1;
+ $sub->created = common_sql_now();
+
+ $result = $sub->insert();
+
+ if (!$result) {
+ common_log_db_error($sub, 'INSERT', __FILE__);
+ throw new Exception(_('Could not save subscription.'));
+ }
+
+ return $sub;
+ }
+
function notify()
{
# XXX: add other notifications (Jabber, SMS) here
diff --git a/classes/User.php b/classes/User.php
index 0b25b71a0..8ad2ec63d 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -153,19 +153,12 @@ class User extends Memcached_DataObject
return Sms_carrier::staticGet('id', $this->carrier);
}
+ /**
+ * @deprecated use Subscription::start($sub, $other);
+ */
function subscribeTo($other)
{
- $sub = new Subscription();
- $sub->subscriber = $this->id;
- $sub->subscribed = $other->id;
-
- $sub->created = common_sql_now(); // current time
-
- if (!$sub->insert()) {
- return false;
- }
-
- return true;
+ return Subscription::start($this->getProfile(), $other);
}
function hasBlocked($other)
@@ -213,6 +206,7 @@ class User extends Memcached_DataObject
if(! User::allowed_nickname($nickname)){
common_log(LOG_WARNING, sprintf("Attempted to register a nickname that is not allowed: %s", $profile->nickname),
__FILE__);
+ return false;
}
$profile->profileurl = common_profile_url($nickname);
@@ -345,17 +339,7 @@ class User extends Memcached_DataObject
common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick),
__FILE__);
} else {
- $defsub = new Subscription();
- $defsub->subscriber = $user->id;
- $defsub->subscribed = $defuser->id;
- $defsub->created = $user->created;
-
- $result = $defsub->insert();
-
- if (!$result) {
- common_log_db_error($defsub, 'INSERT', __FILE__);
- return false;
- }
+ Subscription::start($user, $defuser);
}
}
diff --git a/classes/User_group.php b/classes/User_group.php
index 0460c9870..110f08301 100644
--- a/classes/User_group.php
+++ b/classes/User_group.php
@@ -295,7 +295,7 @@ class User_group extends Memcached_DataObject
}
// If not, check local groups.
-
+
$group = Local_group::staticGet('nickname', $nickname);
if (!empty($group)) {
return User_group::staticGet('id', $group->group_id);
@@ -371,16 +371,15 @@ class User_group extends Memcached_DataObject
if ($source) {
$xs->elementStart('source');
+ $xs->element('id', null, $this->permalink());
$xs->element('title', null, $profile->nickname . " - " . common_config('site', 'name'));
$xs->element('link', array('href' => $this->permalink()));
- }
-
- if ($source) {
+ $xs->element('updated', null, $this->modified);
$xs->elementEnd('source');
}
$xs->element('title', null, $this->nickname);
- $xs->element('summary', null, $this->description);
+ $xs->element('summary', null, common_xml_safe_str($this->description));
$xs->element('link', array('rel' => 'alternate',
'href' => $this->permalink()));
@@ -390,7 +389,11 @@ class User_group extends Memcached_DataObject
$xs->element('published', null, common_date_w3dtf($this->created));
$xs->element('updated', null, common_date_w3dtf($this->modified));
- $xs->element('content', array('type' => 'html'), $this->description);
+ $xs->element(
+ 'content',
+ array('type' => 'html'),
+ common_xml_safe_str($this->description)
+ );
$xs->elementEnd('entry');
@@ -455,7 +458,7 @@ class User_group extends Memcached_DataObject
$group = new User_group();
$group->query('BEGIN');
-
+
if (empty($uri)) {
// fill in later...
$uri = null;
@@ -483,7 +486,7 @@ class User_group extends Memcached_DataObject
$result = $group->update($orig);
if (!$result) {
common_log_db_error($group, 'UPDATE', __FILE__);
- throw new ServerException(_('Could not set group uri.'));
+ throw new ServerException(_('Could not set group URI.'));
}
}
diff --git a/classes/User_username.php b/classes/User_username.php
index 853fd5cb8..8d99cddd3 100644
--- a/classes/User_username.php
+++ b/classes/User_username.php
@@ -55,7 +55,7 @@ class User_username extends Memcached_DataObject
// now define the keys.
function keys() {
- return array('provider_name', 'username');
+ return array('provider_name' => 'K', 'username' => 'K');
}
}