User Tools

Site Tools


documentation:create_first_plugin

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
documentation:create_first_plugin [2015/06/11 10:33]
mooeditor [How to using mailsystem]
documentation:create_first_plugin [2015/09/03 04:02]
mooeditor [What is boot setting?]
Line 2: Line 2:
  
 //NOTE: We’re currently working on documenting these sections. We believe the information here is accurate, however be aware we are also still working on this chapter. Additional information will be provided as we go which should make this chapter more solid.// //NOTE: We’re currently working on documenting these sections. We believe the information here is accurate, however be aware we are also still working on this chapter. Additional information will be provided as we go which should make this chapter more solid.//
 +
 +Sample Plugin: [[https://​www.moosocial.com//​wiki/​lib/​plugins/​ckgedit/​fckeditor/​userfiles/​file/​moo-note-1.0.zip|https://​www.moosocial.com//​wiki/​lib/​plugins/​ckgedit/​fckeditor/​userfiles/​file/​moo-note-1.0.zip]]
 +
 ====== Welcome to the mooSocial guides ====== ====== Welcome to the mooSocial guides ======
  
Line 379: Line 382:
  
 <code php> <code php>
- 
 <!-- File: /​app/​Plugin/​Note/​View/​Notes/​add.ctp --> <!-- File: /​app/​Plugin/​Note/​View/​Notes/​add.ctp -->
 <!-- In case you want to create multiple themed views, ​ ex you want to  only <!-- In case you want to create multiple themed views, ​ ex you want to  only
Line 462: Line 464:
  
 <code php> <code php>
- 
 <!-- File: /​app/​Plugin/​Note/​View/​Notes/​edit.ctp --> <!-- File: /​app/​Plugin/​Note/​View/​Notes/​edit.ctp -->
 <!-- In case you want to create multiple themed views, ​ ex you want to  only <!-- In case you want to create multiple themed views, ​ ex you want to  only
Line 540: Line 541:
  
 Update **/​app/​Plugin/​Note/​Controller/​noteController.php** ​ like this Update **/​app/​Plugin/​Note/​Controller/​noteController.php** ​ like this
-<code php> 
  
 +<code php>
 <?php <?php
 class NotesController extends NoteAppController { class NotesController extends NoteAppController {
Line 551: Line 552:
     public $scaffold;     public $scaffold;
     public function admin_index(){     public function admin_index(){
-         +
     }     }
-     +
     public function admin_infos(){     public function admin_infos(){
         // get plugin info         // get plugin info
Line 561: Line 562:
             $content = file_get_contents($xmlPath);​             $content = file_get_contents($xmlPath);​
             $info = new SimpleXMLElement($content);​             $info = new SimpleXMLElement($content);​
-            $this->​set('​info',​ $info); ​    ​+            $this->​set('​info',​ $info);
         }         }
         else         else
Line 568: Line 569:
         }         }
     }     }
- +
     public function index() {     public function index() {
         $this->​set('​notes',​ $this->​Note->​find('​all'​));​         $this->​set('​notes',​ $this->​Note->​find('​all'​));​
     }     }
-     +
     public function view($id = null) {     public function view($id = null) {
         if (!$id) {         if (!$id) {
Line 582: Line 583:
         }         }
         $this->​set('​note',​ $note);         $this->​set('​note',​ $note);
-         +
         $this->​likesComments($id);​         $this->​likesComments($id);​
     }     }
-     +
     private function likesComments($id) {     private function likesComments($id) {
         //comment         //comment
Line 592: Line 593:
         $comment_count = $this->​Comment->​getCommentsCount($id,​ '​Note_Note'​);​         $comment_count = $this->​Comment->​getCommentsCount($id,​ '​Note_Note'​);​
         $page = 1;         $page = 1;
-         +
         $data['​bIsCommentloadMore'​] = $comment_count - $page * RESULTS_LIMIT;​         $data['​bIsCommentloadMore'​] = $comment_count - $page * RESULTS_LIMIT;​
         $data['​comments'​] = $comments;         $data['​comments'​] = $comments;
         $this->​set('​data',​ $data);         $this->​set('​data',​ $data);
         $this->​set('​comment_count',​ $comment_count);​         $this->​set('​comment_count',​ $comment_count);​
-         +
         //like         //like
         $this->​Like = ClassRegistry::​init('​Like'​);​         $this->​Like = ClassRegistry::​init('​Like'​);​
         $likes = $this->​Like->​getLikes($id,​ '​Note_Note'​);​         $likes = $this->​Like->​getLikes($id,​ '​Note_Note'​);​
         $dislikes = $this->​Like->​getDisLikes($id,​ '​Note_Note'​);​         $dislikes = $this->​Like->​getDisLikes($id,​ '​Note_Note'​);​
-         +
         $this->​set('​likes',​ $likes);         $this->​set('​likes',​ $likes);
         $this->​set('​dislikes',​ $dislikes);         $this->​set('​dislikes',​ $dislikes);
     }     }
