public function run()
 {
     Picture::create(['album_id' => 1, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_03.png']);
     Picture::create(['album_id' => 1, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_03.png']);
     Picture::create(['album_id' => 1, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_03.png']);
     Picture::create(['album_id' => 1, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_03.png']);
     Picture::create(['album_id' => 5, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 5, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 5, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 5, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 9, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 9, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 9, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 9, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 13, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 13, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 13, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 13, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 13, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 13, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 13, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 13, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 13, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 13, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 13, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
     Picture::create(['album_id' => 13, 'title' => '戏剧人生', 'picture' => 'http://7xk6xh.com1.z0.glb.clouddn.com/album_05.png']);
 }
 protected function compile()
 {
     if ($this->defineRoot) {
         $objPage = \PageModel::findByPk($this->rootPage);
     } else {
         global $objPage;
     }
     if (null === $objPage) {
         return;
     }
     $intOffset = (int) $this->levelOffset;
     // Random image
     if ($this->randomPageImage) {
         $intOffset = -1;
     }
     $arrImage = PageImage::getOne($objPage, $intOffset, (bool) $this->inheritPageImage);
     if (null === $arrImage) {
         return;
     }
     $arrSize = deserialize($this->imgSize);
     $arrImage['src'] = $this->getImage($arrImage['path'], $arrSize[0], $arrSize[1], $arrSize[2]);
     $this->Template->setData($arrImage);
     $picture = \Picture::create($arrImage['path'], $arrSize)->getTemplateData();
     $picture['alt'] = specialchars($arrImage['alt']);
     $this->Template->picture = $picture;
     if (($imgSize = @getimagesize(TL_ROOT . '/' . rawurldecode($arrImage['src']))) !== false) {
         $this->Template->size = ' ' . $imgSize[3];
     }
     // Add page information to template
     global $objPage;
     $this->Template->currentPage = $objPage->row();
 }
Exemple #3
0
 public function post5_submit()
 {
     $pic = $this->input_post('pic', true, true);
     $picture = Picture::create(array('file_name' => ''));
     $picture->file_name->put($pic);
     echo '<meta http-equiv="Content-type" content="text/html; charset=utf-8" /><pre>';
     var_dump($picture->file_name->url());
     echo "</pre><hr/><a href='" . base_url(array($this->get_class())) . "'>back</a>";
 }
 function test_custom_attributes()
 {
     $element = Picture::create('element', $this->attachment, array('sizes' => array('thumbnail', 'medium', 'large'), 'attributes' => array('picture' => array('id' => 'custom-id', 'class' => 'picture-element'), 'source' => array('data-foo' => 'bar'), 'img' => array('id' => 'responsive-image'))));
     $expected = '<picture id="custom-id" class="picture-element">';
     $expected .= '<source data-foo="bar" srcset="http://example.org/wp-content/uploads/IMG_2089-1024x1365.jpg" media="(min-width: 600px)">';
     $expected .= '<source data-foo="bar" srcset="http://example.org/wp-content/uploads/IMG_2089-600x800.jpg" media="(min-width: 480px)">';
     $expected .= '<img src="http://example.org/wp-content/uploads/IMG_2089-480x640.jpg" id="responsive-image">';
     $expected .= '</picture>';
     $this->assertEquals($expected, $element);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     if (!is_null($request->file('thumbnail'))) {
         $im = $request->file('thumbnail');
         // estension de l'image
         $ext = $im->getClientOriginalExtension();
         $uri = str_random(12) . '.' . $ext;
         $im->move(env('UPLOAD_PATH', './uploads'), $uri);
         Picture::create(['uri' => $uri, 'size' => $im->getSize(), 'type' => $ext, 'product_id' => $product->id]);
     }
 }
 function test_custom_media_queries()
 {
     $element = Picture::create('element', $this->attachment, array('sizes' => array('thumbnail', 'medium', 'large'), 'media_queries' => array('medium' => 'min-width: 500px', 'large' => 'min-width: 1024px')));
     $expected = '<picture >';
     $expected .= '<!--[if IE 9]><video style="display: none;"><![endif]-->';
     $expected .= '<source  srcset="http://example.org/wp-content/uploads/IMG_2089-1024x1365.jpg" media="(min-width: 1024px)">';
     $expected .= '<source  srcset="http://example.org/wp-content/uploads/IMG_2089-600x800.jpg" media="(min-width: 500px)">';
     $expected .= '<!--[if IE 9]></video><![endif]-->';
     $expected .= '<img srcset="http://example.org/wp-content/uploads/IMG_2089-480x640.jpg" >';
     $expected .= '</picture>';
     $this->assertEquals($expected, $element);
 }
 function test_custom_media_queries()
 {
     $style = Picture::create('style', $this->attachment, array('selector' => '#hero', 'sizes' => array('medium', 'large'), 'media_queries' => array('large' => 'min-width: 800px')));
     $expected = '<style>';
     $expected .= '#hero {';
     $expected .= 'background-image: url("http://example.org/wp-content/uploads/IMG_2089-600x800.jpg");';
     $expected .= '}';
     $expected .= '@media screen and (min-width: 800px) {';
     $expected .= '#hero{background-image: url("http://example.org/wp-content/uploads/IMG_2089-1024x1365.jpg");}';
     $expected .= '}';
     $expected .= '</style>';
     $this->assertEquals($expected, $style);
 }
 function test_custom_media_queries()
 {
     $element = Picture::create('span', $this->attachment, array('sizes' => array('thumbnail', 'medium', 'large'), 'media_queries' => array('medium' => 'min-width: 500px', 'large' => 'min-width: 1024px')));
     $expected = '<span data-picture data-alt="">';
     $expected .= '<span data-src="http://example.org/wp-content/uploads/IMG_2089-480x640.jpg" ></span>';
     $expected .= '<span data-src="http://example.org/wp-content/uploads/IMG_2089-600x800.jpg" data-media="(min-width: 500px)" ></span>';
     $expected .= '<span data-src="http://example.org/wp-content/uploads/IMG_2089-1024x1365.jpg" data-media="(min-width: 1024px)" ></span>';
     $expected .= '<noscript>';
     $expected .= '<img src="http://example.org/wp-content/uploads/IMG_2089-480x640.jpg" alt="">';
     $expected .= '</noscript>';
     $expected .= '</span>';
     $this->assertEquals($expected, $element);
 }
 function test_array_with_density()
 {
     $element = Picture::create('element', $this->attachment, array('retina' => array('1.5x')));
     $expected = '<picture >';
     $expected .= '<!--[if IE 9]><video style="display: none;"><![endif]-->';
     $expected .= '<source  srcset="http://example.org/wp-content/uploads/retina.jpg" media="(min-width: 1024px)">';
     $expected .= '<source  srcset="http://example.org/wp-content/uploads/retina-1024x1365.jpg, http://example.org/wp-content/uploads/retina-1536x2047.jpg 1.5x" media="(min-width: 600px)">';
     $expected .= '<source  srcset="http://example.org/wp-content/uploads/retina-600x800.jpg, http://example.org/wp-content/uploads/retina-900x1200.jpg 1.5x" media="(min-width: 480px)">';
     $expected .= '<!--[if IE 9]></video><![endif]-->';
     $expected .= '<img srcset="http://example.org/wp-content/uploads/retina-480x640.jpg, http://example.org/wp-content/uploads/retina-720x960.jpg 1.5x" >';
     $expected .= '</picture>';
     $this->assertEquals($expected, $element);
 }
 function test_default()
 {
     $img = Picture::create('img', $this->attachment, array('retina' => true));
     $expected = '<img ';
     $expected .= 'src="http://example.org/wp-content/uploads/retina-480x640.jpg" ';
     $expected .= 'srcset="http://example.org/wp-content/uploads/retina-480x640.jpg 480w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-720x960.jpg 720w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-960x1280.jpg 960w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-600x800.jpg 600w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-900x1200.jpg 900w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-1200x1600.jpg 1200w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-1024x1365.jpg 1024w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-1536x2047.jpg 1536w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-2048x2730.jpg 2048w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina.jpg 2448w" ';
     $expected .= 'sizes="(min-width: 1024px) 2448px, (min-width: 600px) 1024px, (min-width: 480px) 600px, 480px"';
     $expected .= '>';
     $this->assertEquals($expected, $img);
 }
 function test_array_of_multiple_densities_and_selected_sizes()
 {
     $img = Picture::create('img', $this->attachment, array('retina' => array('1.5x', '2x'), 'sizes' => array('thumbnail', 'medium', 'large')));
     $expected = '<img ';
     $expected .= 'srcset="http://example.org/wp-content/uploads/retina-480x640.jpg 480w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-720x960.jpg 720w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-960x1280.jpg 960w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-600x800.jpg 600w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-900x1200.jpg 900w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-1200x1600.jpg 1200w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-1024x1365.jpg 1024w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-1536x2047.jpg 1536w, ';
     $expected .= 'http://example.org/wp-content/uploads/retina-2048x2730.jpg 2048w" ';
     $expected .= 'sizes="(min-width: 600px) 1024px, (min-width: 480px) 600px, 480px"';
     $expected .= '>';
     $this->assertEquals($expected, $img);
 }
 function test_custom_attributes()
 {
     $img = Picture::create('img', $this->attachment, array('attributes' => array('id' => 'custom-id')));
     $expected = '<img src="http://example.org/wp-content/uploads/IMG_2089-480x640.jpg" srcset="http://example.org/wp-content/uploads/IMG_2089-480x640.jpg 480w, http://example.org/wp-content/uploads/IMG_2089-600x800.jpg 600w, http://example.org/wp-content/uploads/IMG_2089-1024x1365.jpg 1024w, http://example.org/wp-content/uploads/IMG_2089.jpg 2448w" sizes="(min-width: 1024px) 2448px, (min-width: 600px) 1024px, (min-width: 480px) 600px, 480px" id="custom-id">';
     $this->assertEquals($expected, $img);
 }
Exemple #13
0
 /**
  * Replace insert tags with their values
  *
  * @param string  $strBuffer The text with the tags to be replaced
  * @param boolean $blnCache  If false, non-cacheable tags will be replaced
  *
  * @return string The text with the replaced tags
  */
 protected function doReplace($strBuffer, $blnCache)
 {
     /** @var PageModel $objPage */
     global $objPage;
     // Preserve insert tags
     if (\Config::get('disableInsertTags')) {
         return \StringUtil::restoreBasicEntities($strBuffer);
     }
     $tags = preg_split('/{{([^{}]+)}}/', $strBuffer, -1, PREG_SPLIT_DELIM_CAPTURE);
     if (count($tags) < 2) {
         return \StringUtil::restoreBasicEntities($strBuffer);
     }
     $strBuffer = '';
     // Create one cache per cache setting (see #7700)
     static $arrItCache;
     $arrCache =& $arrItCache[$blnCache];
     for ($_rit = 0, $_cnt = count($tags); $_rit < $_cnt; $_rit += 2) {
         $strBuffer .= $tags[$_rit];
         $strTag = $tags[$_rit + 1];
         // Skip empty tags
         if ($strTag == '') {
             continue;
         }
         $flags = explode('|', $strTag);
         $tag = array_shift($flags);
         $elements = explode('::', $tag);
         // Load the value from cache
         if (isset($arrCache[$strTag]) && !in_array('refresh', $flags)) {
             $strBuffer .= $arrCache[$strTag];
             continue;
         }
         // Skip certain elements if the output will be cached
         if ($blnCache) {
             if ($elements[0] == 'date' || $elements[0] == 'ua' || $elements[0] == 'post' || $elements[0] == 'file' || $elements[1] == 'back' || $elements[1] == 'referer' || $elements[0] == 'request_token' || $elements[0] == 'toggle_view' || strncmp($elements[0], 'cache_', 6) === 0 || in_array('uncached', $flags)) {
                 $strBuffer .= '{{' . $strTag . '}}';
                 continue;
             }
         }
         $arrCache[$strTag] = '';
         // Replace the tag
         switch (strtolower($elements[0])) {
             // Date
             case 'date':
                 $arrCache[$strTag] = \Date::parse($elements[1] ?: \Config::get('dateFormat'));
                 break;
                 // Accessibility tags
             // Accessibility tags
             case 'lang':
                 if ($elements[1] == '') {
                     $arrCache[$strTag] = '</span>';
                 } else {
                     $arrCache[$strTag] = $arrCache[$strTag] = '<span lang="' . $elements[1] . '">';
                 }
                 break;
                 // Line break
             // Line break
             case 'br':
                 $arrCache[$strTag] = '<br>';
                 break;
                 // E-mail addresses
             // E-mail addresses
             case 'email':
             case 'email_open':
             case 'email_url':
                 if ($elements[1] == '') {
                     $arrCache[$strTag] = '';
                     break;
                 }
                 $strEmail = \StringUtil::encodeEmail($elements[1]);
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'email':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $strEmail . '" class="email">' . preg_replace('/\\?.*$/', '', $strEmail) . '</a>';
                         break;
                     case 'email_open':
                         $arrCache[$strTag] = '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $strEmail . '" title="' . $strEmail . '" class="email">';
                         break;
                     case 'email_url':
                         $arrCache[$strTag] = $strEmail;
                         break;
                 }
                 break;
                 // Label tags
             // Label tags
             case 'label':
                 $keys = explode(':', $elements[1]);
                 if (count($keys) < 2) {
                     $arrCache[$strTag] = '';
                     break;
                 }
                 $file = $keys[0];
                 // Map the key (see #7217)
                 switch ($file) {
                     case 'CNT':
                         $file = 'countries';
                         break;
                     case 'LNG':
                         $file = 'languages';
                         break;
                     case 'MOD':
                     case 'FMD':
                         $file = 'modules';
                         break;
                     case 'FFL':
                         $file = 'tl_form_field';
                         break;
                     case 'CACHE':
                         $file = 'tl_page';
                         break;
                     case 'XPL':
                         $file = 'explain';
                         break;
                     case 'XPT':
                         $file = 'exception';
                         break;
                     case 'MSC':
                     case 'ERR':
                     case 'CTE':
                     case 'PTY':
                     case 'FOP':
                     case 'CHMOD':
                     case 'DAYS':
                     case 'MONTHS':
                     case 'UNITS':
                     case 'CONFIRM':
                     case 'DP':
                     case 'COLS':
                         $file = 'default';
                         break;
                 }
                 \System::loadLanguageFile($file);
                 if (count($keys) == 2) {
                     $arrCache[$strTag] = $GLOBALS['TL_LANG'][$keys[0]][$keys[1]];
                 } else {
                     $arrCache[$strTag] = $GLOBALS['TL_LANG'][$keys[0]][$keys[1]][$keys[2]];
                 }
                 break;
                 // Front end user
             // Front end user
             case 'user':
                 if (FE_USER_LOGGED_IN) {
                     $this->import('FrontendUser', 'User');
                     $value = $this->User->{$elements[1]};
                     if ($value == '') {
                         $arrCache[$strTag] = $value;
                         break;
                     }
                     $this->loadDataContainer('tl_member');
                     if ($GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['inputType'] == 'password') {
                         $arrCache[$strTag] = '';
                         break;
                     }
                     $value = \StringUtil::deserialize($value);
                     // Decrypt the value
                     if ($GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['eval']['encrypt']) {
                         $value = \Encryption::decrypt($value);
                     }
                     $rgxp = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['eval']['rgxp'];
                     $opts = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['options'];
                     $rfrc = $GLOBALS['TL_DCA']['tl_member']['fields'][$elements[1]]['reference'];
                     if ($rgxp == 'date') {
                         $arrCache[$strTag] = \Date::parse(\Config::get('dateFormat'), $value);
                     } elseif ($rgxp == 'time') {
                         $arrCache[$strTag] = \Date::parse(\Config::get('timeFormat'), $value);
                     } elseif ($rgxp == 'datim') {
                         $arrCache[$strTag] = \Date::parse(\Config::get('datimFormat'), $value);
                     } elseif (is_array($value)) {
                         $arrCache[$strTag] = implode(', ', $value);
                     } elseif (is_array($opts) && array_is_assoc($opts)) {
                         $arrCache[$strTag] = isset($opts[$value]) ? $opts[$value] : $value;
                     } elseif (is_array($rfrc)) {
                         $arrCache[$strTag] = isset($rfrc[$value]) ? is_array($rfrc[$value]) ? $rfrc[$value][0] : $rfrc[$value] : $value;
                     } else {
                         $arrCache[$strTag] = $value;
                     }
                     // Convert special characters (see #1890)
                     $arrCache[$strTag] = \StringUtil::specialchars($arrCache[$strTag]);
                 }
                 break;
                 // Link
             // Link
             case 'link':
             case 'link_open':
             case 'link_url':
             case 'link_title':
             case 'link_target':
             case 'link_name':
                 $strTarget = null;
                 // Back link
                 if ($elements[1] == 'back') {
                     $strUrl = 'javascript:history.go(-1)';
                     $strTitle = $GLOBALS['TL_LANG']['MSC']['goBack'];
                     // No language files if the page is cached
                     if (!strlen($strTitle)) {
                         $strTitle = 'Go back';
                     }
                     $strName = $strTitle;
                 } elseif (strncmp($elements[1], 'http://', 7) === 0 || strncmp($elements[1], 'https://', 8) === 0) {
                     $strUrl = $elements[1];
                     $strTitle = $elements[1];
                     $strName = str_replace(array('http://', 'https://'), '', $elements[1]);
                 } else {
                     // User login page
                     if ($elements[1] == 'login') {
                         if (!FE_USER_LOGGED_IN) {
                             break;
                         }
                         $this->import('FrontendUser', 'User');
                         $elements[1] = $this->User->loginPage;
                     }
                     $objNextPage = \PageModel::findByIdOrAlias($elements[1]);
                     if ($objNextPage === null) {
                         break;
                     }
                     // Page type specific settings (thanks to Andreas Schempp)
                     switch ($objNextPage->type) {
                         case 'redirect':
                             $strUrl = $objNextPage->url;
                             if (strncasecmp($strUrl, 'mailto:', 7) === 0) {
                                 $strUrl = \StringUtil::encodeEmail($strUrl);
                             }
                             break;
                         case 'forward':
                             if ($objNextPage->jumpTo) {
                                 /** @var PageModel $objNext */
                                 $objNext = $objNextPage->getRelated('jumpTo');
                             } else {
                                 $objNext = \PageModel::findFirstPublishedRegularByPid($objNextPage->id);
                             }
                             if ($objNext instanceof PageModel) {
                                 $strUrl = $objNext->getFrontendUrl();
                                 break;
                             }
                             // DO NOT ADD A break; STATEMENT
                         // DO NOT ADD A break; STATEMENT
                         default:
                             $strUrl = $objNextPage->getFrontendUrl();
                             break;
                     }
                     $strName = $objNextPage->title;
                     $strTarget = $objNextPage->target ? ' target="_blank"' : '';
                     $strTitle = $objNextPage->pageTitle ?: $objNextPage->title;
                 }
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'link':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s"%s>%s</a>', $strUrl, \StringUtil::specialchars($strTitle), $strTarget, $strName);
                         break;
                     case 'link_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s"%s>', $strUrl, \StringUtil::specialchars($strTitle), $strTarget);
                         break;
                     case 'link_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'link_title':
                         $arrCache[$strTag] = \StringUtil::specialchars($strTitle);
                         break;
                     case 'link_target':
                         $arrCache[$strTag] = $strTarget;
                         break;
                     case 'link_name':
                         $arrCache[$strTag] = $strName;
                         break;
                 }
                 break;
                 // Closing link tag
             // Closing link tag
             case 'link_close':
             case 'email_close':
                 $arrCache[$strTag] = '</a>';
                 break;
                 // Insert article
             // Insert article
             case 'insert_article':
                 if (($strOutput = $this->getArticle($elements[1], false, true)) !== false) {
                     $arrCache[$strTag] = ltrim($strOutput);
                 } else {
                     $arrCache[$strTag] = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], $elements[1]) . '</p>';
                 }
                 break;
                 // Insert content element
             // Insert content element
             case 'insert_content':
                 $arrCache[$strTag] = $this->getContentElement($elements[1]);
                 break;
                 // Insert module
             // Insert module
             case 'insert_module':
                 $arrCache[$strTag] = $this->getFrontendModule($elements[1]);
                 break;
                 // Insert form
             // Insert form
             case 'insert_form':
                 $arrCache[$strTag] = $this->getForm($elements[1]);
                 break;
                 // Article
             // Article
             case 'article':
             case 'article_open':
             case 'article_url':
             case 'article_title':
                 if (($objArticle = \ArticleModel::findByIdOrAlias($elements[1])) === null || !($objPid = $objArticle->getRelated('pid')) instanceof PageModel) {
                     break;
                 }
                 /** @var PageModel $objPid */
                 $strUrl = $objPid->getFrontendUrl('/articles/' . ($objArticle->alias ?: $objArticle->id));
                 // Replace the tag
                 switch (strtolower($elements[0])) {
                     case 'article':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, \StringUtil::specialchars($objArticle->title), $objArticle->title);
                         break;
                     case 'article_open':
                         $arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, \StringUtil::specialchars($objArticle->title));
                         break;
                     case 'article_url':
                         $arrCache[$strTag] = $strUrl;
                         break;
                     case 'article_title':
                         $arrCache[$strTag] = \StringUtil::specialchars($objArticle->title);
                         break;
                 }
                 break;
                 // Article teaser
             // Article teaser
             case 'article_teaser':
                 $objTeaser = \ArticleModel::findByIdOrAlias($elements[1]);
                 if ($objTeaser !== null) {
                     $arrCache[$strTag] = \StringUtil::toHtml5($objTeaser->teaser);
                 }
                 break;
                 // Last update
             // Last update
             case 'last_update':
                 $strQuery = "SELECT MAX(tstamp) AS tc";
                 $bundles = \System::getContainer()->getParameter('kernel.bundles');
                 if (isset($bundles['ContaoNewsBundle'])) {
                     $strQuery .= ", (SELECT MAX(tstamp) FROM tl_news) AS tn";
                 }
                 if (isset($bundles['ContaoCalendarBundle'])) {
                     $strQuery .= ", (SELECT MAX(tstamp) FROM tl_calendar_events) AS te";
                 }
                 $strQuery .= " FROM tl_content";
                 $objUpdate = \Database::getInstance()->query($strQuery);
                 if ($objUpdate->numRows) {
                     $arrCache[$strTag] = \Date::parse($elements[1] ?: \Config::get('datimFormat'), max($objUpdate->tc, $objUpdate->tn, $objUpdate->te));
                 }
                 break;
                 // Version
             // Version
             case 'version':
                 $arrCache[$strTag] = VERSION . '.' . BUILD;
                 break;
                 // Request token
             // Request token
             case 'request_token':
                 $arrCache[$strTag] = REQUEST_TOKEN;
                 break;
                 // POST data
             // POST data
             case 'post':
                 $arrCache[$strTag] = \Input::post($elements[1]);
                 break;
                 // Mobile/desktop toggle (see #6469)
             // Mobile/desktop toggle (see #6469)
             case 'toggle_view':
                 $strUrl = ampersand(\Environment::get('request'));
                 $strGlue = strpos($strUrl, '?') === false ? '?' : '&amp;';
                 if (\Input::cookie('TL_VIEW') == 'mobile' || \Environment::get('agent')->mobile && \Input::cookie('TL_VIEW') != 'desktop') {
                     $arrCache[$strTag] = '<a href="' . $strUrl . $strGlue . 'toggle_view=desktop" class="toggle_desktop" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['toggleDesktop'][1]) . '">' . $GLOBALS['TL_LANG']['MSC']['toggleDesktop'][0] . '</a>';
                 } else {
                     $arrCache[$strTag] = '<a href="' . $strUrl . $strGlue . 'toggle_view=mobile" class="toggle_mobile" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['toggleMobile'][1]) . '">' . $GLOBALS['TL_LANG']['MSC']['toggleMobile'][0] . '</a>';
                 }
                 break;
                 // Conditional tags (if)
             // Conditional tags (if)
             case 'iflng':
                 if ($elements[1] != '' && $elements[1] != $objPage->language) {
                     for (; $_rit < $_cnt; $_rit += 2) {
                         if ($tags[$_rit + 1] == 'iflng' || $tags[$_rit + 1] == 'iflng::' . $objPage->language) {
                             break;
                         }
                     }
                 }
                 unset($arrCache[$strTag]);
                 break;
                 // Conditional tags (if not)
             // Conditional tags (if not)
             case 'ifnlng':
                 if ($elements[1] != '') {
                     $langs = \StringUtil::trimsplit(',', $elements[1]);
                     if (in_array($objPage->language, $langs)) {
                         for (; $_rit < $_cnt; $_rit += 2) {
                             if ($tags[$_rit + 1] == 'ifnlng') {
                                 break;
                             }
                         }
                     }
                 }
                 unset($arrCache[$strTag]);
                 break;
                 // Environment
             // Environment
             case 'env':
                 switch ($elements[1]) {
                     case 'host':
                         $arrCache[$strTag] = \Idna::decode(\Environment::get('host'));
                         break;
                     case 'http_host':
                         $arrCache[$strTag] = \Idna::decode(\Environment::get('httpHost'));
                         break;
                     case 'url':
                         $arrCache[$strTag] = \Idna::decode(\Environment::get('url'));
                         break;
                     case 'path':
                         $arrCache[$strTag] = \Idna::decode(\Environment::get('base'));
                         break;
                     case 'request':
                         $arrCache[$strTag] = \Environment::get('indexFreeRequest');
                         break;
                     case 'ip':
                         $arrCache[$strTag] = \Environment::get('ip');
                         break;
                     case 'referer':
                         $arrCache[$strTag] = $this->getReferer(true);
                         break;
                     case 'files_url':
                         $arrCache[$strTag] = TL_FILES_URL;
                         break;
                     case 'assets_url':
                     case 'plugins_url':
                     case 'script_url':
                         $arrCache[$strTag] = TL_ASSETS_URL;
                         break;
                     case 'base_url':
                         $arrCache[$strTag] = \System::getContainer()->get('request_stack')->getCurrentRequest()->getBaseUrl();
                         break;
                 }
                 break;
                 // Page
             // Page
             case 'page':
                 if ($elements[1] == 'pageTitle' && $objPage->pageTitle == '') {
                     $elements[1] = 'title';
                 } elseif ($elements[1] == 'parentPageTitle' && $objPage->parentPageTitle == '') {
                     $elements[1] = 'parentTitle';
                 } elseif ($elements[1] == 'mainPageTitle' && $objPage->mainPageTitle == '') {
                     $elements[1] = 'mainTitle';
                 }
                 // Do not use \StringUtil::specialchars() here (see #4687)
                 $arrCache[$strTag] = $objPage->{$elements[1]};
                 break;
                 // User agent
             // User agent
             case 'ua':
                 $ua = \Environment::get('agent');
                 if ($elements[1] != '') {
                     $arrCache[$strTag] = $ua->{$elements[1]};
                 } else {
                     $arrCache[$strTag] = '';
                 }
                 break;
                 // Abbreviations
             // Abbreviations
             case 'abbr':
             case 'acronym':
                 if ($elements[1] != '') {
                     $arrCache[$strTag] = '<abbr title="' . $elements[1] . '">';
                 } else {
                     $arrCache[$strTag] = '</abbr>';
                 }
                 break;
                 // Images
             // Images
             case 'image':
             case 'picture':
                 $width = null;
                 $height = null;
                 $alt = '';
                 $class = '';
                 $rel = '';
                 $strFile = $elements[1];
                 $mode = '';
                 $size = null;
                 $strTemplate = 'picture_default';
                 // Take arguments
                 if (strpos($elements[1], '?') !== false) {
                     $arrChunks = explode('?', urldecode($elements[1]), 2);
                     $strSource = \StringUtil::decodeEntities($arrChunks[1]);
                     $strSource = str_replace('[&]', '&', $strSource);
                     $arrParams = explode('&', $strSource);
                     foreach ($arrParams as $strParam) {
                         list($key, $value) = explode('=', $strParam);
                         switch ($key) {
                             case 'width':
                                 $width = $value;
                                 break;
                             case 'height':
                                 $height = $value;
                                 break;
                             case 'alt':
                                 $alt = \StringUtil::specialchars($value);
                                 break;
                             case 'class':
                                 $class = $value;
                                 break;
                             case 'rel':
                                 $rel = $value;
                                 break;
                             case 'mode':
                                 $mode = $value;
                                 break;
                             case 'size':
                                 $size = (int) $value;
                                 break;
                             case 'template':
                                 $strTemplate = preg_replace('/[^a-z0-9_]/i', '', $value);
                                 break;
                         }
                     }
                     $strFile = $arrChunks[0];
                 }
                 if (\Validator::isUuid($strFile)) {
                     // Handle UUIDs
                     $objFile = \FilesModel::findByUuid($strFile);
                     if ($objFile === null) {
                         $arrCache[$strTag] = '';
                         break;
                     }
                     $strFile = $objFile->path;
                 } elseif (is_numeric($strFile)) {
                     // Handle numeric IDs (see #4805)
                     $objFile = \FilesModel::findByPk($strFile);
                     if ($objFile === null) {
                         $arrCache[$strTag] = '';
                         break;
                     }
                     $strFile = $objFile->path;
                 } else {
                     // Check the path
                     if (\Validator::isInsecurePath($strFile)) {
                         throw new \RuntimeException('Invalid path ' . $strFile);
                     }
                 }
                 // Check the maximum image width
                 if (\Config::get('maxImageWidth') > 0 && $width > \Config::get('maxImageWidth')) {
                     $width = \Config::get('maxImageWidth');
                     $height = null;
                 }
                 // Generate the thumbnail image
                 try {
                     // Image
                     if (strtolower($elements[0]) == 'image') {
                         $dimensions = '';
                         $imageObj = \Image::create($strFile, array($width, $height, $mode));
                         $src = $imageObj->executeResize()->getResizedPath();
                         $objFile = new \File(rawurldecode($src));
                         // Add the image dimensions
                         if (($imgSize = $objFile->imageSize) !== false) {
                             $dimensions = ' width="' . $imgSize[0] . '" height="' . $imgSize[1] . '"';
                         }
                         $arrCache[$strTag] = '<img src="' . TL_FILES_URL . $src . '" ' . $dimensions . ' alt="' . $alt . '"' . ($class != '' ? ' class="' . $class . '"' : '') . '>';
                     } else {
                         $picture = \Picture::create($strFile, array(0, 0, $size))->getTemplateData();
                         $picture['alt'] = $alt;
                         $picture['class'] = $class;
                         $pictureTemplate = new \FrontendTemplate($strTemplate);
                         $pictureTemplate->setData($picture);
                         $arrCache[$strTag] = $pictureTemplate->parse();
                     }
                     // Add a lightbox link
                     if ($rel != '') {
                         if (strncmp($rel, 'lightbox', 8) !== 0) {
                             $attribute = ' rel="' . $rel . '"';
                         } else {
                             $attribute = ' data-lightbox="' . substr($rel, 8) . '"';
                         }
                         $arrCache[$strTag] = '<a href="' . TL_FILES_URL . $strFile . '"' . ($alt != '' ? ' title="' . $alt . '"' : '') . $attribute . '>' . $arrCache[$strTag] . '</a>';
                     }
                 } catch (\Exception $e) {
                     $arrCache[$strTag] = '';
                 }
                 break;
                 // Files (UUID or template path)
             // Files (UUID or template path)
             case 'file':
                 if (\Validator::isUuid($elements[1])) {
                     $objFile = \FilesModel::findByUuid($elements[1]);
                     if ($objFile !== null) {
                         $arrCache[$strTag] = $objFile->path;
                         break;
                     }
                 }
                 $arrGet = $_GET;
                 \Input::resetCache();
                 $strFile = $elements[1];
                 // Take arguments and add them to the $_GET array
                 if (strpos($elements[1], '?') !== false) {
                     $arrChunks = explode('?', urldecode($elements[1]));
                     $strSource = \StringUtil::decodeEntities($arrChunks[1]);
                     $strSource = str_replace('[&]', '&', $strSource);
                     $arrParams = explode('&', $strSource);
                     foreach ($arrParams as $strParam) {
                         $arrParam = explode('=', $strParam);
                         $_GET[$arrParam[0]] = $arrParam[1];
                     }
                     $strFile = $arrChunks[0];
                 }
                 // Check the path
                 if (\Validator::isInsecurePath($strFile)) {
                     throw new \RuntimeException('Invalid path ' . $strFile);
                 }
                 // Include .php, .tpl, .xhtml and .html5 files
                 if (preg_match('/\\.(php|tpl|xhtml|html5)$/', $strFile) && file_exists(TL_ROOT . '/templates/' . $strFile)) {
                     ob_start();
                     include TL_ROOT . '/templates/' . $strFile;
                     $arrCache[$strTag] = ob_get_clean();
                 }
                 $_GET = $arrGet;
                 \Input::resetCache();
                 break;
                 // HOOK: pass unknown tags to callback functions
             // HOOK: pass unknown tags to callback functions
             default:
                 if (isset($GLOBALS['TL_HOOKS']['replaceInsertTags']) && is_array($GLOBALS['TL_HOOKS']['replaceInsertTags'])) {
                     foreach ($GLOBALS['TL_HOOKS']['replaceInsertTags'] as $callback) {
                         $this->import($callback[0]);
                         $varValue = $this->{$callback[0]}->{$callback[1]}($tag, $blnCache, $arrCache[$strTag], $flags, $tags, $arrCache, $_rit, $_cnt);
                         // see #6672
                         // Replace the tag and stop the loop
                         if ($varValue !== false) {
                             $arrCache[$strTag] = $varValue;
                             break;
                         }
                     }
                 }
                 if (\Config::get('debugMode')) {
                     $GLOBALS['TL_DEBUG']['unknown_insert_tags'][] = $strTag;
                 }
                 break;
         }
         // Handle the flags
         if (!empty($flags)) {
             foreach ($flags as $flag) {
                 switch ($flag) {
                     case 'addslashes':
                     case 'stripslashes':
                     case 'standardize':
                     case 'ampersand':
                     case 'specialchars':
                     case 'nl2br':
                     case 'nl2br_pre':
                     case 'strtolower':
                     case 'utf8_strtolower':
                     case 'strtoupper':
                     case 'utf8_strtoupper':
                     case 'ucfirst':
                     case 'lcfirst':
                     case 'ucwords':
                     case 'trim':
                     case 'rtrim':
                     case 'ltrim':
                     case 'utf8_romanize':
                     case 'strrev':
                     case 'urlencode':
                     case 'rawurlencode':
                         $arrCache[$strTag] = $flag($arrCache[$strTag]);
                         break;
                     case 'encodeEmail':
                     case 'decodeEntities':
                         $arrCache[$strTag] = \StringUtil::$flag($arrCache[$strTag]);
                         break;
                     case 'number_format':
                         $arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 0);
                         break;
                     case 'currency_format':
                         $arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 2);
                         break;
                     case 'readable_size':
                         $arrCache[$strTag] = \System::getReadableSize($arrCache[$strTag]);
                         break;
                     case 'flatten':
                         if (!is_array($arrCache[$strTag])) {
                             break;
                         }
                         $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($arrCache[$strTag]));
                         $result = array();
                         foreach ($it as $leafValue) {
                             $keys = array();
                             foreach (range(0, $it->getDepth()) as $depth) {
                                 $keys[] = $it->getSubIterator($depth)->key();
                             }
                             $result[] = implode('.', $keys) . ': ' . $leafValue;
                         }
                         $arrCache[$strTag] = implode(', ', $result);
                         break;
                         // HOOK: pass unknown flags to callback functions
                     // HOOK: pass unknown flags to callback functions
                     default:
                         if (isset($GLOBALS['TL_HOOKS']['insertTagFlags']) && is_array($GLOBALS['TL_HOOKS']['insertTagFlags'])) {
                             foreach ($GLOBALS['TL_HOOKS']['insertTagFlags'] as $callback) {
                                 $this->import($callback[0]);
                                 $varValue = $this->{$callback[0]}->{$callback[1]}($flag, $tag, $arrCache[$strTag], $flags, $blnCache, $tags, $arrCache, $_rit, $_cnt);
                                 // see #5806
                                 // Replace the tag and stop the loop
                                 if ($varValue !== false) {
                                     $arrCache[$strTag] = $varValue;
                                     break;
                                 }
                             }
                         }
                         if (\Config::get('debugMode')) {
                             $GLOBALS['TL_DEBUG']['unknown_insert_tag_flags'][] = $flag;
                         }
                         break;
                 }
             }
         }
         $strBuffer .= $arrCache[$strTag];
     }
     return \StringUtil::restoreBasicEntities($strBuffer);
 }
 /**
  * Add an image to a template
  *
  * @param object  $objTemplate   The template object to add the image to
  * @param array   $arrItem       The element or module as array
  * @param integer $intMaxWidth   An optional maximum width of the image
  * @param string  $strLightboxId An optional lightbox ID
  */
 public static function addImageToTemplate($objTemplate, $arrItem, $intMaxWidth = null, $strLightboxId = null)
 {
     /** @var \PageModel $objPage */
     global $objPage;
     try {
         $objFile = new \File($arrItem['singleSRC'], true);
     } catch (\Exception $e) {
         $objFile = new \stdClass();
         $objFile->imageSize = false;
     }
     $imgSize = $objFile->imageSize;
     // Store the original dimensions
     if ($imgSize !== false) {
         $objTemplate->width = $imgSize[0];
         $objTemplate->height = $imgSize[1];
     }
     $size = deserialize($arrItem['size']);
     $arrMargin = TL_MODE == 'BE' ? array() : deserialize($arrItem['imagemargin']);
     if (is_array($size)) {
         if ($intMaxWidth === null) {
             $intMaxWidth = TL_MODE == 'BE' ? 320 : \Config::get('maxImageWidth');
         }
         // Adjust the image size
         if ($intMaxWidth > 0 && $imgSize !== false) {
             // Subtract the margins before deciding whether to resize (see #6018)
             if (is_array($arrMargin) && $arrMargin['unit'] == 'px') {
                 $intMargin = $arrMargin['left'] + $arrMargin['right'];
                 // Reset the margin if it exceeds the maximum width (see #7245)
                 if ($intMaxWidth - $intMargin < 1) {
                     $arrMargin['left'] = '';
                     $arrMargin['right'] = '';
                 } else {
                     $intMaxWidth = $intMaxWidth - $intMargin;
                 }
             }
             if ($size[0] > $intMaxWidth || !$size[0] && !$size[1] && $imgSize[0] > $intMaxWidth) {
                 // See #2268 (thanks to Thyon)
                 $ratio = $size[0] && $size[1] ? $size[1] / $size[0] : $imgSize[1] / $imgSize[0];
                 $size[0] = $intMaxWidth;
                 $size[1] = floor($intMaxWidth * $ratio);
             }
         }
         // Disable responsive images in the back end (see #7875)
         if (TL_MODE == 'BE') {
             unset($size[2]);
         }
     }
     try {
         $src = \Image::create($arrItem['singleSRC'], $size)->executeResize()->getResizedPath();
         $picture = \Picture::create($arrItem['singleSRC'], $size)->getTemplateData();
         if ($src !== $arrItem['singleSRC']) {
             $objFile = new \File(rawurldecode($src), true);
         }
     } catch (\Exception $e) {
         \System::log('Image "' . $arrItem['singleSRC'] . '" could not be processed: ' . $e->getMessage(), __METHOD__, TL_ERROR);
         $src = '';
         $picture = array('img' => array('src' => '', 'srcset' => ''), 'sources' => array());
     }
     // Image dimensions
     if (($imgSize = $objFile->imageSize) !== false) {
         $objTemplate->arrSize = $imgSize;
         $objTemplate->imgSize = ' width="' . $imgSize[0] . '" height="' . $imgSize[1] . '"';
     }
     $picture['alt'] = specialchars($arrItem['alt']);
     $picture['title'] = specialchars($arrItem['title']);
     $objTemplate->picture = $picture;
     // Provide an ID for single lightbox images in HTML5 (see #3742)
     if ($strLightboxId === null && $arrItem['fullsize']) {
         if ($objPage->outputFormat == 'xhtml') {
             $strLightboxId = 'lightbox';
         } else {
             $strLightboxId = 'lightbox[' . substr(md5($objTemplate->getName() . '_' . $arrItem['id']), 0, 6) . ']';
         }
     }
     // Float image
     if ($arrItem['floating'] != '') {
         $objTemplate->floatClass = ' float_' . $arrItem['floating'];
     }
     // Do not override the "href" key (see #6468)
     $strHrefKey = $objTemplate->href != '' ? 'imageHref' : 'href';
     // Image link
     if ($arrItem['imageUrl'] != '' && TL_MODE == 'FE') {
         $objTemplate->{$strHrefKey} = $arrItem['imageUrl'];
         $objTemplate->attributes = '';
         if ($arrItem['fullsize']) {
             // Open images in the lightbox
             if (preg_match('/\\.(jpe?g|gif|png)$/', $arrItem['imageUrl'])) {
                 // Do not add the TL_FILES_URL to external URLs (see #4923)
                 if (strncmp($arrItem['imageUrl'], 'http://', 7) !== 0 && strncmp($arrItem['imageUrl'], 'https://', 8) !== 0) {
                     $objTemplate->{$strHrefKey} = TL_FILES_URL . \System::urlEncode($arrItem['imageUrl']);
                 }
                 $objTemplate->attributes = $objPage->outputFormat == 'xhtml' ? ' rel="' . $strLightboxId . '"' : ' data-lightbox="' . substr($strLightboxId, 9, -1) . '"';
             } else {
                 $objTemplate->attributes = $objPage->outputFormat == 'xhtml' ? ' onclick="return !window.open(this.href)"' : ' target="_blank"';
             }
         }
     } elseif ($arrItem['fullsize'] && TL_MODE == 'FE') {
         $objTemplate->{$strHrefKey} = TL_FILES_URL . \System::urlEncode($arrItem['singleSRC']);
         $objTemplate->attributes = $objPage->outputFormat == 'xhtml' ? ' rel="' . $strLightboxId . '"' : ' data-lightbox="' . substr($strLightboxId, 9, -1) . '"';
     }
     // Do not urlEncode() here because getImage() already does (see #3817)
     $objTemplate->src = TL_FILES_URL . $src;
     $objTemplate->alt = specialchars($arrItem['alt']);
     $objTemplate->title = specialchars($arrItem['title']);
     $objTemplate->linkTitle = $objTemplate->title;
     $objTemplate->fullsize = $arrItem['fullsize'] ? true : false;
     $objTemplate->addBefore = $arrItem['floating'] != 'below';
     $objTemplate->margin = static::generateMargin($arrMargin);
     $objTemplate->caption = $arrItem['caption'];
     $objTemplate->singleSRC = $arrItem['singleSRC'];
     $objTemplate->addImage = true;
 }
