Ejemplo n.º 1
0
 public function cleanHtmlFile()
 {
     if (file_exists(Core_Model_Directory::getCacheDirectory(true) . '/' . $this->_getFilename())) {
         @unlink(Core_Model_Directory::getCacheDirectory(true) . '/' . $this->_getFilename());
     }
     return $this;
 }
Ejemplo n.º 2
0
 protected function _initCache()
 {
     $cache_dir = Core_Model_Directory::getCacheDirectory(true);
     if (is_writable($cache_dir)) {
         $frontendConf = array('lifetime' => 345600, 'automatic_seralization' => true);
         $backendConf = array('cache_dir' => $cache_dir);
         $cache = Zend_Cache::factory('Core', 'File', $frontendConf, $backendConf);
         $cache->setOption('automatic_serialization', true);
         Zend_Locale::setCache($cache);
         Zend_Registry::set('cache', $cache);
     }
 }
Ejemplo n.º 3
0
 public function installAction()
 {
     $data = array();
     try {
         $cache = Zend_Registry::isRegistered('cache') ? Zend_Registry::get('cache') : null;
         if ($cache) {
             $cache->clean("all");
         }
         $cache_ids = array('js_mobile.js', 'js_desktop.js', 'css_mobile.css', 'css_desktop.css');
         foreach ($cache_ids as $cache_id) {
             if (file_exists(Core_Model_Directory::getCacheDirectory(true) . "/{$cache_id}")) {
                 @unlink(Core_Model_Directory::getCacheDirectory(true) . "/{$cache_id}");
             }
         }
         $module_names = Zend_Controller_Front::getInstance()->getDispatcher()->getSortedModuleDirectories();
         $modules = array();
         foreach ($module_names as $module_name) {
             $module = new Installer_Model_Installer_Module();
             $module->prepare($module_name);
             if ($module->canUpdate()) {
                 $modules[] = $module->getName();
             }
         }
         foreach ($modules as $module) {
             $installer = new Installer_Model_Installer();
             $installer->setModuleName($module)->install();
         }
         $host = $this->getRequest()->getHeader("host");
         if ($host and $host == base64_decode("YXBwcy5tb2JpdXNjcy5jb20=")) {
             $email = base64_decode("Y29udGFjdEBzaWJlcmlhbmNtcy5jb20=");
             $object = "{$host} - Siberian Update";
             $message = "Siberian " . Siberian_Version::NAME . " " . Siberian_Version::VERSION;
             @mail($email, $object, $message);
         }
         $data = array("success" => 1, "message" => $this->_("Module successfully installed"));
     } catch (Exception $e) {
         $data = array("error" => 1, "message" => $e->getMessage());
     }
     $this->_sendHtml($data);
 }
