PageRenderTime 24ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/sources_custom/galleries2.php

https://github.com/chrisgraham/ocPortal
PHP | 339 lines | 303 code | 13 blank | 23 comment | 0 complexity | f44d74151d9565e5a0a1eedb44dc0de4 MD5 | raw file
  1. <?php /*
  2. ocPortal
  3. Copyright (c) ocProducts, 2004-2012
  4. See text/EN/licence.txt for full licencing information.
  5. */
  6. /**
  7. * @license http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
  8. * @copyright ocProducts Ltd
  9. * @package workflows
  10. */
  11. function init__galleries2($code)
  12. {
  13. // We want to inject our workflow handling code into add_image...
  14. $code=str_replace(
  15. 'log_it(\'ADD_IMAGE\',strval($id),$title);',
  16. '
  17. if ($validated==0)
  18. {
  19. require_code("workflows");
  20. require_lang("workflows");
  21. // See if we have a specific workflow to use
  22. $workflow_id=intval(str_replace("wf_","",either_param("workflow","wf_-1")));
  23. // If we have been given a specific workflow, but we do not have access to
  24. // choose workflows, fall back to the default
  25. if ($workflow_id != -1 && !can_choose_workflow())
  26. $workflow_id=-1;
  27. if ($workflow_id==-1)
  28. {
  29. // Look for the workflow of the containing gallery
  30. $workflow_id=get_workflow_of_content("gallery",$title);
  31. if (is_null($workflow_id))
  32. {
  33. // Use the default if it has none
  34. add_content_to_workflow("image",strval($id));
  35. attach_message(do_lang("CONTENT_NOW_IN_WORKFLOW",get_translated_text(get_default_workflow())),"inform");
  36. }
  37. else
  38. {
  39. // The parent has a workflow. Copy it for this.
  40. add_content_to_workflow("image",strval($id),$workflow_id);
  41. attach_message(do_lang("CONTENT_NOW_IN_WORKFLOW",get_translated_text($workflow_id)),"inform");
  42. }
  43. }
  44. else
  45. {
  46. // Use the specific ID provided
  47. add_content_to_workflow("image",strval($id),$workflow_id);
  48. attach_message(do_lang("CONTENT_NOW_IN_WORKFLOW",get_translated_text($workflow_id)),"inform");
  49. }
  50. log_it(\'ADD_IMAGE\',strval($id),$title);
  51. }
  52. ',
  53. $code
  54. );
  55. // ...and add_video...
  56. $code=str_replace(
  57. 'log_it(\'ADD_VIDEO\',strval($id),$title);',
  58. '
  59. if ($validated==0)
  60. {
  61. require_code("workflows");
  62. require_lang("workflows");
  63. // See if we have a specific workflow to use
  64. $workflow_id=intval(str_replace("wf_","",either_param("workflow","wf_-1")));
  65. // If we have been given a specific workflow, but we do not have access to
  66. // choose workflows, fall back to the default
  67. if ($workflow_id != -1 && !can_choose_workflow())
  68. $workflow_id=-1;
  69. if ($workflow_id==-1)
  70. {
  71. // Look for the workflow of the containing gallery
  72. $workflow_id=get_workflow_of_content("gallery",$title);
  73. if (is_null($workflow_id))
  74. {
  75. // Use the default if it has none
  76. add_content_to_workflow("video",strval($id));
  77. attach_message(do_lang("CONTENT_NOW_IN_WORKFLOW",get_translated_text(get_default_workflow())),"inform");
  78. }
  79. else
  80. {
  81. // The parent has a workflow. Copy it for this.
  82. add_content_to_workflow("video",strval($id),$workflow_id);
  83. attach_message(do_lang("CONTENT_NOW_IN_WORKFLOW",get_translated_text($workflow_id)),"inform");
  84. }
  85. }
  86. else
  87. {
  88. // Use the specific ID provided
  89. add_content_to_workflow("video",strval($id),$workflow_id);
  90. attach_message(do_lang("CONTENT_NOW_IN_WORKFLOW",get_translated_text($workflow_id)),"inform");
  91. }
  92. log_it(\'ADD_VIDEO\',strval($id),$title);
  93. }
  94. ',
  95. $code
  96. );
  97. // ...and add gallery...
  98. $code=str_replace('log_it(\'ADD_GALLERY\',$name,$fullname);',
  99. 'require_code("workflows");
  100. require_lang("workflows");
  101. // See if we have a specific workflow to use
  102. $workflow_id=intval(str_replace("wf_","",either_param("workflow","wf_-1")));
  103. // If we have been given a specific workflow, but we do not have access to
  104. // choose workflows, fall back to the default
  105. if ($workflow_id != -1 && !can_choose_workflow())
  106. $workflow_id=-1;
  107. if ($workflow_id==-1)
  108. {
  109. // Look for the workflow of the containing gallery
  110. $workflow_id=get_workflow_of_content("gallery",$parent_id);
  111. if (is_null($workflow_id))
  112. {
  113. // Use the default if it has none
  114. add_content_to_workflow("gallery",$name);
  115. }
  116. else
  117. {
  118. // The parent has a workflow. Copy it for this.
  119. add_content_to_workflow("gallery",$name,$workflow_id);
  120. }
  121. }
  122. else
  123. {
  124. // Use the specific ID provided
  125. add_content_to_workflow("gallery",$name,$workflow_id);
  126. }
  127. log_it(\'ADD_GALLERY\',$name,$fullname);',
  128. $code
  129. );
  130. // Editing is a bit different; we switch the workflow if needed.
  131. // Do this for images...
  132. $code=str_replace(
  133. 'log_it(\'EDIT_IMAGE\',strval($id),$title);',
  134. '
  135. if ($validated==0)
  136. {
  137. require_code("workflows");
  138. require_lang("workflows");
  139. // See if we have a specific workflow to use
  140. $edit_workflow=array_key_exists("workflow",$_REQUEST) && (either_param("workflow") != "wf_-2");
  141. $current_workflow=get_workflow_of_content("image",strval($id));
  142. if ($edit_workflow)
  143. {
  144. $workflow_id=intval(str_replace("wf_","",either_param("workflow","wf_-1")));
  145. // If we have been given a specific workflow, but we do not have access to
  146. // choose workflows, fail
  147. if (($workflow_id != -1) && (!can_choose_workflow()))
  148. $edit_workflow=false;
  149. }
  150. if ($edit_workflow && ($workflow_id==-1))
  151. {
  152. // Look for the workflow of the containing gallery
  153. $workflow_id=get_workflow_of_content("gallery",$title);
  154. if (is_null($workflow_id))
  155. {
  156. // Use the default if it has none
  157. if ($current_workflow != get_default_workflow())
  158. {
  159. add_content_to_workflow("image",strval($id),NULL,true);
  160. attach_message(do_lang("CONTENT_NOW_IN_WORKFLOW",get_translated_text(get_default_workflow())),"inform");
  161. }
  162. }
  163. else
  164. {
  165. // The parent has a workflow. Copy it for this.
  166. if ($workflow_id != $current_workflow)
  167. {
  168. add_content_to_workflow("image",strval($id),$workflow_id,true);
  169. attach_message(do_lang("CONTENT_NOW_IN_WORKFLOW",get_translated_text($workflow_id)),"inform");
  170. }
  171. }
  172. }
  173. else if ($edit_workflow)
  174. {
  175. // Use the specific ID provided
  176. if ($workflow_id != $current_workflow)
  177. {
  178. add_content_to_workflow("image",strval($id),$workflow_id);
  179. attach_message(do_lang("CONTENT_NOW_IN_WORKFLOW",get_translated_text($workflow_id)),"inform");
  180. }
  181. }
  182. log_it(\'EDIT_IMAGE\',strval($id),$title);
  183. }
  184. ',
  185. $code
  186. );
  187. // ...videos...
  188. $code=str_replace('log_it(\'EDIT_VIDEO\',strval($id),$title);',
  189. '
  190. if ($validated==0)
  191. {
  192. require_code("workflows");
  193. require_lang("workflows");
  194. // See if we have a specific workflow to use
  195. $edit_workflow=array_key_exists("workflow",$_REQUEST) && (either_param("workflow") != "wf_-2");
  196. $current_workflow=get_workflow_of_content("video",strval($id));
  197. if ($edit_workflow)
  198. {
  199. $workflow_id=intval(str_replace("wf_","",either_param("workflow","wf_-1")));
  200. // If we have been given a specific workflow, but we do not have access to
  201. // choose workflows, fail
  202. if (($workflow_id != -1) && (!can_choose_workflow()))
  203. $edit_workflow=false;
  204. }
  205. if (($edit_workflow) && ($workflow_id==-1))
  206. {
  207. // Look for the workflow of the containing gallery
  208. $workflow_id=get_workflow_of_content("gallery",$title);
  209. if (is_null($workflow_id))
  210. {
  211. // Use the default if it has none
  212. if ($current_workflow != get_default_workflow())
  213. {
  214. add_content_to_workflow("video",strval($id),NULL,true);
  215. attach_message(do_lang("CONTENT_NOW_IN_WORKFLOW",get_translated_text(get_default_workflow())),"inform");
  216. }
  217. }
  218. else
  219. {
  220. // The parent has a workflow. Copy it for this.
  221. if ($workflow_id != $current_workflow)
  222. {
  223. add_content_to_workflow("video",strval($id),$workflow_id,true);
  224. attach_message(do_lang("CONTENT_NOW_IN_WORKFLOW",get_translated_text($workflow_id)),"inform");
  225. }
  226. }
  227. }
  228. else if ($edit_workflow)
  229. {
  230. // Use the specific ID provided
  231. if ($workflow_id != $current_workflow)
  232. {
  233. add_content_to_workflow("video",strval($id),$workflow_id);
  234. attach_message(do_lang("CONTENT_NOW_IN_WORKFLOW",get_translated_text($workflow_id)),"inform");
  235. }
  236. }
  237. log_it(\'EDIT_VIDEO\',strval($id),$title);
  238. }
  239. ',
  240. $code
  241. );
  242. // ...and galleries
  243. $code=str_replace('log_it(\'EDIT_GALLERY\',$name,$fullname);',
  244. 'require_code("workflows");
  245. require_lang("workflows");
  246. // See if we have a specific workflow to use
  247. $edit_workflow=array_key_exists("workflow",$_REQUEST) && (post_param("workflow") != "wf_-2");
  248. $current_workflow=get_workflow_of_content("gallery",$name);
  249. if ($edit_workflow)
  250. {
  251. $workflow_id=intval(str_replace("wf_","",either_param("workflow","wf_-1")));
  252. // If we have been given a specific workflow, but we do not have access to
  253. // choose workflows, fail
  254. if (($workflow_id != -1) && (!can_choose_workflow()))
  255. {
  256. $edit_workflow=false;
  257. }
  258. }
  259. if ($edit_workflow && $workflow_id==-1)
  260. {
  261. // Look for the workflow of the containing gallery
  262. $workflow_id=get_workflow_of_content("gallery",$parent_id);
  263. if (is_null($workflow_id))
  264. {
  265. // Use the default if it has none
  266. if ($current_workflow != get_default_workflow())
  267. {
  268. add_content_to_workflow("gallery",$name,NULL,true);
  269. }
  270. }
  271. else
  272. {
  273. // The parent has a workflow. Copy it for this.
  274. if ($workflow_id != $current_workflow)
  275. {
  276. add_content_to_workflow("gallery",$name,$workflow_id,true);
  277. }
  278. }
  279. }
  280. else if ($edit_workflow)
  281. {
  282. // Use the specific ID provided
  283. if ($workflow_id != $current_workflow)
  284. {
  285. add_content_to_workflow("gallery",$name,$workflow_id,true);
  286. }
  287. }
  288. log_it(\'EDIT_GALLERY\',$name,$fullname);',
  289. $code
  290. );
  291. // Now we add removal code for the delete functions.
  292. // We do this for images...
  293. $code=str_replace('log_it(\'DELETE_IMAGE\',strval($id),get_translated_text($comments));',
  294. 'log_it(\'DELETE_IMAGE\',strval($id),get_translated_text($comments));
  295. require_code("workflows");
  296. require_lang("workflows");
  297. if (!is_null(get_workflow_of_content("image",strval($id))))
  298. remove_content_from_workflows("image",strval($id));',
  299. $code
  300. );
  301. // ...videos...
  302. $code=str_replace('log_it(\'DELETE_VIDEO\',strval($id),get_translated_text($comments));',
  303. 'log_it(\'DELETE_VIDEO\',strval($id),get_translated_text($comments));
  304. require_code("workflows");
  305. require_lang("workflows");
  306. if (!is_null(get_workflow_of_content("video",strval($id))))
  307. remove_content_from_workflows("video",strval($id));',
  308. $code
  309. );
  310. // ...and galleries.
  311. $code=str_replace('log_it(\'DELETE_GALLERY\',$name,get_translated_text($rows[0][\'fullname\']));',
  312. 'log_it(\'DELETE_GALLERY\',$name,get_translated_text($rows[0][\'fullname\']));
  313. require_code("workflows");
  314. require_lang("workflows");
  315. if (!is_null(get_workflow_of_content("gallery",$name)))
  316. remove_content_from_workflows("gallery",$name);',
  317. $code
  318. );
  319. return $code;
  320. }