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 Both sides next revision
documentation:create_first_plugin [2015/08/24 05:12]
127.0.0.1 external edit
documentation:create_first_plugin [2015/09/03 03:30]
mooeditor
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 1034: Line 1037:
  
 <file php NoteSettingsController.php>​ <file php NoteSettingsController.php>​
- 
 <?php <?php
 class NoteSettingsController extends NoteAppController{ class NoteSettingsController extends NoteAppController{
Line 1262: Line 1264:
   * 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 1305: Line 1308:
  
 <file php bootstrap.php>​ <file php bootstrap.php>​
- 
 <?php <?php
 App::​uses('​NoteListener',​ '​Note.Lib'​);​ App::​uses('​NoteListener',​ '​Note.Lib'​);​
Line 1410: Line 1412:
  
 <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 1439:
  
 <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 1723: Line 1723:
  
 <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 1737: Line 1736:
  
 <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 1754: Line 1752:
  
 <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 1774: Line 1771:
  
 </​code>​ </​code>​
- 
  
 <file php edit.ctp>​ <file php edit.ctp>​
- 
 //Tag system //Tag system
 <li> <li>
Line 1783: Line 1778:
         <​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 1799: Line 1794:
  
 <file php NoteHelper.php>​ <file php NoteHelper.php>​
- 
  
 //Tag system //Tag system
Line 1811: Line 1805:
 { {
     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 1821: Line 1815:
  
 <file php NotesController.php>​ <file php NotesController.php>​
- 
 //Tag system //Tag system
 $this->​loadModel('​Tag'​);​ $this->​loadModel('​Tag'​);​
Line 1829: Line 1822:
  
 </​file>​ </​file>​
- 
- 
  
 <file php view.ctp>​ <file php view.ctp>​
- 
 //Tag system //Tag system
 <div class="​box_content">​ <div class="​box_content">​
Line 1841: Line 1831:
  
 </​file>​ </​file>​
- 
- 
  
 ===== How to using like system ===== ===== How to using like system =====
Line 1849: Line 1837:
  
 <file php NotesController.php>​ <file php NotesController.php>​
- 
 //Like system //Like system
 MooCore::​getInstance()->​setSubject($note);​ MooCore::​getInstance()->​setSubject($note);​
Line 1857: Line 1844:
  
 <file php view.ctp>​ <file php view.ctp>​
- 
 //Like system //Like system
 <div class="​content_center">​ <div class="​content_center">​
Line 1864: Line 1850:
             <?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 1876: Line 1861:
  
 <file php notescontroller.php>​ <file php notescontroller.php>​
- 
 //Comment system //Comment system
 MooCore::​getInstance()->​setSubject($note);​ MooCore::​getInstance()->​setSubject($note);​
Line 1882: Line 1866:
  
 </​file>​ </​file>​
- 
  
 <file php view.ctp>​ <file php view.ctp>​
- 
 //Comment system //Comment system
 <div class="​content_center">​ <div class="​content_center">​
Line 1895: Line 1877:
  
 </​file>​ </​file>​
- 
  
 <file php NoteHelper.php>​ <file php NoteHelper.php>​
- 
 //Comment system //Comment system
 public function checkPostStatus($note,​$uid) public function checkPostStatus($note,​$uid)
 { {
     if (!$uid)     if (!$uid)
-        return false; ​      ​ +        return false; 
-         ​+
     $friendModel = MooCore::​getInstance()->​getModel('​Friend'​);​     $friendModel = MooCore::​getInstance()->​getModel('​Friend'​);​
     if ($uid == $note['​Note'​]['​user_id'​])     if ($uid == $note['​Note'​]['​user_id'​])
         return true;         return true;
-         +
     if ($note['​Note'​]['​privacy'​] == PRIVACY_EVERYONE)     if ($note['​Note'​]['​privacy'​] == PRIVACY_EVERYONE)
     {     {
         return true;         return true;
     }     }
-     +
     if ($note['​Note'​]['​privacy'​] == PRIVACY_FRIENDS)     if ($note['​Note'​]['​privacy'​] == PRIVACY_FRIENDS)
     {     {
Line 1920: Line 1900:
             return true;             return true;
     }     }
-      +
-     +
     return false;     return false;
 } }
Line 1931: Line 1910:
  
 </​file>​ </​file>​
- 
- 
  
 ===== How to using report system ===== ===== How to using report system =====
Line 1939: Line 1916:
  
 <file php view.tcp>​ <file php view.tcp>​
- 
 //Report system //Report system
 <?​=$this->​Html->​link( <?​=$this->​Html->​link(
Line 1956: Line 1932:
 ====== 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.txt · Last modified: 2015/09/03 00:08 (external edit)