PodsUI

The Pods - Custom Content Types and Fields PodsUI class.

Defined (1)

The class is defined in the following location(s).

/classes/PodsUI.php  
  1. class PodsUI { 
  2.  
  3. /** 
  4. * @var null Nonce for security 
  5. */ 
  6. private $_nonce = null; 
  7.  
  8. // internal 
  9. /** 
  10. * @var bool|PodsData 
  11. */ 
  12. private $pods_data = false; 
  13.  
  14. /** 
  15. * @var array 
  16. */ 
  17. private $actions = array( 
  18. 'manage',  
  19. 'add',  
  20. 'edit',  
  21. 'duplicate',  
  22. 'save',  
  23. //'view',  
  24. 'delete',  
  25. 'reorder',  
  26. 'export' 
  27. ); 
  28.  
  29. /** 
  30. * @var array 
  31. */ 
  32. private $ui_page = array(); 
  33.  
  34. /** 
  35. * @var bool 
  36. */ 
  37. private $unique_identifier = false; 
  38.  
  39. // base 
  40. public $x = array(); 
  41.  
  42. /** 
  43. * @var array|bool|mixed|null|Pods 
  44. */ 
  45. public $pod = false; 
  46.  
  47. /** 
  48. * @var int 
  49. */ 
  50. public $id = 0; 
  51.  
  52. /** 
  53. * @var string 
  54. */ 
  55. public $num = ''; // allows multiple co-existing PodsUI instances with separate functionality in URL 
  56.  
  57. /** 
  58. * @var array 
  59. */ 
  60. static $excluded = array( 
  61. 'do',  
  62. 'id',  
  63. 'pg',  
  64. 'search',  
  65. 'filter_*',  
  66. 'orderby',  
  67. 'orderby_dir',  
  68. 'limit',  
  69. 'action',  
  70. 'action_bulk',  
  71. 'action_bulk_ids',  
  72. '_wpnonce',  
  73. 'view',  
  74. 'export',  
  75. 'export_type',  
  76. 'export_delimiter',  
  77. 'remove_export',  
  78. 'updated',  
  79. 'duplicate',  
  80. 'message' 
  81. ); // used in var_update 
  82.  
  83. static $allowed = array( 
  84. 'page',  
  85. 'post_type' 
  86. ); 
  87.  
  88. // ui 
  89. /** 
  90. * @var bool 
  91. */ 
  92. public $item = false; // to be set with localized string 
  93. /** 
  94. * @var bool 
  95. */ 
  96. public $items = false; // to be set with localized string 
  97. /** 
  98. * @var bool 
  99. */ 
  100. public $heading = false; // to be set with localized string array 
  101. /** 
  102. * @var bool 
  103. */ 
  104. public $header = false; // to be set with localized string array 
  105. /** 
  106. * @var bool 
  107. */ 
  108. public $label = false; // to be set with localized string array 
  109. /** 
  110. * @var bool 
  111. */ 
  112. public $icon = false; 
  113.  
  114. /** 
  115. * @var bool 
  116. */ 
  117. public $css = false; // set to a URL of stylesheet to include 
  118. /** 
  119. * @var bool 
  120. */ 
  121. public $wpcss = false; // set to true to include WP Admin stylesheets 
  122. /** 
  123. * @var array 
  124. */ 
  125. public $fields = array( 
  126. 'manage' => array(),  
  127. 'search' => array(),  
  128. 'form' => array(),  
  129. 'add' => array(),  
  130. 'edit' => array(),  
  131. 'duplicate' => array(),  
  132. 'view' => array(),  
  133. 'reorder' => array(),  
  134. 'export' => array() 
  135. ); 
  136.  
  137. /** 
  138. * @var bool 
  139. */ 
  140. public $searchable = true; 
  141.  
  142. /** 
  143. * @var bool 
  144. */ 
  145. public $sortable = true; 
  146.  
  147. /** 
  148. * @var bool 
  149. */ 
  150. public $pagination = true; 
  151.  
  152. /** 
  153. * @var bool 
  154. */ 
  155. public $pagination_total = true; 
  156.  
  157. /** 
  158. * @var array 
  159. */ 
  160. public $export = array( 
  161. 'on' => false,  
  162. 'formats' => array( 
  163. 'csv' => ', ',  
  164. 'tsv' => "\t",  
  165. 'xml' => false,  
  166. 'json' => false 
  167. ),  
  168. 'url' => false,  
  169. 'type' => false 
  170. ); 
  171.  
  172. /** 
  173. * @var array 
  174. */ 
  175. public $reorder = array( 
  176. 'on' => false,  
  177. 'limit' => 250,  
  178. 'orderby' => false,  
  179. 'orderby_dir' => 'ASC',  
  180. 'sql' => null 
  181. ); 
  182.  
  183. /** 
  184. * @var array 
  185. */ 
  186. public $screen_options = array(); // set to 'page' => 'Text'; false hides link 
  187. /** 
  188. * @var array 
  189. */ 
  190. public $help = array(); // set to 'page' => 'Text'; 'page' => array('link' => 'yourhelplink'); false hides link 
  191.  
  192. // data 
  193. /** 
  194. * @var bool 
  195. */ 
  196. public $search = false; 
  197.  
  198. /** 
  199. * @var bool 
  200. */ 
  201. public $filters_enhanced = false; 
  202.  
  203. /** 
  204. * @var array 
  205. */ 
  206. public $filters = array(); 
  207.  
  208. /** 
  209. * @var string 
  210. */ 
  211. public $view = false; 
  212.  
  213. /** 
  214. * @var array 
  215. */ 
  216. public $views = array(); 
  217.  
  218. /** 
  219. * @var bool 
  220. */ 
  221. public $search_across = true; 
  222.  
  223. /** 
  224. * @var bool 
  225. */ 
  226. public $search_across_picks = false; 
  227.  
  228. /** 
  229. * @var bool 
  230. */ 
  231. public $default_none = false; 
  232.  
  233. /** 
  234. * @var array 
  235. */ 
  236. public $where = array( 
  237. 'manage' => null,  
  238. /**'edit' => null,  
  239. 'duplicate' => null,  
  240. 'delete' => null, */ 
  241. 'reorder' => null 
  242. ); 
  243.  
  244. /** 
  245. * @var bool 
  246. */ 
  247. public $orderby = false; 
  248.  
  249. /** 
  250. * @var string 
  251. */ 
  252. public $orderby_dir = 'DESC'; 
  253.  
  254. /** 
  255. * @var int 
  256. */ 
  257. public $limit = 25; 
  258.  
  259. /** 
  260. * @var int 
  261. */ 
  262. public $page = 1; 
  263.  
  264. /** 
  265. * @var int 
  266. */ 
  267. public $total = 0; 
  268.  
  269. /** 
  270. * @var int 
  271. */ 
  272. public $total_found = 0; 
  273.  
  274. /** 
  275. * @var array 
  276. */ 
  277. public $session = array( 
  278. 'search',  
  279. 'filters' 
  280. ); // allowed: search, filters, show_per_page, orderby (priority over usermeta) 
  281. /** 
  282. * @var array 
  283. */ 
  284. public $user = array( 
  285. 'show_per_page',  
  286. 'orderby' 
  287. ); // allowed: search, filters, show_per_page, orderby (priority under session) 
  288.  
  289. // advanced data 
  290. /** 
  291. * @var array 
  292. */ 
  293. public $sql = array( 
  294. 'table' => null,  
  295. 'field_id' => 'id',  
  296. 'field_index' => 'name',  
  297. 'select' => null,  
  298. 'sql' => null 
  299. ); 
  300.  
  301. /** 
  302. * @var array 
  303. */ 
  304. public $params = array(); 
  305.  
  306. /** 
  307. * @var bool|array 
  308. */ 
  309. public $data = false; 
  310.  
  311. /** 
  312. * @var bool|array 
  313. */ 
  314. public $data_full = false; 
  315.  
  316. /** 
  317. * @var array 
  318. */ 
  319. public $data_keys = array(); 
  320.  
  321. /** 
  322. * @var array 
  323. */ 
  324. public $row = array(); 
  325.  
  326. // actions 
  327. /** 
  328. * @var string 
  329. */ 
  330. public $action = 'manage'; 
  331.  
  332. /** 
  333. * @var string 
  334. */ 
  335. public $action_bulk = false; 
  336.  
  337. /** 
  338. * @var array 
  339. */ 
  340. public $bulk = array(); 
  341.  
  342. /** 
  343. * @var array 
  344. */ 
  345. public $action_after = array( 
  346. 'add' => 'edit',  
  347. 'edit' => 'edit',  
  348. 'duplicate' => 'edit' 
  349. ); // set action to 'manage' 
  350. /** 
  351. * @var bool 
  352. */ 
  353. public $do = false; 
  354.  
  355. /** 
  356. * @var array 
  357. */ 
  358. public $action_links = array( 
  359. 'manage' => null,  
  360. 'add' => null,  
  361. 'edit' => null,  
  362. 'duplicate' => null,  
  363. 'view' => null,  
  364. 'delete' => null,  
  365. 'reorder' => null 
  366. ); // custom links (ex. /my-link/{@id}/ 
  367.  
  368. /** 
  369. * @var array 
  370. */ 
  371. public $actions_disabled = array( 
  372. 'view',  
  373. 'export' 
  374. ); // disable actions 
  375.  
  376. /** 
  377. * @var array 
  378. */ 
  379. public $actions_hidden = array(); // hide actions to not show them but allow them 
  380.  
  381. /** 
  382. * @var array 
  383. */ 
  384. public $actions_custom = array(); // overwrite existing actions or add your own 
  385.  
  386. /** 
  387. * @var array 
  388. */ 
  389. public $actions_bulk = array(); // enabled bulk actions 
  390.  
  391. /** 
  392. * @var array 
  393. */ 
  394. public $restrict = array( 
  395. 'manage' => null,  
  396. 'edit' => null,  
  397. 'duplicate' => null,  
  398. 'delete' => null,  
  399. 'reorder' => null,  
  400. 'author_restrict' => null 
  401. ); 
  402.  
  403. /** 
  404. * @var array 
  405. */ 
  406. public $extra = array( 
  407. 'total' => null 
  408. ); 
  409.  
  410. /** 
  411. * @var string 
  412. */ 
  413. public $style = 'post_type'; 
  414.  
  415. /** 
  416. * @var bool 
  417. */ 
  418. public $save = false; // Allow custom save handling for tables that aren't Pod-based 
  419.  
  420. /** 
  421. * Generate UI for Data Management 
  422. * @param mixed $options Object, Array, or String containing Pod or Options to be used 
  423. * @param bool $deprecated Set to true to support old options array from Pods UI plugin 
  424. * @return \PodsUI 
  425. * @license http://www.gnu.org/licenses/gpl-2.0.html 
  426. * @since 2.0 
  427. */ 
  428. public function __construct ( $options, $deprecated = false ) { 
  429.  
  430. $this->_nonce = pods_v( '_wpnonce', 'request' ); 
  431.  
  432. $object = null; 
  433.  
  434. if ( is_object( $options ) ) { 
  435. $object = $options; 
  436. $options = array(); 
  437.  
  438. if ( isset( $object->ui ) ) { 
  439. $options = (array) $object->ui; 
  440.  
  441. unset( $object->ui ); 
  442.  
  443. if ( is_object( $object ) && ( 'Pods' == get_class( $object ) || 'Pod' == get_class( $object ) ) ) 
  444. $this->pod =& $object; 
  445.  
  446. if ( !is_array( $options ) ) { 
  447. // @todo need to come back to this and allow for multi-dimensional strings 
  448. // like: option=value&option2=value2&option3=key[val], key2[val2]&option4=this, that, another 
  449. if ( false !== strpos( $options, '=' ) || false !== strpos( $options, '&' ) ) 
  450. parse_str( $options, $options ); 
  451. else 
  452. $options = array( 'pod' => $options ); 
  453.  
  454. if ( !is_object( $object ) && isset( $options[ 'pod' ] ) ) { 
  455. if ( is_object( $options[ 'pod' ] ) ) 
  456. $this->pod = $options[ 'pod' ]; 
  457. elseif ( isset( $options[ 'id' ] ) ) 
  458. $this->pod = pods( $options[ 'pod' ], $options[ 'id' ] ); 
  459. else 
  460. $this->pod = pods( $options[ 'pod' ] ); 
  461.  
  462. unset( $options[ 'pod' ] ); 
  463. elseif ( is_object( $object ) ) 
  464. $this->pod = $object; 
  465.  
  466. if ( false !== $deprecated || ( is_object( $this->pod ) && 'Pod' == get_class( $this->pod ) ) ) 
  467. $options = $this->setup_deprecated( $options ); 
  468.  
  469. if ( is_object( $this->pod ) && 'Pod' == get_class( $this->pod ) && is_object( $this->pod->_data ) ) 
  470. $this->pods_data =& $this->pod->_data; 
  471. elseif ( is_object( $this->pod ) && 'Pods' == get_class( $this->pod ) && is_object( $this->pod->data ) ) 
  472. $this->pods_data =& $this->pod->data; 
  473. elseif ( is_object( $this->pod ) ) 
  474. $this->pods_data = pods_data( $this->pod->pod ); 
  475. elseif ( !is_object( $this->pod ) ) 
  476. $this->pods_data = pods_data( $this->pod ); 
  477.  
  478. $options = $this->do_hook( 'pre_init', $options ); 
  479. $this->setup( $options ); 
  480.  
  481. if ( is_object( $this->pods_data ) && is_object( $this->pod ) && 0 < $this->id ) { 
  482. if ( $this->id != $this->pods_data->id ) 
  483. $this->row = $this->pods_data->fetch( $this->id ); 
  484. else 
  485. $this->row = $this->pods_data->row; 
  486.  
  487. if ( ( !is_object( $this->pod ) || 'Pods' != get_class( $this->pod ) ) && false === $this->sql[ 'table' ] && false === $this->data ) { 
  488. 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' ) ); 
  489.  
  490. return false; 
  491.  
  492. $this->go(); 
  493.  
  494. /** 
  495. * @param $deprecated_options 
  496. * @return array 
  497. */ 
  498. public function setup_deprecated ( $deprecated_options ) { 
  499. $options = array(); 
  500.  
  501. if ( isset( $deprecated_options[ 'id' ] ) ) 
  502. $options[ 'id' ] = $deprecated_options[ 'id' ]; 
  503. if ( isset( $deprecated_options[ 'action' ] ) ) 
  504. $options[ 'action' ] = $deprecated_options[ 'action' ]; 
  505. if ( isset( $deprecated_options[ 'num' ] ) ) 
  506. $options[ 'num' ] = $deprecated_options[ 'num' ]; 
  507.  
  508. if ( isset( $deprecated_options[ 'title' ] ) ) 
  509. $options[ 'items' ] = $deprecated_options[ 'title' ]; 
  510. if ( isset( $deprecated_options[ 'item' ] ) ) 
  511. $options[ 'item' ] = $deprecated_options[ 'item' ]; 
  512.  
  513. if ( isset( $deprecated_options[ 'label' ] ) ) 
  514. $options[ 'label' ] = array( 
  515. 'add' => $deprecated_options[ 'label' ],  
  516. 'edit' => $deprecated_options[ 'label' ],  
  517. 'duplicate' => $deprecated_options[ 'label' ] 
  518. ); 
  519. if ( isset( $deprecated_options[ 'label_add' ] ) ) { 
  520. if ( isset( $options[ 'label' ] ) ) 
  521. $options[ 'label' ][ 'add' ] = $deprecated_options[ 'label_add' ]; 
  522. else 
  523. $options[ 'label' ] = array( 'add' => $deprecated_options[ 'label_add' ] ); 
  524. if ( isset( $deprecated_options[ 'label_edit' ] ) ) { 
  525. if ( isset( $options[ 'label' ] ) ) 
  526. $options[ 'label' ][ 'edit' ] = $deprecated_options[ 'label_edit' ]; 
  527. else 
  528. $options[ 'label' ] = array( 'edit' => $deprecated_options[ 'label_edit' ] ); 
  529. if ( isset( $deprecated_options[ 'label_duplicate' ] ) ) { 
  530. if ( isset( $options[ 'label' ] ) ) 
  531. $options[ 'label' ][ 'duplicate' ] = $deprecated_options[ 'label_duplicate' ]; 
  532. else 
  533. $options[ 'label' ] = array( 'duplicate' => $deprecated_options[ 'label_duplicate' ] ); 
  534.  
  535. if ( isset( $deprecated_options[ 'icon' ] ) ) 
  536. $options[ 'icon' ] = $deprecated_options[ 'icon' ]; 
  537.  
  538. if ( isset( $deprecated_options[ 'columns' ] ) ) 
  539. $options[ 'fields' ] = array( 'manage' => $deprecated_options[ 'columns' ] ); 
  540. if ( isset( $deprecated_options[ 'reorder_columns' ] ) ) { 
  541. if ( isset( $options[ 'fields' ] ) ) 
  542. $options[ 'fields' ][ 'reorder' ] = $deprecated_options[ 'reorder_columns' ]; 
  543. else 
  544. $options[ 'fields' ] = array( 'reorder' => $deprecated_options[ 'reorder_columns' ] ); 
  545. if ( isset( $deprecated_options[ 'add_fields' ] ) ) { 
  546. if ( isset( $options[ 'fields' ] ) ) { 
  547. if ( !isset( $options[ 'fields' ][ 'add' ] ) ) 
  548. $options[ 'fields' ][ 'add' ] = $deprecated_options[ 'add_fields' ]; 
  549. if ( !isset( $options[ 'fields' ][ 'edit' ] ) ) 
  550. $options[ 'fields' ][ 'edit' ] = $deprecated_options[ 'add_fields' ]; 
  551. if ( !isset( $options[ 'fields' ][ 'duplicate' ] ) ) 
  552. $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'add_fields' ]; 
  553. else 
  554. $options[ 'fields' ] = array( 
  555. 'add' => $deprecated_options[ 'add_fields' ],  
  556. 'edit' => $deprecated_options[ 'add_fields' ],  
  557. 'duplicate' => $deprecated_options[ 'add_fields' ] 
  558. ); 
  559. if ( isset( $deprecated_options[ 'edit_fields' ] ) ) { 
  560. if ( isset( $options[ 'fields' ] ) ) { 
  561. if ( !isset( $options[ 'fields' ][ 'add' ] ) ) 
  562. $options[ 'fields' ][ 'add' ] = $deprecated_options[ 'edit_fields' ]; 
  563. if ( !isset( $options[ 'fields' ][ 'edit' ] ) ) 
  564. $options[ 'fields' ][ 'edit' ] = $deprecated_options[ 'edit_fields' ]; 
  565. if ( !isset( $options[ 'fields' ][ 'duplicate' ] ) ) 
  566. $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'edit_fields' ]; 
  567. else 
  568. $options[ 'fields' ] = array( 
  569. 'add' => $deprecated_options[ 'edit_fields' ],  
  570. 'edit' => $deprecated_options[ 'edit_fields' ],  
  571. 'duplicate' => $deprecated_options[ 'edit_fields' ] 
  572. ); 
  573. if ( isset( $deprecated_options[ 'duplicate_fields' ] ) ) { 
  574. if ( isset( $options[ 'fields' ] ) ) 
  575. $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_fields' ]; 
  576. else 
  577. $options[ 'fields' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_fields' ] ); 
  578.  
  579. if ( isset( $deprecated_options[ 'session_filters' ] ) && false === $deprecated_options[ 'session_filters' ] ) 
  580. $options[ 'session' ] = false; 
  581. if ( isset( $deprecated_options[ 'user_per_page' ] ) ) { 
  582. if ( isset( $options[ 'user' ] ) && !empty( $options[ 'user' ] ) ) 
  583. $options[ 'user' ] = array( 'orderby' ); 
  584. else 
  585. $options[ 'user' ] = false; 
  586. if ( isset( $deprecated_options[ 'user_sort' ] ) ) { 
  587. if ( isset( $options[ 'user' ] ) && !empty( $options[ 'user' ] ) ) 
  588. $options[ 'user' ] = array( 'show_per_page' ); 
  589. else 
  590. $options[ 'user' ] = false; 
  591.  
  592. if ( isset( $deprecated_options[ 'custom_list' ] ) ) { 
  593. if ( isset( $options[ 'actions_custom' ] ) ) 
  594. $options[ 'actions_custom' ][ 'manage' ] = $deprecated_options[ 'custom_list' ]; 
  595. else 
  596. $options[ 'actions_custom' ] = array( 'manage' => $deprecated_options[ 'custom_list' ] ); 
  597. if ( isset( $deprecated_options[ 'custom_reorder' ] ) ) { 
  598. if ( isset( $options[ 'actions_custom' ] ) ) 
  599. $options[ 'actions_custom' ][ 'reorder' ] = $deprecated_options[ 'custom_reorder' ]; 
  600. else 
  601. $options[ 'actions_custom' ] = array( 'reorder' => $deprecated_options[ 'custom_reorder' ] ); 
  602. if ( isset( $deprecated_options[ 'custom_add' ] ) ) { 
  603. if ( isset( $options[ 'actions_custom' ] ) ) 
  604. $options[ 'actions_custom' ][ 'add' ] = $deprecated_options[ 'custom_add' ]; 
  605. else 
  606. $options[ 'actions_custom' ] = array( 'add' => $deprecated_options[ 'custom_add' ] ); 
  607. if ( isset( $deprecated_options[ 'custom_edit' ] ) ) { 
  608. if ( isset( $options[ 'actions_custom' ] ) ) 
  609. $options[ 'actions_custom' ][ 'edit' ] = $deprecated_options[ 'custom_edit' ]; 
  610. else 
  611. $options[ 'actions_custom' ] = array( 'edit' => $deprecated_options[ 'custom_edit' ] ); 
  612. if ( isset( $deprecated_options[ 'custom_duplicate' ] ) ) { 
  613. if ( isset( $options[ 'actions_custom' ] ) ) 
  614. $options[ 'actions_custom' ][ 'duplicate' ] = $deprecated_options[ 'custom_duplicate' ]; 
  615. else 
  616. $options[ 'actions_custom' ] = array( 'duplicate' => $deprecated_options[ 'custom_duplicate' ] ); 
  617. if ( isset( $deprecated_options[ 'custom_delete' ] ) ) { 
  618. if ( isset( $options[ 'actions_custom' ] ) ) 
  619. $options[ 'actions_custom' ][ 'delete' ] = $deprecated_options[ 'custom_delete' ]; 
  620. else 
  621. $options[ 'actions_custom' ] = array( 'delete' => $deprecated_options[ 'custom_delete' ] ); 
  622. if ( isset( $deprecated_options[ 'custom_save' ] ) ) { 
  623. if ( isset( $options[ 'actions_custom' ] ) ) 
  624. $options[ 'actions_custom' ][ 'save' ] = $deprecated_options[ 'custom_save' ]; 
  625. else 
  626. $options[ 'actions_custom' ] = array( 'save' => $deprecated_options[ 'custom_save' ] ); 
  627.  
  628. if ( isset( $deprecated_options[ 'custom_actions' ] ) ) 
  629. $options[ 'actions_custom' ] = $deprecated_options[ 'custom_actions' ]; 
  630. if ( isset( $deprecated_options[ 'action_after_save' ] ) ) 
  631. $options[ 'action_after' ] = array( 
  632. 'add' => $deprecated_options[ 'action_after_save' ],  
  633. 'edit' => $deprecated_options[ 'action_after_save' ],  
  634. 'duplicate' => $deprecated_options[ 'action_after_save' ] 
  635. ); 
  636. if ( isset( $deprecated_options[ 'edit_link' ] ) ) { 
  637. if ( isset( $options[ 'action_links' ] ) ) 
  638. $options[ 'action_links' ][ 'edit' ] = $deprecated_options[ 'edit_link' ]; 
  639. else 
  640. $options[ 'action_links' ] = array( 'edit' => $deprecated_options[ 'edit_link' ] ); 
  641. if ( isset( $deprecated_options[ 'view_link' ] ) ) { 
  642. if ( isset( $options[ 'action_links' ] ) ) 
  643. $options[ 'action_links' ][ 'view' ] = $deprecated_options[ 'view_link' ]; 
  644. else 
  645. $options[ 'action_links' ] = array( 'view' => $deprecated_options[ 'view_link' ] ); 
  646. if ( isset( $deprecated_options[ 'duplicate_link' ] ) ) { 
  647. if ( isset( $options[ 'action_links' ] ) ) 
  648. $options[ 'action_links' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_link' ]; 
  649. else 
  650. $options[ 'action_links' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_link' ] ); 
  651.  
  652. if ( isset( $deprecated_options[ 'reorder' ] ) ) 
  653. $options[ 'reorder' ] = array( 
  654. 'on' => $deprecated_options[ 'reorder' ],  
  655. 'orderby' => $deprecated_options[ 'reorder' ] 
  656. ); 
  657. if ( isset( $deprecated_options[ 'reorder_sort' ] ) && isset( $options[ 'reorder' ] ) ) 
  658. $options[ 'reorder' ][ 'orderby' ] = $deprecated_options[ 'reorder_sort' ]; 
  659. if ( isset( $deprecated_options[ 'reorder_limit' ] ) && isset( $options[ 'reorder' ] ) ) 
  660. $options[ 'reorder' ][ 'limit' ] = $deprecated_options[ 'reorder_limit' ]; 
  661. if ( isset( $deprecated_options[ 'reorder_sql' ] ) && isset( $options[ 'reorder' ] ) ) 
  662. $options[ 'reorder' ][ 'sql' ] = $deprecated_options[ 'reorder_sql' ]; 
  663.  
  664. if ( isset( $deprecated_options[ 'sort' ] ) ) 
  665. $options[ 'orderby' ] = $deprecated_options[ 'sort' ]; 
  666. if ( isset( $deprecated_options[ 'sortable' ] ) ) 
  667. $options[ 'sortable' ] = $deprecated_options[ 'sortable' ]; 
  668. if ( isset( $deprecated_options[ 'limit' ] ) ) 
  669. $options[ 'limit' ] = $deprecated_options[ 'limit' ]; 
  670.  
  671. if ( isset( $deprecated_options[ 'where' ] ) ) { 
  672. if ( isset( $options[ 'where' ] ) ) 
  673. $options[ 'where' ][ 'manage' ] = $deprecated_options[ 'where' ]; 
  674. else 
  675. $options[ 'where' ] = array( 'manage' => $deprecated_options[ 'where' ] ); 
  676. if ( isset( $deprecated_options[ 'edit_where' ] ) ) { 
  677. /**if ( isset( $options[ 'where' ] ) ) 
  678. $options[ 'where' ][ 'edit' ] = $deprecated_options[ 'edit_where' ]; 
  679. else 
  680. $options[ 'where' ] = array( 'edit' => $deprecated_options[ 'edit_where' ] );*/ 
  681.  
  682. if ( isset( $options[ 'restrict' ] ) ) 
  683. $options[ 'restrict' ][ 'edit' ] = (array) $deprecated_options[ 'edit_where' ]; 
  684. else 
  685. $options[ 'restrict' ] = array( 'edit' => (array) $deprecated_options[ 'edit_where' ] ); 
  686. if ( isset( $deprecated_options[ 'duplicate_where' ] ) ) { 
  687. /**if ( isset( $options[ 'where' ] ) ) 
  688. $options[ 'where' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_where' ]; 
  689. else 
  690. $options[ 'where' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_where' ] );*/ 
  691.  
  692. if ( isset( $options[ 'restrict' ] ) ) 
  693. $options[ 'restrict' ][ 'duplicate' ] = (array) $deprecated_options[ 'duplicate_where' ]; 
  694. else 
  695. $options[ 'restrict' ] = array( 'duplicate' => (array) $deprecated_options[ 'duplicate_where' ] ); 
  696. if ( isset( $deprecated_options[ 'delete_where' ] ) ) { 
  697. /**if ( isset( $options[ 'where' ] ) ) 
  698. $options[ 'where' ][ 'delete' ] = $deprecated_options[ 'delete_where' ]; 
  699. else 
  700. $options[ 'where' ] = array( 'delete' => $deprecated_options[ 'delete_where' ] );*/ 
  701.  
  702. if ( isset( $options[ 'restrict' ] ) ) 
  703. $options[ 'restrict' ][ 'delete' ] = (array) $deprecated_options[ 'delete_where' ]; 
  704. else 
  705. $options[ 'restrict' ] = array( 'delete' => (array) $deprecated_options[ 'delete_where' ] ); 
  706. if ( isset( $deprecated_options[ 'reorder_where' ] ) ) { 
  707. if ( isset( $options[ 'where' ] ) ) 
  708. $options[ 'where' ][ 'reorder' ] = $deprecated_options[ 'reorder_where' ]; 
  709. else 
  710. $options[ 'where' ] = array( 'reorder' => $deprecated_options[ 'reorder_where' ] ); 
  711.  
  712. if ( isset( $deprecated_options[ 'sql' ] ) ) 
  713. $options[ 'sql' ] = array( 'sql' => $deprecated_options[ 'sql' ] ); 
  714.  
  715. if ( isset( $deprecated_options[ 'search' ] ) ) 
  716. $options[ 'searchable' ] = $deprecated_options[ 'search' ]; 
  717. if ( isset( $deprecated_options[ 'search_across' ] ) ) 
  718. $options[ 'search_across' ] = $deprecated_options[ 'search_across' ]; 
  719. if ( isset( $deprecated_options[ 'search_across_picks' ] ) ) 
  720. $options[ 'search_across_picks' ] = $deprecated_options[ 'search_across_picks' ]; 
  721. if ( isset( $deprecated_options[ 'filters' ] ) ) 
  722. $options[ 'filters' ] = $deprecated_options[ 'filters' ]; 
  723. if ( isset( $deprecated_options[ 'custom_filters' ] ) ) { 
  724. if ( is_callable( $deprecated_options[ 'custom_filters' ] ) ) 
  725. add_filter( 'pods_ui_filters', $deprecated_options[ 'custom_filters' ] ); 
  726. else { 
  727. global $pods_ui_custom_filters; 
  728. $pods_ui_custom_filters = $deprecated_options[ 'custom_filters' ]; 
  729. add_filter( 'pods_ui_filters', array( $this, 'deprecated_filters' ) ); 
  730.  
  731. if ( isset( $deprecated_options[ 'disable_actions' ] ) ) 
  732. $options[ 'actions_disabled' ] = $deprecated_options[ 'disable_actions' ]; 
  733. if ( isset( $deprecated_options[ 'hide_actions' ] ) ) 
  734. $options[ 'actions_hidden' ] = $deprecated_options[ 'hide_actions' ]; 
  735.  
  736. if ( isset( $deprecated_options[ 'wpcss' ] ) ) 
  737. $options[ 'wpcss' ] = $deprecated_options[ 'wpcss' ]; 
  738.  
  739. $remaining_options = array_diff_assoc( $options, $deprecated_options ); 
  740.  
  741. foreach ( $remaining_options as $option => $value ) { 
  742. if ( isset( $deprecated_options[ $option ] ) && isset( $this->$option ) ) 
  743. $options[ $option ] = $value; 
  744.  
  745. return $options; 
  746.  
  747. /** 
  748. */ 
  749. public function deprecated_filters () { 
  750. global $pods_ui_custom_filters; 
  751. echo $pods_ui_custom_filters; 
  752.  
  753. /** 
  754. * @param $options 
  755. * @return array|bool|mixed|null|PodsArray 
  756. */ 
  757. public function setup ( $options ) { 
  758. $options = pods_array( $options ); 
  759.  
  760. $options->validate( 'num', '', 'absint' ); 
  761.  
  762. if ( empty( $options->num ) ) 
  763. $options->num = ''; 
  764.  
  765. $options->validate( 'id', pods_var( 'id' . $options->num, 'get', $this->id ) ); 
  766.  
  767. $options->validate( 'do', pods_var( 'do' . $options->num, 'get', $this->do ), 'in_array', array( 
  768. 'save',  
  769. 'create' 
  770. ) ); 
  771.  
  772. $options->validate( 'excluded', self::$excluded, 'array_merge' ); 
  773.  
  774. $options->validate( 'action', pods_var( 'action' . $options->num, 'get', $this->action, null, true ), 'in_array', $this->actions ); 
  775. $options->validate( 'actions_bulk', $this->actions_bulk, 'array_merge' ); 
  776. $options->validate( 'action_bulk', pods_var( 'action_bulk' . $options->num, 'get', $this->action_bulk, null, true ), 'isset', $this->actions_bulk ); 
  777.  
  778. $bulk = pods_var( 'action_bulk_ids' . $options->num, 'get', array(), null, true ); 
  779.  
  780. if ( !empty( $bulk ) ) 
  781. $bulk = (array) pods_var( 'action_bulk_ids' . $options->num, 'get', array(), null, true ); 
  782. else 
  783. $bulk = array(); 
  784.  
  785. $options->validate( 'bulk', $bulk, 'array_merge', $this->bulk ); 
  786.  
  787. $options->validate( 'views', $this->views, 'array' ); 
  788. $options->validate( 'view', pods_var( 'view' . $options->num, 'get', $this->view, null, true ), 'isset', $this->views ); 
  789.  
  790. $options->validate( 'searchable', $this->searchable, 'boolean' ); 
  791. $options->validate( 'search', pods_var( 'search' . $options->num, 'get' ) ); 
  792. $options->validate( 'search_across', $this->search_across, 'boolean' ); 
  793. $options->validate( 'search_across_picks', $this->search_across_picks, 'boolean' ); 
  794. $options->validate( 'filters', $this->filters, 'array' ); 
  795. $options->validate( 'filters_enhanced', $this->filters_enhanced, 'boolean' ); 
  796. $options->validate( 'where', $this->where, 'array_merge' ); 
  797.  
  798. $options->validate( 'pagination', $this->pagination, 'boolean' ); 
  799. $options->validate( 'page', pods_var( 'pg' . $options->num, 'get', $this->page ), 'absint' ); 
  800. $options->validate( 'limit', pods_var( 'limit' . $options->num, 'get', $this->limit ), 'int' ); 
  801.  
  802. if ( isset( $this->pods_data ) && is_object( $this->pods_data ) ) { 
  803. $this->sql = array( 
  804. 'table' => $this->pods_data->table,  
  805. 'field_id' => $this->pods_data->field_id,  
  806. 'field_index' => $this->pods_data->field_index 
  807. ); 
  808. $options->validate( 'sql', $this->sql, 'array_merge' ); 
  809.  
  810. $options->validate( 'orderby_dir', strtoupper( pods_v( 'orderby_dir' . $options[ 'num' ], 'get', $this->orderby_dir, true ) ), 'in_array', array( 'ASC', 'DESC' ) ); 
  811.  
  812. $orderby = $this->orderby; 
  813.  
  814. // Enforce strict DB column name usage 
  815. if ( ! empty( $_GET[ 'orderby' . $options->num ] ) ) { 
  816. $orderby = pods_clean_name( $_GET[ 'orderby' . $options->num ], true, false ); 
  817.  
  818. if ( !empty( $orderby ) ) { 
  819. $orderby = array( 
  820. 'default' => $orderby 
  821. ); 
  822. else 
  823. $orderby = array(); 
  824.  
  825. $options->validate( 'orderby', $orderby, 'array_merge' ); 
  826. $options->validate( 'sortable', $this->sortable, 'boolean' ); 
  827.  
  828. $options->validate( 'params', $this->params, 'array' ); 
  829.  
  830. $options->validate( 'restrict', $this->restrict, 'array_merge' ); 
  831.  
  832. // handle author restrictions 
  833. if ( !empty( $options[ 'restrict' ][ 'author_restrict' ] ) ) { 
  834. $restrict = $options[ 'restrict' ]; 
  835.  
  836. if ( !is_array( $restrict[ 'author_restrict' ] ) ) 
  837. $restrict[ 'author_restrict' ] = array( $restrict[ 'author_restrict' ] => get_current_user_id() ); 
  838.  
  839. if ( null === $restrict[ 'edit' ] ) 
  840. $restrict[ 'edit' ] = $restrict[ 'author_restrict' ]; 
  841.  
  842. $options->restrict = $restrict; 
  843.  
  844. if ( null !== $options[ 'restrict' ][ 'edit' ] ) { 
  845. $restrict = $options[ 'restrict' ]; 
  846.  
  847. if ( null === $restrict[ 'duplicate' ] ) 
  848. $restrict[ 'duplicate' ] = $restrict[ 'edit' ]; 
  849.  
  850. if ( null === $restrict[ 'delete' ] ) 
  851. $restrict[ 'delete' ] = $restrict[ 'edit' ]; 
  852.  
  853. if ( null === $restrict[ 'manage' ] ) 
  854. $restrict[ 'manage' ] = $restrict[ 'edit' ]; 
  855.  
  856. if ( null === $restrict[ 'reorder' ] ) 
  857. $restrict[ 'reorder' ] = $restrict[ 'edit' ]; 
  858.  
  859. $options->restrict = $restrict; 
  860.  
  861. $item = __( 'Item', 'pods' ); 
  862. $items = __( 'Items', 'pods' ); 
  863.  
  864. if ( is_object( $this->pod ) ) { 
  865. $item = pods_var_raw( 'label_singular', $this->pod->pod_data[ 'options' ], pods_var_raw( 'label', $this->pod->pod_data, $item, null, true ), null, true ); 
  866. $items = pods_var_raw( 'label', $this->pod->pod_data, $items, null, true ); 
  867.  
  868. $options->validate( 'item', $item ); 
  869. $options->validate( 'items', $items ); 
  870.  
  871. $options->validate( 'heading', array( 
  872. 'manage' => __( 'Manage', 'pods' ),  
  873. 'add' => __( 'Add New', 'pods' ),  
  874. 'edit' => __( 'Edit', 'pods' ),  
  875. 'duplicate' => __( 'Duplicate', 'pods' ),  
  876. 'view' => __( 'View', 'pods' ),  
  877. 'reorder' => __( 'Reorder', 'pods' ),  
  878. 'search' => __( 'Search', 'pods' ),  
  879. 'views' => __( 'View', 'pods' ) 
  880. ), 'array_merge' ); 
  881.  
  882. $options->validate( 'header', array( 
  883. 'manage' => sprintf( __( 'Manage %s', 'pods' ), $options->items ),  
  884. 'add' => sprintf( __( 'Add New %s', 'pods' ), $options->item ),  
  885. 'edit' => sprintf( __( 'Edit %s', 'pods' ), $options->item ),  
  886. 'duplicate' => sprintf( __( 'Duplicate %s', 'pods' ), $options->item ),  
  887. 'view' => sprintf( __( 'View %s', 'pods' ), $options->item ),  
  888. 'reorder' => sprintf( __( 'Reorder %s', 'pods' ), $options->items ),  
  889. 'search' => sprintf( __( 'Search %s', 'pods' ), $options->items ) 
  890. ), 'array_merge' ); 
  891.  
  892. $options->validate( 'label', array( 
  893. 'add' => sprintf( __( 'Save New %s', 'pods' ), $options->item ),  
  894. 'add_new' => __( 'Add New', 'pods' ),  
  895. 'edit' => sprintf( __( 'Save %s', 'pods' ), $options->item ),  
  896. 'duplicate' => sprintf( __( 'Save New %s', 'pods' ), $options->item ),  
  897. 'delete' => sprintf( __( 'Delete this %s', 'pods' ), $options->item ),  
  898. 'view' => sprintf( __( 'View %s', 'pods' ), $options->item ),  
  899. 'reorder' => sprintf( __( 'Reorder %s', 'pods' ), $options->items ) 
  900. ), 'array_merge' ); 
  901.  
  902. $options->validate( 'fields', array( 
  903. 'manage' => array( 
  904. $options->sql[ 'field_index' ] => array( 'label' => __( 'Name', 'pods' ) ) 
  905. ), 'array' ); 
  906.  
  907. $options->validate( 'export', $this->export, 'array_merge' ); 
  908. $options->validate( 'reorder', $this->reorder, 'array_merge' ); 
  909. $options->validate( 'screen_options', $this->screen_options, 'array_merge' ); 
  910.  
  911. $options->validate( 'session', $this->session, 'in_array', array( 
  912. 'search',  
  913. 'filters',  
  914. 'show_per_page',  
  915. 'orderby' 
  916. ) ); 
  917. $options->validate( 'user', $this->user, 'in_array', array( 
  918. 'search',  
  919. 'filters',  
  920. 'show_per_page',  
  921. 'orderby' 
  922. ) ); 
  923.  
  924. $options->validate( 'action_after', $this->action_after, 'array_merge' ); 
  925. $options->validate( 'action_links', $this->action_links, 'array_merge' ); 
  926. $options->validate( 'actions_disabled', $this->actions_disabled, 'array' ); 
  927. $options->validate( 'actions_hidden', $this->actions_hidden, 'array_merge' ); 
  928. $options->validate( 'actions_custom', $this->actions_custom, 'array_merge' ); 
  929.  
  930. if ( !empty( $options->actions_disabled ) ) { 
  931. if ( !empty( $options->actions_bulk ) ) { 
  932. $actions_bulk = $options->actions_bulk; 
  933.  
  934. foreach ( $actions_bulk as $action => $action_opt ) { 
  935. if ( in_array( $action, $options->actions_disabled ) ) { 
  936. unset( $actions_bulk[ $action ] ); 
  937.  
  938. $options->actions_bulk = $actions_bulk; 
  939.  
  940. if ( !empty( $options->actions_custom ) ) { 
  941. $actions_custom = $options->actions_custom; 
  942.  
  943. foreach ( $actions_custom as $action => $action_opt ) { 
  944. if ( in_array( $action, $options->actions_disabled ) ) { 
  945. unset( $actions_custom[ $action ] ); 
  946.  
  947. $options->actions_custom = $actions_custom; 
  948.  
  949. $options->validate( 'extra', $this->extra, 'array_merge' ); 
  950.  
  951. $options->validate( 'style', $this->style ); 
  952. $options->validate( 'icon', $this->icon ); 
  953. $options->validate( 'css', $this->css ); 
  954. $options->validate( 'wpcss', $this->wpcss, 'boolean' ); 
  955.  
  956. if ( true === $options[ 'wpcss' ] ) { 
  957. global $user_ID; 
  958. get_currentuserinfo(); 
  959.  
  960. $color = get_user_meta( $user_ID, 'admin_color', true ); 
  961. if ( strlen( $color ) < 1 ) 
  962. $color = 'fresh'; 
  963.  
  964. $this->wpcss = "colors-{$color}"; 
  965.  
  966. $options = $options->dump(); 
  967.  
  968. if ( is_object( $this->pod ) ) 
  969. $options = $this->do_hook( $this->pod->pod . '_setup_options', $options ); 
  970.  
  971. $options = $this->do_hook( 'setup_options', $options ); 
  972.  
  973. if ( false !== $options && !empty( $options ) ) { 
  974. foreach ( $options as $option => $value ) { 
  975. if ( isset( $this->{$option} ) ) 
  976. $this->{$option} = $value; 
  977. else 
  978. $this->x[ $option ] = $value; 
  979.  
  980. $unique_identifier = pods_var( 'page', 'get' ); // wp-admin page 
  981. if ( is_object( $this->pod ) && isset( $this->pod->pod ) ) 
  982. $unique_identifier = '_' . $this->pod->pod; 
  983. elseif ( 0 < strlen( $this->sql[ 'table' ] ) ) 
  984. $unique_identifier = '_' . $this->sql[ 'table' ]; 
  985.  
  986. $unique_identifier .= '_' . $this->page; 
  987. if ( 0 < strlen( $this->num ) ) 
  988. $unique_identifier .= '_' . $this->num; 
  989.  
  990. $this->unique_identifier = 'pods_ui_' . md5( $unique_identifier ); 
  991.  
  992. $this->setup_fields(); 
  993.  
  994. return $options; 
  995.  
  996. /** 
  997. * @param null $fields 
  998. * @param string $which 
  999. * @return array|bool|mixed|null 
  1000. */ 
  1001. public function setup_fields ( $fields = null, $which = 'fields' ) { 
  1002. $init = false; 
  1003. if ( null === $fields ) { 
  1004. if ( isset( $this->fields[ $which ] ) ) 
  1005. $fields = (array) $this->fields[ $which ]; 
  1006. elseif ( isset( $this->fields[ 'manage' ] ) ) 
  1007. $fields = (array) $this->fields[ 'manage' ]; 
  1008. else 
  1009. $fields = array(); 
  1010. if ( 'fields' == $which ) 
  1011. $init = true; 
  1012. if ( !empty( $fields ) ) { 
  1013. // Available Attributes 
  1014. // type = field type 
  1015. // type = date (data validation as date) 
  1016. // type = time (data validation as time) 
  1017. // type = datetime (data validation as datetime) 
  1018. // date_touch = use current timestamp when saving (even if readonly, if type is date-related) 
  1019. // date_touch_on_create = use current timestamp when saving ONLY on create (even if readonly, if type is date-related) 
  1020. // 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 
  1021. // type = text / other (single line text box) 
  1022. // type = desc (textarea) 
  1023. // type = number (data validation as int float) 
  1024. // type = decimal (data validation as decimal) 
  1025. // type = password (single line password box) 
  1026. // type = bool (checkbox) 
  1027. // type = related (select box) 
  1028. // related = table to relate to (if type=related) OR custom array of (key => label or comma separated values) items 
  1029. // related_field = field name on table to show (if type=related) - default "name" 
  1030. // related_multiple = true (ability to select multiple values if type=related) 
  1031. // related_sql = custom where / order by SQL (if type=related) 
  1032. // readonly = true (shows as text) 
  1033. // display = false (doesn't show on form, but can be saved) 
  1034. // search = this field is searchable 
  1035. // filter = this field will be independently searchable (by default, searchable fields are searched by the primary search box) 
  1036. // comments = comments to show for field 
  1037. // comments_top = true (shows comments above field instead of below) 
  1038. // real_name = the real name of the field (if using an alias for 'name') 
  1039. // group_related = true (uses HAVING instead of WHERE for filtering field) 
  1040. $new_fields = array(); 
  1041. $filterable = false; 
  1042. if ( empty( $this->filters ) && ( empty( $this->fields[ 'search' ] ) || 'search' == $which ) && false !== $this->searchable ) { 
  1043. $filterable = true; 
  1044. $this->filters = array(); 
  1045.  
  1046. foreach ( $fields as $field => $attributes ) { 
  1047. if ( !is_array( $attributes ) ) { 
  1048. if ( is_int( $field ) ) { 
  1049. $field = $attributes; 
  1050. $attributes = array(); 
  1051. else 
  1052. $attributes = array( 'label' => $attributes ); 
  1053.  
  1054. if ( !isset( $attributes[ 'real_name' ] ) ) 
  1055. $attributes[ 'real_name' ] = pods_var( 'name', $attributes, $field ); 
  1056.  
  1057. if ( is_object( $this->pod ) && isset( $this->pod->fields ) && isset( $this->pod->fields[ $attributes[ 'real_name' ] ] ) ) 
  1058. $attributes = array_merge( $this->pod->fields[ $attributes[ 'real_name' ] ], $attributes ); 
  1059.  
  1060. if ( !isset( $attributes[ 'options' ] ) ) 
  1061. $attributes[ 'options' ] = array(); 
  1062. if ( !isset( $attributes[ 'id' ] ) ) 
  1063. $attributes[ 'id' ] = ''; 
  1064. if ( !isset( $attributes[ 'label' ] ) ) 
  1065. $attributes[ 'label' ] = ucwords( str_replace( '_', ' ', $field ) ); 
  1066. if ( !isset( $attributes[ 'type' ] ) ) 
  1067. $attributes[ 'type' ] = 'text'; 
  1068. if ( !isset( $attributes[ 'options' ][ 'date_format_type' ] ) ) 
  1069. $attributes[ 'options' ][ 'date_format_type' ] = 'date'; 
  1070. if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related' ] ) ) 
  1071. $attributes[ 'related' ] = false; 
  1072. if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_id' ] ) ) 
  1073. $attributes[ 'related_id' ] = 'id'; 
  1074. if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_field' ] ) ) 
  1075. $attributes[ 'related_field' ] = 'name'; 
  1076. if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_multiple' ] ) ) 
  1077. $attributes[ 'related_multiple' ] = false; 
  1078. if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_sql' ] ) ) 
  1079. $attributes[ 'related_sql' ] = false; 
  1080. if ( 'related' == $attributes[ 'type' ] && ( is_array( $attributes[ 'related' ] ) || strpos( $attributes[ 'related' ], ', ' ) ) ) { 
  1081. if ( !is_array( $attributes[ 'related' ] ) ) { 
  1082. $attributes[ 'related' ] = @explode( ', ', $attributes[ 'related' ] ); 
  1083. $related_items = array(); 
  1084. foreach ( $attributes[ 'related' ] as $key => $label ) { 
  1085. if ( is_numeric( $key ) ) { 
  1086. $key = $label; 
  1087. $label = ucwords( str_replace( '_', ' ', $label ) ); 
  1088. $related_items[ $key ] = $label; 
  1089. $attributes[ 'related' ] = $related_items; 
  1090. if ( empty( $attributes[ 'related' ] ) ) 
  1091. $attributes[ 'related' ] = false; 
  1092. if ( !isset( $attributes[ 'readonly' ] ) ) 
  1093. $attributes[ 'readonly' ] = false; 
  1094. if ( !isset( $attributes[ 'date_touch' ] ) || 'date' != $attributes[ 'type' ] ) 
  1095. $attributes[ 'date_touch' ] = false; 
  1096. if ( !isset( $attributes[ 'date_touch_on_create' ] ) || 'date' != $attributes[ 'type' ] ) 
  1097. $attributes[ 'date_touch_on_create' ] = false; 
  1098. if ( !isset( $attributes[ 'display' ] ) ) 
  1099. $attributes[ 'display' ] = true; 
  1100. if ( !isset( $attributes[ 'hidden' ] ) ) 
  1101. $attributes[ 'hidden' ] = false; 
  1102. if ( !isset( $attributes[ 'sortable' ] ) || false === $this->sortable ) 
  1103. $attributes[ 'sortable' ] = $this->sortable; 
  1104. if ( !isset( $attributes[ 'options' ][ 'search' ] ) || false === $this->searchable ) 
  1105. $attributes[ 'options' ][ 'search' ] = $this->searchable; 
  1106. if ( !isset( $attributes[ 'options' ][ 'filter' ] ) || false === $this->searchable ) 
  1107. $attributes[ 'options' ][ 'filter' ] = $this->searchable; 
  1108. /**if ( false !== $attributes[ 'options' ][ 'filter' ] && false !== $filterable ) 
  1109. $this->filters[] = $field;*/ 
  1110. if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'filter_label' ] ) || !in_array( $field, $this->filters ) ) 
  1111. $attributes[ 'filter_label' ] = $attributes[ 'label' ]; 
  1112. if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'filter_default' ] ) || !in_array( $field, $this->filters ) ) 
  1113. $attributes[ 'filter_default' ] = false; 
  1114. if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'date_ongoing' ] ) || 'date' != $attributes[ 'type' ] || !in_array( $field, $this->filters ) ) 
  1115. $attributes[ 'date_ongoing' ] = false; 
  1116. if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'date_ongoing' ] ) || 'date' != $attributes[ 'type' ] || !isset( $attributes[ 'date_ongoing_default' ] ) || !in_array( $field, $this->filters ) ) 
  1117. $attributes[ 'date_ongoing_default' ] = false; 
  1118. if ( !isset( $attributes[ 'export' ] ) ) 
  1119. $attributes[ 'export' ] = true; 
  1120. if ( !isset( $attributes[ 'group_related' ] ) ) 
  1121. $attributes[ 'group_related' ] = false; 
  1122. if ( !isset( $attributes[ 'comments' ] ) ) 
  1123. $attributes[ 'comments' ] = ''; 
  1124. if ( !isset( $attributes[ 'comments_top' ] ) ) 
  1125. $attributes[ 'comments_top' ] = false; 
  1126. if ( !isset( $attributes[ 'custom_view' ] ) ) 
  1127. $attributes[ 'custom_view' ] = false; 
  1128. if ( !isset( $attributes[ 'custom_input' ] ) ) 
  1129. $attributes[ 'custom_input' ] = false; 
  1130. if ( isset( $attributes[ 'display_helper' ] ) ) // pods ui backward compatibility 
  1131. $attributes[ 'custom_display' ] = $attributes[ 'display_helper' ]; 
  1132. if ( !isset( $attributes[ 'custom_display' ] ) ) 
  1133. $attributes[ 'custom_display' ] = false; 
  1134. if ( !isset( $attributes[ 'custom_relate' ] ) ) 
  1135. $attributes[ 'custom_relate' ] = false; 
  1136. if ( !isset( $attributes[ 'custom_form_display' ] ) ) 
  1137. $attributes[ 'custom_form_display' ] = false; 
  1138. if ( !isset( $attributes[ 'css_values' ] ) ) 
  1139. $attributes[ 'css_values' ] = true; 
  1140. if ( 'search_columns' == $which && !$attributes[ 'options' ][ 'search' ] ) 
  1141. continue; 
  1142.  
  1143. $attributes = PodsForm::field_setup( $attributes, null, $attributes[ 'type' ] ); 
  1144.  
  1145. $new_fields[ $field ] = $attributes; 
  1146. $fields = $new_fields; 
  1147. if ( false !== $init ) { 
  1148. if ( 'fields' != $which && !empty( $this->fields ) ) 
  1149. $this->fields = $this->setup_fields( $this->fields, 'fields' ); 
  1150. else 
  1151. $this->fields[ 'manage' ] = $fields; 
  1152.  
  1153. if ( !in_array( 'add', $this->actions_disabled ) || !in_array( 'edit', $this->actions_disabled ) || !in_array( 'duplicate', $this->actions_disabled ) ) { 
  1154. if ( 'form' != $which && isset( $this->fields[ 'form' ] ) && is_array( $this->fields[ 'form' ] ) ) 
  1155. $this->fields[ 'form' ] = $this->setup_fields( $this->fields[ 'form' ], 'form' ); 
  1156. else 
  1157. $this->fields[ 'form' ] = $fields; 
  1158.  
  1159. if ( !in_array( 'add', $this->actions_disabled ) ) { 
  1160. if ( 'add' != $which && isset( $this->fields[ 'add' ] ) && is_array( $this->fields[ 'add' ] ) ) 
  1161. $this->fields[ 'add' ] = $this->setup_fields( $this->fields[ 'add' ], 'add' ); 
  1162. if ( !in_array( 'edit', $this->actions_disabled ) ) { 
  1163. if ( 'edit' != $which && isset( $this->fields[ 'edit' ] ) && is_array( $this->fields[ 'edit' ] ) ) 
  1164. $this->fields[ 'edit' ] = $this->setup_fields( $this->fields[ 'edit' ], 'edit' ); 
  1165. if ( !in_array( 'duplicate', $this->actions_disabled ) ) { 
  1166. if ( 'duplicate' != $which && isset( $this->fields[ 'duplicate' ] ) && is_array( $this->fields[ 'duplicate' ] ) ) 
  1167. $this->fields[ 'duplicate' ] = $this->setup_fields( $this->fields[ 'duplicate' ], 'duplicate' ); 
  1168.  
  1169. if ( false !== $this->searchable ) { 
  1170. if ( 'search' != $which && isset( $this->fields[ 'search' ] ) &&!empty( $this->fields[ 'search' ] ) ) 
  1171. $this->fields[ 'search' ] = $this->setup_fields( $this->fields[ 'search' ], 'search' ); 
  1172. else 
  1173. $this->fields[ 'search' ] = $fields; 
  1174. else 
  1175. $this->fields[ 'search' ] = false; 
  1176.  
  1177. if ( !in_array( 'export', $this->actions_disabled ) ) { 
  1178. if ( 'export' != $which && isset( $this->fields[ 'export' ] ) &&!empty( $this->fields[ 'export' ] ) ) 
  1179. $this->fields[ 'export' ] = $this->setup_fields( $this->fields[ 'export' ], 'export' ); 
  1180.  
  1181. if ( !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) { 
  1182. if ( 'reorder' != $which && isset( $this->fields[ 'reorder' ] ) &&!empty( $this->fields[ 'reorder' ] ) ) 
  1183. $this->fields[ 'reorder' ] = $this->setup_fields( $this->fields[ 'reorder' ], 'reorder' ); 
  1184. else 
  1185. $this->fields[ 'reorder' ] = $fields; 
  1186. return $this->do_hook( 'setup_fields', $fields, $which, $init ); 
  1187.  
  1188. /** 
  1189. * @param $msg 
  1190. * @param bool $error 
  1191. */ 
  1192. public function message ( $msg, $error = false ) { 
  1193. $msg = $this->do_hook( ( $error ) ? 'error' : 'message', $msg ); 
  1194. ?> 
  1195. <div id="message" class="<?php echo esc_attr( ( $error ) ? 'error' : 'updated' ); ?> fade"><p><?php echo $msg; ?></p></div> 
  1196. <?php 
  1197.  
  1198. /** 
  1199. * @param $msg 
  1200. * @return bool 
  1201. */ 
  1202. public function error ( $msg ) { 
  1203. $this->message( $msg, true ); 
  1204.  
  1205. return false; 
  1206.  
  1207. /** 
  1208. * @return mixed 
  1209. */ 
  1210. public function go () { 
  1211. $this->do_hook( 'go' ); 
  1212. $_GET = pods_unsanitize( $_GET ); // fix wp sanitization 
  1213. $_POST = pods_unsanitize( $_POST ); // fix wp sanitization 
  1214.  
  1215. if ( false !== $this->css ) { 
  1216. ?> 
  1217. <link type="text/css" rel="stylesheet" href="<?php echo esc_url( $this->css ); ?>" /> 
  1218. <?php 
  1219. if ( false !== $this->wpcss ) { 
  1220. $stylesheets = array( 'global', 'wp-admin', $this->wpcss ); 
  1221. foreach ( $stylesheets as $style ) { 
  1222. if ( !wp_style_is( $style, 'queue' ) && !wp_style_is( $style, 'to_do' ) && !wp_style_is( $style, 'done' ) ) 
  1223. wp_enqueue_style( $style ); 
  1224.  
  1225. $this->ui_page = array( $this->action ); 
  1226. if ( 'add' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) { 
  1227. $this->ui_page[] = 'form'; 
  1228. if ( 'create' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) { 
  1229. $this->ui_page[] = $this->do; 
  1230. $this->save( true ); 
  1231. $this->manage(); 
  1232. else 
  1233. $this->add(); 
  1234. elseif ( ( 'edit' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) || ( 'duplicate' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) ) { 
  1235. $this->ui_page[] = 'form'; 
  1236. if ( 'save' == $this->do && $this->save && !empty( $_POST ) ) 
  1237. $this->save(); 
  1238. $this->edit( ( 'duplicate' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) ? true : false ); 
  1239. elseif ( 'delete' == $this->action && !in_array( $this->action, $this->actions_disabled ) && false !== wp_verify_nonce( $this->_nonce, 'pods-ui-action-delete' ) ) { 
  1240. $this->delete( $this->id ); 
  1241. $this->manage(); 
  1242. elseif ( 'reorder' == $this->action && !in_array( $this->action, $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) { 
  1243. if ( 'save' == $this->do ) { 
  1244. $this->ui_page[] = $this->do; 
  1245. $this->reorder(); 
  1246. $this->manage( true ); 
  1247. elseif ( 'save' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) { 
  1248. $this->ui_page[] = $this->do; 
  1249. $this->save(); 
  1250. $this->manage(); 
  1251. elseif ( 'create' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) { 
  1252. $this->ui_page[] = $this->do; 
  1253. $this->save( true ); 
  1254. $this->manage(); 
  1255. elseif ( 'view' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) 
  1256. $this->view(); 
  1257. else { 
  1258. if ( isset( $this->actions_custom[ $this->action ] ) ) { 
  1259. $more_args = false; 
  1260.  
  1261. if ( is_array( $this->actions_custom[ $this->action ] ) && isset( $this->actions_custom[ $this->action ][ 'more_args' ] ) ) { 
  1262. $more_args = $this->actions_custom[ $this->action ][ 'more_args' ]; 
  1263.  
  1264. $row = $this->row; 
  1265.  
  1266. if ( empty( $row ) ) { 
  1267. $row = $this->get_row(); 
  1268.  
  1269. if ( $this->restricted( $this->action, $row ) || ( $more_args && ! empty( $more_args[ 'nonce' ] ) && false === wp_verify_nonce( $this->_nonce, 'pods-ui-action-' . $this->action ) ) ) { 
  1270. return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) ); 
  1271. elseif ( $more_args && false !== $this->callback_action( true, $this->action, $this->id, $row ) ) { 
  1272. return null; 
  1273. elseif ( false !== $this->callback_action( true, $this->action, $this->id ) ) { 
  1274. return null; 
  1275.  
  1276. if ( !in_array( 'manage', $this->actions_disabled ) ) { 
  1277. // handle session / user persistent settings for show_per_page, orderby, search, and filters 
  1278. $methods = array( 'session', 'user' ); 
  1279.  
  1280. // @todo fix this to set ($this) AND save (setting) 
  1281. foreach ( $methods as $method ) { 
  1282. foreach ( $this->$method as $setting ) { 
  1283. if ( 'show_per_page' == $setting ) 
  1284. $value = $this->limit; 
  1285. elseif ( 'orderby' == $setting ) { 
  1286. if ( empty( $this->orderby ) ) 
  1287. $value = ''; 
  1288. // save this if we have a default index set 
  1289. elseif ( isset( $this->orderby[ 'default' ] ) ) { 
  1290. $value = $this->orderby[ 'default' ] . ' ' 
  1291. . ( false === strpos( $this->orderby[ 'default' ], ' ' ) ? $this->orderby_dir : '' ); 
  1292. else 
  1293. $value = ''; 
  1294. else 
  1295. $value = $this->$setting; 
  1296.  
  1297. pods_v_set( $value, $setting, $method ); 
  1298.  
  1299. $this->manage(); 
  1300.  
  1301. /** 
  1302. * @return mixed 
  1303. */ 
  1304. public function add () { 
  1305. if ( false !== $this->callback_action( 'add' ) ) { 
  1306. return null; 
  1307. ?> 
  1308. <div class="wrap pods-ui"> 
  1309. <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>><br /></div> 
  1310. <h2> 
  1311. <?php 
  1312. echo $this->header[ 'add' ]; 
  1313.  
  1314. $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() ); 
  1315.  
  1316. if ( !empty( $this->action_links[ 'manage' ] ) ) { 
  1317. $link = $this->action_links[ 'manage' ]; 
  1318. ?> 
  1319. <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">« <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a> 
  1320. </h2> 
  1321.  
  1322. <?php $this->form( true ); ?> 
  1323. </div> 
  1324. <?php 
  1325.  
  1326. /** 
  1327. * @param bool $duplicate 
  1328. * @return mixed 
  1329. */ 
  1330. public function edit ( $duplicate = false ) { 
  1331. if ( in_array( 'duplicate', $this->actions_disabled ) ) 
  1332. $duplicate = false; 
  1333.  
  1334. if ( empty( $this->row ) ) 
  1335. $this->get_row(); 
  1336.  
  1337. if ( $duplicate && false !== $this->callback_action( 'duplicate' ) ) { 
  1338. return null; 
  1339. elseif ( false !== $this->callback_action( 'edit', $duplicate ) ) { 
  1340. return null; 
  1341. ?> 
  1342. <div class="wrap pods-ui"> 
  1343. <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>><br /></div> 
  1344. <h2> 
  1345. <?php 
  1346. echo $this->do_template( $duplicate ? $this->header[ 'duplicate' ] : $this->header[ 'edit' ] ); 
  1347.  
  1348. if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) { 
  1349. $link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num = '' ), self::$allowed, $this->exclusion() ); 
  1350.  
  1351. if ( !empty( $this->action_links[ 'add' ] ) ) 
  1352. $link = $this->action_links[ 'add' ]; 
  1353. ?> 
  1354. <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo $this->heading[ 'add' ]; ?></a> 
  1355. <?php 
  1356. elseif ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) ) { 
  1357. $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() ); 
  1358.  
  1359. if ( !empty( $this->action_links[ 'manage' ] ) ) 
  1360. $link = $this->action_links[ 'manage' ]; 
  1361. ?> 
  1362. <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">« <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a> 
  1363. <?php 
  1364. ?> 
  1365. </h2> 
  1366.  
  1367. <?php $this->form( false, $duplicate ); ?> 
  1368. </div> 
  1369. <?php 
  1370.  
  1371. /** 
  1372. * @param bool $create 
  1373. * @param bool $duplicate 
  1374. * @return bool|mixed 
  1375. */ 
  1376. public function form ( $create = false, $duplicate = false ) { 
  1377. if ( in_array( 'duplicate', $this->actions_disabled ) ) 
  1378. $duplicate = false; 
  1379.  
  1380. if ( false !== $this->callback( 'form' ) ) { 
  1381. return null; 
  1382.  
  1383. $label = $this->label[ 'add' ]; 
  1384. $id = null; 
  1385. $vars = array( 
  1386. 'action' . $this->num => $this->action_after[ 'add' ],  
  1387. 'do' . $this->num => 'create',  
  1388. 'id' . $this->num => 'X_ID_X' 
  1389. ); 
  1390.  
  1391. $alt_vars = $vars; 
  1392. $alt_vars[ 'action' ] = 'manage'; 
  1393. unset( $alt_vars[ 'id' ] ); 
  1394.  
  1395. if ( false === $create ) { 
  1396. if ( empty( $this->row ) ) 
  1397. $this->get_row(); 
  1398.  
  1399. if ( empty( $this->row ) && ( !is_object( $this->pod ) || 'settings' != $this->pod->pod_data[ 'type' ] ) ) 
  1400. return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) ); 
  1401.  
  1402. if ( $this->restricted( $this->action, $this->row ) ) 
  1403. return $this->error( sprintf( __( '<strong>Error:</strong> You do not have access to this %s.', 'pods' ), $this->item ) ); 
  1404.  
  1405. $label = $this->do_template( $this->label[ 'edit' ] ); 
  1406. $id = $this->row[ $this->sql[ 'field_id' ] ]; 
  1407. $vars = array( 
  1408. 'action' . $this->num => $this->action_after[ 'edit' ],  
  1409. 'do' . $this->num => 'save',  
  1410. 'id' . $this->num => $id 
  1411. ); 
  1412.  
  1413. $alt_vars = $vars; 
  1414. $alt_vars[ 'action' ] = 'manage'; 
  1415. unset( $alt_vars[ 'id' ] ); 
  1416.  
  1417. if ( $duplicate ) { 
  1418. $label = $this->do_template( $this->label[ 'duplicate' ] ); 
  1419. $id = null; 
  1420. $vars = array( 
  1421. 'action' . $this->num => $this->action_after[ 'duplicate' ],  
  1422. 'do' . $this->num => 'create',  
  1423. 'id' . $this->num => 'X_ID_X' 
  1424. ); 
  1425.  
  1426. $alt_vars = $vars; 
  1427. $alt_vars[ 'action' ] = 'manage'; 
  1428. unset( $alt_vars[ 'id' ] ); 
  1429.  
  1430. $fields = array(); 
  1431.  
  1432. if ( isset( $this->fields[ $this->action ] ) ) 
  1433. $fields = $this->fields[ $this->action ]; 
  1434.  
  1435. if ( is_object( $this->pod ) ) { 
  1436. $object_fields = (array) pods_var_raw( 'object_fields', $this->pod->pod_data, array(), null, true ); 
  1437.  
  1438. if ( empty( $object_fields ) && in_array( $this->pod->pod_data[ 'type' ], array( 'post_type', 'taxonomy', 'media', 'user', 'comment' ) ) ) 
  1439. $object_fields = $this->pod->api->get_wp_object_fields( $this->pod->pod_data[ 'type' ], $this->pod->pod_data ); 
  1440.  
  1441. if ( empty( $fields ) ) { 
  1442. // Add core object fields if $fields is empty 
  1443. $fields = array_merge( $object_fields, $this->pod->fields ); 
  1444.  
  1445. $form_fields = $fields; // Temporary 
  1446.  
  1447. $fields = array(); 
  1448.  
  1449. foreach ( $form_fields as $k => $field ) { 
  1450. $name = $k; 
  1451.  
  1452. $defaults = array( 
  1453. 'name' => $name 
  1454. ); 
  1455.  
  1456. if ( !is_array( $field ) ) { 
  1457. $name = $field; 
  1458.  
  1459. $field = array( 
  1460. 'name' => $name 
  1461. ); 
  1462.  
  1463. $field = array_merge( $defaults, $field ); 
  1464.  
  1465. $field[ 'name' ] = trim( $field[ 'name' ] ); 
  1466.  
  1467. $default_value = pods_var_raw( 'default', $field ); 
  1468. $value = pods_var_raw( 'value', $field ); 
  1469.  
  1470. if ( empty( $field[ 'name' ] ) ) 
  1471. $field[ 'name' ] = trim( $name ); 
  1472.  
  1473. if ( isset( $object_fields[ $field[ 'name' ] ] ) ) 
  1474. $field = array_merge( $field, $object_fields[ $field[ 'name' ] ] ); 
  1475. elseif ( isset( $this->pod->fields[ $field[ 'name' ] ] ) ) 
  1476. $field = array_merge( $this->pod->fields[ $field[ 'name' ] ], $field ); 
  1477.  
  1478. if ( pods_var_raw( 'hidden', $field, false, null, true ) ) 
  1479. $field[ 'type' ] = 'hidden'; 
  1480.  
  1481. $fields[ $field[ 'name' ] ] = $field; 
  1482.  
  1483. if ( empty( $this->id ) && null !== $default_value ) { 
  1484. $this->pod->row_override[ $field[ 'name' ] ] = $default_value; 
  1485. elseif ( !empty( $this->id ) && null !== $value ) { 
  1486. $this->pod->row[ $field[ 'name' ] ] = $value; 
  1487.  
  1488. unset( $form_fields ); // Cleanup 
  1489.  
  1490. $fields = $this->do_hook( 'form_fields', $fields, $this->pod ); 
  1491.  
  1492. $pod =& $this->pod; 
  1493. $thank_you = pods_query_arg( $vars, self::$allowed, $this->exclusion() ); 
  1494. $thank_you_alt = pods_query_arg( $alt_vars, self::$allowed, $this->exclusion() ); 
  1495. $obj =& $this; 
  1496. $singular_label = $this->item; 
  1497. $plural_label = $this->items; 
  1498.  
  1499. if ( is_object( $this->pod ) && 'settings' == $this->pod->pod_data[ 'type' ] && 'settings' == $this->style ) 
  1500. pods_view( PODS_DIR . 'ui/admin/form-settings.php', compact( array_keys( get_defined_vars() ) ) ); 
  1501. else 
  1502. pods_view( PODS_DIR . 'ui/admin/form.php', compact( array_keys( get_defined_vars() ) ) ); 
  1503.  
  1504. /** 
  1505. * @return bool|mixed 
  1506. * @since 2.3.10 
  1507. */ 
  1508. public function view () { 
  1509.  
  1510. if ( false !== $this->callback_action( 'view' ) ) { 
  1511. return null; 
  1512.  
  1513. if ( empty( $this->row ) ) { 
  1514. $this->get_row(); 
  1515.  
  1516. if ( empty( $this->row ) ) { 
  1517. return $this->error( sprintf( __( '<strong>Error:</strong> %s not found.', 'pods' ), $this->item ) ); 
  1518.  
  1519. $pod =& $this->pod; 
  1520. $obj =& $this; 
  1521.  
  1522. $fields = array(); 
  1523.  
  1524. if ( isset( $this->fields[ $this->action ] ) ) { 
  1525. $fields = $this->fields[ $this->action ]; 
  1526.  
  1527. if ( is_object( $this->pod ) ) { 
  1528. $object_fields = (array) pods_var_raw( 'object_fields', $this->pod->pod_data, array(), null, true ); 
  1529.  
  1530. $object_field_objects = array( 
  1531. 'post_type',  
  1532. 'taxonomy',  
  1533. 'media',  
  1534. 'user',  
  1535. 'comment' 
  1536. ); 
  1537.  
  1538. if ( empty( $object_fields ) && in_array( $this->pod->pod_data[ 'type' ], $object_field_objects ) ) { 
  1539. $object_fields = $this->pod->api->get_wp_object_fields( $this->pod->pod_data[ 'type' ], $this->pod->pod_data ); 
  1540.  
  1541. if ( empty( $fields ) ) { 
  1542. // Add core object fields if $fields is empty 
  1543. $fields = array_merge( $object_fields, $this->pod->fields ); 
  1544.  
  1545. $view_fields = $fields; // Temporary 
  1546.  
  1547. $fields = array(); 
  1548.  
  1549. foreach ( $view_fields as $k => $field ) { 
  1550. $name = $k; 
  1551.  
  1552. $defaults = array( 
  1553. 'name' => $name,  
  1554. 'type' => 'text',  
  1555. 'options' => 'text' 
  1556. ); 
  1557.  
  1558. if ( !is_array( $field ) ) { 
  1559. $name = $field; 
  1560.  
  1561. $field = array( 
  1562. 'name' => $name 
  1563. ); 
  1564.  
  1565. $field = array_merge( $defaults, $field ); 
  1566.  
  1567. $field[ 'name' ] = trim( $field[ 'name' ] ); 
  1568.  
  1569. $value = pods_var_raw( 'default', $field ); 
  1570.  
  1571. if ( empty( $field[ 'name' ] ) ) { 
  1572. $field[ 'name' ] = trim( $name ); 
  1573.  
  1574. if ( isset( $object_fields[ $field[ 'name' ] ] ) ) { 
  1575. $field = array_merge( $field, $object_fields[ $field[ 'name' ] ] ); 
  1576. elseif ( isset( $this->pod->fields[ $field[ 'name' ] ] ) ) { 
  1577. $field = array_merge( $this->pod->fields[ $field[ 'name' ] ], $field ); 
  1578.  
  1579. if ( pods_v( 'hidden', $field, false, null, true ) || 'hidden' == $field[ 'type' ] ) { 
  1580. continue; 
  1581. elseif ( !PodsForm::permission( $field[ 'type' ], $field[ 'name' ], $field[ 'options' ], $fields, $pod, $pod->id() ) ) { 
  1582. continue; 
  1583.  
  1584. $fields[ $field[ 'name' ] ] = $field; 
  1585.  
  1586. if ( empty( $this->id ) && null !== $value ) { 
  1587. $this->pod->row_override[ $field[ 'name' ] ] = $value; 
  1588.  
  1589. unset( $view_fields ); // Cleanup 
  1590. ?> 
  1591. <div class="wrap pods-ui"> 
  1592. <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>><br /></div> 
  1593. <h2> 
  1594. <?php 
  1595. echo $this->do_template( $this->header[ 'view' ] ); 
  1596.  
  1597. if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) { 
  1598. $link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num = '' ), self::$allowed, $this->exclusion() ); 
  1599.  
  1600. if ( !empty( $this->action_links[ 'add' ] ) ) { 
  1601. $link = $this->action_links[ 'add' ]; 
  1602. ?> 
  1603. <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo $this->heading[ 'add' ]; ?></a> 
  1604. <?php 
  1605. elseif ( !in_array( 'manage', $this->actions_disabled ) && !in_array( 'manage', $this->actions_hidden ) ) { 
  1606. $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() ); 
  1607.  
  1608. if ( !empty( $this->action_links[ 'manage' ] ) ) { 
  1609. $link = $this->action_links[ 'manage' ]; 
  1610. ?> 
  1611. <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2">« <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a> 
  1612. <?php 
  1613.  
  1614. pods_view( PODS_DIR . 'ui/admin/view.php', compact( array_keys( get_defined_vars() ) ) ); 
  1615. ?> 
  1616.  
  1617. </h2> 
  1618. </div> 
  1619. <?php 
  1620.  
  1621.  
  1622. /** 
  1623. * Reorder data 
  1624. */ 
  1625. public function reorder () { 
  1626. // loop through order 
  1627. $order = (array) pods_var_raw( 'order', 'post', array(), null, true ); 
  1628.  
  1629. $params = array( 
  1630. 'pod' => $this->pod->pod,  
  1631. 'field' => $this->reorder[ 'on' ],  
  1632. 'order' => $order 
  1633. ); 
  1634.  
  1635. $reorder = pods_api()->reorder_pod_item( $params ); 
  1636.  
  1637. if ( $reorder ) 
  1638. $this->message( sprintf( __( "<strong>Success!</strong> %s reordered successfully.", 'pods' ), $this->items ) ); 
  1639. else 
  1640. $this->error( sprintf( __( "<strong>Error:</strong> %s has not been reordered.", 'pods' ), $this->items ) ); 
  1641.  
  1642. /** 
  1643. * @param bool $insert 
  1644. * @return mixed 
  1645. */ 
  1646. public function save ( $insert = false ) { 
  1647. $this->do_hook( 'pre_save', $insert ); 
  1648.  
  1649. if ( $this->callback( 'save', $insert ) ) { 
  1650. return null; 
  1651.  
  1652. global $wpdb; 
  1653. $action = __( 'saved', 'pods' ); 
  1654. if ( true === $insert ) 
  1655. $action = __( 'created', 'pods' ); 
  1656. $field_sql = array(); 
  1657. $values = array(); 
  1658. $data = array(); 
  1659. foreach ( $this->fields[ 'form' ] as $field => $attributes ) { 
  1660. $vartype = '%s'; 
  1661. if ( 'bool' == $attributes[ 'type' ] ) 
  1662. $selected = ( 1 == pods_var( $field, 'post', 0 ) ) ? 1 : 0; 
  1663. elseif ( '' == pods_var( $field, 'post', '' ) ) 
  1664. continue; 
  1665. if ( false === $attributes[ 'display' ] || false !== $attributes[ 'readonly' ] ) { 
  1666. if ( !in_array( $attributes[ 'type' ], array( 'date', 'time', 'datetime' ) ) ) 
  1667. continue; 
  1668. if ( false === $attributes[ 'date_touch' ] && ( false === $attributes[ 'date_touch_on_create' ] || false === $insert || 0 < $this->id ) ) 
  1669. continue; 
  1670. if ( in_array( $attributes[ 'type' ], array( 'date', 'time', 'datetime' ) ) ) { 
  1671. $format = "Y-m-d H:i:s"; 
  1672. if ( 'date' == $attributes[ 'type' ] ) 
  1673. $format = "Y-m-d"; 
  1674. if ( 'time' == $attributes[ 'type' ] ) 
  1675. $format = "H:i:s"; 
  1676. if ( false !== $attributes[ 'date_touch' ] || ( false !== $attributes[ 'date_touch_on_create' ] && true === $insert && $this->id < 1 ) ) 
  1677. $value = date_i18n( $format ); 
  1678. else 
  1679. $value = date_i18n( $format, strtotime( ( 'time' == $attributes[ 'type' ] ) ? date_i18n( 'Y-m-d ' ) : pods_var( $field, 'post', '' ) ) ); 
  1680. else { 
  1681. if ( 'bool' == $attributes[ 'type' ] ) { 
  1682. $vartype = '%d'; 
  1683. $value = 0; 
  1684. if ( '' != pods_var( $field, 'post', '' ) ) 
  1685. $value = 1; 
  1686. elseif ( 'number' == $attributes[ 'type' ] ) { 
  1687. $vartype = '%d'; 
  1688. $value = number_format( pods_var( $field, 'post', 0 ), 0, '', '' ); 
  1689. elseif ( 'decimal' == $attributes[ 'type' ] ) { 
  1690. $vartype = '%d'; 
  1691. $value = number_format( pods_var( $field, 'post', 0 ), 2, '.', '' ); 
  1692. elseif ( 'related' == $attributes[ 'type' ] ) { 
  1693. if ( is_array( pods_var( $field, 'post', '' ) ) ) 
  1694. $value = implode( ', ', pods_var( $field, 'post', '' ) ); 
  1695. else 
  1696. $value = pods_var( $field, 'post', '' ); 
  1697. else 
  1698. $value = pods_var( $field, 'post', '' ); 
  1699.  
  1700. if ( isset( $attributes[ 'custom_save' ] ) && false !== $attributes[ 'custom_save' ] && is_callable( $attributes[ 'custom_save' ] ) ) 
  1701. $value = call_user_func_array( $attributes[ 'custom_save' ], array( $value, $field, $attributes, &$this ) ); 
  1702.  
  1703. $field_sql[] = "`$field`=$vartype"; 
  1704. $values[] = $value; 
  1705. $data[ $field ] = $value; 
  1706. $field_sql = implode( ', ', $field_sql ); 
  1707. if ( false === $insert && 0 < $this->id ) { 
  1708. $this->insert_id = $this->id; 
  1709. $values[] = $this->id; 
  1710. $check = $wpdb->query( $wpdb->prepare( "UPDATE $this->sql['table'] SET $field_sql WHERE id=%d", $values ) ); 
  1711. else 
  1712. $check = $wpdb->query( $wpdb->prepare( "INSERT INTO $this->sql['table'] SET $field_sql", $values ) ); 
  1713. if ( $check ) { 
  1714. if ( 0 == $this->insert_id ) 
  1715. $this->insert_id = $wpdb->insert_id; 
  1716. $this->message( sprintf( __( "<strong>Success!</strong> %s %s successfully.", 'pods' ), $this->item, $action ) ); 
  1717. else 
  1718. $this->error( sprintf( __( "<strong>Error:</strong> %s has not been %s.", 'pods' ), $this->item, $action ) ); 
  1719. $this->do_hook( 'post_save', $this->insert_id, $data, $insert ); 
  1720.  
  1721. /** 
  1722. * @param null $id 
  1723. * @return bool|mixed 
  1724. */ 
  1725. public function delete ( $id = null ) { 
  1726. $this->do_hook( 'pre_delete', $id ); 
  1727.  
  1728. if ( false !== $this->callback_action( 'delete', $id ) ) { 
  1729. return null; 
  1730.  
  1731. $id = pods_absint( $id ); 
  1732.  
  1733. if ( empty( $id ) ) 
  1734. $id = pods_absint( $this->id ); 
  1735.  
  1736. if ( $id < 1 ) 
  1737. return $this->error( __( '<strong>Error:</strong> Invalid Configuration - Missing "id" definition.', 'pods' ) ); 
  1738.  
  1739. if ( false === $id ) 
  1740. $id = $this->id; 
  1741.  
  1742. if ( is_object( $this->pod ) ) 
  1743. $check = $this->pod->delete( $id ); 
  1744. else 
  1745. $check = $this->pods_data->delete( $this->sql[ 'table' ], array( $this->sql[ 'field_id' ] => $id ) ); 
  1746.  
  1747. if ( $check ) 
  1748. $this->message( sprintf( __( "<strong>Deleted:</strong> %s has been deleted.", 'pods' ), $this->item ) ); 
  1749. else 
  1750. $this->error( sprintf( __( "<strong>Error:</strong> %s has not been deleted.", 'pods' ), $this->item ) ); 
  1751.  
  1752. $this->do_hook( 'post_delete', $id ); 
  1753.  
  1754. /** 
  1755. * @param null $id 
  1756. * @return bool|mixed 
  1757. */ 
  1758. public function delete_bulk () { 
  1759. $this->do_hook( 'pre_delete_bulk' ); 
  1760.  
  1761. if ( 1 != pods_var( 'deleted_bulk', 'get', 0 ) ) { 
  1762. $ids = $this->bulk; 
  1763.  
  1764. $success = false; 
  1765.  
  1766. if ( !empty( $ids ) ) { 
  1767. $ids = (array) $ids; 
  1768.  
  1769. foreach ( $ids as $id ) { 
  1770. $id = pods_absint( $id ); 
  1771.  
  1772. if ( empty( $id ) ) 
  1773. continue; 
  1774.  
  1775. if ( $callback = $this->callback( 'delete', $id ) ) { 
  1776. $check = $callback; 
  1777. elseif ( is_object( $this->pod ) ) 
  1778. $check = $this->pod->delete( $id ); 
  1779. else 
  1780. $check = $this->pods_data->delete( $this->sql[ 'table' ], array( $this->sql[ 'field_id' ] => $id ) ); 
  1781.  
  1782. if ( $check ) 
  1783. $success = true; 
  1784.  
  1785. if ( $success ) 
  1786. pods_redirect( pods_query_arg( array( 'action_bulk' => 'delete', 'deleted_bulk' => 1 ), array( 'page', 'lang', 'action', 'id' ) ) ); 
  1787. else 
  1788. $this->error( sprintf( __( "<strong>Error:</strong> %s has not been deleted.", 'pods' ), $this->item ) ); 
  1789. else { 
  1790. $this->message( sprintf( __( "<strong>Deleted:</strong> %s have been deleted.", 'pods' ), $this->items ) ); 
  1791.  
  1792. unset( $_GET[ 'deleted_bulk' ] ); 
  1793.  
  1794. $this->action_bulk = false; 
  1795. unset( $_GET[ 'action_bulk' ] ); 
  1796.  
  1797. $this->do_hook( 'post_delete_bulk' ); 
  1798.  
  1799. $this->manage(); 
  1800.  
  1801. public function export () { 
  1802. $export_type = pods_var( 'export_type', 'get', 'csv' ); 
  1803.  
  1804. $type = 'sv'; // covers csv + tsv 
  1805.  
  1806. if ( in_array( $export_type, array( 'xml', 'json' ) ) ) 
  1807. $type = $export_type; 
  1808.  
  1809. $delimiter = ', '; 
  1810.  
  1811. if ( 'tsv' == $export_type ) 
  1812. $delimiter = "\t"; 
  1813.  
  1814. $columns = array(); 
  1815.  
  1816. if ( empty( $this->fields[ 'export' ] ) ) { 
  1817. $this->fields[ 'export' ] = $this->pod->fields; 
  1818.  
  1819. $columns = array( 
  1820. $this->pod->pod_data[ 'field_id' ] => 'ID' 
  1821. ); 
  1822.  
  1823. foreach ( $this->fields[ 'export' ] as $field ) { 
  1824. $columns[ $field[ 'name' ] ] = $field[ 'label' ]; 
  1825.  
  1826. $params = array( 
  1827. 'full' => true,  
  1828. 'flatten' => true,  
  1829. 'fields' => array_keys( $columns ),  
  1830. 'type' => $type,  
  1831. 'delimiter' => $delimiter,  
  1832. 'columns' => $columns 
  1833. ); 
  1834.  
  1835. $items = $this->get_data( $params ); 
  1836.  
  1837. $data = array( 
  1838. 'columns' => $columns,  
  1839. 'items' => $items,  
  1840. 'fields' => $this->fields[ 'export' ] 
  1841. ); 
  1842.  
  1843. $migrate = pods_migrate( $type, $delimiter, $data ); 
  1844.  
  1845. $migrate->export(); 
  1846.  
  1847. $export_file = $migrate->save(); 
  1848.  
  1849. $this->message( sprintf( __( '<strong>Success:</strong> Your export is ready, you can download it <a href="%s" target="_blank">here</a>', 'pods' ), $export_file ) ); 
  1850.  
  1851. //echo '<script type="text/javascript">window.open("' . esc_js( $export_file ) . '");</script>'; 
  1852.  
  1853. $this->get_data(); 
  1854.  
  1855. /** 
  1856. * @param $field 
  1857. * @return array|bool|mixed|null 
  1858. */ 
  1859. public function get_field ( $field ) { 
  1860. $value = null; 
  1861.  
  1862. // use PodsData to get field 
  1863.  
  1864. if ( $callback = $this->callback( 'get_field', $field ) ) { 
  1865. return $callback; 
  1866.  
  1867. if ( isset( $this->row[ $field ] ) ) { 
  1868. $value = $this->row[ $field ]; 
  1869. elseif ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) { 
  1870. if ( 'Pod' == get_class( $this->pod ) ) 
  1871. $value = $this->pod->get_field( $field ); 
  1872. else 
  1873. $value = $this->pod->field( $field ); 
  1874.  
  1875. return $this->do_hook( 'get_field', $value, $field ); 
  1876.  
  1877. /** 
  1878. * Get find() params based on current UI action 
  1879. * @param null|array $params 
  1880. * @param null|string $action 
  1881. */ 
  1882. public function get_params( $params = null, $action = null ) { 
  1883.  
  1884. if ( null === $action ) { 
  1885. $action = $this->action; 
  1886.  
  1887. $defaults = array( 
  1888. 'full' => false,  
  1889. 'flatten' => true,  
  1890. 'fields' => null,  
  1891. 'type' => '' 
  1892. ); 
  1893.  
  1894. if ( !empty( $params ) && is_array( $params ) ) 
  1895. $params = (object) array_merge( $defaults, $params ); 
  1896. else 
  1897. $params = (object) $defaults; 
  1898.  
  1899. if ( !in_array( $action, array( 'manage', 'reorder' ) ) ) 
  1900. $action = 'manage'; 
  1901.  
  1902. $params_override = false; 
  1903.  
  1904. $orderby = array(); 
  1905.  
  1906. $limit = $this->limit; 
  1907.  
  1908. $sql = null; 
  1909.  
  1910. if ( 'reorder' == $this->action ) { 
  1911. if ( ! empty( $this->reorder[ 'orderby' ] ) ) { 
  1912. $orderby[ $this->reorder[ 'orderby' ] ] = $this->reorder[ 'orderby_dir' ]; 
  1913. } else { 
  1914. $orderby[ $this->reorder[ 'on' ] ] = $this->reorder[ 'orderby_dir' ]; 
  1915.  
  1916. if ( ! empty( $this->reorder[ 'limit' ] ) ) { 
  1917. $limit = $this->reorder[ 'limit' ]; 
  1918.  
  1919. if ( ! empty( $this->reorder[ 'sql' ] ) ) { 
  1920. $sql = $this->reorder[ 'sql' ]; 
  1921.  
  1922. if ( !empty( $this->orderby ) ) { 
  1923. $this->orderby = (array) $this->orderby; 
  1924.  
  1925. foreach ( $this->orderby as $order ) { 
  1926. if ( false !== strpos( $order, ' ' ) ) { 
  1927. $orderby[] = $order; 
  1928. elseif ( !isset( $orderby[ $order ] ) ) { 
  1929. $orderby[ $order ] = $this->orderby_dir; 
  1930.  
  1931. if ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) { 
  1932. $find_params = array( 
  1933. 'where' => pods_v( $action, $this->where, null, true ),  
  1934. 'orderby' => $orderby,  
  1935. 'page' => (int) $this->page,  
  1936. 'pagination' => true,  
  1937. 'limit' => (int) $limit,  
  1938. 'search' => $this->searchable,  
  1939. 'search_query' => $this->search,  
  1940. 'search_across' => $this->search_across,  
  1941. 'search_across_picks' => $this->search_across_picks,  
  1942. 'filters' => $this->filters,  
  1943. 'sql' => $sql 
  1944. ); 
  1945.  
  1946. $params_override = true; 
  1947. else { 
  1948. $find_params = array( 
  1949. 'table' => $this->sql[ 'table' ],  
  1950. 'id' => $this->sql[ 'field_id' ],  
  1951. 'index' => $this->sql[ 'field_index' ],  
  1952. 'where' => pods_v( $action, $this->where, null, true ),  
  1953. 'orderby' => $orderby,  
  1954. 'page' => (int) $this->page,  
  1955. 'pagination' => true,  
  1956. 'limit' => (int) $limit,  
  1957. 'search' => $this->searchable,  
  1958. 'search_query' => $this->search,  
  1959. 'fields' => $this->fields[ 'search' ],  
  1960. 'sql' => $sql 
  1961. ); 
  1962.  
  1963. if ( ! empty( $this->sql['select'] ) ) { 
  1964. $find_params['select'] = $this->sql['select']; 
  1965.  
  1966. if ( empty( $find_params[ 'where' ] ) && $this->restricted( $this->action ) ) 
  1967. $find_params[ 'where' ] = $this->pods_data->query_fields( $this->restrict[ $this->action ], ( is_object( $this->pod ) ? $this->pod->pod_data : null ) ); 
  1968.  
  1969. if ( $params_override ) { 
  1970. $find_params = array_merge( $find_params, (array) $this->params ); 
  1971.  
  1972. if ( $params->full ) 
  1973. $find_params[ 'limit' ] = -1; 
  1974.  
  1975. // Debug purposes 
  1976. if ( 1 == pods_v( 'pods_debug_params', 'get', 0 ) && pods_is_admin( array( 'pods' ) ) ) 
  1977. pods_debug( $find_params ); 
  1978.  
  1979. return $find_params; 
  1980.  
  1981. /** 
  1982. * @param bool $full Whether to get ALL data or use pagination 
  1983. * @return bool 
  1984. */ 
  1985. public function get_data ( $params = null ) { 
  1986. $action = $this->action; 
  1987.  
  1988. $defaults = array( 
  1989. 'full' => false,  
  1990. 'flatten' => true,  
  1991. 'fields' => null,  
  1992. 'type' => '' 
  1993. ); 
  1994.  
  1995. if ( !empty( $params ) && is_array( $params ) ) 
  1996. $params = (object) array_merge( $defaults, $params ); 
  1997. else 
  1998. $params = (object) $defaults; 
  1999.  
  2000. if ( !in_array( $action, array( 'manage', 'reorder' ) ) ) 
  2001. $action = 'manage'; 
  2002.  
  2003. $find_params = $this->get_params( $params ); 
  2004.  
  2005. if ( false !== $this->pod && is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) { 
  2006. $this->pod->find( $find_params ); 
  2007.  
  2008. if ( !$params->full ) { 
  2009. $data = $this->pod->data(); 
  2010.  
  2011. $this->data = $data; 
  2012.  
  2013. if ( !empty( $this->data ) ) { 
  2014. $this->data_keys = array_keys( $this->data ); 
  2015.  
  2016. $this->total = $this->pod->total(); 
  2017. $this->total_found = $this->pod->total_found(); 
  2018. else { 
  2019. $this->data_full = array(); 
  2020.  
  2021. $export_params = array( 
  2022. 'fields' => $params->fields,  
  2023. 'flatten' => true 
  2024. ); 
  2025.  
  2026. if ( in_array( $params->type, array( 'json', 'xml' ) ) ) 
  2027. $export_params[ 'flatten' ] = false; 
  2028.  
  2029. $export_params = $this->do_hook( 'export_options', $export_params, $params ); 
  2030.  
  2031. while ( $this->pod->fetch() ) { 
  2032. $this->data_full[ $this->pod->id() ] = $this->pod->export( $export_params ); 
  2033.  
  2034. $this->pod->reset(); 
  2035.  
  2036. return $this->data_full; 
  2037. else { 
  2038. if ( !empty( $this->data ) ) 
  2039. return $this->data; 
  2040.  
  2041. if ( empty( $this->sql[ 'table' ] ) ) 
  2042. return $this->data; 
  2043.  
  2044. $this->pods_data->select( $find_params ); 
  2045.  
  2046. if ( !$params->full ) { 
  2047. $this->data = $this->pods_data->data; 
  2048.  
  2049. if ( !empty( $this->data ) ) { 
  2050. $this->data_keys = array_keys( $this->data ); 
  2051.  
  2052. $this->total = $this->pods_data->total(); 
  2053. $this->total_found = $this->pods_data->total_found(); 
  2054. else { 
  2055. $this->data_full = $this->pods_data->data; 
  2056.  
  2057. if ( !empty( $this->data_full ) ) { 
  2058. $this->data_keys = array_keys( $this->data_full ); 
  2059.  
  2060. return $this->data_full; 
  2061.  
  2062. return $this->data; 
  2063.  
  2064. /** 
  2065. * Sort out data alphabetically by a key 
  2066. */ 
  2067. public function sort_data () { 
  2068. // only do this if we have a default orderby 
  2069. if ( isset( $this->orderby[ 'default' ] ) ) { 
  2070. $orderby = $this->orderby[ 'default' ]; 
  2071. foreach ( $this->data as $k => $v ) { 
  2072. $sorter[ $k ] = strtolower( $v[ $orderby ] ); 
  2073. if ( $this->orderby_dir == 'ASC' ) 
  2074. asort( $sorter ); 
  2075. else 
  2076. arsort( $sorter ); 
  2077. foreach ( $sorter as $key => $val ) { 
  2078. $intermediary[] = $this->data[ $key ]; 
  2079. if ( isset( $intermediary ) ) { 
  2080. $this->data = $intermediary; 
  2081. $this->data_keys = array_keys( $this->data ); 
  2082.  
  2083. /** 
  2084. * @return array 
  2085. */ 
  2086. public function get_row ( &$counter = 0, $method = null ) { 
  2087. if ( !empty( $this->row ) && 0 < (int) $this->id && 'table' != $method ) 
  2088. return $this->row; 
  2089.  
  2090. if ( is_object( $this->pod ) && ( 'Pods' == get_class( $this->pod ) || 'Pod' == get_class( $this->pod ) ) ) 
  2091. $this->row = $this->pod->fetch(); 
  2092. else { 
  2093. $this->row = false; 
  2094.  
  2095. if ( !empty( $this->data ) ) { 
  2096. if ( empty( $this->data_keys ) || count( $this->data ) != count( $this->data_keys ) ) { 
  2097. $this->data_keys = array_keys( $this->data ); 
  2098.  
  2099. if ( count( $this->data ) == $this->total && isset( $this->data_keys[ $counter ] ) && isset( $this->data[ $this->data_keys[ $counter ] ] ) ) { 
  2100. $this->row = $this->data[ $this->data_keys[ $counter ] ]; 
  2101.  
  2102. $counter++; 
  2103.  
  2104. if ( false === $this->row && 0 < (int) $this->id && !empty( $this->sql[ 'table' ] ) ) { 
  2105. $this->pods_data->select( 
  2106. array( 
  2107. 'table' => $this->sql[ 'table' ],  
  2108. 'where' => '`' . $this->sql[ 'field_id' ] . '` = ' . (int) $this->id,  
  2109. 'limit' => 1 
  2110. ); 
  2111.  
  2112. $this->row = $this->pods_data->fetch(); 
  2113.  
  2114. return $this->row; 
  2115.  
  2116. /** 
  2117. * @param bool $reorder 
  2118. * @return mixed|null 
  2119. */ 
  2120. public function manage ( $reorder = false ) { 
  2121. if ( false !== $this->callback_action( 'manage', $reorder ) ) { 
  2122. return null; 
  2123.  
  2124. if ( !empty( $this->action_bulk ) && !empty( $this->actions_bulk ) && isset( $this->actions_bulk[ $this->action_bulk ] ) && !in_array( $this->action_bulk, $this->actions_disabled ) && !empty( $this->bulk ) ) { 
  2125. if ( empty( $_REQUEST[ '_wpnonce' . $this->num ] ) || false === wp_verify_nonce( $_REQUEST[ '_wpnonce' . $this->num ], 'pods-ui-action-bulk' ) ) { 
  2126. pods_message( __( 'Invalid bulk request, please try again.', 'pods' ) ); 
  2127. elseif ( false !== $this->callback_bulk( $this->action_bulk, $this->bulk ) ) { 
  2128. return null; 
  2129. elseif ( 'delete' == $this->action_bulk ) { 
  2130. return $this->delete_bulk(); 
  2131.  
  2132. $this->screen_meta(); 
  2133.  
  2134. if ( true === $reorder ) 
  2135. wp_enqueue_script( 'jquery-ui-sortable' ); 
  2136. ?> 
  2137. <div class="wrap pods-admin pods-ui"> 
  2138. <div id="icon-edit-pages" class="icon32"<?php if ( false !== $this->icon ) { ?> style="background-position:0 0;background-size:100%;background-image:url(<?php echo esc_url( $this->icon ); ?>);"<?php } ?>><br /></div> 
  2139. <h2> 
  2140. <?php 
  2141. if ( true === $reorder ) { 
  2142. echo $this->header[ 'reorder' ]; 
  2143.  
  2144. $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() ); 
  2145.  
  2146. if ( !empty( $this->action_links[ 'manage' ] ) ) 
  2147. $link = $this->action_links[ 'manage' ]; 
  2148. ?> 
  2149. <small>(<a href="<?php echo esc_url( $link ); ?>">« <?php echo sprintf( __( 'Back to %s', 'pods' ), $this->heading[ 'manage' ] ); ?></a>)</small> 
  2150. <?php 
  2151. else 
  2152. echo $this->header[ 'manage' ]; 
  2153.  
  2154. if ( !in_array( 'add', $this->actions_disabled ) && !in_array( 'add', $this->actions_hidden ) ) { 
  2155. $link = pods_query_arg( array( 'action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num => '' ), self::$allowed, $this->exclusion() ); 
  2156.  
  2157. if ( !empty( $this->action_links[ 'add' ] ) ) 
  2158. $link = $this->action_links[ 'add' ]; 
  2159. ?> 
  2160. <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo $this->label[ 'add_new' ]; ?></a> 
  2161. <?php 
  2162. if ( !in_array( 'reorder', $this->actions_disabled ) && !in_array( 'reorder', $this->actions_hidden ) && false !== $this->reorder[ 'on' ] ) { 
  2163. $link = pods_query_arg( array( 'action' . $this->num => 'reorder' ), self::$allowed, $this->exclusion() ); 
  2164.  
  2165. if ( !empty( $this->action_links[ 'reorder' ] ) ) 
  2166. $link = $this->action_links[ 'reorder' ]; 
  2167. ?> 
  2168. <a href="<?php echo esc_url( $link ); ?>" class="add-new-h2"><?php echo $this->label[ 'reorder' ]; ?></a> 
  2169. <?php 
  2170. ?> 
  2171. </h2> 
  2172.  
  2173. <form id="posts-filter" action="" method="get"> 
  2174. <?php 
  2175. $excluded_filters = array( 
  2176. 'search' . $this->num,  
  2177. 'pg' . $this->num,  
  2178. 'action' . $this->num,  
  2179. 'action_bulk' . $this->num,  
  2180. 'action_bulk_ids' . $this->num,  
  2181. '_wpnonce' . $this->num 
  2182. ); 
  2183.  
  2184. $filters = $this->filters; 
  2185.  
  2186. foreach ( $filters as $k => $filter ) { 
  2187. if ( isset( $this->pod->fields[ $filter ] ) ) { 
  2188. $filter_field = $this->pod->fields[ $filter ]; 
  2189. elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) { 
  2190. $filter_field = $this->fields[ 'manage' ][ $filter ]; 
  2191. else { 
  2192. unset( $filters[ $k ] ); 
  2193. continue; 
  2194.  
  2195. if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) { 
  2196. if ( '' == pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ) && '' == pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ) ) { 
  2197. unset( $filters[ $k ] ); 
  2198. continue; 
  2199. elseif ( '' === pods_var_raw( 'filter_' . $filter, 'get', '' ) ) { 
  2200. unset( $filters[ $k ] ); 
  2201. continue; 
  2202.  
  2203. $excluded_filters[] = 'filter_' . $filter . '_start'; 
  2204. $excluded_filters[] = 'filter_' . $filter . '_end'; 
  2205. $excluded_filters[] = 'filter_' . $filter; 
  2206.  
  2207. $get = $_GET; 
  2208.  
  2209. foreach ( $get as $k => $v ) { 
  2210. if ( is_array( $v ) || in_array( $k, $excluded_filters ) || strlen( $v ) < 1 ) 
  2211. continue; 
  2212. ?> 
  2213. <input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" /> 
  2214. <?php 
  2215.  
  2216. if ( false !== $this->callback( 'header', $reorder ) ) { 
  2217. return null; 
  2218.  
  2219. if ( false === $this->data ) 
  2220. $this->get_data(); 
  2221. elseif ( $this->sortable ) // we have the data already as an array 
  2222. $this->sort_data(); 
  2223.  
  2224. if ( !in_array( 'export', $this->actions_disabled ) && 'export' == $this->action ) 
  2225. $this->export(); 
  2226.  
  2227. if ( ( !empty( $this->data ) || false !== $this->search || ( $this->filters_enhanced && !empty( $this->views ) ) ) && ( ( $this->filters_enhanced && !empty( $this->views ) ) || false !== $this->searchable ) ) { 
  2228. if ( $this->filters_enhanced ) 
  2229. $this->filters(); 
  2230. else { 
  2231. ?> 
  2232. <p class="search-box" align="right"> 
  2233. <?php 
  2234. $excluded_filters = array( 'search' . $this->num, 'pg' . $this->num ); 
  2235.  
  2236. foreach ( $this->filters as $filter ) { 
  2237. $excluded_filters[] = 'filter_' . $filter . '_start'; 
  2238. $excluded_filters[] = 'filter_' . $filter . '_end'; 
  2239. $excluded_filters[] = 'filter_' . $filter; 
  2240.  
  2241. $this->hidden_vars( $excluded_filters ); 
  2242.  
  2243. foreach ( $this->filters as $filter ) { 
  2244. if ( isset( $this->pod->fields[ $filter ] ) ) { 
  2245. $filter_field = $this->pod->fields[ $filter ]; 
  2246. elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) { 
  2247. $filter_field = $this->fields[ 'manage' ][ $filter ]; 
  2248. else { 
  2249. continue; 
  2250.  
  2251. if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) { 
  2252. $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $filter_field, '', null, true ), null, true ); 
  2253. $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $filter_field, '', null, true ), null, true ); 
  2254.  
  2255. // override default value 
  2256. $filter_field[ 'options' ][ 'default_value' ] = ''; 
  2257. $filter_field[ 'options' ][ $filter_field[ 'type' ] . '_allow_empty' ] = 1; 
  2258.  
  2259.  
  2260. if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) 
  2261. $start = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $start, 'n/j/Y' ); 
  2262.  
  2263. if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) 
  2264. $end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' ); 
  2265. ?> 
  2266. <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_start"> 
  2267. <?php echo $filter_field[ 'label' ]; ?> 
  2268. </label> 
  2269. <?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field[ 'type' ], $filter_field ); ?> 
  2270.  
  2271. <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_end"> 
  2272. to 
  2273. </label> 
  2274. <?php 
  2275. echo PodsForm::field( 'filter_' . $filter . '_end', $end, $filter_field[ 'type' ], $filter_field ); 
  2276. elseif ( 'pick' == $filter_field[ 'type' ] ) { 
  2277. $value = pods_var_raw( 'filter_' . $filter, 'get' ); 
  2278.  
  2279. if ( strlen( $value ) < 1 ) 
  2280. $value = pods_var_raw( 'filter_default', $filter_field ); 
  2281.  
  2282. // override default value 
  2283. $filter_field[ 'options' ][ 'default_value' ] = ''; 
  2284.  
  2285. $filter_field[ 'options' ][ 'pick_format_type' ] = 'single'; 
  2286. $filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown'; 
  2287.  
  2288. $filter_field[ '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 ); 
  2289. $filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true ); 
  2290.  
  2291. $options = array_merge( $filter_field, $filter_field[ 'options' ] ); 
  2292. ?> 
  2293. <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>"> 
  2294. <?php echo $filter_field[ 'label' ]; ?> 
  2295. </label> 
  2296. <?php 
  2297. echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); 
  2298. elseif ( 'boolean' == $filter_field[ 'type' ] ) { 
  2299. $value = pods_var_raw( 'filter_' . $filter, 'get', '' ); 
  2300.  
  2301. if ( strlen( $value ) < 1 ) 
  2302. $value = pods_var_raw( 'filter_default', $filter_field ); 
  2303.  
  2304. // override default value 
  2305. $filter_field[ 'options' ][ 'default_value' ] = ''; 
  2306.  
  2307. $filter_field[ 'options' ][ 'pick_format_type' ] = 'single'; 
  2308. $filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown'; 
  2309.  
  2310. $filter_field[ 'options' ][ 'pick_object' ] = 'custom-simple'; 
  2311. $filter_field[ 'options' ][ 'pick_custom' ] = array( 
  2312. '1' => pods_var_raw( 'boolean_yes_label', $filter_field[ 'options' ], __( 'Yes', 'pods' ), null, true ),  
  2313. '0' => pods_var_raw( 'boolean_no_label', $filter_field[ 'options' ], __( 'No', 'pods' ), null, true ) 
  2314. ); 
  2315.  
  2316. $filter_field[ '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 ); 
  2317. $filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true ); 
  2318.  
  2319. $options = array_merge( $filter_field, $filter_field[ 'options' ] ); 
  2320. ?> 
  2321. <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>"> 
  2322. <?php echo $filter_field[ 'label' ]; ?> 
  2323. </label> 
  2324. <?php 
  2325. echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); 
  2326. else { 
  2327. $value = pods_var_raw( 'filter_' . $filter, 'get' ); 
  2328.  
  2329. if ( strlen( $value ) < 1 ) 
  2330. $value = pods_var_raw( 'filter_default', $filter_field ); 
  2331.  
  2332. // override default value 
  2333. $filter_field[ 'options' ][ 'default_value' ] = ''; 
  2334.  
  2335. $options = array(); 
  2336. $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 ); 
  2337. $options[ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $options, $options[ 'input_helper' ], null, true ); 
  2338. ?> 
  2339. <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>"> 
  2340. <?php echo $filter_field[ 'label' ]; ?> 
  2341. </label> 
  2342. <?php 
  2343. echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options ); 
  2344.  
  2345. if ( false !== $this->do_hook( 'filters_show_search', true ) ) { 
  2346. ?> 
  2347.    <label<?php echo ( empty( $this->filters ) ) ? ' class="screen-reader-text"' : ''; ?> for="page-search<?php echo esc_attr( $this->num ); ?>-input"><?php _e( 'Search', 'pods' ); ?>:</label> 
  2348. <?php echo PodsForm::field( 'search' . $this->num, $this->search, 'text', array( 'attributes' => array( 'id' => 'page-search' . $this->num . '-input' ) ) ); ?> 
  2349. <?php 
  2350. else { 
  2351. echo PodsForm::field( 'search' . $this->num, '', 'hidden' ); 
  2352. ?> 
  2353. <?php echo PodsForm::submit_button( $this->header[ 'search' ], 'button', false, false, array('id' => 'search' . $this->num . '-submit') ); ?> 
  2354. <?php 
  2355. if ( 0 < strlen( $this->search ) ) { 
  2356. $clear_filters = array( 
  2357. 'search' . $this->num => false 
  2358. ); 
  2359.  
  2360. foreach ( $this->filters as $filter ) { 
  2361. $clear_filters[ 'filter_' . $filter . '_start' ] = false; 
  2362. $clear_filters[ 'filter_' . $filter . '_end' ] = false; 
  2363. $clear_filters[ 'filter_' . $filter ] = false; 
  2364. ?> 
  2365. <br class="clear" /> 
  2366. <small>[<a href="<?php echo esc_url( pods_query_arg( $clear_filters, array( 'orderby' . $this->num, 'orderby_dir' . $this->num, 'limit' . $this->num, 'page' ), $this->exclusion() ) ); ?>"><?php _e( 'Reset Filters', 'pods' ); ?></a>]</small> 
  2367. <br class="clear" /> 
  2368. <?php 
  2369. ?> 
  2370. </p> 
  2371. <?php 
  2372. else { 
  2373. ?> 
  2374. <br class="clear" /> 
  2375. <?php 
  2376.  
  2377. 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 ) ) { 
  2378. ?> 
  2379. <div class="tablenav"> 
  2380. <?php 
  2381. if ( !empty( $this->data ) && !empty( $this->actions_bulk ) ) { 
  2382. ?> 
  2383. <div class="alignleft actions"> 
  2384. <?php wp_nonce_field( 'pods-ui-action-bulk', '_wpnonce' . $this->num, false ); ?> 
  2385.  
  2386. <select name="action_bulk<?php echo esc_attr( $this->num ); ?>"> 
  2387. <option value="-1" selected="selected"><?php _e( 'Bulk Actions', 'pods' ); ?></option> 
  2388.  
  2389. <?php 
  2390. foreach ( $this->actions_bulk as $action => $action_data ) { 
  2391. if ( in_array( $action, $this->actions_hidden ) || in_array( $action, $this->actions_hidden ) ) 
  2392. continue; 
  2393.  
  2394. if ( !isset( $action_data[ 'label' ] ) ) 
  2395. $action_data[ 'label' ] = ucwords( str_replace( '_', ' ', $action ) ); 
  2396. ?> 
  2397. <option value="<?php echo esc_attr( $action ); ?>"><?php echo esc_html( $action_data[ 'label' ] ); ?></option> 
  2398. <?php 
  2399. ?> 
  2400. </select> 
  2401.  
  2402. <input type="submit" id="doaction_bulk<?php echo esc_attr( $this->num ); ?>" class="button-secondary action" value="<?php esc_attr_e( 'Apply', 'pods' ); ?>"> 
  2403. </div> 
  2404. <?php 
  2405.  
  2406. if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) { 
  2407. ?> 
  2408. <div class="tablenav-pages<?php echo esc_attr( ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page' ); ?>"> 
  2409. <?php $this->pagination( 1 ); ?> 
  2410. </div> 
  2411. <?php 
  2412.  
  2413. if ( true === $reorder ) { 
  2414. $link = pods_query_arg( array( 'action' . $this->num => 'manage', 'id' . $this->num => '' ), self::$allowed, $this->exclusion() ); 
  2415.  
  2416. if ( !empty( $this->action_links[ 'manage' ] ) ) { 
  2417. $link = $this->action_links[ 'manage' ]; 
  2418. ?> 
  2419. <input type="button" value="<?php esc_attr_e( 'Update Order', 'pods' ); ?>" class="button" onclick="jQuery('form.admin_ui_reorder_form').submit();" /> 
  2420. <input type="button" value="<?php esc_attr_e( 'Cancel', 'pods' ); ?>" class="button" onclick="document.location='<?php echo esc_js( $link ); ?>';" /> 
  2421. </form> 
  2422. <?php 
  2423. elseif ( !in_array( 'export', $this->actions_disabled ) && !in_array( 'export', $this->actions_hidden ) ) { 
  2424. ?> 
  2425. <div class="alignleft actions"> 
  2426. <strong><?php _e( 'Export', 'pods' ); ?>:</strong> 
  2427. <?php 
  2428. foreach ( $this->export[ 'formats' ] as $format => $separator ) { 
  2429. ?> 
  2430. <input type="button" value=" <?php echo esc_attr( strtoupper( $format ) ); ?> " class="button" onclick="document.location='<?php echo pods_slash( pods_query_arg( array( 'action' . $this->num => 'export', 'export_type' . $this->num => $format, '_wpnonce' => wp_create_nonce( 'pods-ui-action-export' ) ), self::$allowed, $this->exclusion() ) ); ?>';" /> 
  2431. <?php 
  2432. ?> 
  2433. </div> 
  2434. <?php 
  2435. ?> 
  2436. <br class="clear" /> 
  2437. </div> 
  2438. <?php 
  2439. else { 
  2440. ?> 
  2441. <br class="clear" /> 
  2442. <?php 
  2443. ?> 
  2444. <div class="clear"></div> 
  2445. <?php 
  2446. if ( empty( $this->data ) && false !== $this->default_none && false === $this->search ) { 
  2447. ?> 
  2448. <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> 
  2449. <?php 
  2450. else 
  2451. $this->table( $reorder ); 
  2452. if ( !empty( $this->data ) ) { 
  2453. if ( true !== $reorder && ( false !== $this->pagination_total || false !== $this->pagination ) ) { 
  2454. ?> 
  2455. <div class="tablenav"> 
  2456. <div class="tablenav-pages<?php echo esc_attr( ( $this->limit < $this->total_found || 1 < $this->page ) ? '' : ' one-page' ); ?>"> 
  2457. <?php $this->pagination( 0 ); ?> 
  2458. <br class="clear" /> 
  2459. </div> 
  2460. </div> 
  2461. <?php 
  2462.  
  2463. ?> 
  2464. </form> 
  2465. </div> 
  2466. <?php 
  2467. if ( $this->filters_enhanced ) 
  2468. $this->filters_popup(); 
  2469.  
  2470. public function filters () { 
  2471. include_once ABSPATH . 'wp-admin/includes/template.php'; 
  2472.  
  2473. wp_enqueue_script( 'thickbox' ); 
  2474. wp_enqueue_style( 'pods-ui-list-table', PODS_URL . 'ui/css/pods-ui-list-table.css', array( 'thickbox' ), PODS_VERSION ); 
  2475.  
  2476. $filters = $this->filters; 
  2477.  
  2478. foreach ( $filters as $k => $filter ) { 
  2479. if ( isset( $this->pod->fields[ $filter ] ) ) { 
  2480. $filter_field = $this->pod->fields[ $filter ]; 
  2481. elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) { 
  2482. $filter_field = $this->fields[ 'manage' ][ $filter ]; 
  2483. else { 
  2484. continue; 
  2485.  
  2486. if ( isset( $filter_field ) && in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) { 
  2487. if ( '' == pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ) && '' == pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ) ) 
  2488. unset( $filters[ $k ] ); 
  2489. elseif ( '' === pods_var_raw( 'filter_' . $filter, 'get', '' ) ) 
  2490. unset( $filters[ $k ] ); 
  2491.  
  2492. $filtered = false; 
  2493.  
  2494. if ( !empty( $filters ) ) 
  2495. $filtered = true; 
  2496. ?> 
  2497. <div class="pods-ui-filter-bar"> 
  2498. <div class="pods-ui-filter-bar-primary"> 
  2499. <?php 
  2500. if ( !empty( $this->views ) ) { 
  2501. ?> 
  2502. <ul class="subsubsub"> 
  2503. <li class="pods-ui-filter-view-label"><strong><?php echo $this->heading[ 'views' ]; ?></strong></li> 
  2504.  
  2505. <?php 
  2506. foreach ( $this->views as $view => $label ) { 
  2507. if ( false === strpos( $label, '<a' ) ) { 
  2508. $link = pods_query_arg( array( 'view' . $this->num => $view, 'pg' . $this->num => '' ), self::$allowed, $this->exclusion() ); 
  2509.  
  2510. if ( $this->view == $view ) 
  2511. $label = '<a href="' . esc_url( $link ) . '" class="current">' . $label . '</a>'; 
  2512. else 
  2513. $label = '<a href="' . esc_url( $link ) . '">' . $label . '</a>'; 
  2514. ?> 
  2515. <li class="<?php echo esc_attr( $view ); ?>"><?php echo $label; ?></li> 
  2516. <?php 
  2517. ?> 
  2518. </ul> 
  2519. <?php 
  2520. ?> 
  2521.  
  2522. <?php 
  2523. if ( false !== $this->search && false !== $this->searchable ) { 
  2524. ?> 
  2525. <p class="search-box"> 
  2526. <?php 
  2527. if ( $filtered || '' != pods_var_raw( 'search' . $this->num, 'get', '', null, true ) ) { 
  2528. $clear_filters = array( 
  2529. 'search' . $this->num => false 
  2530. ); 
  2531.  
  2532. foreach ( $this->filters as $filter ) { 
  2533. $clear_filters[ 'filter_' . $filter . '_start' ] = false; 
  2534. $clear_filters[ 'filter_' . $filter . '_end' ] = false; 
  2535. $clear_filters[ 'filter_' . $filter ] = false; 
  2536. ?> 
  2537. <a href="<?php echo esc_url( pods_query_arg( $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> 
  2538. <?php 
  2539.  
  2540. if ( false !== $this->do_hook( 'filters_show_search', true ) ) { 
  2541. ?> 
  2542.    <label class="screen-reader-text" for="page-search<?php echo esc_attr( $this->num ); ?>-input"><?php _e( 'Search', 'pods' ); ?>:</label> 
  2543. <?php echo PodsForm::field( 'search' . $this->num, $this->search, 'text', array( 'attributes' => array( 'id' => 'page-search' . $this->num . '-input' ) ) ); ?> 
  2544. <?php 
  2545. else { 
  2546. echo PodsForm::field( 'search' . $this->num, '', 'hidden' ); 
  2547. ?> 
  2548.  
  2549. <?php echo PodsForm::submit_button( $this->header[ 'search' ], 'button', false, false, array('id' => 'search' . $this->num . '-submit') ); ?> 
  2550. </p> 
  2551. <?php 
  2552. ?> 
  2553. </div> 
  2554.  
  2555. <?php 
  2556. if ( !empty( $this->filters ) ) { 
  2557. ?> 
  2558. <div class="pods-ui-filter-bar-secondary"> 
  2559. <ul class="subsubsub"> 
  2560. <?php 
  2561. if ( !$filtered ) { 
  2562. ?> 
  2563. <li class="pods-ui-filter-bar-add-filter"> 
  2564. <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>"> 
  2565. <?php _e( 'Advanced Filters', 'pods' ); ?> 
  2566. </a> 
  2567. </li> 
  2568. <?php 
  2569. else { 
  2570. ?> 
  2571. <li class="pods-ui-filter-bar-add-filter"> 
  2572. <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>"> 
  2573. + <?php _e( 'Add Filter', 'pods' ); ?> 
  2574. </a> 
  2575. </li> 
  2576. <?php 
  2577.  
  2578. foreach ( $filters as $filter ) { 
  2579. $value = pods_var_raw( 'filter_' . $filter, 'get' ); 
  2580.  
  2581. if ( isset( $this->pod->fields[ $filter ] ) ) { 
  2582. $filter_field = $this->pod->fields[ $filter ]; 
  2583. elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) { 
  2584. $filter_field = $this->fields[ 'manage' ][ $filter ]; 
  2585. else { 
  2586. continue; 
  2587.  
  2588. $data_filter = 'filter_' . $filter; 
  2589.  
  2590. $start = $end = $value_label = ''; 
  2591.  
  2592. if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) { 
  2593. $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', '', null, true ); 
  2594. $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', '', null, true ); 
  2595.  
  2596. if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) 
  2597. $start = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $start, 'n/j/Y' ); 
  2598.  
  2599. if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) 
  2600. $end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' ); 
  2601.  
  2602. $value = trim( $start . ' - ' . $end, ' -' ); 
  2603.  
  2604. $data_filter = 'filter_' . $filter . '_start'; 
  2605. elseif ( 'pick' == $filter_field[ 'type' ] ) 
  2606. $value_label = trim( PodsForm::field_method( 'pick', 'value_to_label', $filter, $value, $filter_field, $this->pod->pod_data, null ) ); 
  2607. elseif ( 'boolean' == $filter_field[ 'type' ] ) { 
  2608. $yesno_options = array( 
  2609. '1' => pods_var_raw( 'boolean_yes_label', $filter_field[ 'options' ], __( 'Yes', 'pods' ), null, true ),  
  2610. '0' => pods_var_raw( 'boolean_no_label', $filter_field[ 'options' ], __( 'No', 'pods' ), null, true ) 
  2611. ); 
  2612.  
  2613. if ( isset( $yesno_options[ (string) $value ] ) ) 
  2614. $value_label = $yesno_options[ (string) $value ]; 
  2615.  
  2616. if ( strlen( $value_label ) < 1 ) 
  2617. $value_label = $value; 
  2618. ?> 
  2619. <li class="pods-ui-filter-bar-filter" data-filter="<?php echo esc_attr( $data_filter ); ?>"> 
  2620. <a href="#TB_inline?width=640&inlineId=pods-ui-posts-filter-popup" class="thickbox" title="<?php esc_attr_e( 'Advanced Filters', 'pods' ); ?>"> 
  2621. <strong><?php echo $filter_field[ 'label' ]; ?>:</strong> 
  2622. <?php echo esc_html( $value_label ); ?> 
  2623. </a> 
  2624.  
  2625. <a href="#remove-filter" class="remove-filter" title="<?php esc_attr_e( 'Remove Filter', 'pods' ); ?>">x</a> 
  2626.  
  2627. <?php 
  2628. if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) { 
  2629. echo PodsForm::field( 'filter_' . $filter . '_start', $start, 'hidden' ); 
  2630. echo PodsForm::field( 'filter_' . $filter . '_end', $end, 'hidden' ); 
  2631. else 
  2632. echo PodsForm::field( $data_filter, $value, 'hidden' ); 
  2633. ?> 
  2634. </li> 
  2635. <?php 
  2636. ?> 
  2637. </ul> 
  2638. </div> 
  2639. <?php 
  2640. ?> 
  2641. </div> 
  2642.  
  2643. <script type="text/javascript"> 
  2644. jQuery( function() { 
  2645. jQuery( '.pods-ui-filter-bar-secondary' ).on( 'click', '.remove-filter', function ( e ) { 
  2646. jQuery( '.pods-ui-filter-popup #' + jQuery( this ).parent().data( 'filter' ) ).remove(); 
  2647.  
  2648. jQuery( this ).parent().find( 'input' ).each( function () { 
  2649. jQuery( this ).remove(); 
  2650. } ); 
  2651.  
  2652. jQuery( 'form#posts-filter [name="pg<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true ); 
  2653. jQuery( 'form#posts-filter [name="action<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true ); 
  2654. jQuery( 'form#posts-filter [name="action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true ); 
  2655. jQuery( 'form#posts-filter [name="_wpnonce<?php echo esc_attr( $this->num ); ?>"]' ).prop( 'disabled', true ); 
  2656.  
  2657. jQuery( 'form#posts-filter' ).submit(); 
  2658.  
  2659. e.preventDefault(); 
  2660. } ); 
  2661. } ); 
  2662. </script> 
  2663. <?php 
  2664.  
  2665. public function filters_popup () { 
  2666. $filters = $this->filters; 
  2667. ?> 
  2668. <div id="pods-ui-posts-filter-popup" class="hidden"> 
  2669. <form action="" method="get" class="pods-ui-posts-filter-popup"> 
  2670. <h2><?php _e( 'Advanced Filters', 'pods' ); ?></h2> 
  2671.  
  2672. <div class="pods-ui-posts-filters"> 
  2673. <?php 
  2674. $excluded_filters = array( 
  2675. 'search' . $this->num,  
  2676. 'pg' . $this->num,  
  2677. 'action' . $this->num,  
  2678. 'action_bulk' . $this->num,  
  2679. 'action_bulk_ids' . $this->num,  
  2680. '_wpnonce' . $this->num 
  2681. ); 
  2682.  
  2683. foreach ( $filters as $filter ) { 
  2684. $excluded_filters[] = 'filters_relation'; 
  2685. $excluded_filters[] = 'filters_compare_' . $filter; 
  2686. $excluded_filters[] = 'filter_' . $filter . '_start'; 
  2687. $excluded_filters[] = 'filter_' . $filter . '_end'; 
  2688. $excluded_filters[] = 'filter_' . $filter; 
  2689.  
  2690. $get = $_GET; 
  2691.  
  2692. foreach ( $get as $k => $v ) { 
  2693. if ( in_array( $k, $excluded_filters ) || strlen( $v ) < 1 ) 
  2694. continue; 
  2695. ?> 
  2696. <input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" /> 
  2697. <?php 
  2698.  
  2699. $zebra = true; 
  2700.  
  2701. foreach ( $filters as $filter ) { 
  2702. if ( empty( $filter ) ) 
  2703. continue; 
  2704.  
  2705. if ( isset( $this->pod->fields[ $filter ] ) ) { 
  2706. $filter_field = $this->pod->fields[ $filter ]; 
  2707. elseif ( isset( $this->fields[ 'manage' ][ $filter ] ) ) { 
  2708. $filter_field = $this->fields[ 'manage' ][ $filter ]; 
  2709. else { 
  2710. continue; 
  2711. ?> 
  2712. <p class="pods-ui-posts-filter-toggled pods-ui-posts-filter-<?php echo esc_attr( $filter . ( $zebra ? ' clear' : '' ) ); ?>"> 
  2713. <?php 
  2714. if ( in_array( $filter_field[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) { 
  2715. $start = pods_var_raw( 'filter_' . $filter . '_start', 'get', pods_var_raw( 'filter_default', $filter_field, '', null, true ), null, true ); 
  2716. $end = pods_var_raw( 'filter_' . $filter . '_end', 'get', pods_var_raw( 'filter_ongoing_default', $filter_field, '', null, true ), null, true ); 
  2717.  
  2718. // override default value 
  2719. $filter_field[ 'options' ][ 'default_value' ] = ''; 
  2720. $filter_field[ 'options' ][ $filter_field[ 'type' ] . '_allow_empty' ] = 1; 
  2721.  
  2722. if ( !empty( $start ) && !in_array( $start, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) 
  2723. $start = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $start, 'n/j/Y' ); 
  2724.  
  2725. if ( !empty( $end ) && !in_array( $end, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) 
  2726. $end = PodsForm::field_method( $filter_field[ 'type' ], 'convert_date', $end, 'n/j/Y' ); 
  2727. ?> 
  2728. <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? '' : ' hidden' ); ?>">+</span> 
  2729. <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span> 
  2730.  
  2731. <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_start"> 
  2732. <?php echo $filter_field[ 'label' ]; ?> 
  2733. </label> 
  2734.  
  2735. <span class="pods-ui-posts-filter<?php echo esc_attr( ( empty( $start ) && empty( $end ) ) ? ' hidden' : '' ); ?>"> 
  2736. <?php echo PodsForm::field( 'filter_' . $filter . '_start', $start, $filter_field[ 'type' ], $filter_field ); ?> 
  2737.  
  2738. <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>_end">to</label> 
  2739. <?php echo PodsForm::field( 'filter_' . $filter . '_end', $end, $filter_field[ 'type' ], $filter_field ); ?> 
  2740. </span> 
  2741. <?php 
  2742. elseif ( 'pick' == $filter_field[ 'type' ] ) { 
  2743. $value = pods_var_raw( 'filter_' . $filter, 'get', '' ); 
  2744.  
  2745. if ( strlen( $value ) < 1 ) 
  2746. $value = pods_var_raw( 'filter_default', $filter_field ); 
  2747.  
  2748. // override default value 
  2749. $filter_field[ 'options' ][ 'default_value' ] = ''; 
  2750.  
  2751. $filter_field[ 'options' ][ 'pick_format_type' ] = 'single'; 
  2752. $filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown'; 
  2753.  
  2754. $filter_field[ '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 ); 
  2755. $filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true ); 
  2756.  
  2757. $options = array_merge( $filter_field, $filter_field[ 'options' ] ); 
  2758. ?> 
  2759. <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' hidden' ); ?>">+</span> 
  2760. <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span> 
  2761.  
  2762. <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>"> 
  2763. <?php echo $filter_field[ 'label' ]; ?> 
  2764. </label> 
  2765.  
  2766. <span class="pods-ui-posts-filter<?php echo esc_attr( strlen( $value ) < 1 ? ' hidden' : '' ); ?>"> 
  2767. <?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?> 
  2768. </span> 
  2769. <?php 
  2770. elseif ( 'boolean' == $filter_field[ 'type' ] ) { 
  2771. $value = pods_var_raw( 'filter_' . $filter, 'get', '' ); 
  2772.  
  2773. if ( strlen( $value ) < 1 ) 
  2774. $value = pods_var_raw( 'filter_default', $filter_field ); 
  2775.  
  2776. // override default value 
  2777. $filter_field[ 'options' ][ 'default_value' ] = ''; 
  2778.  
  2779. $filter_field[ 'options' ][ 'pick_format_type' ] = 'single'; 
  2780. $filter_field[ 'options' ][ 'pick_format_single' ] = 'dropdown'; 
  2781.  
  2782. $filter_field[ 'options' ][ 'pick_object' ] = 'custom-simple'; 
  2783. $filter_field[ 'options' ][ 'pick_custom' ] = array( 
  2784. '1' => pods_var_raw( 'boolean_yes_label', $filter_field[ 'options' ], __( 'Yes', 'pods' ), null, true ),  
  2785. '0' => pods_var_raw( 'boolean_no_label', $filter_field[ 'options' ], __( 'No', 'pods' ), null, true ) 
  2786. ); 
  2787.  
  2788. $filter_field[ '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 ); 
  2789. $filter_field[ 'options' ][ 'input_helper' ] = pods_var_raw( 'ui_input_helper', $filter_field[ 'options' ], $filter_field[ 'options' ][ 'input_helper' ], null, true ); 
  2790.  
  2791. $options = array_merge( $filter_field, $filter_field[ 'options' ] ); 
  2792. ?> 
  2793. <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' hidden' ); ?>">+</span> 
  2794. <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span> 
  2795.  
  2796. <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>"> 
  2797. <?php echo $filter_field[ 'label' ]; ?> 
  2798. </label> 
  2799.  
  2800. <span class="pods-ui-posts-filter<?php echo esc_attr( strlen( $value ) < 1 ? ' hidden' : '' ); ?>"> 
  2801. <?php echo PodsForm::field( 'filter_' . $filter, $value, 'pick', $options ); ?> 
  2802. </span> 
  2803. <?php 
  2804. else { 
  2805. $value = pods_var_raw( 'filter_' . $filter, 'get' ); 
  2806.  
  2807. if ( strlen( $value ) < 1 ) 
  2808. $value = pods_var_raw( 'filter_default', $filter_field ); 
  2809.  
  2810. $options = array( 
  2811. '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 ) 
  2812. ); 
  2813.  
  2814. if ( empty( $options[ 'input_helper' ] ) && isset( $filter_field[ 'options' ] ) && isset( $filter_field[ 'options' ][ 'input_helper' ] ) ) 
  2815. $options[ 'input_helper' ] = $filter_field[ 'options' ][ 'input_helper' ]; 
  2816. ?> 
  2817. <span class="pods-ui-posts-filter-toggle toggle-on<?php echo esc_attr( empty( $value ) ? '' : ' hidden' ); ?>">+</span> 
  2818. <span class="pods-ui-posts-filter-toggle toggle-off<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>"><?php _e( 'Clear', 'pods' ); ?></span> 
  2819.  
  2820. <label for="pods-form-ui-filter-<?php echo esc_attr( $filter ); ?>"> 
  2821. <?php echo $filter_field[ 'label' ]; ?> 
  2822. </label> 
  2823.  
  2824. <span class="pods-ui-posts-filter<?php echo esc_attr( empty( $value ) ? ' hidden' : '' ); ?>"> 
  2825. <?php echo PodsForm::field( 'filter_' . $filter, $value, 'text', $options ); ?> 
  2826. </span> 
  2827. <?php 
  2828. ?> 
  2829. </p> 
  2830. <?php 
  2831. $zebra = empty( $zebra ); 
  2832. ?> 
  2833.  
  2834. <p class="pods-ui-posts-filter-toggled pods-ui-posts-filter-search<?php echo esc_attr( $zebra ? ' clear' : '' ); ?>"> 
  2835. <label for="pods-form-ui-search<?php echo esc_attr( $this->num ); ?>"><?php _e( 'Search Text', 'pods' ); ?></label> 
  2836. <?php echo PodsForm::field( 'search' . $this->num, pods_var_raw( 'search' . $this->num, 'get' ), 'text' ); ?> 
  2837. </p> 
  2838.  
  2839. <?php $zebra = empty( $zebra ); ?> 
  2840. </div> 
  2841.  
  2842. <p class="submit<?php echo esc_attr( $zebra ? ' clear' : '' ); ?>"><input type="submit" value="<?php echo esc_attr( $this->header[ 'search' ] ); ?>" class="button button-primary" /></p> 
  2843. </form> 
  2844. </div> 
  2845.  
  2846. <script type="text/javascript"> 
  2847. jQuery( function () { 
  2848. jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-on', function ( e ) { 
  2849. jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'hidden' ); 
  2850.  
  2851. jQuery( this ).hide(); 
  2852. jQuery( this ).parent().find( '.toggle-off' ).show(); 
  2853. } ); 
  2854.  
  2855. jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggle.toggle-off', function ( e ) { 
  2856. jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'hidden' ); 
  2857. jQuery( this ).parent().find( 'select, input' ).val( '' ); 
  2858.  
  2859. jQuery( this ).hide(); 
  2860. jQuery( this ).parent().find( '.toggle-on' ).show(); 
  2861. } ); 
  2862.  
  2863. jQuery( document ).on( 'click', '.pods-ui-posts-filter-toggled label', function ( e ) { 
  2864. if ( jQuery( this ).parent().find( '.pods-ui-posts-filter' ).hasClass( 'hidden' ) ) { 
  2865. jQuery( this ).parent().find( '.pods-ui-posts-filter' ).removeClass( 'hidden' ); 
  2866.  
  2867. jQuery( this ).parent().find( '.toggle-on' ).hide(); 
  2868. jQuery( this ).parent().find( '.toggle-off' ).show(); 
  2869. else { 
  2870. jQuery( this ).parent().find( '.pods-ui-posts-filter' ).addClass( 'hidden' ); 
  2871. jQuery( this ).parent().find( 'select, input' ).val( '' ); 
  2872.  
  2873. jQuery( this ).parent().find( '.toggle-on' ).show(); 
  2874. jQuery( this ).parent().find( '.toggle-off' ).hide(); 
  2875. } ); 
  2876. } ); 
  2877. </script> 
  2878. <?php 
  2879.  
  2880. /** 
  2881. * @param bool $reorder 
  2882. * @return bool|mixed 
  2883. */ 
  2884. public function table ( $reorder = false ) { 
  2885. if ( false !== $this->callback( 'table', $reorder ) ) { 
  2886. return null; 
  2887.  
  2888. if ( empty( $this->data ) ) { 
  2889. ?> 
  2890. <p><?php echo sprintf( __( 'No %s found', 'pods' ), $this->items ); ?></p> 
  2891. <?php 
  2892. return false; 
  2893. if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) { 
  2894. ?> 
  2895. <style type="text/css"> 
  2896. table.widefat.fixed tbody.reorderable tr { 
  2897. height: 50px; 
  2898.  
  2899. .dragme { 
  2900. background: url(<?php echo esc_url( PODS_URL ); ?>/ui/images/handle.gif) no-repeat; 
  2901. background-position: 8px 8px; 
  2902. cursor: pointer; 
  2903.  
  2904. .dragme strong { 
  2905. margin-left: 30px; 
  2906. </style> 
  2907. <form action="<?php echo esc_url( pods_query_arg( array( 'action' . $this->num => 'reorder', 'do' . $this->num => 'save', 'page' => pods_var_raw( 'page' ) ), self::$allowed, $this->exclusion() ) ); ?>" method="post" class="admin_ui_reorder_form"> 
  2908. <?php 
  2909. $table_fields = $this->fields[ 'manage' ]; 
  2910. if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) 
  2911. $table_fields = $this->fields[ 'reorder' ]; 
  2912. if ( false === $table_fields || empty( $table_fields ) ) 
  2913. return $this->error( __( '<strong>Error:</strong> Invalid Configuration - Missing "fields" definition.', 'pods' ) ); 
  2914. ?> 
  2915. <table class="widefat page fixed wp-list-table" cellspacing="0"<?php echo ( 1 == $reorder && $this->reorder ) ? ' id="admin_ui_reorder"' : ''; ?>> 
  2916. <thead> 
  2917. <tr> 
  2918. <?php 
  2919. if ( !empty( $this->actions_bulk ) ) { 
  2920. ?> 
  2921. <th scope="col" id="cb" class="manage-column column-cb check-column"><input type="checkbox" /></th> 
  2922. <?php 
  2923.  
  2924. $name_field = false; 
  2925. $fields = array(); 
  2926. if ( !empty( $table_fields ) ) { 
  2927. foreach ( $table_fields as $field => $attributes ) { 
  2928. if ( false === $attributes[ 'display' ] ) 
  2929. continue; 
  2930. if ( false === $name_field ) 
  2931. $id = 'title'; 
  2932. else 
  2933. $id = ''; 
  2934. if ( 'other' == $attributes[ 'type' ] ) 
  2935. $id = ''; 
  2936. if ( in_array( $attributes[ 'type' ], array( 'date', 'datetime', 'time' ) ) ) 
  2937. $id = 'date'; 
  2938. if ( false === $name_field && 'title' == $id ) 
  2939. $name_field = true; 
  2940. $fields[ $field ] = $attributes; 
  2941. $fields[ $field ][ 'field_id' ] = $id; 
  2942. $dir = 'DESC'; 
  2943. $current_sort = ' asc'; 
  2944. if ( isset( $this->orderby[ 'default' ] ) && $field == $this->orderby[ 'default' ] ) { 
  2945. if ( 'DESC' == $this->orderby_dir ) { 
  2946. $dir = 'ASC'; 
  2947. $current_sort = ' desc'; 
  2948.  
  2949. $att_id = ''; 
  2950. if ( !empty( $id ) ) 
  2951. $att_id = ' id="' . esc_attr( $id ) . '"'; 
  2952.  
  2953. $width = ''; 
  2954.  
  2955. if ( isset( $attributes[ 'width' ] ) && !empty( $attributes[ 'width' ] ) ) 
  2956. $width = ' style="width: ' . esc_attr( $attributes[ 'width' ] ) . '"'; 
  2957.  
  2958. if ( $fields[ $field ][ 'sortable' ] ) { 
  2959. ?> 
  2960. <th scope="col"<?php echo $att_id; ?> class="manage-column column-<?php echo esc_attr( $id ); ?> sortable<?php echo esc_attr( $current_sort ); ?>"<?php echo $width; ?>> 
  2961. <a href="<?php echo esc_url_raw( pods_query_arg( 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> 
  2962. </th> 
  2963. <?php 
  2964. else { 
  2965. ?> 
  2966. <th scope="col"<?php echo $att_id; ?> class="manage-column column-<?php echo esc_attr( $id ); ?>"<?php echo $width; ?>><?php echo $attributes[ 'label' ]; ?></th> 
  2967. <?php 
  2968. ?> 
  2969. </tr> 
  2970. </thead> 
  2971. <?php 
  2972. if ( 6 < $this->total_found ) { 
  2973. ?> 
  2974. <tfoot> 
  2975. <tr> 
  2976. <?php 
  2977. if ( !empty( $this->actions_bulk ) ) { 
  2978. ?> 
  2979. <th scope="col" class="manage-column column-cb check-column"><input type="checkbox" /></th> 
  2980. <?php 
  2981.  
  2982. if ( !empty( $fields ) ) { 
  2983. foreach ( $fields as $field => $attributes ) { 
  2984. $dir = 'ASC'; 
  2985. if ( $field == $this->orderby ) { 
  2986. $current_sort = 'desc'; 
  2987. if ( 'ASC' == $this->orderby_dir ) { 
  2988. $dir = 'DESC'; 
  2989. $current_sort = 'asc'; 
  2990.  
  2991. $width = ''; 
  2992.  
  2993. if ( isset( $attributes[ 'width' ] ) && !empty( $attributes[ 'width' ] ) ) 
  2994. $width = ' style="width: ' . esc_attr( $attributes[ 'width' ] ) . '"'; 
  2995.  
  2996. if ( $fields[ $field ][ 'sortable' ] ) { 
  2997. ?> 
  2998. <th scope="col" class="manage-column column-<?php echo esc_attr( $id ); ?> sortable <?php echo esc_attr( $current_sort ); ?>"<?php echo $width; ?>><a href="<?php echo esc_url_raw( pods_query_arg( 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> 
  2999. <?php 
  3000. else { 
  3001. ?> 
  3002. <th scope="col" class="manage-column column-<?php echo esc_attr( $id ); ?>"<?php echo $width; ?>><?php echo $attributes[ 'label' ]; ?></th> 
  3003. <?php 
  3004. ?> 
  3005. </tr> 
  3006. </tfoot> 
  3007. <?php 
  3008. ?> 
  3009. <tbody id="the-list"<?php echo ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) ? ' class="reorderable"' : ''; ?>> 
  3010. <?php 
  3011. if ( !empty( $this->data ) && is_array( $this->data ) ) { 
  3012. $counter = 0; 
  3013.  
  3014. while ( $row = $this->get_row( $counter, 'table' ) ) { 
  3015. if ( is_object( $row ) ) 
  3016. $row = get_object_vars( (object) $row ); 
  3017.  
  3018. $toggle_class = ''; 
  3019.  
  3020. if ( is_array( $this->actions_custom ) && isset( $this->actions_custom[ 'toggle' ] ) ) { 
  3021. $toggle_class = ' pods-toggled-on'; 
  3022.  
  3023. if ( !isset( $row[ 'toggle' ] ) || empty( $row[ 'toggle' ] ) ) 
  3024. $toggle_class = ' pods-toggled-off'; 
  3025. ?> 
  3026. <tr id="item-<?php echo esc_attr( $row[ $this->sql[ 'field_id' ] ] ); ?>" class="iedit<?php echo esc_attr( $toggle_class ); ?>"> 
  3027. <?php 
  3028. if ( !empty( $this->actions_bulk ) ) { 
  3029. ?> 
  3030. <th scope="row" class="check-column"><input type="checkbox" name="action_bulk_ids<?php echo esc_attr( $this->num ); ?>[]" value="<?php echo esc_attr( $row[$this->sql['field_id']] ); ?>"></th> 
  3031. <?php 
  3032.  
  3033. foreach ( $fields as $field => $attributes ) { 
  3034. if ( false === $attributes[ 'display' ] ) 
  3035. continue; 
  3036.  
  3037. if ( !isset( $row[ $field ] ) ) { 
  3038. $row[ $field ] = $this->get_field( $field ); 
  3039.  
  3040. $row_value = $row[ $field ]; 
  3041.  
  3042. if ( !empty( $attributes[ 'custom_display' ] ) ) { 
  3043. if ( is_callable( $attributes[ 'custom_display' ] ) ) 
  3044. $row_value = call_user_func_array( $attributes[ 'custom_display' ], array( $row, &$this, $row_value, $field, $attributes ) ); 
  3045. elseif ( is_object( $this->pod ) && class_exists( 'Pods_Helpers' ) ) 
  3046. $row_value = $this->pod->helper( $attributes[ 'custom_display' ], $row_value, $field ); 
  3047. else { 
  3048. ob_start(); 
  3049.  
  3050. $field_value = PodsForm::field_method( $attributes[ 'type' ], 'ui', $this->id, $row_value, $field, array_merge( $attributes, pods_var_raw( 'options', $attributes, array(), null, true ) ), $fields, $this->pod ); 
  3051.  
  3052. $field_output = trim( (string) ob_get_clean() ); 
  3053.  
  3054. if ( false === $field_value ) 
  3055. $row_value = ''; 
  3056. elseif ( 0 < strlen( trim( (string) $field_value ) ) ) 
  3057. $row_value = trim( (string) $field_value ); 
  3058. elseif ( 0 < strlen( $field_output ) ) 
  3059. $row_value = $field_output; 
  3060.  
  3061. if ( false !== $attributes[ 'custom_relate' ] ) { 
  3062. global $wpdb; 
  3063. $table = $attributes[ 'custom_relate' ]; 
  3064. $on = $this->sql[ 'field_id' ]; 
  3065. $is = $row[ $this->sql[ 'field_id' ] ]; 
  3066. $what = array( 'name' ); 
  3067. if ( is_array( $table ) ) { 
  3068. if ( isset( $table[ 'on' ] ) ) 
  3069. $on = pods_sanitize( $table[ 'on' ] ); 
  3070. if ( isset( $table[ 'is' ] ) && isset( $row[ $table[ 'is' ] ] ) ) 
  3071. $is = pods_sanitize( $row[ $table[ 'is' ] ] ); 
  3072. if ( isset( $table[ 'what' ] ) ) { 
  3073. $what = array(); 
  3074. if ( is_array( $table[ 'what' ] ) ) { 
  3075. foreach ( $table[ 'what' ] as $wha ) { 
  3076. $what[] = pods_sanitize( $wha ); 
  3077. else 
  3078. $what[] = pods_sanitize( $table[ 'what' ] ); 
  3079. if ( isset( $table[ 'table' ] ) ) 
  3080. $table = $table[ 'table' ]; 
  3081. $table = pods_sanitize( $table ); 
  3082. $wha = implode( ', ', $what ); 
  3083. $sql = "SELECT {$wha} FROM {$table} WHERE `{$on}`='{$is}'"; 
  3084. $value = @current( $wpdb->get_results( $sql, ARRAY_A ) ); 
  3085. if ( !empty( $value ) ) { 
  3086. $val = array(); 
  3087. foreach ( $what as $wha ) { 
  3088. if ( isset( $value[ $wha ] ) ) 
  3089. $val[] = $value[ $wha ]; 
  3090. if ( !empty( $val ) ) 
  3091. $row_value = implode( ' ', $val ); 
  3092.  
  3093. $css_classes = ' pods-ui-col-field-' . sanitize_title( $field ); 
  3094.  
  3095. if ( $attributes[ 'css_values' ] ) { 
  3096. $css_field_value = $row[ $field ]; 
  3097.  
  3098. if ( is_object( $css_field_value ) ) { 
  3099. $css_field_value = get_object_vars( $css_field_value ); 
  3100.  
  3101. if ( is_array( $css_field_value ) ) { 
  3102. foreach ( $css_field_value as $css_field_val ) { 
  3103. if ( is_object( $css_field_val ) ) { 
  3104. $css_field_val = get_object_vars( $css_field_val ); 
  3105.  
  3106. if ( is_array( $css_field_val ) ) { 
  3107. foreach ( $css_field_val as $css_field_v ) { 
  3108. if ( is_object( $css_field_v ) ) { 
  3109. $css_field_v = get_object_vars( $css_field_v ); 
  3110.  
  3111. $css_classes .= ' pods-ui-css-value-' . sanitize_title( str_replace( array( "\n", "\r" ), ' ', strip_tags( (string) $css_field_v ) ) ); 
  3112. else { 
  3113. $css_classes .= ' pods-ui-css-value-' . sanitize_title( str_replace( array( "\n", "\r" ), ' ', strip_tags( (string) $css_field_val ) ) ); 
  3114. else { 
  3115. $css_classes .= ' pods-ui-css-value-' . sanitize_title( str_replace( array( "\n", "\r" ), ' ', strip_tags( (string) $css_field_value ) ) ); 
  3116.  
  3117. if ( is_object( $this->pod ) ) 
  3118. $row_value = $this->do_hook( $this->pod->pod . '_field_value', $row_value, $field, $attributes, $row ); 
  3119.  
  3120. $row_value = $this->do_hook( 'field_value', $row_value, $field, $attributes, $row ); 
  3121.  
  3122. if ( 'title' == $attributes[ 'field_id' ] ) { 
  3123. $default_action = $this->do_hook( 'default_action', 'edit', $row ); 
  3124.  
  3125. if ( !in_array( 'edit', $this->actions_disabled ) && !in_array( 'edit', $this->actions_hidden ) && ( false === $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder[ 'on' ] ) && 'edit' == $default_action ) { 
  3126. $link = pods_query_arg( array( 'action' . $this->num => 'edit', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() ); 
  3127.  
  3128. if ( !empty( $this->action_links[ 'edit' ] ) ) 
  3129. $link = $this->do_template( $this->action_links[ 'edit' ], $row ); 
  3130. ?> 
  3131. <td class="post-title page-title column-title<?php echo esc_attr( $css_classes ); ?>"><strong><a class="row-title" href="<?php echo esc_url_raw( $link ); ?>" title="<?php esc_attr_e( 'Edit this item', 'pods' ); ?>"><?php echo $row_value; ?></a></strong> 
  3132. <?php 
  3133. elseif ( !in_array( 'view', $this->actions_disabled ) && !in_array( 'view', $this->actions_hidden ) && ( false === $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder[ 'on' ] ) && 'view' == $default_action ) { 
  3134. $link = pods_query_arg( array( 'action' . $this->num => 'view', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() ); 
  3135.  
  3136. if ( !empty( $this->action_links[ 'view' ] ) ) 
  3137. $link = $this->do_template( $this->action_links[ 'view' ], $row ); 
  3138. ?> 
  3139. <td class="post-title page-title column-title<?php echo esc_attr( $css_classes ); ?>"><strong><a class="row-title" href="<?php echo esc_url_raw( $link ); ?>" title="<?php esc_attr_e( 'View this item', 'pods' ); ?>"><?php echo $row_value; ?></a></strong> 
  3140. <?php 
  3141. else { 
  3142. ?> 
  3143. <td class="post-title page-title column-title<?php echo esc_attr( $css_classes ); ?><?php echo esc_attr( ( 1 == $reorder && $this->reorder ) ? ' dragme' : '' ); ?>"><strong><?php echo $row_value; ?></strong> 
  3144. <?php 
  3145.  
  3146. if ( true !== $reorder || in_array( 'reorder', $this->actions_disabled ) || false === $this->reorder[ 'on' ] ) { 
  3147. $toggle = false; 
  3148. $actions = array(); 
  3149.  
  3150. if ( !in_array( 'view', $this->actions_disabled ) && !in_array( 'view', $this->actions_hidden ) ) { 
  3151. $link = pods_query_arg( array( 'action' . $this->num => 'view', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() ); 
  3152.  
  3153. if ( !empty( $this->action_links[ 'view' ] ) ) 
  3154. $link = $this->do_template( $this->action_links[ 'view' ], $row ); 
  3155.  
  3156. $actions[ 'view' ] = '<span class="view"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'View this item', 'pods' ) . '">' . __( 'View', 'pods' ) . '</a></span>'; 
  3157.  
  3158. if ( !in_array( 'edit', $this->actions_disabled ) && !in_array( 'edit', $this->actions_hidden ) && !$this->restricted( 'edit', $row ) ) { 
  3159. $link = pods_query_arg( array( 'action' . $this->num => 'edit', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() ); 
  3160.  
  3161. if ( !empty( $this->action_links[ 'edit' ] ) ) 
  3162. $link = $this->do_template( $this->action_links[ 'edit' ], $row ); 
  3163.  
  3164. $actions[ 'edit' ] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Edit this item', 'pods' ) . '">' . __( 'Edit', 'pods' ) . '</a></span>'; 
  3165.  
  3166. if ( !in_array( 'duplicate', $this->actions_disabled ) && !in_array( 'duplicate', $this->actions_hidden ) && !$this->restricted( 'edit', $row ) ) { 
  3167. $link = pods_query_arg( array( 'action' . $this->num => 'duplicate', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ] ), self::$allowed, $this->exclusion() ); 
  3168.  
  3169. if ( !empty( $this->action_links[ 'duplicate' ] ) ) 
  3170. $link = $this->do_template( $this->action_links[ 'duplicate' ], $row ); 
  3171.  
  3172. $actions[ 'duplicate' ] = '<span class="edit"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Duplicate this item', 'pods' ) . '">' . __( 'Duplicate', 'pods' ) . '</a></span>'; 
  3173.  
  3174. if ( !in_array( 'delete', $this->actions_disabled ) && !in_array( 'delete', $this->actions_hidden ) && !$this->restricted( 'delete', $row ) ) { 
  3175. $link = pods_query_arg( array( 'action' . $this->num => 'delete', 'id' . $this->num => $row[ $this->sql[ 'field_id' ] ], '_wpnonce' => wp_create_nonce( 'pods-ui-action-delete' ) ), self::$allowed, $this->exclusion() ); 
  3176.  
  3177. if ( !empty( $this->action_links[ 'delete' ] ) ) { 
  3178. $link = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'pods-ui-action-delete' ) ), $this->do_template( $this->action_links[ 'delete' ], $row ) ); 
  3179.  
  3180. $actions[ 'delete' ] = '<span class="delete"><a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Delete this item', 'pods' ) . '" class="submitdelete" onclick="if(confirm(\'' . esc_attr__( '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>'; 
  3181.  
  3182. if ( is_array( $this->actions_custom ) ) { 
  3183. foreach ( $this->actions_custom as $custom_action => $custom_data ) { 
  3184. if ( 'add' != $custom_action && 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 ) ) { 
  3185. if ( !in_array( $custom_action, array( 'add', 'view', 'edit', 'duplicate', 'delete', 'save', 'export', 'reorder', 'manage', 'table' ) ) ) { 
  3186. if ( 'toggle' == $custom_action ) { 
  3187. $toggle = true; 
  3188. $toggle_labels = array( 
  3189. __( 'Enable', 'pods' ),  
  3190. __( 'Disable', 'pods' ) 
  3191. ); 
  3192.  
  3193. $custom_data[ 'label' ] = ( $row[ 'toggle' ] ? $toggle_labels[ 1 ] : $toggle_labels[ 0 ] ); 
  3194.  
  3195. if ( !isset( $custom_data[ 'label' ] ) ) 
  3196. $custom_data[ 'label' ] = ucwords( str_replace( '_', ' ', $custom_action ) ); 
  3197.  
  3198. if ( !isset( $custom_data[ 'link' ] ) ) { 
  3199. $vars = array( 
  3200. 'action' => $custom_action,  
  3201. 'id' => $row[ $this->sql[ 'field_id' ] ],  
  3202. '_wpnonce' => wp_create_nonce( 'pods-ui-action-' . $custom_action ) 
  3203. ); 
  3204.  
  3205. if ( 'toggle' == $custom_action ) { 
  3206. $vars[ 'toggle' ] = (int) ( !$row[ 'toggle' ] ); 
  3207. $vars[ 'toggled' ] = 1; 
  3208.  
  3209. $custom_data[ 'link' ] = pods_query_arg( $vars, self::$allowed, $this->exclusion() ); 
  3210.  
  3211. if ( isset( $this->action_links[ $custom_action ] ) && !empty( $this->action_links[ $custom_action ] ) ) { 
  3212. $custom_data[ 'link' ] = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'pods-ui-action-' . $custom_action ) ), $this->do_template( $this->action_links[ $custom_action ], $row ) ); 
  3213.  
  3214. $confirm = ''; 
  3215.  
  3216. if ( isset( $custom_data[ 'confirm' ] ) ) 
  3217. $confirm = ' onclick="if(confirm(\'' . esc_js( $custom_data[ 'confirm' ] ) . '\')) {return true;}return false;"'; 
  3218.  
  3219. if ( $this->restricted( $custom_action, $row ) ) { 
  3220. continue; 
  3221.  
  3222. $actions[ $custom_action ] = '<span class="edit action-' . esc_attr( $custom_action ) . '"><a href="' . esc_url( $this->do_template( $custom_data[ 'link' ], $row ) ) . '" title="' . esc_attr( $custom_data[ 'label' ] ) . ' this item"' . $confirm . '>' . $custom_data[ 'label' ] . '</a></span>'; 
  3223.  
  3224. $actions = $this->do_hook( 'row_actions', $actions, $row[ $this->sql[ 'field_id' ] ] ); 
  3225.  
  3226. if ( !empty( $actions ) ) { 
  3227. ?> 
  3228. <div class="row-actions<?php echo esc_attr( $toggle ? ' row-actions-toggle' : '' ); ?>"> 
  3229. <?php 
  3230. $this->callback( 'actions_start', $row, $actions ); 
  3231.  
  3232. echo implode( ' | ', $actions ); 
  3233.  
  3234. $this->callback( 'actions_end', $row, $actions ); 
  3235. ?> 
  3236. </div> 
  3237. <?php 
  3238. else { 
  3239. ?> 
  3240. <input type="hidden" name="order[]" value="<?php echo esc_attr( $row[ $this->sql[ 'field_id' ] ] ); ?>" /> 
  3241. <?php 
  3242. ?> 
  3243. </td> 
  3244. <?php 
  3245. elseif ( 'date' == $attributes[ 'type' ] ) { 
  3246. ?> 
  3247. <td class="date column-date<?php echo esc_attr( $css_classes ); ?>"><abbr title="<?php echo esc_attr( $row_value ); ?>"><?php echo $row_value; ?></abbr></td> 
  3248. <?php 
  3249. else { 
  3250. ?> 
  3251. <td class="author<?php echo esc_attr( $css_classes ); ?>"><span><?php echo $row_value; ?></span></td> 
  3252. <?php 
  3253. ?> 
  3254. </tr> 
  3255. <?php 
  3256. ?> 
  3257. </tbody> 
  3258. </table> 
  3259. <?php 
  3260. if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) { 
  3261. ?> 
  3262. </form> 
  3263. <?php 
  3264. ?> 
  3265. <script type="text/javascript"> 
  3266. jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' ); 
  3267. <?php 
  3268. if ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) { 
  3269. ?> 
  3270. jQuery( document ).ready( function () { 
  3271. jQuery( ".reorderable" ).sortable( {axis : "y", handle : ".dragme"} ); 
  3272. jQuery( ".reorderable" ).bind( 'sortupdate', function ( event, ui ) { 
  3273. jQuery( 'table.widefat tbody tr' ).removeClass( 'alternate' ); 
  3274. jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' ); 
  3275. } ); 
  3276. } ); 
  3277. <?php 
  3278. ?> 
  3279. </script> 
  3280. <?php 
  3281.  
  3282. /** 
  3283. */ 
  3284. public function screen_meta () { 
  3285. $screen_html = $help_html = ''; 
  3286. $screen_link = $help_link = ''; 
  3287. if ( !empty( $this->screen_options ) && !empty( $this->help ) ) { 
  3288. foreach ( $this->ui_page as $page ) { 
  3289. if ( isset( $this->screen_options[ $page ] ) ) { 
  3290. if ( is_array( $this->screen_options[ $page ] ) ) { 
  3291. if ( isset( $this->screen_options[ $page ][ 'link' ] ) ) { 
  3292. $screen_link = $this->screen_options[ $page ][ 'link' ]; 
  3293. break; 
  3294. else { 
  3295. $screen_html = $this->screen_options[ $page ]; 
  3296. break; 
  3297. foreach ( $this->ui_page as $page ) { 
  3298. if ( isset( $this->help[ $page ] ) ) { 
  3299. if ( is_array( $this->help[ $page ] ) ) { 
  3300. if ( isset( $this->help[ $page ][ 'link' ] ) ) { 
  3301. $help_link = $this->help[ $page ][ 'link' ]; 
  3302. break; 
  3303. else { 
  3304. $help_html = $this->help[ $page ]; 
  3305. break; 
  3306. $screen_html = $this->do_hook( 'screen_meta_screen_html', $screen_html ); 
  3307. $screen_link = $this->do_hook( 'screen_meta_screen_link', $screen_link ); 
  3308. $help_html = $this->do_hook( 'screen_meta_help_html', $help_html ); 
  3309. $help_link = $this->do_hook( 'screen_meta_help_link', $help_link ); 
  3310. if ( 0 < strlen( $screen_html ) || 0 < strlen( $screen_link ) || 0 < strlen( $help_html ) || 0 < strlen( $help_link ) ) { 
  3311. ?> 
  3312. <div id="screen-meta"> 
  3313. <?php 
  3314. $this->do_hook( 'screen_meta_pre' ); 
  3315. if ( 0 < strlen( $screen_html ) ) { 
  3316. ?> 
  3317. <div id="screen-options-wrap" class="hidden"> 
  3318. <form id="adv-settings" action="" method="post"> 
  3319. <?php 
  3320. echo $screen_html; 
  3321. $fields = array(); 
  3322. foreach ( $this->ui_page as $page ) { 
  3323. if ( isset( $this->fields[ $page ] ) && !empty( $this->fields[ $page ] ) ) 
  3324. $fields = $this->fields[ $page ]; 
  3325. if ( !empty( $fields ) || true === $this->pagination ) { 
  3326. ?> 
  3327. <h5><?php _e( 'Show on screen', 'pods' ); ?></h5> 
  3328. <?php 
  3329. if ( !empty( $fields ) ) { 
  3330. ?> 
  3331. <div class="metabox-prefs"> 
  3332. <?php 
  3333. $this->do_hook( 'screen_meta_screen_options' ); 
  3334. foreach ( $fields as $field => $attributes ) { 
  3335. if ( false === $attributes[ 'display' ] || true === $attributes[ 'hidden' ] ) 
  3336. continue; 
  3337. ?> 
  3338. <label for="<?php echo esc_attr( $field ); ?>-hide"> 
  3339. <input class="hide-column-tog" name="<?php echo esc_attr( $this->unique_identifier ); ?>_<?php echo esc_attr( $field ); ?>-hide" type="checkbox" id="<?php echo esc_attr( $field ); ?>-hide" value="<?php echo esc_attr( $field ); ?>" checked="checked"><?php echo $attributes[ 'label' ]; ?></label> 
  3340. <?php 
  3341. ?> 
  3342. <br class="clear"> 
  3343. </div> 
  3344. <h5><?php _e( 'Show on screen', 'pods' ); ?></h5> 
  3345. <?php 
  3346. ?> 
  3347. <div class="screen-options"> 
  3348. <?php 
  3349. if ( true === $this->pagination ) { 
  3350. ?> 
  3351. <input type="text" class="screen-per-page" name="wp_screen_options[value]" id="<?php echo esc_attr( $this->unique_identifier ); ?>_per_page" maxlength="3" value="20"> <label for="<?php echo esc_attr( $this->unique_identifier ); ?>_per_page"><?php echo $this->items; ?> per page</label> 
  3352. <?php 
  3353. $this->do_hook( 'screen_meta_screen_submit' ); 
  3354. ?> 
  3355. <input type="submit" name="screen-options-apply" id="screen-options-apply" class="button" value="<?php esc_attr_e( 'Apply', 'pods' ); ?>"> 
  3356. <input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $this->unique_identifier ); ?>_per_page"> 
  3357. <?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?> 
  3358. </div> 
  3359. <?php 
  3360. ?> 
  3361. </form> 
  3362. </div> 
  3363. <?php 
  3364. if ( 0 < strlen( $help_html ) ) { 
  3365. ?> 
  3366. <div id="contextual-help-wrap" class="hidden"> 
  3367. <div class="metabox-prefs"> 
  3368. <?php echo $help_html; ?> 
  3369. </div> 
  3370. </div> 
  3371. <?php 
  3372. ?> 
  3373. <div id="screen-meta-links"> 
  3374. <?php 
  3375. $this->do_hook( 'screen_meta_links_pre' ); 
  3376. if ( 0 < strlen( $help_html ) || 0 < strlen( $help_link ) ) { 
  3377. ?> 
  3378. <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle"> 
  3379. <?php 
  3380. if ( 0 < strlen( $help_link ) ) { 
  3381. ?> 
  3382. <a href="<?php echo esc_url( $help_link ); ?>" class="show-settings">Help</a> 
  3383. <?php 
  3384. else { 
  3385. ?> 
  3386. <a href="#contextual-help" id="contextual-help-link" class="show-settings">Help</a> 
  3387. <?php 
  3388. ?> 
  3389. </div> 
  3390. <?php 
  3391. if ( 0 < strlen( $screen_html ) || 0 < strlen( $screen_link ) ) { 
  3392. ?> 
  3393. <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle"> 
  3394. <?php 
  3395. if ( 0 < strlen( $screen_link ) ) { 
  3396. ?> 
  3397. <a href="<?php echo esc_url( $screen_link ); ?>" class="show-settings">Screen Options</a> 
  3398. <?php 
  3399. else { 
  3400. ?> 
  3401. <a href="#screen-options" id="show-settings-link" class="show-settings">Screen Options</a> 
  3402. <?php 
  3403. ?> 
  3404. </div> 
  3405. <?php 
  3406. $this->do_hook( 'screen_meta_links_post' ); 
  3407. ?> 
  3408. </div> 
  3409. <?php 
  3410. $this->do_hook( 'screen_meta_post' ); 
  3411. ?> 
  3412. </div> 
  3413. <?php 
  3414.  
  3415. /** 
  3416. * @param bool $header 
  3417. * @return mixed 
  3418. */ 
  3419. public function pagination ( $header = false ) { 
  3420. if ( false !== $this->callback( 'pagination', $header ) ) { 
  3421. return null; 
  3422.  
  3423. $total_pages = ceil( $this->total_found / $this->limit ); 
  3424. $request_uri = pods_query_arg( array( 'pg' . $this->num => '' ), array( 'limit' . $this->num, 'orderby' . $this->num, 'orderby_dir' . $this->num, 'search' . $this->num, 'filter_*', 'view' . $this->num, 'page' . $this->num ), $this->exclusion() ); 
  3425.  
  3426. $append = false; 
  3427.  
  3428. if ( false !== strpos( $request_uri, '?' ) ) 
  3429. $append = true; 
  3430.  
  3431. if ( false !== $this->pagination_total && ( $header || 1 != $this->total_found ) ) { 
  3432. $singular_label = strtolower( $this->item ); 
  3433. $plural_label = strtolower( $this->items ); 
  3434. ?> 
  3435. <span class="displaying-num"><?php echo number_format_i18n( $this->total_found ) . ' ' . _n( $singular_label, $plural_label, $this->total_found, 'pods' ) . $this->extra[ 'total' ]; ?></span> 
  3436. <?php 
  3437.  
  3438. if ( false !== $this->pagination ) { 
  3439. if ( 1 < $total_pages ) { 
  3440. ?> 
  3441. <a class="first-page<?php echo esc_attr( ( 1 < $this->page ) ? '' : ' disabled' ); ?>" title="<?php esc_attr_e( 'Go to the first page', 'pods' ); ?>" href="<?php echo esc_url( $request_uri . ( $append ? '&' : '?' ) . 'pg' . $this->num . '=1' ); ?>">«</a> 
  3442. <a class="prev-page<?php echo esc_attr( ( 1 < $this->page ) ? '' : ' disabled' ); ?>" title="<?php esc_attr_e( 'Go to the previous page', 'pods' ); ?>" href="<?php echo esc_url( $request_uri . ( $append ? '&' : '?' ) . 'pg' . $this->num . '=' . max( $this->page - 1, 1 ) ); ?>">‹</a> 
  3443. <?php 
  3444. if ( true == $header ) { 
  3445. ?> 
  3446. <span class="paging-input"><input class="current-page" title="<?php esc_attr_e( 'Current page', 'pods' ); ?>" type="text" name="pg<?php echo esc_attr( $this->num ); ?>" value="<?php echo esc_attr( $this->page ); ?>" size="<?php echo esc_attr( strlen( $total_pages ) ); ?>"> <?php _e( 'of', 'pods' ); ?> <span class="total-pages"><?php echo $total_pages; ?></span></span> 
  3447. <script> 
  3448.  
  3449. jQuery( document ).ready( function ( $ ) { 
  3450. var pageInput = $( 'input.current-page' ); 
  3451. var currentPage = pageInput.val(); 
  3452. pageInput.closest( 'form' ).submit( function ( e ) { 
  3453. if ( 
  3454. ( 1 > $( 'select[name="action<?php echo esc_attr( $this->num ); ?>"]' ).length 
  3455. || $( 'select[name="action<?php echo esc_attr( $this->num ); ?>"]' ).val() == -1 ) 
  3456. && ( 1 > $( 'select[name="action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).length 
  3457. || $( 'select[name="action_bulk<?php echo esc_attr( $this->num ); ?>"]' ).val() == -1 ) 
  3458. && pageInput.val() == currentPage ) { 
  3459. pageInput.val( '1' ); 
  3460. } ); 
  3461. } ); 
  3462. </script> 
  3463. <?php 
  3464. else { 
  3465. ?> 
  3466. <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> 
  3467. <?php 
  3468. ?> 
  3469. <a class="next-page<?php echo esc_attr( ( $this->page < $total_pages ) ? '' : ' disabled' ); ?>" title="<?php esc_attr_e( 'Go to the next page', 'pods' ); ?>" href="<?php echo esc_url( $request_uri . ( $append ? '&' : '?' ) . 'pg' . $this->num . '=' . min( $this->page + 1, $total_pages ) ); ?>">›</a> 
  3470. <a class="last-page<?php echo esc_attr( ( $this->page < $total_pages ) ? '' : ' disabled' ); ?>" title="<?php esc_attr_e( 'Go to the last page', 'pods' ); ?>'" href="<?php echo esc_url( $request_uri . ( $append ? '&' : '?' ) . 'pg' . $this->num . '=' . $total_pages ); ?>">»</a> 
  3471. <?php 
  3472.  
  3473. /** 
  3474. * @param bool $options 
  3475. * @return mixed 
  3476. */ 
  3477. public function limit ( $options = false ) { 
  3478. if ( false !== $this->callback( 'limit', $options ) ) { 
  3479. return null; 
  3480.  
  3481. if ( false === $options || !is_array( $options ) || empty( $options ) ) 
  3482. $options = array( 10, 25, 50, 100, 200 ); 
  3483.  
  3484. if ( !in_array( $this->limit, $options ) && -1 != $this->limit ) 
  3485. $this->limit = $options[ 1 ]; 
  3486.  
  3487. foreach ( $options as $option ) { 
  3488. if ( $option == $this->limit ) 
  3489. echo ' <span class="page-numbers current">' . esc_html( $option ) . '</span>'; 
  3490. else 
  3491. echo ' <a href="' . esc_url( pods_query_arg( array( 'limit' => $option ), array( 'orderby' . $this->num, 'orderby_dir' . $this->num, 'search' . $this->num, 'filter_*', 'page' . $this->num ), $this->exclusion() ) ) . '">' . esc_html( $option ) . '</a>'; 
  3492.  
  3493. /** 
  3494. * @param $code 
  3495. * @param bool|array $row 
  3496. * @return mixed 
  3497. */ 
  3498. public function do_template ( $code, $row = false ) { 
  3499. if ( is_object( $this->pod ) && 1 == 0 && 0 < $this->pod->id() ) 
  3500. return $this->pod->do_magic_tags( $code ); 
  3501. else { 
  3502. if ( false !== $row ) { 
  3503. $this->temp_row = $this->row; 
  3504. $this->row = $row; 
  3505.  
  3506. $code = preg_replace_callback( "/({@(.*?)})/m", array( $this, "do_magic_tags" ), $code ); 
  3507.  
  3508. if ( false !== $row ) { 
  3509. $this->row = $this->temp_row; 
  3510. unset( $this->temp_row ); 
  3511.  
  3512. return $code; 
  3513.  
  3514. /** 
  3515. * @param $tag 
  3516. * @return string 
  3517. */ 
  3518. public function do_magic_tags ( $tag ) { 
  3519. if ( is_array( $tag ) ) { 
  3520. if ( !isset( $tag[ 2 ] ) && strlen( trim( $tag[ 2 ] ) ) < 1 ) 
  3521. return ''; 
  3522.  
  3523. $tag = $tag[ 2 ]; 
  3524.  
  3525. $tag = trim( $tag, ' {@}' ); 
  3526. $tag = explode( ', ', $tag ); 
  3527.  
  3528. if ( empty( $tag ) || !isset( $tag[ 0 ] ) || strlen( trim( $tag[ 0 ] ) ) < 1 ) 
  3529. return null; 
  3530.  
  3531. foreach ( $tag as $k => $v ) { 
  3532. $tag[ $k ] = trim( $v ); 
  3533.  
  3534. $field_name = $tag[ 0 ]; 
  3535.  
  3536. $value = $this->get_field( $field_name ); 
  3537.  
  3538. if ( isset( $tag[ 1 ] ) && !empty( $tag[ 1 ] ) && is_callable( $tag[ 1 ] ) ) 
  3539. $value = call_user_func_array( $tag[ 1 ], array( $value, $field_name, $this->row, &$this ) ); 
  3540.  
  3541. $before = $after = ''; 
  3542.  
  3543. if ( isset( $tag[ 2 ] ) && !empty( $tag[ 2 ] ) ) 
  3544. $before = $tag[ 2 ]; 
  3545.  
  3546. if ( isset( $tag[ 3 ] ) && !empty( $tag[ 3 ] ) ) 
  3547. $after = $tag[ 3 ]; 
  3548.  
  3549. if ( 0 < strlen( $value ) ) 
  3550. return $before . $value . $after; 
  3551.  
  3552. return null; 
  3553.  
  3554. /** 
  3555. * @param bool|array $exclude 
  3556. * @param bool|array $array 
  3557. */ 
  3558. public function hidden_vars ( $exclude = false, $array = false ) { 
  3559. $exclude = $this->do_hook( 'hidden_vars', $exclude, $array ); 
  3560. if ( false === $exclude ) 
  3561. $exclude = array(); 
  3562. if ( !is_array( $exclude ) ) 
  3563. $exclude = explode( ', ', $exclude ); 
  3564. $get = $_GET; 
  3565. if ( is_array( $array ) ) { 
  3566. foreach ( $array as $key => $val ) { 
  3567. if ( 0 < strlen( $val ) ) 
  3568. $get[ $key ] = $val; 
  3569. else 
  3570. unset( $get[ $key ] ); 
  3571. foreach ( $get as $k => $v ) { 
  3572. if ( in_array( $k, $exclude ) ) 
  3573. continue; 
  3574.  
  3575. if ( is_array( $v ) ) { 
  3576. foreach ( $v as $vk => $vv ) { 
  3577. ?> 
  3578. <input type="hidden" name="<?php echo esc_attr( $k ); ?>[<?php echo esc_attr( $vk ); ?>]" value="<?php echo esc_attr( $vv ); ?>" /> 
  3579. <?php 
  3580. else { 
  3581. ?> 
  3582. <input type="hidden" name="<?php echo esc_attr( $k ); ?>" value="<?php echo esc_attr( $v ); ?>" /> 
  3583. <?php 
  3584.  
  3585. /** 
  3586. * @return array 
  3587. */ 
  3588. public function exclusion () { 
  3589. $exclusion = self::$excluded; 
  3590.  
  3591. foreach ( $exclusion as $k => $exclude ) { 
  3592. $exclusion[ $k ] = $exclude . $this->num; 
  3593.  
  3594. return $exclusion; 
  3595.  
  3596. public function restricted ( $action = 'edit', $row = null ) { 
  3597. $restricted = false; 
  3598.  
  3599. $restrict = array(); 
  3600.  
  3601. if ( isset( $this->restrict[ $action ] ) ) 
  3602. $restrict = (array) $this->restrict[ $action ]; 
  3603.  
  3604. // @todo Build 'edit', 'duplicate', 'delete' action support for 'where' which runs another find() query 
  3605. /**if ( !in_array( $action, array( 'manage', 'reorder' ) ) ) { 
  3606. $where = pods_var_raw( $action, $this->where, null, null, true ); 
  3607.   
  3608. if ( !empty( $where ) ) { 
  3609. $restricted = true; 
  3610.   
  3611. $old_where = $this->where[ $action ]; 
  3612.   
  3613. $id = $this->row[ $this->sql[ 'field_id' ] ]; 
  3614.   
  3615. if ( is_array( $where ) ) { 
  3616. if ( 'OR' == pods_var( 'relation', $where ) ) 
  3617. $where = array( $where ); 
  3618.   
  3619. $where[] = "`t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id; 
  3620. else 
  3621. $where = "( {$where} ) AND `t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id; 
  3622.   
  3623. $this->where[ $action ] = $where; 
  3624.   
  3625. $data = false; 
  3626.   
  3627. //$data = $this->get_data(); 
  3628.   
  3629. $this->where[ $action ] = $old_where; 
  3630.   
  3631. if ( empty( $data ) ) 
  3632. $restricted = true; 
  3633. }*/ 
  3634.  
  3635. $author_restrict = false; 
  3636.  
  3637. if ( !empty( $this->restrict[ 'author_restrict' ] ) && $restrict === $this->restrict[ 'author_restrict' ] ) { 
  3638. $restricted = false; 
  3639.  
  3640. $author_restrict = true; 
  3641.  
  3642. if ( is_object( $this->pod ) ) { 
  3643. $restricted = true; 
  3644.  
  3645. if ( 'settings' == $this->pod->pod_data[ 'type' ] && 'add' == $action ) 
  3646. $action = 'edit'; 
  3647.  
  3648. if ( pods_is_admin( array( 'pods', 'pods_content' ) ) ) 
  3649. $restricted = false; 
  3650. elseif ( 'manage' == $action ) { 
  3651. if ( !in_array( 'edit', $this->actions_disabled ) && current_user_can( 'pods_edit_' . $this->pod->pod ) && current_user_can( 'pods_edit_others_' . $this->pod->pod ) ) 
  3652. $restricted = false; 
  3653. elseif ( !in_array( 'delete', $this->actions_disabled ) && current_user_can( 'pods_delete_' . $this->pod->pod ) && current_user_can( 'pods_delete_others_' . $this->pod->pod ) ) 
  3654. $restricted = false; 
  3655. elseif ( current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) && current_user_can( 'pods_' . $action . '_others_' . $this->pod->pod ) ) 
  3656. $restricted = false; 
  3657. elseif ( current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) && current_user_can( 'pods_' . $action . '_others_' . $this->pod->pod ) ) 
  3658. $restricted = false; 
  3659. /** @todo determine proper logic for non-pods capabilities 
  3660. else { 
  3661. $restricted = true; 
  3662.   
  3663. if ( pods_is_admin( array( 'pods', 'pods_content' ) ) ) 
  3664. $restricted = false; 
  3665. elseif ( current_user_can( 'pods_' . $action . '_others_' . $_tbd ) ) 
  3666. $restricted = false; 
  3667. }*/ 
  3668.  
  3669. if ( $restricted && !empty( $restrict ) ) { 
  3670. $relation = strtoupper( trim( pods_var( 'relation', $restrict, 'AND', null, true ) ) ); 
  3671.  
  3672. if ( 'AND' != $relation ) 
  3673. $relation = 'OR'; 
  3674.  
  3675. $okay = true; 
  3676.  
  3677. foreach ( $restrict as $field => $match ) { 
  3678. if ( 'relation' == $field ) 
  3679. continue; 
  3680.  
  3681. if ( is_array( $match ) ) { 
  3682. $match_okay = true; 
  3683.  
  3684. $match_relation = strtoupper( trim( pods_var( 'relation', $match, 'OR', null, true ) ) ); 
  3685.  
  3686. if ( 'AND' != $match_relation ) 
  3687. $match_relation = 'OR'; 
  3688.  
  3689. foreach ( $match as $the_field => $the_match ) { 
  3690. if ( 'relation' == $the_field ) 
  3691. continue; 
  3692.  
  3693. $value = null; 
  3694.  
  3695. if ( is_object( $this->pod ) ) 
  3696. $value = $this->pod->field( $the_match, true ); 
  3697. else { 
  3698. if ( empty( $row ) ) 
  3699. $row = $this->row; 
  3700.  
  3701. if ( isset( $row[ $the_match ] ) ) { 
  3702. if ( is_array( $row[ $the_match ] ) ) { 
  3703. if ( false !== strpos( $the_match, '.' ) ) { 
  3704. $the_matches = explode( '.', $the_match ); 
  3705.  
  3706. $value = $row[ $the_match ]; 
  3707.  
  3708. foreach ( $the_matches as $m ) { 
  3709. if ( is_array( $value ) && isset( $value[ $m ] ) ) 
  3710. $value = $value[ $m ]; 
  3711. else { 
  3712. $value = null; 
  3713.  
  3714. break; 
  3715. else 
  3716. $value = $row[ $the_match ]; 
  3717.  
  3718. if ( is_array( $value ) ) { 
  3719. if ( !in_array( $the_match, $value ) ) 
  3720. $match_okay = false; 
  3721. elseif ( 'OR' == $match_relation ) { 
  3722. $match_okay = true; 
  3723.  
  3724. break; 
  3725. elseif ( $value == $the_match ) 
  3726. $match_okay = false; 
  3727. elseif ( 'OR' == $match_relation ) { 
  3728. $match_okay = true; 
  3729.  
  3730. break; 
  3731.  
  3732. if ( !$match_okay ) 
  3733. $okay = false; 
  3734. if ( 'OR' == $relation ) { 
  3735. $okay = true; 
  3736.  
  3737. break; 
  3738. else { 
  3739. $value = null; 
  3740.  
  3741. if ( is_object( $this->pod ) ) 
  3742. $value = $this->pod->field( $match, true ); 
  3743. else { 
  3744. if ( empty( $row ) ) 
  3745. $row = $this->row; 
  3746.  
  3747. if ( isset( $row[ $match ] ) ) { 
  3748. if ( is_array( $row[ $match ] ) ) { 
  3749. if ( false !== strpos( $match, '.' ) ) { 
  3750. $matches = explode( '.', $match ); 
  3751.  
  3752. $value = $row[ $match ]; 
  3753.  
  3754. foreach ( $matches as $m ) { 
  3755. if ( is_array( $value ) && isset( $value[ $m ] ) ) 
  3756. $value = $value[ $m ]; 
  3757. else { 
  3758. $value = null; 
  3759.  
  3760. break; 
  3761. else 
  3762. $value = $row[ $match ]; 
  3763.  
  3764. if ( is_array( $value ) ) { 
  3765. if ( !in_array( $match, $value ) ) 
  3766. $okay = false; 
  3767. elseif ( 'OR' == $relation ) { 
  3768. $okay = true; 
  3769.  
  3770. break; 
  3771. elseif ( $value != $match ) 
  3772. $okay = false; 
  3773. elseif ( 'OR' == $relation ) { 
  3774. $okay = true; 
  3775.  
  3776. break; 
  3777.  
  3778. if ( !empty( $author_restrict ) ) { 
  3779. if ( is_object( $this->pod ) && 'manage' == $action ) { 
  3780. if ( !in_array( 'edit', $this->actions_disabled ) && !current_user_can( 'pods_edit_' . $this->pod->pod ) && !in_array( 'delete', $this->actions_disabled ) && !current_user_can( 'pods_delete_' . $this->pod->pod ) ) 
  3781. $okay = false; 
  3782. if ( is_object( $this->pod ) && !current_user_can( 'pods_' . $action . '_' . $this->pod->pod ) ) 
  3783. $okay = false; 
  3784. /** @todo determine proper logic for non-pods capabilities 
  3785. elseif ( !current_user_can( 'pods_' . $action . '_' . $_tbd ) ) 
  3786. $okay = false;*/ 
  3787.  
  3788. if ( !$okay && !empty( $row ) ) { 
  3789. foreach ( $this->restrict[ 'author_restrict' ] as $key => $val ) { 
  3790. $author_restricted = $this->get_field( $key ); 
  3791.  
  3792. if ( !empty( $author_restricted ) ) { 
  3793. if ( !is_array( $author_restricted ) ) 
  3794. $author_restricted = (array) $author_restricted; 
  3795.  
  3796. if ( is_array( $val ) ) { 
  3797. foreach ( $val as $v ) { 
  3798. if ( in_array( $v, $author_restricted ) ) 
  3799. $okay = true; 
  3800. elseif ( in_array( $val, $author_restricted ) ) 
  3801. $okay = true; 
  3802.  
  3803. if ( $okay ) 
  3804. $restricted = false; 
  3805.  
  3806. if ( isset( $this->actions_custom[ $action ] ) && is_array( $this->actions_custom[ $action ] ) && isset( $this->actions_custom[ $action ][ 'restrict_callback' ] ) && is_callable( $this->actions_custom[ $action ][ 'restrict_callback' ] ) ) { 
  3807. $restricted = call_user_func( $this->actions_custom[ $action ][ 'restrict_callback' ], $restricted, $restrict, $action, $row, $this ); 
  3808.  
  3809. $restricted = $this->do_hook( 'restricted_' . $action, $restricted, $restrict, $action, $row ); 
  3810.  
  3811. return $restricted; 
  3812.  
  3813. /** 
  3814. * Check for a custom action callback and run it 
  3815. * @return bool|mixed 
  3816. */ 
  3817. public function callback() { 
  3818.  
  3819. $args = func_get_args(); 
  3820.  
  3821. if ( empty( $args ) ) { 
  3822. return false; 
  3823.  
  3824. $action = array_shift( $args ); 
  3825.  
  3826. // Do hook 
  3827. $callback_args = $args; 
  3828. array_unshift( $callback_args, null ); 
  3829. array_unshift( $callback_args, $action ); 
  3830.  
  3831. $callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args ); 
  3832.  
  3833. if ( null === $callback ) { 
  3834. $callback = false; 
  3835.  
  3836. $args[] = $this; 
  3837.  
  3838. if ( isset( $this->actions_custom[ $action ] ) ) { 
  3839. if ( is_array( $this->actions_custom[ $action ] ) && isset( $this->actions_custom[ $action ][ 'callback' ] ) && is_callable( $this->actions_custom[ $action ][ 'callback' ] ) ) { 
  3840. $callback = call_user_func_array( $this->actions_custom[ $action ][ 'callback' ], $args ); 
  3841. elseif ( is_callable( $this->actions_custom[ $action ] ) ) { 
  3842. $callback = call_user_func_array( $this->actions_custom[ $action ], $args ); 
  3843.  
  3844. return $callback; 
  3845.  
  3846.  
  3847. /** 
  3848. * Check for a custom action callback and run it (deprecated reverse arg order) 
  3849. * @return bool|mixed 
  3850. */ 
  3851. public function callback_action() { 
  3852.  
  3853. $args = func_get_args(); 
  3854.  
  3855. if ( empty( $args ) ) { 
  3856. return false; 
  3857.  
  3858. $action = array_shift( $args ); 
  3859.  
  3860. $deprecated = false; 
  3861.  
  3862. if ( is_bool( $action ) ) { 
  3863. $deprecated = $action; 
  3864.  
  3865. $action = array_shift( $args ); 
  3866.  
  3867. // Do hook 
  3868. $callback_args = $args; 
  3869. array_unshift( $callback_args, null ); 
  3870. array_unshift( $callback_args, 'action_' . $action ); 
  3871.  
  3872. $callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args ); 
  3873.  
  3874. if ( null === $callback ) { 
  3875. $callback = false; 
  3876.  
  3877. $args[] = $this; 
  3878.  
  3879. // Deprecated reverse arg order 
  3880. if ( $deprecated ) { 
  3881. $args = array_reverse( $args ); 
  3882.  
  3883. if ( isset( $this->actions_custom[ $action ] ) ) { 
  3884. if ( is_array( $this->actions_custom[ $action ] ) && isset( $this->actions_custom[ $action ][ 'callback' ] ) && is_callable( $this->actions_custom[ $action ][ 'callback' ] ) ) { 
  3885. $callback = call_user_func_array( $this->actions_custom[ $action ][ 'callback' ], $args ); 
  3886. elseif ( is_callable( $this->actions_custom[ $action ] ) ) { 
  3887. $callback = call_user_func_array( $this->actions_custom[ $action ], $args ); 
  3888.  
  3889. return $callback; 
  3890.  
  3891.  
  3892. /** 
  3893. * Check for a bulk action callback and run it 
  3894. * @return bool|mixed Callback result 
  3895. */ 
  3896. public function callback_bulk() { 
  3897.  
  3898. $args = func_get_args(); 
  3899.  
  3900. if ( empty( $args ) ) { 
  3901. return false; 
  3902.  
  3903. $action = array_shift( $args ); 
  3904.  
  3905. $deprecated = false; 
  3906.  
  3907. if ( is_bool( $action ) ) { 
  3908. $deprecated = $action; 
  3909.  
  3910. $action = array_shift( $args ); 
  3911.  
  3912. // Do hook 
  3913. $callback_args = $args; 
  3914. array_unshift( $callback_args, null ); 
  3915. array_unshift( $callback_args, 'bulk_action_' . $action ); 
  3916.  
  3917. $callback = call_user_func_array( array( $this, 'do_hook' ), $callback_args ); 
  3918.  
  3919. if ( null === $callback ) { 
  3920. $callback = false; 
  3921.  
  3922. $args[] = $this; 
  3923.  
  3924. // Deprecated reverse arg order 
  3925. if ( $deprecated ) { 
  3926. $args = array_reverse( $args ); 
  3927.  
  3928. if ( isset( $this->actions_bulk[ $action ] ) ) { 
  3929. if ( is_array( $this->actions_bulk[ $action ] ) && isset( $this->actions_bulk[ $action ][ 'callback' ] ) && is_callable( $this->actions_bulk[ $action ][ 'callback' ] ) ) { 
  3930. $callback = call_user_func_array( $this->actions_bulk[ $action ][ 'callback' ], $args ); 
  3931. elseif ( is_callable( $this->actions_bulk[ $action ] ) ) { 
  3932. $callback = call_user_func_array( $this->actions_bulk[ $action ], $args ); 
  3933.  
  3934. return $callback; 
  3935.  
  3936.  
  3937. /** 
  3938. // Example code for use with $this->do_hook 
  3939. public function my_filter_function ($args, $obj) { 
  3940. $obj[0]->item = 'Post'; 
  3941. $obj[0]->add = true; 
  3942. // args are an array (0 => $arg1, 1 => $arg2) 
  3943. // may have more than one arg, dependant on filter 
  3944. return $args; 
  3945. add_filter('pods_ui_post_init', 'my_filter_function', 10, 2); 
  3946. */ 
  3947. /** 
  3948. * @return array|bool|mixed|null 
  3949. */ 
  3950. private function do_hook() { 
  3951.  
  3952. $args = func_get_args(); 
  3953.  
  3954. if ( empty( $args ) ) { 
  3955. return false; 
  3956.  
  3957. $name = array_shift( $args ); 
  3958.  
  3959. return pods_do_hook( "ui", $name, $args, $this ); 
  3960.