Beispiel #1
0
 /**
  * Convert a .scss or .less files to .css and include it in the page
  *
  * @param mixed $scss_files A string or array of scss files
  * @param string $type
  * @return bool
  */
 public static function Cache($file_array, $type = 'scss')
 {
     global $dataDir;
     //generage the name of the css file from the modified times and content length of each imported file
     $file_array = (array) $file_array;
     $type = strtolower($type);
     $files_hash = \gp\tool::ArrayHash($file_array);
     $list_file = $dataDir . '/data/_cache/' . $type . '_' . $files_hash . '.list';
     if (file_exists($list_file)) {
         $list = explode("\n", file_get_contents($list_file));
         //pop the etag
         $etag = array_pop($list);
         // generate an etag if needed or if logged in
         if (\gp\tool::LoggedIn()) {
             $etag = \gp\tool::FilesEtag($list);
         }
         $compiled_name = $type . '_' . $files_hash . '_' . $etag . '.css';
         $compiled_file = '/data/_cache/' . $compiled_name;
         if (file_exists($dataDir . $compiled_file)) {
             return $compiled_file;
         }
     }
     if ($type == 'less') {
         $compiled = self::ParseLess($file_array);
     } else {
         $compiled = self::ParseScss($file_array);
     }
     if (!$compiled) {
         return false;
     }
     // generate the file name
     $etag = \gp\tool::FilesEtag($file_array);
     $compiled_name = $type . '_' . $files_hash . '_' . $etag . '.css';
     $compiled_file = '/data/_cache/' . $compiled_name;
     // save the cache
     // use the last line for the etag
     $list = $file_array;
     $list[] = $etag;
     $cache = implode("\n", $list);
     if (!\gp\tool\Files::Save($list_file, $cache)) {
         return false;
     }
     //save the css
     if (\gp\tool\Files::Save($dataDir . $compiled_file, $compiled)) {
         return $compiled_file;
     }
     return false;
 }
Beispiel #2
0
 /**
  * Save any changes to the $gpAdmin array
  * @param string $file Session file path
  * @param string $checksum_read The original checksum of the $gpAdmin array
  *
  */
 public static function close($file, $checksum_read)
 {
     global $gpAdmin;
     self::FatalNotices();
     self::Cron();
     self::LayoutInfo();
     unset($gpAdmin['checksum']);
     $checksum = \gp\tool::ArrayHash($gpAdmin);
     //nothing changes
     if ($checksum === $checksum_read) {
         return;
     }
     if (!isset($gpAdmin['username'])) {
         trigger_error('username not set');
         die;
     }
     $gpAdmin['checksum'] = $checksum;
     //store the new checksum
     \gp\tool\Files::SaveData($file, 'gpAdmin', $gpAdmin);
 }
Beispiel #3
0
 /**
  * Check for fatal errors corresponing to $hash
  * Notify administrators of disabled components
  *
  */
 public static function FatalNotice($type, $info)
 {
     global $dataDir, $page;
     static $notified = false;
     $info = (array) $info;
     $info['catchable_type'] = $type;
     $hash = $type . '_' . \gp\tool::ArrayHash($info);
     self::$catchable[$hash] = $info;
     //no file = no fatal error
     $file = $dataDir . '/data/_site/fatal_' . $hash;
     if (!file_exists($file)) {
         return false;
     }
     $error_info = $error_text = file_get_contents($file);
     // if the file that caused the fatal error has been modified, treat as fixed
     if ($error_text[0] == '{' && ($error_info = json_decode($error_text, true))) {
         if (!empty($error_info['file']) && file_exists($error_info['file'])) {
             //compare modified time
             if (array_key_exists('file_modified', $error_info) && filemtime($error_info['file']) != $error_info['file_modified']) {
                 unlink($file);
                 return false;
             }
             //compare file size
             if (array_key_exists('file_size', $error_info) && filesize($error_info['file']) != $error_info['file_size']) {
                 unlink($file);
                 return false;
             }
         }
     }
     if (!$notified) {
         error_log('Warning: A component of this page has been disabled because it caused fatal errors');
         $notified = true;
     }
     self::PopCatchable();
     return true;
 }