Exemple #15
0
 public function test_for_has_many()
 {
     $Property = new Property();
     $this->assertEqual($Property->picture->getType(), 'hasMany');
     $this->assertTrue(is_array($Property->pictures) && count($Property->pictures) === 0);
     $Property->picture->load();
     $this->assertEqual($Property->picture->count(), 0);
     $SeaViews = new Picture(array('title' => 'Sea views'));
     $Property->picture->add($SeaViews);
     $this->assertEqual($Property->picture->count(), 1);
     $this->assertReference($Property->pictures[0], $SeaViews);
     $Property->picture->add($SeaViews);
     $this->assertEqual($Property->picture->count(), 1);
     $this->assertNull($Property->pictures[0]->get('property_id'));
     $MountainViews = new Picture(array('title' => 'Mountain views'));
     $this->assertTrue($MountainViews->isNewRecord());
     $Property->picture->add($MountainViews);
     $this->assertEqual($Property->picture->count(), 2);
     $this->assertTrue($Property->save());
     $this->assertFalse($SeaViews->isNewRecord());
     $this->assertFalse($MountainViews->isNewRecord());
     $this->assertEqual($SeaViews->get('property_id'), $Property->getId());
     $this->assertEqual($MountainViews->get('property_id'), $Property->getId());
     $this->assertReference($SeaViews, $Property->pictures[0]);
     $this->assertReference($MountainViews, $Property->pictures[1]);
     $Property = new Property($Property->getId());
     $Property->picture->load();
     $this->assertEqual($Property->picture->association_id, 'pictures');
     $this->assertEqual($Property->picture->count(), 2);
     $Property->pictures = array();
     $this->assertEqual($Property->picture->count(), 0);
     $Property->picture->load();
     $this->assertEqual($Property->picture->count(), 0);
     $Property->picture->load(true);
     $this->assertEqual($Property->picture->count(), 2);
     $this->assertEqual($Property->pictures[1]->getType(), 'Picture');
     $Property->picture->delete($Property->pictures[1]);
     $this->assertEqual($Property->picture->count(), 1);
     $Property->picture->load(true);
     $this->assertEqual($Property->picture->count(), 1);
     $Property = $Property->find('first');
     $Picture = new Picture();
     $Pictures = $Picture->find();
     $Property->picture->set($Pictures);
     $this->assertEqual($Property->picture->count(), count($Pictures));
     $Property = $Property->find('first');
     $Property->picture->load();
     $this->assertEqual($Property->picture->count(), count($Pictures));
     $Picture = $Picture->find('first');
     $Property->picture->set($Picture);
     $this->assertEqual($Property->picture->count(), 1);
     $this->assertTrue(in_array('pictures', $Property->getAssociatedIds()));
     $Property = $Property->find('first', array('include' => 'pictures'));
     $this->assertIdentical($Property->picture->count(), 1);
     $this->assertEqual($Property->pictures[0]->getId(), $Picture->getId());
     $this->assertTrue($Property->picture->delete($Property->pictures[0]));
     $this->assertIdentical($Property->picture->count(), 0);
     $Property =& $Property->find('first');
     $this->assertIdentical($Property->picture->count(), 0);
     //$this->assertTrue($Property =& $Property->find('first', array('include'=>'pictures')));
     //$this->assertIdentical($Property->picture->count(), 0);
     $Picture = new Picture();
     $Alicia =& $Picture->create(array('title' => 'Alicia'));
     $Bermi =& $Picture->create(array('title' => 'Bermi'));
     $Hilario =& $Picture->create(array('title' => 'Hilario'));
     $Property->picture->setByIds(array($Alicia->getId(), $Bermi->getId(), $Hilario->getId()));
     $Property->set('description', 'Cool house');
     $this->assertTrue($Property->save());
     $this->assertTrue($Property =& $Property->findFirstBy('description', 'Cool house'));
     $Property->picture->load();
     $this->assertEqual($Property->picture->count(), 3);
     $FoundAlicia = $Property->picture->find('first', array('conditions' => array('title = ?', "Alicia")));
     $this->assertEqual($Alicia->get('title') . $Alicia->getId(), $FoundAlicia->get('title') . $FoundAlicia->getId());
     $FoundPals = $Property->picture->find();
     $this->assertEqual(count($FoundPals), $Property->picture->count());
     $titles = array();
     foreach ($FoundPals as $FoundPal) {
         $titles[] = $FoundPal->get('title');
     }
     sort($titles);
     $this->assertEqual($titles, array('Alicia', 'Bermi', 'Hilario'));
     $this->assertFalse($Property->picture->isEmpty());
     $this->assertEqual($Property->picture->getSize(), 3);
     $this->assertTrue($Property->picture->clear());
     $this->assertTrue($Property->picture->isEmpty());
     $this->assertEqual($Property->picture->getSize(), 0);
     $Property = new Property();
     $PoolPicture =& $Property->picture->build(array('title' => 'Pool'));
     $this->assertReference($PoolPicture, $Property->pictures[0]);
     $this->assertTrue($Property->pictures[0]->isNewRecord());
     $this->assertEqual($PoolPicture->getType(), 'Picture');
     $Property->set('description', 'Maui Estate');
     $this->assertTrue($Property->save());
     $this->assertTrue($MauiEstate = $Property->findFirstBy('description', 'Maui Estate', array('include' => 'pictures')));
     $this->assertEqual($MauiEstate->pictures[0]->get('title'), 'Pool');
     $Property = new Property(array('description' => 'Villa Altea'));
     $GardenPicture =& $Property->picture->create(array('title' => 'Garden'));
     $this->assertReference($GardenPicture, $Property->pictures[0]);
     $this->assertTrue($GardenPicture->isNewRecord());
     $Property = new Property(array('description' => 'Villa Altea'));
     $this->assertTrue($Property->save());
     $GardenPicture =& $Property->picture->create(array('title' => 'Garden'));
     $this->assertReference($GardenPicture, $Property->pictures[0]);
     $this->assertFalse($GardenPicture->isNewRecord());
     $this->assertTrue($VillaAltea = $Property->findFirstBy('description', 'Villa Altea', array('include' => 'pictures')));
     $this->assertEqual($VillaAltea->pictures[0]->get('title'), 'Garden');
 }
 /**
  * Finds <img> tags in the content and replaces it with a responsive image.
  *
  * @param $content
  * @return mixed
  */
 public function filter_images($content)
 {
     global $post;
     // Don't do anything with the RSS feed.
     if (is_feed() || is_admin()) {
         return $content;
     }
     // Cache $this. Javascript style for PHP 5.3
     $self = $this;
     // Look for and apply custom media queries that the user has selected in the backend.
     if ($this->custom_media_queries->should_be_applied_when('post', $post)) {
         $this->user_settings = $this->custom_media_queries->get_settings();
     }
     $ignored_image_formats = $this->get_ignored_image_formats();
     // Find and replace all <img>
     $content = preg_replace_callback('/<img[^>]*>/', function ($match) use($self, $ignored_image_formats) {
         // Do nothing with images that has the 'rwp-not-responsive' class.
         if (strpos($match[0], 'rwp-not-responsive')) {
             return $match[0];
         }
         $settings = array('attributes' => array('img' => $self->get_img_attributes($match[0])), 'retina' => get_option('rwp_retina', 'off') == 'off' ? false : true);
         if ($self->custom_media_queries->should_be_applied_when('image', $settings['attributes'])) {
             $self->user_settings = $self->custom_media_queries->get_settings();
         }
         $src = isset($settings['attributes']['img']['src']) ? $settings['attributes']['img']['src'] : '';
         $settings['notBiggerThan'] = $src;
         // We don't wanna have an src attribute on the <img>
         unset($settings['attributes']['img']['src']);
         $id = $self->url_to_attachment_id($src);
         // If no ID is found, the image might be an external, hotlinked one.
         if (!$id) {
             return $match[0];
         }
         // Return if the image format is ignored.
         if ($self->is_ignored_format($src, $ignored_image_formats)) {
             return $match[0];
         }
         if ($self->user_settings) {
             $settings = array_merge_recursive($settings, $self->user_settings);
         }
         // Create responsive image markup.
         $type = get_option('selected_element', 'img');
         $element = Picture::create($type, $id, $settings);
         return $element;
     }, $content);
     return $content;
 }
