newb: typo3 access uploaded images in typoscript - image

I'm trying to do something like in this Tutorial, a very basic gallery.
In the example of the Tut they load images from uploads/media/ like so
page.10.marks.PROJECTTHUMBNAIL = IMG_RESOURCE
page.10.marks.PROJECTTHUMBNAIL {
stdWrap.wrap = <img src="|" />
file {
import = uploads/media/
import.data = levelmedia: -1,slide
import.listNum = 0
}
}
but now I want to load pictures that have been uploaded in an image-cObject.
This is an embarrassing question but I've been trying to figure this out for two days and I can't seem to get it right -.- I'm sure there are lots of answers out there... I just don't know the magic words to put into google to FIND them T-T
I tried very basic stuff like just doing the same as above but with a different path, I rummaged through the TSRef of IMAGE and IMG_RESOURCE, tried fiddling with CONTENT, and tried to adapt the tt_content.image.20 = USER (?? O.o) description in the typoscript object-browser... but all to no avail, as I know so little what I'm doing -.-
Any nudge in the right direction would be greatly appreciated!

You have to load the content elements using the CONTENT cObject and set how the content shall be rendered. This will load Image content elements on the given page regardless of what column they are in:
page.10.marks.PROJECTTHUMBNAIL = CONTENT
page.10.marks.PROJECTTHUMBNAIL {
table = tt_content
select {
where = CType = 'image' AND image != ''
orderBy = sorting ASC
}
renderObj = IMAGE
renderObj {
file {
import = uploads/pics/
import.field = image
import.listNum = 0
}
}
}
NOTE: The renderObj is just my example and it renders only the first image of the Image element. You can set the rendering as you please, e.g. set the file to be GIFBUILDER which would allow you to resize the image. You can also tweak the select to load content elements with more refined conditions.

Related

Image duplicates itself when using appendParagraph in Google Script

I wrote a script to add an image from my Google Drive and some custom text to a Google Doc. (I got the image insertion code from here).
The resulting document is created ok, but my image is added twice for some reason...
function myFunction(e) {
var doc = DocumentApp.create('fileTest');
var body = doc.getBody();
var matchedFiles = DriveApp.getFilesByName('logo.png');
if (matchedFiles.hasNext()) {
var image = matchedFiles.next().getBlob();
var positionedImage = body.getParagraphs()[0].addPositionedImage(image);
}
body.appendParagraph('Test line of text for testing');
doc.saveAndClose();
}
However, if I get rid of my appendParagraph code (body.appendParagraph(t1);) I only get one image (but obviously without the paragraph of text I want)
What's going on here? And how do I add both one picture and my paragraph of text?
I have not even the slightest clue as to why, but I found a way to make this work.
Switching the order of my code seemed to do the trick. I simply moved the image-insertion code to the end (i.e., after the appendParagraph code), and it worked fine. No duplicate image!
function myFunction(e) {
var doc = DocumentApp.create('fileTest');
var body = doc.getBody();
body.appendParagraph('Test line of text for testing');
var matchedFiles = DriveApp.getFilesByName('logo.png');
if (matchedFiles.hasNext()) {
var image = matchedFiles.next().getBlob();
var positionedImage = body.getParagraphs()[0].addPositionedImage(image);
}
doc.saveAndClose();
}

Scraping with casperjs -- Not sure how to handle empty div

I'm using casperjs to scrape a site. I setup a function which stores a string into a variable named images (shown below) and it works great.
images = casper.getElementsAttribute('.search-product-image','src');
I then call that variable in fs so I can export it to a CSV, which also works fine.
casper.then(function() {
var f = fs.open('e36v10.csv', 'w');
f.write(imagessplit + String.fromCharCode(13));
f.close();
});
The issue I just noticed is that not all products have images, so when the scraper hits a product without an image it passes by it obviously. I need it to at least alert me somehow (something as simple as filler text thats says, "no image here") when it passes by a product without an image because what I do is I copy that string (along with may other strings) and organize them into columns within the CSV and it messes up the order of everything without having some sort of filler text ("no image here"). Thanks
Edit
Below is the exact source from the website I am trying to pull from.
A product I can get the image from and my code works fine:
<div class="search-v4-product-image">
<img alt="238692" class="search-product-image" src="http://d5otzd52uv6zz.cloudfront.net/group.jpg">
<p class="image-overlay">Generic</p>
</div>
A product with no image and my scraper passes right by it without alerting me.
<div class="search-v4-product-image"> </div>
First I would do images = casper.getElementsInfo('.search-product-image') which will give you an array of elements matching .search-product-image. Then you can iterate over this array and extract the src attribute from each element with: var src = image.attributes.src
Now that you have the src attribute you can simply check wether it has a value or not. If it does not, then you could assign it to placeholder text.
You can write this functionality for the page context this way:
casper.then(function(){
var imgList = this.evaluate(function(){
var productImages = document.querySelectorAll("div.search-v4-product-image"),
imageList = [];
Array.prototype.forEach.call(productImages, function(div){
if (div.children.length == 0) {
imageList.push({empty: true});
} else {
var img = div.children[0]; // assumes that the image is the first child
imageList.push({empty: false, src: img.src});
}
});
return imageList;
});
var csv = "";
imgList.forEach(function(img){
if (img.empty) {
csv += ";empty";
} else {
csv += img.src+";";
}
});
fs.write('e36v10.csv', csv, 'w');
});
This iterates over all divs and pushes the src to an array. You can check the empty property for every element.
I suspect that the output would be more meaningful if you iterate over all product divs and check it this way. Because then you can also write the product name to the csv.
You could use CSS selectors but then you would need make the :nth-child selection much higher in the hierarchy (product div list). This is because :nth-child only works based on its parent and not over the whole tree.

