Type.class.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Declare available resource types
  4. * @author valentin carruesco
  5. * @category Core
  6. * @license copyright
  7. */
  8. class Type{
  9. public static function get($uid){
  10. $t = Type::all();
  11. return $t[$uid];
  12. }
  13. public static function all(){
  14. $types = array();
  15. $types['readme'] = array(
  16. 'label' => 'README',
  17. 'extension' => 'md',
  18. 'codemirror' => array(
  19. 'smartIndent' => false,
  20. 'readOnly' => false
  21. )
  22. );
  23. $types['arduino'] = array(
  24. 'label' => 'Source Arduino',
  25. 'extension' => 'ino',
  26. 'codemirror' => array(
  27. 'mode'=>'clike',
  28. 'theme'=>'monokai',
  29. 'lineNumbers' => true,
  30. 'readOnly' => false
  31. )
  32. );
  33. $types['php'] = array(
  34. 'label' => 'Source PHP',
  35. 'extension' => 'php',
  36. 'codemirror' => array(
  37. 'mode'=>'php',
  38. 'theme'=>'monokai',
  39. 'lineNumbers' => true,
  40. 'readOnly' => false
  41. )
  42. );
  43. $types['python'] = array(
  44. 'label' => 'Source Python',
  45. 'extension' => 'py',
  46. 'codemirror' => array(
  47. 'mode'=>'python',
  48. 'theme'=>'monokai',
  49. 'lineNumbers' => true,
  50. 'readOnly' => false
  51. )
  52. );
  53. $types['c'] = array(
  54. 'label' => 'Source C++',
  55. 'extension' => '.cpp',
  56. 'codemirror' => array(
  57. 'mode'=>'clike',
  58. 'theme'=>'monokai',
  59. 'lineNumbers' => true,
  60. 'readOnly' => false
  61. )
  62. );
  63. $types['java'] = array(
  64. 'label' => 'Source JAVA',
  65. 'extension' => '.java',
  66. 'codemirror' => array(
  67. 'mode'=>'java',
  68. 'theme'=>'monokai',
  69. 'lineNumbers' => true,
  70. 'readOnly' => false
  71. )
  72. );
  73. $types['image'] = array(
  74. 'label' => 'Image',
  75. 'upload' => array()
  76. );
  77. $types['part'] = array(
  78. 'label' => 'Set de composants',
  79. 'extension' => 'part'
  80. );
  81. return $types;
  82. }
  83. public static function toFileStream($resource){
  84. $type = self::get($resource->type);
  85. $file = (object) array('name'=>slugify($resource->label),'content'=>'');
  86. if(isset($type['extension'])) $file->name .= '.'.$type['extension'];
  87. switch($resource->type){
  88. case 'part':
  89. $file->content = '> '.strtoupper($resource->label).PHP_EOL;
  90. $file->content .= str_repeat('=',strlen($resource->label)+2).PHP_EOL;
  91. foreach(ResourcePart::loadAll(array('resource'=>$resource->id)) as $resourcePart):
  92. $part = $resourcePart->part_object;
  93. $file->content .= $part->label."\t";
  94. if(isset($part->link) && !empty($part->link)) $file->content .= $part->link."\t";
  95. if(isset($part->price) && !empty($part->price)) $file->content .= $part->price.'€'.PHP_EOL;
  96. endforeach;
  97. break;
  98. case 'image':
  99. $ext = getExt($resource->content);
  100. $file->name = slugify($resource->label).'.'.$ext;
  101. $file->content = file_get_contents(SKETCH_PATH.$resource->content);
  102. break;
  103. default:
  104. $file->content = html_entity_decode($resource->content);
  105. break;
  106. }
  107. return $file;
  108. }
  109. }
  110. ?>