tag {LISTPAGES}

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
vio
Posts: 16
Joined: Mon 10. May 2004, 19:55
Location: Hanoi, Vietnam

tag {LISTPAGES}

Post by vio »

Pager ur articles.
Add tag {LISTPAGES} after/before {CONTENT} whenever u want to show pages list
demo : http://nro.vietnamair.com.vn/index.php?_tinchuyennganh

add this line to conf.template_default.inc.php and customize the value 20
// Number record per page
$template_default["record_per_page"] = 20;
#
#-----[ CREATE ]---------------------------------------
#

/phpwcms_template/frontend_render/list_page.php

#
#-----[ ADD ]-------------------------------------------
#
// Function pager: Print pages list contain articles

Code: Select all

function pager( $pg, $pglen, $cnt, $q ) {
/*
Input :
    $pg: Current page
    $pglen: Number of items on a page
    $cnt: Total number of items
    $q: Query string (optional)

Output:
    List pages
*/

    $pages = ceil($cnt/$pglen);
    if ( $pages == 1 ) return;
    $lst_pgs = "<p align='center'>";
    if ( $pg > 1 ) $lst_pgs .=  "<a style='text-decoration: none' href='index.php?".$q."&pg=".($pg-1)."'><<</a> ";
           // echo
    for ( $i = 1; $i <= $pages; $i++ ) {
            if ( $i == $pg ) $lst_pgs .=  "<b>$i</b> ";
            else   $lst_pgs .=  "<a <a style='text-decoration: none' href='index.php?".$q."&pg=$i'>$i</a> ";
    }
    if ( $pg < $pages) {
    	if ($pg == 1) {$nxtpg =2;} else {$nxtpg = $pg+1;}
        $lst_pgs .=   "<a style='text-decoration: none' href='index.php?".$q."&pg=".$nxtpg."'>>></a></p> ";
    }    
    return $lst_pgs;
}
if (!$_GET["id"]) {$content["all"] = str_replace('{LISTPAGES}', $lstpg, $content["all"]);}
else {$content["all"] = str_replace('{LISTPAGES}', "", $content["all"]);}
#
#-----[ OPEN ]---------------------------------------
#

include/inc_front/front.func.inc

//rewrite the function get_actcat_articles_data

Code: Select all

function get_actcat_articles_data ($act_cat_id, $dbcon) {
	//returns the complete active and public article data as array (basic infos only)
	//so it is reusable by many functions -> lower db access
	
	$data = array();
	$ao = get_order_sort($GLOBALS['content']['struct'][ $act_cat_id ]['acat_order']);

	$sql  = "SELECT *, UNIX_TIMESTAMP(article_tstamp) AS article_date FROM ".DB_PREPEND."phpwcms_article ";
	$sql .= "WHERE article_cid=".intval($act_cat_id);
	// VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
	switch(VISIBLE_MODE) {
		case 0: $sql .= " AND article_public=1 AND article_aktiv=1";
				break;
		case 1: $sql .= " AND article_uid=".$_SESSION["wcs_user_id"];
				break;
		//case 2: admin mode no additional neccessary
	}
	$sql .= " AND article_deleted=0 AND article_begin < NOW() AND article_end > NOW() ";
	$sql .= "ORDER BY ".$ao[2];
	//start hack by Viet Son//
    $result_ts = mysql_query($sql, $dbcon);
    $num_recs = mysql_num_rows($result_ts);
    mysql_free_result($result_ts);
    $pglen = $GLOBALS["template_default"]["record_per_page"];
    if ($num_recs > $rec_page){
	$pg = $_GET["pg"];
	if(!$pg || $pg == 1){$start = 0;$pg = 1;}
	else{$offset = $pg-1; $start = ($offset * $pglen); }
	
	$sql1 = "SELECT acat_alias FROM ".DB_PREPEND."phpwcms_articlecat WHERE acat_id=".$act_cat_id.";";
    if($result1 = mysql_query($sql1, $dbcon)) 
	{
	if($row = mysql_fetch_row($result1)) {$qrystr = $row[0];}
	}//mysql_free_result($result1);	
    	$lstpg = pager($pg,$pglen,$num_recs,$qrystr);
    	$GLOBALS["lstpg"]= $lstpg;
    	$sql .= " LIMIT $start,$pglen";
    } else {$sql .=";";}
	//END page list hack/////	
	
	if($result = mysql_query($sql, $dbcon)) {
		while($row = mysql_fetch_assoc($result)) {
			$data[$row["article_id"]] = array(
									"article_id"		=> $row["article_id"],
									"article_cid"		=> $row["article_cid"],
									"article_title"		=> $row["article_title"],
									"article_subtitle"	=> $row["article_subtitle"],
									"article_keyword"	=> $row["article_keyword"],
									"article_summary"	=> $row["article_summary"],
									"article_redirect"	=> $row["article_redirect"],
									"article_date"		=> $row["article_date"],
									"article_username"	=> $row["article_username"],
									"article_sort"		=> $row["article_sort"],
									"article_notitle"	=> $row["article_notitle"],
									"article_created"	=> $row["article_created"],
									"article_image"		=> unserialize($row["article_image"]),
									"article_timeout"	=> $row["article_cache"],
									"article_nosearch"	=> $row["article_nosearch"]
											);
		}
		mysql_free_result($result);
	}
	return $data;
}

