1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', 'page' );
function generate_code32($date_before){
$date_32 = "";
$year_before = (intdiv($date_before,10000000000) % 100);
$month_before = intdiv(($date_before % 10000000000),100000000);
$day_before = intdiv(($date_before % 100000000),1000000);
$hour_before = intdiv(($date_before % 1000000),10000);
$minute_before = intdiv(($date_before % 10000),100);
$time_before = ($date_before % 100) + ($minute_before * 60);
if (($year_before % 32) < 10)
{
$date_32 = intdiv($year_before,32) . ($year_before % 32);
} else {
$date_32 = intdiv($year_before,32) . (chr(($year_before % 32) + ord("A") - 10));
}
if ($month_before < 10)
{
$date_32 .= $month_before;
} else {
$date_32 .= (chr($month_before + ord("A") - 10));
}
if ($day_before < 10)
{
$date_32 .= $day_before;
} else {
$date_32 .= (chr($day_before + ord("A") - 10));
}
if ($hour_before < 10)
{
$date_32 .= $hour_before;
} else {
$date_32 .= (chr($hour_before + ord("A") - 10));
}
$xx = 32 * 32;
while ($xx >= 1)
{
$temp_time = intdiv(($time_before % ($xx * 32)),$xx);
if ($temp_time < 10 )
{
$date_32 .= $temp_time;
} else {
$date_32 .= (chr($temp_time + ord("A") - 10));
}
$xx /= 32;
}
return $date_32;
}
function weekGenerate($currentTime){
$jd = gregoriantojd(substr($currentTime,4,2),substr($currentTime,6,2),substr($currentTime,0,4));
$jdRef = 2458645;
sscanf(jdtogregorian($jd - (($jd - $jdRef) % 7)),"%d/%d/%d",$m,$j,$a);
if ($m < 10){$m = "0" . $m;}
if ($j < 10){$j = "0" . $j;}
$weekFrom = generate_code32($a . $m . $j . "000000");
sscanf(jdtogregorian($jd - (($jd - $jdRef) % 7) + 6),"%d/%d/%d",$m,$j,$a);
if ($m < 10){$m = "0" . $m;}
if ($j < 10){$j = "0" . $j;}
$weekTo = generate_code32($a . $m . $j . "000000");
$week = substr($weekFrom,0,4) . "-" . substr($weekTo,0,4);
return $week;
}
$counter = array();
function updateCount($counter,$value) {
if ($counter[0] == 0) {
$counter[0] = "1_" . $value;
} else {
$pos = strpos($counter[0],"_");
if (substr($counter[0],$pos + 1) == $value) {
$counter[0] = (1 + substr($counter[0],0,$pos)) . substr($counter[0],$pos);
} else {
array_unshift($counter,"1_" . $value);
}
}
return $counter;
}
$currentTime = date("YmdHis");
$date32 = generate_code32($currentTime);
$week = weekGenerate($currentTime);
$photo = "0EA4H2MG.jpg";
$ownerID32 = "BJSDDLKM";
$counterPhoto = array();
$path = 'users/' . $ownerID32 . '_count.txt';
$content = file_get_contents("./wp-content/data/" . $path);
$counterPhoto = json_decode($content, true);
$ref = array("AllTime", "ByWeek", "ByYear", "ByMonth", "ByDay");
for ($y = 0;$y < 5;$y++) {
$type = "displayGallery" . $ref[$y];
if ($y > 1) {$value = substr($date32,0,$y);}
else {
if ($y == 1) {$value = $week;}
if ($y == 0) {$value = $counterPhoto[$photo]['UploadDate'];}
}
$counterPhoto[$photo][$type] = updateCount($counterPhoto[$photo][$type],$value);
}
var_dump($counterPhoto[$photo]);
$serialized = json_encode($counterPhoto,true);
echo json_encode($counterPhoto[$photo]);
file_put_contents('./wp-content/data/users/' . $ownerID32 . '_count.txt', $serialized);
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop. ?> |
Partager