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); }
public function getItem() { if (!isset($this->item)) { $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', ''); $this->item = $cache->get($keycache); if ($this->item && $this->item->reference != $this->getState('translation.reference')) { $this->item = null; } } else { $this->item = null; } if (!$this->item) { $path = JFile::exists($this->getState('translation.path')) ? $this->getState('translation.path') : $this->getState('translation.refpath'); $this->item = new JObject(array('reference' => $this->getState('translation.reference'), 'bom' => 'UTF-8', 'svn' => '', 'version' => '', 'description' => '', 'creationdate' => '', 'author' => '', 'maincopyright' => '', 'additionalcopyright' => array(), 'license' => '', 'exists' => JFile::exists($this->getState('translation.path')), 'translated' => 0, 'unchanged' => 0, 'extra' => 0, 'total' => 0, 'complete' => false, 'source' => '', 'error' => array())); if (JFile::exists($path)) { $this->item->source = file_get_contents($path); $stream = new JStream(); $stream->open($path); $begin = $stream->read(4); $bom = strtolower(bin2hex($begin)); if ($bom == '0000feff') { $this->item->bom = 'UTF-32 BE'; } else { if ($bom == 'feff0000') { $this->item->bom = 'UTF-32 LE'; } else { if (substr($bom, 0, 4) == 'feff') { $this->item->bom = 'UTF-16 BE'; } else { if (substr($bom, 0, 4) == 'fffe') { $this->item->bom = 'UTF-16 LE'; } } } } $stream->seek(0); $continue = true; $lineNumber = 0; $params = JComponentHelper::getParams('com_localise'); $isTranslationsView = JRequest::getVar('view') == 'translations'; while (!$stream->eof()) { $line = $stream->gets(); $lineNumber++; if ($line[0] == '#' || $line[0] == ';') { if (preg_match('/^(#|;).*(\\$Id.*\\$)/', $line, $matches)) { $this->item->svn = $matches[2]; } elseif (preg_match('/(#|;)\\s*@?(\\pL+):?.*/', $line, $matches)) { switch (strtolower($matches[2])) { case 'note': preg_match('/(#|;)\\s*@?(\\pL+):?\\s+(.*)/', $line, $matches2); $this->item->complete = $this->item->complete || strtolower($matches2[3]) == 'complete'; break; case 'version': preg_match('/(#|;)\\s*@?(\\pL+):?\\s+(.*)/', $line, $matches2); $this->item->version = $matches2[3]; break; case 'desc': case 'description': preg_match('/(#|;)\\s*@?(\\pL+):?\\s+(.*)/', $line, $matches2); $this->item->description = $matches2[3]; break; case 'date': preg_match('/(#|;)\\s*@?(\\pL+):?\\s+(.*)/', $line, $matches2); $this->item->creationdate = $matches2[3]; break; case 'author': if ($params->get('author') && !$isTranslationsView) { $this->item->author = $params->get('author'); } else { preg_match('/(#|;)\\s*@?(\\pL+):?\\s+(.*)/', $line, $matches2); $this->item->author = $matches2[3]; } break; case 'copyright': preg_match('/(#|;)\\s*@?(\\pL+):?\\s+(.*)/', $line, $matches2); if (empty($this->item->maincopyright)) { if ($params->get('copyright') && !$isTranslationsView) { $this->item->maincopyright = $params->get('copyright'); } else { $this->item->maincopyright = $matches2[3]; } } if (empty($this->item->additionalcopyright)) { if ($params->get('additionalcopyright') && !$isTranslationsView) { $this->item->additionalcopyright[] = $params->get('additionalcopyright'); } else { $this->item->additionalcopyright[] = $matches2[3]; } } break; case 'license': if ($params->get('license') && !$isTranslationsView) { $this->item->license = $params->get('license'); } else { preg_match('/(#|;)\\s*@?(\\pL+):?\\s+(.*)/', $line, $matches2); $this->item->license = $matches2[3]; } break; case 'package': preg_match('/(#|;)\\s*@?(\\pL+):?\\s+(.*)/', $line, $matches2); $this->item->package = $matches2[3]; break; case 'subpackage': preg_match('/(#|;)\\s*@?(\\pL+):?\\s+(.*)/', $line, $matches2); $this->item->subpackage = $matches2[3]; break; case 'link': break; default: if (empty($this->item->author)) { if ($params->get('author') && !$isTranslationsView) { $this->item->author = $params->get('author'); } else { preg_match('/(#|;)\\s*(.*)/', $line, $matches2); $this->item->author = $matches2[2]; } } break; } } } else { break; } } if (empty($this->item->author) && $params->get('author') && !$isTranslationsView) { $this->item->author = $params->get('author'); } if (empty($this->item->license) && $params->get('license') && !$isTranslationsView) { $this->item->license = $params->get('license'); } if (empty($this->item->maincopyright) && $params->get('copyright') && !$isTranslationsView) { $this->item->maincopyright = $params->get('copyright'); } if (empty($this->item->additionalcopyright) && $params->get('additionalcopyright') && !$isTranslationsView) { $this->item->additionalcopyright[] = $params->get('additionalcopyright'); } while (!$stream->eof()) { $line = $stream->gets(); $lineNumber++; if (!preg_match('/^(|(\\[[^\\]]*\\])|([A-Z][A-Z0-9_\\-\\.]*\\s*=(\\s*(("[^"]*")|(_QQ_)))+))\\s*(;.*)?$/', $line)) { $this->item->error[] = $lineNumber; } } $stream->close(); } $this->item->additionalcopyright = implode("\n", $this->item->additionalcopyright); if ($this->getState('translation.layout') != 'raw' && empty($this->item->error)) { $sections = LocaliseHelper::parseSections($this->getState('translation.path')); $refsections = LocaliseHelper::parseSections($this->getState('translation.refpath')); if (!empty($refsections['keys'])) { foreach ($refsections['keys'] as $key => $string) { $this->item->total++; if (!empty($sections['keys']) && array_key_exists($key, $sections['keys']) && $sections['keys'][$key] != '') { if ($sections['keys'][$key] != $string || $this->getState('translation.path') == $this->getState('translation.refpath')) { $this->item->translated++; } else { $this->item->unchanged++; } } } } if (!empty($sections['keys'])) { foreach ($sections['keys'] as $key => $string) { if (empty($refsections['keys']) || !array_key_exists($key, $refsections['keys'])) { $this->item->extra++; } } } $this->item->completed = $this->item->total ? intval(100 * $this->item->translated / $this->item->total) + $this->item->unchanged / $this->item->total : 100; $this->item->complete = $this->item->complete ? 1 : ($this->item->completed == 100 ? 1 : 0); } if ($this->getState('translation.id')) { $table = $this->getTable(); $table->load($this->getState('translation.id')); $user = JFactory::getUser($table->checked_out); $this->item->setProperties($table->getProperties()); if ($this->item->checked_out == JFactory::getUser()->id) { $this->item->checked_out = 0; } $this->item->editor = JText::sprintf('COM_LOCALISE_TEXT_TRANSLATION_EDITOR', $user->name, $user->username); } if ($caching) { $cache->store($this->item, $keycache); } } //$this->item->error = $this->getErrors(); } return $this->item; }