#
# OPEN include/inc_front/content.func.inc
#
#
# ADD after <?php this line
#

Code: Select all

$lstpg 							= "";
Last edited by vio on Tue 22. Mar 2005, 10:59, edited 8 times in total.
Gnolen
Posts: 158
Joined: Thu 11. Mar 2004, 11:34

Post by Gnolen »

Looks intresting...What what does it do exectly? Shows page line...?

/ Gnolen
User avatar
isac
Posts: 410
Joined: Tue 18. Nov 2003, 13:13
Location: Portugal
Contact:

Post by isac »

Hi vio

What exactly does?

I go to website and can't figure it out
User avatar
isac
Posts: 410
Joined: Tue 18. Nov 2003, 13:13
Location: Portugal
Contact:

Post by isac »

ndtoan13
Posts: 29
Joined: Wed 16. Mar 2005, 05:11
Contact:

Post by ndtoan13 »

I dont see where is the function get_order_sort and dont know how to call function pager!!
Can you tell me in detail?
vio
Posts: 16
Joined: Mon 10. May 2004, 19:55
Location: Hanoi, Vietnam

Post by vio »

ndtoan13 wrote:I dont see where is the function get_order_sort and dont know how to call function pager!!
Can you tell me in detail?
function get_order_sort in the file include/inc_lib/general.inc.php
i call the function pager in the function get_actcat_articles_data in the file include/inc_front/front.func.inc
U need read more phpWCMS
ndtoan13
Posts: 29
Joined: Wed 16. Mar 2005, 05:11
Contact:

Post by ndtoan13 »

vio wrote:function get_order_sort in the file include/inc_lib/general.inc.php
i call the function pager in the function get_actcat_articles_data in the file include/inc_front/front.func.inc
U need read more phpWCMS
Thank you vio,

I am newbie in phpwcms (I just have a look at this since last week). I have done as you guide but it displays tag {LISTPAGES} when I put it like this {Content} {LISTPAGES} (I mean it display a text {LISTPAGES} in my main content). Can you tell me why?
vio
Posts: 16
Joined: Mon 10. May 2004, 19:55
Location: Hanoi, Vietnam

Post by vio »

Maybe u r working with a old version.Try it
#
#-----[ OPEN ]---------------------------------------
#
//conf.inc.php
#
#-----[ ADD ]-------------------------------------------
#

Code: Select all

$phpwcms["allow_ext_init"]    = 1;  //allow including of custom external scripts at frontend initialization
$phpwcms["allow_ext_render"]  = 1;  //allow including of custom external scripts at frontend rendering
#
#-----[ OPEN ]---------------------------------------
#
//include/inc_front/content.func.inc.php
#
#-----[ ADD ]-------------------------------------------
#

Code: Select all

// -------------------------------------------------------------

// try to include custom functions and replacement tags or what you want to do at this point of the script
// default dir: "phpwcms_template/inc_script/frontend_render"; only *.php files are allowed there
if($phpwcms["allow_ext_render"]) {
	if(count($custom_includes = get_tmpl_files(PHPWCMS_TEMPLATE.'inc_script/frontend_render', 'php'))) {
		foreach($custom_includes as $value) {
			include_once(PHPWCMS_TEMPLATE.'inc_script/frontend_render/'.$value);
		}
	}
}

// -----------------------------------------------------------
--
User avatar
nekket
Posts: 613
Joined: Tue 18. Nov 2003, 15:46
Location: Baden-Baden
Contact:

Post by nekket »

