plugins/SpecialUserFuncs.php
changeset 541 acb7e23b6ffa
parent 536 218a627eb53e
child 542 5841df0ab575
equal deleted inserted replaced
540:1e4b759da336 541:acb7e23b6ffa
    94       ));
    94       ));
    95       
    95       
    96     $paths->add_page(Array(
    96     $paths->add_page(Array(
    97       \'name\'=>\'specialpage_language_export\',
    97       \'name\'=>\'specialpage_language_export\',
    98       \'urlname\'=>\'LangExportJSON\',
    98       \'urlname\'=>\'LangExportJSON\',
       
    99       \'namespace\'=>\'Special\',
       
   100       \'special\'=>0,\'visible\'=>0,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
       
   101       ));
       
   102       
       
   103     $paths->add_page(Array(
       
   104       \'name\'=>\'specialpage_avatar\',
       
   105       \'urlname\'=>\'Avatar\',
    99       \'namespace\'=>\'Special\',
   106       \'namespace\'=>\'Special\',
   100       \'special\'=>0,\'visible\'=>0,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
   107       \'special\'=>0,\'visible\'=>0,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
   101       ));
   108       ));
   102       
   109       
   103     ');
   110     ');
  2019 
  2026 
  2020 enano_lang[{$lang->lang_id}] = " . enano_json_encode($lang_local->strings) . ";";
  2027 enano_lang[{$lang->lang_id}] = " . enano_json_encode($lang_local->strings) . ";";
  2021   
  2028   
  2022 }
  2029 }
  2023 
  2030 
       
  2031 /**
       
  2032  * Fetches and displays an avatar from the filesystem. Avatar fetching is abstracted as of 1.1.4.
       
  2033  */
       
  2034 
       
  2035 function page_Special_Avatar()
       
  2036 {
       
  2037   global $db, $session, $paths, $template, $plugins; // Common objects
       
  2038   global $aggressive_optimize_html;
       
  2039   $aggressive_optimize_html = false;
       
  2040   
       
  2041   $img_types = array(
       
  2042       IMAGE_TYPE_PNG => 'png',
       
  2043       IMAGE_TYPE_GIF => 'gif',
       
  2044       IMAGE_TYPE_JPG => 'jpg'
       
  2045     );
       
  2046   
       
  2047   $avi_id = $paths->getParam(0);
       
  2048   if ( !$avi_id || !@preg_match('/^[a-f0-9]+$/', $avi_id) )
       
  2049   {
       
  2050     echo 'Doesn\'t match the regexp';
       
  2051     return true;
       
  2052   }
       
  2053   
       
  2054   $avi_id_dec = hexdecode($avi_id);
       
  2055   $avi_id_dec = @unpack('Vdate/Vuid/vimg_type', $avi_id_dec);
       
  2056   if ( !$avi_id_dec )
       
  2057   {
       
  2058     echo 'Bad unpack';
       
  2059     return true;
       
  2060   }
       
  2061   
       
  2062   // check parameters
       
  2063   if ( !isset($img_types[$avi_id_dec['img_type']]) )
       
  2064   {
       
  2065     echo 'Invalid image type';
       
  2066     return true;
       
  2067   }
       
  2068   
       
  2069   // build file path
       
  2070   $avi_type = $img_types[$avi_id_dec['img_type']];
       
  2071   $avi_path = ENANO_ROOT . '/' . getConfig('avatar_directory') . '/' . $avi_id_dec['uid'] . '.' . $avi_type;
       
  2072   if ( file_exists($avi_path) )
       
  2073   {
       
  2074     $avi_mod_time = @filemtime($avi_path);
       
  2075     $avi_mod_time = date('r', $avi_mod_time);
       
  2076     $avi_size = @filesize($avi_path);
       
  2077     header("Last-Modified: $avi_mod_time");
       
  2078     header("Content-Length: $avi_size");
       
  2079     header("Content-Type: image/$avi_type");
       
  2080     // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
       
  2081     header("Cache-Control: public");
       
  2082     
       
  2083     $fh = @fopen($avi_path, 'r');
       
  2084     if ( !$fh )
       
  2085     {
       
  2086       echo 'Could not open file';
       
  2087       return true;
       
  2088     }
       
  2089     
       
  2090     while ( $fd = @fread($fh, 1024) )
       
  2091     {
       
  2092       echo $fd;
       
  2093     }
       
  2094     fclose($fh);
       
  2095     
       
  2096     gzip_output();
       
  2097     
       
  2098     return true;
       
  2099   }
       
  2100   return true;
       
  2101 }
       
  2102 
  2024 ?>
  2103 ?>