/** * Add funders to Acy Mailing list. * * @throws Exception */ public function addFunders() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); /** @var $app JApplicationAdministrator */ $response = new Prism\Response\Json(); $projectId = $this->input->post->getInt('acy_pid'); $listId = $this->input->post->getInt('acy_lid'); $model = $this->getModel(); $numberOfAdded = 0; try { $numberOfAdded = $model->addFundersToAcyList($projectId, $listId); } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure(); echo $response; $app->close(); } if (!$numberOfAdded) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_CANNOT_BE_ADDED_SUBSCRIBERS'))->failure(); } else { $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::sprintf('COM_CROWDFUNDING_ADDED_SUBSCRIBERS_D', $numberOfAdded))->success(); } echo $response; $app->close(); }
/** * Save an item */ public function save($key = null, $urlVar = null) { $response = new Prism\Response\Json(); $userId = JFactory::getUser()->get("id"); if (!$userId) { // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDINGFINANCE_FAIL"))->setText(JText::_("COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM"))->failure(); echo $response; JFactory::getApplication()->close(); } // Get project ID. $projectId = $this->input->post->get('project_id'); // Validate project owner $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $projectId, $userId); if (!$validator->isValid()) { // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDINGFINANCE_FAIL"))->setText(JText::_("COM_CROWDFUNDINGFINANCE_INVALID_PROJECT"))->failure(); echo $response; JFactory::getApplication()->close(); } $data = array("id" => $projectId, "paypal_email" => $this->input->post->get('paypal_email', null, "string"), "paypal_first_name" => $this->input->post->get('paypal_first_name'), "paypal_last_name" => $this->input->post->get('paypal_last_name'), "iban" => $this->input->post->get('iban'), "bank_account" => $this->input->post->get('bank_account', null, "string")); $model = $this->getModel(); /** @var $model CrowdfundingFinanceModelPayout */ try { $model->save($data); } catch (Exception $e) { $response->setTitle(JText::_("COM_CROWDFUNDINGFINANCE_FAIL"))->setText(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM'))->failure(); echo $response; JFactory::getApplication()->close(); } $response->setTitle(JText::_("COM_CROWDFUNDINGFINANCE_SUCCESS"))->setText(JText::_("COM_CROWDFUNDINGFINANCE_PAYOUT_DATA_SAVED_SUCCESSFULLY"))->success(); echo $response; JFactory::getApplication()->close(); }
/** * Remove a log file. */ public function remove() { // Create response object $response = new Prism\Response\Json(); $file = $this->input->post->get('file', null, "raw"); if (!$file) { JFactory::getApplication()->close(404); } $model = $this->getModel(); /** @var $model CrowdfundingModelLog */ jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.path'); try { // Clean and prepare the file. $fileSource = $model->prepareFile(JPath::clean($file)); if (!$model->deleteFile($fileSource)) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_LOG_FILE_CANNOT_BE_REMOVED'))->failure(); echo $response; JFactory::getApplication()->close(); } } catch (Exception $e) { JLog::add($e->getMessage()); $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure(); echo $response; JFactory::getApplication()->close(); } $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_LOG_FILE_REMOVED'))->success(); echo $response; JFactory::getApplication()->close(); }
/** * This method removes a notification. */ public function remove() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $itemId = $this->input->getUint('id'); $userId = JFactory::getUser()->get('id'); $response = new Prism\Response\Json(); $validatorOwner = new Socialcommunity\Validator\Notification\Owner(JFactory::getDbo(), $itemId, $userId); if (!$validatorOwner->isValid()) { $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_FAILURE'))->setText(JText::_('COM_SOCIALCOMMUNITY_ERROR_INVALID_NOTIFICATION'))->failure(); echo $response; $app->close(); } try { $notification = new Socialcommunity\Notification\Notification(JFactory::getDbo()); $notification->load($itemId); $notification->remove(); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_SOCIALCOMMUNITY_ERROR_SYSTEM')); } $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_SUCCESS'))->setText(JText::_('COM_SOCIALCOMMUNITY_NOTIFICATION_REMOVED_SUCCESSFULLY'))->success(); echo $response; $app->close(); }
public function saveAjax() { // Get the data from the form $itemId = $this->input->post->get('pk', 0, 'uint'); $content = $this->input->post->get('value', "", "raw"); // Decode the content if there are encoded symbols. $content = html_entity_decode($content, ENT_QUOTES, "UTF-8"); // Encode the content. $content = htmlentities($content, ENT_QUOTES, "UTF-8"); // Fix Magic Quotes if (get_magic_quotes_gpc()) { $content = stripslashes($content); } $response = new Prism\Response\Json(); $model = $this->getModel(); if (!$itemId or !$content) { $response->setTitle(JText::_('COM_ITPMETA_FAIL'))->setText(JText::_('COM_ITPMETA_ERROR_SYSTEM'))->failure(); echo $response; JFactory::getApplication()->close(); } // Save the item try { $data = $model->saveAjax($itemId, $content); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_ITPMETA_ERROR_SYSTEM')); } $response->setTitle(JText::_('COM_ITPMETA_SUCCESS'))->setText(JText::_('COM_ITPMETA_TAG_SAVED'))->setData($data)->success(); echo $response; JFactory::getApplication()->close(); }
public function getProjectFunds() { // Create response object $response = new Prism\Response\Json(); $app = JFactory::getApplication(); /** @var $app JApplicationAdministrator */ $itemId = $app->input->getInt('id'); // Check for errors. if (!$itemId) { $response->setTitle(JText::_('COM_CROWDFUNDINGFINANCE_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_INVALID_PROJECT'))->failure(); echo $response; JFactory::getApplication()->close(); } try { // Get statistics $project = new Crowdfunding\Statistics\Project(JFactory::getDbo(), $itemId); $data = $project->getFundedAmount(); } catch (Exception $e) { JLog::add($e->getMessage()); $response->setTitle(JText::_('COM_CROWDFUNDINGFINANCE_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM'))->failure(); echo $response; JFactory::getApplication()->close(); throw new Exception(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM')); } $response->setData($data)->success(); echo $response; JFactory::getApplication()->close(); }
/** * Method to load data via AJAX */ public function getNumber() { $response = new Prism\Response\Json(); try { $notifications = new Gamification\Notification\Notifications(JFactory::getDbo()); $options = array('user_id' => JFactory::getUser()->get('id'), 'status' => Prism\Constants::NOT_READ); $notRead = $notifications->getNumber($options); } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_gamification'); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } $data = array('results' => $notRead); $response->setData($data)->success(); echo $response; JFactory::getApplication()->close(); }
/** * Method to load data via AJAX */ public function getNumber() { $response = new Prism\Response\Json(); try { $notifications = new SocialCommunity\Notifications(JFactory::getDbo()); $options = array("user_id" => JFactory::getUser()->get("id"), "status" => Prism\Constants::NOT_READ); $notRead = $notifications->getNumber($options); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } $data = array("results" => $notRead); $response->setData($data)->success(); echo $response; JFactory::getApplication()->close(); }
/** * Method to remove records via AJAX. * * @throws Exception * @return void */ public function remove() { // Get the input $app = JFactory::getApplication(); $itemId = $app->input->post->get('id', 0, 'int'); $userId = JFactory::getUser()->get('id'); $response = new Prism\Response\Json(); // Get the model $model = $this->getModel(); /** @var $model CrowdfundingModelCommentItem */ try { $item = $model->getItem($itemId); if ($item !== null and (int) $item->user_id !== (int) $userId) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_COMMENT_CANNOT_REMOVED'))->failure(); echo $response; $app->close(); } $model->remove($itemId, $userId); } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure(); echo $response; $app->close(); } $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_COMMENT_REMOVED_SUCCESSFULLY'))->success(); echo $response; $app->close(); }
/** * Method to remove records via AJAX. * * @throws Exception * @return void */ public function remove() { // Get the input $app = JFactory::getApplication(); /** $app JApplicationSite */ // Create response object. $response = new Prism\Response\Json(); $itemId = $app->input->post->get('id', 0, 'int'); $userId = JFactory::getUser()->get("id"); // Get the model $model = $this->getModel(); /** @var $model CrowdfundingModelUpdateItem */ try { $item = $model->getItem($itemId); if ($item->user_id != $userId) { $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_RECORD_CANNOT_REMOVED"))->failure(); echo $response; JFactory::getApplication()->close(); } $model->remove($itemId, $userId); } catch (Exception $e) { JLog::add($e->getMessage()); $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM_CANNOT_REMOVED"))->failure(); echo $response; JFactory::getApplication()->close(); } $response->setTitle(JText::_("COM_CROWDFUNDING_SUCCESS"))->setText(JText::_("COM_CROWDFUNDING_RECORD_REMOVED_SUCCESSFULLY"))->success(); echo $response; JFactory::getApplication()->close(); }
/** * Method to save the submitted ordering values for records via AJAX. * * @throws Exception * @return void */ public function loadLocation() { // Get the input $query = $this->input->get->getString('query'); $response = new Prism\Response\Json(); try { $locations = new Crowdfunding\Locations(JFactory::getDbo()); $locations->loadByString($query); $locationData = $locations->toOptions('id', 'name'); } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } $response->setData($locationData)->success(); echo $response; JFactory::getApplication()->close(); }
/** * Method to save the submitted ordering values for records via AJAX. * * @throws Exception * * @return void * * @since 3.0 */ public function loadLocation() { // Get the input $query = $this->input->get->get('query', "", 'string'); $response = new Prism\Response\Json(); try { $locations = new SocialCommunity\Locations(JFactory::getDbo()); $locations->load(array("search" => $query)); $locationData = $locations->toOptions(); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_SOCIALCOMMUNITY_ERROR_SYSTEM')); } $response->setData($locationData)->success(); echo $response; JFactory::getApplication()->close(); }
/** * Method to save the submitted ordering values for records via AJAX. * * @throws Exception * @return void * @since 3.0 */ public function changeRewardsState() { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $id = $this->input->post->getUint('id'); $state = $this->input->post->getUint('state'); $response = new Prism\Response\Json(); // Get the model $model = $this->getModel(); try { $model->changeRewardsState($id, $state); } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } $response->success()->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_REWARD_STATE_CHANGED_SUCCESSFULLY')); echo $response; JFactory::getApplication()->close(); }
/** * Method to save the submitted ordering values for records via AJAX. * * @throws Exception * * @return void * * @since 3.0 */ public function loadLocation() { // Get the input $query = $this->input->get->getCmd('query'); $countryId = $this->input->get->getInt('country_id'); $response = new Prism\Response\Json(); try { $locations = new Socialcommunity\Location\Locations(JFactory::getDbo()); $locations->load(array('search' => $query, 'country_id' => $countryId)); $locationData = $locations->toOptions('id', 'name', 'country_code'); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_SOCIALCOMMUNITY_ERROR_SYSTEM')); } $response->setData($locationData)->success(); echo $response; JFactory::getApplication()->close(); }
/** * Method to save the submitted ordering values for records via AJAX. * * @return void * @throws Exception * * @since 3.0 */ public function saveOrderAjax() { $response = new Prism\Response\Json(); // Get the input $pks = $this->input->post->get('cid', array(), 'array'); $order = $this->input->post->get('order', array(), 'array'); // Sanitize the input $pks = Joomla\Utilities\ArrayHelper::toInteger($pks); $order = Joomla\Utilities\ArrayHelper::toInteger($order); // Get the model $model = $this->getModel(); try { $model->saveorder($pks, $order); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_USERIDEAS_ERROR_SYSTEM')); } $response->setTitle(JText::_('COM_USERIDEAS_SUCCESS'))->setText(JText::_('JLIB_APPLICATION_SUCCESS_ORDERING_SAVED'))->success(); echo $response; JFactory::getApplication()->close(); }
public function batch() { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $response = new Prism\Response\Json(); // Get the input $itemsIds = $this->input->post->getString('ids'); $itemsIds = explode(',', $itemsIds); $itemsIds = Joomla\Utilities\ArrayHelper::toInteger($itemsIds); $action = $this->input->post->get('action'); // Get the model $model = $this->getModel(); /** @var $model EmailTemplatesModelPlaceholder */ // Check for selected packages. if (!$itemsIds) { $response->setTitle(JText::_('COM_EMAILTEMPLATES_FAIL'))->setText(JText::_('COM_EMAILTEMPLATES_PLACEHOLDERS_NOT_SELECTED'))->failure(); echo $response; JFactory::getApplication()->close(); } try { switch ($action) { case 'copy': $categoryId = $this->input->post->get('catid'); // Check for valid category. if (!$categoryId) { $response->setTitle(JText::_('COM_EMAILTEMPLATES_FAIL'))->setText(JText::_('COM_EMAILTEMPLATES_CATEGORY_NOT_SELECTED'))->failure(); echo $response; JFactory::getApplication()->close(); } $model->copyPlaceholders($itemsIds, $categoryId); $response->setTitle(JText::_('COM_EMAILTEMPLATES_SUCCESS'))->setText(JText::_('COM_EMAILTEMPLATES_PLACEHOLDERS_COPIED_SUCCESSFULLY'))->success(); break; } } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_EMAILTEMPLATES_ERROR_SYSTEM')); } echo $response; JFactory::getApplication()->close(); }
public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $response = new Prism\Response\Json(); $userId = JFactory::getUser()->get('id'); if (!$userId) { // Send response to the browser $response->setTitle(JText::_('COM_CROWDFUNDINGFINANCE_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM'))->failure(); echo $response; $app->close(); } // Get project ID. $projectId = $this->input->post->get('project_id'); // Validate project owner $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $projectId, $userId); if (!$validator->isValid()) { // Send response to the browser $response->setTitle(JText::_('COM_CROWDFUNDINGFINANCE_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_INVALID_PROJECT'))->failure(); echo $response; $app->close(); } $data = array('id' => $projectId, 'paypal_email' => $this->input->post->get('paypal_email', null, 'string'), 'paypal_first_name' => $this->input->post->get('paypal_first_name'), 'paypal_last_name' => $this->input->post->get('paypal_last_name'), 'iban' => $this->input->post->get('iban'), 'bank_account' => $this->input->post->get('bank_account', null, 'string')); $model = $this->getModel(); /** @var $model CrowdfundingFinanceModelPayout */ try { $model->save($data); } catch (Exception $e) { $response->setTitle(JText::_('COM_CROWDFUNDINGFINANCE_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM'))->failure(); echo $response; $app->close(); } $response->setTitle(JText::_('COM_CROWDFUNDINGFINANCE_SUCCESS'))->setText(JText::_('COM_CROWDFUNDINGFINANCE_PAYOUT_DATA_SAVED_SUCCESSFULLY'))->success(); echo $response; $app->close(); }
/** * This method remove a notification. */ public function remove() { $itemId = $this->input->getUint("id"); $userId = JFactory::getUser()->get("id"); $response = new Prism\Response\Json(); $validatorOwner = new Gamification\Validator\Notification\Owner(JFactory::getDbo(), $itemId, $userId); if (!$validatorOwner->isValid()) { $response->setTitle(JText::_('COM_GAMIFICATION_FAIL'))->setText(JText::_('COM_GAMIFICATION_INVALID_NOTIFICATION'))->failure(); echo $response; JFactory::getApplication()->close(); } try { $notification = new Gamification\Notification\Notification(JFactory::getDbo()); $notification->load($itemId); $notification->remove(); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_GAMIFICATION_ERROR_SYSTEM')); } $response->setTitle(JText::_('COM_GAMIFICATION_SUCCESS'))->setText(JText::_('COM_GAMIFICATION_NOTIFICATION_REMOVED_SUCCESSFULLY'))->success(); echo $response; JFactory::getApplication()->close(); }
/** * Catch a request from payment plugin via AJAX and process a transaction. */ public function notifyAjax() { $response = new Prism\Response\Json(); // Check for disabled payment functionality if ($this->params->get('debug_payment_disabled', 0)) { $errorData = JText::sprintf('COM_CROWDFUNDING_TRANSACTION_DATA', var_export($_REQUEST, true)); $this->log->add(JText::_('COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED'), 'ERROR_CONTROLLER_NOTIFIER_AJAX', $errorData); // Send response to the browser $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE'))->failure(); echo $response; $this->app->close(); } // Get model object. $model = $this->getModel(); $paymentResult = null; $redirectUrl = null; $message = null; $project = null; /** @var Crowdfunding\Project $project */ // Trigger the event try { // Import Crowdfunding Payment Plugins JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onPaymentNotify event. $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger('onPaymentNotify', array($this->context, &$this->params)); if (is_array($results) and count($results) > 0) { foreach ($results as $result) { if (is_object($result) and isset($result->transaction)) { $paymentResult = $result; $project = isset($result->project) ? $result->project : null; $redirectUrl = isset($result->redirectUrl) ? $result->redirectUrl : null; $message = isset($result->message) ? $result->message : null; break; } } } // If there is no transaction data, the status might be pending or another one. // So, we have to stop the script execution. if (!$paymentResult) { // Send response to the browser $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_TRANSACTION_NOT_PROCESSED_SUCCESSFULLY'))->failure(); echo $response; $this->app->close(); } // Trigger the event onAfterPaymentNotify $dispatcher->trigger('onAfterPaymentNotify', array($this->context, &$paymentResult, &$this->params)); // Trigger the event onAfterPayment $dispatcher->trigger('onAfterPayment', array($this->context, &$paymentResult, &$this->params)); } catch (Exception $e) { // Store log data to the database. $error = 'AJAX NOTIFIER ERROR: ' . $e->getMessage() . "\n"; $errorData = 'INPUT:' . var_export($this->app->input, true) . "\n"; $this->log->add($error, 'ERROR_CONTROLLER_NOTIFIER_AJAX', $errorData); // Send response to the browser $response->failure()->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); // Send notification about the error to the administrator. $model->sendMailToAdministrator(); echo $response; $this->app->close(); } // Generate redirect URL if (!$redirectUrl and is_object($project)) { $uri = JUri::getInstance(); $redirectUrl = $uri->toString(array('scheme', 'host')) . JRoute::_(CrowdfundingHelperRoute::getBackingRoute($project->getSlug(), $project->getCatSlug(), 'share')); } if (!$message) { $message = JText::_('COM_CROWDFUNDING_TRANSACTION_PROCESSED_SUCCESSFULLY'); } // Send response to the browser $response->success()->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText($message)->setRedirectUrl($redirectUrl); echo $response; $this->app->close(); }
/** * Method to remove image via AJAX. * * @throws Exception * * @return void */ public function removeImage() { // Get the input $rewardId = $this->input->post->get('rid', 0, 'int'); $userId = JFactory::getUser()->get('id'); $response = new Prism\Response\Json(); // Validate user if (!$userId) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'))->failure(); echo $response; JFactory::getApplication()->close(); } $params = JComponentHelper::getParams('com_crowdfunding'); /** @var $params Joomla\Registry\Registry */ if (!$params->get('rewards_images', 0)) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARD'))->failure(); echo $response; JFactory::getApplication()->close(); } // Validate reward owner. $validator = new Crowdfunding\Validator\Reward\Owner(JFactory::getDbo(), $rewardId, $userId); if (!$rewardId or !$validator->isValid()) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARD'))->failure(); echo $response; JFactory::getApplication()->close(); } // Get the model $model = $this->getModel(); try { // Get the folder where the images will be stored $imagesFolder = CrowdfundingHelper::getImagesFolder($userId, JPATH_ROOT); $model->removeImage($rewardId, $imagesFolder); } catch (RuntimeException $e) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText($e->getMessage())->failure(); echo $response; JFactory::getApplication()->close(); } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM'))->failure(); echo $response; JFactory::getApplication()->close(); } $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_REWARD_IMAGE_REMOVED_SUCCESSFULLY'))->success(); echo $response; JFactory::getApplication()->close(); }
/** * This method store user vote */ public function vote() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $response = new Prism\Response\Json(); $params = $app->getParams('com_userideas'); // Check for disabled payment functionality if ($params->get('debug_item_adding_disabled', 0)) { $error = JText::_('COM_USERIDEAS_ERROR_VOTING_HAS_BEEN_DISABLED'); JLog::add($error); return null; } $requestMethod = $app->input->getMethod(); if ('POST' !== $requestMethod) { $error = 'COM_USERIDEAS_ERROR_INVALID_REQUEST_METHOD (' . $requestMethod . '):\\n'; $error .= 'INPUT: ' . var_export($app->input, true) . '\\n'; JLog::add($error); return; } $user = JFactory::getUser(); $userId = $user->get('id'); if (!$user->authorise('userideas.vote', 'com_userideas')) { $response->setTitle(JText::_('COM_USERIDEAS_FAIL'))->setText(JText::_('COM_USERIDEAS_ERROR_NO_PERMISSIONS_TO_DO_ACTION'))->failure(); echo $response; JFactory::getApplication()->close(); } $data = array('id' => $app->input->post->getInt('id'), 'user_id' => $userId); // Save data try { // Events $dispatcher = JEventDispatcher::getInstance(); // Execute event onBeforeVote JPluginHelper::importPlugin('userideas'); $results = $dispatcher->trigger('onBeforeVote', array('com_userideas.beforevote', &$data, $params)); // Check for error. foreach ($results as $result) { $success = Joomla\Utilities\ArrayHelper::getValue($result, 'success'); if (false === $success) { $message = Joomla\Utilities\ArrayHelper::getValue($result, 'message', JText::_('COM_USERIDEAS_VOTED_UNSUCCESSFULLY')); $response->setTitle(JText::_('COM_USERIDEAS_FAIL'))->setText($message)->failure(); echo $response; JFactory::getApplication()->close(); } } // Execute event onVote $dispatcher->trigger('onVote', array('com_userideas.vote', &$data, $params)); // Execute event onAfterVote $dispatcher->trigger('onAfterVote', array('com_userideas.aftervote', &$data, $params)); } catch (Exception $e) { JLog::add($e->getMessage()); $response->setTitle(JText::_('COM_USERIDEAS_FAIL'))->setText(JText::_('COM_USERIDEAS_ERROR_SYSTEM'))->failure(); echo $response; JFactory::getApplication()->close(); } $responseData = Joomla\Utilities\ArrayHelper::getValue($data, 'response_data', 0); $userVotes = Joomla\Utilities\ArrayHelper::getValue($responseData, 'user_votes', 0); $votes = Joomla\Utilities\ArrayHelper::getValue($responseData, 'votes', 0); $data = array('votes' => $votes); $response->setTitle(JText::_('COM_USERIDEAS_SUCCESS'))->setText(JText::plural('COM_USERIDEAS_VOTED_SUCCESSFULLY', $userVotes))->setData($data)->success(); echo $response; JFactory::getApplication()->close(); }
/** * Delete a file. */ public function remove() { // Create response object $response = new Prism\Response\Json(); $userId = JFactory::getUser()->get("id"); if (!$userId) { $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFILES_ERROR_NOT_LOG_IN'))->failure(); echo $response; JFactory::getApplication()->close(); } // Get file ID. $fileId = $this->input->post->get("id"); // Get the folder where the images are stored. $mediaFolder = CrowdfundingFilesHelper::getMediaFolder($userId); try { // Get the model $model = $this->getModel(); /** @var $model CrowdfundingFilesModelFiles */ $model->removeFile($fileId, $mediaFolder, $userId); } catch (RuntimeException $e) { $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFILES_ERROR_INVALID_PROJECT'))->failure(); echo $response; JFactory::getApplication()->close(); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception($e->getMessage()); } $response->setTitle(JText::_('COM_CROWDFUNDINGFILES_SUCCESS'))->setText(JText::_('COM_CROWDFUNDINGFILES_FILE_DELETED'))->setData(array("file_id" => $fileId))->success(); echo $response; JFactory::getApplication()->close(); }
/** * Delete an item. */ public function remove() { // Create response object $response = new Prism\Response\Json(); $userId = JFactory::getUser()->get("id"); if (!$userId) { $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_FAIL'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_ERROR_NOT_LOG_IN'))->failure(); echo $response; JFactory::getApplication()->close(); } // Get file ID. $itemId = $this->input->post->get("id"); // Get the model $model = $this->getModel(); /** @var $model CrowdfundingPartnersModelPartners */ // Create an partner object and load the data from database. $partner = new CrowdfundingPartners\Partner(JFactory::getDbo()); $partner->load($itemId); // Validate owner of the project. $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $partner->getProjectId(), $userId); if (!$validator->isValid()) { $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_FAIL'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_ERROR_INVALID_PROJECT'))->failure(); echo $response; JFactory::getApplication()->close(); } try { $model->remove($itemId); } catch (RuntimeException $e) { $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_FAIL'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_ERROR_INVALID_PROJECT'))->failure(); echo $response; JFactory::getApplication()->close(); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception($e->getMessage()); } $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_SUCCESS'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_PARTNER_DELETED'))->setData(array("id" => $itemId))->success(); echo $response; JFactory::getApplication()->close(); }
public function cropImage() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $response = new Prism\Response\Json(); $userId = JFactory::getUser()->get('id'); if (!$userId) { $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_FAILURE'))->setText(JText::_('COM_SOCIALCOMMUNITY_ERROR_NOT_LOG_IN'))->failure(); echo $response; $app->close(); } // Get the model $model = $this->getModel(); /** @var $model SocialcommunityModelAvatar */ $params = JComponentHelper::getParams('com_socialcommunity'); $filesystemHelper = new Prism\Filesystem\Helper($params); // Get the filename from the session. $fileName = basename($app->getUserState(Socialcommunity\Constants::TEMPORARY_IMAGE_CONTEXT)); $temporaryFolder = $filesystemHelper->getTemporaryMediaFolder(JPATH_BASE); $temporaryFile = JPath::clean($temporaryFolder . '/' . $fileName); if (!$fileName or !JFile::exists($temporaryFile)) { $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_FAILURE'))->setText(JText::_('COM_SOCIALCOMMUNITY_ERROR_FILE_DOES_NOT_EXIST'))->failure(); echo $response; $app->close(); } $imageUrl = ''; try { // Get the folder where the images will be stored $params = JComponentHelper::getParams('com_socialcommunity'); $options = array('width' => $this->input->getFloat('width'), 'height' => $this->input->getFloat('height'), 'x' => $this->input->getFloat('x'), 'y' => $this->input->getFloat('y'), 'destination' => $temporaryFolder); // Resize the picture. $images = $model->cropImage($temporaryFile, $options, $params); jimport('Prism.libs.init'); $temporaryAdapter = new League\Flysystem\Adapter\Local($temporaryFolder); $temporaryFilesystem = new League\Flysystem\Filesystem($temporaryAdapter); $storageFilesystem = $filesystemHelper->getFilesystem(); $manager = new League\Flysystem\MountManager(['temporary' => $temporaryFilesystem, 'storage' => $storageFilesystem]); $mediaFolder = $filesystemHelper->getMediaFolder($userId); $model->moveImages($images, $mediaFolder, $manager); $model->storeImages($userId, $images, $mediaFolder, $storageFilesystem); // Prepare URL to the image. $imageName = basename(Joomla\Utilities\ArrayHelper::getValue($images, 'image_profile')); $imageUrl = $filesystemHelper->getMediaFolderUri($userId) . '/' . $imageName; $app->setUserState(Socialcommunity\Constants::TEMPORARY_IMAGE_CONTEXT, null); } catch (RuntimeException $e) { $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_FAILURE'))->setText($e->getMessage())->failure(); echo $response; $app->close(); } catch (Exception $e) { JLog::add($e->getMessage(), JLog::DEBUG); $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_FAILURE'))->setText(JText::_('COM_SOCIALCOMMUNITY_ERROR_SYSTEM'))->failure(); echo $response; $app->close(); } $response->setTitle(JText::_('COM_SOCIALCOMMUNITY_SUCCESS'))->setText(JText::_('COM_SOCIALCOMMUNITY_IMAGE_SAVED'))->setData($imageUrl)->success(); echo $response; $app->close(); }
public function save($key = null, $urlVar = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $response = new Prism\Response\Json(); $data = $this->input->post->get('jform', array(), 'array'); $itemId = Joomla\Utilities\ArrayHelper::getValue($data, "project_id", 0, "int"); $terms = $this->input->post->getInt("terms", 0); $project = new Crowdfunding\Project(JFactory::getDbo()); $project->load($itemId); $returnUrl = CrowdfundingHelperRoute::getBackingRoute($project->getSlug(), $project->getCatSlug()); if (!$project->getId()) { // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDINGDATA_FAIL"))->setText(JText::_("COM_CROWDFUNDINGDATA_INVALID_ITEM"))->setRedirectUrl($returnUrl)->failure(); echo $response; JFactory::getApplication()->close(); } $model = $this->getModel(); /** @var $model CrowdfundingDataModelRecord */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_("COM_CROWDFUNDINGDATA_ERROR_FORM_CANNOT_BE_LOADED"), 500); } // Validate the form data $validData = $model->validate($form, $data); // Check for errors if ($validData === false) { $errors_ = $form->getErrors(); $errors = array(); /** @var $error RuntimeException */ foreach ($errors_ as $error) { $errors[] = $error->getMessage(); } // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDINGDATA_FAIL"))->setText(implode("\n", $errors))->setRedirectUrl($returnUrl)->failure(); echo $response; JFactory::getApplication()->close(); } // Get the payment session object and session ID. $paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $project->getId(); $paymentSession = $app->getUserState($paymentSessionContext); try { $validData["session_id"] = $paymentSession->session_id; $model->save($validData); } catch (Exception $e) { $response->setTitle(JText::_("COM_CROWDFUNDINGDATA_FAIL"))->setText(JText::_('COM_CROWDFUNDINGDATA_ERROR_SYSTEM'))->setRedirectUrl($returnUrl)->failure(); echo $response; JFactory::getApplication()->close(); } $componentParams = JComponentHelper::getParams("com_crowdfunding"); /** @var $componentParams Joomla\Registry\Registry */ $processUrl = JUri::base() . "index.php?option=com_crowdfunding&task=backing.process&id=" . (int) $project->getId() . "&rid=" . (int) $paymentSession->rewardId . "&amount=" . rawurldecode($paymentSession->amount) . "&" . JSession::getFormToken() . "=1"; // Set the value of terms of use condition. if ($componentParams->get("backing_terms", 0) and !empty($terms)) { $processUrl .= "&terms=1"; } $filter = JFilterInput::getInstance(); $processUrl = $filter->clean($processUrl); $response->setTitle(JText::_("COM_CROWDFUNDINGDATA_SUCCESS"))->setText(JText::_("COM_CROWDFUNDINGDATA_DATA_SAVED_SUCCESSFULLY"))->setRedirectUrl($processUrl)->success(); echo $response; JFactory::getApplication()->close(); }
/** * This method trigger the event onPaymentsPreparePayment. * The purpose of this method is to load a data and send it to browser. * That data will be used in the process of payment. * * @throws \InvalidArgumentException */ public function preparePaymentAjax() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get component parameters $params = JComponentHelper::getParams('com_crowdfunding'); /** @var $params Joomla\Registry\Registry */ $response = new Prism\Response\Json(); // Check for disabled payment functionality if ($params->get('debug_payment_disabled', 0)) { // Send response to the browser $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE'))->failure(); echo $response; $app->close(); } $paymentResult = null; // Prepare payment service alias. $filter = new JFilterInput(); $paymentService = $filter->clean(trim(strtolower($this->input->getCmd('payment_service'))), 'ALNUM'); // Trigger the event try { $context = 'com_crowdfunding.preparepayment.' . $paymentService; // Import Crowdfunding Payment Plugins $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onContentPreparePayment event. $results = $dispatcher->trigger('onPaymentsPreparePayment', array($context, &$params)); // Get the result, that comes from the plugin. if (is_array($results) and count($results) > 0) { foreach ($results as $result) { if ($result !== null and is_object($result)) { $paymentResult = $result; break; } } } } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); // Send response to the browser $response->failure()->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); echo $response; $app->close(); } // Check the response $success = isset($paymentResult->success) ? $paymentResult->success : null; $title = isset($paymentResult->title) ? $paymentResult->title : null; $text = isset($paymentResult->text) ? $paymentResult->text : null; $data = isset($paymentResult->data) ? $paymentResult->data : null; if (!$success) { // If there is an error... $paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $this->input->getUint('pid'); // Initialize the payment process object. $paymentSessionLocal = new JData(); $paymentSessionLocal->step1 = false; $app->setUserState($paymentSessionContext, $paymentSessionLocal); // Send response to the browser $response->failure()->setTitle($title)->setText($text); } else { // If all is OK... $response->success()->setTitle($title)->setText($text)->setData($data); } echo $response; $app->close(); }
/** * This method trigger the event onPaymentsPreparePayment. * The purpose of this method is to load a data and send it to browser. * That data will be used in the process of payment. */ public function preparePaymentAjax() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get component parameters $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ $response = new Prism\Response\Json(); // Check for disabled payment functionality if ($params->get("debug_payment_disabled", 0)) { // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE"))->failure(); echo $response; JFactory::getApplication()->close(); } $output = array(); // Prepare payment service name. $filter = new JFilterInput(); $paymentService = Joomla\String\String::trim(Joomla\String\String::strtolower($this->input->getCmd("payment_service"))); $paymentService = $filter->clean($paymentService, "ALNUM"); // Trigger the event try { $context = 'com_crowdfunding.preparepayment.' . $paymentService; // Import Crowdfunding Payment Plugins $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onContentPreparePayment event. $results = $dispatcher->trigger("onPaymentsPreparePayment", array($context, &$params)); // Get the result, that comes from the plugin. if (!empty($results)) { foreach ($results as $result) { if (!is_null($result) and is_array($result)) { $output =& $result; break; } } } } catch (Exception $e) { // Store log data in the database JLog::add($e->getMessage()); // Send response to the browser $response->failure()->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM")); echo $response; JFactory::getApplication()->close(); } // Check the response $success = Joomla\Utilities\ArrayHelper::getValue($output, "success"); if (!$success) { // If there is an error... // Get project id. $projectId = $this->input->getUint("pid"); $paymentProcessContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $projectId; // Initialize the payment process object. $paymentProcess = new JData(); $paymentProcess->step1 = false; $app->setUserState($paymentProcessContext, $paymentProcess); // Send response to the browser $response->failure()->setTitle(Joomla\Utilities\ArrayHelper::getValue($output, "title"))->setText(Joomla\Utilities\ArrayHelper::getValue($output, "text")); } else { // If all is OK... // Send response to the browser $response->success()->setTitle(Joomla\Utilities\ArrayHelper::getValue($output, "title"))->setText(Joomla\Utilities\ArrayHelper::getValue($output, "text"))->setData(Joomla\Utilities\ArrayHelper::getValue($output, "data")); } echo $response; JFactory::getApplication()->close(); }
/** * Catch a request from payment plugin via AJAX and process a transaction. */ public function notifyAjax() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $response = new Prism\Response\Json(); // Check for disabled payment functionality if ($this->params->get("debug_payment_disabled", 0)) { // Log the error. $error = JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED") . "\n"; $error .= JText::sprintf("COM_CROWDFUNDING_TRANSACTION_DATA", var_export($_REQUEST, true)); $this->log->add($error, "CONTROLLER_NOTIFIER_AJAX_ERROR"); // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE"))->failure(); echo $response; $app->close(); } // Get model object. $model = $this->getModel(); $transaction = null; $project = null; $reward = null; $paymentSession = null; $redirectUrl = null; $message = null; // Trigger the event try { // Import Crowdfunding Payment Plugins JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onPaymentNotify event. $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger("onPaymentNotify", array($this->context, &$this->params)); if (!empty($results)) { foreach ($results as $result) { if (!empty($result) and isset($result["transaction"])) { $transaction = Joomla\Utilities\ArrayHelper::getValue($result, "transaction"); $project = Joomla\Utilities\ArrayHelper::getValue($result, "project"); $reward = Joomla\Utilities\ArrayHelper::getValue($result, "reward"); $paymentSession = Joomla\Utilities\ArrayHelper::getValue($result, "payment_session"); $redirectUrl = Joomla\Utilities\ArrayHelper::getValue($result, "redirect_url"); $message = Joomla\Utilities\ArrayHelper::getValue($result, "message"); break; } } } // If there is no transaction data, the status might be pending or another one. // So, we have to stop the script execution. if (!$transaction) { // Remove the record of the payment session from database. $model->closePaymentSession($paymentSession); // Send response to the browser $response->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_TRANSACTION_NOT_PROCESSED_SUCCESSFULLY"))->failure(); echo $response; $app->close(); } // Trigger the event onAfterPayment $dispatcher->trigger('onAfterPayment', array($this->context, &$transaction, &$this->params, &$project, &$reward, &$paymentSession)); // Remove the record of the payment session from database. $model->closePaymentSession($paymentSession); } catch (Exception $e) { // Store log data to the database. $error = "AJAX NOTIFIER ERROR: " . $e->getMessage() . "\n"; $errorData = "INPUT:" . var_export($app->input, true) . "\n"; $this->log->add($error, "CONTROLLER_NOTIFIER_AJAX_ERROR", $errorData); // Remove the record of the payment session from database. $model->closePaymentSession($paymentSession); // Send response to the browser $response->failure()->setTitle(JText::_("COM_CROWDFUNDING_FAIL"))->setText(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM")); // Send notification about the error to the administrator. $model->sendMailToAdministrator(); echo $response; $app->close(); } // Generate redirect URL if (!$redirectUrl) { $uri = JUri::getInstance(); $redirectUrl = $uri->toString(array("scheme", "host")) . JRoute::_(CrowdfundingHelperRoute::getBackingRoute($project->slug, $project->catslug, "share")); } if (!$message) { $message = JText::_("COM_CROWDFUNDING_TRANSACTION_PROCESSED_SUCCESSFULLY"); } // Send response to the browser $response->success()->setTitle(JText::_("COM_CROWDFUNDING_SUCCESS"))->setText($message)->setRedirectUrl($redirectUrl); echo $response; $app->close(); }
/** * Method to follow a project. * * @throws Exception * @return void */ public function follow() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $response = new Prism\Response\Json(); $userId = JFactory::getUser()->get("id"); if (!$userId) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_USER'))->failure(); echo $response; $app->close(); } // Get project ID. $projectId = $this->input->post->getInt('pid', 0); if (!$projectId) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'))->failure(); echo $response; $app->close(); } $state = $this->input->post->getInt('state', 0); $state = !$state ? Prism\Constants::UNFOLLOWED : Prism\Constants::FOLLOWED; try { $user = new Crowdfunding\User\User(JFactory::getDbo()); $user->setId($userId); if (!$state) { $user->unfollow($projectId); } else { $user->follow($projectId); } } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } $responseData = array("state" => $state); $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setData($responseData)->success(); echo $response; $app->close(); }