Great MOD, fits perfectly in my current project! Thank you!
ndtoan13
Posts: 29
Joined: Wed 16. Mar 2005, 05:11
Contact:

Post by ndtoan13 »

Hi there, I now understand step by step phpwcms (thanks Vio) but I try everything as you said : create a folder name frontend_render in folder name phpwcms_template, then create file list_page.php in that folder. Put
#-----[ OPEN ]---------------------------------------
#
//conf.inc.php
#
#-----[ ADD ]-------------------------------------------
#

Code: Select all

$phpwcms["allow_ext_init"]    = 1;  //allow including of custom external scripts at frontend initialization 
$phpwcms["allow_ext_render"]  = 1;  //allow including of custom external scripts at frontend rendering 
 

# 
#-----[ OPEN ]--------------------------------------- 
# 
//include/inc_front/content.func.inc.php 
# 
#-----[ ADD ]------------------------------------------- 
# 

Code: Select all

 
// ------------------------------------------------------------- 

// try to include custom functions and replacement tags or what you want to do at this point of the script 
// default dir: "phpwcms_template/inc_script/frontend_render"; only *.php files are allowed there 
if($phpwcms["allow_ext_render"]) { 
   if(count($custom_includes = get_tmpl_files(PHPWCMS_TEMPLATE.'inc_script/frontend_render', 'php'))) { 
      foreach($custom_includes as $value) { 
         include_once(PHPWCMS_TEMPLATE.'inc_script/frontend_render/'.$value); 
      } 
   } 
} 

// ----------------------------------------------------------- 
--
And do the same as you have said above in content.func.inc and front.func.inc in folder include/inc_front,..

And the result I get is a blank page??? I guest the code have an error at somewhere!!!

PLease help me!! I have install phpwcms Release 1.1-RC4 22-05-2004
User avatar
pico
Posts: 2595
Joined: Wed 28. Jul 2004, 18:04
Location: Frankfurt/M Germany
Contact:

Post by pico »

Hi

think you must update to the latest 1.1RC4 from 28-08-2004 cause the frontend-Rendering isn't in older Version.

See Change-Log:
- introducing some kind of "modules" - external scripts for frontend
init and frontend rendering. init is used before content will be
rendered (use functions, definitions here) and use replacement tags
in frontend rendering section. use of this new function is set by 2 values
in conf.inc.php. place your scripts in "phpwcms_template/inc_script/
frontend_init" or "phpwcms_template/inc_script/frontend_render"
Lieber Gott gib mir Geduld - ABER BEEIL DICH
Horst - find me at Musiker-Board
ndtoan13
Posts: 29
Joined: Wed 16. Mar 2005, 05:11
Contact:

Post by ndtoan13 »

pico wrote:Hi

think you must update to the latest 1.1RC4 from 28-08-2004 cause the frontend-Rendering isn't in older Version.
I have downloaded the new version of phpwcms but the database is a little difference so all article can not import to new version!!!

Any idea?
User avatar
pico
Posts: 2595
Joined: Wed 28. Jul 2004, 18:04
Location: Frankfurt/M Germany
Contact:

Post by pico »

Hi

have you done also the SQL-Table update(s)?

Go to your Setup-Folder and call upgrade.php

see also here

http://www.phpwcms-docu.de/index.php?update_en
Lieber Gott gib mir Geduld - ABER BEEIL DICH
Horst - find me at Musiker-Board
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

Hi Vio

could you please look at the forum which has a list of all the hacks / repatgs listed and post your new reptage under the following:
--...--/index.php/board,1.0.html

we will then include this in the list.

If you have any problems, please let us know

TriP
vio
Posts: 16
Joined: Mon 10. May 2004, 19:55
Location: Hanoi, Vietnam

Post by vio »

okie, ndtoan13 , u can do this

add this line to conf.template_default.inc.php and customize the value 20

Code: Select all

// Number record per page
$template_default["record_per_page"] = 20;

#
#-----[ OPEN ]---------------------------------------
#

include/inc_front/front.func.inc
#
#-----[ ADD ]-------------------------------------------
#

Code: Select all

