Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-webphotoalbum-git / www / inc / funkce.inc.php @ 4fcec884

Historique | Voir | Annoter | Télécharger (3,91 ko)

1 67466a8d Eric Seigne
<?php
2
3
function check($file) {
4 4fcec884 Eric Seigne
  global $gallery_dir, $page;
5 67466a8d Eric Seigne
   
6 4fcec884 Eric Seigne
  //   if (eregi("[^0-9a-z\_\-\ ]",$file) || !file_exists("$gallery_dir/$file")) {
7
  //   if (eregi("CVS",$file) || !file_exists("$gallery_dir/$file")) {
8
  if (!file_exists("$gallery_dir/$file")) {
9
    echo "funkce.inc.php/check(): Bad input";
10
    $page->footer();
11
    exit;
12
  }
13
  }
14 67466a8d Eric Seigne
15
function browserCheck() {
16 4fcec884 Eric Seigne
  global $HTTP_USER_AGENT;
17 67466a8d Eric Seigne
   
18 4fcec884 Eric Seigne
  $HTTP_USER_AGENT=$_SERVER["HTTP_USER_AGENT"];
19
  if (eregi("(MSIE.[456789]).*Mac.*",$HTTP_USER_AGENT)) {
20
    return("macie4+");
21
  } elseif (eregi("(MSIE.[678])",$HTTP_USER_AGENT)) {
22
    return("ie6+");
23
  } elseif (eregi("(MSIE.[45])",$HTTP_USER_AGENT)) {
24
    return("ie4+");
25
  } elseif (eregi("Opera",$HTTP_USER_AGENT)) {
26
    return("opera");
27
  } elseif (eregi("(Mozilla.4)",$HTTP_USER_AGENT)) {
28
    return("netscape4");
29
  } elseif (eregi("(Mozilla.[5-9])",$HTTP_USER_AGENT)) {
30
    return("mozilla");
31
  } elseif (eregi("KMeleon",$HTTP_USER_AGENT)) {
32
    return("mozilla");
33
  } else {
34
    return("Netscape3");
35
  }
36 67466a8d Eric Seigne
}
37
38
function infoParse ($infofile) {
39
        
40 4fcec884 Eric Seigne
  $info_array = file($infofile);
41
  foreach ($info_array as $line) {
42
    list($key,$value) = split("\|",$line);
43
    $result[$key]=$value;
44
  }
45
  return $result;
46 67466a8d Eric Seigne
}
47
48
function readInfo ($infofile, $file) {
49 4fcec884 Eric Seigne
  global $galerieyear, $galeriemonth, $galerieday, $galeriedesc, $galerieauthor,
50
    $galeriename, $galerielogin, $galeriepw, $gallery_dir;
51 67466a8d Eric Seigne
        
52 4fcec884 Eric Seigne
  if (file_exists($infofile)) {
53
    //read from info.txt
54
    $info_array = infoParse($infofile);
55
    if ($info_array["date"]) {
56
      // try to be a little smarter about format
57
      if (ereg("([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})",
58
               $info_array["date"])) {
59
        // remain compatible - DD.MM.YYYY
60
        list($day,$month,$year) = split("\.", $info_array["date"]);
61
        $year = rtrim($year);
62
        $month = rtrim($month);
63
        $day = rtrim($day);
64
        $info_array["date"] = "$year-$month-$day"; //make it US date
65
      }
66
      // US date format at this point
67
      $tstamp = strtotime($info_array["date"]);
68
    } else {
69
      $tstamp = filemtime("$gallery_dir/$file");// Get from filesystem
70
    }
71
    $galerieyear["$file"] = date("Y", $tstamp);
72
    $galeriemonth["$file"] = date("m", $tstamp);
73
    $galerieday["$file"] = date("d", $tstamp);
74 67466a8d Eric Seigne
                
75 4fcec884 Eric Seigne
    if (@$info_array["description"]) {
76
      $galeriedesc["$file"] = rtrim($info_array["description"]);
77
    }
78 67466a8d Eric Seigne
                
79 4fcec884 Eric Seigne
    if (@$info_array["author"]) {
80
      $galerieauthor["$file"] = rtrim($info_array["author"]);
81
    }
82 67466a8d Eric Seigne
                
83 4fcec884 Eric Seigne
    if (@$info_array["name"]) {
84
      $galeriename["$file"] = rtrim($info_array["name"]);
85
    }
86 67466a8d Eric Seigne
                
87 4fcec884 Eric Seigne
    if (@$info_array["restricted_user"]) {
88
      $galerielogin["$file"] = rtrim($info_array["restricted_user"]);
89
      $galeriepw["$file"] = rtrim($info_array["restricted_password"]);
90
    }
91
  } else { // Get Dates from modification stamp
92
    $mtime = filemtime("$gallery_dir/$file");
93
    $galerieyear["$file"] = date("Y", $mtime);
94
    $galeriemonth["$file"] = date("m", $mtime); //F
95
    $galerieday["$file"] = date("d", $mtime);
96
  }
97 67466a8d Eric Seigne
}
98
99
function access_check($login, $password,$realm) {
100 4fcec884 Eric Seigne
  if (!($_SERVER['PHP_AUTH_USER']=="$login" && $_SERVER['PHP_AUTH_PW']=="$password")) {
101
    header("WWW-authenticate: Basic Realm=$realm");
102
    Header("HTTP/1.0 401 Unauthorized");
103
    $err = new C_www;
104
    $err->header("Access Denied");
105
    echo "<div class=\"error\">\n";
106
    echo "<h1>Access Denied</h1>\n";
107
    echo "<p>Sorry, this gallery is restricted</p>\n";
108
    echo "<p><a href=\"index.php\">Return to index</a></p>\n";
109
    echo "</div>\n";
110
    $err->footer();
111
    exit;
112
  }
113 67466a8d Eric Seigne
114
}
115
116
function random_digits($times) {
117 4fcec884 Eric Seigne
  $random="";
118
  for ($i=0;$i<$times;$i++) {
119
    $random .= rand(0,9);
120
  }
121
  return $random;
122 67466a8d Eric Seigne
}
123
124
function get_photo_title($galerie, $id) {
125
  global $gallery_dir;
126
  if ($title = @file_get_contents("$gallery_dir/$galerie/comments/${id}.txt")) {
127
    $title = trim(preg_replace('/[\s\n\r]+/', ' ', strip_tags($title)));
128
    if (strlen($title) > 80)
129
      $title = trim(substr($title, 0, 77)) . "...";
130
  } else 
131
    $title = "Photo ${id}";
132
  return $title;
133
}
134
135
?>
Redmine Appliance - Powered by TurnKey Linux