public function resize($filename, $width, $height) { if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) { return; } $info = pathinfo($filename); $extension = $info['extension']; $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension; if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!file_exists(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height); $image->save(DIR_IMAGE . $new_image); } if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) { return HTTPS_CATALOG . 'image/' . $new_image; } else { return HTTP_CATALOG . 'image/' . $new_image; } }
function template($filename, $flag = TEMPLATE_DISPLAY) { global $_W; $source = IA_ROOT . "/web/themes/{$_W['template']}/{$filename}.html"; $compile = IA_ROOT . "/data/tpl/web/{$_W['template']}/{$filename}.tpl.php"; if (!is_file($source)) { $source = IA_ROOT . "/web/themes/default/{$filename}.html"; $compile = IA_ROOT . "/data/tpl/web/default/{$filename}.tpl.php"; } if (!is_file($source)) { exit("Error: template source '{$filename}' is not exist!"); } if (DEVELOPMENT || !is_file($compile) || filemtime($source) > filemtime($compile)) { template_compile($source, $compile); } switch ($flag) { case TEMPLATE_DISPLAY: default: extract($GLOBALS, EXTR_SKIP); include $compile; break; case TEMPLATE_FETCH: extract($GLOBALS, EXTR_SKIP); ob_clean(); ob_start(); include $compile; $contents = ob_get_contents(); ob_clean(); return $contents; break; case TEMPLATE_INCLUDEPATH: return $compile; break; } }
function display($tmpl_file, $app_id = null) { array_unshift($this->_files, $tmpl_file); $this->_vars = $this->pagedata; if ($p = strpos($tmpl_file, ':')) { $object = kernel::service('tpl_source.' . substr($tmpl_file, 0, $p)); if ($object) { $tmpl_file_path = substr($tmpl_file, $p + 1); $last_modified = $object->last_modified($tmpl_file_path); } } else { $tmpl_file = realpath(APP_DIR . '/' . ($app_id ? $app_id : $this->app->app_id) . '/view/' . $tmpl_file); $last_modified = filemtime($tmpl_file); } if (!$last_modified) { //无文件 } $compile_id = $this->compile_id($tmpl_file); if ($object) { $compile_code = $this->_compiler()->compile($object->get_file_contents($tmpl_file_path)); } else { $compile_code = $this->_compiler()->compile_file($tmpl_file); } eval('?>' . $compile_code); array_shift($this->_files); }
/** * Render home category list xml * * @return string */ protected function _toHtml() { /** @var $homeXmlObj Mage_XmlConnect_Model_Simplexml_Element */ $homeXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<home></home>'); $categoryCollection = array(); $helper = Mage::helper('catalog/category'); $categoryCount = 0; foreach ($helper->getStoreCategories() as $child) { if ($child->getIsActive()) { $categoryCollection[] = $child; $categoryCount++; } if ($categoryCount == self::HOME_PAGE_CATEGORIES_COUNT) { break; } } if (sizeof($categoryCollection)) { $itemsXmlObj = $homeXmlObj->addChild('categories'); } foreach ($categoryCollection as $item) { /** @var $item Mage_Catalog_Model_Category */ $item = Mage::getModel('catalog/category')->load($item->getId()); $itemXmlObj = $itemsXmlObj->addChild('item'); $itemXmlObj->addChild('label', $homeXmlObj->xmlentities($item->getName())); $itemXmlObj->addChild('entity_id', $item->getId()); $itemXmlObj->addChild('content_type', $item->hasChildren() ? 'categories' : 'products'); $icon = Mage::helper('xmlconnect/catalog_category_image')->initialize($item, 'thumbnail')->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('category')); $iconXml = $itemXmlObj->addChild('icon', $icon); $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); } $homeXmlObj->addChild('home_banner', '/current/media/catalog/category/banner_home.png'); return $homeXmlObj->asNiceXml(); }
public function data() { $data = $this->toArray(); $data["modified"] = filemtime($this->file); $data["foundry_version"] = "3.1.15"; return $data; }
/** * @group internet * @group slow */ public function test_recache() { global $conf; $conf['fetchsize'] = 500 * 1024; //500kb $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png', 'png', 5); $this->assertTrue($local !== false); $this->assertFileExists($local); // remember time stamp $time = filemtime($local); clearstatcache(false, $local); sleep(1); // fetch again and make sure we got a cache file $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png', 'png', 5); clearstatcache(false, $local); $this->assertTrue($local !== false); $this->assertFileExists($local); $this->assertEquals($time, filemtime($local)); clearstatcache(false, $local); sleep(6); // fetch again and make sure we got a new file $local = media_get_from_URL('http://www.google.com/images/srpr/logo3w.png', 'png', 5); clearstatcache(false, $local); $this->assertTrue($local !== false); $this->assertFileExists($local); $this->assertNotEquals($time, filemtime($local)); unlink($local); }
/** * Creates and caches the image thumbnail and returns full path from thumbnail file. * * @param string $filename * @param integer $width * @param integer $height * @param string $mode * @return string * @throws FileNotFoundException */ public static function thumbnailFile($filename, $width, $height, $mode = self::THUMBNAIL_OUTBOUND) { $filename = FileHelper::normalizePath(Yii::getAlias($filename)); if (!is_file($filename)) { throw new FileNotFoundException("File {$filename} doesn't exist"); } $cachePath = Yii::getAlias('@webroot/' . self::$cacheAlias); $thumbnailFileExt = strrchr($filename, '.'); $thumbnailFileName = md5($filename . $width . $height . $mode . filemtime($filename)); $thumbnailFilePath = $cachePath . DIRECTORY_SEPARATOR . substr($thumbnailFileName, 0, 2); $thumbnailFile = $thumbnailFilePath . DIRECTORY_SEPARATOR . $thumbnailFileName . $thumbnailFileExt; if (file_exists($thumbnailFile)) { if (self::$cacheExpire !== 0 && time() - filemtime($thumbnailFile) > self::$cacheExpire) { unlink($thumbnailFile); } else { return $thumbnailFile; } } if (!is_dir($thumbnailFilePath)) { mkdir($thumbnailFilePath, 0755, true); } $box = new Box($width, $height); $image = Image::getImagine()->open($filename); $image = $image->thumbnail($box, $mode); $image->save($thumbnailFile); return $thumbnailFile; }
function tplsadmin_copy_templates_f2db($tplset_to, $whr_append = '1') { global $db; // get tplsource $result = $db->query("SELECT * FROM " . $db->prefix("tplfile") . " WHERE tpl_tplset='default' AND ({$whr_append})"); while ($row = $db->fetchArray($result)) { $basefilepath = tplsadmin_get_basefilepath($row['tpl_module'], $row['tpl_type'], $row['tpl_file']); $tpl_source = rtrim(implode("", file($basefilepath))); $lastmodified = filemtime($basefilepath); $drs = $db->query("SELECT tpl_id FROM " . $db->prefix("tplfile") . " WHERE tpl_tplset='" . addslashes($tplset_to) . "' AND ({$whr_append}) AND tpl_file='" . addslashes($row['tpl_file']) . "' AND tpl_refid='" . addslashes($row['tpl_refid']) . "'"); if (!$db->getRowsNum($drs)) { // INSERT mode $sql = "INSERT INTO " . $db->prefix("tplfile") . " SET tpl_refid='" . addslashes($row['tpl_refid']) . "',tpl_desc='" . addslashes($row['tpl_desc']) . "',tpl_lastmodified='" . addslashes($lastmodified) . "',tpl_type='" . addslashes($row['tpl_type']) . "',tpl_tplset='" . addslashes($tplset_to) . "',tpl_file='" . addslashes($row['tpl_file']) . "',tpl_module='" . addslashes($row['tpl_module']) . "'"; $db->query($sql); $tpl_id = $db->getInsertId(); $db->query("INSERT INTO " . $db->prefix("tplsource") . " SET tpl_id='{$tpl_id}', tpl_source='" . addslashes($tpl_source) . "'"); altsys_template_touch($tpl_id); } else { while (list($tpl_id) = $db->fetchRow($drs)) { // UPDATE mode $db->query("UPDATE " . $db->prefix("tplfile") . " SET tpl_lastmodified='" . addslashes($lastmodified) . "' WHERE tpl_id='{$tpl_id}'"); $db->query("UPDATE " . $db->prefix("tplsource") . " SET tpl_source='" . addslashes($tpl_source) . "' WHERE tpl_id='{$tpl_id}'"); altsys_template_touch($tpl_id); } } } }
/** * Creates a stylesheet link with LESS support * * @param string $style file name * @param array $attributes default attributes * @param bool $index include the index page * @param array $imports compare file date for these too, CSS and LESS in style @import * @return string */ public static function style($file, array $attributes = null, $index = false, $imports = null) { $imports = (array) $imports; // Compile only .less files if (substr_compare($file, '.less', -5, 5, false) === 0) { $css = substr_replace($file, 'css', -4); $compiled = is_file($css) ? filemtime($css) : 0; try { // Check if imported files have changed $compile = filemtime($file) > $compiled; if (!$compile && !empty($imports)) { foreach ($imports as $import) { if (filemtime($import) > $compiled) { $compile = true; break; } } } // Compile LESS if ($compile) { $compiler = new self($file); file_put_contents($css, $compiler->parse()); } $file = $css; } catch (Exception $e) { Kohana::$log->add(Kohana::ERROR, __METHOD__ . ': Error compiling LESS file ' . $file . ', ' . $e->getMessage()); } } return HTML::style($file . '?' . filemtime($file), $attributes, $index); }
public function load($locale, $locale_path, $domain, $textdomain = true) { $file = $locale_path . '/' . $locale . '/LC_MESSAGES/' . $domain . '.po'; $cache_file = waSystem::getInstance()->getConfig()->getPath('cache') . '/apps/' . $domain . '/locale/' . $locale . '.php'; if (isset(self::$cache[$locale][$domain])) { } elseif (!file_exists($file)) { self::$cache[$locale][$domain] = array(); } elseif (file_exists($cache_file) && filemtime($cache_file) > filemtime($file)) { self::$cache[$locale][$domain] = (include $cache_file); } else { if (file_exists($file)) { $gettext = new waGettext($file); self::$cache[$locale][$domain] = $gettext->read(); } else { self::$cache[$locale][$domain] = array(); } waFiles::create($cache_file); waUtils::varExportToFile(self::$cache[$locale][$domain], $cache_file); } if (isset(self::$cache[$locale][$domain]['meta']['Plural-Forms']['plural']) && self::$cache[$locale][$domain]['meta']['Plural-Forms']['plural']) { self::$cache[$locale][$domain]['meta']['f'] = create_function('$n', self::$cache[$locale][$domain]['meta']['Plural-Forms']['plural']); } if ($textdomain) { self::$domain = $domain; self::$locale = $locale; } if (!self::$locale) { self::$locale = $locale; } }
/** * Retrieves data from cache, if it's there. If it is, but it's expired, * it performs a conditional GET to see if the data is updated. If it * isn't, it down updates the modification time of the cache file and * returns the data. If the cache is not there, or the remote file has been * modified, it is downloaded and cached. * * @param string URL of remote file to retrieve * @param int Length of time to cache file locally before asking the server * if it changed. * @return string File contents */ function retrieveFile($url, $cacheLength, $cacheDir) { $cacheID = md5($url); $cache = new Cache_Lite(array("cacheDir" => $cacheDir, "lifeTime" => $cacheLength)); if ($data = $cache->get($cacheID)) { return $data; } else { // we need to perform a request, so include HTTP_Request include_once 'HTTP/Request.php'; // HTTP_Request has moronic redirect "handling", turn that off (Alexey Borzov) $req = new HTTP_Request($url, array('allowRedirects' => false)); // if $cache->get($cacheID) found the file, but it was expired, // $cache->_file will exist if (isset($cache->_file) && file_exists($cache->_file)) { $req->addHeader('If-Modified-Since', gmdate("D, d M Y H:i:s", filemtime($cache->_file)) . " GMT"); } $req->sendRequest(); if (!($req->getResponseCode() == 304)) { // data is changed, so save it to cache $data = $req->getResponseBody(); $cache->save($data, $cacheID); return $data; } else { // retrieve the data, since the first time we did this failed if ($data = $cache->get($cacheID, 'default', true)) { return $data; } } } Services_ExchangeRates::raiseError("Unable to retrieve file {$url} (unknown reason)", SERVICES_EXCHANGERATES_ERROR_RETRIEVAL_FAILED); return false; }
public static function minifyTemplateFile($mTimeFile, $fileToMinify, $targetMinifiedFile, $ext) { file_put_contents($targetMinifiedFile, $ext == 'js' ? static::minifyJs($fileToMinify) : static::minifyCss($fileToMinify)); chmod($targetMinifiedFile, 0775); file_put_contents($mTimeFile, filemtime($fileToMinify)); chmod($mTimeFile, 0775); }
/** * 写入缓存 * @param string $name 缓存文件名字 * @param function $callback 回调函数,必须要有返回值 * @param Array or string or Object $params 要传进去的参数 * @param int $time 写入的缓存时间 * @return array * @author wave */ public static function wirte($name, $callback, $params = null, $time = TIME) { self::init(); $file = ROOT . DS . APP_PATH . DS . self::$cache_dir; $content = ''; if (!file_exists($file . self::CACHE_PREFIX . $name)) { $content = $callback($params); if (!empty($content)) { file_put_contents($file . self::CACHE_PREFIX . $name, gzcompress(serialize($content))); return; } } if (empty($time)) { return; } if (file_exists($file . self::CACHE_PREFIX . $name)) { $cache_time = strtotime(date('Y-m-d H:i:s')) - strtotime(date('Y-m-d H:i:s', filemtime($file . self::CACHE_PREFIX . $name))); if ($cache_time / 1000 >= $time || $time == 1) { $content = $callback($params); if (!empty($content)) { file_put_contents($file . self::CACHE_PREFIX . $name, gzcompress(serialize($content))); return; } } } }
function sortByModified($files) { $hasComplexKeys = false; $tmpFiles = array(); foreach ($files as $file) { $key = @filemtime(JPATH_ROOT . DS . $file); if (isset($tmpFiles[$key])) { $hasComplexKeys = true; if (!is_array($tmpFiles[$key])) { $tmpFiles[$key] = array($tmpFiles[$key]); } $tmpFiles[$key][] = $file; } else { $tmpFiles[$key] = $file; } ksort($tmpFiles, SORT_NUMERIC); } if (!$hasComplexKeys) { $files = array_values($tmpFiles); } else { $files = array(); $tmpFiles = array_values($tmpFiles); foreach ($tmpFiles as $file) { if (is_array($file)) { $files = array_merge($files, $file); } else { $files[] = $file; } } } return $files; }
/** * @param string $type The type of init to load, possible values are: frontend, frontend_ajax, frontend_js. */ public function initialize($type) { $type = (string) $type; // check if this is a valid type if (!in_array($type, $this->allowedTypes)) { exit('Invalid init-type'); } $this->type = $type; // set a default timezone if no one was set by PHP.ini if (ini_get('date.timezone') == '') { date_default_timezone_set('Europe/Brussels'); } // get last modified time for globals $lastModifiedTime = @filemtime(PATH_WWW . '/app/config/parameters.yml'); // reset last modified time if needed when invalid or debug is active if ($lastModifiedTime === false || $this->getContainer()->getParameter('kernel.debug')) { $lastModifiedTime = time(); } // define as a constant defined('LAST_MODIFIED_TIME') || define('LAST_MODIFIED_TIME', $lastModifiedTime); $this->definePaths(); $this->defineURLs(); $this->setDebugging(); // require spoon require_once 'spoon/spoon.php'; }
function Get($rss_url) { // If CACHE ENABLED if ($this->cache_dir != '') { $cache_file = $this->cache_dir . '/rsscache_' . md5($rss_url); $timedif = @(time() - filemtime($cache_file)); if ($timedif < $this->cache_time) { // cached file is fresh enough, return cached array $result = unserialize(join('', file($cache_file))); // set 'cached' to 1 only if cached file is correct if ($result) { $result['cached'] = 1; } } else { // cached file is too old, create new $result = $this->Parse($rss_url); $serialized = serialize($result); if ($f = @fopen($cache_file, 'w')) { fwrite($f, $serialized, strlen($serialized)); fclose($f); } if ($result) { $result['cached'] = 0; } } } else { $result = $this->Parse($rss_url); if ($result) { $result['cached'] = 0; } } // return result return $result; }
function fa_cache_avatar($avatar, $id_or_email, $size, $default, $alt) { $avatar = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "cn.gravatar.com", $avatar); $tmp = strpos($avatar, 'http'); $url = get_avatar_url($id_or_email, $size); $url = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "cn.gravatar.com", $url); $avatar2x = get_avatar_url($id_or_email, $size * 2); $avatar2x = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "cn.gravatar.com", $avatar2x); $g = substr($avatar, $tmp, strpos($avatar, "'", $tmp) - $tmp); $tmp = strpos($g, 'avatar/') + 7; $f = substr($g, $tmp, strpos($g, "?", $tmp) - $tmp); $w = home_url(); $e = ABSPATH . 'avatar/' . $size . '*' . $f . '.jpg'; $e2x = ABSPATH . 'avatar/' . $size * 2 . '*' . $f . '.jpg'; $t = 1209600; if ((!is_file($e) || time() - filemtime($e) > $t) && (!is_file($e2x) || time() - filemtime($e2x) > $t)) { copy(htmlspecialchars_decode($g), $e); copy(htmlspecialchars_decode($avatar2x), $e2x); } else { $avatar = $w . '/avatar/' . $size . '*' . $f . '.jpg'; $avatar2x = $w . '/avatar/' . $size * 2 . '*' . $f . '.jpg'; if (filesize($e) < 1000) { copy($w . '/avatar/default.jpg', $e); } if (filesize($e2x) < 1000) { copy($w . '/avatar/default.jpg', $e2x); } $avatar = "<img alt='{$alt}' src='{$avatar}' srcset='{$avatar2x}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />"; } return $avatar; }
/** * 检查缓存文件是否有效 * 如果无效则需要重新编译 * @access public * @param string $tmplTemplateFile 模板文件名 * @return boolean */ protected function checkCache($tmplTemplateFile, $prefix = '') { if (!C('TMPL_CACHE_ON')) { // 优先对配置设定检测 return false; } $tmplCacheFile = C('CACHE_PATH') . $prefix . md5($tmplTemplateFile) . C('TMPL_CACHFILE_SUFFIX'); if (!Storage::has($tmplCacheFile, 'tpl')) { return false; } elseif (filemtime($tmplTemplateFile) > Storage::get($tmplCacheFile, 'mtime', 'tpl')) { // 模板文件如果有更新则缓存需要更新 return false; } elseif (C('TMPL_CACHE_TIME') != 0 && time() > Storage::get($tmplCacheFile, 'mtime', 'tpl') + C('TMPL_CACHE_TIME')) { // 缓存是否在有效期 return false; } // 开启布局模板 if (C('LAYOUT_ON')) { $layoutFile = THEME_PATH . C('LAYOUT_NAME') . C('TMPL_TEMPLATE_SUFFIX'); if (filemtime($layoutFile) > Storage::get($tmplCacheFile, 'mtime', 'tpl')) { return false; } } // 缓存有效 return true; }
public function preRender() { if (Zend_Auth::getInstance()->hasIdentity()) { $controller = sgContext::getInstance()->getController(); if ($controller instanceof FlatCMSPluginController) { $session = new Zend_Session_Namespace(Zend_Auth::getInstance()->getStorage()->getNamespace()); $session->FlatCMSEditorPluginFileMTime = filemtime(FlatCMSPluginPageModel::getPagePath(sgContext::getInstance()->getCurrentPath())); //figure out better way to handle this so libraries aren't double loaded $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.min.js'); $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.mini.js'); $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.autogrow.js'); $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/tinymce/jscripts/tiny_mce/jquery.tinymce.js'); $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.tinymce.js'); $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/init.js'); $controller->js_settings['FlatCMSEditorPlugin'] = array('saveURL' => sgToolkit::url(sgConfiguration::get('routing.FlatCMSEditorPlugin_save.path')), 'currentPath' => sgContext::getInstance()->getCurrentPath()); if (isset($controller->content) && is_array($controller->content)) { $textarea_fields = sgConfiguration::get('settings.FlatCMSEditorPlugin.textarea_fields', array()); foreach ($controller->content as $key => &$field) { if (in_array($key, $textarea_fields)) { $field = '<div class="editable-area" id="' . $key . '">' . $field . '</div>'; } else { $field = '<div class="editable" id="' . $key . '">' . $field . '</div>'; } } } } } }
function backup_delete_old_dirs($delete_from) { global $CFG; $status = true; //Get files and directories in the temp backup dir witout descend $list = get_directory_list($CFG->dataroot . "/temp/backup", "", false, true, true); foreach ($list as $file) { $file_path = $CFG->dataroot . "/temp/backup/" . $file; $moddate = filemtime($file_path); if ($status && $moddate < $delete_from) { //If directory, recurse if (is_dir($file_path)) { $status = delete_dir_contents($file_path); //There is nothing, delete the directory itself if ($status) { $status = rmdir($file_path); } //If file } else { unlink("{$file_path}"); } } } return $status; }
/** * Build a secured file with token name * * @param string $reqkey The reference key * * @return string The secure key */ function buildSecFile($reqkey) { $CI =& get_instance(); $skey = mt_rand(); $dir = $CI->config->item('token_dir'); $file = $skey . '.tok'; //make the file with the reqkey value in it file_put_contents($dir . '/' . $file, $reqkey); //do some cleanup - find ones older then the threshold and remove $rm = $CI->config->item('token_rm'); //this is in minutes if (is_dir($dir)) { if (($h = opendir($dir)) !== false) { while (($file = readdir($h)) !== false) { if (!in_array($file, array('.', '..'))) { $p = $dir . '/' . $file; if (filemtime($p) < time() - $rm * 60) { unlink($p); } } } } } return $skey; }
public function __construct() { parent::__construct(); if (isset($this->post['dir'])) { $dir = $this->checkInputDir($this->post['dir'], true, false); if ($dir === false) { unset($this->post['dir']); } $this->post['dir'] = $dir; } if (isset($this->get['dir'])) { $dir = $this->checkInputDir($this->get['dir'], true, false); if ($dir === false) { unset($this->get['dir']); } $this->get['dir'] = $dir; } $thumbsDir = $this->config['uploadDir'] . "/" . $this->config['thumbsDir']; if (!is_dir($thumbsDir) && !@mkdir($thumbsDir, $this->config['dirPerms']) || !is_readable($thumbsDir) || !dir::isWritable($thumbsDir) || !is_dir("{$thumbsDir}/{$this->type}") && !@mkdir("{$thumbsDir}/{$this->type}", $this->config['dirPerms'])) { $this->errorMsg("Cannot access or create thumbnails folder."); } $this->thumbsDir = $thumbsDir; $this->thumbsTypeDir = "{$thumbsDir}/{$this->type}"; // Remove temporary zip downloads if exists $files = dir::content($this->config['uploadDir'], array('types' => "file", 'pattern' => '/^.*\\.zip$/i')); if (is_array($files) && count($files)) { $time = time(); foreach ($files as $file) { if (is_file($file) && $time - filemtime($file) > 3600) { unlink($file); } } } }
public function __construct($fileName) { $this->file = fopen($fileName, "rb"); $this->fileName = $fileName; $this->fileSize = $this->my_filesize($this->file); $this->filemtime = filemtime($fileName); }
public function load_page($url_path = false) { global $htmlwarrior, $smarty; if ($url_path === false) { $url_path = $htmlwarrior->runtime['parsed_url']['path']; } $page_tpl_path = get_page_template_path($url_path); $page_object = $smarty->createTemplate($page_tpl_path); $page_content_before_assigns = $smarty->fetch($page_object); $page_variables = parse_variables($page_content_before_assigns); if (isset($page_variables['php'])) { $page_template_php_path = $htmlwarrior->config['basepath'] . '/' . $htmlwarrior->runtime['site_dir'] . $htmlwarrior->config['path_templates_pages'] . '/' . $page_variables['php']; } else { $page_template_php_path = str_replace('.tpl', '.php', $page_tpl_path); } // load page php if (file_exists($page_template_php_path)) { $__init_page_php = function ($page_template_php_path) { global $htmlwarrior; require_once $page_template_php_path; return $params; }; $params = $__init_page_php($page_template_php_path); } $page_object = $smarty->createTemplate($page_tpl_path); foreach ($params as $key => $val) { $page_object->assign($key, $val); } $page_object->assign('page', $htmlwarrior->page); $page_content = $smarty->fetch($page_object); if ($htmlwarrior->config['build']) { $template_filetime = filemtime($page_tpl_path); } return array($page_content, $page_variables); }
function tag() { $doc = JFactory::getDocument(); $doc->addStyleSheet(ACYMAILING_CSS . 'frontendedition.css?v=' . filemtime(ACYMAILING_MEDIA . 'css' . DS . 'frontendedition.css')); JPluginHelper::importPlugin('acymailing'); $dispatcher = JDispatcher::getInstance(); $tagsfamilies = $dispatcher->trigger('acymailing_getPluginType'); $defaultFamily = reset($tagsfamilies); $app = JFactory::getApplication(); $fctplug = $app->getUserStateFromRequest(ACYMAILING_COMPONENT . ".tag", 'fctplug', $defaultFamily->function, 'cmd'); ob_start(); $defaultContents = $dispatcher->trigger($fctplug); $defaultContent = ob_get_clean(); $js = 'function insertTag(){if(window.parent.insertTag(window.document.getElementById(\'tagstring\').value)) {acymailing_js.closeBox(true);}}'; $js .= 'function setTag(tagvalue){window.document.getElementById(\'tagstring\').value = tagvalue;}'; $js .= 'function showTagButton(){window.document.getElementById(\'insertButton\').style.display = \'inline\'; window.document.getElementById(\'tagstring\').style.display=\'inline\';}'; $js .= 'function hideTagButton(){}'; $js .= 'try{window.parent.previousSelection = window.parent.getPreviousSelection(); }catch(err){window.parent.previousSelection=false; }'; $doc->addScriptDeclaration($js); $this->assignRef('fctplug', $fctplug); $type = JRequest::getString('type', 'news'); $this->assignRef('type', $type); $this->assignRef('defaultContent', $defaultContent); $this->assignRef('tagsfamilies', $tagsfamilies); $app = JFactory::getApplication(); $this->assignRef('app', $app); $ctrl = JRequest::getString('ctrl'); $this->assignRef('ctrl', $ctrl); }
/** * Factory fuction which produces a configuration based on a policy and based * on local system resources. * * @param $policy array: * - enable_ssl: bool; default: TRUE * - verify_peer: bool; default: TRUE * - cafile: string, path to aggregated PEM; overrides any system defaults * - fallback_cafile: string, path to aggregated PEM; used on systems which lack default; set FALSE to disable * - fallback_ttl: int, seconds, the max age of the fallback cafile before it's regarded as stale; default: 5 years * @return CA_Config_Stream */ public static function probe($policy = array()) { if (isset($policy['enable_ssl']) && $policy['enable_ssl'] === FALSE) { return new CA_Config_Stream(FALSE, FALSE, NULL); } $sw = stream_get_wrappers(); if (!extension_loaded('openssl') || !in_array('https', $sw)) { return new CA_Config_Stream(FALSE, FALSE, NULL); } if (isset($policy['verify_peer']) && $policy['verify_peer'] === FALSE) { return new CA_Config_Stream(TRUE, FALSE, NULL); } if (isset($policy['cafile'])) { if (file_exists($policy['cafile']) && is_readable($policy['cafile'])) { return new CA_Config_Stream(TRUE, TRUE, $policy['cafile']); } else { throw new Exception("Certificate Authority file is missing. Please contact the system administrator. See also: " . $policy['cafile']); } } if (!isset($policy['fallback_ttl'])) { $policy['fallback_ttl'] = 5 * 364 * 24 * 60 * 60; } if (!isset($policy['fallback_cafile'])) { $policy['fallback_cafile'] = dirname(__FILE__) . '/cacert.pem'; } if (empty($policy['fallback_cafile']) || !file_exists($policy['fallback_cafile'])) { throw new Exception("Certificate Authority file is required for SSL. Please contact the system administrator."); } elseif (time() > filemtime($policy['fallback_cafile']) + $policy['fallback_ttl']) { throw new Exception("Certificate Authority file is too old. Please contact the system administrator. See also: " . $policy['fallback_cafile']); } else { return new CA_Config_Stream(TRUE, TRUE, $policy['fallback_cafile']); } }
/** * 遍历目录内容 * @param string $dirName 目录名 * @param string $exts 读取的文件扩展名 * @param int $son 是否显示子目录 * @param array $list * @return array */ public static function tree($dirName = null, $exts = '', $son = 0, $list = array()) { if (is_null($dirName)) { $dirName = '.'; } $dirPath = self::dirPath($dirName); static $id = 0; if (is_array($exts)) { $exts = implode("|", $exts); } foreach (glob($dirPath . '*') as $v) { $id++; if (is_dir($v) || !$exts || preg_match("/\\.({$exts})/i", $v)) { $list[$id]['name'] = basename($v); $list[$id]['path'] = str_replace("\\", "/", realpath($v)); $list[$id]['type'] = filetype($v); $list[$id]['filemtime'] = filemtime($v); $list[$id]['fileatime'] = fileatime($v); $list[$id]['size'] = is_file($v) ? filesize($v) : self::get_dir_size($v); $list[$id]['iswrite'] = is_writeable($v) ? 1 : 0; $list[$id]['isread'] = is_readable($v) ? 1 : 0; } if ($son) { if (is_dir($v)) { $list = self::tree($v, $exts, $son = 1, $list); } } } return $list; }
function __construct() { $this->cache = new Cache(); if (file_exists($this->cache->hash_loc)) { $this->cache->init(file_get_contents($this->cache->hash_loc)); if (file_exists($this->cache->loc)) { $this->cache->preserve(); } } if ($this->cache->exists and time() - filemtime($this->cache->loc) < 60 * 60 * 24) { return; } else { try { $this->soundcloud = new Soundcloud(USER_ID_SOUNDCLOUD); } catch (Exception $e) { $this->abort = true; return; } $this->soundcloud->parse(); $this->cache->init(md5($this->soundcloud->locations)); if ($this->cache->exists and $this->cache->hash == $this->cache->old->hash) { return; } $this->cache->stash_hash(); $this->cache->stash_cache($this->soundcloud->locations); $this->cache->touch(); if (!$this->cache->check()) { $this->abort = true; } } }
/** * RSSをダウンロードし、パース結果を返す */ function p2GetRSS($remotefile, $atom = 0) { global $_conf; $refresh = !empty($_GET['refresh']) || !empty($_POST['refresh']); $localpath = rss_get_save_path($remotefile); if (PEAR::isError($localpath)) { P2Util::pushInfoHtml('<p>' . $localpath->getMessage() . '</p>'); return $localpath; } // 保存用ディレクトリがなければつくる if (!is_dir(dirname($localpath))) { FileCtl::mkdirFor($localpath); } // If-Modified-Sinceつきでダウンロード(ファイルが無いか、古いか、強制リロードのとき) if (!file_exists($localpath) || $refresh || filemtime($localpath) < time() - $_conf['expack.rss.check_interval'] * 60) { $dl = P2Util::fileDownload($remotefile, $localpath, true, 301); if ($dl->isSuccess()) { chmod($localpath, $_conf['expack.rss.setting_perm']); } } // キャッシュが更新されなかったか、ダウンロード成功ならRSSをパース if (file_exists($localpath) && (!isset($dl) || $dl->isSuccess())) { if ($atom) { $atom = isset($dl) && $dl->code == 200 ? 2 : 1; } $rss = p2ParseRSS($localpath, $atom); return $rss; } else { return $dl; } }
public function getCreationDate() { $date = new \DateTime(); $date->setTimezone(new \DateTimeZone('UTC')); $date->setTimestamp(filemtime($this->getDir())); return $date; }