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
documentation:create_first_plugin [2015/06/11 11:19]
mooeditor [How to using like system]
documentation:create_first_plugin [2015/09/03 00:08] (current)
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 683: 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 759: Line 765:
 //]]> //]]>
 <?php $this->​Html->​scriptEnd();​ ?> <?php $this->​Html->​scriptEnd();​ ?>
 +</​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:
 +<file php 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);​
 +    }
 </​file>​ </​file>​
  
Line 1031: Line 1055:
  
 <file php NoteSettingsController.php>​ <file php NoteSettingsController.php>​
- 
 <?php <?php
 class NoteSettingsController extends NoteAppController{ class NoteSettingsController extends NoteAppController{
Line 1097: Line 1120:
  
 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 1259: Line 1284:
   * Update **/​app/​Plugin/​Note/​Model/​Note.php **  like this   * Update **/​app/​Plugin/​Note/​Model/​Note.php **  like this
  
-<code file Note.php>+Note.php
  
 +<code file>
 <?php <?php
 App::​uses('​NoteAppModel',​ '​Note.Model'​);​ App::​uses('​NoteAppModel',​ '​Note.Model'​);​
Line 1302: Line 1328:
  
 <file php bootstrap.php>​ <file php bootstrap.php>​
- 
 <?php <?php
 App::​uses('​NoteListener',​ '​Note.Lib'​);​ App::​uses('​NoteListener',​ '​Note.Lib'​);​
Line 1407: Line 1432:
  
 <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 1435: Line 1459:
  
 <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 1720: Line 1743:
  
 <file php NotesController.php>​ <file php NotesController.php>​
- 
 if ($this->​Note->​save($this->​request->​data)) { if ($this->​Note->​save($this->​request->​data)) {
-        //Tag system ​       +        //Tag system
     $this->​loadModel('​Tag'​);​     $this->​loadModel('​Tag'​);​
     $this->​Tag->​saveTags($this->​request->​data['​Note'​]['​tags'​],​ $this->​Note->​id,​ '​Note_Note'​);​     $this->​Tag->​saveTags($this->​request->​data['​Note'​]['​tags'​],​ $this->​Note->​id,​ '​Note_Note'​);​
     //     //
- +
     $this->​Session->​setFlash(__d('​Note',​ 'Your note has been saved.'​));​     $this->​Session->​setFlash(__d('​Note',​ 'Your note has been saved.'​));​
     return $this->​redirect(array('​action'​ => '​index'​));​     return $this->​redirect(array('​action'​ => '​index'​));​
Line 1734: Line 1756:
  
 <file php add.ctp> <file php add.ctp>
- +//Tag system
-//Tag system ​       +
 <div class="​col-md-2">​ <div class="​col-md-2">​
         <​label><?​=__d('​Note',​ '​Tags'​)?></​label>​         <​label><?​=__d('​Note',​ '​Tags'​)?></​label>​
Line 1751: Line 1772:
  
 <code php> <code php>
- 
 if ($this->​request->​is(array('​post',​ '​put'​))) { if ($this->​request->​is(array('​post',​ '​put'​))) {
     $this->​Note->​id = $id;     $this->​Note->​id = $id;
     $this->​request->​data['​Note'​]['​user_id'​] = $this->​Session->​read('​uid'​);​     $this->​request->​data['​Note'​]['​user_id'​] = $this->​Session->​read('​uid'​);​
     if ($this->​Note->​save($this->​request->​data)) {     if ($this->​Note->​save($this->​request->​data)) {
-                //Tag system ​+                //Tag system
         $this->​Tag->​saveTags($this->​request->​data['​Note'​]['​tags'​],​ $id, '​Note_Note'​);​         $this->​Tag->​saveTags($this->​request->​data['​Note'​]['​tags'​],​ $id, '​Note_Note'​);​
         //         //
- +
         $this->​Session->​setFlash(__d('​Note',​ 'Your note has been updated.'​));​         $this->​Session->​setFlash(__d('​Note',​ 'Your note has been updated.'​));​
         return $this->​redirect(array('​action'​ => '​index'​));​         return $this->​redirect(array('​action'​ => '​index'​));​
Line 1771: Line 1791:
  
 </​code>​ </​code>​
- 
  
 <file php edit.ctp>​ <file php edit.ctp>​
- 
 //Tag system //Tag system
 <li> <li>
Line 1780: Line 1798:
         <​label><?​=__d('​Blog',​ '​Tags'​)?></​label>​         <​label><?​=__d('​Blog',​ '​Tags'​)?></​label>​
     </​div>​     </​div>​
-    <?​php ​+    <?php
     $tags_value = '';​     $tags_value = '';​
         if (!empty($tags)) $tags_value = implode(',​ ', $tags);         if (!empty($tags)) $tags_value = implode(',​ ', $tags);
Line 1796: Line 1814:
  
 <file php NoteHelper.php>​ <file php NoteHelper.php>​
- 
- 
 //Tag system //Tag system
 public function getTagUnionsNote($noteids) public function getTagUnionsNote($noteids)
Line 1808: Line 1824:
 { {
     return $this->​assetUrl('​Note.noimage/​note.png',​$options + array('​pathPrefix'​ => Configure::​read('​App.imageBaseUrl'​)));​     return $this->​assetUrl('​Note.noimage/​note.png',​$options + array('​pathPrefix'​ => Configure::​read('​App.imageBaseUrl'​)));​
-     +
     return $url;     return $url;
 } }
Line 1818: Line 1834:
  
 <file php NotesController.php>​ <file php NotesController.php>​
- 
 //Tag system //Tag system
 $this->​loadModel('​Tag'​);​ $this->​loadModel('​Tag'​);​
Line 1826: Line 1841:
  
 </​file>​ </​file>​
- 
- 
  
 <file php view.ctp>​ <file php view.ctp>​
- 
 //Tag system //Tag system
 <div class="​box_content">​ <div class="​box_content">​
Line 1838: Line 1850:
  
 </​file>​ </​file>​
- 
- 
  
 ===== How to using like system ===== ===== How to using like system =====
Line 1846: Line 1856:
  
 <file php NotesController.php>​ <file php NotesController.php>​
- 
 //Like system //Like system
 MooCore::​getInstance()->​setSubject($note);​ MooCore::​getInstance()->​setSubject($note);​
Line 1854: Line 1863:
  
 <file php view.ctp>​ <file php view.ctp>​
- 
 //Like system //Like system
 <div class="​content_center">​ <div class="​content_center">​
Line 1861: Line 1869:
             <?php echo $this->​renderLike();?>​             <?php echo $this->​renderLike();?>​
         </​div>​         </​div>​
-    </​div> ​           +    </​div>​
 </​div>​ </​div>​
 // //
  
 </​file>​ </​file>​
- 
  
 ===== How to using comment system ===== ===== How to using comment system =====
Line 1872: Line 1879:
 View note View note
  
-notescontroller.php+<file php notescontroller.php
 +//Comment system 
 +MooCore::​getInstance()->​setSubject($note);​ 
 +//
  
-view.ctp+</​file>​
  
-notehelper.php+<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 ===== ===== How to using report system =====
Line 1882: Line 1934:
 View note: View note:
  
-view.tcp+<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 ====== ====== Plugin Development Suggestions ======
  
-  * Do not hardcode the mooSocial database table prefix ​ into your Plugins .+  * Do not hardcode the mooSocial database table prefix into your Plugins .
   * Use the existing database tables instead of creating new custom tables if possible.   * 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.   * 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.
documentation/create_first_plugin.1434021585.txt.gz · Last modified: 2015/08/24 01:13 (external edit)