private function getProcPersonObject() { static $procPersObject; // Open the file as a stream. $stream = new JStream(); $stream->open($this->file); $value = $stream->read(); $stream->close(); if (!$value) { stop1(); } $procPersObject = json_decode($value); return $procPersObject; }
public function compile() { $doc = JFactory::getDocument(); $headers = $doc->getHeadData(); $javascripts = JArrayHelper::getValue($headers, 'scripts'); $dest = JPath::clean($this->paths->get('js.compressed')); $compile = $this->params->get('minify_js', 1); $changed = (bool) $this->isJsUpdated(); JLog::add('Javascript cache changed: ' . ((bool) $changed ? 'true' : 'false'), JLog::DEBUG, $this->logger); $force = (bool) ($compile == 2); $changed = (bool) ($compile == 1 && $changed); JLog::add('Force Javascript minification: ' . ((bool) $force ? 'true' : 'false'), JLog::DEBUG, $this->logger); JLog::add('Minify Javascript: ' . ((bool) $changed ? 'true' : 'false'), JLog::DEBUG, $this->logger); $uncompressed = ''; foreach (array_keys($javascripts) as $script) { $url = new JUri($script); if (!$url->getScheme()) { $url = new JUri(JUri::base()); $url->setPath($script); } $key = str_replace(JUri::base(), JPATH_ROOT . '/', (string) $url); if (array_search($key, $this->paths->get('js.uncompressed')) !== false) { unset($headers['scripts'][$script]); if (!JFile::exists($dest) || $changed || $force) { JLog::add('Compressing: ' . $key . ' to ' . $dest, JLog::DEBUG, $this->logger); $stream = new JStream(); $stream->open($key); $response = $stream->read($stream->filesize()); $stream->close(); $uncompressed .= $response; } } } if ($uncompressed) { file_put_contents($dest, JSMinPlus::minify($uncompressed, $dest)); $this->updateCache(self::CACHEKEY . '.files.js', $this->paths->get('js.uncompressed')); } // workaround. There needs to be at least one script. if (count($headers['scripts']) == 0) { $url = str_replace(JPATH_ROOT . '/', JUri::base(), $dest); $headers['scripts'][$url] = array('mime' => 'text/javascript', 'defer' => false, 'async' => false); } $doc->setHeadData($headers); }
/** * Parses a language file. * * @param string $filename The name of the file. * * @return array The array of parsed strings. * * @since 11.1 */ protected function parse($filename) { if ($this->debug) { // Capture hidden PHP errors from the parsing. $php_errormsg = null; $track_errors = ini_get('track_errors'); ini_set('track_errors', true); } $contents = file_get_contents($filename); $contents = str_replace('_QQ_', '"\\""', $contents); $strings = @parse_ini_string($contents); // Restore error tracking to what it was before. ini_set('track_errors', $track_errors); if (!is_array($strings)) { $strings = array(); } if ($this->debug) { jimport('joomla.filesystem.stream'); // Initialise variables for manually parsing the file for common errors. $blacklist = array('YES', 'NO', 'NULL', 'FALSE', 'ON', 'OFF', 'NONE', 'TRUE'); $regex = '/^(|(\\[[^\\]]*\\])|([A-Z][A-Z0-9_\\-]*\\s*=(\\s*(("[^"]*")|(_QQ_)))+))\\s*(;.*)?$/'; $this->debug = false; $errors = array(); $lineNumber = 0; // Open the file as a stream. $stream = new JStream(); $stream->open($filename); while (!$stream->eof()) { $line = $stream->gets(); // Avoid BOM error as BOM is OK when using parse_ini if ($lineNumber == 0) { $line = str_replace("", '', $line); } $lineNumber++; // Check that the key is not in the blacklist and that the line format passes the regex. $key = strtoupper(trim(substr($line, 0, strpos($line, '=')))); if (!preg_match($regex, $line) || in_array($key, $blacklist)) { $errors[] = $lineNumber; } } $stream->close(); // Check if we encountered any errors. if (count($errors)) { if (basename($filename) != $this->lang . '.ini') { $this->errorfiles[$filename] = $filename . JText::sprintf('JERROR_PARSING_LANGUAGE_FILE', implode(', ', $errors)); } else { $this->errorfiles[$filename] = $filename . ' : error(s) in line(s) ' . implode(', ', $errors); } } elseif ($php_errormsg) { // We didn't find any errors but there's probably a parse notice. $this->errorfiles['PHP' . $filename] = 'PHP parser errors :' . $php_errormsg; } $this->debug = true; } return $strings; }
public function saveFile($data) { $path = $this->getState('translation.path'); $refpath = $this->getState('translation.refpath'); $exists = JFile::exists($path); $refexists = JFile::exists($refpath); $client = $this->getState('translation.client'); // Set FTP credentials, if given. JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); // Try to make the file writeable. if ($exists && !$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, '0644')) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_TRANSLATION_WRITABLE', $path)); return false; } if (array_key_exists('source', $data)) { $contents = $data['source']; } else { $data['description'] = str_replace(array("\r\n", "\n", "\r"), " ", $data['description']); $additionalcopyrights = trim($data['additionalcopyright']); if (empty($additionalcopyrights)) { $additionalcopyrights = array(); } else { $additionalcopyrights = explode("\n", $additionalcopyrights); } $contents2 = ''; if (!empty($data['svn'])) { $contents2 .= "; " . $data['svn'] . "\n;\n"; } if (!empty($data['package'])) { $contents2 .= "; @package " . $data['package'] . "\n"; } if (!empty($data['subpackage'])) { $contents2 .= "; @subpackage " . $data['subpackage'] . "\n"; } if (!empty($data['description'])) { $contents2 .= "; @description " . $data['description'] . "\n"; } if (!empty($data['version'])) { $contents2 .= "; @version " . $data['version'] . "\n"; } if (!empty($data['creationdate'])) { $contents2 .= "; @date " . $data['creationdate'] . "\n"; } if (!empty($data['author'])) { $contents2 .= "; @author " . $data['author'] . "\n"; } if (!empty($data['maincopyright'])) { $contents2 .= "; @copyright " . $data['maincopyright'] . "\n"; } foreach ($additionalcopyrights as $copyright) { $contents2 .= "; @copyright " . $copyright . "\n"; } if (!empty($data['license'])) { $contents2 .= "; @license " . $data['license'] . "\n"; } if (array_key_exists('complete', $data) && $data['complete'] == '1') { $contents2 .= "; @note Complete\n"; } $contents2 .= "; @note Client " . ucfirst($client) . "\n"; $contents2 .= "; @note All ini files need to be saved as UTF-8 - No BOM\n\n"; $contents = array(); $stream = new JStream(); if ($exists) { $stream->open($path); while (!$stream->eof()) { $line = $stream->gets(); // Comment lines if (preg_match('/^(;.*)$/', $line, $matches)) { //$contents[] = $matches[1]."\n"; } else { break; } } if ($refexists) { $stream->close(); $stream->open($refpath); while (!$stream->eof()) { $line = $stream->gets(); // Comment lines if (!preg_match('/^(;.*)$/', $line, $matches)) { break; } } } } else { $stream->open($refpath); while (!$stream->eof()) { $line = $stream->gets(); // Comment lines if (preg_match('/^(;.*)$/', $line, $matches)) { $contents[] = $matches[1] . "\n"; } else { break; } } } $strings = $data['strings']; while (!$stream->eof()) { if (preg_match('/^([A-Z][A-Z0-9_\\-\\.]*)\\s*=/', $line, $matches)) { $key = $matches[1]; if (isset($strings[$key])) { $contents[] = $key . '="' . str_replace('"', '"_QQ_"', $strings[$key]) . "\"\n"; unset($strings[$key]); } } else { $contents[] = $line; } $line = $stream->gets(); } if (!empty($strings)) { $contents[] = "\n[New Strings]\n\n"; foreach ($strings as $key => $string) { $contents[] = $key . '="' . str_replace('"', '"_QQ_"', $string) . "\"\n"; } } $stream->close(); $contents = implode($contents); $contents = $contents2 . $contents; } $return = JFile::write($path, $contents); // Try to make the template file unwriteable. // Get the parameters $coparams = JComponentHelper::getParams('com_localise'); // Get the file save permission $fsper = $coparams->get('filesavepermission', '0444'); if (!$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, $fsper)) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_TRANSLATION_UNWRITABLE', $path)); return false; } else { if (!$return) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_TRANSLATION_FILESAVE', $path)); return false; } } // Remove the cache $conf = JFactory::getConfig(); $caching = $conf->get('caching') >= 1; if ($caching) { $keycache = $this->getState('translation.client') . '.' . $this->getState('translation.tag') . '.' . $this->getState('translation.filename') . '.' . 'translation'; $cache = JFactory::getCache('com_localise', ''); $cache->remove($keycache); } }