/** * Возвращает список скриптов и стилей для использования на сайте. * * @mcms_message ru.molinos.cms.compressor.enumXXX */ public static function on_compressor_enum(Context $ctx, $mode = 'website') { $result = array(); $conf = $ctx->config->get('modules/tinymce'); $conf['gzip'] = false; if (empty($conf['gzip'])) { $result[] = array('script', 'lib/modules/tinymce/editor/tiny_mce.js'); } else { $result[] = array('script', 'lib/modules/tinymce/editor/tiny_mce_gzip.js'); } $initializer = empty($conf['initializer']) ? '' : $conf['initializer'] . ', '; $initializer .= 'document_base_url: "http://' . MCMS_HOST_NAME . $ctx->folder() . '/", '; $initializer .= 'tiny_mce_path: "lib/modules/tinymce/editor"'; $text = 'tinyMCE_initializer = {' . $initializer . '};'; os::write($path = os::path($ctx->config->getPath('main/tmpdir'), 'tinymce_initializer.js'), $text); $result[] = array('script', os::localpath($path)); $theme = empty($conf['theme']) ? 'simple' : $conf['theme']; if (!empty($conf['gzip'])) { if (file_exists($path = os::path('lib', 'modules', 'tinymce', 'editor', 'template_' . $theme . '_gzip.js'))) { $result[] = array('script', os::webpath($path)); } } if (file_exists($path = os::path('lib', 'modules', 'tinymce', 'editor', 'template_' . $theme . '.js'))) { $result[] = array('script', os::webpath($path)); } return $result; }
private static function compressCSS($filename) { $data = file_get_contents($filename); // Remove comments $data = preg_replace('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '', $data); // Remove tabs, spaces, newlines, etc. $data = preg_replace('/\\s+/s', ' ', $data); $data = str_replace(array(' {', '{ ', ' }', '} ', ' +', '+ ', ' >', '> ', ' :', ': ', ' ;', '; ', ' ,', ', ', ';}'), array('{', '{', '}', '}', '+', '+', '>', '>', ':', ':', ';', ';', ',', ',', '}'), $data); // Remove empty CSS declarations $data = preg_replace('/[^{}]++\\{\\}/', '', $data); // Fix relative url() $data = preg_replace('@(url\\(([^/][^)]+)\\))@i', 'url(' . MCMS_WEB_FOLDER . '/' . os::webpath(os::localpath(dirname($filename))) . '/\\2)', $data); return $data; }
public static function trace($message) { $trace = debug_backtrace(); if ($message instanceof Exception) { $trace = $message->getTrace(); array_unshift($trace, array('file' => $message->getFile(), 'line' => $message->getLine(), 'class' => 'throw', 'type' => ' new ', 'function' => get_class($message))); $message = get_class($message) . ': ' . $message->getMessage(); } error_log($message, 0); foreach ($trace as $line) { if (!empty($line['class']) and !empty($line['function'])) { $file = empty($line['file']) ? '???' : os::localpath($line['file']) . ' @' . $line['line']; error_log(" -- {$line['class']}{$line['type']}{$line['function']}() — {$file}", 0); } } error_log(' -- ' . MCMS_REQUEST_URI, 0); }
/** * Обрабатывает экстренное завершение работы. */ public static function on_shutdown() { if (null !== ($e = error_get_last()) and $e['type'] & (E_ERROR | E_RECOVERABLE_ERROR)) { $type = self::getErrorType($e['type']); self::send_error("shutdown[{$type}]: {$e['message']}", sprintf("File: %s\nLine: %u\n\n", os::localpath($e['file']), $e['line'])); } }
/** * Безопасная замена содержимого файла. * * Если не удастся сохранить новый файл — старый изменён не будет. */ public static function write($fileName, $content) { $vpath = dirname($fileName) . DIRECTORY_SEPARATOR . basename($fileName); if (!is_dir($dirName = dirname($fileName))) { if (!mkdir($dirName, 0775, true)) { throw new RuntimeException(t('Не удалось создать папку %path.', array('%path' => os::localpath($dirName)))); } } if (file_exists($fileName)) { if (!is_writable($fileName)) { if (is_writable(dirname($fileName))) { unlink($fileName); } else { throw new RuntimeException(t('Изменение файла %file невозможно: он защищён от записи.', array('%file' => self::localpath($vpath)))); } } } if (strlen($content) != @file_put_contents($fileName, $content)) { throw new RuntimeException(t('Не удалось записать файл %file, проверьте права на папку %folder.', array('%file' => self::localpath($vpath), '%folder' => dirname(self::localpath($vpath))))); } }