RANDOM_CP

Hier bekommst Du deutschsprachigen Support. Keine Fehlermeldungen oder Erweiterungswünsche bitte!
Post Reply
User avatar
update
Moderator
Posts: 6394
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

RANDOM_CP

Post by update » Tue 14. May 2019, 10:38

Hat den jemand schon mal auf die neueste Version gefummelt? Ich kriege es einfach nicht hin... :(
It's mostly all about webdesign, logo design, new and old pages refresh, print BUT slowly switching to be supporter for the band Mykket Morton. Visit Mykket Morton on FB. Listen Mykket Morton and live videos on youtube.

kmstario
Posts: 381
Joined: Thu 27. Jul 2006, 11:34
Location: Berlin
Contact:

Re: RANDOM_CP

Post by kmstario » Tue 14. May 2019, 11:04

Moin moin,

also wir haben es wieder zum laufen gebracht aber es wirft im Error Log noch einen Fehler aus. Funktioniert aber:

Code: Select all

<?php
//----------------------------------------------------------------------------------------------
// {SHOW_CONTENT}
// 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).
// AUTHOR:          Jens Zetterström
// ADAPTED BY:      pSouper
// 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.
// RCS:             set article to invisible, but CPs to visible
//----------------------------------------------------------------------------------------------
// ------------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
   die("You Cannot Access This Script Directly, Have a Nice Day."); }
// ------------------------------------------------------------------ // RCS inserted 03.11.08
 
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() " .

            "ORDER BY RAND()";
 
   if($cresult = $db->query($sql) )
   {
      if($crow = $cresult->fetch_array())
      {
         // 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_callback('/\{RANDOMCP:(.*?)\}/i', 
   function($m){
	   return random_cp($m[1], $GLOBALS['db'] );
   }, 
   $content["all"]);
}
?>
Viele Grüße, Andreas
--------------------------------------------

Alles Gelingen hat sein Geheimnis, alles Mißlingen seine Gründe.
PHPWCMS ist einfach nur großartig!

User avatar
update
Moderator
Posts: 6394
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Re: RANDOM_CP

Post by update » Tue 14. May 2019, 11:28

Danke, ich probiere es mal :)
It's mostly all about webdesign, logo design, new and old pages refresh, print BUT slowly switching to be supporter for the band Mykket Morton. Visit Mykket Morton on FB. Listen Mykket Morton and live videos on youtube.

Post Reply