]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
move class BlogEntry to Blog_entry for DB_DataObject compliance
authorEvan Prodromou <evan@status.net>
Mon, 20 Jun 2011 14:20:01 +0000 (10:20 -0400)
committerEvan Prodromou <evan@status.net>
Mon, 20 Jun 2011 14:20:01 +0000 (10:20 -0400)
plugins/Blog/BlogEntry.php [deleted file]
plugins/Blog/BlogPlugin.php
plugins/Blog/Blog_entry.php [new file with mode: 0644]
plugins/Blog/blogentrylistitem.php
plugins/Blog/newblogentry.php
plugins/Blog/showblogentry.php

diff --git a/plugins/Blog/BlogEntry.php b/plugins/Blog/BlogEntry.php
deleted file mode 100644 (file)
index 32915dc..0000000
+++ /dev/null
@@ -1,233 +0,0 @@
-<?php
-/**
- * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2011, StatusNet, Inc.
- *
- * Data structure for blog entries
- * 
- * 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  Blog
- * @package   StatusNet
- * @author    Evan Prodromou <evan@status.net>
- * @copyright 2011 StatusNet, Inc.
- * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
- * @link      http://status.net/
- */
-
-if (!defined('STATUSNET')) {
-    // This check helps protect against security problems;
-    // your code file can't be executed directly from the web.
-    exit(1);
-}
-
-/**
- * Data structure for blog entries
- *
- * @category  Blog
- * @package   StatusNet
- * @author    Evan Prodromou <evan@status.net>
- * @copyright 2011 StatusNet, Inc.
- * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
- * @link      http://status.net/
- */
-
-class BlogEntry extends Managed_DataObject
-{
-    public $__table = 'blog_entry';
-
-    public $id; // UUID
-    public $profile_id; // int
-    public $title; // varchar(255)
-    public $summary; // text
-    public $content; // text
-    public $uri; // text
-    public $url; // text
-    public $created; // datetime
-    public $modified; // datetime
-
-    const TYPE = 'http://activitystrea.ms/schema/1.0/blog-entry';
-    
-    function staticGet($k, $v=null)
-    {
-        return Managed_DataObject::staticGet('blog_entry', $k, $v);
-    }
-
-    static function schemaDef()
-    {
-        return array(
-            'description' => 'lite blog entry',
-            'fields' => array(
-                'id' => array('type' => 'char',
-                              'length' => 36,
-                              'not null' => true,
-                              'description' => 'Unique ID (UUID)'),
-                'profile_id' => array('type' => 'int',
-                                      'not null' => true,
-                                      'description' => 'Author profile ID'),
-                'title' => array('type' => 'varchar',
-                                 'length' => 255,
-                                 'description' => 'title of the entry'),
-                'summary' => array('type' => 'text',
-                                   'description' => 'initial summary'),
-                'content' => array('type' => 'text',
-                                   'description' => 'HTML content of the entry'),
-                'uri' => array('type' => 'varchar',
-                               'length' => 255,
-                               'description' => 'URI (probably http://) for this entry'),
-                'url' => array('type' => 'varchar',
-                               'length' => 255,
-                               'description' => 'URL (probably http://) for this entry'),
-                'created' => array('type' => 'datetime',
-                                   'not null' => true,
-                                   'description' => 'date this record was created'),
-                'modified' => array('type' => 'datetime',
-                                    'not null' => true,
-                                    'description' => 'date this record was created'),
-            ),
-            'primary key' => array('id'),
-            'foreign keys' => array(
-                'blog_entry_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
-            ),
-            'indexes' => array(
-                'blog_entry_created_idx' => array('created'),
-                'blog_entry_uri_idx' => array('uri'),
-            ),
-        );
-    }
-
-    static function saveNew($profile, $title, $content, $options=null)
-    {
-        if (is_null($options)) {
-            $options = array();
-        }
-        
-        $be             = new BlogEntry();
-        $be->id         = (string) new UUID();
-        $be->profile_id = $profile->id;
-        $be->title      = htmlspecialchars($title);
-        $be->content    = $content;
-        
-        if (array_key_exists('summary', $options)) {
-            $be->summary = $options['summary'];
-        } else {
-            $be->summary = self::summarize($content);
-        }
-
-        $url = common_local_url('showblogentry', array('id' => $be->id));
-
-        if (!array_key_exists('uri', $options)) {
-            $options['uri'] = $url;
-        } 
-
-        $be->uri = $options['uri'];
-
-        if (!array_key_exists('url', $options)) {
-            $options['url'] = $url;
-        }
-
-        $be->url = $options['url'];
-
-        if (!array_key_exists('created', $options)) {
-            $be->created = common_sql_now();
-        }
-        
-        $be->created = $options['created'];
-
-        $be->modified = common_sql_now();
-
-        $be->insert();
-
-        // Use user's preferences for short URLs, if possible
-
-        try {
-            $user = $profile->getUser();
-            $shortUrl = File_redirection::makeShort($url,
-                                                    empty($user) ? null : $user);
-        } catch (Exception $e) {
-            // Don't let this stop us.
-            $shortUrl = $url;
-        }
-
-        // XXX: this might be too long.
-
-        $options['rendered'] = $be->summary . ' ' . 
-            XMLStringer::estring('a', array('href' => $shortUrl,
-                                            'class' => 'blog-entry'),
-                                 _('More...'));
-
-        $summaryText = html_entity_decode(strip_tags($summary), ENT_QUOTES, 'UTF-8');
-
-        if (Notice::contentTooLong($summaryText)) {
-            $summaryText = substr($summaryText, 0, Notice::maxContent() - mb_strlen($shortUrl) - 2) .
-                '… ' . $shortUrl;
-        }
-
-        $content = $summaryText;
-
-        // Override this no matter what.
-        
-        $options['object_type'] = self::TYPE;
-
-        $source = array_key_exists('source', $options) ?
-                                    $options['source'] : 'web';
-        
-        Notice::saveNew($profile->id, $content, $source, $options);
-    }
-
-    /**
-     * Summarize the contents of a blog post
-     *
-     * We take the first div or paragraph of the blog post if there's a hit;
-     * Otherwise we take the whole thing.
-     * 
-     * @param string $html HTML of full content
-     */
-    static function summarize($html)
-    {
-        if (preg_match('#<p>.*?</p>#s', $html, $matches)) {
-            return $matches[0];
-        } else if (preg_match('#<div>.*?</div>#s', $html, $matches)) {
-            return $matches[0];
-        } else {
-            return $html;
-        }
-    }
-
-    static function fromNotice($notice)
-    {
-        return BlogEntry::staticGet('uri', $notice->uri);
-    }
-
-    function getNotice()
-    {
-        return Notice::staticGet('uri', $this->uri);
-    }
-
-    function asActivityObject()
-    {
-        $obj = new ActivityObject();
-
-        $obj->id      = $this->uri;
-        $obj->type    = self::TYPE;
-        $obj->title   = $this->title;
-        $obj->summary = $this->summary;
-        $obj->content = $this->content;
-        $obj->link    = $this->url;
-
-        return $obj;
-    }
-}
index 7f8e8fd1d0b37700a16563d0fa666ca6b4388e8a..89619b5f54fec08789fc6f3d3653a5f2820d0952 100644 (file)
@@ -62,7 +62,7 @@ class BlogPlugin extends MicroAppPlugin
     {
         $schema = Schema::get();
 
-        $schema->ensureTable('blog_entry', BlogEntry::schemaDef());
+        $schema->ensureTable('blog_entry', Blog_entry::schemaDef());
 
         return true;
     }
