OpenClassroomsBridge.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. class OpenClassroomsBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "sebsauvage";
  5. $this->name = "OpenClassrooms Bridge";
  6. $this->uri = "https://openclassrooms.com/";
  7. $this->description = "Returns latest tutorials from OpenClassrooms.";
  8. $this->update = "2015-10-30";
  9. $this->parameters[] =
  10. '[
  11. {
  12. "name" : "Catégorie",
  13. "identifier" : "u",
  14. "type" : "list",
  15. "values" : [
  16. {
  17. "name" : "Arts & Culture",
  18. "value" : "arts"
  19. },
  20. {
  21. "name" : "Code",
  22. "value" : "code"
  23. },
  24. {
  25. "name" : "Design",
  26. "value" : "design"
  27. },
  28. {
  29. "name" : "Entreprise",
  30. "value" : "business"
  31. },
  32. {
  33. "name" : "Numérique",
  34. "value" : "digital"
  35. },
  36. {
  37. "name" : "Sciences",
  38. "value" : "sciences"
  39. },
  40. {
  41. "name" : "Sciences Humaines",
  42. "value" : "humainities"
  43. },
  44. {
  45. "name" : "Systèmes d\'information",
  46. "value" : "it"
  47. },
  48. {
  49. "name" : "Autres",
  50. "value" : "others"
  51. }
  52. ]
  53. }
  54. ]';
  55. }
  56. public function collectData(array $param){
  57. if (empty($param['u']))
  58. {
  59. $this->returnError('Error: You must chose a category.', 404);
  60. }
  61. $html = '';
  62. $link = 'https://openclassrooms.com/courses?categories='.$param['u'].'&title=&sort=updatedAt+desc';
  63. $html = $this->file_get_html($link) or $this->returnError('Could not request OpenClassrooms.', 404);
  64. foreach($html->find('.courseListItem') as $element) {
  65. $item = new \Item();
  66. $item->uri = 'https://openclassrooms.com'.$element->find('a', 0)->href;
  67. $item->title = $element->find('h3', 0)->plaintext;
  68. $item->content = $element->find('slidingItem__descriptionContent', 0)->plaintext;
  69. $this->items[] = $item;
  70. }
  71. }
  72. public function getName(){
  73. return 'OpenClassrooms';
  74. }
  75. public function getURI(){
  76. return 'https://openclassrooms.com/';
  77. }
  78. public function getCacheDuration(){
  79. return 21600; // 6 hours
  80. }
  81. }