PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.1.5
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.1.5
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / libraries / XmlGoogleMerchants.php
wp-all-export / libraries Last commit date
VariableProductTitle 8 years ago .gitkeep 8 years ago WpaeInvalidPhpException.php 8 years ago WpaeInvalidStringException.php 8 years ago WpaeMethodNotFoundException.php 8 years ago WpaePhpInterpreterErrorHandler.php 8 years ago WpaeString.php 8 years ago WpaeTooMuchRecursionException.php 8 years ago WpaeXmlProcessor.php 8 years ago XmlCsvExport.php 8 years ago XmlExportACF.php 8 years ago XmlExportComment.php 8 years ago XmlExportCpt.php 8 years ago XmlExportEngine.php 8 years ago XmlExportFiltering.php 8 years ago XmlExportMediaGallery.php 8 years ago XmlExportTaxonomy.php 8 years ago XmlExportUser.php 8 years ago XmlExportWooCommerce.php 8 years ago XmlExportWooCommerceCoupon.php 8 years ago XmlExportWooCommerceOrder.php 8 years ago XmlGoogleMerchants.php 8 years ago XmlSpec.php 8 years ago
XmlGoogleMerchants.php
161 lines
1 <?php
2
3 /**
4 * Class XmlGoogleMerchants
5 */
6 final class XmlGoogleMerchants
7 {
8 /**
9 * @var bool
10 */
11 private $export_id = false;
12 /**
13 * @var array
14 */
15 private $add_data = array();
16
17 /**
18 * @var array
19 *
20 * https://support.google.com/merchants/answer/160589?hl=en
21 *
22 */
23 private $required_fields = array(
24 array(
25 'name' => 'g:id',
26 'type' => 'ID',
27 // 'label' => 'id'
28 ),
29 array(
30 'name' => 'title',
31 'type' => 'Title',
32 // 'label' => 'title'
33 ),
34 array(
35 'name' => 'link',
36 'type' => 'Permalink',
37 // 'label' => 'permalink'
38 ),
39 array(
40 'name' => 'description',
41 'type' => 'Content',
42 // 'label' => 'content'
43 ),
44 array(
45 'name' => 'g:image_link',
46 'type' => 'Image Url',
47 // 'options' => '{"is_export_featured":true,"is_export_attached":false,"image_separator":"|"}'
48 ),
49 array(
50 'name' => 'g:price',
51 'type' => 'Regular Price',
52 ),
53 // array(
54 // 'name' => 'g:condition',
55 // 'type' => 'woo',
56 // 'label' => '_regular_price'
57 // )
58 );
59
60 /**
61 * XmlGoogleMerchants constructor.
62 * @param $id
63 * @param array $additional_data
64 */
65 public function __construct($id, $additional_data = array())
66 {
67 $this->export_id = $id;
68 $this->add_data = $additional_data;
69
70 if ( ! empty($this->export_id))
71 {
72 add_filter('wp_all_export_xml_header', array( &$this, 'wpae_xml_header'), 10, 2);
73 add_filter('wp_all_export_additional_data', array( &$this, 'wpae_additional_data'), 10, 3);
74 add_filter('wp_all_export_xml_footer', array( &$this, 'wpae_xml_footer'), 10, 2);
75 add_filter('wp_all_export_main_xml_tag', array( &$this, 'wpae_main_xml_tag'), 10, 2);
76 add_filter('wp_all_export_record_xml_tag', array( &$this, 'wpae_record_xml_tag'), 10, 2);
77 }
78 }
79
80 /**
81 * @param $header
82 * @param $export_id
83 * @return string
84 */
85 public function wpae_xml_header($header, $export_id)
86 {
87 if ( $export_id == $this->export_id )
88 {
89 $header .= "\n<rss version=\"2.0\" xmlns:g=\"http://base.google.com/ns/1.0\">";
90 }
91 return $header;
92 }
93
94 /**
95 * @param $add_data
96 * @param $options
97 * @param $export_id
98 * @return array
99 */
100 public function wpae_additional_data($add_data, $options, $export_id)
101 {
102 if ( $export_id == $this->export_id && ! empty($this->add_data))
103 {
104 $add_data = array_merge($add_data, $this->add_data);
105 }
106 return $add_data;
107 }
108
109 /**
110 * @param $footer
111 * @param $export_id
112 * @return string
113 */
114 public function wpae_xml_footer($footer, $export_id)
115 {
116 if ( $export_id == $this->export_id )
117 {
118 $footer = "</rss>";
119 }
120 return $footer;
121 }
122
123 /**
124 * @param $tag
125 * @param $export_id
126 * @return string
127 */
128 public function wpae_main_xml_tag($tag, $export_id )
129 {
130 return ( $export_id == $this->export_id ) ? 'channel' : $tag;
131 }
132
133 /**
134 * @param $tag
135 * @param $export_id
136 * @return string
137 */
138 public function wpae_record_xml_tag($tag, $export_id )
139 {
140 return ( $export_id == $this->export_id ) ? 'item' : $tag;
141 }
142
143 /**
144 *
145 */
146 public function get_required_fields()
147 {
148 $xml_template = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rss version=\"2.0\" xmlns:g=\"http://base.google.com/ns/1.0\">\n";
149 $xml_template .= "\t<chanel>";
150 $xml_template .= "\n\t\t<!-- BEGIN LOOP -->";
151 $xml_template .= "\n\t\t<item>";
152 foreach ($this->required_fields as $field){
153 $xml_template .= "\n\t\t\t<" . $field['name'] . ">{" . $field['type'] . "}</" . $field['name'] . ">";
154 }
155 $xml_template .= "\n\t\t</item>";
156 $xml_template .= "\n\t\t<!-- END LOOP -->";
157 $xml_template .= "\n\t</chanel>";
158 $xml_template .= "\n</rss>";
159 return $xml_template;
160 }
161 }