@@ -88,7 +88,7 @@ class BlogPlugin extends MicroAppPlugin
         case 'BlogEntryListItem':
             include_once $dir . '/'.strtolower($cls).'.php';
             return false;
-        case 'BlogEntry':
+        case 'Blog_entry':
             include_once $dir . '/'.$cls.'.php';
             return false;
         default:
@@ -136,7 +136,7 @@ class BlogPlugin extends MicroAppPlugin
 
     function types()
     {
-        return array(BlogEntry::TYPE);
+        return array(Blog_entry::TYPE);
     }
 
     function saveNoticeFromActivity($activity, $actor, $options=array())
@@ -148,7 +148,7 @@ class BlogPlugin extends MicroAppPlugin
 
         $entryObj = $activity->objects[0];
 
-        if ($entryObj->type != BlogEntry::TYPE) {
+        if ($entryObj->type != Blog_entry::TYPE) {
             // TRANS: Exception thrown when blog plugin comes across a non-event type object.
             throw new ClientException(_m('Wrong type for object.'));
         }
@@ -157,7 +157,7 @@ class BlogPlugin extends MicroAppPlugin
 
         switch ($activity->verb) {
         case ActivityVerb::POST:
-            $notice = BlogEntry::saveNew($actor,
+            $notice = Blog_entry::saveNew($actor,
                                          $entryObj->title,
                                          $entryObj->content,
                                          $options);
@@ -172,7 +172,7 @@ class BlogPlugin extends MicroAppPlugin
 
     function activityObjectFromNotice($notice)
     {
-        $entry = BlogEntry::fromNotice($notice);
+        $entry = Blog_entry::fromNotice($notice);
 
         if (empty($entry)) {
             throw new ClientException(sprintf(_('No blog entry for notice %s'),
@@ -189,8 +189,8 @@ class BlogPlugin extends MicroAppPlugin
 
     function deleteRelated($notice)
     {
-        if ($notice->object_type == BlogEntry::TYPE) {
-            $entry = BlogEntry::fromNotice($notice);
+        if ($notice->object_type == Blog_entry::TYPE) {
+            $entry = Blog_entry::fromNotice($notice);
             if (exists($entry)) {
                 $entry->delete();
             }
@@ -201,7 +201,7 @@ class BlogPlugin extends MicroAppPlugin
     {
         $notice = $nli->notice;
 
-        if ($notice->object_type == BlogEntry::TYPE) {
+        if ($notice->object_type == Blog_entry::TYPE) {
             return new BlogEntryListItem($nli);
         }
         
diff --git a/plugins/Blog/Blog_entry.php b/plugins/Blog/Blog_entry.php
new file mode 100644 (file)
index 0000000..34e4ea2
--- /dev/null
@@ -0,0 +1,233 @@
+<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2011, StatusNet, Inc.
+ *
+ * Data structure for blog entries
+ * 
+ * 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  Blog
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2011 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link      http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+    // This check helps protect against security problems;
+    // your code file can't be executed directly from the web.
+    exit(1);
+}
+
+/**
+ * Data structure for blog entries
+ *
+ * @category  Blog
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2011 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link      http://status.net/
+ */
+
+class Blog_entry extends Managed_DataObject
+{
+    public $__table = 'blog_entry';
+
+    public $id; // UUID
+    public $profile_id; // int
+    public $title; // varchar(255)
+    public $summary; // text
+    public $content; // text
+    public $uri; // text
+    public $url; // text
+    public $created; // datetime
+    public $modified; // datetime
+
+    const TYPE = 'http://activitystrea.ms/schema/1.0/blog-entry';
+    
+    function staticGet($k, $v=null)
+    {
+        return Managed_DataObject::staticGet('blog_entry', $k, $v);
+    }
+
+    static function schemaDef()
+    {
+        return array(
+            'description' => 'lite blog entry',
+            'fields' => array(
+                'id' => array('type' => 'char',
+                              'length' => 36,
+                              'not null' => true,
+                              'description' => 'Unique ID (UUID)'),
+                'profile_id' => array('type' => 'int',
+                                      'not null' => true,
+                                      'description' => 'Author profile ID'),
+                'title' => array('type' => 'varchar',
+                                 'length' => 255,
+                                 'description' => 'title of the entry'),
+                'summary' => array('type' => 'text',
+                                   'description' => 'initial summary'),
+                'content' => array('type' => 'text',
+                                   'description' => 'HTML content of the entry'),
+                'uri' => array('type' => 'varchar',
+                               'length' => 255,
+                               'description' => 'URI (probably http://) for this entry'),
+                'url' => array('type' => 'varchar',
+                               'length' => 255,
+                               'description' => 'URL (probably http://) for this entry'),
+                'created' => array('type' => 'datetime',
+                                   'not null' => true,
+                                   'description' => 'date this record was created'),
+                'modified' => array('type' => 'datetime',
+                                    'not null' => true,
+                                    'description' => 'date this record was created'),
+            ),
+            'primary key' => array('id'),
+            'foreign keys' => array(
+                'blog_entry_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
+            ),
+            'indexes' => array(
+                'blog_entry_created_idx' => array('created'),
+                'blog_entry_uri_idx' => array('uri'),
+            ),
+        );
+    }
+
+    static function saveNew($profile, $title, $content, $options=null)
+    {
+        if (is_null($options)) {
+            $options = array();
+        }
+        
+        $be             = new Blog_entry();
+        $be->id         = (string) new UUID();
+        $be->profile_id = $profile->id;
+        $be->title      = htmlspecialchars($title);
+        $be->content    = $content;
+        
+        if (array_key_exists('summary', $options)) {
+            $be->summary = $options['summary'];
+        } else {
+            $be->summary = self::summarize($content);
+        }
+
+        $url = common_local_url('showblogentry', array('id' => $be->id));
+
+        if (!array_key_exists('uri', $options)) {
+            $options['uri'] = $url;
+        } 
+
+        $be->uri = $options['uri'];
+
+        if (!array_key_exists('url', $options)) {
+            $options['url'] = $url;
+        }
+
+        $be->url = $options['url'];
+
+        if (!array_key_exists('created', $options)) {
+            $be->created = common_sql_now();
+        }
+        
+        $be->created = $options['created'];
+
+        $be->modified = common_sql_now();
+
+        $be->insert();
+
+        // Use user's preferences for short URLs, if possible
+
+        try {
+            $user = $profile->getUser();
+            $shortUrl = File_redirection::makeShort($url,
+                                                    empty($user) ? null : $user);
+        } catch (Exception $e) {
+            // Don't let this stop us.
+            $shortUrl = $url;
+        }
+
+        // XXX: this might be too long.
+
+        $options['rendered'] = $be->summary . ' ' . 
+            XMLStringer::estring('a', array('href' => $shortUrl,
+                                            'class' => 'blog-entry'),
+                                 _('More...'));
+
+        $summaryText = html_entity_decode(strip_tags($summary), ENT_QUOTES, 'UTF-8');
+
+        if (Notice::contentTooLong($summaryText)) {
+            $summaryText = substr($summaryText, 0, Notice::maxContent() - mb_strlen($shortUrl) - 2) .
+                '… ' . $shortUrl;
+        }
+
+        $content = $summaryText;
+
+        // Override this no matter what.
+        
+        $options['object_type'] = self::TYPE;
+
+        $source = array_key_exists('source', $options) ?
+                                    $options['source'] : 'web';
+        
+        Notice::saveNew($profile->id, $content, $source, $options);
+    }
+
+    /**
+     * Summarize the contents of a blog post
+     *
+     * We take the first div or paragraph of the blog post if there's a hit;
+     * Otherwise we take the whole thing.
+     * 
+     * @param string $html HTML of full content
+     */
+    static function summarize($html)
+    {
+        if (preg_match('#<p>.*?</p>#s', $html, $matches)) {
+            return $matches[0];
+        } else if (preg_match('#<div>.*?</div>#s', $html, $matches)) {
+            return $matches[0];
+        } else {
+            return $html;
+        }
+    }
+
+    static function fromNotice($notice)
+    {
+        return Blog_entry::staticGet('uri', $notice->uri);
+    }
+
+    function getNotice()
+    {
+        return Notice::staticGet('uri', $this->uri);
+    }
+
+    function asActivityObject()
+    {
+        $obj = new ActivityObject();
+
+        $obj->id      = $this->uri;
+        $obj->type    = self::TYPE;
+        $obj->title   = $this->title;
+        $obj->summary = $this->summary;
+        $obj->content = $this->content;
+        $obj->link    = $this->url;
+
+        return $obj;
+    }
+}
index 287339f8c2809e9c628757e71031d8722c2d771a..97a06acfa7e1451aadcc5dc17f043e39e699e875 100644 (file)
@@ -61,7 +61,7 @@ class BlogEntryListItem extends NoticeListItemAdapter
         $notice = $this->nli->notice;
         $out    = $this->nli->out;
 
-        $entry  = BlogEntry::fromNotice($notice);
+        $entry  = Blog_entry::fromNotice($notice);
 
         if (empty($entry)) {
             throw new Exception('BlogEntryListItem used for non-blog notice.');
index 94988c533520592c0e92b5a4f1b2b8ebe78d8a47..c33c69d109ecec3b80ddb9dd1f9ff50c62963d44 100644 (file)
@@ -114,7 +114,7 @@ class NewblogentryAction extends Action
             
         $profile = $this->user->getProfile();
 
-        $saved = BlogEntry::saveNew($profile,
+        $saved = Blog_entry::saveNew($profile,
                                     $this->title,
                                     $this->content,
                                     $options);
index 4ddf7963e05837a915fbe8bdedf5566832970d78..c5aa54a4c289394f42f75390709674ff5059d1f3 100644 (file)
@@ -54,7 +54,7 @@ class ShowblogentryAction extends ShownoticeAction
     {
         $this->id = $this->trimmed('id');
 
-        $this->entry = BlogEntry::staticGet('id', $this->id);
+        $this->entry = Blog_entry::staticGet('id', $this->id);
 
         if (empty($this->entry)) {
             // TRANS: Client exception thrown when referring to a non-existing blog entry.