예제 #1
0
 function widget($args, $instance)
 {
     try {
         extract($args, EXTR_SKIP);
         self::log(str_pad(" BEGIN {$widget_id} ", 72, '-', STR_PAD_BOTH));
         self::log("DEBUG[{$widget_id}] - Frontend Initalization");
         $title = esc_attr($instance['title']);
         $type = esc_attr($instance['type']);
         $deviant = esc_attr($instance['deviant']);
         $items = intval($instance['items']);
         $rating = esc_attr($instance['rating']);
         $html = intval($instance['html']);
         $filter = intval($instance['filter']);
         self::log("DEBUG[{$widget_id}] - Cache is " . (get_option('cache-enabled') ? 'enabled' : 'disabled') . " (duration : " . get_option('cache-duration') . ")");
         self::log("DEBUG[{$widget_id}] - Thumnbails are " . (get_option('thumb-enabled') ? 'enabled' : 'disabled') . ' (size : ' . get_option('thumb-size-x') . 'x' . get_option('thumb-size-y') . ')');
         self::log("DEBUG[{$widget_id}] - Config : " . print_r($instance, true));
         echo $before_widget;
         echo $before_title . $title . $after_title;
         if (get_option('cache-enabled')) {
             $fragment = 'wp-content/cache' . DIRECTORY_SEPARATOR . 'da-widgets-' . sha1(serialize($instance)) . '.html.gz';
             $duration = sprintf('+%d minutes', get_option('cache-duration'));
             $cache = new Cache(ABSPATH . $fragment, $duration);
             self::log("DEBUG[{$widget_id}] - Cache fragment : " . $fragment);
         }
         if (!$cache || $cache->start()) {
             self::log("DEBUG[{$widget_id}] - Generating content");
             switch ($type) {
                 case self::DA_WIDGET_LOG:
                     $res = new DeviantArt_Log($deviant, $html);
                     $body = $res->get($items);
                     break;
                 case self::DA_WIDGET_GALLERY:
                     $res = new DeviantArt_Gallery($deviant);
                     $body = $res->get($items, $rating, $filter);
                     break;
                 case self::DA_WIDGET_FAVOURITE:
                     $res = new DeviantArt_Favourite($deviant);
                     $body = $res->get($items, $rating, $filter);
                     break;
             }
             self::log("DEBUG[{$widget_id}] - Preparing content : {$body}");
             if (in_array($type, array(self::DA_WIDGET_GALLERY, self::DA_WIDGET_FAVOURITE)) && get_option('thumb-enabled')) {
                 self::log("DEBUG[{$widget_id}] - Generating thumbnails");
                 // Creating Thumbnail cache
                 if (preg_match_all('/\\t?\\ssrc="([^"]*\\.(?:jpg|gif|png))"/x', $body, $m)) {
                     switch (get_option('thumb-format')) {
                         case IMG_PNG:
                             $ext = 'png';
                             break;
                         case IMG_GIF:
                             $ext = 'gif';
                             break;
                         case IMG_JPG:
                             $ext = 'jpg';
                             break;
                     }
                     foreach ($m[1] as $picture) {
                         $thumbfile = 'wp-content/cache' . DIRECTORY_SEPARATOR . 'da-widgets-' . sha1($picture) . '.' . $ext;
                         // TODO : Update this old image library
                         if (!file_exists(ABSPATH . $thumbfile)) {
                             $thumb = Image::CreateFromFile($picture);
                             Image::Resize($thumb, get_option('thumb-size-x') * 2, get_option('thumb-size-y') * 2);
                             Image::Crop($thumb, get_option('thumb-size-x'), get_option('thumb-size-y'), false, false, IMAGE_ALIGN_CENTER | IMAGE_ALIGN_CENTER);
                             if (is_writeable(dirname(ABSPATH . $thumbfile))) {
                                 Image::Output($thumb, IMAGE_OUTPUTMODE_FILE, get_option('thumb-format'), ABSPATH . $thumbfile);
                             }
                         }
                         self::log("DEBUG[{$widget_id}] - > " . $picture . ' => ' . $thumbfile);
                         if (is_file(ABSPATH . $thumbfile)) {
                             $body = str_replace($picture, get_bloginfo('wpurl') . '/' . $thumbfile . '" width="' . get_option('thumb-size-x') . 'px" height="' . get_option('thumb-size-y') . 'px', $body);
                         }
                     }
                 }
             }
             echo $body;
             self::log("DEBUG[{$widget_id}] - Output content : {$body}");
             if ($cache) {
                 $cache->end();
             }
         }
         echo $after_widget;
     } catch (Exception $ex) {
         self::log("ERROR[{$widget_id}] - " . get_class($ex) . ' - ' . $ex->getMessage() . ' (' . $ex->getCode() . ')');
     }
     self::log(str_pad(" END {$widget_id} ", 72, '-', STR_PAD_BOTH));
 }
