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:52]
mooeditor [How to using mailsystem]
documentation:create_first_plugin [2015/08/24 05:12]
127.0.0.1 external edit
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 1685: Line 1688:
 </​code>​ </​code>​
  
-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+How to using it $mailComponentsend($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'​);​ 
 +        $notes = $noteModel->​find('​all',​array('​conditions'​=>​array( 
 +            '​check_reminder'​ => false, 
 +            '​reminder>'​ => 0, 
 +            '​(UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(Note.created)>​ Note.reminder * 3600)'​ 
 +        ))); 
 + 
 +        if (count($notes)) 
 +        { 
 +            $mailComponent = MooCore::​getInstance()->​getComponent('​Mail.MooMail'​);​ 
 +            $ssl_mode = Configure::​read('​core.ssl_mode'​);​ 
 +            $http = (!empty($ssl_mode)) ? '​https'​ :  '​http';​ 
 +            foreach ($notes as $note) 
 +            { 
 +                $mailComponent->​send($note['​Note'​]['​user_id'​],'​note_reminder',​ 
 +                    array( 
 +                        '​note_name'​ => $note['​Note'​]['​moo_title'​],​ 
 +                        '​note_link'​ => $http.'://'​.$_SERVER['​SERVER_NAME'​].$note['​Note'​]['​moo_href'​],​ 
 +                    ) 
 +                ); 
 + 
 +                $noteModel->​id = $note['​Note'​]['​id'​];​ 
 +                $noteModel->​save(array('​check_reminder'​=>​true));​ 
 +            } 
 +        } 
 +</​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)