<commit_before><?php
/**
 *                    Jojo CMS
 *                ================
 *
 * Copyright 2007 <NAME> <<EMAIL>>
 * Copyright 2007 <NAME> <<EMAIL>>
 * Copyright 2007 <NAME> <<EMAIL>>
 *
 * See the enclosed file license.txt for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  <NAME> <<EMAIL>>
 * @author  <NAME> <<EMAIL>>
 * @author  <NAME> <<EMAIL>>
 * @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
 * @link    http://www.jojocms.org JojoCMS
 */

class JOJO_Plugin_jojo_convert_currency extends JOJO_Plugin
{
    public static function inpageconverter($content)
    {
        if (strpos($content, '[[convert_currency]]') === false) {
            return $content;
        }

        global $smarty;
        foreach (Jojo::listPlugins('classes/JOJO/Currency.php') as $pluginfile) {
            require_once($pluginfile);
            break;
        }

        $c = new JOJO_Currency_yahoo();

        $amount = Util::getFormData('amount', 1);
        $smarty->assign('from',   isset($_SESSION['jojo_currency_from'])   ? $_SESSION['jojo_currency_from'] : Jojo::getOption('currency_convert_from'));
        $smarty->assign('to',     isset($_SESSION['jojo_currency_to'])     ? $_SESSION['jojo_currency_to']   : Jojo::getOption('currency_convert_to'));
        $smarty->assign('amount', isset($_SESSION['jojo_currency_amount']) ? $_SESSION['jojo_currency_amount'] : 1);

        $smarty->assign('currencies', $c->getCurrencies()); //adds an empty element to the start of the array
        return str_replace('[[convert_currency]]', $smarty->fetch('convert-currency.tpl'), $content);
    }

