]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'oembed-thumbnails' into 0.9.x
authorBrion Vibber <brion@status.net>
Fri, 12 Nov 2010 20:28:44 +0000 (12:28 -0800)
committerBrion Vibber <brion@status.net>
Fri, 12 Nov 2010 20:28:44 +0000 (12:28 -0800)
EVENTS.txt
actions/allrss.php
actions/emailsettings.php
db/074to080.sql
lib/statusnet.php
plugins/EmailSummary/EmailSummaryPlugin.php [new file with mode: 0644]
plugins/EmailSummary/Email_summary_status.php [new file with mode: 0644]
plugins/EmailSummary/sendemailsummary.php [new file with mode: 0644]
plugins/EmailSummary/siteemailsummaryhandler.php [new file with mode: 0644]
plugins/EmailSummary/useremailsummaryhandler.php [new file with mode: 0644]
plugins/Mapstraction/MapstractionPlugin.php

index 675ac5437e5713decef1cb791a7199935a936fb2..fed489705c29a7a26854f7cc70edc9633c3495ac 100644 (file)
@@ -302,6 +302,20 @@ StartProfileSaveForm: before starting to save a profile settings form
 EndProfileSaveForm: after saving a profile settings form (after commit, no profile or user object!)
 - $action: action object being shown
 
+StartEmailFormData: just before showing text entry fields on email settings page
+- $action: action object being shown
+
+EndEmailFormData: just after showing text entry fields on email settings page
+- $action: action object being shown
+
+StartEmailSaveForm: before starting to save a email settings form
+- $action: action object being shown
+- &$user: user being saved
+
+EndEmailSaveForm: after saving a email settings form (after commit)
+- $action: action object being shown
+- &$user: user being saved
+
 StartRegistrationFormData: just before showing text entry fields on registration page
 - $action: action object being shown
 
index d398c8a6ad126fbdfbe64560779943a054023fbe..573bb4eb2fac27c83a200df9d8b40bfa6347ed2a 100644 (file)
@@ -56,6 +56,8 @@ class AllrssAction extends Rss10Action
      * @param array $args Web and URL arguments
      *
      * @return boolean false if user doesn't exist