Ejemplo n.º 4
0
 public function load($use_base)
 {
     if (!$this->isEnabled()) {
         return $this;
     }
     $this->_createXml($use_base);
     $base = $this->_xml->base;
     // Récupère la vue de base et lui affecte les données (template, title, etc...)
     if ($base and isset($base->class)) {
         $baseView = $this->_getView($base->class);
         $this->setView($baseView);
     } else {
         $baseView = $this->getView();
     }
     if ($use_base) {
         $baseView->setTitle($base->title);
         $baseView->default_class_name = $this->_action;
         $mergeFiles = APPLICATION_TYPE == "mobile" && APPLICATION_ENV == "production";
         $scripts_path = Core_Model_Directory::getDesignPath();
         $scripts = $base->scripts;
         $metas = $base->metas;
         // Scripts JS
         $jsToMerge = array();
         $cache = Zend_Registry::isRegistered('cache') ? Zend_Registry::get('cache') : null;
         $cacheId = 'js_' . APPLICATION_TYPE;
         if (!$mergeFiles or !$cache or !$cache->load($cacheId)) {
             foreach ($scripts->js as $files) {
                 foreach ($files as $file) {
                     $link = '';
                     if ($file->attributes()->link) {
                         $link = strpos($file->attributes()->link, '/') === 0 ? '' : $scripts_path . '/';
                         $link .= $file->attributes()->link;
                         $jsToMerge["local"][] = $link;
                     } else {
                         if ($file->attributes()->href) {
                             $link = (string) $file->attributes()->href;
                             $jsToMerge["external"][] = $link;
                         }
                     }
                     if ($file->attributes()->folder) {
                         $link = strpos($file->attributes()->folder, '/') === 0 ? '' : $scripts_path . '/';
                         $link .= $file->attributes()->folder . '/';
                         $base_link = Core_Model_Directory::getBasePathTo($link);
                         if (is_dir($base_link)) {
                             $tmp_files = new DirectoryIterator($base_link);
                             foreach ($tmp_files as $tmp_file) {
                                 if (!$tmp_file->isFile()) {
                                     continue;
                                 }
                                 $pathinfo = pathinfo($tmp_file->getRealPath());
                                 if (empty($pathinfo["extension"]) or $pathinfo["extension"] != "js") {
                                     continue;
                                 }
                                 $this->_scripts['js'][] = $link . $tmp_file->getFileName();
                                 $jsToMerge["local"][] = $link . $tmp_file->getFileName();
                             }
                         }
                     }
                 }
                 if ($cache) {
                     $cache->save($jsToMerge, $cacheId);
                 }
             }
         }
         if (empty($jsToMerge) and $cache) {
             $jsToMerge = $cache->load($cacheId);
         }
         $js_file = Core_Model_Directory::getCacheDirectory() . "/js_" . APPLICATION_TYPE . ".js";
         if ($mergeFiles) {
             if (!file_exists(Core_Model_Directory::getBasePathTo($js_file))) {
                 // Merging javascript files
                 $js = fopen(Core_Model_Directory::getBasePathTo($js_file), "w");
                 foreach ($jsToMerge["local"] as $file) {
                     fputs($js, file_get_contents(Core_Model_Directory::getBasePathTo($file)) . PHP_EOL);
                 }
                 fclose($js);
             }
             // Appending the JS files to the view
             $js_file .= "?" . filemtime(Core_Model_Directory::getBasePathTo($js_file));
             $this->_scripts['js'][] = $js_file;
             $baseView->headScript()->appendFile($js_file);
         } else {
             foreach ($jsToMerge["local"] as $file) {
                 $file .= "?" . filemtime(Core_Model_Directory::getBasePathTo($file));
                 $this->_scripts['js'][] = $file;
                 $baseView->headScript()->appendFile($file);
             }
         }
         if (!empty($jsToMerge["external"])) {
             foreach ($jsToMerge["external"] as $external_js) {
                 $this->_scripts['js'][] = $external_js;
                 $baseView->headScript()->appendFile($external_js);
             }
         }
         // Scripts CSS
         $cssToMerge = array();
         $cacheId = 'css_' . APPLICATION_TYPE;
         if (!$mergeFiles or !$cache or !$cache->load($cacheId)) {
             foreach ($scripts->css as $files) {
                 foreach ($files as $file) {
                     $src = '';
                     if ($file->attributes()->link) {
                         $cssToMerge["local"][] = (string) ($scripts_path . '/' . $file->attributes()->link);
                     } else {
                         $cssToMerge["external"][] = (string) $file->attributes()->href;
                     }
                     //                        $baseView->headLink()->appendStylesheet($src, 'screen', $file->attributes()->if ? (string) $file->attributes()->if : null);
                     //                        $this->_scripts['css'][] = $src;
                     if ($file->attributes()->folder) {
                         $link = strpos($file->attributes()->folder, '/') === 0 ? '' : $scripts_path . '/';
                         $link .= $file->attributes()->folder . '/';
                         $base_link = Core_Model_Directory::getBasePathTo($link);
                         if (is_dir($base_link)) {
                             $tmp_files = new DirectoryIterator($base_link);
                             foreach ($tmp_files as $tmp_file) {
                                 if (!$tmp_file->isFile()) {
                                     continue;
                                 }
                                 $pathinfo = pathinfo($tmp_file->getRealPath());
                                 if (empty($pathinfo["extension"]) or $pathinfo["extension"] != "css") {
                                     continue;
                                 }
                                 //                                    $this->_scripts['css'][] = $link.$tmp_file->getFileName();
                                 $cssToMerge["local"][] = $link . $tmp_file->getFileName();
                             }
                         }
                     }
                 }
             }
             if ($cache) {
                 $cache->save($cssToMerge, $cacheId);
             }
         }
         if (empty($cssToMerge) and $cache) {
             $cssToMerge = $cache->load($cacheId);
         }
         $css_file = Core_Model_Directory::getCacheDirectory() . "/css_" . APPLICATION_TYPE . ".css";
         $base_css_file = Core_Model_Directory::getCacheDirectory(true) . "/css_" . APPLICATION_TYPE . ".css";
         if ($mergeFiles) {
             if (!file_exists($base_css_file)) {
                 // Merging css files
                 $css = fopen($base_css_file, "w");
                 foreach ($cssToMerge["local"] as $file) {
                     fputs($css, file_get_contents(Core_Model_Directory::getBasePathTo($file)) . PHP_EOL);
                 }
                 fclose($css);
             }
             // Appending the JS files to the view
             $css_file .= "?" . filemtime(Core_Model_Directory::getBasePathTo($css_file));
             $this->_scripts['css'][] = $css_file;
             $baseView->headLink()->appendStylesheet($css_file, 'screen');
         } else {
             foreach ($cssToMerge["local"] as $file) {
                 $file .= "?" . filemtime(Core_Model_Directory::getBasePathTo($file));
                 $this->_scripts['css'][] = $file;
                 $baseView->headLink()->appendStylesheet($file, 'screen');
             }
         }
         if (!empty($cssToMerge["external"])) {
             foreach ($cssToMerge["external"] as $external_css) {
                 $this->_scripts['css'][] = $external_css;
                 $baseView->headLink()->appendStylesheet($external_css, 'screen');
             }
         }
         // Balises meta
         foreach ($base->metas as $metas) {
             foreach ($metas as $key => $meta) {
                 $type = $meta->attributes()->type;
                 $baseView->addMeta($type, $key, $meta->attributes()->value);
                 $this->_scripts['meta'][] = array('type' => (string) $type, 'key' => (string) $key, 'value' => (string) $meta->attributes()->value);
                 //                    switch($type) {
                 //                        case 'http-equiv':
                 //                            $baseView->headMeta()->appendHttpEquiv($key, $meta->attributes()->value);
                 //                        break;
                 //
                 //                        case 'name':
                 //                        default:
                 //                            $baseView->headMeta()->appendName($key, $meta->attributes()->value);
                 //                        break;
                 //                    }
             }
         }
         // Layout du template de base
         if (count($this->_xml->{$base->template}->views)) {
             foreach ($this->_xml->{$base->template}->views as $partials) {
                 foreach ($partials as $key => $partial) {
                     $class = (string) $partial->attributes()->class;
                     $template = (string) $partial->attributes()->template;
                     if (!empty($class) and !empty($template)) {
                         $this->addPartial($key, $class, $template);
                     }
                 }
             }
         }
     }
     // Layout
     foreach ($this->_xml->views as $partials) {
         foreach ($partials as $key => $partial) {
             if ($use_base or !$use_base and empty($partial->attributes()->no_ajax)) {
                 $class = (string) $partial->attributes()->class;
                 $template = (string) $partial->attributes()->template;
                 if (!empty($class) and !empty($template)) {
                     $this->addPartial($key, $class, $template);
                 }
             }
         }
     }
     // Actions
     if (isset($this->_xml->actions)) {
         foreach ($this->_xml->actions->children() as $partial => $values) {
             if ($partial = $this->getPartial($partial)) {
                 $method = (string) $values->attributes()->name;
                 if (is_callable(array($partial, $method))) {
                     $params = array();
                     if (count($values) == 1) {
                         foreach ($values as $key => $value) {
                             $params = (string) $value;
                         }
                     } else {
                         foreach ($values as $key => $value) {
                             $params[$key] = (string) $value;
                         }
                     }
                     $partial->{$method}($params);
                 }
             }
         }
     }
     // Classes dans le body
     if (isset($this->_xml->classes)) {
         $classes = array($baseView->default_class_name);
         foreach ($this->_xml->classes->children() as $class) {
             $classes[] = $class->attributes()->name;
         }
         $baseView->default_class_name = implode(' ', $classes);
     }
     if ($use_base) {
         $this->setBaseRender("base", (string) $base->template, null);
     } elseif (isset($this->_partials['base'])) {
         $this->setBaseRender($this->_partials['base']);
     } else {
         $this->setBaseRender($this->getFirstPartial());
     }
     return $this;
 }