public function __construct($config = array()) { parent::__construct($config); $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get project id. $this->projectId = $this->input->getUint("pid"); // Prepare log object $registry = Joomla\Registry\Registry::getInstance("com_crowdfunding"); /** @var $registry Joomla\Registry\Registry */ $fileName = $registry->get("logger.file"); $tableName = $registry->get("logger.table"); $file = JPath::clean($app->get("log_path") . DIRECTORY_SEPARATOR . $fileName); $this->log = new Prism\Log\Log(); $this->log->addWriter(new Prism\Log\Writer\Database(JFactory::getDbo(), $tableName)); $this->log->addWriter(new Prism\Log\Writer\File($file)); // Create an object that contains a data used during the payment process. $this->paymentProcessContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $this->projectId; $this->paymentProcess = $app->getUserState($this->paymentProcessContext); // Prepare context $filter = new JFilterInput(); $paymentService = Joomla\String\String::trim(Joomla\String\String::strtolower($this->input->getCmd("payment_service"))); $paymentService = $filter->clean($paymentService, "ALNUM"); $this->context = !empty($paymentService) ? 'com_crowdfunding.notify.' . $paymentService : 'com_crowdfunding.notify'; // Prepare params $this->params = JComponentHelper::getParams("com_crowdfunding"); }
/** * Method to set up the document properties * @return void */ protected function setDocument() { $this->document->setTitle($this->documentTitle); // Scripts JHtml::_('behavior.formvalidation'); JHtml::_('behavior.tooltip'); JHtml::_('formbehavior.chosen', 'select'); $this->document->addScript(JURI::root() . 'media/' . $this->option . '/js/admin/' . Joomla\String\String::strtolower($this->getName()) . '.js'); }
public function save($key = null, $urlVar = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $data = $this->input->post->get('jform', array(), 'array'); $itemId = JArrayHelper::getValue($data, "id"); $dataFile = $this->input->files->get('jform', array(), 'array'); $image = JArrayHelper::getValue($dataFile, "image", array(), "array"); $imageName = Joomla\String\String::trim(JArrayHelper::getValue($image, 'name')); $redirectOptions = array("task" => $this->getTask(), "id" => $itemId); // Parse formatted amount. $data["amount"] = CrowdfundingHelper::parseAmount($data["amount"]); $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"), 500); } // Validate the form $validData = $model->validate($form, $data); // Check for errors. if ($validData === false) { $this->displayNotice($form->getErrors(), $redirectOptions); return; } $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ 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()); jimport("joomla.filesystem.folder"); 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()); throw new Exception(JText::_('COM_Crowdfunding_ERROR_SYSTEM')); } $this->displayMessage(JText::_('COM_Crowdfunding_REWARD_SAVED'), $redirectOptions); }
/** * @param $txt * @param int $len * * @return mixed|string|void */ public static function parseText($txt, $len = 0) { if (!$txt) { return; } if ($len && Joomla\String\String::strlen($txt) > $len) { $txt = Joomla\String\String::substr($txt, 0, $len) . ' ...'; } $txt = self::escape($txt); $txt = preg_replace('/(\\S{30})/u', '\\1​', $txt); $txt = self::prepareContent($txt, 'title'); return $txt; }
public function onAfterPost($message) { if (Joomla\String\String::strlen($message->message) > $this->params->get('activity_points_limit', 0)) { $this->assignPoints('thread.new'); } if (Joomla\String\String::strlen($message->message) > $this->params->get('activity_badge_limit', 0)) { $this->assignBadge('thread.new', JText::_('PLG_KUNENA_EASYSOCIAL_BADGE_NEW_TITLE')); } $stream = FD::stream(); $tmpl = $stream->getTemplate(); $tmpl->setActor($message->userid, SOCIAL_TYPE_USER); $tmpl->setContext($message->thread, 'kunena'); $tmpl->setVerb('create'); $tmpl->setAccess('core.view'); $stream->add($tmpl); }
public static function badge(Gamification\User\Badge $badge, $mediaPath, $tip = false, $placeholders = array()) { $title = ""; $class = ""; $classes = array(); if (!empty($tip) and $badge->getDescription()) { JHtml::_("bootstrap.tooltip"); $classes[] = "hasTooltip"; $description = strip_tags(Joomla\String\String::trim($badge->getDescription($placeholders))); $title = ' title="' . htmlspecialchars($description, ENT_QUOTES, "UTF-8") . '"'; } // Prepare class property if (!empty($classes)) { $class = ' class="' . implode(" ", $classes) . '"'; } // Prepare alt property $alt = strip_tags(Joomla\String\String::trim($badge->getTitle())); if (!empty($alt)) { $alt = ' alt="' . htmlspecialchars($alt, ENT_QUOTES, "UTF-8") . '"'; } $html = '<img src="' . $mediaPath . "/" . $badge->getImage() . '"' . $class . $alt . $title . ' />'; return $html; }
/** * Method to save social profiles data. * * @param int $userId * @param array $data * * @return mixed The record id on success, null on failure. * @since 1.6 */ public function saveSocialProfiles($userId, $data) { // Prepare profiles. $profiles = array('facebook' => Joomla\Utilities\ArrayHelper::getValue($data, 'facebook'), 'twitter' => Joomla\Utilities\ArrayHelper::getValue($data, 'twitter'), 'linkedin' => Joomla\Utilities\ArrayHelper::getValue($data, 'linkedin')); $allowedTypes = array('facebook', 'twitter', 'linkedin'); foreach ($profiles as $key => $alias) { $type = Joomla\String\String::trim($key); $alias = Joomla\String\String::trim($alias); if (!in_array($type, $allowedTypes, true)) { continue; } $keys = array('user_id' => (int) $userId, 'type' => $type); // Load a record from the database $row = $this->getTable('SocialProfile'); $row->load($keys); // Remove old if ($row->get('id') > 0 and !$alias) { // If there is a record but there is no alias, remove the record. $row->delete(); } elseif (!$alias) { // If missing alias, continue to next social profile. continue; } else { // Add new if (!$row->get('id')) { $row->set('user_id', (int) $userId); } $row->set('alias', $alias); $row->set('type', $type); $row->store(); } } }
/** * 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(); }
/** * Check the system for debug mode * * @param JData */ protected function prepareDebugMode(&$paymentSession) { // Check for maintenance (debug) state. $params = $this->state->get("params"); if ($params->get("debug_payment_disabled", 0)) { $msg = Joomla\String\String::trim($params->get("debug_disabled_functionality_msg")); if (!$msg) { $msg = JText::_("COM_CROWDFUNDING_DEBUG_MODE_DEFAULT_MSG"); } $this->app->enqueueMessage($msg, "notice"); $this->disabledButton = 'disabled="disabled"'; // Store the new values of the payment process to the user session. $paymentSession->step1 = false; $this->app->setUserState($this->paymentSessionContext, $paymentSession); } }
/** * Prepare some main filters. * * @param JDatabaseQuery $query */ protected function prepareFilters(&$query) { $db = JFactory::getDbo(); // Filter by featured state. $featured = $this->getState($this->context . ".filter_featured"); if (!is_null($featured)) { if (!$featured) { $query->where('a.featured = 0'); } else { $query->where('a.featured = 1'); } } // Filter by category ID $categoryId = $this->getState($this->context . ".category_id", 0); if (!empty($categoryId)) { $query->where('a.catid = ' . (int) $categoryId); } // Filter by project type $projectTypeId = $this->getState($this->context . ".filter_projecttype", 0); if (!empty($projectTypeId)) { $query->where('a.type_id = ' . (int) $projectTypeId); } // Filter by country $countryCode = $this->getState($this->context . ".filter_country"); if (!empty($countryCode)) { $query->innerJoin($db->quoteName("#__crowdf_locations", "l") . " ON a.location_id = l.id"); $query->where('l.country_code = ' . $db->quote($countryCode)); } // Filter by location $locationId = $this->getState($this->context . ".filter_location"); if (!empty($locationId)) { $query->where('a.location_id = ' . (int) $locationId); } // Filter by funding type $filterFundingType = Joomla\String\String::strtoupper(Joomla\String\String::trim($this->getState($this->context . ".filter_fundingtype"))); if (!empty($filterFundingType)) { $allowedFundingTypes = array("FIXED", "FLEXIBLE"); if (in_array($filterFundingType, $allowedFundingTypes)) { $query->where('a.funding_type = ' . $db->quote($filterFundingType)); } } // Filter by phrase $phrase = $this->getState($this->context . ".filter_phrase"); if (!empty($phrase)) { $escaped = $db->escape($phrase, true); $quoted = $db->quote("%" . $escaped . "%", false); $query->where('a.title LIKE ' . $quoted); } }
public function process() { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Check for request forgeries. $requestMethod = $app->input->getMethod(); if (strcmp("POST", $requestMethod) == 0) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); } else { JSession::checkToken("get") or jexit(JText::_('JINVALID_TOKEN')); } // Get params $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Get the data from the form $itemId = $this->input->getInt('id', 0); $rewardId = $this->input->getInt('rid', 0); // Get amount $amount = CrowdfundingHelper::parseAmount($this->input->getString("amount")); // Get user ID $user = JFactory::getUser(); $userId = (int) $user->get("id"); // Anonymous user ID $aUserId = ""; $model = $this->getModel(); /** @var $model CrowdfundingModelBacking */ // Get the item $item = $model->getItem($itemId); $returnUrl = CrowdfundingHelperRoute::getBackingRoute($item->slug, $item->catslug); // Authorise the user if (!$user->authorise("crowdfunding.donate", "com_crowdfunding")) { $this->setRedirect(JRoute::_($returnUrl, false), JText::_('COM_CROWDFUNDING_ERROR_NO_PERMISSIONS'), "notice"); return; } // Check for valid project if (empty($item->id)) { $this->setRedirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute()), JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), "notice"); return; } // Check for maintenance (debug) state. if ($params->get("debug_payment_disabled", 0)) { $msg = Joomla\String\String::trim($params->get("debug_disabled_functionality_msg")); if (!$msg) { $msg = JText::_("COM_CROWDFUNDING_DEBUG_MODE_DEFAULT_MSG"); } $this->setRedirect(JRoute::_($returnUrl, false), $msg, "notice"); return; } // Check for agreed conditions from the user. if ($params->get("backing_terms", 0)) { $terms = $this->input->get("terms", 0, "int"); if (!$terms) { $this->setRedirect(JRoute::_($returnUrl, false), JText::_("COM_CROWDFUNDING_ERROR_TERMS_NOT_ACCEPTED"), "notice"); return; } } // Check for valid amount. if (!$amount) { $this->setRedirect(JRoute::_($returnUrl, false), JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT"), "notice"); return; } // Store payment process data // Get the payment process object and // store the selected data from the user. $paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $item->id; $paymentSessionLocal = $app->getUserState($paymentSessionContext); $paymentSessionLocal->step1 = true; $paymentSessionLocal->amount = $amount; $paymentSessionLocal->rewardId = $rewardId; $app->setUserState($paymentSessionContext, $paymentSessionLocal); // Generate hash user ID used for anonymous payment. if (!$userId) { $aUserId = $app->getUserState("auser_id"); if (!$aUserId) { // Generate a hash ID for anonymous user. $anonymousUserId = new Prism\String(); $anonymousUserId->generateRandomString(32); $aUserId = (string) $anonymousUserId; $app->setUserState("auser_id", $aUserId); } } $date = new JDate(); // Create an intention record. $intentionId = 0; if (!empty($userId)) { $intentionKeys = array("user_id" => $userId, "project_id" => $item->id); $intention = new Crowdfunding\Intention(JFactory::getDbo()); $intention->load($intentionKeys); $intentionData = array("user_id" => $userId, "project_id" => $item->id, "reward_id" => $rewardId, "record_date" => $date->toSql()); $intention->bind($intentionData); $intention->store(); $intentionId = $intention->getId(); } // Create a payment session. $paymentSessionDatabase = new Crowdfunding\Payment\Session(JFactory::getDbo()); $paymentSessionData = array("user_id" => $userId, "auser_id" => $aUserId, "project_id" => $item->id, "reward_id" => $rewardId, "record_date" => $date->toSql(), "session_id" => $paymentSessionLocal->session_id, "intention_id" => $intentionId); $paymentSessionDatabase->bind($paymentSessionData); $paymentSessionDatabase->store(); // Redirect to next page $link = CrowdfundingHelperRoute::getBackingRoute($item->slug, $item->catslug, "payment"); $this->setRedirect(JRoute::_($link, false)); }
<div class="panel panel-default"> <div class="panel-heading"> <h2><?php echo JText::_("COM_CROWDFUNDING_INVESTMENT_SUMMARY"); ?> </h2> </div> <div class="panel-body"> <p><?php $amount = $this->amount->setValue($this->paymentAmount)->formatCurrency(); echo JText::sprintf("COM_CROWDFUNDING_INVESTMENT_AMOUNT", $amount); ?> </p> <p><?php echo JText::_("COM_CROWDFUNDING_FUNDING_TYPE_" . Joomla\String\String::strtoupper($this->item->funding_type)); ?> </p> <p class="bg-info p-5"> <span class="glyphicon glyphicon-info-sign"></span> <?php $endDate = JHtml::_('date', $this->item->funding_end, JText::_('DATE_FORMAT_LC3')); if ($this->item->funding_type == "FIXED") { $goal = $this->amount->setValue($this->item->goal)->formatCurrency(); echo JText::sprintf("COM_CROWDFUNDING_FUNDING_TYPE_INFO_FIXED", $goal, $endDate); } else { echo JText::sprintf("COM_CROWDFUNDING_FUNDING_TYPE_INFO_FLEXIBLE", $endDate); } ?> </p>
/** * Import states that are based on not official states data, * and which are not connected to locations IDs. * * @param SimpleXMLElement $content * * @todo remove this in next major version. */ protected function importUnofficialStates($content) { if (!empty($content)) { $states = array(); $db = $this->getDbo(); foreach ($content->city as $item) { // Check for missing ascii characters title $name = Joomla\String\String::trim($item->name); if (!$name) { continue; } $code = Joomla\String\String::trim($item->state_code); $states[$code][] = "(" . $db->quoteName("name") . "=" . $db->quote($name) . " AND " . $db->quoteName("country_code") . "=" . $db->quote("US") . ")"; } foreach ($states as $stateCode => $cities) { $query = $db->getQuery(true); $query->update("#__crowdf_locations")->set($db->quoteName("state_code") . " = " . $db->quote($stateCode))->where(implode(" OR ", $cities)); $db->setQuery($query); $db->execute(); } unset($states); unset($content); } }
protected function getOrderString() { $params = $this->getState("params"); $order = $params->get("items_order", "start_date"); $orderDirn = $params->get("items_order_direction", "desc"); $allowedDirns = array("asc", "desc"); if (!in_array($orderDirn, $allowedDirns)) { $orderDirn = "ASC"; } else { $orderDirn = Joomla\String\String::strtoupper($orderDirn); } switch ($order) { case "ordering": $orderCol = "a.ordering"; break; case "added": $orderCol = "a.id"; break; default: // Start date $orderCol = "a.funding_start"; break; } $orderString = $orderCol . ' ' . $orderDirn; return $orderString; }
/** * Invoke the plugin method onPaymentsCompleteCheckout. * * @throws UnexpectedValueException * @throws Exception */ public function completeCheckout() { // Get component parameters $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Check for disabled payment functionality if ($params->get("debug_payment_disabled", 0)) { throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE")); } $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $output = array(); // Get payment gateway name. $paymentService = $this->input->get("payment_service"); if (!$paymentService) { throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PAYMENT_GATEWAY")); } // Set the name of the payment service to session. $this->paymentProcess->paymentService = $paymentService; // Trigger the event try { $context = 'com_crowdfunding.payments.completeCheckout.' . Joomla\String\String::strtolower($paymentService); // Import Crowdfunding Payment Plugins $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('crowdfundingpayment'); // Trigger onContentPreparePayment event. $results = $dispatcher->trigger("onPaymentsCompleteCheckout", 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 (UnexpectedValueException $e) { $this->setMessage($e->getMessage(), "notice"); $this->setRedirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute(), false)); return; } catch (Exception $e) { // Store log data in the database $this->log->add(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM"), "CONTROLLER_PAYMENTS_CHECKOUT_ERROR", $e->getMessage()); throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_SYSTEM")); } $redirectUrl = Joomla\Utilities\ArrayHelper::getValue($output, "redirect_url"); $message = Joomla\Utilities\ArrayHelper::getValue($output, "message"); if (!$redirectUrl) { throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_REDIRECT_URL")); } // Store the payment process data into the session. $app->setUserState($this->paymentProcessContext, $this->paymentProcess); if (!$message) { $this->setRedirect($redirectUrl); } else { $this->setRedirect($redirectUrl, $message, "notice"); } }
/** * Upload a pitch image. * * @param array $image * * @throws Exception * * @return array */ public function uploadPitchImage($image) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ $uploadedFile = Joomla\Utilities\ArrayHelper::getValue($image, 'tmp_name'); $uploadedName = Joomla\Utilities\ArrayHelper::getValue($image, 'name'); $errorCode = Joomla\Utilities\ArrayHelper::getValue($image, 'error'); // Load parameters. $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ $destFolder = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $params->get("images_directory", "images/crowdfunding")); $tmpFolder = $app->get("tmp_path"); // Joomla! media extension parameters $mediaParams = JComponentHelper::getParams("com_media"); /** @var $mediaParams Joomla\Registry\Registry */ $file = new Prism\File\File(); // Prepare size validator. $KB = 1024 * 1024; $fileSize = (int) $app->input->server->get('CONTENT_LENGTH'); $uploadMaxSize = $mediaParams->get("upload_maxsize") * $KB; $sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize); // Prepare server validator. $serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE)); // Prepare image validator. $imageValidator = new Prism\File\Validator\Image($uploadedFile, $uploadedName); // Get allowed mime types from media manager options $mimeTypes = explode(",", $mediaParams->get("upload_mime")); $imageValidator->setMimeTypes($mimeTypes); // Get allowed image extensions from media manager options $imageExtensions = explode(",", $mediaParams->get("image_extensions")); $imageValidator->setImageExtensions($imageExtensions); $file->addValidator($sizeValidator)->addValidator($imageValidator)->addValidator($serverValidator); // Validate the file if (!$file->isValid()) { throw new RuntimeException($file->getError()); } // Generate temporary file name $ext = Joomla\String\String::strtolower(JFile::makeSafe(JFile::getExt($image['name']))); $generatedName = new Prism\String(); $generatedName->generateRandomString(32); $tmpDestFile = $tmpFolder . DIRECTORY_SEPARATOR . $generatedName . "." . $ext; // Prepare uploader object. $uploader = new Prism\File\Uploader\Local($uploadedFile); $uploader->setDestination($tmpDestFile); // Upload temporary file $file->setUploader($uploader); $file->upload(); // Get file $tmpDestFile = $file->getFile(); if (!is_file($tmpDestFile)) { throw new Exception('COM_CROWDFUNDING_ERROR_FILE_CANT_BE_UPLOADED'); } // Resize image $image = new JImage(); $image->loadFile($tmpDestFile); if (!$image->isLoaded()) { throw new Exception(JText::sprintf('COM_CROWDFUNDING_ERROR_FILE_NOT_FOUND', $tmpDestFile)); } $imageName = $generatedName . "_pimage.png"; $imageFile = JPath::clean($destFolder . DIRECTORY_SEPARATOR . $imageName); // Create main image $width = $params->get("pitch_image_width", 600); $height = $params->get("pitch_image_height", 400); $image->resize($width, $height, false); $image->toFile($imageFile, IMAGETYPE_PNG); // Remove the temporary if (is_file($tmpDestFile)) { JFile::delete($tmpDestFile); } return $imageName; }
/** * Return payment receiver. * * @param $paymentReceiverOption * @param $itemId * * @return null|string */ protected function getPaymentReceiver($paymentReceiverOption, $itemId) { if ($this->params->get('paypal_sandbox', 1)) { return Joomla\String\String::strtolower(Joomla\String\String::trim($this->params->get('paypal_sandbox_business_name'))); } else { if (strcmp("site_owner", $paymentReceiverOption) == 0) { // Site owner return Joomla\String\String::strtolower(Joomla\String\String::trim($this->params->get('paypal_business_name'))); } else { if (!JComponentHelper::isEnabled("com_crowdfundingfinance")) { return null; } else { $payout = new CrowdfundingFinance\Payout(JFactory::getDbo()); $payout->load($itemId); if (!$payout->getPaypalEmail()) { return null; } return Joomla\String\String::strtolower(Joomla\String\String::trim($payout->getPaypalEmail())); } } } }
/** * Method to set up the document properties * * @return void */ protected function setDocument() { $this->document->setTitle($this->documentTitle); $layout = $this->getLayout(); // Scripts JHtml::_('jquery.framework'); JHtml::_('bootstrap.tooltip'); switch ($layout) { case "files": // HTML Helpers JHtml::_('prism.ui.pnotify'); JHtml::_("prism.ui.joomlaHelper"); // Load language string in JavaScript JText::script('COM_CROWDFUNDING_DELETE_FILE_QUESTION'); break; } $this->document->addScript('../media/' . $this->option . '/js/admin/' . Joomla\String\String::strtolower($this->getName()) . '.js'); }
/** * Upload images. * * @param array $files * @param string $destFolder * @param array $rewardsIds * * @return array */ public function uploadImages($files, $destFolder, $rewardsIds) { // Load parameters. $params = JComponentHelper::getParams($this->option); /** @var $params Joomla\Registry\Registry */ // Joomla! media extension parameters $mediaParams = JComponentHelper::getParams("com_media"); /** @var $mediaParams Joomla\Registry\Registry */ $KB = 1024 * 1024; $uploadMaxSize = $mediaParams->get("upload_maxsize") * $KB; $mimeTypes = explode(",", $mediaParams->get("upload_mime")); $imageExtensions = explode(",", $mediaParams->get("image_extensions")); $images = array(); foreach ($files as $rewardId => $image) { // If the image is set to not valid reward, continue to next one. // It is impossible to store image to missed reward. if (!in_array($rewardId, $rewardsIds)) { continue; } $uploadedFile = Joomla\Utilities\ArrayHelper::getValue($image, 'tmp_name'); $uploadedName = Joomla\String\String::trim(Joomla\Utilities\ArrayHelper::getValue($image, 'name')); $errorCode = Joomla\Utilities\ArrayHelper::getValue($image, 'error'); $file = new Prism\File\Image(); if (!empty($uploadedName)) { // Prepare size validator. $fileSize = (int) Joomla\Utilities\ArrayHelper::getValue($image, 'size'); // Prepare file 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)); // Prepare image validator. $imageValidator = new Prism\File\Validator\Image($uploadedFile, $uploadedName); // Get allowed mime types from media manager options $imageValidator->setMimeTypes($mimeTypes); // Get allowed image extensions from media manager options $imageValidator->setImageExtensions($imageExtensions); $file->addValidator($sizeValidator)->addValidator($imageValidator)->addValidator($serverValidator); // Validate the file if (!$file->isValid()) { continue; } // Generate temporary file name $ext = Joomla\String\String::strtolower(JFile::makeSafe(JFile::getExt($image['name']))); $generatedName = new Prism\String(); $generatedName->generateRandomString(12, "reward_"); $destFile = JPath::clean($destFolder . DIRECTORY_SEPARATOR . $generatedName . "." . $ext); // Prepare uploader object. $uploader = new Prism\File\Uploader\Local($uploadedFile); $uploader->setDestination($destFile); // Upload temporary file $file->setUploader($uploader); $file->upload(); // Get file $imageSource = $file->getFile(); if (!is_file($imageSource)) { continue; } // Generate thumbnails. // Create thumbnail. $generatedName->generateRandomString(12, "reward_thumb_"); $options = array("width" => $params->get("rewards_image_thumb_width", 200), "height" => $params->get("rewards_image_thumb_height", 200), "scale" => $params->get("image_resizing_scale", JImage::SCALE_INSIDE), "destination" => JPath::clean($destFolder . DIRECTORY_SEPARATOR . $generatedName . "." . $ext)); $thumbSource = $file->createThumbnail($options); // Create square image. $generatedName->generateRandomString(12, "reward_square_"); $options = array("width" => $params->get("rewards_image_square_width", 50), "height" => $params->get("rewards_image_square_height", 50), "scale" => $params->get("image_resizing_scale", JImage::SCALE_INSIDE), "destination" => JPath::clean($destFolder . DIRECTORY_SEPARATOR . $generatedName . "." . $ext)); $squareSource = $file->createThumbnail($options); $names = array("image" => "", "thumb" => "", "square" => ""); $names['image'] = basename($imageSource); $names["thumb"] = basename($thumbSource); $names["square"] = basename($squareSource); $images[$rewardId] = $names; } } return $images; }
/** * Check the system for debug mode */ protected function prepareDebugMode() { // Check for maintenance (debug) state $params = $this->state->get("params"); $this->debugMode = $params->get("debug_project_adding_disabled", 0); if ($this->debugMode) { $msg = Joomla\String\String::trim($params->get("debug_disabled_functionality_msg")); if (!$msg) { $msg = JText::_("COM_CROWDFUNDING_DEBUG_MODE_DEFAULT_MSG"); } $this->app->enqueueMessage($msg, "notice"); $this->disabledButton = 'disabled="disabled"'; } }
?> : <input name="modal-video-width" id="modal-video-width" type="text" maxlength="5" size="5" value="" /> <?php echo JText::_('COM_KUNENA_EDITOR_MODAL_TITLE_LINK_SETTINGS_HEIGHT'); ?> : <input name="modal-video-height" id="modal-video-height" type="text" maxlength="5" size="5" value="" /> <?php echo JText::_('COM_KUNENA_EDITOR_VIDEO_PROVIDER'); ?> <select id="kvideoprovider-list-modal" name="provider" class="kbutton"> <?php $vid_provider = array('', 'Bofunk', 'Break', 'Clipfish', 'DivX,divx]http://', 'Flash,flash]http://', 'FlashVars,flashvars param=]http://', 'MediaPlayer,mediaplayer]http://', 'Metacafe', 'MySpace', 'QuickTime,quicktime]http://', 'RealPlayer,realplayer]http://', 'RuTube', 'Sapo', 'Streetfire', 'Veoh', 'Videojug', 'Vimeo', 'Wideo.fr', 'YouTube'); foreach ($vid_provider as $vid_type) { $vid_type = explode(',', $vid_type); echo '<option value = "' . (!empty($vid_type[1]) ? $this->escape($vid_type[1]) : Joomla\String\String::strtolower($this->escape($vid_type[0])) . '') . '">' . $this->escape($vid_type[0]) . '</option>'; } ?> </select> <?php echo JText::_('COM_KUNENA_EDITOR_MODAL_TITLE_LINK_SETTINGS_ID'); ?> : <input name="modal-video-id" id="modal-video-id" type="text" maxlength="30" size="11" value="" /></p> </div> <div class="modal-footer"> <button id="videosettings-modal-submit" class="btn btn-primary"><?php echo JText::_('COM_KUNENA_EDITOR_MODAL_ADD_LABEL'); ?> </button> <button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo JText::_('COM_KUNENA_EDITOR_MODAL_CLOSE_LABEL');
/** * @param $alias * * @return array */ public static function resolveAlias($alias) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; $db = JFactory::getDbo(); $query = "SELECT * FROM #__kunena_aliases WHERE alias LIKE {$db->Quote($alias . '%')}"; $db->setQuery($query); $aliases = $db->loadObjectList(); $vars = array(); foreach ($aliases as $object) { if (Joomla\String\String::strtolower($alias) == Joomla\String\String::strtolower($object->alias)) { $var = $object->type != 'legacy' ? $object->type : 'view'; $vars[$var] = $object->type != 'layout' ? $object->item : preg_replace('/.*\\./', '', $object->item); if ($var == 'catid') { $vars['view'] = 'category'; } break; } } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $vars; }
/** * Validate a date * * @param string $string * * @return boolean * @deprecated deprecated since version 1.8 */ public static function isValidDate($string) { $string = Joomla\String\String::trim($string); try { $date = new DateTime($string); } catch (Exception $e) { return false; } $month = $date->format('m'); $day = $date->format('d'); $year = $date->format('Y'); if (checkdate($month, $day, $year)) { return true; } else { return false; } }
public function dovoid() { // Get component parameters $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Check for disabled payment functionality if ($params->get("debug_payment_disabled", 0)) { throw new Exception(JText::_($this->text_prefix . "_ERROR_PAYMENT_HAS_BEEN_DISABLED_MESSAGE")); } $app = JFactory::getApplication(); /** @var $app JApplicationAdministrator */ $cid = $this->input->get("cid", array(), "array"); JArrayHelper::toInteger($cid); $messages = array(); try { if (!empty($cid)) { $options = array("ids" => $cid, "txn_status" => "pending"); $items = new Crowdfunding\Transactions(JFactory::getDbo()); $items->load($options); if (count($items) == 0) { throw new UnexpectedValueException(JText::_($this->text_prefix . "_ERROR_INVALID_TRANSACTIONS")); } // Import Crowdfunding Payment Plugins $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('crowdfundingpayment'); foreach ($items as $item) { $context = $this->option . '.payments.void.' . Joomla\String\String::strtolower(str_replace(" ", "", $item->service_provider)); // Trigger onContentPreparePayment event. $results = $dispatcher->trigger("onPaymentsVoid", array($context, &$item, &$params)); foreach ($results as $message) { if (!is_null($message) and is_array($message)) { $messages[] = $message; } } } } } catch (UnexpectedValueException $e) { $this->setMessage($e->getMessage(), "notice"); $this->setRedirect(JRoute::_("index.php?option=" . $this->option . "&view=transactions", false)); return; } catch (Exception $e) { // Store log data in the database $this->log->add(JText::_($this->text_prefix . "_ERROR_SYSTEM"), "CONTROLLER_PAYMENTS_DOCAPTURE_ERROR", $e->getMessage()); throw new Exception(JText::_($this->text_prefix . "_ERROR_SYSTEM")); } // Set messages. if (!empty($messages)) { foreach ($messages as $message) { $app->enqueueMessage($message["text"], $message["type"]); } } $this->setRedirect(JRoute::_("index.php?option=" . $this->option . "&view=transactions", false)); }
/** * @param $a * @param $b * * @return integer */ public static function compareByNameDesc($a, $b) { if (!isset(self::$_instances[$a]) || !isset(self::$_instances[$b])) { return 0; } return Joomla\String\String::strcasecmp(self::$_instances[$b]->name, self::$_instances[$a]->name); }
/** * Method to set up the document properties * * @return void */ protected function setDocument() { $this->document->setTitle(JText::_('COM_CROWDFUNDING_IMPORT_MANAGER')); // Scripts JHtml::_('behavior.formvalidation'); JHtml::_('bootstrap.tooltip'); JHtml::_('prism.ui.bootstrap2FileInput'); $this->document->addScript('../media/' . $this->option . '/js/admin/' . Joomla\String\String::strtolower($this->getName()) . '.js'); }
/** * Method to set up the document properties. * * @return void */ protected function setDocument() { $this->document->setTitle(JText::_('COM_CROWDFUNDING_REPORTS_MANAGER')); // Scripts JHtml::_('behavior.multiselect'); JHtml::_('bootstrap.tooltip'); JHtml::_('formbehavior.chosen', 'select'); JHtml::_('prism.ui.joomlaList'); $this->document->addScript('../media/' . $this->option . '/js/admin/' . Joomla\String\String::strtolower($this->getName()) . '.js'); }
/** * Upload file by passing it by HTML input * * @param array $fileInput The file object returned by JInput * @param string $destination The path of destination of file uploaded * @param string $type The type of file uploaded: attachment or avatar * * @return object */ public function upload($fileInput, $destination, $type = 'attachment') { $file = new stdClass(); $file->ext = JFile::getExt($fileInput['name']); $file->size = $fileInput['size']; $file->tmp_name = $fileInput['tmp_name']; $file->error = $fileInput['error']; $file->destination = $destination . '.' . $file->ext; $file->success = false; $file->isAvatar = false; if ($type != 'attachment') { $file->isAvatar = true; } if (!is_uploaded_file($file->tmp_name)) { $exception = $this->checkUpload($fileInput); if ($exception) { throw $exception; } } elseif ($file->error != 0) { throw new RuntimeException(JText::_('COM_KUNENA_UPLOAD_ERROR_NOT_UPLOADED'), 500); } // Check if file extension matches any allowed extensions (case insensitive) foreach ($this->validExtensions as $ext) { $extension = Joomla\String\String::substr($file->tmp_name, -Joomla\String\String::strlen($ext)); if (Joomla\String\String::strtolower($extension) == Joomla\String\String::strtolower($ext)) { // File must contain one letter before extension $name = Joomla\String\String::substr($file->tmp_name, 0, -Joomla\String\String::strlen($ext)); $extension = Joomla\String\String::substr($extension, 1); if (!$name) { throw new RuntimeException(JText::sprintf('COM_KUNENA_UPLOAD_ERROR_EXTENSION_FILE', implode(', ', $this->validExtensions)), 400); } } } if (!$this->checkFileSize($file->size, true)) { if ($file->isAvatar) { throw new RuntimeException(JText::_('COM_KUNENA_UPLOAD_ERROR_AVATAR_EXCEED_LIMIT_IN_CONFIGURATION'), 500); } else { throw new RuntimeException(JText::_('COM_KUNENA_UPLOAD_ERROR_FILE_EXCEED_LIMIT_IN_CONFIGURATION'), 500); } } if (!KunenaFile::copy($file->tmp_name, $file->destination)) { throw new RuntimeException(JText::_('COM_KUNENA_UPLOAD_ERROR_FILE_RIGHT_MEDIA_DIR'), 500); } unlink($file->tmp_name); KunenaPath::setPermissions($file->destination); $file->success = true; return $file; }
/** * Method to set up the document properties * * @return void */ protected function setDocument() { $this->document->setTitle($this->documentTitle); // Add scripts JHtml::_('behavior.keepalive'); JHtml::_('behavior.formvalidation'); JHtml::_('formbehavior.chosen', 'select'); JHtml::_('bootstrap.tooltip'); JHtml::_('prism.ui.bootstrap2FileInput'); JHtml::_('prism.ui.bootstrap2Typeahead'); JHtml::_("prism.ui.joomlaHelper"); $this->document->addScript('../media/' . $this->option . '/js/admin/' . Joomla\String\String::strtolower($this->getName()) . '.js'); }
/** * @param string $alias * * @return boolean */ public function deleteAlias($alias) { // Do not delete valid alias. if (Joomla\String\String::strtolower($this->alias) == Joomla\String\String::strtolower($alias)) { return false; } $db = JFactory::getDbo(); $query = "DELETE FROM #__kunena_aliases WHERE type='catid' AND item={$db->Quote($this->id)} AND alias={$db->Quote($alias)}"; $db->setQuery($query); $db->execute(); KunenaError::checkDatabaseError(); return (bool) $db->getAffectedRows(); }