Liferay Dynamic Data Lists: How to get image URL? - dynamic

I am creating a custom template in velocity for a Dynamic Data Lists and I want to get the image URL for the selected image. How can I get it?
The code is:
#set ( $DDLRecordService = $serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService") )
#set ( $records = $DDLRecordService.getRecords($mathTool.toNumber($reserved_record_set_id)) )
#foreach ($record in $records)
#set( $fields = $record.getFields() )
#set( $URL = $fields.get("URL").getValue() )
#set( $Link = $fields.get("Linktitle").getValue() )
#set( $Preview = $fields.get("Vorschaubild").getValue() ) ##the image is here
$URL
$Link
$Preview
#end
The $preview output is: {"groupId":"0000000","uuid":"ccdaccec-00a0-4284-a000-589be48‌​99281","version":"1.‌​0"}
Any suggestion?

Itt will work if you replace UUID_HERE to the real UUID.
<a href='${themeDisplay.getPortalURL()}/c/document_library/get_file?uuid=UUID_HERE&groupId=${themeDisplay.getScopeGroupId()}'>MyFile OR Image</a>

I also came across similar situation and after searching on the internet for hour(s), didn't find any useful information apart from LPS-34792 ticket.
Well, you can render image on the UI from a Documents and Media field using:
<#assign hasPicture = cur_record.getFieldValue("picture")?has_content>
<#if hasPicture>
<#assign picture = jsonFactoryUtil.createJSONObject(cur_record.getFieldValue("picture"))>
<img src='/documents/${picture.getString("groupId")}/${picture.getString("uuid")}' />
</#if>
Where picture is the name of field and hasPicture will check if the image was selected.

Related

Prestashop 1.7.6: Getting and displaying the 2° product image as background in text customization area

I am on prestashop 1.7.6. On the product page: i need to show the second(2°) or third(3°) image as background-image in the textarea text customization (when text customization is active).
example image getting first product image
In the photo attached i get the first image but i don't know how to get the second one.
Can someone help me?
Create a new method in Product.php class, to get the images:
public static function getImagesByID($id_product, $limit = 2){
$id_image = Db::getInstance()->ExecuteS('SELECT `id_image` FROM `'._DB_PREFIX_.'image` WHERE `id_product` = '.(int)($id_product) . ' ORDER BY position ASC LIMIT 1, ' . $limit);
$toReturn = array();
if(!$id_image)
return;
else
foreach($id_image as $image)
$toReturn[] = $id_product . '-' . $image['id_image'];
return $toReturn;
}
And use the static function in the smarty template
{assign var="pImages" value=Product::geImagesByID($product.id_product, 2)}
{foreach from=$pImages item=image name=images}
<img src="{$link->getImageLink($product.link_rewrite, $image, 'home_default')}" {if $smarty.foreach.images.first}class="current img_{$smarty.foreach.images.index}"{else} class="img_{$smarty.foreach.images.index}" style="display:none;"{/if} alt="{$product.legend|escape:'htmlall':'UTF-8'}" {if isset($homeSize)} width="{$homeSize.width}" height="{$homeSize.height}"{/if}/>
{/foreach}

remove html tags from result in CodeIgniter

I am getting result from database
$query = $this->db->query("Select Query");
return $query->result_array();
In controller
$this->output->set_content_type('application/json');
echo json_encode($query);
Now I want to remove all html tags from text inside array result in model.
You could just use the strip_tags function!

