Publishing news with automatic features (autosummary, img au

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
User avatar
blast2007
Power Poster
Power Poster
Posts: 508
Joined: Wed Aug 01, 2007 5:36 pm

Publishing news with automatic features (autosummary, img au

Post by blast2007 »

UPDATE: jump to this post for CMSMS v1.11.xx compatible version.
---------------------------------------------------------------------

Hi all,
I want to share some tricks used for make easy life to my editors and also for create standard formatted news article without pain. A lot of following work comes from various post of this forum (many thanks to all contributors)

First of all I want to show the result of my work, "next 5 upcoming events" news summary template, based on current date (in my example 31/12/2008).

Summary Template
Image

Detail template:
Image


Where are the tricks?

* The thumbnail images in news summary template are taken from a news field.
* The same field is used inside news detail page (placed on top right)  but with bigger size.
* The summaries (of news summary template) are taken from the news content (first 140 chars).
* All img ALT tags are generated from article name (not nice I know)
* Editors can create a news article without inserting/resizing images in TinyMCE and without worries about ALT tags
* No need of creating summaries.
* All articles published in standard ways with standard images size

Here tools needed:

* News module (if you want "next upcoming event" feature just apply my "period" patch)
* Plugin dynresize (to install in /plugin directory)

Here the steps for this task
1) Create a new field in news (file type) with a smart name i.e. "img_news_max_width_300px"

2) Create two new templates:

the First is summary_template:

Code: Select all

<div class="NewsSummary">
{foreach from=$items item=entry}
<div class="NewsSummaryArticle">
{if isset($entry->fields)}
      {if $entry->fields|@count>0}
      {foreach from=$entry->fields item='field'}
              {if $field->name == 'img_news_max_width_300px' && $field->value!=''}
                            {assign var='loc' value=$entry->file_location}
                            {assign var='theFile' value=$field->value}
                            {capture name=some_content assign="imgName"}{dynresize path=$loc|cat:'/'|cat:$theFile width='90' alt=$entry->title|escape:htmlall}{/capture}
                            {assign var=title value=$entry->title|escape:htmlall}
                            {$imgName|replace:"/>":" alt=\"$title\" />"}
              {/if}
      {/foreach} 
      {else}
              <img src="uploads/images/no_img.gif" alt="No images for this article" />
      {/if}
{/if}
<strong>{$entry->postdate|date_format:"%d/%m/%Y"} - {$entry->title}</strong>
<br />


<div class="NewsSummarySummary">
		{$entry->content|strip_tags|truncate:140}
</div>

<div class="NewsSummaryMorelink">
		[{$entry->morelink}]
</div>

</div>
{/foreach}
</div>
The second is detail_template:

Code: Select all

{assign var="pagetitle" value=$entry->title}

<div class="NewsDetail">
<h3 id="NewsPostDetailTitle">{$entry->postdate|date_format:"%d/%m/%Y"}: 
{$entry->title}</h3>

{if isset($entry->fields)}
      {if $entry->fields|@count>0}

      {foreach from=$entry->fields item='field'}
              {if $field->name == 'img_news_max_width_300px' && $field->value!=''}
                            {assign var='loc' value=$entry->file_location}
                            {assign var='theFile' value=$field->value}
                            {capture name=some_content assign="imgName"}{dynresize path=$loc|cat:'/'|cat:$theFile width='300' alt=$entry->title|escape:htmlall}{/capture}
                            {assign var=title value=$entry->title|escape:htmlall}
                            {$imgName|replace:"/>":" alt=\"$title\" />"}
              {/if}
      {/foreach}

      {/if}
{/if}

<div id="NewsPostDetailContent">
	{eval var=$entry->content}
</div>

</div>

You can call your news template with this code:

Code: Select all