-     +
     public function add() {     public function add() {
         if ($this->​request->​is('​post'​)) {         if ($this->​request->​is('​post'​)) {
Line 618: Line 619:
         }         }
     }     }
-     +
     public function edit($id = null) {     public function edit($id = null) {
         if (!$id) {         if (!$id) {
Line 640: Line 641:
         }         }
     }     }
-     +
     public function delete($id) {     public function delete($id) {
         if (!$id) {         if (!$id) {
Line 652: Line 653:
         }         }
     }     }
-     +
     public function myNotes(){     public function myNotes(){
         $notes = $this->​Note->​find('​all',​ array(         $notes = $this->​Note->​find('​all',​ array(
Line 661: Line 662:
         return $notes;         return $notes;
     }     }
-     +
     public function ajax_add(){     public function ajax_add(){
-         +
         if ($this->​request->​is('​post'​)) {         if ($this->​request->​is('​post'​)) {
             $this->​Note->​create();​             $this->​Note->​create();​
Line 679: Line 680:
  
 </​code>​ </​code>​
- 
  
 ==== Create an element ==== ==== Create an element ====
Line 686: Line 686:
  
 Create new ctp file in **/​app/​Plugin/​Note/​View/​Elements/​myNotes.ctp** Create new ctp file in **/​app/​Plugin/​Note/​View/​Elements/​myNotes.ctp**
 +
 +> New in version 2.2.1> Your ctp file must be place at /​app/​Plugin/​{plugin_name}/​View/​Widgets/​ instead of /​app/​Plugin/​{plugin}/​View/​Elements/​
  
 <file php myNotes.ctp>​ <file php myNotes.ctp>​
Line 763: Line 765:
 <?php $this->​Html->​scriptEnd();​ ?> <?php $this->​Html->​scriptEnd();​ ?>
 </​file>​ </​file>​
 +
 +> New in version 2.2.1> You don't have to use $this→requestAction() method to get the need variables anymore e.g: <font 10.0ptline-height:​ 13.0pt;/​arial;;#​000000;;#​ffffff><?​php $notes = $this→requestAction(array('​plugin'​ ⇒ '​Note',​ '​controller'​ ⇒ '​notes',​ '​action'​ ⇒ '​myNotes'​),​ array('​uri'​ ⇒ $this→here));?></​font>​. Instead, create a file in //​app/​Plugin/​{plugin_name}/​Controller/​Widgets/​{your_element_name}Widget.php//,​ for <font 10.0ptline-height:​ 13.0pt;​font-family:​ Arial , Helvetica , FreeSans , sans-serif;/​Arial , Helvetica , FreeSans , sans-serif;;#​000000;;#​ffffff>​example:</​font>​ <font 10.0ptline-height:​ 13.0pt;​font-family:​ Arial , Helvetica , FreeSans , sans-serif;/​Arial , Helvetica , FreeSans , sans-serif;;#​000000;;#​ffffff>//​app/​Plugin/​Note/​Controller/​Widgets/​myNotesWidget.php//</​font>​ with the content like the below code:
 +<​code>​
 +/* **myNotesWidget.ctp** ​ */
 +<?php
 +App::​uses('​Widget','​Controller/​Widgets'​);​
 +class MyNotesWidget extends Widget {
 +    public function beforeRender(Controller $controller) {
 +        $this->​Note = MooCore::​getInstance()->​getModel('​Note'​);​
 +        $notes = $this->​Note->​find('​all',​ array(
 +            '​conditions'​ => array('​uri'​ => $controller->​request->​here),​
 +            '​limit'​ => 1,
 +            '​order'​ => array('​Note.id'​ => '​DESC'​)
 +        ));
 +        $controller->​set('​notes',​$notes);​
 +    }
 +</​code>​
  
 ==== Create widget database ==== ==== Create widget database ====
Line 777: Line 796:
 {{:​documentation:​95fc9fba8f98a2fa3666374b9500fd7e.png}} {{:​documentation:​95fc9fba8f98a2fa3666374b9500fd7e.png}}
  
-  * Note: before export your plugin, you need to implement sql query above into **YourPlugin/​Config/​install/​install.txt. ** (See [[http://​confluence.socialloft.com/​display/​Production/​Creating+Your+mooSocial+First+Plugin#​CreatingYourmooSocialFirstPlugin-Howtoinstallplugin|the flowchart]] for more details)+  * Note: before export your plugin, you need to implement sql query above into **YourPlugin/​Config/​install/​install.txt. **  (See [[http://​confluence.socialloft.com/​display/​Production/​Creating+Your+mooSocial+First+Plugin#​CreatingYourmooSocialFirstPlugin-Howtoinstallplugin|the flowchart]] for more details)
  
 ==== How to use widget ==== ==== How to use widget ====
Line 1034: Line 1053:
  
 <file php NoteSettingsController.php>​ <file php NoteSettingsController.php>​
- +<?php
- +
-<?​php ​+
 class NoteSettingsController extends NoteAppController{ class NoteSettingsController extends NoteAppController{
     public $components = array('​QuickSettings'​);​     public $components = array('​QuickSettings'​);​
Line 1050: Line 1067:
  
 <file php NoteSettings/​admin_index.php>​ <file php NoteSettings/​admin_index.php>​
- 
 <?php <?php
     echo $this->​Html->​css(array('​jquery-ui',​ '​footable.core.min'​),​ null, array('​inline'​ => false));     echo $this->​Html->​css(array('​jquery-ui',​ '​footable.core.min'​),​ null, array('​inline'​ => false));
Line 1102: Line 1118:
  
 Which case do we need? In common, almost plugin settings needn'​t a boot setting, but some still have one such as '​enabled'​ setting which makes us know whether user can access that plugin or not. Why do we need a boot setting? Because when we want to block access, we need to check enable or not in '​routes.php'​ file of plugin; And importantly,​ '​routes.php'​ file is loaded before the system loads unboot settings, so if we don't make '​enabled'​ setting by boot, we can't check it (because that setting doesn'​t exist at that time). Which case do we need? In common, almost plugin settings needn'​t a boot setting, but some still have one such as '​enabled'​ setting which makes us know whether user can access that plugin or not. Why do we need a boot setting? Because when we want to block access, we need to check enable or not in '​routes.php'​ file of plugin; And importantly,​ '​routes.php'​ file is loaded before the system loads unboot settings, so if we don't make '​enabled'​ setting by boot, we can't check it (because that setting doesn'​t exist at that time).
 +
 +> New in version 2.2** ** > In version 2.2, the "​{plugin}_enabled"​ setting have "​is_boot"​ field is '​1'​ by default when you created a new plugin
  
 ==== Create boot setting ==== ==== Create boot setting ====
Line 1118: Line 1136:
  
 <file php NotePlugin.php>​ <file php NotePlugin.php>​
- 
 <?php <?php
 App::​uses('​MooPlugin','​Lib'​);​ App::​uses('​MooPlugin','​Lib'​);​
Line 1164: Line 1181:
  
 <file php NoteListener.php>​ <file php NoteListener.php>​
- 
 <?php <?php
 App::​uses('​CakeEventListener',​ '​Event'​);​ App::​uses('​CakeEventListener',​ '​Event'​);​
Line 1195: Line 1211:
         }         }
     }     }
- +
     public function suggestion($event)     public function suggestion($event)
     {     {
Line 1205: Line 1221:
         {         {
             $notes = $this->​Note->​search($e->​keyword);​             $notes = $this->​Note->​search($e->​keyword);​
-        ​+
             $e->​set('​notes',​ $notes);             $e->​set('​notes',​ $notes);
             $e->​set('​result',​1);​             $e->​set('​result',​1);​
Line 1231: Line 1247:
  
 </​file>​ </​file>​
- 
- 
  
 **Note**: the event name must be "​**Controller.Search.search**"​ and "​**Controller.Search.suggestion**"​. **Note**: the event name must be "​**Controller.Search.search**"​ and "​**Controller.Search.suggestion**"​.
Line 1239: Line 1253:
  
 <file php notes_list.ctp>​ <file php notes_list.ctp>​
- 
 <ul class="​list6 comment_wrapper">​ <ul class="​list6 comment_wrapper">​
 <?php if($notes != null):?> <?php if($notes != null):?>
Line 1249: Line 1262:
                     <div>                     <div>
                         <?php                         <?php
-                        echo $this->​Text->​truncate(strip_tags(str_replace(array('<​br>',​ '&nbsp;'), array('​ ', ''​),​ $note['​Note'​]['​body'​])),​ 150, array('​exact'​ => false));+                        echo $this->​Text->​truncate(strip_tags(str_replace(array('<​br>',​ ' '), array('​ ', ''​),​ $note['​Note'​]['​body'​])),​ 150, array('​exact'​ => false));
                         ?>                         ?>
                     </​div>​                     </​div>​
Line 1257: Line 1270:
                     <?= $this->​Moo->​getTime($note['​Note'​]['​created'​],​ Configure::​read('​core.date_format'​),​ $utz) ?> . <a href="<?​= $this->​request->​base ?>/​notes/​view/<?​= $note['​Note'​]['​id'​] ?>/<?​= seoUrl($note['​Note'​]['​title'​]) ?>"><?​= __d('​Note',​ 'Read more') ?></​a>​                     <?= $this->​Moo->​getTime($note['​Note'​]['​created'​],​ Configure::​read('​core.date_format'​),​ $utz) ?> . <a href="<?​= $this->​request->​base ?>/​notes/​view/<?​= $note['​Note'​]['​id'​] ?>/<?​= seoUrl($note['​Note'​]['​title'​]) ?>"><?​= __d('​Note',​ 'Read more') ?></​a>​
                 </​div>​                 </​div>​
-            </​div> ​   +            </​div>​
         </li>         </li>
     <?php endforeach;?>​     <?php endforeach;?>​
Line 1266: Line 1279:
  
 </​file>​ </​file>​
- 
  
   * Update **/​app/​Plugin/​Note/​Model/​Note.php **  like this   * Update **/​app/​Plugin/​Note/​Model/​Note.php **  like this
  
-<​file ​Note.php+Note.php
  
 +<code file>
 <?php <?php
 App::​uses('​NoteAppModel',​ '​Note.Model'​);​ App::​uses('​NoteAppModel',​ '​Note.Model'​);​
Line 1288: Line 1300:
         )         )
     );     );
-      ​+
     public $belongsTo = array( '​User' ​ => array('​counterCache'​ => true ));     public $belongsTo = array( '​User' ​ => array('​counterCache'​ => true ));
     public $mooFields = array('​title','​href','​plugin','​type'​);​     public $mooFields = array('​title','​href','​plugin','​type'​);​
Line 1300: Line 1312:
         return '';​         return '';​
     }     }
-     +
     public function search($keyword)     public function search($keyword)
     {     {
Line 1309: Line 1321:
 } }
  
-</file> +</code>
  
   * Update **/​app/​Plugin/​Note/​Config/​bootstrap.php **  like this   * Update **/​app/​Plugin/​Note/​Config/​bootstrap.php **  like this
  
 <file php bootstrap.php>​ <file php bootstrap.php>​
- 
- 
 <?php <?php
 App::​uses('​NoteListener',​ '​Note.Lib'​);​ App::​uses('​NoteListener',​ '​Note.Lib'​);​
Line 1329: Line 1338:
  
 <file php /​app/​Plugin/​Note/​Model/​Note.php>​ <file php /​app/​Plugin/​Note/​Model/​Note.php>​
- 
 <?php <?php
 App::​uses('​NoteAppModel',​ '​Note.Model'​);​ App::​uses('​NoteAppModel',​ '​Note.Model'​);​
Line 1385: Line 1393:
  
 <file php content/​note_feed.ctp>​ <file php content/​note_feed.ctp>​
- 
 <div class="">​ <div class="">​
     <!-- end blog thumbnail -->     <!-- end blog thumbnail -->
Line 1394: Line 1401:
             </a>             </a>
         </​div>​         </​div>​
-    <?​=$this->​Text->​truncate( strip_tags( str_replace( array('<​br>','​&nbsp;'), array('​ ',''​),​ $activity['​Content'​]['​Note'​]['​body'​] ) ), 160 , array('​exact'​ => false))?>​+    <?​=$this->​Text->​truncate( strip_tags( str_replace( array('<​br>','​ '), array('​ ',''​),​ $activity['​Content'​]['​Note'​]['​body'​] ) ), 160 , array('​exact'​ => false))?>​
     </​div>​     </​div>​
     <div class="​clear"></​div>​     <div class="​clear"></​div>​
Line 1404: Line 1411:
  
 <file php text/​note_feed>​ <file php text/​note_feed>​
- 
 <?php <?php
 echo __('​created a new note'​);​ echo __('​created a new note'​);​
Line 1410: Line 1416:
 </​file>​ </​file>​
  
-  * To test activity feed go to **http://​domainname/​blogs** ​ and add a new note+  * To test activity feed go to **[[http://​domainname/​blogs|http://​domainname/​blogs]]** and add a new note
  
 {{:​documentation:​feb3ba6f34084150bf1c038b81a50fe8.png}} {{:​documentation:​feb3ba6f34084150bf1c038b81a50fe8.png}}
  
-  * To see new feed go to **http://​domainname/​home**+  * To see new feed go to **[[http://​domainname/​home|http://​domainname/​home]]**
  
 {{:​documentation:​a59705393ec2d0c1d460cb50d2443fbe.png}} {{:​documentation:​a59705393ec2d0c1d460cb50d2443fbe.png}}
Line 1421: Line 1427:
  
   * Copy the sql query below into **/​app/​Plugin/​Note/​Config/​install/​install.sql**   * Copy the sql query below into **/​app/​Plugin/​Note/​Config/​install/​install.sql**
-  *  +  *
-<file sql /​app/​Plugin/​Note/​Config/​install/​install.sql>​ +
  
 +<file sql /​app/​Plugin/​Note/​Config/​install/​install.sql>​
 CREATE TABLE IF NOT EXISTS {PREFIX}notes ( CREATE TABLE IF NOT EXISTS {PREFIX}notes (
     id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,     id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
Line 1438: Line 1443:
     FULLTEXT KEY title (title,​body)     FULLTEXT KEY title (title,​body)
 )ENGINE=MyISAM ​ DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;​ )ENGINE=MyISAM ​ DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;​
- +
 INSERT INTO {PREFIX}notes (user_id,​title,​body,​created,​modified,​uri) INSERT INTO {PREFIX}notes (user_id,​title,​body,​created,​modified,​uri)
 VALUES ('​1',​ 'The title',​ 'This is the post body.',​ NOW(), NOW(),'​uri_1'​),​ VALUES ('​1',​ 'The title',​ 'This is the post body.',​ NOW(), NOW(),'​uri_1'​),​
        ​('​1',​ 'A title once again',​ 'And the post body follows.',​ NOW(), NOW(),'​uri_2'​),​        ​('​1',​ 'A title once again',​ 'And the post body follows.',​ NOW(), NOW(),'​uri_2'​),​
        ​('​1',​ 'Title strikes back', 'This is really exciting! Not.', NOW(), NOW(),'​uri_3'​);​        ​('​1',​ 'Title strikes back', 'This is really exciting! Not.', NOW(), NOW(),'​uri_3'​);​
-  + 
-INSERT INTO core_blocks(name,​ path_view,​params,​is_active) ​+INSERT INTO core_blocks(name,​ path_view,​params,​is_active)
 VALUES('​My Notes',​ '​myNotes','​[{"​label":"​Title","​input":"​text","​value":"​MyNotes","​name":"​title"​},​{"​label":"​plugin","​input":"​hidden","​value":"​Note","​name":"​plugin"​}]',​1);​ VALUES('​My Notes',​ '​myNotes','​[{"​label":"​Title","​input":"​text","​value":"​MyNotes","​name":"​title"​},​{"​label":"​plugin","​input":"​hidden","​value":"​Note","​name":"​plugin"​}]',​1);​
  
 </​file>​ </​file>​
- 
  
   * Copy the sql query below into **/​app/​Plugin/​Note/​Config/​install/​uninstall.sql**   * Copy the sql query below into **/​app/​Plugin/​Note/​Config/​install/​uninstall.sql**
  
 <file sql Copy SQL to /​app/​Plugin/​Note/​Config/​install/​uninstall.sql>​ <file sql Copy SQL to /​app/​Plugin/​Note/​Config/​install/​uninstall.sql>​
- 
- 
 DROP TABLE IF EXISTS {PREFIX}notes;​ DROP TABLE IF EXISTS {PREFIX}notes;​
 DELETE FROM {PREFIX}core_blocks WHERE path_view = '​myNotes';​ DELETE FROM {PREFIX}core_blocks WHERE path_view = '​myNotes';​
Line 1518: Line 1520:
 Create plugin informations:​ Read plugin informations from **YourPlugin/​info.xml** ​ and store into database. Create plugin informations:​ Read plugin informations from **YourPlugin/​info.xml** ​ and store into database.
  
-      ​*+  ​*
  
 Create plugin settings (Optional): Read setting informations from **YourPlugin/​info.xml** ​ and store into database. Create plugin settings (Optional): Read setting informations from **YourPlugin/​info.xml** ​ and store into database.
  
-      ​* Register plugin: register plugin into **Config/​plugins/​plugins.xml**. +  ​* Register plugin: register plugin into **Config/​plugins/​plugins.xml**. 
-      *+  *
  
 Install database (Optional): execute sql query in **YourPlugin/​Config/​install/​install.txt** ​ (sql query maybe: create new table, insert new widget etc). Install database (Optional): execute sql query in **YourPlugin/​Config/​install/​install.txt** ​ (sql query maybe: create new table, insert new widget etc).
  
-      ​*+  ​*
  
 Execute install function (Optional): execute install function from** YourPlugin/​plugin.php** Execute install function (Optional): execute install function from** YourPlugin/​plugin.php**
 +
   * Step 3:Set up and configure extended functionality   * Step 3:Set up and configure extended functionality
       * Load menu tabs: as default, there are twoo tabs: General and Settings. You can add, edit or remove tabs in function menu from **YourPlugin/​plugin.php**.       * Load menu tabs: as default, there are twoo tabs: General and Settings. You can add, edit or remove tabs in function menu from **YourPlugin/​plugin.php**.
-      * View setting guide: if you want to have a text to guide users how to use your settings. Just add it in function ​ settingGuide from **YourPlugin/​plugin.php**.+      * View setting guide: if you want to have a text to guide users how to use your settings. Just add it in function settingGuide from **YourPlugin/​plugin.php**.
  
 ===== How to upgrade plugin ===== ===== How to upgrade plugin =====
Line 1598: Line 1601:
 Install database (Optional): execute sql query in **YourPlugin/​Config/​install/​upgrade.xml** ​ (sql query maybe: create new table, insert new widget etc). Install database (Optional): execute sql query in **YourPlugin/​Config/​install/​upgrade.xml** ​ (sql query maybe: create new table, insert new widget etc).
  
-      ​*+  ​*
  
 Execute extended functions (Optional): base on version number, process will execute function named like callback_1_0 in **YourPlugin/​plugin.php.** Execute extended functions (Optional): base on version number, process will execute function named like callback_1_0 in **YourPlugin/​plugin.php.**
 +
   * Step 3:Set up and configure extended functionality   * Step 3:Set up and configure extended functionality
       * Load menu tabs: as default, there are twoo tabs: General and Settings. You can add, edit or remove tabs in function menu from **YourPlugin/​plugin.php**.       * Load menu tabs: as default, there are twoo tabs: General and Settings. You can add, edit or remove tabs in function menu from **YourPlugin/​plugin.php**.
-      * View setting guide: if you want to have a text to guide users how to use your settings. Just add it in function ​ settingGuide from **YourPlugin/​plugin.php**.+      * View setting guide: if you want to have a text to guide users how to use your settings. Just add it in function settingGuide from **YourPlugin/​plugin.php**.
  
 ===== Internationalizing Your Plugin ===== ===== Internationalizing Your Plugin =====
Line 1664: Line 1668:
 </​code>​ </​code>​
  
-  * You can manage task on Admin ACP **Home > System Admin > Tasks**+  * You can manage task on Admin ACP **Home> System Admin> Tasks**
  
 ===== How to using mailsystem ===== ===== How to using mailsystem =====
Line 1671: Line 1675:
  
 <code php> <code php>
- 
- 
 public function install(){ public function install(){
-        $mailModel = MooCore::​getInstance()->​getModel('​Mail_Mailtemplate'​); ​     +        $mailModel = MooCore::​getInstance()->​getModel('​Mail_Mailtemplate'​);​
         $languageModel = MooCore::​getInstance()->​getModel('​Language'​);​         $languageModel = MooCore::​getInstance()->​getModel('​Language'​);​
         $langs = $languageModel->​find('​all'​);​         $langs = $languageModel->​find('​all'​);​
Line 1692: Line 1694:
     <​p>​[header]</​p>​     <​p>​[header]</​p>​
     <​p>​This is mail reminder : <a href="​[note_link]">​[note_name]</​a></​p>​     <​p>​This is mail reminder : <a href="​[note_link]">​[note_name]</​a></​p>​
-    <​p>​[footer]</​p> ​   +    <​p>​[footer]</​p>​
 EOF; EOF;
             $data_translate['​content'​] = $content;             $data_translate['​content'​] = $content;
Line 1702: Line 1704:
         $mailModel->​deleteAll(array('​Mailtemplate.type'​=>'​note_reminder'​),​true,​true);​         $mailModel->​deleteAll(array('​Mailtemplate.type'​=>'​note_reminder'​),​true,​true);​
     }     }
-     +</​code>​
-    ​</​code>​+
  
-<code php>+How to using it $mailComponent→send($mix,​$type,​$params) $mix: email or $user_id or model user, $type: type of email, $params: param for mail type.
  
 +<code php>
 $noteModel = MooCore::​getInstance()->​getModel('​Note_Note'​);​ $noteModel = MooCore::​getInstance()->​getModel('​Note_Note'​);​
         $notes = $noteModel->​find('​all',​array('​conditions'​=>​array(         $notes = $noteModel->​find('​all',​array('​conditions'​=>​array(
             '​check_reminder'​ => false,             '​check_reminder'​ => false,
-            '​reminder >' => 0, +            '​reminder>'​ => 0, 
-            '​(UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(Note.created) > Note.reminder * 3600)'+            '​(UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(Note.created)>​ Note.reminder * 3600)'
         )));         )));
-         +
         if (count($notes))         if (count($notes))
         {         {
Line 1727: Line 1729:
                     )                     )
                 );                 );
-                 +
                 $noteModel->​id = $note['​Note'​]['​id'​];​                 $noteModel->​id = $note['​Note'​]['​id'​];​
                 $noteModel->​save(array('​check_reminder'​=>​true));​                 $noteModel->​save(array('​check_reminder'​=>​true));​
             }             }
         }         }
