public function save($key = null, $urlVar = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $data = $this->input->post->get('jform', array(), 'array'); $itemId = Joomla\Utilities\ArrayHelper::getValue($data, 'id'); $responseOptions = array('task' => $this->getTask(), 'id' => $itemId); $model = $this->getModel(); /** @var $model EmailTemplatesModelPlaceholder */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_('COM_EMAILTEMPLATES_ERROR_FORM_CANNOT_BE_LOADED')); } // Validate the form data $validData = $model->validate($form, $data); // Check for errors if ($validData === false) { $this->displayNotice($form->getErrors(), $responseOptions); return; } try { $itemId = $model->save($validData); $responseOptions['id'] = $itemId; } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_EMAILTEMPLATES_ERROR_SYSTEM')); } $this->displayMessage(JText::_('COM_EMAILTEMPLATES_PLACEHOLDER_SAVED_SUCCESSFULLY'), $responseOptions); }
/** * Method to toggle the featured setting of a list of memberss. * * @return void * * @since 1.7.0 */ public function featured() { // Check for request forgeries JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Initialise variables. $user = JFactory::getUser(); $app = JFactory::getApplication(); $ids = $app->input->get('id', [], 'array'); $task = $this->getTask(); $value = Joomla\Utilities\ArrayHelper::getValue($values, $task, 0, 'int'); // Get the model. $model = $this->getModel(); // Access checks. foreach ($ids as $i => $id) { if (!$user->authorise('core.edit.state')) { // Prune items that you can't change. unset($ids[$i]); $app->enqueueMessage(JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), 'notice'); } } if (empty($ids)) { $app->enqueueMessage(JText::_('COM_CHURCHDIRECTORY_NO_ITEM_SELECTED'), 'warning'); } else { // Publish the items. if (!$model->featured($ids, $value)) { $app->enqueueMessage($model->getError(), 'warning'); } } $this->setRedirect('index.php?option=com_churchdirectory&view=postions'); }
public function create() { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Get form data $pks = $this->input->post->get('cid', array(), 'array'); $model = $this->getModel('Profile', 'GamificationModel'); /** @var $model GamificationModelProfile */ $pks = Joomla\Utilities\ArrayHelper::toInteger($pks); // Check for validation errors. if (!$pks) { $this->defaultLink .= '&view=' . $this->view_list; $this->setMessage(JText::_('COM_GAMIFICATION_INVALID_ITEM'), 'notice'); $this->setRedirect(JRoute::_($this->defaultLink, false)); return; } try { $pks = $model->filterProfiles($pks); if (!$pks) { $this->defaultLink .= '&view=' . $this->view_list; $this->setMessage(JText::_('COM_GAMIFICATION_INVALID_ITEM'), 'notice'); $this->setRedirect(JRoute::_($this->defaultLink, false)); return; } $model->create($pks); } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_gamification'); throw new Exception(JText::_('COM_GAMIFICATION_ERROR_SYSTEM')); } $msg = JText::plural('COM_GAMIFICATION_N_PROFILES_CREATED', count(pks)); $link = $this->defaultLink . '&view=' . $this->view_list; $this->setRedirect(JRoute::_($link, false), $msg); }
/** * @throws Exception */ public function delete() { if (!JSession::checkToken('post')) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } $cid = JFactory::getApplication()->input->get('cid', array(), 'post', 'array'); // Array of integers Joomla\Utilities\ArrayHelper::toInteger($cid); if (!$cid) { $this->app->enqueueMessage(JText::_('COM_KUNENA_NO_ATTACHMENTS_SELECTED'), 'error'); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } foreach ($cid as $id) { $attachment = KunenaAttachmentHelper::get($id); $message = $attachment->getMessage(); $attachments = array($attachment->id, 1); $attach = array(); $removeList = array_keys(array_diff_key($attachments, $attach)); Joomla\Utilities\ArrayHelper::toInteger($removeList); $message->removeAttachments($removeList); $message->save(); $topic = $message->getTopic(); $attachment->delete(); if ($topic->attachments > 0) { $topic->attachments = $topic->attachments - 1; $topic->save(false); } } $this->app->enqueueMessage(JText::_('COM_KUNENA_ATTACHMENTS_DELETED_SUCCESSFULLY')); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); }
public function save($key = null, $urlVar = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $data = $this->input->post->get('jform', array(), 'array'); $itemId = Joomla\Utilities\ArrayHelper::getValue($data, "id"); $redirectOptions = array("task" => $this->getTask(), "id" => $itemId); $model = $this->getModel(); /** @var $model CrowdfundingModelComment */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_FORM_CANNOT_BE_LOADED"), 500); } // Validate the form data $validData = $model->validate($form, $data); // Check for errors if ($validData === false) { $this->displayNotice($form->getErrors(), $redirectOptions); return; } try { $itemId = $model->save($validData); $redirectOptions["id"] = $itemId; } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } $this->displayMessage(JText::_('COM_CROWDFUNDING_COMMENT_SAVED'), $redirectOptions); }
/** * Remove all sessions for the user name * * Method is called after user data is deleted from the database * * @param array $user Holds the user data * @param boolean $success True if user was successfully stored in the database * @param string $msg Message * * @return boolean * * @since 1.6 */ public function onUserAfterDelete($user, $success, $msg) { $userId = Joomla\Utilities\ArrayHelper::getValue($user, 'id', 0, 'int'); if (!$success or !$userId) { return false; } // Remove profile images. $profile = new Socialcommunity\Profile\Profile($this->db); $profile->load(array('user_id' => $userId)); if ($profile->getId()) { // Remove profile record. $query = $this->db->getQuery(true); $query->delete($this->db->quoteName('#__itpsc_profiles'))->where($this->db->quoteName('user_id') . '=' . (int) $userId); $this->db->setQuery($query); $this->db->execute(); // Remove profile images. $params = JComponentHelper::getParams('com_socialcommunity'); /** @var $params Joomla\Registry\Registry */ jimport('Prism.libs.init'); $filesystemHelper = new Prism\Filesystem\Helper($params); $mediaFolder = $filesystemHelper->getMediaFolder($userId); $filesystem = $filesystemHelper->getFilesystem(); $profile->removeImages($filesystem, $mediaFolder); } return true; }
public function save($key = null, $urlVar = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $data = $this->input->post->get('jform', array(), 'array'); $itemId = Joomla\Utilities\ArrayHelper::getValue($data, 'id'); $redirectData = array('task' => $this->getTask(), 'id' => $itemId); $model = $this->getModel(); /** @var $model SocialCommunityModelLocation */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_('COM_SOCIALCOMMUNITY_ERROR_FORM_CANNOT_BE_LOADED')); } // Validate the form $validData = $model->validate($form, $data); // Check for errors if ($validData === false) { $this->displayNotice($form->getErrors(), $redirectData); return; } try { $itemId = $model->save($validData); $redirectData['id'] = $itemId; } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_SOCIALCOMMUNITY_ERROR_SYSTEM')); } $this->displayMessage(JText::_('COM_SOCIALCOMMUNITY_LOCATION_SAVED'), $redirectData); }
/** * Enable auto-update. * * @throws Exception * @return void */ public function enableau() { // Check for request forgeries JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $redirectOptions = array("view" => "urls"); $cid = $this->input->post->get("cid", array(), "array"); $cid = Joomla\Utilities\ArrayHelper::toInteger($cid); $data = array('enableau' => 1, 'disableau' => 0); $task = $this->getTask(); $value = JArrayHelper::getValue($data, $task, 0, 'int'); if (empty($cid)) { $this->displayNotice(JText::_($this->text_prefix . '_ERROR_NO_ITEM_SELECTED'), $redirectOptions); return; } try { $model = $this->getModel(); $model->updateAutoupdate($cid, $value); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_ITPMETA_ERROR_SYSTEM')); } if ($value == 1) { $msg = $this->text_prefix . '_N_ITEMS_AUTOUPDATE_ENABLED'; } else { $msg = $this->text_prefix . '_N_ITEMS_AUTOUPDATE_DISABLED'; } $this->displayMessage(JText::plural($msg, count($cid)), $redirectOptions); }
/** * Remove an item. * * @throws Exception * @return void * * @since 12.2 */ public function delete() { // Check for request forgeries JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); /* @var $app JApplicationAdministrator */ // Gets the data from the form $cid = $this->input->post->get('cid', array(), 'array'); $cid = Joomla\Utilities\ArrayHelper::toInteger($cid); $urlId = $app->getUserState("url.id"); $redirectData = array("view" => "url", "layout" => "edit", "id" => $urlId); if (!$cid) { $this->displayWarning(JText::_("COM_ITPMETA_ERROR_INVALID_ITEMS"), $redirectData); return; } try { $model = $this->getModel(); $model->delete($cid); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_ITPMETA_ERROR_SYSTEM')); } $msg = JText::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid)); $this->displayMessage($msg, $redirectData); }
/** * Method to load data via AJAX */ public function getData() { // Create response object. $response = new Prism\Response\Json(); // Get the input $itemId = $this->input->get->get('id', 0, 'int'); $userId = JFactory::getUser()->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_EDIT"))->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(); } if (isset($item) and is_object($item)) { $response->setData(Joomla\Utilities\ArrayHelper::fromObject($item))->success(); } else { $response->failure(); } echo $response; JFactory::getApplication()->close(); }
/** * Method to remove records via AJAX. * * @throws Exception * @return void */ public function remove() { // Get the input $app = JFactory::getApplication(); $pks = $app->input->post->get('rid', array(), 'array'); $userId = JFactory::getUser()->get('id'); $response = new Prism\Response\Json(); // Sanitize the input $pks = Joomla\Utilities\ArrayHelper::toInteger($pks); // Validate user if (!$userId) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'))->failure(); echo $response; $app->close(); } // Validate primary keys if (!$pks) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARDS_SELECTED'))->failure(); echo $response; $app->close(); } $rewardId = Joomla\Utilities\ArrayHelper::getValue($pks, 0); // 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_REWARDS_SELECTED'))->failure(); echo $response; $app->close(); } // Get the model $model = $this->getModel(); try { $reward = new Crowdfunding\Reward(JFactory::getDbo()); $reward->load($rewardId); // If the reward is part of transaction, // set it as trashed. if ($reward->isSelectedByUser()) { $reward->trash(); } else { // Get the folder where the images are stored $imagesFolder = CrowdfundingHelper::getImagesFolder($userId, JPATH_ROOT); $model->remove($rewardId, $imagesFolder); } } catch (RuntimeException $e) { $response->setTitle(JText::_('COM_CROWDFUNDING_FAIL'))->setText($e->getMessage())->failure(); echo $response; $app->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; $app->close(); } $response->setTitle(JText::_('COM_CROWDFUNDING_SUCCESS'))->setText(JText::_('COM_CROWDFUNDING_REWARD_SUCCESSFULY_REMOVED'))->success(); echo $response; $app->close(); }
public function save($key = null, $urlVar = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $data = $this->input->post->get('jform', array(), 'array'); $itemId = Joomla\Utilities\ArrayHelper::getValue($data, 'id'); $dataFile = $this->input->files->get('jform', array(), 'array'); $image = Joomla\Utilities\ArrayHelper::getValue($dataFile, 'image', array(), 'array'); $imageName = JString::trim(Joomla\Utilities\ArrayHelper::getValue($image, 'name')); $redirectOptions = array('task' => $this->getTask(), 'id' => $itemId); $model = $this->getModel(); /** @var $model CrowdfundingModelReward */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_FORM_CANNOT_BE_LOADED')); } $params = JComponentHelper::getParams('com_crowdfunding'); /** @var $params Joomla\Registry\Registry */ // Prepare amounts. $moneyFormatter = $this->getMoneyFormatter($params); $data['amount'] = $moneyFormatter->setAmount($data['amount'])->parse(); // Validate the form $validData = $model->validate($form, $data); // Check for errors. if ($validData === false) { $this->displayNotice($form->getErrors(), $redirectOptions); return; } try { $itemId = $model->save($validData); $redirectOptions['id'] = $itemId; // Upload an image $imagesAllowed = $params->get('rewards_images', 0); // Upload images. if ($imagesAllowed and !empty($imageName) and !empty($itemId)) { $reward = new Crowdfunding\Reward(JFactory::getDbo()); $reward->load($itemId); // Get the folder where the images will be stored $imagesFolder = CrowdfundingHelper::getImagesFolder($reward->getUserId(), JPATH_ROOT); if (!JFolder::exists($imagesFolder)) { CrowdfundingHelper::createFolder($imagesFolder); } $images = $model->uploadImage($image, $imagesFolder); if (!empty($images)) { $model->storeImage($images, $imagesFolder, $itemId); } } } catch (RuntimeException $e) { $this->displayError($e->getMessage(), $redirectOptions); return; } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } $this->displayMessage(JText::_('COM_CROWDFUNDING_REWARD_SAVED'), $redirectOptions); }
public function save($key = null, $urlVar = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $data = $this->input->post->get('jform', array(), 'array'); $itemId = Joomla\Utilities\ArrayHelper::getValue($data, 'id'); $redirectOptions = array('task' => $this->getTask(), 'id' => $itemId); // Get component parameters. $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ // Prepare amounts. $moneyFormatter = $this->getMoneyFormatter($params); $data['goal'] = $moneyFormatter->setAmount($data['goal'])->parse(); $data['funded'] = $moneyFormatter->setAmount($data['funded'])->parse(); $model = $this->getModel(); /** @var $model CrowdfundingModelProject */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_FORM_CANNOT_BE_LOADED')); } // Validate the form $validData = $model->validate($form, $data); $validData['duration_type'] = Joomla\Utilities\ArrayHelper::getValue($data, 'funding_duration_type'); // Check for errors. if ($validData === false) { $this->displayNotice($form->getErrors(), $redirectOptions); return; } try { // Get image $files = $this->input->files->get('jform', array(), 'array'); $image = Joomla\Utilities\ArrayHelper::getValue($files, 'image'); $pitchImage = Joomla\Utilities\ArrayHelper::getValue($files, 'pitch_image'); // Upload image if (!empty($image['name'])) { $imageNames = $model->uploadImage($image); if (!empty($imageNames['image'])) { $validData = array_merge($validData, $imageNames); } } // Upload pitch image if (!empty($pitchImage['name'])) { $pitchImageName = $model->uploadPitchImage($pitchImage); if ($pitchImageName !== '') { $validData['pitch_image'] = $pitchImageName; } } $itemId = $model->save($validData); $redirectOptions['id'] = $itemId; } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } $this->displayMessage(JText::_('COM_CROWDFUNDING_PROJECT_SAVED'), $redirectOptions); }
public function save($key = null, $urlVar = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); /** @var $app JApplicationAdministrator */ $data = $app->input->post->get('jform', array(), 'array'); $itemId = Joomla\Utilities\ArrayHelper::getValue($data, "id"); $redirectOptions = array("task" => $this->getTask(), "id" => $itemId); $model = $this->getModel(); /** @var $model CrowdfundingModelProject */ $form = $model->getForm($data, false); /** @var $form JForm * */ if (!$form) { throw new Exception($model->getError(), 500); } // Validate the form $validData = $model->validate($form, $data); // @todo fix this $validData["duration_type"] = Joomla\Utilities\ArrayHelper::getValue($data, "funding_duration_type"); // Check for errors. if ($validData === false) { $this->displayNotice($form->getErrors(), $redirectOptions); return; } try { // Get image $files = $app->input->files->get('jform', array(), 'array'); $image = Joomla\Utilities\ArrayHelper::getValue($files, "image"); $pitchImage = Joomla\Utilities\ArrayHelper::getValue($files, "pitch_image"); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.path'); jimport('joomla.image.image'); // Upload image if (!empty($image['name'])) { $imageNames = $model->uploadImage($image); if (!empty($imageNames["image"])) { $validData = array_merge($validData, $imageNames); } } // Upload pitch image if (!empty($pitchImage['name'])) { $pitchImageName = $model->uploadPitchImage($pitchImage); if (!empty($pitchImageName)) { $validData["pitch_image"] = $pitchImageName; } } $model->save($validData); } catch (Exception $e) { JLog::add($e->getMessage()); throw new Exception(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM')); } $this->displayMessage(JText::_('COM_CROWDFUNDINGFINANCE_PROJECT_SAVED'), $redirectOptions); }
/** * Fetured * * @param int $value The featured value * @param int $i ? * @param bool $canChange Whether the value can be changed or not * * @return string The anchor tag to toggle featured/unfeatured contacts. * * @since 1.6 */ public static function featured($value = 0, $i = 0, $canChange = true) { // Array of image, task, title, action $states = [0 => ['disabled.png', 'members.featured', 'COM_CHURCHDIRECTORY_UNFEATURED', 'COM_CHURCHDIRECTORY_TOGGLE_TO_FEATURE'], 1 => ['featured.png', 'members.unfeatured', 'JFEATURED', 'COM_CHURCHDIRECTORY_TOGGLE_TO_UNFEATURE']]; $state = Joomla\Utilities\ArrayHelper::getValue($states, (int) $value, $states[1]); $html = JHtml::_('image', 'admin/' . $state[0], JText::_($state[2]), null, true); if ($canChange) { $html = '<a href="#" onclick="return listItemTask(\'cb' . $i . '\',\'' . $state[1] . '\')" title="' . JText::_($state[3]) . '">' . $html . '</a>'; } return $html; }
/** * Save data into the DB * * @param array $data The data about item * * @return int Item ID */ public function save($data) { $id = Joomla\Utilities\ArrayHelper::getValue($data, 'id'); $name = Joomla\Utilities\ArrayHelper::getValue($data, 'name'); $code = Joomla\Utilities\ArrayHelper::getValue($data, 'code'); // Load a record from the database $row = $this->getTable(); $row->load($id); $row->set('name', $name); $row->set('code', $code); $row->store(); return $row->get('id'); }
/** * Save data into the DB * * @param array $data The data about item * * @return int */ public function save($data) { $id = Joomla\Utilities\ArrayHelper::getValue($data, "id"); $name = Joomla\Utilities\ArrayHelper::getValue($data, "name"); $note = Joomla\Utilities\ArrayHelper::getValue($data, "note"); // Load a record from the database $row = $this->getTable(); $row->load($id); $row->set("name", $name); $row->set("note", $note); $row->store(); return $row->get("id"); }
/** * Save data into the DB. * * @param array $data * * @return int */ public function save($data) { $id = Joomla\Utilities\ArrayHelper::getValue($data, "id"); $comment = Joomla\Utilities\ArrayHelper::getValue($data, "comment"); $published = Joomla\Utilities\ArrayHelper::getValue($data, "published"); // Load a record from the database $row = $this->getTable(); /** @var $row UserIdeasTableComment */ $row->load($id); $row->set("comment", $comment); $row->set("published", $published); $row->store(); return $row->get("id"); }
public function send() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $redirectOptions = array('view' => 'discover'); $params = JComponentHelper::getParams('com_crowdfunding'); /** @var $params Joomla\Registry\Registry */ if (!$params->get('security_display_friend_form', 0)) { $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_CANT_SEND_MAIL'), $redirectOptions); return; } // Get the data from the form POST $data = $this->input->post->get('jform', array(), 'array'); $itemId = Joomla\Utilities\ArrayHelper::getValue($data, 'id', 0, 'uint'); // Get project slug and check for valid project. $slug = Crowdfunding\Helper\ProjectHelper::getSlug($itemId); if (!$slug) { $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), $redirectOptions); return; } // Prepare redirect link $redirectOptions = array('view' => 'friendmail', 'id' => $slug); $model = $this->getModel(); /** @var $model CrowdfundingModelFriendMail */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_FORM_CANNOT_BE_LOADED')); } // Test if the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { $this->displayNotice($form->getErrors(), $redirectOptions); return; } try { $model->send($validData); } catch (RuntimeException $e) { JLog::add($e->getMessage(), JLog::WARNING, 'com_crowdfunding'); $this->displayWarning($e->getMessage(), $redirectOptions); return; } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } // Redirect to next page $this->displayMessage(JText::_('COM_CROWDFUNDING_FRIEND_MAIL_SUCCESSFULLY_SEND'), $redirectOptions); }
/** * * This method is triggered bofore user vote be stored. * * @param string $context * @param array $data * @param Joomla\Registry\Registry $params * * @return null|array */ public function onBeforeVote($context, &$data, $params) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ if ($app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp('raw', $docType) !== 0) { return null; } if (strcmp('com_userideas.beforevote', $context) !== 0) { return null; } $numberOfVotes = abs($this->params->get('votes_per_item', 0)); $itemId = Joomla\Utilities\ArrayHelper::getValue($data, 'id', 0, 'int'); $userId = Joomla\Utilities\ArrayHelper::getValue($data, 'user_id', 0, 'int'); $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('COUNT(*)')->from($db->quoteName('#__uideas_votes', 'a'))->where('a.item_id = ' . (int) $itemId); // Check if it is anonymous user. if (!$userId) { $hash = $this->generateHash(); $query->where('a.hash = ' . $db->quote($hash)); } else { $query->where('a.user_id = ' . (int) $userId); } $db->setQuery($query, 0, 1); $result = $db->loadResult(); $votingAllowed = false; if (!$result or $numberOfVotes === 0) { $votingAllowed = true; } if ($numberOfVotes > 0 and $result < $numberOfVotes) { $votingAllowed = true; } if ($votingAllowed) { // User vote is not recorded. Return true $result = array('success' => true); } else { // User vote is recorded. Return false. $this->loadLanguage(); $result = array('success' => false, 'message' => JText::_('PLG_USERIDEAS_VOTE_YOU_HAVE_VOTED')); } return $result; }
/** * Method to send mail to friend. * * @param array $data The form data. */ public function send($data) { // Send email to the administrator $subject = Joomla\Utilities\ArrayHelper::getValue($data, "subject"); $body = Joomla\Utilities\ArrayHelper::getValue($data, "message"); $from = Joomla\Utilities\ArrayHelper::getValue($data, "sender"); $fromName = Joomla\Utilities\ArrayHelper::getValue($data, "sender_name"); $recipient = Joomla\Utilities\ArrayHelper::getValue($data, "receiver"); $return = JFactory::getMailer()->sendMail($from, $fromName, $recipient, $subject, $body); // Check for an error. if ($return !== true) { $error = JText::sprintf("COM_CROWDFUNDING_ERROR_MAIL_SENDING_FRIEND"); JLog::add($error); } }
/** * Display an HTML code for a row * * @param string $title * @param array $result * array( * type => success, important, warning, * text => yes, no, off, on, warning,... * ) * @param string $info */ public static function addRow($title, $result, $info) { $outputType = Joomla\Utilities\ArrayHelper::getValue($result, 'type', ''); $outputText = Joomla\Utilities\ArrayHelper::getValue($result, 'text', ''); $output = ''; if ($outputType !== '' and $outputText !== '') { $output = '<span class="label label-' . $outputType . '">' . $outputText . '</span>'; } echo ' <tr> <td>' . $title . '</td> <td>' . $output . '</td> <td>' . $info . '</td> </tr>'; }
/** * Display an HTML code for a row * * @param string $title * @param array $result * @param string $info * * # Example * array( * type => success, important, warning, * text => yes, no, off, on, warning,... * ) */ public static function addRow($title, $result, $info) { $outputType = Joomla\Utilities\ArrayHelper::getValue($result, "type", ""); $outputText = Joomla\Utilities\ArrayHelper::getValue($result, "text", ""); $output = ""; if (!empty($outputType) and !empty($outputText)) { $output = '<span class="label label-' . $outputType . '">' . $outputText . '</span>'; } echo ' <tr> <td>' . $title . '</td> <td>' . $output . '</td> <td>' . $info . '</td> </tr>'; }
/** * Save data into the DB * * @param array $data The data about item * * @return int */ public function save($data) { $id = Joomla\Utilities\ArrayHelper::getValue($data, "id"); $content = Joomla\Utilities\ArrayHelper::getValue($data, "content"); $url = Joomla\Utilities\ArrayHelper::getValue($data, "url"); $image = Joomla\Utilities\ArrayHelper::getValue($data, "image"); // Load a record from the database $row = $this->getTable(); $row->load($id); $row->set("content", $content); $row->set("url", !$url ? null : $url); $row->set("image", !$image ? null : $image); $row->store(true); return $row->get("id"); }
/** * Save data into the DB * * @param array $data The data about item * * @return int */ public function save($data) { $id = Joomla\Utilities\ArrayHelper::getValue($data, 'id'); $content = Joomla\Utilities\ArrayHelper::getValue($data, 'content'); $url = Joomla\Utilities\ArrayHelper::getValue($data, 'url'); $image = Joomla\Utilities\ArrayHelper::getValue($data, 'image'); // Load a record from the database $row = $this->getTable(); $row->load($id); $row->set('content', $content); $row->set('url', !$url ? null : $url); $row->set('image', !$image ? null : $image); $row->store(true); return $row->get('id'); }
public function send() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Get the data from the form POST $data = $this->input->post->get('cfreport', array(), 'array'); $itemId = Joomla\Utilities\ArrayHelper::getValue($data, 'id'); if (!$itemId) { $redirectOptions = array('force_direction' => CrowdfundingHelperRoute::getReportRoute()); $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), $redirectOptions); return; } // Get project $item = Crowdfunding\Project::getInstance(JFactory::getDbo(), $itemId); $redirectOptions = array('force_direction' => CrowdfundingHelperRoute::getReportRoute($item->getId())); $model = $this->getModel(); /** @var $model CrowdfundingModelReport */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_FORM_CANNOT_BE_LOADED')); } // Test if the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { $errors = $form->getErrors(); $error = array_shift($errors); $msg = $error->getMessage(); $this->displayNotice($msg, $redirectOptions); return; } try { $userId = (int) JFactory::getUser()->get('id'); if ($userId > 0) { $validData['user_id'] = $userId; } $model->save($validData); } catch (RuntimeException $e) { $this->displayNotice($e->getMessage(), $redirectOptions); return; } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } // Redirect to next page $this->displayMessage(JText::_('COM_CROWDFUNDING_REPORT_SENT_SUCCESSFULLY'), $redirectOptions); }
public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $userId = (int) JFactory::getUser()->get('id'); if (!$userId) { $redirectOptions = array('force_direction' => 'index.php?option=com_users&view=login'); $this->displayNotice(JText::_('COM_CROWDFUNDING_ERROR_NOT_LOG_IN'), $redirectOptions); return; } // Get the data from the form POST $data = $this->input->post->get('jform', array(), 'array'); $itemId = Joomla\Utilities\ArrayHelper::getValue($data, 'project_id', 0, 'int'); // Get project $item = Crowdfunding\Project::getInstance(JFactory::getDbo(), $itemId); $redirectOptions = array('force_direction' => CrowdfundingHelperRoute::getDetailsRoute($item->getSlug(), $item->getCatSlug(), 'updates')); // Check for valid owner. if ($userId !== $item->getUserId()) { $this->displayWarning(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), $redirectOptions); return; } $model = $this->getModel(); /** @var $model CrowdfundingModelUpdate */ $form = $model->getForm($data, false); /** @var $form JForm */ if (!$form) { throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_FORM_CANNOT_BE_LOADED')); } // Test if the data is valid. $validData = $model->validate($form, $data); // Check for validation errors. if ($validData === false) { $errors = $form->getErrors(); $error = array_shift($errors); $msg = $error->getMessage(); $this->displayNotice($msg, $redirectOptions); return; } try { $model->save($validData); } catch (Exception $e) { JLog::add($e->getMessage(), JLog::ERROR, 'com_crowdfunding'); throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_SYSTEM')); } // Redirect to next page $this->displayMessage(JText::_('COM_CROWDFUNDING_UPDATE_SUCCESSFULLY_SAVED'), $redirectOptions); }
public function uploadFile($fileData, $type) { $app = JFactory::getApplication(); /** @var $app JApplicationAdministrator */ jimport('joomla.filesystem.archive'); $uploadedFile = Joomla\Utilities\ArrayHelper::getValue($fileData, 'tmp_name'); $uploadedName = Joomla\Utilities\ArrayHelper::getValue($fileData, 'name'); $errorCode = Joomla\Utilities\ArrayHelper::getValue($fileData, 'error'); $destination = JPath::clean($app->get('tmp_path') . DIRECTORY_SEPARATOR . JFile::makeSafe($uploadedName)); $file = new Prism\File\File(); // Prepare size validator. $KB = 1024 * 1024; $fileSize = (int) $app->input->server->get('CONTENT_LENGTH'); $mediaParams = JComponentHelper::getParams('com_media'); /** @var $mediaParams Joomla\Registry\Registry */ $uploadMaxSize = $mediaParams->get('upload_maxsize') * $KB; // Prepare size validator. $sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize); // Prepare server validator. $serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE)); $file->addValidator($sizeValidator); $file->addValidator($serverValidator); // Validate the file if (!$file->isValid()) { throw new RuntimeException($file->getError()); } // Prepare uploader object. $uploader = new Prism\File\Uploader\Local($uploadedFile); $uploader->setDestination($destination); // Upload the file $file->setUploader($uploader); $file->upload(); $fileName = basename($destination); // Extract file if it is archive. $ext = JString::strtolower(JFile::getExt($fileName)); if (strcmp($ext, 'zip') === 0) { $destFolder = JPath::clean($app->get('tmp_path') . '/' . $type); if (is_dir($destFolder)) { JFolder::delete($destFolder); } $filePath = $this->extractFile($destination, $destFolder); } else { $filePath = $destination; } return $filePath; }
/** * Method override to check if you can add a new record. * * @param array $data An array of input data. * * @return boolean * * @since 1.7.0 */ protected function allowAdd($data = []) { // Initialise variables. $user = JFactory::getUser(); $categoryId = Joomla\Utilities\ArrayHelper::getValue($data, 'catid', JFactory::getApplication()->input->getInt('filter_category_id', 0), 'int'); $allow = null; if ($categoryId) { // If the category has been passed in the URL check it. $allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId); } if ($allow === null) { // In the absense of better information, revert to the component permissions. return parent::allowAdd(); } else { return $allow; } }
/** * Save data into the DB. * * @param array $data * * @return int */ public function save($data) { $id = Joomla\Utilities\ArrayHelper::getValue($data, 'id'); $name = Joomla\Utilities\ArrayHelper::getValue($data, 'name'); $description = Joomla\Utilities\ArrayHelper::getValue($data, 'description'); $categoryId = Joomla\Utilities\ArrayHelper::getValue($data, 'catid'); // Load a record from the database $row = $this->getTable(); /** @var $row EmailTemplatesTablePlaceholder */ $row->load($id); $row->set('name', $name); $row->set('description', $description); $row->set('catid', $categoryId); $this->prepareTable($row); $row->store(); return $row->get('id'); }