Postie - Version 1.9.1

Version Description

(2017-06-28) = * Feature: Add postie_file_added_pre action * Fix: improvements to tag detection * Fix: tags may be specified multiple times * Fix: significant code restructure to bring Postie in line with current coding practices * Fix: move signature removal to before newline filtering * Fix: signature removal was deleting all text if the matching regex had whitespace characters

Download this release

Release Info

Developer WayneAllen
Plugin Icon 128x128 Postie
Version 1.9.1
Comparing to
See all releases

Code changes from version 1.8.45 to 1.9.1

COPYING CHANGED
@@ -1,280 +1,674 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 2, June 1991
3
 
4
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
- 675 Mass Ave, Cambridge, MA 02139, USA
6
  Everyone is permitted to copy and distribute verbatim copies
7
  of this license document, but changing it is not allowed.
8
 
9
- Preamble
10
 
11
- The licenses for most software are designed to take away your
12
- freedom to share and change it. By contrast, the GNU General Public
13
- License is intended to guarantee your freedom to share and change free
14
- software--to make sure the software is free for all its users. This
15
- General Public License applies to most of the Free Software
16
- Foundation's software and to any other program whose authors commit to
17
- using it. (Some other Free Software Foundation software is covered by
18
- the GNU Library General Public License instead.) You can apply it to
 
 
19
  your programs, too.
20
 
21
  When we speak of free software, we are referring to freedom, not
22
  price. Our General Public Licenses are designed to make sure that you
23
  have the freedom to distribute copies of free software (and charge for
24
- this service if you wish), that you receive source code or can get it
25
- if you want it, that you can change the software or use pieces of it
26
- in new free programs; and that you know you can do these things.
27
 
28
- To protect your rights, we need to make restrictions that forbid
29
- anyone to deny you these rights or to ask you to surrender the rights.
30
- These restrictions translate to certain responsibilities for you if you
31
- distribute copies of the software, or if you modify it.
32
 
33
  For example, if you distribute copies of such a program, whether
34
- gratis or for a fee, you must give the recipients all the rights that
35
- you have. You must make sure that they, too, receive or can get the
36
- source code. And you must show them these terms so they know their
37
- rights.
38
-
39
- We protect your rights with two steps: (1) copyright the software, and
40
- (2) offer you this license which gives you legal permission to copy,
41
- distribute and/or modify the software.
42
-
43
- Also, for each author's protection and ours, we want to make certain
44
- that everyone understands that there is no warranty for this free
45
- software. If the software is modified by someone else and passed on, we
46
- want its recipients to know that what they have is not the original, so
47
- that any problems introduced by others will not reflect on the original
48
- authors' reputations.
49
-
50
- Finally, any free program is threatened constantly by software
51
- patents. We wish to avoid the danger that redistributors of a free
52
- program will individually obtain patent licenses, in effect making the
53
- program proprietary. To prevent this, we have made it clear that any
54
- patent must be licensed for everyone's free use or not licensed at all.
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  The precise terms and conditions for copying, distribution and
57
  modification follow.
58
 
59
- GNU GENERAL PUBLIC LICENSE
60
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
-
62
- 0. This License applies to any program or other work which contains
63
- a notice placed by the copyright holder saying it may be distributed
64
- under the terms of this General Public License. The "Program", below,
65
- refers to any such program or work, and a "work based on the Program"
66
- means either the Program or any derivative work under copyright law:
67
- that is to say, a work containing the Program or a portion of it,
68
- either verbatim or with modifications and/or translated into another
69
- language. (Hereinafter, translation is included without limitation in
70
- the term "modification".) Each licensee is addressed as "you".
71
-
72
- Activities other than copying, distribution and modification are not
73
- covered by this License; they are outside its scope. The act of
74
- running the Program is not restricted, and the output from the Program
75
- is covered only if its contents constitute a work based on the
76
- Program (independent of having been made by running the Program).
77
- Whether that is true depends on what the Program does.
78
-
79
- 1. You may copy and distribute verbatim copies of the Program's
80
- source code as you receive it, in any medium, provided that you
81
- conspicuously and appropriately publish on each copy an appropriate
82
- copyright notice and disclaimer of warranty; keep intact all the
83
- notices that refer to this License and to the absence of any warranty;
84
- and give any other recipients of the Program a copy of this License
85
- along with the Program.
86
-
87
- You may charge a fee for the physical act of transferring a copy, and
88
- you may at your option offer warranty protection in exchange for a fee.
89
-
90
- 2. You may modify your copy or copies of the Program or any portion
91
- of it, thus forming a work based on the Program, and copy and
92
- distribute such modifications or work under the terms of Section 1
93
- above, provided that you also meet all of these conditions:
94
-
95
- a) You must cause the modified files to carry prominent notices
96
- stating that you changed the files and the date of any change.
97
-
98
- b) You must cause any work that you distribute or publish, that in
99
- whole or in part contains or is derived from the Program or any
100
- part thereof, to be licensed as a whole at no charge to all third
101
- parties under the terms of this License.
102
-
103
- c) If the modified program normally reads commands interactively
104
- when run, you must cause it, when started running for such
105
- interactive use in the most ordinary way, to print or display an
106
- announcement including an appropriate copyright notice and a
107
- notice that there is no warranty (or else, saying that you provide
108
- a warranty) and that users may redistribute the program under
109
- these conditions, and telling the user how to view a copy of this
110
- License. (Exception: if the Program itself is interactive but
111
- does not normally print such an announcement, your work based on
112
- the Program is not required to print an announcement.)
113
-
114
- These requirements apply to the modified work as a whole. If
115
- identifiable sections of that work are not derived from the Program,
116
- and can be reasonably considered independent and separate works in
117
- themselves, then this License, and its terms, do not apply to those
118
- sections when you distribute them as separate works. But when you
119
- distribute the same sections as part of a whole which is a work based
120
- on the Program, the distribution of the whole must be on the terms of
121
- this License, whose permissions for other licensees extend to the
122
- entire whole, and thus to each and every part regardless of who wrote it.
123
- Thus, it is not the intent of this section to claim rights or contest
124
- your rights to work written entirely by you; rather, the intent is to
125
- exercise the right to control the distribution of derivative or
126
- collective works based on the Program.
127
-
128
- In addition, mere aggregation of another work not based on the Program
129
- with the Program (or with a work based on the Program) on a volume of
130
- a storage or distribution medium does not bring the other work under
131
- the scope of this License.
132
-
133
- 3. You may copy and distribute the Program (or a work based on it,
134
- under Section 2) in object code or executable form under the terms of
135
- Sections 1 and 2 above provided that you also do one of the following:
136
-
137
- a) Accompany it with the complete corresponding machine-readable
138
- source code, which must be distributed under the terms of Sections
139
- 1 and 2 above on a medium customarily used for software interchange; or,
140
-
141
- b) Accompany it with a written offer, valid for at least three
142
- years, to give any third party, for a charge no more than your
143
- cost of physically performing source distribution, a complete
144
- machine-readable copy of the corresponding source code, to be
145
- distributed under the terms of Sections 1 and 2 above on a medium
146
- customarily used for software interchange; or,
147
-
148
- c) Accompany it with the information you received as to the offer
149
- to distribute corresponding source code. (This alternative is
150
- allowed only for noncommercial distribution and only if you
151
- received the program in object code or executable form with such
152
- an offer, in accord with Subsection b above.)
153
-
154
- The source code for a work means the preferred form of the work for
155
- making modifications to it. For an executable work, complete source
156
- code means all the source code for all modules it contains, plus any
157
- associated interface definition files, plus the scripts used to
158
- control compilation and installation of the executable. However, as a
159
- special exception, the source code distributed need not include
160
- anything that is normally distributed (in either source or binary
161
- form) with the major components (compiler, kernel, and so on) of the
162
- operating system on which the executable runs, unless that component
163
- itself accompanies the executable.
164
-
165
- If distribution of executable or object code is made by offering
166
- access to copy from a designated place, then offering equivalent
167
- access to copy the source code from the same place counts as
168
- distribution of the source code, even though third parties are not
169
- compelled to copy the source along with the object code.
170
-
171
- 4. You may not copy, modify, sublicense, or distribute the Program
172
- except as expressly provided under this License. Any attempt
173
- otherwise to copy, modify, sublicense or distribute the Program is
174
- void, and will automatically terminate your rights under this License.
175
- However, parties who have received copies, or rights, from you under
176
- this License will not have their licenses terminated so long as such
177
- parties remain in full compliance.
178
-
179
- 5. You are not required to accept this License, since you have not
180
- signed it. However, nothing else grants you permission to modify or
181
- distribute the Program or its derivative works. These actions are
182
- prohibited by law if you do not accept this License. Therefore, by
183
- modifying or distributing the Program (or any work based on the
184
- Program), you indicate your acceptance of this License to do so, and
185
- all its terms and conditions for copying, distributing or modifying
186
- the Program or works based on it.
187
-
188
- 6. Each time you redistribute the Program (or any work based on the
189
- Program), the recipient automatically receives a license from the
190
- original licensor to copy, distribute or modify the Program subject to
191
- these terms and conditions. You may not impose any further
192
- restrictions on the recipients' exercise of the rights granted herein.
193
- You are not responsible for enforcing compliance by third parties to
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  this License.
195
 
196
- 7. If, as a consequence of a court judgment or allegation of patent
197
- infringement or for any other reason (not limited to patent issues),
198
- conditions are imposed on you (whether by court order, agreement or
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  otherwise) that contradict the conditions of this License, they do not
200
- excuse you from the conditions of this License. If you cannot
201
- distribute so as to satisfy simultaneously your obligations under this
202
- License and any other pertinent obligations, then as a consequence you
203
- may not distribute the Program at all. For example, if a patent
204
- license would not permit royalty-free redistribution of the Program by
205
- all those who receive copies directly or indirectly through you, then
206
- the only way you could satisfy both it and this License would be to
207
- refrain entirely from distribution of the Program.
208
-
209
- If any portion of this section is held invalid or unenforceable under
210
- any particular circumstance, the balance of the section is intended to
211
- apply and the section as a whole is intended to apply in other
212
- circumstances.
213
-
214
- It is not the purpose of this section to induce you to infringe any
215
- patents or other property right claims or to contest validity of any
216
- such claims; this section has the sole purpose of protecting the
217
- integrity of the free software distribution system, which is
218
- implemented by public license practices. Many people have made
219
- generous contributions to the wide range of software distributed
220
- through that system in reliance on consistent application of that
221
- system; it is up to the author/donor to decide if he or she is willing
222
- to distribute software through any other system and a licensee cannot
223
- impose that choice.
224
-
225
- This section is intended to make thoroughly clear what is believed to
226
- be a consequence of the rest of this License.
227
-
228
- 8. If the distribution and/or use of the Program is restricted in
229
- certain countries either by patents or by copyrighted interfaces, the
230
- original copyright holder who places the Program under this License
231
- may add an explicit geographical distribution limitation excluding
232
- those countries, so that distribution is permitted only in or among
233
- countries not thus excluded. In such case, this License incorporates
234
- the limitation as if written in the body of this License.
235
-
236
- 9. The Free Software Foundation may publish revised and/or new versions
237
- of the General Public License from time to time. Such new versions will
238
  be similar in spirit to the present version, but may differ in detail to
239
  address new problems or concerns.
240
 
241
- Each version is given a distinguishing version number. If the Program
242
- specifies a version number of this License which applies to it and "any
243
- later version", you have the option of following the terms and conditions
244
- either of that version or of any later version published by the Free
245
- Software Foundation. If the Program does not specify a version number of
246
- this License, you may choose any version ever published by the Free Software
247
- Foundation.
248
-
249
- 10. If you wish to incorporate parts of the Program into other free
250
- programs whose distribution conditions are different, write to the author
251
- to ask for permission. For software which is copyrighted by the Free
252
- Software Foundation, write to the Free Software Foundation; we sometimes
253
- make exceptions for this. Our decision will be guided by the two goals
254
- of preserving the free status of all derivatives of our free software and
255
- of promoting the sharing and reuse of software generally.
256
-
257
- NO WARRANTY
258
-
259
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
260
- FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
261
- OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
262
- PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
263
- OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
264
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
265
- TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
266
- PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
267
- REPAIR OR CORRECTION.
268
-
269
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
270
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
271
- REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
272
- INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
273
- OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
274
- TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
275
- YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
276
- PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
277
- POSSIBILITY OF SUCH DAMAGES.
278
-
279
- END OF TERMS AND CONDITIONS
280
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
 
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
 
5
  Everyone is permitted to copy and distribute verbatim copies
6
  of this license document, but changing it is not allowed.
7
 
8
+ Preamble
9
 
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
  your programs, too.
21
 
22
  When we speak of free software, we are referring to freedom, not
23
  price. Our General Public Licenses are designed to make sure that you
24
  have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
 
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
 
34
  For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
 
68
  The precise terms and conditions for copying, distribution and
69
  modification follow.
70
 
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds of
78
+ works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ 1. Source Code.
113
+
114
+ The "source code" for a work means the preferred form of the work
115
+ for making modifications to it. "Object code" means any non-source
116
+ form of a work.
117
+
118
+ A "Standard Interface" means an interface that either is an official
119
+ standard defined by a recognized standards body, or, in the case of
120
+ interfaces specified for a particular programming language, one that
121
+ is widely used among developers working in that language.
122
+
123
+ The "System Libraries" of an executable work include anything, other
124
+ than the work as a whole, that (a) is included in the normal form of
125
+ packaging a Major Component, but which is not part of that Major
126
+ Component, and (b) serves only to enable use of the work with that
127
+ Major Component, or to implement a Standard Interface for which an
128
+ implementation is available to the public in source code form. A
129
+ "Major Component", in this context, means a major essential component
130
+ (kernel, window system, and so on) of the specific operating system
131
+ (if any) on which the executable work runs, or a compiler used to
132
+ produce the work, or an object code interpreter used to run it.
133
+
134
+ The "Corresponding Source" for a work in object code form means all
135
+ the source code needed to generate, install, and (for an executable
136
+ work) run the object code and to modify the work, including scripts to
137
+ control those activities. However, it does not include the work's
138
+ System Libraries, or general-purpose tools or generally available free
139
+ programs which are used unmodified in performing those activities but
140
+ which are not part of the work. For example, Corresponding Source
141
+ includes interface definition files associated with source files for
142
+ the work, and the source code for shared libraries and dynamically
143
+ linked subprograms that the work is specifically designed to require,
144
+ such as by intimate data communication or control flow between those
145
+ subprograms and other parts of the work.
146
+
147
+ The Corresponding Source need not include anything that users
148
+ can regenerate automatically from other parts of the Corresponding
149
+ Source.
150
+
151
+ The Corresponding Source for a work in source code form is that
152
+ same work.
153
+
154
+ 2. Basic Permissions.
155
+
156
+ All rights granted under this License are granted for the term of
157
+ copyright on the Program, and are irrevocable provided the stated
158
+ conditions are met. This License explicitly affirms your unlimited
159
+ permission to run the unmodified Program. The output from running a
160
+ covered work is covered by this License only if the output, given its
161
+ content, constitutes a covered work. This License acknowledges your
162
+ rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+ You may make, run and propagate covered works that you do not
165
+ convey, without conditions so long as your license otherwise remains
166
+ in force. You may convey covered works to others for the sole purpose
167
+ of having them make modifications exclusively for you, or provide you
168
+ with facilities for running those works, provided that you comply with
169
+ the terms of this License in conveying all material for which you do
170
+ not control copyright. Those thus making or running the covered works
171
+ for you must do so exclusively on your behalf, under your direction
172
+ and control, on terms that prohibit them from making any copies of
173
+ your copyrighted material outside their relationship with you.
174
+
175
+ Conveying under any other circumstances is permitted solely under
176
+ the conditions stated below. Sublicensing is not allowed; section 10
177
+ makes it unnecessary.
178
+
179
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+ No covered work shall be deemed part of an effective technological
182
+ measure under any applicable law fulfilling obligations under article
183
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+ similar laws prohibiting or restricting circumvention of such
185
+ measures.
186
+
187
+ When you convey a covered work, you waive any legal power to forbid
188
+ circumvention of technological measures to the extent such circumvention
189
+ is effected by exercising rights under this License with respect to
190
+ the covered work, and you disclaim any intention to limit operation or
191
+ modification of the work as a means of enforcing, against the work's
192
+ users, your or third parties' legal rights to forbid circumvention of
193
+ technological measures.
194
+
195
+ 4. Conveying Verbatim Copies.
196
+
197
+ You may convey verbatim copies of the Program's source code as you
198
+ receive it, in any medium, provided that you conspicuously and
199
+ appropriately publish on each copy an appropriate copyright notice;
200
+ keep intact all notices stating that this License and any
201
+ non-permissive terms added in accord with section 7 apply to the code;
202
+ keep intact all notices of the absence of any warranty; and give all
203
+ recipients a copy of this License along with the Program.
204
+
205
+ You may charge any price or no price for each copy that you convey,
206
+ and you may offer support or warranty protection for a fee.
207
+
208
+ 5. Conveying Modified Source Versions.
209
+
210
+ You may convey a work based on the Program, or the modifications to
211
+ produce it from the Program, in the form of source code under the
212
+ terms of section 4, provided that you also meet all of these conditions:
213
+
214
+ a) The work must carry prominent notices stating that you modified
215
+ it, and giving a relevant date.
216
+
217
+ b) The work must carry prominent notices stating that it is
218
+ released under this License and any conditions added under section
219
+ 7. This requirement modifies the requirement in section 4 to
220
+ "keep intact all notices".
221
+
222
+ c) You must license the entire work, as a whole, under this
223
+ License to anyone who comes into possession of a copy. This
224
+ License will therefore apply, along with any applicable section 7
225
+ additional terms, to the whole of the work, and all its parts,
226
+ regardless of how they are packaged. This License gives no
227
+ permission to license the work in any other way, but it does not
228
+ invalidate such permission if you have separately received it.
229
+
230
+ d) If the work has interactive user interfaces, each must display
231
+ Appropriate Legal Notices; however, if the Program has interactive
232
+ interfaces that do not display Appropriate Legal Notices, your
233
+ work need not make them do so.
234
+
235
+ A compilation of a covered work with other separate and independent
236
+ works, which are not by their nature extensions of the covered work,
237
+ and which are not combined with it such as to form a larger program,
238
+ in or on a volume of a storage or distribution medium, is called an
239
+ "aggregate" if the compilation and its resulting copyright are not
240
+ used to limit the access or legal rights of the compilation's users
241
+ beyond what the individual works permit. Inclusion of a covered work
242
+ in an aggregate does not cause this License to apply to the other
243
+ parts of the aggregate.
244
+
245
+ 6. Conveying Non-Source Forms.
246
+
247
+ You may convey a covered work in object code form under the terms
248
+ of sections 4 and 5, provided that you also convey the
249
+ machine-readable Corresponding Source under the terms of this License,
250
+ in one of these ways:
251
+
252
+ a) Convey the object code in, or embodied in, a physical product
253
+ (including a physical distribution medium), accompanied by the
254
+ Corresponding Source fixed on a durable physical medium
255
+ customarily used for software interchange.
256
+
257
+ b) Convey the object code in, or embodied in, a physical product
258
+ (including a physical distribution medium), accompanied by a
259
+ written offer, valid for at least three years and valid for as
260
+ long as you offer spare parts or customer support for that product
261
+ model, to give anyone who possesses the object code either (1) a
262
+ copy of the Corresponding Source for all the software in the
263
+ product that is covered by this License, on a durable physical
264
+ medium customarily used for software interchange, for a price no
265
+ more than your reasonable cost of physically performing this
266
+ conveying of source, or (2) access to copy the
267
+ Corresponding Source from a network server at no charge.
268
+
269
+ c) Convey individual copies of the object code with a copy of the
270
+ written offer to provide the Corresponding Source. This
271
+ alternative is allowed only occasionally and noncommercially, and
272
+ only if you received the object code with such an offer, in accord
273
+ with subsection 6b.
274
+
275
+ d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+
288
+ e) Convey the object code using peer-to-peer transmission, provided
289
+ you inform other peers where the object code and Corresponding
290
+ Source of the work are being offered to the general public at no
291
+ charge under subsection 6d.
292
+
293
+ A separable portion of the object code, whose source code is excluded
294
+ from the Corresponding Source as a System Library, need not be
295
+ included in conveying the object code work.
296
+
297
+ A "User Product" is either (1) a "consumer product", which means any
298
+ tangible personal property which is normally used for personal, family,
299
+ or household purposes, or (2) anything designed or sold for incorporation
300
+ into a dwelling. In determining whether a product is a consumer product,
301
+ doubtful cases shall be resolved in favor of coverage. For a particular
302
+ product received by a particular user, "normally used" refers to a
303
+ typical or common use of that class of product, regardless of the status
304
+ of the particular user or of the way in which the particular user
305
+ actually uses, or expects or is expected to use, the product. A product
306
+ is a consumer product regardless of whether the product has substantial
307
+ commercial, industrial or non-consumer uses, unless such uses represent
308
+ the only significant mode of use of the product.
309
+
310
+ "Installation Information" for a User Product means any methods,
311
+ procedures, authorization keys, or other information required to install
312
+ and execute modified versions of a covered work in that User Product from
313
+ a modified version of its Corresponding Source. The information must
314
+ suffice to ensure that the continued functioning of the modified object
315
+ code is in no case prevented or interfered with solely because
316
+ modification has been made.
317
+
318
+ If you convey an object code work under this section in, or with, or
319
+ specifically for use in, a User Product, and the conveying occurs as
320
+ part of a transaction in which the right of possession and use of the
321
+ User Product is transferred to the recipient in perpetuity or for a
322
+ fixed term (regardless of how the transaction is characterized), the
323
+ Corresponding Source conveyed under this section must be accompanied
324
+ by the Installation Information. But this requirement does not apply
325
+ if neither you nor any third party retains the ability to install
326
+ modified object code on the User Product (for example, the work has
327
+ been installed in ROM).
328
+
329
+ The requirement to provide Installation Information does not include a
330
+ requirement to continue to provide support service, warranty, or updates
331
+ for a work that has been modified or installed by the recipient, or for
332
+ the User Product in which it has been modified or installed. Access to a
333
+ network may be denied when the modification itself materially and
334
+ adversely affects the operation of the network or violates the rules and
335
+ protocols for communication across the network.
336
+
337
+ Corresponding Source conveyed, and Installation Information provided,
338
+ in accord with this section must be in a format that is publicly
339
+ documented (and with an implementation available to the public in
340
+ source code form), and must require no special password or key for
341
+ unpacking, reading or copying.
342
+
343
+ 7. Additional Terms.
344
+
345
+ "Additional permissions" are terms that supplement the terms of this
346
+ License by making exceptions from one or more of its conditions.
347
+ Additional permissions that are applicable to the entire Program shall
348
+ be treated as though they were included in this License, to the extent
349
+ that they are valid under applicable law. If additional permissions
350
+ apply only to part of the Program, that part may be used separately
351
+ under those permissions, but the entire Program remains governed by
352
+ this License without regard to the additional permissions.
353
+
354
+ When you convey a copy of a covered work, you may at your option
355
+ remove any additional permissions from that copy, or from any part of
356
+ it. (Additional permissions may be written to require their own
357
+ removal in certain cases when you modify the work.) You may place
358
+ additional permissions on material, added by you to a covered work,
359
+ for which you have or can give appropriate copyright permission.
360
+
361
+ Notwithstanding any other provision of this License, for material you
362
+ add to a covered work, you may (if authorized by the copyright holders of
363
+ that material) supplement the terms of this License with terms:
364
+
365
+ a) Disclaiming warranty or limiting liability differently from the
366
+ terms of sections 15 and 16 of this License; or
367
+
368
+ b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+
372
+ c) Prohibiting misrepresentation of the origin of that material, or
373
+ requiring that modified versions of such material be marked in
374
+ reasonable ways as different from the original version; or
375
+
376
+ d) Limiting the use for publicity purposes of names of licensors or
377
+ authors of the material; or
378
+
379
+ e) Declining to grant rights under trademark law for use of some
380
+ trade names, trademarks, or service marks; or
381
+
382
+ f) Requiring indemnification of licensors and authors of that
383
+ material by anyone who conveys the material (or modified versions of
384
+ it) with contractual assumptions of liability to the recipient, for
385
+ any liability that these contractual assumptions directly impose on
386
+ those licensors and authors.
387
+
388
+ All other non-permissive additional terms are considered "further
389
+ restrictions" within the meaning of section 10. If the Program as you
390
+ received it, or any part of it, contains a notice stating that it is
391
+ governed by this License along with a term that is a further
392
+ restriction, you may remove that term. If a license document contains
393
+ a further restriction but permits relicensing or conveying under this
394
+ License, you may add to a covered work material governed by the terms
395
+ of that license document, provided that the further restriction does
396
+ not survive such relicensing or conveying.
397
+
398
+ If you add terms to a covered work in accord with this section, you
399
+ must place, in the relevant source files, a statement of the
400
+ additional terms that apply to those files, or a notice indicating
401
+ where to find the applicable terms.
402
+
403
+ Additional terms, permissive or non-permissive, may be stated in the
404
+ form of a separately written license, or stated as exceptions;
405
+ the above requirements apply either way.
406
+
407
+ 8. Termination.
408
+
409
+ You may not propagate or modify a covered work except as expressly
410
+ provided under this License. Any attempt otherwise to propagate or
411
+ modify it is void, and will automatically terminate your rights under
412
+ this License (including any patent licenses granted under the third
413
+ paragraph of section 11).
414
+
415
+ However, if you cease all violation of this License, then your
416
+ license from a particular copyright holder is reinstated (a)
417
+ provisionally, unless and until the copyright holder explicitly and
418
+ finally terminates your license, and (b) permanently, if the copyright
419
+ holder fails to notify you of the violation by some reasonable means
420
+ prior to 60 days after the cessation.
421
+
422
+ Moreover, your license from a particular copyright holder is
423
+ reinstated permanently if the copyright holder notifies you of the
424
+ violation by some reasonable means, this is the first time you have
425
+ received notice of violation of this License (for any work) from that
426
+ copyright holder, and you cure the violation prior to 30 days after
427
+ your receipt of the notice.
428
+
429
+ Termination of your rights under this section does not terminate the
430
+ licenses of parties who have received copies or rights from you under
431
+ this License. If your rights have been terminated and not permanently
432
+ reinstated, you do not qualify to receive new licenses for the same
433
+ material under section 10.
434
+
435
+ 9. Acceptance Not Required for Having Copies.
436
+
437
+ You are not required to accept this License in order to receive or
438
+ run a copy of the Program. Ancillary propagation of a covered work
439
+ occurring solely as a consequence of using peer-to-peer transmission
440
+ to receive a copy likewise does not require acceptance. However,
441
+ nothing other than this License grants you permission to propagate or
442
+ modify any covered work. These actions infringe copyright if you do
443
+ not accept this License. Therefore, by modifying or propagating a
444
+ covered work, you indicate your acceptance of this License to do so.
445
+
446
+ 10. Automatic Licensing of Downstream Recipients.
447
+
448
+ Each time you convey a covered work, the recipient automatically
449
+ receives a license from the original licensors, to run, modify and
450
+ propagate that work, subject to this License. You are not responsible
451
+ for enforcing compliance by third parties with this License.
452
+
453
+ An "entity transaction" is a transaction transferring control of an
454
+ organization, or substantially all assets of one, or subdividing an
455
+ organization, or merging organizations. If propagation of a covered
456
+ work results from an entity transaction, each party to that
457
+ transaction who receives a copy of the work also receives whatever
458
+ licenses to the work the party's predecessor in interest had or could
459
+ give under the previous paragraph, plus a right to possession of the
460
+ Corresponding Source of the work from the predecessor in interest, if
461
+ the predecessor has it or can get it with reasonable efforts.
462
+
463
+ You may not impose any further restrictions on the exercise of the
464
+ rights granted or affirmed under this License. For example, you may
465
+ not impose a license fee, royalty, or other charge for exercise of
466
+ rights granted under this License, and you may not initiate litigation
467
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
468
+ any patent claim is infringed by making, using, selling, offering for
469
+ sale, or importing the Program or any portion of it.
470
+
471
+ 11. Patents.
472
+
473
+ A "contributor" is a copyright holder who authorizes use under this
474
+ License of the Program or a work on which the Program is based. The
475
+ work thus licensed is called the contributor's "contributor version".
476
+
477
+ A contributor's "essential patent claims" are all patent claims
478
+ owned or controlled by the contributor, whether already acquired or
479
+ hereafter acquired, that would be infringed by some manner, permitted
480
+ by this License, of making, using, or selling its contributor version,
481
+ but do not include claims that would be infringed only as a
482
+ consequence of further modification of the contributor version. For
483
+ purposes of this definition, "control" includes the right to grant
484
+ patent sublicenses in a manner consistent with the requirements of
485
  this License.
486
 
487
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+ patent license under the contributor's essential patent claims, to
489
+ make, use, sell, offer for sale, import and otherwise run, modify and
490
+ propagate the contents of its contributor version.
491
+
492
+ In the following three paragraphs, a "patent license" is any express
493
+ agreement or commitment, however denominated, not to enforce a patent
494
+ (such as an express permission to practice a patent or covenant not to
495
+ sue for patent infringement). To "grant" such a patent license to a
496
+ party means to make such an agreement or commitment not to enforce a
497
+ patent against the party.
498
+
499
+ If you convey a covered work, knowingly relying on a patent license,
500
+ and the Corresponding Source of the work is not available for anyone
501
+ to copy, free of charge and under the terms of this License, through a
502
+ publicly available network server or other readily accessible means,
503
+ then you must either (1) cause the Corresponding Source to be so
504
+ available, or (2) arrange to deprive yourself of the benefit of the
505
+ patent license for this particular work, or (3) arrange, in a manner
506
+ consistent with the requirements of this License, to extend the patent
507
+ license to downstream recipients. "Knowingly relying" means you have
508
+ actual knowledge that, but for the patent license, your conveying the
509
+ covered work in a country, or your recipient's use of the covered work
510
+ in a country, would infringe one or more identifiable patents in that
511
+ country that you have reason to believe are valid.
512
+
513
+ If, pursuant to or in connection with a single transaction or
514
+ arrangement, you convey, or propagate by procuring conveyance of, a
515
+ covered work, and grant a patent license to some of the parties
516
+ receiving the covered work authorizing them to use, propagate, modify
517
+ or convey a specific copy of the covered work, then the patent license
518
+ you grant is automatically extended to all recipients of the covered
519
+ work and works based on it.
520
+
521
+ A patent license is "discriminatory" if it does not include within
522
+ the scope of its coverage, prohibits the exercise of, or is
523
+ conditioned on the non-exercise of one or more of the rights that are
524
+ specifically granted under this License. You may not convey a covered
525
+ work if you are a party to an arrangement with a third party that is
526
+ in the business of distributing software, under which you make payment
527
+ to the third party based on the extent of your activity of conveying
528
+ the work, and under which the third party grants, to any of the
529
+ parties who would receive the covered work from you, a discriminatory
530
+ patent license (a) in connection with copies of the covered work
531
+ conveyed by you (or copies made from those copies), or (b) primarily
532
+ for and in connection with specific products or compilations that
533
+ contain the covered work, unless you entered into that arrangement,
534
+ or that patent license was granted, prior to 28 March 2007.
535
+
536
+ Nothing in this License shall be construed as excluding or limiting
537
+ any implied license or other defenses to infringement that may
538
+ otherwise be available to you under applicable patent law.
539
+
540
+ 12. No Surrender of Others' Freedom.
541
+
542
+ If conditions are imposed on you (whether by court order, agreement or
543
  otherwise) that contradict the conditions of this License, they do not
544
+ excuse you from the conditions of this License. If you cannot convey a
545
+ covered work so as to satisfy simultaneously your obligations under this
546
+ License and any other pertinent obligations, then as a consequence you may
547
+ not convey it at all. For example, if you agree to terms that obligate you
548
+ to collect a royalty for further conveying from those to whom you convey
549
+ the Program, the only way you could satisfy both those terms and this
550
+ License would be to refrain entirely from conveying the Program.
551
+
552
+ 13. Use with the GNU Affero General Public License.
553
+
554
+ Notwithstanding any other provision of this License, you have
555
+ permission to link or combine any covered work with a work licensed
556
+ under version 3 of the GNU Affero General Public License into a single
557
+ combined work, and to convey the resulting work. The terms of this
558
+ License will continue to apply to the part which is the covered work,
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
562
+
563
+ 14. Revised Versions of this License.
564
+
565
+ The Free Software Foundation may publish revised and/or new versions of
566
+ the GNU General Public License from time to time. Such new versions will
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
567
  be similar in spirit to the present version, but may differ in detail to
568
  address new problems or concerns.
569
 
570
+ Each version is given a distinguishing version number. If the
571
+ Program specifies that a certain numbered version of the GNU General
572
+ Public License "or any later version" applies to it, you have the
573
+ option of following the terms and conditions either of that numbered
574
+ version or of any later version published by the Free Software
575
+ Foundation. If the Program does not specify a version number of the
576
+ GNU General Public License, you may choose any version ever published
577
+ by the Free Software Foundation.
578
+
579
+ If the Program specifies that a proxy can decide which future
580
+ versions of the GNU General Public License can be used, that proxy's
581
+ public statement of acceptance of a version permanently authorizes you
582
+ to choose that version for the Program.
583
+
584
+ Later license versions may give you additional or different
585
+ permissions. However, no additional obligations are imposed on any
586
+ author or copyright holder as a result of your choosing to follow a
587
+ later version.
588
+
589
+ 15. Disclaimer of Warranty.
590
+
591
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+ 16. Limitation of Liability.
601
+
602
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+ SUCH DAMAGES.
611
+
612
+ 17. Interpretation of Sections 15 and 16.
613
+
614
+ If the disclaimer of warranty and limitation of liability provided
615
+ above cannot be given local legal effect according to their terms,
616
+ reviewing courts shall apply local law that most closely approximates
617
+ an absolute waiver of all civil liability in connection with the
618
+ Program, unless a warranty or assumption of liability accompanies a
619
+ copy of the Program in return for a fee.
620
+
621
+ END OF TERMS AND CONDITIONS
622
+
623
+ How to Apply These Terms to Your New Programs
624
+
625
+ If you develop a new program, and you want it to be of the greatest
626
+ possible use to the public, the best way to achieve this is to make it
627
+ free software which everyone can redistribute and change under these terms.
628
+
629
+ To do so, attach the following notices to the program. It is safest
630
+ to attach them to the start of each source file to most effectively
631
+ state the exclusion of warranty; and each file should have at least
632
+ the "copyright" line and a pointer to where the full notice is found.
633
+
634
+ <one line to give the program's name and a brief idea of what it does.>
635
+ Copyright (C) <year> <name of author>
636
+
637
+ This program is free software: you can redistribute it and/or modify
638
+ it under the terms of the GNU General Public License as published by
639
+ the Free Software Foundation, either version 3 of the License, or
640
+ (at your option) any later version.
641
+
642
+ This program is distributed in the hope that it will be useful,
643
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
644
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
+ GNU General Public License for more details.
646
+
647
+ You should have received a copy of the GNU General Public License
648
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
649
+
650
+ Also add information on how to contact you by electronic and paper mail.
651
+
652
+ If the program does terminal interaction, make it output a short
653
+ notice like this when it starts in an interactive mode:
654
+
655
+ <program> Copyright (C) <year> <name of author>
656
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
+ This is free software, and you are welcome to redistribute it
658
+ under certain conditions; type `show c' for details.
659
+
660
+ The hypothetical commands `show w' and `show c' should show the appropriate
661
+ parts of the General Public License. Of course, your program's commands
662
+ might be different; for a GUI interface, you would use an "about box".
663
+
664
+ You should also get your employer (if you work as a programmer) or school,
665
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
666
+ For more information on this, and how to apply and follow the GNU GPL, see
667
+ <http://www.gnu.org/licenses/>.
668
+
669
+ The GNU General Public License does not permit incorporating your program
670
+ into proprietary programs. If your program is a subroutine library, you
671
+ may consider it more useful to permit linking proprietary applications with
672
+ the library. If this is what you want to do, use the GNU Lesser General
673
+ Public License instead of this License. But first, please read
674
+ <http://www.gnu.org/philosophy/why-not-lgpl.html>.
CREDITS CHANGED
@@ -6,6 +6,6 @@ Copyright (c) 2005 David Luden
6
  Copyright (c) 2005 Adrian Heydecker - http://wavestyle.ch
7
  Copyright (c) 2005 Jay Talbot - webmaster@jaytalbot.com
8
  Copyright (c) 2008-2012 Rob Felty http://robfelty.com/
9
- Copyright (c) 2012 Wayne Allen http://postieplugin.com/
10
 
11
  Licensed under the GNU GPL. For full terms see the file COPYING
6
  Copyright (c) 2005 Adrian Heydecker - http://wavestyle.ch
7
  Copyright (c) 2005 Jay Talbot - webmaster@jaytalbot.com
8
  Copyright (c) 2008-2012 Rob Felty http://robfelty.com/
9
+ Copyright (c) 2012-present Wayne Allen http://postieplugin.com/
10
 
11
  Licensed under the GNU GPL. For full terms see the file COPYING
config_form.php CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  <div class="wrap">
2
  <h2>
3
  <a style='text-decoration:none' href='admin.php?page=postie-settings'>
@@ -10,27 +13,27 @@
10
  </h2>
11
 
12
  <?php
13
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'postie-functions.php');
14
- if (isset($_POST["action"])) {
15
- switch ($_POST["action"]) {
16
- case "reset":
17
- config_ResetToDefault();
18
  $message = 1;
19
  break;
20
- case "cronless":
21
- check_postie();
22
  $message = 1;
23
  break;
24
- case "test":
25
- postie_test_config();
26
  exit;
27
  break;
28
- case "runpostie":
29
  DebugEcho(__("Checking for mail manually", 'postie'));
30
  postie_get_mail();
31
  exit;
32
  break;
33
- case "runpostie-debug":
34
  DebugEcho(__("Checking for mail manually with debug output", 'postie'));
35
  if (!defined('POSTIE_DEBUG')) {
36
  define('POSTIE_DEBUG', true);
@@ -45,12 +48,13 @@
45
  }
46
  global $wpdb, $wp_roles;
47
 
48
- $config = config_Read();
 
49
  if (empty($config)) {
50
- $config = config_ResetToDefault();
51
  }
52
 
53
- $arrays = config_ArrayedSettings();
54
  // some fields are stored as arrays, because that makes back-end processing much easier
55
  // and we need to convert those fields to strings here, for the options form
56
  foreach ($arrays as $sep => $fields) {
@@ -194,8 +198,8 @@
194
  </div>
195
  </div>
196
 
197
- <?php
198
- $iconDir = esc_url(plugins_url() . '/postie/icons');
199
  //print_r($config);
200
  ?>
201
  <script type="text/javascript">
@@ -223,8 +227,7 @@ $iconDir = esc_url(plugins_url() . '/postie/icons');
223
  var d = jQuery(this).find("description").text();
224
  if ((i = d.indexOf('<p class="more')) != -1) {
225
  d = d.substring(0, i);
226
- }
227
- else if ((i = d.indexOf('<p>The post <a')) != -1) {
228
  d = d.substring(0, i);
229
  }
230
  h += "<div>" + d + "</div>";
@@ -283,7 +286,7 @@ $iconDir = esc_url(plugins_url() . '/postie/icons');
283
  var medium = '<?php echo $templateDir ?>/' + sample.replace(/\.jpg/, '-300x200.jpg');
284
  var large = '<?php echo $templateDir ?>/' + sample.replace(/\.jpg/, '-1024x682.jpg');
285
  var pagelink = '<?php echo get_option("siteurl") ?>' + '/?attachment_id=9999';
286
- var fileType='mp4';
287
  previewHTML = previewHTML.replace(/{FILELINK}/g, fileLink);
288
  previewHTML = previewHTML.replace(/{FULL}/g, fileLink);
289
  previewHTML = previewHTML.replace(/{IMAGE}/g, fileLink);
1
+ <?php
2
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "postie-admin.class.php");
3
+ ?>
4
  <div class="wrap">
5
  <h2>
6
  <a style='text-decoration:none' href='admin.php?page=postie-settings'>
13
  </h2>
14
 
15
  <?php
16
+ if (isset($_POST['action'])) {
17
+ switch ($_POST['action']) {
18
+ case 'reset':
19
+ $pconfig = new PostieConfig();
20
+ $pconfig->reset_to_default();
21
  $message = 1;
22
  break;
23
+ case 'cronless':
24
+ postie_check();
25
  $message = 1;
26
  break;
27
+ case 'test':
28
+ $g_postie->test_config();
29
  exit;
30
  break;
31
+ case 'runpostie':
32
  DebugEcho(__("Checking for mail manually", 'postie'));
33
  postie_get_mail();
34
  exit;
35
  break;
36
+ case 'runpostie-debug':
37
  DebugEcho(__("Checking for mail manually with debug output", 'postie'));
38
  if (!defined('POSTIE_DEBUG')) {
39
  define('POSTIE_DEBUG', true);
48
  }
49
  global $wpdb, $wp_roles;
50
 
51
+ $pconfig = new PostieConfig();
52
+ $config = $pconfig->config_read();
53
  if (empty($config)) {
54
+ $config = $pconfig->reset_to_default();
55
  }
56
 
57
+ $arrays = $pconfig->arrayed_settings();
58
  // some fields are stored as arrays, because that makes back-end processing much easier
59
  // and we need to convert those fields to strings here, for the options form
60
  foreach ($arrays as $sep => $fields) {
198
  </div>
199
  </div>
200
 
201
+ <?php
202
+ $iconDir = esc_url(plugins_url() . '/postie/icons');
203
  //print_r($config);
204
  ?>
205
  <script type="text/javascript">
227
  var d = jQuery(this).find("description").text();
228
  if ((i = d.indexOf('<p class="more')) != -1) {
229
  d = d.substring(0, i);
230
+ } else if ((i = d.indexOf('<p>The post <a')) != -1) {
 
231
  d = d.substring(0, i);
232
  }
233
  h += "<div>" + d + "</div>";
286
  var medium = '<?php echo $templateDir ?>/' + sample.replace(/\.jpg/, '-300x200.jpg');
287
  var large = '<?php echo $templateDir ?>/' + sample.replace(/\.jpg/, '-1024x682.jpg');
288
  var pagelink = '<?php echo get_option("siteurl") ?>' + '/?attachment_id=9999';
289
+ var fileType = 'mp4';
290
  previewHTML = previewHTML.replace(/{FILELINK}/g, fileLink);
291
  previewHTML = previewHTML.replace(/{FULL}/g, fileLink);
292
  previewHTML = previewHTML.replace(/{IMAGE}/g, fileLink);
config_form_attachments.php CHANGED
@@ -1,7 +1,7 @@
1
  <div id="simpleTabs-content-6" class="simpleTabs-content">
2
  <table class='form-table'>
3
- <?php echo BuildTextArea(__("Supported MIME Types", 'postie'), "postie-settings[supported_file_types]", $supported_file_types, __("Add just the type (not the subtype). Text, Video, Audio, Image and Multipart are always supported. Put each type on a single line", 'postie')); ?>
4
- <?php echo BuildTextArea(__("Banned File Names", 'postie'), "postie-settings[banned_files_list]", $banned_files_list, __("Put each file name on a single line.Files matching this list will never be posted to your blog. You can use wildcards such as *.xls, or *.* for all files", 'postie')); ?>
5
 
6
  <tr>
7
  <th scope='row'><?php _e('Attachment icon set', 'postie') ?></th>
1
  <div id="simpleTabs-content-6" class="simpleTabs-content">
2
  <table class='form-table'>
3
+ <?php echo PostieAdmin::textarea_html(__("Supported MIME Types", 'postie'), "postie-settings[supported_file_types]", $supported_file_types, __("Add just the type (not the subtype). Text, Video, Audio, Image and Multipart are always supported. Put each type on a single line", 'postie')); ?>
4
+ <?php echo PostieAdmin::textarea_html(__("Banned File Names", 'postie'), "postie-settings[banned_files_list]", $banned_files_list, __("Put each file name on a single line.Files matching this list will never be posted to your blog. You can use wildcards such as *.xls, or *.* for all files", 'postie')); ?>
5
 
6
  <tr>
7
  <th scope='row'><?php _e('Attachment icon set', 'postie') ?></th>
config_form_image.php CHANGED
@@ -2,13 +2,13 @@
2
  <table class='form-table'>
3
 
4
  <?php
5
- echo BuildBooleanSelect(__("Use First Image as Featured Image", 'postie'), "postie-settings[featured_image]", $featured_image, __("If any images are attached, the first one will be the featured image for the post", 'postie'));
6
- echo BuildBooleanSelect(__("Include Featured Image in Post", 'postie'), "postie-settings[include_featured_image]", $include_featured_image, __("Should the featured image be included in the post.", 'postie'));
7
- echo BuildBooleanSelect(__("Automatically insert image gallery", 'postie'), "postie-settings[auto_gallery]", $auto_gallery, __("If any images are attached, they will automatically be inserted as a gallery. If the 'Preferred Text Type' is 'HTML' this will add a galery in addition to the images in the email. Not recommended.", 'postie'));
8
- echo BuildSelect(__("Gallery Link Type", 'postie'), "postie-settings[auto_gallery_link]", $auto_gallery_link, array('Default', 'Post', 'File', 'None'), "Select the type of link the gallery should use");
9
- echo BuildBooleanSelect(__("Image Location", 'postie'), "postie-settings[images_append]", $images_append, __("Location of attachments if using 'plain' format. Before or After content. For 'html' content this will only affect attachments that are not inline.", 'postie'), array('After', 'Before'));
10
- echo BuildBooleanSelect(__("Start Image Count At", 'postie'), "postie-settings[start_image_count_at_zero]", $start_image_count_at_zero, __('For use if using "Image Place Holder Tag" below.', 'postie'), array('Start at 0', 'Start at 1'));
11
- echo BuildBooleanSelect(__("Use custom image field for images", 'postie'), "postie-settings[custom_image_field]", $custom_image_field, __("When set to 'Yes' no images will appear in the post (other attachment types will be processed normally). Instead the url to the attachment will be put into a custom field named 'image'. Your theme will need logic to display these attachments", 'postie'));
12
  ?>
13
  <tr>
14
  <th scope="row"><?php _e('Image Place Holder Tag', 'postie') ?></th>
@@ -51,7 +51,7 @@
51
  <div id='imageTemplatePreview'></div>
52
  <textarea onchange='changeStyle("imageTemplatePreview", "postie-settings-imagetemplate", "imagetemplateselect",
53
  "postie-settings-selected_imagetemplate", "smiling.jpg", true);' cols='70' rows='7' id='postie-settings-imagetemplate' name='postie-settings[imagetemplate]'>
54
- <?php echo esc_attr($imagetemplate) ?>
55
  </textarea>
56
  <div class='recommendation'>
57
  <ul>
2
  <table class='form-table'>
3
 
4
  <?php
5
+ echo PostieAdmin::boolean_select_html(__("Use First Image as Featured Image", 'postie'), "postie-settings[featured_image]", $featured_image, __("If any images are attached, the first one will be the featured image for the post", 'postie'));
6
+ echo PostieAdmin::boolean_select_html(__("Include Featured Image in Post", 'postie'), "postie-settings[include_featured_image]", $include_featured_image, __("Should the featured image be included in the post.", 'postie'));
7
+ echo PostieAdmin::boolean_select_html(__("Automatically insert image gallery", 'postie'), "postie-settings[auto_gallery]", $auto_gallery, __("If any images are attached, they will automatically be inserted as a gallery. If the 'Preferred Text Type' is 'HTML' this will add a galery in addition to the images in the email. Not recommended.", 'postie'));
8
+ echo PostieAdmin::select_html(__("Gallery Link Type", 'postie'), "postie-settings[auto_gallery_link]", $auto_gallery_link, array('Default', 'Post', 'File', 'None'), "Select the type of link the gallery should use");
9
+ echo PostieAdmin::boolean_select_html(__("Image Location", 'postie'), "postie-settings[images_append]", $images_append, __("Location of attachments if using 'plain' format. Before or After content. For 'html' content this will only affect attachments that are not inline.", 'postie'), array('After', 'Before'));
10
+ echo PostieAdmin::boolean_select_html(__("Start Image Count At", 'postie'), "postie-settings[start_image_count_at_zero]", $start_image_count_at_zero, __('For use if using "Image Place Holder Tag" below.', 'postie'), array('Start at 0', 'Start at 1'));
11
+ echo PostieAdmin::boolean_select_html(__("Use custom image field for images", 'postie'), "postie-settings[custom_image_field]", $custom_image_field, __("When set to 'Yes' no images will appear in the post (other attachment types will be processed normally). Instead the url to the attachment will be put into a custom field named 'image'. Your theme will need logic to display these attachments", 'postie'));
12
  ?>
13
  <tr>
14
  <th scope="row"><?php _e('Image Place Holder Tag', 'postie') ?></th>
51
  <div id='imageTemplatePreview'></div>
52
  <textarea onchange='changeStyle("imageTemplatePreview", "postie-settings-imagetemplate", "imagetemplateselect",
53
  "postie-settings-selected_imagetemplate", "smiling.jpg", true);' cols='70' rows='7' id='postie-settings-imagetemplate' name='postie-settings[imagetemplate]'>
54
+ <?php echo esc_attr($imagetemplate) ?>
55
  </textarea>
56
  <div class='recommendation'>
57
  <ul>
config_form_message.php CHANGED
@@ -10,7 +10,7 @@
10
  </td>
11
  </tr>
12
  <?php
13
- echo BuildBooleanSelect(__("Text fallback", 'postie'), "postie-settings[prefer_text_convert]", $prefer_text_convert, __("Use plain if html is missing and vice versa.", 'postie'));
14
  ?>
15
  <tr valign = "top">
16
  <th scope = "row"><?php _e('Default category', 'postie') ?></th>
@@ -22,12 +22,12 @@
22
  ?>
23
  </tr>
24
  <?php
25
- echo BuildBooleanSelect(__("Match short category", 'postie'), "postie-settings[category_match]", $category_match, __("Try to match categories using 'starts with logic' otherwise only do exact matches.<br />Note that custom taxonomies will not be found if this setting is 'No'", 'postie'));
26
 
27
- echo BuildBooleanSelect(__("Use colon to match category", 'postie'), "postie-settings[category_colon]", $category_colon);
28
- echo BuildBooleanSelect(__("Use dash to match category", 'postie'), "postie-settings[category_dash]", $category_dash);
29
- echo BuildBooleanSelect(__("Use square bracket to match category", 'postie'), "postie-settings[category_bracket]", $category_bracket, __('See the following article for more information <a href="http://postieplugin.com/faq/override-post-categories/" target="_blank">http://postieplugin.com/faq/override-post-categories/</a>', 'postie'));
30
- echo BuildBooleanSelect(__("Remove matched categories", 'postie'), "postie-settings[category_remove]", $category_remove,__('Typically you want any categories specified on the subject line removed from the post title.'));
31
  ?>
32
 
33
  <tr valign="top">
@@ -110,13 +110,13 @@
110
  </td>
111
  </tr>
112
 
113
- <?php echo BuildBooleanSelect(__("Treat Replies As", 'postie'), "postie-settings[reply_as_comment]", $reply_as_comment, "", array("comments", "new posts")); ?>
114
- <?php echo BuildBooleanSelect(__("Strip Original Content from Replies", 'postie'), "postie-settings[strip_reply]", $strip_reply, "Only applicable if replies are trated as comments"); ?>
115
 
116
- <?php echo BuildBooleanSelect(__("Forward Rejected Mail", 'postie'), "postie-settings[forward_rejected_mail]", $forward_rejected_mail); ?>
117
- <?php echo BuildBooleanSelect(__("Allow Subject In Mail", 'postie'), "postie-settings[allow_subject_in_mail]", $allow_subject_in_mail, "Enclose the subject between '#' on the very first line. E.g. #this is my subject#"); ?>
118
- <?php echo BuildBooleanSelect(__("Allow HTML In Mail Subject", 'postie'), "postie-settings[allow_html_in_subject]", $allow_html_in_subject); ?>
119
- <?php echo BuildBooleanSelect(__("Allow HTML In Mail Body", 'postie'), "postie-settings[allow_html_in_body]", $allow_html_in_body); ?>
120
  <tr>
121
  <th scope="row"><?php _e('Text for Message Start', 'postie') ?> </th>
122
  <td>
@@ -133,9 +133,9 @@
133
  </tr>
134
 
135
  <?php
136
- echo BuildBooleanSelect(__("Filter newlines", 'postie'), "postie-settings[filternewlines]", $filternewlines, __("Whether to strip newlines from plain text. Set to no if using markdown or textitle syntax", 'postie'));
137
- echo BuildBooleanSelect(__("Replace newline characters with html line breaks (&lt;br /&gt;)", 'postie'), "postie-settings[convertnewline]", $convertnewline, __("Filter newlines must be turned on for this option to take effect", 'postie'));
138
- echo BuildBooleanSelect(__("Return rejected mail to sender", 'postie'), "postie-settings[return_to_sender]", $return_to_sender);
139
  ?>
140
  <tr>
141
  <th>
@@ -152,7 +152,7 @@
152
  </tr>
153
 
154
  <?php
155
- echo BuildBooleanSelect(__("Automatically convert urls to links", 'postie'), "postie-settings[converturls]", $converturls);
156
  ?>
157
  <tr>
158
  <th scope="row"><?php _e('Encoding for pages and feeds', 'postie') ?> </th>
@@ -162,7 +162,7 @@
162
  <p class='description'>UTF-8 <?php _e("should handle ISO-8859-1 as well", 'postie'); ?></p>
163
  </td>
164
  </tr>
165
- <?php echo BuildBooleanSelect(__("Drop The Signature From Mail", 'postie'), "postie-settings[drop_signature]", $drop_signature, __("Really only works with 'plain' format.")); ?>
166
- <?php echo BuildTextArea(__("Signature Patterns", 'postie'), "postie-settings[sig_pattern_list]", $sig_pattern_list, __("Really only works with 'plain' format. Put each pattern on a separate line. Patterns are <a href='http://regex101.com/' target='_blank'>regular expressions</a> and are put inside /^{pattern}$/i", 'postie')); ?>
167
  </table>
168
  </div>
10
  </td>
11
  </tr>
12
  <?php
13
+ echo PostieAdmin::boolean_select_html(__("Text fallback", 'postie'), "postie-settings[prefer_text_convert]", $prefer_text_convert, __("Use plain if html is missing and vice versa.", 'postie'));
14
  ?>
15
  <tr valign = "top">
16
  <th scope = "row"><?php _e('Default category', 'postie') ?></th>
22
  ?>
23
  </tr>
24
  <?php
25
+ echo PostieAdmin::boolean_select_html(__("Match short category", 'postie'), "postie-settings[category_match]", $category_match, __("Try to match categories using 'starts with logic' otherwise only do exact matches.<br />Note that custom taxonomies will not be found if this setting is 'No'", 'postie'));
26
 
27
+ echo PostieAdmin::boolean_select_html(__("Use colon to match category", 'postie'), "postie-settings[category_colon]", $category_colon);
28
+ echo PostieAdmin::boolean_select_html(__("Use dash to match category", 'postie'), "postie-settings[category_dash]", $category_dash);
29
+ echo PostieAdmin::boolean_select_html(__("Use square bracket to match category", 'postie'), "postie-settings[category_bracket]", $category_bracket, __('See the following article for more information <a href="http://postieplugin.com/faq/override-post-categories/" target="_blank">http://postieplugin.com/faq/override-post-categories/</a>', 'postie'));
30
+ echo PostieAdmin::boolean_select_html(__("Remove matched categories", 'postie'), "postie-settings[category_remove]", $category_remove,__('Typically you want any categories specified on the subject line removed from the post title.'));
31
  ?>
32
 
33
  <tr valign="top">
110
  </td>
111
  </tr>
112
 
113
+ <?php echo PostieAdmin::boolean_select_html(__("Treat Replies As", 'postie'), "postie-settings[reply_as_comment]", $reply_as_comment, "", array("comments", "new posts")); ?>
114
+ <?php echo PostieAdmin::boolean_select_html(__("Strip Original Content from Replies", 'postie'), "postie-settings[strip_reply]", $strip_reply, "Only applicable if replies are trated as comments"); ?>
115
 
116
+ <?php echo PostieAdmin::boolean_select_html(__("Forward Rejected Mail", 'postie'), "postie-settings[forward_rejected_mail]", $forward_rejected_mail); ?>
117
+ <?php echo PostieAdmin::boolean_select_html(__("Allow Subject In Mail", 'postie'), "postie-settings[allow_subject_in_mail]", $allow_subject_in_mail, "Enclose the subject between '#' on the very first line. E.g. #this is my subject#"); ?>
118
+ <?php echo PostieAdmin::boolean_select_html(__("Allow HTML In Mail Subject", 'postie'), "postie-settings[allow_html_in_subject]", $allow_html_in_subject); ?>
119
+ <?php echo PostieAdmin::boolean_select_html(__("Allow HTML In Mail Body", 'postie'), "postie-settings[allow_html_in_body]", $allow_html_in_body); ?>
120
  <tr>
121
  <th scope="row"><?php _e('Text for Message Start', 'postie') ?> </th>
122
  <td>
133
  </tr>
134
 
135
  <?php
136
+ echo PostieAdmin::boolean_select_html(__("Filter newlines", 'postie'), "postie-settings[filternewlines]", $filternewlines, __("Whether to strip newlines from plain text. Set to no if using markdown or textitle syntax", 'postie'));
137
+ echo PostieAdmin::boolean_select_html(__("Replace newline characters with html line breaks (&lt;br /&gt;)", 'postie'), "postie-settings[convertnewline]", $convertnewline, __("Filter newlines must be turned on for this option to take effect", 'postie'));
138
+ echo PostieAdmin::boolean_select_html(__("Return rejected mail to sender", 'postie'), "postie-settings[return_to_sender]", $return_to_sender);
139
  ?>
140
  <tr>
141
  <th>
152
  </tr>
153
 
154
  <?php
155
+ echo PostieAdmin::boolean_select_html(__("Automatically convert urls to links", 'postie'), "postie-settings[converturls]", $converturls);
156
  ?>
157
  <tr>
158
  <th scope="row"><?php _e('Encoding for pages and feeds', 'postie') ?> </th>
162
  <p class='description'>UTF-8 <?php _e("should handle ISO-8859-1 as well", 'postie'); ?></p>
163
  </td>
164
  </tr>
165
+ <?php echo PostieAdmin::boolean_select_html(__("Drop The Signature From Mail", 'postie'), "postie-settings[drop_signature]", $drop_signature, __("Really only works with 'plain' format.")); ?>
166
+ <?php echo PostieAdmin::textarea_html(__("Signature Patterns", 'postie'), "postie-settings[sig_pattern_list]", $sig_pattern_list, __("Really only works with 'plain' format. Put each pattern on a separate line. Patterns are <a href='http://regex101.com/' target='_blank'>regular expressions</a> and are put inside /^{pattern}$/i", 'postie')); ?>
167
  </table>
168
  </div>
config_form_server.php CHANGED
@@ -55,8 +55,8 @@
55
  </td>
56
  </tr>
57
 
58
- <?php echo BuildBooleanSelect(__("Ignore Email Date", 'postie'), 'postie-settings[ignore_email_date]', $ignore_email_date, __("If set to 'Yes' the email date will be ignored and the post will be published with the system time. If set to 'No' the date in the email will be used as the post date.", 'postie')); ?>
59
- <?php echo BuildBooleanSelect(__("Use Postie Time Correction", 'postie'), 'postie-settings[use_time_offset]', $use_time_offset, __("If set to 'Yes' adjust the time according to Postie Time Correction otherwise use the date provided by the email.", 'postie')); ?>
60
 
61
  <tr>
62
  <th scope="row"><?php _e('Postie Time Correction', 'postie') ?></th>
@@ -162,18 +162,18 @@
162
  </td>
163
  </tr>
164
  <?php
165
- echo BuildBooleanSelect(__("Delete email after posting", 'postie'), 'postie-settings[delete_mail_after_processing]', $delete_mail_after_processing, __("Only set to no for testing purposes", 'postie'));
166
- //echo BuildBooleanSelect(__("Ignore mail state", 'postie'), 'postie-settings[ignore_mail_state]', $ignore_mail_state, __("Ignore whether the mails is 'read' or 'unread' If 'No' then only unread messages are processed. IMAP only", 'postie'));
167
 
168
- echo BuildBooleanSelect(__("Enable Error Logging", 'postie'), 'postie-settings[postie_log_error]', $postie_log_error, __("Log error messages to the web server error log.", 'postie'));
169
 
170
  $notification_options = array('(Nobody)', '(All Admins)');
171
  foreach (get_users(array('role' => 'administrator')) as $user) {
172
  $notification_options[] = $user->user_login;
173
  }
174
- echo BuildSelect(__('Notify on Error', 'postie'), 'postie-settings[postie_log_error_notify]', $postie_log_error_notify, $notification_options);
175
 
176
- echo BuildBooleanSelect(__("Enable Debug Logging", 'postie'), 'postie-settings[postie_log_debug]', $postie_log_debug, __("Log debug messages to the web server error log.", 'postie'));
177
  ?>
178
 
179
  </table>
55
  </td>
56
  </tr>
57
 
58
+ <?php echo PostieAdmin::boolean_select_html(__("Ignore Email Date", 'postie'), 'postie-settings[ignore_email_date]', $ignore_email_date, __("If set to 'Yes' the email date will be ignored and the post will be published with the system time. If set to 'No' the date in the email will be used as the post date.", 'postie')); ?>
59
+ <?php echo PostieAdmin::boolean_select_html(__("Use Postie Time Correction", 'postie'), 'postie-settings[use_time_offset]', $use_time_offset, __("If set to 'Yes' adjust the time according to Postie Time Correction otherwise use the date provided by the email.", 'postie')); ?>
60
 
61
  <tr>
62
  <th scope="row"><?php _e('Postie Time Correction', 'postie') ?></th>
162
  </td>
163
  </tr>
164
  <?php
165
+ echo PostieAdmin::boolean_select_html(__("Delete email after posting", 'postie'), 'postie-settings[delete_mail_after_processing]', $delete_mail_after_processing, __("Only set to no for testing purposes", 'postie'));
166
+ //echo PostieAdmin::BuildBooleanSelect(__("Ignore mail state", 'postie'), 'postie-settings[ignore_mail_state]', $ignore_mail_state, __("Ignore whether the mails is 'read' or 'unread' If 'No' then only unread messages are processed. IMAP only", 'postie'));
167
 
168
+ echo PostieAdmin::boolean_select_html(__("Enable Error Logging", 'postie'), 'postie-settings[postie_log_error]', $postie_log_error, __("Log error messages to the web server error log.", 'postie'));
169
 
170
  $notification_options = array('(Nobody)', '(All Admins)');
171
  foreach (get_users(array('role' => 'administrator')) as $user) {
172
  $notification_options[] = $user->user_login;
173
  }
174
+ echo PostieAdmin::select_html(__('Notify on Error', 'postie'), 'postie-settings[postie_log_error_notify]', $postie_log_error_notify, $notification_options);
175
 
176
+ echo PostieAdmin::boolean_select_html(__("Enable Debug Logging", 'postie'), 'postie-settings[postie_log_debug]', $postie_log_debug, __("Log debug messages to the web server error log.", 'postie'));
177
  ?>
178
 
179
  </table>
config_form_user.php CHANGED
@@ -37,7 +37,7 @@
37
  </td>
38
  </tr>
39
 
40
- <?php echo BuildTextArea(__("Authorized Addresses", 'postie'), "postie-settings[authorized_addresses]", $authorized_addresses, __("Put each email address on a single line. Posts from emails in this list will be treated as if they came from the admin. If you would prefer to have users post under their own name - create a WordPress user with the correct access level.", 'postie')); ?>
41
  <tr>
42
  <th scope="row"><?php _e('Default Poster', 'postie') ?></th>
43
  <td>
@@ -59,8 +59,8 @@
59
  <p class='description'><?php _e("This will be the poster if you allow posting from emails that are not a registered blog user.", 'postie'); ?></p>
60
  </td>
61
  </tr>
62
- <?php echo BuildBooleanSelect(__("Force User Login", 'postie'), "postie-settings[force_user_login]", $force_user_login, __("Changing this to yes will cause Postie to try and login as the 'from' user if they exist. This should be set to 'Yes' if you use custom taxonomies in the subject line.", 'postie')); ?>
63
- <?php echo BuildBooleanSelect(__("Allow Anyone To Post Via Email", 'postie'), "postie-settings[turn_authorization_off]", $turn_authorization_off, __("Changing this to yes <b style='color: red'>is not recommended</b> - anything that gets sent in will automatically be posted.", 'postie')); ?>
64
 
65
  </table>
66
  </div>
37
  </td>
38
  </tr>
39
 
40
+ <?php echo PostieAdmin::textarea_html(__("Authorized Addresses", 'postie'), "postie-settings[authorized_addresses]", $authorized_addresses, __("Put each email address on a single line. Posts from emails in this list will be treated as if they came from the admin. If you would prefer to have users post under their own name - create a WordPress user with the correct access level.", 'postie')); ?>
41
  <tr>
42
  <th scope="row"><?php _e('Default Poster', 'postie') ?></th>
43
  <td>
59
  <p class='description'><?php _e("This will be the poster if you allow posting from emails that are not a registered blog user.", 'postie'); ?></p>
60
  </td>
61
  </tr>
62
+ <?php echo PostieAdmin::boolean_select_html(__("Force User Login", 'postie'), "postie-settings[force_user_login]", $force_user_login, __("Changing this to yes will cause Postie to try and login as the 'from' user if they exist. This should be set to 'Yes' if you use custom taxonomies in the subject line.", 'postie')); ?>
63
+ <?php echo PostieAdmin::boolean_select_html(__("Allow Anyone To Post Via Email", 'postie'), "postie-settings[turn_authorization_off]", $turn_authorization_off, __("Changing this to yes <b style='color: red'>is not recommended</b> - anything that gets sent in will automatically be posted.", 'postie')); ?>
64
 
65
  </table>
66
  </div>
docs/Changes.txt CHANGED
@@ -35,6 +35,14 @@ All script, style and body tags are stripped from html emails.
35
  Attachments are now processed in the order they were attached.
36
 
37
  == CHANGELOG ==
 
 
 
 
 
 
 
 
38
  = 1.8.45 (2017-06-21) =
39
  * Feature: If image placement directive has a caption, update the image metadata to include the caption.
40
  * Fix: Only process delay tag if date was found in header
35
  Attachments are now processed in the order they were attached.
36
 
37
  == CHANGELOG ==
38
+ = 1.9.1 (2017-06-28) =
39
+ * Feature: Add postie_file_added_pre action
40
+ * Fix: improvements to tag detection
41
+ * Fix: tags may be specified multiple times
42
+ * Fix: significant code restructure to bring Postie in line with current coding practices
43
+ * Fix: move signature removal to before newline filtering
44
+ * Fix: signature removal was deleting all text if the matching regex had whitespace characters
45
+
46
  = 1.8.45 (2017-06-21) =
47
  * Feature: If image placement directive has a caption, update the image metadata to include the caption.
48
  * Fix: Only process delay tag if date was found in header
docs/Postie.txt CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.8
9
- Stable tag: 1.8.45
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.8
9
+ Stable tag: 1.9.1
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
lib/fMailbox.php CHANGED
@@ -1004,6 +1004,8 @@ class fMailbox {
1004
  * @return array The parsed email message - see method description for details
1005
  */
1006
  public function fetchMessage($uid, $convert_newlines = FALSE) {
 
 
1007
  $this->connect();
1008
 
1009
  $source = $this->fetchMessageSource($uid);
@@ -1012,8 +1014,8 @@ class fMailbox {
1012
  $info = self::parseMessage($source, $convert_newlines);
1013
  $info['uid'] = $uid;
1014
 
1015
- if (IsDebugMode()) {
1016
- postie_save_email_debug($source, $info);
1017
  }
1018
 
1019
  return $info;
1004
  * @return array The parsed email message - see method description for details
1005
  */
1006
  public function fetchMessage($uid, $convert_newlines = FALSE) {
1007
+ global $g_postie;
1008
+
1009
  $this->connect();
1010
 
1011
  $source = $this->fetchMessageSource($uid);
1014
  $info = self::parseMessage($source, $convert_newlines);
1015
  $info['uid'] = $uid;
1016
 
1017
+ if ($g_postie->is_debugmode()) {
1018
+ $g_postie->save_email_debug($source, $info);
1019
  }
1020
 
1021
  return $info;
postie-admin.class.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class PostieAdmin {
4
+
5
+ /**
6
+ * Takes a value and builds a simple simple yes/no select box
7
+ */
8
+ static function boolean_select_html($label, $id, $current_value, $recommendation = NULL, $options = null) {
9
+
10
+ $html = "<tr>
11
+ <th scope='row'><label for='$id'>$label</label>";
12
+
13
+
14
+ if (!(is_array($options) && count($options) == 2)) {
15
+ $options = Array('Yes', 'No');
16
+ }
17
+
18
+ $html .= "</th>
19
+ <td><select name='$id' id='$id'>
20
+ <option value='1'>" . __($options[0], 'postie') . "</option>
21
+ <option value='0' " . (!$current_value ? "selected='selected'" : "") . ">" . __($options[1], 'postie') . '</option>
22
+ </select>';
23
+ if (!empty($recommendation)) {
24
+ $html .= '<p class = "description">' . $recommendation . '</p>';
25
+ }
26
+ $html .= "</td>\n</tr>";
27
+
28
+ return $html;
29
+ }
30
+
31
+ /**
32
+ * This takes an array and display a text box for editing
33
+ */
34
+ static function textarea_html($label, $id, $current_value, $recommendation = NULL) {
35
+ $html = "<tr><th scope='row'><label for='$id'>$label</label>";
36
+
37
+ $html .= "</th>";
38
+
39
+ $html .= "<td><br /><textarea cols=40 rows=3 name='$id' id='$id'>";
40
+ $current_value = preg_split("/[\r\n]+/", esc_attr(trim($current_value)));
41
+ if (is_array($current_value)) {
42
+ foreach ($current_value as $item) {
43
+ $html .= "$item\n";
44
+ }
45
+ }
46
+ $html .= "</textarea>";
47
+ if ($recommendation) {
48
+ $html .= "<p class='description'>" . $recommendation . "</p>";
49
+ }
50
+ $html .= "</td></tr>";
51
+ return $html;
52
+ }
53
+
54
+ /**
55
+ * Takes a value and builds a simple simple yes/no select box
56
+ */
57
+ static function select_html($label, $id, $current_value, $options, $recommendation = NULL) {
58
+
59
+ $html = "<tr>
60
+ <th scope='row'><label for='$id'>$label</label>";
61
+
62
+ $html .= "</th><td><select name='$id' id='$id'>";
63
+ foreach ($options as $value) {
64
+ $html .= "<option value='$value' " . ($value == $current_value ? "selected='selected'" : "") . ">" . __($value, 'postie') . '</option>';
65
+ }
66
+ $html .= '</select>';
67
+ if (!empty($recommendation)) {
68
+ $html .= '<p class = "description">' . $recommendation . '</p>';
69
+ }
70
+ $html .= "</td>\n</tr>";
71
+
72
+ return $html;
73
+ }
74
+
75
+ }
postie-api.php CHANGED
@@ -1,5 +1,8 @@
1
  <?php
2
 
 
 
 
3
  /*
4
  * These are the only official public methods for accessing postie functionality
5
  */
@@ -17,20 +20,45 @@ function RemoveExtraCharactersInEmailAddress($address) {
17
  }
18
 
19
  function EchoError($v) {
20
- postie_log_error($v);
 
21
  do_action('postie_log_debug', $v);
22
  }
23
 
24
  function DebugDump($v) {
 
25
  if (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG) {
26
- postie_log_onscreen(print_r($v, true));
27
  }
28
  do_action('postie_log_debug', print_r($v, true));
29
  }
30
 
31
  function DebugEcho($v, $force = false) {
 
32
  if ($force || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
33
- postie_log_onscreen($v);
34
  }
35
  do_action('postie_log_debug', $v);
36
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'postie-config.class.php');
4
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'postie.class.php');
5
+
6
  /*
7
  * These are the only official public methods for accessing postie functionality
8
  */
20
  }
21
 
22
  function EchoError($v) {
23
+ global $g_postie;
24
+ $g_postie->log_error($v);
25
  do_action('postie_log_debug', $v);
26
  }
27
 
28
  function DebugDump($v) {
29
+ global $g_postie;
30
  if (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG) {
31
+ $g_postie->log_onscreen(print_r($v, true));
32
  }
33
  do_action('postie_log_debug', print_r($v, true));
34
  }
35
 
36
  function DebugEcho($v, $force = false) {
37
+ global $g_postie;
38
  if ($force || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
39
+ $g_postie->log_onscreen($v);
40
  }
41
  do_action('postie_log_debug', $v);
42
  }
43
+
44
+ function postie_config_read() {
45
+ $pconfig = new PostieConfig();
46
+ return $pconfig->config_read();
47
+ }
48
+
49
+ /**
50
+ * called by WP cron
51
+ */
52
+ function postie_check() {
53
+ //don't use DebugEcho or EchoInfo here as it is not defined when called as an action
54
+ //error_log("check_postie");
55
+ global $g_postie;
56
+ $g_postie->get_mail();
57
+ }
58
+
59
+ function postie_get_mail() {
60
+ //don't use DebugEcho or EchoInfo here as it is not defined when called as an action
61
+ //error_log("check_postie");
62
+ global $g_postie;
63
+ $g_postie->get_mail();
64
+ }
postie-compatibility.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* this function is necessary for wildcard matching on non-posix systems */
4
+ if (!function_exists('fnmatch')) {
5
+
6
+ function fnmatch($pattern, $string) {
7
+ $pattern = strtr(preg_quote($pattern, '#'), array('\*' => '.*', '\?' => '.', '\[' => '[', '\]' => ']'));
8
+ return preg_match('/^' . strtr(addcslashes($pattern, '/\\.+^$(){}=!<>|'), array('*' => '.*', '?' => '.?')) . '$/i', $string);
9
+ }
10
+
11
+ }
12
+
13
+ if (!function_exists('mb_str_replace')) {
14
+ if (function_exists('mb_split')) {
15
+
16
+ function mb_str_replace($search, $replace, $subject, &$count = 0) {
17
+ if (!is_array($subject)) {
18
+ // Normalize $search and $replace so they are both arrays of the same length
19
+ $searches = is_array($search) ? array_values($search) : array($search);
20
+ $replacements = array_pad(is_array($replace) ? array_values($replace) : array($replace), count($searches), '');
21
+
22
+ foreach ($searches as $key => $search) {
23
+ $parts = mb_split(preg_quote($search), $subject);
24
+ $count += count($parts) - 1;
25
+ $subject = implode($replacements[$key], $parts);
26
+ }
27
+ } else {
28
+ // Call mb_str_replace for each subject in array, recursively
29
+ foreach ($subject as $key => $value) {
30
+ $subject[$key] = mb_str_replace($search, $replace, $value, $count);
31
+ }
32
+ }
33
+
34
+ return $subject;
35
+ }
36
+
37
+ } else {
38
+
39
+ function mb_str_replace($search, $replace, $subject, &$count = null) {
40
+ return str_replace($search, $replace, $subject, $count);
41
+ }
42
+
43
+ }
44
+ }
45
+
46
+ if (!function_exists('boolval')) {
47
+
48
+ function boolval($val) {
49
+ return (bool) $val;
50
+ }
51
+
52
+ }
postie-config.class.php ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class PostieConfig {
4
+
5
+ private $config;
6
+
7
+ function __construct() {
8
+ $this->config = $this->config_fetch();
9
+ }
10
+
11
+ function config_fetch() {
12
+ $config = get_option('postie-settings');
13
+ return $this->validate_settings($config);
14
+ }
15
+
16
+ function config_read() {
17
+ return $this->config;
18
+ }
19
+
20
+ /**
21
+ * validates the config form output, fills in any gaps by using the defaults,
22
+ * and ensures that arrayed items are stored as such
23
+ */
24
+ function validate_settings($in) {
25
+ //DebugEcho("config_ValidateSettings");
26
+
27
+ $out = array();
28
+
29
+ //DebugDump($in);
30
+ // use the default as a template:
31
+ // if a field is present in the defaults, we want to store it; otherwise we discard it
32
+ $allowed_keys = $this->defaults();
33
+ foreach ($allowed_keys as $key => $default) {
34
+ if (is_array($in)) {
35
+ $out[$key] = array_key_exists($key, $in) ? $in[$key] : $default;
36
+ } else {
37
+ $out[$key] = $default;
38
+ }
39
+ }
40
+
41
+ // some fields are always forced to lower case:
42
+ $lowercase = array('authorized_addresses', 'smtp', 'supported_file_types', 'video1types', 'video2types', 'audiotypes');
43
+ foreach ($lowercase as $field) {
44
+ $out[$field] = ( is_array($out[$field]) ) ? array_map("strtolower", $out[$field]) : strtolower($out[$field]);
45
+ }
46
+ $arrays = $this->arrayed_settings();
47
+
48
+ foreach ($arrays as $sep => $fields) {
49
+ foreach ($fields as $field) {
50
+ if (!is_array($out[$field])) {
51
+ $out[$field] = explode($sep, trim($out[$field]));
52
+ }
53
+ foreach ($out[$field] as $key => $val) {
54
+ $tst = trim($val);
55
+ if
56
+ (empty($tst)) {
57
+ unset($out[$field][$key]);
58
+ } else {
59
+ $out[$field][$key] = $tst;
60
+ }
61
+ }
62
+ }
63
+ }
64
+
65
+ $this->fix_permission_cron($out);
66
+ return $out;
67
+ }
68
+
69
+ /**
70
+ * This function used to handle updating the configuration.
71
+ * @return boolean
72
+ */
73
+ function fix_permission_cron($data) {
74
+ $this->update_permissions($data['role_access']);
75
+ // We also update the cron settings
76
+ PostieInit::postie_cron_hook($data['interval']);
77
+ }
78
+
79
+ /**
80
+ * This function handles setting up the basic permissions
81
+ */
82
+ function update_permissions($role_access) {
83
+ global $wp_roles;
84
+ if (is_object($wp_roles)) {
85
+ $admin = $wp_roles->get_role('administrator');
86
+ $admin->add_cap('config_postie');
87
+ $admin->add_cap('post_via_postie');
88
+
89
+ if (!is_array($role_access)) {
90
+ $role_access = array();
91
+ }
92
+ foreach ($wp_roles->role_names as $roleId => $name) {
93
+ $role = $wp_roles->get_role($roleId);
94
+ if ($roleId != 'administrator') {
95
+ if (array_key_exists($roleId, $role_access)) {
96
+ $role->add_cap('post_via_postie');
97
+ //DebugEcho("added $roleId");
98
+ } else {
99
+ $role->remove_cap('post_via_postie');
100
+ //DebugEcho("removed $roleId");
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Returns a list of config keys that should be arrays
109
+ * @return array
110
+ */
111
+ function arrayed_settings() {
112
+ return array(
113
+ ', ' => array('audiotypes', 'video1types', 'video2types', 'default_post_tags'),
114
+ "\n" => array('smtp', 'authorized_addresses', 'supported_file_types', 'banned_files_list', 'sig_pattern_list'));
115
+ }
116
+
117
+ /**
118
+ * return an array of the config defaults
119
+ */
120
+ function defaults() {
121
+ include('templates/audio_templates.php');
122
+ include('templates/image_templates.php');
123
+ include('templates/video1_templates.php');
124
+ include('templates/video2_templates.php');
125
+ include 'templates/general_template.php';
126
+ return array(
127
+ 'add_meta' => 'no',
128
+ 'admin_username' => 'admin',
129
+ 'allow_html_in_body' => true,
130
+ 'allow_html_in_subject' => true,
131
+ 'allow_subject_in_mail' => true,
132
+ 'audiotemplate' => $simple_link,
133
+ 'audiotypes' => array('m4a', 'mp3', 'ogg', 'wav', 'mpeg'),
134
+ 'authorized_addresses' => array(),
135
+ 'banned_files_list' => array(),
136
+ 'confirmation_email' => '',
137
+ 'convertnewline' => false,
138
+ 'converturls' => true,
139
+ 'custom_image_field' => false,
140
+ 'default_post_category' => NULL,
141
+ 'category_match' => true,
142
+ 'default_post_tags' => array(),
143
+ 'default_title' => "Live From The Field",
144
+ 'delete_mail_after_processing' => true,
145
+ 'drop_signature' => true,
146
+ 'filternewlines' => true,
147
+ 'forward_rejected_mail' => true,
148
+ 'icon_set' => 'silver',
149
+ 'icon_size' => 32,
150
+ 'auto_gallery' => false,
151
+ 'image_new_window' => false,
152
+ 'image_placeholder' => "#img%#",
153
+ 'images_append' => true,
154
+ 'imagetemplate' => $wordpress_default,
155
+ 'imagetemplates' => $imageTemplates,
156
+ 'input_protocol' => "pop3",
157
+ 'input_connection' => 'sockets',
158
+ 'interval' => 'twiceperhour',
159
+ 'mail_server' => NULL,
160
+ 'mail_server_port' => 110,
161
+ 'mail_userid' => NULL,
162
+ 'mail_password' => NULL,
163
+ 'maxemails' => 0,
164
+ 'message_start' => ":start",
165
+ 'message_end' => ":end",
166
+ 'message_encoding' => "UTF-8",
167
+ 'message_dequote' => true,
168
+ 'post_status' => 'publish',
169
+ 'prefer_text_type' => "plain",
170
+ 'return_to_sender' => false,
171
+ 'role_access' => array(),
172
+ 'selected_audiotemplate' => 'simple_link',
173
+ 'selected_imagetemplate' => 'wordpress_default',
174
+ 'selected_video1template' => 'vshortcode',
175
+ 'selected_video2template' => 'simple_link',
176
+ 'shortcode' => false,
177
+ 'sig_pattern_list' => array('--\s?[\r\n]?', '--\s', '--', '---'),
178
+ 'smtp' => array(),
179
+ 'start_image_count_at_zero' => false,
180
+ 'supported_file_types' => array('application'),
181
+ 'turn_authorization_off' => false,
182
+ 'time_offset' => get_option('gmt_offset'),
183
+ 'video1template' => $simple_link,
184
+ 'video1types' => array('mp4', 'mpeg4', '3gp', '3gpp', '3gpp2', '3gp2', 'mov', 'mpeg', 'quicktime'),
185
+ 'video2template' => $simple_link,
186
+ 'video2types' => array('x-flv'),
187
+ 'video1templates' => $video1Templates,
188
+ 'video2templates' => $video2Templates,
189
+ 'wrap_pre' => 'no',
190
+ 'featured_image' => false,
191
+ 'include_featured_image' => true,
192
+ 'email_tls' => false,
193
+ 'post_format' => 'standard',
194
+ 'post_type' => 'post',
195
+ 'generaltemplates' => $generalTemplates,
196
+ 'generaltemplate' => $postie_default,
197
+ 'selected_generaltemplate' => 'postie_default',
198
+ 'generate_thumbnails' => true,
199
+ 'reply_as_comment' => true,
200
+ 'force_user_login' => false,
201
+ 'auto_gallery_link' => 'default',
202
+ 'ignore_mail_state' => false,
203
+ 'strip_reply' => true,
204
+ 'postie_log_error' => true,
205
+ 'postie_log_debug' => false,
206
+ 'category_colon' => true,
207
+ 'category_dash' => true,
208
+ 'category_bracket' => true,
209
+ 'prefer_text_convert' => true,
210
+ 'category_remove' => true,
211
+ 'ignore_email_date' => false,
212
+ 'use_time_offset' => false,
213
+ 'postie_log_error_notify' => '(All Admins)'
214
+ );
215
+ }
216
+
217
+ /**
218
+ * This function resets all the configuration options to the default
219
+ */
220
+ function reset_to_default() {
221
+ $newconfig = $this->defaults();
222
+ $config = get_option('postie-settings');
223
+ $save_keys = array('mail_password', 'mail_server', 'mail_server_port', 'mail_userid', 'input_protocol', 'input_connection');
224
+ foreach ($save_keys as $key) {
225
+ $newconfig[$key] = $config[$key];
226
+ }
227
+ update_option('postie-settings', $newconfig);
228
+ $this->fix_permission_cron($newconfig);
229
+ return $newconfig;
230
+ }
231
+
232
+ }
postie-filters.php ADDED
@@ -0,0 +1,483 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/autolink.php");
4
+
5
+ function filter_AttachmentTemplates($content, $mimeDecodedEmail, $post_id, $config) {
6
+ global $g_postie;
7
+
8
+ $matches = array();
9
+ $addimages = !($config['custom_image_field'] || $config['auto_gallery'] || preg_match("/\[gallery[^\[]*\]/u", $content, $matches));
10
+ $fiid = -1;
11
+
12
+ DebugEcho("filter_AttachmentTemplates: looking for attachments to add to post");
13
+ $html = '';
14
+ if (!$config['include_featured_image']) {
15
+ //find the image to exclude
16
+ $fiid = get_post_thumbnail_id($post_id);
17
+ }
18
+ DebugEcho("filter_AttachmentTemplates: featured image: $fiid");
19
+
20
+ DebugEcho("filter_AttachmentTemplates: # attachments: " . count($mimeDecodedEmail['attachment']));
21
+ foreach ($mimeDecodedEmail['attachment'] as $attachment) {
22
+ DebugEcho("filter_AttachmentTemplates: image: " . $attachment['wp_filename']);
23
+ $skip = ($fiid == $attachment['wp_id'] && !$config['include_featured_image']) || $attachment['exclude'];
24
+ if (!$skip) {
25
+ if (!$addimages && $attachment['primary'] == 'image') {
26
+ DebugEcho("filter_AttachmentTemplates: skip image " . $attachment['wp_filename']);
27
+ } else {
28
+ $template = $attachment['template'];
29
+ if ($config['images_append']) {
30
+ DebugEcho("filter_AttachmentTemplates: pre postie_place_media_after");
31
+ $template = apply_filters('postie_place_media_after', $template, $attachment['wp_id']);
32
+ } else {
33
+ DebugEcho("filter_AttachmentTemplates: pre postie_place_media_before");
34
+ $template = apply_filters('postie_place_media_before', $template, $attachment['wp_id']);
35
+ }
36
+ $template = mb_str_replace('{CAPTION}', '', $template);
37
+ DebugEcho("filter_AttachmentTemplates: post filter '$template'");
38
+ $html .= $template;
39
+ }
40
+ } else {
41
+ DebugEcho("filter_AttachmentTemplates: skip attachment " . $attachment['wp_filename']);
42
+ }
43
+ }
44
+
45
+ DebugEcho("filter_AttachmentTemplates: # inline: " . count($mimeDecodedEmail['inline']));
46
+ DebugEcho("filter_AttachmentTemplates: # related: " . count($mimeDecodedEmail['related']));
47
+ foreach (array_merge($mimeDecodedEmail['inline'], $mimeDecodedEmail['related']) as $attachment) {
48
+ DebugEcho("filter_AttachmentTemplates: image: " . $attachment['wp_filename']);
49
+ $skip = ($fiid == $attachment['wp_id'] && !$config['include_featured_image']) || $attachment['exclude'];
50
+ if (!$skip) {
51
+ if (!$addimages && $attachment['primary'] == 'image') {
52
+ DebugEcho("filter_AttachmentTemplates: skip image (alt) " . $attachment['wp_filename']);
53
+ } else {
54
+ $template = $attachment['template'];
55
+ if ($config['images_append']) {
56
+ DebugEcho("filter_AttachmentTemplates: pre postie_place_media_after");
57
+ $template = apply_filters('postie_place_media_after', $template, $attachment['wp_id']);
58
+ } else {
59
+ DebugEcho("filter_AttachmentTemplates: pre postie_place_media_before");
60
+ $template = apply_filters('postie_place_media_before', $template, $attachment['wp_id']);
61
+ }
62
+ $template = mb_str_replace('{CAPTION}', '', $template);
63
+ DebugEcho("filter_AttachmentTemplates: post filter (alt) '$template'");
64
+ $html .= $template;
65
+ }
66
+ } else {
67
+ DebugEcho("filter_AttachmentTemplates: skip attachment (alt) " . $attachment['wp_filename']);
68
+ }
69
+ }
70
+
71
+ if (!empty($html)) {
72
+ if ($config['images_append']) {
73
+ $content = $content . '<div class="postie-attachments">' . $html . '</div>';
74
+ } else {
75
+ $content = '<div class="postie-attachments">' . $html . '</div>' . $content;
76
+ }
77
+ }
78
+
79
+
80
+ //strip featured image from html
81
+ if ($fiid > 0 && $config['prefer_text_type'] == 'html' && !$config['include_featured_image']) {
82
+ DebugEcho("filter_AttachmentTemplates: remove featured image from post");
83
+ $html = str_get_html($content);
84
+ if ($html) {
85
+ $elements = $html->find('img[src=' . wp_get_attachment_url($fiid) . ']');
86
+ foreach ($elements as $e) {
87
+ DebugEcho('filter_AttachmentTemplates: outertext:' . $e->outertext);
88
+ $e->outertext = '';
89
+ }
90
+ $content = $html->save();
91
+ }
92
+ }
93
+
94
+ $imagecount = 0;
95
+ foreach ($mimeDecodedEmail['attachment'] as $attachment) {
96
+ DebugEcho("filter_AttachmentTemplates: attachment mime primary: {$attachment['primary']}");
97
+ if ($attachment['primary'] == 'image' && $attachment['exclude'] == false) {
98
+ $imagecount++;
99
+ }
100
+ }
101
+ if ($config['prefer_text_type'] == 'plain') {
102
+ foreach (array_merge($mimeDecodedEmail['inline'], $mimeDecodedEmail['related']) as $attachment) {
103
+ DebugEcho("filter_AttachmentTemplates: attachment mime primary: {$attachment['primary']}");
104
+ if ($attachment['primary'] == 'image' && $attachment['exclude'] == false) {
105
+ $imagecount++;
106
+ }
107
+ }
108
+ }
109
+ DebugEcho("filter_AttachmentTemplates: image count $imagecount");
110
+
111
+ if (($imagecount > 0) && $config['auto_gallery']) {
112
+ $linktype = strtolower($config['auto_gallery_link']);
113
+ DebugEcho("filter_AttachmentTemplates: Auto gallery: link type $linktype");
114
+ $g_postie->show_filters_for('postie_gallery');
115
+ if ($linktype == 'default') {
116
+ DebugEcho("filter_AttachmentTemplates: pre postie_gallery (default)");
117
+ $imageTemplate = apply_filters('postie_gallery', '[gallery]', $post_id);
118
+ } else {
119
+ DebugEcho("filter_AttachmentTemplates: pre postie_gallery ($linktype)");
120
+ $imageTemplate = apply_filters('postie_gallery', "[gallery link='$linktype']", $post_id);
121
+ }
122
+ DebugEcho("filter_AttachmentTemplates: Auto gallery: template '$imageTemplate'");
123
+ if ($config['images_append']) {
124
+ $content .= "\n$imageTemplate";
125
+ DebugEcho("filter_AttachmentTemplates: Auto gallery: append");
126
+ } else {
127
+ $content = "$imageTemplate\n" . $content;
128
+ DebugEcho("filter_AttachmentTemplates: Auto gallery: prepend");
129
+ }
130
+ } else {
131
+ DebugEcho("filter_AttachmentTemplates: Auto gallery: none");
132
+ }
133
+
134
+ return $content;
135
+ }
136
+
137
+ // This function cleans up HTML in the email
138
+ function filter_CleanHtml($content) {
139
+ $html = str_get_html($content);
140
+ if ($html) {
141
+ DebugEcho("filter_CleanHtml: checking filter postie_cleanhtml");
142
+ if (apply_filters('postie_cleanhtml', true)) {
143
+ DebugEcho("filter_CleanHtml: Looking for invalid tags");
144
+ foreach ($html->find('script, style, head') as $node) {
145
+ DebugEcho("filter_CleanHtml: Removing: " . $node->outertext);
146
+ $node->outertext = '';
147
+ }
148
+ DebugEcho("filter_CleanHtml: " . $html->save());
149
+
150
+ $html->load($html->save());
151
+
152
+ $b = $html->find('body');
153
+ if ($b) {
154
+ DebugEcho("filter_CleanHtml: replacing body with div");
155
+ $content = "<div>" . $b[0]->innertext . "</div>\n";
156
+ }
157
+ } else {
158
+ DebugEcho("filter_CleanHtml: skipping clean html due to filter");
159
+ }
160
+ } else {
161
+ DebugEcho("filter_CleanHtml: No HTML found");
162
+ }
163
+ return $content;
164
+ }
165
+
166
+ /**
167
+ * Looks at the content for the start of the message and removes everything before that
168
+ * If the pattern is not found everything is returned
169
+ * @param string
170
+ * @param string
171
+ */
172
+ function filter_Start($content, $config) {
173
+ $start = $config['message_start'];
174
+ if (!empty($start)) {
175
+ $pos = stripos($content, $start);
176
+ if ($pos === false) {
177
+ return $content;
178
+ }
179
+ DebugEcho("start filter $start");
180
+ $content = substr($content, $pos + strlen($start), strlen($content));
181
+ }
182
+ return $content;
183
+ }
184
+
185
+ /**
186
+ * Looks at the content for the start of the signature and removes all text
187
+ * after that point
188
+ * @param string
189
+ * @param array - a list of patterns to determine if it is a sig block
190
+ */
191
+ function filter_RemoveSignature($content, $config) {
192
+ global $g_postie;
193
+
194
+ DebugEcho("filter_RemoveSignature: start");
195
+ if ($config['drop_signature']) {
196
+ if (empty($config['sig_pattern_list'])) {
197
+ DebugEcho("filter_RemoveSignature: no sig_pattern_list");
198
+ return $content;
199
+ }
200
+ //DebugEcho("looking for signature in: $content");
201
+
202
+ $pattern = '/^(' . implode('|', $config['sig_pattern_list']) . ')\s?$/miu';
203
+ DebugEcho("filter_RemoveSignature: pattern: $pattern");
204
+
205
+ $html = $g_postie->load_html($content);
206
+ if ($html !== false) {
207
+ filter_RemoveSignatureWorker($html->root, $pattern);
208
+ $content = $html->save();
209
+ } else {
210
+ DebugEcho("filter_RemoveSignature: non-html");
211
+ $arrcontent = explode("\n", $content);
212
+ $strcontent = '';
213
+
214
+ for ($i = 0; $i < count($arrcontent); $i++) {
215
+ $line = trim($arrcontent[$i]);
216
+ if (preg_match($pattern, trim($line))) {
217
+ DebugEcho("filter_RemoveSignature: signature found: removing");
218
+ break;
219
+ }
220
+
221
+ DebugEcho("filter_RemoveSignature: keeping '$line'");
222
+ $strcontent .= $line;
223
+ }
224
+ $content = $strcontent;
225
+ }
226
+ } else {
227
+ DebugEcho("filter_RemoveSignature: configured to skip");
228
+ }
229
+ return $content;
230
+ }
231
+
232
+ function filter_RemoveSignatureWorker(&$html, $pattern) {
233
+ $found = false;
234
+ $matches = array();
235
+ if (preg_match($pattern, trim($html->plaintext), $matches)) {
236
+ $sig = trim($matches[1]);
237
+ DebugEcho("filter_RemoveSignatureWorker: signature '$sig' found in:\n" . trim($html->plaintext));
238
+ //DebugDump($matches);
239
+ $found = true;
240
+ $i = stripos($html->innertext, $sig);
241
+ if (false !== $i) {
242
+ DebugEcho("filter_RemoveSignatureWorker: signature index: $i");
243
+ $presig = substr($html->innertext, 0, $i);
244
+ DebugEcho("filter_RemoveSignatureWorker sig new text:\n$presig");
245
+ $html->innertext = $presig;
246
+ } else {
247
+ DebugEcho("filter_RemoveSignatureWorker: signature not found: '$sig' " . strlen($sig));
248
+ }
249
+ } else {
250
+ DebugEcho("filter_RemoveSignatureWorker: no matches " . preg_last_error() . " '$pattern' $html->plaintext");
251
+ //DebugDump($matches);
252
+ }
253
+
254
+ foreach ($html->children() as $e) {
255
+ //DebugEcho("sig: " . $e->plaintext);
256
+ if (!$found && preg_match($pattern, trim($e->plaintext))) {
257
+ DebugEcho("filter_RemoveSignatureWorker signature found: removing");
258
+ $found = true;
259
+ }
260
+ if ($found) {
261
+ $e->outertext = '';
262
+ } else {
263
+ $found = filter_RemoveSignatureWorker($e, $pattern);
264
+ }
265
+ }
266
+ return $found;
267
+ }
268
+
269
+ /**
270
+ * Looks at the content for the given tag and removes all text
271
+ * after that point
272
+ * @param string
273
+ * @param filter
274
+ */
275
+ function filter_End($content, $config) {
276
+ $end = $config['message_end'];
277
+ if (!empty($end)) {
278
+ $pos = stripos($content, $end);
279
+ if ($pos === false) {
280
+ return $content;
281
+ }
282
+ DebugEcho("end filter: $end");
283
+ $content = substr($content, 0, $pos);
284
+ }
285
+ return $content;
286
+ }
287
+
288
+ //filter content for new lines
289
+ function filter_Newlines($content, $config) {
290
+ if ($config['filternewlines']) {
291
+ DebugEcho("filter_Newlines: filternewlines");
292
+ $search = array(
293
+ "/\r\n\r\n/",
294
+ "/\r\n/",
295
+ "/\n\n/",
296
+ "/\r/",
297
+ "/\n/"
298
+ );
299
+ $replace = array(
300
+ 'PARABREAK',
301
+ 'LINEBREAK',
302
+ 'LINEBREAK',
303
+ 'LINEBREAK',
304
+ 'LINEBREAK'
305
+ );
306
+
307
+ $result = preg_replace($search, $replace, $content);
308
+ DebugDump($result);
309
+
310
+ if ($config['convertnewline']) {
311
+ DebugEcho("filter_Newlines: converting newlines to <br>");
312
+ $content = preg_replace('/(LINEBREAK)/', "<br />\n", $result);
313
+ $content = preg_replace('/(PARABREAK)/', "<br />\n<br />\n", $content);
314
+ } else {
315
+ $content = preg_replace('/(LINEBREAK)/', " ", $result);
316
+ $content = preg_replace('/(PARABREAK)/', "\r\n", $content);
317
+ }
318
+ }
319
+ return $content;
320
+ }
321
+
322
+ //strip pgp stuff
323
+ function filter_StripPGP($content) {
324
+ $search = array(
325
+ '/-----BEGIN PGP SIGNED MESSAGE-----/',
326
+ '/Hash: SHA1/'
327
+ );
328
+ $replace = array(
329
+ ' ',
330
+ ''
331
+ );
332
+ return preg_replace($search, $replace, $content);
333
+ }
334
+
335
+ function filter_Linkify($text) {
336
+ DebugEcho("begin: filter_linkify");
337
+ $oe = _wp_oembed_get_object();
338
+
339
+ $al = new PostieAutolink();
340
+ DebugEcho("begin: filter_linkify (html)");
341
+ $text = $al->autolink($text, $oe);
342
+ DebugEcho("begin: filter_linkify (email)");
343
+ return $al->autolink_email($text);
344
+ }
345
+
346
+ /**
347
+ * When sending in HTML email the html refers to the content-id(CID) of the image - this replaces
348
+ * the cid place holder with the actual url of the image sent in
349
+ * @param string - text of post
350
+ * @param array - array of HTML for images for post
351
+ */
352
+ function filter_ReplaceImageCIDs($content, &$email) {
353
+ DebugEcho('filter_ReplaceImageCIDs: start');
354
+ $content = preg_replace("/\[(cid:\S+)\]/i", '<img src="$1"/>', $content); //fix "[cid:xxx-xxx-xx]" image references gmail adds to plain text
355
+ if (count($email['related'])) {
356
+ DebugEcho("filter_ReplaceImageCIDs: # CID attachments: " . count($email['related']));
357
+ foreach ($email['related'] as $cid => &$attachment) {
358
+ if (false !== stripos($content, $cid)) {
359
+ DebugEcho("filter_ReplaceImageCIDs: CID: $cid");
360
+ $fileid = $attachment['wp_id'];
361
+ $url = wp_get_attachment_url($fileid);
362
+ $content = str_replace($cid, $url, $content);
363
+ $attachment['exclude'] = true;
364
+ } else {
365
+ DebugEcho("filter_ReplaceImageCIDs: CID not found: $cid");
366
+ }
367
+ }
368
+ } else {
369
+ DebugEcho("filter_ReplaceImageCIDs: no cid attachments");
370
+ }
371
+ return $content;
372
+ }
373
+
374
+ function filter_ReplaceInlineImage($content, &$email, $config) {
375
+ DebugEcho('filter_ReplaceInlineImage: start');
376
+ $i = 1;
377
+ foreach ($email['inline'] as &$inlineImage) {
378
+ if (($inlineImage['primary'] == 'image' && $config['auto_gallery']) ||
379
+ $config['custom_image_field'] ||
380
+ $config['featured_image'] && !$config['include_featured_image'] && $i == 1) {
381
+ //remove inline placeholder if we're not showing the image here
382
+ DebugEcho('filter_ReplaceInlineImage: do not add inline due to config');
383
+ $template = '';
384
+ } else {
385
+ $template = $inlineImage['template'];
386
+ }
387
+ $inlinemarker = '<:inline ' . $inlineImage['filename'] . ' inline:>'; //use the original non-sanitized name
388
+ if (false !== stripos($content, $inlinemarker)) {
389
+ DebugEcho('filter_ReplaceInlineImage: ' . $inlineImage['filename']);
390
+ $content = str_ireplace($inlinemarker, $template, $content);
391
+ $inlineImage['exclude'] = !empty($template); //don't exclude if we didn't add
392
+ } else {
393
+ DebugEcho('filter_ReplaceInlineImage: not found: ' . $inlineImage['filename']);
394
+ }
395
+ $i++;
396
+ }
397
+ return $content;
398
+ }
399
+
400
+ /**
401
+ * This function handles replacing image place holder #img1# with the HTML for that image
402
+ */
403
+ function filter_ReplaceImagePlaceHolders($content, &$email, $config, $post_id, $image_pattern) {
404
+ DebugEcho("filter_ReplaceImagePlaceHolders: start");
405
+ if (!$config['custom_image_field']) {
406
+ $startIndex = $config['start_image_count_at_zero'] ? 0 : 1;
407
+
408
+ $images = get_posts(array(
409
+ 'post_parent' => $post_id,
410
+ 'post_type' => 'attachment',
411
+ 'numberposts' => -1,
412
+ 'post_mime_type' => 'image',));
413
+ DebugEcho("filter_ReplaceImagePlaceHolders: images in post: " . count($images));
414
+ DebugDump($images);
415
+
416
+ $i = 0;
417
+
418
+ //TODO only call the worker if the attachment matches one of the images
419
+ foreach ($email['attachment'] as &$attachment) {
420
+ $content = filter_ReplaceImagePlaceHolders_worker($content, $attachment, $image_pattern, $startIndex, $i);
421
+ $i++;
422
+ }
423
+ foreach ($email['inline'] as &$attachment) {
424
+ $content = filter_ReplaceImagePlaceHolders_worker($content, $attachment, $image_pattern, $startIndex, $i);
425
+ $i++;
426
+ }
427
+ foreach ($email['related'] as &$attachment) {
428
+ $content = filter_ReplaceImagePlaceHolders_worker($content, $attachment, $image_pattern, $startIndex, $i);
429
+ $i++;
430
+ }
431
+ } else {
432
+ DebugEcho("filter_ReplaceImagePlaceHolders: Custom image field, not adding images");
433
+ }
434
+ DebugEcho("filter_ReplaceImagePlaceHolders: end");
435
+ return $content;
436
+ }
437
+
438
+ function filter_ReplaceImagePlaceHolders_worker($content, &$attachment, $imagePattern, $startIndex, $currentIndex) {
439
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: " . $attachment['wp_filename']);
440
+
441
+ if (empty($attachment['template'])) {
442
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: no template");
443
+ return $content;
444
+ }
445
+
446
+ $matches = array();
447
+ $pparts = explode('%', $imagePattern);
448
+ if (count($pparts) != 2) {
449
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: invalid image pattern: $imagePattern");
450
+ return $content;
451
+ }
452
+ $pattern = '/' . $pparts[0] . (string) ($startIndex + $currentIndex) . '\s?(caption=[\'"]?(.*?)[\'"]?)?' . $pparts[1] . '/iu';
453
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: pattern: $pattern");
454
+ preg_match_all($pattern, $content, $matches, PREG_SET_ORDER);
455
+ //DebugEcho($content);
456
+ DebugDump($matches);
457
+ foreach ($matches as $match) {
458
+ $attachment['exclude'] = true;
459
+ $imageTemplate = $attachment['template'];
460
+
461
+ $caption = '';
462
+ if (count($match) > 2) {
463
+ $caption = trim($match[2]);
464
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: caption: '$caption'");
465
+ }
466
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: parameterize templete: $imageTemplate");
467
+ $imageTemplate = mb_str_replace('{CAPTION}', htmlspecialchars($caption, ENT_QUOTES), $imageTemplate);
468
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: captioned template: $imageTemplate");
469
+
470
+ if (!empty($caption)) {
471
+ $img = get_post($attachment['wp_id']);
472
+ $img->post_excerpt = $caption;
473
+ wp_update_post($img);
474
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: caption added to metadata");
475
+ }
476
+ $imageTemplate = apply_filters('postie_place_media', $imageTemplate, $attachment['wp_id']);
477
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: post postie_place_media: '$imageTemplate'");
478
+
479
+ $content = str_ireplace($match[0], $imageTemplate, $content);
480
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: post replace: $content");
481
+ }
482
+ return $content;
483
+ }
postie-functions.php DELETED
@@ -1,3305 +0,0 @@
1
- <?php
2
- /*
3
- $Id: postie-functions.php 1682900 2017-06-21 19:45:59Z WayneAllen $
4
- */
5
-
6
- class PostiePostModifiers {
7
-
8
- var $PostFormat = 'standard';
9
-
10
- function apply($postid) {
11
-
12
- if ($this->PostFormat != 'standard') {
13
- set_post_format($postid, $this->PostFormat);
14
- }
15
- }
16
-
17
- }
18
-
19
- if (!function_exists('boolval')) {
20
-
21
- function boolval($val) {
22
- return (bool) $val;
23
- }
24
-
25
- }
26
-
27
- if (!function_exists('mb_str_replace')) {
28
- if (function_exists('mb_split')) {
29
-
30
- function mb_str_replace($search, $replace, $subject, &$count = 0) {
31
- if (!is_array($subject)) {
32
- // Normalize $search and $replace so they are both arrays of the same length
33
- $searches = is_array($search) ? array_values($search) : array($search);
34
- $replacements = array_pad(is_array($replace) ? array_values($replace) : array($replace), count($searches), '');
35
-
36
- foreach ($searches as $key => $search) {
37
- $parts = mb_split(preg_quote($search), $subject);
38
- $count += count($parts) - 1;
39
- $subject = implode($replacements[$key], $parts);
40
- }
41
- } else {
42
- // Call mb_str_replace for each subject in array, recursively
43
- foreach ($subject as $key => $value) {
44
- $subject[$key] = mb_str_replace($search, $replace, $value, $count);
45
- }
46
- }
47
-
48
- return $subject;
49
- }
50
-
51
- } else {
52
-
53
- function mb_str_replace($search, $replace, $subject, &$count = null) {
54
- return str_replace($search, $replace, $subject, $count);
55
- }
56
-
57
- }
58
- }
59
-
60
- function postie_environment($force_display = false) {
61
- DebugEcho("OS: " . php_uname(), $force_display);
62
- DebugEcho("PHP Version: " . phpversion(), $force_display);
63
- DebugEcho("PHP error_log: " . ini_get('error_log'), $force_display);
64
- DebugEcho("PHP log_errors: " . (ini_get('log_errors') ? 'On' : 'Off'), $force_display);
65
- DebugEcho("PHP get_temp_dir: " . get_temp_dir(), $force_display);
66
- if (function_exists('curl_version')) {
67
- $cv = curl_version();
68
- DebugEcho("PHP cURL version: " . $cv['version'], $force_display);
69
- }
70
-
71
- DebugEcho("WordPress Version: " . get_bloginfo('version'), $force_display);
72
- if (defined('MULTISITE') && MULTISITE) {
73
- DebugEcho("WordPress Multisite", $force_display);
74
- DebugEcho("network_home_url(): " . network_home_url(), $force_display);
75
- } else {
76
- DebugEcho("WordPress Singlesite", $force_display);
77
- }
78
- DebugEcho("WP_TEMP_DIR: " . (defined('WP_TEMP_DIR') ? WP_TEMP_DIR : '(none)'), $force_display);
79
- DebugEcho("WP_HOME: " . (defined('WP_HOME') ? WP_HOME : '(none)'), $force_display);
80
- DebugEcho("home_url(): " . home_url(), $force_display);
81
- DebugEcho("WP_SITEURL: " . (defined('WP_SITEURL') ? WP_SITEURL : '(none)'), $force_display);
82
- DebugEcho("site_url(): " . site_url(), $force_display);
83
-
84
- if (defined('WP_DEBUG')) {
85
- DebugEcho("WP_DEBUG: " . (WP_DEBUG === true ? 'On' : 'Off'), $force_display);
86
- } else {
87
- DebugEcho("WP_DEBUG: Off", $force_display);
88
- }
89
-
90
- if (defined('WP_DEBUG_DISPLAY')) {
91
- if (null == WP_DEBUG_DISPLAY) {
92
- DebugEcho("WP_DEBUG_DISPLAY: null", $force_display);
93
- } else {
94
- DebugEcho("WP_DEBUG_DISPLAY: " . (WP_DEBUG_DISPLAY === true ? 'On' : 'Off'), $force_display);
95
- }
96
- } else {
97
- DebugEcho("WP_DEBUG_DISPLAY: Off", $force_display);
98
- }
99
-
100
- if (defined('WP_DEBUG_LOG')) {
101
- DebugEcho("WP_DEBUG_LOG: " . (WP_DEBUG_LOG === true ? 'On' : 'Off'), $force_display);
102
- } else {
103
- DebugEcho("WP_DEBUG_LOG: Off", $force_display);
104
- }
105
-
106
- if (defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
107
- DebugEcho("Alternate cron is enabled", $force_display);
108
- }
109
-
110
- if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) {
111
- DebugEcho("WordPress cron is disabled. Postie will not run unless you have an external cron set up.", $force_display);
112
- }
113
-
114
- if (defined('WP_MAX_MEMORY_LIMIT ')) {
115
- DebugEcho("WP_MAX_MEMORY_LIMIT: " . WP_MAX_MEMORY_LIMIT, $force_display);
116
- } else {
117
- DebugEcho("WP_MAX_MEMORY_LIMIT: 256M (default)", $force_display);
118
- }
119
-
120
- if (defined('WP_MEMORY_LIMIT')) {
121
- DebugEcho("WP_MEMORY_LIMIT: " . WP_MEMORY_LIMIT, $force_display);
122
- } else {
123
- DebugEcho("WP_MEMORY_LIMIT: 32M (default)", $force_display);
124
- }
125
-
126
- DebugEcho("DISABLE_WP_CRON: " . (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON === true ? 'On' : 'Off'), $force_display);
127
- DebugEcho("ALTERNATE_WP_CRON: " . (defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON === true ? 'On' : 'Off'), $force_display);
128
-
129
- if (defined('WP_CRON_LOCK_TIMEOUT')) {
130
- DebugEcho("WP_CRON_LOCK_TIMEOUT: " . WP_CRON_LOCK_TIMEOUT, $force_display);
131
- }
132
-
133
- if (postie_IsIconvInstalled()) {
134
- DebugEcho("iconv: present", $force_display);
135
- } else {
136
- DebugEcho("iconv: missing", $force_display);
137
- }
138
-
139
- DebugEcho('Active plugins', $force_display);
140
- DebugDump(get_option('active_plugins'));
141
-
142
- DebugEcho("Postie is in " . plugin_dir_path(__FILE__), $force_display);
143
- DebugEcho("Postie Version: " . POSTIE_VERSION, $force_display);
144
- DebugEcho("POSTIE_DEBUG: " . (IsDebugMode() ? 'On' : 'Off'), $force_display);
145
- }
146
-
147
- function postie_disable_revisions($restore = false) {
148
- global $_wp_post_type_features, $_postie_revisions;
149
-
150
- if (!$restore) {
151
- $_postie_revisions = false;
152
- if (isset($_wp_post_type_features['post']) && isset($_wp_post_type_features['post']['revisions'])) {
153
- $_postie_revisions = $_wp_post_type_features['post']['revisions'];
154
- unset($_wp_post_type_features['post']['revisions']);
155
- }
156
- } else {
157
- if ($_postie_revisions) {
158
- $_wp_post_type_features['post']['revisions'] = $_postie_revisions;
159
- }
160
- }
161
- }
162
-
163
- /* this function is necessary for wildcard matching on non-posix systems */
164
- if (!function_exists('fnmatch')) {
165
-
166
- function fnmatch($pattern, $string) {
167
- $pattern = strtr(preg_quote($pattern, '#'), array('\*' => '.*', '\?' => '.', '\[' => '[', '\]' => ']'));
168
- return preg_match('/^' . strtr(addcslashes($pattern, '/\\.+^$(){}=!<>|'), array('*' => '.*', '?' => '.?')) . '$/i', $string);
169
- }
170
-
171
- }
172
-
173
- function postie_log_onscreen($data) {
174
- if (php_sapi_name() == "cli") {
175
- print( "$data\n");
176
- } else {
177
- //flush the buffers
178
- while (ob_get_level() > 0) {
179
- ob_end_flush();
180
- }
181
- print( "<pre>" . htmlspecialchars($data) . "</pre>\n");
182
- }
183
- }
184
-
185
- function postie_log_error($v) {
186
- postie_log_onscreen($v);
187
- error_log("Postie [error]: $v");
188
- }
189
-
190
- function postie_log_debug($data) {
191
- error_log("Postie [debug]: $data");
192
- }
193
-
194
- function tag_Date(&$content, $message_date) {
195
- //don't apply any offset here as it is accounted for later
196
- $html = postie_LoadDOM($content);
197
- if ($html !== false) {
198
- $es = $html->find('text');
199
- //DebugEcho("tag_Date: html " . count($es));
200
- foreach ($es as $e) {
201
- //DebugEcho("tag_Date: " . trim($e->plaintext));
202
- $matches = array();
203
- if (1 === preg_match("/^date:\s?(.*)$/imu", trim($e->plaintext), $matches)) {
204
- $possibledate = trim($matches[1]);
205
- DebugEcho("tag_Date: found date tag $matches[1]");
206
- $newdate = strtotime($possibledate);
207
- if (false !== $newdate) {
208
- $t = date("H:i:s", $newdate);
209
- DebugEcho("tag_Date: original time: $t");
210
-
211
- $format = "Y-m-d";
212
- if ($t != '00:00:00') {
213
- $format .= " H:i:s";
214
- }
215
- $message_date = date($format, $newdate);
216
- $content = str_replace($matches[0], '', $content);
217
- break;
218
- } else {
219
- DebugEcho("tag_Date: failed to parse '$possibledate' ($newdate)");
220
- }
221
- }
222
- }
223
- } else {
224
- DebugEcho("tag_Date: not html");
225
- }
226
- return $message_date;
227
- }
228
-
229
- function tag_CustomImageField($post_ID, $email, $config) {
230
- if ($config['custom_image_field']) {
231
- DebugEcho("Saving custom image post_meta");
232
-
233
- foreach (array_merge($email['attachment'], $email['inline'], $email['related']) as $attachment) {
234
- add_post_meta($post_ID, 'image', $attachment['wp_filename']);
235
- DebugEcho("Saving custom attachment '{$attachment['wp_filename']}'");
236
- }
237
- }
238
- }
239
-
240
- function filter_AttachmentTemplates($content, $mimeDecodedEmail, $post_id, $config) {
241
-
242
- $matches = array();
243
- $addimages = !($config['custom_image_field'] || $config['auto_gallery'] || preg_match("/\[gallery[^\[]*\]/u", $content, $matches));
244
- $fiid = -1;
245
-
246
- DebugEcho("filter_AttachmentTemplates: looking for attachments to add to post");
247
- $html = '';
248
- if (!$config['include_featured_image']) {
249
- //find the image to exclude
250
- $fiid = get_post_thumbnail_id($post_id);
251
- }
252
- DebugEcho("filter_AttachmentTemplates: featured image: $fiid");
253
-
254
- DebugEcho("filter_AttachmentTemplates: # attachments: " . count($mimeDecodedEmail['attachment']));
255
- foreach ($mimeDecodedEmail['attachment'] as $attachment) {
256
- DebugEcho("filter_AttachmentTemplates: image: " . $attachment['wp_filename']);
257
- $skip = ($fiid == $attachment['wp_id'] && !$config['include_featured_image']) || $attachment['exclude'];
258
- if (!$skip) {
259
- if (!$addimages && $attachment['primary'] == 'image') {
260
- DebugEcho("filter_AttachmentTemplates: skip image " . $attachment['wp_filename']);
261
- } else {
262
- $template = $attachment['template'];
263
- if ($config['images_append']) {
264
- DebugEcho("filter_AttachmentTemplates: pre postie_place_media_after");
265
- $template = apply_filters('postie_place_media_after', $template, $attachment['wp_id']);
266
- } else {
267
- DebugEcho("filter_AttachmentTemplates: pre postie_place_media_before");
268
- $template = apply_filters('postie_place_media_before', $template, $attachment['wp_id']);
269
- }
270
- $template = mb_str_replace('{CAPTION}', '', $template);
271
- DebugEcho("filter_AttachmentTemplates: post filter '$template'");
272
- $html .= $template;
273
- }
274
- } else {
275
- DebugEcho("filter_AttachmentTemplates: skip attachment " . $attachment['wp_filename']);
276
- }
277
- }
278
-
279
- DebugEcho("filter_AttachmentTemplates: # inline: " . count($mimeDecodedEmail['inline']));
280
- DebugEcho("filter_AttachmentTemplates: # related: " . count($mimeDecodedEmail['related']));
281
- foreach (array_merge($mimeDecodedEmail['inline'], $mimeDecodedEmail['related']) as $attachment) {
282
- DebugEcho("filter_AttachmentTemplates: image: " . $attachment['wp_filename']);
283
- $skip = ($fiid == $attachment['wp_id'] && !$config['include_featured_image']) || $attachment['exclude'];
284
- if (!$skip) {
285
- if (!$addimages && $attachment['primary'] == 'image') {
286
- DebugEcho("filter_AttachmentTemplates: skip image (alt) " . $attachment['wp_filename']);
287
- } else {
288
- $template = $attachment['template'];
289
- if ($config['images_append']) {
290
- DebugEcho("filter_AttachmentTemplates: pre postie_place_media_after");
291
- $template = apply_filters('postie_place_media_after', $template, $attachment['wp_id']);
292
- } else {
293
- DebugEcho("filter_AttachmentTemplates: pre postie_place_media_before");
294
- $template = apply_filters('postie_place_media_before', $template, $attachment['wp_id']);
295
- }
296
- $template = mb_str_replace('{CAPTION}', '', $template);
297
- DebugEcho("filter_AttachmentTemplates: post filter (alt) '$template'");
298
- $html .= $template;
299
- }
300
- } else {
301
- DebugEcho("filter_AttachmentTemplates: skip attachment (alt) " . $attachment['wp_filename']);
302
- }
303
- }
304
-
305
- if (!empty($html)) {
306
- if ($config['images_append']) {
307
- $content = $content . '<div class="postie-attachments">' . $html . '</div>';
308
- } else {
309
- $content = '<div class="postie-attachments">' . $html . '</div>' . $content;
310
- }
311
- }
312
-
313
-
314
- //strip featured image from html
315
- if ($fiid > 0 && $config['prefer_text_type'] == 'html' && !$config['include_featured_image']) {
316
- DebugEcho("filter_AttachmentTemplates: remove featured image from post");
317
- $html = str_get_html($content);
318
- if ($html) {
319
- $elements = $html->find('img[src=' . wp_get_attachment_url($fiid) . ']');
320
- foreach ($elements as $e) {
321
- DebugEcho('filter_AttachmentTemplates: outertext:' . $e->outertext);
322
- $e->outertext = '';
323
- }
324
- $content = $html->save();
325
- }
326
- }
327
-
328
- $imagecount = 0;
329
- foreach ($mimeDecodedEmail['attachment'] as $attachment) {
330
- DebugEcho("filter_AttachmentTemplates: attachment mime primary: {$attachment['primary']}");
331
- if ($attachment['primary'] == 'image' && $attachment['exclude'] == false) {
332
- $imagecount++;
333
- }
334
- }
335
- if ($config['prefer_text_type'] == 'plain') {
336
- foreach (array_merge($mimeDecodedEmail['inline'], $mimeDecodedEmail['related']) as $attachment) {
337
- DebugEcho("filter_AttachmentTemplates: attachment mime primary: {$attachment['primary']}");
338
- if ($attachment['primary'] == 'image' && $attachment['exclude'] == false) {
339
- $imagecount++;
340
- }
341
- }
342
- }
343
- DebugEcho("filter_AttachmentTemplates: image count $imagecount");
344
-
345
- if (($imagecount > 0) && $config['auto_gallery']) {
346
- $linktype = strtolower($config['auto_gallery_link']);
347
- DebugEcho("filter_AttachmentTemplates: Auto gallery: link type $linktype");
348
- postie_show_filters_for('postie_gallery');
349
- if ($linktype == 'default') {
350
- DebugEcho("filter_AttachmentTemplates: pre postie_gallery (default)");
351
- $imageTemplate = apply_filters('postie_gallery', '[gallery]', $post_id);
352
- } else {
353
- DebugEcho("filter_AttachmentTemplates: pre postie_gallery ($linktype)");
354
- $imageTemplate = apply_filters('postie_gallery', "[gallery link='$linktype']", $post_id);
355
- }
356
- DebugEcho("filter_AttachmentTemplates: Auto gallery: template '$imageTemplate'");
357
- if ($config['images_append']) {
358
- $content .= "\n$imageTemplate";
359
- DebugEcho("filter_AttachmentTemplates: Auto gallery: append");
360
- } else {
361
- $content = "$imageTemplate\n" . $content;
362
- DebugEcho("filter_AttachmentTemplates: Auto gallery: prepend");
363
- }
364
- } else {
365
- DebugEcho("filter_AttachmentTemplates: Auto gallery: none");
366
- }
367
-
368
- return $content;
369
- }
370
-
371
- function postie_create_post($poster, $mimeDecodedEmail, $post_id, &$is_reply, $config, $postmodifiers) {
372
- DebugEcho("postie_create_post: prefer_text_type: " . $config['prefer_text_type']);
373
-
374
- $fulldebug = IsDebugMode();
375
- $fulldebugdump = false;
376
-
377
- if (array_key_exists('message-id', $mimeDecodedEmail['headers'])) {
378
- DebugEcho("Message Id is :" . htmlentities($mimeDecodedEmail['headers']['message-id']));
379
- if ($fulldebugdump) {
380
- DebugDump($mimeDecodedEmail);
381
- }
382
- }
383
-
384
- if ($fulldebugdump) {
385
- DebugDump($mimeDecodedEmail);
386
- }
387
-
388
- postie_save_attachments($mimeDecodedEmail, $post_id, $poster, $config);
389
-
390
- $content = postie_get_content($mimeDecodedEmail, $config);
391
-
392
- $subject = postie_get_subject($mimeDecodedEmail, $content, $config);
393
-
394
- $content = filter_Newlines($content, $config);
395
- if ($fulldebug) {
396
- DebugEcho("post filter_Newlines: $content");
397
- }
398
-
399
- $content = filter_RemoveSignature($content, $config);
400
- if ($fulldebug) {
401
- DebugEcho("post filter_RemoveSignature: $content");
402
- }
403
-
404
- $post_excerpt = tag_Excerpt($content, $config);
405
- if ($fulldebug) {
406
- DebugEcho("post tag_Excerpt: $content");
407
- }
408
-
409
- $postAuthorDetails = postie_getPostAuthorDetails($mimeDecodedEmail);
410
- if ($fulldebug) {
411
- DebugEcho("post postie_getPostAuthorDetails: $content");
412
- }
413
-
414
- $message_date = NULL;
415
- if (array_key_exists("date", $mimeDecodedEmail['headers']) && !empty($mimeDecodedEmail['headers']['date'])) {
416
- DebugEcho("date header: {$mimeDecodedEmail['headers']['date']}");
417
- if ($config['ignore_email_date']) {
418
- $message_date = current_time('mysql');
419
- DebugEcho("system date: $message_date");
420
- } else {
421
- $message_date = $mimeDecodedEmail['headers']['date'];
422
- DebugEcho("decoded date: $message_date");
423
- list($message_date, $delay) = tag_Delay($content, $message_date, $config);
424
- if ($fulldebug) {
425
- DebugEcho("post tag_Delay: $content");
426
- }
427
- }
428
- } else {
429
- DebugEcho("date header missing");
430
- $message_date = current_time('mysql');
431
- }
432
-
433
- $post_date = tag_Date($content, $message_date);
434
- if ($fulldebug) {
435
- DebugEcho("post tag_Date: $content");
436
- }
437
-
438
-
439
- //do post type before category to keep the subject line correct
440
- $post_type = tag_PostType($subject, $postmodifiers, $config);
441
- if ($fulldebug) {
442
- DebugEcho("post tag_PostType: $content");
443
- }
444
-
445
- $default_categoryid = $config['default_post_category'];
446
-
447
- DebugEcho("pre postie_category_default: '$default_categoryid'");
448
- $default_categoryid = apply_filters('postie_category_default', $default_categoryid);
449
- DebugEcho("post postie_category_default: '$default_categoryid'");
450
-
451
- $post_categories = tag_Categories($subject, $default_categoryid, $config, $post_id);
452
- if ($fulldebug) {
453
- DebugEcho("post tag_Categories: $content");
454
- }
455
-
456
- $post_tags = tag_Tags($content, $config['default_post_tags'], 'html' == $config['prefer_text_type']);
457
- if ($fulldebug) {
458
- DebugEcho("post tag_Tags: $content");
459
- }
460
-
461
- $comment_status = tag_AllowCommentsOnPost($content);
462
- if ($fulldebug) {
463
- DebugEcho("post tag_AllowCommentsOnPost: $content");
464
- }
465
-
466
- $post_status = tag_Status($content, $config['post_status']);
467
- if ($fulldebug) {
468
- DebugEcho("post tag_Status: $content");
469
- }
470
-
471
- //handle CID before linkify
472
- $content = filter_ReplaceImageCIDs($content, $mimeDecodedEmail);
473
- if ($fulldebug) {
474
- DebugEcho("post filter_ReplaceImageCIDs: $content");
475
- }
476
-
477
- if ($config['converturls']) {
478
- $content = filter_Linkify($content);
479
- if ($fulldebug) {
480
- DebugEcho("post filter_Linkify: $content");
481
- }
482
- }
483
-
484
- if ($config['reply_as_comment'] == true) {
485
- $id = postie_get_parent_post($subject);
486
- if (empty($id)) {
487
- DebugEcho("Not a reply");
488
- $id = $post_id;
489
- $is_reply = false;
490
- } else {
491
- DebugEcho("Reply detected");
492
- $is_reply = true;
493
- if (true == $config['strip_reply']) {
494
- // strip out quoted content
495
- $lines = explode("\n", $content);
496
- $newContents = '';
497
- foreach ($lines as $line) {
498
- if (preg_match("/^>.*/i", $line) == 0 &&
499
- preg_match("/^(from|subject|to|date):.*?/iu", $line) == 0 &&
500
- preg_match("/^-+.*?(from|subject|to|date).*?/iu", $line) == 0 &&
501
- preg_match("/^on.*?wrote:$/iu", $line) == 0 &&
502
- preg_match("/^-+\s*forwarded\s*message\s*-+/iu", $line) == 0) {
503
- $newContents .= "$line\n";
504
- }
505
- }
506
- if ((strlen($newContents) <> strlen($content)) && ('html' == $config['prefer_text_type'])) {
507
- DebugEcho("Attempting to fix reply html (before): $newContents");
508
- $newContents = postie_LoadDOM($newContents)->__toString();
509
- DebugEcho("Attempting to fix reply html (after): $newContents");
510
- }
511
- $content = $newContents;
512
- }
513
- wp_delete_post($post_id);
514
- }
515
- } else {
516
- $id = $post_id;
517
- DebugEcho("Replies will not be processed as comments");
518
- }
519
-
520
- if ($delay > 0 && $post_status == 'publish') {
521
- DebugEcho("publish in future");
522
- $post_status = 'future';
523
- }
524
-
525
- $content = filter_Start($content, $config);
526
- if ($fulldebug) {
527
- DebugEcho("post filter_Start: $content");
528
- }
529
-
530
- $content = filter_End($content, $config);
531
- if ($fulldebug) {
532
- DebugEcho("post filter_End: $content");
533
- }
534
-
535
- $content = filter_ReplaceImagePlaceHolders($content, $mimeDecodedEmail, $config, $id, $config['image_placeholder']);
536
- if ($fulldebug) {
537
- DebugEcho("post filter_ReplaceImagePlaceHolders: $content");
538
- }
539
-
540
- if ($post_excerpt) {
541
- $post_excerpt = filter_ReplaceImagePlaceHolders($post_excerpt, $mimeDecodedEmail, $config, $id, '#eimg%#');
542
- DebugEcho("excerpt: $post_excerpt");
543
- if ($fulldebug) {
544
- DebugEcho("post excerpt ReplaceImagePlaceHolders: $content");
545
- }
546
- }
547
-
548
- //handle inline images after linkify
549
- if ('plain' == $config['prefer_text_type']) {
550
- $content = filter_ReplaceInlineImage($content, $mimeDecodedEmail, $config);
551
- if ($fulldebug) {
552
- DebugEcho("post filter_ReplaceInlineImage: $content");
553
- }
554
- }
555
-
556
- $content = filter_AttachmentTemplates($content, $mimeDecodedEmail, $post_id, $config);
557
-
558
- if (trim($subject) == "") {
559
- $subject = $config['default_title'];
560
- DebugEcho("post parsing subject is blank using: " . $config['default_title']);
561
- }
562
-
563
- $details = array(
564
- 'post_author' => $poster,
565
- 'comment_author' => $postAuthorDetails['author'],
566
- 'comment_author_url' => $postAuthorDetails['comment_author_url'],
567
- 'user_ID' => $postAuthorDetails['user_ID'],
568
- 'email_author' => $postAuthorDetails['email'],
569
- 'post_date' => $post_date,
570
- 'post_date_gmt' => get_gmt_from_date($post_date),
571
- 'post_content' => $content,
572
- 'post_title' => $subject,
573
- 'post_type' => $post_type, /* Added by Raam Dev <raam@raamdev.com> */
574
- 'ping_status' => get_option('default_ping_status'),
575
- 'post_category' => $post_categories,
576
- 'tags_input' => $post_tags,
577
- 'comment_status' => $comment_status,
578
- 'post_name' => $subject,
579
- 'post_excerpt' => $post_excerpt,
580
- 'ID' => $id,
581
- 'post_status' => $post_status
582
- );
583
- return $details;
584
- }
585
-
586
- /**
587
- * This is the main handler for all of the processing
588
- */
589
- function PostEmail($poster, $mimeDecodedEmail, $config) {
590
- postie_disable_revisions();
591
- //extract($config);
592
-
593
- /* in order to do attachments correctly, we need to associate the
594
- attachments with a post. So we add the post here, then update it */
595
- $tmpPost = array('post_title' => 'tmptitle', 'post_content' => 'tmpPost', 'post_status' => 'draft');
596
- $post_id = wp_insert_post($tmpPost, true);
597
- if (!is_wp_error($post_id)) {
598
- DebugEcho("PostEmail: tmp post id is $post_id");
599
-
600
- $is_reply = false;
601
- $postmodifiers = new PostiePostModifiers();
602
-
603
- DebugEcho("PostEmail: pre postie_post_pre");
604
- $mimeDecodedEmail = apply_filters('postie_post_pre', $mimeDecodedEmail);
605
-
606
- $details = postie_create_post($poster, $mimeDecodedEmail, $post_id, $is_reply, $config, $postmodifiers);
607
-
608
- $details = apply_filters('postie_post', $details);
609
- $details = apply_filters('postie_post_before', $details, $mimeDecodedEmail['headers']);
610
-
611
- DebugEcho("PostEmail: Post postie_post_before filter");
612
- DebugDump($details);
613
-
614
- if (empty($details)) {
615
- // It is possible that the filter has removed the post, in which case, it should not be posted.
616
- // And if we created a placeholder post (because this was not a reply to an existing post),
617
- // then it should be removed
618
- if (!$is_reply) {
619
- wp_delete_post($post_id);
620
- EchoError("postie_post filter cleared the post, not saving.");
621
- }
622
- } else {
623
- $postid = postie_save_post($details, $is_reply, $config['custom_image_field'], $postmodifiers);
624
-
625
- if ($config['confirmation_email'] != '') {
626
- if ($config['confirmation_email'] == 'sender' || $config['confirmation_email'] == 'both') {
627
- $recipients = array($details['email_author']);
628
- }
629
- if ($config['confirmation_email'] == 'admin' || $config['confirmation_email'] == 'both') {
630
- foreach (get_users(array('role' => 'administrator', 'blog_id' => get_current_blog_id())) as $user) {
631
- $recipients[] = $user->user_email;
632
- }
633
- }
634
- postie_email_notify($mimeDecodedEmail, $recipients, $postid);
635
- }
636
- if (IsDebugMode()) {
637
- $post = get_post($post_id);
638
- DebugEcho("PostEmail: resulting post");
639
- DebugDump($post);
640
- }
641
- }
642
- } else {
643
- EchoError("PostEmail: wp_insert_post failed: " . $post_id->get_error_message());
644
- DebugDump($post_id->get_error_messages());
645
- DebugDump($post_id->get_error_data());
646
- postie_notify_error("PostEmail wp_insert_post failed creating placeholder", $post_id->get_error_message());
647
- }
648
- postie_disable_revisions(true);
649
- DebugEcho("Done");
650
- }
651
-
652
- /** FUNCTIONS * */
653
- /*
654
- * Added by Raam Dev <raam@raamdev.com>
655
- * Adds support for handling Custom Post Types by adding the
656
- * Custom Post Type name to the email subject separated by
657
- * $custom_post_type_delim, e.g. "Movies // My Favorite Movie"
658
- * Also supports setting the Post Format.
659
- */
660
- function tag_PostType(&$subject, $postmodifiers, $config) {
661
-
662
- $post_type = $config['post_type'];
663
- $custom_post_type = $config['post_format'];
664
- $separated_subject = array();
665
- $separated_subject[0] = "";
666
- $separated_subject[1] = $subject;
667
-
668
- $custom_post_type_delim = "//";
669
- if (strpos($subject, $custom_post_type_delim) !== FALSE) {
670
- // Captures the custom post type in the subject before $custom_post_type_delim
671
- $separated_subject = explode($custom_post_type_delim, $subject);
672
- $custom_post_type = trim(strtolower($separated_subject[0]));
673
- DebugEcho("post type: found possible type '$custom_post_type'");
674
- }
675
-
676
- $known_post_types = get_post_types();
677
-
678
- if (in_array($custom_post_type, array_map('strtolower', $known_post_types))) {
679
- DebugEcho("post type: found type '$post_type'");
680
- $post_type = $custom_post_type;
681
- $subject = trim($separated_subject[1]);
682
- } elseif (in_array($custom_post_type, array_keys(get_post_format_strings()))) {
683
- DebugEcho("post type: found format '$custom_post_type'");
684
- $postmodifiers->PostFormat = $custom_post_type;
685
- $subject = trim($separated_subject[1]);
686
- }
687
-
688
- return $post_type;
689
- }
690
-
691
- function filter_Linkify($text) {
692
- DebugEcho("begin: filter_linkify");
693
- $oe = _wp_oembed_get_object();
694
-
695
- $al = new PostieAutolink();
696
- DebugEcho("begin: filter_linkify (html)");
697
- $text = $al->autolink($text, $oe);
698
- DebugEcho("begin: filter_linkify (email)");
699
- return $al->autolink_email($text);
700
- }
701
-
702
- function postie_LoadDOM($text) {
703
- return str_get_html($text, true, true, DEFAULT_TARGET_CHARSET, false);
704
- }
705
-
706
- /* we check whether or not the email is a forwards or a redirect. If it is
707
- * a fwd, then we glean the author details from the body of the post.
708
- * Otherwise we get them from the headers
709
- */
710
-
711
- function postie_getPostAuthorDetails($mimeDecodedEmail) {
712
-
713
- $theEmail = $mimeDecodedEmail['headers']['from']['mailbox'] . '@' . $mimeDecodedEmail['headers']['from']['host'];
714
-
715
- $regAuthor = get_user_by('email', $theEmail);
716
- if ($regAuthor) {
717
- $theAuthor = $regAuthor->user_login;
718
- $theUrl = $regAuthor->user_url;
719
- $theID = $regAuthor->ID;
720
- } else {
721
- $theAuthor = postie_get_name_from_email($theEmail);
722
- $theUrl = '';
723
- $theID = '';
724
- }
725
-
726
- $theDetails = array(
727
- 'author' => $theAuthor,
728
- 'comment_author_url' => $theUrl,
729
- 'user_ID' => $theID,
730
- 'email' => $theEmail
731
- );
732
-
733
- return $theDetails;
734
- }
735
-
736
- /* we check whether or not the email is a reply to a previously
737
- * published post. First we check whether it starts with Re:, and then
738
- * we see if the remainder matches an already existing post. If so,
739
- * then we add that post id to the details array, which will cause the
740
- * existing post to be overwritten, instead of a new one being
741
- * generated
742
- */
743
-
744
- function postie_get_parent_post(&$subject) {
745
- global $wpdb;
746
-
747
- $id = NULL;
748
- DebugEcho("GetParentPostForReply: Looking for parent '$subject'");
749
- // see if subject starts with Re:
750
- $matches = array();
751
- if (preg_match("/(^Re:)(.*)/iu", $subject, $matches)) {
752
- DebugEcho("GetParentPostForReply: Re: detected");
753
- $subject = trim($matches[2]);
754
- // strip out category info into temporary variable
755
- $tmpSubject = $subject;
756
- if (preg_match('/(.+): (.*)/u', $tmpSubject, $matches)) {
757
- $tmpSubject = trim($matches[2]);
758
- $matches[1] = array($matches[1]);
759
- } else if (preg_match_all('/\[(.[^\[]*)\]/', $tmpSubject, $matches)) {
760
- $tmpSubject_matches = array();
761
- preg_match("/](.[^\[]*)$/", $tmpSubject, $tmpSubject_matches);
762
- $tmpSubject = trim($tmpSubject_matches[1]);
763
- } else if (preg_match_all('/-(.[^-]*)-/', $tmpSubject, $matches)) {
764
- preg_match("/-(.[^-]*)$/", $tmpSubject, $tmpSubject_matches);
765
- $tmpSubject = trim($tmpSubject_matches[1]);
766
- }
767
- DebugEcho("GetParentPostForReply: tmpSubject: $tmpSubject");
768
- $checkExistingPostQuery = "SELECT ID FROM $wpdb->posts WHERE post_title LIKE %s AND post_status = 'publish' AND comment_status = 'open'";
769
- if ($id = $wpdb->get_var($wpdb->prepare($checkExistingPostQuery, $tmpSubject))) {
770
- if (!empty($id)) {
771
- DebugEcho("GetParentPostForReply: id: $id");
772
- } else {
773
- DebugEcho("GetParentPostForReply: No parent id found");
774
- }
775
- }
776
- } else {
777
- DebugEcho("GetParentPostForReply: No parent found");
778
- }
779
- return $id;
780
- }
781
-
782
- /**
783
- * This handles actually showing the form. Called by WordPress
784
- */
785
- function postie_configure() {
786
- include(POSTIE_ROOT . DIRECTORY_SEPARATOR . "config_form.php");
787
- }
788
-
789
- /**
790
- * This function handles determining the protocol and fetching the mail
791
- * @return array
792
- */
793
- function postie_fetch_mail($server, $port, $email, $password, $protocol, $deleteMessages, $maxemails, $connectiontype) {
794
- $emails = array();
795
- if (!$server || !$port || !$email) {
796
- EchoError("Missing Configuration For Mail Server");
797
- return $emails;
798
- }
799
- if ($server == "pop.gmail.com") {
800
- DebugEcho("MAKE SURE POP IS TURNED ON IN SETTING AT Gmail");
801
- }
802
- switch (strtolower($protocol)) {
803
- case 'imap':
804
- case 'imap-ssl':
805
- $emails = postie_getemails('imap', $server, $port, $email, $password, $protocol, $deleteMessages, $maxemails, $connectiontype);
806
- break;
807
- case 'pop3':
808
- case 'pop3-ssl':
809
- default:
810
- $emails = postie_getemails('pop3', $server, $port, $email, $password, $protocol, $deleteMessages, $maxemails, $connectiontype);
811
- }
812
-
813
- return $emails;
814
- }
815
-
816
- function postie_getemails($type, $server, $port, $email, $password, $protocol, $deleteMessages, $maxemails, $connectiontype) {
817
-
818
- DebugEcho("postie_getemails: Connecting to $server:$port ($protocol)");
819
-
820
- $emails = array();
821
-
822
- try {
823
- DebugEcho("postie_getemails: procol: $protocol");
824
- if ($connectiontype == 'curl') {
825
- $conn = new pCurlConnection($type, trim($server), $email, $password, $port, ($protocol == 'imap-ssl' || $protocol == 'pop3-ssl'));
826
- } else {
827
- $conn = new pSocketConnection($type, trim($server), $email, $password, $port, ($protocol == 'imap-ssl' || $protocol == 'pop3-ssl'));
828
- }
829
-
830
- if ($type == 'imap') {
831
- $srv = new pImapMailServer($conn);
832
- } else {
833
- $srv = new pPop3MailServer($conn);
834
- }
835
-
836
- DebugEcho("postie_getemails: listing messages");
837
- $mailbox = new fMailbox($type, $conn, $srv);
838
- $messages = $mailbox->listMessages($maxemails);
839
-
840
- foreach ($messages as $uid => $messages) {
841
- DebugEcho("postie_getemails: fetch $uid");
842
-
843
- $email = $mailbox->fetchMessage($uid);
844
-
845
- if (!empty($email['html'])) {
846
- DebugEcho("postie_getemails: html");
847
- $email['html'] = filter_CleanHtml($email['html']);
848
- } else {
849
- DebugEcho("postie_getemails: no html");
850
- }
851
-
852
- $emails[] = $email;
853
- if ($deleteMessages) {
854
- DebugEcho("postie_getemails: deleting $uid");
855
- $mailbox->deleteMessages($uid);
856
- }
857
- }
858
-
859
- DebugEcho("postie_getemails: closing connection");
860
- $mailbox->close();
861
- } catch (Exception $e) {
862
- EchoError("postie_getemails: " . $e->getMessage());
863
- }
864
-
865
- return $emails;
866
- }
867
-
868
- function postie_notify_error($subject, $message) {
869
- $recipients = array();
870
- $config = config_Read();
871
- if ($config['postie_log_error_notify'] == '(Nobody)') {
872
- return;
873
- }
874
- if ($config['postie_log_error_notify'] == '(All Admins)') {
875
- foreach (get_users(array('role' => 'administrator', 'blog_id' => get_current_blog_id())) as $user) {
876
- $recipients[] = $user->user_email;
877
- }
878
- if (count($recipients) == 0) {
879
- return;
880
- }
881
- } else {
882
- $user = get_user_by('login', $config['postie_log_error_notify']);
883
- if ($user === false) {
884
- return;
885
- }
886
- $recipients[] = $user->user_login;
887
- }
888
-
889
- $message = "This message has been sent from " . get_site_url() . ". You can disable or control who receives them by changing the Postie 'Notify on Error' setting.\n\n" . $message;
890
- wp_mail($recipients, $subject, $message);
891
- }
892
-
893
- /**
894
- * This function handles putting the actual entry into the database
895
- */
896
- function postie_save_post($details, $isReply, $customImageField, $postmodifiers) {
897
- $post_ID = 0;
898
- if (!$isReply) {
899
- $post_ID = wp_insert_post($details, true);
900
- if (is_wp_error($post_ID)) {
901
- EchoError("PostToDB Error: " . $post_ID->get_error_message());
902
- DebugDump($post_ID->get_error_messages());
903
- DebugDump($post_ID->get_error_data());
904
- wp_delete_post($details['ID']);
905
-
906
- postie_notify_error("Failed to create {$details['post_type']}: {$details['post_title']}", "Error: " . $post_ID->get_error_message() . "\n\n" . $details['post_content']);
907
-
908
- $post_ID = null;
909
- }
910
- } else {
911
- $comment = array(
912
- 'comment_author' => $details['comment_author'],
913
- 'comment_post_ID' => $details['ID'],
914
- 'comment_author_email' => $details['email_author'],
915
- 'comment_date' => $details['post_date'],
916
- 'comment_date_gmt' => $details['post_date_gmt'],
917
- 'comment_content' => $details['post_content'],
918
- 'comment_author_url' => $details['comment_author_url'],
919
- 'comment_author_IP' => '',
920
- 'comment_approved' => 1,
921
- 'comment_agent' => '',
922
- 'comment_type' => '',
923
- 'comment_parent' => 0,
924
- 'user_id' => $details['user_ID']
925
- );
926
- $comment = apply_filters('postie_comment_before', $comment);
927
- DebugEcho("postie_save_post: post postie_comment_before");
928
- DebugDump($comment);
929
-
930
- $post_ID = wp_new_comment($comment);
931
-
932
- DebugEcho("doing postie_comment_after");
933
- do_action('postie_comment_after', $comment);
934
- }
935
-
936
- if ($post_ID) {
937
- $postmodifiers->apply($post_ID);
938
- DebugEcho("doing postie_post_after");
939
- do_action('postie_post_after', $details);
940
- }
941
-
942
- return $post_ID;
943
- }
944
-
945
- /**
946
- * This function determines if the mime attachment is on the BANNED_FILE_LIST
947
- * @param string
948
- * @return boolean
949
- */
950
- function postie_isBannedFileName($filename, $bannedFiles) {
951
- if (preg_match('/ATT\d\d\d\d\d.txt/i', $filename)) {
952
- return true;
953
- }
954
-
955
- if (empty($filename) || empty($bannedFiles)) {
956
- return false;
957
- }
958
- foreach ($bannedFiles as $bannedFile) {
959
- if (fnmatch($bannedFile, $filename)) {
960
- EchoError("Ignoring attachment: $filename - it is on the banned files list.");
961
- postie_notify_error("Ignoring attachment: $filename - it is on the banned files list.", "Ignoring attachment: $filename - it is on the banned files list.");
962
- return true;
963
- }
964
- }
965
- return false;
966
- }
967
-
968
- function postie_get_content(&$email, $config) {
969
- DebugEcho('postie_save_attachments: ---- start');
970
- $meta_return = '';
971
- if ($config['prefer_text_type'] == 'html') {
972
- if (isset($email['html'])) {
973
- $meta_return = $email['html'];
974
- }
975
- } else {
976
- if (isset($email['text'])) {
977
- $meta_return = $email['text'];
978
- }
979
- }
980
- return $meta_return;
981
- }
982
-
983
- function postie_save_attachments(&$email, $post_id, $poster, $config) {
984
- DebugEcho('postie_save_attachments: ---- start');
985
-
986
- if (!isset($email['attachment'])) {
987
- $email['attachment'] = array();
988
- }
989
- if (!isset($email['inline'])) {
990
- $email['inline'] = array();
991
- }
992
- if (!isset($email['related'])) {
993
- $email['related'] = array();
994
- }
995
-
996
- DebugEcho("postie_save_attachments: [attachment]");
997
- postie_save_attachments_worker($email['attachment'], $post_id, $poster, $config);
998
- DebugEcho("postie_save_attachments: [inline]");
999
- postie_save_attachments_worker($email['inline'], $post_id, $poster, $config);
1000
- DebugEcho("postie_save_attachments: [related]");
1001
- postie_save_attachments_worker($email['related'], $post_id, $poster, $config);
1002
-
1003
-
1004
- DebugEcho("postie_save_attachments: ==== end");
1005
- }
1006
-
1007
- function postie_save_attachments_worker(&$attachments, $post_id, $poster, $config) {
1008
- foreach ($attachments as &$attachment) {
1009
- if (array_key_exists('filename', $attachment) && !empty($attachment['filename'])) {
1010
- DebugEcho('postie_save_attachments_worker: ' . $attachment['filename']);
1011
-
1012
- if (postie_isBannedFileName($attachment['filename'], $config['banned_files_list'])) {
1013
- DebugEcho("postie_save_attachments_worker: skipping banned filename " . $attachment['filename']);
1014
- break;
1015
- }
1016
- } else {
1017
- DebugEcho('postie_save_attachments_worker: un-named attachment');
1018
- }
1019
-
1020
- postie_save_attachment($attachment, $post_id, $poster, $config);
1021
-
1022
- $filename = $attachment['wp_filename'];
1023
- $fileext = $attachment['ext'];
1024
- $mparts = explode('/', $attachment['mimetype']);
1025
- $mimetype_primary = $mparts[0];
1026
- $mimetype_secondary = $mparts[1];
1027
- DebugEcho("postie_save_attachments_worker: mime primary: $mimetype_primary");
1028
-
1029
- $attachment['primary'] = $mimetype_primary;
1030
- $attachment['exclude'] = false;
1031
-
1032
- $file_id = $attachment['wp_id'];
1033
- $file = wp_get_attachment_url($file_id);
1034
-
1035
- switch ($mimetype_primary) {
1036
- case 'text':
1037
- DebugEcho("postie_save_attachments_worker: text attachment");
1038
- $icon = postie_chooseAttachmentIcon($file, $mimetype_primary, $mimetype_secondary, $config['icon_set'], $config['icon_size']);
1039
- $attachment['template'] = "<a href='$file'>" . $icon . $filename . '</a>' . "\n";
1040
- break;
1041
-
1042
- case 'image':
1043
- DebugEcho("postie_save_attachments_worker: image attachment");
1044
- $attachment['template'] = parseTemplate($file_id, $mimetype_primary, $config['imagetemplate'], $filename) . "\n";
1045
- break;
1046
-
1047
- case 'audio':
1048
- DebugEcho("postie_save_attachments_worker: audio attachment");
1049
- if (in_array($fileext, $config['audiotypes'])) {
1050
- DebugEcho("postie_save_attachments_worker: using audio template: $mimetype_secondary");
1051
- $audioTemplate = $config['audiotemplate'];
1052
- } else {
1053
- DebugEcho("postie_save_attachments_worker: using default audio template: $mimetype_secondary");
1054
- $icon = postie_chooseAttachmentIcon($file, $mimetype_primary, $mimetype_secondary, $config['icon_set'], $config['icon_size']);
1055
- $audioTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>';
1056
- }
1057
- $attachment['template'] = parseTemplate($file_id, $mimetype_primary, $audioTemplate, $filename);
1058
- break;
1059
-
1060
- case 'video':
1061
- DebugEcho("postie_save_attachments_worker: video attachment");
1062
- if (in_array($fileext, $config['video1types'])) {
1063
- DebugEcho("postie_save_attachments_worker: using video1 template: $fileext");
1064
- $videoTemplate = $config['video1template'];
1065
- } elseif (in_array($fileext, $config['video2types'])) {
1066
- DebugEcho("postie_save_attachments_worker: using video2 template: $fileext");
1067
- $videoTemplate = $config['video2template'];
1068
- } else {
1069
- DebugEcho("postie_save_attachments_worker: using default template: $fileext");
1070
- $icon = postie_chooseAttachmentIcon($file, $mimetype_primary, $mimetype_secondary, $config['icon_set'], $config['icon_size']);
1071
- $videoTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>';
1072
- }
1073
- $attachment['template'] = parseTemplate($file_id, $mimetype_primary, $videoTemplate, $filename);
1074
- break;
1075
-
1076
- default :
1077
- DebugEcho("postie_save_attachments_worker: generic attachment ($mimetype_primary)");
1078
- $icon = postie_chooseAttachmentIcon($file, $mimetype_primary, $mimetype_secondary, $config['icon_set'], $config['icon_size']);
1079
- $attachment['template'] = parseTemplate($file_id, $mimetype_primary, $config['generaltemplate'], $filename, $icon) . "\n";
1080
- break;
1081
- }
1082
- }
1083
- }
1084
-
1085
- function postie_save_attachment(&$attachment, $post_id, $poster, $config) {
1086
-
1087
- if (isset($attachment['filename']) && !empty($attachment['filename'])) {
1088
- $filename = $attachment['filename'];
1089
- } else {
1090
- DebugEcho("postie_save_attachment: generating file name");
1091
- $filename = uniqid();
1092
- $attachment['filename'] = $filename;
1093
- }
1094
-
1095
- DebugEcho("postie_save_attachment: pre sanitize file name '$filename'");
1096
- //DebugDump($part);
1097
- $filename = sanitize_file_name($filename);
1098
- $attachment['wp_filename'] = $filename;
1099
-
1100
- DebugEcho("postie_save_attachment: file name '$filename'");
1101
-
1102
- $mparts = explode('/', $attachment['mimetype']);
1103
- $mimetype_primary = $mparts[0];
1104
- $mimetype_secondary = $mparts[1];
1105
-
1106
- $fileext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
1107
- $attachment['ext'] = $fileext;
1108
- if (empty($fileext) && $mimetype_primary == 'image') {
1109
- $attachment['ext'] = $mimetype_secondary;
1110
- $filename = $filename . '.' . $mimetype_secondary;
1111
- $attachment['wp_filename'] = $filename;
1112
- DebugEcho("postie_save_attachment: blank image extension, changed to $mimetype_secondary ($filename)");
1113
- }
1114
- DebugEcho("postie_save_attachment: extension '$fileext'");
1115
-
1116
- $typeinfo = wp_check_filetype($filename);
1117
- //DebugDump($typeinfo);
1118
- if (!empty($typeinfo['type'])) {
1119
- DebugEcho("postie_save_attachment: secondary lookup found " . $typeinfo['type']);
1120
- $mimeparts = explode('/', strtolower($typeinfo['type']));
1121
- $mimetype_primary = $mimeparts[0];
1122
- $mimetype_secondary = $mimeparts[1];
1123
- } else {
1124
- DebugEcho("postie_save_attachment: secondary lookup failed, checking configured extensions");
1125
- if (in_array($fileext, $config['audiotypes'])) {
1126
- DebugEcho("postie_save_attachment: found audio extension");
1127
- $mimetype_primary = 'audio';
1128
- $mimetype_secondary = $fileext;
1129
- } elseif (in_array($fileext, array_merge($config['video1types'], $config['video2types']))) {
1130
- DebugEcho("postie_save_attachment: found video extension");
1131
- $mimetype_primary = 'video';
1132
- $mimetype_secondary = $fileext;
1133
- } else {
1134
- DebugEcho("postie_save_attachment: found no extension");
1135
- }
1136
- }
1137
- $attachment['mimetype'] = "$mimetype_primary/$mimetype_secondary";
1138
- DebugEcho("postie_save_attachment: mimetype $mimetype_primary/$mimetype_secondary");
1139
-
1140
- switch ($mimetype_primary) {
1141
- case 'text':
1142
- DebugEcho("postie_save_attachment: ctype_primary: text");
1143
- //DebugDump($part);
1144
-
1145
- DebugEcho("postie_save_attachment: text Attachement: $filename");
1146
- $file_id = postie_media_handle_upload($attachment, $post_id);
1147
- if (!is_wp_error($file_id)) {
1148
- $attachment['wp_id'] = $file_id;
1149
- DebugEcho("postie_save_attachment: text attachment: adding '$filename'");
1150
- } else {
1151
- EchoError($file_id->get_error_message());
1152
- postie_notify_error("Failed to add text media file: $filename", $file_id->get_error_message());
1153
- }
1154
-
1155
- break;
1156
-
1157
- case 'image':
1158
- DebugEcho("postie_save_attachment: image Attachement: $filename");
1159
- $file_id = postie_media_handle_upload($attachment, $post_id);
1160
- if (!is_wp_error($file_id)) {
1161
- $attachment['wp_id'] = $file_id;
1162
- //set the first image we come across as the featured image
1163
- if ($config['featured_image'] && !has_post_thumbnail($post_id)) {
1164
- DebugEcho("postie_save_attachment: featured image: $file_id");
1165
- set_post_thumbnail($post_id, $file_id);
1166
- }
1167
- } else {
1168
- EchoError("postie_save_attachment image error: " . $file_id->get_error_message());
1169
- postie_notify_error("Failed to add image media file: $filename", $file_id->get_error_message());
1170
- }
1171
- break;
1172
-
1173
- case 'audio':
1174
- DebugEcho("postie_save_attachment: audio Attachement: $filename");
1175
- $file_id = postie_media_handle_upload($attachment, $post_id);
1176
- if (!is_wp_error($file_id)) {
1177
- $attachment['wp_id'] = $file_id;
1178
- } else {
1179
- EchoError("postie_save_attachment audio error: " . $file_id->get_error_message());
1180
- postie_notify_error("Failed to add audio media file: $filename", $file_id->get_error_message());
1181
- }
1182
- break;
1183
-
1184
- case 'video':
1185
- DebugEcho("postie_save_attachment: video Attachement: $filename");
1186
- $file_id = postie_media_handle_upload($attachment, $post_id);
1187
- if (!is_wp_error($file_id)) {
1188
- $attachment['wp_id'] = $file_id;
1189
- } else {
1190
- EchoError("postie_save_attachment video error: " . $file_id->get_error_message());
1191
- postie_notify_error("Failed to add video file: $filename", $file_id->get_error_message());
1192
- }
1193
- break;
1194
-
1195
- default:
1196
- DebugEcho("postie_save_attachment: found file type: " . $mimetype_primary);
1197
- if (in_array($mimetype_primary, $config['supported_file_types'])) {
1198
- //pgp signature - then forget it
1199
- if ($mimetype_secondary == 'pgp-signature') {
1200
- DebugEcho("postie_save_attachment: found pgp-signature - done");
1201
- break;
1202
- }
1203
- $file_id = postie_media_handle_upload($attachment, $post_id);
1204
- if (!is_wp_error($file_id)) {
1205
- $attachment['wp_id'] = $file_id;
1206
- $file = wp_get_attachment_url($file_id);
1207
- DebugEcho("postie_save_attachment: uploaded $file_id ($file)");
1208
- } else {
1209
- EchoError("postie_save_attachment file error: " . $file_id->get_error_message());
1210
- postie_notify_error("Failed to add media file: $filename", $file_id->get_error_message());
1211
- }
1212
- } else {
1213
- EchoError("$filename has an unsupported MIME type $mimetype_primary and was not added.");
1214
- DebugEcho("postie_save_attachment: Not in supported filetype list: '$mimetype_primary'");
1215
- DebugDump($config['supported_file_types']);
1216
- postie_notify_error("Unsupported MIME type: $mimetype_primary", "$filename has an unsupported MIME type $mimetype_primary and was not added.\nSupported types:\n" . print_r($config['supported_file_types'], true));
1217
- }
1218
- break;
1219
- }
1220
- }
1221
-
1222
- // This function cleans up HTML in the email
1223
- function filter_CleanHtml($content) {
1224
- $html = str_get_html($content);
1225
- if ($html) {
1226
- DebugEcho("filter_CleanHtml: checking filter postie_cleanhtml");
1227
- if (apply_filters('postie_cleanhtml', true)) {
1228
- DebugEcho("filter_CleanHtml: Looking for invalid tags");
1229
- foreach ($html->find('script, style, head') as $node) {
1230
- DebugEcho("filter_CleanHtml: Removing: " . $node->outertext);
1231
- $node->outertext = '';
1232
- }
1233
- DebugEcho("filter_CleanHtml: " . $html->save());
1234
-
1235
- $html->load($html->save());
1236
-
1237
- $b = $html->find('body');
1238
- if ($b) {
1239
- DebugEcho("filter_CleanHtml: replacing body with div");
1240
- $content = "<div>" . $b[0]->innertext . "</div>\n";
1241
- }
1242
- } else {
1243
- DebugEcho("filter_CleanHtml: skipping clean html due to filter");
1244
- }
1245
- } else {
1246
- DebugEcho("filter_CleanHtml: No HTML found");
1247
- }
1248
- return $content;
1249
- }
1250
-
1251
- /**
1252
- * Determines if the sender is a valid user.
1253
- * @return integer|NULL
1254
- */
1255
- function postie_ValidatePoster(&$mimeDecodedEmail, $config) {
1256
- extract($config);
1257
- $poster = NULL;
1258
- $from = "";
1259
- if (array_key_exists('headers', $mimeDecodedEmail) && array_key_exists('from', $mimeDecodedEmail['headers'])) {
1260
- $from = $mimeDecodedEmail['headers']['from']['mailbox'] . '@' . $mimeDecodedEmail['headers']['from']['host'];
1261
- $from = apply_filters('postie_filter_email', $from);
1262
- DebugEcho("ValidatePoster: post postie_filter_email $from");
1263
-
1264
- $toEmail = '';
1265
- if (isset($mimeDecodedEmail['headers']['to'])) {
1266
- $toEmail = $mimeDecodedEmail['headers']['to'][0]['mailbox'] . '@' . $mimeDecodedEmail['headers']['to'][0]['host'];
1267
- }
1268
-
1269
- $replytoEmail = '';
1270
- if (isset($mimeDecodedEmail['headers']['reply-to'])) {
1271
- $replytoEmail = $mimeDecodedEmail['headers']['reply-to']['mailbox'] . '@' . $mimeDecodedEmail['headers']['reply-to']['host'];
1272
- }
1273
-
1274
- $from = apply_filters("postie_filter_email2", $from, $toEmail, $replytoEmail);
1275
- DebugEcho("ValidatePoster: post postie_filter_email2 $from");
1276
- } else {
1277
- DebugEcho("No 'from' header found");
1278
- DebugDump($mimeDecodedEmail['headers']);
1279
- }
1280
-
1281
- if (array_key_exists("headers", $mimeDecodedEmail)) {
1282
- $from = apply_filters("postie_filter_email3", $from, $mimeDecodedEmail['headers']);
1283
- DebugEcho("ValidatePoster: post postie_filter_email3 $from");
1284
- }
1285
-
1286
- $resentFrom = "";
1287
- if (array_key_exists('headers', $mimeDecodedEmail) && array_key_exists('resent-from', $mimeDecodedEmail['headers'])) {
1288
- $resentFrom = postie_RemoveExtraCharactersInEmailAddress(trim($mimeDecodedEmail['headers']['resent-from']));
1289
- }
1290
-
1291
- //See if the email address is one of the special authorized ones
1292
- $user_ID = '';
1293
- if (!empty($from)) {
1294
- DebugEcho("Confirming Access For $from ");
1295
- $user = get_user_by('email', $from);
1296
- if ($user !== false) {
1297
- if (is_user_member_of_blog($user->ID)) {
1298
- $user_ID = $user->ID;
1299
- } else {
1300
- DebugEcho("$from is not user of blog " . get_current_blog_id());
1301
- }
1302
- }
1303
- }
1304
-
1305
- if (!empty($user_ID)) {
1306
- $user = new WP_User($user_ID);
1307
- if ($user->has_cap("post_via_postie")) {
1308
- DebugEcho("$user_ID has 'post_via_postie' permissions");
1309
- $poster = $user_ID;
1310
-
1311
- DebugEcho("ValidatePoster: pre postie_author $poster");
1312
- $poster = apply_filters("postie_author", $poster);
1313
- DebugEcho("ValidatePoster: post postie_author $poster");
1314
- } else {
1315
- DebugEcho("$user_ID does not have 'post_via_postie' permissions");
1316
- $user_ID = "";
1317
- }
1318
- }
1319
-
1320
- if (empty($user_ID) && ($config['turn_authorization_off'] || postie_isEmailAddressAuthorized($from, $config['authorized_addresses']) || postie_isEmailAddressAuthorized($resentFrom, $config['authorized_addresses']))) {
1321
- DebugEcho("ValidatePoster: looking up default user " . $config['admin_username']);
1322
- $user = get_user_by('login', $config['admin_username']);
1323
- if ($user === false) {
1324
- EchoError("Your 'Default Poster' setting '" . $config['admin_username'] . "' is not a valid WordPress user (2)");
1325
- $poster = 1;
1326
- } else {
1327
- $poster = $user->ID;
1328
- DebugEcho("ValidatePoster: pre postie_author (default) $poster");
1329
- $poster = apply_filters("postie_author", $poster);
1330
- DebugEcho("ValidatePoster: post postie_author (default) $poster");
1331
- }
1332
- DebugEcho("ValidatePoster: found user '$poster'");
1333
- }
1334
-
1335
- if (!$poster) {
1336
- EchoError('Invalid sender: ' . htmlentities($from) . "! Not adding email!");
1337
- if ($config['forward_rejected_mail']) {
1338
- postie_email_reject($mimeDecodedEmail, array(get_option("admin_email")), $config['return_to_sender']);
1339
- EchoError("A copy of the message has been forwarded to the administrator.");
1340
- }
1341
- return '';
1342
- }
1343
-
1344
- //actually log in as the user
1345
- if ($config['force_user_login'] == true) {
1346
- $user = get_user_by('id', $poster);
1347
- if ($user) {
1348
- DebugEcho("logging in as {$user->user_login}");
1349
- wp_set_current_user($poster);
1350
- //wp_set_auth_cookie($poster);
1351
- do_action('wp_login', $user->user_login);
1352
- }
1353
- }
1354
- return $poster;
1355
- }
1356
-
1357
- /**
1358
- * Looks at the content for the start of the message and removes everything before that
1359
- * If the pattern is not found everything is returned
1360
- * @param string
1361
- * @param string
1362
- */
1363
- function filter_Start($content, $config) {
1364
- $start = $config['message_start'];
1365
- if (!empty($start)) {
1366
- $pos = stripos($content, $start);
1367
- if ($pos === false) {
1368
- return $content;
1369
- }
1370
- DebugEcho("start filter $start");
1371
- $content = substr($content, $pos + strlen($start), strlen($content));
1372
- }
1373
- return $content;
1374
- }
1375
-
1376
- /**
1377
- * Looks at the content for the start of the signature and removes all text
1378
- * after that point
1379
- * @param string
1380
- * @param array - a list of patterns to determine if it is a sig block
1381
- */
1382
- function filter_RemoveSignature($content, $config) {
1383
- DebugEcho("filter_RemoveSignature: start");
1384
- if ($config['drop_signature']) {
1385
- if (empty($config['sig_pattern_list'])) {
1386
- DebugEcho("filter_RemoveSignature: no sig_pattern_list");
1387
- return $content;
1388
- }
1389
- //DebugEcho("looking for signature in: $content");
1390
-
1391
- $pattern = '/^(' . implode('|', $config['sig_pattern_list']) . ')\s?$/miu';
1392
- DebugEcho("filter_RemoveSignature: pattern: $pattern");
1393
-
1394
- $html = postie_LoadDOM($content);
1395
- if ($html !== false) {
1396
- filter_RemoveSignatureWorker($html->root, $pattern);
1397
- $content = $html->save();
1398
- } else {
1399
- DebugEcho("filter_RemoveSignature: non-html");
1400
- $arrcontent = explode("\n", $content);
1401
- $strcontent = '';
1402
-
1403
- for ($i = 0; $i < count($arrcontent); $i++) {
1404
- $line = trim($arrcontent[$i]);
1405
- if (preg_match($pattern, trim($line))) {
1406
- DebugEcho("filter_RemoveSignature: signature found: removing");
1407
- break;
1408
- }
1409
-
1410
- DebugEcho("filter_RemoveSignature: keeping '$line'");
1411
- $strcontent .= $line;
1412
- }
1413
- $content = $strcontent;
1414
- }
1415
- } else {
1416
- DebugEcho("filter_RemoveSignature: configured to skip");
1417
- }
1418
- return $content;
1419
- }
1420
-
1421
- function filter_RemoveSignatureWorker(&$html, $pattern) {
1422
- $found = false;
1423
- $matches = array();
1424
- if (preg_match($pattern, trim($html->plaintext), $matches)) {
1425
- DebugEcho("filter_RemoveSignatureWorker: signature '$matches[1]' found in:\n" . trim($html->plaintext));
1426
- //DebugDump($matches);
1427
- $found = true;
1428
- $i = stripos($html->innertext, $matches[1]);
1429
- $presig = substr($html->innertext, 0, $i);
1430
- DebugEcho("filter_RemoveSignatureWorker sig new text:\n$presig");
1431
- $html->innertext = $presig;
1432
- } else {
1433
- DebugEcho("filter_RemoveSignatureWorker: no matches " . preg_last_error() . " '$pattern' $html->plaintext");
1434
- //DebugDump($matches);
1435
- }
1436
-
1437
- foreach ($html->children() as $e) {
1438
- //DebugEcho("sig: " . $e->plaintext);
1439
- if (!$found && preg_match($pattern, trim($e->plaintext))) {
1440
- DebugEcho("filter_RemoveSignatureWorker signature found: removing");
1441
- $found = true;
1442
- }
1443
- if ($found) {
1444
- $e->outertext = '';
1445
- } else {
1446
- $found = filter_RemoveSignatureWorker($e, $pattern);
1447
- }
1448
- }
1449
- return $found;
1450
- }
1451
-
1452
- /**
1453
- * Looks at the content for the given tag and removes all text
1454
- * after that point
1455
- * @param string
1456
- * @param filter
1457
- */
1458
- function filter_End($content, $config) {
1459
- $end = $config['message_end'];
1460
- if (!empty($end)) {
1461
- $pos = stripos($content, $end);
1462
- if ($pos === false) {
1463
- return $content;
1464
- }
1465
- DebugEcho("end filter: $end");
1466
- $content = substr($content, 0, $pos);
1467
- }
1468
- return $content;
1469
- }
1470
-
1471
- //filter content for new lines
1472
- function filter_Newlines($content, $config) {
1473
- if ($config['filternewlines']) {
1474
- DebugEcho("filter_Newlines: filternewlines");
1475
- $search = array(
1476
- "/\r\n\r\n/",
1477
- "/\r\n/",
1478
- "/\n\n/",
1479
- "/\r/",
1480
- "/\n/"
1481
- );
1482
- $replace = array(
1483
- 'PARABREAK',
1484
- 'LINEBREAK',
1485
- 'LINEBREAK',
1486
- 'LINEBREAK',
1487
- 'LINEBREAK'
1488
- );
1489
-
1490
- $result = preg_replace($search, $replace, $content);
1491
- DebugDump($result);
1492
-
1493
- if ($config['convertnewline']) {
1494
- DebugEcho("filter_Newlines: converting newlines to <br>");
1495
- $content = preg_replace('/(LINEBREAK)/', "<br />\n", $result);
1496
- $content = preg_replace('/(PARABREAK)/', "<br />\n<br />\n", $content);
1497
- } else {
1498
- $content = preg_replace('/(LINEBREAK)/', " ", $result);
1499
- $content = preg_replace('/(PARABREAK)/', "\r\n", $content);
1500
- }
1501
- }
1502
- return $content;
1503
- }
1504
-
1505
- //strip pgp stuff
1506
- function filter_StripPGP($content) {
1507
- $search = array(
1508
- '/-----BEGIN PGP SIGNED MESSAGE-----/',
1509
- '/Hash: SHA1/'
1510
- );
1511
- $replace = array(
1512
- ' ',
1513
- ''
1514
- );
1515
- return preg_replace($search, $replace, $content);
1516
- }
1517
-
1518
- /**
1519
- * Checks for the comments tag
1520
- * @return boolean
1521
- */
1522
- function tag_AllowCommentsOnPost(&$content) {
1523
- $comments_allowed = get_option('default_comment_status'); // 'open' or 'closed'
1524
-
1525
- $matches = array();
1526
- if (preg_match("/comments:([0|1|2])/iu", $content, $matches)) {
1527
- $content = preg_replace("/comments:$matches[1]/i", "", $content);
1528
- if ($matches[1] == "1") {
1529
- $comments_allowed = "open";
1530
- } else if ($matches[1] == "2") {
1531
- $comments_allowed = "registered_only";
1532
- } else {
1533
- $comments_allowed = "closed";
1534
- }
1535
- }
1536
- return $comments_allowed;
1537
- }
1538
-
1539
- function tag_Status(&$content, $currentstatus) {
1540
- $poststatus = $currentstatus;
1541
- $matches = array();
1542
- if (preg_match("/status:\s*(draft|publish|pending|private|future)/iu", $content, $matches)) {
1543
- DebugEcho("tag_Status: found status $matches[1]");
1544
- DebugDump($matches);
1545
- $content = preg_replace("/$matches[0]/i", "", $content);
1546
- $poststatus = $matches[1];
1547
- }
1548
- return $poststatus;
1549
- }
1550
-
1551
- function tag_Delay(&$content, $message_date, $config) {
1552
- $offset = (!$config['ignore_email_date'] && $config['use_time_offset']) ? $config['time_offset'] : 0;
1553
-
1554
- //DebugEcho("tag_Delay: $content");
1555
- $delay = 0;
1556
- $matches = array();
1557
- if (preg_match("/delay:(-?[0-9dhm]+)/iu", $content, $matches) && trim($matches[1])) {
1558
- DebugEcho("tag_Delay: found delay: " . $matches[1]);
1559
- $days = 0;
1560
- $hours = 0;
1561
- $minutes = 0;
1562
- $dayMatches = array();
1563
- if (preg_match("/(-?[0-9]+)d/iu", $matches[1], $dayMatches)) {
1564
- $days = $dayMatches[1];
1565
- }
1566
- $hourMatches = array();
1567
- if (preg_match("/(-?[0-9]+)h/iu", $matches[1], $hourMatches)) {
1568
- $hours = $hourMatches[1];
1569
- }
1570
- $minuteMatches = array();
1571
- if (preg_match("/(-?[0-9]+)m/iu", $matches[1], $minuteMatches)) {
1572
- $minutes = $minuteMatches[1];
1573
- }
1574
- $delay = (($days * 24 + $hours) * 60 + $minutes) * 60;
1575
- $interval = 'P';
1576
- if (abs($days) > 0) {
1577
- $interval .= abs($days) . 'D';
1578
- }
1579
- if (abs($hours) > 0) {
1580
- $interval .= 'T' . abs($hours) . 'H';
1581
- }
1582
- if (abs($minutes) > 0) {
1583
- if (abs($hours) > 0) {
1584
- $interval .= abs($minutes) . 'M';
1585
- } else {
1586
- $interval .= 'T' . abs($minutes) . 'M';
1587
- }
1588
- }
1589
-
1590
- DebugEcho("tag_Delay: calculated delay: $delay");
1591
- DebugEcho("tag_Delay: interval: $interval");
1592
- $content = preg_replace("/delay:$matches[1]/i", "", $content);
1593
- }
1594
-
1595
- $tzs = get_option('timezone_string');
1596
- if (empty($tzs)) {
1597
- $tzs = 'GMT';
1598
- }
1599
- DebugEcho("tag_Delay: timezone: $tzs");
1600
-
1601
- if ($config['ignore_email_date']) {
1602
- $dateInSeconds = new DateTime(current_time('mysql'), new DateTimeZone($tzs));
1603
- DebugEcho("tag_Delay: ignoring date: " . $dateInSeconds->format(DATE_RFC2822));
1604
- } else {
1605
- if (empty($message_date)) {
1606
- $dateInSeconds = new DateTime(current_time('mysql'), new DateTimeZone($tzs));
1607
- DebugEcho("tag_Delay: using current date: " . $dateInSeconds->format(DATE_RFC2822));
1608
- } else {
1609
- DebugEcho("tag_Delay: using message date(1): $message_date");
1610
- $dateInSeconds = new DateTime($message_date, new DateTimeZone($tzs));
1611
- DebugEcho("tag_Delay: using message date(2): " . $dateInSeconds->format(DATE_RFC2822));
1612
- }
1613
- }
1614
-
1615
- if ($delay > 0) {
1616
- $delayeddateInSeconds = $dateInSeconds->add(new DateInterval($interval));
1617
- }
1618
- if ($delay < 0) {
1619
- $delayeddateInSeconds = $dateInSeconds->sub(new DateInterval($interval));
1620
- }
1621
- if ($delay == 0) {
1622
- $delayeddateInSeconds = clone $dateInSeconds;
1623
- }
1624
- //$delayeddateInSeconds->setTimezone(new DateTimeZone($tzs));
1625
-
1626
- if ($offset > 0) {
1627
- $corrected_date = $delayeddateInSeconds->add(new DateInterval('PT' . $offset . 'H'));
1628
- }
1629
- if ($offset < 0) {
1630
- $corrected_date = $delayeddateInSeconds->sub(new DateInterval('PT' . abs($offset) . 'H'));
1631
- }
1632
- if ($offset == 0) {
1633
- $corrected_date = clone $delayeddateInSeconds;
1634
- }
1635
- $corrected_date->setTimezone(new DateTimeZone($tzs));
1636
-
1637
- DebugEcho("tag_Delay: message date: " . $dateInSeconds->format(DATE_RFC2822));
1638
- DebugEcho("tag_Delay: delay: $delay");
1639
- DebugEcho("tag_Delay: offset: $offset");
1640
- DebugEcho("tag_Delay: delayed date: " . $delayeddateInSeconds->format(DATE_RFC2822));
1641
- DebugEcho("tag_Delay: delayed with offset: " . $corrected_date->format(DATE_RFC2822));
1642
-
1643
- return array($corrected_date->format(DATE_W3C), $delay);
1644
- }
1645
-
1646
- /**
1647
- * This function takes the content of the message - looks for a subject at the beginning surrounded by # and then removes that from the content
1648
- */
1649
- function tag_Subject($content, $defaultTitle) {
1650
- DebugEcho("tag_Subject: Looking for subject in email body");
1651
- if (substr($content, 0, 1) != "#") {
1652
- DebugEcho("tag_Subject: No inline subject found, using supplied default [1] '$defaultTitle'");
1653
- return(array($defaultTitle, $content));
1654
- }
1655
- //make sure the first line isn't #img
1656
- if (strtolower(substr($content, 1, 3)) != "img") {
1657
- $subjectEndIndex = strpos($content, "#", 1);
1658
- if (!$subjectEndIndex > 0) {
1659
- DebugEcho("tag_Subject: No subject found, using default [2]");
1660
- return(array($defaultTitle, $content));
1661
- }
1662
- $subject = substr($content, 1, $subjectEndIndex - 1);
1663
- $content = substr($content, $subjectEndIndex + 1, strlen($content));
1664
- DebugEcho("tag_Subject: Subject found in body: $subject");
1665
- return array($subject, $content);
1666
- } else {
1667
- return(array($defaultTitle, $content));
1668
- }
1669
- }
1670
-
1671
- function postie_media_handle_upload($attachment, $post_id) {
1672
-
1673
- $tmpFile = tempnam(get_temp_dir(), 'postie');
1674
- if ($tmpFile !== false) {
1675
- $fp = fopen($tmpFile, 'w');
1676
- if ($fp) {
1677
- fwrite($fp, $attachment['data']);
1678
- fclose($fp);
1679
- DebugEcho("postie_media_handle_upload: wrote data to '$tmpFile'");
1680
- } else {
1681
- EchoError("postie_media_handle_upload: Could not write to temp file: '$tmpFile' ");
1682
- postie_notify_error("postie_media_handle_upload: Could not write to temp file: '$tmpFile' ", "postie_media_handle_upload: Could not write to temp file: '$tmpFile' ");
1683
- }
1684
- } else {
1685
- EchoError("postie_media_handle_upload: Could not create temp file in " . get_temp_dir());
1686
- postie_notify_error("postie_media_handle_upload: Could not create temp file in " . get_temp_dir(), "postie_media_handle_upload: Could not create temp file in " . get_temp_dir());
1687
- }
1688
-
1689
- $file_array = array(
1690
- 'name' => $attachment['wp_filename'],
1691
- 'type' => $attachment['mimetype'],
1692
- 'tmp_name' => $tmpFile,
1693
- 'error' => 0,
1694
- 'size' => filesize($tmpFile)
1695
- );
1696
- DebugEcho("postie_media_handle_upload: adding " . $file_array['name']);
1697
- DebugDump($file_array);
1698
-
1699
- $id = media_handle_sideload($file_array, $post_id);
1700
-
1701
- if (!is_wp_error($id)) {
1702
- $mediapath = get_attached_file($id);
1703
- $file_array['tmp_name'] = $mediapath;
1704
- DebugEcho("doing postie_file_added");
1705
- do_action('postie_file_added', $post_id, $id, $file_array);
1706
- } else {
1707
- EchoError("There was an error adding the attachement: " . $id->get_error_message());
1708
- DebugDump($id->get_error_messages());
1709
- DebugDump($id->get_error_data());
1710
- postie_notify_error("There was an error adding the attachement: " . $attachment['wp_filename'], $id->get_error_message());
1711
- }
1712
-
1713
- return $id;
1714
- }
1715
-
1716
- function postie_email_notify($email, $recipients, $postid) {
1717
- DebugEcho("postie_email_notify: start");
1718
-
1719
- if (count($recipients) == 0) {
1720
- DebugEcho("postie_email_notify: no recipients");
1721
- return;
1722
- }
1723
- if (empty($postid)) {
1724
- DebugEcho("postie_email_notify: no post id");
1725
- return;
1726
- }
1727
-
1728
- $myemailadd = get_option("admin_email");
1729
- $blogname = get_option("blogname");
1730
- $eblogname = "=?utf-8?b?" . base64_encode($blogname) . "?= ";
1731
- $posturl = get_permalink($postid);
1732
- $subject = $email['headers']['subject'];
1733
-
1734
- $sendheaders = array("From: $eblogname <$myemailadd>");
1735
-
1736
- $post_status = get_post_status($postid);
1737
-
1738
- $mailtext = "Your email '$subject' has been successfully imported into $blogname $posturl with the current status of '$post_status'.\n";
1739
-
1740
- $recipients = apply_filters('postie_email_notify_recipients', $recipients, $email, $postid);
1741
- if (count($recipients) == 0) {
1742
- DebugEcho("postie_email_notify: no recipients after postie_email_notify_recipients filter");
1743
- return;
1744
- } else {
1745
- DebugEcho("postie_email_notify: post postie_email_notify_recipients");
1746
- DebugDump($recipients);
1747
- }
1748
- $subject = "Email imported to $blogname ($post_status)";
1749
- $subject = apply_filters('postie_email_notify_subject', $subject, $email, $postid);
1750
- DebugEcho("postie_email_notify: post postie_email_notify_subject: $subject");
1751
-
1752
- $mailtext = apply_filters('postie_email_notify_body', $mailtext, $email, $postid);
1753
- DebugEcho("postie_email_notify: post postie_email_notify_body: $mailtext");
1754
-
1755
-
1756
- wp_mail($recipients, $subject, $mailtext, $sendheaders);
1757
- }
1758
-
1759
- function postie_header_encode($value) {
1760
- return "=?utf-8?b?" . base64_encode($value) . "?= ";
1761
- }
1762
-
1763
- function postie_email_reject($email, $recipients, $returnToSender) {
1764
- DebugEcho("postie_email_reject: start");
1765
-
1766
- if (count($recipients) == 0) {
1767
- DebugEcho("postie_email_reject: no recipients");
1768
- return;
1769
- }
1770
-
1771
- $blogname = get_option("blogname");
1772
- $from = $email['headers']['from']['mailbox'] . '@' . $email['headers']['from']['host'];
1773
-
1774
- $subject = $email['headers']['subject'];
1775
- if ($returnToSender) {
1776
- DebugEcho("postie_email_reject: return to sender $from");
1777
- array_push($recipients, $from);
1778
- }
1779
-
1780
- $eblogname = postie_header_encode($blogname);
1781
- $adminemail = get_option("admin_email");
1782
-
1783
- $headers = array();
1784
- $headers[] = "From: $eblogname <$adminemail>";
1785
-
1786
- DebugEcho("postie_email_reject: To:");
1787
- DebugDump($recipients);
1788
- DebugEcho("postie_email_reject: header:");
1789
- DebugDump($headers);
1790
-
1791
- $message = "An unauthorized message has been sent to $blogname.\n";
1792
- $message .= "Sender: $from\n";
1793
- $message .= "Subject: $subject\n";
1794
- $message .= "\n\nIf you wish to allow posts from this address, please add " . $from . " to the registered users list and manually add the content of the email found below.";
1795
- $message .= "\n\nOtherwise, the email has already been deleted from the server and you can ignore this message.";
1796
- $message .= "\n\nIf you would like to prevent postie from forwarding mail in the future, please change the FORWARD_REJECTED_MAIL setting in the Postie settings panel";
1797
- $message .= "\n\nThe original content of the email has been attached.\n\n";
1798
-
1799
- $recipients = apply_filters('postie_email_reject_recipients', $recipients, $email);
1800
- if (count($recipients) == 0) {
1801
- DebugEcho("postie_email_reject: no recipients after postie_email_reject_recipients filter");
1802
- return;
1803
- } else {
1804
- DebugEcho("postie_email_reject: post postie_email_reject_recipients");
1805
- DebugDump($recipients);
1806
- }
1807
-
1808
- $subject = $blogname . ": Unauthorized Post Attempt from $from";
1809
- $subject = apply_filters('postie_email_reject_subject', $subject, $email);
1810
- DebugEcho("postie_email_reject: post postie_email_reject_subject: $subject");
1811
-
1812
- $message = apply_filters('postie_email_reject_body', $message, $email);
1813
- DebugEcho("postie_email_reject: post postie_email_reject_body: $message");
1814
-
1815
- $attachTxt = wp_tempnam() . '.txt';
1816
- file_put_contents($attachTxt, $email['text']);
1817
-
1818
- $attachHtml = wp_tempnam() . '.htm';
1819
- file_put_contents($attachHtml, $email['html']);
1820
-
1821
- wp_mail($recipients, $subject, $message, $headers, array($attachTxt, $attachHtml));
1822
-
1823
- unlink($attachTxt);
1824
- unlink($attachHtml);
1825
- }
1826
-
1827
- /**
1828
- * This compares the current address to the list of authorized addresses
1829
- * @param string - email address
1830
- * @return boolean
1831
- */
1832
- function postie_isEmailAddressAuthorized($address, $authorized) {
1833
- $r = false;
1834
- if (is_array($authorized)) {
1835
- $a = strtolower(trim($address));
1836
- if (!empty($a)) {
1837
- $r = in_array($a, array_map('strtolower', $authorized));
1838
- }
1839
- }
1840
- return $r;
1841
- }
1842
-
1843
- /**
1844
- * This method works around a problem with email address with extra <> in the email address
1845
- * @param string
1846
- * @return string
1847
- */
1848
- function postie_RemoveExtraCharactersInEmailAddress($address) {
1849
- $matches = array();
1850
- if (preg_match('/^[^<>]+<([^<> ()]+)>$/', $address, $matches)) {
1851
- $address = $matches[1];
1852
- DebugEcho("RemoveExtraCharactersInEmailAddress: $address (1)");
1853
- DebugDump($matches);
1854
- } else if (preg_match('/<([^<> ()]+)>/', $address, $matches)) {
1855
- $address = $matches[1];
1856
- DebugEcho("RemoveExtraCharactersInEmailAddress: $address (2)");
1857
- }
1858
-
1859
- return $address;
1860
- }
1861
-
1862
- /**
1863
- * This function gleans the name from an email address if available. If not
1864
- * it just returns the username (everything before @)
1865
- */
1866
- function postie_get_name_from_email($address) {
1867
- $name = "";
1868
- $matches = array();
1869
- if (preg_match('/^([^<>]+)<([^<> ()]+)>$/', $address, $matches)) {
1870
- $name = $matches[1];
1871
- } else if (preg_match('/<([^<>@ ()]+)>/', $address, $matches)) {
1872
- $name = $matches[1];
1873
- } else if (preg_match('/(.+?)@(.+)/', $address, $matches)) {
1874
- $name = $matches[1];
1875
- }
1876
-
1877
- return trim($name);
1878
- }
1879
-
1880
- /**
1881
- * Choose an appropriate file icon based on the extension and mime type of
1882
- * the attachment
1883
- */
1884
- function postie_chooseAttachmentIcon($file, $primary, $secondary, $iconSet = 'silver', $size = '32') {
1885
- if ($iconSet == 'none') {
1886
- return('');
1887
- }
1888
- $fileName = basename($file);
1889
- $parts = explode('.', $fileName);
1890
- $ext = $parts[count($parts) - 1];
1891
- $docExts = array('doc', 'docx');
1892
- $docMimes = array('msword', 'vnd.ms-word', 'vnd.openxmlformats-officedocument.wordprocessingml.document');
1893
- $pptExts = array('ppt', 'pptx');
1894
- $pptMimes = array('mspowerpoint', 'vnd.ms-powerpoint', 'vnd.openxmlformats-officedocument.');
1895
- $xlsExts = array('xls', 'xlsx');
1896
- $xlsMimes = array('msexcel', 'vnd.ms-excel', 'vnd.openxmlformats-officedocument.spreadsheetml.sheet');
1897
- $iWorkMimes = array('zip', 'octet-stream');
1898
- $mpgExts = array('mpg', 'mpeg', 'mp2');
1899
- $mpgMimes = array('mpg', 'mpeg', 'mp2');
1900
- $mp3Exts = array('mp3');
1901
- $mp3Mimes = array('mp3', 'mpeg3', 'mpeg');
1902
- $mp4Exts = array('mp4', 'm4v');
1903
- $mp4Mimes = array('mp4', 'mpeg4', 'octet-stream');
1904
- $aacExts = array('m4a', 'aac');
1905
- $aacMimes = array('m4a', 'aac', 'mp4');
1906
- $aviExts = array('avi');
1907
- $aviMimes = array('avi', 'x-msvideo');
1908
- $movExts = array('mov');
1909
- $movMimes = array('mov', 'quicktime');
1910
- if ($ext == 'pdf' && $secondary == 'pdf') {
1911
- $fileType = 'pdf';
1912
- } else if ($ext == 'pages' && in_array($secondary, $iWorkMimes)) {
1913
- $fileType = 'pages';
1914
- } else if ($ext == 'numbers' && in_array($secondary, $iWorkMimes)) {
1915
- $fileType = 'numbers';
1916
- } else if ($ext == 'key' && in_array($secondary, $iWorkMimes)) {
1917
- $fileType = 'key';
1918
- } else if (in_array($ext, $docExts) && in_array($secondary, $docMimes)) {
1919
- $fileType = 'doc';
1920
- } else if (in_array($ext, $pptExts) && in_array($secondary, $pptMimes)) {
1921
- $fileType = 'ppt';
1922
- } else if (in_array($ext, $xlsExts) && in_array($secondary, $xlsMimes)) {
1923
- $fileType = 'xls';
1924
- } else if (in_array($ext, $mp4Exts) && in_array($secondary, $mp4Mimes)) {
1925
- $fileType = 'mp4';
1926
- } else if (in_array($ext, $movExts) && in_array($secondary, $movMimes)) {
1927
- $fileType = 'mov';
1928
- } else if (in_array($ext, $aviExts) && in_array($secondary, $aviMimes)) {
1929
- $fileType = 'avi';
1930
- } else if (in_array($ext, $mp3Exts) && in_array($secondary, $mp3Mimes)) {
1931
- $fileType = 'mp3';
1932
- } else if (in_array($ext, $mpgExts) && in_array($secondary, $mpgMimes)) {
1933
- $fileType = 'mpg';
1934
- } else if (in_array($ext, $aacExts) && in_array($secondary, $aacMimes)) {
1935
- $fileType = 'aac';
1936
- } else {
1937
- $fileType = 'default';
1938
- }
1939
- $fileName = "/icons/$iconSet/$fileType-$size.png";
1940
- if (!file_exists(POSTIE_ROOT . $fileName)) {
1941
- $fileName = "/icons/$iconSet/default-$size.png";
1942
- }
1943
- $iconHtml = "<img src='" . POSTIE_URL . $fileName . "' alt='$fileType icon' />";
1944
- DebugEcho("icon: $iconHtml");
1945
- return $iconHtml;
1946
- }
1947
-
1948
- function parseTemplate($fileid, $type, $template, $orig_filename, $icon = "") {
1949
- DebugEcho("parseTemplate: before '$template'");
1950
-
1951
- $attachment = get_post($fileid);
1952
- $uploadDir = wp_upload_dir();
1953
- $fileName = basename($attachment->guid);
1954
- $fileType = pathinfo($fileName, PATHINFO_EXTENSION);
1955
- $absFileName = $uploadDir['path'] . '/' . $fileName;
1956
- $relFileName = str_replace(ABSPATH, '', $absFileName);
1957
- $fileLink = wp_get_attachment_url($fileid);
1958
- $pageLink = get_attachment_link($fileid);
1959
-
1960
- $template = str_replace('{TITLE}', $attachment->post_title, $template);
1961
- $template = str_replace('{ID}', $fileid, $template);
1962
-
1963
- if ($type == 'image') {
1964
- $widths = array();
1965
- $heights = array();
1966
- $img_urls = array();
1967
-
1968
- postie_show_filters_for('image_downsize'); //possible overrides for image_downsize()
1969
-
1970
- /*
1971
- * Possible enhancement: support all sizes returned by get_intermediate_image_sizes()
1972
- */
1973
- $sizes = array('thumbnail', 'medium', 'large');
1974
- for ($i = 0; $i < count($sizes); $i++) {
1975
- $iinfo = image_downsize($fileid, $sizes[$i]);
1976
- if (false !== $iinfo) {
1977
- $img_urls[$i] = $iinfo[0];
1978
- $widths[$i] = $iinfo[1];
1979
- $heights[$i] = $iinfo[2];
1980
- }
1981
- }
1982
- DebugEcho('parseTemplate: Sources');
1983
- DebugDump($img_urls);
1984
- DebugEcho('parseTemplate: Heights');
1985
- DebugDump($heights);
1986
- DebugEcho('parseTemplate: Widths');
1987
- DebugDump($widths);
1988
-
1989
- $template = str_replace('{THUMBNAIL}', $img_urls[0], $template);
1990
- $template = str_replace('{THUMB}', $img_urls[0], $template);
1991
- $template = str_replace('{MEDIUM}', $img_urls[1], $template);
1992
- $template = str_replace('{LARGE}', $img_urls[2], $template);
1993
- $template = str_replace('{THUMBWIDTH}', $widths[0] . 'px', $template);
1994
- $template = str_replace('{THUMBHEIGHT}', $heights[0] . 'px', $template);
1995
- $template = str_replace('{MEDIUMWIDTH}', $widths[1] . 'px', $template);
1996
- $template = str_replace('{MEDIUMHEIGHT}', $heights[1] . 'px', $template);
1997
- $template = str_replace('{LARGEWIDTH}', $widths[2] . 'px', $template);
1998
- $template = str_replace('{LARGEHEIGHT}', $heights[2] . 'px', $template);
1999
- }
2000
-
2001
- $template = str_replace('{FULL}', $fileLink, $template);
2002
- $template = str_replace('{FILELINK}', $fileLink, $template);
2003
- $template = str_replace('{FILETYPE}', $fileType, $template);
2004
- $template = str_replace('{PAGELINK}', $pageLink, $template);
2005
- $template = str_replace('{FILENAME}', $orig_filename, $template);
2006
- $template = str_replace('{IMAGE}', $fileLink, $template);
2007
- $template = str_replace('{URL}', $fileLink, $template);
2008
- $template = str_replace('{RELFILENAME}', $relFileName, $template);
2009
- $template = str_replace('{ICON}', $icon, $template);
2010
- $template = str_replace('{FILEID}', $fileid, $template);
2011
-
2012
- DebugEcho("parseTemplate: after: '$template<br />'");
2013
- return $template . '<br />';
2014
- }
2015
-
2016
- /**
2017
- * When sending in HTML email the html refers to the content-id(CID) of the image - this replaces
2018
- * the cid place holder with the actual url of the image sent in
2019
- * @param string - text of post
2020
- * @param array - array of HTML for images for post
2021
- */
2022
- function filter_ReplaceImageCIDs($content, &$email) {
2023
- DebugEcho('filter_ReplaceImageCIDs: start');
2024
- $content = preg_replace("/\[(cid:\S+)\]/i", '<img src="$1"/>', $content); //fix "[cid:xxx-xxx-xx]" image references gmail adds to plain text
2025
- if (count($email['related'])) {
2026
- DebugEcho("filter_ReplaceImageCIDs: # CID attachments: " . count($email['related']));
2027
- foreach ($email['related'] as $cid => &$attachment) {
2028
- if (false !== stripos($content, $cid)) {
2029
- DebugEcho("filter_ReplaceImageCIDs: CID: $cid");
2030
- $fileid = $attachment['wp_id'];
2031
- $url = wp_get_attachment_url($fileid);
2032
- $content = str_replace($cid, $url, $content);
2033
- $attachment['exclude'] = true;
2034
- } else {
2035
- DebugEcho("filter_ReplaceImageCIDs: CID not found: $cid");
2036
- }
2037
- }
2038
- } else {
2039
- DebugEcho("filter_ReplaceImageCIDs: no cid attachments");
2040
- }
2041
- return $content;
2042
- }
2043
-
2044
- function filter_ReplaceInlineImage($content, &$email, $config) {
2045
- DebugEcho('filter_ReplaceInlineImage: start');
2046
- $i = 1;
2047
- foreach ($email['inline'] as &$inlineImage) {
2048
- if (($inlineImage['primary'] == 'image' && $config['auto_gallery']) ||
2049
- $config['custom_image_field'] ||
2050
- $config['featured_image'] && !$config['include_featured_image'] && $i == 1) {
2051
- //remove inline placeholder if we're not showing the image here
2052
- DebugEcho('filter_ReplaceInlineImage: do not add inline due to config');
2053
- $template = '';
2054
- } else {
2055
- $template = $inlineImage['template'];
2056
- }
2057
- $inlinemarker = '<:inline ' . $inlineImage['filename'] . ' inline:>'; //use the original non-sanitized name
2058
- if (false !== stripos($content, $inlinemarker)) {
2059
- DebugEcho('filter_ReplaceInlineImage: ' . $inlineImage['filename']);
2060
- $content = str_ireplace($inlinemarker, $template, $content);
2061
- $inlineImage['exclude'] = !empty($template); //don't exclude if we didn't add
2062
- } else {
2063
- DebugEcho('filter_ReplaceInlineImage: not found: ' . $inlineImage['filename']);
2064
- }
2065
- $i++;
2066
- }
2067
- return $content;
2068
- }
2069
-
2070
- /**
2071
- * This function handles replacing image place holder #img1# with the HTML for that image
2072
- */
2073
- function filter_ReplaceImagePlaceHolders($content, &$email, $config, $post_id, $image_pattern) {
2074
- DebugEcho("filter_ReplaceImagePlaceHolders: start");
2075
- if (!$config['custom_image_field']) {
2076
- $startIndex = $config['start_image_count_at_zero'] ? 0 : 1;
2077
-
2078
- $images = get_posts(array(
2079
- 'post_parent' => $post_id,
2080
- 'post_type' => 'attachment',
2081
- 'numberposts' => -1,
2082
- 'post_mime_type' => 'image',));
2083
- DebugEcho("filter_ReplaceImagePlaceHolders: images in post: " . count($images));
2084
- DebugDump($images);
2085
-
2086
- $i = 0;
2087
-
2088
- //TODO only call the worker if the attachment matches one of the images
2089
- foreach ($email['attachment'] as &$attachment) {
2090
- $content = filter_ReplaceImagePlaceHolders_worker($content, $attachment, $image_pattern, $startIndex, $i);
2091
- $i++;
2092
- }
2093
- foreach ($email['inline'] as &$attachment) {
2094
- $content = filter_ReplaceImagePlaceHolders_worker($content, $attachment, $image_pattern, $startIndex, $i);
2095
- $i++;
2096
- }
2097
- foreach ($email['related'] as &$attachment) {
2098
- $content = filter_ReplaceImagePlaceHolders_worker($content, $attachment, $image_pattern, $startIndex, $i);
2099
- $i++;
2100
- }
2101
- } else {
2102
- DebugEcho("filter_ReplaceImagePlaceHolders: Custom image field, not adding images");
2103
- }
2104
- DebugEcho("filter_ReplaceImagePlaceHolders: end");
2105
- return $content;
2106
- }
2107
-
2108
- function filter_ReplaceImagePlaceHolders_worker($content, &$attachment, $imagePattern, $startIndex, $currentIndex) {
2109
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: " . $attachment['wp_filename']);
2110
-
2111
- if (empty($attachment['template'])) {
2112
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: no template");
2113
- return $content;
2114
- }
2115
-
2116
- $matches = array();
2117
- $pparts = explode('%', $imagePattern);
2118
- if (count($pparts) != 2) {
2119
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: invalid image pattern: $imagePattern");
2120
- return $content;
2121
- }
2122
- $pattern = '/' . $pparts[0] . (string) ($startIndex + $currentIndex) . '\s?(caption=[\'"]?(.*?)[\'"]?)?' . $pparts[1] . '/iu';
2123
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: pattern: $pattern");
2124
- preg_match_all($pattern, $content, $matches, PREG_SET_ORDER);
2125
- //DebugEcho($content);
2126
- DebugDump($matches);
2127
- foreach ($matches as $match) {
2128
- $attachment['exclude'] = true;
2129
- $imageTemplate = $attachment['template'];
2130
-
2131
- $caption = '';
2132
- if (count($match) > 2) {
2133
- $caption = trim($match[2]);
2134
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: caption: '$caption'");
2135
- }
2136
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: parameterize templete: $imageTemplate");
2137
- $imageTemplate = mb_str_replace('{CAPTION}', htmlspecialchars($caption, ENT_QUOTES), $imageTemplate);
2138
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: captioned template: $imageTemplate");
2139
-
2140
- if (!empty($caption)) {
2141
- $img = get_post($attachment['wp_id']);
2142
- $img->post_excerpt = $caption;
2143
- wp_update_post($img);
2144
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: caption added to metadata");
2145
- }
2146
- $imageTemplate = apply_filters('postie_place_media', $imageTemplate, $attachment['wp_id']);
2147
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: post postie_place_media: '$imageTemplate'");
2148
-
2149
- $content = str_ireplace($match[0], $imageTemplate, $content);
2150
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: post replace: $content");
2151
- }
2152
- return $content;
2153
- }
2154
-
2155
- /**
2156
- * This function handles finding and setting the correct subject
2157
- * @return array - (subject,content)
2158
- */
2159
- function postie_get_subject(&$mimeDecodedEmail, &$content, $config) {
2160
- //assign the default title/subject
2161
- if (empty($mimeDecodedEmail['headers']['subject'])) {
2162
- DebugEcho("postie_get_subject: No subject in email");
2163
- if ($config['allow_subject_in_mail']) {
2164
- list($subject, $content) = tag_Subject($content, $config['default_title']);
2165
- } else {
2166
- DebugEcho("postie_get_subject: Using default subject");
2167
- $subject = $config['default_title'];
2168
- }
2169
- $mimeDecodedEmail['headers']['subject'] = $subject;
2170
- } else {
2171
- $subject = $mimeDecodedEmail['headers']['subject'];
2172
- DebugEcho(("postie_get_subject: Predecoded subject: $subject"));
2173
-
2174
- if ($config['allow_subject_in_mail']) {
2175
- list($subject, $content) = tag_Subject($content, $subject);
2176
- }
2177
- }
2178
- if (!$config['allow_html_in_subject']) {
2179
- DebugEcho("postie_get_subject: subject before htmlentities: $subject");
2180
- $subject = htmlentities($subject, ENT_COMPAT, $config['message_encoding']);
2181
- DebugEcho("postie_get_subject: subject after htmlentities: $subject");
2182
- }
2183
-
2184
- //This is for ISO-2022-JP - Can anyone confirm that this is still neeeded?
2185
- // escape sequence is 'ESC $ B' == 1b 24 42 hex.
2186
- if (strpos($subject, "\x1b\x24\x42") !== false) {
2187
- // found iso-2022-jp escape sequence in subject... convert!
2188
- DebugEcho("postie_get_subject: extra parsing for ISO-2022-JP");
2189
- $subject = iconv("ISO-2022-JP", "UTF-8//TRANSLIT", $subject);
2190
- }
2191
- DebugEcho("postie_get_subject: '$subject'");
2192
- return $subject;
2193
- }
2194
-
2195
- function tag_Tags(&$content, $defaultTags, $isHtml) {
2196
- $post_tags = array();
2197
-
2198
- $matches = array();
2199
- $rx = '/>\s*tags:\s?(.*?)</isu';
2200
- if (!$isHtml) {
2201
- $rx = '/tags:\s?(.*)/iu';
2202
- }
2203
- if (preg_match($rx, $content, $matches)) {
2204
- if (!empty($matches[1])) {
2205
- DebugEcho("Found tags: $matches[1]");
2206
- if ($isHtml) {
2207
- $content = str_replace($matches[0], "><", $content);
2208
- } else {
2209
- $content = str_replace($matches[0], "", $content);
2210
- }
2211
- $post_tags = preg_split("/,\s*/", trim($matches[1]));
2212
- }
2213
- }
2214
-
2215
- if (count($post_tags) == 0 && is_array($defaultTags)) {
2216
- $post_tags = $defaultTags;
2217
- }
2218
- return $post_tags;
2219
- }
2220
-
2221
- function tag_Excerpt(&$content, $config) {
2222
- $post_excerpt = '';
2223
- $matches = array();
2224
- if (preg_match('/:excerptstart ?(.*):excerptend/is', $content, $matches)) {
2225
- $content = str_replace($matches[0], "", $content);
2226
- $post_excerpt = $matches[1];
2227
- DebugEcho("excerpt found: $post_excerpt");
2228
- if ($config['filternewlines']) {
2229
- DebugEcho("filtering newlines from excerpt");
2230
- $post_excerpt = filter_Newlines($post_excerpt, $config);
2231
- }
2232
- }
2233
- return $post_excerpt;
2234
- }
2235
-
2236
- /**
2237
- * This function determines the categories ids for the post
2238
- * @return array
2239
- */
2240
- function tag_Categories(&$subject, $defaultCategoryId, $config, $post_id) {
2241
- DebugEcho("tag_Categories: start");
2242
- $category_match = $config['category_match'];
2243
- $original_subject = $subject;
2244
- $found = false;
2245
- $post_categories = array();
2246
- $matchtypes = array();
2247
- $matches = array();
2248
-
2249
- if ($config['category_bracket']) {
2250
- if (preg_match_all('/\[(.[^\[]*)\]/', $subject, $matches)) { // [<category1>] [<category2>] <Subject>
2251
- $matchtypes[] = $matches;
2252
- }
2253
- }
2254
-
2255
- if ($config['category_dash']) {
2256
- if (preg_match_all('/-(.[^-]*)-/', $subject, $matches)) { // -<category>- -<category2>- <Subject>
2257
- $matchtypes[] = $matches;
2258
- }
2259
- }
2260
-
2261
- if ($config['category_colon']) {
2262
- if (preg_match('/(.+):\s?(.*)/', $subject, $matches)) { // <category>: <Subject>
2263
- $matchtypes[] = array(array(0 => $matches[1] . ':'), array(1 => $matches[1]));
2264
- }
2265
- }
2266
-
2267
- DebugEcho("tag_Categories: found categories");
2268
- DebugDump($matchtypes);
2269
- foreach ($matchtypes as $matches) {
2270
- if (count($matches)) {
2271
- $i = 0;
2272
- foreach ($matches[1] as $match) {
2273
- DebugEcho("tag_Categories: checking: $match");
2274
-
2275
- DebugEcho("tag_Categories: looking up: $defaultCategoryId");
2276
- $defaultcat_name = '';
2277
- $defaultcat = get_term_by('id', $defaultCategoryId, postie_lookup_taxonomy_name($defaultCategoryId));
2278
- if (false !== $defaultcat) {
2279
- $defaultcat_name = $defaultcat->name;
2280
- DebugEcho("tag_Categories: default: $defaultcat_name");
2281
- } else {
2282
- DebugEcho("tag_Categories: default not found");
2283
- }
2284
- $trial_category = apply_filters('postie_category', trim($match), $category_match, $defaultcat_name);
2285
- DebugEcho("tag_Categories: post postie_category: $trial_category");
2286
-
2287
- $categoryid = postie_lookup_category_id($trial_category, $category_match);
2288
- if (!empty($categoryid)) {
2289
- $found = true;
2290
- $subject = str_replace($matches[0][$i], '', $subject);
2291
- DebugEcho("tag_Categories: subject: $subject");
2292
- $tax = postie_lookup_taxonomy_name($categoryid);
2293
- if ('category' == $tax) {
2294
- DebugEcho("tag_Categories: standard taxonomy $tax");
2295
- $post_categories[] = $categoryid;
2296
- } else {
2297
- DebugEcho("tag_Categories: custom taxonomy $tax");
2298
- wp_set_object_terms($post_id, $categoryid, $tax, true);
2299
- }
2300
- }
2301
- $i++;
2302
- }
2303
- }
2304
- }
2305
- if (!$found || !$config['category_remove']) {
2306
- DebugEcho("tag_Categories: using default: $defaultCategoryId");
2307
- $post_categories[] = $defaultCategoryId;
2308
- $subject = $original_subject;
2309
- }
2310
- $subject = trim($subject);
2311
- return $post_categories;
2312
- }
2313
-
2314
- function postie_lookup_taxonomy_name($termid) {
2315
- global $wpdb;
2316
- $tax_sql = 'SELECT taxonomy FROM ' . $wpdb->term_taxonomy . ' WHERE term_id = ' . $termid;
2317
- $tax = $wpdb->get_var($tax_sql);
2318
- DebugEcho("lookup_taxonomy: $termid is in taxonomy $tax");
2319
- return $tax;
2320
- }
2321
-
2322
- function postie_lookup_category_id($trial_category, $category_match = true) {
2323
- global $wpdb;
2324
- DebugEcho("lookup_category: $trial_category");
2325
-
2326
- $term = get_term_by('name', esc_attr($trial_category), 'category');
2327
- if (!empty($term)) {
2328
- DebugEcho("lookup_category: found by name $trial_category");
2329
- //DebugDump($term);
2330
- //then category is a named and found
2331
- return $term->term_id;
2332
- } else {
2333
- DebugEcho("lookup_category: not found by name $trial_category");
2334
- }
2335
-
2336
- $term = get_term_by('slug', esc_attr($trial_category), 'category');
2337
- if (!empty($term)) {
2338
- DebugEcho("lookup_category: found by slug $trial_category");
2339
- return $term->term_id;
2340
- } else {
2341
- DebugEcho("lookup_category: not found by slug $trial_category");
2342
- }
2343
-
2344
- if (is_numeric($trial_category)) {
2345
- DebugEcho("lookup_category: looking for id '$trial_category'");
2346
- $cat_id = intval($trial_category);
2347
- $term = get_term_by('id', $cat_id, 'category');
2348
- if (!empty($term) && $term->term_id == $trial_category) {
2349
- DebugEcho("lookup_category: found by id '$cat_id'");
2350
- DebugDump($term);
2351
- //then category was an ID and found
2352
- return $term->term_id;
2353
- } else {
2354
- DebugEcho("lookup_category: not found by id '$cat_id'");
2355
- }
2356
- }
2357
-
2358
- $found_category = NULL;
2359
- if ($category_match) {
2360
- DebugEcho("category wildcard lookup: $trial_category");
2361
- $sql_sub_name = 'SELECT term_id FROM ' . $wpdb->terms . ' WHERE name LIKE \'' . addslashes(esc_attr($trial_category)) . '%\' OR slug LIKE \'' . addslashes(esc_attr($trial_category)) . '%\' limit 1';
2362
- $found_category = $wpdb->get_var($sql_sub_name);
2363
- DebugEcho("lookup_category: wildcard found: $found_category");
2364
- } else {
2365
- DebugEcho("lookup_category: wildcard not found: $found_category");
2366
- }
2367
-
2368
- return intval($found_category); //force to integer
2369
- }
2370
-
2371
- /**
2372
- * Takes a value and builds a simple simple yes/no select box
2373
- * @param string
2374
- * @param string
2375
- * @param string
2376
- * @param string
2377
- */
2378
- function BuildSelect($label, $id, $current_value, $options, $recommendation = NULL) {
2379
-
2380
- $html = "<tr>
2381
- <th scope='row'><label for='$id'>$label</label>";
2382
-
2383
- $html .= "</th><td><select name='$id' id='$id'>";
2384
- foreach ($options as $value) {
2385
- $html .= "<option value='$value' " . ($value == $current_value ? "selected='selected'" : "") . ">" . __($value, 'postie') . '</option>';
2386
- }
2387
- $html .= '</select>';
2388
- if (!empty($recommendation)) {
2389
- $html .= '<p class = "description">' . $recommendation . '</p>';
2390
- }
2391
- $html .= "</td>\n</tr>";
2392
-
2393
- return $html;
2394
- }
2395
-
2396
- /**
2397
- * Takes a value and builds a simple simple yes/no select box
2398
- * @param string
2399
- * @param string
2400
- * @param string
2401
- * @param string
2402
- */
2403
- function BuildBooleanSelect($label, $id, $current_value, $recommendation = NULL, $options = null) {
2404
-
2405
- $html = "<tr>
2406
- <th scope='row'><label for='$id'>$label</label>";
2407
-
2408
-
2409
- if (!(is_array($options) && count($options) == 2)) {
2410
- $options = Array('Yes', 'No');
2411
- }
2412
-
2413
- $html .= "</th>
2414
- <td><select name='$id' id='$id'>
2415
- <option value='1'>" . __($options[0], 'postie') . "</option>
2416
- <option value='0' " . (!$current_value ? "selected='selected'" : "") . ">" . __($options[1], 'postie') . '</option>
2417
- </select>';
2418
- if (!empty($recommendation)) {
2419
- $html .= '<p class = "description">' . $recommendation . '</p>';
2420
- }
2421
- $html .= "</td>\n</tr>";
2422
-
2423
- return $html;
2424
- }
2425
-
2426
- /**
2427
- * This takes an array and display a text box for editing
2428
- * @param string
2429
- * @param string
2430
- * @param array
2431
- * @param string
2432
- */
2433
- function BuildTextArea($label, $id, $current_value, $recommendation = NULL) {
2434
- $html = "<tr><th scope='row'><label for='$id'>$label</label>";
2435
-
2436
- $html .= "</th>";
2437
-
2438
- $html .= "<td><br /><textarea cols=40 rows=3 name='$id' id='$id'>";
2439
- $current_value = preg_split("/[\r\n]+/", esc_attr(trim($current_value)));
2440
- if (is_array($current_value)) {
2441
- foreach ($current_value as $item) {
2442
- $html .= "$item\n";
2443
- }
2444
- }
2445
- $html .= "</textarea>";
2446
- if ($recommendation) {
2447
- $html .= "<p class='description'>" . $recommendation . "</p>";
2448
- }
2449
- $html .= "</td></tr>";
2450
- return $html;
2451
- }
2452
-
2453
- /**
2454
- * This function resets all the configuration options to the default
2455
- */
2456
- function config_ResetToDefault() {
2457
- $newconfig = config_GetDefaults();
2458
- $config = get_option('postie-settings');
2459
- $save_keys = array('mail_password', 'mail_server', 'mail_server_port', 'mail_userid', 'input_protocol', 'input_connection');
2460
- foreach ($save_keys as $key) {
2461
- $newconfig[$key] = $config[$key];
2462
- }
2463
- update_option('postie-settings', $newconfig);
2464
- config_Update($newconfig);
2465
- return $newconfig;
2466
- }
2467
-
2468
- /**
2469
- * This function used to handle updating the configuration.
2470
- * @return boolean
2471
- */
2472
- function config_Update($data) {
2473
- postie_UpdatePermissions($data['role_access']);
2474
- // We also update the cron settings
2475
- postie_cron($data['interval']);
2476
- }
2477
-
2478
- /**
2479
- * return an array of the config defaults
2480
- */
2481
- function config_GetDefaults() {
2482
- include('templates/audio_templates.php');
2483
- include('templates/image_templates.php');
2484
- include('templates/video1_templates.php');
2485
- include('templates/video2_templates.php');
2486
- include 'templates/general_template.php';
2487
- return array(
2488
- 'add_meta' => 'no',
2489
- 'admin_username' => 'admin',
2490
- 'allow_html_in_body' => true,
2491
- 'allow_html_in_subject' => true,
2492
- 'allow_subject_in_mail' => true,
2493
- 'audiotemplate' => $simple_link,
2494
- 'audiotypes' => array('m4a', 'mp3', 'ogg', 'wav', 'mpeg'),
2495
- 'authorized_addresses' => array(),
2496
- 'banned_files_list' => array(),
2497
- 'confirmation_email' => '',
2498
- 'convertnewline' => false,
2499
- 'converturls' => true,
2500
- 'custom_image_field' => false,
2501
- 'default_post_category' => NULL,
2502
- 'category_match' => true,
2503
- 'default_post_tags' => array(),
2504
- 'default_title' => "Live From The Field",
2505
- 'delete_mail_after_processing' => true,
2506
- 'drop_signature' => true,
2507
- 'filternewlines' => true,
2508
- 'forward_rejected_mail' => true,
2509
- 'icon_set' => 'silver',
2510
- 'icon_size' => 32,
2511
- 'auto_gallery' => false,
2512
- 'image_new_window' => false,
2513
- 'image_placeholder' => "#img%#",
2514
- 'images_append' => true,
2515
- 'imagetemplate' => $wordpress_default,
2516
- 'imagetemplates' => $imageTemplates,
2517
- 'input_protocol' => "pop3",
2518
- 'input_connection' => 'sockets',
2519
- 'interval' => 'twiceperhour',
2520
- 'mail_server' => NULL,
2521
- 'mail_server_port' => 110,
2522
- 'mail_userid' => NULL,
2523
- 'mail_password' => NULL,
2524
- 'maxemails' => 0,
2525
- 'message_start' => ":start",
2526
- 'message_end' => ":end",
2527
- 'message_encoding' => "UTF-8",
2528
- 'message_dequote' => true,
2529
- 'post_status' => 'publish',
2530
- 'prefer_text_type' => "plain",
2531
- 'return_to_sender' => false,
2532
- 'role_access' => array(),
2533
- 'selected_audiotemplate' => 'simple_link',
2534
- 'selected_imagetemplate' => 'wordpress_default',
2535
- 'selected_video1template' => 'vshortcode',
2536
- 'selected_video2template' => 'simple_link',
2537
- 'shortcode' => false,
2538
- 'sig_pattern_list' => array('--\s?[\r\n]?', '--\s', '--', '---'),
2539
- 'smtp' => array(),
2540
- 'start_image_count_at_zero' => false,
2541
- 'supported_file_types' => array('application'),
2542
- 'turn_authorization_off' => false,
2543
- 'time_offset' => get_option('gmt_offset'),
2544
- 'video1template' => $simple_link,
2545
- 'video1types' => array('mp4', 'mpeg4', '3gp', '3gpp', '3gpp2', '3gp2', 'mov', 'mpeg', 'quicktime'),
2546
- 'video2template' => $simple_link,
2547
- 'video2types' => array('x-flv'),
2548
- 'video1templates' => $video1Templates,
2549
- 'video2templates' => $video2Templates,
2550
- 'wrap_pre' => 'no',
2551
- 'featured_image' => false,
2552
- 'include_featured_image' => true,
2553
- 'email_tls' => false,
2554
- 'post_format' => 'standard',
2555
- 'post_type' => 'post',
2556
- 'generaltemplates' => $generalTemplates,
2557
- 'generaltemplate' => $postie_default,
2558
- 'selected_generaltemplate' => 'postie_default',
2559
- 'generate_thumbnails' => true,
2560
- 'reply_as_comment' => true,
2561
- 'force_user_login' => false,
2562
- 'auto_gallery_link' => 'default',
2563
- 'ignore_mail_state' => false,
2564
- 'strip_reply' => true,
2565
- 'postie_log_error' => true,
2566
- 'postie_log_debug' => false,
2567
- 'category_colon' => true,
2568
- 'category_dash' => true,
2569
- 'category_bracket' => true,
2570
- 'prefer_text_convert' => true,
2571
- 'category_remove' => true,
2572
- 'ignore_email_date' => false,
2573
- 'use_time_offset' => false,
2574
- 'postie_log_error_notify' => '(All Admins)'
2575
- );
2576
- }
2577
-
2578
- /**
2579
- * =======================================================
2580
- * the following functions are only used to retrieve the old (pre 1.4) config, to convert it
2581
- * to the new format
2582
- */
2583
- function config_GetListOfArrayConfig() {
2584
- return(array('SUPPORTED_FILE_TYPES', 'AUTHORIZED_ADDRESSES',
2585
- 'SIG_PATTERN_LIST', 'BANNED_FILES_LIST', 'VIDEO1TYPES',
2586
- 'VIDEO2TYPES', 'AUDIOTYPES', 'SMTP'));
2587
- }
2588
-
2589
- function config_Read() {
2590
- $config = get_option('postie-settings');
2591
- return config_ValidateSettings($config);
2592
- }
2593
-
2594
- /**
2595
- * This function retrieves the old-format config (pre 1.4) from the database
2596
- * @return array
2597
- */
2598
- function config_ReadOld() {
2599
- $config = array();
2600
- global $wpdb;
2601
- $wpdb->query("SHOW TABLES LIKE '" . $GLOBALS['table_prefix'] . "postie_config'");
2602
- if ($wpdb->num_rows > 0) {
2603
- $data = $wpdb->get_results("SELECT label,value FROM " . $GLOBALS['table_prefix'] . "postie_config;");
2604
- if (is_array($data)) {
2605
- foreach ($data as $row) {
2606
- if (in_array($row->label, config_GetListOfArrayConfig())) {
2607
- $config[$row->label] = unserialize($row->value);
2608
- } else {
2609
- $config[$row->label] = $row->value;
2610
- }
2611
- }
2612
- }
2613
- }
2614
- return $config;
2615
- }
2616
-
2617
- /**
2618
- * This function processes the old-format config (pre 1.4) for conversion to the 1.4 format
2619
- * @return array
2620
- * @access private
2621
- */
2622
- function config_UpgradeOld() {
2623
- $config = config_ReadOld();
2624
- if (!isset($config['ADMIN_USERNAME'])) {
2625
- $config['ADMIN_USERNAME'] = 'admin';
2626
- }
2627
- if (!isset($config['PREFER_TEXT_TYPE'])) {
2628
- $config['PREFER_TEXT_TYPE'] = "plain";
2629
- }
2630
- if (!isset($config['DEFAULT_TITLE'])) {
2631
- $config['DEFAULT_TITLE'] = "Live From The Field";
2632
- }
2633
- if (!isset($config["INPUT_PROTOCOL"])) {
2634
- $config["INPUT_PROTOCOL"] = "pop3";
2635
- }
2636
- if (!isset($config["IMAGE_PLACEHOLDER"])) {
2637
- $config["IMAGE_PLACEHOLDER"] = "#img%#";
2638
- }
2639
- if (!isset($config["IMAGES_APPEND"])) {
2640
- $config["IMAGES_APPEND"] = true;
2641
- }
2642
- if (!isset($config["ALLOW_SUBJECT_IN_MAIL"])) {
2643
- $config["ALLOW_SUBJECT_IN_MAIL"] = true;
2644
- }
2645
- if (!isset($config["DROP_SIGNATURE"])) {
2646
- $config["DROP_SIGNATURE"] = true;
2647
- }
2648
- if (!isset($config["MESSAGE_START"])) {
2649
- $config["MESSAGE_START"] = ":start";
2650
- }
2651
- if (!isset($config["MESSAGE_END"])) {
2652
- $config["MESSAGE_END"] = ":end";
2653
- }
2654
- if (!isset($config["FORWARD_REJECTED_MAIL"])) {
2655
- $config["FORWARD_REJECTED_MAIL"] = true;
2656
- }
2657
- if (!isset($config["RETURN_TO_SENDER"])) {
2658
- $config["RETURN_TO_SENDER"] = false;
2659
- }
2660
- if (!isset($config["CONFIRMATION_EMAIL"])) {
2661
- $config["CONFIRMATION_EMAIL"] = '';
2662
- }
2663
- if (!isset($config["ALLOW_HTML_IN_SUBJECT"])) {
2664
- $config["ALLOW_HTML_IN_SUBJECT"] = true;
2665
- }
2666
- if (!isset($config["ALLOW_HTML_IN_BODY"])) {
2667
- $config["ALLOW_HTML_IN_BODY"] = true;
2668
- }
2669
- if (!isset($config["START_IMAGE_COUNT_AT_ZERO"])) {
2670
- $config["START_IMAGE_COUNT_AT_ZERO"] = false;
2671
- }
2672
- if (!isset($config["MESSAGE_ENCODING"])) {
2673
- $config["MESSAGE_ENCODING"] = "UTF-8";
2674
- }
2675
- if (!isset($config["MESSAGE_DEQUOTE"])) {
2676
- $config["MESSAGE_DEQUOTE"] = true;
2677
- }
2678
- if (!isset($config["TURN_AUTHORIZATION_OFF"])) {
2679
- $config["TURN_AUTHORIZATION_OFF"] = false;
2680
- }
2681
- if (!isset($config["CUSTOM_IMAGE_FIELD"])) {
2682
- $config["CUSTOM_IMAGE_FIELD"] = false;
2683
- }
2684
- if (!isset($config["CONVERTNEWLINE"])) {
2685
- $config["CONVERTNEWLINE"] = false;
2686
- }
2687
- if (!isset($config["SIG_PATTERN_LIST"])) {
2688
- $config["SIG_PATTERN_LIST"] = array('--', '---');
2689
- }
2690
- if (!isset($config["BANNED_FILES_LIST"])) {
2691
- $config["BANNED_FILES_LIST"] = array();
2692
- }
2693
- if (!isset($config["SUPPORTED_FILE_TYPES"])) {
2694
- $config["SUPPORTED_FILE_TYPES"] = array("application");
2695
- }
2696
- if (!isset($config["AUTHORIZED_ADDRESSES"])) {
2697
- $config["AUTHORIZED_ADDRESSES"] = array();
2698
- }
2699
- if (!isset($config["MAIL_SERVER"])) {
2700
- $config["MAIL_SERVER"] = NULL;
2701
- }
2702
- if (!isset($config["MAIL_SERVER_PORT"])) {
2703
- $config["MAIL_SERVER_PORT"] = NULL;
2704
- }
2705
- if (!isset($config["MAIL_USERID"])) {
2706
- $config["MAIL_USERID"] = NULL;
2707
- }
2708
- if (!isset($config["MAIL_PASSWORD"])) {
2709
- $config["MAIL_PASSWORD"] = NULL;
2710
- }
2711
- if (!isset($config["DEFAULT_POST_CATEGORY"])) {
2712
- $config["DEFAULT_POST_CATEGORY"] = NULL;
2713
- }
2714
- if (!isset($config["DEFAULT_POST_TAGS"])) {
2715
- $config["DEFAULT_POST_TAGS"] = NULL;
2716
- }
2717
- if (!isset($config["TIME_OFFSET"])) {
2718
- $config["TIME_OFFSET"] = get_option('gmt_offset');
2719
- }
2720
- if (!isset($config["WRAP_PRE"])) {
2721
- $config["WRAP_PRE"] = 'no';
2722
- }
2723
- if (!isset($config["CONVERTURLS"])) {
2724
- $config["CONVERTURLS"] = true;
2725
- }
2726
- if (!isset($config["SHORTCODE"])) {
2727
- $config["SHORTCODE"] = false;
2728
- }
2729
- if (!isset($config["ADD_META"])) {
2730
- $config["ADD_META"] = 'no';
2731
- }
2732
- $config['ICON_SETS'] = array('silver', 'black', 'white', 'custom', 'none');
2733
- if (!isset($config["ICON_SET"])) {
2734
- $config["ICON_SET"] = 'silver';
2735
- }
2736
- $config['ICON_SIZES'] = array(32, 48, 64);
2737
- if (!isset($config["ICON_SIZE"])) {
2738
- $config["ICON_SIZE"] = 32;
2739
- }
2740
-
2741
- //audio
2742
- include('templates/audio_templates.php');
2743
- if (!isset($config["SELECTED_AUDIOTEMPLATE"])) {
2744
- $config['SELECTED_AUDIOTEMPLATE'] = 'simple_link';
2745
- }
2746
- $config['AUDIOTEMPLATES'] = $audioTemplates;
2747
- if (!isset($config["SELECTED_VIDEO1TEMPLATE"])) {
2748
- $config['SELECTED_VIDEO1TEMPLATE'] = 'simple_link';
2749
- }
2750
- if (!isset($config["AUDIOTEMPLATE"])) {
2751
- $config["AUDIOTEMPLATE"] = $simple_link;
2752
- }
2753
-
2754
- //video1
2755
- if (!isset($config["VIDEO1TYPES"])) {
2756
- $config['VIDEO1TYPES'] = array('mp4', 'mpeg4', '3gp', '3gpp', '3gpp2', '3gp2', 'mov', 'mpeg', 'quicktime');
2757
- }
2758
- if (!isset($config["AUDIOTYPES"])) {
2759
- $config['AUDIOTYPES'] = array('m4a', 'mp3', 'ogg', 'wav', 'mpeg');
2760
- }
2761
- if (!isset($config["SELECTED_VIDEO2TEMPLATE"])) {
2762
- $config['SELECTED_VIDEO2TEMPLATE'] = 'simple_link';
2763
- }
2764
- include('templates/video1_templates.php');
2765
- $config['VIDEO1TEMPLATES'] = $video1Templates;
2766
- if (!isset($config["VIDEO1TEMPLATE"])) {
2767
- $config["VIDEO1TEMPLATE"] = $simple_link;
2768
- }
2769
-
2770
- //video2
2771
- if (!isset($config["VIDEO2TYPES"])) {
2772
- $config['VIDEO2TYPES'] = array('x-flv');
2773
- }
2774
- if (!isset($config["POST_STATUS"])) {
2775
- $config["POST_STATUS"] = 'publish';
2776
- }
2777
- if (!isset($config["IMAGE_NEW_WINDOW"])) {
2778
- $config["IMAGE_NEW_WINDOW"] = false;
2779
- }
2780
- if (!isset($config["FILTERNEWLINES"])) {
2781
- $config["FILTERNEWLINES"] = true;
2782
- }
2783
- include('templates/video2_templates.php');
2784
- $config['VIDEO2TEMPLATES'] = $video2Templates;
2785
- if (!isset($config["VIDEO2TEMPLATE"])) {
2786
- $config["VIDEO2TEMPLATE"] = $simple_link;
2787
- }
2788
-
2789
- //image
2790
- if (!isset($config["SELECTED_IMAGETEMPLATE"])) {
2791
- $config['SELECTED_IMAGETEMPLATE'] = 'wordpress_default';
2792
- }
2793
- if (!isset($config["SMTP"])) {
2794
- $config["SMTP"] = array();
2795
- }
2796
- include('templates/image_templates.php');
2797
- if (!isset($config["IMAGETEMPLATE"])) {
2798
- $config["IMAGETEMPLATE"] = $wordpress_default;
2799
- }
2800
- $config['IMAGETEMPLATES'] = $imageTemplates;
2801
-
2802
- //general
2803
- include('templates/general_template.php');
2804
- if (!isset($config["GENERALTEMPLATE"])) {
2805
- $config["GENERALTEMPLATE"] = $postie_default;
2806
- }
2807
-
2808
- return $config;
2809
- }
2810
-
2811
- /**
2812
- * This function returns the old
2813
- -format config (pre 1.4)
2814
- * @return array
2815
- */
2816
- function config_GetOld() {
2817
- $config = config_UpgradeOld();
2818
- //These should only be modified if you are testing
2819
- $config["DELETE_MAIL_AFTER_PROCESSING"] = true;
2820
- $config["POST_TO_DB"] = true;
2821
- $config["TEST_EMAIL"] = false;
2822
- $config["TEST_EMAIL_ACCOUNT"] = "blogtest";
2823
- $config["TEST_EMAIL_PASSWORD"] = "yourpassword";
2824
- if (file_exists(POSTIE_ROOT . '/postie_test_variables.php')) {
2825
- include(POSTIE_ROOT . '/postie_test_variables.php');
2826
- }
2827
- //include(POSTIE_ROOT . "/../postie-test.php");
2828
- // These are computed
2829
- $config["TIME_OFFSET"] = get_option('gmt_offset');
2830
- $config["POSTIE_ROOT"] = POSTIE_ROOT;
2831
- for ($i = 0; $i < count($config["AUTHORIZED_ADDRESSES"]); $i++) {
2832
- $config["AUTHORIZED_ADDRESSES"][$i] = strtolower($config["AUTHORIZED_ADDRESSES"][$i]);
2833
- }
2834
- return $config;
2835
- }
2836
-
2837
- /**
2838
- * end of functions used to retrieve the old (pre 1.4) config
2839
- * =======================================================
2840
- */
2841
-
2842
- /**
2843
- * Returns a list of config keys that should be arrays
2844
- * @return array
2845
- */
2846
- function config_ArrayedSettings() {
2847
- return array(
2848
- ', ' => array('audiotypes', 'video1types', 'video2types', 'default_post_tags'),
2849
- "\n" => array('smtp', 'authorized_addresses', 'supported_file_types', 'banned_files_list', 'sig_pattern_list'));
2850
- }
2851
-
2852
- function postie_IsIconvInstalled($display = true) {
2853
- $function_list = array('iconv');
2854
- return(postie_HasFunctions($function_list, $display));
2855
- }
2856
-
2857
- /**
2858
- * Handles verifying that a list of functions exists
2859
- * @return boolean
2860
- * @param array
2861
- */
2862
- function postie_HasFunctions($function_list, $display = true) {
2863
- foreach ($function_list as $function) {
2864
- if (!function_exists($function)) {
2865
- if ($display) {
2866
- EchoError("Missing $function");
2867
- }
2868
- return false;
2869
- }
2870
- }
2871
- return true;
2872
- }
2873
-
2874
- /**
2875
- * This function looks for markdown which causes problems with postie
2876
- */
2877
- function postie_isMarkdownInstalled() {
2878
- if (in_array("markdown.php", get_option("active_plugins"))) {
2879
- return true;
2880
- }
2881
- return false;
2882
- }
2883
-
2884
- /**
2885
- * validates the config form output, fills in any gaps by using the defaults,
2886
- * and ensures that arrayed items are stored as such
2887
- */
2888
- function config_ValidateSettings($in) {
2889
- //DebugEcho("config_ValidateSettings");
2890
-
2891
- $out = array();
2892
-
2893
- //DebugDump($in);
2894
- // use the default as a template:
2895
- // if a field is present in the defaults, we want to store it; otherwise we discard it
2896
- $allowed_keys = config_GetDefaults();
2897
- foreach ($allowed_keys as $key => $default) {
2898
- if (is_array($in)) {
2899
- $out[$key] = array_key_exists($key, $in) ? $in[$key] : $default;
2900
- } else {
2901
- $out[$key] = $default;
2902
- }
2903
- }
2904
-
2905
- // some fields are always forced to lower case:
2906
- $lowercase = array('authorized_addresses', 'smtp', 'supported_file_types', 'video1types', 'video2types', 'audiotypes');
2907
- foreach ($lowercase as $field) {
2908
- $out[$field] = ( is_array($out[$field]) ) ? array_map("strtolower", $out[$field]) : strtolower($out[$field]);
2909
- }
2910
- $arrays = config_ArrayedSettings();
2911
-
2912
- foreach ($arrays as $sep => $fields) {
2913
- foreach ($fields as $field) {
2914
- if (!is_array($out[$field])) {
2915
- $out[$field] = explode($sep, trim($out[$field]));
2916
- }
2917
- foreach ($out[$field] as $key => $val) {
2918
- $tst = trim($val);
2919
- if
2920
- (empty($tst)) {
2921
- unset($out[$field][$key]);
2922
- } else {
2923
- $out[$field][$key] = $tst;
2924
- }
2925
- }
2926
- }
2927
- }
2928
-
2929
- config_Update($out);
2930
- return $out;
2931
- }
2932
-
2933
- /**
2934
- * This function handles setting up the basic permissions
2935
- */
2936
- function postie_UpdatePermissions($role_access) {
2937
- global $wp_roles;
2938
- if (is_object($wp_roles)) {
2939
- $admin = $wp_roles->get_role("administrator");
2940
- $admin->add_cap("config_postie");
2941
- $admin->add_cap("post_via_postie");
2942
-
2943
- if (!is_array($role_access)) {
2944
- $role_access = array();
2945
- }
2946
- foreach ($wp_roles->role_names as $roleId => $name) {
2947
- $role = $wp_roles->get_role($roleId);
2948
- if ($roleId != "administrator") {
2949
- if (array_key_exists($roleId, $role_access)) {
2950
- $role->add_cap("post_via_postie");
2951
- //DebugEcho("added $roleId");
2952
- } else {
2953
- $role->remove_cap("post_via_postie");
2954
- //DebugEcho("removed $roleId");
2955
- }
2956
- }
2957
- }
2958
- }
2959
- }
2960
-
2961
- function IsDebugMode() {
2962
- return (defined('POSTIE_DEBUG') && POSTIE_DEBUG == true);
2963
- }
2964
-
2965
- function postie_save_email_debug($raw, $email) {
2966
- if (IsDebugMode()) {
2967
- //DebugDump($email);
2968
- //DebugDump($mimeDecodedEmail);
2969
-
2970
- $dname = POSTIE_ROOT . DIRECTORY_SEPARATOR . 'test_emails' . DIRECTORY_SEPARATOR;
2971
- if (is_dir($dname)) {
2972
- $mid = $email['headers']['message-id'];
2973
- if (empty($mid)) {
2974
- $mid = uniqid();
2975
- }
2976
- $fname = $dname . sanitize_file_name($mid);
2977
-
2978
- file_put_contents($fname . '-raw.txt', $raw);
2979
- file_put_contents($fname . '.txt', $email['text']);
2980
- file_put_contents($fname . '.html', $email['html']);
2981
- }
2982
- }
2983
- }
2984
-
2985
- function postie_show_filters_for($hook = '') {
2986
- global $wp_filter;
2987
- if (empty($hook) || !isset($wp_filter[$hook])) {
2988
- DebugEcho("No registered filters for $hook");
2989
- return;
2990
- }
2991
- DebugEcho("Registered filters for $hook");
2992
- DebugDump($wp_filter[$hook]);
2993
- }
2994
-
2995
- function postie_test_config() {
2996
-
2997
- wp_get_current_user();
2998
-
2999
- if (!current_user_can('manage_options')) {
3000
- DebugEcho("non-admin tried to set options");
3001
- echo "<h2> Sorry only admin can run this file</h2>";
3002
- exit();
3003
- }
3004
-
3005
- $config = config_Read();
3006
- if (true == $config['postie_log_error'] || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
3007
- add_action('postie_log_error', 'postie_log_error');
3008
- }
3009
- if (true == $config['postie_log_debug'] && !defined('POSTIE_DEBUG')) {
3010
- define('POSTIE_DEBUG', true);
3011
- }
3012
- if (true == $config['postie_log_debug'] || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
3013
- add_action('postie_log_debug', 'postie_log_debug');
3014
- }
3015
- ?>
3016
- <div class="wrap">
3017
- <h1>Postie Configuration Test</h1>
3018
- <?php
3019
- postie_environment(true);
3020
- ?>
3021
-
3022
- <h2>Clock</h2>
3023
- <p>This shows what time it would be if you posted right now</p>
3024
- <?php
3025
- $wptz = get_option('gmt_offset');
3026
- $wptzs = get_option('timezone_string');
3027
- DebugEcho("Wordpress timezone: $wptzs ($wptz)", true);
3028
- DebugEcho("Current time: " . current_time('mysql'), true);
3029
- DebugEcho("Current time (gmt): " . current_time('mysql', 1), true);
3030
- DebugEcho("Postie time correction: {$config['time_offset']}", true);
3031
- $offsetdate = strtotime(current_time('mysql')) + ($config['use_time_offset'] ? $config['time_offset'] * 3600 : 0);
3032
-
3033
- DebugEcho("Post time: " . date('Y-m-d H:i:s', $offsetdate), true);
3034
- ?>
3035
- <h2>Encoding</h2>
3036
- <?php
3037
- $default_charset = ini_get('default_charset');
3038
- if (version_compare(phpversion(), '5.6.0', '<')) {
3039
- if (empty($default_charset)) {
3040
- DebugEcho("default_charset: WARNING no default_charset set see http://php.net/manual/en/ini.core.php#ini.default-charset", true);
3041
- } else {
3042
- DebugEcho("default_charset: $default_charset", true);
3043
- }
3044
- } else {
3045
- if (empty($default_charset)) {
3046
- DebugEcho("default_charset: UTF-8 (default)", true);
3047
- } else {
3048
- DebugEcho("default_charset: $default_charset", true);
3049
- }
3050
- }
3051
-
3052
- if (defined('DB_CHARSET')) {
3053
- DebugEcho("DB_CHARSET: " . DB_CHARSET, true);
3054
- } else {
3055
- DebugEcho("DB_CHARSET: undefined (utf8)", true);
3056
- }
3057
-
3058
- if (defined('DB_COLLATE')) {
3059
- $db_collate = DB_COLLATE;
3060
- if (empty($db_collate)) {
3061
- DebugEcho("DB_COLLATE: database default", true);
3062
- } else {
3063
- DebugEcho("DB_COLLATE: " . DB_COLLATE, true);
3064
- }
3065
- }
3066
-
3067
- DebugEcho("WordPress encoding: " . esc_attr(get_option('blog_charset')), true);
3068
- DebugEcho("Postie encoding: " . $config['message_encoding'], true);
3069
- ?>
3070
- <h2>Images</h2>
3071
- <?php
3072
- DebugEcho("registered image sizes");
3073
- DebugDump(get_intermediate_image_sizes());
3074
- ?>
3075
- <h2>Connect to Mail Host</h2>
3076
- <?php
3077
- DebugEcho("Postie connection: " . $config['input_connection'], true);
3078
- DebugEcho("Postie protocol: " . $config['input_protocol'], true);
3079
- DebugEcho("Postie server: " . $config['mail_server'], true);
3080
- DebugEcho("Postie port: " . $config['mail_server_port'], true);
3081
-
3082
- if (!$config['mail_server'] || !$config['mail_server_port'] || !$config['mail_userid']) {
3083
- EchoError("FAIL - server settings not complete");
3084
- }
3085
-
3086
- $conninfo = postie_get_conn_info($config);
3087
- if (IsDebugMode()) {
3088
- fCore::enableDebugging(true);
3089
- fCore::registerDebugCallback('DebugEcho');
3090
- }
3091
-
3092
- switch (strtolower($config['input_protocol'])) {
3093
- case 'imap':
3094
- case 'imap-ssl':
3095
- try {
3096
- if ($config['input_connection'] == 'curl') {
3097
- $conn = new pCurlConnection('imap', $conninfo['mail_server'], $conninfo['mail_user'], $conninfo['mail_password'], $conninfo['mail_port'], ($conninfo['mail_protocol'] == 'imap-ssl' || $conninfo['mail_protocol'] == 'pop3-ssl'));
3098
- } else {
3099
- $conn = new pSocketConnection('imap', $conninfo['mail_server'], $conninfo['mail_user'], $conninfo['mail_password'], $conninfo['mail_port'], ($conninfo['mail_protocol'] == 'imap-ssl' || $conninfo['mail_protocol'] == 'pop3-ssl'));
3100
- }
3101
- $srv = new pImapMailServer($conn);
3102
- $mailbox = new fMailbox('imap', $conn, $srv);
3103
- $m = $mailbox->countMessages();
3104
- DebugEcho("Successful " . strtoupper($config['input_protocol']) . " connection on port {$config['mail_server_port']}", true);
3105
- DebugEcho("# of waiting messages: $m", true);
3106
- } catch (Exception $e) {
3107
- EchoError("Unable to connect. The server said: " . $e->getMessage());
3108
- }
3109
- break;
3110
-
3111
- case 'pop3':
3112
- case 'pop3-ssl':
3113
- try {
3114
- if ($config['input_connection'] == 'curl') {
3115
- $conn = new pCurlConnection('pop3', $conninfo['mail_server'], $conninfo['mail_user'], $conninfo['mail_password'], $conninfo['mail_port'], ($conninfo['mail_protocol'] == 'imap-ssl' || $conninfo['mail_protocol'] == 'pop3-ssl'), 30);
3116
- } else {
3117
- $conn = new pSocketConnection('pop3', $conninfo['mail_server'], $conninfo['mail_user'], $conninfo['mail_password'], $conninfo['mail_port'], ($conninfo['mail_protocol'] == 'imap-ssl' || $conninfo['mail_protocol'] == 'pop3-ssl'));
3118
- }
3119
- $srv = new pPop3MailServer($conn);
3120
- $mailbox = new fMailbox('pop3', $conn, $srv);
3121
- $m = $mailbox->countMessages();
3122
- DebugEcho("Successful " . strtoupper($config['input_protocol']) . " connection on port {$config['mail_server_port']}", true);
3123
- DebugEcho("# of waiting messages: $m", true);
3124
- } catch (Exception $e) {
3125
- EchoError("Unable to connect. The server said:");
3126
- EchoError($e->getMessage());
3127
- }
3128
- break;
3129
- default:
3130
- EchoError("Unable to connect. Invalid setup");
3131
- break;
3132
- }
3133
- ?>
3134
- </div>
3135
- <?php
3136
- }
3137
-
3138
- function postie_get_conn_info($config) {
3139
- $conninfo = array();
3140
- $conninfo['mail_server'] = $config['mail_server'];
3141
- $conninfo['mail_port'] = $config['mail_server_port'];
3142
- $conninfo['mail_user'] = $config['mail_userid'];
3143
- $conninfo['mail_password'] = $config['mail_password'];
3144
- $conninfo['mail_protocol'] = $config['input_protocol'];
3145
- $conninfo['mail_tls'] = $config['email_tls'];
3146
- $conninfo['email_delete_after_processing'] = $config['delete_mail_after_processing'];
3147
- $conninfo['email_max'] = $config['maxemails'];
3148
- $conninfo['email_ignore_state'] = $config['ignore_mail_state'];
3149
-
3150
- return apply_filters('postie_preconnect', $conninfo);
3151
- }
3152
-
3153
- function postie_get_mail() {
3154
- $config = config_Read();
3155
- if (true == $config['postie_log_error'] || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
3156
- add_action('postie_log_error', 'postie_log_error');
3157
- }
3158
- if (true == $config['postie_log_debug'] && !defined('POSTIE_DEBUG')) {
3159
- define('POSTIE_DEBUG', true);
3160
- }
3161
- if (true == $config['postie_log_debug'] || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
3162
- add_action('postie_log_debug', 'postie_log_debug');
3163
- }
3164
-
3165
- DebugEcho('Starting mail fetch');
3166
- DebugEcho('WordPress datetime: ' . current_time('mysql'));
3167
-
3168
- DebugEcho("doing postie_session_start");
3169
- do_action('postie_session_start');
3170
-
3171
- postie_environment();
3172
-
3173
- $wp_content_path = dirname(dirname(dirname(__FILE__)));
3174
- DebugEcho("wp_content_path: $wp_content_path");
3175
- if (file_exists($wp_content_path . DIRECTORY_SEPARATOR . 'filterPostie.php')) {
3176
- DebugEcho("found filterPostie.php in $wp_content_path");
3177
- include_once ($wp_content_path . DIRECTORY_SEPARATOR . 'filterPostie.php');
3178
- }
3179
-
3180
- if (function_exists('memory_get_usage')) {
3181
- DebugEcho(__("memory at start of email processing: ", 'postie') . memory_get_usage());
3182
- }
3183
-
3184
- if (has_filter('postie_post')) {
3185
- echo "Postie: filter 'postie_post' is depricated in favor of 'postie_post_before'";
3186
- }
3187
-
3188
- if (!array_key_exists('maxemails', $config)) {
3189
- $config['maxemails'] = 0;
3190
- }
3191
-
3192
- $conninfo = postie_get_conn_info($config);
3193
-
3194
- $emails = postie_fetch_mail($conninfo['mail_server'], $conninfo['mail_port'], $conninfo['mail_user'], $conninfo['mail_password'], $conninfo['mail_protocol'], $conninfo['email_delete_after_processing'], $conninfo['email_max'], $config['input_connection']);
3195
-
3196
- $message = 'Done.';
3197
-
3198
- DebugEcho(sprintf(__("There are %d messages to process", 'postie'), count($emails)));
3199
-
3200
- //don't output the password
3201
- $tmp_config = $config;
3202
- unset($tmp_config['mail_password']);
3203
- DebugDump($tmp_config);
3204
-
3205
- //loop through messages
3206
- $message_number = 0;
3207
- foreach ($emails as $email) {
3208
- $message_number++;
3209
- DebugEcho("$message_number: ------------------------------------");
3210
- //DebugDump($email);
3211
- //sanity check to see if there is any info in the message
3212
- if ($email == NULL) {
3213
- $message = __('Dang, message is empty!', 'postie');
3214
- EchoError("$message_number: $message");
3215
- continue;
3216
- } else if ($email == 'already read') {
3217
- $message = __("Message is already marked 'read'.", 'postie');
3218
- DebugEcho("$message_number: $message");
3219
- continue;
3220
- }
3221
-
3222
- $tmp_config = $config;
3223
- if ($config['prefer_text_convert']) {
3224
- if ($config['prefer_text_type'] == 'plain' && trim($email['text']) == '' && trim($email['html']) != '') {
3225
- DebugEcho('postie_get_mail: switching to html');
3226
- $tmp_config['prefer_text_type'] = 'html';
3227
- }
3228
- if ($config['prefer_text_type'] == 'html' && trim($email['html']) == '' && trim($email['text']) != '') {
3229
- DebugEcho('postie_get_mail: switching to plain');
3230
- $tmp_config['prefer_text_type'] = 'plain';
3231
- }
3232
- }
3233
-
3234
- //Check poster to see if a valid person
3235
- $poster = postie_ValidatePoster($email, $tmp_config);
3236
- if (!empty($poster)) {
3237
- PostEmail($poster, $email, $tmp_config);
3238
- DebugEcho("$message_number: processed");
3239
- } else {
3240
- EchoError('Ignoring email - not authorized.');
3241
- }
3242
- flush();
3243
- }
3244
- DebugEcho("Mail fetch complete, $message_number emails");
3245
- DebugEcho("doing postie_session_end");
3246
- do_action('postie_session_end');
3247
-
3248
- if (function_exists('memory_get_usage')) {
3249
- DebugEcho('memory at end of email processing: ' . memory_get_usage());
3250
- }
3251
- }
3252
-
3253
- /* here we add some more cron options for how often to check for email */
3254
-
3255
- function postie_more_reccurences($schedules) {
3256
- //Do not echo output in filters, it seems to break some installs
3257
- //error_log("postie_more_reccurences: setting cron schedules");
3258
- $schedules['weekly'] = array('interval' => (60 * 60 * 24 * 7), 'display' => __('Once Weekly', 'postie'));
3259
- $schedules['twiceperhour'] = array('interval' => 60 * 30, 'display' => __('Twice per hour', 'postie'));
3260
- $schedules['tenminutes'] = array('interval' => 60 * 10, 'display' => __('Every 10 minutes', 'postie'));
3261
- $schedules['fiveminutes'] = array('interval' => 60 * 5, 'display' => __('Every 5 minutes', 'postie'));
3262
- $schedules['oneminute'] = array('interval' => 60 * 1, 'display' => __('Every 1 minute', 'postie'));
3263
- $schedules['thirtyseconds'] = array('interval' => 30, 'display' => __('Every 30 seconds', 'postie'));
3264
- $schedules['fifteenseconds'] = array('interval' => 15, 'display' => __('Every 15 seconds', 'postie'));
3265
- return $schedules;
3266
- }
3267
-
3268
- function postie_cron($interval = false) {
3269
- //Do not echo output in filters, it seems to break some installs
3270
- //error_log("postie_cron: setting up cron task: $interval");
3271
- //$schedules = wp_get_schedules();
3272
- //error_log("postie_cron\n" . print_r($schedules, true));
3273
-
3274
- if (!$interval) {
3275
- $config = config_Read();
3276
- $interval = $config['interval'];
3277
- //error_log("postie_cron: setting up cron task from config: $interval");
3278
- }
3279
- if (!$interval || $interval == '') {
3280
- $interval = 'hourly';
3281
- //error_log("Postie: setting up cron task: defaulting to hourly");
3282
- }
3283
- if ($interval == 'manual') {
3284
- postie_decron();
3285
- //error_log("postie_cron: clearing cron (manual)");
3286
- } else {
3287
- if ($interval != wp_get_schedule('check_postie_hook')) {
3288
- postie_decron(); //remove existing
3289
- //try to create the new schedule with the first run in 5 minutes
3290
- if (false === wp_schedule_event(time() + 5 * 60, $interval, 'check_postie_hook')) {
3291
- //error_log("postie_cron: Failed to set up cron task: $interval");
3292
- } else {
3293
- //error_log("postie_cron: Set up cron task: $interval");
3294
- }
3295
- } else {
3296
- //error_log("postie_cron: OK: $interval");
3297
- //don't need to do anything, cron already scheduled
3298
- }
3299
- }
3300
- }
3301
-
3302
- function postie_decron() {
3303
- //error_log("postie_decron: clearing cron");
3304
- wp_clear_scheduled_hook('check_postie_hook');
3305
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
postie-tags.php ADDED
@@ -0,0 +1,440 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function postie_is_html($str) {
4
+ return (1 == preg_match('/<[a-z][\s\S]*>/i', $str));
5
+ }
6
+
7
+ function postie_content_lines($content) {
8
+ global $g_postie;
9
+
10
+ $lines = array();
11
+ if (postie_is_html($content)) {
12
+ //DebugEcho("postie_content_lines: html");
13
+ $html = $g_postie->load_html($content);
14
+ if ($html !== false) {
15
+ $es = $html->find('text');
16
+ //DebugEcho("postie_content_lines: html " . count($es));
17
+ foreach ($es as $e) {
18
+ $lines[] = trim($e->plaintext);
19
+ }
20
+ }
21
+ } else {
22
+ //DebugEcho("postie_content_lines: not html");
23
+ $lines = explode("\n", $content);
24
+ }
25
+ return $lines;
26
+ }
27
+
28
+ function postie_lookup_taxonomy_name($termid) {
29
+ global $wpdb;
30
+ $tax_sql = 'SELECT taxonomy FROM ' . $wpdb->term_taxonomy . ' WHERE term_id = ' . $termid;
31
+ $tax = $wpdb->get_var($tax_sql);
32
+ DebugEcho("lookup_taxonomy: $termid is in taxonomy $tax");
33
+ return $tax;
34
+ }
35
+
36
+ function postie_lookup_category_id($trial_category, $category_match = true) {
37
+ global $wpdb;
38
+ DebugEcho("lookup_category: $trial_category");
39
+
40
+ $term = get_term_by('name', esc_attr($trial_category), 'category');
41
+ if (!empty($term)) {
42
+ DebugEcho("lookup_category: found by name $trial_category");
43
+ //DebugDump($term);
44
+ //then category is a named and found
45
+ return $term->term_id;
46
+ } else {
47
+ DebugEcho("lookup_category: not found by name $trial_category");
48
+ }
49
+
50
+ $term = get_term_by('slug', esc_attr($trial_category), 'category');
51
+ if (!empty($term)) {
52
+ DebugEcho("lookup_category: found by slug $trial_category");
53
+ return $term->term_id;
54
+ } else {
55
+ DebugEcho("lookup_category: not found by slug $trial_category");
56
+ }
57
+
58
+ if (is_numeric($trial_category)) {
59
+ DebugEcho("lookup_category: looking for id '$trial_category'");
60
+ $cat_id = intval($trial_category);
61
+ $term = get_term_by('id', $cat_id, 'category');
62
+ if (!empty($term) && $term->term_id == $trial_category) {
63
+ DebugEcho("lookup_category: found by id '$cat_id'");
64
+ DebugDump($term);
65
+ //then category was an ID and found
66
+ return $term->term_id;
67
+ } else {
68
+ DebugEcho("lookup_category: not found by id '$cat_id'");
69
+ }
70
+ }
71
+
72
+ $found_category = NULL;
73
+ if ($category_match) {
74
+ DebugEcho("category wildcard lookup: $trial_category");
75
+ $sql_sub_name = 'SELECT term_id FROM ' . $wpdb->terms . ' WHERE name LIKE \'' . addslashes(esc_attr($trial_category)) . '%\' OR slug LIKE \'' . addslashes(esc_attr($trial_category)) . '%\' limit 1';
76
+ $found_category = $wpdb->get_var($sql_sub_name);
77
+ DebugEcho("lookup_category: wildcard found: $found_category");
78
+ } else {
79
+ DebugEcho("lookup_category: wildcard not found: $found_category");
80
+ }
81
+
82
+ return intval($found_category); //force to integer
83
+ }
84
+
85
+ /**
86
+ * Checks for the comments tag
87
+ * @return boolean
88
+ */
89
+ function tag_AllowCommentsOnPost(&$content) {
90
+ $comments_allowed = get_option('default_comment_status'); // 'open' or 'closed'
91
+
92
+ foreach (postie_content_lines($content) as $line) {
93
+ $matches = array();
94
+ if (preg_match("/^comments:([0|1|2])/iu", $line, $matches)) {
95
+ $content = preg_replace("/comments:$matches[1]/i", "", $content);
96
+ if ($matches[1] == '1') {
97
+ $comments_allowed = 'open';
98
+ } else if ($matches[1] == '2') {
99
+ $comments_allowed = 'registered_only';
100
+ } else {
101
+ $comments_allowed = 'closed';
102
+ }
103
+ break;
104
+ }
105
+ }
106
+ return $comments_allowed;
107
+ }
108
+
109
+ function tag_Status(&$content, $currentstatus) {
110
+ $poststatus = $currentstatus;
111
+
112
+ foreach (postie_content_lines($content) as $lines) {
113
+ $matches = array();
114
+ if (preg_match("/^status:\s*(draft|publish|pending|private|future)/iu", $lines, $matches)) {
115
+ DebugEcho("tag_Status: found status $matches[1]");
116
+ DebugDump($matches);
117
+ $content = preg_replace("/$matches[0]/i", "", $content);
118
+ $poststatus = $matches[1];
119
+ break;
120
+ }
121
+ }
122
+ return $poststatus;
123
+ }
124
+
125
+ function tag_Delay(&$content, $message_date, $config) {
126
+ $offset = (!$config['ignore_email_date'] && $config['use_time_offset']) ? $config['time_offset'] : 0;
127
+
128
+ DebugEcho("tag_Delay: start");
129
+ $delay = 0;
130
+
131
+ foreach (postie_content_lines($content) as $line) {
132
+ $matches = array();
133
+ if (preg_match("/^delay:(-?[0-9dhm]+)/iu", $line, $matches) && trim($matches[1])) {
134
+ DebugEcho("tag_Delay: found delay: " . $matches[1]);
135
+ $days = 0;
136
+ $hours = 0;
137
+ $minutes = 0;
138
+ $dayMatches = array();
139
+ if (preg_match("/(-?[0-9]+)d/iu", $matches[1], $dayMatches)) {
140
+ $days = $dayMatches[1];
141
+ }
142
+ $hourMatches = array();
143
+ if (preg_match("/(-?[0-9]+)h/iu", $matches[1], $hourMatches)) {
144
+ $hours = $hourMatches[1];
145
+ }
146
+ $minuteMatches = array();
147
+ if (preg_match("/(-?[0-9]+)m/iu", $matches[1], $minuteMatches)) {
148
+ $minutes = $minuteMatches[1];
149
+ }
150
+ $delay = (($days * 24 + $hours) * 60 + $minutes) * 60;
151
+ $interval = 'P';
152
+ if (abs($days) > 0) {
153
+ $interval .= abs($days) . 'D';
154
+ }
155
+ if (abs($hours) > 0) {
156
+ $interval .= 'T' . abs($hours) . 'H';
157
+ }
158
+ if (abs($minutes) > 0) {
159
+ if (abs($hours) > 0) {
160
+ $interval .= abs($minutes) . 'M';
161
+ } else {
162
+ $interval .= 'T' . abs($minutes) . 'M';
163
+ }
164
+ }
165
+
166
+ DebugEcho("tag_Delay: calculated delay: $delay");
167
+ DebugEcho("tag_Delay: interval: $interval");
168
+ $content = preg_replace("/delay:$matches[1]/i", "", $content);
169
+ break;
170
+ }
171
+ }
172
+
173
+ $tzs = get_option('timezone_string');
174
+ if (empty($tzs)) {
175
+ $tzs = 'GMT';
176
+ }
177
+ DebugEcho("tag_Delay: timezone: $tzs");
178
+
179
+ if ($config['ignore_email_date']) {
180
+ $dateInSeconds = new DateTime(current_time('mysql'), new DateTimeZone($tzs));
181
+ DebugEcho("tag_Delay: ignoring date: " . $dateInSeconds->format(DATE_RFC2822));
182
+ } else {
183
+ if (empty($message_date)) {
184
+ $dateInSeconds = new DateTime(current_time('mysql'), new DateTimeZone($tzs));
185
+ DebugEcho("tag_Delay: using current date: " . $dateInSeconds->format(DATE_RFC2822));
186
+ } else {
187
+ DebugEcho("tag_Delay: using message date(1): $message_date");
188
+ $dateInSeconds = new DateTime($message_date, new DateTimeZone($tzs));
189
+ DebugEcho("tag_Delay: using message date(2): " . $dateInSeconds->format(DATE_RFC2822));
190
+ }
191
+ }
192
+
193
+ if ($delay > 0) {
194
+ $delayeddateInSeconds = $dateInSeconds->add(new DateInterval($interval));
195
+ }
196
+ if ($delay < 0) {
197
+ $delayeddateInSeconds = $dateInSeconds->sub(new DateInterval($interval));
198
+ }
199
+ if ($delay == 0) {
200
+ $delayeddateInSeconds = clone $dateInSeconds;
201
+ }
202
+ //$delayeddateInSeconds->setTimezone(new DateTimeZone($tzs));
203
+
204
+ if ($offset > 0) {
205
+ $corrected_date = $delayeddateInSeconds->add(new DateInterval('PT' . $offset . 'H'));
206
+ }
207
+ if ($offset < 0) {
208
+ $corrected_date = $delayeddateInSeconds->sub(new DateInterval('PT' . abs($offset) . 'H'));
209
+ }
210
+ if ($offset == 0) {
211
+ $corrected_date = clone $delayeddateInSeconds;
212
+ }
213
+ $corrected_date->setTimezone(new DateTimeZone($tzs));
214
+
215
+ DebugEcho("tag_Delay: message date: " . $dateInSeconds->format(DATE_RFC2822));
216
+ DebugEcho("tag_Delay: delay: $delay");
217
+ DebugEcho("tag_Delay: offset: $offset");
218
+ DebugEcho("tag_Delay: delayed date: " . $delayeddateInSeconds->format(DATE_RFC2822));
219
+ DebugEcho("tag_Delay: delayed with offset: " . $corrected_date->format(DATE_RFC2822));
220
+
221
+ return array($corrected_date->format(DATE_W3C), $delay);
222
+ }
223
+
224
+ /**
225
+ * This function takes the content of the message - looks for a subject at the beginning surrounded by # and then removes that from the content
226
+ */
227
+ function tag_Subject($content, $defaultTitle) {
228
+ DebugEcho("tag_Subject: Looking for subject in email body");
229
+ if (substr($content, 0, 1) != "#") {
230
+ DebugEcho("tag_Subject: No inline subject found, using supplied default [1] '$defaultTitle'");
231
+ return(array($defaultTitle, $content));
232
+ }
233
+ //make sure the first line isn't #img
234
+ if (strtolower(substr($content, 1, 3)) != "img") {
235
+ $subjectEndIndex = strpos($content, "#", 1);
236
+ if (!$subjectEndIndex > 0) {
237
+ DebugEcho("tag_Subject: No subject found, using default [2]");
238
+ return(array($defaultTitle, $content));
239
+ }
240
+ $subject = substr($content, 1, $subjectEndIndex - 1);
241
+ $content = substr($content, $subjectEndIndex + 1, strlen($content));
242
+ DebugEcho("tag_Subject: Subject found in body: $subject");
243
+ return array($subject, $content);
244
+ } else {
245
+ return(array($defaultTitle, $content));
246
+ }
247
+ }
248
+
249
+ function tag_Excerpt(&$content, $config) {
250
+ $post_excerpt = '';
251
+ $matches = array();
252
+ if (preg_match('/:excerptstart ?(.*):excerptend/is', $content, $matches)) {
253
+ $content = str_replace($matches[0], "", $content);
254
+ $post_excerpt = $matches[1];
255
+ DebugEcho("excerpt found: $post_excerpt");
256
+ if ($config['filternewlines']) {
257
+ DebugEcho("filtering newlines from excerpt");
258
+ $post_excerpt = filter_Newlines($post_excerpt, $config);
259
+ }
260
+ }
261
+ return $post_excerpt;
262
+ }
263
+
264
+ /**
265
+ * This function determines the categories ids for the post
266
+ * @return array
267
+ */
268
+ function tag_Categories(&$subject, $defaultCategoryId, $config, $post_id) {
269
+ DebugEcho("tag_Categories: start");
270
+ $category_match = $config['category_match'];
271
+ $original_subject = $subject;
272
+ $found = false;
273
+ $post_categories = array();
274
+ $matchtypes = array();
275
+ $matches = array();
276
+
277
+ if ($config['category_bracket']) {
278
+ if (preg_match_all('/\[(.[^\[]*)\]/', $subject, $matches)) { // [<category1>] [<category2>] <Subject>
279
+ $matchtypes[] = $matches;
280
+ }
281
+ }
282
+
283
+ if ($config['category_dash']) {
284
+ if (preg_match_all('/-(.[^-]*)-/', $subject, $matches)) { // -<category>- -<category2>- <Subject>
285
+ $matchtypes[] = $matches;
286
+ }
287
+ }
288
+
289
+ if ($config['category_colon']) {
290
+ if (preg_match('/(.+):\s?(.*)/', $subject, $matches)) { // <category>: <Subject>
291
+ $matchtypes[] = array(array(0 => $matches[1] . ':'), array(1 => $matches[1]));
292
+ }
293
+ }
294
+
295
+ DebugEcho("tag_Categories: found categories");
296
+ DebugDump($matchtypes);
297
+ foreach ($matchtypes as $matches) {
298
+ if (count($matches)) {
299
+ $i = 0;
300
+ foreach ($matches[1] as $match) {
301
+ DebugEcho("tag_Categories: checking: $match");
302
+
303
+ DebugEcho("tag_Categories: looking up: $defaultCategoryId");
304
+ $defaultcat_name = '';
305
+ $defaultcat = get_term_by('id', $defaultCategoryId, postie_lookup_taxonomy_name($defaultCategoryId));
306
+ if (false !== $defaultcat) {
307
+ $defaultcat_name = $defaultcat->name;
308
+ DebugEcho("tag_Categories: default: $defaultcat_name");
309
+ } else {
310
+ DebugEcho("tag_Categories: default not found");
311
+ }
312
+ $trial_category = apply_filters('postie_category', trim($match), $category_match, $defaultcat_name);
313
+ DebugEcho("tag_Categories: post postie_category: $trial_category");
314
+
315
+ $categoryid = postie_lookup_category_id($trial_category, $category_match);
316
+ if (!empty($categoryid)) {
317
+ $found = true;
318
+ $subject = str_replace($matches[0][$i], '', $subject);
319
+ DebugEcho("tag_Categories: subject: $subject");
320
+ $tax = postie_lookup_taxonomy_name($categoryid);
321
+ if ('category' == $tax) {
322
+ DebugEcho("tag_Categories: standard taxonomy $tax");
323
+ $post_categories[] = $categoryid;
324
+ } else {
325
+ DebugEcho("tag_Categories: custom taxonomy $tax");
326
+ wp_set_object_terms($post_id, $categoryid, $tax, true);
327
+ }
328
+ }
329
+ $i++;
330
+ }
331
+ }
332
+ }
333
+ if (!$found || !$config['category_remove']) {
334
+ DebugEcho("tag_Categories: using default: $defaultCategoryId");
335
+ $post_categories[] = $defaultCategoryId;
336
+ $subject = $original_subject;
337
+ }
338
+ $subject = trim($subject);
339
+ return $post_categories;
340
+ }
341
+
342
+ function tag_CustomImageField($post_ID, $email, $config) {
343
+ if ($config['custom_image_field']) {
344
+ DebugEcho("Saving custom image post_meta");
345
+
346
+ foreach (array_merge($email['attachment'], $email['inline'], $email['related']) as $attachment) {
347
+ add_post_meta($post_ID, 'image', $attachment['wp_filename']);
348
+ DebugEcho("Saving custom attachment '{$attachment['wp_filename']}'");
349
+ }
350
+ }
351
+ }
352
+
353
+ /*
354
+ * Added by Raam Dev <raam@raamdev.com>
355
+ * Adds support for handling Custom Post Types by adding the
356
+ * Custom Post Type name to the email subject separated by
357
+ * $custom_post_type_delim, e.g. "Movies // My Favorite Movie"
358
+ * Also supports setting the Post Format.
359
+ */
360
+
361
+ function tag_PostType(&$subject, $config) {
362
+
363
+ $post_type = $config['post_type'];
364
+ $custom_post_type = $config['post_format'];
365
+ $separated_subject = array();
366
+ $separated_subject[0] = "";
367
+ $separated_subject[1] = $subject;
368
+
369
+ $custom_post_type_delim = "//";
370
+ if (strpos($subject, $custom_post_type_delim) !== FALSE) {
371
+ // Captures the custom post type in the subject before $custom_post_type_delim
372
+ $separated_subject = explode($custom_post_type_delim, $subject);
373
+ $custom_post_type = trim(strtolower($separated_subject[0]));
374
+ DebugEcho("post type: found possible type '$custom_post_type'");
375
+ }
376
+
377
+ $known_post_types = get_post_types();
378
+
379
+ if (in_array($custom_post_type, array_map('strtolower', $known_post_types))) {
380
+ DebugEcho("post type: found type '$post_type'");
381
+ $post_type = $custom_post_type;
382
+ $subject = trim($separated_subject[1]);
383
+ } elseif (in_array($custom_post_type, array_keys(get_post_format_strings()))) {
384
+ DebugEcho("post type: found format '$custom_post_type'");
385
+ $subject = trim($separated_subject[1]);
386
+ }
387
+
388
+ return $post_type;
389
+ }
390
+
391
+ function tag_Date(&$content, $message_date) {
392
+ DebugEcho("tag_Date: starting");
393
+
394
+ foreach (postie_content_lines($content) as $e) {
395
+ //DebugEcho("tag_Date: " . $e);
396
+ $matches = array();
397
+ if (1 === preg_match("/^date:\s?(.*)$/imu", $e, $matches)) {
398
+ $possibledate = trim($matches[1]);
399
+ DebugEcho("tag_Date: found date tag $matches[1]");
400
+ $newdate = strtotime($possibledate);
401
+ if (false !== $newdate) {
402
+ $t = date("H:i:s", $newdate);
403
+ DebugEcho("tag_Date: original time: $t");
404
+
405
+ $format = "Y-m-d";
406
+ if ($t != '00:00:00') {
407
+ $format .= " H:i:s";
408
+ }
409
+ $message_date = date($format, $newdate);
410
+ $content = str_replace($matches[0], '', $content);
411
+ break;
412
+ } else {
413
+ DebugEcho("tag_Date: failed to parse '$possibledate' ($newdate)");
414
+ }
415
+ } else {
416
+ //DebugEcho("tag_Date: nothing found");
417
+ }
418
+ }
419
+
420
+ return $message_date;
421
+ }
422
+
423
+ function tag_Tags(&$content, $defaultTags) {
424
+ $post_tags = array();
425
+ foreach (postie_content_lines($content) as $lines) {
426
+ $matches = array();
427
+ if (preg_match('/^tags:\s?(.*)/iu', $lines, $matches)) {
428
+ if (!empty($matches[1])) {
429
+ DebugEcho("Found tags: $matches[1]");
430
+ $content = str_replace($matches[0], "", $content);
431
+ $post_tags = array_merge($post_tags, preg_split("/,\s*/", trim($matches[1])));
432
+ }
433
+ }
434
+ }
435
+
436
+ if (count($post_tags) == 0 && is_array($defaultTags)) {
437
+ $post_tags = $defaultTags;
438
+ }
439
+ return $post_tags;
440
+ }
postie.class.php ADDED
@@ -0,0 +1,1736 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fException.php");
3
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fUnexpectedException.php");
4
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fExpectedException.php");
5
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fConnectivityException.php");
6
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fValidationException.php");
7
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fProgrammerException.php");
8
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fEnvironmentException.php");
9
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fCore.php");
10
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fMailbox.php");
11
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fEmail.php");
12
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/pConnection.php");
13
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/pCurlConnection.php");
14
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/pSocketConnection.php");
15
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/pMailServer.php");
16
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/pImapMailServer.php");
17
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/pPop3MailServer.php");
18
+
19
+ require_once(ABSPATH . 'wp-admin/includes/file.php');
20
+ require_once(ABSPATH . 'wp-admin/includes/image.php');
21
+ require_once(ABSPATH . 'wp-admin/includes/media.php');
22
+ require_once(ABSPATH . 'wp-admin/includes/file.php'); //wp_tempnam()
23
+
24
+ require_once( ABSPATH . WPINC . '/class-oembed.php' );
25
+
26
+ if (!function_exists('file_get_html')) {
27
+ require_once (plugin_dir_path(__FILE__) . 'lib/simple_html_dom.php');
28
+ }
29
+
30
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "postie-filters.php");
31
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "postie-tags.php");
32
+
33
+ class Postie {
34
+
35
+ function get_mail() {
36
+ $config = postie_config_read();
37
+ if (true == $config['postie_log_error'] || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
38
+ add_action('postie_log_error', array($this, 'log_error'));
39
+ }
40
+ if (true == $config['postie_log_debug'] && !defined('POSTIE_DEBUG')) {
41
+ define('POSTIE_DEBUG', true);
42
+ }
43
+ if (true == $config['postie_log_debug'] || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
44
+ add_action('postie_log_debug', array($this, 'log_debug'));
45
+ }
46
+
47
+ DebugEcho('Starting mail fetch');
48
+ DebugEcho('WordPress datetime: ' . current_time('mysql'));
49
+
50
+ DebugEcho("doing postie_session_start");
51
+ do_action('postie_session_start');
52
+
53
+ $this->postie_environment();
54
+
55
+ $wp_content_path = dirname(dirname(dirname(__FILE__)));
56
+ DebugEcho("wp_content_path: $wp_content_path");
57
+ if (file_exists($wp_content_path . DIRECTORY_SEPARATOR . 'filterPostie.php')) {
58
+ DebugEcho("found filterPostie.php in $wp_content_path");
59
+ include_once ($wp_content_path . DIRECTORY_SEPARATOR . 'filterPostie.php');
60
+ }
61
+
62
+ if (function_exists('memory_get_usage')) {
63
+ DebugEcho(__("memory at start of email processing: ", 'postie') . memory_get_usage());
64
+ }
65
+
66
+ if (has_filter('postie_post')) {
67
+ echo "Postie: filter 'postie_post' is depricated in favor of 'postie_post_before'";
68
+ }
69
+
70
+ if (!array_key_exists('maxemails', $config)) {
71
+ $config['maxemails'] = 0;
72
+ }
73
+
74
+ $conninfo = $this->connection_info($config);
75
+
76
+ $emails = $this->fetch_mail($conninfo['mail_server'], $conninfo['mail_port'], $conninfo['mail_user'], $conninfo['mail_password'], $conninfo['mail_protocol'], $conninfo['email_delete_after_processing'], $conninfo['email_max'], $config['input_connection']);
77
+
78
+ $message = 'Done.';
79
+
80
+ DebugEcho(sprintf(__("There are %d messages to process", 'postie'), count($emails)));
81
+
82
+ //don't output the password
83
+ $tmp_config = $config;
84
+ unset($tmp_config['mail_password']);
85
+ DebugDump($tmp_config);
86
+
87
+ //loop through messages
88
+ $message_number = 0;
89
+ foreach ($emails as $email) {
90
+ $message_number++;
91
+ DebugEcho("$message_number: ------------------------------------");
92
+ //DebugDump($email);
93
+ //sanity check to see if there is any info in the message
94
+ if ($email == NULL) {
95
+ $message = __('Dang, message is empty!', 'postie');
96
+ EchoError("$message_number: $message");
97
+ continue;
98
+ } else if ($email == 'already read') {
99
+ $message = __("Message is already marked 'read'.", 'postie');
100
+ DebugEcho("$message_number: $message");
101
+ continue;
102
+ }
103
+
104
+ $tmp_config = $config;
105
+ if ($config['prefer_text_convert']) {
106
+ if ($config['prefer_text_type'] == 'plain' && trim($email['text']) == '' && trim($email['html']) != '') {
107
+ DebugEcho('get_mail: switching to html');
108
+ $tmp_config['prefer_text_type'] = 'html';
109
+ }
110
+ if ($config['prefer_text_type'] == 'html' && trim($email['html']) == '' && trim($email['text']) != '') {
111
+ DebugEcho('get_mail: switching to plain');
112
+ $tmp_config['prefer_text_type'] = 'plain';
113
+ }
114
+ }
115
+
116
+ //Check poster to see if a valid person
117
+ $poster = $this->validate_poster($email, $tmp_config);
118
+ if (!empty($poster)) {
119
+ $this->post_email($poster, $email, $tmp_config);
120
+ DebugEcho("$message_number: processed");
121
+ } else {
122
+ EchoError('Ignoring email - not authorized.');
123
+ }
124
+ flush();
125
+ }
126
+ DebugEcho("Mail fetch complete, $message_number emails");
127
+ DebugEcho("doing postie_session_end");
128
+ do_action('postie_session_end');
129
+
130
+ if (function_exists('memory_get_usage')) {
131
+ DebugEcho('memory at end of email processing: ' . memory_get_usage());
132
+ }
133
+ }
134
+
135
+ function save_attachments(&$email, $post_id, $config) {
136
+ DebugEcho('save_attachments: ---- start');
137
+
138
+ if (!isset($email['attachment'])) {
139
+ $email['attachment'] = array();
140
+ }
141
+ if (!isset($email['inline'])) {
142
+ $email['inline'] = array();
143
+ }
144
+ if (!isset($email['related'])) {
145
+ $email['related'] = array();
146
+ }
147
+
148
+ DebugEcho("save_attachments: [attachment]");
149
+ $this->save_attachments_worker($email['attachment'], $post_id, $config);
150
+ DebugEcho("save_attachments: [inline]");
151
+ $this->save_attachments_worker($email['inline'], $post_id, $config);
152
+ DebugEcho("save_attachments: [related]");
153
+ $this->save_attachments_worker($email['related'], $post_id, $config);
154
+
155
+
156
+ DebugEcho("save_attachments: ==== end");
157
+ }
158
+
159
+ /**
160
+ * This function determines if the mime attachment is on the BANNED_FILE_LIST
161
+ * @param string
162
+ * @return boolean
163
+ */
164
+ function is_banned_filename($filename, $bannedFiles) {
165
+ if (preg_match('/ATT\d\d\d\d\d.txt/i', $filename)) {
166
+ return true;
167
+ }
168
+
169
+ if (empty($filename) || empty($bannedFiles)) {
170
+ return false;
171
+ }
172
+ foreach ($bannedFiles as $bannedFile) {
173
+ if (fnmatch($bannedFile, $filename)) {
174
+ EchoError("Ignoring attachment: $filename - it is on the banned files list.");
175
+ $this->notify_error("Ignoring attachment: $filename - it is on the banned files list.", "Ignoring attachment: $filename - it is on the banned files list.");
176
+ return true;
177
+ }
178
+ }
179
+ return false;
180
+ }
181
+
182
+ function save_attachments_worker(&$attachments, $post_id, $config) {
183
+ foreach ($attachments as &$attachment) {
184
+ if (array_key_exists('filename', $attachment) && !empty($attachment['filename'])) {
185
+ DebugEcho('save_attachments_worker: ' . $attachment['filename']);
186
+
187
+ if ($this->is_banned_filename($attachment['filename'], $config['banned_files_list'])) {
188
+ DebugEcho("save_attachments_worker: skipping banned filename " . $attachment['filename']);
189
+ break;
190
+ }
191
+ } else {
192
+ DebugEcho('save_attachments_worker: un-named attachment');
193
+ }
194
+
195
+ $this->save_attachment($attachment, $post_id, $config);
196
+
197
+ $filename = $attachment['wp_filename'];
198
+ $fileext = $attachment['ext'];
199
+ $mparts = explode('/', $attachment['mimetype']);
200
+ $mimetype_primary = $mparts[0];
201
+ $mimetype_secondary = $mparts[1];
202
+ DebugEcho("save_attachments_worker: mime primary: $mimetype_primary");
203
+
204
+ $attachment['primary'] = $mimetype_primary;
205
+ $attachment['exclude'] = false;
206
+
207
+ $file_id = $attachment['wp_id'];
208
+ $file = wp_get_attachment_url($file_id);
209
+
210
+ switch ($mimetype_primary) {
211
+ case 'text':
212
+ DebugEcho("save_attachments_worker: text attachment");
213
+ $icon = $this->choose_attachment_icon($file, $mimetype_primary, $mimetype_secondary, $config['icon_set'], $config['icon_size']);
214
+ $attachment['template'] = "<a href='$file'>" . $icon . $filename . '</a>' . "\n";
215
+ break;
216
+
217
+ case 'image':
218
+ DebugEcho("save_attachments_worker: image attachment");
219
+ $attachment['template'] = $this->parse_template($file_id, $mimetype_primary, $config['imagetemplate'], $filename) . "\n";
220
+ break;
221
+
222
+ case 'audio':
223
+ DebugEcho("save_attachments_worker: audio attachment");
224
+ if (in_array($fileext, $config['audiotypes'])) {
225
+ DebugEcho("save_attachments_worker: using audio template: $mimetype_secondary");
226
+ $audioTemplate = $config['audiotemplate'];
227
+ } else {
228
+ DebugEcho("save_attachments_worker: using default audio template: $mimetype_secondary");
229
+ $icon = $this->choose_attachment_icon($file, $mimetype_primary, $mimetype_secondary, $config['icon_set'], $config['icon_size']);
230
+ $audioTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>';
231
+ }
232
+ $attachment['template'] = $this->parse_template($file_id, $mimetype_primary, $audioTemplate, $filename);
233
+ break;
234
+
235
+ case 'video':
236
+ DebugEcho("save_attachments_worker: video attachment");
237
+ if (in_array($fileext, $config['video1types'])) {
238
+ DebugEcho("save_attachments_worker: using video1 template: $fileext");
239
+ $videoTemplate = $config['video1template'];
240
+ } elseif (in_array($fileext, $config['video2types'])) {
241
+ DebugEcho("save_attachments_worker: using video2 template: $fileext");
242
+ $videoTemplate = $config['video2template'];
243
+ } else {
244
+ DebugEcho("save_attachments_worker: using default template: $fileext");
245
+ $icon = $this->choose_attachment_icon($file, $mimetype_primary, $mimetype_secondary, $config['icon_set'], $config['icon_size']);
246
+ $videoTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>';
247
+ }
248
+ $attachment['template'] = $this->parse_template($file_id, $mimetype_primary, $videoTemplate, $filename);
249
+ break;
250
+
251
+ default :
252
+ DebugEcho("save_attachments_worker: generic attachment ($mimetype_primary)");
253
+ $icon = $this->choose_attachment_icon($file, $mimetype_primary, $mimetype_secondary, $config['icon_set'], $config['icon_size']);
254
+ $attachment['template'] = $this->parse_template($file_id, $mimetype_primary, $config['generaltemplate'], $filename, $icon) . "\n";
255
+ break;
256
+ }
257
+ }
258
+ }
259
+
260
+ function parse_template($fileid, $type, $template, $orig_filename, $icon = "") {
261
+ DebugEcho("parseTemplate: before '$template'");
262
+
263
+ $attachment = get_post($fileid);
264
+ $uploadDir = wp_upload_dir();
265
+ $fileName = basename($attachment->guid);
266
+ $fileType = pathinfo($fileName, PATHINFO_EXTENSION);
267
+ $absFileName = $uploadDir['path'] . '/' . $fileName;
268
+ $relFileName = str_replace(ABSPATH, '', $absFileName);
269
+ $fileLink = wp_get_attachment_url($fileid);
270
+ $pageLink = get_attachment_link($fileid);
271
+
272
+ $template = str_replace('{TITLE}', $attachment->post_title, $template);
273
+ $template = str_replace('{ID}', $fileid, $template);
274
+
275
+ if ($type == 'image') {
276
+ $widths = array();
277
+ $heights = array();
278
+ $img_urls = array();
279
+
280
+ $this->show_filters_for('image_downsize'); //possible overrides for image_downsize()
281
+
282
+ /*
283
+ * Possible enhancement: support all sizes returned by get_intermediate_image_sizes()
284
+ */
285
+ $sizes = array('thumbnail', 'medium', 'large');
286
+ for ($i = 0; $i < count($sizes); $i++) {
287
+ $iinfo = image_downsize($fileid, $sizes[$i]);
288
+ if (false !== $iinfo) {
289
+ $img_urls[$i] = $iinfo[0];
290
+ $widths[$i] = $iinfo[1];
291
+ $heights[$i] = $iinfo[2];
292
+ }
293
+ }
294
+ DebugEcho('parseTemplate: Sources');
295
+ DebugDump($img_urls);
296
+ DebugEcho('parseTemplate: Heights');
297
+ DebugDump($heights);
298
+ DebugEcho('parseTemplate: Widths');
299
+ DebugDump($widths);
300
+
301
+ $template = str_replace('{THUMBNAIL}', $img_urls[0], $template);
302
+ $template = str_replace('{THUMB}', $img_urls[0], $template);
303
+ $template = str_replace('{MEDIUM}', $img_urls[1], $template);
304
+ $template = str_replace('{LARGE}', $img_urls[2], $template);
305
+ $template = str_replace('{THUMBWIDTH}', $widths[0] . 'px', $template);
306
+ $template = str_replace('{THUMBHEIGHT}', $heights[0] . 'px', $template);
307
+ $template = str_replace('{MEDIUMWIDTH}', $widths[1] . 'px', $template);
308
+ $template = str_replace('{MEDIUMHEIGHT}', $heights[1] . 'px', $template);
309
+ $template = str_replace('{LARGEWIDTH}', $widths[2] . 'px', $template);
310
+ $template = str_replace('{LARGEHEIGHT}', $heights[2] . 'px', $template);
311
+ }
312
+
313
+ $template = str_replace('{FULL}', $fileLink, $template);
314
+ $template = str_replace('{FILELINK}', $fileLink, $template);
315
+ $template = str_replace('{FILETYPE}', $fileType, $template);
316
+ $template = str_replace('{PAGELINK}', $pageLink, $template);
317
+ $template = str_replace('{FILENAME}', $orig_filename, $template);
318
+ $template = str_replace('{IMAGE}', $fileLink, $template);
319
+ $template = str_replace('{URL}', $fileLink, $template);
320
+ $template = str_replace('{RELFILENAME}', $relFileName, $template);
321
+ $template = str_replace('{ICON}', $icon, $template);
322
+ $template = str_replace('{FILEID}', $fileid, $template);
323
+
324
+ DebugEcho("parseTemplate: after: '$template<br />'");
325
+ return $template . '<br />';
326
+ }
327
+
328
+ function show_filters_for($hook = '') {
329
+ global $wp_filter;
330
+ if (empty($hook) || !isset($wp_filter[$hook])) {
331
+ DebugEcho("No registered filters for $hook");
332
+ return;
333
+ }
334
+ DebugEcho("Registered filters for $hook");
335
+ DebugDump($wp_filter[$hook]);
336
+ }
337
+
338
+ function save_attachment(&$attachment, $post_id, $config) {
339
+
340
+ if (isset($attachment['filename']) && !empty($attachment['filename'])) {
341
+ $filename = $attachment['filename'];
342
+ } else {
343
+ DebugEcho("save_attachment: generating file name");
344
+ $filename = uniqid();
345
+ $attachment['filename'] = $filename;
346
+ }
347
+
348
+ DebugEcho("save_attachment: pre sanitize file name '$filename'");
349
+ //DebugDump($part);
350
+ $filename = sanitize_file_name($filename);
351
+ $attachment['wp_filename'] = $filename;
352
+
353
+ DebugEcho("save_attachment: file name '$filename'");
354
+
355
+ $mparts = explode('/', $attachment['mimetype']);
356
+ $mimetype_primary = $mparts[0];
357
+ $mimetype_secondary = $mparts[1];
358
+
359
+ $fileext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
360
+ $attachment['ext'] = $fileext;
361
+ if (empty($fileext) && $mimetype_primary == 'image') {
362
+ $attachment['ext'] = $mimetype_secondary;
363
+ $filename = $filename . '.' . $mimetype_secondary;
364
+ $attachment['wp_filename'] = $filename;
365
+ DebugEcho("save_attachment: blank image extension, changed to $mimetype_secondary ($filename)");
366
+ }
367
+ DebugEcho("save_attachment: extension '$fileext'");
368
+
369
+ $typeinfo = wp_check_filetype($filename);
370
+ //DebugDump($typeinfo);
371
+ if (!empty($typeinfo['type'])) {
372
+ DebugEcho("save_attachment: secondary lookup found " . $typeinfo['type']);
373
+ $mimeparts = explode('/', strtolower($typeinfo['type']));
374
+ $mimetype_primary = $mimeparts[0];
375
+ $mimetype_secondary = $mimeparts[1];
376
+ } else {
377
+ DebugEcho("save_attachment: secondary lookup failed, checking configured extensions");
378
+ if (in_array($fileext, $config['audiotypes'])) {
379
+ DebugEcho("save_attachment: found audio extension");
380
+ $mimetype_primary = 'audio';
381
+ $mimetype_secondary = $fileext;
382
+ } elseif (in_array($fileext, array_merge($config['video1types'], $config['video2types']))) {
383
+ DebugEcho("save_attachment: found video extension");
384
+ $mimetype_primary = 'video';
385
+ $mimetype_secondary = $fileext;
386
+ } else {
387
+ DebugEcho("save_attachment: found no extension");
388
+ }
389
+ }
390
+ $attachment['mimetype'] = "$mimetype_primary/$mimetype_secondary";
391
+ DebugEcho("save_attachment: mimetype $mimetype_primary/$mimetype_secondary");
392
+
393
+ switch ($mimetype_primary) {
394
+ case 'text':
395
+ DebugEcho("save_attachment: ctype_primary: text");
396
+ //DebugDump($part);
397
+
398
+ DebugEcho("save_attachment: text Attachement: $filename");
399
+ $file_id = $this->media_handle_upload($attachment, $post_id);
400
+ if (!is_wp_error($file_id)) {
401
+ $attachment['wp_id'] = $file_id;
402
+ DebugEcho("save_attachment: text attachment: adding '$filename'");
403
+ } else {
404
+ EchoError($file_id->get_error_message());
405
+ $this->notify_error("Failed to add text media file: $filename", $file_id->get_error_message());
406
+ }
407
+
408
+ break;
409
+
410
+ case 'image':
411
+ DebugEcho("save_attachment: image Attachement: $filename");
412
+ $file_id = $this->media_handle_upload($attachment, $post_id);
413
+ if (!is_wp_error($file_id)) {
414
+ $attachment['wp_id'] = $file_id;
415
+ //set the first image we come across as the featured image
416
+ if ($config['featured_image'] && !has_post_thumbnail($post_id)) {
417
+ DebugEcho("save_attachment: featured image: $file_id");
418
+ set_post_thumbnail($post_id, $file_id);
419
+ }
420
+ } else {
421
+ EchoError("save_attachment image error: " . $file_id->get_error_message());
422
+ $this->notify_error("Failed to add image media file: $filename", $file_id->get_error_message());
423
+ }
424
+ break;
425
+
426
+ case 'audio':
427
+ DebugEcho("save_attachment: audio Attachement: $filename");
428
+ $file_id = $this->media_handle_upload($attachment, $post_id);
429
+ if (!is_wp_error($file_id)) {
430
+ $attachment['wp_id'] = $file_id;
431
+ } else {
432
+ EchoError("save_attachment audio error: " . $file_id->get_error_message());
433
+ $this->notify_error("Failed to add audio media file: $filename", $file_id->get_error_message());
434
+ }
435
+ break;
436
+
437
+ case 'video':
438
+ DebugEcho("save_attachment: video Attachement: $filename");
439
+ $file_id = $this->media_handle_upload($attachment, $post_id);
440
+ if (!is_wp_error($file_id)) {
441
+ $attachment['wp_id'] = $file_id;
442
+ } else {
443
+ EchoError("save_attachment video error: " . $file_id->get_error_message());
444
+ $this->notify_error("Failed to add video file: $filename", $file_id->get_error_message());
445
+ }
446
+ break;
447
+
448
+ default:
449
+ DebugEcho("save_attachment: found file type: " . $mimetype_primary);
450
+ if (in_array($mimetype_primary, $config['supported_file_types'])) {
451
+ //pgp signature - then forget it
452
+ if ($mimetype_secondary == 'pgp-signature') {
453
+ DebugEcho("save_attachment: found pgp-signature - done");
454
+ break;
455
+ }
456
+ $file_id = $this->media_handle_upload($attachment, $post_id);
457
+ if (!is_wp_error($file_id)) {
458
+ $attachment['wp_id'] = $file_id;
459
+ $file = wp_get_attachment_url($file_id);
460
+ DebugEcho("save_attachment: uploaded $file_id ($file)");
461
+ } else {
462
+ EchoError("save_attachment file error: " . $file_id->get_error_message());
463
+ $this->notify_error("Failed to add media file: $filename", $file_id->get_error_message());
464
+ }
465
+ } else {
466
+ EchoError("$filename has an unsupported MIME type $mimetype_primary and was not added.");
467
+ DebugEcho("save_attachment: Not in supported filetype list: '$mimetype_primary'");
468
+ DebugDump($config['supported_file_types']);
469
+ $this->notify_error("Unsupported MIME type: $mimetype_primary", "$filename has an unsupported MIME type $mimetype_primary and was not added.\nSupported types:\n" . print_r($config['supported_file_types'], true));
470
+ }
471
+ break;
472
+ }
473
+ }
474
+
475
+ function notify_error($subject, $message) {
476
+ $recipients = array();
477
+ $config = postie_config_read();
478
+ if ($config['postie_log_error_notify'] == '(Nobody)') {
479
+ return;
480
+ }
481
+ if ($config['postie_log_error_notify'] == '(All Admins)') {
482
+ foreach (get_users(array('role' => 'administrator', 'blog_id' => get_current_blog_id())) as $user) {
483
+ $recipients[] = $user->user_email;
484
+ }
485
+ if (count($recipients) == 0) {
486
+ return;
487
+ }
488
+ } else {
489
+ $user = get_user_by('login', $config['postie_log_error_notify']);
490
+ if ($user === false) {
491
+ return;
492
+ }
493
+ $recipients[] = $user->user_login;
494
+ }
495
+
496
+ $message = "This message has been sent from " . get_site_url() . ". You can disable or control who receives them by changing the Postie 'Notify on Error' setting.\n\n" . $message;
497
+ wp_mail($recipients, $subject, $message);
498
+ }
499
+
500
+ function media_handle_upload($attachment, $post_id) {
501
+
502
+ $tmpFile = tempnam(get_temp_dir(), 'postie');
503
+ if ($tmpFile !== false) {
504
+ $fp = fopen($tmpFile, 'w');
505
+ if ($fp) {
506
+ fwrite($fp, $attachment['data']);
507
+ fclose($fp);
508
+ DebugEcho("media_handle_upload: wrote data to '$tmpFile'");
509
+ } else {
510
+ EchoError("media_handle_upload: Could not write to temp file: '$tmpFile' ");
511
+ $this->notify_error("media_handle_upload: Could not write to temp file: '$tmpFile' ", "media_handle_upload: Could not write to temp file: '$tmpFile' ");
512
+ }
513
+ } else {
514
+ EchoError("media_handle_upload: Could not create temp file in " . get_temp_dir());
515
+ $this->notify_error("media_handle_upload: Could not create temp file in " . get_temp_dir(), "media_handle_upload: Could not create temp file in " . get_temp_dir());
516
+ }
517
+
518
+ $file_array = array(
519
+ 'name' => $attachment['wp_filename'],
520
+ 'type' => $attachment['mimetype'],
521
+ 'tmp_name' => $tmpFile,
522
+ 'error' => 0,
523
+ 'size' => filesize($tmpFile)
524
+ );
525
+ DebugEcho("media_handle_upload: adding " . $file_array['name']);
526
+ DebugDump($file_array);
527
+
528
+ DebugEcho("doing postie_file_added_pre");
529
+ do_action('postie_file_added_pre', $post_id, $file_array);
530
+
531
+ $id = media_handle_sideload($file_array, $post_id);
532
+
533
+ if (!is_wp_error($id)) {
534
+ $mediapath = get_attached_file($id);
535
+ $file_array['tmp_name'] = $mediapath;
536
+ DebugEcho("doing postie_file_added");
537
+ do_action('postie_file_added', $post_id, $id, $file_array);
538
+ } else {
539
+ EchoError("There was an error adding the attachement: " . $id->get_error_message());
540
+ DebugDump($id->get_error_messages());
541
+ DebugDump($id->get_error_data());
542
+ $this->notify_error("There was an error adding the attachement: " . $attachment['wp_filename'], $id->get_error_message());
543
+ }
544
+
545
+ return $id;
546
+ }
547
+
548
+ function get_content(&$email, $config) {
549
+ DebugEcho('get_content: ---- start');
550
+ $meta_return = '';
551
+ if ($config['prefer_text_type'] == 'html') {
552
+ if (isset($email['html'])) {
553
+ $meta_return = $email['html'];
554
+ }
555
+ } else {
556
+ if (isset($email['text'])) {
557
+ $meta_return = $email['text'];
558
+ }
559
+ }
560
+ return $meta_return;
561
+ }
562
+
563
+ /**
564
+ * This function handles finding and setting the correct subject
565
+ * @return array - (subject,content)
566
+ */
567
+ function get_subject(&$mimeDecodedEmail, &$content, $config) {
568
+ //assign the default title/subject
569
+ if (empty($mimeDecodedEmail['headers']['subject'])) {
570
+ DebugEcho("get_subject: No subject in email");
571
+ if ($config['allow_subject_in_mail']) {
572
+ list($subject, $content) = tag_Subject($content, $config['default_title']);
573
+ } else {
574
+ DebugEcho("get_subject: Using default subject");
575
+ $subject = $config['default_title'];
576
+ }
577
+ $mimeDecodedEmail['headers']['subject'] = $subject;
578
+ } else {
579
+ $subject = $mimeDecodedEmail['headers']['subject'];
580
+ DebugEcho(("get_subject: Predecoded subject: $subject"));
581
+
582
+ if ($config['allow_subject_in_mail']) {
583
+ list($subject, $content) = tag_Subject($content, $subject);
584
+ }
585
+ }
586
+ if (!$config['allow_html_in_subject']) {
587
+ DebugEcho("get_subject: subject before htmlentities: $subject");
588
+ $subject = htmlentities($subject, ENT_COMPAT, $config['message_encoding']);
589
+ DebugEcho("get_subject: subject after htmlentities: $subject");
590
+ }
591
+
592
+ //This is for ISO-2022-JP - Can anyone confirm that this is still neeeded?
593
+ // escape sequence is 'ESC $ B' == 1b 24 42 hex.
594
+ if (strpos($subject, "\x1b\x24\x42") !== false) {
595
+ // found iso-2022-jp escape sequence in subject... convert!
596
+ DebugEcho("get_subject: extra parsing for ISO-2022-JP");
597
+ $subject = iconv("ISO-2022-JP", "UTF-8//TRANSLIT", $subject);
598
+ }
599
+ DebugEcho("get_subject: '$subject'");
600
+ return $subject;
601
+ }
602
+
603
+ function create_post($poster, $mimeDecodedEmail, $post_id, &$is_reply, $config) {
604
+ DebugEcho("create_post: prefer_text_type: " . $config['prefer_text_type']);
605
+
606
+ $fulldebug = $this->is_debugmode();
607
+ $fulldebugdump = false;
608
+
609
+ if (array_key_exists('message-id', $mimeDecodedEmail['headers'])) {
610
+ DebugEcho("Message Id is :" . htmlentities($mimeDecodedEmail['headers']['message-id']));
611
+ if ($fulldebugdump) {
612
+ DebugDump($mimeDecodedEmail);
613
+ }
614
+ }
615
+
616
+ if ($fulldebugdump) {
617
+ DebugDump($mimeDecodedEmail);
618
+ }
619
+
620
+ $this->save_attachments($mimeDecodedEmail, $post_id, $config);
621
+
622
+ $content = $this->get_content($mimeDecodedEmail, $config);
623
+
624
+ $subject = $this->get_subject($mimeDecodedEmail, $content, $config);
625
+
626
+ $content = filter_RemoveSignature($content, $config);
627
+ if ($fulldebug) {
628
+ DebugEcho("post filter_RemoveSignature: $content");
629
+ }
630
+
631
+ $content = filter_Newlines($content, $config);
632
+ if ($fulldebug) {
633
+ DebugEcho("post filter_Newlines: $content");
634
+ }
635
+
636
+ $post_excerpt = tag_Excerpt($content, $config);
637
+ if ($fulldebug) {
638
+ DebugEcho("post tag_Excerpt: $content");
639
+ }
640
+
641
+ $postAuthorDetails = $this->post_author_details($mimeDecodedEmail);
642
+ if ($fulldebug) {
643
+ DebugEcho("post getPostAuthorDetails: $content");
644
+ }
645
+
646
+ $message_date = NULL;
647
+ if (array_key_exists("date", $mimeDecodedEmail['headers']) && !empty($mimeDecodedEmail['headers']['date'])) {
648
+ DebugEcho("date header: {$mimeDecodedEmail['headers']['date']}");
649
+ if ($config['ignore_email_date']) {
650
+ $message_date = current_time('mysql');
651
+ DebugEcho("system date: $message_date");
652
+ } else {
653
+ $message_date = $mimeDecodedEmail['headers']['date'];
654
+ DebugEcho("decoded date: $message_date");
655
+ list($message_date, $delay) = tag_Delay($content, $message_date, $config);
656
+ if ($fulldebug) {
657
+ DebugEcho("post tag_Delay: $content");
658
+ }
659
+ }
660
+ } else {
661
+ DebugEcho("date header missing");
662
+ $message_date = current_time('mysql');
663
+ }
664
+
665
+ $post_date = tag_Date($content, $message_date);
666
+ if ($fulldebug) {
667
+ DebugEcho("post tag_Date: $content");
668
+ }
669
+
670
+
671
+ //do post type before category to keep the subject line correct
672
+ $post_type = tag_PostType($subject, $config);
673
+ if ($fulldebug) {
674
+ DebugEcho("post tag_PostType: $content");
675
+ }
676
+
677
+ $default_categoryid = $config['default_post_category'];
678
+
679
+ DebugEcho("pre postie_category_default: '$default_categoryid'");
680
+ $default_categoryid = apply_filters('postie_category_default', $default_categoryid);
681
+ DebugEcho("post postie_category_default: '$default_categoryid'");
682
+
683
+ $post_categories = tag_Categories($subject, $default_categoryid, $config, $post_id);
684
+ if ($fulldebug) {
685
+ DebugEcho("post tag_Categories: $content");
686
+ }
687
+
688
+ $post_tags = tag_Tags($content, $config['default_post_tags']);
689
+ if ($fulldebug) {
690
+ DebugEcho("post tag_Tags: $content");
691
+ }
692
+
693
+ $comment_status = tag_AllowCommentsOnPost($content);
694
+ if ($fulldebug) {
695
+ DebugEcho("post tag_AllowCommentsOnPost: $content");
696
+ }
697
+
698
+ $post_status = tag_Status($content, $config['post_status']);
699
+ if ($fulldebug) {
700
+ DebugEcho("post tag_Status: $content");
701
+ }
702
+
703
+ //handle CID before linkify
704
+ $content = filter_ReplaceImageCIDs($content, $mimeDecodedEmail);
705
+ if ($fulldebug) {
706
+ DebugEcho("post filter_ReplaceImageCIDs: $content");
707
+ }
708
+
709
+ if ($config['converturls']) {
710
+ $content = filter_Linkify($content);
711
+ if ($fulldebug) {
712
+ DebugEcho("post filter_Linkify: $content");
713
+ }
714
+ }
715
+
716
+ if ($config['reply_as_comment'] == true) {
717
+ $id = $this->parent_post($subject);
718
+ if (empty($id)) {
719
+ DebugEcho("Not a reply");
720
+ $id = $post_id;
721
+ $is_reply = false;
722
+ } else {
723
+ DebugEcho("Reply detected");
724
+ $is_reply = true;
725
+ if (true == $config['strip_reply']) {
726
+ // strip out quoted content
727
+ $lines = explode("\n", $content);
728
+ $newContents = '';
729
+ foreach ($lines as $line) {
730
+ if (preg_match("/^>.*/i", $line) == 0 &&
731
+ preg_match("/^(from|subject|to|date):.*?/iu", $line) == 0 &&
732
+ preg_match("/^-+.*?(from|subject|to|date).*?/iu", $line) == 0 &&
733
+ preg_match("/^on.*?wrote:$/iu", $line) == 0 &&
734
+ preg_match("/^-+\s*forwarded\s*message\s*-+/iu", $line) == 0) {
735
+ $newContents .= "$line\n";
736
+ }
737
+ }
738
+ if ((strlen($newContents) <> strlen($content)) && ('html' == $config['prefer_text_type'])) {
739
+ DebugEcho("Attempting to fix reply html (before): $newContents");
740
+ $newContents = $this->load_html($newContents)->__toString();
741
+ DebugEcho("Attempting to fix reply html (after): $newContents");
742
+ }
743
+ $content = $newContents;
744
+ }
745
+ wp_delete_post($post_id);
746
+ }
747
+ } else {
748
+ $id = $post_id;
749
+ DebugEcho("Replies will not be processed as comments");
750
+ }
751
+
752
+ if ($delay > 0 && $post_status == 'publish') {
753
+ DebugEcho("publish in future");
754
+ $post_status = 'future';
755
+ }
756
+
757
+ $content = filter_Start($content, $config);
758
+ if ($fulldebug) {
759
+ DebugEcho("post filter_Start: $content");
760
+ }
761
+
762
+ $content = filter_End($content, $config);
763
+ if ($fulldebug) {
764
+ DebugEcho("post filter_End: $content");
765
+ }
766
+
767
+ $content = filter_ReplaceImagePlaceHolders($content, $mimeDecodedEmail, $config, $id, $config['image_placeholder']);
768
+ if ($fulldebug) {
769
+ DebugEcho("post filter_ReplaceImagePlaceHolders: $content");
770
+ }
771
+
772
+ if ($post_excerpt) {
773
+ $post_excerpt = filter_ReplaceImagePlaceHolders($post_excerpt, $mimeDecodedEmail, $config, $id, '#eimg%#');
774
+ DebugEcho("excerpt: $post_excerpt");
775
+ if ($fulldebug) {
776
+ DebugEcho("post excerpt ReplaceImagePlaceHolders: $content");
777
+ }
778
+ }
779
+
780
+ //handle inline images after linkify
781
+ if ('plain' == $config['prefer_text_type']) {
782
+ $content = filter_ReplaceInlineImage($content, $mimeDecodedEmail, $config);
783
+ if ($fulldebug) {
784
+ DebugEcho("post filter_ReplaceInlineImage: $content");
785
+ }
786
+ }
787
+
788
+ $content = filter_AttachmentTemplates($content, $mimeDecodedEmail, $post_id, $config);
789
+
790
+ if (trim($subject) == "") {
791
+ $subject = $config['default_title'];
792
+ DebugEcho("post parsing subject is blank using: " . $config['default_title']);
793
+ }
794
+
795
+ $details = array(
796
+ 'post_author' => $poster,
797
+ 'comment_author' => $postAuthorDetails['author'],
798
+ 'comment_author_url' => $postAuthorDetails['comment_author_url'],
799
+ 'user_ID' => $postAuthorDetails['user_ID'],
800
+ 'email_author' => $postAuthorDetails['email'],
801
+ 'post_date' => $post_date,
802
+ 'post_date_gmt' => get_gmt_from_date($post_date),
803
+ 'post_content' => $content,
804
+ 'post_title' => $subject,
805
+ 'post_type' => $post_type, /* Added by Raam Dev <raam@raamdev.com> */
806
+ 'ping_status' => get_option('default_ping_status'),
807
+ 'post_category' => $post_categories,
808
+ 'tags_input' => $post_tags,
809
+ 'comment_status' => $comment_status,
810
+ 'post_name' => $subject,
811
+ 'post_excerpt' => $post_excerpt,
812
+ 'ID' => $id,
813
+ 'post_status' => $post_status
814
+ );
815
+ return $details;
816
+ }
817
+
818
+ function save_post($details, $isReply) {
819
+ $post_ID = 0;
820
+ if (!$isReply) {
821
+ $post_ID = wp_insert_post($details, true);
822
+ if (is_wp_error($post_ID)) {
823
+ EchoError("PostToDB Error: " . $post_ID->get_error_message());
824
+ DebugDump($post_ID->get_error_messages());
825
+ DebugDump($post_ID->get_error_data());
826
+ wp_delete_post($details['ID']);
827
+
828
+ $this->notify_error("Failed to create {$details['post_type']}: {$details['post_title']}", "Error: " . $post_ID->get_error_message() . "\n\n" . $details['post_content']);
829
+
830
+ $post_ID = null;
831
+ }
832
+ } else {
833
+ $comment = array(
834
+ 'comment_author' => $details['comment_author'],
835
+ 'comment_post_ID' => $details['ID'],
836
+ 'comment_author_email' => $details['email_author'],
837
+ 'comment_date' => $details['post_date'],
838
+ 'comment_date_gmt' => $details['post_date_gmt'],
839
+ 'comment_content' => $details['post_content'],
840
+ 'comment_author_url' => $details['comment_author_url'],
841
+ 'comment_author_IP' => '',
842
+ 'comment_approved' => 1,
843
+ 'comment_agent' => '',
844
+ 'comment_type' => '',
845
+ 'comment_parent' => 0,
846
+ 'user_id' => $details['user_ID']
847
+ );
848
+ $comment = apply_filters('postie_comment_before', $comment);
849
+ DebugEcho("postie_save_post: post postie_comment_before");
850
+ DebugDump($comment);
851
+
852
+ $post_ID = wp_new_comment($comment);
853
+
854
+ DebugEcho("doing postie_comment_after");
855
+ do_action('postie_comment_after', $comment);
856
+ }
857
+
858
+ if ($post_ID) {
859
+ DebugEcho("doing postie_post_after");
860
+ do_action('postie_post_after', $details);
861
+ }
862
+
863
+ return $post_ID;
864
+ }
865
+
866
+ function load_html($text) {
867
+ return str_get_html($text, true, true, DEFAULT_TARGET_CHARSET, false);
868
+ }
869
+
870
+ /* we check whether or not the email is a reply to a previously
871
+ * published post. First we check whether it starts with Re:, and then
872
+ * we see if the remainder matches an already existing post. If so,
873
+ * then we add that post id to the details array, which will cause the
874
+ * existing post to be overwritten, instead of a new one being
875
+ * generated
876
+ */
877
+
878
+ function parent_post(&$subject) {
879
+ global $wpdb;
880
+
881
+ $id = NULL;
882
+ DebugEcho("GetParentPostForReply: Looking for parent '$subject'");
883
+ // see if subject starts with Re:
884
+ $matches = array();
885
+ if (preg_match("/(^Re:)(.*)/iu", $subject, $matches)) {
886
+ DebugEcho("GetParentPostForReply: Re: detected");
887
+ $subject = trim($matches[2]);
888
+ // strip out category info into temporary variable
889
+ $tmpSubject = $subject;
890
+ if (preg_match('/(.+): (.*)/u', $tmpSubject, $matches)) {
891
+ $tmpSubject = trim($matches[2]);
892
+ $matches[1] = array($matches[1]);
893
+ } else if (preg_match_all('/\[(.[^\[]*)\]/', $tmpSubject, $matches)) {
894
+ $tmpSubject_matches = array();
895
+ preg_match("/](.[^\[]*)$/", $tmpSubject, $tmpSubject_matches);
896
+ $tmpSubject = trim($tmpSubject_matches[1]);
897
+ } else if (preg_match_all('/-(.[^-]*)-/', $tmpSubject, $matches)) {
898
+ preg_match("/-(.[^-]*)$/", $tmpSubject, $tmpSubject_matches);
899
+ $tmpSubject = trim($tmpSubject_matches[1]);
900
+ }
901
+ DebugEcho("GetParentPostForReply: tmpSubject: $tmpSubject");
902
+ $checkExistingPostQuery = "SELECT ID FROM $wpdb->posts WHERE post_title LIKE %s AND post_status = 'publish' AND comment_status = 'open'";
903
+ if ($id = $wpdb->get_var($wpdb->prepare($checkExistingPostQuery, $tmpSubject))) {
904
+ if (!empty($id)) {
905
+ DebugEcho("GetParentPostForReply: id: $id");
906
+ } else {
907
+ DebugEcho("GetParentPostForReply: No parent id found");
908
+ }
909
+ }
910
+ } else {
911
+ DebugEcho("GetParentPostForReply: No parent found");
912
+ }
913
+ return $id;
914
+ }
915
+
916
+ function post_author_details($mimeDecodedEmail) {
917
+
918
+ $theEmail = $mimeDecodedEmail['headers']['from']['mailbox'] . '@' . $mimeDecodedEmail['headers']['from']['host'];
919
+
920
+ $regAuthor = get_user_by('email', $theEmail);
921
+ if ($regAuthor) {
922
+ $theAuthor = $regAuthor->user_login;
923
+ $theUrl = $regAuthor->user_url;
924
+ $theID = $regAuthor->ID;
925
+ } else {
926
+ $theAuthor = $this->get_name_from_email($theEmail);
927
+ $theUrl = '';
928
+ $theID = '';
929
+ }
930
+
931
+ $theDetails = array(
932
+ 'author' => $theAuthor,
933
+ 'comment_author_url' => $theUrl,
934
+ 'user_ID' => $theID,
935
+ 'email' => $theEmail
936
+ );
937
+
938
+ return $theDetails;
939
+ }
940
+
941
+ /**
942
+ * Choose an appropriate file icon based on the extension and mime type of
943
+ * the attachment
944
+ */
945
+ function choose_attachment_icon($file, $primary, $secondary, $iconSet = 'silver', $size = '32') {
946
+ if ($iconSet == 'none') {
947
+ return('');
948
+ }
949
+ $fileName = basename($file);
950
+ $parts = explode('.', $fileName);
951
+ $ext = $parts[count($parts) - 1];
952
+ $docExts = array('doc', 'docx');
953
+ $docMimes = array('msword', 'vnd.ms-word', 'vnd.openxmlformats-officedocument.wordprocessingml.document');
954
+ $pptExts = array('ppt', 'pptx');
955
+ $pptMimes = array('mspowerpoint', 'vnd.ms-powerpoint', 'vnd.openxmlformats-officedocument.');
956
+ $xlsExts = array('xls', 'xlsx');
957
+ $xlsMimes = array('msexcel', 'vnd.ms-excel', 'vnd.openxmlformats-officedocument.spreadsheetml.sheet');
958
+ $iWorkMimes = array('zip', 'octet-stream');
959
+ $mpgExts = array('mpg', 'mpeg', 'mp2');
960
+ $mpgMimes = array('mpg', 'mpeg', 'mp2');
961
+ $mp3Exts = array('mp3');
962
+ $mp3Mimes = array('mp3', 'mpeg3', 'mpeg');
963
+ $mp4Exts = array('mp4', 'm4v');
964
+ $mp4Mimes = array('mp4', 'mpeg4', 'octet-stream');
965
+ $aacExts = array('m4a', 'aac');
966
+ $aacMimes = array('m4a', 'aac', 'mp4');
967
+ $aviExts = array('avi');
968
+ $aviMimes = array('avi', 'x-msvideo');
969
+ $movExts = array('mov');
970
+ $movMimes = array('mov', 'quicktime');
971
+ if ($ext == 'pdf' && $secondary == 'pdf') {
972
+ $fileType = 'pdf';
973
+ } else if ($ext == 'pages' && in_array($secondary, $iWorkMimes)) {
974
+ $fileType = 'pages';
975
+ } else if ($ext == 'numbers' && in_array($secondary, $iWorkMimes)) {
976
+ $fileType = 'numbers';
977
+ } else if ($ext == 'key' && in_array($secondary, $iWorkMimes)) {
978
+ $fileType = 'key';
979
+ } else if (in_array($ext, $docExts) && in_array($secondary, $docMimes)) {
980
+ $fileType = 'doc';
981
+ } else if (in_array($ext, $pptExts) && in_array($secondary, $pptMimes)) {
982
+ $fileType = 'ppt';
983
+ } else if (in_array($ext, $xlsExts) && in_array($secondary, $xlsMimes)) {
984
+ $fileType = 'xls';
985
+ } else if (in_array($ext, $mp4Exts) && in_array($secondary, $mp4Mimes)) {
986
+ $fileType = 'mp4';
987
+ } else if (in_array($ext, $movExts) && in_array($secondary, $movMimes)) {
988
+ $fileType = 'mov';
989
+ } else if (in_array($ext, $aviExts) && in_array($secondary, $aviMimes)) {
990
+ $fileType = 'avi';
991
+ } else if (in_array($ext, $mp3Exts) && in_array($secondary, $mp3Mimes)) {
992
+ $fileType = 'mp3';
993
+ } else if (in_array($ext, $mpgExts) && in_array($secondary, $mpgMimes)) {
994
+ $fileType = 'mpg';
995
+ } else if (in_array($ext, $aacExts) && in_array($secondary, $aacMimes)) {
996
+ $fileType = 'aac';
997
+ } else {
998
+ $fileType = 'default';
999
+ }
1000
+ $fileName = "/icons/$iconSet/$fileType-$size.png";
1001
+ if (!file_exists(POSTIE_ROOT . $fileName)) {
1002
+ $fileName = "/icons/$iconSet/default-$size.png";
1003
+ }
1004
+ $iconHtml = "<img src='" . POSTIE_URL . $fileName . "' alt='$fileType icon' />";
1005
+ DebugEcho("icon: $iconHtml");
1006
+ return $iconHtml;
1007
+ }
1008
+
1009
+ function save_email_debug($raw, $email) {
1010
+ if ($this->is_debugmode()) {
1011
+ //DebugDump($email);
1012
+ //DebugDump($mimeDecodedEmail);
1013
+
1014
+ $dname = POSTIE_ROOT . DIRECTORY_SEPARATOR . 'test_emails' . DIRECTORY_SEPARATOR;
1015
+ if (is_dir($dname)) {
1016
+ $mid = $email['headers']['message-id'];
1017
+ if (empty($mid)) {
1018
+ $mid = uniqid();
1019
+ }
1020
+ $fname = $dname . sanitize_file_name($mid);
1021
+
1022
+ file_put_contents($fname . '-raw.txt', $raw);
1023
+ file_put_contents($fname . '.txt', $email['text']);
1024
+ file_put_contents($fname . '.html', $email['html']);
1025
+ }
1026
+ }
1027
+ }
1028
+
1029
+ function get_emails($type, $server, $port, $email, $password, $protocol, $deleteMessages, $maxemails, $connectiontype) {
1030
+
1031
+ DebugEcho("getemails: Connecting to $server:$port ($protocol)");
1032
+
1033
+ $emails = array();
1034
+
1035
+ try {
1036
+ DebugEcho("getemails: procol: $protocol");
1037
+ if ($connectiontype == 'curl') {
1038
+ $conn = new pCurlConnection($type, trim($server), $email, $password, $port, ($protocol == 'imap-ssl' || $protocol == 'pop3-ssl'));
1039
+ } else {
1040
+ $conn = new pSocketConnection($type, trim($server), $email, $password, $port, ($protocol == 'imap-ssl' || $protocol == 'pop3-ssl'));
1041
+ }
1042
+
1043
+ if ($type == 'imap') {
1044
+ $srv = new pImapMailServer($conn);
1045
+ } else {
1046
+ $srv = new pPop3MailServer($conn);
1047
+ }
1048
+
1049
+ DebugEcho("getemails: listing messages");
1050
+ $mailbox = new fMailbox($type, $conn, $srv);
1051
+ $messages = $mailbox->listMessages($maxemails);
1052
+
1053
+ foreach ($messages as $uid => $messages) {
1054
+ DebugEcho("getemails: fetch $uid");
1055
+
1056
+ $email = $mailbox->fetchMessage($uid);
1057
+
1058
+ if (!empty($email['html'])) {
1059
+ DebugEcho("getemails: html");
1060
+ $email['html'] = filter_CleanHtml($email['html']);
1061
+ } else {
1062
+ DebugEcho("getemails: no html");
1063
+ }
1064
+
1065
+ $emails[] = $email;
1066
+ if ($deleteMessages) {
1067
+ DebugEcho("getemails: deleting $uid");
1068
+ $mailbox->deleteMessages($uid);
1069
+ }
1070
+ }
1071
+
1072
+ DebugEcho("getemails: closing connection");
1073
+ $mailbox->close();
1074
+ } catch (Exception $e) {
1075
+ EchoError("getemails: " . $e->getMessage());
1076
+ }
1077
+
1078
+ return $emails;
1079
+ }
1080
+
1081
+ /**
1082
+ * This function handles determining the protocol and fetching the mail
1083
+ * @return array
1084
+ */
1085
+ function fetch_mail($server, $port, $email, $password, $protocol, $deleteMessages, $maxemails, $connectiontype) {
1086
+ $emails = array();
1087
+ if (!$server || !$port || !$email) {
1088
+ EchoError("Missing Configuration For Mail Server");
1089
+ return $emails;
1090
+ }
1091
+ if ($server == "pop.gmail.com") {
1092
+ DebugEcho("MAKE SURE POP IS TURNED ON IN SETTING AT Gmail");
1093
+ }
1094
+ switch (strtolower($protocol)) {
1095
+ case 'imap':
1096
+ case 'imap-ssl':
1097
+ $emails = $this->get_emails('imap', $server, $port, $email, $password, $protocol, $deleteMessages, $maxemails, $connectiontype);
1098
+ break;
1099
+ case 'pop3':
1100
+ case 'pop3-ssl':
1101
+ default:
1102
+ $emails = $this->get_emails('pop3', $server, $port, $email, $password, $protocol, $deleteMessages, $maxemails, $connectiontype);
1103
+ }
1104
+
1105
+ return $emails;
1106
+ }
1107
+
1108
+ function disable_revisions($restore = false) {
1109
+ global $_wp_post_type_features, $_postie_revisions;
1110
+
1111
+ if (!$restore) {
1112
+ $_postie_revisions = false;
1113
+ if (isset($_wp_post_type_features['post']) && isset($_wp_post_type_features['post']['revisions'])) {
1114
+ $_postie_revisions = $_wp_post_type_features['post']['revisions'];
1115
+ unset($_wp_post_type_features['post']['revisions']);
1116
+ }
1117
+ } else {
1118
+ if ($_postie_revisions) {
1119
+ $_wp_post_type_features['post']['revisions'] = $_postie_revisions;
1120
+ }
1121
+ }
1122
+ }
1123
+
1124
+ function email_notify($email, $recipients, $postid) {
1125
+ DebugEcho("email_notify: start");
1126
+
1127
+ if (count($recipients) == 0) {
1128
+ DebugEcho("email_notify: no recipients");
1129
+ return;
1130
+ }
1131
+ if (empty($postid)) {
1132
+ DebugEcho("email_notify: no post id");
1133
+ return;
1134
+ }
1135
+
1136
+ $myemailadd = get_option("admin_email");
1137
+ $blogname = get_option("blogname");
1138
+ $eblogname = "=?utf-8?b?" . base64_encode($blogname) . "?= ";
1139
+ $posturl = get_permalink($postid);
1140
+ $subject = $email['headers']['subject'];
1141
+
1142
+ $sendheaders = array("From: $eblogname <$myemailadd>");
1143
+
1144
+ $post_status = get_post_status($postid);
1145
+
1146
+ $mailtext = "Your email '$subject' has been successfully imported into $blogname $posturl with the current status of '$post_status'.\n";
1147
+
1148
+ $recipients = apply_filters('postie_email_notify_recipients', $recipients, $email, $postid);
1149
+ if (count($recipients) == 0) {
1150
+ DebugEcho("email_notify: no recipients after postie_email_notify_recipients filter");
1151
+ return;
1152
+ } else {
1153
+ DebugEcho("email_notify: post postie_email_notify_recipients");
1154
+ DebugDump($recipients);
1155
+ }
1156
+ $subject = "Email imported to $blogname ($post_status)";
1157
+ $subject = apply_filters('postie_email_notify_subject', $subject, $email, $postid);
1158
+ DebugEcho("email_notify: post postie_email_notify_subject: $subject");
1159
+
1160
+ $mailtext = apply_filters('postie_email_notify_body', $mailtext, $email, $postid);
1161
+ DebugEcho("email_notify: post postie_email_notify_body: $mailtext");
1162
+
1163
+
1164
+ wp_mail($recipients, $subject, $mailtext, $sendheaders);
1165
+ }
1166
+
1167
+ /**
1168
+ * This is the main handler for all of the processing
1169
+ */
1170
+ function post_email($poster, $mimeDecodedEmail, $config) {
1171
+ $this->disable_revisions();
1172
+ //extract($config);
1173
+
1174
+ /* in order to do attachments correctly, we need to associate the
1175
+ attachments with a post. So we add the post here, then update it */
1176
+ $tmpPost = array('post_title' => 'tmptitle', 'post_content' => 'tmpPost', 'post_status' => 'draft');
1177
+ $post_id = wp_insert_post($tmpPost, true);
1178
+ if (!is_wp_error($post_id)) {
1179
+ DebugEcho("PostEmail: tmp post id is $post_id");
1180
+
1181
+ $is_reply = false;
1182
+
1183
+ DebugEcho("PostEmail: pre postie_post_pre");
1184
+ $mimeDecodedEmail = apply_filters('postie_post_pre', $mimeDecodedEmail);
1185
+
1186
+ $details = $this->create_post($poster, $mimeDecodedEmail, $post_id, $is_reply, $config);
1187
+
1188
+ $details = apply_filters('postie_post', $details);
1189
+ $details = apply_filters('postie_post_before', $details, $mimeDecodedEmail['headers']);
1190
+
1191
+ DebugEcho("PostEmail: Post postie_post_before filter");
1192
+ DebugDump($details);
1193
+
1194
+ if (empty($details)) {
1195
+ // It is possible that the filter has removed the post, in which case, it should not be posted.
1196
+ // And if we created a placeholder post (because this was not a reply to an existing post),
1197
+ // then it should be removed
1198
+ if (!$is_reply) {
1199
+ wp_delete_post($post_id);
1200
+ EchoError("postie_post filter cleared the post, not saving.");
1201
+ }
1202
+ } else {
1203
+ $postid = $this->save_post($details, $is_reply);
1204
+
1205
+ if ($config['confirmation_email'] != '') {
1206
+ if ($config['confirmation_email'] == 'sender' || $config['confirmation_email'] == 'both') {
1207
+ $recipients = array($details['email_author']);
1208
+ }
1209
+ if ($config['confirmation_email'] == 'admin' || $config['confirmation_email'] == 'both') {
1210
+ foreach (get_users(array('role' => 'administrator', 'blog_id' => get_current_blog_id())) as $user) {
1211
+ $recipients[] = $user->user_email;
1212
+ }
1213
+ }
1214
+ $this->email_notify($mimeDecodedEmail, $recipients, $postid);
1215
+ }
1216
+ if ($this->is_debugmode()) {
1217
+ $post = get_post($post_id);
1218
+ DebugEcho("PostEmail: resulting post");
1219
+ DebugDump($post);
1220
+ }
1221
+ }
1222
+ } else {
1223
+ EchoError("PostEmail: wp_insert_post failed: " . $post_id->get_error_message());
1224
+ DebugDump($post_id->get_error_messages());
1225
+ DebugDump($post_id->get_error_data());
1226
+ $this->notify_error("PostEmail wp_insert_post failed creating placeholder", $post_id->get_error_message());
1227
+ }
1228
+ $this->disable_revisions(true);
1229
+ DebugEcho("Done");
1230
+ }
1231
+
1232
+ /**
1233
+ * This function gleans the name from an email address if available. If not
1234
+ * it just returns the username (everything before @)
1235
+ */
1236
+ function get_name_from_email($address) {
1237
+ $name = "";
1238
+ $matches = array();
1239
+ if (preg_match('/^([^<>]+)<([^<> ()]+)>$/', $address, $matches)) {
1240
+ $name = $matches[1];
1241
+ } else if (preg_match('/<([^<>@ ()]+)>/', $address, $matches)) {
1242
+ $name = $matches[1];
1243
+ } else if (preg_match('/(.+?)@(.+)/', $address, $matches)) {
1244
+ $name = $matches[1];
1245
+ }
1246
+
1247
+ return trim($name);
1248
+ }
1249
+
1250
+ /**
1251
+ * This method works around a problem with email address with extra <> in the email address
1252
+ * @param string
1253
+ * @return string
1254
+ */
1255
+ function remove_extra_characters_in_email_address($address) {
1256
+ $matches = array();
1257
+ if (preg_match('/^[^<>]+<([^<> ()]+)>$/', $address, $matches)) {
1258
+ $address = $matches[1];
1259
+ DebugEcho("RemoveExtraCharactersInEmailAddress: $address (1)");
1260
+ DebugDump($matches);
1261
+ } else if (preg_match('/<([^<> ()]+)>/', $address, $matches)) {
1262
+ $address = $matches[1];
1263
+ DebugEcho("RemoveExtraCharactersInEmailAddress: $address (2)");
1264
+ }
1265
+
1266
+ return $address;
1267
+ }
1268
+
1269
+ /**
1270
+ * This compares the current address to the list of authorized addresses
1271
+ * @param string - email address
1272
+ * @return boolean
1273
+ */
1274
+ function is_email_authorized($address, $authorized) {
1275
+ $r = false;
1276
+ if (is_array($authorized)) {
1277
+ $a = strtolower(trim($address));
1278
+ if (!empty($a)) {
1279
+ $r = in_array($a, array_map('strtolower', $authorized));
1280
+ }
1281
+ }
1282
+ return $r;
1283
+ }
1284
+
1285
+ function header_encode($value) {
1286
+ return "=?utf-8?b?" . base64_encode($value) . "?= ";
1287
+ }
1288
+
1289
+ function email_reject($email, $recipients, $returnToSender) {
1290
+ DebugEcho("email_reject: start");
1291
+
1292
+ if (count($recipients) == 0) {
1293
+ DebugEcho("email_reject: no recipients");
1294
+ return;
1295
+ }
1296
+
1297
+ $blogname = get_option("blogname");
1298
+ $from = $email['headers']['from']['mailbox'] . '@' . $email['headers']['from']['host'];
1299
+
1300
+ $subject = $email['headers']['subject'];
1301
+ if ($returnToSender) {
1302
+ DebugEcho("email_reject: return to sender $from");
1303
+ array_push($recipients, $from);
1304
+ }
1305
+
1306
+ $eblogname = $this->header_encode($blogname);
1307
+ $adminemail = get_option("admin_email");
1308
+
1309
+ $headers = array();
1310
+ $headers[] = "From: $eblogname <$adminemail>";
1311
+
1312
+ DebugEcho("email_reject: To:");
1313
+ DebugDump($recipients);
1314
+ DebugEcho("email_reject: header:");
1315
+ DebugDump($headers);
1316
+
1317
+ $message = "An unauthorized message has been sent to $blogname.\n";
1318
+ $message .= "Sender: $from\n";
1319
+ $message .= "Subject: $subject\n";
1320
+ $message .= "\n\nIf you wish to allow posts from this address, please add " . $from . " to the registered users list and manually add the content of the email found below.";
1321
+ $message .= "\n\nOtherwise, the email has already been deleted from the server and you can ignore this message.";
1322
+ $message .= "\n\nIf you would like to prevent postie from forwarding mail in the future, please change the FORWARD_REJECTED_MAIL setting in the Postie settings panel";
1323
+ $message .= "\n\nThe original content of the email has been attached.\n\n";
1324
+
1325
+ $recipients = apply_filters('postie_email_reject_recipients', $recipients, $email);
1326
+ if (count($recipients) == 0) {
1327
+ DebugEcho("email_reject: no recipients after postie_email_reject_recipients filter");
1328
+ return;
1329
+ } else {
1330
+ DebugEcho("email_reject: post postie_email_reject_recipients");
1331
+ DebugDump($recipients);
1332
+ }
1333
+
1334
+ $subject = $blogname . ": Unauthorized Post Attempt from $from";
1335
+ $subject = apply_filters('postie_email_reject_subject', $subject, $email);
1336
+ DebugEcho("email_reject: post postie_email_reject_subject: $subject");
1337
+
1338
+ $message = apply_filters('postie_email_reject_body', $message, $email);
1339
+ DebugEcho("email_reject: post postie_email_reject_body: $message");
1340
+
1341
+ $attachTxt = wp_tempnam() . '.txt';
1342
+ file_put_contents($attachTxt, $email['text']);
1343
+
1344
+ $attachHtml = wp_tempnam() . '.htm';
1345
+ file_put_contents($attachHtml, $email['html']);
1346
+
1347
+ wp_mail($recipients, $subject, $message, $headers, array($attachTxt, $attachHtml));
1348
+
1349
+ unlink($attachTxt);
1350
+ unlink($attachHtml);
1351
+ }
1352
+
1353
+ /**
1354
+ * Determines if the sender is a valid user.
1355
+ * @return integer|NULL
1356
+ */
1357
+ function validate_poster(&$mimeDecodedEmail, $config) {
1358
+ extract($config);
1359
+ $poster = NULL;
1360
+ $from = "";
1361
+ if (array_key_exists('headers', $mimeDecodedEmail) && array_key_exists('from', $mimeDecodedEmail['headers'])) {
1362
+ $from = $mimeDecodedEmail['headers']['from']['mailbox'] . '@' . $mimeDecodedEmail['headers']['from']['host'];
1363
+ $from = apply_filters('postie_filter_email', $from);
1364
+ DebugEcho("ValidatePoster: post postie_filter_email $from");
1365
+
1366
+ $toEmail = '';
1367
+ if (isset($mimeDecodedEmail['headers']['to'])) {
1368
+ $toEmail = $mimeDecodedEmail['headers']['to'][0]['mailbox'] . '@' . $mimeDecodedEmail['headers']['to'][0]['host'];
1369
+ }
1370
+
1371
+ $replytoEmail = '';
1372
+ if (isset($mimeDecodedEmail['headers']['reply-to'])) {
1373
+ $replytoEmail = $mimeDecodedEmail['headers']['reply-to']['mailbox'] . '@' . $mimeDecodedEmail['headers']['reply-to']['host'];
1374
+ }
1375
+
1376
+ $from = apply_filters("postie_filter_email2", $from, $toEmail, $replytoEmail);
1377
+ DebugEcho("ValidatePoster: post postie_filter_email2 $from");
1378
+ } else {
1379
+ DebugEcho("No 'from' header found");
1380
+ DebugDump($mimeDecodedEmail['headers']);
1381
+ }
1382
+
1383
+ if (array_key_exists("headers", $mimeDecodedEmail)) {
1384
+ $from = apply_filters("postie_filter_email3", $from, $mimeDecodedEmail['headers']);
1385
+ DebugEcho("ValidatePoster: post postie_filter_email3 $from");
1386
+ }
1387
+
1388
+ $resentFrom = "";
1389
+ if (array_key_exists('headers', $mimeDecodedEmail) && array_key_exists('resent-from', $mimeDecodedEmail['headers'])) {
1390
+ $resentFrom = $this->remove_extra_characters_in_email_address(trim($mimeDecodedEmail['headers']['resent-from']));
1391
+ }
1392
+
1393
+ //See if the email address is one of the special authorized ones
1394
+ $user_ID = '';
1395
+ if (!empty($from)) {
1396
+ DebugEcho("Confirming Access For $from ");
1397
+ $user = get_user_by('email', $from);
1398
+ if ($user !== false) {
1399
+ if (is_user_member_of_blog($user->ID)) {
1400
+ $user_ID = $user->ID;
1401
+ } else {
1402
+ DebugEcho("$from is not user of blog " . get_current_blog_id());
1403
+ }
1404
+ }
1405
+ }
1406
+
1407
+ if (!empty($user_ID)) {
1408
+ $user = new WP_User($user_ID);
1409
+ if ($user->has_cap("post_via_postie")) {
1410
+ DebugEcho("$user_ID has 'post_via_postie' permissions");
1411
+ $poster = $user_ID;
1412
+
1413
+ DebugEcho("ValidatePoster: pre postie_author $poster");
1414
+ $poster = apply_filters("postie_author", $poster);
1415
+ DebugEcho("ValidatePoster: post postie_author $poster");
1416
+ } else {
1417
+ DebugEcho("$user_ID does not have 'post_via_postie' permissions");
1418
+ $user_ID = "";
1419
+ }
1420
+ }
1421
+
1422
+ if (empty($user_ID) && ($config['turn_authorization_off'] || $this->is_email_authorized($from, $config['authorized_addresses']) || $this->is_email_authorized($resentFrom, $config['authorized_addresses']))) {
1423
+ DebugEcho("ValidatePoster: looking up default user " . $config['admin_username']);
1424
+ $user = get_user_by('login', $config['admin_username']);
1425
+ if ($user === false) {
1426
+ EchoError("Your 'Default Poster' setting '" . $config['admin_username'] . "' is not a valid WordPress user (2)");
1427
+ $poster = 1;
1428
+ } else {
1429
+ $poster = $user->ID;
1430
+ DebugEcho("ValidatePoster: pre postie_author (default) $poster");
1431
+ $poster = apply_filters("postie_author", $poster);
1432
+ DebugEcho("ValidatePoster: post postie_author (default) $poster");
1433
+ }
1434
+ DebugEcho("ValidatePoster: found user '$poster'");
1435
+ }
1436
+
1437
+ if (!$poster) {
1438
+ EchoError('Invalid sender: ' . htmlentities($from) . "! Not adding email!");
1439
+ if ($config['forward_rejected_mail']) {
1440
+ $this->email_reject($mimeDecodedEmail, array(get_option("admin_email")), $config['return_to_sender']);
1441
+ EchoError("A copy of the message has been forwarded to the administrator.");
1442
+ }
1443
+ return '';
1444
+ }
1445
+
1446
+ //actually log in as the user
1447
+ if ($config['force_user_login'] == true) {
1448
+ $user = get_user_by('id', $poster);
1449
+ if ($user) {
1450
+ DebugEcho("logging in as {$user->user_login}");
1451
+ wp_set_current_user($poster);
1452
+ //wp_set_auth_cookie($poster);
1453
+ do_action('wp_login', $user->user_login);
1454
+ }
1455
+ }
1456
+ return $poster;
1457
+ }
1458
+
1459
+ function postie_environment($force_display = false) {
1460
+ global $g_postie_init;
1461
+
1462
+ DebugEcho("OS: " . php_uname(), $force_display);
1463
+ DebugEcho("PHP Version: " . phpversion(), $force_display);
1464
+ DebugEcho("PHP error_log: " . ini_get('error_log'), $force_display);
1465
+ DebugEcho("PHP log_errors: " . (ini_get('log_errors') ? 'On' : 'Off'), $force_display);
1466
+ DebugEcho("PHP get_temp_dir: " . get_temp_dir(), $force_display);
1467
+ if (function_exists('curl_version')) {
1468
+ $cv = curl_version();
1469
+ DebugEcho("PHP cURL version: " . $cv['version'], $force_display);
1470
+ }
1471
+
1472
+ DebugEcho("WordPress Version: " . get_bloginfo('version'), $force_display);
1473
+ if (defined('MULTISITE') && MULTISITE) {
1474
+ DebugEcho("WordPress Multisite", $force_display);
1475
+ DebugEcho("network_home_url(): " . network_home_url(), $force_display);
1476
+ } else {
1477
+ DebugEcho("WordPress Singlesite", $force_display);
1478
+ }
1479
+ DebugEcho("WP_TEMP_DIR: " . (defined('WP_TEMP_DIR') ? WP_TEMP_DIR : '(none)'), $force_display);
1480
+ DebugEcho("WP_HOME: " . (defined('WP_HOME') ? WP_HOME : '(none)'), $force_display);
1481
+ DebugEcho("home_url(): " . home_url(), $force_display);
1482
+ DebugEcho("WP_SITEURL: " . (defined('WP_SITEURL') ? WP_SITEURL : '(none)'), $force_display);
1483
+ DebugEcho("site_url(): " . site_url(), $force_display);
1484
+
1485
+ if (defined('WP_DEBUG')) {
1486
+ DebugEcho("WP_DEBUG: " . (WP_DEBUG === true ? 'On' : 'Off'), $force_display);
1487
+ } else {
1488
+ DebugEcho("WP_DEBUG: Off", $force_display);
1489
+ }
1490
+
1491
+ if (defined('WP_DEBUG_DISPLAY')) {
1492
+ if (null == WP_DEBUG_DISPLAY) {
1493
+ DebugEcho("WP_DEBUG_DISPLAY: null", $force_display);
1494
+ } else {
1495
+ DebugEcho("WP_DEBUG_DISPLAY: " . (WP_DEBUG_DISPLAY === true ? 'On' : 'Off'), $force_display);
1496
+ }
1497
+ } else {
1498
+ DebugEcho("WP_DEBUG_DISPLAY: Off", $force_display);
1499
+ }
1500
+
1501
+ if (defined('WP_DEBUG_LOG')) {
1502
+ DebugEcho("WP_DEBUG_LOG: " . (WP_DEBUG_LOG === true ? 'On' : 'Off'), $force_display);
1503
+ } else {
1504
+ DebugEcho("WP_DEBUG_LOG: Off", $force_display);
1505
+ }
1506
+
1507
+ if (defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
1508
+ DebugEcho("Alternate cron is enabled", $force_display);
1509
+ }
1510
+
1511
+ if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) {
1512
+ DebugEcho("WordPress cron is disabled. Postie will not run unless you have an external cron set up.", $force_display);
1513
+ }
1514
+
1515
+ if (defined('WP_MAX_MEMORY_LIMIT ')) {
1516
+ DebugEcho("WP_MAX_MEMORY_LIMIT: " . WP_MAX_MEMORY_LIMIT, $force_display);
1517
+ } else {
1518
+ DebugEcho("WP_MAX_MEMORY_LIMIT: 256M (default)", $force_display);
1519
+ }
1520
+
1521
+ if (defined('WP_MEMORY_LIMIT')) {
1522
+ DebugEcho("WP_MEMORY_LIMIT: " . WP_MEMORY_LIMIT, $force_display);
1523
+ } else {
1524
+ DebugEcho("WP_MEMORY_LIMIT: 32M (default)", $force_display);
1525
+ }
1526
+
1527
+ DebugEcho("DISABLE_WP_CRON: " . (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON === true ? 'On' : 'Off'), $force_display);
1528
+ DebugEcho("ALTERNATE_WP_CRON: " . (defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON === true ? 'On' : 'Off'), $force_display);
1529
+
1530
+ if (defined('WP_CRON_LOCK_TIMEOUT')) {
1531
+ DebugEcho("WP_CRON_LOCK_TIMEOUT: " . WP_CRON_LOCK_TIMEOUT, $force_display);
1532
+ }
1533
+
1534
+ if ($g_postie_init->postie_IsIconvInstalled()) {
1535
+ DebugEcho("iconv: present", $force_display);
1536
+ } else {
1537
+ DebugEcho("iconv: missing", $force_display);
1538
+ }
1539
+
1540
+ DebugEcho('Active plugins', $force_display);
1541
+ DebugDump(get_option('active_plugins'));
1542
+
1543
+ DebugEcho("Postie is in " . plugin_dir_path(__FILE__), $force_display);
1544
+ DebugEcho("Postie Version: " . POSTIE_VERSION, $force_display);
1545
+ DebugEcho("POSTIE_DEBUG: " . ($this->is_debugmode() ? 'On' : 'Off'), $force_display);
1546
+ }
1547
+
1548
+ function is_debugmode() {
1549
+ return (defined('POSTIE_DEBUG') && POSTIE_DEBUG == true);
1550
+ }
1551
+
1552
+ function log_onscreen($data) {
1553
+ if (php_sapi_name() == "cli") {
1554
+ print( "$data\n");
1555
+ } else {
1556
+ //flush the buffers
1557
+ while (ob_get_level() > 0) {
1558
+ ob_end_flush();
1559
+ }
1560
+ print( "<pre>" . htmlspecialchars($data) . "</pre>\n");
1561
+ }
1562
+ }
1563
+
1564
+ function log_error($v) {
1565
+ $this->log_onscreen($v);
1566
+ error_log("Postie [error]: $v");
1567
+ }
1568
+
1569
+ function log_debug($data) {
1570
+ error_log("Postie [debug]: $data");
1571
+ }
1572
+
1573
+ function connection_info($config) {
1574
+ $conninfo = array();
1575
+ $conninfo['mail_server'] = $config['mail_server'];
1576
+ $conninfo['mail_port'] = $config['mail_server_port'];
1577
+ $conninfo['mail_user'] = $config['mail_userid'];
1578
+ $conninfo['mail_password'] = $config['mail_password'];
1579
+ $conninfo['mail_protocol'] = $config['input_protocol'];
1580
+ $conninfo['mail_tls'] = $config['email_tls'];
1581
+ $conninfo['email_delete_after_processing'] = $config['delete_mail_after_processing'];
1582
+ $conninfo['email_max'] = $config['maxemails'];
1583
+ $conninfo['email_ignore_state'] = $config['ignore_mail_state'];
1584
+
1585
+ return apply_filters('postie_preconnect', $conninfo);
1586
+ }
1587
+
1588
+ function test_config() {
1589
+
1590
+ wp_get_current_user();
1591
+
1592
+ if (!current_user_can('manage_options')) {
1593
+ DebugEcho("non-admin tried to set options");
1594
+ echo "<h2> Sorry only admin can run this file</h2>";
1595
+ exit();
1596
+ }
1597
+
1598
+ $config = postie_config_read();
1599
+ if (true == $config['postie_log_error'] || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
1600
+ add_action('postie_log_error', array($this, 'log_error'));
1601
+ }
1602
+ if (true == $config['postie_log_debug'] && !defined('POSTIE_DEBUG')) {
1603
+ define('POSTIE_DEBUG', true);
1604
+ }
1605
+ if (true == $config['postie_log_debug'] || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
1606
+ add_action('postie_log_debug', array($this, 'log_debug'));
1607
+ }
1608
+ ?>
1609
+ <div class="wrap">
1610
+ <h1>Postie Configuration Test</h1>
1611
+ <?php
1612
+ $this->postie_environment(true);
1613
+ ?>
1614
+
1615
+ <h2>Clock</h2>
1616
+ <p>This shows what time it would be if you posted right now</p>
1617
+ <?php
1618
+ $wptz = get_option('gmt_offset');
1619
+ $wptzs = get_option('timezone_string');
1620
+ DebugEcho("Wordpress timezone: $wptzs ($wptz)", true);
1621
+ DebugEcho("Current time: " . current_time('mysql'), true);
1622
+ DebugEcho("Current time (gmt): " . current_time('mysql', 1), true);
1623
+ DebugEcho("Postie time correction: {$config['time_offset']}", true);
1624
+ $offsetdate = strtotime(current_time('mysql')) + ($config['use_time_offset'] ? $config['time_offset'] * 3600 : 0);
1625
+
1626
+ DebugEcho("Post time: " . date('Y-m-d H:i:s', $offsetdate), true);
1627
+ ?>
1628
+ <h2>Encoding</h2>
1629
+ <?php
1630
+ $default_charset = ini_get('default_charset');
1631
+ if (version_compare(phpversion(), '5.6.0', '<')) {
1632
+ if (empty($default_charset)) {
1633
+ DebugEcho("default_charset: WARNING no default_charset set see http://php.net/manual/en/ini.core.php#ini.default-charset", true);
1634
+ } else {
1635
+ DebugEcho("default_charset: $default_charset", true);
1636
+ }
1637
+ } else {
1638
+ if (empty($default_charset)) {
1639
+ DebugEcho("default_charset: UTF-8 (default)", true);
1640
+ } else {
1641
+ DebugEcho("default_charset: $default_charset", true);
1642
+ }
1643
+ }
1644
+
1645
+ if (defined('DB_CHARSET')) {
1646
+ DebugEcho("DB_CHARSET: " . DB_CHARSET, true);
1647
+ } else {
1648
+ DebugEcho("DB_CHARSET: undefined (utf8)", true);
1649
+ }
1650
+
1651
+ if (defined('DB_COLLATE')) {
1652
+ $db_collate = DB_COLLATE;
1653
+ if (empty($db_collate)) {
1654
+ DebugEcho("DB_COLLATE: database default", true);
1655
+ } else {
1656
+ DebugEcho("DB_COLLATE: " . DB_COLLATE, true);
1657
+ }
1658
+ }
1659
+
1660
+ DebugEcho("WordPress encoding: " . esc_attr(get_option('blog_charset')), true);
1661
+ DebugEcho("Postie encoding: " . $config['message_encoding'], true);
1662
+ ?>
1663
+ <h2>Images</h2>
1664
+ <?php
1665
+ DebugEcho("registered image sizes");
1666
+ DebugDump(get_intermediate_image_sizes());
1667
+ ?>
1668
+ <h2>Connect to Mail Host</h2>
1669
+ <?php
1670
+ DebugEcho("Postie connection: " . $config['input_connection'], true);
1671
+ DebugEcho("Postie protocol: " . $config['input_protocol'], true);
1672
+ DebugEcho("Postie server: " . $config['mail_server'], true);
1673
+ DebugEcho("Postie port: " . $config['mail_server_port'], true);
1674
+
1675
+ if (!$config['mail_server'] || !$config['mail_server_port'] || !$config['mail_userid']) {
1676
+ EchoError("FAIL - server settings not complete");
1677
+ }
1678
+
1679
+ $conninfo = $this->connection_info($config);
1680
+ if ($this->is_debugmode()) {
1681
+ fCore::enableDebugging(true);
1682
+ fCore::registerDebugCallback('DebugEcho');
1683
+ }
1684
+
1685
+ switch (strtolower($config['input_protocol'])) {
1686
+ case 'imap':
1687
+ case 'imap-ssl':
1688
+ try {
1689
+ if ($config['input_connection'] == 'curl') {
1690
+ $conn = new pCurlConnection('imap', $conninfo['mail_server'], $conninfo['mail_user'], $conninfo['mail_password'], $conninfo['mail_port'], ($conninfo['mail_protocol'] == 'imap-ssl' || $conninfo['mail_protocol'] == 'pop3-ssl'));
1691
+ } else {
1692
+ $conn = new pSocketConnection('imap', $conninfo['mail_server'], $conninfo['mail_user'], $conninfo['mail_password'], $conninfo['mail_port'], ($conninfo['mail_protocol'] == 'imap-ssl' || $conninfo['mail_protocol'] == 'pop3-ssl'));
1693
+ }
1694
+ $srv = new pImapMailServer($conn);
1695
+ $mailbox = new fMailbox('imap', $conn, $srv);
1696
+ $m = $mailbox->countMessages();
1697
+ DebugEcho("Successful " . strtoupper($config['input_protocol']) . " connection on port {$config['mail_server_port']}", true);
1698
+ DebugEcho("# of waiting messages: $m", true);
1699
+ $mailbox->close();
1700
+ } catch (Exception $e) {
1701
+ EchoError("Unable to connect. The server said: " . $e->getMessage());
1702
+ }
1703
+ break;
1704
+
1705
+ case 'pop3':
1706
+ case 'pop3-ssl':
1707
+ try {
1708
+ if ($config['input_connection'] == 'curl') {
1709
+ $conn = new pCurlConnection('pop3', $conninfo['mail_server'], $conninfo['mail_user'], $conninfo['mail_password'], $conninfo['mail_port'], ($conninfo['mail_protocol'] == 'imap-ssl' || $conninfo['mail_protocol'] == 'pop3-ssl'), 30);
1710
+ } else {
1711
+ $conn = new pSocketConnection('pop3', $conninfo['mail_server'], $conninfo['mail_user'], $conninfo['mail_password'], $conninfo['mail_port'], ($conninfo['mail_protocol'] == 'imap-ssl' || $conninfo['mail_protocol'] == 'pop3-ssl'));
1712
+ }
1713
+ $srv = new pPop3MailServer($conn);
1714
+ $mailbox = new fMailbox('pop3', $conn, $srv);
1715
+ $m = $mailbox->countMessages();
1716
+ DebugEcho("Successful " . strtoupper($config['input_protocol']) . " connection on port {$config['mail_server_port']}", true);
1717
+ DebugEcho("# of waiting messages: $m", true);
1718
+ $mailbox->close();
1719
+ } catch (Exception $e) {
1720
+ EchoError("Unable to connect. The server said:");
1721
+ EchoError($e->getMessage());
1722
+ }
1723
+ break;
1724
+ default:
1725
+ EchoError("Unable to connect. Invalid setup");
1726
+ break;
1727
+ }
1728
+ ?>
1729
+ </div>
1730
+ <?php
1731
+ DebugEcho("Test complete");
1732
+ }
1733
+
1734
+ }
1735
+
1736
+ $g_postie = new Postie();
postie.php CHANGED
@@ -4,18 +4,19 @@
4
  Plugin Name: Postie
5
  Plugin URI: http://PostiePlugin.com/
6
  Description: Create posts via email. Significantly upgrades the Post by Email features of WordPress.
7
- Version: 1.8.45
8
  Author: Wayne Allen
9
  Author URI: http://PostiePlugin.com/
10
- License: GPL2
11
  Text Domain: postie
12
  */
13
 
14
- /* Copyright (c) 2015 Wayne Allen (email : wayne@allens-home.com)
15
 
16
- This program is free software; you can redistribute it and/or modify
17
- it under the terms of the GNU General Public License, version 2, as
18
- published by the Free Software Foundation.
 
19
 
20
  This program is distributed in the hope that it will be useful,
21
  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -23,214 +24,205 @@
23
  GNU General Public License for more details.
24
 
25
  You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
  */
29
 
30
  /*
31
- $Id: postie.php 1682901 2017-06-21 19:47:20Z WayneAllen $
32
  */
33
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fException.php");
34
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fUnexpectedException.php");
35
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fExpectedException.php");
36
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fConnectivityException.php");
37
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fValidationException.php");
38
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fProgrammerException.php");
39
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fEnvironmentException.php");
40
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fCore.php");
41
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fMailbox.php");
42
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fEmail.php");
43
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/pConnection.php");
44
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/pCurlConnection.php");
45
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/pSocketConnection.php");
46
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/pMailServer.php");
47
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/pImapMailServer.php");
48
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/pPop3MailServer.php");
49
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/autolink.php");
50
-
51
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "postie-functions.php");
52
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "postie-api.php");
53
-
54
- require_once(ABSPATH . 'wp-admin/includes/file.php');
55
- require_once(ABSPATH . 'wp-admin/includes/image.php');
56
- require_once(ABSPATH . 'wp-admin/includes/media.php');
57
- require_once(ABSPATH . 'wp-admin/includes/file.php'); //wp_tempnam()
58
-
59
- require_once( ABSPATH . WPINC . '/class-oembed.php' );
60
-
61
- if (!function_exists('file_get_html')) {
62
- require_once (plugin_dir_path(__FILE__) . 'lib/simple_html_dom.php');
63
  }
64
 
65
- define('POSTIE_VERSION', '1.8.45');
66
- define("POSTIE_ROOT", dirname(__FILE__));
67
- define("POSTIE_URL", WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)));
68
-
69
- //register the hooks early in the page in case some method needs the result of one of them (i.e. cron_schedules)
70
- add_action('init', 'postie_disable_kses_content', 20);
71
- add_action('check_postie_hook', 'check_postie');
72
- add_action('parse_request', 'postie_parse_request');
73
- add_action('admin_init', 'postie_admin_init');
74
- add_action('admin_menu', 'postie_admin_menu');
75
- add_action('admin_head', 'postie_admin_head');
76
-
77
- add_filter('whitelist_options', 'postie_whitelist');
78
- add_filter('cron_schedules', 'postie_more_reccurences');
79
- add_filter('query_vars', 'postie_query_vars');
80
- add_filter("plugin_action_links_" . plugin_basename(__FILE__), 'postie_plugin_action_links');
81
- add_filter('plugin_row_meta', 'postie_plugin_row_meta', 10, 2);
82
-
83
- register_activation_hook(__FILE__, 'activate_postie');
84
- register_activation_hook(__FILE__, 'postie_cron');
85
- register_deactivation_hook(__FILE__, 'postie_decron');
86
-
87
- //Add Menu Configuration
88
- if (is_admin()) {
89
- if (function_exists('load_plugin_textdomain')) {
90
-
91
- function postie_load_domain() {
92
- load_plugin_textdomain('postie', false, dirname(plugin_basename(__FILE__)) . '/languages/');
93
- }
94
 
95
- add_action('init', 'postie_load_domain');
96
- }
97
- postie_warnings();
98
- }
99
 
100
- //****************** functions *************************
101
- function postie_admin_head() {
102
- ?>
103
- <style type="text/css">
104
- #adminmenu #toplevel_page_postie-settings div.wp-menu-image:before {
105
- content: "\f466";
106
- }
107
- </style>
108
- <?php
109
 
110
- }
111
 
112
- function postie_plugin_row_meta($links, $file) {
113
- if (strpos($file, plugin_basename(__FILE__)) !== false) {
114
- $new_links = array(
115
- '<a href="http://postieplugin.com/" target="_blank">Support</a>',
116
- '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HPK99BJ88V4C2" target="_blank">Donate</a>'
117
- );
 
 
118
 
119
- $links = array_merge($links, $new_links);
120
- }
 
 
 
 
121
 
122
- return $links;
123
- }
 
 
124
 
125
- function postie_plugin_action_links($links) {
126
- $links[] = '<a href="admin.php?page=postie-settings">Settings</a>';
127
- return $links;
128
- }
129
 
130
- function postie_query_vars($vars) {
131
- $vars[] = 'postie';
132
- return $vars;
133
- }
134
 
135
- function postie_parse_request($wp) {
136
- if (array_key_exists('postie', $wp->query_vars)) {
137
- switch ($wp->query_vars['postie']) {
138
- case 'get-mail':
139
- postie_get_mail();
140
- die();
141
- case 'test-config':
142
- postie_test_config();
143
- die();
144
- default :
145
- dir('Unknown option: ' . $wp->query_vars['postie']);
146
  }
147
- }
148
- }
149
 
150
- function postie_admin_init() {
151
- wp_register_style('postie-style', plugins_url('css/style.css', __FILE__));
152
- register_setting('postie-settings', 'postie-settings', 'config_ValidateSettings');
153
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
- function postie_admin_menu() {
156
- $page = add_menu_page('Postie', 'Postie', 'manage_options', 'postie-settings', 'postie_loadjs_options_page');
157
- add_action('admin_print_styles-' . $page, 'postie_admin_styles');
158
- }
 
159
 
160
- function postie_loadjs_options_page() {
161
- require_once POSTIE_ROOT . '/config_form.php';
162
- }
163
 
164
- function postie_admin_page() {
165
- if (!current_user_can('manage_options')) {
166
- wp_die(__('You do not have sufficient permissions to access this page.', 'postie'));
167
- }
168
- include 'config_form.php';
169
- }
170
 
171
- function postie_admin_styles() {
172
- wp_enqueue_style('postie-style');
173
- }
 
 
 
174
 
175
- /*
176
- * called by WP when activating the plugin
177
- * Note that you can't do any output during this funtion or activation
178
- * will fail on some systems. This means no DebugEcho, EchoInfo or DebugDump.
179
- */
180
 
181
- function activate_postie() {
182
- static $init = false;
183
- $options = config_Read();
184
 
185
- if ($init) {
186
- return;
187
- }
 
 
 
 
 
 
 
 
 
 
 
188
 
189
- if (!$options) {
190
- $options = array();
191
- }
192
- $default_options = config_GetDefaults();
193
- $old_config = array();
194
 
195
- $result = config_GetOld();
196
- if (is_array($result)) {
197
- foreach ($result as $key => $val) {
198
- $old_config[strtolower($key)] = $val;
199
  }
200
- }
201
 
202
- // overlay the options on top of each other:
203
- // the current value of $options takes priority over the $old_config, which takes priority over the $default_options
204
- $options = array_merge($default_options, $old_config, $options);
205
- $options = config_ValidateSettings($options);
206
- update_option('postie-settings', $options);
207
- $init = true;
208
- }
 
209
 
210
- /**
211
- * set up actions to show relevant warnings,
212
- * if mail server is not set, or if IMAP extension is not available
213
- */
214
- function postie_warnings() {
 
 
215
 
216
- $config = config_Read();
 
 
 
 
 
 
 
 
 
 
 
217
 
218
- if ((empty($config['mail_server']) ||
219
- empty($config['mail_server_port']) ||
220
- empty($config['mail_userid']) ||
221
- empty($config['mail_password'])
222
- ) && !isset($_POST['submit'])) {
223
 
224
- function postie_enter_info() {
225
- echo "<div id='postie-info-warning' class='updated fade'><p><strong>" . __('Postie is almost ready.', 'postie') . "</strong> "
226
- . sprintf(__('You must <a href="%1$s">enter your email settings</a> for it to work.', 'postie'), "admin.php?page=postie-settings")
227
- . "</p></div> ";
228
  }
229
 
230
- add_action('admin_notices', 'postie_enter_info');
231
- }
 
 
232
 
233
- if (postie_isMarkdownInstalled() && $config['prefer_text_type'] == 'html') {
 
 
 
 
 
 
 
 
 
 
 
 
234
 
235
  function postie_markdown_warning() {
236
  echo "<div id='postie-lst-warning' class='error'><p><strong>";
@@ -238,10 +230,11 @@ function postie_warnings() {
238
  echo "</strong></p></div>";
239
  }
240
 
241
- add_action('admin_notices', 'postie_markdown_warning');
242
- }
243
-
244
- if (!postie_IsIconvInstalled()) {
 
245
 
246
  function postie_iconv_warning() {
247
  echo "<div id='postie-lst-warning' class='error'><p><strong>";
@@ -249,27 +242,12 @@ function postie_warnings() {
249
  echo "</strong></p></div>";
250
  }
251
 
252
- add_action('admin_notices', 'postie_iconv_warning');
253
- }
254
-
255
- if (!fCore::checkVersion('5.2.0')) {
256
-
257
  function postie_php_warning() {
258
  echo "<div id='postie-lst-warning' class='error'><p><strong>";
259
  _e("Warning! Postie requires that PHP be verion 5.2 or higher. You have version " . phpversion(), 'postie');
260
  echo "</strong></p></div>";
261
  }
262
 
263
- add_action('admin_notices', 'postie_php_warning');
264
- }
265
-
266
- if (function_exists('curl_version')) {
267
- $cv = curl_version();
268
- } else {
269
- $cv = '1.0.0';
270
- }
271
- if ($config['input_connection'] == 'curl' && !version_compare($cv['version'], '7.30.0', 'ge')) {
272
-
273
  function postie_curl_warning() {
274
  $cv = curl_version();
275
  echo "<div id='postie-lst-warning' class='error'><p><strong>";
@@ -277,34 +255,74 @@ function postie_warnings() {
277
  echo "</strong></p></div>";
278
  }
279
 
280
- add_action('admin_notices', 'postie_curl_warning');
281
- }
282
-
283
- $userdata = WP_User::get_data_by('login', $config['admin_username']);
284
- if (!$userdata) {
285
-
286
  function postie_adminuser_warning() {
287
  echo "<div id='postie-mbstring-warning' class='error'><p><strong>";
288
  echo __('Warning: the Default Poster is not a valid WordPress login. Postie may reject emails if this is not corrected.', 'postie');
289
  echo "</strong></p></div>";
290
  }
291
 
292
- add_action('admin_notices', 'postie_adminuser_warning');
293
- }
294
- }
 
295
 
296
- function postie_disable_kses_content() {
297
- remove_filter('content_save_pre', 'wp_filter_post_kses');
298
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
299
 
300
- function postie_whitelist($options) {
301
- $added = array('postie-settings' => array('postie-settings'));
302
- $options = add_option_whitelist($added, $options);
303
- return $options;
304
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
 
306
- //don't use DebugEcho or EchoInfo here as it is not defined when called as an action
307
- function check_postie() {
308
- //error_log("check_postie");
309
- postie_get_mail();
310
  }
4
  Plugin Name: Postie
5
  Plugin URI: http://PostiePlugin.com/
6
  Description: Create posts via email. Significantly upgrades the Post by Email features of WordPress.
7
+ Version: 1.9.1
8
  Author: Wayne Allen
9
  Author URI: http://PostiePlugin.com/
10
+ License: GPL3
11
  Text Domain: postie
12
  */
13
 
14
+ /* Copyright (c) 2015-17 Wayne Allen (email : wayne@postieplugin.com)
15
 
16
+ This program is free software: you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License as published by
18
+ the Free Software Foundation, either version 3 of the License, or
19
+ (at your option) any later version.
20
 
21
  This program is distributed in the hope that it will be useful,
22
  but WITHOUT ANY WARRANTY; without even the implied warranty of
24
  GNU General Public License for more details.
25
 
26
  You should have received a copy of the GNU General Public License
27
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
 
28
  */
29
 
30
  /*
31
+ $Id: postie.php 1684501 2017-06-23 19:59:20Z WayneAllen $
32
  */
33
+
34
+ if (!defined('WPINC')) {
35
+ die; // Exit if accessed directly
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  }
37
 
38
+ define('POSTIE_VERSION', '1.9.1');
39
+ define('POSTIE_ROOT', dirname(__FILE__));
40
+ define('POSTIE_URL', WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'postie-compatibility.php');
43
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'postie-api.php');
 
 
44
 
45
+ if (!class_exists('PostieInit')) {
 
 
 
 
 
 
 
 
46
 
47
+ class PostieInit {
48
 
49
+ public function __construct() {
50
+ //WordPress Actions
51
+ add_action('init', array($this, 'init_action'), 20);
52
+ add_action('parse_request', array($this, 'parse_request_action'));
53
+ add_action('admin_init', array($this, 'admin_init_action'));
54
+ add_action('admin_menu', array($this, 'admin_menu_action'));
55
+ add_action('admin_head', array($this, 'admin_head_action'));
56
+ add_action('plugins_loaded', array($this, 'plugins_loaded_action'));
57
 
58
+ //WordPress filters
59
+ add_filter('whitelist_options', array($this, 'whitelist_options_filter'));
60
+ add_filter('cron_schedules', array($this, 'cron_schedules_filter'));
61
+ add_filter('query_vars', array($this, 'query_vars_filter'));
62
+ add_filter("plugin_action_links_" . plugin_basename(__FILE__), array($this, 'plugin_action_links_filter'));
63
+ add_filter('plugin_row_meta', array($this, 'plugin_row_meta_filter'), 10, 2);
64
 
65
+ //WordPress Hooks
66
+ register_activation_hook(__FILE__, array('PostieInit', 'postie_activate_hook'));
67
+ register_activation_hook(__FILE__, array('PostieInit', 'postie_cron_hook'));
68
+ register_deactivation_hook(__FILE__, array('PostieInit', 'postie_decron_hook'));
69
 
70
+ //Postie actions
71
+ add_action('check_postie_hook', 'postie_check');
 
 
72
 
73
+ if (is_admin()) {
74
+ $this->postie_warnings();
75
+ }
76
+ }
77
 
78
+ static function postie_activate_hook() {
79
+ /*
80
+ * called by WP when activating the plugin
81
+ * Note that you can't do any output during this funtion or activation
82
+ * will fail on some systems. This means no DebugEcho, EchoInfo or DebugDump.
83
+ */
 
 
 
 
 
84
  }
 
 
85
 
86
+ static function postie_cron_hook($interval = false) {
87
+ //Do not echo output in filters, it seems to break some installs
88
+ //error_log("postie_cron: setting up cron task: $interval");
89
+ //$schedules = wp_get_schedules();
90
+ //error_log("postie_cron\n" . print_r($schedules, true));
91
+
92
+ if (empty($interval)) {
93
+ $interval = 'hourly';
94
+ //error_log("Postie: setting up cron task: defaulting to hourly");
95
+ }
96
+
97
+ if ($interval == 'manual') {
98
+ PostieInit::postie_decron_hook();
99
+ //error_log("postie_cron: clearing cron (manual)");
100
+ } else {
101
+ if ($interval != wp_get_schedule('check_postie_hook')) {
102
+ PostieInit::postie_decron_hook(); //remove existing
103
+ //try to create the new schedule with the first run in 5 minutes
104
+ if (false === wp_schedule_event(time() + 5 * 60, $interval, 'check_postie_hook')) {
105
+ //error_log("postie_cron: Failed to set up cron task: $interval");
106
+ } else {
107
+ //error_log("postie_cron: Set up cron task: $interval");
108
+ }
109
+ } else {
110
+ //error_log("postie_cron: OK: $interval");
111
+ //don't need to do anything, cron already scheduled
112
+ }
113
+ }
114
+ }
115
 
116
+ static function postie_decron_hook() {
117
+ //don't use DebugEcho or EchoInfo here as it is not defined when called as a hook
118
+ //error_log("postie_decron: clearing cron");
119
+ wp_clear_scheduled_hook('check_postie_hook');
120
+ }
121
 
122
+ function plugins_loaded_action() {
123
+ load_plugin_textdomain('postie', false, dirname(plugin_basename(__FILE__)) . '/languages/');
124
+ }
125
 
126
+ function init_action() {
127
+ remove_filter('content_save_pre', 'wp_filter_post_kses');
128
+ }
 
 
 
129
 
130
+ function plugin_row_meta_filter($links, $file) {
131
+ if (strpos($file, plugin_basename(__FILE__)) !== false) {
132
+ $new_links = array(
133
+ '<a href="http://postieplugin.com/" target="_blank">Support</a>',
134
+ '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HPK99BJ88V4C2" target="_blank">Donate</a>'
135
+ );
136
 
137
+ $links = array_merge($links, $new_links);
138
+ }
 
 
 
139
 
140
+ return $links;
141
+ }
 
142
 
143
+ function parse_request_action($wp) {
144
+ if (array_key_exists('postie', $wp->query_vars)) {
145
+ switch ($wp->query_vars['postie']) {
146
+ case 'get-mail':
147
+ postie_get_mail();
148
+ die();
149
+ case 'test-config':
150
+ postie_test_config();
151
+ die();
152
+ default :
153
+ dir('Unknown option: ' . $wp->query_vars['postie']);
154
+ }
155
+ }
156
+ }
157
 
158
+ function admin_init_action() {
159
+ wp_register_style('postie-style', plugins_url('css/style.css', __FILE__));
160
+ register_setting('postie-settings', 'postie-settings', array(new PostieConfig(), 'config_ValidateSettings'));
161
+ }
 
162
 
163
+ function admin_menu_action() {
164
+ $page = add_menu_page('Postie', 'Postie', 'manage_options', 'postie-settings', array($this, 'postie_show_config_page'));
165
+ add_action('admin_print_styles-' . $page, array($this, 'postie_admin_styles'));
 
166
  }
 
167
 
168
+ function admin_head_action() {
169
+ ?>
170
+ <style type="text/css">
171
+ #adminmenu #toplevel_page_postie-settings div.wp-menu-image:before {
172
+ content: "\f466";
173
+ }
174
+ </style>
175
+ <?php
176
 
177
+ }
178
+
179
+ function whitelist_options_filter($options) {
180
+ $added = array('postie-settings' => array('postie-settings'));
181
+ $options = add_option_whitelist($added, $options);
182
+ return $options;
183
+ }
184
 
185
+ function cron_schedules_filter($schedules) {
186
+ //Do not echo output in filters, it seems to break some installs
187
+ //error_log("cron_schedules_filter: setting cron schedules");
188
+ $schedules['weekly'] = array('interval' => (60 * 60 * 24 * 7), 'display' => __('Once Weekly', 'postie'));
189
+ $schedules['twiceperhour'] = array('interval' => 60 * 30, 'display' => __('Twice per hour', 'postie'));
190
+ $schedules['tenminutes'] = array('interval' => 60 * 10, 'display' => __('Every 10 minutes', 'postie'));
191
+ $schedules['fiveminutes'] = array('interval' => 60 * 5, 'display' => __('Every 5 minutes', 'postie'));
192
+ $schedules['oneminute'] = array('interval' => 60 * 1, 'display' => __('Every 1 minute', 'postie'));
193
+ $schedules['thirtyseconds'] = array('interval' => 30, 'display' => __('Every 30 seconds', 'postie'));
194
+ $schedules['fifteenseconds'] = array('interval' => 15, 'display' => __('Every 15 seconds', 'postie'));
195
+ return $schedules;
196
+ }
197
 
198
+ function query_vars_filter($vars) {
199
+ $vars[] = 'postie';
200
+ return $vars;
201
+ }
 
202
 
203
+ function plugin_action_links_filter($links) {
204
+ $links[] = '<a href="admin.php?page=postie-settings">Settings</a>';
205
+ return $links;
 
206
  }
207
 
208
+ function postie_show_config_page() {
209
+ global $g_postie;
210
+ require_once POSTIE_ROOT . '/config_form.php';
211
+ }
212
 
213
+ function postie_admin_styles() {
214
+ wp_enqueue_style('postie-style');
215
+ }
216
+
217
+ /**
218
+ * This function looks for markdown which causes problems with postie
219
+ */
220
+ function postie_isMarkdownInstalled() {
221
+ if (in_array("markdown.php", get_option("active_plugins"))) {
222
+ return true;
223
+ }
224
+ return false;
225
+ }
226
 
227
  function postie_markdown_warning() {
228
  echo "<div id='postie-lst-warning' class='error'><p><strong>";
230
  echo "</strong></p></div>";
231
  }
232
 
233
+ function postie_enter_info() {
234
+ echo "<div id='postie-info-warning' class='updated fade'><p><strong>" . __('Postie is almost ready.', 'postie') . "</strong> "
235
+ . sprintf(__('You must <a href="%1$s">enter your email settings</a> for it to work.', 'postie'), "admin.php?page=postie-settings")
236
+ . "</p></div> ";
237
+ }
238
 
239
  function postie_iconv_warning() {
240
  echo "<div id='postie-lst-warning' class='error'><p><strong>";
242
  echo "</strong></p></div>";
243
  }
244
 
 
 
 
 
 
245
  function postie_php_warning() {
246
  echo "<div id='postie-lst-warning' class='error'><p><strong>";
247
  _e("Warning! Postie requires that PHP be verion 5.2 or higher. You have version " . phpversion(), 'postie');
248
  echo "</strong></p></div>";
249
  }
250
 
 
 
 
 
 
 
 
 
 
 
251
  function postie_curl_warning() {
252
  $cv = curl_version();
253
  echo "<div id='postie-lst-warning' class='error'><p><strong>";
255
  echo "</strong></p></div>";
256
  }
257
 
 
 
 
 
 
 
258
  function postie_adminuser_warning() {
259
  echo "<div id='postie-mbstring-warning' class='error'><p><strong>";
260
  echo __('Warning: the Default Poster is not a valid WordPress login. Postie may reject emails if this is not corrected.', 'postie');
261
  echo "</strong></p></div>";
262
  }
263
 
264
+ function postie_IsIconvInstalled($display = true) {
265
+ $function_list = array('iconv');
266
+ return($this->postie_HasFunctions($function_list, $display));
267
+ }
268
 
269
+ /**
270
+ * Handles verifying that a list of functions exists
271
+ * @return boolean
272
+ * @param array
273
+ */
274
+ function postie_HasFunctions($function_list, $display = true) {
275
+ foreach ($function_list as $function) {
276
+ if (!function_exists($function)) {
277
+ if ($display) {
278
+ EchoError("Missing $function");
279
+ }
280
+ return false;
281
+ }
282
+ }
283
+ return true;
284
+ }
285
 
286
+ function postie_warnings() {
287
+ $config = postie_config_read();
288
+
289
+ if ((empty($config['mail_server']) ||
290
+ empty($config['mail_server_port']) ||
291
+ empty($config['mail_userid']) ||
292
+ empty($config['mail_password'])
293
+ ) && !isset($_POST['submit'])) {
294
+
295
+ add_action('admin_notices', array($this, 'postie_enter_info'));
296
+ }
297
+
298
+ if ($this->postie_isMarkdownInstalled() && $config['prefer_text_type'] == 'html') {
299
+ add_action('admin_notices', array($this, 'postie_markdown_warning'));
300
+ }
301
+
302
+ if (!$this->postie_IsIconvInstalled()) {
303
+ add_action('admin_notices', array($this, 'postie_iconv_warning'));
304
+ }
305
+
306
+ if (!fCore::checkVersion('5.2.0')) {
307
+ add_action('admin_notices', array($this, 'postie_php_warning'));
308
+ }
309
+
310
+ if (function_exists('curl_version')) {
311
+ $cv = curl_version();
312
+ } else {
313
+ $cv = '1.0.0';
314
+ }
315
+ if ($config['input_connection'] == 'curl' && !version_compare($cv['version'], '7.30.0', 'ge')) {
316
+ add_action('admin_notices', array($this, 'postie_curl_warning'));
317
+ }
318
+
319
+ $userdata = WP_User::get_data_by('login', $config['admin_username']);
320
+ if (!$userdata) {
321
+ add_action('admin_notices', array($this, 'postie_adminuser_warning'));
322
+ }
323
+ }
324
+
325
+ }
326
 
327
+ $g_postie_init = new PostieInit();
 
 
 
328
  }
readme.txt CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.8
9
- Stable tag: 1.8.45
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -242,6 +242,14 @@ All script, style and body tags are stripped from html emails.
242
  Attachments are now processed in the order they were attached.
243
 
244
  == CHANGELOG ==
 
 
 
 
 
 
 
 
245
  = 1.8.45 (2017-06-21) =
246
  * Feature: If image placement directive has a caption, update the image metadata to include the caption.
247
  * Fix: Only process delay tag if date was found in header
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.8
9
+ Stable tag: 1.9.1
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
242
  Attachments are now processed in the order they were attached.
243
 
244
  == CHANGELOG ==
245
+ = 1.9.1 (2017-06-28) =
246
+ * Feature: Add postie_file_added_pre action
247
+ * Fix: improvements to tag detection
248
+ * Fix: tags may be specified multiple times
249
+ * Fix: significant code restructure to bring Postie in line with current coding practices
250
+ * Fix: move signature removal to before newline filtering
251
+ * Fix: signature removal was deleting all text if the matching regex had whitespace characters
252
+
253
  = 1.8.45 (2017-06-21) =
254
  * Feature: If image placement directive has a caption, update the image metadata to include the caption.
255
  * Fix: Only process delay tag if date was found in header