-        ​ +</​code>​ 
-        </​code>​+ 
 +===== How to using tag system ===== 
 + 
 +When create a note: 
 + 
 +<file php NotesController.php>​ 
 +if ($this->​Note->​save($this->​request->​data)) { 
 +        ​//Tag system 
 +    $this->​loadModel('​Tag'​);​ 
 +    $this->​Tag->​saveTags($this->​request->​data['​Note'​]['​tags'​],​ $this->​Note->​id,​ '​Note_Note'​);​ 
 +    // 
 + 
 +    $this->​Session->​setFlash(__d('​Note',​ 'Your note has been saved.'​));​ 
 +    return $this->​redirect(array('​action'​ => '​index'​));​ 
 +
 + 
 +</file> 
 + 
 +<file php add.ctp>​ 
 +//Tag system 
 +<div class="​col-md-2">​ 
 +        <​label><?​=__d('​Note',​ '​Tags'​)?></​label>​ 
 +    </​div>​ 
 +    <div class="​col-md-10">​ 
 +        <?php echo $this->​Form->​text('​tags'​);​ ?> <a href="​javascript:​void(0)"​ class="​tip profile-tip"​ title="<?​=__d('​Note',​ '​Separated by commas'​)?>">​(?​)</​a>​ 
 +    </​div>​ 
 +    <div class="​clear"></​div>​ 
 +</​li>​ 
 +// 
 + 
 +</​file>​ 
 + 
 +When edit a note: NotesController.php 
 + 
 +<code php> 
 +if ($this->​request->​is(array('​post',​ '​put'​))) { 
 +    $this->​Note->​id = $id; 
 +    $this->​request->​data['​Note'​]['​user_id'​] = $this->​Session->​read('​uid'​);​ 
 +    if ($this->​Note->​save($this->​request->​data)) { 
 +                //Tag system 
 +        $this->​Tag->​saveTags($this->​request->​data['​Note'​]['​tags'​],​ $id, '​Note_Note'​);​ 
 +        // 
 + 
 +        $this->​Session->​setFlash(__d('​Note',​ 'Your note has been updated.'​));​ 
 +        return $this->​redirect(array('​action'​ => '​index'​));​ 
 +    } 
 +    $this->​Session->​setFlash(__d('​Note',​ '​Unable to update your note.'​));​ 
 +
 +//Tag system 
 +$tags = $this->​Tag->​getContentTags($id,​ '​Note_Note'​);​ 
 +$this->​set('​tags',​ $tags); 
 +// 
 + 
 +</​code>​ 
 + 
 +<file php edit.ctp>​ 
 +//Tag system 
 +<​li>​ 
 +    <div class="​col-md-2">​ 
 +        <​label><?​=__d('​Blog',​ '​Tags'​)?></​label>​ 
 +    </​div>​ 
 +    <?php 
 +    $tags_value = '';​ 
 +        if (!empty($tags)) $tags_value = implode(',​ ', $tags); 
 +    ?> 
 +    <div class="​col-md-10">​ 
 +        <?php echo $this->​Form->​text('​tags',​ array('​value'​ => $tags_value));​ ?> <a href="​javascript:​void(0)"​ class="​tip profile-tip"​ title="<?​=__d('​Blog',​ '​Separated by commas'​)?>">​(?​)</​a>​ 
 +    </​div>​ 
 +    <div class="​clear"></​div>​ 
 +</​li>​ 
 +// 
 + 
 +</​file>​ 
 + 
 +Helper hook 
 + 
 +<file php NoteHelper.php>​ 
 +//Tag system 
 +public function getTagUnionsNote($noteids) 
 +
 +    return "​SELECT i.id, i.title, i.body, i.like_count,​ i.created, '​Note_Note'​ as moo_type 
 +                     FROM " . Configure::​read('​core.prefix'​) . "notes i 
 +                     WHERE i.id IN (" . implode(',',​ $noteids) . ") AND i.privacy = "​.PRIVACY_EVERYONE;​ 
 +
 +public function getImage($item,​$options) 
 +
 +    return $this->​assetUrl('​Note.noimage/​note.png',​$options + array('​pathPrefix'​ => Configure::​read('​App.imageBaseUrl'​)));​ 
 + 
 +    return $url; 
 +
 +// 
 + 
 +</​file>​ 
 + 
 +When view note 
 + 
 +<file php NotesController.php>​ 
 +//Tag system 
 +$this->​loadModel('​Tag'​);​ 
 +$tags = $this->​Tag->​getContentTags($id,​ '​Note_Note'​);​ 
 +$this->​set('​tags',​ $tags); 
 +// 
 + 
 +</​file>​ 
 + 
 +<file php view.ctp>​ 
 +//Tag system 
 +<div class="​box_content">​ 
 +    <?php echo $this->​element( '​blocks/​tags_item_block'​ ); ?> 
 +</​div>​ 
 +// 
 + 
 +</​file>​ 
 + 
 +===== How to using like system ===== 
 + 
 +View note 
 + 
 +<file php NotesController.php>​ 
 +//Like system 
 +MooCore::​getInstance()->​setSubject($note);​ 
 +// 
 + 
 +</​file>​ 
 + 
 +<file php view.ctp>​ 
 +//Like system 
 +<div class="​content_center">​ 
 +    <div class="​bar-content full_content p_m_10">​ 
 +        <div class="​content_center">​ 
 +            <?php echo $this->​renderLike();?>​ 
 +        </​div>​ 
 +    </​div>​ 
 +</​div>​ 
 +// 
 + 
 +</​file>​ 
 + 
 +===== How to using comment system ===== 
 + 
 +View note 
 + 
 +<file php notescontroller.php>​ 
 +//Comment system 
 +MooCore::​getInstance()->​setSubject($note);​ 
 +// 
 + 
 +</​file>​ 
 + 
 +<file php view.ctp>​ 
 +//Comment system 
 +<div class="​content_center">​ 
 +    <div class="​bar-content full_content p_m_10">​ 
 +        <?php echo $this->​renderComment();?>​ 
 +    </​div>​ 
 +</​div>​ 
 +// 
 + 
 +</​file>​ 
 + 
 +<file php NoteHelper.php>​ 
 +//Comment system 
 +public function checkPostStatus($note,​$uid) 
 +
 +    if (!$uid) 
 +        return false; 
 + 
 +    $friendModel = MooCore::​getInstance()->​getModel('​Friend'​);​ 
 +    if ($uid == $note['​Note'​]['​user_id'​]) 
 +        return true; 
 + 
 +    if ($note['​Note'​]['​privacy'​] == PRIVACY_EVERYONE) 
 +    { 
 +        return true; 
 +    } 
 + 
 +    if ($note['​Note'​]['​privacy'​] == PRIVACY_FRIENDS) 
 +    { 
 +        $areFriends = $friendModel->​areFriends( $uid, $note['​Blog'​]['​user_id'​] ); 
 +        if ($areFriends) 
 +            return true; 
 +    } 
 + 
 +    return false; 
 +
 +public function checkSeeActivity($note,​$uid) 
 +
 +    return $this->​checkPostStatus($note,​$uid);​ 
 +
 +// 
 + 
 +</​file>​ 
 + 
 +===== How to using report system ===== 
 + 
 +View note: 
 + 
 +<file php view.tcp>​ 
 +//Report system 
 +<?​=$this->​Html->​link( 
 +    __d('​Note',​ '​Report Note'​),​ array( 
 +        '​controller'​ => '​reports',​ 
 +        '​action'​ => '​ajax_create',​ 
 +        '​plugin'​ => '',​ 
 +        $note['​Note'​]['​moo_type'​],​ 
 +        $note['​Note'​]['​id'​] 
 +    ), array('​data-target'​=>'#​themeModal','​class'​=>'​button button-action topButton button-mobi-top','​data-toggle'​=>'​modal'​) 
 +); 
 +// 
 + 
 +</​file>​ 
 + 
 +====== Plugin Development Suggestions ====== 
 + 
 +  * Do not hardcode the mooSocial database table prefix into your Plugins . 
 +  * Use the existing database tables instead of creating new custom tables if possible. 
 +  * SELECT only what you need.Naming conventions are very important in CakePHP. By naming our model Post, CakePHP can automatically infer that this model will be used in the PostsController,​ and will be tied to a database table called posts. 
 + 
 +====== Themed Plugin ====== 
 + 
 +path **app/​View/​Themed/​[ThemeName]/​Plugin/​[PluginName]/​** 
 + 
 +{{:​documentation:​23fb6cd688d81fcb558c8984a443b870.jpg}}
  
documentation/create_first_plugin.txt · Last modified: 2015/09/03 00:08 (external edit)