示例#1
0
 public function image($request)
 {
     if (!$request->request->has('image')) {
         return new Response('Image URI is missing', 400);
     }
     $uri = $request->request->get('image');
     if (!$request->request->has('data')) {
         return new Response('Image transformation data is missing', 400);
     }
     $data = $request->request->get('data');
     if (!$this->ctx['fs']->has($uri)) {
         return new Response("Source image not found ({$uri})", 400);
     }
     $img = WideImage::loadFromString($this->ctx['fs']->read($uri));
     if (Utils::isResourceUrl($uri)) {
         $info = Utils::resurlinfo($uri);
     } else {
         $pathinfo = pathinfo($uri);
         $info = array('name' => $pathinfo['filename'], 'ext' => $pathinfo['extension']);
     }
     $datas = explode(':', $data);
     $left = $datas[0];
     $top = $datas[1];
     $width = $datas[2];
     $height = $datas[3];
     $filename = $info['name'];
     $ext = $info['ext'];
     $img = $this->transform_image($img, $top, $left, $width, $height);
     // generate image set
     $res = $this->generateImageSet($img, $filename, $ext);
     $res = array('status' => 0, 'srcset' => $res['srcset'], 'ratio' => $res['ratio']);
     return $this->json($request, $res, 200);
 }
示例#2
0
 function test_isResourceUrl()
 {
     $this->assertTrue(Utils::isResourceUrl('files/doc-sc123456789abcd.doc'));
     $this->assertTrue(Utils::isResourceUrl('files/doc-sc123456789abcd00.doc'));
     $this->assertTrue(Utils::isResourceUrl('images/image-2-sc123456789abcd-00.jpg'));
     $this->assertFalse(Utils::isResourceUrl('#files/doc-sc123456789abcd.doc'));
     $this->assertFalse(Utils::isResourceUrl('javascript:files/doc-sc123456789abcd-00.doc'));
     $this->assertFalse(Utils::isResourceUrl('http://some.come/files/doc-sc123456789abcd.doc'));
 }
示例#3
0
文件: Page.php 项目: anpone/sitecake
 protected function listContainerResourceUrls($container)
 {
     $urls = array();
     $html = (string) phpQuery::pq($container, $this->doc);
     preg_match_all("/[^\\s\"',]*(?:files|images)\\/[^\\s]*\\-sc[0-9a-f]{13}[^\\.]*\\.[0-9a-zA-Z]+/", $html, $matches);
     foreach ($matches[0] as $match) {
         if (Utils::isResourceUrl($match)) {
             array_push($urls, urldecode($match));
         }
     }
     return $urls;
 }