public function image($uri, $x = '0%', $y = '0%', $w = '100%', $h = '100%') { if (Utils::isURL($uri)) { list($image, $extension) = $this->loadFromURL($uri); //$this->transform(Utils::nameFromURL($uri), $extension, WideImage::loadFromString($image), $x, $y, $w, $h) : } else { $imageName = $this->imageName($uri); $this->transform($imageName['name'], $imageName['extension'], WideImage::loadFromString($this->fs->read($uri)), $x, $y, $w, $h); } }
public function upload($request) { if (!$request->headers->has('x-filename')) { return new Response('Filename is missing (header X-FILENAME)', 400); } $filename = $request->headers->get('x-filename'); $pathinfo = pathinfo($filename); $dpath = Utils::resurl($this->draftPath . '/files', $pathinfo['filename'], null, null, $pathinfo['extension']); if (!$this->isSafeExtension($pathinfo['extension'])) { return $this->json($request, array('status' => 1, 'errMessage' => 'Forbidden file extension ' . $pathinfo['extension']), 200); } $res = $this->fs->writeStream($dpath, fopen("php://input", 'r')); if ($res === false) { return $this->json($request, array('status' => 1, 'errMessage' => 'Unable to upload file ' . $pathinfo['filename'] . '.' . $pathinfo['extension']), 200); } else { return $this->json($request, array('status' => 0, 'url' => $res), 200); } }
protected function adjustNavLinks() { foreach (phpQuery::pq('a', $this->doc) as $node) { $href = $node->getAttribute('href'); if (!Utils::isExternalNavLink($href)) { $node->setAttribute('href', 'sitecake.php?page=' . $href); } } }
static function array_find_prop($array, $prop, $value) { return array_shift(Utils::array_filter_prop($array, $prop, $value)); }
protected function generateImageSet($img, $filename, $ext) { $width = $img->getWidth(); $ratio = $width / $img->getHeight(); $widths = $this->ctx['image.srcset_widths']; $maxDiff = $this->ctx['image.srcset_width_maxdiff']; rsort($widths); $maxWidth = $widths[0]; if ($width > $maxWidth) { $width = $maxWidth; } $id = uniqid(); $srcset = array(); foreach ($this->neededWidths($width, $widths, $maxDiff) as $targetWidth) { $tpath = Utils::resurl($this->imgDir(), $filename, $id, '-' . $targetWidth, $ext); $timg = $img->resize($targetWidth); $targetHeight = $timg->getHeight(); $this->ctx['fs']->write($tpath, $timg->asString($ext)); unset($timg); array_push($srcset, array('width' => $targetWidth, 'height' => $targetHeight, 'url' => $tpath)); } return array('srcset' => $srcset, 'ratio' => $ratio); }
function test_resurlinfo() { $info = Utils::resurlinfo('p1/p2/name-sc1234567890abcDEF.ex'); $this->assertEquals(array('path' => 'p1/p2', 'name' => 'name', 'id' => '1234567890abc', 'subid' => 'DEF', 'ext' => 'ex'), $info); $info = Utils::resurlinfo('n-a.me-sc1234567890abc.ex'); $this->assertEquals(array('path' => '', 'name' => 'n-a.me', 'id' => '1234567890abc', 'subid' => '', 'ext' => 'ex'), $info); $info = Utils::resurlinfo(array('p1/n1-sc1234567890123.ext', 'p2/n2-sc1234567890123.ext')); $this->assertEquals(array(array('path' => 'p1', 'name' => 'n1', 'id' => '1234567890123', 'subid' => '', 'ext' => 'ext'), array('path' => 'p2', 'name' => 'n2', 'id' => '1234567890123', 'subid' => '', 'ext' => 'ext')), $info); }
function test_sanitizeFilename() { $this->assertEquals("some-file-name", Utils::sanitizeFilename("some-file~name", "Unix")); $this->assertEquals("ssscccczz", Utils::sanitizeFilename("sŠšČčĆćĐđŽž", "Unix")); $this->assertEquals("jcukengshshzhfyvaproldzheyachsmitbyu", Utils::sanitizeFilename("йцукенгшщзхъфывапролджэячсмитьбю", "Unix")); $this->assertEquals("file", Utils::sanitizeFilename("׳קראטוןםפשדגכעיחלךףזסבהנמצתץ", "Unix")); $this->assertEquals("some-file-name", Utils::sanitizeFilename("some-file~name", "WINDOWS")); $this->assertEquals("ssscccczz", Utils::sanitizeFilename("sŠšČčĆćĐđŽž", "WINDOWS")); $this->assertEquals("jcukengshshzhfyvaproldzheyachsmitbyu", Utils::sanitizeFilename("йцукенгшщзхъфывапролджэячсмитьбю", "WINDOWS")); }