/system/application/controllers/admin/media.php

https://github.com/geekbuntu/Microweber · PHP · 465 lines · 249 code · 126 blank · 90 comment · 54 complexity · 349216897b2ebb5adcf166dc60bb67f1 MD5 · raw file

  1. <?php
  2. class Media extends Controller {
  3. function __construct() {
  4. parent::Controller ();
  5. require_once (APPPATH . 'controllers/default_constructor.php');
  6. require_once (APPPATH . 'controllers/admin/default_constructor.php');
  7. }
  8. function index() {
  9. exit ( 'Media manager is not yet fully ready! Write us at info@ooyes.net with request!' );
  10. }
  11. function reorderMedia() {
  12. $positions = $_POST ['gallery_module_sortable_pics_positions'];
  13. if (! empty ( $positions )) {
  14. CI::model('core')->mediaReOrder ( $positions );
  15. }
  16. exit ();
  17. }
  18. function mediaDelete() {
  19. $id = $_POST ['id'];
  20. if (intval ( $id ) != 0) {
  21. CI::model('core')->mediaDelete ( $id );
  22. }
  23. exit ();
  24. }
  25. function mediaSave() {
  26. $id = $_POST ['id'];
  27. if (intval ( $id ) != 0) {
  28. CI::model('core')->mediaSave ( $_POST );
  29. }
  30. print intval ( $id );
  31. exit ();
  32. }
  33. /**
  34. * @desc Upload pictures
  35. * @author Peter Ivanov
  36. * @version 1.0
  37. * @since 1.0
  38. */
  39. function mediaUploadPictures() {
  40. if (! empty ( $_FILES )) {
  41. $queue_id = CI::model('core')->getParamFromURL ( 'queue_id' , $param_sub_position = false, $skip_ajax = true);
  42. $to_table = CI::model('core')->getParamFromURL ( 'to_table', $param_sub_position = false, $skip_ajax = true );
  43. $to_table_id = CI::model('core')->getParamFromURL ( 'to_table_id', $param_sub_position = false, $skip_ajax = true );
  44. if (strval ( $to_table ) == '') {
  45. exit ( 'Error: please give me the $to_table var in the URL' );
  46. }
  47. if (intval ( $to_table_id ) != 0) {
  48. $queue_id = false;
  49. }
  50. CI::model('core')->mediaUploadPictures ( $to_table, $to_table_id, $queue_id );
  51. //CI::model('core')->cacheDeleteAll();
  52. sleep ( 1 );
  53. echo 1;
  54. } else {
  55. echo "1";
  56. }
  57. exit ();
  58. }
  59. function mediaUploadFilesIframe() {
  60. $queue_id = CI::model('core')->getParamFromURL ( 'queue_id' , $param_sub_position = false, $skip_ajax = true);
  61. $to_table = CI::model('core')->getParamFromURL ( 'to_table' , $param_sub_position = false, $skip_ajax = true);
  62. $to_table_id = CI::model('core')->getParamFromURL ( 'to_table_id' , $param_sub_position = false, $skip_ajax = true);
  63. $this->template ['queue_id'] = $queue_id;
  64. $this->template ['to_table'] = $to_table;
  65. $this->template ['to_table_id'] = $to_table_id;
  66. //var_dump ( $media2 );
  67. //$medias = array_merge ( $media1, $media2 );
  68. //var_dump($medias);
  69. //$this->template ['medias'] = $medias;
  70. $this->load->vars ( $this->template );
  71. $layout = CI::view ( 'admin/media/fileUploadIframe.php', true, true );
  72. //CI::library('output')->set_output ( $layout );
  73. exit ( $layout );
  74. }
  75. function mediaUploadPicturesIframe() {
  76. $queue_id = CI::model('core')->getParamFromURL ( 'queue_id' , $param_sub_position = false, $skip_ajax = true);
  77. $to_table = CI::model('core')->getParamFromURL ( 'to_table', $param_sub_position = false, $skip_ajax = true );
  78. $to_table_id = CI::model('core')->getParamFromURL ( 'to_table_id', $param_sub_position = false, $skip_ajax = true );
  79. //P($queue_id);
  80. $this->template ['queue_id'] = $queue_id;
  81. $this->template ['to_table'] = $to_table;
  82. $this->template ['to_table_id'] = $to_table_id;
  83. $this->load->vars ( $this->template );
  84. $layout = CI::view ( 'admin/media/picUploadIframe.php', true, true );
  85. //CI::library('output')->set_output ( $layout );
  86. exit ( $layout );
  87. }
  88. function mediaUploadVideosIframe() {
  89. $queue_id = CI::model('core')->getParamFromURL ( 'queue_id', $param_sub_position = false, $skip_ajax = true );
  90. $to_table = CI::model('core')->getParamFromURL ( 'to_table', $param_sub_position = false, $skip_ajax = true );
  91. $to_table_id = CI::model('core')->getParamFromURL ( 'to_table_id', $param_sub_position = false, $skip_ajax = true );
  92. $this->template ['queue_id'] = $queue_id;
  93. $this->template ['to_table'] = $to_table;
  94. $this->template ['to_table_id'] = $to_table_id;
  95. //var_dump ( $media2 );
  96. //$medias = array_merge ( $media1, $media2 );
  97. //var_dump($medias);
  98. //$this->template ['medias'] = $medias;
  99. $this->load->vars ( $this->template );
  100. $layout = CI::view ( 'admin/media/videoUploadIframe.php', true, true );
  101. //CI::library('output')->set_output ( $layout );
  102. exit ( $layout );
  103. }
  104. /**
  105. * @desc Upload videos
  106. * @author Peter Ivanov
  107. * @version 1.0
  108. * @since 1.0
  109. */
  110. function mediaUploadFiles() {
  111. //var_dump ( $_FILES );
  112. if (! empty ( $_FILES )) {
  113. if ($_FILES ["file"] ["error"] > 0) {
  114. echo "Return Code: " . $_FILES ["file"] ["error"] . "<br />";
  115. }
  116. $queue_id = CI::model('core')->getParamFromURL ( 'queue_id', $param_sub_position = false, $skip_ajax = true );
  117. $to_table = CI::model('core')->getParamFromURL ( 'to_table', $param_sub_position = false, $skip_ajax = true );
  118. $to_table_id = CI::model('core')->getParamFromURL ( 'to_table_id', $param_sub_position = false, $skip_ajax = true );
  119. if (strval ( $to_table ) == '') {
  120. exit ( 'Error: please give me the $to_table var in the URL' );
  121. }
  122. if (intval ( $to_table_id ) != 0) {
  123. $queue_id = false;
  124. }
  125. // var_dump( $to_table, $to_table_id, $queue_id);
  126. CI::model('core')->mediaUploadFiles ( $to_table, $to_table_id, $queue_id );
  127. CI::model('core')->cacheDeleteAll ();
  128. //exit ( 1 );
  129. } else {
  130. //echo "1";
  131. exit ();
  132. }
  133. exit ();
  134. //exit ( 'ok' );
  135. }
  136. /**
  137. * @desc Upload videos
  138. * @author Peter Ivanov
  139. * @version 1.0
  140. * @since 1.0
  141. */
  142. function mediaUploadVideos() {
  143. //var_dump ( $_FILES );
  144. if (! empty ( $_FILES )) {
  145. if ($_FILES ["file"] ["error"] > 0) {
  146. echo "Return Code: " . $_FILES ["file"] ["error"] . "<br />";
  147. }
  148. $queue_id = CI::model('core')->getParamFromURL ( 'queue_id', $param_sub_position = false, $skip_ajax = true );
  149. $to_table = CI::model('core')->getParamFromURL ( 'to_table' , $param_sub_position = false, $skip_ajax = true);
  150. $to_table_id = CI::model('core')->getParamFromURL ( 'to_table_id', $param_sub_position = false, $skip_ajax = true );
  151. if (strval ( $to_table ) == '') {
  152. exit ( 'Error: please give me the $to_table var in the URL' );
  153. }
  154. if (intval ( $to_table_id ) != 0) {
  155. $queue_id = false;
  156. }
  157. // var_dump( $to_table, $to_table_id, $queue_id);
  158. CI::model('core')->mediaUploadVideos ( $to_table, $to_table_id, $queue_id );
  159. CI::model('core')->cacheDeleteAll ();
  160. //exit ( 1 );
  161. } else {
  162. //echo "1";
  163. exit ();
  164. }
  165. exit ();
  166. //exit ( 'ok' );
  167. }
  168. function contentMediaPicturesList() {
  169. $this->template ['functionName'] = strtolower ( __FUNCTION__ );
  170. $queue_id = CI::model('core')->getParamFromURL ( 'queue_id', false, true );
  171. $to_table = CI::model('core')->getParamFromURL ( 'to_table', false, true );
  172. $to_table_id = CI::model('core')->getParamFromURL ( 'to_table_id', false, true );
  173. //var_Dump($to_table_id);
  174. // var_dump($queue_id,$to_table,$to_table_id);
  175. if ($queue_id != false) {
  176. $media1 = CI::model('core')->mediaGet ( $to_table, false, $media_type = 'picture', $order = "ASC", $queue_id, $no_cache = true, false );
  177. $this->template ['media1'] = $media1 ['pictures'];
  178. }
  179. // var_dump ( $media1 );
  180. if ($to_table_id != false) {
  181. $media2 = CI::model('core')->mediaGet ( $to_table, $to_table_id, $media_type = 'picture', $order = "ASC", $queue_id = false, $no_cache = true, false );
  182. $this->template ['media2'] = $media2 ['pictures'];
  183. }
  184. $this->load->vars ( $this->template );
  185. $try_view = TEMPLATE_DIR . 'admin/media/contentMediaPicturesList.php';
  186. //var_dump($try_view);
  187. if (is_file ( $try_view ) and is_readable ( $try_view )) {
  188. //$primarycontent = CI::view ( $try_view, true, true );
  189. $layout = $this->load->file ( $try_view, true );
  190. if (trim ( $layout ) == '') {
  191. print 'admin/media/contentMediaPicturesList';
  192. $layout = CI::view ( 'admin/media/contentMediaPicturesList', true, true );
  193. } else {
  194. var_dump ( $try_view );
  195. }
  196. } else {
  197. $layout = CI::view ( 'admin/media/contentMediaPicturesList', true, true );
  198. // var_dump('asd');
  199. }
  200. //CI::library('output')->set_output ( $layout );
  201. exit ( $layout );
  202. }
  203. function contentMediaFilesList() {
  204. $this->template ['functionName'] = strtolower ( __FUNCTION__ );
  205. global $cms_db_tables;
  206. $table = $cms_db_tables ['table_media'];
  207. $queue_id = CI::model('core')->getParamFromURL ( 'queue_id', false, true );
  208. $to_table = CI::model('core')->getParamFromURL ( 'to_table' , false, true);
  209. $to_table_id = CI::model('core')->getParamFromURL ( 'to_table_id', false, true );
  210. //var_dump($queue_id,$to_table,$to_table_id);
  211. //var_dump($_REQUEST);
  212. //p($q);
  213. if (strval ( trim ( $queue_id ) != '' )) {
  214. $q = "SELECT id FROM $table WHERE to_table = '$to_table' AND queue_id = '$queue_id'
  215. AND media_type = 'file'
  216. AND to_table_id IS NULL AND ID is not null ORDER BY media_order";
  217. $q = CI::model('core')->dbQuery ( $q );
  218. $ids = CI::model('core')->dbExtractIdsFromArray ( $q );
  219. if (! empty ( $ids )) {
  220. $media_get = array ();
  221. $media_get ['queue_id'] = trim ( $queue_id );
  222. $media_get ['to_table'] = $to_table;
  223. //$media_get ['to_table_id'] = $to_table_id;
  224. $media1 = CI::model('core')->mediaGet2 ( false, false, $ids );
  225. //p($media1);
  226. $this->template ['files'] = $media1 ['files'];
  227. }
  228. } else {
  229. $media1 = array ();
  230. }
  231. //var_dump ( $media1 );
  232. if (intval ( $to_table_id ) != 0) {
  233. $media_get = array ();
  234. //$media_get ['queue_id'] = $queue_id;
  235. $media_get ['to_table'] = $to_table;
  236. $media_get ['to_table_id'] = $to_table_id;
  237. $q = "SELECT id FROM $table WHERE to_table = '$to_table'
  238. AND media_type = 'file' and
  239. to_table_id = '$to_table_id' AND ID is not null ORDER BY media_order";
  240. //var_dump($q);
  241. $q = CI::model('core')->dbQuery ( $q );
  242. $ids = CI::model('core')->dbExtractIdsFromArray ( $q );
  243. if (! empty ( $ids )) {
  244. $media2 = CI::model('core')->mediaGet2 ( false, false, $ids );
  245. //p($media2);
  246. $this->template ['files'] = $media2 ['files'];
  247. }
  248. } else {
  249. $media2 = array ();
  250. }
  251. //var_dump ( $media2 );
  252. //var_dump ( $media1 );
  253. if (! empty ( $media1 )) {
  254. //$media1 = $media1 ['videos'];
  255. }
  256. if (! empty ( $media2 )) {
  257. //$media2 = $media2 ['videos'];
  258. }
  259. //var_dump( $media1, $media2);
  260. $videos = @array_merge ( $media1, $media2 );
  261. //var_dump ( $videos );
  262. $videos = $videos ['files'];
  263. //@array_unique ( $videos );
  264. //$this->template ['videos'] = $videos;
  265. //$medias = array_merge ( $media1, $media2 );
  266. //var_dump($medias);
  267. //$this->template ['medias'] = $medias;
  268. $this->load->vars ( $this->template );
  269. $layout = CI::view ( 'admin/media/contentMediaFilesList', true, true );
  270. //CI::library('output')->set_output ( $layout );
  271. exit ( $layout );
  272. }
  273. function contentMediaVideosList() {
  274. $this->template ['functionName'] = strtolower ( __FUNCTION__ );
  275. global $cms_db_tables;
  276. $table = $cms_db_tables ['table_media'];
  277. $queue_id = CI::model('core')->getParamFromURL ( 'queue_id', false, true );
  278. $to_table = CI::model('core')->getParamFromURL ( 'to_table', false, true );
  279. $to_table_id = CI::model('core')->getParamFromURL ( 'to_table_id', false, true );
  280. //var_dump($queue_id,$to_table,$to_table_id);
  281. //p($q);
  282. if (strval ( trim ( $queue_id ) != '' )) {
  283. $q = "SELECT id FROM $table WHERE to_table = '$to_table' AND queue_id = '$queue_id' AND to_table_id IS NULL AND ID is not null ORDER BY media_order";
  284. $q = CI::model('core')->dbQuery ( $q );
  285. $ids = CI::model('core')->dbExtractIdsFromArray ( $q );
  286. if (! empty ( $ids )) {
  287. $media_get = array ();
  288. $media_get ['queue_id'] = trim ( $queue_id );
  289. $media_get ['to_table'] = $to_table;
  290. //$media_get ['to_table_id'] = $to_table_id;
  291. $media1 = CI::model('core')->mediaGet2 ( false, false, $ids );
  292. //p($media1);
  293. $this->template ['videos'] = $media1 ['videos'];
  294. }
  295. } else {
  296. $media1 = array ();
  297. }
  298. //var_dump ( $media1 );
  299. if (intval ( $to_table_id ) != 0) {
  300. $media_get = array ();
  301. //$media_get ['queue_id'] = $queue_id;
  302. $media_get ['to_table'] = $to_table;
  303. $media_get ['to_table_id'] = $to_table_id;
  304. $q = "SELECT id FROM $table WHERE to_table = '$to_table' AND to_table_id = '$to_table_id' AND ID is not null ORDER BY media_order";
  305. $q = CI::model('core')->dbQuery ( $q );
  306. $ids = CI::model('core')->dbExtractIdsFromArray ( $q );
  307. if (! empty ( $ids )) {
  308. $media2 = CI::model('core')->mediaGet2 ( false, false, $ids );
  309. //p($media2);
  310. $this->template ['videos'] = $media2 ['videos'];
  311. }
  312. } else {
  313. $media2 = array ();
  314. }
  315. //var_dump ( $media2 );
  316. //var_dump ( $media1 );
  317. if (! empty ( $media1 )) {
  318. //$media1 = $media1 ['videos'];
  319. }
  320. if (! empty ( $media2 )) {
  321. //$media2 = $media2 ['videos'];
  322. }
  323. //var_dump( $media1, $media2);
  324. $videos = @array_merge ( $media1, $media2 );
  325. //var_dump ( $videos );
  326. $videos = $videos ['videos'];
  327. //@array_unique ( $videos );
  328. //$this->template ['videos'] = $videos;
  329. //$medias = array_merge ( $media1, $media2 );
  330. //var_dump($medias);
  331. //$this->template ['medias'] = $medias;
  332. $this->load->vars ( $this->template );
  333. $layout = CI::view ( 'admin/media/contentMediaVideosList', true, true );
  334. //CI::library('output')->set_output ( $layout );
  335. exit ( $layout );
  336. }
  337. }
  338. /* End of file welcome.php */
  339. /* Location: ./system/application/controllers/welcome.php */