示例#1
0
 /**
  * Execute the Command
  *
  * @access protected
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Fetch paths for Applications
     $applications = \Skeleton\Core\Application::get_all();
     // If the paths array hasn't been defined yet, make sure it exists
     if (!isset($paths) or !is_array($paths)) {
         $paths = [];
     }
     foreach ($applications as $application) {
         $paths[$application->name] = $application->path;
     }
     // Fetch additional paths to translate
     foreach (\Skeleton\I18n\Config::$additional_template_paths as $name => $path) {
         $paths[$name] = $path;
     }
     // Translate all the applications
     foreach ($paths as $application => $directory) {
         $log = $this->translate_application($application, $directory);
         $output->writeln($log);
     }
     $packages = \Skeleton\Core\Package::get_all();
     foreach ($packages as $package) {
         $log = $this->translate_skeleton_package($package);
         $output->writeln($log);
     }
     return 0;
 }
示例#2
0
 /**
  * Execute the Command
  *
  * @access protected
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $packages = \Skeleton\Core\Package::get_all();
     $name = $input->getArgument('name');
     $to_translate = null;
     foreach ($packages as $package) {
         if ($package->name == $name) {
             $to_translate = $package;
         }
     }
     $log = $this->translate_skeleton_package($to_translate);
     $output->writeln($log);
 }
示例#3
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->template = new \Skeleton\Template\Template();
     $application = \Skeleton\Core\Application::Get();
     if (file_exists($application->template_path)) {
         $this->template->add_template_directory($application->template_path, $application->name);
     }
     $packages = \Skeleton\Core\Package::get_all();
     foreach ($packages as $package) {
         if (file_exists($package->template_path)) {
             $this->template->add_template_directory($package->template_path, $package->name);
         }
     }
 }
示例#4
0
 /**
  * Read the po files
  *
  * @access public
  */
 private function reload_po_file()
 {
     $po_files = [];
     $po_files[] = Config::$po_directory . '/' . $this->language->name_short . '/' . $this->application_name . '.po';
     $packages = \Skeleton\Core\Package::get_all();
     foreach ($packages as $package) {
         if (file_exists(Config::$po_directory . '/' . $this->language->name_short . '/package/' . $package->name . '.po')) {
             $po_files[] = Config::$po_directory . '/' . $this->language->name_short . '/package/' . $package->name . '.po';
         }
     }
     $array_modified = 0;
     if (file_exists(Config::$cache_directory . '/' . $this->language->name_short . '/' . $this->application_name . '.php')) {
         $array_modified = filemtime(Config::$cache_directory . '/' . $this->language->name_short . '/' . $this->application_name . '.php');
     }
     $po_file_modified = null;
     foreach ($po_files as $po_file) {
         if (!file_exists($po_file)) {
             continue;
         }
         if ($po_file_modified === null) {
             $po_file_modified = filemtime($po_file);
         }
         if (filemtime($po_file) > $po_file_modified) {
             $po_file_modified = filemtime($po_file);
         }
     }
     if ($array_modified >= $po_file_modified) {
         return;
     }
     $po_strings = [];
     foreach (array_reverse($po_files) as $po_file) {
         $strings = Util::load($po_file);
         foreach ($strings as $key => $value) {
             if (!isset($po_strings[$key])) {
                 $po_strings[$key] = $value;
             } elseif ($value != '') {
                 $po_strings[$key] = $value;
             } else {
                 continue;
             }
         }
     }
     if (!file_exists(Config::$cache_directory . '/' . $this->language->name_short)) {
         mkdir(Config::$cache_directory . '/' . $this->language->name_short, 0755, true);
     }
     file_put_contents(Config::$cache_directory . '/' . $this->language->name_short . '/' . $this->application_name . '.php', '<?php $strings = ' . var_export($po_strings, true) . ';');
 }
