Example #1
0
 public static function truncate_for_summary($width, $value) {
   $length = 110 + (($width - 1) * 130);
   return WOOF::truncate_advanced($value, $length, $etc = ' … ', false, true);
 }
Example #2
0
  public static function ui( MEOW_Field $field ) {

    global $wf;

    $prop_inputs = self::prop_inputs($field, "attachment_id");

    $prop_source_url = $field->prop("source_url");
    
    $no_file = __("( no file )", MASTERPRESS_DOMAIN);

    $empty = "";
    $filename = "";
    $filesize = "";
    $filetype = "";
    $fileurl = "";
    $filetype_class = "";
    $filename_trunc = "";
    $filetype_trunc = "";

    $summary_filename_trunc = "";
    $summary_filetype_trunc = "";

    
    if (!$field->blank()) {
      $file = $field->file();

      if ($file && $file->exists()) {

        $filename = $file->basename();
        $filesize = $file->filesize();
        $filetype = $file->filetype();

        if ($file->is_external()) {
          $fileurl = $field->value();
        } else {
          $fileurl = $file->permalink();
        }
        
        $filetype_class = "file-type file-type-".$file->extension();

        $filename_trunc = WOOF::truncate_advanced($filename, 37, $etc = ' … ', false, true);
        $filetype_trunc = WOOF::truncate_advanced($filetype, 36, $etc = ' … ', false, true);

        $summary_filename_trunc = WOOF::truncate_advanced($filename, 26, $etc = ' … ', false, true);
        $summary_filetype_trunc = WOOF::truncate_advanced($filetype, 25, $etc = ' … ', false, true);

      }
    } else {

      $empty = "empty";
      $filename = $no_file;
      $filename_trunc = $no_file;

    }

    $replace_image_label = __("Replace File:", MASTERPRESS_DOMAIN);
    $choose_image_label = __("Choose File:", MASTERPRESS_DOMAIN);

    $url_label = __("Enter File URL:", MASTERPRESS_DOMAIN);

    $button_view_download_label = __("View / Download", MASTERPRESS_DOMAIN);
    $button_delete_label = __("Delete", MASTERPRESS_DOMAIN);

    $button_from_computer_label = __("From Computer…", MASTERPRESS_DOMAIN);
    $button_from_media_library_label = __("From Media Library…", MASTERPRESS_DOMAIN);
    $button_from_url_label = __("From URL…", MASTERPRESS_DOMAIN);
    $button_from_existing_uploads_label = __("From Existing Uploads…", MASTERPRESS_DOMAIN);

    $button_clear_label = __("Clear", MASTERPRESS_DOMAIN);
    $button_delete_label = __("Delete", MASTERPRESS_DOMAIN);

    $button_download_label = __("Download", MASTERPRESS_DOMAIN);
    $button_cancel_label = __("Cancel", MASTERPRESS_DOMAIN);

    $button_clear_title = __("Clear field without deleting the file", MASTERPRESS_DOMAIN);
    $button_delete_title = __("Clear field and delete the file", MASTERPRESS_DOMAIN);

    $drop_label = __("Drop file here to upload", MASTERPRESS_DOMAIN);

    $base_url = MASTERPRESS_CONTENT_URL;
    $dir = 'uploads/';

    $media_library_progress_message = __("Fetching URL from Media Library...", MASTERPRESS_DOMAIN);
    $upload_progress_message = __("Uploading...", MASTERPRESS_DOMAIN);
    $fetching_info_message = __("Fetching File Information...", MASTERPRESS_DOMAIN);
    $dowloading_progress_message = __("Downloading File...", MASTERPRESS_DOMAIN);

    
    $upload_html = "";
    $download_html = "";
    $file_controls_html = "";
    $labels_html = "";
    $controls_html = "";
    
    $drop_html = "";
    
    if ($wf->the_user->can("upload_files") && $field->is_editable()) {
      
      $controls_html = <<<HTML
      
      <div class="choose-controls">

        <h5 class="replace-label">{$replace_image_label}</h5>
        <h5 class="choose-label">{$choose_image_label}</h5>

        <div class="buttons">

          <div class="file-uploader { input: '#{{id}}', inputName: '{{id}}_file', ids: { drop: '{{id}}_drop_area' }, base_url: '{$base_url}', params: { dir: '{$dir}' }, limit: 1, lang: { buttonChoose: '{$button_from_computer_label}', buttonReplace: '{$button_from_computer_label}' } }">
            <input id="{{id}}" name="{{name}}" value="{$fileurl}" type="hidden" class="value" autocomplete="off" />
            <div class="uploader-ui"></div>
          </div>
          <!-- /.file-uploader -->

          <button type="button" class="button button-small button-from-url">{$button_from_url_label}</button> 
          <button type="button" class="button button-small button-from-media-library">{$button_from_media_library_label}</button>

        </div>

      </div>
      
      
HTML;

      $file_controls_html = <<<HTML
      
      <div class="file-controls">
        <ul>
          <li><button type="button" type="button" class="text with-icon view">{$button_view_download_label}</button></li>
          <li><button type="button" type="button" class="text with-icon clear">{$button_clear_label}</button></li>
        </ul>
      </div>
      
HTML;

      $drop_html = <<<HTML
      <div id="{{id}}_drop_area" class="drop-area">{$drop_label}</div>
HTML;

    } else {
      
      $controls_html = <<<HTML
      <input id="{{id}}" name="{{name}}" value="{$fileurl}" type="hidden" class="value" autocomplete="off" />
HTML;
      
    }
    
    $html = <<<HTML


    <div class="summary">
      <span class="name" title="{$filename}">{$summary_filename_trunc}</span>
      <span class="type-size"><span class="type" title="{$filetype}">{$summary_filetype_trunc}</span>
      <br><span class="size">{$filesize}</span></span>
    </div>

    <div class="ui-state {$empty}">

    {$prop_inputs}

    <a href="{$fileurl}" class="file-info" tabindex="-1" target="_blank">

      {$drop_html}

      <h4 class="name"><i class="{$filetype_class}"></i>{$filename_trunc}</h4>
      <ul class="prop">
        <li class="filetype">{$filetype}</li>
        <li class="filesize">{$filesize}</li>
      </ul>

    </a>
    <!-- /.file-info -->

    {$file_controls_html}

    <div class="media-library-progress">
      <span class="fetching-message progress-message">{$media_library_progress_message}</span>  
      <span class="fetching-info-message progress-message">{$fetching_info_message}</span>  
    </div>
    <!-- /.media-library-progress -->
      
    <div class="upload-progress">

      <div class="upload-progress-well">
        <span class="name"><i></i></span>

        <div class="progress-bar-with-val">
          <div class="progress-bar"><div class="border"><div><span class="bar">&nbsp;</span></div></div></div>
          <div class="val">0%</div>
        </div>

      </div>

      <span class="uploading-message progress-message">{$upload_progress_message}</span>  
      <span class="fetching-info-message progress-message">{$fetching_info_message}</span>  

    </div>
    <!-- /.upload-progress -->

    {$controls_html}



    <div class="from-url-ui">
      <label for="{{id}}-url">{$url_label}</label>
      <input id="{{prop_id}}-source_url" name="{{prop_name}}[source_url]" type="text" value="{$prop_source_url}" class="text url" />

      <div class="buttons">
        <button type="button" class="button button-small download">{$button_download_label}</button>
        <button type="button" class="button button-small cancel">{$button_cancel_label}</button>
      </div>
    </div>
    <!-- /.from-url -->

    <div class="download-progress">
      <span class="downloading-message progress-message">{$dowloading_progress_message}</span>  
      <span class="fetching-info-message progress-message">{$fetching_info_message}</span>  
    </div>
    <!-- /.download-progress -->



    </div>
    <!-- /.ui-state -->

HTML;

    return $html;

  }
