{SHOW_CONTENT} Show content of a particular content part

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Random Content part from a given Article ID

Post by pSouper »

hi all, I realise that SHOW_CONTENT is now built in and I use it/ recommend it thoroughly :)

what I have spent a few mins adapting it to do a small job i need... show a random content part from a given article - think of it as a 'random quotes' script on steroids - the steroids are that it can show any content part not just plain text.

OK- a small adaptation to Jens's script means a big thanks and all credit go to him.

A working version can be seen http://www.teensunitefightingcancer.org as the 'QUOTES' box in the {RIGHT} column - this is a live site so no funny business please!

As it's a replacement tag, you know the procedure by now... save this code as a file name in template/inc_script/frontend_render/randomCP.php
then use it by adding the article ID in the tag as per the script header blurb... {RANDOMCP:xx}

Code: Select all

<?php
//----------------------------------------------------------------------------------------------
// {SHOW_CONTENT}
// AUTHOR:          Jens Zetterström
// ADAPTED BY:		pSouper
// DESCRIPTION:    Shows a random content part from within a given article (you supply the article ID - it show a random content part from within that article).
// INSTALLATION:    Put the code in frontend_render (for example in a file called random_cp.php)
//                  Note: If the article content part contains replacement tags (for example {SITE}),
//                  they will not be replaced because code in frontend_render is executed after those
//                  replacement tags already have been processed. To fix, put the code in
//                  content.article.inc.php instead.
// USAGE:          {RANDOMCP:article_id}
//                  where article_id is the id of the ARTICLE.
//----------------------------------------------------------------------------------------------
function random_cp($aid, $db)
{
   $CNT_TMP = '';
   $template_default = $GLOBALS["template_default"];
   
   $sql =   "SELECT * " . 
            "FROM " . DB_PREPEND . "phpwcms_articlecontent " .
			"INNER JOIN " . DB_PREPEND . "phpwcms_article ON " . DB_PREPEND . "phpwcms_article.article_id = " . DB_PREPEND . "phpwcms_articlecontent.acontent_aid " .
            "WHERE acontent_aid = " . $aid . " " .
            "AND acontent_visible = 1 " .
            "AND acontent_trash = 0 " .
            "AND " . DB_PREPEND . "phpwcms_article.article_deleted=0 AND ".DB_PREPEND."phpwcms_article.article_begin < NOW() " .
             // the line below is deleted as it introduces a bug that stops it showing random CP's - not sure why, help?
            //"AND " . DB_PREPEND . "phpwcms_article.article_end > NOW() ";
            "ORDER BY RAND()";
             
   if($cresult = mysql_query($sql, $db) or die("error retrieving article from database"))
   {
      if($crow = mysql_fetch_array($cresult))
      {
	  	//echo "<pre>";print_r($crow);echo"</pre>";
         // Space before
         if($crow["acontent_before"])
         {
            $CNT_TMP .= '<div style="margin:' . $crow["acontent_before"] . 'px 0 0 0; padding:0 0 0 0; clear:both;"></div>';
         }
         
         // include content part code section
         include("include/inc_front/content/cnt" . $crow["acontent_type"] . ".article.inc.php");

         //check if top link should be shown
         if($crow["acontent_top"])
         {
            if($template_default["article"]["top_sign_before"].$template_default["article"]["top_sign_after"])
            {
               $CNT_TMP .= $template_default["article"]["top_sign_before"];
               $CNT_TMP .= '<a href="#top">'.$template_default["article"]["top_sign"].'</a>';
               $CNT_TMP .= $template_default["article"]["top_sign_after"];
            }
            else
            {
               $CNT_TMP .= '<br /><a href="#top">' . $template_default["article"]["top_sign"] . '</a>';
            }
         }

         // Space after
         if($crow["acontent_after"])
         {
            $CNT_TMP .= '<div style="margin:0 0 ' . $crow["acontent_before"] . 'px 0; padding:0 0 0 0; clear:both;"></div>';
         }
      }
   }
   return $CNT_TMP;
}

