JoomlaStats添加按单元、分类、栏目、独立ip统计等

注意现在是简要的基于joomlaStats组件的再次开发,功能还需加强
新建统计数据库
CREATE TABLE `yggj`.`mycode_jstats_all` (
`ip` VARCHAR( 50 ) NOT NULL ,
`userid` INT( 11 ) NOT NULL ,
`useragent` VARCHAR( 255 ) NOT NULL ,
`Refere` VARCHAR( 255 ) NOT NULL ,
`requestpage` VARCHAR( 255 ) NOT NULL ,
`time` DATE NOT NULL ,
`itemid` INT( 11 ) NOT NULL ,
`option` VARCHAR( 50 ) NOT NULL ,
`view` VARCHAR( 50 ) NOT NULL ,
`contentid` INT( 11 ) NOT NULL
) ENGINE = MYISAM


前台统计代码在/components/com_joomlastats/jommlastats.inc.php中:
function getStatsAll(){
			global $mainframe,$database;
			$userid = $this->UserId;
			$useragent = $this->UserAgent ;
			$requestpage = $this->RequestedPage;
			$ip = $this->IpAddress;
			$time = $mainframe->requestTime;
			$time = date("Y-m-d H:i:s",strtotime($mainframe->requestTime));
			$itemid = JRequest::getCmd( 'Itemid' );
			$contentid = JRequest::getCmd( 'id' );
			$option = JRequest::getCmd( 'option' );
			$refere = $this->refere;
			$view = JRequest::getCmd( 'view' );
			
			$sql =  "INSERT INTO #__jstats_all (ip,requestpage,userid,useragent,`time`,itemid,contentid,`option`,refere,view) " .
									"VALUES ('$ip','$requestpage','$userid','$useragent','$time','$itemid','$contentid','$option','$refere','$view')";
      									
			$database->setQuery($sql);
			$database->query();
		}

将每次点击取得的数据存入#__jstats_all表。

后台
找到后台语言文件ch.ini.php在[menu]下添加
r15=按单元统计
r16=按分类统计
r17=按栏目统计
r18=独立ip统计
。。。
就可以由admin.joomlasats.html.php中的DisplayTitle()函数打印出相应菜单


/administrator/components/com_joomlastats/admin.joomlastats.php中添加:
case "r15":
			$JoomlaStatsEngine->JoomlaStatsHeader();
			echo $JoomlaStatsEngine->getSecStats();//单元统计
			$JoomlaStatsEngine->JoomlaStatsfooter();
			break;
		case "r16":
			$JoomlaStatsEngine->JoomlaStatsHeader();
			echo $JoomlaStatsEngine->getCatStats();//分类统计
			$JoomlaStatsEngine->JoomlaStatsfooter();
			break;
		case "r17":
			$JoomlaStatsEngine->JoomlaStatsHeader();
			echo $JoomlaStatsEngine->getItemStats();//栏目统计
			$JoomlaStatsEngine->JoomlaStatsfooter();
			break;
		case "r18":
			$JoomlaStatsEngine->JoomlaStatsHeader();
			echo $JoomlaStatsEngine->geIpStats();//独立ip统计
			$JoomlaStatsEngine->JoomlaStatsfooter();
			break;

这样点击相应菜单就可以转向对应的处理函数,下面实现这些方法;
/administrator/components/com_joomlastats/admin.joomlastats.html.ph中实现
getSecStats();getCatStats();getItemStats();geIpStats();
function getSecStats(){
			global $database;
			$sql = "select count(*) as count,contentid from #__jstats_all where `option`='com_content' and `view` = 'section' group by contentid ";
			$database->setQuery($sql);
			$rows = $database->loadObjectList();
			if($rows){?>
				<table class="adminform" width="100%" border="0" cellspacing="5" cellpadding="0">
					<? foreach($rows as $key=> $row){
					$sql1 = "select title  from #__sections where id=$row->contentid";
					$database->setQuery($sql1);
					$rs = $database->loadObjectList();
					?>
						<tr>
							<td>
							 <? echo $row->contentid;?>
							</td>
							<td>
							 <? echo $rs[0]->title;?>
							</td>
							<td>
							 <? echo $row->count;?>
							</td>
						</tr>
						<?}?>
				</table>
			<?}
		}

		function getCatStats(){
			global $database;
			$sql = "select count(*) as count,contentid from #__jstats_all where `option`='com_content' and `view` = 'category' group by contentid ";
			$database->setQuery($sql);
			$rows = $database->loadObjectList();
			if($rows){?>
				<table class="adminform" width="100%" border="0" cellspacing="5" cellpadding="0">
					<? foreach($rows as $key=> $row){
					$sql1 = "select title  from #__categories where id=$row->contentid";
					$database->setQuery($sql1);
					$rs = $database->loadObjectList();
					?>
						<tr>
							<td>
							 <? echo $row->contentid;?>
							</td>
							<td>
							 <? echo $rs[0]->title;?>
							</td>
							<td>
							 <? echo $row->count;?>
							</td>
						</tr>
						<?}?>
				</table>
			<?}
		}
		
		function getItemStats(){
			global $database;
			$sql = "select count(*) as count,itemid from #__jstats_all group by itemid order by count desc";
			$database->setQuery($sql);
			$rows = $database->loadObjectList();
			if($rows){?>
				<table class="adminform" width="100%" border="0" cellspacing="5" cellpadding="0">
					<? foreach($rows as $key=> $row){
					$sql1 = "select params  from #__menu where id=$row->itemid";
					$database->setQuery($sql1);
					$rs = $database->loadObjectList();
					$result = new JParameter( $rs[0]->params );
					$pagetitle = $result->get('page_title');
					?>
						<tr>
							<td>
							 <? echo $row->itemid;?>
							</td>
							<td>
							 <? echo $pagetitle;?>
							</td>
							<td>
							 <? echo $row->count;?>
							</td>
						</tr>
						<?}?>
				</table>
			<?}
		}
		
		function getIpStats(){
			global $database;
			$sql = "select count(*) as count,ip from #__jstats_all group by ip order by count desc";
			$database->setQuery($sql);
			$rows = $database->loadObjectList();
			if($rows){?>
				<table class="adminform" width="100%" border="0" cellspacing="5" cellpadding="0">
					<? foreach($rows as $key=> $row){
					?>
						<tr>
							<td>
							 <? echo $row->ip;?>
							</td>
							<td>
							 <? echo $row->count;?>
							</td>
						</tr>
						<?}?>
				</table>
			<?}
		}

效果图:


你可能感兴趣的:(html,sql,PHP,D语言)