Exemple #1
0
  public static function summary( MEOW_Field $field ) {

    global $wf;

    $image = "";
    
    list($stw, $sth) = array(82, 39);

    $no_image = __("( no image )", MASTERPRESS_DOMAIN);

    $empty = "empty";
    $thumb = WOOF_Image::empty_mp_thumb(array("w" => $stw, "h" => $sth, "no_image" => $no_image, "class" => "summary-thumb") );
    
    if (!$field->blank()) {
      $image = $field->file();

      if ($image && $image->exists()) {
        $width = $image->width();
        $height = $image->height();

        list($stw, $sth) = self::summary_thumb_wh($width, $height);
        
        $thumb = $image->mp_thumb(array("w" => $stw, "h" => $sth, "no_image" => $no_image, "thumb_only" => true, "class" => "summary-thumb"));

      }
    }

    $html = $thumb;

    return $html;

  }
Exemple #2
0
  public static function create_icon_sprite($color_icon, $color_icon_2x = "", $overwrite = false, $tints = array("#0F191F", "#0F1900" ) ) {

    if (!is_admin()) {
      return new WOOF_Silent( __("Cannot create icon sprites outside of admin", MASTERPRESS_DOMAIN) );
    }
    
    if (is_object($color_icon) && get_class($color_icon) == "WOOF_Image") {
      $name = $color_icon->basename();
      $color_icon_1x_path = $color_icon->path;
    } else {
      $name = $color_icon;
      $color_icon_1x_path = MASTERPRESS_CONTENT_MENU_ICONS_DIR.$color_icon;
    }

    if (is_object($color_icon_2x) && get_class($color_icon_2x) == "WOOF_Image") {
      $color_icon_2x_path = $color_icon_2x->path;
    } else {
      $color_icon_2x_path = MASTERPRESS_CONTENT_MENU_ICONS_DIR.$color_icon_2x;
    }

    $sprite_icon = self::sprite_filename($name);
    

    $sprite_icon_path = MASTERPRESS_CONTENT_MENU_ICONS_DIR.$sprite_icon;
    $sprite_icon_url = MASTERPRESS_CONTENT_MENU_ICONS_URL.$sprite_icon;
    
    $exists = self::file_exists($color_icon, $color_icon_1x_path);
    $exists_2x = self::file_exists($color_icon_2x, $color_icon_2x_path);
    
    if ( ( $exists || $exists_2x) && ( $overwrite || (!file_exists($sprite_icon_path) ) ) )  {
      
      // determine the mode - if we have both icons, we'll use both, otherwise we'll the one we have up or down
      
      if ( $exists && $exists_2x ) {

        $mode = "both";
        $src_icon_1x = $color_icon_1x_path;
        $src_icon_2x = $color_icon_2x_path;
      } else if ( $exists_2x ) {

        $mode = "2x";
        $src_icon_1x = $color_icon_2x_path;
        $src_icon_2x = $color_icon_2x_path;
      } else {
        $mode = "1x";
        $src_icon_1x = $color_icon_1x_path;
        $src_icon_2x = $color_icon_1x_path;
      }
      
      $size_1x = getimagesize($src_icon_1x);
      $size_2x = getimagesize($src_icon_2x);
      
      
      // create color handles
      
      $color_1x = self::imagecreatefromauto($src_icon_1x);
      $color_2x = self::imagecreatefromauto($src_icon_2x);
      
      // create grayscale images
      
      $grayscale_1x = self::imagecreatefromauto($src_icon_1x);
      $grayscale_2x = self::imagecreatefromauto($src_icon_2x);
      
      imagefilter($grayscale_1x, IMG_FILTER_GRAYSCALE);
      imagefilter($grayscale_2x, IMG_FILTER_GRAYSCALE);

      // create image tints
      
      $tinted_1x = array();
      $tinted_2x = array();
      
      foreach ($tints as $tint) {

        $tint_1x = self::imagecreatefromauto($src_icon_1x);
        $tint_2x = self::imagecreatefromauto($src_icon_2x);
      
        $ci = WOOF_Image::parse_color($tint);
        
        $r = $ci["rgb"][0];
        $g = $ci["rgb"][1];
        $b = $ci["rgb"][2];
        
        imagefilter($tint_1x, IMG_FILTER_GRAYSCALE);
        imagefilter($tint_1x, IMG_FILTER_COLORIZE, $r, $g, $b);
        imagefilter($tint_2x, IMG_FILTER_GRAYSCALE);
        imagefilter($tint_2x, IMG_FILTER_COLORIZE, $r, $g, $b);
        
        $tinted_1x[$tint] = $tint_1x;
        $tinted_2x[$tint] = $tint_2x;
        
      }
      
      // now compose the sprite
      
      
      // calculate dimensions

      
      $spacing = 300;

      $width = 32 + $spacing + 32 + ( count($tints) * (32 + $spacing) );
      $height = 16 + 64 + 32;
      
      
      // create the sprite handle
      
      $sprite = imagecreatetruecolor( $width, $height );
      $transparent = imagecolorallocatealpha( $sprite, 0, 0, 0, 127 ); 
      imagefill( $sprite, 0, 0, $transparent ); 

      $x = 0;

      // place the grayscale 1x and 2x

      imagecopyresampled($sprite, $grayscale_1x, $x * $spacing, 0,  0, 0, 16, 16, $size_1x[0], $size_1x[1]); 
      imagecopyresampled($sprite, $grayscale_2x, $x * $spacing, 64, 0, 0, 32, 32, $size_2x[0], $size_2x[1]); 
       
      // place the color 1x and 2x

      $x++;
       
      imagecopyresampled($sprite, $color_1x, $x * $spacing, 0,  0, 0, 16, 16, $size_1x[0], $size_1x[1]); 
      imagecopyresampled($sprite, $color_2x, $x * $spacing, 64, 0, 0, 32, 32, $size_2x[0], $size_2x[1]); 
      
      // place the tints
      
      foreach ($tints as $tint) {
        $x++;
        imagecopyresampled($sprite, $tinted_1x[$tint], $x * $spacing, 0,  0, 0, 16, 16, $size_1x[0], $size_1x[1]); 
        imagecopyresampled($sprite, $tinted_2x[$tint], $x * $spacing, 64, 0, 0, 32, 32, $size_2x[0], $size_2x[1]); 
      }
      
      // finally save the image
      
      imagesavealpha($sprite, true);
      imagepng($sprite, $sprite_icon_path);

    }

    return new WOOF_Image( $sprite_icon_path, $sprite_icon_url ); 
    

  }
