Page 1 of 3

tag {LISTPAGES}

Posted: Thu 17. Mar 2005, 13:29
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 							= "";

Posted: Thu 17. Mar 2005, 13:34
by Gnolen
Looks intresting...What what does it do exectly? Shows page line...?

/ Gnolen

Posted: Thu 17. Mar 2005, 13:56
by isac
Hi vio

What exactly does?

I go to website and can't figure it out

Posted: Thu 17. Mar 2005, 17:20
by isac

Posted: Sat 19. Mar 2005, 04:37
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?

Posted: Sat 19. Mar 2005, 19:06
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

Posted: Mon 21. Mar 2005, 02:50
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?

Posted: Mon 21. Mar 2005, 09:50
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);
		}
	}
}

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

Posted: Mon 21. Mar 2005, 12:15
by nekket
Great MOD, fits perfectly in my current project! Thank you!

Posted: Mon 21. Mar 2005, 12:29
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

Posted: Mon 21. Mar 2005, 14:52
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"

Posted: Tue 22. Mar 2005, 03:25
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?

Posted: Tue 22. Mar 2005, 08:10
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

Posted: Tue 22. Mar 2005, 08:35
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

Posted: Tue 22. Mar 2005, 10:24
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"]);}