Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-webphotoalbum-git / data / www / inc / funkce.inc.php @ eee84392

Historique | Voir | Annoter | Télécharger (4,06 ko)

1
<?php
2

    
3
function check($file) {
4
  global $gallery_dir, $page;
5
   
6
  //   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

    
15
function browserCheck() {
16
  global $HTTP_USER_AGENT;
17
   
18
  $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
}
37

    
38
function infoParse ($infofile) {
39
        
40
  $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
}
47

    
48
function readInfo ($infofile, $file) {
49
  global $galerieyear, $galeriemonth, $galerieday, $galeriedesc, $galerieauthor,
50
    $galeriename, $galerielogin, $galeriepw, $gallery_dir, $galerievideo;
51
        
52
  if (file_exists($infofile)) {
53
    //read from info.txt
54
    $info_array = infoParse($infofile);
55

    
56
    //video ?
57
    if($info_array["video"] == "true") {
58
      $galerievideo = true;
59
    }
60
    else {
61
      $galerievideo = false;
62
    }
63

    
64
    if ($info_array["date"]) {
65
      // try to be a little smarter about format
66
      if (ereg("([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})",
67
               $info_array["date"])) {
68
        // remain compatible - DD.MM.YYYY
69
        list($day,$month,$year) = split("\.", $info_array["date"]);
70
        $year = rtrim($year);
71
        $month = rtrim($month);
72
        $day = rtrim($day);
73
        $info_array["date"] = "$year-$month-$day"; //make it US date
74
      }
75
      // US date format at this point
76
      $tstamp = strtotime($info_array["date"]);
77
    } else {
78
      $tstamp = filemtime("$gallery_dir/$file");// Get from filesystem
79
    }
80
    $galerieyear["$file"] = date("Y", $tstamp);
81
    $galeriemonth["$file"] = date("m", $tstamp);
82
    $galerieday["$file"] = date("d", $tstamp);
83
                
84
    if (@$info_array["description"]) {
85
      $galeriedesc["$file"] = rtrim($info_array["description"]);
86
    }
87
                
88
    if (@$info_array["author"]) {
89
      $galerieauthor["$file"] = rtrim($info_array["author"]);
90
    }
91
                
92
    if (@$info_array["name"]) {
93
      $galeriename["$file"] = rtrim($info_array["name"]);
94
    }
95
                
96
    if (@$info_array["restricted_user"]) {
97
      $galerielogin["$file"] = rtrim($info_array["restricted_user"]);
98
      $galeriepw["$file"] = rtrim($info_array["restricted_password"]);
99
    }
100
  } else { // Get Dates from modification stamp
101
    $mtime = filemtime("$gallery_dir/$file");
102
    $galerieyear["$file"] = date("Y", $mtime);
103
    $galeriemonth["$file"] = date("m", $mtime); //F
104
    $galerieday["$file"] = date("d", $mtime);
105
  }
106
}
107

    
108
function access_check($login, $password,$realm) {
109
  if (!($_SERVER['PHP_AUTH_USER']=="$login" && $_SERVER['PHP_AUTH_PW']=="$password")) {
110
    header("WWW-authenticate: Basic Realm=$realm");
111
    Header("HTTP/1.0 401 Unauthorized");
112
    $err = new C_www;
113
    $err->header("Access Denied");
114
    echo "<div class=\"error\">\n";
115
    echo "<h1>Access Denied</h1>\n";
116
    echo "<p>Sorry, this gallery is restricted</p>\n";
117
    echo "<p><a href=\"index.php\">Return to index</a></p>\n";
118
    echo "</div>\n";
119
    $err->footer();
120
    exit;
121
  }
122

    
123
}
124

    
125
function random_digits($times) {
126
  $random="";
127
  for ($i=0;$i<$times;$i++) {
128
    $random .= rand(0,9);
129
  }
130
  return $random;
131
}
132

    
133
function get_photo_title($galerie, $id) {
134
  global $gallery_dir;
135
  if ($title = @file_get_contents("$gallery_dir/$galerie/comments/${id}.txt")) {
136
    $title = trim(preg_replace('/[\s\n\r]+/', ' ', strip_tags($title)));
137
    if (strlen($title) > 80)
138
      $title = trim(substr($title, 0, 77)) . "...";
139
  } else 
140
    $title = "Photo ${id}";
141
  return $title;
142
}
143

    
144
?>
Redmine Appliance - Powered by TurnKey Linux