{capture assign='currentdate'}{current_date format="%F" }{/capture}
{CGFeedMaker action='rsslink' feed='your_feed_name_here text=' ' image='/images/cms/RSS_feed.png'}
Here your news title <br />
{news category="your_category_name_here" sortasc="true" startperiod=$currentdate number="5" summarytemplate="summary_template" detailtemplate="detail_template"}
I hope this post will be useful.
Waiting for your reply
regards
blast.

P.S. All pictures in example are property of respective owners (random pictures taken from google images)
Last edited by blast2007 on Sat Dec 08, 2012 3:41 pm, edited 4 times in total.
vilkis

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by vilkis »

Cool. I have bookmarked this topic. I will try it late. Thanks for sharing.
vilkis
goodfella1978
Forum Members
Forum Members
Posts: 13
Joined: Wed Sep 10, 2008 6:12 am

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by goodfella1978 »

Brilliant work! Can't wait to try it out, thank you!

Just one question, sorry to sound silly but how do you add the image? Is it using the new 'file type' field? Because you mention TinyMCE won't be required for the news image. Sorry I've never created new fileds in the News module so that bit will be new to me!

Thanks again.
goodfella1978
Forum Members
Forum Members
Posts: 13
Joined: Wed Sep 10, 2008 6:12 am

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by goodfella1978 »

Sorry Blast, one quick question (ignore my first one above!)

I've set this all up and have tried to post a sample news article. My 'no_img.gif' (for when no image is uploaded) appears appears just fine but when I upload an image for the article it appears as a broken link.

I checked the code and the link appears as this below, is it correct?



I'm using CMSMS version 1.5.4 with News Module version 2.9.3

Many thanks for any help!
User avatar
blast2007
Power Poster
Power Poster
Posts: 508
Joined: Wed Aug 01, 2007 5:36 pm

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by blast2007 »

Have you installed a working copy of dynresize?

Here the files and their path:
* imager.php must be copied in the root / of your site,
* function.dynresize.php must be copied in /plugins directory.

Then you can check if dynresize works simply entering:

Code: Select all

http://www.yoursite.com/imager.php?id=abcdefg
(abcdefg is the name you posted before)

in your browser. If you can see image, then it works. If not, check error.log of your webserver.

You should also check if "URL file-access" is enabled in the server configuration: in php.ini check

Code: Select all

allow_url_fopen = on  
This is mandatory

Regards
blast
goodfella1978
Forum Members
Forum Members
Posts: 13
Joined: Wed Sep 10, 2008 6:12 am

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by goodfella1978 »

Thanks Blast

Yes I had the latest versions of imager.php and function.dynresize.php, and they were in the correct locations, but when I try to view the image by entering the URL I get the following error:

Warning: imagesx(): supplied argument is not a valid Image resource in .../public_html/imager.php on line 58

Warning: Division by zero in .../public_html/imager.php on line 69

Warning: imagesy(): supplied argument is not a valid Image resource in .../public_html/imager.php on line 61

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in .../public_html/imager.php on line 79

Warning: imagesx(): supplied argument is not a valid Image resource in .../public_html/imager.php on line 58

Warning: imagesy(): supplied argument is not a valid Image resource in .../public_html/imager.php on line 61

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in .../public_html/imager.php on line 80

Warning: imagejpeg(): supplied argument is not a valid Image resource in .../public_html/imager.php on line 50


I have used phpinfo() to check my php configuration and allow_url_fopen is enabled.

I have checked most of the line numbers where it is finding problems in imager.php but it's all a bit beyond me (I'm more used to XHTML and CSS, my PHP knowledge is a little limited!)

Thanks for getting back to me so quicky!
Last edited by goodfella1978 on Tue Jun 16, 2009 8:15 am, edited 1 time in total.
User avatar
blast2007
Power Poster
Power Poster
Posts: 508
Joined: Wed Aug 01, 2007 5:36 pm

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by blast2007 »

These errors are shown because "URL file-access" is turned off.

If you have a shared hosting maybe you can try adding php5.ini in root path or your site with

Code: Select all

allow_url_fopen = on  
Ask your provider how to override php parameters.
goodfella1978
Forum Members
Forum Members
Posts: 13
Joined: Wed Sep 10, 2008 6:12 am

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by goodfella1978 »

