PageRenderTime 58ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/dynamic-widgets/dynwid_worker.php

https://bitbucket.org/Thane2376/death-edge.ru
PHP | 839 lines | 700 code | 92 blank | 47 comment | 291 complexity | 0ee985d8afa1385bd0acc0eee4e6ccf4 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-3.0, AGPL-1.0
  1. <?php
  2. /**
  3. * dynwid_worker.php - The worker does the actual work.
  4. *
  5. * @version $Id: dynwid_worker.php 939272 2014-06-26 19:44:38Z qurl $
  6. * @copyright 2011 Jacco Drabbe
  7. */
  8. $DW->message('Worker START');
  9. $DW->message('WhereAmI = ' . $DW->whereami);
  10. // Registering Custom Post Type & Custom Taxonomy to $DW (object overload)
  11. include(DW_MODULES . 'custompost_module.php');
  12. DWModule::registerPlugin(DW_CustomPost::$plugin);
  13. // Device
  14. $DW->device = ( wp_is_mobile() ) ? 'mobile' : 'desktop';
  15. $DW->message('Device = ' . $DW->device);
  16. // Template
  17. if (! is_archive() && ! is_404() ) {
  18. $tpl = get_page_template();
  19. if ( $DW->whereami == 'pods' ) {
  20. global $pod_page_exists;
  21. if (! empty($pod_page_exists['page_template']) ) {
  22. $tpl = $pod_page_exists['page_template'];
  23. }
  24. }
  25. $DW->template = basename($tpl);
  26. $DW->message('Template = ' . $DW->template);
  27. }
  28. // WPML Plugin support
  29. include_once(DW_MODULES . 'wpml_module.php');
  30. if ( DW_WPML::detect(FALSE) ) {
  31. $curlang = DW_WPML::detectLanguage();
  32. }
  33. // QT Plugin support
  34. include_once(DW_MODULES . 'qt_module.php');
  35. if ( DW_QT::detect(FALSE) ) {
  36. $curlang = DW_QT::detectLanguage();
  37. }
  38. foreach ( $sidebars as $sidebar_id => $widgets ) {
  39. // Only processing active sidebars with widgets
  40. if ( $sidebar_id != 'wp_inactive_widgets' && count($widgets) > 0 && is_array($widgets) ) {
  41. foreach ( $widgets as $widget_key => $widget_id ) {
  42. // Check if the widget has options set
  43. if ( in_array($widget_id, $DW->dynwid_list) ) {
  44. $act = array();
  45. $opt = $DW->getOpt($widget_id, $DW->whereami, FALSE);
  46. $DW->message('Number of rules to check for widget ' . $widget_id . ': ' . count($opt));
  47. $init = array_merge(array('display'), $DW->overrule_maintype);
  48. foreach ( $init as $m ) {
  49. $$m = TRUE;
  50. }
  51. // First run > The defaults
  52. foreach ( $opt as $condition ) {
  53. if ( empty($condition->name) && $condition->value == '0' && $condition->maintype == $DW->whereami ) {
  54. $DW->message('Default for ' . $widget_id . ' set to FALSE (rule D1)');
  55. $display = FALSE;
  56. $other = TRUE;
  57. } else if (! in_array($condition->maintype, $DW->overrule_maintype) ) {
  58. // Get default value
  59. if ( $condition->name == 'default' ) {
  60. $default = $condition->value;
  61. if ( $default == '0' ) {
  62. $DW->message('Default for ' . $widget_id . ' set to FALSE (rule D2)');
  63. $display = FALSE;
  64. $other = TRUE;
  65. } else {
  66. $DW->message('Default for ' . $widget_id . ' set to TRUE (rule D3)');
  67. $display = TRUE;
  68. $other = FALSE;
  69. }
  70. } else {
  71. $act[ ] = $condition->name;
  72. }
  73. } else {
  74. foreach ( $DW->overrule_maintype as $m ) {
  75. if ( $condition->maintype == $m && $condition->name == 'default' ) {
  76. $DW->message('Default for ' . $widget_id . ' set to ' . ( (bool) ($condition->value) ? 'TRUE' : 'FALSE' ) . ' by ' . $m . ' (rule OM1)');
  77. $$m = (bool) $condition->value;
  78. }
  79. }
  80. }
  81. }
  82. // Act the condition(s) when there are options set
  83. if ( count($opt) > 0 ) {
  84. // Role exceptions
  85. if ( isset($role) ) {
  86. foreach ( $opt as $condition ) {
  87. if ( $condition->maintype == 'role' && in_array($condition->name, $DW->userrole) ) {
  88. $DW->message('Exception triggered for Role, sets display to ' . ( (bool) ($condition->value) ? 'TRUE' : 'FALSE' ) . ' (rule ER1)');
  89. $role = (bool) $condition->value;;
  90. }
  91. }
  92. }
  93. // Date exceptions
  94. if (! $date ) {
  95. $dates = array();
  96. foreach ( $opt as $condition ) {
  97. if ( $condition->maintype == 'date' ) {
  98. switch ( $condition->name ) {
  99. case 'date_start':
  100. $date_start = $condition->value;
  101. break;
  102. case 'date_end':
  103. $date_end = $condition->value;
  104. break;
  105. }
  106. }
  107. }
  108. $now = current_time('timestamp', 0);
  109. if (! empty($date_end) ) {
  110. @list($date_end_year, $date_end_month, $date_end_day) = explode('-', $date_end);
  111. if ( mktime(23, 59, 59, $date_end_month, $date_end_day, $date_end_year) > $now ) {
  112. $date = TRUE;
  113. $DW->message('End date is in the future, sets Date to TRUE (rule EDT1)');
  114. if (! empty($date_start) ) {
  115. @list($date_start_year, $date_start_month, $date_start_day) = explode('-', $date_start);
  116. if ( mktime(0, 0, 0, $date_start_month, $date_start_day, $date_start_year) > $now ) {
  117. $date = FALSE;
  118. $DW->message('From date is in the future, sets Date to FALSE (rule EDT2)');
  119. }
  120. }
  121. }
  122. } else if (! empty($date_start) ) {
  123. @list($date_start_year, $date_start_month, $date_start_day) = explode('-', $date_start);
  124. if ( mktime(0, 0, 0, $date_start_month, $date_start_day, $date_start_year) < $now ) {
  125. $date = TRUE;
  126. $DW->message('From date is in the past, sets Date to TRUE (rule EDT3)');
  127. }
  128. }
  129. }
  130. // WPML
  131. if ( isset($wpml) && isset($curlang) ) {
  132. foreach ( $opt as $condition ) {
  133. if ( $condition->maintype == 'wpml' && $condition->name == $curlang ) {
  134. (bool) $wpml_tmp = $condition->value;
  135. }
  136. }
  137. if ( isset($wpml_tmp) && $wpml_tmp != $wpml ) {
  138. $DW->message('Exception triggered for WPML language, sets display to ' . ( ($wpml_tmp) ? 'TRUE' : 'FALSE' ) . ' (rule EML1)');
  139. $wpml = $wpml_tmp;
  140. }
  141. }
  142. unset($wpml_tmp);
  143. // QTranslate
  144. if ( isset($qt) && isset($curlang) ) {
  145. foreach ( $opt as $condition ) {
  146. if ( $condition->maintype == 'qt' && $condition->name == $curlang ) {
  147. (bool) $qt_tmp = $condition->value;
  148. }
  149. }
  150. if ( isset($qt_tmp) && $qt_tmp != $qt ) {
  151. $DW->message('Exception triggered for QT language, sets display to ' . ( ($qt_tmp) ? 'TRUE' : 'FALSE' ) . ' (rule EQT1)');
  152. $qt = $qt_tmp;
  153. }
  154. }
  155. unset($qt_tmp);
  156. // Browser, Device, IP, Template, Day, Week and URL
  157. foreach ( $opt as $condition ) {
  158. if ( $condition->maintype == 'browser' && $condition->name == $DW->useragent ) {
  159. (bool) $browser_tmp = $condition->value;
  160. } else if ( $condition->maintype == 'device' && $condition->name == $DW->device ) {
  161. (bool) $device_tmp = $condition->value;
  162. } else if ( $condition->maintype == 'tpl' && $condition->name == $DW->template ) {
  163. (bool) $tpl_tmp = $condition->value;
  164. } else if ( $condition->maintype == 'day' && $condition->name == date('N', current_time('timestamp', 0)) ) {
  165. (bool) $day_tmp = $condition->value;
  166. } else if ( $condition->maintype == 'week' && $condition->name == date('W', current_time('timestamp', 0)) ) {
  167. (bool) $week_tmp = $condition->value;
  168. } else if ( $condition->maintype == 'url' && $condition->name == 'url' ) {
  169. $urls = unserialize($condition->value);
  170. $other_url = ( $url ) ? FALSE : TRUE;
  171. foreach ( $urls as $u ) {
  172. $u = $DW->getURLPrefix() . $u;
  173. $DW->message('URL matching: ' . $u);
  174. $like_start = substr($u, 0, 1);
  175. $like_end = substr($u, -1);
  176. if ( $like_start == '*' && $like_end == '*' ) {
  177. $u = substr($u, 1, strlen($u) - 2);
  178. if ( stristr($DW->url, $u) !== FALSE ) {
  179. $DW->message('Anywhere within URL found');
  180. $url_tmp = $other_url;
  181. }
  182. } else if ( $like_end == '*' ) {
  183. $u = substr($u, 0, strlen($u) - 1);
  184. $u = addcslashes($u, '/?+.[]{}*^$');
  185. if ( preg_match('/^' . $u . '/', $DW->url) ) {
  186. $DW->message('Starts with URL found');
  187. $url_tmp = $other_url;
  188. }
  189. } else if ( $like_start == '*' ) {
  190. $u = substr($u, 1);
  191. $u = addcslashes($u, '/?+.[]{}*^$');
  192. if ( preg_match('/' . $u . '$/', $DW->url) ) {
  193. $DW->message('Ends with URL found');
  194. $url_tmp = $other_url;
  195. }
  196. } else {
  197. if ( $DW->url == $u ) {
  198. $DW->message('Exact match URL found');
  199. $url_tmp = $other_url;
  200. }
  201. }
  202. }
  203. } else if ( $condition->maintype == 'ip' && $condition->name == 'ip' && ! is_null($DW->ip_address) ) {
  204. $ips = unserialize($condition->value);
  205. $other_ip = ( $ip ) ? FALSE : TRUE;
  206. foreach ( $ips as $range ) {
  207. if ( $DW->IPinRange($DW->ip_address, $range) ) {
  208. $ip_tmp = $other_ip;
  209. break;
  210. }
  211. }
  212. }
  213. }
  214. if ( isset($browser_tmp) && $browser_tmp != $browser ) {
  215. $DW->message('Exception triggered for browser, sets display to ' . ( ($browser_tmp) ? 'TRUE' : 'FALSE' ) . ' (rule EB1)');
  216. $browser = $browser_tmp;
  217. }
  218. unset($browser_tmp);
  219. if ( isset($device_tmp) && $device_tmp != $device ) {
  220. $DW->message('Exception triggered for device, sets display to ' . ( ($device_tmp) ? 'TRUE' : 'FALSE' ) . ' (rule ED1)');
  221. $device = $device_tmp;
  222. }
  223. if ( isset($tpl_tmp) && $tpl_tmp != $tpl ) {
  224. $DW->message('Exception triggered for template, sets display to ' . ( ($tpl_tmp) ? 'TRUE' : 'FALSE' ) . ' (rule ETPL1)');
  225. $tpl = $tpl_tmp;
  226. }
  227. unset($tpl_tmp);
  228. if ( isset($day_tmp) && $day_tmp != $day ) {
  229. $DW->message('Exception triggered for day, sets display to ' . ( ($day_tmp) ? 'TRUE' : 'FALSE' ) . ' (rule EDAY1)');
  230. $day = $day_tmp;
  231. }
  232. unset($day_tmp);
  233. if ( isset($week_tmp) && $week_tmp != $week ) {
  234. $DW->message('Exception triggered for day, sets display to ' . ( ($week_tmp) ? 'TRUE' : 'FALSE' ) . ' (rule EWK1)');
  235. $week = $week_tmp;
  236. }
  237. unset($day_tmp);
  238. if ( isset($url_tmp) && $url_tmp != $url ) {
  239. $DW->message('Exception triggered for url, sets display to ' . ( ($url_tmp) ? 'TRUE' : 'FALSE' ) . ' (rule EURL1)');
  240. $url = $url_tmp;
  241. }
  242. unset($url_tmp, $other_url);
  243. if ( isset($ip_tmp) && $ip_tmp != $ip ) {
  244. $DW->message('Exception triggered for ip, sets display to ' . ( ($ip_tmp) ? 'TRUE' : 'FALSE' ) . ' (rule EIP1)');
  245. $ip = $ip_tmp;
  246. }
  247. unset($ip_tmp, $other_ip);
  248. // For debug messages
  249. $e = ( isset($other) && $other ) ? 'TRUE' : 'FALSE';
  250. // Display exceptions (custom post type)
  251. if ( $DW->custom_post_type ) {
  252. // Custom Post Type behaves the same as a single post
  253. $post = $GLOBALS['post'];
  254. if ( count($act) > 0 ) {
  255. $id = $post->ID;
  256. $DW->message('PostID: ' . $id);
  257. if ( $DW->wpml ) {
  258. $id = DW_WPML::getID($id, 'post_' . $DW->whereami);
  259. $DW->message('WPML ObjectID: ' . $id);
  260. }
  261. $act_custom = array();
  262. foreach ( $opt as $condition ) {
  263. if ( $condition->name != 'default' && $condition->maintype == $DW->whereami . '-post' ) {
  264. $act_custom[ ] = $condition->name;
  265. }
  266. }
  267. // Taxonomies within CPT
  268. $act_tax = array();
  269. $act_tax_childs = array();
  270. foreach ( get_object_taxonomies($DW->whereami) as $t ) {
  271. $m = $DW->whereami . '-tax_' . $t;
  272. foreach ( $opt as $condition ) {
  273. if ( $condition->maintype == $m ) {
  274. if (! key_exists($t, $act_tax) ) {
  275. $act_tax[$t] = array();
  276. $act_tax_childs[$t] = array();
  277. }
  278. }
  279. if ( $condition->name != 'default' ) {
  280. switch ( $condition->maintype ) {
  281. case $m:
  282. $act_tax[$t][ ] = $condition->name;
  283. break;
  284. case $m . '-childs':
  285. $act_tax_childs[$t][ ] = $condition->name;
  286. break;
  287. } // END switch
  288. }
  289. } // END $opt
  290. } // END object_taxonomies
  291. $term = wp_get_object_terms($id, get_object_taxonomies($DW->whereami), array('fields' => 'all'));
  292. if ( in_array($id, $act_custom) ) {
  293. $display = $other;
  294. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ECP1)');
  295. } else if ( count($act_tax) > 0 ) {
  296. // bcause $id has already been moved to default language, term doesn't need to be converted. WPML takes care of default language term
  297. foreach ( $term as $t ) {
  298. if ( isset($act_tax[$t->taxonomy]) && is_array($act_tax[$t->taxonomy]) && in_array($t->term_id, $act_tax[$t->taxonomy]) ) {
  299. $display = $other;
  300. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ECP3)');
  301. break;
  302. }
  303. $parents = $DW->getTaxParents($t->taxonomy, array(), $t->term_id);
  304. if ( isset($act_tax_childs[$t->taxonomy]) && is_array($act_tax_childs[$t->taxonomy]) && (bool) array_intersect($act_tax_childs[$t->taxonomy], $parents) ) {
  305. $display = $other;
  306. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ECP4)');
  307. }
  308. }
  309. }
  310. unset($act_custom, $act_childs, $act_tax);
  311. } // END count($act)
  312. } else if ( $DW->custom_taxonomy ) { // Custom Taxonomy Archive
  313. $wp_query = &$GLOBALS['wp_query'];
  314. $taxonomy = $wp_query->get('taxonomy');
  315. $term = $wp_query->get_queried_object_id();
  316. if ( $DW->wpml ) {
  317. $term = DW_WPML::getID($term, $DW->whereami);
  318. $DW->message('WPML ObjectID: ' . $term);
  319. }
  320. $act_custom = array();
  321. $act_custom_childs = array();
  322. foreach ( $opt as $condition ) {
  323. if ( $condition->name != 'default' ) {
  324. switch ( $condition->maintype ) {
  325. case $DW->whereami:
  326. $act_custom[ ] = $condition->name;
  327. break;
  328. case $DW->whereami . '-childs':
  329. $act_custom_childs[ ] = $condition->name;
  330. break;
  331. } // switch
  332. }
  333. }
  334. if ( in_array($term, $act_custom) ) {
  335. $display = $other;
  336. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ECT1)');
  337. } else if ( count($act_custom_childs) > 0 ) {
  338. $parents = $DW->getTaxParents($taxonomy, array(), $term);
  339. if ( (bool) array_intersect($act_custom_childs, $parents) ) {
  340. $display = $other;
  341. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ECT2)');
  342. }
  343. }
  344. unset($act_custom);
  345. unset($act_custom_childs);
  346. } else {
  347. // no custom post type
  348. switch ( $DW->whereami ) {
  349. case 'single':
  350. $post = $GLOBALS['post'];
  351. $act_author = array();
  352. $act_category = array();
  353. $act_category_childs = array();
  354. $act_post = array();
  355. $act_tag = array();
  356. $post_category = array();
  357. $post_tag = array();
  358. // Get the categories from the post
  359. $categories = get_the_category();
  360. foreach ( $categories as $category ) {
  361. $id = $category->cat_ID;
  362. if ( $DW->wpml ) {
  363. $id = DW_WPML::getID($id, 'tax_category');
  364. }
  365. $post_category[ ] = $id;
  366. }
  367. // Get the tags form the post
  368. if ( has_tag() ) {
  369. $tags = get_the_tags();
  370. /* For some reason WP reports the post has tags, but then returns not an array with tags.
  371. Maybe because it's not in the loop anymore? */
  372. if (! is_array($tags) ) {
  373. $tags = array();
  374. }
  375. foreach ( $tags as $tag ) {
  376. $post_tag[ ] = $tag->term_id;
  377. }
  378. } else {
  379. $tags = array();
  380. }
  381. // Split out the conditions
  382. foreach ( $opt as $condition ) {
  383. if ( $condition->name != 'default' ) {
  384. switch ( $condition->maintype ) {
  385. case 'single-author':
  386. $act_author[ ] = $condition->name;
  387. break;
  388. case 'single-category':
  389. $act_category[ ] = $condition->name;
  390. break;
  391. case 'single-category-childs':
  392. $act_category_childs[ ] = $condition->name;
  393. break;
  394. case 'single-tag':
  395. $act_tag[ ] = $condition->name;
  396. break;
  397. case 'single-post':
  398. $act_post[ ] = $condition->name;
  399. break;
  400. } // END switch
  401. }
  402. }
  403. /* Author AND Category */
  404. if ( count($act_author) > 0 && count($act_category) > 0 ) {
  405. // Use of array_intersect to be sure one value in both arrays returns true
  406. if ( in_array($post->post_author, $act_author) ) {
  407. if ( (bool) array_intersect($post_category, $act_category) ) {
  408. $display = $other;
  409. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ES1)');
  410. } else if ( count($act_category_childs) > 0 ) {
  411. $parents = $DW->getPostCatParents($post_category);
  412. if ( (bool) array_intersect($act_category_childs, $parents) ) {
  413. $display = $other;
  414. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ES6)');
  415. }
  416. }
  417. }
  418. /* Only Author */
  419. } else if ( count($act_author) > 0 && count($act_category == 0) ) {
  420. if ( in_array($post->post_author, $act_author) ) {
  421. $display = $other;
  422. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ES2)');
  423. }
  424. /* Only Category */
  425. } else if ( count($act_author) == 0 && count($act_category) > 0 ) {
  426. if ( (bool) array_intersect($post_category, $act_category) ) {
  427. $display = $other;
  428. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ES3)');
  429. } else if ( count($act_category_childs) > 0 ) {
  430. $parents = $DW->getPostCatParents($post_category);
  431. if ( (bool) array_intersect($act_category_childs, $parents) ) {
  432. $display = $other;
  433. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ES7)');
  434. }
  435. }
  436. /* None or individual checked - individual is not included in the $opt */
  437. } else {
  438. $DW->message('Looking for tags, individual posts or taxonomies');
  439. /* Tags */
  440. if ( count($act_tag) > 0 ) {
  441. if ( (bool) array_intersect($post_tag, $act_tag) ) {
  442. $display = $other;
  443. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ES4)');
  444. }
  445. }
  446. /* Posts */
  447. if ( count($act_post) > 0 ) {
  448. if ( in_array($post->ID, $act_post) ) {
  449. $display = $other;
  450. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ES5)');
  451. }
  452. }
  453. // Taxonomies
  454. $act_tax = array();
  455. $act_tax_childs = array();
  456. foreach ( get_object_taxonomies('post') as $t ) {
  457. $m = 'single-tax_' . $t;
  458. foreach ( $opt as $condition ) {
  459. if ( $condition->maintype == $m ) {
  460. if (! key_exists($t, $act_tax) ) {
  461. $act_tax[$t] = array();
  462. $act_tax_childs[$t] = array();
  463. }
  464. }
  465. if ( $condition->name != 'default' ) {
  466. switch ( $condition->maintype ) {
  467. case $m:
  468. $act_tax[$t][ ] = $condition->name;
  469. break;
  470. case $m . '-childs':
  471. $act_tax_childs[$t][ ] = $condition->name;
  472. break;
  473. } // END switch
  474. }
  475. } // END $opt
  476. } // END object_taxonomies
  477. $term = wp_get_object_terms($post->ID, get_object_taxonomies('post'), array('fields' => 'all'));
  478. if ( count($act_tax) > 0 ) {
  479. // bcause $id has already been moved to default language, term doesn't need to be converted. WPML takes care of default language term
  480. foreach ( $term as $t ) {
  481. if ( isset($act_tax[$t->taxonomy]) && is_array($act_tax[$t->taxonomy]) && in_array($t->term_id, $act_tax[$t->taxonomy]) ) {
  482. $display = $other;
  483. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ESTX1)');
  484. break;
  485. }
  486. $parents = $DW->getTaxParents($t->taxonomy, array(), $t->term_id);
  487. if ( isset($act_tax_childs[$t->taxonomy]) && is_array($act_tax_childs[$t->taxonomy]) && (bool) array_intersect($act_tax_childs[$t->taxonomy], $parents) ) {
  488. $display = $other;
  489. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ESTX2)');
  490. }
  491. }
  492. }
  493. unset($act_tax, $act_tax_childs);
  494. }
  495. break;
  496. case 'front-page':
  497. if ( count($act) > 0 ) {
  498. $pagenr = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
  499. if ( in_array($pagenr, $act) ) {
  500. $display = $other;
  501. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EFP1)');
  502. }
  503. }
  504. break;
  505. case 'home':
  506. if ( count($act) > 0 ) {
  507. $home_id = get_option('page_for_posts');
  508. $DW->message('ID = ' . $home_id);
  509. if ( $DW->wpml ) {
  510. $home_id = DW_WPML::getID($home_id);
  511. $DW->message('WPML ObjectID: ' . $home_id);
  512. }
  513. if ( in_array($home_id, $act) ) {
  514. $display = $other;
  515. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EH1)');
  516. }
  517. }
  518. break;
  519. case 'page':
  520. if ( count($act) > 0 ) {
  521. $act_page = array();
  522. $act_childs = array();
  523. $post = $GLOBALS['post'];
  524. $id = $post->ID;
  525. $DW->message('ID = ' . $id);
  526. $page_act_tax = array();
  527. $page_act_tax_childs = array();
  528. if ( $DW->wpml ) {
  529. $id = DW_WPML::getID($id);
  530. $DW->message('WPML ObjectID: ' . $id);
  531. }
  532. foreach ( $opt as $condition ) {
  533. if ( $condition->name != 'default' ) {
  534. switch ( $condition->maintype ) {
  535. case 'page':
  536. $act_page[ ] = $condition->name;
  537. break;
  538. case 'page-childs':
  539. $act_childs[ ] = $condition->name;
  540. break;
  541. }
  542. }
  543. }
  544. if ( in_array($id, $act_page) ) {
  545. $display = $other;
  546. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EP1)');
  547. } else if ( count($act_childs) > 0 ) {
  548. $parents = $DW->getParents('page', array(), $id);
  549. if ( (bool) array_intersect($act_childs, $parents) ) {
  550. $display = $other;
  551. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EP2)');
  552. }
  553. } else {
  554. $term = wp_get_object_terms($id, get_object_taxonomies($DW->whereami), array('fields' => 'all'));
  555. if (! is_wp_error($term) && count($term) > 0 ) {
  556. foreach ( get_object_taxonomies($DW->whereami) as $t ) {
  557. $m = $DW->whereami . '-tax_' . $t;
  558. foreach ( $opt as $condition ) {
  559. if ( $condition->maintype == $m ) {
  560. if (! key_exists($t, $page_act_tax) ) {
  561. $page_act_tax[$t] = array();
  562. $page_act_tax_childs[$t] = array();
  563. }
  564. }
  565. if ( $condition->name != 'default' ) {
  566. switch ( $condition->maintype ) {
  567. case $m:
  568. $page_act_tax[$t][ ] = $condition->name;
  569. break;
  570. case $m . '-childs':
  571. $page_act_tax_childs[$t][ ] = $condition->name;
  572. break;
  573. } // END switch
  574. }
  575. } // END $opt
  576. }
  577. } // END count($term)
  578. }
  579. if ( isset($term) && ! is_wp_error($term) && ! empty($term) ) {
  580. foreach ( $term as $t ) {
  581. if ( isset($page_act_tax[$t->taxonomy]) && is_array($page_act_tax[$t->taxonomy]) && in_array($t->term_id, $page_act_tax[$t->taxonomy]) ) {
  582. $display = $other;
  583. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EP3)');
  584. break;
  585. }
  586. $page_parents = $DW->getTaxParents($t->taxonomy, array(), $t->term_id);
  587. if ( isset($page_act_tax_childs[$t->taxonomy]) && is_array($page_act_tax_childs[$t->taxonomy]) && (bool) array_intersect($page_act_tax_childs[$t->taxonomy], $page_parents) ) {
  588. $display = $other;
  589. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EP4)');
  590. }
  591. }
  592. }
  593. }
  594. break;
  595. case 'author':
  596. if ( count($act) > 0 && is_author($act) ) {
  597. $display = $other;
  598. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EA1)');
  599. }
  600. break;
  601. case 'category':
  602. if ( count($act) > 0 ) {
  603. $act_cat = array();
  604. $act_childs = array();
  605. $id = get_query_var('cat');
  606. $DW->message('CatID: ' . $id);
  607. if ( DW_WPML::detect(FALSE) ) {
  608. $id = DW_WPML::getID($id, 'tax_category');
  609. $DW->message('WPML ObjectID: ' . $id);
  610. }
  611. foreach ( $opt as $condition ) {
  612. if ( $condition->name != 'default' ) {
  613. switch ( $condition->maintype ) {
  614. case 'category':
  615. $act_cat[ ] = $condition->name;
  616. break;
  617. case 'category-childs':
  618. $act_childs[ ] = $condition->name;
  619. break;
  620. }
  621. }
  622. }
  623. if ( in_array($id, $act_cat) ) {
  624. $display = $other;
  625. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EC1)');
  626. } else if ( count($act_childs) > 0 ) {
  627. $parents = $DW->getTaxParents('category', array(), $id);
  628. if ( (bool) array_intersect($act_childs, $parents) ) {
  629. $display = $other;
  630. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EC2)');
  631. }
  632. }
  633. }
  634. break;
  635. case 'tag':
  636. if ( count($act) > 0 ) {
  637. global $wp_query;
  638. $tag = $wp_query->get_queried_object_id();
  639. if ( in_array($tag, $act) ) {
  640. $display = $other;
  641. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule T1)');
  642. }
  643. }
  644. break;
  645. case 'cp_archive':
  646. if ( count($act) > 0 ) {
  647. /*
  648. is_post_type_archive() is natively supported in WP 3.1
  649. WP 3.0.x gets is_post_type_archive() via plugin
  650. 'Custom Post Type Archive', but does not accept array
  651. */
  652. $is_cpa = FALSE;
  653. if ( version_compare(substr($GLOBALS['wp_version'], 0, 3), '3.1', '>=') ) {
  654. if ( is_post_type_archive($act) ) {
  655. $is_cpa = TRUE;
  656. }
  657. } else {
  658. $post_type = get_query_var('post_type');
  659. if ( in_array($post_type, $act) ) {
  660. $is_cpa = TRUE;
  661. }
  662. }
  663. if ( $is_cpa ) {
  664. $display = $other;
  665. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ECPA1)');
  666. }
  667. }
  668. break;
  669. case 'wpsc':
  670. if ( count($act) > 0 ) {
  671. include_once(DW_MODULES . 'wpec_module.php');
  672. if ( DW_WPSC::is_dw_wpsc_category($act) ) {
  673. $display = $other;
  674. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ESC1)');
  675. }
  676. }
  677. break;
  678. case 'bp':
  679. // We have to split out the conditions as we don't want the bp-groups to interfere
  680. $act = array();
  681. foreach ( $opt as $condition ) {
  682. if ( $condition->name != 'default' && $condition->maintype == 'bp' ) {
  683. $act[ ] = $condition->name;
  684. }
  685. }
  686. if ( count($act) > 0 ) {
  687. include_once(DW_MODULES . 'bp_module.php');
  688. if ( DW_BP::is_dw_bp_component($act) ) {
  689. $display = $other;
  690. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EBP1)');
  691. }
  692. }
  693. break;
  694. case 'bp-group':
  695. if ( count($act) > 0 ) {
  696. include_once(DW_MODULES . 'bp_module.php');
  697. if ( DW_BP::is_dw_bp_group($act) ) {
  698. $display = $other;
  699. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EBPG1)');
  700. } else if ( DW_BP::is_dw_bp_group_forum($act) ) {
  701. $display = $other;
  702. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EBPG2)');
  703. } else if ( DW_BP::is_dw_bp_group_members($act) ) {
  704. $display = $other;
  705. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EBPG3)');
  706. }
  707. }
  708. break;
  709. case 'pods':
  710. if ( count($act) > 0 ) {
  711. include_once(DW_MODULES . 'pods_module.php');
  712. if ( DW_Pods::is_dw_pods_page($act) ) {
  713. $display = $other;
  714. $DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EPDS1)');
  715. }
  716. }
  717. break;
  718. } // END switch ( $DW->whereami )
  719. } // END if/else ( $DW->custom_post_type )
  720. } /* END if ( count($opt) > 0 ) */
  721. if ( $display ) {
  722. foreach ( $DW->overrule_maintype as $mt ) {
  723. if (! $$mt ) {
  724. $display = FALSE;
  725. break;
  726. }
  727. }
  728. }
  729. if (! $display ) {
  730. $DW->message('Removed ' . $widget_id . ' from display, SID = ' . $sidebar_id . ' / WID = ' . $widget_id . ' / KID = ' . $widget_key);
  731. if ( DW_OLD_METHOD ) {
  732. unset($DW->registered_widgets[$widget_id]);
  733. } else {
  734. unset($sidebars[$sidebar_id][$widget_key]);
  735. if (! isset($DW->removelist[$sidebar_id]) ) {
  736. $DW->removelist[$sidebar_id] = array();
  737. }
  738. $DW->removelist[$sidebar_id][ ] = $widget_key;
  739. }
  740. }
  741. } // END if ( in_array($widget_id, $DW->dynwid_list) )
  742. } // END foreach ( $widgets as $widget_id )
  743. } // END if ( $sidebar_id != 'wp_inactive_widgets' && count($widgets) > 0 )
  744. } // END foreach ( $DW->sidebars as $sidebar_id => $widgets )
  745. $DW->listmade = TRUE;
  746. $DW->message('Dynamic Widgets END');
  747. ?>