Advertisement
Guest User

Untitled

a guest
Jun 29th, 2010
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.00 KB | None | 0 0
  1. // PageHitCounter - module for MODx 0.9.x
  2. // creates page_hit_counter table if necessary
  3. // displays page requests
  4. // Version 2 - Ajax-based single page view
  5. // 08-2006 sottwell@sottwell.com
  6. // released to the Public Domain
  7. // requires the CountPageHit plugin to insert data into the table
  8. // Repaired by Xaevo
  9.  
  10. global $table_prefix, $manager_theme;
  11.  
  12. if(isset($_POST['tables']) && $_POST['tables'] == 'Create Table') {
  13.   $sql = "CREATE TABLE IF NOT EXISTS `".$table_prefix."page_hit_counter` (
  14.  `page_id` int(4) unsigned NOT NULL default '0',
  15.  `page_count` int(10) unsigned NOT NULL default '0',
  16.  UNIQUE KEY `page_id` (`page_id`)
  17. )";
  18.   $modx->db->query($sql);
  19. }
  20. $page = '  
  21. <html>
  22. <head>
  23.     <title>PageHitCounter</title>
  24.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  25.     <link rel="stylesheet" type="text/css" href="media/style/'.$manager_theme.'/style.css?" />
  26.     <script type="text/javascript">var MODX_MEDIA_PATH = "media";</script>
  27.     <script type="text/javascript" language="JavaScript" src="media/script/modx.js"></script>
  28.     <script type="text/javascript" src="media/script/scriptaculous/prototype.js"></script>
  29.     <script type="text/javascript" language="JavaScript">
  30.         document.setIncludePath("media/script/bin/");
  31.         document.addEventListener("oninit",function() {
  32.             document.include("dynelement");
  33.         })
  34.     </script>  
  35.     <script type="text/javascript" language="JavaScript" src="media/script/cb2.js"></script>
  36.     <script language="JavaScript" type="text/javascript">
  37.  
  38.         var MODX_MEDIA_PATH = "media"; // set media path
  39.  
  40.         function document_onload() {
  41.             stopWorker();
  42.             msgCount();
  43.             hideLoader();
  44.             ;  
  45.         };
  46.        
  47.         var dontShowWorker = false;
  48.         function document_onunload() {
  49.             if(!dontShowWorker) {
  50.                 top.scripter.work();
  51.             }
  52.         };
  53.        
  54.         // set tree to default action.     
  55.         parent.menu.ca = "open";
  56.  
  57.         function msgCount() {
  58.             try {
  59.                 top.scripter.startmsgcount(0,0,1);
  60.             } catch(oException) {
  61.                 ww = window.setTimeout(\'msgCount()\',1000);
  62.             }
  63.         }
  64.        
  65.         function stopWorker() {
  66.             try {
  67.                 parent.scripter.stopWork();
  68.             } catch(oException) {
  69.                 ww = window.setTimeout(\'stopWorker()\',500);
  70.             }
  71.         }
  72.        
  73.         function doRefresh(r) {
  74.             try {
  75.                 rr = r;
  76.                 top.scripter.startrefresh(rr);
  77.             } catch(oException) {
  78.                 vv = window.setTimeout(\'doRefresh()\',1000);
  79.             }
  80.         }
  81.         var documentDirty=false;
  82.  
  83.         function checkDirt() {
  84.             if(documentDirty==true) {
  85.                 event.returnValue = "The changes you have made have not been saved yet. You can choose to stay on the current page in order to save the changes (\'Cancel\'), or you can leave this page, losing any changes you have made (\'OK\').";
  86.             }
  87.         }
  88.        
  89.         function saveWait(fName) {
  90.             document.getElementById("savingMessage").innerHTML = "Saving, please wait...";
  91.             for(i = 0; i < document.forms[fName].elements.length; i++) {
  92.                 document.forms[fName].elements[i].disabled=\'disabled\';
  93.             }
  94.         }
  95.  
  96.         var managerPath = "";
  97.  
  98.         function hideLoader() {
  99.             document.getElementById(\'preLoader\').style.display = "none";
  100.         }
  101.        
  102.         retry=0;
  103.         function loadagain(id) {
  104.             try {
  105.                 top.menu.Sync();
  106.             } catch(oException) {
  107.                 retry=retry + 1;
  108.                 if(retry<4) {
  109.                     xyy=window.setTimeout("loadagain()", 2000);
  110.                 } else {
  111.                     //alert("Failed to sync to tree!");
  112.                 }
  113.             }
  114.         }
  115.  
  116.         hideL = window.setTimeout("hideLoader()", 5000);
  117.        
  118. var allowParentSelection = false;
  119.        
  120. function enableParentSelection(b){
  121.  parent.menu.ca = "parent";
  122.  
  123.     var closed = "media/style/MODxCarbon/images/icons/folder.gif";
  124.     var opened = "media/style/MODxCarbon/images/icons/folderopen.gif";
  125.     if(b) {
  126.         document.images["plock"].src = opened;
  127.         allowParentSelection = true;
  128.     }
  129.     else {
  130.         document.images["plock"].src = closed;
  131.         allowParentSelection = false;
  132.     }
  133. }
  134.  
  135. function setParent(pId, pName) {
  136.     if (!allowParentSelection) {
  137.         window.location.href="index.php?a=3&id="+pId;
  138.         return;
  139.     } else {
  140.       enableParentSelection(!allowParentSelection);
  141.         var url = \'../assets/modules/pagehitcounter/getcount.php\';
  142.         var pars = \'docid=\' + pId + \'&docname=\' + pName;
  143.        
  144.    var myAjax = new Ajax.Updater(
  145.      {success: \'placeholder\'},
  146.      url,
  147.      {
  148.         method: \'get\',
  149.         parameters: pars,
  150.         onFailure: reportError
  151.      });
  152.     }
  153.  
  154. }
  155.  
  156. function closeSingle() {
  157. var singleView = document.getElementById(\'placeholder\');
  158. singleView.innerHTML = "";
  159. }
  160.  
  161. function reportError(request)
  162. {
  163.     alert(\'Sorry. There was an error.\');
  164. }
  165.  
  166.        
  167.     </script>
  168.     <style>
  169.     #preLoader {
  170.         position:                       absolute;
  171.         z-index:                        50000;
  172.         width:                          100%;
  173.         height:                         100%;
  174.         text-align:                     center;
  175.         vertical-align:                 middle;
  176.     }
  177.     .preLoaderText {
  178.         background-color:               #ffffff;
  179.         width:                          300px;
  180.         height:                         150px;
  181.         padding:                        50px;
  182.         border:                         1px solid #003399;
  183.     }
  184.     </style>
  185.  
  186. <script>
  187.     function getCntxMenu(id) {
  188.         if(self.DynElement) return new DynElement(id);
  189.         else return document.getElementById(id);
  190.     }
  191.     function hideCntxMenu(id){
  192.         var cm = getCntxMenu(id);
  193.         cm.style.visibility = \'hidden\';
  194.     }
  195.  
  196. </script>
  197. <style>
  198. .contextMenu {
  199.     background: #fff url(media/images/bg/context.gif) repeat-y top left;
  200.     margin:                     0;
  201.     padding:                    0;
  202.     border:                     1px solid #003399;
  203.     border-left-color:          #eaeaea;
  204.     border-top-color:           #eaeaea;
  205.     border-right-color:         #909090;
  206.     border-bottom-color:        #707070;
  207.     position:                   absolute;
  208.     z-index:                    10000; }
  209.  
  210. .cntxMnuItem {
  211.     background-image:           url(media/images/_tx_.gif);
  212.     cursor:                     pointer;
  213.     color:                      #000;
  214.     padding:                    3px 16px 3px 2px; }
  215.  
  216. .cntxMnuItemOver {
  217.     cursor:                     pointer;
  218.     color:                      #000;
  219.     background: #fc0 url(media/style/MODxCarbon/images/misc/buttonbar_gs.gif) repeat-x bottom left;
  220.     padding:                    2px 15px 2px 1px;
  221.     border:                     1px solid #fa0; /*#003399;*/
  222. }
  223.  
  224. .cntxMnuItemDisabled {
  225.     cursor:                     default;
  226.     font:                       menu;
  227.     padding:                    3px 16px 3px 2px;
  228.     color:                      #111;
  229. }
  230. .cntxMnuItem IMG, .cntxMnuItemOver IMG, .cntxMnuItemDisabled IMG {
  231.     margin-right:               8px;
  232. }
  233.  
  234. .cntxMnuItem IMG, .cntxMnuItemDisabled IMG {
  235.     filter:                     gray();
  236. }
  237.  
  238. .cntxMnuSeparator {
  239.     font-size:                  0;
  240.     height:                     1px;
  241.     background-color:           #6A8CCB;
  242.     overflow:                   hidden;
  243.     margin:                     3px 1px 3px 28px; }
  244.    
  245. .countTable{
  246. width:300px;
  247. margin-bottom:20px;
  248. }
  249. .countTable td{
  250. padding-right:20px;
  251. border-bottom:1px solid #000;
  252. padding-top:10px;
  253. }
  254. .countTable th{
  255. text-align:left;
  256. border-bottom:1px solid #000;
  257. }
  258. </style>
  259. </head>
  260. <body>
  261.  
  262. <!-- <div id="preLoader"><table width="100%" height="50%" border="0" cellpadding="0"><tr><td align="center"><div class="preLoaderText">Please wait while MODx loads the page...</div></td></tr></table></div> -->
  263. <div id=\'cntxm\' class=\'contextMenu\' style=\'width:150px; visibility:hidden\'>  
  264.         </div>
  265. <div class="subTitle">
  266.     <span class="right"><img src="media/style/MODxCarbon/images/icons/_tx_.gif" width="1" height="5"><br />Page Hit Counter</span>
  267. </div>
  268.  
  269. <div class="sectionHeader"><img src="media/style/'.$manager_theme.'/images/dot.gif" alt="" />&nbsp;Page Hit Counter</div><div class="sectionBody">
  270.     <p><img name="plock" src="media/style/MODxCarbon/images/icons/folder.gif" width="18" height="18" align="absmiddle" onClick="enableParentSelection(!allowParentSelection);" style="cursor:pointer;" /> <strong>Select Document</strong><br />Click on the icon, then click on the document in the Document Tree to view the page view count for that document.</p>      
  271. ';
  272.            
  273. $sql = "SHOW TABLES LIKE '".$table_prefix."page_hit_counter'";
  274. $rs = $modx->db->query($sql);
  275. $count = $modx->db->getRecordCount($rs);
  276.  
  277. if($count < 1) {
  278.   $page .= '
  279.     <div class="searchbar">
  280.         <table border="0" style="width:100%">
  281.             <tr>
  282.             <td><form id="phcCreateTableForm" action="" enctype="multipart/form-data" method="post" style="margin:0;padding:0;" >
  283. <fieldset style="border:none;margin:0 0 0 20px;padding:0;">
  284. <label for="tables">Table does not exist. Please create the table: <input type="submit" name="tables" value="Create Table" /></label>
  285. </fieldset>
  286. </form></td>
  287.             <td nowrap="nowrap">
  288.             </td>
  289.             </tr>
  290.         </table>
  291.     </div> 
  292. ';
  293. } else {           
  294.     $page .= '
  295.     <div id="mainContent"><div id="placeholder"></div>';
  296.    
  297.     $sql = "SELECT * FROM ".$table_prefix."page_hit_counter";
  298.     $rs = $modx->db->query($sql);
  299.     $count = $modx->db->getRecordCount($rs);
  300.     if($count < 1) {
  301.         $page .= "No records found.";
  302.     } else {
  303.         // list page hits
  304.         $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";
  305.         $rs = $modx->db->query($sql);
  306.         $page .= '<table class="countTable" cellpadding="0" cellspacing="0" border="0"><tr><th>Page</th><th>Count</th></tr>';
  307.         while($row = $modx->db->getRow($rs)) {
  308.             $page .= '<tr><td style="width:80%">'.$row['pagetitle'].'</td><td>'.$row['page_count'].'</td></tr>';
  309.         }
  310.         $page .= '</table>';
  311.   }
  312.     $page .= '</div>
  313.     </div>
  314.     </body>
  315.     </html>
  316.     <!-- end footer -->
  317.     ';
  318. }
  319. return $page;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement