pxg 1.2.0 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/pxg.rb +39 -4
  2. metadata +1 -23
data/lib/pxg.rb CHANGED
@@ -5,7 +5,6 @@ require 'fileutils'
5
5
  # gems
6
6
  require 'git'
7
7
  require 'json'
8
- require 'xmlsimple'
9
8
 
10
9
  class Pxg
11
10
 
@@ -21,10 +20,10 @@ class Pxg
21
20
  xml_data = File.read xml
22
21
  # eg image: http://pixelgrade.com/demos/bucket/wp-content/uploads/2013/10/kelly-brooks.jpg
23
22
  # locate all images
24
- rimages = xml_data.scan /(http(s){0,1}:\/\/[^"<>]*\/[0-9]{4}\/[0-9]{2}\/[^"<>]+\.(jpg|png|tiff|gif))/
23
+ rimages = xml_data.scan /(http(s){0,1}:\/\/[^"<>]*\/[0-9]{4}\/[0-9]{2}\/[^"<>]+\.(jpg|jpeg|png|tiff|gif|webp))/
25
24
  targets = []
26
25
  rimages.each do |arr|
27
- match_data = arr[0].match /(http(s){0,1}:\/\/[^"<>]*\/)([0-9]{4}\/[0-9]{2}\/[^"<>]+\.(jpg|png|tiff|gif))/
26
+ match_data = arr[0].match /(http(s){0,1}:\/\/[^"<>]*\/)([0-9]{4}\/[0-9]{2}\/[^"<>]+\.(jpg|jpeg|png|tiff|gif|webp))/
28
27
  targets.push([match_data[0], match_data[1], arr[0].gsub(match_data[1], '')])
29
28
  end#each
30
29
 
@@ -34,7 +33,43 @@ class Pxg
34
33
  xml_data.gsub! img[2], img[2][0..7] + random_image[0]
35
34
  end#each
36
35
 
37
- puts xml_data
36
+ # split xml in parts
37
+ parts1 = xml_data.split '</generator>';
38
+ opening = parts1[0] + '</generator>'
39
+ parts2 = parts1[1].split '</channel>'
40
+ ending = '</channel>' + parts2[1]
41
+ items = parts2[0];
42
+
43
+ # split items into item array
44
+ clean_items = ''
45
+ association = {}
46
+ corrections = {}
47
+ ids = [];
48
+
49
+ guid_regex = /<guid isPermaLink=\"false\">(http(s){0,1}:\/\/[^"<>]+\.(jpg|jpeg|png|tiff|gif|webp))<\/guid>/m
50
+ id_regex = /<wp:post_id>([0-9]+)<\/wp:post_id>/m
51
+
52
+ items.split('</item>').each do |itemstr|
53
+ if itemstr =~ guid_regex
54
+ matches = itemstr.match guid_regex
55
+ idmatch = itemstr.match id_regex
56
+ if ! association.has_key? matches[0]
57
+ association[matches[0]] = idmatch[1]
58
+ itemstr = itemstr + '</item>'
59
+ else # already associated
60
+ corrections[idmatch[1]] = association[matches[0]]
61
+ itemstr = ''
62
+ end#if
63
+ else # not image attachment
64
+ corrections.each do |oldid, newid|
65
+ itemstr.sub "<wp:meta_value><![CDATA[#{oldid}]]></wp:meta_value>", "<wp:meta_value><![CDATA[#{newid}]]></wp:meta_value>"
66
+ end#each
67
+ itemstr = itemstr + '</item>'
68
+ end#if
69
+ clean_items = clean_items + itemstr;
70
+ end#each
71
+
72
+ puts opening + clean_items + ending
38
73
  end#def
39
74
 
40
75
  def find_and_replace(path, search, replace)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pxg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -55,28 +55,6 @@ dependencies:
55
55
  - - <
56
56
  - !ruby/object:Gem::Version
57
57
  version: '2.0'
58
- - !ruby/object:Gem::Dependency
59
- name: xml-simple
60
- requirement: !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '1.1'
66
- - - <
67
- - !ruby/object:Gem::Version
68
- version: '2.0'
69
- type: :runtime
70
- prerelease: false
71
- version_requirements: !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ! '>='
75
- - !ruby/object:Gem::Version
76
- version: '1.1'
77
- - - <
78
- - !ruby/object:Gem::Version
79
- version: '2.0'
80
58
  description: Pixelgrade Utilities
81
59
  email: source.spider@gmail.com
82
60
  executables: