public static function getAndroidSenderId() { if (is_null(self::$_android_sender_id)) { $certificat = new self(); $certificat->find('android_sender_id', 'type'); self::$_android_sender_id = $certificat->getPath(); } return self::$_android_sender_id; }
public static function run($config = [], $isConsoleApp = false, $path = '') { static $inst = null; if (null === $inst) { $inst = new self($isConsoleApp); \CW::$app = $inst; $inst->components = isset($config['components']) ? $config['components'] : []; $inst->params = isset($config['params']) ? $config['params'] : []; if (!$isConsoleApp) { $inst->dispatch($inst->getPath($path)); } } }
/** * Resolve a base URI with a relative URI and return a new URI. * * @param UriInterface $base Base URI * @param null|string|UriInterface $rel Relative URI * * @throws \InvalidArgumentException * * @return UriInterface */ public static function resolve(UriInterface $base, $rel = null) { if ($rel === null || $rel === '') { return $base; } if (!$rel instanceof UriInterface) { $rel = new self($rel); } // Return the relative uri as-is if it has a scheme. if ($rel->getScheme()) { return $rel->withPath(static::removeDotSegments($rel->getPath())); } $relParts = ['scheme' => $rel->getScheme(), 'authority' => $rel->getAuthority(), 'path' => $rel->getPath(), 'query' => $rel->getQuery(), 'fragment' => $rel->getFragment()]; $parts = ['scheme' => $base->getScheme(), 'authority' => $base->getAuthority(), 'path' => $base->getPath(), 'query' => $base->getQuery(), 'fragment' => $base->getFragment()]; if (!empty($relParts['path'])) { if (strpos($relParts['path'], '/') === 0) { $parts['path'] = self::removeDotSegments($relParts['path']); $parts['query'] = $relParts['query']; $parts['fragment'] = $relParts['fragment']; } else { $mergedPath = substr($parts['path'], 0, strrpos($parts['path'], '/') + 1); $parts['path'] = self::removeDotSegments($mergedPath . $relParts['path']); $parts['query'] = $relParts['query']; $parts['fragment'] = $relParts['fragment']; } } elseif (!empty($relParts['query'])) { $parts['query'] = $relParts['query']; } elseif ($relParts['fragment'] !== null) { $parts['fragment'] = $relParts['fragment']; } return new self(static::createUriString($parts['scheme'], $parts['authority'], $parts['path'], $parts['query'], $parts['fragment'])); }
/** * Test whether this URL belongs to the local Apparat instance * * @return bool URL belongs to the local Apparat instance */ public function isAbsoluteLocal() { // Instantiate the apparat base URL $apparatBaseUrl = new self(getenv('APPARAT_BASE_URL')); $apparatBaseUrlPath = $apparatBaseUrl->getPath(); $apparatBaseUrl = $apparatBaseUrl->setScheme(null)->setPath(null); // If the URL matches the Apparat base URL (the scheme is disregarded) return $this->isAbsolute() && $this->matches($apparatBaseUrl) && !strncmp($apparatBaseUrlPath, $this->getPath(), strlen($apparatBaseUrlPath)); }
/** * Returns the edit theme. * By default the edit theme is loaded from the cms.editTheme parameter, * but this behavior can be overridden by the cms.editTheme event listeners. * If the edit theme is not defined in the configuration file, the active theme * is returned. * @return \Cms\Classes\Theme Returns the loaded theme object. * If the theme doesn't exist, returns null. */ public static function getEditTheme() { $editTheme = Config::get('cms.editTheme'); if (!$editTheme) { $editTheme = Config::get('cms.activeTheme'); } $apiResult = Event::fire('cms.editTheme', [], true); if ($apiResult !== null) { $editTheme = $apiResult; } if (!strlen($editTheme)) { throw new SystemException(Lang::get('cms::lang.theme.edit.not_set')); } $theme = new self(); $theme->load($editTheme); if (!File::isDirectory($theme->getPath())) { return null; } return $theme; }
/** * Resolve a base URI with a relative URI and return a new URI. * * @param UriInterface $base Base URI * @param string|UriInterface $rel Relative URI * * @return UriInterface * @link http://tools.ietf.org/html/rfc3986#section-5.2 */ public static function resolve(UriInterface $base, $rel) { if (!$rel instanceof UriInterface) { $rel = new self($rel); } if ((string) $rel === '') { // we can simply return the same base URI instance for this same-document reference return $base; } if ($rel->getScheme() != '') { return $rel->withPath(self::removeDotSegments($rel->getPath())); } if ($rel->getAuthority() != '') { $targetAuthority = $rel->getAuthority(); $targetPath = self::removeDotSegments($rel->getPath()); $targetQuery = $rel->getQuery(); } else { $targetAuthority = $base->getAuthority(); if ($rel->getPath() === '') { $targetPath = $base->getPath(); $targetQuery = $rel->getQuery() != '' ? $rel->getQuery() : $base->getQuery(); } else { if ($rel->getPath()[0] === '/') { $targetPath = $rel->getPath(); } else { if ($targetAuthority != '' && $base->getPath() === '') { $targetPath = '/' . $rel->getPath(); } else { $lastSlashPos = strrpos($base->getPath(), '/'); if ($lastSlashPos === false) { $targetPath = $rel->getPath(); } else { $targetPath = substr($base->getPath(), 0, $lastSlashPos + 1) . $rel->getPath(); } } } $targetPath = self::removeDotSegments($targetPath); $targetQuery = $rel->getQuery(); } } return new self(self::createUriString($base->getScheme(), $targetAuthority, $targetPath, $targetQuery, $rel->getFragment())); }
public static function makeBox($obj, $obj_id, $showUploadForm = false, $suffix = false) { global $lng; // Prints a nice picture box. $height = $width = 250; # Picture dimensions. $img = new self($obj, $obj_id); ?> <img alt="Image" height="<?php echo $height; ?> " width="<?php echo $width; ?> " src="<?php echo $img->getPath(); ?> "> <br><br> <?php if ($showUploadForm) { ?> <form method='POST' enctype="multipart/form-data"> <input type="hidden" name="type" value="pic"> <input type="hidden" name="add_del" id="_pic_add_del__<?php echo $suffix ? $suffix : ''; ?> " value="add"> <input type="hidden" name="pic_obj" value="<?php echo $obj; ?> "> <?php echo $lng->getTrn('common/uploadnew'); ?> (<?php echo "{$width}x{$height}"; ?> ): <br> <input name="<?php echo self::$defaultHTMLUploadName . ($suffix ? $suffix : ''); ?> " type="file"><br> <input type="submit" name="pic_upload" value="<?php echo $lng->getTrn('common/upload'); ?> "> | <input type="submit" name="pic_delete" value="<?php echo $lng->getTrn('common/delete'); ?> " onClick="document.getElementById('_pic_add_del__<?php echo $suffix ? $suffix : ''; ?> ').value='del';"> </form> <?php } }
protected static function cloneOriginal($fileUid, $suffix) { // Get original image /** @var self $originalMeta */ $originalMeta = self::findOriginal($fileUid); if (!$originalMeta) { throw new FileException('Not found original image by uid `' . $fileUid . '`.'); } // New file meta $imageMeta = new self(); $imageMeta->fileUid = $originalMeta->fileUid; $imageMeta->folder = $originalMeta->folder; $imageMeta->fileMimeType = $originalMeta->fileMimeType; // Generate new file name $extension = pathinfo($originalMeta->fileName, PATHINFO_EXTENSION); $thumbFormat = $extension && $extension === 'png' ? 'png' : FileModule::getInstance()->thumbFormat; $imageMeta->fileName = pathinfo($originalMeta->fileName, PATHINFO_FILENAME) . '.' . $suffix . '.' . $thumbFormat; // Clone original file if (!copy($originalMeta->getPath(), $imageMeta->getPath())) { throw new FileException('Can not clone original file `' . $originalMeta->getRelativePath() . '` to `' . $imageMeta->getRelativePath() . '`.'); } return $imageMeta; }
/** * Create a symlink pointing to this directory * * @param Dir|string $dir Dir object or path * @param boolean $createPaths Create paths (if does not exist) * * @return $this * @throws \InvalidArgumentException */ public function symlink($dir, $createPaths = true) { if (!$this->exists()) { throw new \InvalidArgumentException(sprintf("Cannot create a link. Directory must exist: '%s'", $this->path)); } if (!$dir instanceof self) { $dir = new self($dir); } if ($dir->isLink()) { unlink($dir->getPath()); } $parent = $dir->getParent(); if ($createPaths) { if (!$this->exists()) { $this->create(); } if (!$parent->exists()) { $parent->create(); } } symlink($this->getAbsolutePath(), $parent->getAbsolutePath() . '/' . $dir->getName()); return $this; }
/** * @param array * @param IMAPConnection * @return Mailbox[] Multi dimensional map, keyed by imap-encoded path's * @usedby ImapConnection->getMailboxes() */ public static function fromList($list, $connection = null) { $boxes_temp = array(); foreach ($list as $i => $m) { $mb = new self(substr($m->name, strpos($m->name, '}') + 1), $connection); $mb->delimiter = $m->delimiter; $mb->flags = $m->attributes; $boxes_temp[$mb->getPath()] = $mb; } # Sort $boxes = array(); ksort($boxes_temp); foreach ($boxes_temp as $mb) { $r = explode($m->delimiter, $mb->getPath(true)); eval('$boxes[\'' . implode('\'][\'', $r) . '\'][\'#\'] = $mb;'); } return $boxes; }