PageRenderTime 76ms CodeModel.GetById 18ms 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
  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 ( 'save' == $this->do ) {
  1100. $this->ui_page[] = $this->do;
  1101. $this->reorder();
  1102. }
  1103. $this->manage( true );
  1104. }
  1105. elseif ( 'save' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) {
  1106. $this->ui_page[] = $this->do;
  1107. $this->save();
  1108. $this->manage();
  1109. }
  1110. elseif ( 'create' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) {
  1111. $this->ui_page[] = $this->do;
  1112. $this->save( true );
  1113. $this->manage();
  1114. }
  1115. elseif ( 'view' == $this->action && !in_array( $this->action, $this->actions_disabled ) )
  1116. $this->view();
  1117. elseif ( isset( $this->actions_custom[ $this->action ] ) && is_callable( $this->actions_custom[ $this->action ] ) )
  1118. return call_user_func_array( $this->actions_custom[ $this->action ], array( &$this, $this->id ) );
  1119. elseif ( isset( $this->actions_custom[ $this->action ] ) && ( is_array( $this->actions_custom[ $this->action ] ) && isset( $this->actions_custom[ $this->action ][ 'callback' ] ) && is_callable( $this->actions_custom[ $this->action ][ 'callback' ] ) ) )
  1120. return call_user_func_array( $this->actions_custom[ $this->action ][ 'callback' ], array( &$this, $this->id ) );
  1121. elseif ( !in_array( 'manage', $this->actions_disabled ) )
  1122. $this->manage();
  1123. // handle session / user persistent settings for show_per_page, orderby, search, and filters
  1124. $methods = array( 'session', 'user' );
  1125. foreach ( $methods as $method ) {
  1126. foreach ( $this->$method as $setting ) {
  1127. if ( 'show_per_page' == $setting )
  1128. $value = $this->limit;
  1129. elseif ( 'orderby' == $setting ) {
  1130. if ( empty( $this->orderby ) )
  1131. $value = '';
  1132. elseif ( isset( $this->orderby[ 'default' ] ) ) // save this if we have a default index set
  1133. $value = $this->orderby[ 'default' ] . ' '
  1134. . ( false === strpos( $this->orderby[ 'default' ], ' ' ) ? $this->orderby_dir : '' );
  1135. else
  1136. $value = '';
  1137. }
  1138. else
  1139. $value = $this->$setting;
  1140. pods_var_set( $value, $setting, $method );
  1141. }
  1142. }
  1143. }
  1144. /**
  1145. * @return mixed
  1146. */
  1147. public function add () {
  1148. $this->do_hook( 'add' );
  1149. if ( isset( $this->actions_custom[ 'add' ] ) && is_callable( $this->actions_custom[ 'add' ] ) )
  1150. return call_user_func_array( $this->actions_custom[ 'add' ], array( &$this ) );
  1151. ?>
  1152. <div class="wrap">
  1153. <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-image:url(<?php echo $this->icon; ?>);"<?php } ?>><br /></div>
  1154. <h2>
  1155. <?php
  1156. echo $this->header[ 'add' ];
  1157. $link = pods_var_update( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), array( 'page' ), $this->exclusion() );
  1158. ?>
  1159. <a href="<?php echo $link; ?>" class="add-new-h2">&laquo; <?php _e( 'Back to', 'pods' ); ?> <?php echo $this->heading[ 'manage' ]; ?></a>
  1160. </h2>
  1161. <?php $this->form( true ); ?>
  1162. </div>
  1163. <?php
  1164. }
  1165. /**
  1166. * @param bool $duplicate
  1167. *
  1168. * @return mixed
  1169. */
  1170. public function edit ( $duplicate = false ) {
  1171. if ( in_array( 'duplicate', $this->actions_disabled ) )
  1172. $duplicate = false;
  1173. if ( empty( $this->row ) )
  1174. $this->get_row();
  1175. $this->do_hook( 'edit', $duplicate );
  1176. if ( isset( $this->actions_custom[ 'edit' ] ) && is_callable( $this->actions_custom[ 'edit' ] ) )
  1177. return call_user_func_array( $this->actions_custom[ 'edit' ], array( $duplicate, &$this ) );
  1178. ?>
  1179. <div class="wrap">
  1180. <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-image:url(<?php echo $this->icon; ?>);"<?php } ?>><br /></div>
  1181. <h2>
  1182. <?php
  1183. echo ( $duplicate ? $this->header[ 'duplicate' ] : $this->header[ 'edit' ] );
  1184. if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
  1185. $link = pods_var_update( array( 'action' . $this->num => 'add', 'id' . $this->num => '' ), array( 'page' ), $this->exclusion() );
  1186. if ( !empty( $this->action_links[ 'add' ] ) )
  1187. $link = $this->action_links[ 'add' ];
  1188. ?>
  1189. <a href="<?php echo $link; ?>" class="add-new-h2"><?php echo $this->heading[ 'add' ]; ?></a>
  1190. <?php
  1191. }
  1192. elseif ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) ) {
  1193. $link = pods_var_update( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), array( 'page' ), $this->exclusion() );
  1194. ?>
  1195. <a href="<?php echo $link; ?>" class="add-new-h2">&laquo; <?php _e( 'Back to', 'pods' ); ?> <?php echo $this->heading[ 'manage' ]; ?></a>
  1196. <?php
  1197. }
  1198. ?>
  1199. </h2>
  1200. <?php $this->form( false, $duplicate ); ?>
  1201. </div>
  1202. <?php
  1203. }
  1204. /**
  1205. * @param bool $create
  1206. * @param bool $duplicate
  1207. *
  1208. * @return bool|mixed
  1209. */
  1210. public function form ( $create = false, $duplicate = false ) {
  1211. if ( in_array( 'duplicate', $this->actions_disabled ) )
  1212. $duplicate = false;
  1213. $this->do_hook( 'form' );
  1214. if ( isset( $this->actions_custom[ 'form' ] ) && is_callable( $this->actions_custom[ 'form' ] ) )
  1215. return call_user_func_array( $this->actions_custom[ 'form' ], array( &$this ) );
  1216. $label = $this->label[ 'add' ];
  1217. $id = null;
  1218. $vars = array(
  1219. 'action' . $this->num => $this->action_after[ 'add' ],
  1220. 'do' . $this->num => 'create',
  1221. 'id' . $this->num => 'X_ID_X'
  1222. );
  1223. $alt_vars = $vars;
  1224. $alt_vars[ 'action' ] = 'manage';
  1225. unset( $alt_vars[ 'id' ] );
  1226. if ( false === $create ) {
  1227. if ( empty( $this->row ) )
  1228. $this->get_row();
  1229. if ( empty( $this->row ) )
  1230. return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) );
  1231. if ( $this->restricted( $this->action ) )
  1232. return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) );
  1233. $label = $this->label[ 'edit' ];
  1234. $id = $this->row[ $this->sql[ 'field_id' ] ];
  1235. $vars = array(
  1236. 'action' . $this->num => $this->action_after[ 'edit' ],
  1237. 'do' . $this->num => 'save',
  1238. 'id' . $this->num => $id
  1239. );
  1240. $alt_vars = $vars;
  1241. $alt_vars[ 'action' ] = 'manage';
  1242. unset( $alt_vars[ 'id' ] );
  1243. if ( $duplicate ) {
  1244. $label = $this->label[ 'duplicate' ];
  1245. $id = null;
  1246. $vars = array(
  1247. 'action' . $this->num => $this->action_after[ 'duplicate' ],
  1248. 'do' . $this->num => 'create',
  1249. 'id' . $this->num => 'X_ID_X'
  1250. );
  1251. $alt_vars = $vars;
  1252. $alt_vars[ 'action' ] = 'manage';
  1253. unset( $alt_vars[ 'id' ] );
  1254. }
  1255. }
  1256. if ( isset( $this->fields[ $this->action ] ) )
  1257. $fields = $this->fields[ $this->action ];
  1258. $object_fields = (array) pods_var_raw( 'object_fields', $this->pod->pod_data, array(), null, true );
  1259. if ( empty( $object_fields ) && in_array( $this->pod->pod_data[ 'type' ], array( 'post_type', 'taxonomy', 'media', 'user', 'comment' ) ) )
  1260. $object_fields = $this->pod->api->get_wp_object_fields( $this->pod->pod_data[ 'type' ], $this->pod->pod_data );
  1261. if ( empty( $fields ) ) {
  1262. // Add core object fields if $fields is empty
  1263. $fields = array_merge( $object_fields, $this->pod->fields );
  1264. }
  1265. $form_fields = $fields; // Temporary
  1266. $fields = array();
  1267. foreach ( $form_fields as $k => $field ) {
  1268. $name = $k;
  1269. $defaults = array(
  1270. 'name' => $name
  1271. );
  1272. if ( !is_array( $field ) ) {
  1273. $name = $field;
  1274. $field = array(
  1275. 'name' => $name
  1276. );
  1277. }
  1278. $field = array_merge( $defaults, $field );
  1279. $field[ 'name' ] = trim( $field[ 'name' ] );
  1280. if ( empty( $field[ 'name' ] ) )
  1281. $field[ 'name' ] = trim( $name );
  1282. if ( pods_var_raw( 'hidden', $field, false, null, true ) )
  1283. continue;
  1284. elseif ( isset( $object_fields[ $field[ 'name' ] ] ) )
  1285. $fields[ $field[ 'name' ] ] = array_merge( $field, $object_fields[ $field[ 'name' ] ] );
  1286. elseif ( isset( $this->pod->fields[ $field[ 'name' ] ] ) )
  1287. $fields[ $field[ 'name' ] ] = array_merge( $this->pod->fields[ $field[ 'name' ] ], $field );
  1288. }
  1289. unset( $form_fields ); // Cleanup
  1290. $fields = $this->do_hook( 'form_fields', $fields, $this->pod );
  1291. $pod =& $this->pod;
  1292. $thank_you = pods_var_update( $vars, array( 'page' ), $this->exclusion() );
  1293. $thank_you_alt = pods_var_update( $alt_vars, array( 'page' ), $this->exclusion() );
  1294. $obj =& $this;
  1295. $singular_label = $this->item;
  1296. $plural_label = $this->items;
  1297. if ( is_object( $this->pod ) && 'settings' == $this->pod->pod_data[ 'type' ] )
  1298. pods_view( PODS_DIR . 'ui/admin/form-settings.php', compact( array_keys( get_defined_vars() ) ) );
  1299. else
  1300. pods_view( PODS_DIR . 'ui/admin/form.php', compact( array_keys( get_defined_vars() ) ) );
  1301. }
  1302. /**
  1303. * @return bool|mixed
  1304. */
  1305. public function view () {
  1306. $this->do_hook( 'view' );
  1307. if ( isset( $this->actions_custom[ 'view' ] ) && is_callable( $this->actions_custom[ 'view' ] ) )
  1308. return call_user_func_array( $this->actions_custom[ 'view' ], array( &$this ) );
  1309. if ( empty( $this->row ) )
  1310. $this->get_row();
  1311. if ( empty( $this->row ) )
  1312. return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) );
  1313. $id = $this->row[ $this->sql[ 'field_id' ] ];
  1314. // HOOK INTO FORM CLASS HERE FOR VIEW
  1315. }
  1316. /**
  1317. * Reorder data
  1318. */
  1319. public function reorder () {
  1320. // loop through order
  1321. $order = (array) pods_var_raw( 'order', 'post', array(), null, true );
  1322. $params = array(
  1323. 'pod' => $this->pod->pod,
  1324. 'field' => $this->reorder[ 'on' ],
  1325. 'order' => $order
  1326. );
  1327. $reorder = pods_api()->reorder_pod_item( $params );
  1328. if ( $reorder )
  1329. $this->message( sprintf( __( "<strong>Success!</strong> %s reordered successfully.", 'pods' ), $this->items ) );
  1330. else
  1331. $this->error( sprintf( __( "<strong>Error:</strong> %s has not been reordered.", 'pods' ), $this->items ) );
  1332. }
  1333. /**
  1334. * @param bool $insert
  1335. *
  1336. * @return mixed
  1337. */
  1338. public function save ( $insert = false ) {
  1339. $this->do_hook( 'pre_save', $insert );
  1340. if ( isset( $this->actions_custom[ 'save' ] ) && is_callable( $this->actions_custom[ 'save' ] ) )
  1341. return call_user_func_array( $this->actions_custom[ 'save' ], array( $insert, &$this ) );
  1342. global $wpdb;
  1343. $action = __( 'saved', 'pods' );
  1344. if ( true === $insert )
  1345. $action = __( 'created', 'pods' );
  1346. $field_sql = array();
  1347. $values = array();
  1348. $data = array();
  1349. foreach ( $this->fields[ 'form' ] as $field => $attributes ) {
  1350. $vartype = '%s';
  1351. if ( 'bool' == $attributes[ 'type' ] )
  1352. $selected = ( 1 == pods_var( $field, 'post', 0 ) ) ? 1 : 0;
  1353. elseif ( '' == pods_var( $field, 'post', '' ) )
  1354. continue;
  1355. if ( false === $attributes[ 'display' ] || false !== $attributes[ 'readonly' ] ) {
  1356. if ( !in_array( $attributes[ 'type' ], array( 'date', 'time', 'datetime' ) ) )
  1357. continue;
  1358. if ( false === $attributes[ 'date_touch' ] && ( false === $attributes[ 'date_touch_on_create' ] || false === $insert || 0 < $this->id ) )
  1359. continue;
  1360. }
  1361. if ( in_array( $attributes[ 'type' ], array( 'date', 'time', 'datetime' ) ) ) {
  1362. $format = "Y-m-d H:i:s";
  1363. if ( 'date' == $attributes[ 'type' ] )
  1364. $format = "Y-m-d";
  1365. if ( 'time' == $attributes[ 'type' ] )
  1366. $format = "H:i:s";
  1367. if ( false !== $attributes[ 'date_touch' ] || ( false !== $attributes[ 'date_touch_on_create' ] && true === $insert && $this->id < 1 ) )
  1368. $value = date_i18n( $format );
  1369. else
  1370. $value = date_i18n( $format, strtotime( ( 'time' == $attributes[ 'type' ] ) ? date_i18n( 'Y-m-d ' ) : pods_var( $field, 'post', '' ) ) );
  1371. }
  1372. else {
  1373. if ( 'bool' == $attributes[ 'type' ] ) {
  1374. $vartype = '%d';
  1375. $value = 0;
  1376. if ( '' != pods_var( $field, 'post', '' ) )
  1377. $value = 1;
  1378. }
  1379. elseif ( 'number' == $attributes[ 'type' ] ) {
  1380. $vartype = '%d';
  1381. $value = number_format( pods_var( $field, 'post', 0 ), 0, '', '' );
  1382. }
  1383. elseif ( 'decimal' == $attributes[ 'type' ] ) {
  1384. $vartype = '%d';
  1385. $value = number_format( pods_var( $field, 'post', 0 ), 2, '.', '' );
  1386. }
  1387. elseif ( 'related' == $attributes[ 'type' ] ) {
  1388. if ( is_array( pods_var( $field, 'post', '' ) ) )
  1389. $value = implode( ',', pods_var( $field, 'post', '' ) );
  1390. else
  1391. $value = pods_var( $field, 'post', '' );
  1392. }
  1393. else
  1394. $value = pods_var( $field, 'post', '' );
  1395. }
  1396. if ( isset( $this->actions_custom[ 'save' ] ) && is_callable( $this->actions_custom[ 'save' ] ) )
  1397. return call_user_func_array( $this->actions_custom[ 'save' ], array( $insert, &$this ) );
  1398. if ( isset( $attributes[ 'custom_save' ] ) && false !== $attributes[ 'custom_save' ] && is_callable( $attributes[ 'custom_save' ] ) )
  1399. $value = call_user_func_array( $attributes[ 'custom_save' ], array( $value, $field, $attributes, &$this ) );
  1400. $field_sql[] = "`$field`=$vartype";
  1401. $values[] = $value;
  1402. $data[ $field ] = $value;
  1403. }
  1404. $field_sql = implode( ',', $field_sql );
  1405. if ( false === $insert && 0 < $this->id ) {
  1406. $this->insert_id = $this->id;
  1407. $values[] = $this->id;
  1408. $check = $wpdb->query( $wpdb->prepare( "UPDATE $this->sql['table'] SET $field_sql WHERE id=%d", $values ) );
  1409. }
  1410. else
  1411. $check = $wpdb->query( $wpdb->prepare( "INSERT INTO $this->sql['table'] SET $field_sql", $values ) );
  1412. if ( $check ) {
  1413. if ( 0 == $this->insert_id )
  1414. $this->insert_id = $wpdb->insert_id;
  1415. $this->message( __( "<strong>Success!</strong> {$this->item} {$action} successfully.", 'pods' ) );
  1416. }
  1417. else
  1418. $this->error( __( "<strong>Error:</strong> {$this->item} has not been {$action}.", 'pods' ) );
  1419. $this->do_hook( 'post_save', $this->insert_id, $data, $insert );
  1420. }
  1421. /**
  1422. * @param null $id
  1423. *
  1424. * @return bool|mixed
  1425. */
  1426. public function delete ( $id = null ) {
  1427. $this->do_hook( 'pre_delete', $id );
  1428. if ( isset( $this->actions_custom[ 'delete' ] ) && is_callable( $this->actions_custom[ 'delete' ] ) )
  1429. return call_user_func_array( $this->actions_custom[ 'delete' ], array( $id, &$this ) );
  1430. $id = pods_absint( $id );
  1431. if ( empty( $id ) )
  1432. $id = pods_absint( $this->id );
  1433. if ( $id < 1 )
  1434. return $this->error( __( '<strong>Error:</strong> Invalid Configuration - Missing "id" definition.', 'pods' ) );
  1435. if ( false === $id )
  1436. $id = $this->id;
  1437. if ( is_object( $this->pod ) )
  1438. $check = $this->pod->delete( $id );
  1439. else
  1440. $check = $this->pods_data->delete( $this->table, array( $this->data->field_id => $id ) );
  1441. if ( $check )
  1442. $this->message( __( "<strong>Deleted:</strong> {$this->item} has been deleted.", 'pods' ) );
  1443. else
  1444. $this->error( __( "<strong>Error:</strong> {$this->item} has not been deleted.", 'pods' ) );
  1445. $this->do_hook( 'post_delete', $id );
  1446. }
  1447. /**
  1448. * @param null $id
  1449. *
  1450. * @return bool|mixed
  1451. */
  1452. public function delete_bulk () {
  1453. $this->do_hook( 'pre_delete_bulk' );
  1454. if ( 1 != pods_var( 'deleted_bulk', 'get', 0 ) ) {
  1455. $ids = $this->bulk;
  1456. $success = false;
  1457. if ( !empty( $ids ) ) {
  1458. foreach ( $ids as $id ) {
  1459. $id = pods_absint( $id );
  1460. if ( empty( $id ) )
  1461. continue;
  1462. if ( isset( $this->actions_custom[ 'delete' ] ) && is_callable( $this->actions_custom[ 'delete' ] ) ) {
  1463. $check = call_user_func_array( $this->actions_custom[ 'delete' ], array( $id, &$this ) );
  1464. if ( false !== $check )
  1465. $check = true;
  1466. }
  1467. elseif ( is_object( $this->pod ) )
  1468. $check = $this->pod->delete( $id );
  1469. else
  1470. $check = $this->pods_data->delete( $this->table, array( $this->data->field_id => $id ) );
  1471. if ( $check )
  1472. $success = true;
  1473. }
  1474. }
  1475. if ( $success )
  1476. pods_redirect( pods_var_update( array( 'action_bulk' => 'delete', 'deleted_bulk' => 1 ), array( 'page', 'lang', 'action', 'id' ) ) );
  1477. else
  1478. $this->error( __( "<strong>Error:</strong> {$this->item} has not been deleted.", 'pods' ) );
  1479. }
  1480. else {
  1481. $this->message( __( "<strong>Deleted:</strong> {$this->items} have been deleted.", 'pods' ) );
  1482. unset( $_GET[ 'deleted_bulk' ] );
  1483. }
  1484. $this->action_bulk = false;
  1485. unset( $_GET[ 'action_bulk' ] );
  1486. $this->do_hook( 'post_delete_bulk' );
  1487. $this->manage();
  1488. }
  1489. public function export () {
  1490. $export_type = pods_var( 'export_type', 'get', 'csv' );
  1491. $type = 'sv';
  1492. $delimiter = ',';
  1493. if ( 'tsv' == $export_type )
  1494. $delimiter = "\t";
  1495. elseif ( in_array( $export_type, array( 'xml', 'json' ) ) )
  1496. $type = $export_type;
  1497. $columns = array();
  1498. if ( empty( $this->fields[ 'export' ] ) ) {
  1499. $this->fields[ 'export' ] = $this->pod->fields;
  1500. $columns = array(
  1501. $this->pod->pod_data[ 'field_id' ] => 'ID'
  1502. );
  1503. }
  1504. foreach ( $this->fields[ 'export' ] as $field ) {
  1505. $columns[ $field[ 'name' ] ] = $field[ 'label' ];
  1506. }
  1507. $items = $this->get_data( true, array_keys( $columns ) );
  1508. $data = array(
  1509. 'columns' => $columns,
  1510. 'items' => $items
  1511. );
  1512. $migrate = pods_migrate( $type, $delimiter, $data );
  1513. $migrate->export();
  1514. $export_file = $migrate->save();
  1515. $this->message( sprintf( __( '<strong>Success:</strong> Your export is ready, the download should begin in a few moments. If it doesn\'t, you can download it <a href="%s" target="_blank">here</a>', 'pods' ), $export_file ) );
  1516. echo '<script type="text/javascript">window.open("' . esc_js( $export_file ) . '");</script>';
  1517. }
  1518. /**
  1519. * @param $field
  1520. *
  1521. * @return array|bool|mixed|null
  1522. */
  1523. public function get_field ( $field ) {
  1524. $value = null;
  1525. // use PodsData to get field
  1526. if ( isset( $this->actions_custom[ 'get_field' ] ) && is_callable( $this->actions_custom[ 'get_field' ] ) )
  1527. return call_user_func_array( $this->actions_custom[ 'get_field' ], array( $field, &$this ) );
  1528. if ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
  1529. if ( 'Pod' == get_class( $this->pod ) )
  1530. $value = $this->pod->get_field( $field );
  1531. else
  1532. $value = $this->pod->field( $field );
  1533. }
  1534. elseif ( isset( $this->row[ $field ] ) )
  1535. $value = $this->row[ $field ];
  1536. return $this->do_hook( 'get_field', $value, $field );
  1537. }
  1538. /**
  1539. * @param bool $full Whether to get ALL data or use pagination
  1540. *
  1541. * @return bool
  1542. */
  1543. public function get_data ( $full = false, $fields = null ) {
  1544. if ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) {
  1545. $orderby = array();
  1546. $limit = $this->limit;
  1547. $sql = null;
  1548. if ( 'reorder' == $this->action ) {
  1549. if ( !empty( $this->reorder[ 'orderby' ] ) )
  1550. $orderby[ $this->reorder[ 'orderby' ] ] = $this->reorder[ 'orderby_dir' ];
  1551. else
  1552. $orderby[ $this->reorder[ 'on' ] ] = $this->reorder[ 'orderby_dir' ];
  1553. if ( !empty( $this->reorder[ 'limit' ] ) )
  1554. $limit = $this->reorder[ 'limit' ];
  1555. if ( !empty( $this->reorder[ 'sql' ] ) )
  1556. $sql = $this->reorder[ 'sql' ];
  1557. }
  1558. if ( !empty( $this->orderby ) ) {
  1559. $this->orderby = (array) $this->orderby;
  1560. foreach ( $this->orderby as $order ) {
  1561. if ( false === strpos( ' ', $order ) && !isset( $orderby[ $order ] ) )
  1562. $orderby[ $order ] = $this->orderby_dir;
  1563. }
  1564. }
  1565. $params = array(
  1566. 'where' => pods_var_raw( $this->action, $this->where, null, null, true ),
  1567. 'orderby' => $orderby,
  1568. 'page' => (int) $this->page,
  1569. 'limit' => (int) $limit,
  1570. 'search' => $this->searchable,
  1571. 'search_query' => $this->search,
  1572. 'search_across' => $this->search_across,
  1573. 'search_across_picks' => $this->search_across_picks,
  1574. 'filters' => $this->filters,
  1575. 'sql' => $sql
  1576. );
  1577. if ( empty( $params[ 'where' ] ) && $this->restricted( $this->action ) )
  1578. $params[ 'where' ] = $this->pods_data->query_fields( $this->restrict[ $this->action ], ( is_object( $this->pod ) ? $this->pod->pod_data : null ) );
  1579. if ( $full )
  1580. $params[ 'limit' ] = -1;
  1581. $params = array_merge( $params, (array) $this->params );
  1582. $this->pod->find( $params );
  1583. if ( !$full ) {
  1584. $data = $this->pod->data();
  1585. $this->data = $data;
  1586. if ( !empty( $this->data ) )
  1587. $this->data_keys = array_keys( $this->data );
  1588. $this->total = $this->pod->total();
  1589. $this->total_found = $this->pod->total_found();
  1590. }
  1591. else {
  1592. $this->data_full = array();
  1593. while ( $this->pod->fetch() ) {
  1594. $this->data_full[ $this->pod->id() ] = $this->pod->export( $fields );
  1595. }
  1596. return $this->data_full;
  1597. }
  1598. }
  1599. else {
  1600. if ( !empty( $this->data ) )
  1601. return $this->data;
  1602. if ( empty( $this->sql[ 'table' ] ) )
  1603. return $this->data;
  1604. $orderby = '';
  1605. if ( !empty( $this->orderby ) )
  1606. $orderby = '`' . $this->orderby . '` '
  1607. . ( false === strpos( $this->orderby, ' ' ) ? strtoupper( $this->orderby_dir ) : '' );
  1608. $params = array(
  1609. 'table' => $this->sql[ 'table' ],
  1610. 'where' => pods_var_raw( $this->action, $this->where, null, null, true ),
  1611. 'orderby' => $orderby,
  1612. 'page' => (int) $this->page,
  1613. 'limit' => (int) $this->limit,
  1614. 'search' => $this->searchable,
  1615. 'search_query' => $this->search,
  1616. 'fields' => $this->fields[ 'search' ]
  1617. );
  1618. if ( empty( $params[ 'where' ] ) && $this->restricted( $this->action ) )
  1619. $params[ 'where' ] = $this->pods_data->query_fields( $this->restrict[ $this->action ], ( is_object( $this->pod ) ? $this->pod->pod_data : null ) );
  1620. if ( $full )
  1621. $params[ 'limit' ] = -1;
  1622. $this->pods_data->select( $params );
  1623. if ( !$full ) {
  1624. $this->data = $this->pods_data->data;
  1625. if ( !empty( $this->data ) )
  1626. $this->data_keys = array_keys( $this->data );
  1627. $this->total = $this->pods_data->total();
  1628. $this->total_found = $this->pods_data->total_found();
  1629. }
  1630. else {
  1631. $this->data_full = $this->pods_data->data;
  1632. return $this->data_full;
  1633. }
  1634. }
  1635. return $this->data;
  1636. }
  1637. /**
  1638. * Sort out data alphabetically by a key
  1639. */
  1640. public function sort_data () {
  1641. // only do this if we have a default orderby
  1642. if ( isset( $this->orderby[ 'default' ] ) ) {
  1643. $orderby = $this->orderby[ 'default' ];
  1644. foreach ( $this->data as $k => $v ) {
  1645. $sorter[ $k ] = strtolower( $v[ $orderby ] );
  1646. }
  1647. if ( $this->orderby_dir == 'ASC' )
  1648. asort( $sorter );
  1649. else
  1650. arsort( $sorter );
  1651. foreach ( $sorter as $key => $val ) {
  1652. $intermediary[] = $this->data[ $key ];
  1653. }
  1654. if ( isset( $intermediary ) ) {
  1655. $this->data = $intermediary;
  1656. $this->data_keys = array_keys( $this->data );
  1657. }
  1658. }
  1659. }
  1660. /**
  1661. * @return array
  1662. */
  1663. public function get_row ( &$counter = 0 ) {
  1664. if ( is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) )
  1665. $this->row = $this->pod->fetch();
  1666. else {
  1667. $this->row = false;
  1668. if ( !empty( $this->data ) ) {
  1669. if ( empty( $this->data_keys ) || count( $this->data ) != count( $this->data_keys ) )
  1670. $this->data_keys = array_keys( $this->data );
  1671. if ( count( $this->data ) == $this->total_found && isset( $this->data_keys[ $counter ] ) && isset( $this->data[ $this->data_keys[ $counter ] ] ) ) {
  1672. $this->row = $this->data[ $this->data_keys[ $counter ] ];
  1673. $counter++;
  1674. }
  1675. }
  1676. if ( false === $this->row && 0 < (int) $this->id && !empty( $this->sql[ 'table' ] ) ) {
  1677. $this->pods_data->select(
  1678. array(
  1679. 'table' => $this->sql[ 'table' ],
  1680. 'where' => '`' . $this->sql[ 'field_id' ] . '` = ' . (int) $this->id,
  1681. 'limit' => 1
  1682. )
  1683. );
  1684. $this->row = $this->pods_data->fetch();
  1685. }
  1686. }
  1687. return $this->row;
  1688. }
  1689. /**
  1690. * @param bool $reorder
  1691. *
  1692. * @return mixed
  1693. */
  1694. public function manage ( $reorder = false ) {
  1695. $this->do_hook( 'manage', $reorder );
  1696. if ( isset( $this->actions_custom[ 'manage' ] ) && is_callable( $this->actions_custom[ 'manage' ] ) )
  1697. return call_user_func_array( $this->actions_custom[ 'manage' ], array( $reorder, &$this ) );
  1698. if ( !empty( $this->action_bulk ) && !empty( $this->actions_bulk ) && isset( $this->actions_bulk[ $this->action_bulk ] ) && !in_array( $this->action_bulk, $this->actions_disabled ) ) {
  1699. if ( is_callable( $this->actions_bulk[ $this->action_bulk ] ) )
  1700. return call_user_func_array( $this->actions_bulk[ $this->action_bulk ], array( &$this, $this->bulk ) );
  1701. elseif ( isset( $this->actions_bulk[ $this->action_bulk ][ 'callback' ] ) && is_callable( $this->actions_bulk[ $this->action_bulk ][ 'callback' ] ) )
  1702. return call_user_func_array( $this->actions_bulk[ $this->action_bulk ][ 'callback' ], array( &$this, $this->bulk ) );
  1703. elseif ( 'delete' == $this->action_bulk )
  1704. return $this->delete_bulk();
  1705. }
  1706. $this->screen_meta();
  1707. if ( true === $reorder )
  1708. wp_enqueue_script( 'jquery-ui-sortable' );
  1709. ?>
  1710. <div class="wrap">
  1711. <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-image:url(<?php echo $this->icon; ?>);"<?php } ?>><br /></div>
  1712. <h2>
  1713. <?php
  1714. if ( true === $reorder ) {
  1715. echo $this->header[ 'reorder' ];
  1716. ?>
  1717. <small>(<a href="<?php echo pods_var_update( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), array( 'page' ), $this->exclusion() ); ?>">&laquo; <?php _e( 'Back to Manage', 'pods' ); ?></a>)</small>
  1718. <?php
  1719. }
  1720. else
  1721. echo $this->header[ 'manage' ];
  1722. if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) {
  1723. $link = pods_var_update( array( 'action' . $this->num => 'add' ), array( 'page' ), $this->exclusion() );
  1724. if ( !empty( $this->action_links[ 'add' ] ) )
  1725. $link = $this->action_links[ 'add' ];
  1726. ?>
  1727. <a href="<?php echo $link; ?>" class="add-new-h2"><?php echo $this->label[ 'add_new' ]; ?></a>
  1728. <?php
  1729. }
  1730. if ( !in_array( 'reorder', $this->actions_disabled ) && !in_array( 'reorder', $this->actions_hidden ) && false !== $this->reorder[ 'on' ] ) {
  1731. ?>
  1732. <a href="<?php echo pods_var_update( array( 'action' . $this->num => 'reorder' ), array( 'page' ), $this->exclusion() ); ?>" class="add-new-h2"><?php echo $this->label[ 'reorder' ]; ?></a>
  1733. <?php
  1734. }
  1735. ?>
  1736. </h2>
  1737. <?php if ( true !== $reorder ) { ?>
  1738. <form id="posts-filter" action="<?php echo pods_var_update( array( 'pg' . $this->num => '' ), array( 'page' ), $this->exclusion() ); ?>" method="get">
  1739. <?php
  1740. if ( 0 < strlen( pods_var( 'page' ) ) ) {
  1741. ?>
  1742. <input type="hidden" name="page" value="<?php echo esc_attr( pods_var( 'page' ) ); ?>" />
  1743. <?php } } ?>
  1744. <?php
  1745. if ( isset( $this->actions_custom[ 'header' ] ) && is_callable( $this->actions_custom[ 'header' ] ) )
  1746. return call_user_func_array( $this->actions_custom[ 'header' ], array( $reorder, &$this ) );
  1747. if ( false === $this->data )
  1748. $this->get_data();
  1749. elseif ( $this->sortable ) // we have the data already as an array
  1750. $this->sort_data();
  1751. if ( !in_array( 'export', $this->actions_disabled ) && 'export' == $this->action )
  1752. $this->export();
  1753. if ( ( !empty( $this->data ) || false !== $this->search || ( $this->filters_enhanced && !empty( $this->views ) ) ) && ( ( $this->filters_enhanced && !empty( $this->views ) ) || false !== $this->searchable ) ) {
  1754. if ( $this->filters_enhanced )
  1755. $this->filters();
  1756. else {
  1757. ?>
  1758. <p class="search-box" align="right">
  1759. <?php
  1760. $excluded_filters = array( 'search' . $this->num, 'pg' . $this->num );
  1761. foreach ( $this->filters as $filter ) {
  1762. $excluded_filters[] = 'filter_' . $filter . '_start';
  1763. $excluded_filters[] = 'filter_' . $filter . '_end';
  1764. $excluded_filters[] = 'filter_' . $filter;
  1765. }
  1766. $this->hidden_vars( $excluded_filters );
  1767. foreach ( $this->filters as $filter ) {
  1768. // use PodsFormUI fields
  1769. if ( !isset( $this->pod->fields[ $filter ] ) )
  1770. continue;
  1771. if ( in_array( $this->pod->fields[ $filter ][ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
  1772. $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $this->pod->fields[ $filter ], '', null, true ), null, true );
  1773. $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $this->pod->fields[ $filter ], '', null, true ), null, true );
  1774. if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
  1775. $start = PodsForm::field_method( $this->pod->fields[ $filter ][ 'type' ], 'convert_date', $start, 'n/j/Y' );
  1776. if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
  1777. $end = PodsForm::field_method( $this->pod->fields[ $filter ][ 'type' ], 'convert_date', $end, 'n/j/Y' );
  1778. ?>
  1779. <label for="pods-form-ui-filter-<?php echo $filter; ?>_start">
  1780. <?php echo $this->pod->fields[ $filter ][ 'label' ]; ?>
  1781. </label>
  1782. <?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $this->pod->fields[ $filter ][ 'type' ], $this->pod->fields[ $filter ] ); ?>
  1783. <label for="pods-form-ui-filter-<?php echo $filter; ?>_end">
  1784. to
  1785. </label>
  1786. <?php
  1787. echo PodsForm::field( 'filter_' . $filter . '_end', $end, $this->pod->fields[ $filter ][ 'type' ], $this->pod->fields[ $filter ] );
  1788. }
  1789. elseif ( 'pick' == $this->pod->fields[ $filter ][ 'type' ] ) {
  1790. $value = pods_var_raw( 'filter_' . $filter, 'get', pods_var_raw( 'filter_default', $this->pod->fields[ $filter ], '', null, true ), null, true );
  1791. $this->pod->fields[ $filter ][ 'options' ][ 'pick_format_type' ] = 'single';
  1792. $this->pod->fields[ $filter ][ 'options' ][ 'pick_format_single' ] = 'dropdown';
  1793. $this->pod->fields[ $filter ][ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields[ 'search' ], array(), null, true ), array(), null, true ), '', null, true );
  1794. $this->pod->fields[ $filter ][ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $this->pod->fields[ $filter ][ 'options' ], $this->pod->fields[ $filter ][ 'options' ][ 'input_helper' ], null, true );
  1795. $options = array_merge( $this->pod->fields[ $filter ], $this->pod->fields[ $filter ][ 'options' ] );
  1796. ?>
  1797. <label for="pods-form-ui-filter-<?php echo $filter; ?>">
  1798. <?php echo $this->pod->fields[ $filter ][ 'label' ]; ?>
  1799. </label>
  1800. <?php
  1801. echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options );
  1802. }
  1803. else {
  1804. $value = pods_var_raw( 'filter_' . $filter, 'get', pods_var_raw( 'filter_default', $this->pod->fields[ $filter ], '', null, true ), null, true );
  1805. $options = array();
  1806. $options[ 'input_helper' ] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields[ 'search' ], array(), null, true ), array(), null, true ), '', null, true );
  1807. $options[ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $options, $this->pod->fields[ $filter ][ 'options' ][ 'input_helper' ], null, true );
  1808. ?>
  1809. <label for="pods-form-ui-filter-<?php echo $filter; ?>">
  1810. <?php echo $this->pod->fields[ $filter ][ 'label' ]; ?>
  1811. </label>
  1812. <?php
  1813. echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options );
  1814. }
  1815. }
  1816. ?>
  1817. &nbsp;&nbsp; <label<?php echo ( empty( $this->filters ) ) ? ' class="screen-reader-text"' : ''; ?> for="page-search-input"><?php _e( 'Search', 'pods' ); ?>:</label>
  1818. <?php echo PodsForm::field( 'search' . $this->num, $this->search, 'text', array( 'attributes' => array( 'id' => 'page-search-input' ) ) ); ?>
  1819. <input type="submit" value="<?php esc_attr_e( 'Search', 'pods' ); echo ' ' . esc_attr( $this->items ); ?>" class="button" />
  1820. <?php
  1821. if ( 0 < strlen( $this->search ) ) {
  1822. $clear_filters = array();
  1823. foreach ( $this->filters as $filter ) {
  1824. $clear_filters[ 'filter_' . $filter . '_start' ] = '';
  1825. $clear_filters[ 'filter_' . $filter . '_end' ] = '';
  1826. $clear_filters[ 'filter_' . $filter ] = '';
  1827. }
  1828. ?>
  1829. <br class="clear" />
  1830. <small>[<a href="<?php echo pods_var_update( $clear_filters, array( 'orderby' . $this->num, 'orderby_dir' . $this->num, 'limit' . $this->num, 'page' ), $this->exclusion() ); ?>"><?php _e( 'Reset Filters', 'pods' ); ?></a>]</small>
  1831. <br class="clear" />
  1832. <?php
  1833. }
  1834. ?>
  1835. </p>
  1836. <?php
  1837. }
  1838. }
  1839. else {
  1840. ?>
  1841. <br class="clear" />
  1842. <?php
  1843. }
  1844. if ( !empty( $this->data ) && ( false !== $this->pagination_total || false !== $this->pagination || true === $reorder ) || ( !in_array( 'export', $this->actions_disabled ) && !in_array( 'export', $this->actions_hidden ) ) || !empty( $this->actions_disabled ) ) {
  1845. ?>
  1846. <div class="tablenav">
  1847. <?php
  1848. if ( !empty( $this->actions_bulk ) ) {
  1849. ?>
  1850. <div class="alignleft actions">
  1851. <select name="action_bulk<?php echo $this->num; ?>">
  1852. <option value="-1" selected="selected"><?php _e( 'Bulk Actions', 'pods' ); ?></option>
  1853. <?php
  1854. foreach ( $this->actions_bulk as $action => $action_data ) {
  1855. if ( in_array( $action, $this->actions_hidden ) || in_array( $action, $this->actions_hidden ) )
  1856. continue;
  1857. if ( !isset( $action_data[ 'label' ] ) )
  1858. $action_data[ 'label' ] = ucwords( str_replace( '_', ' ', $action ) );
  1859. ?>
  1860. <option value="<?php echo esc_attr( $action ); ?>"><?php echo esc_html( $action_data[ 'label' ] ); ?></option>
  1861. <?php
  1862. }
  1863. ?>
  1864. </select>
  1865. <input type="submit" id="doaction_bulk<?php echo $this->num; ?>" class="button-secondary action" value="<?php _e( 'Apply', 'pods' ); ?>">
  1866. </div>
  1867. <?php
  1868. }
  1869. if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) {
  1870. ?>
  1871. <div class="tablenav-pages<?php echo ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page'; ?>">
  1872. <?php $this->pagination( 1 ); ?>
  1873. </div>
  1874. <?php
  1875. }
  1876. if ( true === $reorder ) {
  1877. ?>
  1878. <input type="button" value="<?php _e( 'Update Order', 'pods' ); ?>" class="button" onclick="jQuery('form.admin_ui_reorder_form').submit();" />
  1879. <input type="button" value="<?php _e( 'Cancel', 'pods' ); ?>" class="button" onclick="document.location='<?php echo pods_var_update( array( 'action' . $this->num => 'manage' ), array( 'page' ), $this->exclusion() ); ?>';" />
  1880. <?php
  1881. }
  1882. /*
  1883. elseif (!in_array('delete', $this->actions_disabled) && !in_array('delete', $this->actions_hidden) && is_developer() ) {
  1884. ?>
  1885. <div class="alignleft actions">
  1886. <select name="action">
  1887. <option value="-1" selected="selected"><?php _e('Bulk Actions', 'pods'); ?></option>
  1888. <option value="delete"><?php _e('Delete', 'pods'); ?></option>
  1889. </select> <input type="submit" id="doaction" class="button-secondary action" value="<?php _e('Apply', 'pods'); ?>">
  1890. </div>
  1891. <?php
  1892. }*/
  1893. elseif ( !in_array( 'export', $this->actions_disabled ) && !in_array( 'export', $this->actions_hidden ) ) {
  1894. ?>
  1895. <div class="alignleft actions">
  1896. <strong><?php _e( 'Export', 'pods' ); ?>:</strong>
  1897. <?php
  1898. foreach ( $this->export[ 'formats' ] as $format => $separator ) {
  1899. ?>
  1900. <input type="button" value=" <?php echo strtoupper( $format ); ?> " class="button" onclick="document.location='<?php echo pods_var_update( array( 'action' . $this->num => 'export', 'export_type' . $this->num => $format ), array( 'page' ), $this->exclusion() ); ?>';" />
  1901. <?php
  1902. }
  1903. ?>
  1904. </div>
  1905. <?php
  1906. }
  1907. ?>
  1908. <br class="clear" />
  1909. </div>
  1910. <?php
  1911. }
  1912. else {
  1913. ?>
  1914. <br class="clear" />
  1915. <?php
  1916. }
  1917. ?>
  1918. <div class="clear"></div>
  1919. <?php
  1920. if ( empty( $this->data ) && false !== $this->default_none && false === $this->search ) {
  1921. ?>
  1922. <p><?php _e( 'Please use the search filter(s) above to display data', 'pods' ); ?><?php if ( $this->export ) { ?>, <?php _e( 'or click on an Export to download a full copy of the data', 'pods' ); ?><?php } ?>.</p>
  1923. <?php
  1924. }
  1925. else
  1926. $this->table( $reorder );
  1927. if ( !empty( $this->data ) ) {
  1928. if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) {
  1929. ?>
  1930. <div class="tablenav">
  1931. <div class="tablenav-pages<?php echo ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page'; ?>">
  1932. <?php $this->pagination( 0 ); ?>
  1933. <br class="clear" />
  1934. </div>
  1935. </div>
  1936. <?php
  1937. }
  1938. }
  1939. if ( true !== $reorder ) {
  1940. ?>
  1941. </form>
  1942. <?php } ?>
  1943. </div>
  1944. <?php
  1945. if ( $this->filters_enhanced )
  1946. $this->filters_popup();
  1947. }
  1948. public function filters () {
  1949. wp_enqueue_script( 'thickbox' );
  1950. wp_enqueue_style( 'pods-ui-list-table', PODS_URL . 'ui/css/pods-ui-list-table.css', array( 'thickbox' ), PODS_VERSION );
  1951. $filters = $this->filters;
  1952. foreach ( $filters as $k => $filter ) {
  1953. if ( in_array( $this->pod->fields[ $filter ][ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
  1954. if ( '' == pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ) && '' == pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ) )
  1955. unset( $filters[ $k ] );
  1956. }
  1957. elseif ( '' == pods_var_raw( 'filter_' . $filter, 'get', '', null, true ) )
  1958. unset( $filters[ $k ] );
  1959. }
  1960. $filtered = false;
  1961. if ( !empty( $filters ) )
  1962. $filtered = true;
  1963. ?>
  1964. <div class="pods-ui-filter-bar">
  1965. <div class="pods-ui-filter-bar-primary">
  1966. <?php
  1967. if ( !empty( $this->views ) ) {
  1968. ?>
  1969. <ul class="subsubsub">
  1970. <li class="pods-ui-filter-view-label"><strong><?php echo $this->heading[ 'views' ]; ?></strong></li>
  1971. <?php
  1972. foreach ( $this->views as $view => $label ) {
  1973. if ( false === strpos( $label, '<a' ) ) {
  1974. $link = pods_var_update( array( 'view' . $this->num => $view, 'pg' . $this->num => '' ), array( 'page' ), $this->exclusion() );
  1975. if ( $this->view == $view )
  1976. $label = '<a href="' . $link . '" class="current">' . $label . '</a>';
  1977. else
  1978. $label = '<a href="' . $link . '">' . $label . '</a>';
  1979. }
  1980. ?>
  1981. <li class="<?php echo $view; ?>"><?php echo $label; ?></li>
  1982. <?php
  1983. }
  1984. ?>
  1985. </ul>
  1986. <?php
  1987. }
  1988. ?>
  1989. <?php
  1990. if ( false !== $this->search && false !== $this->searchable ) {
  1991. ?>
  1992. <p class="search-box">
  1993. <?php
  1994. if ( $filtered || '' != pods_var_raw( 'search' . $this->num, 'get', '', null, true ) ) {
  1995. $clear_filters = array();
  1996. foreach ( $this->filters as $filter ) {
  1997. $clear_filters[ 'filter_' . $filter . '_start' ] = '';
  1998. $clear_filters[ 'filter_' . $filter . '_end' ] = '';
  1999. $clear_filters[ 'filter_' . $filter ] = '';
  2000. }
  2001. ?>
  2002. <a href="<?php echo pods_var_update( $clear_filters, array( 'orderby' . $this->num, 'orderby_dir' . $this->num, 'limit' . $this->num, 'page' ), $this->exclusion() ); ?>" class="pods-ui-filter-reset">[<?php _e( 'Reset', 'pods' ); ?>]</a>
  2003. <?php
  2004. }
  2005. ?>
  2006. <label class="screen-reader-text" for="search<?php echo $this->num; ?>-input"><?php _e( 'Search', 'pods' ); ?>:</label>
  2007. <input type="search" id="search<?php echo $this->num; ?>-input" name="search<?php echo $this->num; ?>" value="<?php echo esc_attr( $this->search ); ?>" />
  2008. <?php submit_button( $this->header[ 'search' ], 'button', false, false, array('id' => 'search-submit') ); ?>
  2009. </p>
  2010. <?php
  2011. }
  2012. ?>
  2013. </div>
  2014. <?php
  2015. if ( !empty( $this->filters ) ) {
  2016. ?>
  2017. <div class="pods-ui-filter-bar-secondary">
  2018. <ul class="subsubsub">
  2019. <?php
  2020. if ( !$filtered ) {
  2021. ?>
  2022. <li class="pods-ui-filter-bar-add-filter">
  2023. <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
  2024. <?php _e( 'Advanced Filters', 'pods' ); ?>
  2025. </a>
  2026. </li>
  2027. <?php
  2028. }
  2029. else {
  2030. ?>
  2031. <li class="pods-ui-filter-bar-add-filter">
  2032. <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
  2033. + <?php _e( 'Add Filter', 'pods' ); ?>
  2034. </a>
  2035. </li>
  2036. <?php
  2037. }
  2038. foreach ( $filters as $filter ) {
  2039. $value = pods_var_raw( 'filter_' . $filter, 'get', '', null, true );
  2040. $data_filter = 'filter_' . $filter;
  2041. $start = $end = $value_label = '';
  2042. if ( in_array( $this->pod->fields[ $filter ][ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
  2043. $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true );
  2044. $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true );
  2045. if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
  2046. $start = PodsForm::field_method( $this->pod->fields[ $filter ][ 'type' ], 'convert_date', $start, 'n/j/Y' );
  2047. if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
  2048. $end = PodsForm::field_method( $this->pod->fields[ $filter ][ 'type' ], 'convert_date', $end, 'n/j/Y' );
  2049. $value = trim( $start . ' - ' . $end, ' -' );
  2050. $data_filter = 'filter_' . $filter . '_start';
  2051. }
  2052. elseif ( 'pick' == $this->pod->fields[ $filter ][ 'type' ] )
  2053. $value_label = trim( PodsForm::field_method( 'pick', 'value_to_label', $this->pod->pod_data, $this->pod->fields[ $filter ], $value ) );
  2054. if ( strlen( $value_label ) < 1 )
  2055. $value_label = $value;
  2056. ?>
  2057. <li class="pods-ui-filter-bar-filter" data-filter="<?php echo $data_filter; ?>">
  2058. <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>">
  2059. <strong><?php echo $this->pod->fields[ $filter ][ 'label' ]; ?>:</strong>
  2060. <?php echo esc_html( $value_label ); ?>
  2061. </a>
  2062. <a href="#remove-filter" class="remove-filter" title="<?php esc_attr_e( 'Remove Filter', 'pods' ); ?>">x</a>
  2063. <?php
  2064. if ( in_array( $this->pod->fields[ $filter ][ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
  2065. echo PodsForm::field( 'filter_' . $filter . '_start', $start, 'hidden' );
  2066. echo PodsForm::field( 'filter_' . $filter . '_end', $end, 'hidden' );
  2067. }
  2068. else
  2069. echo PodsForm::field( $data_filter, $value, 'hidden' );
  2070. ?>
  2071. </li>
  2072. <?php
  2073. }
  2074. ?>
  2075. </ul>
  2076. </div>
  2077. <?php
  2078. }
  2079. ?>
  2080. </div>
  2081. <script type="text/javascript">
  2082. jQuery( function() {
  2083. jQuery( '.pods-ui-filter-bar-secondary' ).on( 'click', '.remove-filter', function ( e ) {
  2084. jQuery( '.pods-ui-filter-popup #' + jQuery( this ).parent().data( 'filter' ) ).remove();
  2085. jQuery( this ).parent().find( 'input' ).each( function () {
  2086. jQuery( this ).remove();
  2087. } );
  2088. jQuery( 'form#posts-filter [name="pg"]' ).prop( 'disabled', true );
  2089. jQuery( 'form#posts-filter [name="action"]' ).prop( 'disabled', true );
  2090. jQuery( 'form#posts-filter [name="action_bulk<?php echo $this->num; ?>"]' ).prop( 'disabled', true );
  2091. jQuery( 'form#posts-filter' ).submit();
  2092. e.preventDefault();
  2093. } );
  2094. } );
  2095. </script>
  2096. <?php
  2097. }
  2098. public function filters_popup () {
  2099. $filters = $this->filters;
  2100. ?>
  2101. <div id="pods-ui-posts-filter-popup" class="hidden">
  2102. <form action="" method="get" class="pods-ui-posts-filter-popup">
  2103. <h2><?php _e( 'Advanced Filters', 'pods' ); ?></h2>
  2104. <div class="pods-ui-posts-filters">
  2105. <?php
  2106. $excluded_filters = array( 'search' . $this->num, 'pg' . $this->num, 'action' . $this->num, 'action_bulk' . $this->num );
  2107. foreach ( $filters as $filter ) {
  2108. $excluded_filters[] = 'filter_' . $filter . '_start';
  2109. $excluded_filters[] = 'filter_' . $filter . '_end';
  2110. $excluded_filters[] = 'filter_' . $filter;
  2111. }
  2112. $get = $_GET;
  2113. foreach ( $get as $k => $v ) {
  2114. if ( in_array( $k, $excluded_filters ) || empty( $v ) )
  2115. continue;
  2116. ?>
  2117. <input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" />
  2118. <?php
  2119. }
  2120. $zebra = true;
  2121. foreach ( $filters as $filter ) {
  2122. ?>
  2123. <p class="pods-ui-posts-filter-toggled pods-ui-posts-filter-<?php echo $filter . ( $zebra ? ' clear' : '' ); ?>">
  2124. <?php
  2125. if ( in_array( $this->pod->fields[ $filter ][ 'type' ], array( 'date', 'datetime', 'time' ) ) ) {
  2126. $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $this->pod->fields[ $filter ], '', null, true ), null, true );
  2127. $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $this->pod->fields[ $filter ], '', null, true ), null, true );
  2128. if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
  2129. $start = PodsForm::field_method( $this->pod->fields[ $filter ][ 'type' ], 'convert_date', $start, 'n/j/Y' );
  2130. if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) )
  2131. $end = PodsForm::field_method( $this->pod->fields[ $filter ][ 'type' ], 'convert_date', $end, 'n/j/Y' );
  2132. ?>
  2133. <span class="pods-ui-posts-filter-toggle toggle-on<?php echo ( ( empty( $start ) && empty( $end ) ) ? '' : ' hidden' ); ?>">+</span>
  2134. <span class="pods-ui-posts-filter-toggle toggle-off<?php echo ( ( empty( $start ) && empty( $end ) ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
  2135. <label for="pods-form-ui-filter-<?php echo $filter; ?>_start">
  2136. <?php echo $this->pod->fields[ $filter ][ 'label' ]; ?>
  2137. </label>
  2138. <span class="pods-ui-posts-filter<?php echo ( ( empty( $start ) && empty( $end ) ) ? ' hidden' : '' ); ?>">
  2139. <?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $this->pod->fields[ $filter ][ 'type' ], $this->pod->fields[ $filter ] ); ?>
  2140. <label for="pods-form-ui-filter-<?php echo $filter; ?>_end">to</label>
  2141. <?php echo PodsForm::field( 'filter_' . $filter . '_end', $end, $this->pod->fields[ $filter ][ 'type' ], $this->pod->fields[ $filter ] ); ?>
  2142. </span>
  2143. <?php
  2144. }
  2145. elseif ( 'pick' == $this->pod->fields[ $filter ][ 'type' ] ) {
  2146. $value = pods_var_raw( 'filter_' . $filter, 'get', pods_var_raw( 'filter_default', $this->pod->fields[ $filter ], '', null, true ), null, true );
  2147. $this->pod->fields[ $filter ][ 'options' ][ 'pick_format_type' ] = 'single';
  2148. $this->pod->fields[ $filter ][ 'options' ][ 'pick_format_single' ] = 'dropdown';
  2149. $this->pod->fields[ $filter ][ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields[ 'search' ], array(), null, true ), array(), null, true ), '', null, true );
  2150. $this->pod->fields[ $filter ][ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $this->pod->fields[ $filter ][ 'options' ], $this->pod->fields[ $filter ][ 'options' ][ 'input_helper' ], null, true );
  2151. $options = array_merge( $this->pod->fields[ $filter ], $this->pod->fields[ $filter ][ 'options' ] );
  2152. ?>
  2153. <span class="pods-ui-posts-filter-toggle toggle-on<?php echo ( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
  2154. <span class="pods-ui-posts-filter-toggle toggle-off<?php echo ( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
  2155. <label for="pods-form-ui-filter-<?php echo $filter; ?>">
  2156. <?php echo $this->pod->fields[ $filter ][ 'label' ]; ?>
  2157. </label>
  2158. <span class="pods-ui-posts-filter<?php echo ( empty( $value ) ? ' hidden' : '' ); ?>">
  2159. <?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?>
  2160. </span>
  2161. <?php
  2162. }
  2163. else {
  2164. $value = pods_var_raw( 'filter_' . $filter, 'get', pods_var_raw( 'filter_default', $this->pod->fields[ $filter ], '', null, true ), null, true );
  2165. $options = array();
  2166. $options[ 'input_helper' ] = pods_var_raw( 'ui_input_helper', pods_var_raw( 'options', pods_var_raw( $filter, $this->fields[ 'search' ], array(), null, true ), array(), null, true ), '', null, true );
  2167. $options[ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $options, $this->pod->fields[ $filter ][ 'options' ][ 'input_helper' ], null, true );
  2168. ?>
  2169. <span class="pods-ui-posts-filter-toggle toggle-on<?php echo ( empty( $value ) ? '' : ' hidden' ); ?>">+</span>
  2170. <span class="pods-ui-posts-filter-toggle toggle-off<?php echo ( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span>
  2171. <label for="pods-form-ui-filter-<?php echo $filter; ?>">
  2172. <?php echo $this->pod->fields[ $filter ][ 'label' ]; ?>
  2173. </label>
  2174. <span class="pods-ui-posts-filter<?php echo ( empty( $value ) ? ' hidden' : '' ); ?>">
  2175. <?php echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options ); ?>
  2176. </span>
  2177. <?php
  2178. }
  2179. ?>
  2180. </p>
  2181. <?php
  2182. $zebra = empty( $zebra );
  2183. }
  2184. ?>
  2185. <p class="pods-ui-posts-filter-toggled pods-ui-posts-filter-search<?php echo ( $zebra ? ' clear' : '' ); ?>">
  2186. <label for="pods-form-ui-search<?php echo $this->num; ?>"><?php _e( 'Search Text', 'pods' ); ?></label>
  2187. <?php echo PodsForm::field( 'search' . $this->num, pods_var_raw( 'search' . $this->num, 'get' ), 'text' ); ?>
  2188. </p>
  2189. <?php $zebra = empty( $zebra ); ?>
  2190. </div>
  2191. <p class="submit<?php echo ( $zebra ? ' clear' : '' ); ?>"><input type="submit" value="<?php echo esc_attr( $this->header[ 'search' ] ); ?>" class="button button-primary" /></p>
  2192. </form>
  2193. </div>
  2194. <script type="text/javascript">
  2195. jQuery( function () {
  2196. jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-on', function ( e ) {
  2197. jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'hidden' );
  2198. jQuery( this ).hide();
  2199. jQuery( this ).parent().find( '.toggle-off' ).show();
  2200. } );
  2201. jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-off', function ( e ) {
  2202. jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'hidden' );
  2203. jQuery( this ).parent().find( 'select, input' ).val( '' );
  2204. jQuery( this ).hide();
  2205. jQuery( this ).parent().find( '.toggle-on' ).show();
  2206. } );
  2207. jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggled label', function ( e ) {
  2208. if ( jQuery( this ).parent().find( '.pods-ui-posts-filter' ).hasClass( 'hidden' ) ) {
  2209. jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'hidden' );
  2210. jQuery( this ).parent().find( '.toggle-on' ).hide();
  2211. jQuery( this ).parent().find( '.toggle-off' ).show();
  2212. }
  2213. else {
  2214. jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'hidden' );
  2215. jQuery( this ).parent().find( 'select, input' ).val( '' );
  2216. jQuery( this ).parent().find( '.toggle-on' ).show();
  2217. jQuery( this ).parent().find( '.toggle-off' ).hide();
  2218. }
  2219. } );
  2220. } );
  2221. </script>
  2222. <?php
  2223. }
  2224. /**
  2225. * @param bool $reorder
  2226. *
  2227. * @return bool|mixed
  2228. */
  2229. public function table ( $reorder = false ) {
  2230. $this->do_hook( 'table', $reorder );
  2231. if ( isset( $this->actions_custom[ 'table' ] ) && is_callable( $this->actions_custom[ 'table' ] ) )
  2232. return call_user_func_array( $this->actions_custom[ 'table' ], array( $reorder, &$this ) );
  2233. if ( empty( $this->data ) ) {
  2234. ?>
  2235. <p><?php echo sprintf( __( 'No %s found', 'pods' ), $this->items ); ?></p>
  2236. <?php
  2237. return false;
  2238. }
  2239. if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
  2240. ?>
  2241. <style type="text/css">
  2242. table.widefat.fixed tbody.reorderable tr {
  2243. height: 50px;
  2244. }
  2245. .dragme {
  2246. background: url(<?php echo PODS_URL; ?>/ui/images/handle.gif) no-repeat;
  2247. background-position: 8px 8px;
  2248. cursor: pointer;
  2249. }
  2250. .dragme strong {
  2251. margin-left: 30px;
  2252. }
  2253. </style>
  2254. <form action="<?php echo pods_var_update( array( 'action' . $this->num => 'reorder', 'do' . $this->num => 'save' ), array( 'page' ), $this->exclusion() ); ?>" method="post" class="admin_ui_reorder_form">
  2255. <?php
  2256. }
  2257. $table_fields = $this->fields[ 'manage' ];
  2258. if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] )
  2259. $table_fields = $this->fields[ 'reorder' ];
  2260. if ( false === $table_fields || empty( $table_fields ) )
  2261. return $this->error( __( '<strong>Error:</strong> Invalid Configuration - Missing "fields" definition.', 'pods' ) );
  2262. ?>
  2263. <table class="widefat page fixed wp-list-table" cellspacing="0"<?php echo ( 1 == $reorder && $this->reorder ) ? ' id="admin_ui_reorder"' : ''; ?>>
  2264. <thead>
  2265. <tr>
  2266. <?php
  2267. if ( !empty( $this->actions_bulk ) ) {
  2268. ?>
  2269. <th scope="col" id="cb" class="manage-column column-cb check-column"><input type="checkbox" /></th>
  2270. <?php
  2271. }
  2272. $name_field = false;
  2273. $fields = array();
  2274. if ( !empty( $table_fields ) ) {
  2275. foreach ( $table_fields as $field => $attributes ) {
  2276. if ( false === $attributes[ 'display' ] )
  2277. continue;
  2278. if ( false === $name_field )
  2279. $id = 'title';
  2280. else
  2281. $id = '';
  2282. if ( 'other' == $attributes[ 'type' ] )
  2283. $id = '';
  2284. if ( in_array( $attributes[ 'type' ], array( 'date', 'datetime', 'time' ) ) )
  2285. $id = 'date';
  2286. if ( false === $name_field && 'title' == $id )
  2287. $name_field = true;
  2288. $fields[ $field ] = $attributes;
  2289. $fields[ $field ][ 'field_id' ] = $id;
  2290. $dir = 'DESC';
  2291. $current_sort = ' asc';
  2292. if ( isset( $this->orderby[ 'default' ] ) && $field == $this->orderby[ 'default' ] ) {
  2293. if ( 'DESC' == $this->orderby_dir ) {
  2294. $dir = 'ASC';
  2295. $current_sort = ' desc';
  2296. }
  2297. }
  2298. $att_id = '';
  2299. if ( !empty( $id ) )
  2300. $att_id = ' id="' . $id . '"';
  2301. $width = '';
  2302. if ( isset( $attributes[ 'width' ] ) && !empty( $attributes[ 'width' ] ) )
  2303. $width = ' style="width: ' . $attributes[ 'width' ] . '"';
  2304. if ( $fields[ $field ][ 'sortable' ] ) {
  2305. ?>
  2306. <th scope="col"<?php echo $att_id; ?> class="manage-column column-<?php echo $id; ?> sortable<?php echo $current_sort; ?>"<?php echo $width; ?>>
  2307. <a href="<?php echo pods_var_update( array( 'orderby' . $this->num => $field, 'orderby_dir' . $this->num => $dir ), array( 'limit' . $this->num, 'search' . $this->num, 'pg' . $this->num, 'page' ), $this->exclusion() ); ?>"> <span><?php echo $attributes[ 'label' ]; ?></span> <span class="sorting-indicator"></span> </a>
  2308. </th>
  2309. <?php
  2310. }
  2311. else {
  2312. ?>
  2313. <th scope="col"<?php echo $att_id; ?> class="manage-column column-<?php echo $id; ?>"<?php echo $width; ?>><?php echo $attributes[ 'label' ]; ?></th>
  2314. <?php
  2315. }
  2316. }
  2317. }
  2318. ?>
  2319. </tr>
  2320. </thead>
  2321. <?php
  2322. if ( 6 < $this->total_found ) {
  2323. ?>
  2324. <tfoot>
  2325. <tr>
  2326. <?php
  2327. if ( !empty( $this->actions_bulk ) ) {
  2328. ?>
  2329. <th scope="col" class="manage-column column-cb check-column"><input type="checkbox" /></th>
  2330. <?php
  2331. }
  2332. if ( !empty( $fields ) ) {
  2333. foreach ( $fields as $field => $attributes ) {
  2334. $dir = 'ASC';
  2335. if ( $field == $this->orderby ) {
  2336. $current_sort = 'desc';
  2337. if ( 'ASC' == $this->orderby_dir ) {
  2338. $dir = 'DESC';
  2339. $current_sort = 'asc';
  2340. }
  2341. }
  2342. $width = '';
  2343. if ( isset( $attributes[ 'width' ] ) && !empty( $attributes[ 'width' ] ) )
  2344. $width = ' style="width: ' . $attributes[ 'width' ] . '"';
  2345. if ( $fields[ $field ][ 'sortable' ] ) {
  2346. ?>
  2347. <th scope="col" class="manage-column column-<?php echo $id; ?> sortable <?php echo $current_sort; ?>"<?php echo $width; ?>><a href="<?php echo pods_var_update( array( 'orderby' . $this->num => $field, 'orderby_dir' . $this->num => $dir ), array( 'limit' . $this->num, 'search' . $this->num, 'pg' . $this->num, 'page' ), $this->exclusion() ); ?>"><span><?php echo $attributes[ 'label' ]; ?></span><span class="sorting-indicator"></span></a></th>
  2348. <?php
  2349. }
  2350. else {
  2351. ?>
  2352. <th scope="col" class="manage-column column-<?php echo $id; ?>"<?php echo $width; ?>><?php echo $attributes[ 'label' ]; ?></th>
  2353. <?php
  2354. }
  2355. }
  2356. }
  2357. ?>
  2358. </tr>
  2359. </tfoot>
  2360. <?php
  2361. }
  2362. ?>
  2363. <tbody id="the-list"<?php echo ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) ? ' class="reorderable"' : ''; ?>>
  2364. <?php
  2365. if ( !empty( $this->data ) && is_array( $this->data ) ) {
  2366. $counter = 0;
  2367. while ( $row = $this->get_row( $counter ) ) {
  2368. if ( is_object( $row ) )
  2369. $row = get_object_vars( (object) $row );
  2370. $toggle_class = '';
  2371. if ( is_array( $this->actions_custom ) && isset( $this->actions_custom[ 'toggle' ] ) ) {
  2372. $toggle_class = ' pods-toggled-on';
  2373. if ( !isset( $row[ 'toggle' ] ) || empty( $row[ 'toggle' ] ) )
  2374. $toggle_class = ' pods-toggled-off';
  2375. }
  2376. ?>
  2377. <tr id="item-<?php echo $row[ $this->sql[ 'field_id' ] ]; ?>" class="iedit<?php echo $toggle_class; ?>">
  2378. <?php
  2379. if ( !empty( $this->actions_bulk ) ) {
  2380. ?>
  2381. <th scope="row" class="check-column"><input type="checkbox" name="action_bulk_ids<?php echo $this->num; ?>[]" value="<?php echo $row[$this->sql['field_id']]; ?>"></th>
  2382. <?php
  2383. }
  2384. foreach ( $fields as $field => $attributes ) {
  2385. if ( false === $attributes[ 'display' ] )
  2386. continue;
  2387. if ( !isset( $row[ $field ] ) )
  2388. $row[ $field ] = $this->get_field( $field );
  2389. if ( !empty( $attributes[ 'custom_display' ] ) ) {
  2390. if ( is_callable( $attributes[ 'custom_display' ] ) )
  2391. $row[ $field ] = call_user_func_array( $attributes[ 'custom_display' ], array( $row, &$this ) );
  2392. elseif ( is_object( $this->pod ) && class_exists( 'Pods_Helpers' ) )
  2393. $row[ $field ] = $this->pod->helper( $attributes[ 'custom_display' ], $row[ $field ], $field );
  2394. }
  2395. else {
  2396. ob_start();
  2397. $field_value = PodsForm::field_method( $attributes[ 'type' ], 'ui', $this->id, $row[ $field ], $field, $attributes[ 'options' ], $fields, $this->pod );
  2398. $field_output = trim( (string) ob_get_clean() );
  2399. if ( false === $field_value )
  2400. $row[ $field ] = '';
  2401. elseif ( 0 < strlen( trim( (string) $field_value ) ) )
  2402. $row[ $field ] = trim( (string) $field_value );
  2403. elseif ( 0 < strlen( $field_output ) )
  2404. $row[ $field ] = $field_output;
  2405. else {
  2406. // run formats
  2407. }
  2408. }
  2409. if ( false !== $attributes[ 'custom_relate' ] ) {
  2410. global $wpdb;
  2411. $table = $attributes[ 'custom_relate' ];
  2412. $on = $this->sql[ 'field_id' ];
  2413. $is = $row[ $this->sql[ 'field_id' ] ];
  2414. $what = array( 'name' );
  2415. if ( is_array( $table ) ) {
  2416. if ( isset( $table[ 'on' ] ) )
  2417. $on = pods_sanitize( $table[ 'on' ] );
  2418. if ( isset( $table[ 'is' ] ) && isset( $row[ $table[ 'is' ] ] ) )
  2419. $is = pods_sanitize( $row[ $table[ 'is' ] ] );
  2420. if ( isset( $table[ 'what' ] ) ) {
  2421. $what = array();
  2422. if ( is_array( $table[ 'what' ] ) ) {
  2423. foreach ( $table[ 'what' ] as $wha ) {
  2424. $what[] = pods_sanitize( $wha );
  2425. }
  2426. }
  2427. else
  2428. $what[] = pods_sanitize( $table[ 'what' ] );
  2429. }
  2430. if ( isset( $table[ 'table' ] ) )
  2431. $table = $table[ 'table' ];
  2432. }
  2433. $table = pods_sanitize( $table );
  2434. $wha = implode( ',', $what );
  2435. $sql = "SELECT {$wha} FROM {$table} WHERE `{$on}`='{$is}'";
  2436. $value = @current( $wpdb->get_results( $sql, ARRAY_A ) );
  2437. if ( !empty( $value ) ) {
  2438. $val = array();
  2439. foreach ( $what as $wha ) {
  2440. if ( isset( $value[ $wha ] ) )
  2441. $val[] = $value[ $wha ];
  2442. }
  2443. if ( !empty( $val ) )
  2444. $row[ $field ] = implode( ' ', $val );
  2445. }
  2446. }
  2447. if ( 'title' == $attributes[ 'field_id' ] ) {
  2448. if ( !in_array( 'edit', $this->actions_disabled ) && ( false === $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder[ 'on' ] ) ) {
  2449. ?>
  2450. <td class="post-title page-title column-title"><strong><a class="row-title" href="<?php echo pods_var_update( array( 'action' . $this->num => 'edit', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), array( 'page' ), $this->exclusion() ); ?>" title="Edit &#8220;<?php echo htmlentities( $row[ $field ], ENT_COMPAT, get_bloginfo( 'charset' ) ); ?>&#8221;"><?php echo $row[ $field ]; ?></a></strong>
  2451. <?php
  2452. }
  2453. elseif ( !in_array( 'view', $this->actions_disabled ) && ( false === $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder[ 'on' ] ) ) {
  2454. ?>
  2455. <td class="post-title page-title column-title"><strong><a class="row-title" href="<?php echo pods_var_update( array( 'action' . $this->num => 'view', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), array( 'page' ), $this->exclusion() ); ?>" title="View &#8220;<?php echo htmlentities( $row[ $field ], ENT_COMPAT, get_bloginfo( 'charset' ) ); ?>&#8221;"><?php echo $row[ $field ]; ?></a></strong>
  2456. <?php
  2457. }
  2458. else {
  2459. ?>
  2460. <td class="post-title page-title column-title<?php echo ( 1 == $reorder && $this->reorder ) ? ' dragme' : ''; ?>"><strong><?php echo $row[ $field ]; ?></strong>
  2461. <?php
  2462. }
  2463. if ( true !== $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder[ 'on' ] ) {
  2464. $toggle = false;
  2465. $actions = array();
  2466. if ( !in_array( 'view', $this->actions_disabled ) && !in_array( 'view', $this->actions_hidden ) )
  2467. $actions[ 'view' ] = '<span class="view"><a href="' . pods_var_update( array( 'action' . $this->num => 'view', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), array( 'page' ), $this->exclusion() ) . '" title="' . __( 'View this item', 'pods' ) . '">' . __( 'View', 'pods' ) . '</a></span>';
  2468. if ( !in_array( 'edit', $this->actions_disabled ) && !in_array( 'edit', $this->actions_hidden ) )
  2469. $actions[ 'edit' ] = '<span class="edit"><a href="' . pods_var_update( array( 'action' . $this->num => 'edit', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), array( 'page' ), $this->exclusion() ) . '" title="' . __( 'Edit this item', 'pods' ) . '">' . __( 'Edit', 'pods' ) . '</a></span>';
  2470. if ( !in_array( 'duplicate', $this->actions_disabled ) && !in_array( 'duplicate', $this->actions_hidden ) )
  2471. $actions[ 'duplicate' ] = '<span class="edit"><a href="' . pods_var_update( array( 'action' . $this->num => 'duplicate', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), array( 'page' ), $this->exclusion() ) . '" title="' . __( 'Duplicate this item', 'pods' ) . '">' . __( 'Duplicate', 'pods' ) . '</a></span>';
  2472. if ( !in_array( 'delete', $this->actions_disabled ) && !in_array( 'delete', $this->actions_hidden ) )
  2473. $actions[ 'delete' ] = '<span class="delete"><a href="' . pods_var_update( array( 'action' . $this->num => 'delete', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), array( 'page' ), $this->exclusion() ) . '" title="' . __( 'Delete this item', 'pods' ) . '" class="submitdelete" onclick="if(confirm(\'' . __( 'You are about to permanently delete this item\n Choose \\\'Cancel\\\' to stop, \\\'OK\\\' to delete.', 'pods' ) . '\')){return true;}return false;">' . __( 'Delete', 'pods' ) . '</a></span>';
  2474. if ( is_array( $this->actions_custom ) ) {
  2475. foreach ( $this->actions_custom as $custom_action => $custom_data ) {
  2476. if ( is_array( $custom_data ) && ( isset( $custom_data[ 'link' ] ) || isset( $custom_data[ 'callback' ] ) ) && !in_array( $custom_action, $this->actions_disabled ) && !in_array( $custom_action, $this->actions_hidden ) ) {
  2477. if ( !in_array( $custom_action, array( 'add', 'view', 'edit', 'duplicate', 'delete', 'save', 'export', 'reorder', 'manage', 'table' ) ) ) {
  2478. if ( 'toggle' == $custom_action ) {
  2479. $toggle = true;
  2480. $toggle_labels = array(
  2481. __( 'Enable', 'pods' ),
  2482. __( 'Disable', 'pods' )
  2483. );
  2484. $custom_data[ 'label' ] = ( $row[ 'toggle' ] ? $toggle_labels[ 1 ] : $toggle_labels[ 0 ] );
  2485. }
  2486. if ( !isset( $custom_data[ 'label' ] ) )
  2487. $custom_data[ 'label' ] = ucwords( str_replace( '_', ' ', $custom_action ) );
  2488. if ( !isset( $custom_data[ 'link' ] ) ) {
  2489. $vars = array(
  2490. 'action' => $custom_action,
  2491. 'id' => $row[ $this->sql[ 'field_id' ] ]
  2492. );
  2493. if ( 'toggle' == $custom_action ) {
  2494. $vars[ 'toggle' ] = (int) ( !$row[ 'toggle' ] );
  2495. $vars[ 'toggled' ] = 1;
  2496. }
  2497. $custom_data[ 'link' ] = pods_var_update( $vars );
  2498. }
  2499. $confirm = '';
  2500. if ( isset( $custom_data[ 'confirm' ] ) )
  2501. $confirm = ' onclick="if(confirm(\'' . $custom_data[ 'confirm' ] . '\')){return true;}return false;"';
  2502. $actions[ $custom_action ] = '<span class="edit action-' . $custom_action . '"><a href="' . $this->do_template( $custom_data[ 'link' ], $row ) . '" title="' . esc_attr( $custom_data[ 'label' ] ) . ' this item"' . $confirm . '>' . $custom_data[ 'label' ] . '</a></span>';
  2503. }
  2504. }
  2505. }
  2506. }
  2507. $actions = $this->do_hook( 'row_actions', $actions, $row[ $this->sql[ 'field_id' ] ] );
  2508. if ( !empty( $actions ) ) {
  2509. ?>
  2510. <div class="row-actions<?php echo ( $toggle ? ' row-actions-toggle' : '' ); ?>">
  2511. <?php
  2512. if ( isset( $this->actions_custom[ 'actions_start' ] ) && is_callable( $this->actions_custom[ 'actions_start' ] ) )
  2513. call_user_func_array( $this->actions_custom[ 'actions_start' ], array( $row, $actions, &$this ) );
  2514. echo implode( ' | ', $actions );
  2515. if ( isset( $this->actions_custom[ 'actions_end' ] ) && is_callable( $this->actions_custom[ 'actions_end' ] ) )
  2516. call_user_func_array( $this->actions_custom[ 'actions_end' ], array( $row, $actions, &$this ) );
  2517. ?>
  2518. </div>
  2519. <?php
  2520. }
  2521. }
  2522. else {
  2523. ?>
  2524. <input type="hidden" name="order[]" value="<?php echo $row[ $this->sql[ 'field_id' ] ]; ?>" />
  2525. <?php
  2526. }
  2527. ?>
  2528. </td>
  2529. <?php
  2530. }
  2531. elseif ( 'date' == $attributes[ 'type' ] ) {
  2532. ?>
  2533. <td class="date column-date"><abbr title="<?php echo esc_attr( $row[ $field ] ); ?>"><?php echo $row[ $field ]; ?></abbr></td>
  2534. <?php
  2535. }
  2536. else {
  2537. ?>
  2538. <td class="author"><?php echo $row[ $field ]; ?></td>
  2539. <?php
  2540. }
  2541. }
  2542. ?>
  2543. </tr>
  2544. <?php
  2545. }
  2546. }
  2547. ?>
  2548. </tbody>
  2549. </table>
  2550. <?php
  2551. if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
  2552. ?>
  2553. </form>
  2554. <?php
  2555. }
  2556. ?>
  2557. <script type="text/javascript">
  2558. jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' );
  2559. <?php
  2560. if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
  2561. ?>
  2562. jQuery( document ).ready( function () {
  2563. jQuery( ".reorderable" ).sortable( {axis : "y", handle : ".dragme"} );
  2564. jQuery( ".reorderable" ).bind( 'sortupdate', function ( event, ui ) {
  2565. jQuery( 'table.widefat tbody tr' ).removeClass( 'alternate' );
  2566. jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' );
  2567. } );
  2568. } );
  2569. <?php
  2570. }
  2571. ?>
  2572. </script>
  2573. <?php
  2574. }
  2575. /**
  2576. *
  2577. */
  2578. public function screen_meta () {
  2579. $screen_html = $help_html = '';
  2580. $screen_link = $help_link = '';
  2581. if ( !empty( $this->screen_options ) && !empty( $this->help ) ) {
  2582. foreach ( $this->ui_page as $page ) {
  2583. if ( isset( $this->screen_options[ $page ] ) ) {
  2584. if ( is_array( $this->screen_options[ $page ] ) ) {
  2585. if ( isset( $this->screen_options[ $page ][ 'link' ] ) ) {
  2586. $screen_link = $this->screen_options[ $page ][ 'link' ];
  2587. break;
  2588. }
  2589. }
  2590. else {
  2591. $screen_html = $this->screen_options[ $page ];
  2592. break;
  2593. }
  2594. }
  2595. }
  2596. foreach ( $this->ui_page as $page ) {
  2597. if ( isset( $this->help[ $page ] ) ) {
  2598. if ( is_array( $this->help[ $page ] ) ) {
  2599. if ( isset( $this->help[ $page ][ 'link' ] ) ) {
  2600. $help_link = $this->help[ $page ][ 'link' ];
  2601. break;
  2602. }
  2603. }
  2604. else {
  2605. $help_html = $this->help[ $page ];
  2606. break;
  2607. }
  2608. }
  2609. }
  2610. }
  2611. $screen_html = $this->do_hook( 'screen_meta_screen_html', $screen_html );
  2612. $screen_link = $this->do_hook( 'screen_meta_screen_link', $screen_link );
  2613. $help_html = $this->do_hook( 'screen_meta_help_html', $help_html );
  2614. $help_link = $this->do_hook( 'screen_meta_help_link', $help_link );
  2615. if ( 0 < strlen( $screen_html ) || 0 < strlen( $screen_link ) || 0 < strlen( $help_html ) || 0 < strlen( $help_link ) ) {
  2616. ?>
  2617. <div id="screen-meta">
  2618. <?php
  2619. $this->do_hook( 'screen_meta_pre' );
  2620. if ( 0 < strlen( $screen_html ) ) {
  2621. ?>
  2622. <div id="screen-options-wrap" class="hidden">
  2623. <form id="adv-settings" action="" method="post">
  2624. <?php
  2625. echo $screen_html;
  2626. $fields = array();
  2627. foreach ( $this->ui_page as $page ) {
  2628. if ( isset( $this->fields[ $page ] ) && !empty( $this->fields[ $page ] ) )
  2629. $fields = $this->fields[ $page ];
  2630. }
  2631. if ( !empty( $fields ) || true === $this->pagination ) {
  2632. ?>
  2633. <h5><?php _e( 'Show on screen', 'pods' ); ?></h5>
  2634. <?php
  2635. if ( !empty( $fields ) ) {
  2636. ?>
  2637. <div class="metabox-prefs">
  2638. <?php
  2639. $this->do_hook( 'screen_meta_screen_options' );
  2640. foreach ( $fields as $field => $attributes ) {
  2641. if ( false === $attributes[ 'display' ] || true === $attributes[ 'hidden' ] )
  2642. continue;
  2643. ?>
  2644. <label for="<?php echo $field; ?>-hide">
  2645. <input class="hide-column-tog" name="<?php echo $this->unique_identifier; ?>_<?php echo $field; ?>-hide" type="checkbox" id="<?php echo $field; ?>-hide" value="<?php echo $field; ?>" checked="checked"><?php echo $attributes[ 'label' ]; ?></label>
  2646. <?php
  2647. }
  2648. ?>
  2649. <br class="clear">
  2650. </div>
  2651. <h5><?php _e( 'Show on screen', 'pods' ); ?></h5>
  2652. <?php
  2653. }
  2654. ?>
  2655. <div class="screen-options">
  2656. <?php
  2657. if ( true === $this->pagination ) {
  2658. ?>
  2659. <input type="text" class="screen-per-page" name="wp_screen_options[value]" id="<?php echo $this->unique_identifier; ?>_per_page" maxlength="3" value="20"> <label for="<?php echo $this->unique_identifier; ?>_per_page"><?php echo $this->items; ?> per page</label>
  2660. <?php
  2661. }
  2662. $this->do_hook( 'screen_meta_screen_submit' );
  2663. ?>
  2664. <input type="submit" name="screen-options-apply" id="screen-options-apply" class="button" value="Apply">
  2665. <input type="hidden" name="wp_screen_options[option]" value="<?php echo $this->unique_identifier; ?>_per_page">
  2666. <?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?>
  2667. </div>
  2668. <?php
  2669. }
  2670. ?>
  2671. </form>
  2672. </div>
  2673. <?php
  2674. }
  2675. if ( 0 < strlen( $help_html ) ) {
  2676. ?>
  2677. <div id="contextual-help-wrap" class="hidden">
  2678. <div class="metabox-prefs">
  2679. <?php echo $help_html; ?>
  2680. </div>
  2681. </div>
  2682. <?php
  2683. }
  2684. ?>
  2685. <div id="screen-meta-links">
  2686. <?php
  2687. $this->do_hook( 'screen_meta_links_pre' );
  2688. if ( 0 < strlen( $help_html ) || 0 < strlen( $help_link ) ) {
  2689. ?>
  2690. <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
  2691. <?php
  2692. if ( 0 < strlen( $help_link ) ) {
  2693. ?>
  2694. <a href="<?php echo $help_link; ?>" class="show-settings">Help</a>
  2695. <?php
  2696. }
  2697. else {
  2698. ?>
  2699. <a href="#contextual-help" id="contextual-help-link" class="show-settings">Help</a>
  2700. <?php
  2701. }
  2702. ?>
  2703. </div>
  2704. <?php
  2705. }
  2706. if ( 0 < strlen( $screen_html ) || 0 < strlen( $screen_link ) ) {
  2707. ?>
  2708. <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
  2709. <?php
  2710. if ( 0 < strlen( $screen_link ) ) {
  2711. ?>
  2712. <a href="<?php echo $screen_link; ?>" class="show-settings">Screen Options</a>
  2713. <?php
  2714. }
  2715. else {
  2716. ?>
  2717. <a href="#screen-options" id="show-settings-link" class="show-settings">Screen Options</a>
  2718. <?php
  2719. }
  2720. ?>
  2721. </div>
  2722. <?php
  2723. }
  2724. $this->do_hook( 'screen_meta_links_post' );
  2725. ?>
  2726. </div>
  2727. <?php
  2728. $this->do_hook( 'screen_meta_post' );
  2729. ?>
  2730. </div>
  2731. <?php
  2732. }
  2733. }
  2734. /**
  2735. * @param bool $header
  2736. *
  2737. * @return mixed
  2738. */
  2739. public function pagination ( $header = false ) {
  2740. $this->do_hook( 'pagination', $header );
  2741. if ( isset( $this->actions_custom[ 'pagination' ] ) && is_callable( $this->actions_custom[ 'pagination' ] ) )
  2742. return call_user_func_array( $this->actions_custom[ 'pagination' ], array( $header, &$this ) );
  2743. $total_pages = ceil( $this->total_found / $this->limit );
  2744. $request_uri = pods_var_update( array( 'pg' . $this->num => '' ), array( 'limit' . $this->num, 'orderby' . $this->num, 'orderby_dir' . $this->num, 'search' . $this->num, 'filter_*', 'page' . $this->num ), $this->exclusion() );
  2745. if ( false !== $this->pagination_total ) {
  2746. ?>
  2747. <span class="displaying-num"><?php echo number_format_i18n( $this->total_found ); ?> <?php echo _n( 'item', 'items', $this->total_found, 'pods' ); ?></span>
  2748. <?php
  2749. }
  2750. if ( false !== $this->pagination ) {
  2751. if ( 1 < $total_pages ) {
  2752. ?>
  2753. <a class="first-page<?php echo ( 1 < $this->page ) ? '' : ' disabled'; ?>" title="<?php _e( 'Go to the first page', 'pods' ); ?>" href="<?php echo $request_uri; ?>">&laquo;</a>
  2754. <a class="prev-page<?php echo ( 1 < $this->page ) ? '' : ' disabled'; ?>" title="<?php _e( 'Go to the previous page', 'pods' ); ?>" href="<?php echo $request_uri; ?>&pg<?php echo $this->num; ?>=<?php echo max( $this->page - 1, 1 ); ?>">&lsaquo;</a>
  2755. <?php
  2756. if ( true == $header ) {
  2757. ?>
  2758. <span class="paging-input"><input class="current-page" title="<?php _e( 'Current page', 'pods' ); ?>" type="text" name="pg<?php echo $this->num; ?>" value="<?php echo $this->page; ?>" size="<?php echo strlen( $total_pages ); ?>"> <?php _e( 'of', 'pods' ); ?> <span class="total-pages"><?php echo $total_pages; ?></span></span>
  2759. <script>
  2760. jQuery( document ).ready( function ( $ ) {
  2761. var pageInput = $( 'input.current-page' );
  2762. var currentPage = pageInput.val();
  2763. pageInput.closest( 'form' ).submit( function ( e ) {
  2764. if ( (1 > $( 'select[name="action"]' ).length || $( 'select[name="action"]' ).val() == -1) && (1 > $( 'select[name="action_bulk]' ).length || $( 'select[name="action_bulk"]' ).val() == -1) && pageInput.val() == currentPage ) {
  2765. pageInput.val( '1' );
  2766. }
  2767. } );
  2768. } );
  2769. </script>
  2770. <?php
  2771. }
  2772. else {
  2773. ?>
  2774. <span class="paging-input"><?php echo $this->page; ?> <?php _e( 'of', 'pods' ); ?> <span class="total-pages"><?php echo number_format_i18n( $total_pages ); ?></span></span>
  2775. <?php
  2776. }
  2777. ?>
  2778. <a class="next-page<?php echo ( $this->page < $total_pages ) ? '' : ' disabled'; ?>" title="<?php _e( 'Go to the next page', 'pods' ); ?>" href="<?php echo $request_uri; ?>&pg<?php echo $this->num; ?>=<?php echo min( $this->page + 1, $total_pages ); ?>">&rsaquo;</a>
  2779. <a class="last-page<?php echo ( $this->page < $total_pages ) ? '' : ' disabled'; ?>" title="<?php _e( 'Go to the last page', 'pods' ); ?>'" href="<?php echo $request_uri; ?>&pg<?php echo $this->num; ?>=<?php echo $total_pages; ?>">&raquo;</a>
  2780. <?php
  2781. }
  2782. }
  2783. }
  2784. /**
  2785. * @param bool $options
  2786. *
  2787. * @return mixed
  2788. */
  2789. public function limit ( $options = false ) {
  2790. $this->do_hook( 'limit', $options );
  2791. if ( isset( $this->actions_custom[ 'limit' ] ) && is_callable( $this->actions_custom[ 'limit' ] ) )
  2792. return call_user_func_array( $this->actions_custom[ 'limit' ], array( $options, &$this ) );
  2793. if ( false === $options || !is_array( $options ) || empty( $options ) )
  2794. $options = array( 10, 25, 50, 100, 200 );
  2795. if ( !in_array( $this->limit, $options ) && -1 != $this->limit )
  2796. $this->limit = $options[ 1 ];
  2797. foreach ( $options as $option ) {
  2798. if ( $option == $this->limit )
  2799. echo " <span class=\"page-numbers current\">{$option}</span>";
  2800. else
  2801. echo ' <a href="' . pods_var_update( array( 'limit' => $option ), array( 'orderby' . $this->num, 'orderby_dir' . $this->num, 'search' . $this->num, 'filter_*', 'page' . $this->num ), $this->exclusion() ) . '">' . $option . '</a>';
  2802. }
  2803. }
  2804. /**
  2805. * @param $code
  2806. * @param bool|array $row
  2807. *
  2808. * @return mixed
  2809. */
  2810. public function do_template ( $code, $row = false ) {
  2811. if ( is_object( $this->pod ) && 0 < $this->pod->id() )
  2812. return $this->pod->do_magic_tags( $code );
  2813. else {
  2814. if ( false !== $row ) {
  2815. $this->temp_row = $this->row;
  2816. $this->row = $row;
  2817. }
  2818. $code = preg_replace_callback( "/({@(.*?)})/m", array( $this, "do_magic_tags" ), $code );
  2819. if ( false !== $row ) {
  2820. $this->row = $this->temp_row;
  2821. unset( $this->temp_row );
  2822. }
  2823. }
  2824. return $code;
  2825. }
  2826. /**
  2827. * @param $tag
  2828. *
  2829. * @return string
  2830. */
  2831. public function do_magic_tags ( $tag ) {
  2832. $tag = trim( $tag, ' {@}' );
  2833. $tag = explode( ',', $tag );
  2834. if ( empty( $tag ) || !isset( $tag[ 0 ] ) || 0 < strlen( trim( $tag[ 0 ] ) ) )
  2835. return;
  2836. foreach ( $tag as $k => $v ) {
  2837. $tag[ $k ] = trim( $v );
  2838. }
  2839. $field_name = $tag[ 0 ];
  2840. $value = $this->get_field( $field_name );
  2841. if ( isset( $tag[ 1 ] ) && !empty( $tag[ 1 ] ) && is_callable( $tag[ 1 ] ) )
  2842. $value = call_user_func_array( $tag[ 1 ], array( $value, $field_name, $this->row, &$this ) );
  2843. $before = $after = '';
  2844. if ( isset( $tag[ 2 ] ) && !empty( $tag[ 2 ] ) )
  2845. $before = $tag[ 2 ];
  2846. if ( isset( $tag[ 3 ] ) && !empty( $tag[ 3 ] ) )
  2847. $after = $tag[ 3 ];
  2848. if ( 0 < strlen( $value ) )
  2849. return $before . $value . $after;
  2850. return;
  2851. }
  2852. /**
  2853. * @param bool|array $exclude
  2854. * @param bool|array $array
  2855. */
  2856. public function hidden_vars ( $exclude = false, $array = false ) {
  2857. $exclude = $this->do_hook( 'hidden_vars', $exclude, $array );
  2858. if ( false === $exclude )
  2859. $exclude = array();
  2860. if ( !is_array( $exclude ) )
  2861. $exclude = explode( ',', $exclude );
  2862. $get = $_GET;
  2863. if ( is_array( $array ) ) {
  2864. foreach ( $array as $key => $val ) {
  2865. if ( 0 < strlen( $val ) )
  2866. $get[ $key ] = $val;
  2867. else
  2868. unset( $get[ $key ] );
  2869. }
  2870. }
  2871. foreach ( $get as $k => $v ) {
  2872. if ( in_array( $k, $exclude ) )
  2873. continue;
  2874. ?>
  2875. <input type="hidden" name="<?php echo $k; ?>" value="<?php echo $v; ?>" />
  2876. <?php
  2877. }
  2878. }
  2879. /**
  2880. * @return array
  2881. */
  2882. public function exclusion () {
  2883. $exclusion = self::$excluded;
  2884. foreach ( $exclusion as &$exclude ) {
  2885. $exclude = $exclude . $this->num;
  2886. }
  2887. return $exclusion;
  2888. }
  2889. public function restricted ( $action = 'edit', $row = null ) {
  2890. $restricted = false;
  2891. $restrict = array();
  2892. if ( isset( $this->restrict[ $action ] ) )
  2893. $restrict = (array) $this->restrict[ $action ];
  2894. $author_restrict = false;
  2895. if ( !empty( $this->restrict[ 'author_restrict' ] ) && $restrict == $this->restrict[ 'author_restrict' ] ) {
  2896. $author_restrict = true;
  2897. if ( is_object( $this->pod ) ) {
  2898. $restricted = true;
  2899. if ( is_super_admin() || current_user_can( 'delete_users' ) || current_user_can( 'pods' ) || current_user_can( 'pods_content' ) )
  2900. $restricted = false;
  2901. elseif ( current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) && current_user_can( 'pods_' . $action . '_others_' . $this->pod->pod ) )
  2902. $restricted = false;
  2903. }
  2904. /* @todo determine proper logic for non-pods capabilities
  2905. else {
  2906. $restricted = true;
  2907. if ( is_super_admin() || current_user_can( 'delete_users' ) || current_user_can( 'pods' ) || current_user_can( 'pods_content' ) )
  2908. $restricted = false;
  2909. elseif ( current_user_can( 'pods_' . $action . '_others_' . $_tbd ) )
  2910. $restricted = false;
  2911. }*/
  2912. }
  2913. if ( $restricted && !empty( $restrict ) ) {
  2914. $relation = strtoupper( trim( pods_var( 'relation', $restrict, 'AND', null, true ) ) );
  2915. if ( 'AND' != $relation )
  2916. $relation = 'OR';
  2917. $okay = true;
  2918. foreach ( $restrict as $field => $match ) {
  2919. if ( 'relation' == $field )
  2920. continue;
  2921. if ( is_array( $match ) ) {
  2922. $match_okay = true;
  2923. $match_relation = strtoupper( trim( pods_var( 'relation', $match, 'OR', null, true ) ) );
  2924. if ( 'AND' != $match_relation )
  2925. $match_relation = 'OR';
  2926. foreach ( $match as $the_field => $the_match ) {
  2927. if ( 'relation' == $the_field )
  2928. continue;
  2929. $value = null;
  2930. if ( is_object( $this->pod ) )
  2931. $value = $this->pod->field( $the_match, true );
  2932. else {
  2933. if ( empty( $row ) )
  2934. $row = $this->row;
  2935. if ( isset( $row[ $the_match ] ) ) {
  2936. if ( is_array( $row[ $the_match ] ) ) {
  2937. if ( false !== strpos( $the_match, '.' ) ) {
  2938. $the_matches = explode( '.', $the_match );
  2939. $value = $row[ $the_match ];
  2940. foreach ( $the_matches as $m ) {
  2941. if ( is_array( $value ) && isset( $value[ $m ] ) )
  2942. $value = $value[ $m ];
  2943. else {
  2944. $value = null;
  2945. break;
  2946. }
  2947. }
  2948. }
  2949. }
  2950. else
  2951. $value = $row[ $the_match ];
  2952. }
  2953. }
  2954. if ( is_array( $value ) ) {
  2955. if ( !in_array( $the_match, $value ) )
  2956. $match_okay = false;
  2957. elseif ( 'OR' == $match_relation ) {
  2958. $match_okay = true;
  2959. break;
  2960. }
  2961. }
  2962. elseif ( $value == $the_match )
  2963. $match_okay = false;
  2964. elseif ( 'OR' == $match_relation ) {
  2965. $match_okay = true;
  2966. break;
  2967. }
  2968. }
  2969. if ( !$match_okay )
  2970. $okay = false;
  2971. if ( 'OR' == $relation ) {
  2972. $okay = true;
  2973. break;
  2974. }
  2975. }
  2976. else {
  2977. $value = null;
  2978. if ( is_object( $this->pod ) )
  2979. $value = $this->pod->field( $match, true );
  2980. else {
  2981. if ( empty( $row ) )
  2982. $row = $this->row;
  2983. if ( isset( $row[ $match ] ) ) {
  2984. if ( is_array( $row[ $match ] ) ) {
  2985. if ( false !== strpos( $match, '.' ) ) {
  2986. $matches = explode( '.', $match );
  2987. $value = $row[ $match ];
  2988. foreach ( $matches as $m ) {
  2989. if ( is_array( $value ) && isset( $value[ $m ] ) )
  2990. $value = $value[ $m ];
  2991. else {
  2992. $value = null;
  2993. break;
  2994. }
  2995. }
  2996. }
  2997. }
  2998. else
  2999. $value = $row[ $match ];
  3000. }
  3001. }
  3002. if ( is_array( $value ) ) {
  3003. if ( !in_array( $match, $value ) )
  3004. $okay = false;
  3005. elseif ( 'OR' == $relation ) {
  3006. $okay = true;
  3007. break;
  3008. }
  3009. }
  3010. elseif ( $value != $match )
  3011. $okay = false;
  3012. elseif ( 'OR' == $relation ) {
  3013. $okay = true;
  3014. break;
  3015. }
  3016. }
  3017. }
  3018. if ( $author_restrict ) {
  3019. if ( is_object( $this->pod ) && !current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) )
  3020. $okay = false;
  3021. /* @todo determine proper logic for non-pods capabilities
  3022. elseif ( !current_user_can( 'pods_' . $action . '_' . $_tbd ) )
  3023. $okay = false;*/
  3024. }
  3025. if ( $okay )
  3026. $restricted = false;
  3027. }
  3028. $restricted = $this->do_hook( 'restricted_' . $action, $restricted, $restrict, $action );
  3029. return $restricted;
  3030. }
  3031. /*
  3032. // Example code for use with $this->do_hook
  3033. public function my_filter_function ($args, $obj) {
  3034. $obj[0]->item = 'Post';
  3035. $obj[0]->add = true;
  3036. // args are an array (0 => $arg1, 1 => $arg2)
  3037. // may have more than one arg, dependant on filter
  3038. return $args;
  3039. }
  3040. add_filter('pods_ui_post_init', 'my_filter_function', 10, 2);
  3041. */
  3042. /**
  3043. * @return array|bool|mixed|null
  3044. */
  3045. private function do_hook () {
  3046. $args = func_get_args();
  3047. if ( empty( $args ) )
  3048. return false;
  3049. $name = array_shift( $args );
  3050. return pods_do_hook( "ui", $name, $args, $this );
  3051. }
  3052. }