| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage core |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2019 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
JLoader::import('adapter.mvc.controllers.admin'); |
| 15 |
|
| 16 |
/** |
| 17 |
* VikBooking plugin Shortcode controller. |
| 18 |
* |
| 19 |
* @since 1.0 |
| 20 |
* @see JControllerAdmin |
| 21 |
*/ |
| 22 |
class VikBookingControllerShortcode extends JControllerAdmin |
| 23 |
{ |
| 24 |
public function savenew() |
| 25 |
{ |
| 26 |
$this->save(2); |
| 27 |
} |
| 28 |
|
| 29 |
public function saveclose() |
| 30 |
{ |
| 31 |
$this->save(1); |
| 32 |
} |
| 33 |
|
| 34 |
public function save($close = 0) |
| 35 |
{ |
| 36 |
$app = JFactory::getApplication(); |
| 37 |
$input = $app->input; |
| 38 |
$dbo = JFactory::getDbo(); |
| 39 |
|
| 40 |
// get return URL |
| 41 |
$encoded = $input->getBase64('return', ''); |
| 42 |
|
| 43 |
// make sure the user is authorised to change shortcodes |
| 44 |
if (!JFactory::getUser()->authorise('core.admin', 'com_vikbooking')) |
| 45 |
{ |
| 46 |
$app->redirect($return); |
| 47 |
} |
| 48 |
|
| 49 |
// get item from request |
| 50 |
$data = $this->model->getFormData(); |
| 51 |
|
| 52 |
// dispatch model to save the item |
| 53 |
$id = $this->model->save($data); |
| 54 |
|
| 55 |
if ($close == 2) |
| 56 |
{ |
| 57 |
// save and new |
| 58 |
$return = 'admin.php?option=com_vikbooking&task=shortcodes.create&return=' . $encoded; |
| 59 |
} |
| 60 |
else if ($close == 1) |
| 61 |
{ |
| 62 |
// save and close |
| 63 |
$return = 'admin.php?option=com_vikbooking&view=shortcodes&return=' . $encoded; |
| 64 |
} |
| 65 |
else |
| 66 |
{ |
| 67 |
// save and stay in edit page |
| 68 |
$return = 'admin.php?option=com_vikbooking&task=shortcodes.edit&cid[]=' . $id . '&return=' . $encoded; |
| 69 |
} |
| 70 |
|
| 71 |
$app->redirect($return); |
| 72 |
} |
| 73 |
|
| 74 |
public function params() |
| 75 |
{ |
| 76 |
$input = JFactory::getApplication()->input; |
| 77 |
|
| 78 |
$id = $input->getInt('id', 0); |
| 79 |
$type = $input->getString('type', ''); |
| 80 |
|
| 81 |
// dispatch model to get the item (an empty ITEM if not exists) |
| 82 |
$item = $this->model->getItem($id); |
| 83 |
|
| 84 |
// inject the type to load the right form |
| 85 |
$item->type = $type; |
| 86 |
|
| 87 |
// obtain the type form |
| 88 |
$form = $this->model->getTypeForm($item); |
| 89 |
|
| 90 |
// if the form doesn't exist, the type is probably empty |
| 91 |
if (!$form) |
| 92 |
{ |
| 93 |
// return an empty HTML |
| 94 |
echo ""; |
| 95 |
} |
| 96 |
// render the form and encode the response |
| 97 |
else |
| 98 |
{ |
| 99 |
$args = json_decode($item->json); |
| 100 |
echo json_encode($form->renderForm($args)); |
| 101 |
} |
| 102 |
|
| 103 |
exit; |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* This task will create a page on WordPress with the requested Shortcode inside it. |
| 108 |
* This is useful to automatically link Shortcodes in pages with no manual actions. |
| 109 |
* |
| 110 |
* @since 1.3.6 |
| 111 |
*/ |
| 112 |
public function add_to_page() |
| 113 |
{ |
| 114 |
$app = JFactory::getApplication(); |
| 115 |
$input = $app->input; |
| 116 |
$dbo = JFactory::getDbo(); |
| 117 |
|
| 118 |
// get return URL |
| 119 |
$encoded = $input->getBase64('return', ''); |
| 120 |
|
| 121 |
// always redirect to the shortcodes list |
| 122 |
$this->setRedirect('admin.php?option=com_vikbooking&view=shortcodes&return=' . $encoded); |
| 123 |
|
| 124 |
// make sure the user is authorised to change shortcodes |
| 125 |
if (!JFactory::getUser()->authorise('core.admin', 'com_vikbooking')) |
| 126 |
{ |
| 127 |
return; |
| 128 |
} |
| 129 |
|
| 130 |
// get selected shortcodes |
| 131 |
$cid = $input->getUint('cid', array()); |
| 132 |
|
| 133 |
// attempt to assign the shortcodes to a page |
| 134 |
if ($this->model->addPage($cid)) |
| 135 |
{ |
| 136 |
// add success message and redirect |
| 137 |
$app->enqueueMessage(JText::translate('VBO_SC_ADDTOPAGE_OK')); |
| 138 |
} |
| 139 |
|
| 140 |
// fetch all registered errors (if any) |
| 141 |
$errors = $this->model->getErrors(); |
| 142 |
|
| 143 |
foreach ($errors as $error) |
| 144 |
{ |
| 145 |
if ($error instanceof Exception) |
| 146 |
{ |
| 147 |
$error = $error->getMessage(); |
| 148 |
} |
| 149 |
|
| 150 |
// enqueue error message |
| 151 |
$app->enqueueMessage($error, 'error'); |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
|