Contact.class.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. class Contact extends Entity{
  3. public $id,$label,$phone,$birth,$hour,$author,$address,$vehicle,$story,$login,$password,$icon;
  4. protected $TABLE_NAME = 'plugin_contact';
  5. public $fields =
  6. array(
  7. 'id' => 'key',
  8. 'label' => 'string',
  9. 'phone' => 'string',
  10. 'birth' => 'date',
  11. 'hour' => 'date',
  12. 'author' => 'string',
  13. 'address' => 'string',
  14. 'vehicle' => 'int',
  15. 'story' => 'longstring',
  16. 'login' => 'string',
  17. 'password' => 'string',
  18. 'icon'=>'string'
  19. );
  20. function picture(){
  21. return $this->get_image();
  22. }
  23. function get_image($key=null){
  24. $finded = false;
  25. $image = array();
  26. $paths = array(
  27. 'jpg' => FILE_PATH.'contact'.SLASH.$this->id.'.jpg',
  28. 'png' => FILE_PATH.'contact'.SLASH.$this->id.'.png',
  29. 'jpeg' => FILE_PATH.'contact'.SLASH.$this->id.'.jpeg',
  30. );
  31. $image['url'] = 'action.php?action=contact_download_picture&contact='.$this->id.'&extension=png';
  32. foreach ($paths as $extension => $path) {
  33. if (!file_exists( __ROOT__.$path) && !$finded) {
  34. $image['path'] = __ROOT__.'img'.SLASH.'default-avatar.png';
  35. } else if (!$finded) {
  36. $image['path'] = __ROOT__.$path;
  37. $finded = true;
  38. $image['url'] = 'action.php?action=contact_download_picture&contact='.$this->id.'&extension='.$extension;
  39. }
  40. }
  41. return isset($key) && isset($image[$key]) ? $image[$key] : $image['url'];
  42. }
  43. function documents(){
  44. $documents = array();
  45. foreach(glob(__ROOT__.FILE_PATH.'contact'.SLASH.'documents'.SLASH.$this->id.SLASH.'*.*') as $file){
  46. if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $file = utf8_encode($file);
  47. $documents[] = array(
  48. 'path' => 'contact'.SLASH.'documents'.SLASH.$this->id.SLASH.basename($file),
  49. 'url' => 'action.php?action=contact_download_document&path='.$this->id.SLASH.rawurlencode(basename($file)),
  50. 'name' => basename($file),
  51. 'icon' => getExtIcon(getExt($file))
  52. );
  53. }
  54. return $documents;
  55. }
  56. }
  57. ?>