function wistiapress_shortcode_media_list($atts) { $apiKey = get_option('wistiapress_api_key'); if ($apiKey === false) return; $wistiaApi = new WistiaApi($apiKey); // Is a Project ID defined if (!isset($atts['project'])) { return 'Error: WistiaPress Media List Shortcode missing project atttribute.'; } $mediaList = $wistiaApi->mediaList($atts['project']); if (isset($mediaList->error)) { return 'Error: ' . esc_html($mediaList->error); } ob_start(); ?> <p>Right-click on the download icon and click on "Save Link As..." to download.</p> <table style="width:99%;"> <thead> <tr> <th>Video Name</th> <th style="padding-right:10px;padding-left:10px;">Duration</th> <th style="padding-right:10px;padding-left:10px;">File Size</th> <th style="padding-right:10px;padding-left:10px;text-align:center;">Right‑Click to Download</th> </tr> </thead> <tbody> <?foreach ($mediaList as $media) {?> <tr style="border-right:1px solid #ccc;"> <td><?php echo esc_html($media->name); ?></td> <td style="white-space: nowrap;text-align:center;padding-right:10px;padding-left:10px;vertical-align: middle;"><?php echo esc_html(gmdate("H:i:s", $media->duration)); ?></td> <td style="white-space: nowrap;text-align:center;padding-right:10px;padding-left:10px;vertical-align: middle;"><?php echo esc_html(wistiapress_human_filesize($media->assets[0]->fileSize)); ?></td> <td style="white-space: nowrap;text-align:center;padding-right:10px;padding-left:10px;vertical-align: middle;"><a class="wistiadownload" href="<?php echo esc_url(str_replace('.bin', '/' . urlencode(str_replace(',', '_', strtolower(str_replace(' ', '_', $media->name)))) . '.mp4', $media->assets[0]->url)); ?>"><img title="Download '<?php echo esc_attr($media->name); ?>'" alt="Download Video" src="<?php echo plugins_url( 'img/box_download.png', __FILE__ ); ?>" /></a></td> </tr> <?php } ?> </tbody> </table> <script type="text/javascript"> jQuery('.wistiadownload').click(function(e) { e.preventDefault(); alert('Right-click to download this video'); }); </script> <?php return ob_get_clean(); }
function wistiapress_settings_shortcodes_list() { $apiKey = get_option('wistiapress_api_key'); $wistiaApi = new WistiaApi($apiKey); $projects = $wistiaApi->projectList(); if (isset($projects->error)) { echo '<p><strong>Could not retrieve project list: ' . $projects->error . '</strong></p>'; return; } if (count($projects) > 0 && $projects !== null) { ?> <p>The following shortcodes can be used to list the videos in your Wistia projects:</p> <table style="width:100%;max-width:800px;border:1px solid black;border-collapse: collapse;" border="1"> <thead> <tr> <th>Project Name</th> <th># of Videos</th> <th>Shortcode</th> </tr> </thead> <tbody> <?php foreach ($projects as $project) { ?> <tr> <th style="text-align: center;"><?php echo esc_html($project->name); ?> </th> <td style="text-align: center;"><?php echo esc_html($project->mediaCount); ?> </td> <td style="text-align: center;">[wistiapress_media_list project="<?php echo $project->id; ?> "]</td> </tr> <?php } ?> </tbody> </table> <?php } }