예제 #2
0
 function widget($args, $instance)
 {
     try {
         extract($args, EXTR_SKIP);
         $title = esc_attr($instance['title']);
         $type = esc_attr($instance['type']);
         $deviant = esc_attr($instance['deviant']);
         $html = intval($instance['html']);
         $items = intval($instance['items']);
         $rating = esc_attr($instance['rating']);
         echo $before_widget;
         echo $before_title . $title . $after_title;
         if (get_option('cache-enabled')) {
             $fragment = rtrim(get_option('cache-path'), '/') . DIRECTORY_SEPARATOR . 'da-widgets-' . sha1(serialize($instance)) . '.html.gz';
             $duration = sprintf('+%d minutes', get_option('cache-duration'));
             $cache = new Cache($fragment, $duration);
         }
         if (!$cache || $cache->start()) {
             switch ($type) {
                 case self::DA_WIDGET_LOG:
                     $res = new DeviantArt_Log($deviant, $html);
                     $body = $res->get($items);
                     break;
                 case self::DA_WIDGET_GALLERY:
                     $res = new DeviantArt_Gallery($deviant, $rating);
                     $body = $res->get($items);
                     break;
                 case self::DA_WIDGET_FAVOURITE:
                     $feed = new DeviantArt_Favourite($deviant, $rating);
                     $body = $feed->get($items);
                     if (get_option('thumb-enabled')) {
                         // Creating Thumbnail cache
                         if (preg_match_all('/\\t?\\ssrc="([^"]*\\.(?:jpg|gif|png))"/x', $body, $m)) {
                             switch (get_option('thumb-format')) {
                                 case IMG_PNG:
                                     $ext = 'png';
                                     break;
                                 case IMG_GIF:
                                     $ext = 'gif';
                                     break;
                                 case IMG_JPG:
                                     $ext = 'jpg';
                                     break;
                             }
                             foreach ($m[1] as $picture) {
                                 $thumbfile = get_option('thumb-path') . DIRECTORY_SEPARATOR . 'da-widgets-' . sha1($picture) . '.' . $ext;
                                 // TODO : Update this old image library
                                 if (!file_exists($thumbfile)) {
                                     $thumb = Image::CreateFromFile($picture);
                                     Image::Resize($thumb, get_option('thumb-size-x') * 2, get_option('thumb-size-y') * 2);
                                     Image::Crop($thumb, get_option('thumb-size-x'), get_option('thumb-size-y'), false, false, IMAGE_ALIGN_CENTER | IMAGE_ALIGN_CENTER);
                                     Image::Output($thumb, IMAGE_OUTPUTMODE_FILE, get_option('thumb-format'), $thumbfile);
                                 }
                                 $body = str_replace($picture, '/' . $thumbfile, $body);
                             }
                         }
                     }
                     break;
             }
             echo $body;
             if ($cache) {
                 $cache->end();
             }
         }
         echo $after_widget;
     } catch (Exception $ex) {
     }
 }