Example #3
0
  public static function ui( MEOW_Field $field ) {

    global $wf;
    
    // $field here is a MEOW_Field, which is a class that encapsulates the value of a field AND the info associated with it

    $options = $field->info->type_options;

    $readonly = WOOF_HTML::readonly_attr( !$field->is_editable() );

    $no_url = __("( no URL entered )", MASTERPRESS_DOMAIN);
    $url_label = __("URL:", MASTERPRESS_DOMAIN);

    $button_refresh = __("Refresh Info", MASTERPRESS_DOMAIN);
    
    $fetching_info_message = __("Fetching video info&hellip; please wait", MASTERPRESS_DOMAIN);

    $visit_video_title = __("Visit video page", MASTERPRESS_DOMAIN);

    $watch_video_title = __("Watch video", MASTERPRESS_DOMAIN);
    
    $style = "";

    if (isset($options["height"]) && is_numeric($options["height"])) {
      $style .= "height: ".$options["height"]."px;";
    }

    $watch_url = "";
    $video_url = "";
    $host = "";
    $title = "";
    $value = "";
    $video_id = "";
    
    $empty = "empty";
    
    if (!$field->blank()) {
      $value = htmlspecialchars($field->value());
      $empty = "";
      $video_id = $field->prop("video_id");
      $host = $field->prop("host");

      $title = $field->prop("title");
      
      if ($title == "") {
        $empty = "empty";
      }
      
      if ($video_id && $video_id != "") {
        list($watch_url, $video_url) = self::urls($video_id, $host);
      }
      
    }

    $prop_inputs = self::prop_inputs($field, self::ui_prop());

    $summary_thumb = "";
    $thumb = "";
    
    
    $prop_title = $field->prop("title");
    $prop_host = $field->prop("host");
    $prop_duration = $field->prop("duration");
    $prop_published = self::format_date($field->prop("published"));
    $prop_updated = self::format_date($field->prop("updated"));
    $prop_thumbnail = $field->prop_val("thumbnail");
    
    $published_style = "";
    $updated_style = "";
    
    if ($field->prop("published") == "") {
      $published_style = ' style="display:none;" ';
    }

    if ($field->prop("updated") == "") {
      $updated_style = ' style="display:none;" ';
    }
    
    $prop_video_id = $field->prop("video_id");
      
    $display_title = WOOF::truncate_advanced($prop_title, 60, $etc = ' &hellip; ', false, true);
    $summary_display_title = WOOF::truncate_advanced($prop_title, 50, $etc = ' &hellip; ', false, true);


    $host_name = self::host_name($prop_host);
    
    
    list($tw, $th) = array(120, 90);
    list($stw, $sth) = array(84, 63);

    $orientation = "square";

    $thumb = WOOF_Image::empty_mp_thumb(array("w" => $tw, "h" => $th, "no_image" => $no_url, "class" => "managed thumb") );
    $summary_thumb = WOOF_Image::empty_mp_thumb(array("w" => $stw, "h" => $sth, "no_image" => $no_url, "class" => "managed summary-thumb" ) );


    if ($prop_thumbnail && $prop_thumbnail != "") {
      $img = $wf->image_from_url($prop_thumbnail);
      
      if ($img && $img->exists()) {

        $watermark = MPU::type_image("video", "play-overlay.png");
        $watermark_args = array("at" => "c", "h" => "60%");

        $thumb = $img->mp_thumb(array("w" => $tw, "h" => $th, "no_image" => $no_url, "watermark" => $watermark, "watermark_args" => $watermark_args, "link_attr" => array("class" => "thumb iframe", "href" => $watch_url), "class" => "thumb managed") );
        $summary_thumb = $img->mp_thumb(array("w" => $stw, "h" => $sth, "no_image" => $no_url, "class" => "managed summary-thumb", "thumb_only" => true ) );
      }
    
    }
    
    $html = <<<HTML

    <div class="state {$empty}">

      {$prop_inputs}

      <div class="summary-content">
        
        {$summary_thumb}
      
        <div class="summary-info">
          <span class="title">{$summary_display_title}</span>
          <span class="host"><span class="host-type {$prop_host}"><span class="host-name">{$host_name}</span><span class="duration">({$prop_duration})</span></span></span>
        </div>
      
      </div>
      
      <div class="ui-content">
       
      {$thumb}
      
      <div class="url-info">
        
        <div class="f f-url">
          <label for="{{id}}" class="{prop_host}">{$url_label}</label>
          <input id="{{id}}" name="{{name}}" autocomplete="off" {$readonly} type="text" value="{$value}" class="url text" />
        </div>
          
        <div class="info">

          <span class="error-message"><i></i>error</span>  
          
          <span class="fetching-info-message progress-message">{$fetching_info_message}</span>  

          <div class="title">
            <a href="{$video_url}" target="_blank" title="{$visit_video_title}" class="{$prop_host} title-link">{$display_title}</a>
            <button class="text refresh with-icon" title="{$button_refresh}" type="button">{$button_refresh}</button>
          </div>
        
          <div class="prop-wrap">
            
            
            <ul class="prop">
              <li class="duration">{$prop_duration}</li>
              <li class="published" {$published_style}>Published: <span class="val">{$prop_published}</span></li>
              <li class="updated" {$updated_style}>Updated: <span class="val">{$prop_updated}</span></li>
            </ul>
          </div>
        
          
        </div>
        
      </div>
      
      </div>

    </div>
    <!-- /.state -->

HTML;

    return $html;

  }