Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • this will pull the first image of the post if thumb is not available

    replace the “DD_Pinterest” class in digg-digg\include\dd-class.php with following code:

    [ 199 lines of code moderated. For more than 10 lines of code please pastebin.com instead. ]

    ^^^ this will pull the first image of the post if thumb is not available

    replace the “DD_Pinterest” class in digg-digg\include\dd-class.php with following code:

    class DD_Pinterest extends BaseDD{

    const NAME = “Pinterest”;

    const URL_WEBSITE = “https://pinterest.com”;

    const URL_API = “https://pinterest.com/about/goodies/#button_for_websites”;

    const DEFAULT_BUTTON_WEIGHT = “10”;

    const BASEURL = ‘<script type=”text/javascript” src=”https://assets.pinterest.com/js/pinit.js”></script>&#8217;;

    const BASEURL_LAZY = ‘‘;

    const BASEURL_LAZY_SCRIPT = “function loadPinterest_POST_ID(){ jQuery(document).ready(function(\$) { \$.getScript(‘https://assets.pinterest.com/js/pinit.js&#8217;); }); }”;

    const SCHEDULER_LAZY_SCRIPT = “window.setTimeout(‘loadPinterest_POST_ID()’,SCHEDULER_TIMER);”;

    const SCHEDULER_LAZY_TIMER = “1000”;

    const OPTION_APPEND_TYPE = “dd_pinterest_appendType”;

    const OPTION_BUTTON_DESIGN = “dd_pinterest_buttonDesign”;

    const OPTION_BUTTON_WEIGHT = “dd_pinterest_button_weight”;

    const OPTION_AJAX_LEFT_FLOAT = “dd_pinterest_ajax_left_float”;

    const OPTION_LAZY_LOAD = “dd_pinterest_lazy_load”;

    var $buttonLayout = array(

    “Normal” => “vertical”,

    “Compact” => “horizontal”,

    “No Count” => “none”

    );

    var $buttonLayoutLazy = array(

    “Normal” => “vertical”,

    “Compact” => “horizontal”,

    “No Count” => “none”

    );

    public function DD_Pinterest() {

    $this->option_append_type = self::OPTION_APPEND_TYPE;

    $this->option_button_design = self::OPTION_BUTTON_DESIGN;

    $this->option_button_weight = self::OPTION_BUTTON_WEIGHT;

    $this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;

    $this->option_lazy_load = self::OPTION_LAZY_LOAD;

    $this->baseURL_lazy = self::BASEURL_LAZY;

    $this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;

    $this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;

    $this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;

    $this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;

    parent::BaseDD(self::NAME, self::URL_WEBSITE, self::URL_API, self::BASEURL);

    }

    //construct base URL, based on $lazy value

    public function constructURL($url, $title, $button, $postId, $lazy, $globalcfg = ”){

    //rawurlencode – replace space with %20

    //urlencode – replace space with +

    if($this->isEncodeRequired) {

    $title = rawurlencode($title);

    $url = rawurlencode($url);

    }

    if($lazy==DD_EMPTY_VALUE || $lazy==false){

    $this->constructNormalURL($url, $title,$button, $postId);

    }else{

    $this->constructLazyLoadURL($url, $title,$button, $postId);

    }

    }

    public function getFirstPostImage($postId){
    //Get url of img and compare width and height

    $post = get_post($postId);

    $output = preg_match_all( ‘/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, $post->post_content, $matches );

    $first_img = $matches [1] [0];

    return $first_img;

    }

    public function constructNormalURL($url, $title,$button, $postId){

    $finalURL = $this->baseURL;

    $finalURL = str_replace(self::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$finalURL);

    $finalURL = str_replace(self::VOTE_TITLE,$title,$finalURL);

    $finalURL = str_replace(self::VOTE_URL,$url,$finalURL);

    $finalURL = str_replace(parent::POST_ID,$postId,$finalURL);

    $finalURL = str_replace(parent::VOTE_TITLE,$title,$finalURL);

    $finalURL = str_replace(parent::VOTE_URL,$url,$finalURL);

    if(current_theme_supports(‘post-thumbnails’)) $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($postId), ‘thumbnail’ );

    else $thumb = false;

    if($thumb){
    $image = $thumb[0];
    }
    else{
    $image = $this->getFirstPostImage($postId);
    }
    /*echo “<script>alert(‘”.$image.”‘);</script>”;*/

    $finalURL = str_replace(parent::VOTE_IMAGE,$image,$finalURL);

    $this->finalURL = $finalURL;

    }

    public function constructLazyLoadURL($url, $title,$button, $postId){

    $finalURL_lazy = $this->baseURL_lazy;

    $finalURL_lazy = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesignLazy($button),$finalURL_lazy);

    $finalURL_lazy = str_replace(parent::POST_ID,$postId,$finalURL_lazy);

    $finalURL_lazy = str_replace(parent::VOTE_TITLE,$title,$finalURL_lazy);

    $finalURL_lazy = str_replace(parent::VOTE_URL,$url,$finalURL_lazy);

    if(current_theme_supports(‘post-thumbnails’)) $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($postId), ‘thumbnail’ );

    else $thumb = false;

    if($thumb){
    $image = $thumb[0];
    }
    else{
    $image = $this->getFirstPostImage($postId);
    }
    /*echo “<script>alert(‘LAZY’);</script>”;*/
    $finalURL_lazy = str_replace(parent::VOTE_IMAGE,$image,$finalURL_lazy);

    $this->finalURL_lazy = $finalURL_lazy;

    $finalURL_lazy_script = $this->baseURL_lazy_script;

    $finalURL_lazy_script = str_replace(parent::VOTE_TITLE,$title,$finalURL_lazy_script);

    $finalURL_lazy_script = str_replace(parent::VOTE_URL,$url,$finalURL_lazy_script);

    $finalURL_lazy_script = str_replace(parent::POST_ID,$postId,$finalURL_lazy_script);

    $this->finalURL_lazy_script = $finalURL_lazy_script;

    $final_scheduler_lazy_script = $this->scheduler_lazy_script;

    $final_scheduler_lazy_script = str_replace(parent::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$final_scheduler_lazy_script);

    $final_scheduler_lazy_script = str_replace(parent::POST_ID,$postId,$final_scheduler_lazy_script);

    $this->final_scheduler_lazy_script = $final_scheduler_lazy_script;

    }

    }

Viewing 3 replies - 1 through 3 (of 3 total)