1
+ <?php
2
+ class PluginHelper {
3
+ public $ basePath = 'src/android/LibraryProject/ ' ;
4
+
5
+ private function perror ($ msg )
6
+ {
7
+ file_put_contents ('php://stderr ' , $ msg , FILE_APPEND );
8
+ }
9
+
10
+ /**
11
+ * Get contents of an XML file.
12
+ *
13
+ * @param string $xmlFilePath The XML file path relative to $this->basePath.
14
+ * @param string $parent Parent element from which to get children.
15
+ * @param array $options
16
+ * <li>ident - ident chanracters.
17
+ * <li>ignorePattern - pattern that will be matched to XML.
18
+ * @return string
19
+ */
20
+ public function getXml ($ xmlFilePath , $ parent , $ options =array ())
21
+ {
22
+ if (!isset ($ options ['indent ' ]))
23
+ {
24
+ $ options ['indent ' ] = "" ;
25
+ }
26
+
27
+ $ contents = "" ;
28
+ $ filePath = $ this ->basePath . $ xmlFilePath ;
29
+ if (!file_exists ($ filePath ))
30
+ {
31
+ $ this ->perror ("File $ filePath does not exist " );
32
+ return $ contents ;
33
+ }
34
+
35
+ $ xml = file_get_contents ($ this ->basePath . $ xmlFilePath );
36
+ $ document = new SimpleXMLElement ($ xml );
37
+ $ els = $ document ->xpath ($ parent );
38
+ if (!empty ($ els ))
39
+ {
40
+ $ rootNode = $ els [0 ];
41
+ foreach ($ rootNode ->children () as $ child )
42
+ {
43
+ $ childContent = $ child ->asXML ();
44
+ if (isset ($ options ['ignorePattern ' ]) && preg_match ($ options ['ignorePattern ' ], $ childContent ))
45
+ {
46
+ $ this ->perror ("\nignored $ childContent " );
47
+ continue ;
48
+ }
49
+ $ contents .= "\n" . $ options ['indent ' ] . $ childContent ;
50
+ }
51
+ $ contents = ltrim ($ contents ) . "\n" ;
52
+ return $ contents ;
53
+ }
54
+ else
55
+ {
56
+ $ this ->perror ("Path $ parent not found in $ xmlFilePath " );
57
+ return $ contents ;
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Generate source-file tags to copy all resources from given dir.
63
+ *
64
+ * @param type $dir Dir path relative to $this->basePath.
65
+ * @param array $options
66
+ * <li>ident - ident chanracters.
67
+ */
68
+ public function sourceFiles ($ dir , $ options =array ())
69
+ {
70
+ //ob_end_clean();
71
+
72
+ if (!isset ($ options ['indent ' ]))
73
+ {
74
+ $ options ['indent ' ] = "" ;
75
+ }
76
+ $ path = $ this ->basePath . $ dir ;
77
+
78
+ $ it = new RecursiveIteratorIterator (new RecursiveDirectoryIterator ($ path ));
79
+ while ($ it ->valid ())
80
+ {
81
+ if (!$ it ->isDot ())
82
+ {
83
+ $ filename = strtr ($ it ->key (), '\\' , '/ ' );
84
+ if (isset ($ options ['ignorePattern ' ]) && preg_match ($ options ['ignorePattern ' ], $ filename ))
85
+ {
86
+ $ this ->perror ("\nignored $ filename " );
87
+ $ it ->next ();
88
+ continue ;
89
+ }
90
+
91
+ $ targetDir = preg_replace ('#.+LibraryProject/(.+?)/[^/]+$# ' , '$1 ' , $ filename );
92
+ echo "\n{$ options ['indent ' ]}<source-file src= \"$ filename \" target-dir= \"$ targetDir \"/> " ;
93
+ }
94
+ $ it ->next ();
95
+ }
96
+
97
+ echo "\n" ;
98
+ //exit;
99
+ }
100
+ }
101
+
102
+ // init
103
+ $ pluginHelper = new PluginHelper ();
104
+
105
+ ob_start ();
106
+ echo '<?xml version="1.0" encoding="UTF-8"?> ' ;
107
+ ?>
108
+ <plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
109
+ xmlns:android="http://schemas.android.com/apk/res/android"
110
+ id="com.phonegap.plugins.barcodescanner"
111
+ version="0.5.3">
112
+
113
+ <name>BarcodeScanner</name>
114
+
115
+ <description>Scans Barcodes.</description>
116
+
117
+ <engines>
118
+ <engine name="cordova" version=">=2.0.0" />
119
+ </engines>
120
+
121
+ <asset src="www/barcodescanner.js" target="barcodescanner.js" />
122
+
123
+ <!-- ios -->
124
+ <platform name="ios">
125
+ <plugins-plist key="BarcodeScanner" string="CDVBarcodeScanner" />
126
+
127
+ <!-- Cordova >= 2.3 -->
128
+ <config-file target="config.xml" parent="plugins">
129
+ <plugin name="BarcodeScanner" value="CDVBarcodeScanner"/>
130
+ </config-file>
131
+
132
+ <resource-file src="src/ios/scannerOverlay.xib" />
133
+
134
+ <header-file src="src/ios/zxing-all-in-one.h" />
135
+
136
+ <source-file src="src/ios/CDVBarcodeScanner.mm" />
137
+ <source-file src="src/ios/zxing-all-in-one.cpp" />
138
+
139
+ <framework src="libiconv.dylib" />
140
+ <framework src="AVFoundation.framework" />
141
+ <framework src="AssetsLibrary.framework" />
142
+ <framework src="CoreVideo.framework" />
143
+ </platform>
144
+
145
+ <!-- android -->
146
+ <platform name="android">
147
+
148
+ <source-file src="src/android/com/phonegap/plugins/barcodescanner/BarcodeScanner.java" target-dir="src/com/phonegap/plugins/barcodescanner" />
149
+ <!--
150
+ <source-file src="R.java" target-dir="src/com/google/zxing/client/android" />
151
+ -->
152
+
153
+ <config-file target="res/xml/plugins.xml" parent="/plugins">
154
+ <plugin name="BarcodeScanner" value="com.phonegap.plugins.barcodescanner.BarcodeScanner"/>
155
+ </config-file>
156
+
157
+ <config-file target="res/xml/config.xml" parent="plugins">
158
+ <plugin name="BarcodeScanner" value="com.phonegap.plugins.barcodescanner.BarcodeScanner"/>
159
+ </config-file>
160
+
161
+ <config-file target="AndroidManifest.xml" parent="/manifest/application">
162
+ <activity
163
+ android:name="com.google.zxing.client.android.CaptureActivity"
164
+ android:screenOrientation="landscape"
165
+ android:clearTaskOnLaunch="true"
166
+ android:configChanges="orientation|keyboardHidden"
167
+ android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
168
+ android:windowSoftInputMode="stateAlwaysHidden"
169
+ android:exported="false">
170
+ <intent-filter>
171
+ <action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
172
+ <category android:name="android.intent.category.DEFAULT"/>
173
+ </intent-filter>
174
+ </activity>
175
+ <activity android:name="com.google.zxing.client.android.encode.EncodeActivity" android:label="@string/share_name">
176
+ <intent-filter>
177
+ <action android:name="com.phonegap.plugins.barcodescanner.ENCODE"/>
178
+ <category android:name="android.intent.category.DEFAULT"/>
179
+ </intent-filter>
180
+ </activity>
181
+ <activity android:name="com.google.zxing.client.android.HelpActivity" android:label="@string/share_name">
182
+ <intent-filter>
183
+ <action android:name="android.intent.action.VIEW"/>
184
+ <category android:name="android.intent.category.DEFAULT"/>
185
+ </intent-filter>
186
+ </activity>
187
+ </config-file>
188
+
189
+ <config-file target="AndroidManifest.xml" parent="/manifest">
190
+ <uses-permission android:name="android.permission.CAMERA" />
191
+ <uses-permission android:name="android.permission.FLASHLIGHT" />
192
+ <!-- Not required to allow users to work around this -->
193
+ <uses-feature android:name="android.hardware.camera" android:required="false" />
194
+ </config-file>
195
+
196
+ <source-file src="src/android/com.google.zxing.client.android.captureactivity.jar" target-dir="libs"/>
197
+
198
+ <!--
199
+ LibraryProject/res/*.*
200
+ search: (src/android/LibraryProject/(.+?)/[^/]+)$
201
+ replace: <source-file src="$1" target-dir="$2"/>
202
+ -->
203
+ <?
204
+ $ pluginHelper ->sourceFiles ("res " , array ('indent ' =>"\t\t" , 'ignorePattern ' => '#values/strings.xml# ' ));
205
+ ?>
206
+
207
+ <!-- plugman cannot merge - prepare manual merge -->
208
+ <config-file target="res/values/strings.xml" parent="/resources">
209
+ <?= $ pluginHelper ->getXml ('res/values/strings.xml ' , "/resources " , array ('ignorePattern ' => '/name="(app_name|menu_settings)"/ ' , 'indent ' => "\t\t\t" ))?>
210
+ </config-file>
211
+ </platform>
212
+ </plugin>
213
+ <?php
214
+ $ pluginText = ob_get_clean ();
215
+ file_put_contents ("plugin.xml " , $ pluginText );
216
+ ?>
0 commit comments