Sketch.class.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Define a sketch.
  4. * @author Idleman
  5. * @category Plugin
  6. * @license copyright
  7. */
  8. class Sketch extends Entity{
  9. public $id,$label,$state,$comment,$slug;
  10. protected $TABLE_NAME = 'hackpoint_sketch';
  11. public $fields =
  12. array(
  13. 'id' => 'key',
  14. 'label' => 'string',
  15. 'state' => 'string',
  16. 'comment' => 'longstring',
  17. 'slug' => 'string'
  18. );
  19. public $links = array(
  20. );
  21. public function picture(){
  22. $folder = $this->directory();
  23. if(!file_exists($folder)) mkdir($folder,0755,true);
  24. $picture = $folder.SLASH.'cover.jpg';
  25. if(!file_exists($picture)){
  26. copy(__DIR__.SLASH.'img'.SLASH.'default-sketch.png',$picture);
  27. }
  28. return 'action.php?action=hackpoint_download_file&file='.base64_encode('sketch'.SLASH.$this->id.SLASH.'cover.jpg');
  29. }
  30. public function directory(){
  31. return File::dir().'hackpoint'.SLASH.'sketch'.SLASH.$this->id;
  32. }
  33. public function save()
  34. {
  35. if ($this->id == 0) {
  36. $this->slug = slugify($this->label);
  37. }
  38. parent::save();
  39. }
  40. public static function removeById($id){
  41. require_once(__DIR__.SLASH.'Resource.class.php');
  42. $sketch = self::getById($id);
  43. self::deleteById($sketch->id);
  44. Resource::delete(array('sketch'=>$sketch->id));
  45. if(file_exists($sketch->directory())) delete_folder_tree($sketch->directory(),true);
  46. }
  47. }
  48. ?>