Gallery:如何在页面底部嵌入计数器的代码

来自站长百科
跳转至: 导航、​ 搜索

Netstat/OneStat[ ]

你可能想添加 [Nedstat]/[Onestat]等类型的代码至页面底部以统计相册访问量。这里给出指导:

  • 将themes/<theme>/templates/theme.tpl复制到themes/<theme>/templates/local/theme.tpl
  • 在文件的本地版本中找到含有{g->trailer}的语句行
  • 就在该行之前添加如下的代码:
{g->addToTrailer}
{php}
$countercode = <<<END

<the code provided to you by the counter site guys>

END;
echo $countercode;
{/php}
{/g->addToTrailer}   
  • 保存文件即可

BBClone[ ]

---针对G2.1进行了更新 – 查看G2.0版本的历史---

在你的gallery2之下安装bbclone。

创建一个名为gallery2.php的文件并将其置入gallery2的根目录下。在gallery2.php文件中置入如下文本。

<?php
require_once(dirname(__FILE__) . "/main.php");

if (!defined('GALLERY_CONFIG_DIR')){
	define('GALLERY_CONFIG_DIR', dirname(__FILE__));
}

if (!defined("_BBCLONE_DIR")){
	define("_BBCLONE_DIR", GALLERY_CONFIG_DIR . "/bbclone/");
}

$Title = "";
$Title = pathway($_GET['g2_itemId']);
if (strlen($Title) > 0){
	define("_BBC_PAGE_NAME", $Title);
	define("COUNTER", _BBCLONE_DIR."mark_page.php");
	if (is_readable(COUNTER)) require (COUNTER);
}

function pathway($g2_itemId){
	//first get parent albums
	if (empty($g2_itemId)){
		//return "Gallery Root";
		$g2_itemId = 7;
	}
	if (!class_exists('GalleryCoreApi')){
		return "";
	}
	list ($ret, $parents) = GalleryCoreApi::fetchParentSequence($g2_itemId);
	if ($ret) { $parents = array(); }
	$parents[count($parents)+1]=$g2_itemId;
 	$g2_s=0;
	//gogogo
	$path = "";
	$extend = "";
	$seperator = " -> ";
	foreach($parents as $items){
		list ($ret,	$item) = GalleryCoreApi::loadEntitiesById($items);
		if (GalleryUtilities::isA($item, 'GalleryItem')){
			$title = "";		
			if (!$ret && $item){
				if ($item->getTitle()){
					$title = $item->getTitle();
				}else{
					$title = $item->getPathComponent();
				}
			}
			$titles[$item->getId()] = preg_replace('/\r\n/', ' ', $title);
	 
			//let's switch again
			if($g2_s == 0 AND count($parents) ==1){ //first and last		
				$path .= $extend.$title;
				$extend = $seperator;
			} elseif($g2_s == 0 AND count($parents) !=1) {// first but not last
				$path .= $extend.$title;
				$extend = $seperator;
			} elseif($g2_s == count($parents)-1 AND $g2_s == 1){// second and last	
				$path .=$extend.$title;
				$extend = $seperator;
			} elseif($g2_s == count($parents)-1){ // not second but it is last
				$path .=$extend.$title;
				$extend = $seperator;
			} elseif($g2_s == 1) {// everything in between			
				$path .=$extend.$title;
				$extend = $seperator;
			} else {
				$path .=$extend.$title;
				$extend = $seperator;
			}
		}
		$g2_s++;
	}
	if (!empty($_GET['g2_view']))
		if ($_GET['g2_view'] == "imageframe.CSS" ||
			$_GET['g2_view'] == "core.DownloadItem" ||
			$_GET['g2_view'] == "rewrite.FileNotFound")
			return "";
		else
 		    if ($_GET['g2_view'] != "core.ShowItem")
			$path .= " * " . $_GET['g2_view'];
	if (!empty($_GET['g2_subView']))
		$path .= " ~ " . $_GET['g2_subView'];
	return $path;		
}//end pathway function
?>

接着在你的config.php中包括进如下语句

define('GALLERY_MAIN_PHP', 'gallery2.php');

这将保证无论使用哪个外观主题都可以记录下点击次数。如果你不想使用bbclone的话,你可以使用其他点击计数器代码替换bbclone代码。

phpTrafficA[ ]

遵照 BBClone相关的指导即可。

安装phpTrafficA并遵照其所有的安装指导。

修改phpTrafficA 的write_logs.php文件。

if ($sites[$sid]['trim']) {
    $To = $_SERVER["PHP_SELF"];
} else {
    $To = $_SERVER["REQUEST_URI"];
}

修改为


if ($PageName != null &&
    strlen($PageName) > 0)
{
    $To = $PageName;
}else{
    if ($sites[$sid]['trim']) {
        $To = $_SERVER["PHP_SELF"];
    } else {
        $To = $_SERVER["REQUEST_URI"];
    }
}

并在gallery2.php中,替换

$Title = "";
$Title = pathway($_GET['g2_itemId']);
if (strlen($Title) > 0){
    define("_BBC_PAGE_NAME", $Title);
    define("COUNTER", _BBCLONE_DIR."mark_page.php");
    if (is_readable(COUNTER)) require (COUNTER);
}

输入

$PageName = "";
$PageName = pathway($_GET['g2_itemId']);
if (strlen($PageName) > 0){
   $sid="12345";
   require("/phpTrafficA/write_logs.php"); 
}

确保在代码的最后部分置入你phpTrafficA 站点的正确sid,并保证write_logs.php的路径无误。