documentation:create_first_plugin
Differences
This shows you the differences between two versions of the page.
| Previous revision | |||
| — | documentation:create_first_plugin [2015/09/03 04:08] (current) – [Create an element] mooeditor | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Creating Your mooSocial First Plugin ====== | ||
| + | |||
| + | //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:// | ||
| + | |||
| + | ====== Welcome to the mooSocial guides ====== | ||
| + | |||
| + | It is designed to start from the basics, and slowly increase to more sophisticated concepts until you know everything there is to know about building awesome mooSocial plugin .\\ | ||
| + | \\ | ||
| + | mooSocial is built on CakePHP 2 framework and its plugins are designed base on CakePHP plugin so that you can set up a combination of controllers , models, and views and release them as a packaged . | ||
| + | |||
| + | ====== Development Mode ====== | ||
| + | |||
| + | To enable this setting, go to **Home> System Admin> System Setting> Sytem Mode> Production Mode> Develelopment** Mode | ||
| + | |||
| + | {{: | ||
| + | |||
| + | There are three modes: | ||
| + | |||
| + | * Production (default): hide all errors, warnings and sql query strings. | ||
| + | * Development 1: show all errors, warnings, model caches refreshed and flash messages halted. | ||
| + | * Development 2: show all errors, warnings, sql query strings, model caches refreshed and flash messages halted | ||
| + | |||
| + | ====== Frontend ====== | ||
| + | |||
| + | ===== Creating a Plugin ===== | ||
| + | |||
| + | ==== How to create plugin ==== | ||
| + | |||
| + | Let’s begin to create a Note plugin .In this tutorial we will be making a simple // | ||
| + | |||
| + | {{: | ||
| + | |||
| + | === Plugin Name , Key === | ||
| + | |||
| + | The first task in creating a mooSocial Plugin is to think about what the plugin will do, and make a unique key for your plugin. Key only contains letters, numbers and the underscore ' | ||
| + | |||
| + | Example: ContactManager | ||
| + | |||
| + | === Plugin Files === | ||
| + | |||
| + | == Basic directory structure == | ||
| + | |||
| + | After that , our plugin’s [[http:// | ||
| + | |||
| + | {{: | ||
| + | |||
| + | == info.xml == | ||
| + | |||
| + | This file contains the standard plugin information . | ||
| + | |||
| + | == PluginNamePlugin.php == | ||
| + | |||
| + | * install: executed during installation proccess. | ||
| + | * install: executed during uninstallation proccess. | ||
| + | * settingGuide: | ||
| + | * menu: you can add or remove plugin tabs. There are two default tabs: General and Settings. | ||
| + | * callback_x (Optional) (x is version): executed during upgrade process. Example: you want to create a callback function for version 2.0, just create a function named callback_2_0. | ||
| + | |||
| + | == Config/ | ||
| + | |||
| + | This file contains the configuration of your plugin . | ||
| + | |||
| + | == Config/ | ||
| + | |||
| + | This file contains your routers configuration plugin . \\ \\ Note : Routing is a feature that maps URLs to controller actions . It will help plugins to make pretty URLs more configurable and flexible. | ||
| + | |||
| + | == Config/ | ||
| + | |||
| + | This file contains sql query strings that will be executed during installation proccess. | ||
| + | |||
| + | == Config/ | ||
| + | |||
| + | This file contains sql query strings that will be executed during uninstallation proccess. | ||
| + | |||
| + | == Config/ | ||
| + | |||
| + | This file contains sql query strings that will be executed during upgrade proccess.' | ||
| + | |||
| + | ==== Creating Note Database ==== | ||
| + | |||
| + | <font 13.3333330154419px font-style: normal; font-variant: | ||
| + | |||
| + | <file sql install.sql> | ||
| + | CREATE TABLE IF NOT EXISTS {PREFIX}notes ( | ||
| + | id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
| + | user_id INT(11) NOT NULL, | ||
| + | title VARCHAR(50), | ||
| + | body TEXT, | ||
| + | uri VARCHAR(150), | ||
| + | created DATETIME DEFAULT NULL, | ||
| + | modified DATETIME DEFAULT NULL, | ||
| + | like_count INT(11) DEFAULT ' | ||
| + | dislike_count INT(11) DEFAULT ' | ||
| + | comment_count INT(11) DEFAULT ' | ||
| + | FULLTEXT KEY title (title, | ||
| + | )ENGINE=MyISAM | ||
| + | |||
| + | INSERT INTO {PREFIX}notes (user_id, | ||
| + | VALUES (' | ||
| + | | ||
| + | | ||
| + | |||
| + | INSERT INTO `{PREFIX}tasks` (`title`, `plugin`, `timeout`, `processes`, | ||
| + | (' | ||
| + | </ | ||
| + | |||
| + | ==== Create Note Model ==== | ||
| + | |||
| + | Create a new model file **Plugin/ | ||
| + | |||
| + | Plugin model class files go in **/ | ||
| + | <file php / | ||
| + | <?php | ||
| + | App:: | ||
| + | /** | ||
| + | * Note Model | ||
| + | * | ||
| + | */ | ||
| + | class Note extends NoteAppModel { | ||
| + | public $mooFields = array(' | ||
| + | |||
| + | public $belongsTo = array( ' | ||
| + | public $validate = array( | ||
| + | ' | ||
| + | ' | ||
| + | ), | ||
| + | ' | ||
| + | ' | ||
| + | ) | ||
| + | ); | ||
| + | |||
| + | public $belongsTo = array( ' | ||
| + | public $mooFields = array(' | ||
| + | public function getHref($row) | ||
| + | { | ||
| + | if(isset($row[' | ||
| + | { | ||
| + | $request = Router:: | ||
| + | return $request-> | ||
| + | } | ||
| + | return ''; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | Naming conventions are very important in CakePHP. By naming our model Note, CakePHP can automatically infer that this model will be used in the NotesController, | ||
| + | |||
| + | CakePHP will dynamically create a model object for you if it cannot find a corresponding file in /app/Model. This also means that if you accidentally name your file wrong (for example, note.php or notes.php instead of Note.php), CakePHP will not recognize any of your settings and will use the defaults instead. | ||
| + | |||
| + | For more on models, such as table prefixes, callbacks, and validation , see [[http:// | ||
| + | |||
| + | ==== Create a Notes Controller ==== | ||
| + | |||
| + | Next, we’ll create a controller for our notes. The controller is where all the business logic for notes interaction will happen . We will define functions : index , create , delete , update in NotesController . Users can access the logic there by requesting : mooSite/ | ||
| + | |||
| + | <font 13.3333330154419px font-style: normal; font-variant: | ||
| + | |||
| + | <file php / | ||
| + | <?php | ||
| + | class NotesController extends NoteAppController { | ||
| + | /** | ||
| + | * Scaffold | ||
| + | * | ||
| + | * @var mixed | ||
| + | */ | ||
| + | public $scaffold; | ||
| + | public function admin_index(){ | ||
| + | } | ||
| + | |||
| + | public function index() { | ||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | public function view($id = null) { | ||
| + | if (!$id) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | $note = $this-> | ||
| + | if (!$note) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | $this-> | ||
| + | |||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | private function likesComments($id) { | ||
| + | //comment | ||
| + | $this-> | ||
| + | $comments = $this-> | ||
| + | $comment_count = $this-> | ||
| + | $page = 1; | ||
| + | |||
| + | $data[' | ||
| + | $data[' | ||
| + | $this-> | ||
| + | $this-> | ||
| + | |||
| + | //like | ||
| + | $this-> | ||
| + | $likes = $this-> | ||
| + | $dislikes = $this-> | ||
| + | |||
| + | $this-> | ||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | public function add() { | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | return $this-> | ||
| + | } | ||
| + | $this-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public function edit($id = null) { | ||
| + | if (!$id) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | $note = $this-> | ||
| + | if (!$note) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | return $this-> | ||
| + | } | ||
| + | $this-> | ||
| + | } | ||
| + | if (!$this-> | ||
| + | $this-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public function delete($id) { | ||
| + | if (!$id) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | __(' | ||
| + | ); | ||
| + | return $this-> | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | The single instruction in the action uses set() to pass data from the controller to the view (which we’ll create next). The line sets the view variable called ‘notes’ equal to the return value of the find(' | ||
| + | |||
| + | ==== Creating Views ==== | ||
| + | |||
| + | CakePHP views are just presentation-flavored fragments that fit inside an application’s layout. For most applications, | ||
| + | |||
| + | === Note index view === | ||
| + | |||
| + | <code php> | ||
| + | <!-- File: / | ||
| + | <!-- In case you want to create multiple themed views, | ||
| + | apply this view for default template , you can copy it to the folder: / | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | < | ||
| + | <?php | ||
| + | echo $this-> | ||
| + | __d(' | ||
| + | ' | ||
| + | ' | ||
| + | ), array(' | ||
| + | ); | ||
| + | ?> | ||
| + | </ | ||
| + | <table class=" | ||
| + | <tr> | ||
| + | <th class=" | ||
| + | < | ||
| + | <th class=" | ||
| + | <th class=" | ||
| + | </tr> | ||
| + | <!-- Here is where we loop through our $posts array, printing out post info --> | ||
| + | <?php foreach ($notes as $note): ?> | ||
| + | <tr> | ||
| + | < | ||
| + | <td> | ||
| + | <?php echo $this-> | ||
| + | ' | ||
| + | ' | ||
| + | $note[' | ||
| + | ?> | ||
| + | </td> | ||
| + | < | ||
| + | <td> | ||
| + | <?php echo $this-> | ||
| + | ' | ||
| + | ' | ||
| + | $note[' | ||
| + | ));?> | | ||
| + | <?php echo $this-> | ||
| + | ' | ||
| + | ' | ||
| + | $note[' | ||
| + | array( | ||
| + | ' | ||
| + | ));?> | ||
| + | </td> | ||
| + | </tr> | ||
| + | <?php endforeach; ?> | ||
| + | <?php unset($note); | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | === Note view === | ||
| + | |||
| + | Now let’s create the view for our new ‘view’ action and place it in **/ | ||
| + | |||
| + | <code php> | ||
| + | <!-- File: / | ||
| + | <!-- In case you want to create multiple themed views, | ||
| + | apply this view for default template , you can copy it to the folder: / | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | < | ||
| + | <? | ||
| + | __d(' | ||
| + | ' | ||
| + | ' | ||
| + | ), array(' | ||
| + | ); | ||
| + | ?> | ||
| + | <?php echo $this-> | ||
| + | ' | ||
| + | ' | ||
| + | $note[' | ||
| + | ), array(' | ||
| + | );?> | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <? | ||
| + | </ | ||
| + | </ | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | < | ||
| + | <ul class=" | ||
| + | <?php echo $this-> | ||
| + | </ul> | ||
| + | <?php echo $this-> | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Verify that this is working by trying the links at **[[http:// | ||
| + | |||
| + | === Add view === | ||
| + | |||
| + | Create add view file in **/ | ||
| + | |||
| + | <code php> | ||
| + | <!-- File: / | ||
| + | <!-- In case you want to create multiple themed views, | ||
| + | apply this view for default template , you can copy it to the file : / | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <? | ||
| + | <div class=" | ||
| + | < | ||
| + | <?php | ||
| + | echo $this-> | ||
| + | __d(' | ||
| + | ' | ||
| + | ' | ||
| + | ), array(' | ||
| + | ); | ||
| + | ?> | ||
| + | </ | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <ul> | ||
| + | <li> | ||
| + | <div class=" | ||
| + | < | ||
| + | </ | ||
| + | <div class=" | ||
| + | <? | ||
| + | ' | ||
| + | ' | ||
| + | ));?> | ||
| + | </ | ||
| + | <div class=" | ||
| + | </li> | ||
| + | <li> | ||
| + | <div class=" | ||
| + | < | ||
| + | </ | ||
| + | <div class=" | ||
| + | <? | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ));?> | ||
| + | </ | ||
| + | <div class=" | ||
| + | </li> | ||
| + | <li> | ||
| + | <div class=" | ||
| + | < | ||
| + | </ | ||
| + | <div class=" | ||
| + | <? | ||
| + | ' | ||
| + | ' | ||
| + | ));?> <?php echo __d(' | ||
| + | </ | ||
| + | <div class=" | ||
| + | </li> | ||
| + | </ul> | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <? | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ));?> | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | === Editing view: === | ||
| + | |||
| + | Create edit view file in **/ | ||
| + | |||
| + | <code php> | ||
| + | <!-- File: / | ||
| + | <!-- In case you want to create multiple themed views, | ||
| + | apply this view for default template , you can copy it to the file : / | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <? | ||
| + | <? | ||
| + | <div class=" | ||
| + | < | ||
| + | <?php | ||
| + | echo $this-> | ||
| + | __d(' | ||
| + | ' | ||
| + | ' | ||
| + | ), array(' | ||
| + | ); | ||
| + | ?> | ||
| + | </ | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <ul> | ||
| + | <li> | ||
| + | <div class=" | ||
| + | < | ||
| + | </ | ||
| + | <div class=" | ||
| + | <? | ||
| + | ' | ||
| + | ' | ||
| + | ));?> | ||
| + | </ | ||
| + | <div class=" | ||
| + | </li> | ||
| + | <li> | ||
| + | <div class=" | ||
| + | < | ||
| + | </ | ||
| + | <div class=" | ||
| + | <? | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ));?> | ||
| + | </ | ||
| + | <div class=" | ||
| + | </li> | ||
| + | </ul> | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <? | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ));?> | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | To see result, go to url **[[http:// | ||
| + | |||
| + | ===== Creating a widget ===== | ||
| + | |||
| + | Widgets were originally designed to provide a simple and easy-to-use way of giving design and structure control of the mooSocial Theme to the user, which is now available on properly " | ||
| + | |||
| + | ==== Create an action ==== | ||
| + | |||
| + | Controller actions are responsible for converting the request parameters into a response for the browser/ | ||
| + | |||
| + | Update **/ | ||
| + | |||
| + | <code php> | ||
| + | <?php | ||
| + | class NotesController extends NoteAppController { | ||
| + | /** | ||
| + | * Scaffold | ||
| + | * | ||
| + | * @var mixed | ||
| + | */ | ||
| + | public $scaffold; | ||
| + | public function admin_index(){ | ||
| + | |||
| + | } | ||
| + | |||
| + | public function admin_infos(){ | ||
| + | // get plugin info | ||
| + | $xmlPath = sprintf(PLUGIN_INFO_PATH, | ||
| + | if(file_exists($xmlPath)) | ||
| + | { | ||
| + | $content = file_get_contents($xmlPath); | ||
| + | $info = new SimpleXMLElement($content); | ||
| + | $this-> | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | $this-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public function index() { | ||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | public function view($id = null) { | ||
| + | if (!$id) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | $note = $this-> | ||
| + | if (!$note) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | $this-> | ||
| + | |||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | private function likesComments($id) { | ||
| + | //comment | ||
| + | $this-> | ||
| + | $comments = $this-> | ||
| + | $comment_count = $this-> | ||
| + | $page = 1; | ||
| + | |||
| + | $data[' | ||
| + | $data[' | ||
| + | $this-> | ||
| + | $this-> | ||
| + | |||
| + | //like | ||
| + | $this-> | ||
| + | $likes = $this-> | ||
| + | $dislikes = $this-> | ||
| + | |||
| + | $this-> | ||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | public function add() { | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | return $this-> | ||
| + | } | ||
| + | $this-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public function edit($id = null) { | ||
| + | if (!$id) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | $note = $this-> | ||
| + | if (!$note) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | return $this-> | ||
| + | } | ||
| + | $this-> | ||
| + | } | ||
| + | if (!$this-> | ||
| + | $this-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public function delete($id) { | ||
| + | if (!$id) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | __(' | ||
| + | ); | ||
| + | return $this-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public function myNotes(){ | ||
| + | $notes = $this-> | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | )); | ||
| + | return $notes; | ||
| + | } | ||
| + | |||
| + | public function ajax_add(){ | ||
| + | |||
| + | if ($this-> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | if ($this-> | ||
| + | $note = $this-> | ||
| + | echo json_encode(array(' | ||
| + | exit; | ||
| + | } | ||
| + | echo json_encode(array(' | ||
| + | exit; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== Create an element ==== | ||
| + | |||
| + | <font 13.3333330154419px font-style: normal; font-variant: | ||
| + | |||
| + | Create new ctp file in **/ | ||
| + | |||
| + | > New in version 2.2.1> Your ctp file must be place at / | ||
| + | |||
| + | |||
| + | <file php myNotes.ctp> | ||
| + | <?php $notes = $this-> | ||
| + | <div class=" | ||
| + | < | ||
| + | <div class=" | ||
| + | <div id=" | ||
| + | <?php if($notes != null): ?> | ||
| + | <? | ||
| + | <?php else:?> | ||
| + | <? | ||
| + | <?php endif;?> | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | <div class=" | ||
| + | <? | ||
| + | <? | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ));?> | ||
| + | <ul class=" | ||
| + | <li> | ||
| + | < | ||
| + | <? | ||
| + | ' | ||
| + | ' | ||
| + | ));?> | ||
| + | </li> | ||
| + | <li> | ||
| + | < | ||
| + | <? | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ));?> | ||
| + | </li> | ||
| + | </ul> | ||
| + | <? | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ));?> | ||
| + | <div class=" | ||
| + | </ | ||
| + | </ | ||
| + | <?php $this-> | ||
| + | //< | ||
| + | $(document).ready(function() | ||
| + | { | ||
| + | $(window).load(function(){ | ||
| + | $("# | ||
| + | }) | ||
| + | |||
| + | $("# | ||
| + | e.preventDefault(); | ||
| + | $.post('/ | ||
| + | data = jQuery.parseJSON(data); | ||
| + | if(data.result) | ||
| + | { | ||
| + | $("# | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | $("# | ||
| + | } | ||
| + | $("# | ||
| + | }); | ||
| + | }) | ||
| + | }); | ||
| + | //]]> | ||
| + | <?php $this-> | ||
| + | </ | ||
| + | |||
| + | |||
| + | > 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: | ||
| + | <file php myNotesWidget.ctp> | ||
| + | |||
| + | <?php | ||
| + | App:: | ||
| + | class MyNotesWidget extends Widget { | ||
| + | public function beforeRender(Controller $controller) { | ||
| + | $this-> | ||
| + | $notes = $this-> | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | )); | ||
| + | $controller-> | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Create widget database ==== | ||
| + | |||
| + | * Run the following sql query | ||
| + | |||
| + | <code sql> | ||
| + | INSERT INTO {PREFIX}core_blocks(name, | ||
| + | VALUES(' | ||
| + | </ | ||
| + | |||
| + | * Go to **Home> Site Manager> Themes Manager> Layout Editor**, take a look at " | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * Note: before export your plugin, you need to implement sql query above into **YourPlugin/ | ||
| + | |||
| + | ==== How to use widget ==== | ||
| + | |||
| + | * Select page you want to show the widget. (See image) | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * Drag and drop widget into the section and click Save Changes. There are three sections in a page: left, center and right. In this example we will select a page named "Blog Browse Page". In this example we will select Blogs Browse Page (See image) | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * At frontend go to [[http:// | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ====== Backend ====== | ||
| + | |||
| + | ===== How to create plugin tabs ===== | ||
| + | |||
| + | * Update **/ | ||
| + | |||
| + | <file php NotesController.php> | ||
| + | <?php | ||
| + | class NotesController extends NoteAppController { | ||
| + | /** | ||
| + | * Scaffold | ||
| + | * | ||
| + | * @var mixed | ||
| + | */ | ||
| + | public $scaffold; | ||
| + | public function admin_index(){ | ||
| + | |||
| + | } | ||
| + | |||
| + | public function admin_infos(){ | ||
| + | // get plugin info | ||
| + | $xmlPath = sprintf(PLUGIN_INFO_PATH, | ||
| + | if(file_exists($xmlPath)) | ||
| + | { | ||
| + | $content = file_get_contents($xmlPath); | ||
| + | $info = new SimpleXMLElement($content); | ||
| + | $this-> | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | $this-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public function index() { | ||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | public function view($id = null) { | ||
| + | if (!$id) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | $note = $this-> | ||
| + | if (!$note) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | $this-> | ||
| + | |||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | private function likesComments($id) { | ||
| + | //comment | ||
| + | $this-> | ||
| + | $comments = $this-> | ||
| + | $comment_count = $this-> | ||
| + | $page = 1; | ||
| + | |||
| + | $data[' | ||
| + | $data[' | ||
| + | $this-> | ||
| + | $this-> | ||
| + | |||
| + | //like | ||
| + | $this-> | ||
| + | $likes = $this-> | ||
| + | $dislikes = $this-> | ||
| + | |||
| + | $this-> | ||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | public function add() { | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | return $this-> | ||
| + | } | ||
| + | $this-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public function edit($id = null) { | ||
| + | if (!$id) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | $note = $this-> | ||
| + | if (!$note) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | return $this-> | ||
| + | } | ||
| + | $this-> | ||
| + | } | ||
| + | if (!$this-> | ||
| + | $this-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public function delete($id) { | ||
| + | if (!$id) { | ||
| + | throw new NotFoundException(__d(' | ||
| + | } | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | __(' | ||
| + | ); | ||
| + | return $this-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public function myNotes(){ | ||
| + | $notes = $this-> | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | )); | ||
| + | return $notes; | ||
| + | } | ||
| + | |||
| + | public function ajax_add(){ | ||
| + | |||
| + | if ($this-> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | if ($this-> | ||
| + | $note = $this-> | ||
| + | echo json_encode(array(' | ||
| + | exit; | ||
| + | } | ||
| + | echo json_encode(array(' | ||
| + | exit; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | Create admin_infos.ctp in **/ | ||
| + | |||
| + | <file php admininfos.ctp> | ||
| + | <?php | ||
| + | echo $this-> | ||
| + | echo $this-> | ||
| + | $this-> | ||
| + | echo $this-> | ||
| + | $this-> | ||
| + | ?> | ||
| + | <?= $this-> | ||
| + | <?php if(isset($info) && $info != null):?> | ||
| + | <div class=" | ||
| + | <label class=" | ||
| + | <div class=" | ||
| + | <p class=" | ||
| + | <? | ||
| + | </p> | ||
| + | </ | ||
| + | </ | ||
| + | <div class=" | ||
| + | <label class=" | ||
| + | <div class=" | ||
| + | <p class=" | ||
| + | <? | ||
| + | </p> | ||
| + | </ | ||
| + | </ | ||
| + | <div class=" | ||
| + | <label class=" | ||
| + | <div class=" | ||
| + | <p class=" | ||
| + | <? | ||
| + | </p> | ||
| + | </ | ||
| + | </ | ||
| + | <div class=" | ||
| + | <label class=" | ||
| + | <div class=" | ||
| + | <p class=" | ||
| + | <? | ||
| + | </p> | ||
| + | </ | ||
| + | </ | ||
| + | <div class=" | ||
| + | <label class=" | ||
| + | <div class=" | ||
| + | <p class=" | ||
| + | <? | ||
| + | </p> | ||
| + | </ | ||
| + | </ | ||
| + | <div class=" | ||
| + | <label class=" | ||
| + | <div class=" | ||
| + | <p class=" | ||
| + | <? | ||
| + | </p> | ||
| + | </ | ||
| + | </ | ||
| + | <?php endif;?> | ||
| + | |||
| + | </ | ||
| + | |||
| + | * Update** / | ||
| + | |||
| + | <file php NotePlugin.php> | ||
| + | <?php | ||
| + | App:: | ||
| + | class NotePlugin implements MooPlugin{ | ||
| + | public function install(){} | ||
| + | public function uninstall(){} | ||
| + | public function settingGuide(){} | ||
| + | public function menu() | ||
| + | { | ||
| + | return array( | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ); | ||
| + | } | ||
| + | /* | ||
| + | Example for version 1.0: This function will be executed when plugin is upgraded (Optional) | ||
| + | public function callback_1_0(){} | ||
| + | */ | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | To see the result go to **Home> Plugins Manager> Note**, select table Infos. | ||
| + | |||
| + | ===== How to add and display plugin settings ===== | ||
| + | |||
| + | * Add the code below into **/ | ||
| + | |||
| + | <file php NoteSettingsController.php> | ||
| + | <?php | ||
| + | class NoteSettingsController extends NoteAppController{ | ||
| + | public $components = array(' | ||
| + | public function admin_index($id = null) | ||
| + | { | ||
| + | $this-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | * Update **/ | ||
| + | |||
| + | <file php NoteSettings/ | ||
| + | <?php | ||
| + | echo $this-> | ||
| + | echo $this-> | ||
| + | $this-> | ||
| + | echo $this-> | ||
| + | $this-> | ||
| + | ?> | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <? | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <? | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | * To create setting, go to **Home> System admin> System Settings**, select tab system mode. At Production Mode select Development 1 and click Save Seetings (See image) | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * Now, the Create New Setting button appears (See image) | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * Click button " | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * Go to **Home> Plugins Manager> Note**, select tab Settings. the result should like this (See image) | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ==== What is boot setting? ==== | ||
| + | |||
| + | In mooSocial, settings will be loaded 2 times: App load and plugin load. So, boot settings are loaded in the first. | ||
| + | |||
| + | Why do we distinguish it? Because each plugin can have so many settings and if we always load all settings, performance becomes slow but not really necessary. | ||
| + | |||
| + | How to create a boot setting? After we have created a setting, it was saved in ' | ||
| + | |||
| + | Which case do we need? In common, almost plugin settings needn' | ||
| + | |||
| + | > New in version 2.2** ** > In version 2.2, the " | ||
| + | |||
| + | ==== Create boot setting ==== | ||
| + | |||
| + | To create a boot setting, we have 5 steps: | ||
| + | |||
| + | - Create a setting in system settings page. | ||
| + | - Open ' | ||
| + | - Set ' | ||
| + | - Go to plugin settings page and save (because after save, ' | ||
| + | - Check ' | ||
| + | |||
| + | ===== How to add setting guide ===== | ||
| + | |||
| + | * Update **/ | ||
| + | |||
| + | <file php NotePlugin.php> | ||
| + | <?php | ||
| + | App:: | ||
| + | class NotePlugin implements MooPlugin{ | ||
| + | public function install(){} | ||
| + | public function uninstall(){} | ||
| + | public function settingGuide(){ | ||
| + | return "This is an example for settingGuide"; | ||
| + | } | ||
| + | public function menu() | ||
| + | { | ||
| + | return array( | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ); | ||
| + | } | ||
| + | /* | ||
| + | Example for version 1.0: This function will be executed when plugin is upgraded (Optional) | ||
| + | public function callback_1_0(){} | ||
| + | */ | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | * Go to **Home> Plugins Manager> Note**, select tab Settings, and see the result (See image) | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ===== Intergration ===== | ||
| + | |||
| + | ==== How to interagte plugin into search ==== | ||
| + | |||
| + | === Events system === | ||
| + | |||
| + | * There are certain cases where you need to cleanly communicate with other parts of an application, | ||
| + | * Listeners in the observer pattern can subscribe to events and choose to act upon them if they are relevant. If you have used JavaScript, there is a good chance that you are already familiar with event driven programming. | ||
| + | * MooSocial emulates several aspects of how events are triggered and managed in popular JavaScript libraries such as jQuery. In the MooSocial implementation, | ||
| + | * The event subsystem is at the heart of Model, Behavior, Controller, View and Helper callbacks. If you’ve ever used any of them, you are already somewhat familiar with events in MooSocial.. | ||
| + | |||
| + | === Create listener === | ||
| + | |||
| + | * The first important things we want to notice are table engine must be **MyISAM** | ||
| + | * Create " | ||
| + | |||
| + | <file php NoteListener.php> | ||
| + | <?php | ||
| + | App:: | ||
| + | class NoteListener implements CakeEventListener | ||
| + | { | ||
| + | public function implementedEvents() | ||
| + | { | ||
| + | return array( | ||
| + | ' | ||
| + | ' | ||
| + | ); | ||
| + | } | ||
| + | public function search($event) | ||
| + | { | ||
| + | $e = $event-> | ||
| + | App:: | ||
| + | $this-> | ||
| + | $results = $this-> | ||
| + | if(isset($e-> | ||
| + | { | ||
| + | $e-> | ||
| + | $e-> | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | $event-> | ||
| + | $event-> | ||
| + | $event-> | ||
| + | $e-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public function suggestion($event) | ||
| + | { | ||
| + | $e = $event-> | ||
| + | App:: | ||
| + | $this-> | ||
| + | //search with filter | ||
| + | if(isset($event-> | ||
| + | { | ||
| + | $notes = $this-> | ||
| + | |||
| + | $e-> | ||
| + | $e-> | ||
| + | $e-> | ||
| + | } | ||
| + | //search all | ||
| + | if(isset($event-> | ||
| + | { | ||
| + | $event-> | ||
| + | $notes = $this-> | ||
| + | if(!empty($notes)){ | ||
| + | foreach($notes as $index=>& | ||
| + | $event-> | ||
| + | if(!empty($detail[' | ||
| + | $event-> | ||
| + | $event-> | ||
| + | $event-> | ||
| + | $event-> | ||
| + | $event-> | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | **Note**: the event name must be " | ||
| + | |||
| + | * Create search view file " | ||
| + | |||
| + | <file php notes_list.ctp> | ||
| + | <ul class=" | ||
| + | <?php if($notes != null):?> | ||
| + | <?php foreach ($notes as $note):?> | ||
| + | <li class=" | ||
| + | <div> | ||
| + | <a class=" | ||
| + | <div class=" | ||
| + | <div> | ||
| + | <?php | ||
| + | echo $this-> | ||
| + | ?> | ||
| + | </ | ||
| + | </ | ||
| + | <div class=" | ||
| + | <?= __d(' | ||
| + | <?= $this-> | ||
| + | </ | ||
| + | </ | ||
| + | </li> | ||
| + | <?php endforeach;?> | ||
| + | <?php else:?> | ||
| + | <div align=" | ||
| + | <?php endif;?> | ||
| + | </ul> | ||
| + | |||
| + | </ | ||
| + | |||
| + | * Update **/ | ||
| + | |||
| + | Note.php | ||
| + | |||
| + | <code file> | ||
| + | <?php | ||
| + | App:: | ||
| + | /** | ||
| + | * Note Model | ||
| + | * | ||
| + | */ | ||
| + | class Note extends NoteAppModel { | ||
| + | public $validate = array( | ||
| + | ' | ||
| + | ' | ||
| + | ), | ||
| + | ' | ||
| + | ' | ||
| + | ) | ||
| + | ); | ||
| + | |||
| + | public $belongsTo = array( ' | ||
| + | public $mooFields = array(' | ||
| + | public function getHref($row) | ||
| + | { | ||
| + | if(isset($row[' | ||
| + | { | ||
| + | $request = Router:: | ||
| + | return $request-> | ||
| + | } | ||
| + | return ''; | ||
| + | } | ||
| + | |||
| + | public function search($keyword) | ||
| + | { | ||
| + | $cond = array( ' | ||
| + | $notes = $this-> | ||
| + | return $notes; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | * Update **/ | ||
| + | |||
| + | <file php bootstrap.php> | ||
| + | <?php | ||
| + | App:: | ||
| + | CakeEventManager:: | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== How to integrate the Note plugin in mooSocial activity feed ==== | ||
| + | |||
| + | * The Activity behavior provides a way to seamlessly integrate a model with our mooSocial Activity Feed system. | ||
| + | * To use that behavior, you can add it to the $actsAs property of your model. When adding it to the actsAs array you choose to make the related Activity entry . Update **/ | ||
| + | |||
| + | <file php / | ||
| + | <?php | ||
| + | App:: | ||
| + | /** | ||
| + | * Note Model | ||
| + | * | ||
| + | */ | ||
| + | class Note extends NoteAppModel { | ||
| + | public $validate = array( | ||
| + | ' | ||
| + | ' | ||
| + | ), | ||
| + | ' | ||
| + | ' | ||
| + | ) | ||
| + | ); | ||
| + | |||
| + | public $belongsTo = array( ' | ||
| + | public $mooFields = array(' | ||
| + | public function getHref($row) | ||
| + | { | ||
| + | if(isset($row[' | ||
| + | { | ||
| + | $request = Router:: | ||
| + | return $request-> | ||
| + | } | ||
| + | return ''; | ||
| + | } | ||
| + | |||
| + | public function search($keyword) | ||
| + | { | ||
| + | $cond = array( ' | ||
| + | $notes = $this-> | ||
| + | return $notes; | ||
| + | } | ||
| + | |||
| + | public $actsAs = array( | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ), | ||
| + | ); | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | * Create a structure below into **Note/ | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * Copy the code below into content/ | ||
| + | |||
| + | <file php content/ | ||
| + | <div class=""> | ||
| + | <!-- end blog thumbnail --> | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <a href="<? | ||
| + | < | ||
| + | </a> | ||
| + | </ | ||
| + | <? | ||
| + | </ | ||
| + | <div class=" | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | * Copy the code below into text/ | ||
| + | |||
| + | <file php text/ | ||
| + | <?php | ||
| + | echo __(' | ||
| + | |||
| + | </ | ||
| + | |||
| + | * To test activity feed go to **[[http:// | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * To see new feed go to **[[http:// | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ===== How to export plugin ===== | ||
| + | |||
| + | * Copy the sql query below into **/ | ||
| + | * | ||
| + | |||
| + | <file sql / | ||
| + | CREATE TABLE IF NOT EXISTS {PREFIX}notes ( | ||
| + | id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
| + | user_id INT(11) NOT NULL, | ||
| + | title VARCHAR(50), | ||
| + | body TEXT, | ||
| + | uri VARCHAR(150), | ||
| + | created DATETIME DEFAULT NULL, | ||
| + | modified DATETIME DEFAULT NULL, | ||
| + | like_count INT(11) DEFAULT ' | ||
| + | dislike_count INT(11) DEFAULT ' | ||
| + | comment_count INT(11) DEFAULT ' | ||
| + | FULLTEXT KEY title (title, | ||
| + | )ENGINE=MyISAM | ||
| + | |||
| + | INSERT INTO {PREFIX}notes (user_id, | ||
| + | VALUES (' | ||
| + | | ||
| + | | ||
| + | |||
| + | INSERT INTO core_blocks(name, | ||
| + | VALUES(' | ||
| + | |||
| + | </ | ||
| + | |||
| + | * Copy the sql query below into **/ | ||
| + | |||
| + | <file sql Copy SQL to / | ||
| + | DROP TABLE IF EXISTS {PREFIX}notes; | ||
| + | DELETE FROM {PREFIX}core_blocks WHERE path_view = ' | ||
| + | DELETE FROM {PREFIX}core_contents WHERE name = ' | ||
| + | DELETE FROM {PREFIX}activities WHERE action = ' | ||
| + | |||
| + | </ | ||
| + | |||
| + | * To export the plugin, go to **Home> Plugins Manager> Manage**, click download icon to export (See image) | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ===== How to uninstall plugin ===== | ||
| + | |||
| + | * To uninstall the plugin, go to **Home> Plugins Manager> Manage**, click recycle bin icon to uninstall (See image) | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * The basic uninsatllation process for mooSocial Plugin is illustrated below. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * Step 1: Validate uninstallation | ||
| + | * Check plugin exists: make sure plugin exists before uninstallation. | ||
| + | * Step 2: Install plugin | ||
| + | * | ||
| + | |||
| + | Create plugin informations: | ||
| + | |||
| + | * | ||
| + | |||
| + | Create plugin settings (Optional): Read setting informations from **YourPlugin/ | ||
| + | |||
| + | * Register plugin: register plugin into **Config/ | ||
| + | * | ||
| + | |||
| + | Install database (Optional): execute sql query in **YourPlugin/ | ||
| + | |||
| + | * | ||
| + | |||
| + | Execute install function (Optional): execute install function from** YourPlugin/ | ||
| + | |||
| + | * 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/ | ||
| + | * 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/ | ||
| + | |||
| + | ===== How to install plugin ===== | ||
| + | |||
| + | * Copy plugin source code into / | ||
| + | * Go to **Home> Plugins Manager> Manage**, select tab "not uninstalled plugins" | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * The basic installation process for mooSocial Plugin is illustrated below. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * Step 1: Validate installation | ||
| + | * Check informations from **YourPlugin/ | ||
| + | * Step 2: Install plugin | ||
| + | * | ||
| + | |||
| + | Create plugin informations: | ||
| + | |||
| + | * | ||
| + | |||
| + | Create plugin settings (Optional): Read setting informations from **YourPlugin/ | ||
| + | |||
| + | * Register plugin: register plugin into **Config/ | ||
| + | * | ||
| + | |||
| + | Install database (Optional): execute sql query in **YourPlugin/ | ||
| + | |||
| + | * | ||
| + | |||
| + | Execute install function (Optional): execute install function from** YourPlugin/ | ||
| + | |||
| + | * 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/ | ||
| + | * 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/ | ||
| + | |||
| + | ===== How to upgrade plugin ===== | ||
| + | |||
| + | ==== Create upgrade version ==== | ||
| + | |||
| + | * The first important thing to create an upgrade version for plugin is change the version number between tag < | ||
| + | |||
| + | <file xml info.xml> | ||
| + | <?xml version=" | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | * If your upgrade need to execute sql query, go to **/ | ||
| + | |||
| + | <file xml / | ||
| + | <?xml version=" | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | INSERT INTO {PREFIX}notes (user_id, | ||
| + | VALUES (' | ||
| + | </ | ||
| + | < | ||
| + | INSERT INTO {PREFIX}notes (user_id, | ||
| + | VALUES (' | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | Note: You must implement new sql query into **/ | ||
| + | |||
| + | ==== Upgrade plugin ==== | ||
| + | |||
| + | * Copy and replace current plugin source code with new source code. | ||
| + | * Click upgrade icon to upgrade (See image) | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * The basic upgrade process for mooSocial Plugin is illustrated below. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | * Step 1: Validate upgrade | ||
| + | * Check plugin exists: make sure plugin exists before uninstallation. | ||
| + | * Check new version: make sure there is new version before upgrade. | ||
| + | * Step 2: Upgrade plugin | ||
| + | * | ||
| + | |||
| + | Install database (Optional): execute sql query in **YourPlugin/ | ||
| + | |||
| + | * | ||
| + | |||
| + | Execute extended functions (Optional): base on version number, process will execute function named like callback_1_0 in **YourPlugin/ | ||
| + | |||
| + | * 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/ | ||
| + | * 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/ | ||
| + | |||
| + | ===== Internationalizing Your Plugin ===== | ||
| + | |||
| + | ===== How to create a task ===== | ||
| + | |||
| + | Insert to install.sql | ||
| + | |||
| + | <code sql> | ||
| + | INSERT INTO `{PREFIX}tasks` (`title`, `plugin`, `timeout`, `processes`, | ||
| + | (' | ||
| + | |||
| + | </ | ||
| + | |||
| + | Insert to uninstall.sql | ||
| + | |||
| + | <code sql> | ||
| + | DELETE FROM {PREFIX}tasks\\ | ||
| + | WHERE `class` = ' | ||
| + | |||
| + | </ | ||
| + | |||
| + | Create NoteTaskReminder.php in / | ||
| + | |||
| + | <code php> | ||
| + | <?php | ||
| + | App:: | ||
| + | class NoteTaskReminder extends CronTaskAbstract | ||
| + | { | ||
| + | public function execute() | ||
| + | { | ||
| + | $noteModel = MooCore:: | ||
| + | $notes = $noteModel-> | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ))); | ||
| + | |||
| + | if (count($notes)) | ||
| + | { | ||
| + | $mailComponent = MooCore:: | ||
| + | $ssl_mode = Configure:: | ||
| + | $http = (!empty($ssl_mode)) ? ' | ||
| + | foreach ($notes as $note) | ||
| + | { | ||
| + | $mailComponent-> | ||
| + | array( | ||
| + | ' | ||
| + | ' | ||
| + | ) | ||
| + | ); | ||
| + | |||
| + | $noteModel-> | ||
| + | $noteModel-> | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | * You can manage task on Admin ACP **Home> System Admin> Tasks** | ||
| + | |||
| + | ===== How to using mailsystem ===== | ||
| + | |||
| + | Insert to NotePlugin.php on function install and uninstall | ||
| + | |||
| + | <code php> | ||
| + | public function install(){ | ||
| + | $mailModel = MooCore:: | ||
| + | $languageModel = MooCore:: | ||
| + | $langs = $languageModel-> | ||
| + | $data[' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ); | ||
| + | $mailModel-> | ||
| + | $id = $mailModel-> | ||
| + | foreach ($langs as $lang) | ||
| + | { | ||
| + | $language = $lang[' | ||
| + | $mailModel-> | ||
| + | $data_translate[' | ||
| + | $content = <<< | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | EOF; | ||
| + | $data_translate[' | ||
| + | $mailModel-> | ||
| + | } | ||
| + | } | ||
| + | public function uninstall(){ | ||
| + | $mailModel = MooCore:: | ||
| + | $mailModel-> | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | How to using it $mailComponent→send($mix, | ||
| + | |||
| + | <code php> | ||
| + | $noteModel = MooCore:: | ||
| + | $notes = $noteModel-> | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ))); | ||
| + | |||
| + | if (count($notes)) | ||
| + | { | ||
| + | $mailComponent = MooCore:: | ||
| + | $ssl_mode = Configure:: | ||
| + | $http = (!empty($ssl_mode)) ? ' | ||
| + | foreach ($notes as $note) | ||
| + | { | ||
| + | $mailComponent-> | ||
| + | array( | ||
| + | ' | ||
| + | ' | ||
| + | ) | ||
| + | ); | ||
| + | |||
| + | $noteModel-> | ||
| + | $noteModel-> | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== How to using tag system ===== | ||
| + | |||
| + | When create a note: | ||
| + | |||
| + | <file php NotesController.php> | ||
| + | if ($this-> | ||
| + | //Tag system | ||
| + | $this-> | ||
| + | $this-> | ||
| + | // | ||
| + | |||
| + | $this-> | ||
| + | return $this-> | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | <file php add.ctp> | ||
| + | //Tag system | ||
| + | <div class=" | ||
| + | < | ||
| + | </ | ||
| + | <div class=" | ||
| + | <?php echo $this-> | ||
| + | </ | ||
| + | <div class=" | ||
| + | </li> | ||
| + | // | ||
| + | |||
| + | </ | ||
| + | |||
| + | When edit a note: NotesController.php | ||
| + | |||
| + | <code php> | ||
| + | if ($this-> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | if ($this-> | ||
| + | //Tag system | ||
| + | $this-> | ||
| + | // | ||
| + | |||
| + | $this-> | ||
| + | return $this-> | ||
| + | } | ||
| + | $this-> | ||
| + | } | ||
| + | //Tag system | ||
| + | $tags = $this-> | ||
| + | $this-> | ||
| + | // | ||
| + | |||
| + | </ | ||
| + | |||
| + | <file php edit.ctp> | ||
| + | //Tag system | ||
| + | <li> | ||
| + | <div class=" | ||
| + | < | ||
| + | </ | ||
| + | <?php | ||
| + | $tags_value = ''; | ||
| + | if (!empty($tags)) $tags_value = implode(', | ||
| + | ?> | ||
| + | <div class=" | ||
| + | <?php echo $this-> | ||
| + | </ | ||
| + | <div class=" | ||
| + | </li> | ||
| + | // | ||
| + | |||
| + | </ | ||
| + | |||
| + | Helper hook | ||
| + | |||
| + | <file php NoteHelper.php> | ||
| + | //Tag system | ||
| + | public function getTagUnionsNote($noteids) | ||
| + | { | ||
| + | return " | ||
| + | FROM " . Configure:: | ||
| + | WHERE i.id IN (" . implode(',', | ||
| + | } | ||
| + | public function getImage($item, | ||
| + | { | ||
| + | return $this-> | ||
| + | |||
| + | return $url; | ||
| + | } | ||
| + | // | ||
| + | |||
| + | </ | ||
| + | |||
| + | When view note | ||
| + | |||
| + | <file php NotesController.php> | ||
| + | //Tag system | ||
| + | $this-> | ||
| + | $tags = $this-> | ||
| + | $this-> | ||
| + | // | ||
| + | |||
| + | </ | ||
| + | |||
| + | <file php view.ctp> | ||
| + | //Tag system | ||
| + | <div class=" | ||
| + | <?php echo $this-> | ||
| + | </ | ||
| + | // | ||
| + | |||
| + | </ | ||
| + | |||
| + | ===== How to using like system ===== | ||
| + | |||
| + | View note | ||
| + | |||
| + | <file php NotesController.php> | ||
| + | //Like system | ||
| + | MooCore:: | ||
| + | // | ||
| + | |||
| + | </ | ||
| + | |||
| + | <file php view.ctp> | ||
| + | //Like system | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <?php echo $this-> | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | // | ||
| + | |||
| + | </ | ||
| + | |||
| + | ===== How to using comment system ===== | ||
| + | |||
| + | View note | ||
| + | |||
| + | <file php notescontroller.php> | ||
| + | //Comment system | ||
| + | MooCore:: | ||
| + | // | ||
| + | |||
| + | </ | ||
| + | |||
| + | <file php view.ctp> | ||
| + | //Comment system | ||
| + | <div class=" | ||
| + | <div class=" | ||
| + | <?php echo $this-> | ||
| + | </ | ||
| + | </ | ||
| + | // | ||
| + | |||
| + | </ | ||
| + | |||
| + | <file php NoteHelper.php> | ||
| + | //Comment system | ||
| + | public function checkPostStatus($note, | ||
| + | { | ||
| + | if (!$uid) | ||
| + | return false; | ||
| + | |||
| + | $friendModel = MooCore:: | ||
| + | if ($uid == $note[' | ||
| + | return true; | ||
| + | |||
| + | if ($note[' | ||
| + | { | ||
| + | return true; | ||
| + | } | ||
| + | |||
| + | if ($note[' | ||
| + | { | ||
| + | $areFriends = $friendModel-> | ||
| + | if ($areFriends) | ||
| + | return true; | ||
| + | } | ||
| + | |||
| + | return false; | ||
| + | } | ||
| + | public function checkSeeActivity($note, | ||
| + | { | ||
| + | return $this-> | ||
| + | } | ||
| + | // | ||
| + | |||
| + | </ | ||
| + | |||
| + | ===== How to using report system ===== | ||
| + | |||
| + | View note: | ||
| + | |||
| + | <file php view.tcp> | ||
| + | //Report system | ||
| + | <? | ||
| + | __d(' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | $note[' | ||
| + | $note[' | ||
| + | ), array(' | ||
| + | ); | ||
| + | // | ||
| + | |||
| + | </ | ||
| + | |||
| + | ====== 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, | ||
| + | |||
| + | ====== Themed Plugin ====== | ||
| + | |||
| + | path **app/ | ||
| + | |||
| + | {{: | ||