Exemple #3
0
  function watermark(WOOF_Image $watermark, $attr = array()) {

    // setup default offsets, based on specified 
    
    global $wf;
    $ic = $wf->get_image_class();
    
    
    $r = wp_parse_args( $attr, array( 
      "at" => "se",
      "inset" => 10,
      "alpha" => true,
      "q" => 90
    ));

    $w = "";
    $h = "";
    
    if (isset($r["w"])) {
      $r["width"] = $r["w"];
    }

    if (isset($r["h"])) {
      $r["height"] = $r["h"];
    }
    
    if (isset($r["height"])) {
      $h = $r["height"];
    }
    
    if (isset($r["width"])) {
      $w = $r["width"];
    }
  
    if (isset($r["size"])) {
      $w = $r["size"];
    }
    
    if (isset($h)) {
      
      if (preg_match("/(\d+)%/", $h, $m)) {
        $h = round(($m[1] / 100) * $this->height());
      }
      
    }

    if (isset($w)) {
      
      if (preg_match("/(\d+)%/", $w, $m)) {
        $w = round(($m[1] / 100) * $this->width());
      }
      
    }

    $os = "";
    
    if (isset($r["offset"])) {
      $os = $r["offset"];
    }
    
    $r["suffix"] = ".mark.".md5($watermark->filepath()).".".$r["at"].$r["inset"].$os.$w.$h;

    $ci = $this->cacheinfo($r);

    if (file_exists($ci["path"]) && !isset($r["nocache"])) {

      return new $ic( $ci["path"], $ci["url"], $this->attr() );
      
    } else {

      // work out the offsets
    
      if (isset($r["offset"])) {
        $offset = self::parse_coord($r["offset"]);
      } else {
        $offset = self::get_offset($r["inset"], $r["at"]);
      }
      
      $image = WOOF_Image::load($this->filepath());

      if (isset($w) && isset($h)) {
        $watermark = $watermark->resize("w=$w&h=$h&q=".$r["q"]);
      } else if (isset($w)) {
        $watermark = $watermark->resize("w=$w&q=".$r["q"]);
      } else if (isset($h)) {
        $watermark = $watermark->resize("h=$h&q=".$r["q"]);
      }

      $wimage = WOOF_Image::load($watermark->filepath());
      
      $sw = $watermark->width();
      $sh = $watermark->height();

      $dw = $this->width();
      $dh = $this->height();

    
      // work out the position

      $coord = self::get_at_coord( $dw, $dh, $sw, $sh, $r["at"] );
      
      // get final coord 
      
      $fc = array( $coord[0] + $offset[0], $coord[1] + $offset[1] ); 
      
      // Set the margins for the stamp and get the height/width of the stamp image
      $marge_right = 10;
      $marge_bottom = 10;

      // Merge the stamp onto our photo with an opacity (transparency) of 50%
      self::imagecopymerge_alpha($image, $wimage, $fc[0], $fc[1], 0, 0, $sw, $sh, 100);
      
      if ( self::save_image( $ci["path"], $image, $this->infer_content_type($r), $attr ) ) {
        return new $ic( $ci["path"], $ci["url"], $this->attr() );
      }
      
    }

  }
Exemple #4
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… 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 = ' … ', false, true);
    $summary_display_title = WOOF::truncate_advanced($prop_title, 50, $etc = ' … ', 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;

  }