align="right" width="80"> <?php echo $r->gross_amount; ?> € </td> </tr> <?php } ?> </tbody> <tfoot> <tr style="background-color: black; color: white; font-weight: bold;"> <td colspan="4"> <?php echo JText::sprintf('COM_AKEEBASUBS_REPORTS_INVOICES_LBL_COUNTRYTOTAL', AkeebasubsHelperSelect::formatCountry($lastCountry), $countryInvoicesShown); ?> </td> <td align="right"> <?php echo $countryNet; ?> € </td> <td></td> <td align="right"> <?php echo $countryTax; ?> € </td>
/** * 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; }
/** * This method is called whenever Akeeba Subscriptions is updating the user * record with new information, either during sign-up or when you manually * update this information in the back-end. * * In this plugin, it does nothing, but it serves as an example for any * developer interested in creating, for example, a "bridge" with a social * component like Community Builder or JomSocial. * * @param AkeebasubsTableUser $userData The user data */ public function onAKUserSaveData($userData) { // Get the user ID $user_id = $userData->user_id; // Initialise the data array $data = $userData->getData(); // Remove the params field $params = array(); if (isset($data['params'])) { $params = $data['params']; if (is_string($params)) { $params = json_decode($params, true); } elseif (is_object($params)) { $params = (array) $params; } unset($data['params']); } // Remove some fields which must not be saved foreach (array('akeebasubs_user_id', 'user_id', 'notes', 'input') as $key) { if (isset($data[$key])) { unset($data[$key]); } } // Translate country and state if (!class_exists('AkeebasubsHelperSelect')) { require_once JPATH_ADMINISTRATOR . '/components/com_akeebasubs/helpers/select.php'; } if (isset($data['state'])) { $data['state'] = AkeebasubsHelperSelect::formatState($data['state']); } if (isset($data['country'])) { $data['country'] = AkeebasubsHelperSelect::formatCountry($data['country']); } // Rename the ZIP field if (isset($data['zip'])) { $data['postal_code'] = $data['zip']; unset($data['zip']); } // Rename the state field if (isset($data['state'])) { $data['region'] = $data['state']; unset($data['state']); } // Convert basic data foreach (array_keys($data) as $key) { $data['profile.' . $key] = json_encode($data[$key]); unset($data[$key]); } // Explode the params field (unless it's an array or object) if (!empty($params)) { foreach ($params as $k => $v) { $data['akeebasubs.' . $k] = json_encode($v); } } $db = JFactory::getDbo(); $result = true; // Loop through all keys, check if they already exist and create/replace them if (count($data)) { foreach ($data as $k => $v) { // Check for an existing record $query = $db->getQuery(true)->select('*')->from($db->qn('#__user_profiles'))->where($db->qn('user_id') . '=' . $db->q($user_id))->where($db->qn('profile_key') . '=' . $db->q($k)); $db->setQuery($query); $existing = $db->loadObject(); if (is_object($existing)) { // The record exists. Delete it. $query = $db->getQuery(true)->delete($db->qn('#__user_profiles'))->where($db->qn('user_id') . '=' . $db->q($user_id))->where($db->qn('profile_key') . '=' . $db->q($k)); $db->setQuery($query); $db->execute(); } // Insert the new record $o = array('user_id' => $user_id, 'profile_key' => $k, 'profile_value' => $v, 'ordering' => 1); $o = (object) $o; $result = $result && $db->insertObject('#__user_profiles', $o); } } return $result; }