+     *
+     */
     function prepare($args)
     {
         parent::prepare($args);
index 9c250fc8a93a97a77d0fc7e3e3b22da18d1e8f60..5a816e5c0ab17fd4e3107baa7a3b77c0bd136fc4 100644 (file)
@@ -178,51 +178,55 @@ class EmailsettingsAction extends AccountSettingsAction
         $this->element('legend', null, _('Email preferences'));
 
         $this->elementStart('ul', 'form_data');
-        $this->elementStart('li');
-        $this->checkbox('emailnotifysub',
-                        // TRANS: Checkbox label in e-mail preferences form.
-                        _('Send me notices of new subscriptions through email.'),
-                        $user->emailnotifysub);
-        $this->elementEnd('li');
-        $this->elementStart('li');
-        $this->checkbox('emailnotifyfav',
-                        // TRANS: Checkbox label in e-mail preferences form.
-                        _('Send me email when someone '.
-                          'adds my notice as a favorite.'),
-                        $user->emailnotifyfav);
-        $this->elementEnd('li');
-        $this->elementStart('li');
-        $this->checkbox('emailnotifymsg',
-                        // TRANS: Checkbox label in e-mail preferences form.
-                        _('Send me email when someone sends me a private message.'),
-                        $user->emailnotifymsg);
-        $this->elementEnd('li');
-        $this->elementStart('li');
-        $this->checkbox('emailnotifyattn',
-                        // TRANS: Checkbox label in e-mail preferences form.
-                        _('Send me email when someone sends me an "@-reply".'),
-                        $user->emailnotifyattn);
-        $this->elementEnd('li');
-        $this->elementStart('li');
-        $this->checkbox('emailnotifynudge',
-                        // TRANS: Checkbox label in e-mail preferences form.
-                        _('Allow friends to nudge me and send me an email.'),
-                        $user->emailnotifynudge);
-        $this->elementEnd('li');
-        if (common_config('emailpost', 'enabled')) {
-            $this->elementStart('li');
-            $this->checkbox('emailpost',
-                            // TRANS: Checkbox label in e-mail preferences form.
-                            _('I want to post notices by email.'),
-                            $user->emailpost);
-            $this->elementEnd('li');
-        }
-        $this->elementStart('li');
-        $this->checkbox('emailmicroid',
-                        // TRANS: Checkbox label in e-mail preferences form.
-                        _('Publish a MicroID for my email address.'),
-                        $user->emailmicroid);
-        $this->elementEnd('li');
+       
+        if (Event::handle('StartEmailFormData', array($this))) {
+           $this->elementStart('li');
+           $this->checkbox('emailnotifysub',
+                           // TRANS: Checkbox label in e-mail preferences form.
+                           _('Send me notices of new subscriptions through email.'),
+                           $user->emailnotifysub);
+           $this->elementEnd('li');
+           $this->elementStart('li');
+           $this->checkbox('emailnotifyfav',
+                           // TRANS: Checkbox label in e-mail preferences form.
+                           _('Send me email when someone '.
+                             'adds my notice as a favorite.'),
+                           $user->emailnotifyfav);
+           $this->elementEnd('li');
+           $this->elementStart('li');
+           $this->checkbox('emailnotifymsg',
+                           // TRANS: Checkbox label in e-mail preferences form.
+                           _('Send me email when someone sends me a private message.'),
+                           $user->emailnotifymsg);
+           $this->elementEnd('li');
+           $this->elementStart('li');
+           $this->checkbox('emailnotifyattn',
+                           // TRANS: Checkbox label in e-mail preferences form.
+                           _('Send me email when someone sends me an "@-reply".'),
+                           $user->emailnotifyattn);
+           $this->elementEnd('li');
+           $this->elementStart('li');
+           $this->checkbox('emailnotifynudge',
+                           // TRANS: Checkbox label in e-mail preferences form.
+                           _('Allow friends to nudge me and send me an email.'),
+                           $user->emailnotifynudge);
+           $this->elementEnd('li');
+           if (common_config('emailpost', 'enabled')) {
+               $this->elementStart('li');
+               $this->checkbox('emailpost',
+                               // TRANS: Checkbox label in e-mail preferences form.
+                               _('I want to post notices by email.'),
+                               $user->emailpost);
+               $this->elementEnd('li');
+           }
+           $this->elementStart('li');
+           $this->checkbox('emailmicroid',
+                           // TRANS: Checkbox label in e-mail preferences form.
+                           _('Publish a MicroID for my email address.'),
+                           $user->emailmicroid);
+           $this->elementEnd('li');
+           Event::handle('EndEmailFormData', array($this));
+       }
         $this->elementEnd('ul');
         // TRANS: Button label to save e-mail preferences.
         $this->submit('save', _m('BUTTON','Save'));
@@ -299,43 +303,48 @@ class EmailsettingsAction extends AccountSettingsAction
 
     function savePreferences()
     {
-        $emailnotifysub   = $this->boolean('emailnotifysub');
-        $emailnotifyfav   = $this->boolean('emailnotifyfav');
-        $emailnotifymsg   = $this->boolean('emailnotifymsg');
-        $emailnotifynudge = $this->boolean('emailnotifynudge');
-        $emailnotifyattn  = $this->boolean('emailnotifyattn');
-        $emailmicroid     = $this->boolean('emailmicroid');
-        $emailpost        = $this->boolean('emailpost');
-
-        $user = common_current_user();
-
-        assert(!is_null($user)); // should already be checked
-
-        $user->query('BEGIN');
-
-        $original = clone($user);
-
-        $user->emailnotifysub   = $emailnotifysub;
-        $user->emailnotifyfav   = $emailnotifyfav;
-        $user->emailnotifymsg   = $emailnotifymsg;
-        $user->emailnotifynudge = $emailnotifynudge;
-        $user->emailnotifyattn  = $emailnotifyattn;
-        $user->emailmicroid     = $emailmicroid;
-        $user->emailpost        = $emailpost;
-
-        $result = $user->update($original);
-
-        if ($result === false) {
-            common_log_db_error($user, 'UPDATE', __FILE__);
-            // TRANS: Server error thrown on database error updating e-mail preferences.
-            $this->serverError(_('Couldn\'t update user.'));
-            return;
-        }
-
-        $user->query('COMMIT');
-
-        // TRANS: Confirmation message for successful e-mail preferences save.
-        $this->showForm(_('Email preferences saved.'), true);
+       $user = common_current_user();
+       
+       if (Event::handle('StartEmailSaveForm', array($this, &$user))) {
+           
+           $emailnotifysub   = $this->boolean('emailnotifysub');
+           $emailnotifyfav   = $this->boolean('emailnotifyfav');
+           $emailnotifymsg   = $this->boolean('emailnotifymsg');
+           $emailnotifynudge = $this->boolean('emailnotifynudge');
+           $emailnotifyattn  = $this->boolean('emailnotifyattn');
+           $emailmicroid     = $this->boolean('emailmicroid');
+           $emailpost        = $this->boolean('emailpost');
+           
+           assert(!is_null($user)); // should already be checked
+           
+           $user->query('BEGIN');
+           
+           $original = clone($user);
+           
+           $user->emailnotifysub   = $emailnotifysub;
+           $user->emailnotifyfav   = $emailnotifyfav;
+           $user->emailnotifymsg   = $emailnotifymsg;
+           $user->emailnotifynudge = $emailnotifynudge;
+           $user->emailnotifyattn  = $emailnotifyattn;
+           $user->emailmicroid     = $emailmicroid;
+           $user->emailpost        = $emailpost;
+           
+           $result = $user->update($original);
+           
+           if ($result === false) {
+               common_log_db_error($user, 'UPDATE', __FILE__);
+               // TRANS: Server error thrown on database error updating e-mail preferences.
+               $this->serverError(_('Couldn\'t update user.'));
+               return;
+           }
+           
+           $user->query('COMMIT');
+           
+           Event::handle('EndEmailSaveForm', array($this));
+           
+           // TRANS: Confirmation message for successful e-mail preferences save.
+           $this->showForm(_('Email preferences saved.'), true);
+       }
     }
 
     /**
index ff08191596655ab8e1bef3c20d7be7380bf9f3f4..e3631e214accb851050f2660c8ca7d641e14afc3 100644 (file)
@@ -107,3 +107,15 @@ create table group_alias (
    index group_alias_group_id_idx (group_id)
 
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
+
+create table session (
+
+    id varchar(32) primary key comment 'session ID',
+    session_data text comment 'session data',
+    created datetime not null comment 'date this record was created',
+    modified timestamp comment 'date this record was modified',
+
+    index session_modified_idx (modified)
+
+) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
+
index 33bf32b10e2a59f962cb06a72312f49054ff4a66..85b46bbb3fed09904a31878c5f91caa01f5fd495 100644 (file)
@@ -377,7 +377,11 @@ class StatusNet
     static function isHTTPS()
     {
         // There are some exceptions to this; add them here!
-        return !empty($_SERVER['HTTPS']);
+        if(empty($_SERVER['HTTPS'])) {
+            return false;
+        } else {
+            return $_SERVER['HTTPS'] !== 'off';
+        }
     }
 }
 
diff --git a/plugins/EmailSummary/EmailSummaryPlugin.php b/plugins/EmailSummary/EmailSummaryPlugin.php
new file mode 100644 (file)
index 0000000..58c40e4
--- /dev/null
@@ -0,0 +1,202 @@
+<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * Sends an email summary of the inbox to users in the network
+ *
+ * PHP version 5
+ *
+ * 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/>.
+ *
+ * @category  Sample
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2010 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link      http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
+/**
+ * Plugin for sending email summaries to users
+ *
+ * @category  Email
+ * @package   StatusNet
+ * @author    Brion Vibber <brionv@status.net>
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2010 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link      http://status.net/
+ */
+
+class EmailSummaryPlugin extends Plugin
+{
+    /**
+     * Database schema setup
+     *
+     * @return boolean hook value
+     */
+
+    function onCheckSchema()
+    {
+        $schema = Schema::get();
+
+        // For storing user-submitted flags on profiles
+
+        $schema->ensureTable('email_summary_status',
+                             array(new ColumnDef('user_id', 'integer', null,
+                                                 false, 'PRI'),
+                                   new ColumnDef('send_summary', 'tinyint', null,
+                                                false, null, 1),
+                                   new ColumnDef('last_summary_id', 'integer', null,
+                                                true),
+                                   new ColumnDef('created', 'datetime', null,
+                                                false),
+                                   new ColumnDef('modified', 'datetime', null,
+                                                false),
+                                  )
+                            );
+        return true;
+    }
+
+    /**
+     * Load related modules when needed
+     *
+     * @param string $cls Name of the class to be loaded
+     *
+     * @return boolean hook value; true means continue processing, false means stop.
+     * 
+     */
+    
+    function onAutoload($cls)
+    {
+        $dir = dirname(__FILE__);
+
+        switch ($cls)
+        {
+        case 'SiteEmailSummaryHandler':
+        case 'UserEmailSummaryHandler':
+            include_once $dir . '/'.strtolower($cls).'.php';
+           return false;
+        case 'Email_summary_status':
+            include_once $dir . '/'.$cls.'.php';
+            return false;
+        default:
+            return true;
+        }
+    }
+
+    /**
+     * Version info for this plugin
+     *
+     * @param array &$versions array of version data
+     *
+     * @return boolean hook value; true means continue processing, false means stop.
+     * 
+     */
+    
+    function onPluginVersion(&$versions)
+    {
+        $versions[] = array('name' => 'EmailSummary',
+                            'version' => STATUSNET_VERSION,
+                            'author' => 'Evan Prodromou',
+                            'homepage' => 'http://status.net/wiki/Plugin:EmailSummary',
+                            'rawdescription' =>
+                            _m('Send an email summary of the inbox to users.'));
+        return true;
+    }
+
+    /**
+     * Register our queue handlers
+     * 
+     * @param QueueManager $qm Current queue manager
+     * 
+     * @return boolean hook value
+     */
+    
+    function onEndInitializeQueueManager($qm)
+    {
+       $qm->connect('sitesum', 'SiteEmailSummaryHandler');
+       $qm->connect('usersum', 'UserEmailSummaryHandler');
+       return true;
+    }
+    
+    /**
+     * Add a checkbox to turn off email summaries
+     * 
+     * @param Action $action Action being executed (emailsettings)
+     * 
+     * @return boolean hook value
+     */
+    
+    function onEndEmailFormData($action)
+    {
+       $user = common_current_user();
+       
+       $action->elementStart('li');
+       $action->checkbox('emailsummary',
+                         // TRANS: Checkbox label in e-mail preferences form.
+                         _('Send me a periodic summary of updates from my network.'),
+                         Email_summary_status::getSendSummary($user->id));
+       $action->elementEnd('li');
+       return true;
+    }
+    
+    /**
+     * Add a checkbox to turn off email summaries
+     * 
+     * @param Action $action Action being executed (emailsettings)
+     * 
+     * @return boolean hook value
+     */
+    
+    function onEndEmailSaveForm($action)
+    {
+       $sendSummary = $action->boolean('emailsummary');
+       
+       $user = common_current_user();
+       
+       if (!empty($user)) {
+           
+           $ess = Email_summary_status::staticGet('user_id', $user->id);
+           
+           if (empty($ess)) {
+               
+               $ess = new Email_summary_status();
+
+               $ess->user_id      = $user->id;
+               $ess->send_summary = $sendSummary;
+               $ess->created      = common_sql_now();
+               $ess->modified     = common_sql_now();
+               
+               $ess->insert();
+               
+           } else {
+               
+               $orig = clone($ess);
+               
+               $ess->send_summary = $sendSummary;
+               $ess->modified     = common_sql_now();
+               
+               $ess->update($orig);
+           }
+       }
+       
+       return true;
+    }
+}
diff --git a/plugins/EmailSummary/Email_summary_status.php b/plugins/EmailSummary/Email_summary_status.php
new file mode 100644 (file)
index 0000000..5b5b231
--- /dev/null
@@ -0,0 +1,167 @@
+<?php
+/**
+ * Data class for email summary status
+ *
+ * PHP version 5
+ *
+ * @category Data
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ *
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, 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/>.
+ */
+
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
+require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
+
+/**
+ * Data class for email summaries
+ * 
+ * Email summary information for users
+ *
+ * @category Action
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link     http://status.net/
+ *
+ * @see      DB_DataObject
+ */
+
+class Email_summary_status extends Memcached_DataObject
+{
+    public $__table = 'email_summary_status'; // table name
+    public $user_id;                         // int(4)  primary_key not_null
+    public $send_summary;                    // tinyint not_null
+    public $last_summary_id;                 // int(4)  null
+    public $created;                         // datetime not_null
+    public $modified;                        // datetime not_null
+
+    /**
+     * Get an instance by key
+     *
+     * @param string $k Key to use to lookup (usually 'user_id' for this class)
+     * @param mixed  $v Value to lookup
+     *
+     * @return Email_summary_status object found, or null for no hits
+     *
+     */
+    function staticGet($k, $v=null)
+    {
+        return Memcached_DataObject::staticGet('email_summary_status', $k, $v);
+    }
+
+    /**
+     * return table definition for DB_DataObject
+     *
+     * DB_DataObject needs to know something about the table to manipulate
+     * instances. This method provides all the DB_DataObject needs to know.
+     *
+     * @return array array of column definitions
+     */
+
+    function table()
+    {
+        return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
+                    'send_summary' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
+                    'last_summary_id' => DB_DATAOBJECT_INT,
+                    'created' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
+                    'modified' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
+    }
+
+    /**
+     * return key definitions for DB_DataObject
+     *
+     * @return array list of key field names
+     */
+
+    function keys()
+    {
+        return array_keys($this->keyTypes());
+    }
+
+    /**
+     * return key definitions for Memcached_DataObject
+     *
+     * Our caching system uses the same key definitions, but uses a different
+     * method to get them. This key information is used to store and clear
+     * cached data, so be sure to list any key that will be used for static
+     * lookups.
+     *
+     * @return array associative array of key definitions, field name to type:
+     *         'K' for primary key: for compound keys, add an entry for each component;
+     *         'U' for unique keys: compound keys are not well supported here.
+     */
+    function keyTypes()
+    {
+        return array('user_id' => 'K');
+    }
+
+    /**
+     * Magic formula for non-autoincrementing integer primary keys
+     *
+     * @return array magic three-false array that stops auto-incrementing.
+     */
+    
+    function sequenceKey()
+    {
+        return array(false, false, false);
+    }
+
+    /**
+     * Helper function
+     *
+     * @param integer $user_id ID of the user to get a count for
+     *
+     * @return int flag for whether to send this user a summary email
+     */
+
+    static function getSendSummary($user_id)
+    {
+        $ess = Email_summary_status::staticGet('user_id', $user_id);
+
+       if (!empty($ess)) {
+           return $ess->send_summary;
+       } else {
+           return 1;
+       }
+    }
+
+    /**
+     * Get email summary status for a user
+     *
+     * @param integer $user_id ID of the user to get a count for
+     *
+     * @return Email_summary_status instance for this user, with count already incremented.
+     */
+
+    static function getLastSummaryID($user_id)
+    {
+        $ess = Email_summary_status::staticGet('user_id', $user_id);
+       
+       if (!empty($ess)) {
+           return $ess->last_summary_id;
+       } else {
+           return null;
+       }
+    }
+}
diff --git a/plugins/EmailSummary/sendemailsummary.php b/plugins/EmailSummary/sendemailsummary.php
new file mode 100644 (file)
index 0000000..37bfdcf
--- /dev/null
@@ -0,0 +1,47 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, 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/>.
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
+
+$shortoptions = 'i:n:a';
+$longoptions = array('id=', 'nickname=', 'all');
+
+$helptext = <<<END_OF_SENDEMAILSUMMARY_HELP
+sendemailsummary.php [options]
+Send an email summary of the inbox to users
+
+  -i --id       ID of user to send summary to
+  -n --nickname nickname of the user to send summary to
+  -a --all      send summary to all users
+
+END_OF_SENDEMAILSUMMARY_HELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+$qm = QueueManager::get();
+
+// enqueue summary for user or all users
+
+try {
+    $user = getUser();
+    $qm->enqueue($user->id, 'usersum');
+} catch (NoUserArgumentException $nuae) {
+    $qm->enqueue(null, 'sitesum');
+}
diff --git a/plugins/EmailSummary/siteemailsummaryhandler.php b/plugins/EmailSummary/siteemailsummaryhandler.php
new file mode 100644 (file)
index 0000000..595c326
--- /dev/null
@@ -0,0 +1,96 @@
+<?php
+/*
+ * StatusNet - the distributed open-source microblogging tool
+ * 
+ * Handler for queue items of type 'sitesum', sends email summaries
+ * to all users on the site.
+ *
+ * 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/>.
+ *
+ * @category  Sample
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2010 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link      http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
+/**
+ * 
+ * Handler for queue items of type 'sitesum', sends email summaries
+ * to all users on the site.
+ *
+ * @category  Email
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2010 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link      http://status.net/
+ */
+
+class SiteEmailSummaryHandler extends QueueHandler
+{
+
+    /**
+     * Return transport keyword which identifies items this queue handler
+     * services; must be defined for all subclasses.
+     *
+     * Must be 8 characters or less to fit in the queue_item database.
+     * ex "email", "jabber", "sms", "irc", ...
+     *
+     * @return string
+     */
+    
+    function transport()
+    {
+        return 'sitesum';
+    }
+
+    /**
+     * Handle the site
+     * 
+     * @param mixed $object
+     * @return boolean true on success, false on failure
+     */
+    
+    function handle($object)
+    {
+       $qm = QueueManager::get();
+
+       try {
+           // Enqueue a summary for all users
+           
+           $user = new User();
+           $user->find();
+           
+           while ($user->fetch()) {
+               try {
+                   $qm->enqueue($user->id, 'usersum');
+               } catch (Exception $e) {
+                   common_log(LOG_WARNING, $e->getMessage());
+                   continue;
+               }
+           }
+       } catch (Exception $e) {
+           common_log(LOG_WARNING, $e->getMessage());
+       }
+       
+       return true;
+    }
+}
+
diff --git a/plugins/EmailSummary/useremailsummaryhandler.php b/plugins/EmailSummary/useremailsummaryhandler.php
new file mode 100644 (file)
index 0000000..b1ebd0c
--- /dev/null
@@ -0,0 +1,226 @@
+<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * 
+ * Handler for queue items of type 'usersum', sends an email summaries
+ * to a particular user.
+ *
+ * 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/>.
+ *
+ * @category  Sample
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2010 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link      http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
+/**
+ * Handler for queue items of type 'usersum', sends an email summaries
+ * to a particular user.
+ *
+ * @category  Email
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2010 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link      http://status.net/
+ */
+
+class UserEmailSummaryHandler extends QueueHandler
+{
+    // Maximum number of notices to include by default. This is probably too much.
+    
+    const MAX_NOTICES = 200;
+    
+    /**
+     * Return transport keyword which identifies items this queue handler
+     * services; must be defined for all subclasses.
+     *
+     * Must be 8 characters or less to fit in the queue_item database.
+     * ex "email", "jabber", "sms", "irc", ...
+     *
+     * @return string
+     */
+    
+    function transport()
+    {
+        return 'sitesum';
+    }
+
+    /**
+     * Send a summary email to the user
+     * 
+     * @param mixed $object
+     * @return boolean true on success, false on failure
+     */
+    
+    function handle($user_id)
+    {
+       // Skip if they've asked not to get summaries
+
+       $ess = Email_summary_status::staticGet('user_id', $user_id);
+       
+       if (!empty($ess) && !$ess->send_summary) {
+           common_log(LOG_INFO, sprintf('Not sending email summary for user %s by request.', $user_id));
+           return true;
+       }
+
+       $since_id = null;
+       
+       if (!empty($ess)) {
+           $since_id = $ess->last_summary_id;
+       }
+         
+       $user = User::staticGet('id', $user_id);
+
+       if (empty($user)) {
+           common_log(LOG_INFO, sprintf('Not sending email summary for user %s; no such user.', $user_id));
+           return true;
+       }
+       
+       if (empty($user->email)) {
+           common_log(LOG_INFO, sprintf('Not sending email summary for user %s; no email address.', $user_id));
+           return true;
+       }
+       
+       $profile = $user->getProfile();
+       
+       if (empty($profile)) {
+           common_log(LOG_WARNING, sprintf('Not sending email summary for user %s; no profile.', $user_id));
+           return true;
+       }
+       
+       $notice = $user->ownFriendsTimeline(0, self::MAX_NOTICES, $since_id);
+
+       if (empty($notice) || $notice->N == 0) {
+           common_log(LOG_WARNING, sprintf('Not sending email summary for user %s; no notices.', $user_id));
+           return true;
+       }
+
+       // XXX: This is risky fingerpoken in der objektvars, but I didn't feel like
+       // figuring out a better way. -ESP
+
+       $new_top = null;
+       
+       if ($notice instanceof ArrayWrapper) {
+           $new_top = $notice->_items[0]->id;
+       }
+       
+       $out = new XMLStringer();
+
+       $out->raw(sprintf(_('<p>Recent updates from %1s for %2s:</p>'),
+                         common_config('site', 'name'),
+                         $profile->getBestName()));
+       
+
+       $out->elementStart('table', array('width' => '541px', 'style' => 'border: none'));
+       
+       while ($notice->fetch()) {
+           
+           $profile = Profile::staticGet('id', $notice->profile_id);
+           
+           if (empty($profile)) {
+               continue;
+           }
+           
+           $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
+
+           $out->elementStart('tr');
+           $out->elementStart('td', array('width' => AVATAR_STREAM_SIZE,
+                                          'height' => AVATAR_STREAM_SIZE,
+                                          'align' => 'left',
+                                          'valign' => 'top'));
+           $out->element('img', array('src' => ($avatar) ?
+                                      $avatar->displayUrl() :
+                                      Avatar::defaultImage($avatar_size),
+                                      'class' => 'avatar photo',
+                                      'width' => AVATAR_STREAM_SIZE,
+                                      'height' => AVATAR_STREAM_SIZE,
+                                      'alt' => $profile->getBestName()));
+           $out->elementEnd('td');
+           $out->elementStart('td', array('align' => 'left',
+                                          'valign' => 'top'));
+           $out->element('a', array('href' => $profile->profileurl),
+                         $profile->nickname);
+           $out->text(' ');
+           $out->raw($notice->rendered);
+           $out->element('br'); // yeah, you know it. I just wrote a <br> in the middle of my table layout.
+           $noticeurl = $notice->bestUrl();
+           // above should always return an URL
+           assert(!empty($noticeurl));
+           $out->elementStart('a', array('rel' => 'bookmark',
+                                         'class' => 'timestamp',
+                                         'href' => $noticeurl));
+           $dt = common_date_iso8601($notice->created);
+           $out->element('abbr', array('class' => 'published',
+                                       'title' => $dt),
+                         common_date_string($notice->created));
+           $out->elementEnd('a');
+           if ($notice->hasConversation()) {
+               $conv = Conversation::staticGet('id', $notice->conversation);
+               $convurl = $conv->uri;
+               if (!empty($convurl)) {
+                                 $out->text(' ');
+                                 $out->element('a',
+                                               array('href' => $convurl.'#notice-'.$notice->id,
+                                                     'class' => 'response'),
+                                               _('in context'));
+               }
+           }
+           $out->elementEnd('td');
+           $out->elementEnd('tr');
+       }
+       
+       $out->elementEnd('table');
+       
+       $out->raw(sprintf(_('<p><a href="%1s">change your email settings for %2s</a></p>'),
+                         common_local_url('emailsettings'),
+                         common_config('site', 'name')));
+
+       $body = $out->getString();
+       
+       // FIXME: do something for people who don't like HTML email
+       
+       mail_to_user($user, _('Updates from your network'), $body,
+                    array('Content-Type' => 'text/html; charset=UTF-8'));
+
+       if (empty($ess)) {
+           
+           $ess = new Email_summary_status();
+           
+           $ess->user_id         = $user_id;
+           $ess->created         = common_sql_now();
+           $ess->last_summary_id = $new_top;
+           $ess->modified        = common_sql_now();
+
+           $ess->insert();
+           
+       } else {
+           
+           $orig = clone($ess);
+           
+           $ess->last_summary_id = $new_top;
+           $ess->modified        = common_sql_now();
+
+           $ess->update($orig);
+       }
+       
+       return true;
+    }
+}
index c4ba6464eaa1077e5ca81b8e2fb65439d2f5d782..d5261d8bc7764f833d524462353d0918512f117f 100644 (file)
@@ -156,7 +156,8 @@ class MapstractionPlugin extends Plugin
                                   ' var user = null; '.
                                   (($actionName == 'showstream') ? ' user = scrapeUser(); ' : '') .
                                   ' var notices = scrapeNotices(user); ' .
-                                  ' showMapstraction($("#map_canvas"), notices); '.
+                                 ' var canvas = $("#map_canvas")[0]; ' .
+                                  ' if (typeof(canvas) != "undefined") { showMapstraction(canvas, notices); } '.
                                   '});');
         }