Image in article

forwarddesign 01 Feb, 2012
Hi!
I would like to add an image to an article. I've done that with CF 3 thanks to some Nice tutorials!
Now I can manage to upload the image, save the text to database byt I can't get the image into the article. I suppose there is some code in the before box.
But what code .....
GreyHead 01 Feb, 2012
Hi forwarddesing,

I'd use a Custom Code action to build an image link from the image name and path; then insert the result into the article body. How you do that bit depends on where you get the rest of the article content from and where you want the image to be placed.

Bob
forwarddesign 01 Feb, 2012
Hi!
I´ve made a form where registered users can create an article with title, introtext, publish up and down. I´d just want the image into the same article, and if its possible to choose left och right align it would be nice.

Is it possible I would like to get the smaller image in introtext and a larger image to fulltext with left align. I´m using the image resize utillity

How can I do?


Here is my form code if you need it.

<div class="ccms_form_element cfdiv_text" id="title_container_div"><label for="title">Rubrik</label><input id="title" maxlength="150" size="30" class=" validate['required']" title="" type="text" value="" name="title" />
<div title="Rubrik" rel="Rubriken för artikeln!" class="tooltipimg"><a href="#">?</a></div><div class="clear"></div><div id="error-message-title"></div></div><div class="ccms_form_element cfdiv_textarea" id="introtext_container_div"><label for="introtext">Introtext</label><textarea id="introtext" cols="45" rows="12" class=" validate['required']" title="" name="introtext"></textarea>
<div class="clear"></div><div id="error-message-introtext"></div></div><div class="ccms_form_element cfdiv_textarea" id="fulltext_container_div"><label for="fulltext">Långa texten</label><textarea id="fulltext" cols="45" rows="12" class="" title="" name="fulltext"></textarea>
<div class="clear"></div><div id="error-message-fulltext"></div></div><div class="ccms_form_element cfdiv_file" id="file_upload_container_div"><label for="file_upload">Bifoga bild</label><input type="hidden" name="file_upload" value="" alt="ghost" />
<input id="file_upload" class="" title="" type="file" name="file_upload" />
<div class="clear"></div><div id="error-message-file_upload"></div></div><div class="ccms_form_element cfdiv_text" id="publish_up_container_div"><label for="publish_up">Starta publisering</label><input id="publish_up" maxlength="150" size="30" class=" validate['required']" title="" type="text" value="" name="publish_up" />
<div title="Starta publisering" rel="Skriv i detta format:<br />
2012-05-15 10:05:00" class="tooltipimg"><a href="#">?</a></div><div class="clear"></div><div id="error-message-publish_up"></div></div><div class="ccms_form_element cfdiv_text" id="publish_sown_container_div"><label for="publish_sown">Avsluta publisering</label><input id="publish_sown" maxlength="150" size="30" class=" validate['required']" title="" type="text" value="" name="publish_down" />
<div title="Avsluta publisering" rel="Skriv i detta format:<br />
2012-05-15 10:05:00" class="tooltipimg"><a href="#">?</a></div><div class="clear"></div><div id="error-message-publish_down"></div></div><div class="ccms_form_element cfdiv_text" id="created_by_alias_container_div"><label for="created_by_alias">Ditt namn</label><input id="created_by_alias" maxlength="150" size="30" class=" validate['required']" title="created_by_alias" type="text" value="" name="created_by_alias" />
<div class="clear"></div><div id="error-message-created_by_alias"></div></div><div class="ccms_form_element cfdiv_submit" id="autoID-a2d6b47714e5fe1daecc981e9a4b41bf_container_div"><input name="input_submit_6" class="" value="Skicka in text" type="submit" />
 <input type='reset' name='reset' value='Återställ' /> <input type='button' name='back' value='Back' onclick='history.back()' /><div class="clear"></div><div id="error-message-input_submit_6"></div></div>
GreyHead 02 Feb, 2012
Hi forwarddesign,

