rendered paste body<?php/*Plugin Name: Video LibraryVersion: 0.1 alphaPlugin URI: http://massanti.com/Description: Helps in the process of creating a video library based in wordpress pages.Author: Diego MassantiAuthor URI: http://www.massanti.com*/add_action('edit_page_form', 'pageForm');// Init Settings$mediaPath = '/home/massanti/public_html/media';$httpPath = 'http://massanti.com/media';function pageForm() { global $post_ID; ?> <h2>Video Library Options</h2> <div id="stckd_options" class="postbox if-js-closed"> <h3>Active Video</h3> <div class="inside"> <table id="stckd" cellspacing="3" cellpadding="3"> <tbody> <tr> <td>Active video for this page:</td> <td> <?php echo createVideoSelect(get_post_meta($post_ID,'_videolibrary_video_item', true)); ?> </td> <td style="width:10%;background-color:<?php echo get_post_meta($post_ID,'_videolibrary_video_item', true);?>" id="_stckd_post_color_display"></td> </tr> </tbody> </table> </div> </div><?php } ?><?phpfunction createVideoSelect($selected) { global $mediaPath; $videos = recur_dir($mediaPath); $output = '<select id="_videolibrary_video_item" tabindex="7" name="_videolibrary_video_item">'; $output .= '<option value="">- No video selected! -</option>'; foreach ($videos as $video) { if ($selected == $video['name']) { $output .= '<option selected value="'.$video['name'].'">'.$video['name'].'</option>'; } else { if ($video['kind'] == 'dir') { $output .= '<optgroup style="background-color:cyan;" label="↓ DIR: '.$video['name'].'">'; foreach ($video['content'] as $subVideo) { $wholePath = $video['name'].'/'.$subVideo['name']; if ($selected == $wholePath) { $output .= '<option selected value="'.$video['name'].'/'.$subVideo['name'].'">→ '.$subVideo['name'].'</option>'; } else { $output .= '<option value="'.$video['name'].'/'.$subVideo['name'].'">→ '.$subVideo['name'].'</option>'; } } $output .= '</optgroup>'; } else { $output .= '<option value="'.$video['name'].'">'.$video['name'].'</option>'; } } } $output .= '</select>'; return $output; }function recur_dir($dir){ $dirlist = opendir($dir); while ($file = readdir ($dirlist)) { if ($file != '.' && $file != '..') { $newpath = $dir.'/'.$file; $level = explode('/',$newpath); if (is_dir($newpath)) { $mod_array[] = array( 'level'=>count($level)-1, 'path'=>$newpath, 'name'=>end($level), 'kind'=>'dir', 'mod_time'=>filemtime($newpath), 'content'=>recur_dir($newpath)); }else{ $mod_array[] = array( 'level'=>count($level)-1, 'path'=>$newpath, 'name'=>end($level), 'kind'=>'file', 'mod_time'=>filemtime($newpath), 'size'=>filesize($newpath)); } } } closedir($dirlist); asort($mod_array); return $mod_array;}// Functions to store the custom field:add_action('edit_post', 'add_vl_field');add_action('publish_post', 'add_vl_field');add_action('save_post', 'add_vl_field');add_action('edit_page_form', 'add_vl_field');function add_vl_field($id) { //delete the existing field delete_post_meta($id, '_videolibrary_video_item'); //Get the value from your form $userEnteredValue = $_POST["_videolibrary_video_item"]; //Add your value as a custom field with the key 'myKey' //but only if the form data exists if (isset($userEnteredValue) && !empty ($userEnteredValue)){ add_post_meta($id, '_videolibrary_video_item', $userEnteredValue);}}// frontend functionsfunction vl_video_link($id) { global $httpPath; $video = get_post_meta($id, '_videolibrary_video_item', true); return "<a href=\"$httpPath/$video\">Click</a>";}function vl_video_url($id) { global $httpPath; $video = get_post_meta($id, '_videolibrary_video_item', true); return "$httpPath/$video";}?>