01 <div class="widget-assets widget"> 02 <h3 class="widget-header">Photo Gallery</h3> 03 <div class="widget-content" style="text-align: center;"> 04 05 <?php 06 $DebugFlag = 0; 07 08 $BlogBaseURL = "http://www.(userdomain)/blog/"; 09 $BlogBasePath = "/home/(username)/blog/"; 10 $ThumbnailDataPath = "image/thumbnail.dat"; 11 12 $ThumbnailImageNum = 12; 13 $ThumbnailWidth = 80; 14 $ThumbnailHeight = 60; 15 16 if(!$ThumbnailDataHandle = fopen($BlogBasePath . $ThumbnailDataPath, "r")) { 17 die("fopen(ERROR): $BlogBasePath$ThumbnailDataPath"); 18 } 19 20 $cnt = 0; 21 while ($line = fgets($ThumbnailDataHandle)) { 22 $word = preg_split("/[\t\n]/", $line); 23 $AssetImageArray[$cnt]['path'] = $word[0]; 24 $AssetImageArray[$cnt]['select'] = 0; 25 $cnt++; 26 } 27 $AssetImageNum = $cnt; 28 29 fclose($ThumbnailDataHandle); 30 31 if($DebugFlag) { 32 printf("<div>found %d asset images.</div>\n", $AssetImageNum); 33 } 34 35 for($cnt = 0; $cnt < $ThumbnailImageNum; $cnt++) { 36 do { 37 $rnd = mt_rand(0, $AssetImageNum - 1); 38 } while ($AssetImageArray[$rnd]['select']); 39 $AssetImageArray[$rnd]['select'] = 1; 40 41 $AssetImagePath = preg_replace('/^%r\//', $BlogBaseURL, $AssetImageArray[$rnd]['path']); 42 43 $path = pathinfo($AssetImagePath); 44 $ThumbnailImagePath = sprintf("%s/%s_%dx%d.%s", $path['dirname'], $path['filename'], $ThumbnailWidth, $ThumbnailHeight, $path['extension']); 45 46 preg_match('/(.*)\/image\/(\d{2})(\d{2})(\d{2}-*\d*)/', $ThumbnailImagePath, $match); 47 $EntryLinkPath = sprintf("%s/20%s/%s/%s%s%s.php", $match[1], $match[2], $match[3], $match[2], $match[3], $match[4]); 48 49 printf("<a href=\"%s\"><img src=\"%s\" width=\"%d\" height=\"%d\" border=\"0\" alt=\"Click Here!!\" /></a>\n", $EntryLinkPath, $ThumbnailImagePath, $ThumbnailWidth, $ThumbnailHeight); 50 } 51 52 if($DebugFlag) { 53 printf("<div>selected %d thumbnails.</div>\n", $ThumbnailImageNum); 54 } 55 ?> 56 57 </div> 58 </div>