HEX
Server: Apache
System: Linux msm5694.mjhst.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: camjab_ssh (1000)
PHP: 5.3.29
Disabled: NONE
Upload Files
File: /home/httpd/html/baretube.com/admin/cronRescanStrings.php
<?php

require 'db.php';

error_reporting(-1);
ini_set('display_errors', 1);

$paths = array(
    "$basepath/controllers",
    "$basepath/core/js",
    "$basepath/includes",
    "$basepath/templates",
    "$template_path",
);

dbQuery("DELETE FROM `cache` WHERE `key` LIKE 'translations_strings_%'", false);

$match_sep_js = array(
    "', {",
    "',{",
    '", {',
    '",{',
);
$match_sep = array(
    "', array(",
    "',array(",
    '", array(',
    '",array(',
    '") ?>',
    '"); ?>',
    "'),'",
    "'), '",
    '"),"',
    '"), "',
    '"), \'',
    '"),\'',
    "')",
    '")."',
    '") : ',
);

$strings = array();
foreach ($paths as $path) {
    $dir = new RecursiveDirectoryIterator($path);
    foreach (new RecursiveIteratorIterator($dir) as $filename => $file) {
        if (substr($file, strlen($file) - 3) == '.js') {
            $file_content = file_get_contents($file);
            preg_match_all("/Tube\._t\((.*)[\"\'][\)]+/i", $file_content, $matches);
            if (count($matches[0]) > 0) {
                foreach ($matches[0] as $match) {
                    $separator_found = false;
                    foreach($match_sep_js as $separator) {
                        if (strpos($match, $separator) !== false) {
                            $string = chop(trim(str_replace(array("Tube._t('", 'Tube._t("', "\'", '\"'), '', substr($match, 0, strpos($match, $separator))), '"'), '")');
                            $strings[md5($string)] = array(
                                'string' => $string,
                                'file' => str_replace($basepath, '', $file),
                                'js' => true,
                            );
                            $separator_found = true;
                            break;
                        }
                    }
                    if ($separator_found === false) {
                        $string = chop(trim(str_replace(array("Tube._t('", 'Tube._t("', "\'", '\"'), '', substr($match, 0, -1)), '"'), '")');
                        $strings[md5($string)] = array(
                            'string' => $string,
                            'file' => str_replace($basepath, '', $file),
                            'js' => true,
                        );
                    }
                }
            }
        } else if (substr($file, strlen($file) - 4) == '.php') {
            $file_content = file_get_contents($file);
//            preg_match_all("/_t\([\'\"]{1}+(.*)+[\"\']{1}+[,\)]{1}+/i", $file_content, $matches);
            preg_match_all("/_t\((.*)[\"\'][\)]+/i", $file_content, $matches);
            if (count($matches[0]) > 0) {
                foreach ($matches[0] as $match) {
                    $separator_found = false;
                    foreach($match_sep as $separator) {
                        if (strpos($match, $separator) !== false) {
                            $string = chop(trim(str_replace(array("_t('", '_t("', "\'", '\"'), '', substr($match, 0, strpos($match, $separator))), '"'), '")');
                            $strings[md5($string)] = array(
                                'string' => $string,
                                'file' => str_replace($basepath, '', $file),
                            );
                            $separator_found = true;
                            break;
                        }
                    }
                    if ($separator_found === false) {
                        $string = chop(trim(str_replace(array("_t('", '_t("', "\'", '\"'), '', substr($match, 0, -1)), '"'), '")');
                        $strings[md5($string)] = array(
                            'string' => $string,
                            'file' => str_replace($basepath, '', $file),
                        );
                    }
                }
            }
        }
    }
}

$count = 0;
echo count($strings) . ' localized strings found<br>';
foreach ($strings as $string) {
    if (isset($string['js']) && $string['js'] === true) {
        if (!is_array(dbQuery("SELECT * FROM `locales_source` WHERE `text` = '" . mysqli_real_escape_string($dblink, $string['string']) . "'", false))) {
            dbQuery("INSERT INTO `locales_source` (`text`, `source_js`) VALUES ('" . mysqli_real_escape_string($dblink, $string['string']) . "', '" . mysqli_real_escape_string($dblink, $string['file']) . "')", false);
            if (mysqli_insert_id($dblink) > 0) {
                $count++;
            }
        }
    } else {
        if (!is_array(dbQuery("SELECT * FROM `locales_source` WHERE `text` = '" . mysqli_real_escape_string($dblink, $string['string']) . "'", false))) {
            dbQuery("INSERT INTO `locales_source` (`text`) VALUES ('" . mysqli_real_escape_string($dblink, $string['string']) . "')", false);
            if (mysqli_insert_id($dblink) > 0) {
                $count++;
            }
        }
    }
}
echo (count($strings) - $count) . " strings already existing in DB<br>";
echo "$count new strings added to translation set";