Thanks again Blast (you're so quick!)

I tried adding php5.ini to the root path but no joy I'm afraid. Same errors appear.

My PHP config says allow_url_fopen is enabled (see here: http://www.davidcleworth.com/phpinfo.php). Could there be something else causing the problem? Thank you for your help so far.
User avatar
blast2007
Power Poster
Power Poster
Posts: 508
Joined: Wed Aug 01, 2007 5:36 pm

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by blast2007 »

Some stupid questions...

Did you add an image to news post via news field?

Did you check /uploads/news/idxxx/ directory read permission? Try opening your browser with

Code: Select all

http://www.yoursite.com/uploads/news/idxxx/yourfilename.jpg
You should see your image.
goodfella1978
Forum Members
Forum Members
Posts: 13
Joined: Wed Sep 10, 2008 6:12 am

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by goodfella1978 »

Cheers Blast

Yep, I uploaded the image when I added the news item (fair enough, you had to ask just to be sure!). Permissions are 755. Is that ok?

The image shows up fine when linking directly: http://www.davidcleworth.com/uploads/ne ... %20001.jpg

Sorry, are you tearing your hair out yet?

usually I can play with the code until I finally get something working, even with my limited php knowledge, but this is really baffling me now. I got the Dynresize files from here: http://dev.cmsmadesimple.org/projects/dynresize I'm guessing that's the latest version?
Last edited by goodfella1978 on Tue Jun 16, 2009 8:55 am, edited 1 time in total.
User avatar
blast2007
Power Poster
Power Poster
Posts: 508
Joined: Wed Aug 01, 2007 5:36 pm

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by blast2007 »

Try renaming your img file a flat name (e.g. myimgfile.jpg) with no strange chars (%,_, etc)
goodfella1978
Forum Members
Forum Members
Posts: 13
Joined: Wed Sep 10, 2008 6:12 am

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by goodfella1978 »

Blast, you are a GENIUS!!

Thank you, it always ends up being something so simple. So it simply doesn't like spaces in the image filename.

Works an absolute treat now! Thank you very, very much. Good work.

(genius)
nico63
Forum Members
Forum Members
Posts: 36
Joined: Wed Mar 07, 2007 1:00 am
Location: Paris

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by nico63 »

Hi,
Excuse me for my poor english first.
I tryed your trick for adding functions to a website in production, host on a share hosting. the php version is : 4.4.9 and allow_url_fopen is on. I download the two files then upload function.dynresize.php in the /plugins directory and imager.php in the root directory of my CMS made simple installation. I create a new field for the photo and the two new templates. Permissions on directory are 755.

But when i try to use it with news, no photo is displaying but there is no error message. So it doesn't work at all
I think that function.dynresize.php don't call correctly imager.php but i am not sure.

Do you ave any idea on how to resolve this problem ?

Thanks for your help.
User avatar
blast2007
Power Poster
Power Poster
Posts: 508
Joined: Wed Aug 01, 2007 5:36 pm

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by blast2007 »

nico63 wrote: Do you ave any idea on how to resolve this problem ?
Hi nico63,
did you follow all steps posted above?
a) Can you see new uploaded picture typing: http://www.yoursite.com/uploads/news/id ... lename.jpg in your browser?
b) Did you try typing http://www.yoursite.com/imager.php?id=abcdefg in your browser?
c) Filename is plain?

Post if you want your URL and template used.

Regards
blast
nico63
Forum Members
Forum Members
Posts: 36
Joined: Wed Mar 07, 2007 1:00 am
Location: Paris

Re: Publishing news with automatic features (autosummary, img autoresize,auto "alt")

Post by nico63 »

Hi Blast2007,

Thanks a lot for your answers and your help.

first step :
a) Can you see new uploaded picture typing: http://www.yoursite.com/uploads/news/id ... lename.jpg in your browser?
  YES I can see the new uploaded picture

second step :
b) Did you try typing http://www.yoursite.com/imager.php?id=abcdefg in your browser?
I just try this with generate id=aHR0cDovL3d3dy5kbWouYXNzby5mci9zZWpvdXJzL3VwbG9hZHMvbmV3cy9pZDIvc2F1dC5qcGcmd2lkdGg9OTA

and now i have 3 errors messages :
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in .../imager.php on line 79

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in.../imager.php on line 80

Warning: imagejpeg(): supplied argument is not a valid Image resource in .../imager.php on line 50


third step :
c) Filename is plain?
YES I try for testing the function with a simple file name : saut.jpg

I use, for testing, your template, I just changing the fields name.

I use CMSMS version 1.5.3 with News Module version 2.9.3

Regard,
Nico63
Locked

Return to “Tips and Tricks”