protected function getCancelUrl() { $page = JString::trim($this->params->get('paypal_cancel_url')); if (!$page) { $uri = JURI::getInstance(); $page = $uri->toString(array("scheme", "host")) . JRoute::_(VirtualCurrencyHelperRoute::getPaymentRoute("default"), false); } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_CANCEL_URL"), $this->debugType, $page) : null; return $page; }
protected static function findItem($needles = null) { $app = JFactory::getApplication(); $menus = $app->getMenu('site'); // Prepare the reverse lookup array. // Collect all menu items and creat an array that contains // the ID from the query string of the menu item as a key, // and the menu item id (Itemid) as a value // Example: // array( "category" => // 1(id) => 100 (Itemid), // 2(id) => 101 (Itemid) // ); if (self::$lookup === null) { self::$lookup = array(); $component = JComponentHelper::getComponent('com_virtualcurrency'); $items = $menus->getItems('component_id', $component->id); if ($items) { foreach ($items as $item) { if (isset($item->query) && isset($item->query['view'])) { $view = $item->query['view']; if (!isset(self::$lookup[$view])) { self::$lookup[$view] = array(); } if (isset($item->query['id'])) { self::$lookup[$view][$item->query['id']] = $item->id; } else { // If it is a root element that have no a request parameter ID ( categories, authors ), we set 0 for an key self::$lookup[$view][0] = $item->id; } } } } } if ($needles) { foreach ($needles as $view => $ids) { if (isset(self::$lookup[$view])) { foreach ($ids as $id) { if (isset(self::$lookup[$view][(int) $id])) { return self::$lookup[$view][(int) $id]; } } } } } else { $active = $menus->getActive(); if ($active) { return $active->id; } } return null; }
/** * Send emails to the administrator and buyer of units. * * @param object $currency * @param object $transaction * @param Joomla\Registry\Registry $params */ protected function sendMails($currency, $transaction, $params) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get website $uri = JUri::getInstance(); $website = $uri->toString(array("scheme", "host")); $emailMode = $this->params->get("email_mode", "plain"); jimport("virtualcurrency.currency"); $units = VirtualCurrencyCurrency::getInstance(JFactory::getDbo(), $currency->id); jimport("virtualcurrency.realcurrency"); $currencyId = $params->get("payments_currency_id"); $realCurrency = VirtualCurrencyRealCurrency::getInstance(JFactory::getDbo(), $currencyId, $params); // Prepare data for parsing $data = array("site_name" => $app->get("sitename"), "site_url" => JUri::root(), "item_title" => $currency->title, "order_url" => $website . JRoute::_(VirtualCurrencyHelperRoute::getAccountsRoute()), "units" => $units->getAmountString($transaction->units), "units_title" => $units->getTitle(), "amount" => $realCurrency->getAmountString($transaction->txn_amount), "transaction_id" => $transaction->txn_id); // DEBUG DATA JDEBUG ? $this->log->add($this->textPrefix . "_DEBUG_MAIL_DATA", $this->debugType, var_export($data, true)) : null; // Send mail to the administrator $emailId = $this->params->get("admin_mail_id", 0); if (!empty($emailId)) { jimport("virtualcurrency.email"); $email = new VirtualCurrencyEmail(); $email->setDb(JFactory::getDbo()); $email->load($emailId); if (!$email->getSenderName()) { $email->setSenderName($app->get("fromname")); } if (!$email->getSenderEmail()) { $email->setSenderEmail($app->get("mailfrom")); } $recipientName = $email->getSenderName(); $recipientMail = $email->getSenderEmail(); // Prepare data for parsing $data["sender_name"] = $email->getSenderName(); $data["sender_email"] = $email->getSenderEmail(); $data["recipient_name"] = $recipientName; $data["recipient_email"] = $recipientMail; $email->parse($data); $subject = $email->getSubject(); $body = $email->getBody($emailMode); $mailer = JFactory::getMailer(); if (strcmp("html", $emailMode) == 0) { // Send as HTML message $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, VirtualCurrencyConstants::MAIL_MODE_HTML); } else { // Send as plain text. $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, VirtualCurrencyConstants::MAIL_MODE_PLAIN_TEXT); } // Check for an error. if ($return !== true) { $this->log->add(JText::_($this->textPrefix . "_ERROR_MAIL_SENDING_ADMIN"), $this->debugType); } } // Send mail to buyer $emailId = $this->params->get("user_mail_id", 0); $userId = $transaction->receiver_id; if (!empty($emailId) and !empty($userId)) { $email = new VirtualCurrencyEmail(); $email->setDb(JFactory::getDbo()); $email->load($emailId); if (!$email->getSenderName()) { $email->setSenderName($app->get("fromname")); } if (!$email->getSenderEmail()) { $email->setSenderEmail($app->get("mailfrom")); } $user = JFactory::getUser($userId); $recipientName = $user->get("name"); $recipientMail = $user->get("email"); // Prepare data for parsing $data["sender_name"] = $email->getSenderName(); $data["sender_email"] = $email->getSenderEmail(); $data["recipient_name"] = $recipientName; $data["recipient_email"] = $recipientMail; $email->parse($data); $subject = $email->getSubject(); $body = $email->getBody($emailMode); $mailer = JFactory::getMailer(); if (strcmp("html", $emailMode) == 0) { // Send as HTML message $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, VirtualCurrencyConstants::MAIL_MODE_HTML); } else { // Send as plain text. $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, VirtualCurrencyConstants::MAIL_MODE_PLAIN_TEXT); } // Check for an error. if ($return !== true) { // Log error $this->log->add(JText::_($this->textPrefix . "_ERROR_MAIL_SENDING_USER"), $this->debugType); } } }