    public static function inlineconverter($content)
    {
        if (strpos($content, '[[convert_currency_inline') === false) {
            return $content;
        }

        global $smarty;

        preg_match_all('/\[\[convert_currency_inline:([^\]]*)\]\]/', $content, $filters);
        $replacestring = $filters[0] ? $filters[0] : '[[convert_currency_inline]]';
        $defaulttocurrency = isset($filters[1][0]) ? $filters[1][0] : '';
        foreach (Jojo::listPlugins('classes/JOJO/Currency.php') as $pluginfile) {
            require_once($pluginfile);
            break;
        }
        $c = new JOJO_Currency_yahoo();

        /* Get Exchange Rate */
        $from   = Jojo::getOption('currency_convert_from');
        $to     = Util::getFormData('to', isset($_SESSION['jojo_currency_to']) ? $_SESSION['jojo_currency_to'] : ($defaulttocurrency ? $defaulttocurrency : Jojo::getOption('currency_convert_to')));
        $_SESSION['jojo_currency_to'] = $to;

        if ($to != $from) {
            $cacheFile = _CACHEDIR . "/currency/$from-$to";
            if (!file_exists($cacheFile) || ((time() - filemtime($cacheFile)) > 1800 )) {
                /* Update cached copy */
                foreach (Jojo::listPlugins('classes/JOJO/Currency.php') as $pluginfile) {
                    require_once($pluginfile);
                    break;
                }
                $c = new JOJO_Currency_yahoo();
                $rate = $c->getRate($from, $to, true);
                file_put_contents($cacheFile, $rate);
            } else {
                /* Use cached copy */
                $rate = file_get_contents($cacheFile);
            }

            /* Location prices in html */
            preg_match_all('#\$(^[0-9]+[0-9,.]*)#', $content, $prices);

            /* Sort results */
            uasort($prices[1], create_function('$a,$b','return strlen($b) - strlen($a);'));

            $done = array();
            foreach ($prices[1] as $k => $value) {
                $original = $prices[0][$k];
                if (in_array($original, $done)) {
                    continue;
                }
                $new = str_replace(',', '', $value) * $rate;

                $currencies = array(
                                    'USD' => '$',
                                    'NZD' => '$',
                                    'AUD' => '$',
                                    'CAD' => '$',
                                    'GBP' => '&pound;',
                                    'EUR' => '&euro;',
                                    'JPY' => '&yen;',
                                   );

                $decimals      = (strpos($original, '.') && $rate < 10) ? 2 : 0;
                $thousands_sep = strpos($original, ',') ? ',' : '';
                $currencysymbol = isset($currencies[$to]) ? $currencies[$to] : ' ';<commit_msg>correcting bug that caused inline currency conversion to not work - had previous been fixed in trunk, and not copied to branches.<commit_after><?php
/**
 *                    Jojo CMS
 *                ================
 *
 * Copyright 2007 <NAME> <<EMAIL>>
 * Copyright 2007 <NAME> <<EMAIL>>
 * Copyright 2007 <NAME> <<EMAIL>>
 *
 * See the enclosed file license.txt for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  <NAME> <<EMAIL>>
 * @author  <NAME> <<EMAIL>>
 * @author  <NAME> <<EMAIL>>
 * @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
 * @link    http://www.jojocms.org JojoCMS
 */

class JOJO_Plugin_jojo_convert_currency extends JOJO_Plugin
{
    public static function inpageconverter($content)
    {
        if (strpos($content, '[[convert_currency]]') === false) {
            return $content;
        }

        global $smarty;
        foreach (Jojo::listPlugins('classes/JOJO/Currency.php') as $pluginfile) {
            require_once($pluginfile);
            break;
        }

        $c = new JOJO_Currency_yahoo();

        $amount = Util::getFormData('amount', 1);
        $smarty->assign('from',   isset($_SESSION['jojo_currency_from'])   ? $_SESSION['jojo_currency_from'] : Jojo::getOption('currency_convert_from'));
        $smarty->assign('to',     isset($_SESSION['jojo_currency_to'])     ? $_SESSION['jojo_currency_to']   : Jojo::getOption('currency_convert_to'));
        $smarty->assign('amount', isset($_SESSION['jojo_currency_amount']) ? $_SESSION['jojo_currency_amount'] : 1);

        $smarty->assign('currencies', $c->getCurrencies()); //adds an empty element to the start of the array
        return str_replace('[[convert_currency]]', $smarty->fetch('convert-currency.tpl'), $content);
    }

    public static function inlineconverter($content)
    {
        if (strpos($content, '[[convert_currency_inline') === false) {
            return $content;
        }

        global $smarty;

        preg_match_all('/\[\[convert_currency_inline:([^\]]*)\]\]/', $content, $filters);
        $replacestring = $filters[0] ? $filters[0] : '[[convert_currency_inline]]';
        $defaulttocurrency = isset($filters[1][0]) ? $filters[1][0] : '';
        foreach (Jojo::listPlugins('classes/JOJO/Currency.php') as $pluginfile) {
            require_once($pluginfile);
            break;
        }
        $c = new JOJO_Currency_yahoo();

        /* Get Exchange Rate */
        $from   = Jojo::getOption('currency_convert_from');
        $to     = Util::getFormData('to', isset($_SESSION['jojo_currency_to']) ? $_SESSION['jojo_currency_to'] : ($defaulttocurrency ? $defaulttocurrency : Jojo::getOption('currency_convert_to')));
        $_SESSION['jojo_currency_to'] = $to;

        if ($to != $from) {
            $cacheFile = _CACHEDIR . "/currency/$from-$to";
            if (!file_exists($cacheFile) || ((time() - filemtime($cacheFile)) > 1800 )) {
                /* Update cached copy */
                foreach (Jojo::listPlugins('classes/JOJO/Currency.php') as $pluginfile) {
                    require_once($pluginfile);
                    break;
                }
                $c = new JOJO_Currency_yahoo();
                $rate = $c->getRate($from, $to, true);
                file_put_contents($cacheFile, $rate);
            } else {
                /* Use cached copy */
                $rate = file_get_contents($cacheFile);
            }

            /* Location prices in html */
            preg_match_all('#\$([0-9]+[0-9,.]*)#', $content, $prices);

            /* Sort results */
            uasort($prices[1], create_function('$a,$b','return strlen($b) - strlen($a);'));

            $done = array();
            foreach ($prices[1] as $k => $value) {
                $original = $prices[0][$k];
                if (in_array($original, $done)) {
                    continue;
                }
                $new = str_replace(',', '', $value) * $rate;

                $currencies = array(
                                    'USD' => '$',
                                    'NZD' => '$',
                                    'AUD' => '$',
                                    'CAD' => '$',
                                    'GBP' => '&pound;',
                                    'EUR' => '&euro;',
                                    'JPY' => '&yen;',
                                   );

                $decimals      = (strpos($original, '.') && $rate < 10) ? 2 : 0;
                $thousands_sep = strpos($original, ',') ? ',' : '';
                $currencysymbol = isset($currencies[$to]) ? $currencies[$to] : ' ';
{'fraction_non_alphanumeric': 0.16798013602504588, 'fraction_numerical': 0.007556946993414661, 'mean_word_length': 1.9616368286445012, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5492438', 'n_tokens_mistral': 2813, 'n_tokens_neox': 2682, 'n_words': 502}