$imgw, 'imgh' => $imgh); return $imgsize; } function image_type($type) { $file_types = array( 'image/pjpeg' => 'jpg', 'image/jpeg' => 'jpg', 'image/jpeg' => 'jpeg', 'image/gif' => 'gif', 'image/X-PNG' => 'png', 'image/PNG' => 'png', 'image/png' => 'png', 'image/x-png' => 'png', 'image/JPG' => 'jpg', 'image/GIF' => 'gif', ); if(!array_key_exists($type, $file_types)) { return false; } else { return true; } } function get_date($date) { list($year, $month, $day, $hours, $minutes, $seconds) = sscanf($date, "%d-%d-%d %d:%d:%d"); $month=str_pad($month, 2, '0', STR_PAD_LEFT); $day=str_pad($day, 2, '0', STR_PAD_LEFT); $hours=str_pad($hours, 2, '0', STR_PAD_LEFT); $minutes=str_pad($minutes, 2, '0', STR_PAD_LEFT); $$seconds=str_pad($seconds, 2, '0', STR_PAD_LEFT); $new['date']="$day.$month.$year"; $new['time']="$hours:$minutes:$seconds"; $new['year']="$year"; $new['month']="$month"; $new['day']="$day"; $new['hours']="$hours"; $new['minutes']="$minutes"; $new['seconds']="$seconds"; return $new; } function secure($text) //избавление текста от вредоносной дряни :) { $text=trim(htmlspecialchars($text, ENT_QUOTES)); return $text; } function unsecure($text) //возвращение вредоносной дряни в текст { $text=stripslashes($text); return $text; } function randomize($min,$max,$array) { $random_number=rand($min,$max); foreach($array as $index => $val) { if ($val==$random_number) { $random_number=randomize($min,$max,$array); } } return $random_number; } function draw_header($header_type = "default", $header_options = "") { $link_img = "http://fukurokudzu.ru/pb/graphics/bg/logo2.png"; $link_desc = "PhotoBlog v.3 Beta"; $title = "PhotoBlog v.3 Beta"; switch ($header_type) { case "default": $scripts=" "; $title = "PhotoBlog v.3 Beta"; break; case "storage": $scripts=" "; $title = "PhotoBlog Storage"; break; case "photo": $scripts=" "; $title = "PhotoBlog Photo"; if ($header_options) { $photo = new Photo; $photo->Init($header_options); $link_img = "http://fukurokudzu.ru/pb/photo/thumb/".$photo->file_small_addr; $entry = new BlogEntry; $entry->Init($photo->entry); $owner = new User; $owner->Init($entry->owner); $link_desc = "by ".$owner->login; if ($entry->ost) { $link_desc.=", ost: ".$entry->ost; } $title = $entry->subject; } break; case "profile": $scripts=" "; break; case "edit_profile": $scripts=" "; break; case "fast": $scripts=" "; break; case "milestone": $scripts=" "; break; case "entry": $scripts=" "; $title = "PhotoBlog Post"; if ($header_options) { $entry = new BlogEntry; $entry->Init($header_options); $rand_index = rand(0, count($entry->photoes) - 1); $photo = new Photo; $photo->Init($entry->photoes[$rand_index]); $link_img = "http://fukurokudzu.ru/pb/photo/thumb/".$photo->file_small_addr; $owner = new User; $owner->Init($entry->owner); $link_desc = "by ".$owner->login; if ($entry->ost) { $link_desc.=", ost: ".$entry->ost; } $title = $entry->subject; } break; } //print(""); print(""); print(" "); print("".$title."".$scripts." "); print("
"); print("
"); } function draw_logo() { print("
"); print(""); print("
"); } function draw_menu() { if (if_auth() && !isset($_SESSION['identity'])) { $fast_link="
  • fast
  • "; $upload_link="
  • Загрузка
  • "; $profile_link="
  • Профиль
  • "; $login_link="
  • Мой PhotoBlog
  • "; $register_link="
  • "; } else { $login_link="
  • "; $profile_link="
  • "; $upload_link="
  • "; $fast_link="
  • "; $register_link="
  • Регистрация
  • "; } draw_auth(); print (""); } function draw_auth() // отрисовка окошка логина { //--------------- отрисовка html print("
    логин"); //print("или openid"); print("
         
    "); /*print("
      
    ");*/ print("
    "); if(isset($_SESSION['start_errors'])) { echo $_SESSION['start_errors']; } print("
    Выход
    "); } function draw_footer() { print("
    "); print("
    "); print("
    "); print("
    "); print(""); print(""); } function if_auth() { $result=0; if (isset($_COOKIE['login']) && isset($_COOKIE['passwd'])) { $cookie_login=secure($_COOKIE['login']); $cookie_passwd=secure($_COOKIE['passwd']); if ($query=mysql_query("SELECT * from pb_users where login='$cookie_login' LIMIT 1")) { $query_data=mysql_fetch_array($query); if ($query_data['login']==$cookie_login && $query_data['passwd']==$cookie_passwd) { $_SESSION['login']=$query_data['login']; $_SESSION['id']=$query_data['id']; $_SESSION['username']=$query_data['username']; unset ($_SESSION['identity']); $result="1"; $options=$query_data['login']; } else { $result="0"; $error="логин и пароль не совпадают"; } } else { $result="0"; $error="нет такого логина"; } } elseif (isset($_SESSION['identity'])) { if ($_SESSION['identity']!="") { $query=mysql_query("SELECT identity from pb_openid_users where identity='$_SESSION[identity]' LIMIT 1"); $query_data=mysql_fetch_array($query); if($query_data['identity']==$_SESSION['identity']) { $result="1"; $options=$_SESSION['identity']; } } else { $result="0"; $error="openid не задан"; } } else { $error='не залогинен'; $result="0"; } return $result; } function create_thumb($file_addr, $path) { $CURRENT_PATH="/var/www/pb"; if (!isset($path)) { $CURRENT_PHOTO_PATH=$CURRENT_PATH."/photo"; $CURRENT_THUMB_PATH=$CURRENT_PHOTO_PATH."/thumb"; $CURRENT_PREVIEW_PATH=$CURRENT_PHOTO_PATH."/preview"; } else { $CURRENT_PHOTO_PATH=$CURRENT_PATH.$path; $CURRENT_THUMB_PATH=$CURRENT_PATH.$path."/thumb"; $CURRENT_PREVIEW_PATH=$CURRENT_PATH.$path."/preview"; } $THUMB_SIZE="250"; $PREVIEW_SIZE="900"; // File and new size $filename = $CURRENT_PHOTO_PATH."/".$file_addr; // Get new sizes list($width, $height) = getimagesize($filename); if ($width>$height) { $smallestside=$height; $x=($width-$height)/2; $y=0; } else { $x=0; $y=($height-$width)/2; $smallestside=$width; } // Load $thumb = @imagecreatetruecolor($THUMB_SIZE, $THUMB_SIZE); if ($source = @imagecreatefromjpeg($filename)) { // Resize @imagecopyresampled($thumb, $source, 0, 0, $x, $y, $THUMB_SIZE, $THUMB_SIZE, $smallestside, $smallestside); // Output @imagejpeg($thumb, $CURRENT_THUMB_PATH."/".$file_addr, 100); } if ($source = @imagecreatefrompng ($filename)) { @imagecopyresampled($thumb, $source, 0, 0, $x, $y, $THUMB_SIZE, $THUMB_SIZE, $smallestside, $smallestside); @imagepng ($thumb, $CURRENT_THUMB_PATH."/".$file_addr, 0); } if ($source = @imagecreatefromgif ($filename)) { @imagecopyresampled($thumb, $source, 0, 0, $x, $y, $THUMB_SIZE, $THUMB_SIZE, $smallestside, $smallestside); @imagegif ($thumb, $CURRENT_THUMB_PATH."/".$file_addr); } return 1; } //старая функция для старого аплода function create_preview($file_addr, $path) { $CURRENT_PATH="/var/www/pb"; if (!isset($path)) { $CURRENT_PHOTO_PATH=$CURRENT_PATH."/photo"; $CURRENT_PREVIEW_PATH=$CURRENT_PHOTO_PATH."/preview"; } else { $CURRENT_PHOTO_PATH=$CURRENT_PATH.$path; $CURRENT_PREVIEW_PATH=$CURRENT_PATH.$path."/preview"; } $PREVIEW_SIZE="900"; // File and new size $filename = $CURRENT_PHOTO_PATH."/".$file_addr; list($width, $height) = getimagesize($filename); // Load if ($width>$PREVIEW_SIZE) { $preview_height=($height/$width)*$PREVIEW_SIZE; $preview = imagecreatetruecolor($PREVIEW_SIZE, $preview_height); if ($source = @imagecreatefromjpeg($filename)) { @imagecopyresampled($preview, $source, 0, 0, 0, 0, $PREVIEW_SIZE, $preview_height, $width, $height); @imagejpeg($preview, $CURRENT_PREVIEW_PATH."/".$file_addr, 100); } if ($source = @imagecreatefrompng ($filename)) { @imagecopyresampled($preview, $source, 0, 0, 0, 0, $PREVIEW_SIZE, $preview_height, $width, $height); @imagepng ($preview, $CURRENT_PREVIEW_PATH."/".$file_addr, 0); } if ($source = @imagecreatefromgif ($filename)) { @imagecopyresampled($preview, $source, 0, 0, 0, 0, $PREVIEW_SIZE, $preview_height, $width, $height); @imagegif ($preview, $CURRENT_PREVIEW_PATH."/".$file_addr); } } return 1; } // новая функция для нового классного аплода function create_fast_preview($file_addr) { $Settings = new Settings(); $Settings->Init(); // File and new size $filename = $Settings->CURRENT_TMP_PATH."/".$file_addr; list($width, $height) = getimagesize($filename); // Load if ($width>$Settings->PREVIEW_SIZE) { $preview_height=($height/$width)*$Settings->PREVIEW_SIZE; $preview = imagecreatetruecolor($Settings->PREVIEW_SIZE, $preview_height); if ($source = @imagecreatefromjpeg($filename)) { @imagecopyresampled($preview, $source, 0, 0, 0, 0, $Settings->PREVIEW_SIZE, $preview_height, $width, $height); @imagejpeg($preview, $Settings->CURRENT_TMP_PREVIEW_PATH."/".$file_addr, 100); return 1; } if ($source = @imagecreatefrompng ($filename)) { @imagecopyresampled($preview, $source, 0, 0, 0, 0, $Settings->PREVIEW_SIZE, $preview_height, $width, $height); @imagepng ($preview, $Settings->CURRENT_TMP_PREVIEW_PATH."/".$file_addr, 0); return 1; } if ($source = @imagecreatefromgif ($filename)) { @imagecopyresampled($preview, $source, 0, 0, 0, 0, $PREVIEW_SIZE, $preview_height, $width, $height); @imagegif ($preview, $Settings->CURRENT_TMP_PREVIEW_PATH."/".$file_addr); return 1; } } else { return 0; } } /*// ============================= Отрисовка комментария ================================ function print_comment($current_id) { $comment = new Comment; $comment->Init($current_id); $comment_owner = new User; $comment_owner->Init($comment->owner); if ($comment->deleted) { $text="

    deleted comment

    "; } else { $text=nl2br($comment->text); } if ($comment_owner->avatar) { $avatar=""; } else { $avatar=""; } print($avatar."posted by ".$comment_owner->login." at ".$comment->posted); print("
    ".$text); print("
    (Ответить)(Удалить)"); return 1; } // ============================= Просчет и печать дерева комментариев ================================ function print_childs($current_id, $tab_count) { $comments=mysql_query("SELECT id from pb_comments where parent_id='".$current_id."' LIMIT 1"); if ($comments) { print("
    "); print_comment($current_id, $tab_count); print("
    "); $comments_count=mysql_num_rows($comments); for ($i=0;$i<$comments_count;$i++) { $tab_count++; $child=mysql_fetch_array($comments); print("
    "); print_childs($child['id'], $tab_count); print("
    "); } } else { print("
    "); print_comment($current_id, $tab_count); print("
    "); } }*/ /*// ============================= Отрисовка комментария ================================ function print_comment($current_id,$tab_count) { $comment = new Comment; $comment->Init($current_id); $comment_owner = new User; $comment_owner->Init($comment->owner); $tab=""; if (isset($tab_count) && $tab_count>0) { for ($i=0;$i<$tab_count;$i++) { $tab.=" "; } } if ($comment->deleted && isset($tab_count) && $tab_count>0) { $text="

    deleted comment

    "; } if ($comment->deleted && (!isset($tab_count) || $tab_count==0)) { return 0; } else { $text=nl2br($comment->text); } if ($comment_owner->avatar) { $avatar=""; } else { $avatar=""; } print("".$tab.""); print("".$tab.""); print("".$tab."
    ".$avatar."posted by ".$comment_owner->login." at ".$comment->posted."
    ".$text."
    (Ответить)(Удалить)
    "); return 1; } // ============================= Просчет и печать дерева комментариев ================================ function print_childs($current_id, $tab_count) { $comments=mysql_query("SELECT id from pb_comments where parent_id='".$current_id."' LIMIT 1"); if ($comments) { print("
    "); print_comment($current_id, $tab_count); print("
    "); $comments_count=mysql_num_rows($comments); for ($i=0;$i<$comments_count;$i++) { $tab_count++; $child=mysql_fetch_array($comments); print("
    "); print_childs($child['id'], $tab_count); print("
    "); } } else { print("
    "); print_comment($current_id, $tab_count); print("
    "); } }*/ function print_comment_form() { print("
    "); print("
    "); print(""); print("
    "); } // ============================= функция, честно стыренная у webew.ru ================================ // по идее позволяет легко работать с GET-параметрами, что требуется для пагинации главной страницы. function sgp($url, $varname, $value) // substitute get parameter { if (is_array($varname)) { foreach ($varname as $i => $n) { $v = (is_array($value)) ? ( isset($value[$i]) ? $value[$i] : NULL ) : $value; $url = sgp($url, $n, $v); } return $url; } preg_match('/^([^?]+)(\?.*?)?(#.*)?$/', $url, $matches); $gp = (isset($matches[2])) ? $matches[2] : ''; // GET-parameters if (!$gp) return $url; $pattern = "/([?&])$varname=.*?(?=&|#|\z)/"; if (preg_match($pattern, $gp)) { $substitution = ($value !== '') ? "\${1}$varname=" . preg_quote($value) : ''; $newgp = preg_replace($pattern, $substitution, $gp); // new GET-parameters $newgp = preg_replace('/^&/', '?', $newgp); } else { $s = ($gp) ? '&' : '?'; $newgp = $gp.$s.$varname.'='.$value; } $anchor = (isset($matches[3])) ? $matches[3] : ''; $newurl = $matches[1].$newgp.$anchor; return $newurl; } ?>