Plugin Directory

Changeset 1509023


Ignore:
Timestamp:
10/05/2016 11:50:05 PM (9 years ago)
Author:
molven
Message:

OSmedi aplugin version 2.2

Location:
os-media/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • os-media/trunk/OSmedia-functions.php

    r1297200 r1509023  
    1 <?php ////////////////////////////////////
    2 
     1<?php
     2// OS media WP plugin FUNCTIONS /////////////////////////////////////////////////////////////////////////
    33
    44if ( ! function_exists( 'OSmedia_video' ) ) :
     
    2121}
    2222endif;
    23 
    2423
    2524////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    111110
    112111}
    113 
    114 /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    115 PRESO DA :
    116 http://stackoverflow.com/questions/157318/resumable-downloads-when-using-php-to-send-the-file/4451376#4451376
    117 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    118 
    119 function serve_file_resumable ($file, $contenttype = 'application/octet-stream') {
    120 
    121     // Avoid sending unexpected errors to the client - we should be serving a file,
    122     // we don't want to corrupt the data we send
    123     @error_reporting(0);
    124 
    125     // Make sure the files exists, otherwise we are wasting our time
    126     if (!file_exists($file)) {
    127       header("HTTP/1.1 404 Not Found");
    128       exit;
    129     }
    130 
    131     // Get the 'Range' header if one was sent
    132     if (isset($_SERVER['HTTP_RANGE'])) $range = $_SERVER['HTTP_RANGE']; // IIS/Some Apache versions
    133     else if ($apache = apache_request_headers()) { // Try Apache again
    134       $headers = array();
    135       foreach ($apache as $header => $val) $headers[strtolower($header)] = $val;
    136       if (isset($headers['range'])) $range = $headers['range'];
    137       else $range = FALSE; // We can't get the header/there isn't one set
    138     } else $range = FALSE; // We can't get the header/there isn't one set
    139 
    140     // Get the data range requested (if any)
    141     $filesize = filesize($file);
    142     if ($range) {
    143       $partial = true;
    144       list($param,$range) = explode('=',$range);
    145       if (strtolower(trim($param)) != 'bytes') { // Bad request - range unit is not 'bytes'
    146         header("HTTP/1.1 400 Invalid Request");
    147         exit;
    148       }
    149       $range = explode(',',$range);
    150       $range = explode('-',$range[0]); // We only deal with the first requested range
    151       if (count($range) != 2) { // Bad request - 'bytes' parameter is not valid
    152         header("HTTP/1.1 400 Invalid Request");
    153         exit;
    154       }
    155       if ($range[0] === '') { // First number missing, return last $range[1] bytes
    156         $end = $filesize - 1;
    157         $start = $end - intval($range[0]);
    158       } else if ($range[1] === '') { // Second number missing, return from byte $range[0] to end
    159         $start = intval($range[0]);
    160         $end = $filesize - 1;
    161       } else { // Both numbers present, return specific range
    162         $start = intval($range[0]);
    163         $end = intval($range[1]);
    164         if ($end >= $filesize || (!$start && (!$end || $end == ($filesize - 1)))) $partial = false; // Invalid range/whole file specified, return whole file
    165       }     
    166       $length = $end - $start + 1;
    167     } else $partial = false; // No range requested
    168 
    169     // Send standard headers
    170     header("Content-Type: $contenttype");
    171     header("Content-Length: $filesize");
    172     header('Content-Disposition: attachment; filename="'.basename($file).'"');
    173     header('Accept-Ranges: bytes');
    174 
    175     // if requested, send extra headers and part of file...
    176     if ($partial) {
    177       header('HTTP/1.1 206 Partial Content');
    178       header("Content-Range: bytes $start-$end/$filesize");
    179       if (!$fp = fopen($file, 'r')) { // Error out if we can't read the file
    180         header("HTTP/1.1 500 Internal Server Error");
    181         exit;
    182       }
    183       if ($start) fseek($fp,$start);
    184       while ($length) { // Read in blocks of 8KB so we don't chew up memory on the server
    185         $read = ($length > 8192) ? 8192 : $length;
    186         $length -= $read;
    187         print(fread($fp,$read));
    188       }
    189       fclose($fp);
    190     } else readfile($file); // ...otherwise just send the whole file
    191 
    192     // Exit here to avoid accidentally sending extra content on the end of the file
    193     exit;
    194 
    195 }
    196 */
    197 
    198 ?>
  • os-media/trunk/classes/OSmedia-post-admin.php

    r1300766 r1509023  
    294294                $s3 = new S3($OSmedia_s3access, $OSmedia_s3secret);
    295295                $s3_array = $s3->getBucket($OSmedia_s3bucket);
    296                 if($s3_array) $monitor_server['s3'] = 'ok'; elseif(!$s3_url) $monitor_server['s3'] = 'unset'; else $monitor_server['s3'] = 'error';
     296                if($s3_array) $monitor_server['s3'] = 'ok';
     297                elseif(!$s3_url) $monitor_server['s3'] = 'unset';
     298                else $monitor_server['s3'] = 'error';
     299               
    297300                if( $s3_array ) {
    298301                // array forma [file]=>path_file
     
    300303                        $file = str_replace( $OSmedia_s3dir, '', $vv['name']); // toglie la directory s3 dal nome del file
    301304                        // $file = preg_replace( '/\.[^.]+$/', '', $file ); // SANITIZE
    302                         if( $file ) $s3_list[$file] = $s3_url;
     305                        if( $file ) $s3_list[$file] = 3;
    303306                    }
    304307                   
     
    317320                            // $value = preg_replace( '/\.[^.]+$/', '', $value );
    318321                            // if ( $value != '.' && $value != '..' )
    319                                 $path_list[$value] = ''; // $dir /*. $value*/;
     322                                $path_list[$value] = 1; // $dir /*. $value*/;
    320323                        }
    321324                        $monitor_server['path'] = 'ok';
     
    340343                    preg_match_all("/(a href\=\")([^\?\"]*)(\")/i", $content, $res);
    341344                    // array forma [file]=>path_file senza ext
    342                     // DA VERIFICARE !!!!!!
    343345                    foreach ($res[2] as $val) {
    344                         // $value = preg_replace( '/\.[^.]+$/', '', $value );
    345                         if ( $val != '.' && $val != '..' ) $url_list[$val] = $url /*. $val*/;
     346                        $val = pathinfo($val)['basename'];
     347                        if ( $val != '.' && $val != '..' ) $url_list[$val] = 2 /*. $val*/;
    346348                    }
    347349                    $monitor_server['url'] = 'ok';
     
    355357            // unisce i 3 risultati
    356358            $file_list = $s3_list;
    357             if( !empty($path_list) ) foreach( $path_list as $k2 => $v2 ) $file_list[$k2] = $v2;
    358             if( !empty($url_list) ) foreach( $url_list as $k3 => $v3 ) $file_list[$k3] = $v3;           
     359            if( !empty($path_list) )
     360                foreach( $path_list as $k2 => $v2 ) $file_list[$k2] = $v2;
     361            if( !empty($url_list) )
     362                foreach( $url_list as $k3 => $v3 ) $file_list[$k3] = $v3;           
    359363
    360364            // SANITIZE
     
    392396
    393397            $result['monitor_server'] = $monitor_server;
    394 
    395             // echo 'ARRAY_S3: <pre>'; print_r($monitor_server); echo '</pre>'; // MONITOR
    396             // echo 'ARRAY_PATH: <pre>'; print_r($path_list); echo '</pre>'; // MONITOR
    397             // echo 'ARRAY_URL: <pre>'; print_r($url_list); echo '</pre>'; // MONITOR
    398             // echo 'RESULT: <pre>'; print_r($result); echo '</pre>'; // MONITOR   
     398            // MONITOR
     399            // echo 'OPTIONS: <pre>'; print_r($options); echo '</pre>';
     400            // echo 'ARRAY_S3: <pre>'; print_r($monitor_server); echo '</pre>';
     401            // echo 'ARRAY_PATH: <pre>'; print_r($path_list); echo '</pre>';
     402            // echo 'ARRAY_URL: <pre>'; print_r($url_list); echo '</pre>';
     403            // echo 'RESULT: <pre>'; print_r($result); echo '</pre>';   
    399404
    400405            return $result;
     
    435440                    if ( array_key_exists($k, $meta_values ) )
    436441                        $out[$k] = $meta_values[$k];
    437                     // else $out[$k] = $v;
     442                    else    $out[$k] = $v;
    438443                }
    439444                // carica i POSTMETA di questo plugin, aggiungo i valori con chiavi che NON ci sono già in $out..
     
    449454            }           
    450455
    451             // echo '<pre> DATA_MODEL: post_id->'.$post_id.'  ';var_dump($out);  echo '</pre>'; // MONITOR
     456            // echo 'post_id->'.$post_id.'<br>DATA_MODEL: <pre>'; print_r($out);  echo '</pre>'; // MONITOR
    452457            return $out;
    453458        }
     
    516521            ///////////////// MONITOR
    517522            // foreach ($variables as $mon_k => $mon_atts) if( $mon_atts !='' ) $mon[$mon_k] = $mon_atts; // nasconde valori nulli
    518             // echo '<pre style="font-size:12px"> --->post_type: '.get_post_type($post->ID).' -->GET_POSTMETA: '; var_dump($variables); echo '</pre>';
     523            // echo '<pre style="font-size:12px"> --->post_type: '.get_post_type($post->ID).' -->GET_POSTMETA: '; print_r($variables); echo '</pre>';
    519524            // echo '<br>--------- max upload file size ----->'.ini_get('post_max_size');
    520525            /////////////////////////
  • os-media/trunk/classes/OSmedia-post-frontend.php

    r1300766 r1509023  
    165165            // FILE controller (HTML5)
    166166            if ( isset($atts['file']) && $atts['file'] != '' ) $file = $atts['file']; else $file = '';
    167             if ( isset($atts['fileurl']) && $atts['fileurl'] != '' ) $url = OSmedia_path_sanitize($atts['fileurl']); else $url = '';
    168            
    169             if( $file != '' && $url == '' )     // local file
    170                 $filepath = plugins_url( OSmedia_FOLDER ) . "/videostream.php?file=";
    171             elseif( $file != '' && $url != '' ) // remote file
    172                 $filepath = $url;
    173             else                                // no filepath (direct url)
    174                 $filepath = '';
     167
     168            switch ($atts['fileurl']) {
     169                case 1:
     170                    if(isset($options['OSmedia_path']) && $options['OSmedia_path'] != ''){
     171                        $url_img = OSmedia_path_sanitize($options['OSmedia_path']);
     172                        $filepath = plugins_url( OSmedia_FOLDER ) . "/videostream.php?file=";
     173                    }else{
     174                        $filepath = $url_img = OSmedia_path_sanitize($options['OSmedia_url']);
     175                    }
     176                    break;
     177                case 2:
     178                    if(isset($options['OSmedia_url']) && $options['OSmedia_url'] != ''){
     179                        $filepath = $url_img = OSmedia_path_sanitize($options['OSmedia_url']);
     180                    }else{
     181                        $url_img = OSmedia_path_sanitize($options['OSmedia_path']);
     182                        $filepath = plugins_url( OSmedia_FOLDER ) . "/videostream.php?file=";
     183                    }
     184                    break;
     185                case 3:
     186                    $s3_url = $url_img = $options['OSmedia_s3server'] . $options['OSmedia_s3bucket'] . '/' . $options['OSmedia_s3dir'];
     187                    $filepath = $url_img = OSmedia_path_sanitize($s3_url);
     188                    break;
     189                default:
     190                    // RETROCOMPATIBILITA'
     191                    if( substr($atts['fileurl'], 0, 7) == 'http://' || substr($atts['fileurl'], 0, 8) == 'https://'){ // caso 2 e 3
     192                        $filepath = $url_img = OSmedia_path_sanitize($atts['fileurl']);
     193                    }elseif( !isset($atts['fileurl']) || $atts['fileurl'] == '' ){ // caso 1
     194                        $filepath = plugins_url( OSmedia_FOLDER ) . "/videostream.php?file=";
     195                        $url_img = OSmedia_path_sanitize($options['OSmedia_path']);
     196                    }                                       
     197            }
    175198
    176199            if( $file && $filepath ) {
     
    203226            // CPT
    204227            if( $cpt_flag ){
     228                // if(isset($url_img)) $filepath = $url_img;
    205229                // if ( $file && $filepath && $file != '' && $filepath != '' && @getimagesize($filepath . $file . ".jpg") ) $atts['img'] = $filepath . $file. ".jpg";
    206230                $post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
     
    249273            $atts['flag_cpt'] = $cpt_flag;
    250274
     275            // echo '<br><br><br>'.$filepath;
     276            // echo '<pre> ATTS:'; var_dump($atts); echo '</pre>';
    251277            // return apply_filters( 'OSmedia_validate_shortcode_attributes', $atts );
    252278            return $atts;
  • os-media/trunk/javascript/OSmedia.js

    r1297200 r1509023  
    2828         */
    2929        registerEventHandlers: function () {   
    30 
     30                       
     31            // flag input change SELECT/INPUT for video file selection
     32            $('#flag_input').change(function() {
     33                if($("select#OSmedia_file").is(":visible")){
     34                    $('select#OSmedia_file').hide();
     35                    $('select#OSmedia_file').prop('disabled', true);
     36                    $('input#OSmedia_file').show();
     37                    $('input#OSmedia_file').prop('disabled', false);
     38                }else{
     39                    $('input#OSmedia_file').hide();
     40                    $('input#OSmedia_file').prop('disabled', true);
     41                    $('select#OSmedia_file').show();
     42                    $('select#OSmedia_file').prop('disabled', false);
     43                }
     44            });
     45            // selezione server       
    3146            $("#OSmedia_file").change(function() {
    32                 sel_url = $(this).find(':selected').attr('data-url');           
    33                 $("#OSmedia_fileurl").val(sel_url);
     47                if($("select#OSmedia_file").is(":visible")) {
     48                    var sel_url = $(this).find(':selected').attr('data-url');           
     49                    $("#OSmedia_fileurl").val(sel_url);
     50                }
    3451            });
     52                       
    3553            $( '#gen_shortcode' ).click( OSmedia.genShortcode );
    3654            $( '#reset_btn' ).click( OSmedia.resetForm );
     
    5169
    5270            var shortcode = '['+shortcode_name;
     71            // selezione file
     72            if($("select#OSmedia_file").is(":visible")){
     73                name_file = $('select#OSmedia_file').val();
     74            }else if($("input#OSmedia_file").is(":visible")){
     75                name_file = $('input#OSmedia_file').val(); 
     76                $("#OSmedia_fileurl").val(2); // input manuale fa riferimento sempre al server 2           
     77            }
    5378            // input items
    5479            var input_items =  {
    55                 file:       $('#OSmedia_file').val(),
     80                file:       name_file,
    5681                fileurl:    $('#OSmedia_fileurl').val(),
    5782                mp4:        $('#OSmedia_mp4').val(),
  • os-media/trunk/readme.txt

    r1305099 r1509023  
    44Plugin URI: http://www.mariomarino.eu/en/os-media-wordpress-video-plugin/
    55Tested up to: 4.4
    6 Stable tag: 2.1
     6Stable tag: 2.2
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7979== Changelog ==
    8080
     81= 2.2 =
     82* dinamically URL select from setting.
     83* add manual video-file input for extenal server.
     84* fixed bug in file url external server
     85
    8186= 2.1 =
    8287* Optimized OS-media theme integration.
  • os-media/trunk/views/OSmedia-postmeta/metabox.php

    r1297200 r1509023  
    88
    99<ul class="server-monitor-list">
    10     <li><b>OSmedia File Server Monitor:</b></li>
    11     <li class="<?php echo $monitor_server['path'] ?>">1 - local video path: <span><?php echo $monitor_server['path'] ?></span></li>
    12     <li class="<?php echo $monitor_server['url'] ?>">2 - video server url: <span><?php echo $monitor_server['url'] ?></span></li>
    13     <li class="<?php echo $monitor_server['s3'] ?>">3 - S3 server: <span><?php echo $monitor_server['s3'] ?></span></li>
     10    <li><b>FILE SERVER:</b></li>
     11    <li class="<?php echo $monitor_server['path'] ?>"><b>1</b> - local (path): <span><?php echo $monitor_server['path'] ?></span></li>
     12    <li class="<?php echo $monitor_server['url'] ?>"><b>2</b> - remote (url): <span><?php echo $monitor_server['url'] ?></span></li>
     13    <li class="<?php echo $monitor_server['s3'] ?>"><b>3</b> - Amazon S3: <span><?php echo $monitor_server['s3'] ?></span></li>
    1414</ul>
    1515
    1616<table class="metabox_table">
    1717<thead></thead>
    18     <th>video identification</th>
    19     <th>on-fly local upload (MAX upload file-size: <?php echo ini_get('post_max_size') ?>)</th>
     18    <th>video identification</th>
     19    <th>on-fly local upload (MAX upload file-size: <?php echo ini_get('post_max_size') ?>)</th>
    2020<tr>
    21     <td>
     21    <td>
    2222
    23     <?php if ( !empty($video_list) ) : ; // $file_explode = explode('|', $OSmedia_file); ?>
     23    <?php if ( (!empty($video_list) && array_key_exists($OSmedia_file, $video_list)) || $OSmedia_file == '' ) : ?>
     24       
     25        <p class="metacheck">   
     26            <input id="flag_input" type="checkbox" />
     27            <label for="OSmedia_yt_related"><?php _e('manual name-file input (only for server 2)', 'OSmedia_player') ?></label>
     28        </p>
    2429
    25         <select id="OSmedia_file" name="OSmedia_file">
     30        <select id="OSmedia_file" name="OSmedia_file">
     31            <option class="default_opt" value="" <?php if( !array_key_exists($OSmedia_file, $video_list)) echo " selected='selected' "; ?>> </option>
     32            <?php foreach ($video_list as $key => $value) : ?>
     33        <option value="<?php echo $key ?>" <?php if( $OSmedia_file == $key ) echo " selected='selected' "; ?> data-url="<?php echo $value ?>"><?php echo $key ?></option>
     34            <?php endforeach ?>
     35        </select>
     36           
     37        <input id="OSmedia_file" name="OSmedia_file" style="display:none" type="text" size="15" placeholder="file without ext" value="<?php echo $OSmedia_file; ?>" />
    2638
    27             <option class="default_opt" value="" <?php if( !array_key_exists($OSmedia_file, $video_list)) echo " selected='selected' "; ?>> </option>
    28             <?php foreach ($video_list as $key => $value) : ?>
    29             <option value="<?php echo $key ?>" <?php if( $OSmedia_file == $key ) echo " selected='selected' "; ?> data-url="<?php echo $value ?>">
    30                 <?php echo $key ?>
    31             </option>
    32             <?php endforeach ?>
     39    <?php elseif( (!empty($video_list) && !in_array($OSmedia_file, $video_list)) || empty($video_list) ) : ?>
     40       
     41        <p class="metacheck">   
     42            <input id="flag_input" type="checkbox" checked="on" />
     43            <label for="OSmedia_yt_related"><?php _e('manual name-file input (only for server 2)', 'OSmedia_player') ?></label>
     44        </p>
     45       
     46        <select id="OSmedia_file" name="OSmedia_file" style="display:none">
     47            <option class="default_opt" value="" <?php if( !array_key_exists($OSmedia_file, $video_list)) echo " selected='selected' "; ?>> </option>
     48            <?php foreach ($video_list as $key => $value) : ?>
     49        <option value="<?php echo $key ?>" <?php if( $OSmedia_file == $key ) echo " selected='selected' "; ?> data-url="<?php echo $value ?>"><?php echo $key ?></option>
     50            <?php endforeach ?>
     51        </select>
     52           
     53        <input id="OSmedia_file" name="OSmedia_file" type="text" size="15" placeholder="file without ext" value="<?php echo $OSmedia_file; ?>" />
     54           
     55    <?php endif ?>
    3356
    34         </select>
    35 
    36     <?php else : ?>
    37 
    38     <input id="OSmedia_file" name="OSmedia_file" type="text" size="15" placeholder="file without ext" value="<?php echo $OSmedia_file; ?>" />
    39 
    40     <?php endif ?>
    41 
    42     <laber for="OSmedia_file"><?php _e( 'file', 'OSmedia_player' ) ?> <?php if( isset($server_no) ) echo "(server {$server_no})" ?></label>
     57    <laber for="OSmedia_file"><?php _e( 'file', 'OSmedia_player' ) ?> <?php // if( isset($server_no) ) echo "(server {$server_no})" ?></label>
    4358
    4459    <input id="OSmedia_fileurl" name="OSmedia_fileurl" type="hidden" value="<?php if( isset($OSmedia_fileurl) ) echo $OSmedia_fileurl ?>" />
Note: See TracChangeset for help on using the changeset viewer.