Remove original image after automatic creation of featured image

I installed the plugin http://wordpress.org/plugins/automatic-featured-image-posts/ but I am having a problemm, because the plugin doesn't remove the original image from the post content after creating the featured image. (and therefore when I don't add the featured image there appear 2 images on the post)
I tried adding this to the auto-featured-image.php
add_action('publish_post', 'eliminaroriginal');
and then
function eliminaroriginal(){ //update the post without image
$post_parent_id = $post->post_parent === 0 ? $post->ID :
$post->post_parent; $contenido = preg_replace("/[caption
.+?[/caption]|\< [img][^>][.]*>/i", "", $post->post_content,
1); $mipost = array(); $mipost['ID'] = $post_parent_id;
$mipost['post_content'] = $contenido; wp_update_post( $mipost );
}
but it didn't have any result.
Please help me, I don't know what should I do.
Thank you before hand!

CKEditor 4: Image Properties dialog and custom preview image

Just to get you up to speed, I have set-up my CKEditor instance so that when viewing the WYSIWYG (live) mode [image:abc123] is replaced with the actual URL to the image.
So for example in the HTML source view, you see this:
<img src="[image:abc123]" />
But when you view the WYSIWYG (live) mode, it shows this:
<img src="/file/image/abc123" />
This is all working great. An issue I am now having is when you edit the image in Image properties. As the image does not exist, it show's the red x.
http://img405.imageshack.us/img405/104/jzny.png
My question is, is there a way to customise the Image Properties dialog so that if it matches [image:abc123], it loads a different image URL in the Preview window?
This code doesn't work but might make it a little clearer what I'm trying to achieve here.
CKEDITOR.on('dialogDefinition', function(evt) {
if (evt.data.name == 'image') {
var image_url = ???;
var preview_image = ???;
var file_id = image_url.value.match(/\[image:([a-zA-Z0-9-]+)\]/);
if (file_id)
preview_image.src = '/file/image/' + file_id[1];
}
});
Thanks in advance!

link an image in tt_news

I'm using TYPO3 4.2.8 and tt_news 2.5.2. I tried the following snippet:
plugin.tt_news.displaySingle {
image {
# turn off default popup anchor
imageLinkWrap = 0
# add our link to the first URL in links field
stdWrap.typolink {
parameter = {current:1}
parameter {
setCurrent.field = links
setCurrent.listNum = 0
insertData = 1
}
}
}
}
Then I added an image to my news and also put a link into the link field (in the tab relations).
<LINK http://www.yourwesite.com/fileadmin/user_upload/downloads/broschure.pdf _blank>Download brochure</LINK>
But if I look at the news I don't have a link on the image. What do I have to change to get it work with my old version of tt_news?
Edit:
Now I tried it with gernericmarkers (idea from this topic). My TS looks like the following:
temp.img = COA
temp.img.5 = IMAGE
temp.img.5 < plugin.tt_news.displaySingle.image
temp.img.5 {
required = 1
wrap = |
file {
import = uploads/pics/
import.field = image
import.listNum = 0
}
titleText.field = title
altText.field = title
if.isTrue.field = links
imageLinkWrap.typolink.parameter.data = field:links
}
plugin.tt_news.genericmarkers.imagewithlink < temp.img
The marker is working but there is no content displayed in the news. What is wrong with my TS?
I don't know if this works in your old tt_news version but at least from version 3.0+ you can simply use the marker <!--###LINK_ITEM###--> around your image <!--###LINK_ITEM###--> inside your template to link anything you like to the detail page.
Your first snippet works, but you have to insert the link without the tags into the link field.
e.g.
http://www.yourwesite.com/fileadmin/user_upload/downloads/broschure.pdf _blank

Resources