Something like this:
<?php
jimport( 'joomla.filesystem.file' );
$small_image = $form->data['image_input']; 
$ext = JFile::getExt($small_image);
$name = JFile::stripExt($small_image);
$name = 'some_prefix'.$name.'some_suffix.'.$ext;
$uri = JFactory::getURI();
$img_tag = "<img src='{$uri->root()}some_path{$name}' style='float:right;'/>";

// add the image to the introtext
$form->data['introtext'] = $img_tag.$form->data['introtext'];
?>

This will just put the image tag at the beginning of the introtext floated to the right.
You can use similar code for the other images.

If you want to allow users to embed images in their text you can ask them to use place holders e.g. ##small_image_right## and then use search and replace to put the images tags into the text.

Bob

PS The Image Resizer would be friendlier if it gave you the new file names and paths - maybe a future version will do that.
forwarddesign 06 Feb, 2012
Thank you for the code! It works perfectly!

I have one more question...
I would like to insert some code before and after the text that the user insert in 'introtext'
I want to use Nonumbers modalizer and I have managed to insert code before the text but not after

So what I want is
{/modal}
at the end of the text in the formfield 'introtext'

Is this possible
GreyHead 06 Feb, 2012
Hi forwarddesign,

Please try:
$form->data['introtext'] .= '{/modal}';


Bob
forwarddesign 06 Feb, 2012
Thank you for the code!
It insert
{/modal}
in introtext but it gets first not in the end...