function pager( $pg, $pglen, $cnt, $q ) {
/*
Input :
    $pg: Current page
    $pglen: Number of items on a page
    $cnt: Total number of items
    $q: Query string (optional)

Output:
    List pages
*/

    $pages = ceil($cnt/$pglen);
    if ( $pages == 1 ) return;
    $lst_pgs = "<p align='center'>";
    if ( $pg > 1 ) $lst_pgs .=  "<a style='text-decoration: none' href='index.php?".$q."&pg=".($pg-1)."'><<</a> ";
           // echo
    for ( $i = 1; $i <= $pages; $i++ ) {
            if ( $i == $pg ) $lst_pgs .=  "<b>$i</b> ";
            else   $lst_pgs .=  "<a <a style='text-decoration: none' href='index.php?".$q."&pg=$i'>$i</a> ";
    }
    if ( $pg < $pages) {
       if ($pg == 1) {$nxtpg =2;} else {$nxtpg = $pg+1;}
        $lst_pgs .=   "<a style='text-decoration: none' href='index.php?".$q."&pg=".$nxtpg."'>>></a></p> ";
    }   
    return $lst_pgs;
} 
//rewrite the function get_actcat_articles_data

Code: Select all

function get_actcat_articles_data ($act_cat_id, $dbcon) {
   //returns the complete active and public article data as array (basic infos only)
   //so it is reusable by many functions -> lower db access
   
   $data = array();
   $ao = get_order_sort($GLOBALS['content']['struct'][ $act_cat_id ]['acat_order']);

   $sql  = "SELECT *, UNIX_TIMESTAMP(article_tstamp) AS article_date FROM ".DB_PREPEND."phpwcms_article ";
   $sql .= "WHERE article_cid=".intval($act_cat_id);
   // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
   switch(VISIBLE_MODE) {
      case 0: $sql .= " AND article_public=1 AND article_aktiv=1";
            break;
      case 1: $sql .= " AND article_uid=".$_SESSION["wcs_user_id"];
            break;
      //case 2: admin mode no additional neccessary
   }
   $sql .= " AND article_deleted=0 AND article_begin < NOW() AND article_end > NOW() ";
   $sql .= "ORDER BY ".$ao[2];
   //start hack by Viet Son//
    $result_ts = mysql_query($sql, $dbcon);
    $num_recs = mysql_num_rows($result_ts);
    mysql_free_result($result_ts);
    $pglen = $GLOBALS["template_default"]["record_per_page"];
    if ($num_recs > $rec_page){
   $pg = $_GET["pg"];
   if(!$pg || $pg == 1){$start = 0;$pg = 1;}
   else{$offset = $pg-1; $start = ($offset * $pglen); }
   
   $sql1 = "SELECT acat_alias FROM ".DB_PREPEND."phpwcms_articlecat WHERE acat_id=".$act_cat_id.";";
    if($result1 = mysql_query($sql1, $dbcon))
   {
   if($row = mysql_fetch_row($result1)) {$qrystr = $row[0];}
   }//mysql_free_result($result1);   
       $lstpg = pager($pg,$pglen,$num_recs,$qrystr);
       $GLOBALS["lstpg"]= $lstpg;
       $sql .= " LIMIT $start,$pglen";
    } else {$sql .=";";}
   //END page list hack/////   
   
   if($result = mysql_query($sql, $dbcon)) {
      while($row = mysql_fetch_assoc($result)) {
         $data[$row["article_id"]] = array(
                           "article_id"      => $row["article_id"],
                           "article_cid"      => $row["article_cid"],
                           "article_title"      => $row["article_title"],
                           "article_subtitle"   => $row["article_subtitle"],
                           "article_keyword"   => $row["article_keyword"],
                           "article_summary"   => $row["article_summary"],
                           "article_redirect"   => $row["article_redirect"],
                           "article_date"      => $row["article_date"],
                           "article_username"   => $row["article_username"],
                           "article_sort"      => $row["article_sort"],
                           "article_notitle"   => $row["article_notitle"],
                           "article_created"   => $row["article_created"],
                           "article_image"      => unserialize($row["article_image"]),
                           "article_timeout"   => $row["article_cache"],
                           "article_nosearch"   => $row["article_nosearch"]
                                 );
      }
      mysql_free_result($result);
   }
   return $data;
} 
#
# OPEN include/inc_front/content.func.inc
#

#
# ADD after <?php this line
#

Code: Select all

$lstpg                      = "";
#
# ADD before ?> this
#

Code: Select all

if (!$_GET["id"]) {$content["all"] = str_replace('{LISTPAGES}', $lstpg, $content["all"]);}
else {$content["all"] = str_replace('{LISTPAGES}', "", $content["all"]);}
Post Reply