示例#5
0
 /**
  * Do a reverse rewrite of a link
  *
  * @access private
  * @param string $url_raw
  * @return string $reverse_rewrite
  */
 private static function rewrite_reverse_routes($url_raw)
 {
     $url = parse_url($url_raw);
     $params = [];
     $application = \Skeleton\Core\Application::Get();
     $routes = $application->config->routes;
     if (isset($url['query'])) {
         // Allow &amp; instead of &
         $url['query'] = str_replace('&amp;', '&', $url['query']);
         parse_str($url['query'], $params);
     }
     /**
      * Add language to the known parameters
      */
     if (isset($application->language) and !isset($params['language'])) {
         $params['language'] = $application->language->name_short;
     }
     /**
      * Search for the requested module
      */
     if (!isset($url['path'])) {
         return $url_raw;
     }
     if ($url['path'] != '' and $url['path'][0] == '/') {
         $url['path'] = substr($url['path'], 1);
     }
     $module_name = null;
     /**
      * Check skeleton packages
      */
     $packages = \Skeleton\Core\Package::get_all();
     foreach ($packages as $package) {
         $parts = explode('/', $url['path']);
         if (isset($parts[0]) and $parts[0] == $package->name) {
             unset($parts[0]);
             $package_parts = explode('-', str_replace('skeleton-package-', '', $package->name));
             foreach ($package_parts as $key => $package_part) {
                 $package_parts[$key] = ucfirst($package_part);
             }
             $module_name = '\\Skeleton\\Package\\' . implode('\\', $package_parts) . '\\Web\\Module\\' . str_replace('_', '\\', implode('/', $parts));
         }
     }
     if ($module_name === null) {
         $module_name = 'web_module_' . str_replace('/', '_', $url['path']);
     }
     $module_defined = false;
     $package_module = false;
     if (isset($routes[$module_name])) {
         $module_defined = true;
     } elseif (isset($routes[$module_name . '_index'])) {
         $module_name = $module_name . '_index';
         $module_defined = true;
     } else {
         foreach ($routes as $classname => $dummy) {
             $application = Application::get();
             $module_filename = str_replace('web_module_', '', $classname);
             $filename_parts = explode('_', $module_filename);
             $module_filename = '';
             foreach ($filename_parts as $filename_part) {
                 $module_filename .= '/' . strtolower($filename_part);
             }
             $module_filename .= '.php';
             $module_filename = $application->module_path . $module_filename;
             if (file_exists($module_filename) and !class_exists($classname)) {
                 require_once $module_filename;
             }
             if (class_exists($classname) and (strtolower(get_parent_class($classname)) == strtolower($module_name) or is_subclass_of($classname, $module_name))) {
                 $module_name = strtolower($classname);
                 $module_defined = true;
                 $package_module = true;
             }
         }
     }
     if (!$module_defined) {
         return $url_raw;
     }
     $routes = $routes[$module_name];
     $correct_route = null;
     foreach ($routes as $route) {
         $route_parts = explode('/', $route);
         $route_part_matches = 0;
         foreach ($route_parts as $key => $route_part) {
             if (trim($route_part) == '') {
                 unset($route_parts[$key]);
                 continue;
             }
             if ($route_part[0] != '$') {
                 $route_part_matches++;
                 continue;
             }
             /**
              * $language[en,nl] => language[en,nl]
              */
             $route_part = substr($route_part, 1);
             /**
              * Fetch required values
              */
             $required_values = [];
             preg_match_all('/(\\[(.*?)\\])/', $route_part, $matches);
             if (count($matches[2]) > 0) {
                 /**
                  * There are required values, parse them
                  */
                 $required_values = explode(',', $matches[2][0]);
                 $route_part = str_replace($matches[0][0], '', $route_part);
                 $route_parts[$key] = '$' . $route_part;
             }
             if (isset($params[$route_part])) {
                 /**
                  * if there are no required values => Proceed
                  */
                 if (count($required_values) == 0) {
                     $route_part_matches++;
                     continue;
                 }
                 /**
                  * Check the required values
                  */
                 $values_ok = false;
                 foreach ($required_values as $required_value) {
                     if ($required_value == $params[$route_part]) {
                         $values_ok = true;
                     }
                 }
                 if ($values_ok) {
                     $route_part_matches++;
                     continue;
                 }
             }
         }
         if ($route_part_matches == count($route_parts)) {
             $correct_route = $route_parts;
         }
     }
     if ($correct_route === null and !$package_module) {
         return $url_raw;
     } elseif ($correct_route === null and $package_module) {
         $module_name = str_replace('web_module_', '', $module_name);
         $new_url = '/' . str_replace('_', '/', $module_name);
     } else {
         $new_url = '';
         foreach ($correct_route as $url_part) {
             if ($url_part[0] !== '$') {
                 $new_url .= '/' . $url_part;
                 continue;
             }
             $url_part = substr($url_part, 1);
             $new_url .= '/' . $params[$url_part];
             unset($params[$url_part]);
         }
     }
     /**
      * If the first character is a /, remove it
      */
     if ($new_url[0] == '/') {
         $new_url = substr($new_url, 1);
     }
     if (count($params) > 0) {
         $new_url .= '?' . urldecode(http_build_query($params));
     }
     /**
      * Is there a fragment ('#') available?
      */
     if (isset($url['fragment'])) {
         $new_url .= '#' . $url['fragment'];
     }
     return $new_url;
 }
示例#6
0
 /**
  * Fetch the contents and mtime of a file
  *
  * @access private
  * @param string $type
  * @param string $path
  * @param string $extension
  * @return mixed $content Returns a string with the content, false if it
  *  couldn't be found or null if it shouldn't be handled by us anyway
  */
 private static function fetch($type, $path, $extension)
 {
     $packages = \Skeleton\Core\Package::get_all();
     foreach (self::$filetypes as $filetype => $extensions) {
         $filepaths = [\Skeleton\Core\Config::$asset_dir . '/' . $path, Application::get()->media_path . '/' . $filetype . '/' . $path];
         foreach ($packages as $package) {
             $path_parts = explode('/', $path);
             if (!isset($path_parts[0]) or $path_parts[0] != $package->name) {
                 continue;
             }
             unset($path_parts[0]);
             $package_path = $package->asset_path . '/' . $filetype . '/' . implode('/', $path_parts);
             $filepaths[] = $package_path;
         }
         if (in_array($extension, $extensions)) {
             foreach ($filepaths as $filepath) {
                 if (file_exists($filepath)) {
                     if ($type == 'mtime') {
                         return filemtime($filepath);
                     } else {
                         return file_get_contents($filepath);
                     }
                 }
             }
             return false;
         }
     }
     return null;
 }