This comes first in the article:
{/modal}{modal url= http://localhost:8888/Joomla_1.7.3/index.php/test/0-1632}


Here´s my code that i put in a customcode box before the submit article box.
<?php
jimport( 'joomla.filesystem.file' );
$title = $form->data['title'];
//$articleId = JRequest::getInt('id');
$articleId = (JRequest::getVar('option')==='com_content' && JRequest::getVar('view')==='article')? JRequest::getInt('id') : 0;
$exit = "{/modal}";


$modal = "{modal url= http://localhost:8888/Joomla_1.7.3/index.php/test/$articleId-$title}";
$form->data['introtext'] = $modal.$form->data['introtext'];
$form->data['introtext'] = $exit.$form->data['introtext'];
?>


As you can see I´m trying to get the articleid as well....
GreyHead 06 Feb, 2012
Hi forwarddesign ,

Hmm, I'm not sure how that ends up at the beginning .= should always add to the end.

In your code these lines
$form->data['introtext'] = $modal.$form->data['introtext'];
$form->data['introtext'] = $exit.$form->data['introtext'];
Should be

$form->data['introtext'] = $modal.$form->data['introtext'].$exit;


Bob
forwarddesign 06 Feb, 2012
hmm it dosen´t work...

is it possible to do something like this
add a hidden field with the value
{/modal}
and merge the hidden field with the introtext field with some php code to a new and use the new field in the submit article box?
GreyHead 06 Feb, 2012
Hi forwarddesign ,

There is something going wrong here. Both those examples should work OK.

Exactly what code do you have now?

Using hidden fields might work - but it really isn't necessary.

Bob
forwarddesign 06 Feb, 2012
Hi Bob!
Somehow it´s workning now, maybe I was trying with several solutions at the same time.
Thank you for your time and engagement!
forwarddesign 07 Feb, 2012
Hi there again!

There is one more thing that I´ve been working on but can´t get it right

My users can submit an article with images and now the modulizer is working but I can´t get the linking right. I have know what item/article id the new articles is getting.
The url looks like this http://mydomain.com/category/itemid-title

I´ve started with this code
<?php
jimport( 'joomla.filesystem.file' );
$articleId = (JRequest::getVar('option')==='com_content' && JRequest::getVar('view')==='article')? JRequest::getInt('id') : 0;
$title = $form->data['title'];
$exit = "{/modal}";


$modal = "{modal url= http://localhost:8888/Joomla_1.7.3/index.php/test/$articleId-$title}";
$form->data['introtext'] = $modal.$form->data['introtext'].$exit;
?>

And it returns with /test/0-title

My plan was to get the lastest record for item id and just add 1 up for my url.
If the lastest is 22 then I make it 23 in the url
Is it possible? Should I change my plan?
GreyHead 08 Feb, 2012
Hi forwarddesign,

You can get into problem using JRequest in If statements. Try replacing this line
$articleId = (JRequest::getVar('option')==='com_content' && JRequest::getVar('view')==='article')? JRequest::getInt('id') : 0;
with
$article = JRequest::getVar('view');
$option = JRequest::getVar('option');
$id = JRequest::getInt('id');
$articleId = 0;
if ( $option == 'com_content' && $view == 'article' ) {
  $articleId = $id;
}

Bob
forwarddesign 08 Feb, 2012
Hi Bob!
Thank you for the code, but it still dosen´t work
I´ve tried with the code you sent
<?php
jimport( 'joomla.filesystem.file' );
$article = JRequest::getVar('view');
$option = JRequest::getVar('option');
$id = JRequest::getInt('id');
$articleId = 0;
if ( $option == 'com_content' && $view == 'article' ) {
  $articleId = $id;
}
$title = $form->data['title'];
$exit = "{/modal}";



$modal = "{modal url=test/$articleId-$title}";
$form->data['introtext'] = $modal.$form->data['introtext'].$exit;
?>


The modal url gets like this mydomain.com/test/0-title
Have you got any suggestions?
GreyHead 10 Feb, 2012
Hi forwarddesign,

Is the article id in the URL at all?

Bob
forwarddesign 10 Feb, 2012
Yes and no
Instead of articleId I get 0 in the url
ex. mydomain.com/test/0-title


<?php
jimport( 'joomla.filesystem.file' );
$article = JRequest::getVar('view');
$option = JRequest::getVar('option');
$id = JRequest::getInt('id');
$articleId = 0;
if ( $option == 'com_content' && $view == 'article' ) {
  $articleId = $id;
}
$title = $form->data['title'];
$exit = "{/modal}";



$modal = "{modal url=http://localhost:8888/Joomla_1.7.3/index.php/test/$articleId-$title}";
$form->data['introtext'] = $modal.$form->data['introtext'].$exit;

?>
GreyHead 10 Feb, 2012
Hi forwarddesign ,

Sorry my question was vague - I meant does it appear in the article page URL that you are starting from.

Bob
forwarddesign 10 Feb, 2012
Yes it does. I got the url by add the read more feature to the article
I display the articles with category blogg you can se it and try it here http://www.ejk.se/demo2
I have added the url my self on that site
GreyHead 11 Feb, 2012
Hi forwarddesign,

I don't see the form anywhere - nor do I see any URLs with article ids in them; but I may not be looking in the correct place :-(

Bob
forwarddesign 11 Feb, 2012
Sorry the site is in Swedish, but I changed it i little bit now

The form is under "Form"
The result of the form is under "Efterrätter"
If you hover over the articles under "Efterrätter" you will se the url for the modalbox

I hope you can see it now
forwarddesign 20 Feb, 2012
Hi Bob!
Could you please look at this one more time?
I can´t get it right.

I has been looking a bit at
http://docs.joomla.org/How_to_use_the_database_classes_in_your_script#Single_Value_Result

and found this and was thinking maybe this can be a solution
$db =& JFactory::getDBO();
$query = "
  SELECT ".$db->nameQuote('field_name')."
    FROM ".$db->nameQuote('#__my_table')."
    WHERE ".$db->nameQuote('some_name')." = ".$db->quote($some_value).";
  ";
$db->setQuery($query);
$result = $db->loadResult();


Thank you!
GreyHead 21 Feb, 2012
Hi forwarddesign,

The code is fine but by itself it doesn't mean anything.

What **exactly** do you need to do?

I can see the 135, 136 and 137 in the modal window links. Are these the ids that you need?

Bob
forwarddesign 21 Feb, 2012
Hi Bob!

Yes! 135, 136, 137 and so on that´s the id´s I need. That is the articles id and I what it in the modal-link via the form
This topic is locked and no more replies can be posted.