7 * Full file system path to cache directory
13 * Full URL to cache directory
19 * Credentials for access
20 * username => secret key (used for signature)
23 public $access = false;
26 * How long requests with an old timestamp may be used.
31 public $timestampLifetime = 172800;
34 public function __construct()
36 $this->cacheDir = getcwd() . '/imgcache/';
37 $this->cacheDirUrl = $this->getCurrentUrlDir() . '/imgcache/';
40 public function load()
42 $cfgFile = __DIR__ . '/../../data/phancap.config.php';
43 if (file_exists($cfgFile)) {
44 $this->loadFile($cfgFile);
50 protected function loadFile($filename)
53 $vars = get_defined_vars();
54 foreach ($vars as $k => $value) {
59 public function setupCheck()
61 if (!is_dir($this->cacheDir)) {
62 throw new \Exception('Cache directory does not exist: ' . $this->cacheDir);
64 if (!is_writable($this->cacheDir)) {
65 throw new \Exception('Cache directory is not writable: ' . $this->cacheDir);
69 protected function getCurrentUrl()
71 if (!isset($_SERVER['REQUEST_SCHEME'])) {
72 $_SERVER['REQUEST_SCHEME'] = 'http';
74 return $_SERVER['REQUEST_SCHEME'] . '://'
75 . $_SERVER['HTTP_HOST']
76 . preg_replace('/#.*$/', '', $_SERVER['REQUEST_URI']);
79 protected function getCurrentUrlDir()
81 $url = $this->getCurrentUrl();
82 $url = preg_replace('/\?.*$/', '', $url);
83 if (substr($url, -1) == '/') {
87 return substr($url, 0, -strlen(basename($url)) - 1);