api.avatars.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // Copyright (C) ReloadCMS Development Team //
  4. // http://reloadcms.sf.net //
  5. // //
  6. // This program is distributed in the hope that it will be useful, //
  7. // but WITHOUT ANY WARRANTY, without even the implied warranty of //
  8. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
  9. // //
  10. // This product released under GNU General Public License v2 //
  11. ////////////////////////////////////////////////////////////////////////////////
  12. //config section
  13. $config_avatars = parse_ini_file(CONFIG_PATH . 'avatars.ini');
  14. $avatars_enabled=parse_ini_file(CONFIG_PATH . 'disable.ini');
  15. $avatars_path=DATA_PATH.'avatars/';
  16. $avatar_h=$config_avatars['avatars_h'];
  17. $avatar_w=$config_avatars['avatars_w'];
  18. $avatar_size=$config_avatars['avatars_size'];
  19. //Avatars API functions
  20. //function thats shows avatars requitements
  21. function show_avatar_requirements()
  22. {
  23. global $avatars_path;
  24. global $avatar_h;
  25. global $avatar_w;
  26. global $avatar_size;
  27. $requirements=__('Your avatar must be less than ').$avatar_size.__(' bytes in size'). __(', have resolution at ').$avatar_w.'x'.$avatar_h.__(' and type png, jpg or gif');
  28. return $requirements;
  29. }
  30. // function to show avatar for such user
  31. function show_avatar($user)
  32. {
  33. global $avatars_path;
  34. global $avatar_h;
  35. global $avatar_w;
  36. global $avatars_enabled;
  37. $result='';
  38. if (file_exists($avatars_path.$user.'.img'))
  39. {
  40. $result='<img src="'.$avatars_path.$user.'.img">';
  41. }
  42. if (!file_exists($avatars_path.$user.'.img'))
  43. {
  44. $result='<img src="'.$avatars_path.'noavatar.img">';
  45. }
  46. if ($user=="guest")
  47. {
  48. $result="";
  49. }
  50. if (isset($avatars_enabled['avatar.control'])) {
  51. $result="";
  52. }
  53. return $result;
  54. }
  55. // function to upload avatar
  56. function upload_avatar()
  57. {
  58. global $avatars_path;
  59. global $system;
  60. global $avatar_h;
  61. global $avatar_w;
  62. if ((isset($_POST['upload_avatar'])) AND ($_POST['upload_avatar']=="true") AND (is_images($_FILES['avatar']['name'])))
  63. {
  64. $avarez=getimagesize($_FILES['avatar']['tmp_name']);
  65. $uploadfile = $avatars_path . $system->user['username'].'.img';
  66. if (($avarez[0]<="$avatar_w") AND ($avarez[1]<="$avatar_h")) {
  67. if ((move_uploaded_file($_FILES['avatar']['tmp_name'], $uploadfile))) {
  68. show_window(__('Result'),__('Avatar filesucefully uploaded'),'center');
  69. $config_ext = parse_ini_file(CONFIG_PATH . 'adminpanel.ini');
  70. if($config_ext['chmod_on']) {
  71. chmod($uploadfile, octdec($config_ext['chmod']));
  72. }
  73. return $_FILES['avatar']['name'];
  74. }
  75. }
  76. else {
  77. show_window(__('Result'),__('Your avatar don\'t meet our requirements'),'center');
  78. }
  79. }
  80. }
  81. // Function that shows form to upload avatar
  82. function avatar_upload_box()
  83. {
  84. global $avatar_size;
  85. $form='<form enctype="multipart/form-data" action="" method="POST">
  86. <input type="hidden" name="upload_avatar" value="true">
  87. <input type="hidden" name="MAX_FILE_SIZE" value="'.$avatar_size.'" />
  88. '.__('Select avatar from your HDD').': <input name="avatar" type="file"/>
  89. <input type="submit" value="'.__('Upload avatar').'" />
  90. </form>';
  91. return $form;
  92. }
  93. //function for check image type
  94. // NB: ôóíêöèÿ âîáùå ñòðåìíàÿ íàäî áóäåò íà äîñóãå ïåðåïèñàòü, íî ëîìàåò ñòðàøíî
  95. function is_images($filename)
  96. {
  97. $ext=strtolower(substr(strrev($filename),0,4));
  98. if (($ext=='gpj.') OR ($ext=='gnp.') OR ($ext=='fig.') OR ($ext=='gepj'))
  99. {
  100. return true;
  101. }
  102. else
  103. {
  104. show_window(__('Error'),'<center><b>'.__('Your avatar is not an image or is corrupted').'</b></center>');
  105. return false;
  106. }
  107. }
  108. ?>