]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
save the notice title when the notice is saved
authorEvan Prodromou <evan@status.net>
Fri, 13 Aug 2010 18:29:18 +0000 (11:29 -0700)
committerEvan Prodromou <evan@status.net>
Fri, 13 Aug 2010 18:29:18 +0000 (11:29 -0700)
plugins/NoticeTitle/NoticeTitlePlugin.php
plugins/NoticeTitle/Notice_title.php

index 524faef3a201e68bc66aeb9c6605150afd8b1d06..86a74a4da54e00757303d40cb7e0f37bfd8c31cf 100644 (file)
@@ -70,7 +70,7 @@ class NoticeTitlePlugin extends Plugin
 
         $schema->ensureTable('notice_title',
                              array(new ColumnDef('notice_id', 'integer', null, true, 'PRI'),
-                                   new ColumnDef('title', 'varchar', 255, false)));
+                                   new ColumnDef('title', 'varchar', Notice_title::MAXCHARS, false)));
 
         return true;
     }
@@ -114,11 +114,42 @@ class NoticeTitlePlugin extends Plugin
                                            'id' => 'notice_title',
                                            'name' => 'notice_title',
                                            'size' => 40,
+                                           'maxlength' => Notice_title::MAXCHARS,
                                            'value' => _m('Title'),
                                            'style' => 'color: 333333',
                                            'onFocus' => 'this.value = ""; this.style = \'color: black\';'));
         return true;
     }
 
+    function onStartNoticeSaveWeb($action, &$authorId, &$text, &$options)
+    {
+        $title = $action->trimmed('notice_title');
+        if (!empty($title)) {
+            if (mb_strlen($title) > Notice_title::MAXCHARS) {
+                throw new Exception(sprintf(_m("Notice title too long (max %d chars)", Notice_title::MAXCHARS)));
+            }
+        }
+        return true;
+    }
+
+    function onEndNoticeSaveWeb($action, $notice)
+    {
+        if (!empty($notice)) {
+
+            $title = $action->trimmed('notice_title');
+
+            if (!empty($title)) {
+
+                $nt = new Notice_title();
+
+                $nt->notice_id = $notice->id;
+                $nt->title     = $title;
+
+                $nt->insert();
+            }
+        }
+
+        return true;
+    }
 }
 
index ed71f135675862edd0f7cf32811060035201e99a..44d56b49687606a2541fb6fc35e1372ce943161e 100644 (file)
@@ -47,6 +47,8 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
 
 class Notice_title extends Memcached_DataObject
 {
+    const MAXCHARS = 255;
+
     public $__table = 'notice_title'; // table name
     public $notice_id;                         // int(4)  primary_key not_null
     public $title;                             // varchar(255)