if( ! ( strpos($content["all"],'{RANDOMCP:')===false ) )
{
   $content["all"] = preg_replace('/\{RANDOMCP:(.*?)\}/ie', 'random_cp("$1", $db);', $content["all"]);
	$content["all"] = (psTagParser ($content["all"]));
}


?>
hope it helps, pSouper

__________

A 'minor bug-ette' is that I had to comment out the line that checks if the article end date has past but I can't figure out why it does not work - basically, with the line in it only show the same CP over & over again. any help with this would be very nice too :)
stemmen
Posts: 67
Joined: Wed 4. May 2005, 22:13
Contact:

SHOW CONTENT manual

Post by stemmen »

HI all

Has anyone made a manual.

I have no idea have to use {SHOW_CONTENT: id, id, id}.

If I put it inside my template, is it to replace {CONTENT} and {LEFT} etc.?

Is it supposed to be used alongside {CONTENT} and {LEFT} etc.?

What are the actual functions?

Obviously, I am not a php-expert, so any help will be highly appreciated.

Reg.Jan
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post by pSouper »

SHOW_CONTENT is now redundant for the lastest few releases and can now be used via the content part 'contentpart alias'

if you still insist on using the {RT} too then you simply add the replacement tag {SHOW_CONTENT:cp,contentpartID,contentpartID,contentpartID} to antywhere in your content text - for example, in your article summary or plain text/wywiwyg content parts etc.

each (comma seperated) contentpartID will add a teaser of that content part to the list (best to try it to see it)

the cp part of the tag can also be cpa - this simple shows the contentparts in acceding order.

the contentpartId's are fount in the backend > article menu by the side of each contentpart and look like this... [ID:16]plain text (it's the number only ok ;) )

it does NOT replace {CONTENT} or {RIGHT} etc. it can be used within a template and may be included within {CONTENT} or {RIGHT} etc. To do this you add the {SHOW_CONTENT:cp,xxx} to the bottom blocks of the template that corespond to the area you wish this to appear such as within the {RIGHT} block... this will adda div above the content of the {RIGHT} block that contains the contentpart [ID:116]....

Code: Select all

{<div id="rightBox">{SHOW_CONTENT:CP,116}{RIGHT}</div>

give it a go and see what you get :)
User avatar
flip-flop
Moderator
Posts: 8178
Joined: Sat 21. May 2005, 21:25
Location: HAMM (Germany)
Contact:

Post by flip-flop »

And please, have a look into the docu: http://www.phpwcms-docu.de/article_tags.phtml :wink:
>> HowTo | DOCU | FAQ | TEMPLATES/DOCS << ( SITE )
sparks
Posts: 39
Joined: Mon 1. Aug 2005, 15:49

Re: {SHOW_CONTENT} Show content of a particular content part

Post by sparks »

still, a random CP would be needed. I tried the last "hack" of this RT and it does not work.
User avatar
flip-flop
Moderator
Posts: 8178
Joined: Sat 21. May 2005, 21:25
Location: HAMM (Germany)
Contact:

Re: {SHOW_CONTENT} Show content of a particular content part

Post by flip-flop »

{SHOW_CONTENT:MODE,id,id,id} is pegged into durably. -> http://www.phpwcms-docu.de/article_tags.phtml
>> HowTo | DOCU | FAQ | TEMPLATES/DOCS << ( SITE )
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Re: {SHOW_CONTENT} Show content of a particular content part

Post by pSouper »

was it my random_cp hack that didn't work?
if so - please let me know the phpwcms version you are using along with any errors or signs of failure you are experiencing and I will look into an update if needed.
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Re: {SHOW_CONTENT} Show content of a particular content part

Post by update »

This is working smoothly with r273 (sorry to say that, but this is still the newest)

Code: Select all

<?php
//----------------------------------------------------------------------------------------------
// {SHOW_CONTENT}
// AUTHOR:          Jens Zetterström
// ADAPTED BY:      pSouper
// DESCRIPTION:    Shows a random content part from within a given article (you supply the article ID - it show a random content part from within that article).
// INSTALLATION:    Put the code in frontend_render (for example in a file called random_cp.php)
//                  Note: If the article content part contains replacement tags (for example {SITE}),
//                  they will not be replaced because code in frontend_render is executed after those
//                  replacement tags already have been processed. To fix, put the code in
//                  content.article.inc.php instead.
// USAGE:          {RANDOMCP:article_id}
//                  where article_id is the id of the ARTICLE.
//----------------------------------------------------------------------------------------------
// ------------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
   die("You Cannot Access This Script Directly, Have a Nice Day."); }
