<?php
 // Old and New WordPress Blog Postings Comment Count Comparison - RJM Programming - April, 2018

set_time_limit(0);
$tablestr ="";
$cdel=",";
if (strpos(str_replace(" ", "", strtolower(urldecode($_SERVER['QUERY_STRING']))), "answer=") !== false) {

 date_default_timezone_set('Australia/Perth');
 $sdate = date('l jS \of F Y h:i:s A');
 
 $hostname = 'database_hostname';

 /*** mysql username ***/
 $username = 'mysql_username';

 /*** mysql ***/
 $password = 'mysql_username_password';

 $dbaltname = 'database_name_2';
 $dbname = 'database_name_1';
 $link = mysql_connect($hostname, $username, $password);
 if (!$link) {
    die('Could not connect: ' . mysql_error());
 }

 mysql_select_db($dbname);
 $res = mysql_query("SELECT t1.ID, t2.ID, t1.post_title, t2.post_title, t1.comment_count, t2.comment_count, t1.post_content, t2.post_content  
FROM " . $dbaltname . ".wps_posts t1
JOIN " . $dbname . ".wp_posts t2
ON t2.post_title = t1.post_title and t2.post_status in ('publish','future') and t1.post_status in ('publish','future')
WHERE t2.ID = t1.ID and lower(concat(concat(' ',t1.post_title),' ')) LIKE '% " . strtolower(urldecode($_GET['answer'])) . " %' ");
 if ($res == 0) {
  echo("<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>");
 } else if (mysql_num_rows($res) == 0) {
  echo("<b>Query executed successfully</b>");
 } else {
  while (($r_array = mysql_fetch_row($res))) {
    if ($tablestr == "") { 
      $tablestr="<h1>Report on RJM Programming WordPress Blog Comment Counts of Titles Containing '" . urldecode($_GET['answer']) . "' <input onclick=openthese(true); type=button value='Open Blog Postings Ticked' style=background-color:yellow;></input></h1><br><table border=20><tbody id=mytbody><tr><th style=width:10%;>Title</th><th style=width:10%;>Open these Blog Postings?</th><th style=width:300px;>Look 4.1.1</th><th style=width:300px;>Other Look</th></tr></tbody></table><br><form method=GET action=./old_new_wp_comment_count.php><input type=hidden name=fliesthisitsobecauseyoullneverfindhigh value=y></input><input type=hidden name=from value='" . $from . "'></input><input type=hidden name=to value='" . $to . "'></input><input type=hidden name=commit id=commit value=',"; // . $r_array[0] . ","; // . "'></input><input type=submit value=Commit></input></form>";     
    } 
    $tablestr.=$r_array[0] . $cdel;
    $tablestr=str_replace("</tr></tbody></table><br><form method=", "</tr><tr><td>" . $r_array[2] . "</td><td><input onchange=\"document.getElementById('commit').value=document.getElementById('commit').value.replace('," . $r_array[0] . ",',',-" . $r_array[0] . ",');\" type=checkbox></input></td><td style=width:300px;><!--div style='overflow:hidden; -ms-transform: scale(0.2, 0.2); -webkit-transform: scale(0.2, 0.2); transform: scale(0.2, 0.2);'--><details><summary>Reveal " . $r_array[4]  . " as WordPress 4.1.1 Look Comment Count ...</summary>" . $r_array[6] . "</details><!--/div--></td><td style=width:300px;><!--div style='overflow:hidden; -ms-transform: scale(0.2, 0.2); -webkit-transform: scale(0.2, 0.2); transform: scale(0.2, 0.2);'--><details><summary>Reveal " . $r_array[5]  . " Other Look Comment Count ...</summary>" . $r_array[7] . "</details><!--/div--></td></tr></tbody></table><br><form method=", $tablestr);
  }
 }
 if ($tablestr != "") {
    $tablestr.="'></input><input onclick=openthese(true); type=button value='Open Blog Postings Ticked' style=background-color:yellow;></input><input style=display:none; type=submit value=Open></input></form>";
    echo "<!doctype html><html><head><title>Old and New WordPress Blog Postings Comment Count Comparison - RJM Programming - April, 2018</title><script type='text/javascript' src='//www.rjmprogramming.com.au/wordpress/wp-admin/js/hexlib.js'></script>
<script type='text/javascript' src='//www.rjmprogramming.com.au/wordpress/wp-admin/js/noughtsandcrosses.js'></script>
<script type='text/javascript' src='//www.rjmprogramming.com.au/wordpress/wp-admin/js/englishverb.js'></script>
<script type='text/javascript' src='//www.rjmprogramming.com.au/ITblog/wp-admin/js/wajax.js'></script>
<script type='text/javascript' src='//www.rjmprogramming.com.au/HTMLCSS/longhover_sup.js?period=5000&from=+&to=-'></script>
<scri" . "pt type='text/javascript'> function openthese(v_4_1_1) { if (typeof v_4_1_1 === 'undefined') { v_4_1_1=false; }  var ota=document.getElementById('commit').value.split('-'); for (var iota=1; iota<ota.length; iota++) { if (v_4_1_1) { window.open('//www.rjmprogramming.com.au/ITblog/?p=' + ota[iota].split(',')[0],'_blank','top=50,left=50,width=400,height=400'); } else { window.open('//www.rjmprogramming.com.au/wordpress/?p=' + ota[iota].split(',')[0],'_blank','top=50,left=450,width=400,height=400'); }     } if (v_4_1_1) { setTimeout(openthese,3000);  }  }    </scr" . "ipt></head><body>" . $tablestr . "</body></html>";
 }

 mysql_close($link);
} else {
echo "<!doctype html><html><body onload=\" var huh=''; while (huh.trim() == '') { huh=prompt('Find this word (case insensitive) in WordPress Blog title', ''); if (huh == null) { huh=''; }   } if (huh != null) { location.href='./old_new_wp_comment_count.php?answer=' + encodeURIComponent(huh); } \"></body></html>";
}
?>
