| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
class PowerPressNetworkGrid extends PowerPressNetworkShortCode |
| 5 |
{ |
| 6 |
function __construct() |
| 7 |
{ |
| 8 |
parent::__construct('ppn-gridview'); |
| 9 |
} |
| 10 |
|
| 11 |
function ppn_shortcode($attr, $contents) |
| 12 |
{ |
| 13 |
require_once(WP_PLUGIN_DIR . '/powerpress/powerpressadmin.php'); |
| 14 |
|
| 15 |
$ctx = $this->getNetworkContext(); |
| 16 |
if (is_string($ctx)) return $ctx; |
| 17 |
|
| 18 |
$rows = $attr['rows'] ?? 1; |
| 19 |
$cols = (isset($attr['cols']) && in_array($attr['cols'], [1, 2, 3, 4, 6])) ? $attr['cols'] : 4; |
| 20 |
$disp = isset($attr['display-title']) && $attr['display-title'] == 'true'; |
| 21 |
$listId = $attr['id']; |
| 22 |
|
| 23 |
$props = []; |
| 24 |
$props['hover'] = !isset($attr['hover']) || $attr['hover'] != 'false'; |
| 25 |
$props['network_general'] = $ctx['general']; |
| 26 |
$props['network_map'] = $ctx['map']; |
| 27 |
|
| 28 |
$networkInfo = $ctx['networkInfo']; |
| 29 |
$networkInfo['list_id'] = $listId; |
| 30 |
$networkId = $networkInfo['network_id']; |
| 31 |
$networkTitle = $networkInfo['network_title']; |
| 32 |
|
| 33 |
$checkNetwork = PowerpressNetworkDataBus::getSpecificNetworkInAccount($ctx['apiUrl'], $ctx['creds'], $networkInfo, false); |
| 34 |
if (!empty($checkNetwork['error'])) { |
| 35 |
return PowerPressNetwork::getHTML('invalid-network.php', $props, null, null); |
| 36 |
} |
| 37 |
|
| 38 |
if ($listId != 'all') { |
| 39 |
$results = PowerpressNetworkDataBus::getSpecificListInNetwork($ctx['apiUrl'], $ctx['creds'], $networkInfo, false); |
| 40 |
if (!is_array($results) || empty($results['programs'])) { |
| 41 |
return PowerPressNetwork::getHTML('no-list-results.php', $props, null, null); |
| 42 |
} |
| 43 |
$props['results'] = $results['programs']; |
| 44 |
$props['list_title'] = $results['list_info']['list_title'] ?? ''; |
| 45 |
$props['list_desc'] = $results['list_info']['list_description'] ?? ''; |
| 46 |
} else { |
| 47 |
$results = PowerpressNetworkDataBus::getProgramsInNetwork($ctx['apiUrl'], $ctx['creds'], $networkInfo, false); |
| 48 |
$props['results'] = $results; |
| 49 |
$props['list_title'] = $networkTitle; |
| 50 |
$props['network_description'] = $networkInfo['network_description'] ?? ''; |
| 51 |
} |
| 52 |
|
| 53 |
$props['network_title'] = $networkTitle; |
| 54 |
$props['network_id'] = $networkId; |
| 55 |
$props['post'] = false; |
| 56 |
$props['cols'] = $cols; |
| 57 |
$props['rows'] = $rows; |
| 58 |
$props['display-title'] = $disp; |
| 59 |
$props['apiUrl'] = $ctx['apiUrl']; |
| 60 |
|
| 61 |
// filter to checked programs (for specific lists) and resolve page links |
| 62 |
$temp = null; |
| 63 |
if (!empty($props['results'])) { |
| 64 |
foreach ($props['results'] as $program) { |
| 65 |
if ($listId == 'all' || isset($program['checked']) && $program['checked'] == true) { |
| 66 |
$temp[] = $program; |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
if (!empty($temp)) { |
| 71 |
$this->resolvePageLinks($temp, $ctx['map']); |
| 72 |
} |
| 73 |
$props['results'] = $temp; |
| 74 |
|
| 75 |
if (empty($props['list_title'])) { |
| 76 |
return PowerPressNetwork::getHTML('no-list-results.php', $props, null, null); |
| 77 |
} else if (empty($props['results'])) { |
| 78 |
return PowerPressNetwork::getHTML('list-no-programs.php', $props, null, null); |
| 79 |
} else { |
| 80 |
return PowerPressNetwork::getHTML('grid-results.php', $props, null, null); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
$GLOBALS['ppn-grid'] = new PowerPressNetworkGrid(); |
| 86 |
|