// ------------------------------------------------------------------

function random_cp($aid, $db)
{
   $CNT_TMP = '';
   $template_default = $GLOBALS["template_default"];
   
   $sql =   "SELECT * " .
            "FROM " . DB_PREPEND . "phpwcms_articlecontent " .
         "INNER JOIN " . DB_PREPEND . "phpwcms_article ON " . DB_PREPEND . "phpwcms_article.article_id = " . DB_PREPEND . "phpwcms_articlecontent.acontent_aid " .
            "WHERE acontent_aid = " . $aid . " " .
            "AND acontent_visible = 1 " .
            "AND acontent_trash = 0 " .
            "AND " . DB_PREPEND . "phpwcms_article.article_deleted=0 AND ".DB_PREPEND."phpwcms_article.article_begin < NOW() " .
             // the line below is deleted as it introduces a bug that stops it showing random CP's - not sure why, help?
            //"AND " . DB_PREPEND . "phpwcms_article.article_end > NOW() ";
            "ORDER BY RAND()";
             
   if($cresult = mysql_query($sql, $db) or die("error retrieving article from database"))
   {
      if($crow = mysql_fetch_array($cresult))
      {
        //echo "<pre>";print_r($crow);echo"</pre>";
         // Space before
         if($crow["acontent_before"])
         {
            $CNT_TMP .= '<div style="margin:' . $crow["acontent_before"] . 'px 0 0 0; padding:0 0 0 0; clear:both;"></div>';
         }
         
         // include content part code section
         include("include/inc_front/content/cnt" . $crow["acontent_type"] . ".article.inc.php");

         //check if top link should be shown
         if($crow["acontent_top"])
         {
            if($template_default["article"]["top_sign_before"].$template_default["article"]["top_sign_after"])
            {
               $CNT_TMP .= $template_default["article"]["top_sign_before"];
               $CNT_TMP .= '<a href="#top">'.$template_default["article"]["top_sign"].'</a>';
               $CNT_TMP .= $template_default["article"]["top_sign_after"];
            }
            else
            {
               $CNT_TMP .= '<br /><a href="#top">' . $template_default["article"]["top_sign"] . '</a>';
            }
         }

         // Space after
         if($crow["acontent_after"])
         {
            $CNT_TMP .= '<div style="margin:0 0 ' . $crow["acontent_before"] . 'px 0; padding:0 0 0 0; clear:both;"></div>';
         }
      }
   }
   return $CNT_TMP;
}

if( ! ( strpos($content["all"],'{RANDOMCP:')===false ) )
{
   $content["all"] = preg_replace('/\{RANDOMCP:(.*?)\}/ie', 'random_cp("$1", $db);', $content["all"]);
   //$content["all"] = (psTagParser ($content["all"]));
}


?>

I had to comment

Code: Select all

//$content["all"] = (psTagParser ($content["all"]));
due to some errors and have added

Code: Select all

// ------------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
   die("You Cannot Access This Script Directly, Have a Nice Day."); }
// ------------------------------------------------------------------
to meet the standard.
Really cool thing! Thanks!
It's mostly all about maintaining two or three customer's sites Still supporter for the band Mykket Morton. Visit Mykket Morton on FB. Listen Mykket Morton and live videos on youtube.
Now building a venue for young artists to get wet on stage, rehearsal rooms, a studio, a guitar shop - yes I'm going to build some guitars.
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Re: {SHOW_CONTENT} Show content of a particular content part

Post by pSouper »

hehe - sorry about the commented line - that's residue from additional stuff i do elsewhere in my scripts - thanks for pointing it out.

also - you're right, it is always good to add those lines to your added scripts - preventing direct access and potential back doors.
Post Reply