Add full link to short link to make it valid using scrapy? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Scrapy Modify Link to include Domain Name
I use this code to extract data from html website and i stored the data in XML file and it works great with me.
def parse(self, response):
hxs = HtmlXPathSelector(response)
items = []
site1 = hxs.select('/html/body/div/div[4]/div[3]/div/div/div[2]/div/ul/li')
for site in site1:
item = NewsItem()
item ['title'] = site.select('a[2]/text()').extract()
item ['image'] = site.select('a/img/#src').extract()
item ['text'] = site.select('p/text()').extract()
item ['link'] = site.select('a[2]/#href').extract()
items.append(item)
return items
but the issue that i am facing is the website provide a short link for ['image'] which like this:
<img src="/a/small/72/72089be43654dc6d7215ec49f4be5a07_w200_h180.jpg"
while the full link should be like this:
<img src="http://www.aleqt.com/a/small/72/72089be43654dc6d7215ec49f4be5a07_w200_h180.jpg"
I want to know how to modify my code to add the missing link automatically
You can try this
item ['link'] = urljoin(response.url, site.select('a[2]/#href').extract())
On the assumption that all such image links simply need "http://www.aleqt.com" added to them, you could just do something like this:
def parse(self, response):
base_url = 'http://www.aleqt.com'
hxs = HtmlXPathSelector(response)
items = []
site1 = hxs.select('/html/body/div/div[4]/div[3]/div/div/div[2]/div/ul/li')
for site in site1:
item = NewsItem()
item ['title'] = site.select('a[2]/text()').extract()
item ['image'] = base_url + site.select('a/img/#src').extract()
item ['text'] = site.select('p/text()').extract()
item ['link'] = base_url + site.select('a[2]/#href').extract()
items.append(item)
return items
Alternatively, if you've added that exact same url to the start_urls list (and assuming there's only one, you could replace base_url with self.start_urls[0]

Get title, nav_title and subtitle

I want to print the fields title, nav_title and subtitle with Typoscript. I saw that there are several possibilities. E.g. data, field, levelfield, leveltitle, ...
Currently I'm using this code (because the only one which works for me so far):
lib.heading = TEXT
lib.heading.dataWrap = <p class="title"> {leveltitle:0} </p>
but I want something with alternatives like this
stdWrap.field = subtitle // nav_title // title
What is the correct way of retrieving these fields?
Edit:
[userFunc = user_isMobile]
page.headerData.10 = TEXT
page.headerData.10.value (
// ...
)
// ...
lib.heading = TEXT
#lib.heading.dataWrap = <p class="title"> {leveltitle:0} </p>
lib.heading {
field = title
wrap = <p class="title"> | </p>
}
lib.subpages = HMENU
lib.subpages {
// ...
}
[global]
The userfunction itself is a function in a php script (user_mobile.php). It makes a user agent detection for mobile devices and returns true or false.
field will get values from the current data which in your context is the data of the current page.
lib.heading = TEXT
lib.heading {
field = subtitle // nav_title // title
wrap = <p class="title">|</p>
}
leveltitle, leveluid, levelmedia, etc. allow you to retrieve some of the data from other pages in the rootline of the current page.
For more information see getText in the documentation.

Youtube api get latest upload thumbnail

