PageRenderTime 81ms CodeModel.GetById 25ms RepoModel.GetById 2ms app.codeStats 0ms

/Controller/WallpapersController.php

https://github.com/Wargo/reddevil
PHP | 108 lines | 81 code | 27 blank | 0 comment | 17 complexity | bcd921f2328bd658bedab0aaddc418cd MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. class WallpapersController extends AppController {
  3. function admin_index() {
  4. $wallpapers = $this->Wallpaper->find('all');
  5. $this->set(compact('wallpapers'));
  6. }
  7. function admin_edit($id = null) {
  8. if ($this->request->data) {
  9. if ($id) {
  10. $this->Wallpaper->id = $id;
  11. } else {
  12. $this->Wallpaper->create();
  13. }
  14. $avatar = (!empty($this->request->data['Wallpaper']['avatar']))?$this->request->data['Wallpaper']['avatar']:'placeholder';
  15. if (!empty($_FILES['data']['name']['Wallpaper']['file'])) {
  16. if ($avatar == 'placeholder') {
  17. $avatar = String::uuid();
  18. $this->request->data['Wallpaper']['avatar'] = $avatar;
  19. }
  20. $aux = explode('-', $avatar);
  21. $aux = substr($aux[1], 0, 3);
  22. if (!is_dir(APP . 'uploads' . DS . 'img' . DS . 'Wallpaper' . DS . $aux)) {
  23. mkdir(APP . 'uploads' . DS . 'img' . DS . 'Wallpaper' . DS . $aux);
  24. }
  25. exec('rm -f ' . WWW_ROOT . 'img' . DS . 'Wallpaper' . DS . $aux . DS . $avatar . '*');
  26. move_uploaded_file($_FILES['data']['tmp_name']['Wallpaper']['file'],
  27. APP . 'uploads' . DS . 'img' . DS . 'Wallpaper' . DS . $aux . DS . $avatar . '.jpg');
  28. }
  29. if (!empty($_FILES['data']['name']['Wallpaper']['file2'])) {
  30. if ($avatar == 'placeholder') {
  31. $avatar = String::uuid();
  32. $this->request->data['Wallpaper']['avatar'] = $avatar;
  33. }
  34. $aux = explode('-', $avatar);
  35. $aux = substr($aux[1], 0, 3);
  36. if (!is_dir(APP . 'uploads' . DS . 'img' . DS . 'Wallpaper2' . DS . $aux)) {
  37. mkdir(APP . 'uploads' . DS . 'img' . DS . 'Wallpaper2' . DS . $aux);
  38. }
  39. exec('rm -f ' . WWW_ROOT . 'img' . DS . 'Wallpaper2' . DS . $aux . DS . $avatar . '*');
  40. move_uploaded_file($_FILES['data']['tmp_name']['Wallpaper']['file2'],
  41. APP . 'uploads' . DS . 'img' . DS . 'Wallpaper2' . DS . $aux . DS . $avatar . '.jpg');
  42. }
  43. if (!empty($_FILES['data']['name']['Wallpaper']['file3'])) {
  44. if ($avatar == 'placeholder') {
  45. $avatar = String::uuid();
  46. $this->request->data['Wallpaper']['avatar'] = $avatar;
  47. }
  48. $aux = explode('-', $avatar);
  49. $aux = substr($aux[1], 0, 3);
  50. if (!is_dir(APP . 'uploads' . DS . 'img' . DS . 'bg' . DS . $aux)) {
  51. mkdir(APP . 'uploads' . DS . 'img' . DS . 'bg' . DS . $aux);
  52. }
  53. exec('rm -f ' . WWW_ROOT . 'img' . DS . 'bg' . DS . $aux . DS . $avatar . '*');
  54. move_uploaded_file($_FILES['data']['tmp_name']['Wallpaper']['file3'],
  55. APP . 'uploads' . DS . 'img' . DS . 'bg' . DS . $aux . DS . $avatar . '.jpg');
  56. }
  57. $this->Wallpaper->save($this->request->data);
  58. return $this->redirect(array('action' => 'index'));
  59. }
  60. if ($id) {
  61. $this->request->data = $this->Wallpaper->findById($id);
  62. }
  63. $this->loadModel('Video');
  64. $conditions = array('active' => 1);
  65. $order = array('title' => 'asc');
  66. $videos = $this->Video->find('list', compact('order', 'conditions'));
  67. $this->set(compact('id', 'videos'));
  68. }
  69. function admin_delete($id = null) {
  70. if ($id) {
  71. $this->Wallpaper->delete($id);
  72. }
  73. return $this->redirect('index');
  74. }
  75. function admin_active($id) {
  76. $this->Wallpaper->updateAll(array('active' => 0));
  77. $this->Wallpaper->id = $id;
  78. $this->Wallpaper->save(array('active' => 1));
  79. return $this->redirect(array('action' => 'index'));
  80. }
  81. }