~burner/xsb/debianized-xsb

« back to all changes in this revision

Viewing changes to docs/homepage/counter.php

  • Committer: Michael R. Head
  • Date: 2006-09-06 22:11:55 UTC
  • Revision ID: burner@n23-20060906221155-7e398d23438a7ee4
Add the files from the 3.0.1 release package

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
        // counter.php the program to show the counter number.
 
3
        
 
4
        function CounterImage() {
 
5
           $counterLogFile = ".counter.log";
 
6
           
 
7
           if (file_exists($counterLogFile) == true) {
 
8
              if(($fp= fopen($counterLogFile, "r+")) == false) {
 
9
                 printf("fopen of the file %s failed\n", $counterLogFile);
 
10
                 exit;
 
11
              }
 
12
              if (($content = fread($fp, filesize($counterLogFile))) == false) {
 
13
                 printf(" fread failed on the file %s\n", $counterLogFile);
 
14
                 exit;
 
15
              } else {
 
16
                 $content=chop($content); //trim the return character
 
17
                 if (($imageLocation = convertToImage($content)) == false) {
 
18
                    printf("ConverttoImage failed\n");
 
19
                    exit;
 
20
                 } else {
 
21
                    $content++;
 
22
                    if (rewind($fp) == 0) {
 
23
                       printf("rewind failed\n");
 
24
                       exit;
 
25
                    }
 
26
                    if (!fwrite($fp, $content, strlen($content))) {
 
27
                       printf("fwrite failed while updateing count in the file %s\n", $counterLogFile);
 
28
                       exit;
 
29
                    }
 
30
                    return $imageLocation;
 
31
                 }
 
32
              }
 
33
           }else {
 
34
              if (($fp = fopen($counterLogFile, "w")) ==false) {
 
35
                 printf("fopen of the file %s failed\n", $counterLogFile);
 
36
                 exit;
 
37
              }
 
38
              if (!fwrite($fp, "1", 1)) {
 
39
                 printf("fwrite failed on the file %s\n", $counterLogFile);
 
40
                 exit;
 
41
              }
 
42
           }
 
43
        }
 
44
 
 
45
 
 
46
        function ConvertToImage($content) {
 
47
           
 
48
           $imageFile = ".counter.png";
 
49
           $relativePath = ".counter.png";
 
50
           $noOfChars = strlen($content);
 
51
           
 
52
           $charHeight = ImageFontHeight(5);
 
53
           $charWidth = ImageFontWidth(5);
 
54
           $strWidth = $charWidth * $noOfChars;
 
55
           $strHeight = $charHeight;
 
56
           
 
57
           //15 padding
 
58
           $imgWidth = $strWidth + 15;
 
59
           $imgHeight = $strHeight + 15;
 
60
           $imgCenterX = $imgWidth /2;
 
61
           $imgCenterY = $imgHeight /2;
 
62
           
 
63
           $im = ImageCreate($imgWidth, $imgHeight);
 
64
           $script = ImageColorAllocate($im, 0, 255, 0);
 
65
           $outercolor = ImageColorAllocate($im, 99, 140, 214);
 
66
           $innercolor = ImageColorAllocate($im, 0, 0, 0);
 
67
           ImageFilledRectangle($im, 0, 0, $imgWidth, $imgHeight, $outercolor);
 
68
           ImageFilledRectangle($im, 3, 3, $imgWidth -4, $imgHeight-4, $innercolor);
 
69
           
 
70
           //draw string
 
71
           $drawPosX = $imgCenterX - ($strWidth /2) +1;
 
72
           $drawPosY = $imgCenterY - ($strHeight /2);
 
73
           ImageString($im, 5, $drawPosX, $drawPosY, $content, $script);
 
74
           
 
75
           //save image and return
 
76
           ImagePNG($im, $imageFile);
 
77
           return $relativePath;
 
78
        }
 
79
?>