| @@ -29,8 +29,10 @@ | ||
| 29 | 29 | // Initialize parent! |
| 30 | 30 | parent::__construct($hasView, $request); |
| 31 | 31 | // Register actions! |
| 32 | 32 | $this->registryAction('getBlocksList'); |
| 33 | + $this->registryAction('getShortcode'); | |
| 34 | + $this->registryAction('getBlockParametersForm'); | |
| 33 | 35 | // @TODO: $this->defaultCapability is risky if there is any admin actions added later, please remove! |
| 34 | 36 | $this->defaultCapability = array('edit_posts', 'edit_pages'); |
| 35 | 37 | } |
| 36 | 38 | |
| @@ -37,9 +39,45 @@ | ||
| 37 | 39 | /** |
| 38 | 40 | * put your comment there... |
| 39 | 41 | * |
| 40 | 42 | */ |
| 41 | - public function getBlocksListAction() { | |
| 43 | + protected function getBlockParametersFormAction() { | |
| 44 | + // Get block id. | |
| 45 | + $blockId = (int) $_REQUEST['blockId']; | |
| 46 | + // Get block form! | |
| 47 | + $form = CJTxTable::getInstance('form') | |
| 48 | + ->setTableKey(array('blockId')) | |
| 49 | + ->setData(array('blockId' => $blockId)) | |
| 50 | + ->load(); | |
| 51 | + // Set HTTP header | |
| 52 | + $this->httpContentType = 'text/html'; | |
| 53 | + // Display form view. | |
| 54 | + if ($form->get('blockId')) { | |
| 55 | + // Load parameters form. | |
| 56 | + $groups = new CJT_Models_Block_Parameters_Form_Groups($blockId); | |
| 57 | + $params = new CJT_Models_Block_Parameters_Form_Parameters($blockId); | |
| 58 | + $blockParams = new CJT_Framework_View_Block_Parameter_Parameters($params); | |
| 59 | + // Return view content! | |
| 60 | + $paramsView = CJTView::getInstance('tinymce/params', array( | |
| 61 | + 'groups' => $groups, | |
| 62 | + 'params' => $blockParams->getParams(), | |
| 63 | + 'form' => $form->getData(), | |
| 64 | + 'blockId' => $blockId | |
| 65 | + ) | |
| 66 | + ); | |
| 67 | + // Return paramters form content! | |
| 68 | + $this->response = $paramsView->getTemplate('default'); | |
| 69 | + } | |
| 70 | + else { // Error loading form! | |
| 71 | + $this->response = cssJSToolbox::getText('The requested Block doesnt has parameters form!'); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * put your comment there... | |
| 77 | + * | |
| 78 | + */ | |
| 79 | + protected function getBlocksListAction() { | |
| 42 | 80 | // Read all blocks! |
| 43 | 81 | $blocks = $this->model->getItems(); |
| 44 | 82 | // retreive owener name! |
| 45 | 83 | foreach ($blocks as $id => $block) { |
| @@ -49,5 +87,58 @@ | ||
| 49 | 87 | } |
| 50 | 88 | $this->response['count'] = count($this->response['list']); |
| 51 | 89 | } |
| 52 | 90 | |
| 91 | + /** | |
| 92 | + * put your comment there... | |
| 93 | + * | |
| 94 | + */ | |
| 95 | + protected function getShortcodeAction() { | |
| 96 | + // Get block id. | |
| 97 | + $blockId = $_REQUEST['blockId']; | |
| 98 | + // Load block | |
| 99 | + $block = CJTxTable::getInstance('block') | |
| 100 | + ->setTableKey(array('id')) | |
| 101 | + ->setData(array('id' => $blockId)) | |
| 102 | + ->load() | |
| 103 | + ->getData(); | |
| 104 | + $blockForm = (array) CJTxTable::getInstance('form') | |
| 105 | + ->setTableKey(array('blockId')) | |
| 106 | + ->setData(array('blockId' => $blockId)) | |
| 107 | + ->load() | |
| 108 | + ->getData(); | |
| 109 | + // Load block parameters. | |
| 110 | + $parameters = new CJT_Models_Block_Parameters_Parameters($blockId); | |
| 111 | + $blockParams = new CJT_Framework_Developer_Interface_Block_Shortcode_Parameters_Parameters($parameters); | |
| 112 | + // The the block has FORM associated | |
| 113 | + if (isset($blockForm['blockId'])) { | |
| 114 | + // If the data is submitted then load the parameters object with the post data! | |
| 115 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { | |
| 116 | + // Get RAW data from the data submitted (avoid magic_quotes, Why called MAGIC!!!!)! | |
| 117 | + $rawPostData = filter_input(INPUT_POST, 'form-data', FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY); | |
| 118 | + // Fill the form by the posted data | |
| 119 | + $blockParams->setValue($rawPostData); | |
| 120 | + // Validate the submitted data against their parameters. | |
| 121 | + if ($blockParams->validate()) { | |
| 122 | + // Generate and Return Shortcode string! | |
| 123 | + $this->response['state'] = 'shortcode-notation'; | |
| 124 | + $this->response['content'] = $blockParams->shortcode($block->name); | |
| 125 | + } | |
| 126 | + else { | |
| 127 | + $this->response['state'] = 'invalid'; | |
| 128 | + $this->response['content'] = $blockParams->getMessages(); | |
| 129 | + } | |
| 130 | + } | |
| 131 | + // Redirect to the parameters form view! | |
| 132 | + else { | |
| 133 | + $this->response['state'] = 'show-form'; | |
| 134 | + } | |
| 135 | + } | |
| 136 | + else { | |
| 137 | + // If block doesn't has a parameters defined return | |
| 138 | + // the Shortcode code string from the parameters loader. | |
| 139 | + $this->response['state'] = 'shortcode-notation'; | |
| 140 | + $this->response['content'] = $blockParams->shortcode($block->name); | |
| 141 | + } | |
| 142 | + } | |
| 143 | + | |
| 53 | 144 | } // End class. |