Exemple #17
0
 public function uploadimage()
 {
     $picture = array();
     $files = Input::file('images');
     $strRand = strtolower(str_random(20));
     $array[0] = $files;
     $extension = $array[0]->getClientOriginalExtension();
     $fileName = $strRand . '.' . $extension;
     $uploadPath = 'upload';
     $picture['image_path'] = $uploadPath . '/normal/' . $fileName;
     $picture['big_path'] = $uploadPath . '/big/' . $fileName;
     $picture['thumbnail_path'] = $uploadPath . '/thumbnail/' . $fileName;
     $picture['image_type'] = Input::get('type');
     $picture['ref_id'] = Input::get('ref_id');
     Image::make($files->getRealPath())->resize(480, 480)->save($picture['big_path']);
     Image::make($files->getRealPath())->resize(308, 308)->save($picture['image_path']);
     Image::make($files->getRealPath())->resize(64, 64)->save($picture['thumbnail_path']);
     $result = Picture::create($picture);
     $picture['id'] = $result->id;
     return json_encode($picture);
 }
 function test_returns_custom_picture_media_query()
 {
     $attributes = Picture::create('attributes', $this->attachment, array('element' => 'picture', 'sizes' => array('thumbnail', 'medium'), 'media_queries' => array('medium' => 'min-width: 1024px')));
     $expected = array('source' => array(array('srcset' => 'http://example.org/wp-content/uploads/IMG_2089-600x800.jpg', 'media' => '(min-width: 1024px)')), 'img' => array('srcset' => 'http://example.org/wp-content/uploads/IMG_2089-480x640.jpg'));
     $this->assertEquals($expected, $attributes);
 }
