Source for file api.avatars.php

Documentation is available at api.avatars.php

  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.  
  14. $config_avatars = parse_ini_file(CONFIG_PATH . 'avatars.ini');
  15. $avatars_enabled=parse_ini_file(CONFIG_PATH . 'disable.ini');
  16. $avatars_path=DATA_PATH.'avatars/';
  17. $avatar_h=$config_avatars['avatars_h'];
  18. $avatar_w=$config_avatars['avatars_w'];
  19. $avatar_size=$config_avatars['avatars_size'];
  20. //Avatars API functions
  21. //function thats shows avatars requitements
  22.  
  23. function show_avatar_requirements()
  24. {
  25. global $avatars_path;
  26. global $avatar_h;
  27. global $avatar_w;
  28. global $avatar_size;
  29. $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');
  30. return $requirements;
  31. }
  32. // function to show avatar for such user
  33. function show_avatar($user)
  34. {
  35. global $avatars_path;
  36. global $avatar_h;
  37. global $avatar_w;
  38. global $avatars_enabled;
  39. $result='';
  40. if (file_exists($avatars_path.$user.'.img'))
  41. {
  42. $result='<img src="'.$avatars_path.$user.'.img">';
  43. }
  44. if (!file_exists($avatars_path.$user.'.img'))
  45. {
  46. $result='<img src="'.$avatars_path.'noavatar.img">';
  47. }
  48.  
  49. if ($user=="guest")
  50. {
  51. $result="";
  52. }
  53.  
  54. if (isset($avatars_enabled['avatar.control'])) {
  55. $result="";
  56. }
  57.  
  58. return $result;
  59. }
  60. // function to upload avatar
  61. function upload_avatar()
  62. {
  63. global $avatars_path;
  64. global $system;
  65. global $avatar_h;
  66. global $avatar_w;
  67. if ((isset($_POST['upload_avatar'])) AND ($_POST['upload_avatar']=="true") AND (is_images($_FILES['avatar']['name'])))
  68. {
  69. $avarez=getimagesize($_FILES['avatar']['tmp_name']);
  70. $uploadfile = $avatars_path . $system->user['username'].'.img';
  71. if (($avarez[0]<="$avatar_w") AND ($avarez[1]<="$avatar_h")) {
  72. if ((move_uploaded_file($_FILES['avatar']['tmp_name'], $uploadfile))) {
  73. show_window(__('Result'),__('Avatar filesucefully uploaded'),'center');
  74. $config_ext = parse_ini_file(CONFIG_PATH . 'adminpanel.ini');
  75. if($config_ext['chmod_on']) {
  76. chmod($uploadfile, octdec($config_ext['chmod']));
  77. }
  78. return $_FILES['avatar']['name'];
  79. }
  80. }
  81. else {
  82. show_window(__('Result'),__('Your avatar don\'t meet our requirements'),'center');
  83. }
  84. }
  85. }
  86. // Function that shows form to upload avatar
  87. function avatar_upload_box()
  88. {
  89. global $avatar_size;
  90. $form='<form enctype="multipart/form-data" action="" method="POST">
  91. <input type="hidden" name="upload_avatar" value="true">
  92. <input type="hidden" name="MAX_FILE_SIZE" value="'.$avatar_size.'" />
  93. '.__('Select avatar from your HDD').': <input name="avatar" type="file"/>
  94. <input type="submit" value="'.__('Upload avatar').'" />
  95. </form>';
  96. return $form;
  97. }
  98. //function for check image type
  99. // NB: функция вобще стремная надо будет на досуге переписать, но ломает страшно
  100.  
  101. function is_images($filename)
  102. {
  103. $ext=strtolower(substr(strrev($filename),0,4));
  104. if (($ext=='gpj.') OR ($ext=='gnp.') OR ($ext=='fig.') OR ($ext=='gepj'))
  105. {
  106. return true;
  107. }
  108. else
  109. {
  110. show_window(__('Error'),'<center><b>'.__('Your avatar is not an image or is corrupted').'</b></center>');
  111. return false;
  112. }
  113. }
  114.  
  115. ?>

Documentation generated on Fri, 08 Jun 2007 12:21:17 +0300 by phpDocumentor 1.3.0RC3