PageRenderTime 63ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 1ms

/classes/PodsUI.php

https://github.com/ElmsPark/pods
PHP | 3523 lines | 2764 code | 410 blank | 349 comment | 773 complexity | 5983e2663f1640e9d8f68e03953b2a6b MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * @package Pods
  4. */
  5. class PodsUI {
  6. // internal
  7. /**
  8. * @var bool|PodsData
  9. */
  10. private $pods_data = false;
  11. /**
  12. * @var array
  13. */
  14. private $actions = array(
  15. 'manage',
  16. 'add',
  17. 'edit',
  18. 'duplicate',
  19. 'save',
  20. 'view',
  21. 'delete',
  22. 'reorder',
  23. 'export'
  24. );
  25. /**
  26. * @var array
  27. */
  28. private $ui_page = array();
  29. /**
  30. * @var bool
  31. */
  32. private $unique_identifier = false;
  33. // base
  34. public $x = array();
  35. /**
  36. * @var array|bool|mixed|null|Pods
  37. */
  38. public $pod = false;
  39. /**
  40. * @var int
  41. */
  42. public $id = 0;
  43. /**
  44. * @var string
  45. */
  46. public $num = ''; // allows multiple co-existing PodsUI instances with separate functionality in URL
  47. /**
  48. * @var array
  49. */
  50. static $excluded = array(
  51. 'do',
  52. 'id',
  53. 'pg',
  54. 'search',
  55. 'filter_*',
  56. 'orderby',
  57. 'orderby_dir',
  58. 'limit',
  59. 'action',
  60. 'action_bulk',
  61. 'action_bulk_ids',
  62. 'view',
  63. 'export',
  64. 'export_type',
  65. 'export_delimiter',
  66. 'remove_export',
  67. 'updated',
  68. 'duplicate'
  69. ); // used in var_update
  70. // ui
  71. /**
  72. * @var bool
  73. */
  74. public $item = false; // to be set with localized string
  75. /**
  76. * @var bool
  77. */
  78. public $items = false; // to be set with localized string
  79. /**
  80. * @var bool
  81. */
  82. public $heading = false; // to be set with localized string array
  83. /**
  84. * @var bool
  85. */
  86. public $header = false; // to be set with localized string array
  87. /**
  88. * @var bool
  89. */
  90. public $label = false; // to be set with localized string array
  91. /**
  92. * @var bool
  93. */
  94. public $icon = false;
  95. /**
  96. * @var bool
  97. */
  98. public $css = false; // set to a URL of stylesheet to include
  99. /**
  100. * @var bool
  101. */
  102. public $wpcss = false; // set to true to include WP Admin stylesheets
  103. /**
  104. * @var array
  105. */
  106. public $fields = array(
  107. 'manage' => array(),
  108. 'search' => array(),
  109. 'form' => array(),
  110. 'add' => array(),
  111. 'edit' => array(),
  112. 'duplicate' => array(),
  113. 'view' => array(),
  114. 'reorder' => array(),
  115. 'export' => array()
  116. );
  117. /**
  118. * @var bool
  119. */
  120. public $searchable = true;
  121. /**
  122. * @var bool
  123. */
  124. public $sortable = true;
  125. /**
  126. * @var bool
  127. */
  128. public $pagination = true;
  129. /**
  130. * @var bool
  131. */
  132. public $pagination_total = true;
  133. /**
  134. * @var array
  135. */
  136. public $export = array(
  137. 'on' => false,
  138. 'formats' => array(
  139. 'csv' => ',',
  140. 'tsv' => "\t",
  141. 'xml' => false,
  142. 'json' => false
  143. ),
  144. 'url' => false,
  145. 'type' => false
  146. );
  147. /**
  148. * @var array
  149. */
  150. public $reorder = array(
  151. 'on' => false,
  152. 'limit' => 250,
  153. 'orderby' => false,
  154. 'orderby_dir' => 'ASC',
  155. 'sql' => null
  156. );
  157. /**
  158. * @var array
  159. */
  160. public $screen_options = array(); // set to 'page' => 'Text'; false hides link
  161. /**
  162. * @var array
  163. */
  164. public $help = array(); // set to 'page' => 'Text'; 'page' => array('link' => 'yourhelplink'); false hides link
  165. // data
  166. /**
  167. * @var bool
  168. */
  169. public $search = false;
  170. /**
  171. * @var bool
  172. */
  173. public $filters_enhanced = false;
  174. /**
  175. * @var array
  176. */
  177. public $filters = array();
  178. /**
  179. * @var string
  180. */
  181. public $view = false;
  182. /**
  183. * @var array
  184. */
  185. public $views = array();
  186. /**
  187. * @var bool
  188. */
  189. public $search_across = true;
  190. /**
  191. * @var bool
  192. */
  193. public $search_across_picks = false;
  194. /**
  195. * @var bool
  196. */
  197. public $default_none = false;
  198. /**
  199. * @var array
  200. */
  201. public $where = array(
  202. 'manage' => null,
  203. 'edit' => null,
  204. 'duplicate' => null,
  205. 'delete' => null,
  206. 'reorder' => null
  207. );
  208. /**
  209. * @var bool
  210. */
  211. public $orderby = false;
  212. /**
  213. * @var string
  214. */
  215. public $orderby_dir = 'DESC';
  216. /**
  217. * @var int
  218. */
  219. public $limit = 25;
  220. /**
  221. * @var int
  222. */
  223. public $page = 1;
  224. /**
  225. * @var int
  226. */
  227. public $total = 0;
  228. /**
  229. * @var int
  230. */
  231. public $total_found = 0;
  232. /**
  233. * @var array
  234. */
  235. public $session = array(
  236. 'search',
  237. 'filters'
  238. ); // allowed: search, filters, show_per_page, orderby (priority over usermeta)
  239. /**
  240. * @var array
  241. */
  242. public $user = array(
  243. 'show_per_page',
  244. 'orderby'
  245. ); // allowed: search, filters, show_per_page, orderby (priority under session)
  246. // advanced data
  247. /**
  248. * @var array
  249. */
  250. public $sql = array(
  251. 'table' => null,
  252. 'field_id' => 'id',
  253. 'field_index' => 'name',
  254. 'select' => null,
  255. 'sql' => null
  256. );
  257. /**
  258. * @var array
  259. */
  260. public $params = array();
  261. /**
  262. * @var bool|array
  263. */
  264. public $data = false;
  265. /**
  266. * @var bool|array
  267. */
  268. public $data_full = false;
  269. /**
  270. * @var array
  271. */
  272. public $data_keys = array();
  273. /**
  274. * @var array
  275. */
  276. public $row = array();
  277. // actions
  278. /**
  279. * @var string
  280. */
  281. public $action = 'manage';
  282. /**
  283. * @var string
  284. */
  285. public $action_bulk = false;
  286. /**
  287. * @var array
  288. */
  289. public $bulk = array();
  290. /**
  291. * @var array
  292. */
  293. public $action_after = array(
  294. 'add' => 'edit',
  295. 'edit' => 'edit',
  296. 'duplicate' => 'edit'
  297. ); // set action to 'manage'
  298. /**
  299. * @var bool
  300. */
  301. public $do = false;
  302. /**
  303. * @var array
  304. */
  305. public $action_links = array(
  306. 'add' => null,
  307. 'edit' => null,
  308. 'duplicate' => null,
  309. 'view' => null,
  310. 'delete' => null,
  311. 'reorder' => null,
  312. 'export' => null
  313. ); // custom links (callable allowed)
  314. /**
  315. * @var array
  316. */
  317. public $actions_disabled = array(
  318. 'view',
  319. 'export'
  320. ); // disable actions
  321. /**
  322. * @var array
  323. */
  324. public $actions_hidden = array(); // hide actions to not show them but allow them
  325. /**
  326. * @var array
  327. */
  328. public $actions_custom = array(); // overwrite existing actions or add your own
  329. /**
  330. * @var array
  331. */
  332. public $actions_bulk = array(); // enabled bulk actions
  333. /**
  334. * @var bool|string
  335. */
  336. public $restrict = array(
  337. 'manage' => null,
  338. 'edit' => null,
  339. 'duplicate' => null,
  340. 'delete' => null,
  341. 'reorder' => null,
  342. 'author_restrict' => null
  343. );
  344. /**
  345. * @var bool
  346. */
  347. public $save = false; // Allow custom save handling for tables that aren't Pod-based
  348. /**
  349. * Generate UI for Data Management
  350. *
  351. * @param mixed $options Object, Array, or String containing Pod or Options to be used
  352. * @param bool $deprecated Set to true to support old options array from Pods UI plugin
  353. *
  354. * @license http://www.gnu.org/licenses/gpl-2.0.html
  355. * @since 2.0.0
  356. */
  357. public function __construct ( $options, $deprecated = false ) {
  358. $object = null;
  359. if ( is_object( $options ) ) {
  360. $object = $options;
  361. $options = array();
  362. if ( isset( $object->ui ) ) {
  363. $options = (array) $object->ui;
  364. unset( $object->ui );
  365. }
  366. if ( is_object( $object ) && ( 'Pods' == get_class( $object ) || 'Pod' == get_class( $object ) ) )
  367. $this->pod = &$object;
  368. }
  369. if ( !is_array( $options ) ) {
  370. // @todo need to come back to this and allow for multi-dimensional strings
  371. // like: option=value&option2=value2&option3=key[val],key2[val2]&option4=this,that,another
  372. if ( false !== strpos( $options, '=' ) || false !== strpos( $options, '&' ) )
  373. parse_str( $options, $options );
  374. else
  375. $options = array( 'pod' => $options );
  376. }
  377. if ( !is_object( $object ) && isset( $options[ 'pod' ] ) ) {
  378. if ( is_object( $options[ 'pod' ] ) )
  379. $this->pod = $options[ 'pod' ];
  380. elseif ( isset( $options[ 'id' ] ) )
  381. $this->pod = pods( $options[ 'pod' ], $options[ 'id' ] );
  382. else
  383. $this->pod = pods( $options[ 'pod' ] );
  384. unset( $options[ 'pod' ] );
  385. }
  386. elseif ( is_object( $object ) )
  387. $this->pod = $object;
  388. if ( false !== $deprecated || ( is_object( $this->pod ) && 'Pod' == get_class( $this->pod ) ) )
  389. $options = $this->setup_deprecated( $options );
  390. if ( is_object( $this->pod ) && 'Pod' == get_class( $this->pod ) && is_object( $this->pod->_data ) )
  391. $this->pods_data =& $this->pod->_data;
  392. elseif ( is_object( $this->pod ) && 'Pods' == get_class( $this->pod ) && is_object( $this->pod->data ) )
  393. $this->pods_data =& $this->pod->data;
  394. elseif ( is_object( $this->pod ) )
  395. $this->pods_data = pods_data( $this->pod->pod );
  396. elseif ( !is_object( $this->pod ) )
  397. $this->pods_data = pods_data( $this->pod );
  398. $options = $this->do_hook( 'pre_init', $options );
  399. $this->setup( $options );
  400. if ( is_object( $this->pods_data ) && is_object( $this->pod ) && 0 < $this->id && $this->id != $this->pods_data->id )
  401. $this->row = $this->pods_data->fetch( $this->id );
  402. if ( ( !is_object( $this->pod ) || 'Pods' != get_class( $this->pod ) ) && false === $this->sql[ 'table' ] && false === $this->data ) {
  403. echo $this->error( __( '<strong>Error:</strong> Pods UI needs a Pods object or a Table definition to run from, see the User Guide for more information.', 'pods' ) );
  404. return false;
  405. }
  406. $this->go();
  407. }
  408. /**
  409. * @param $deprecated_options
  410. *
  411. * @return array
  412. */
  413. public function setup_deprecated ( $deprecated_options ) {
  414. $options = array();
  415. if ( isset( $deprecated_options[ 'id' ] ) )
  416. $options[ 'id' ] = $deprecated_options[ 'id' ];
  417. if ( isset( $deprecated_options[ 'action' ] ) )
  418. $options[ 'action' ] = $deprecated_options[ 'action' ];
  419. if ( isset( $deprecated_options[ 'num' ] ) )
  420. $options[ 'num' ] = $deprecated_options[ 'num' ];
  421. if ( isset( $deprecated_options[ 'title' ] ) )
  422. $options[ 'items' ] = $deprecated_options[ 'title' ];
  423. if ( isset( $deprecated_options[ 'item' ] ) )
  424. $options[ 'item' ] = $deprecated_options[ 'item' ];
  425. if ( isset( $deprecated_options[ 'label' ] ) )
  426. $options[ 'label' ] = array(
  427. 'add' => $deprecated_options[ 'label' ],
  428. 'edit' => $deprecated_options[ 'label' ],
  429. 'duplicate' => $deprecated_options[ 'label' ]
  430. );
  431. if ( isset( $deprecated_options[ 'label_add' ] ) ) {
  432. if ( isset( $options[ 'label' ] ) )
  433. $options[ 'label' ][ 'add' ] = $deprecated_options[ 'label_add' ];
  434. else
  435. $options[ 'label' ] = array( 'add' => $deprecated_options[ 'label_add' ] );
  436. }
  437. if ( isset( $deprecated_options[ 'label_edit' ] ) ) {
  438. if ( isset( $options[ 'label' ] ) )
  439. $options[ 'label' ][ 'edit' ] = $deprecated_options[ 'label_edit' ];
  440. else
  441. $options[ 'label' ] = array( 'edit' => $deprecated_options[ 'label_edit' ] );
  442. }
  443. if ( isset( $deprecated_options[ 'label_duplicate' ] ) ) {
  444. if ( isset( $options[ 'label' ] ) )
  445. $options[ 'label' ][ 'duplicate' ] = $deprecated_options[ 'label_duplicate' ];
  446. else
  447. $options[ 'label' ] = array( 'duplicate' => $deprecated_options[ 'label_duplicate' ] );
  448. }
  449. if ( isset( $deprecated_options[ 'icon' ] ) )
  450. $options[ 'icon' ] = $deprecated_options[ 'icon' ];
  451. if ( isset( $deprecated_options[ 'columns' ] ) )
  452. $options[ 'fields' ] = array( 'manage' => $deprecated_options[ 'columns' ] );
  453. if ( isset( $deprecated_options[ 'reorder_columns' ] ) ) {
  454. if ( isset( $options[ 'fields' ] ) )
  455. $options[ 'fields' ][ 'reorder' ] = $deprecated_options[ 'reorder_columns' ];
  456. else
  457. $options[ 'fields' ] = array( 'reorder' => $deprecated_options[ 'reorder_columns' ] );
  458. }
  459. if ( isset( $deprecated_options[ 'add_fields' ] ) ) {
  460. if ( isset( $options[ 'fields' ] ) ) {
  461. if ( !isset( $options[ 'fields' ][ 'add' ] ) )
  462. $options[ 'fields' ][ 'add' ] = $deprecated_options[ 'add_fields' ];
  463. if ( !isset( $options[ 'fields' ][ 'edit' ] ) )
  464. $options[ 'fields' ][ 'edit' ] = $deprecated_options[ 'add_fields' ];
  465. if ( !isset( $options[ 'fields' ][ 'duplicate' ] ) )
  466. $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'add_fields' ];
  467. }
  468. else
  469. $options[ 'fields' ] = array(
  470. 'add' => $deprecated_options[ 'add_fields' ],
  471. 'edit' => $deprecated_options[ 'add_fields' ],
  472. 'duplicate' => $deprecated_options[ 'add_fields' ]
  473. );
  474. }
  475. if ( isset( $deprecated_options[ 'edit_fields' ] ) ) {
  476. if ( isset( $options[ 'fields' ] ) ) {
  477. if ( !isset( $options[ 'fields' ][ 'add' ] ) )
  478. $options[ 'fields' ][ 'add' ] = $deprecated_options[ 'edit_fields' ];
  479. if ( !isset( $options[ 'fields' ][ 'edit' ] ) )
  480. $options[ 'fields' ][ 'edit' ] = $deprecated_options[ 'edit_fields' ];
  481. if ( !isset( $options[ 'fields' ][ 'duplicate' ] ) )
  482. $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'edit_fields' ];
  483. }
  484. else
  485. $options[ 'fields' ] = array(
  486. 'add' => $deprecated_options[ 'edit_fields' ],
  487. 'edit' => $deprecated_options[ 'edit_fields' ],
  488. 'duplicate' => $deprecated_options[ 'edit_fields' ]
  489. );
  490. }
  491. if ( isset( $deprecated_options[ 'duplicate_fields' ] ) ) {
  492. if ( isset( $options[ 'fields' ] ) )
  493. $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_fields' ];
  494. else
  495. $options[ 'fields' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_fields' ] );
  496. }
  497. if ( isset( $deprecated_options[ 'session_filters' ] ) && false === $deprecated_options[ 'session_filters' ] )
  498. $options[ 'session' ] = false;
  499. if ( isset( $deprecated_options[ 'user_per_page' ] ) ) {
  500. if ( isset( $options[ 'user' ] ) && !empty( $options[ 'user' ] ) )
  501. $options[ 'user' ] = array( 'orderby' );
  502. else
  503. $options[ 'user' ] = false;
  504. }
  505. if ( isset( $deprecated_options[ 'user_sort' ] ) ) {
  506. if ( isset( $options[ 'user' ] ) && !empty( $options[ 'user' ] ) )
  507. $options[ 'user' ] = array( 'show_per_page' );
  508. else
  509. $options[ 'user' ] = false;
  510. }
  511. if ( isset( $deprecated_options[ 'custom_list' ] ) ) {
  512. if ( isset( $options[ 'actions_custom' ] ) )
  513. $options[ 'actions_custom' ][ 'manage' ] = $deprecated_options[ 'custom_list' ];
  514. else
  515. $options[ 'actions_custom' ] = array( 'manage' => $deprecated_options[ 'custom_list' ] );
  516. }
  517. if ( isset( $deprecated_options[ 'custom_reorder' ] ) ) {
  518. if ( isset( $options[ 'actions_custom' ] ) )
  519. $options[ 'actions_custom' ][ 'reorder' ] = $deprecated_options[ 'custom_reorder' ];
  520. else
  521. $options[ 'actions_custom' ] = array( 'reorder' => $deprecated_options[ 'custom_reorder' ] );
  522. }
  523. if ( isset( $deprecated_options[ 'custom_add' ] ) ) {
  524. if ( isset( $options[ 'actions_custom' ] ) )
  525. $options[ 'actions_custom' ][ 'add' ] = $deprecated_options[ 'custom_add' ];
  526. else
  527. $options[ 'actions_custom' ] = array( 'add' => $deprecated_options[ 'custom_add' ] );
  528. }
  529. if ( isset( $deprecated_options[ 'custom_edit' ] ) ) {
  530. if ( isset( $options[ 'actions_custom' ] ) )
  531. $options[ 'actions_custom' ][ 'edit' ] = $deprecated_options[ 'custom_edit' ];
  532. else
  533. $options[ 'actions_custom' ] = array( 'edit' => $deprecated_options[ 'custom_edit' ] );
  534. }
  535. if ( isset( $deprecated_options[ 'custom_duplicate' ] ) ) {
  536. if ( isset( $options[ 'actions_custom' ] ) )
  537. $options[ 'actions_custom' ][ 'duplicate' ] = $deprecated_options[ 'custom_duplicate' ];
  538. else
  539. $options[ 'actions_custom' ] = array( 'duplicate' => $deprecated_options[ 'custom_duplicate' ] );
  540. }
  541. if ( isset( $deprecated_options[ 'custom_delete' ] ) ) {
  542. if ( isset( $options[ 'actions_custom' ] ) )
  543. $options[ 'actions_custom' ][ 'delete' ] = $deprecated_options[ 'custom_delete' ];
  544. else
  545. $options[ 'actions_custom' ] = array( 'delete' => $deprecated_options[ 'custom_delete' ] );
  546. }
  547. if ( isset( $deprecated_options[ 'custom_save' ] ) ) {
  548. if ( isset( $options[ 'actions_custom' ] ) )
  549. $options[ 'actions_custom' ][ 'save' ] = $deprecated_options[ 'custom_save' ];
  550. else
  551. $options[ 'actions_custom' ] = array( 'save' => $deprecated_options[ 'custom_save' ] );
  552. }
  553. if ( isset( $deprecated_options[ 'custom_actions' ] ) )
  554. $options[ 'actions_custom' ] = $deprecated_options[ 'custom_actions' ];
  555. if ( isset( $deprecated_options[ 'action_after_save' ] ) )
  556. $options[ 'action_after' ] = array(
  557. 'add' => $deprecated_options[ 'action_after_save' ],
  558. 'edit' => $deprecated_options[ 'action_after_save' ],
  559. 'duplicate' => $deprecated_options[ 'action_after_save' ]
  560. );
  561. if ( isset( $deprecated_options[ 'edit_link' ] ) ) {
  562. if ( isset( $options[ 'action_links' ] ) )
  563. $options[ 'action_links' ][ 'edit' ] = $deprecated_options[ 'edit_link' ];
  564. else
  565. $options[ 'action_links' ] = array( 'edit' => $deprecated_options[ 'edit_link' ] );
  566. }
  567. if ( isset( $deprecated_options[ 'view_link' ] ) ) {
  568. if ( isset( $options[ 'action_links' ] ) )
  569. $options[ 'action_links' ][ 'view' ] = $deprecated_options[ 'view_link' ];
  570. else
  571. $options[ 'action_links' ] = array( 'view' => $deprecated_options[ 'view_link' ] );
  572. }
  573. if ( isset( $deprecated_options[ 'duplicate_link' ] ) ) {
  574. if ( isset( $options[ 'action_links' ] ) )
  575. $options[ 'action_links' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_link' ];
  576. else
  577. $options[ 'action_links' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_link' ] );
  578. }
  579. if ( isset( $deprecated_options[ 'reorder' ] ) )
  580. $options[ 'reorder' ] = array(
  581. 'on' => $deprecated_options[ 'reorder' ],
  582. 'orderby' => $deprecated_options[ 'reorder' ]
  583. );
  584. if ( isset( $deprecated_options[ 'reorder_sort' ] ) && isset( $options[ 'reorder' ] ) )
  585. $options[ 'reorder' ][ 'orderby' ] = $deprecated_options[ 'reorder_sort' ];
  586. if ( isset( $deprecated_options[ 'reorder_limit' ] ) && isset( $options[ 'reorder' ] ) )
  587. $options[ 'reorder' ][ 'limit' ] = $deprecated_options[ 'reorder_limit' ];
  588. if ( isset( $deprecated_options[ 'reorder_sql' ] ) && isset( $options[ 'reorder' ] ) )
  589. $options[ 'reorder' ][ 'sql' ] = $deprecated_options[ 'reorder_sql' ];
  590. if ( isset( $deprecated_options[ 'sort' ] ) )
  591. $options[ 'orderby' ] = $deprecated_options[ 'sort' ];
  592. if ( isset( $deprecated_options[ 'sortable' ] ) )
  593. $options[ 'sortable' ] = $deprecated_options[ 'sortable' ];
  594. if ( isset( $deprecated_options[ 'limit' ] ) )
  595. $options[ 'limit' ] = $deprecated_options[ 'limit' ];
  596. if ( isset( $deprecated_options[ 'where' ] ) ) {
  597. if ( isset( $options[ 'where' ] ) )
  598. $options[ 'where' ][ 'manage' ] = $deprecated_options[ 'where' ];
  599. else
  600. $options[ 'where' ] = array( 'manage' => $deprecated_options[ 'where' ] );
  601. }
  602. if ( isset( $deprecated_options[ 'edit_where' ] ) ) {
  603. if ( isset( $options[ 'where' ] ) )
  604. $options[ 'where' ][ 'edit' ] = $deprecated_options[ 'edit_where' ];
  605. else
  606. $options[ 'where' ] = array( 'edit' => $deprecated_options[ 'edit_where' ] );
  607. if ( isset( $options[ 'restrict' ] ) )
  608. $options[ 'restrict' ][ 'edit' ] = (array) $deprecated_options[ 'edit_where' ];
  609. else
  610. $options[ 'restrict' ] = array( 'edit' => (array) $deprecated_options[ 'edit_where' ] );
  611. }
  612. if ( isset( $deprecated_options[ 'duplicate_where' ] ) ) {
  613. if ( isset( $options[ 'where' ] ) )
  614. $options[ 'where' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_where' ];
  615. else
  616. $options[ 'where' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_where' ] );
  617. if ( isset( $options[ 'restrict' ] ) )
  618. $options[ 'restrict' ][ 'duplicate' ] = (array) $deprecated_options[ 'duplicate_where' ];
  619. else
  620. $options[ 'restrict' ] = array( 'duplicate' => (array) $deprecated_options[ 'duplicate_where' ] );
  621. }
  622. if ( isset( $deprecated_options[ 'delete_where' ] ) ) {
  623. if ( isset( $options[ 'where' ] ) )
  624. $options[ 'where' ][ 'delete' ] = $deprecated_options[ 'delete_where' ];
  625. else
  626. $options[ 'where' ] = array( 'delete' => $deprecated_options[ 'delete_where' ] );
  627. if ( isset( $options[ 'restrict' ] ) )
  628. $options[ 'restrict' ][ 'delete' ] = (array) $deprecated_options[ 'delete_where' ];
  629. else
  630. $options[ 'restrict' ] = array( 'delete' => (array) $deprecated_options[ 'delete_where' ] );
  631. }
  632. if ( isset( $deprecated_options[ 'reorder_where' ] ) ) {
  633. if ( isset( $options[ 'where' ] ) )
  634. $options[ 'where' ][ 'reorder' ] = $deprecated_options[ 'reorder_where' ];
  635. else
  636. $options[ 'where' ] = array( 'reorder' => $deprecated_options[ 'reorder_where' ] );
  637. }
  638. if ( isset( $deprecated_options[ 'sql' ] ) )
  639. $options[ 'sql' ] = array( 'sql' => $deprecated_options[ 'sql' ] );
  640. if ( isset( $deprecated_options[ 'search' ] ) )
  641. $options[ 'searchable' ] = $deprecated_options[ 'search' ];
  642. if ( isset( $deprecated_options[ 'search_across' ] ) )
  643. $options[ 'search_across' ] = $deprecated_options[ 'search_across' ];
  644. if ( isset( $deprecated_options[ 'search_across_picks' ] ) )
  645. $options[ 'search_across_picks' ] = $deprecated_options[ 'search_across_picks' ];
  646. if ( isset( $deprecated_options[ 'filters' ] ) )
  647. $options[ 'filters' ] = $deprecated_options[ 'filters' ];
  648. if ( isset( $deprecated_options[ 'custom_filters' ] ) ) {
  649. if ( is_callable( $deprecated_options[ 'custom_filters' ] ) )
  650. add_filter( 'pods_ui_filters', $deprecated_options[ 'custom_filters' ] );
  651. else {
  652. global $pods_ui_custom_filters;
  653. $pods_ui_custom_filters = $deprecated_options[ 'custom_filters' ];
  654. add_filter( 'pods_ui_filters', array( $this, 'deprecated_filters' ) );
  655. }
  656. }
  657. if ( isset( $deprecated_options[ 'disable_actions' ] ) )
  658. $options[ 'actions_disabled' ] = $deprecated_options[ 'disable_actions' ];
  659. if ( isset( $deprecated_options[ 'hide_actions' ] ) )
  660. $options[ 'actions_hidden' ] = $deprecated_options[ 'hide_actions' ];
  661. if ( isset( $deprecated_options[ 'wpcss' ] ) )
  662. $options[ 'wpcss' ] = $deprecated_options[ 'wpcss' ];
  663. $remaining_options = array_diff_assoc( $options, $deprecated_options );
  664. foreach ( $remaining_options as $option => $value ) {
  665. if ( isset( $deprecated_options[ $option ] ) && isset( $this->$option ) )
  666. $options[ $option ] = $value;
  667. }
  668. return $options;
  669. }
  670. /**
  671. *
  672. */
  673. public function deprecated_filters () {
  674. global $pods_ui_custom_filters;
  675. echo $pods_ui_custom_filters;
  676. }
  677. /**
  678. * @param $options
  679. *
  680. * @return array|bool|mixed|null|PodsArray
  681. */
  682. public function setup ( $options ) {
  683. $options = pods_array( $options );
  684. $options->validate( 'num', '', 'absint' );
  685. if ( empty( $options->num ) )
  686. $options->num = '';
  687. $options->validate( 'id', pods_var( 'id' . $options->num, 'get', $this->id ) );
  688. $options->validate( 'do', pods_var( 'do' . $options->num, 'get', $this->do ), 'in_array', array(
  689. 'save',
  690. 'create'
  691. ) );
  692. $options->validate( 'excluded', self::$excluded, 'array_merge' );
  693. $options->validate( 'action', pods_var( 'action' . $options->num, 'get', $this->action, null, true ), 'in_array', $this->actions );
  694. $options->validate( 'actions_bulk', $this->actions_bulk, 'array_merge' );
  695. $options->validate( 'action_bulk', pods_var( 'action_bulk' . $options->num, 'get', $this->action_bulk, null, true ), 'isset', $this->actions_bulk );
  696. $options->validate( 'bulk', pods_var( 'action_bulk_ids' . $options->num, 'get', array(), null, true ), 'array_merge', $this->bulk );
  697. $options->validate( 'views', $this->views, 'array' );
  698. $options->validate( 'view', pods_var( 'view' . $options->num, 'get', $this->view, null, true ), 'isset', $this->views );
  699. $options->validate( 'searchable', $this->searchable, 'boolean' );
  700. $options->validate( 'search', pods_var( 'search' . $options->num, 'get' ) );
  701. $options->validate( 'search_across', $this->search_across, 'boolean' );
  702. $options->validate( 'search_across_picks', $this->search_across_picks, 'boolean' );
  703. $options->validate( 'filters', $this->filters, 'array' );
  704. $options->validate( 'filters_enhanced', $this->filters_enhanced, 'boolean' );
  705. $options->validate( 'where', $this->where, 'array_merge' );
  706. $options->validate( 'pagination', $this->pagination, 'boolean' );
  707. $options->validate( 'page', pods_var( 'pg' . $options->num, 'get', $this->page ), 'absint' );
  708. $options->validate( 'limit', pods_var( 'limit' . $options->num, 'get', $this->limit ), 'int' );
  709. if ( isset( $this->pods_data ) && is_object( $this->pods_data ) ) {
  710. $this->sql = array(
  711. 'table' => $this->pods_data->table,
  712. 'field_id' => $this->pods_data->field_id,
  713. 'field_index' => $this->pods_data->field_index
  714. );
  715. }
  716. $options->validate( 'sql', $this->sql, 'array_merge' );
  717. $options->validate( 'orderby_dir', strtoupper( pods_var_raw( 'orderby_dir' . $options[ 'num' ], 'get', $this->orderby_dir, null, true ) ), 'in_array', array( 'ASC', 'DESC' ) );
  718. $orderby = pods_var_raw( 'orderby' . $options->num, 'get', $this->orderby, null, true );
  719. if ( !empty( $orderby ) ) {
  720. $orderby = array(
  721. 'default' => $orderby
  722. );
  723. }
  724. else
  725. $orderby = array();
  726. $options->validate( 'orderby', $orderby, 'array_merge' );
  727. $options->validate( 'sortable', $this->sortable, 'boolean' );
  728. $options->validate( 'params', $this->params, 'array' );
  729. $options->validate( 'restrict', $this->restrict, 'array_merge' );
  730. // handle author restrictions
  731. if ( !empty( $options[ 'restrict' ][ 'author_restrict' ] ) ) {
  732. if ( !is_array( $options[ 'restrict' ][ 'author_restrict' ] ) )
  733. $options->restrict[ 'author_restrict' ] = array( $options[ 'restrict' ][ 'author_restrict' ] => get_current_user_id() );
  734. if ( null === $options[ 'restrict' ][ 'edit' ] )
  735. $options->restrict[ 'edit' ] = $options[ 'restrict' ][ 'author_restrict' ];
  736. }
  737. if ( null !== $options[ 'restrict' ][ 'edit' ] ) {
  738. if ( null === $options[ 'restrict' ][ 'duplicate' ] )
  739. $options->restrict[ 'duplicate' ] = $options[ 'restrict' ][ 'edit' ];
  740. if ( null === $options[ 'restrict' ][ 'delete' ] )
  741. $options->restrict[ 'delete' ] = $options[ 'restrict' ][ 'edit' ];
  742. if ( null === $options[ 'restrict' ][ 'manage' ] )
  743. $options->restrict[ 'manage' ] = $options[ 'restrict' ][ 'edit' ];
  744. if ( null === $options[ 'restrict' ][ 'reorder' ] )
  745. $options->restrict[ 'reorder' ] = $options[ 'restrict' ][ 'edit' ];
  746. }
  747. $item = __( 'Item', 'pods' );
  748. $items = __( 'Items', 'pods' );
  749. if ( is_object( $this->pod ) ) {
  750. $item = pods_var_raw( 'label_singular', $this->pod->pod_data[ 'options' ], pods_var_raw( 'label', $this->pod->pod_data, $item, null, true ), null, true );
  751. $items = pods_var_raw( 'label', $this->pod->pod_data, $items, null, true );
  752. }
  753. $options->validate( 'item', $item );
  754. $options->validate( 'items', $items );
  755. $options->validate( 'heading', array(
  756. 'manage' => __( 'Manage', 'pods' ),
  757. 'add' => __( 'Add New', 'pods' ),
  758. 'edit' => __( 'Edit', 'pods' ),
  759. 'duplicate' => __( 'Duplicate', 'pods' ),
  760. 'view' => __( 'View', 'pods' ),
  761. 'reorder' => __( 'Reorder', 'pods' ),
  762. 'search' => __( 'Search', 'pods' ),
  763. 'views' => __( 'View', 'pods' )
  764. ), 'array_merge' );
  765. $options->validate( 'header', array(
  766. 'manage' => $options->items,
  767. 'add' => $options->heading[ 'add' ] . " {$options->item}",
  768. 'edit' => $options->heading[ 'edit' ] . " {$options->item}",
  769. 'duplicate' => $options->heading[ 'duplicate' ] . " {$options->item}",
  770. 'view' => $options->heading[ 'view' ] . " {$options->item}",
  771. 'reorder' => $options->heading[ 'reorder' ] . " {$options->items}",
  772. 'search' => $options->heading[ 'search' ] . " {$options->items}"
  773. ), 'array_merge' );
  774. $options->validate( 'label', array(
  775. 'add' => __( 'Save New', 'pods' ) . " {$options->item}",
  776. 'add_new' => __( 'Add New', 'pods' ),
  777. 'edit' => __( 'Save', 'pods' ) . " {$options->item}",
  778. 'duplicate' => __( 'Save New', 'pods' ) . " {$options->item}",
  779. 'delete' => __( 'Delete this', 'pods' ) . " {$options->item}",
  780. 'view' => __( 'View', 'pods' ) . " {$options->item}",
  781. 'reorder' => __( 'Reorder', 'pods' ) . " {$options->items}"
  782. ), 'array_merge' );
  783. $options->validate( 'fields', array(
  784. 'manage' => array(
  785. $options->sql[ 'field_index' ] => array( 'label' => __( 'Name', 'pods' ) )
  786. )
  787. ), 'array' );
  788. $options->validate( 'export', $this->export, 'array_merge' );
  789. $options->validate( 'reorder', $this->reorder, 'array_merge' );
  790. $options->validate( 'screen_options', $this->screen_options, 'array_merge' );
  791. $options->validate( 'session', $this->session, 'in_array', array(
  792. 'search',
  793. 'filters',
  794. 'show_per_page',
  795. 'orderby'
  796. ) );
  797. $options->validate( 'user', $this->user, 'in_array', array(
  798. 'search',
  799. 'filters',
  800. 'show_per_page',
  801. 'orderby'
  802. ) );
  803. $options->validate( 'action_after', $this->action_after, 'array_merge' );
  804. $options->validate( 'action_links', $this->action_links, 'array_merge' );
  805. $options->validate( 'actions_disabled', $this->actions_disabled, 'array' );
  806. $options->validate( 'actions_hidden', $this->actions_hidden, 'array_merge' );
  807. $options->validate( 'actions_custom', $this->actions_custom, 'array_merge' );
  808. $options->validate( 'icon', $this->icon );
  809. $options->validate( 'css', $this->css );
  810. $options->validate( 'wpcss', $this->wpcss, 'boolean' );
  811. if ( true === $options[ 'wpcss' ] ) {
  812. global $user_ID;
  813. get_currentuserinfo();
  814. $color = get_user_meta( $user_ID, 'admin_color', true );
  815. if ( strlen( $color ) < 1 )
  816. $color = 'fresh';
  817. $this->wpcss = "colors-{$color}";
  818. }
  819. $options = $options->dump();
  820. $options = $this->do_hook( 'setup_options', $options );
  821. if ( false !== $options && !empty( $options ) ) {
  822. foreach ( $options as $option => $value ) {
  823. if ( isset( $this->{$option} ) )
  824. $this->{$option} = $value;
  825. else
  826. $this->x[ $option ] = $value;
  827. }
  828. }
  829. $unique_identifier = pods_var( 'page', 'get' ); // wp-admin page
  830. if ( is_object( $this->pod ) && isset( $this->pod->pod ) )
  831. $unique_identifier = '_' . $this->pod->pod;
  832. elseif ( 0 < strlen( $this->sql[ 'table' ] ) )
  833. $unique_identifier = '_' . $this->sql[ 'table' ];
  834. $unique_identifier .= '_' . $this->page;
  835. if ( 0 < strlen( $this->num ) )
  836. $unique_identifier .= '_' . $this->num;
  837. $this->unique_identifier = 'pods_ui_' . md5( $unique_identifier );
  838. $this->setup_fields();
  839. return $options;
  840. }
  841. /**
  842. * @param null $fields
  843. * @param string $which
  844. *
  845. * @return array|bool|mixed|null
  846. */
  847. public function setup_fields ( $fields = null, $which = 'fields' ) {
  848. $init = false;
  849. if ( null === $fields ) {
  850. if ( isset( $this->fields[ $which ] ) )
  851. $fields = (array) $this->fields[ $which ];
  852. elseif ( isset( $this->fields[ 'manage' ] ) )
  853. $fields = (array) $this->fields[ 'manage' ];
  854. else
  855. $fields = array();
  856. if ( 'fields' == $which )
  857. $init = true;
  858. }
  859. if ( !empty( $fields ) ) {
  860. // Available Attributes
  861. // type = field type
  862. // type = date (data validation as date)
  863. // type = time (data validation as time)
  864. // type = datetime (data validation as datetime)
  865. // date_touch = use current timestamp when saving (even if readonly, if type is date-related)
  866. // date_touch_on_create = use current timestamp when saving ONLY on create (even if readonly, if type is date-related)
  867. // date_ongoing = use this additional field to search between as if the first is the "start" and the date_ongoing is the "end" for filter
  868. // type = text / other (single line text box)
  869. // type = desc (textarea)
  870. // type = number (data validation as int float)
  871. // type = decimal (data validation as decimal)
  872. // type = password (single line password box)
  873. // type = bool (checkbox)
  874. // type = related (select box)
  875. // related = table to relate to (if type=related) OR custom array of (key => label or comma separated values) items
  876. // related_field = field name on table to show (if type=related) - default "name"
  877. // related_multiple = true (ability to select multiple values if type=related)
  878. // related_sql = custom where / order by SQL (if type=related)
  879. // readonly = true (shows as text)
  880. // display = false (doesn't show on form, but can be saved)
  881. // search = this field is searchable
  882. // filter = this field will be independently searchable (by default, searchable fields are searched by the primary search box)
  883. // comments = comments to show for field
  884. // comments_top = true (shows comments above field instead of below)
  885. // real_name = the real name of the field (if using an alias for 'name')
  886. // group_related = true (uses HAVING instead of WHERE for filtering field)
  887. $new_fields = array();
  888. $filterable = false;
  889. if ( empty( $this->filters ) && ( empty( $this->fields[ 'search' ] ) || 'search' == $which ) && false !== $this->searchable ) {
  890. $filterable = true;
  891. $this->filters = array();
  892. }
  893. foreach ( $fields as $field => $attributes ) {
  894. if ( !is_array( $attributes ) ) {
  895. if ( is_int( $field ) ) {
  896. $field = $attributes;
  897. $attributes = array();
  898. }
  899. else
  900. $attributes = array( 'label' => $attributes );
  901. }
  902. if ( !isset( $attributes[ 'real_name' ] ) )
  903. $attributes[ 'real_name' ] = pods_var( 'name', $attributes, $field );
  904. if ( is_object( $this->pod ) && isset( $this->pod->fields ) && isset( $this->pod->fields[ $attributes[ 'real_name' ] ] ) )
  905. $attributes = array_merge( $this->pod->fields[ $attributes[ 'real_name' ] ], $attributes );
  906. if ( !isset( $attributes[ 'options' ] ) )
  907. $attributes[ 'options' ] = array();
  908. if ( !isset( $attributes[ 'id' ] ) )
  909. $attributes[ 'id' ] = '';
  910. if ( !isset( $attributes[ 'label' ] ) )
  911. $attributes[ 'label' ] = ucwords( str_replace( '_', ' ', $field ) );
  912. if ( !isset( $attributes[ 'type' ] ) )
  913. $attributes[ 'type' ] = 'text';
  914. if ( !isset( $attributes[ 'options' ][ 'date_format_type' ] ) )
  915. $attributes[ 'options' ][ 'date_format_type' ] = 'date';
  916. if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related' ] ) )
  917. $attributes[ 'related' ] = false;
  918. if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_id' ] ) )
  919. $attributes[ 'related_id' ] = 'id';
  920. if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_field' ] ) )
  921. $attributes[ 'related_field' ] = 'name';
  922. if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_multiple' ] ) )
  923. $attributes[ 'related_multiple' ] = false;
  924. if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_sql' ] ) )
  925. $attributes[ 'related_sql' ] = false;
  926. if ( 'related' == $attributes[ 'type' ] && ( is_array( $attributes[ 'related' ] ) || strpos( $attributes[ 'related' ], ',' ) ) ) {
  927. if ( !is_array( $attributes[ 'related' ] ) ) {
  928. $attributes[ 'related' ] = @explode( ',', $attributes[ 'related' ] );
  929. $related_items = array();
  930. foreach ( $attributes[ 'related' ] as $key => $label ) {
  931. if ( is_numeric( $key ) ) {
  932. $key = $label;
  933. $label = ucwords( str_replace( '_', ' ', $label ) );
  934. }
  935. $related_items[ $key ] = $label;
  936. }
  937. $attributes[ 'related' ] = $related_items;
  938. }
  939. if ( empty( $attributes[ 'related' ] ) )
  940. $attributes[ 'related' ] = false;
  941. }
  942. if ( !isset( $attributes[ 'readonly' ] ) )
  943. $attributes[ 'readonly' ] = false;
  944. if ( !isset( $attributes[ 'date_touch' ] ) || 'date' != $attributes[ 'type' ] )
  945. $attributes[ 'date_touch' ] = false;
  946. if ( !isset( $attributes[ 'date_touch_on_create' ] ) || 'date' != $attributes[ 'type' ] )
  947. $attributes[ 'date_touch_on_create' ] = false;
  948. if ( !isset( $attributes[ 'display' ] ) )
  949. $attributes[ 'display' ] = true;
  950. if ( !isset( $attributes[ 'hidden' ] ) )
  951. $attributes[ 'hidden' ] = false;
  952. if ( !isset( $attributes[ 'sortable' ] ) || false === $this->sortable )
  953. $attributes[ 'sortable' ] = $this->sortable;
  954. if ( !isset( $attributes[ 'options' ][ 'search' ] ) || false === $this->searchable )
  955. $attributes[ 'options' ][ 'search' ] = $this->searchable;
  956. if ( !isset( $attributes[ 'options' ][ 'filter' ] ) || false === $this->searchable )
  957. $attributes[ 'options' ][ 'filter' ] = $this->searchable;
  958. /*if ( false !== $attributes[ 'options' ][ 'filter' ] && false !== $filterable )
  959. $this->filters[] = $field;*/
  960. if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'filter_label' ] ) || !in_array( $field, $this->filters ) )
  961. $attributes[ 'filter_label' ] = $attributes[ 'label' ];
  962. if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'filter_default' ] ) || !in_array( $field, $this->filters ) )
  963. $attributes[ 'filter_default' ] = false;
  964. if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'date_ongoing' ] ) || 'date' != $attributes[ 'type' ] || !in_array( $field, $this->filters ) )
  965. $attributes[ 'date_ongoing' ] = false;
  966. if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'date_ongoing' ] ) || 'date' != $attributes[ 'type' ] || !isset( $attributes[ 'date_ongoing_default' ] ) || !in_array( $field, $this->filters ) )
  967. $attributes[ 'date_ongoing_default' ] = false;
  968. if ( !isset( $attributes[ 'export' ] ) )
  969. $attributes[ 'export' ] = true;
  970. if ( !isset( $attributes[ 'group_related' ] ) )
  971. $attributes[ 'group_related' ] = false;
  972. if ( !isset( $attributes[ 'comments' ] ) )
  973. $attributes[ 'comments' ] = '';
  974. if ( !isset( $attributes[ 'comments_top' ] ) )
  975. $attributes[ 'comments_top' ] = false;
  976. if ( !isset( $attributes[ 'custom_view' ] ) )
  977. $attributes[ 'custom_view' ] = false;
  978. if ( !isset( $attributes[ 'custom_input' ] ) )
  979. $attributes[ 'custom_input' ] = false;
  980. if ( isset( $attributes[ 'display_helper' ] ) ) // pods ui backward compatibility
  981. $attributes[ 'custom_display' ] = $attributes[ 'display_helper' ];
  982. if ( !isset( $attributes[ 'custom_display' ] ) )
  983. $attributes[ 'custom_display' ] = false;
  984. if ( !isset( $attributes[ 'custom_relate' ] ) )
  985. $attributes[ 'custom_relate' ] = false;
  986. if ( !isset( $attributes[ 'custom_form_display' ] ) )
  987. $attributes[ 'custom_form_display' ] = false;
  988. if ( 'search_columns' == $which && !$attributes[ 'options' ][ 'search' ] )
  989. continue;
  990. $attributes = PodsForm::field_setup( $attributes, null, $attributes[ 'type' ] );
  991. $new_fields[ $field ] = $attributes;
  992. }
  993. $fields = $new_fields;
  994. }
  995. if ( false !== $init ) {
  996. if ( 'fields' != $which && !empty( $this->fields ) )
  997. $this->fields = $this->setup_fields( $this->fields, 'fields' );
  998. else
  999. $this->fields[ 'manage' ] = $fields;
  1000. if ( !in_array( 'add', $this->actions_disabled ) || !in_array( 'edit', $this->actions_disabled ) || !in_array( 'duplicate', $this->actions_disabled ) ) {
  1001. if ( 'form' != $which && isset( $this->fields[ 'form' ] ) && is_array( $this->fields[ 'form' ] ) )
  1002. $this->fields[ 'form' ] = $this->setup_fields( $this->fields[ 'form' ], 'form' );
  1003. else
  1004. $this->fields[ 'form' ] = $fields;
  1005. if ( !in_array( 'add', $this->actions_disabled ) ) {
  1006. if ( 'add' != $which && isset( $this->fields[ 'add' ] ) && is_array( $this->fields[ 'add' ] ) )
  1007. $this->fields[ 'add' ] = $this->setup_fields( $this->fields[ 'add' ], 'add' );
  1008. }
  1009. if ( !in_array( 'edit', $this->actions_disabled ) ) {
  1010. if ( 'edit' != $which && isset( $this->fields[ 'edit' ] ) && is_array( $this->fields[ 'edit' ] ) )
  1011. $this->fields[ 'edit' ] = $this->setup_fields( $this->fields[ 'edit' ], 'edit' );
  1012. }
  1013. if ( !in_array( 'duplicate', $this->actions_disabled ) ) {
  1014. if ( 'duplicate' != $which && isset( $this->fields[ 'duplicate' ] ) && is_array( $this->fields[ 'duplicate' ] ) )
  1015. $this->fields[ 'duplicate' ] = $this->setup_fields( $this->fields[ 'duplicate' ], 'duplicate' );
  1016. }
  1017. }
  1018. if ( false !== $this->searchable ) {
  1019. if ( 'search' != $which && isset( $this->fields[ 'search' ] ) &&!empty( $this->fields[ 'search' ] ) )
  1020. $this->fields[ 'search' ] = $this->setup_fields( $this->fields[ 'search' ], 'search' );
  1021. else
  1022. $this->fields[ 'search' ] = $fields;
  1023. }
  1024. else
  1025. $this->fields[ 'search' ] = false;
  1026. if ( !in_array( 'export', $this->actions_disabled ) ) {
  1027. if ( 'export' != $which && isset( $this->fields[ 'export' ] ) &&!empty( $this->fields[ 'export' ] ) )
  1028. $this->fields[ 'export' ] = $this->setup_fields( $this->fields[ 'export' ], 'export' );
  1029. }
  1030. if ( !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
  1031. if ( 'reorder' != $which && isset( $this->fields[ 'reorder' ] ) &&!empty( $this->fields[ 'reorder' ] ) )
  1032. $this->fields[ 'reorder' ] = $this->setup_fields( $this->fields[ 'reorder' ], 'reorder' );
  1033. else
  1034. $this->fields[ 'reorder' ] = $fields;
  1035. }
  1036. }
  1037. return $this->do_hook( 'setup_fields', $fields, $which, $init );
  1038. }
  1039. /**
  1040. * @param $msg
  1041. * @param bool $error
  1042. */
  1043. public function message ( $msg, $error = false ) {
  1044. $msg = $this->do_hook( ( $error ) ? 'error' : 'message', $msg );
  1045. ?>
  1046. <div id="message" class="<?php echo ( $error ) ? 'error' : 'updated'; ?> fade"><p><?php echo $msg; ?></p></div>
  1047. <?php
  1048. }
  1049. /**
  1050. * @param $msg
  1051. *
  1052. * @return bool
  1053. */
  1054. public function error ( $msg ) {
  1055. $this->message( $msg, true );
  1056. return false;
  1057. }
  1058. /**
  1059. * @return mixed
  1060. */
  1061. public function go () {
  1062. $this->do_hook( 'go' );
  1063. $_GET = pods_unsanitize( $_GET ); // fix wp sanitization
  1064. $_POST = pods_unsanitize( $_POST ); // fix wp sanitization
  1065. if ( false !== $this->css ) {
  1066. ?>
  1067. <link type="text/css" rel="stylesheet" href="<?php echo $this->css; ?>" />
  1068. <?php
  1069. }
  1070. if ( false !== $this->wpcss ) {
  1071. $stylesheets = array( 'global', 'wp-admin', $this->wpcss );
  1072. foreach ( $stylesheets as $style ) {
  1073. if ( !wp_style_is( $style, 'queue' ) && !wp_style_is( $style, 'to_do' ) && !wp_style_is( $style, 'done' ) )
  1074. wp_enqueue_style( $style );
  1075. }
  1076. }
  1077. $this->ui_page = array( $this->action );
  1078. if ( 'add' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) {
  1079. $this->ui_page[] = 'form';
  1080. if ( 'create' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) {
  1081. $this->ui_page[] = $this->do;
  1082. $this->save( true );
  1083. $this->manage();
  1084. }
  1085. else
  1086. $this->add();
  1087. }
  1088. elseif ( ( 'edit' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) || ( 'duplicate' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) ) {
  1089. $this->ui_page[] = 'form';
  1090. if ( 'save' == $this->do && $this->save && !empty( $_POST ) )
  1091. $this->save();
  1092. $this->edit( ( 'duplicate' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) ? 1 : 0 );
  1093. }
  1094. elseif ( 'delete' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) {
  1095. $this->delete( $this->id );
  1096. $this->manage();
  1097. }
  1098. elseif ( 'reorder' == $this->action && !in_array( $this->action, $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
  1099. if ( 's…

Large files files are truncated, but you can click here to view the full file