We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1535
    • 84 Posts
    Hi.

    Thanks for the module, very handy.

    It works fine for me except the document selection. Seems the javascript is not working properly. The folder does not open when I click it and if I click on a document in the tree afterwards it just loads the doc as usual.

    I also noticed a few of the images referenced in the javscript that needed the path updated, but fixing that did not help my issue.

    Cheers,

    Andreas
      • 33962
      • 13 Posts
      Hi, thanks for the module.

      I use it with mySql V4.0, which doesn’t support the ON DUPLICATE KEY feature.

      This is my workaround:

      if($modx->documentObject['donthit'] != 1 && $_SESSION['usertype'] != 'manager') {
      
        $query = $modx->db->select("page_id", $table_prefix."page_hit_counter", "page_id = ".$modx->documentIdentifier);
        $count = $modx->db->getRecordCount($query);
      
        if ($count >0) {
            $sql = "update ".$table_prefix."page_hit_counter set page_count=page_count +1 where page_id = ".$modx->documentIdentifier;
        }else {
           $sql = "INSERT INTO ".$table_prefix."page_hit_counter (page_id, page_count) VALUES ($modx->documentIdentifier, 1)";
        }
        $modx->db->query($sql);
       
      }
      
      return;


      --Raffy
        • 7915
        • 3 Posts
        We are brand new to MODxCMS we have used Joomla in the past. I must say installing MODULES in MODx is proving to be a lot more work. Well I finally got Page Hit Counter installed. I had to figure out the SQL and run it manually in phpMyAdmin to create the table in the database. As the script didn’t do so on its own for some odd reason. For anyone else with the same problem here is the SQL so you don’t have to figure it out.

        CREATE TABLE modx_page_hit_counter (page_id int(4) unsigned NOT NULL default ’0’, page_count int(10) unsigned NOT NULL default ’0’)

        But now that it’s installed and working. I can’t for the life of me seem to find the back end page for viewing the stats. Seems it would just be a link under the modules tab. But it’s not. I even logged on to Scott’s web manager to see if I could find it on his. No luck!!! So can anyone tell me where it’s hiding? I am driving myself crazy and feeling really stupid here. I can see MODx is going to be a huge learning curve after using Joomla. I am going to really miss how easy it is to install things by just uploading a zip file.

        How Do I Get To This Page?


        And why is Page Hit Counter even an add on at all? Seems to me this is something that should come with the CMS as well as some other modules that you have to post-install install.
          Please follow the signature guidelines.
        • Which version of MySQL are you using? It may be that your version doesn’t like the "IF NOT EXISTS" keywords.
            $sql = "CREATE TABLE IF NOT EXISTS `".$table_prefix."page_hit_counter` (
            `page_id` int(4) unsigned NOT NULL default '0',
            `page_count` int(10) unsigned NOT NULL default '0',
            UNIQUE KEY `page_id` (`page_id`)
          )";
            $modx->db->query($sql);
          
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 7915
            • 3 Posts
            SYSTEM DETAILS:
            Operating system Linux
            Kernel version 2.6.9-55.0.2.ELsmp
            Machine Type i686
            Apache version 1.3.37 (Unix)
            PHP version 4.4.4
            MySQL version 4.1.22-standard

            But what about the back end page hit counter question? As I couldn’t even seem to find it on your demo site. I fixed the other issue already as I stated.

            HOW DO I GET TO THIS PAGE?
              Please follow the signature guidelines.
              • 7915
              • 3 Posts
              I was told this forum was very active and friendly but instead of responding the forum mods just keep deleting my signature. EGO 31337 All Your Base Are Belong To US! huh huh huh
                Please follow the signature guidelines.
              • Quote from: Down at Sep 21, 2007, 10:00 PM

                I was told this forum was very active and friendly but instead of responding the forum mods just keep deleting my signature. EGO 31337 All Your Base Are Belong To US! huh huh huh
                I think you’ll find this community very active and friendly.

                All the moderators are asking is that you not use your signature as an advertisement for your company. Feel free to include a link or two, but we have very clear guidelines on what you can include in your signature here.

                As for your page hit counter module question, I’ll have to defer to someone else that has used it, as I have not. I typically use Google Analytics to track my site stats.
                • I used it once, a long time ago, and released what I had in case someone else found it useful. I have no idea why you are having problems with it, it’s pretty simple and should do what it is meant to do.

                  Run the module, and the page you have a screenshot of will show. Of course, the pages have to have hits before anything shows...
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 1649
                    • 13 Posts
                    I’m using modx 0.9.6 with friendly URLs and friendly URL paths turned on.

                    The module screen didnt work for me - images didnt load and javascript was broken.

                    Rather than fixing the javascript which would be too much for me(!) I ripped it out - here is the module code that loads the images and doesn’t display any javascript errors in the above conditions but doesn’t have the nice click on document to get statistics feature.

                    Could the author update it for modx 0.9.6 with friendly URLs and paths?

                    Thanks



                    // PageHitCounter - module for MODx 0.9.x
                    // creates page_hit_counter table if necessary
                    // displays page requests
                    // Version 2 - Ajax-based single page view
                    // 08-2006 [email protected]
                    // released to the Public Domain
                    // requires the CountPageHit plugin to insert data into the table
                    
                    global $table_prefix, $manager_theme;
                    
                    if(isset($_POST['tables']) && $_POST['tables'] == 'Create Table') {
                      $sql = "CREATE TABLE IF NOT EXISTS `".$table_prefix."page_hit_counter` (
                      `page_id` int(4) unsigned NOT NULL default '0',
                      `page_count` int(10) unsigned NOT NULL default '0',
                      UNIQUE KEY `page_id` (`page_id`)
                    )";
                      $modx->db->query($sql);
                    }
                    
                    
                    $basePath = $modx->config['site_url'];
                    
                    
                    $page = '	
                    <html>
                    <head>
                    	<title>PageHitCounter</title>
                    	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                    
                    	<link rel="stylesheet" type="text/css" href="' . $basePath . 'manager/media/style/'.$manager_theme.'/style.css?" />
                    
                    	<style>
                    	#preLoader {
                    		position: 						absolute;
                    		z-index:						50000;
                    		width:							100%;
                    		height:							100%;
                    		text-align:						center;
                    		vertical-align:					middle;
                    	}
                    	.preLoaderText {
                    		background-color:				#ffffff;
                    		width:							300px;
                    		height:							150px;
                    		padding:						50px;
                    		border:							1px solid #003399;
                    	}
                    	</style>
                    
                    <style>
                    .contextMenu {
                    	background: #fff url(' . $basePath . 'manager/media/images/bg/context.gif) repeat-y top left;
                    	margin:						0;
                    	padding:					0;
                    	border: 					1px solid #003399;
                    	border-left-color:			#eaeaea;
                    	border-top-color:			#eaeaea;
                    	border-right-color:			#909090;
                    	border-bottom-color:		#707070;
                    	position:					absolute;
                    	z-index:					10000; }
                    
                    .cntxMnuItem {
                    	background-image:			url(media/images/_tx_.gif);
                    	cursor:						pointer;
                    	color:						#000;
                    	padding: 					3px 16px 3px 2px; }
                    
                    .cntxMnuItemOver {
                    	cursor:						pointer;
                    	color: 						#000;
                    	background: #fc0 url(media/images/misc/buttonbar_gs.gif) repeat-x bottom left;	
                    	padding: 					2px 15px 2px 1px;
                    	border: 					1px solid #fa0; /*#003399;*/
                    }
                    
                    .cntxMnuItemDisabled {
                    	cursor:						default;
                    	font: 						menu;
                    	padding: 					3px 16px 3px 2px;
                    	color:						#111;
                    }
                    .cntxMnuItem IMG, .cntxMnuItemOver IMG, .cntxMnuItemDisabled IMG {
                    	margin-right:				8px;
                    }
                    
                    .cntxMnuItem IMG, .cntxMnuItemDisabled IMG {
                    	filter:						gray();
                    }
                    
                    .cntxMnuSeparator {
                    	font-size:      			0;
                    	height:         			1px;
                    	background-color: 			#6A8CCB;
                    	overflow:       			hidden;
                    	margin:						3px 1px 3px 28px; }	
                    	
                    .countTable{
                    width:300px;
                    margin-bottom:20px;
                    }
                    .countTable td{
                    padding-right:20px;
                    border-bottom:1px solid #000;
                    padding-top:10px;
                    }
                    .countTable th{
                    text-align:left;
                    border-bottom:1px solid #000;
                    }
                    </style>
                    </head>
                    <body>
                    
                    <div class="subTitle">
                    	<span class="right"><img src="' . $basePath . 'manager/media/images/_tx_.gif" width="1" height="5"><br />Page Hit Counter</span>
                    </div>
                    
                    <div class="sectionHeader"><img src="' . $basePath . 'manager/media/style/'.$manager_theme.'/images/misc/dot.gif" alt="" /> Page Hit Counter</div><div class="sectionBody">
                    ';
                    			
                    $sql = "SHOW TABLES LIKE '".$table_prefix."page_hit_counter'";
                    $rs = $modx->db->query($sql);
                    $count = $modx->db->getRecordCount($rs);
                    
                    if($count < 1) { 
                      $page .= '
                    	<div class="searchbar">
                    		<table border="0" style="width:100%">
                    			<tr>
                    			<td><form id="phcCreateTableForm" action="" enctype="multipart/form-data" method="post" style="margin:0;padding:0;" >
                    <fieldset style="border:none;margin:0 0 0 20px;padding:0;">
                    <label for="tables">Table does not exist. Please create the table: <input type="submit" name="tables" value="Create Table" /></label>
                    </fieldset>
                    </form></td>
                    			<td nowrap="nowrap">
                    			</td>
                    			</tr>
                    		</table>
                    	</div>	
                    ';
                    } else {			
                    	$page .= '
                    	<div id="mainContent"><div id="placeholder"></div>';
                    	
                    	$sql = "SELECT * FROM ".$table_prefix."page_hit_counter";
                    	$rs = $modx->db->query($sql);
                    	$count = $modx->db->getRecordCount($rs);
                    	if($count < 1) {
                    		$page .= "No records found.";
                    	} else {
                    		// list page hits
                    		$sql = "SELECT phc.page_count, sc.pagetitle FROM ".$table_prefix."page_hit_counter phc, ".$table_prefix."site_content sc WHERE sc.id = phc.page_id ORDER BY phc.page_count DESC, sc.pagetitle ASC";
                    		$rs = $modx->db->query($sql);
                    		$page .= '<table class="countTable" cellpadding="0" cellspacing="0" border="0"><tr><th>Page</th><th>Count</th></tr>';
                    		while($row = $modx->db->getRow($rs)) {
                    		    $page .= '<tr><td style="width:80%">'.$row['pagetitle'].'</td><td>'.$row['page_count'].'</td></tr>';
                    		}
                    		$page .= '</table>';
                      }	
                    	$page .= '</div>
                    	</div>
                    	</body>
                    	</html>
                    	<!-- end footer -->
                    	';
                    }
                    return $page;
                    
                      • 26182
                      • 164 Posts
                      I’m trying to write a snippet that will show the documents that have the highest page_counts that have been assigned to be able to log hits. This is the code I have so far and I am getting the output of "Resource id # 21":

                      <?php
                      /*
                       ****************************************
                       *
                       * Snippet Name: ShowHits
                       * Short Desc: Shows hits on pages of the IT Newsletters site
                       * Created By: Sarah Vardy
                       *
                       * Version: 1.0 beta
                       * Modified: November 8th, 2007
                       *
                       * Changelog: 
                       *   
                       *
                       ****************************************
                       *
                       * Description: 	
                       *   Display a list of articles that have had the most hits in descending order
                       *   Show the number of hits on a page at the bottom of a page
                       *
                       ****************************************
                       *  
                       * Example: [[ShowHits?]]
                      */
                      
                      //connect to table that stores site content
                      $table_content = $modx->getFullTableName("site_content");
                      $table_hits = $modx->getFullTableName("page_hit_counter");
                      
                      $fields = 'pagetitle';
                      
                      $sql= "SELECT {$fields} FROM {$table_content} table_content JOIN {$table_hits} table_hits ON table_hits.page_id = table_content.id  WHERE table_content.donthit = '0' ORDER BY table_hits.page_count DESC";
                      
                      $output = $modx->db->query($sql);
                      
                      return $output;
                      ?>
                      


                      I want to print out a link to each document. So I’ll need the id, pagetitle and the introtext.

                      Please help!

                      Thanks in advance,

                      Sarah