Exemplo n.º 1
0
 public static function getURL($filename)
 {
     // Get the base site URL
     $url = JURI::base();
     $url = rtrim($url, '/');
     // Take into account relative URL for administrator
     list($isCLI, $isAdmin) = F0FDispatcher::isCliAdmin();
     if ($isAdmin) {
         $url .= '/..';
     }
     if (!class_exists('AkeebasubsHelperCparams')) {
         require_once JPATH_ADMINISTRATOR . '/components/com_akeebasubs/helpers/cparams.php';
     }
     $imagePath = trim(AkeebasubsHelperCparams::getParam('imagedir', 'images/'), '/');
     if (version_compare(JVERSION, '3.0', 'le')) {
         // Joomla! 2.5 : Pretty much straightforward
         return $url . '/' . $imagePath . '/' . $filename;
     } else {
         // Joomla! 3.0+ : Where the heck is the image?
         $testJ25 = JPATH_SITE . '/' . $imagePath . '/' . $filename;
         $testJ30 = JPATH_SITE . '/' . $filename;
         if (file_exists($testJ30)) {
             return $url . '/' . $filename;
         } else {
             return $url . '/' . $imagePath . '/' . $filename;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * getComponentParam.
  *
  * @param   string  $option   Params
  * @param   string  $key      Params
  * @param   string  $default  Params
  *
  * @return	string.
  */
 public static function getComponentParam($option, $key, $default = null)
 {
     jimport('joomla.application.component.helper');
     if (F0FDispatcher::isCliAdmin()) {
         $params = JComponentHelper::getParams($option);
     } else {
         $app = JFactory::getApplication();
         $params = $app->getParams($option);
     }
     return $params->get($key, $default);
 }
Exemplo n.º 3
0
 /**
  * Pre-processes the message text in $text, replacing merge tags with those
  * fetched based on subscription $sub
  *
  * @param   string  $text    The message to process
  * @param   AkeebasubsTableSubscription  $sub  A subscription object
  *
  * @return  string  The processed string
  */
 public static function processSubscriptionTags($text, $sub, $extras = array())
 {
     // Get the user object for this subscription
     $user = JFactory::getUser($sub->user_id);
     // Get the extra user parameters object for the subscription
     $kuser = F0FModel::getTmpInstance('Users', 'AkeebasubsModel')->user_id($sub->user_id)->getFirstItem();
     // Get the subscription level
     $level = F0FModel::getTmpInstance('Levels', 'AkeebasubsModel')->getItem($sub->akeebasubs_level_id);
     // Merge the user objects
     $userdata = array_merge((array) $user, (array) $kuser->getData());
     // Create and replace merge tags for subscriptions. Format [SUB:KEYNAME]
     if ($sub instanceof AkeebasubsTableSubscription) {
         $subData = (array) $sub->getData();
     } else {
         $subData = (array) $sub;
     }
     foreach ($subData as $k => $v) {
         if (is_array($v) || is_object($v)) {
             continue;
         }
         if (substr($k, 0, 1) == '_') {
             continue;
         }
         if ($k == 'akeebasubs_subscription_id') {
             $k = 'id';
         }
         $tag = '[SUB:' . strtoupper($k) . ']';
         if (in_array($k, array('net_amount', 'gross_amount', 'tax_amount', 'prediscount_amount', 'discount_amount', 'affiliate_comission'))) {
             $v = sprintf('%.2f', $v);
         }
         $text = str_replace($tag, $v, $text);
     }
     // Create and replace merge tags for the subscription level. Format [LEVEL:KEYNAME]
     $levelData = (array) $level->getData();
     foreach ($levelData as $k => $v) {
         if (is_array($v) || is_object($v)) {
             continue;
         }
         if (substr($k, 0, 1) == '_') {
             continue;
         }
         if ($k == 'akeebasubs_level_id') {
             $k = 'id';
         }
         $tag = '[LEVEL:' . strtoupper($k) . ']';
         $text = str_replace($tag, $v, $text);
     }
     // Create and replace merge tags for custom per-subscription data. Format [SUBCUSTOM:KEYNAME]
     if (array_key_exists('params', $subData)) {
         if (is_string($subData['params'])) {
             $custom = json_decode($subData['params'], true);
         } elseif (is_array($subData['params'])) {
             $custom = $subData['params'];
         } elseif (is_object($subData['params'])) {
             $custom = (array) $subData['params'];
         } else {
             $custom = array();
         }
         // Extra check for subcustom params: if you save a subscription form the backend,
         // custom fields are inside an array named subcustom
         if (is_array($custom) && isset($custom['subcustom'])) {
             $custom = $custom['subcustom'];
         }
         if (!empty($custom)) {
             foreach ($custom as $k => $v) {
                 if (is_object($v)) {
                     continue;
                 }
                 if (substr($k, 0, 1) == '_') {
                     continue;
                 }
                 $tag = '[SUBCUSTOM:' . strtoupper($k) . ']';
                 if (is_array($v)) {
                     continue;
                 }
                 $text = str_replace($tag, $v, $text);
             }
         }
     }
     // Create and replace merge tags for user data. Format [USER:KEYNAME]
     foreach ($userdata as $k => $v) {
         if (is_object($v) || is_array($v)) {
             continue;
         }
         if (substr($k, 0, 1) == '_') {
             continue;
         }
         if ($k == 'akeebasubs_subscription_id') {
             $k = 'id';
         }
         $tag = '[USER:'******']';
         $text = str_replace($tag, $v, $text);
     }
     // Create and replace merge tags for custom fields data. Format [CUSTOM:KEYNAME]
     if (array_key_exists('params', $userdata)) {
         if (is_string($userdata['params'])) {
             $custom = json_decode($userdata['params']);
         } elseif (is_array($userdata['params'])) {
             $custom = $userdata['params'];
         } elseif (is_object($userdata['params'])) {
             $custom = (array) $userdata['params'];
         } else {
             $custom = array();
         }
         if (!empty($custom)) {
             foreach ($custom as $k => $v) {
                 if (substr($k, 0, 1) == '_') {
                     continue;
                 }
                 $tag = '[CUSTOM:' . strtoupper($k) . ']';
                 if (is_array($v)) {
                     $v = implode(', ', $v);
                 }
                 $text = str_replace($tag, $v, $text);
             }
         }
     }
     // Extra variables replacement
     // -- Coupon code
     $couponcode = '';
     if ($sub->akeebasubs_coupon_id) {
         $couponData = F0FModel::getTmpInstance('Coupons', 'AkeebasubsModel')->savestate(0)->getItem($sub->akeebasubs_coupon_id);
         $couponcode = $couponData->coupon;
     }
     // -- Get the site name
     $config = JFactory::getConfig();
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $sitename = $config->get('sitename');
     } else {
         $sitename = $config->getValue('config.sitename');
     }
     // -- First/last name
     $fullname = $user->name;
     $nameParts = explode(' ', $fullname, 2);
     $firstname = array_shift($nameParts);
     $lastname = !empty($nameParts) ? array_shift($nameParts) : '';
     // -- Get the subscription level
     $level = F0FModel::getTmpInstance('Levels', 'AkeebasubsModel')->setId($sub->akeebasubs_level_id)->getItem();
     // -- Site URL
     list($isCli, $isAdmin) = F0FDispatcher::isCliAdmin();
     if ($isCli) {
         JLoader::import('joomla.application.component.helper');
         $baseURL = JComponentHelper::getParams('com_akeebasubs')->get('siteurl', 'http://www.example.com');
         $temp = str_replace('http://', '', $baseURL);
         $temp = str_replace('https://', '', $temp);
         $parts = explode($temp, '/', 2);
         $subpathURL = count($parts) > 1 ? $parts[1] : '';
     } else {
         $baseURL = JURI::base();
         $subpathURL = JURI::base(true);
     }
     $baseURL = str_replace('/administrator', '', $baseURL);
     $subpathURL = str_replace('/administrator', '', $subpathURL);
     // -- My Subscriptions URL
     if ($isAdmin || $isCli) {
         $url = 'index.php?option=com_akeebasubs&view=subscriptions&layout=default';
     } else {
         $url = str_replace('&', '&', JRoute::_('index.php?option=com_akeebasubs&view=subscriptions&layout=default'));
     }
     $url = ltrim($url, '/');
     $subpathURL = ltrim($subpathURL, '/');
     if (substr($url, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") {
         $url = substr($url, strlen($subpathURL) + 1);
     }
     $mysubsurl = rtrim($baseURL, '/') . '/' . ltrim($url, '/');
     $currency = '';
     if (!class_exists('AkeebasubsHelperCparams')) {
         @(include_once JPATH_ADMINISTRATOR . '/components/com_akeebasubs/helpers/cparams.php');
     }
     if (class_exists('AkeebasubsHelperCparams')) {
         $currency = AkeebasubsHelperCparams::getParam('currencysymbol', '€');
     }
     // Dates
     JLoader::import('joomla.utilities.date');
     $jFrom = new JDate($sub->publish_up);
     $jTo = new JDate($sub->publish_down);
     // Download ID
     $dlid = md5($user->id . $user->username . $user->password);
     // User's state, human readable
     $formatted_state = '';
     $state = $kuser->state;
     if (!empty($state)) {
         if (!class_exists('AkeebasubsHelperSelect')) {
             require_once JPATH_ADMINISTRATOR . '/components/com_akeebasubs/helpers/select.php';
         }
         $formatted_state = AkeebasubsHelperSelect::formatState($state);
     }
     // User's country, human readable
     $formatted_country = '';
     $country = $kuser->country;
     if (!empty($country)) {
         if (!class_exists('AkeebasubsHelperSelect')) {
             require_once JPATH_ADMINISTRATOR . '/components/com_akeebasubs/helpers/select.php';
         }
         $formatted_country = AkeebasubsHelperSelect::formatCountry($country);
     }
     // -- The actual replacement
     $extras = array_merge(array("\\n" => "\n", '[SITENAME]' => $sitename, '[SITEURL]' => $baseURL, '[FULLNAME]' => $fullname, '[FIRSTNAME]' => $firstname, '[LASTNAME]' => $lastname, '[USERNAME]' => $user->username, '[USEREMAIL]' => $user->email, '[LEVEL]' => $level->title, '[ENABLED]' => JText::_('COM_AKEEBASUBS_SUBSCRIPTION_COMMON_' . ($sub->enabled ? 'ENABLED' : 'DISABLED')), '[PAYSTATE]' => JText::_('COM_AKEEBASUBS_SUBSCRIPTION_STATE_' . $sub->state), '[PUBLISH_UP]' => $jFrom->format(JText::_('DATE_FORMAT_LC2'), true), '[PUBLISH_UP_EU]' => $jFrom->format('d/m/Y H:i:s', true), '[PUBLISH_UP_USA]' => $jFrom->format('m/d/Y h:i:s a', true), '[PUBLISH_UP_JAPAN]' => $jFrom->format('Y/m/d H:i:s', true), '[PUBLISH_DOWN]' => $jTo->format(JText::_('DATE_FORMAT_LC2'), true), '[PUBLISH_DOWN_EU]' => $jTo->format('d/m/Y H:i:s', true), '[PUBLISH_DOWN_USA]' => $jTo->format('m/d/Y h:i:s a', true), '[PUBLISH_DOWN_JAPAN]' => $jTo->format('Y/m/d H:i:s', true), '[MYSUBSURL]' => $mysubsurl, '[URL]' => $mysubsurl, '[CURRENCY]' => $currency, '[$]' => $currency, '[DLID]' => $dlid, '[COUPONCODE]' => $couponcode, '[USER:STATE_FORMATTED]' => $formatted_state, '[USER:COUNTRY_FORMATTED]' => $formatted_country, '[NAME]' => $firstname, '[STATE]' => JText::_('COM_AKEEBASUBS_SUBSCRIPTION_STATE_' . $sub->state), '[FROM]' => $jFrom->format(JText::_('DATE_FORMAT_LC2'), true), '[TO]' => $jTo->format(JText::_('DATE_FORMAT_LC2'), true)), $extras);
     foreach ($extras as $key => $value) {
         $text = str_replace($key, $value, $text);
     }
     return $text;
 }
Exemplo n.º 4
0
 /**
  * Autoload Toolbars
  *
  * @param   string  $class_name  The name of the class to load
  *
  * @return  void
  */
 public function autoload_fof_toolbar($class_name)
 {
     F0FPlatform::getInstance()->logDebug(__METHOD__ . "() autoloading {$class_name}");
     static $isCli = null, $isAdmin = null;
     if (is_null($isCli) && is_null($isAdmin)) {
         list($isCli, $isAdmin) = F0FDispatcher::isCliAdmin();
     }
     if (strpos($class_name, 'Toolbar') === false) {
         return;
     }
     // Change from camel cased into a lowercase array
     $class_modified = preg_replace('/(\\s)+/', '_', $class_name);
     $class_modified = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $class_modified));
     $parts = explode('_', $class_modified);
     // We need two parts in the name
     if (count($parts) != 2) {
         return;
     }
     // We need the second part to be "model"
     if ($parts[1] != 'toolbar') {
         return;
     }
     // Get the information about this class
     $component_raw = $parts[0];
     $component = 'com_' . $parts[0];
     $platformDirs = F0FPlatform::getInstance()->getPlatformBaseDirs();
     // Get the proper and alternate paths and file names
     $file = "/components/{$component}/toolbar.php";
     $path = $isAdmin || $isCli ? $platformDirs['admin'] : $platformDirs['public'];
     $altPath = $isAdmin || $isCli ? $platformDirs['public'] : $platformDirs['admin'];
     // Try to find the proper class in the proper path
     if (file_exists($path . $file)) {
         @(include_once $path . $file);
     }
     // Try to find the proper class in the alternate path
     if (!class_exists($class_name) && file_exists($altPath . $file)) {
         @(include_once $altPath . $file);
     }
     // No class found? Map to F0FToolbar
     if (!class_exists($class_name)) {
         $this->class_alias('F0FToolbar', $class_name, true);
     }
 }
Exemplo n.º 5
0
 /**
  * _onAllPages.
  *
  * @return	void
  */
 public function _onAllPages()
 {
     // On frontend, buttons must be added specifically
     list($isCli, $isAdmin) = F0FDispatcher::isCliAdmin();
     if ($isAdmin || $this->renderFrontendSubmenu) {
         $this->renderSubmenu();
     }
     if (!$isAdmin && !$this->renderFrontendButtons) {
         return;
     }
 }
Exemplo n.º 6
0
 public function onInvoicesBrowse()
 {
     //on frontend, buttons must be added specifically
     list($isCli, $isAdmin) = F0FDispatcher::isCliAdmin();
     if ($isAdmin || $this->renderFrontendSubmenu) {
         $this->renderSubmenu();
     }
     if (!$isAdmin && !$this->renderFrontendButtons) {
         return;
     }
     // Set toolbar title
     $subtitle_key = $this->input->getCmd('option', 'com_foobar') . '_TITLE_' . strtoupper($this->input->getCmd('view', 'cpanel'));
     JToolBarHelper::title(JText::_($this->input->getCmd('option', 'com_foobar')) . ' &ndash; <small>' . JText::_($subtitle_key) . '</small>', str_replace('com_', '', $this->input->getCmd('option', 'com_foobar')));
     // Add toolbar buttons
     if ($this->perms->delete) {
         JToolBarHelper::deleteList();
     }
 }
 /**
  * getControllerParams
  *
  * @return	array
  */
 public static function getControllerParams()
 {
     list($isCli, $isAdmin) = F0FDispatcher::isCliAdmin();
     $input = new F0FInput();
     $option = $input->get('option');
     $controller = $input->get('controller');
     $task = $input->get('task');
     $view = $input->get('view');
     $layout = $input->get('layout');
     $id = $input->get('id', null, 'int');
     if (!$id) {
         $cid = $input->get('cid', array(), 'ARRAY');
         if (is_array($cid) && count($cid) == 1) {
             $id = $cid[0];
         } elseif (is_numeric($cid) && $cid > 0) {
             $id = $cid;
         }
     }
     // EasyBlog
     if (!$id) {
         $id = $input->get('blogid', null, 'int');
     }
     // JoomShopping
     if (!$id) {
         $id = $input->get('product_id', null, 'int');
     }
     // Content - Front
     if (!$id) {
         $id = $input->get('a_id', null, 'int');
     }
     // SobiPro
     if (!$id) {
         $id = $input->get('sid', null, 'int');
     }
     // Zoo - Front
     if (!$id) {
         $id = $input->get('item_id', null, 'int');
     }
     // Joocial - Composer
     if (!$id) {
         $id = $input->get('ref_id', null, 'cmd');
     }
     return array($isAdmin, $option, $controller, $task, $view, $layout, $id);
 }