Exemple #19
0
 function test_custom_size_attribute()
 {
     $img = Picture::create('img', $this->attachment, array('sizes' => array('medium', 'large'), 'attributes' => array('sizes' => '(min-width: 800px) 2448px, 600px')));
     $expected = '<img srcset="http://example.org/wp-content/uploads/IMG_2089-600x800.jpg 600w, http://example.org/wp-content/uploads/IMG_2089-1024x1365.jpg 1024w" sizes="(min-width: 800px) 2448px, 600px">';
     $this->assertEquals($expected, $img);
 }
function rwp_attributes($id, $settings = null)
{
    return Picture::create('attributes', $id, $settings);
}
 protected function addImageData($strKey, $arrSize = array(), &$arrBanner, $objBanner, $strSuffix = '')
 {
     if ($objBanner->{$strKey} == '') {
         return false;
     }
     if ($strSuffix == '') {
         $strSuffix = $strKey;
     }
     $objModel = \FilesModel::findByUuid($objBanner->{$strKey});
     if ($objModel === null || !file_exists(TL_ROOT . '/' . $objModel->path)) {
         return false;
     }
     $objBannerImage = new \BugBuster\Banner\BannerImage();
     $arrImageSize = $objBannerImage->getBannerImageSize($objModel->path, $objBanner->banner_type);
     $arrImageSizenNew = $objBannerImage->getBannerImageSizeNew($arrImageSize[0], $arrImageSize[1], $arrSize[0], $arrSize[1]);
     $singleSRC = $objModel->path;
     //if oriSize = true, oder bei GIF - 1/SWF - 4/SWC - 13 = use original path
     if ($arrImageSizenNew[2] === true || in_array($arrImageSize[2], array(1, 4, 13))) {
         $arrImageSize[0] = $arrImageSizenNew[0];
         $arrImageSize[1] = $arrImageSizenNew[1];
         $arrImageSize[3] = ' height="' . $arrImageSizenNew[1] . '" width="' . $arrImageSizenNew[0] . '"';
         //fake the Picture::create
         $picture['img'] = array('src' => specialchars(ampersand($singleSRC)), 'width' => $arrImageSizenNew[0], 'height' => $arrImageSizenNew[1], 'srcset' => specialchars(ampersand($singleSRC)));
         $picture['alt'] = specialchars(ampersand($objBanner->banner_name));
         $picture['title'] = specialchars(ampersand($objBanner->banner_comment));
         $picture['class'] = 'banner_image_' . $strSuffix;
         \BugBuster\Banner\ModuleBannerLog::writeLog(__METHOD__, __LINE__, 'Orisize Picture ' . $strKey . ': ' . print_r($picture, true));
     } else {
         $singleSRC = \Image::get($this->urlEncode($objModel->path), $arrImageSizenNew[0], $arrImageSizenNew[1], 'proportional');
         $picture = \Picture::create($this->urlEncode($objModel->path), array($arrImageSizenNew[0], $arrImageSizenNew[1], $arrSize[2]))->getTemplateData();
         $picture['alt'] = specialchars(ampersand($objBanner->banner_name));
         $picture['title'] = specialchars(ampersand($objBanner->banner_comment));
         $picture['class'] = 'banner_image_' . $strSuffix;
         \BugBuster\Banner\ModuleBannerLog::writeLog(__METHOD__, __LINE__, 'Resize Picture ' . $strKey . ': ' . print_r($picture, true));
         $arrImageSize[0] = $arrImageSizenNew[0];
         $arrImageSize[1] = $arrImageSizenNew[1];
         $arrImageSize[3] = ' height="' . $arrImageSizenNew[1] . '" width="' . $arrImageSizenNew[0] . '"';
     }
     switch ($arrImageSize[2]) {
         case 1:
         case 2:
         case 3:
             $arrBanner['banner_pic_' . $strSuffix] = true;
             $arrBanner['src_' . $strSuffix] = specialchars(ampersand($singleSRC));
             $arrBanner['picture_' . $strSuffix] = $picture;
             $arrBanner['size_' . $strKey] = $arrImageSize[3];
             break;
     }
 }