I am looking to returning the video-thumbnail of the latest uploaded video from my channel, and display it on my website.
Anyone know how I can do a minimal connection trough api and get only the thumbnail?
Thanks!
-Tom
REVISED!!
Using Cakephp, this is how I did it (thanks dave for suggestions using zend);
controller:
App::import('Xml');
$channel = 'Blanktv';
$url = 'https://gdata.youtube.com/feeds/api/users/'.$channel.'/uploads?v=2&max-results=1&orderby=published';
$parsed_xml =& new XML($url);
$parsed_xml = Set::reverse($parsed_xml);
//debug($parsed_xml);
$this->set('parsed_xml',$parsed_xml);
View;
$i=0;
foreach ($parsed_xml as $entry)
{
echo '<a href="/videokanalen" target="_self">
<img width="220px" src="'.$entry['Entry']['Group']['Thumbnail'][1]['url'] .'">
</a>';
}
Now the only thing remaining is to cache the feed call someway.. Any suggestions???
-Tom
here is a quick dirty way of doing it without really touching the api at all.
I'm not suggesting it's best practice or anything and I'm sure there are smarter ways but it definitely works with the current Youtube feed service.
My solution is PHP using the Zend_Feed_Reader component from Zend Framework, if you need a hand setting this up if you're not familiar with it let me know.
Essentially you can download version 1.11 from Zend.com here and then make sure the framework files are accessible on your PHP include path.
If you are already using Zend Framework in an MVC pattern you can do this in your chosen controller action:
$channel = 'Blanktv'; //change this to your channel name
$url = 'https://gdata.youtube.com/feeds/api/users/'.$channel.'/uploads';
$feed = Zend_Feed_Reader::import($url);
$this->view->feed = $feed;
Then you can do this in your view:
<h1>Latest Video</h1>
<div>
<?php
$i=0;
foreach ($this->feed as $entry)
{
$urlChop = explode ('http://gdata.youtube.com/feeds/api/videos/',$entry->getId());
$videoId = end($urlChop);
echo '<h3>' . $entry->getTitle() . '</h3>';
echo '<p>Uploaded on: '. $entry->getDateCreated() .'</p>';
echo '<a href="http://www.youtube.com/watch?v=' . $videoId .'" target="_blank">
<img src="http://img.youtube.com/vi/' . $videoId .'/hqdefault.jpg">
</a>';
$i++;
if($i==1) break;
}
?>
</div>
otherwise you can do:
<?php
$channel = 'Blanktv'; //change this to your channel
$url = 'https://gdata.youtube.com/feeds/api/users/'.$channel.'/uploads';
$feed = Zend_Feed_Reader::import($url);
?>
<h1>Latest Video</h1>
<div>
<?php
$i=0;
foreach ($feed as $entry)
{
$urlChop = explode ('http://gdata.youtube.com/feeds/api/videos/',$entry->getId());
$videoId = end($urlChop);
echo '<h3>' . $entry->getTitle() . '</h3>';
echo '<p>Uploaded on: '. $entry->getDateCreated() .'</p>';
echo '<a href="http://www.youtube.com/watch?v=' . $videoId .'" target="_blank">
<img src="http://img.youtube.com/vi/' . $videoId .'/hqdefault.jpg">
</a>';
$i++;
if($i==1) break;
}
?>
</div>
With the latter method you'll likely need to use a php require statement for the Zend_Feed_Reader files etc....
Hope this helps, like I say let me know if you need a hand.
All the best,
Dave
UPDATE: In response to your comments about caching
Hi Tom, here is another quick and dirty solution which doesn't use cache but may be very quick to implement.
The reason I didn't go with a caching component is because I figured a simple db solution would suffice under the circumstances. I also thought having to pull the feed to compare whether it was new or not wouldn't be the most economical for you.
You could automate this process to be run automatically at specified times but if you don't want to automate the process and don't mind clicking a link to update the video manually you could trigger it that way.
My solution is again based on ZF but since you were ok hacking it into something useful with cakephp you should have no problem doing the same here.
First set up a new table (assuming a MySQL db):
CREATE TABLE `yourdbname`.`latestvid` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique identifier',
`videoId` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Video id',
`videoTitle` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Video title',
`uploadDate` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Video upload date'
) ENGINE = INNODB CHARACTER SET utf8 COLLATE utf8_general_ci;
INSERT INTO `yourdbname`.`latestvid` (`id`, `videoId`, `videoTitle`, `uploadDate`) VALUES (NULL, '--', '--', '--');
This will create a table for your latest video info for use in your template however the default values I've set up will not work with your template for obvious reasons.
You could then do something similar to this:
public function updateAction()
{
$this->_helper->viewRenderer->setNoRender(); // disable view
$this->_helper->layout()->disableLayout(); // disable layout
$user = 'Blanktv'; // insert your channel name
$url = 'https://gdata.youtube.com/feeds/api/users/'.$user.'/uploads';
$feed = Zend_Feed_Reader::import($url);
if(!$feed)
{
die("couldn't access the feed"); // Note: the Zend component will display an error if the feed is not available so this wouldn't really be necessary for ZF
}
else
{
$i=0;
foreach ($feed as $entry)
{
$urlChop = explode ('http://gdata.youtube.com/feeds/api/videos/',$entry->getId());
$videoId = end($urlChop);
$videoTitle = $entry->getTitle();
$uploadDate = $entry->getDateCreated();
// use your preferred method to update the db record where the id = 1
$i++;
if($i==1) break;
}
}
}
Maybe have a go and let me know how you get on?
You'd just need to tweak the template so you'd get the variables from the database instead of Youtube with the exception of the thumbnail.
I suppose you could always take that approach further and actually store images etc since the thumbnail is still being pulled from Youtube and may slow things down.
You could set up a script to copy the thumbnail to your own server and store the path in the db or use a standard thumbnail if you are running a series of videos for which you require standard branding - anyway hope it helps.
:-D
Dave