Exemple #22
0
 /**
  * Returns the information-array about an album
  *
  * @param null $intPictureId
  * @param $objThis
  * @return array|null
  */
 public static function getPictureInformationArray($intPictureId = null, $objThis)
 {
     if ($intPictureId < 1) {
         return;
     }
     global $objPage;
     $defaultThumbSRC = $objThis->defaultThumb;
     if (\Config::get('gc_error404_thumb') !== '') {
         $objFile = \FilesModel::findByUuid(\Config::get('gc_error404_thumb'));
         if ($objFile !== null) {
             if (\Validator::isUuid(\Config::get('gc_error404_thumb'))) {
                 if (is_file(TL_ROOT . '/' . $objFile->path)) {
                     $defaultThumbSRC = $objFile->path;
                 }
             }
         }
     }
     // Get the page model
     $objPageModel = \PageModel::findByPk($objPage->id);
     $objPicture = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE id=?')->execute($intPictureId);
     //Alle Informationen zum Album in ein array packen
     $objAlbum = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_albums WHERE id=?')->execute($objPicture->pid);
     $arrAlbumInfo = $objAlbum->fetchAssoc();
     //Bild-Besitzer
     $objOwner = \Database::getInstance()->prepare('SELECT name FROM tl_user WHERE id=?')->execute($objPicture->owner);
     $strImageSrc = '';
     $arrMeta = array();
     $objFileModel = \FilesModel::findByUuid($objPicture->uuid);
     if ($objFileModel == null) {
         $strImageSrc = $defaultThumbSRC;
     } else {
         $strImageSrc = $objFileModel->path;
         if (!is_file(TL_ROOT . '/' . $strImageSrc)) {
             // Fallback to the default thumb
             $strImageSrc = $defaultThumbSRC;
         }
         //meta
         $arrMeta = $objThis->getMetaData($objFileModel->meta, $objPage->language);
         // Use the file name as title if none is given
         if ($arrMeta['title'] == '') {
             $arrMeta['title'] = specialchars($objFileModel->name);
         }
     }
     // get thumb dimensions
     $arrSize = unserialize($objThis->gc_size_detailview);
     //Generate the thumbnails and the picture element
     try {
         $thumbSrc = \Image::create($strImageSrc, $arrSize)->executeResize()->getResizedPath();
         $picture = \Picture::create($strImageSrc, $arrSize)->getTemplateData();
         if ($thumbSrc !== $strImageSrc) {
             $objFile = new \File(rawurldecode($thumbSrc), true);
         }
     } catch (\Exception $e) {
         \System::log('Image "' . $strImageSrc . '" could not be processed: ' . $e->getMessage(), __METHOD__, TL_ERROR);
         $thumbSrc = '';
         $picture = array('img' => array('src' => '', 'srcset' => ''), 'sources' => array());
     }
     $picture['alt'] = $objPicture->title != '' ? specialchars($objPicture->title) : specialchars($arrMeta['title']);
     $picture['title'] = $objPicture->comment != '' ? $objPage->outputFormat == 'xhtml' ? specialchars(\String::toXhtml($objPicture->comment)) : specialchars(\String::toHtml5($objPicture->comment)) : specialchars($arrMeta['caption']);
     $objFileThumb = new \File(rawurldecode($thumbSrc));
     $arrSize[0] = $objFileThumb->width;
     $arrSize[1] = $objFileThumb->height;
     $arrFile["thumb_width"] = $objFileThumb->width;
     $arrFile["thumb_height"] = $objFileThumb->height;
     // get some image params
     if (is_file(TL_ROOT . '/' . $strImageSrc)) {
         $objFileImage = new \File($strImageSrc);
         if (!$objFileImage->isGdImage) {
             return null;
         }
         $arrFile["path"] = $objFileImage->path;
         $arrFile["basename"] = $objFileImage->basename;
         // filename without extension
         $arrFile["filename"] = $objFileImage->filename;
         $arrFile["extension"] = $objFileImage->extension;
         $arrFile["dirname"] = $objFileImage->dirname;
         $arrFile["image_width"] = $objFileImage->width;
         $arrFile["image_height"] = $objFileImage->height;
     } else {
         return null;
     }
     //check if there is a custom thumbnail selected
     if ($objPicture->addCustomThumb && !empty($objPicture->customThumb)) {
         $customThumbModel = \FilesModel::findByUuid($objPicture->customThumb);
         if ($customThumbModel !== null) {
             if (is_file(TL_ROOT . '/' . $customThumbModel->path)) {
                 $objFileCustomThumb = new \File($customThumbModel->path, true);
                 if ($objFileCustomThumb->isGdImage) {
                     $arrSize = unserialize($objThis->gc_size_detailview);
                     $thumbSrc = \Image::get($objFileCustomThumb->path, $arrSize[0], $arrSize[1], $arrSize[2]);
                     $objFileCustomThumb = new \File(rawurldecode($thumbSrc));
                     $arrSize[0] = $objFileCustomThumb->width;
                     $arrSize[1] = $objFileCustomThumb->height;
                     $arrFile["thumb_width"] = $objFileCustomThumb->width;
                     $arrFile["thumb_height"] = $objFileCustomThumb->height;
                 }
             }
         }
     }
     //exif
     if ($GLOBALS['TL_CONFIG']['gc_read_exif']) {
         try {
             $exif = is_callable('exif_read_data') && TL_MODE == 'FE' ? exif_read_data($strImageSrc) : array('info' => "The function 'exif_read_data()' is not available on this server.");
         } catch (Exception $e) {
             $exif = array('info' => "The function 'exif_read_data()' is not available on this server.");
         }
     } else {
         $exif = array('info' => "The function 'exif_read_data()' has not been activated in the Contao backend settings.");
     }
     //video-integration
     $strMediaSrc = trim($objPicture->socialMediaSRC) != "" ? trim($objPicture->socialMediaSRC) : "";
     if (\Validator::isUuid($objPicture->localMediaSRC)) {
         //get path of a local Media
         $objMovieFile = \FilesModel::findById($objPicture->localMediaSRC);
         $strMediaSrc = $objMovieFile !== null ? $objMovieFile->path : $strMediaSrc;
     }
     $href = null;
     if (TL_MODE == 'FE' && $objThis->gc_fullsize) {
         $href = $strMediaSrc != "" ? $strMediaSrc : \System::urlEncode($strImageSrc);
     }
     //cssID
     $cssID = deserialize($objPicture->cssID, true);
     // build the array
     $arrPicture = array('id' => $objPicture->id, 'pid' => $objPicture->pid, 'date' => $objPicture->date, 'owner' => $objPicture->owner, 'owners_name' => $objOwner->name, 'album_id' => $objPicture->pid, 'name' => specialchars($arrFile["basename"]), 'filename' => $arrFile["filename"], 'uuid' => $objPicture->uuid, 'path' => $arrFile["path"], 'basename' => $arrFile["basename"], 'dirname' => $arrFile["dirname"], 'extension' => $arrFile["extension"], 'alt' => $objPicture->title != '' ? specialchars($objPicture->title) : specialchars($arrMeta['title']), 'title' => $objPicture->title != '' ? specialchars($objPicture->title) : specialchars($arrMeta['title']), 'comment' => $objPicture->comment != '' ? $objPage->outputFormat == 'xhtml' ? specialchars(\String::toXhtml($objPicture->comment)) : specialchars(\String::toHtml5($objPicture->comment)) : specialchars($arrMeta['caption']), 'caption' => $objPicture->comment != '' ? $objPage->outputFormat == 'xhtml' ? specialchars(\String::toXhtml($objPicture->comment)) : specialchars(\String::toHtml5($objPicture->comment)) : specialchars($arrMeta['caption']), 'href' => TL_FILES_URL . $href, 'single_image_url' => $objPageModel->getFrontendUrl(($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . \Input::get('items') . '/img/' . $arrFile["filename"], $objPage->language), 'image_src' => $arrFile["path"], 'media_src' => $strMediaSrc, 'socialMediaSRC' => $objPicture->socialMediaSRC, 'localMediaSRC' => $objPicture->localMediaSRC, 'addCustomThumb' => $objPicture->addCustomThumb, 'thumb_src' => isset($thumbSrc) ? TL_FILES_URL . $thumbSrc : '', 'size' => $arrSize, 'thumb_width' => $arrFile["thumb_width"], 'thumb_height' => $arrFile["thumb_height"], 'image_width' => $arrFile["image_width"], 'image_height' => $arrFile["image_height"], 'lightbox' => $objPage->outputFormat == 'xhtml' ? 'rel="lightbox[lb' . $objPicture->pid . ']"' : 'data-lightbox="lb' . $objPicture->pid . '"', 'tstamp' => $objPicture->tstamp, 'sorting' => $objPicture->sorting, 'published' => $objPicture->published, 'exif' => $exif, 'albuminfo' => $arrAlbumInfo, 'metaData' => $arrMeta, 'cssID' => $cssID[0] != '' ? $cssID[0] : '', 'cssClass' => $cssID[1] != '' ? $cssID[1] : '', 'externalFile' => $objPicture->externalFile, 'picture' => $picture);
     //Fuegt dem Array weitere Eintraege hinzu, falls tl_gallery_creator_pictures erweitert wurde
     $objPicture = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE id=?')->execute($intPictureId);
     foreach ($objPicture->fetchAssoc() as $key => $value) {
         if (!array_key_exists($key, $arrPicture)) {
             $arrPicture[$key] = $value;
         }
     }
     return $arrPicture;
 }