├── .gitignore
├── LICENSE
├── README.md
├── _build
├── build.config.php
├── config.json
├── data
│ └── .gitignore
├── gpm_resolvers
│ └── gpm.resolve.tv_templates.php
├── includes
│ └── .gitignore
├── resolvers
│ └── .gitignore
└── setup.options.php
├── _packages
└── ampify-0.2.1-dev1.transport.zip
├── config.core.php
└── core
└── components
└── ampify
├── docs
├── changelog.txt
├── license.txt
└── readme.txt
├── elements
├── .gitignore
├── plugins
│ └── ampify.plugin.php
├── snippets
│ └── ampfilter.snippet.php
└── templates
│ └── amp_template.template.tpl
├── index.php
└── model
├── ampify
└── ampify.class.php
└── modx-amp
├── class-amp-content.php
└── includes
├── lib
└── class-fastimage.php
├── sanitizers
├── class-amp-audio-sanitizer.php
├── class-amp-base-sanitizer.php
├── class-amp-blacklist-sanitizer.php
├── class-amp-iframe-sanitizer.php
├── class-amp-img-sanitizer.php
└── class-amp-video-sanitizer.php
└── utils
├── class-amp-dom-utils.php
└── class-amp-html-utils.php
/.gitignore:
--------------------------------------------------------------------------------
1 | _build/build.config.php
2 | config.core.php
3 | .idea
4 | .settings
5 | .project
6 | _packages/*.*
7 | !_packages/.gitignore
8 | !_packages/*.zip
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser 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 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Ampify
2 |
3 | Effortless Google [Accelerated Mobile Pages](https://www.ampproject.org/), aka "AMP", for MODX Revolution.
4 |
5 | ## What is it?
6 |
7 | **Ampify** is a MODX Revolution Extra that includes a toolset to easily serve AMP HTML for Google's search results pages. The package includes a Plugin, and a sample AMP Template.
8 |
9 | ## What does it do?
10 |
11 | When triggered, the Plugin switches the Template used by the currently requested Resource, to the specified AMP Template.
12 |
13 | ## I want details
14 |
15 | The Ampify Plugin fires in two different modes: 'param' and 'context'.
16 |
17 | ### Context Mode
18 |
19 | In 'context' mode, the Plugin action is triggered when a request is made to a specified AMP Context. (Context routing and setup are outside the scope of this Extra, but there's an [example implementation](#example-implementation) below.)
20 |
21 | The AMP Context will automatically route requests to Resources that have been added to the ContextResource table. Resources are added automatically when they are saved. In future versions, a CMP will be provided to add/remove Resources from the table, with bulk actions.
22 |
23 | This mode has the advantage of being able to include and exclude Resources from having an AMP view.
24 |
25 | However, it has the disadvantage that AMP views will be rendered at a different URI than the canonical. At the minimum, the Context's base_url will be prefixed, for example: `/amp/resource-alias.html` versus `/resource-alias.html`
26 |
27 | Also, if you have a lot of pre-existing Resources for which you want to provide an AMP view, you'll need to add them all to the ContextResource table by triggering the `OnDocFormSave` Event on all of them—or modify the ContextResource table yourself, programmatically. Until the CMP with bulk actions is developed (in a later version soon-to-come) this is a drawback of the 'context' mode.
28 |
29 | ### Param Mode
30 |
31 | In 'param' mode, the Plugin action is triggered when the GET param specified is set, in the URL string. This will override the `amp_context` property. In this mode:
32 |
33 | - If a request does not have the GET param specified, the Plugin will not fire, even if the request is in the specified `amp_context`.
34 | - The Plugin action will not be triggered on the `OnDocFormSave` Event, and the ContextResource table will not be modified while in this mode.
35 |
36 | This mode has the advantage of rendering the AMP view at the same URI as the requested Resource. Nothing about the Resource's URI needs to change, except the presence of the specified GET param.
37 |
38 | Also, the AMP view becomes immediately enabled for all your Resources, without any additional modifications of database records.
39 |
40 | However, it has the disadvantage that Resources cannot be specifically included or excluded from having an AMP view—the Plugin will fire for all Resources if the GET param is present.
41 |
42 | Another, perhaps more critical drawback, is that **the AMP view will not be cacheable**. This can cause serious performance issues, depending on the complexity of the AMP Template used. It's true that Google caches the AMP views, but it opens a door for anyone to trigger high loads on your site, if your AMP Template requires processing.
43 |
44 | A workaround for excluding Resources from the AMP view, would be to use the `amp_tv` property, and for Resources you want to exclude from having an AMP view, set the TV value to the same Template that the Resource uses natively. However, if the URL param is set, **the Resource will not be cacheable**. There's no workaround in this version of Ampify, for the caching limitation in 'param' mode.
45 |
46 | ### AMP TV
47 |
48 | If a value is provided in the `amp_tv` Plugin property, then the Resource will _only_ be added to the ContextResource table, if the Resource has a valid Template ID set in the TV. In that case, it will override the Template ID in the Plugin's `amp_template` property `OnLoadWebDocument` _for that Resource_.
49 |
50 | If the TV is empty for a given Resource, that Resource will be removed from the ContextResource table.
51 |
52 | In 'param' mode, no modifications happen to the ContextResource table, but the `amp_tv` value will be used to render the AMP view, falling back to the `amp_template` Plugin property as default.
53 |
54 | ## Installation
55 |
56 | Install via the MODX Revolution Extras Installer (aka "Package Manager").
57 |
58 | ## Usage
59 |
60 | The default Plugin property values are:
61 |
62 | - `amp_context` = `""` If this property is empty or doesn't contain a valid Context key, the Plugin will try to run in 'param' mode.
63 | - `amp_url_param` = `""` If this property is set, it will override the `amp_context` property and trigger the AMP Template view if a GET param with the specified key is set in the URL string. If this property is empty and `amp_context` is also empty, the Plugin effectively does nothing.
64 | - `amp_template` = `""` This property is required. At least 1 Template must be dedicated to an AMP view, and that Template's ID set here, in order for the Plugin to work at all.
65 | - `amp_tv` = `""` If a valid TV **name** is entered here, it will transform the Plugin's actions in the following way:
66 | - `OnLoadWebDocument` it will switch the Template of the Resource to the one specified in the TV with name `amp_tv`, falling back to the default set in `amp_template`
67 | - `OnDocFormSave` it will _only_ add the Resource to the table for automatic routing if there's a truth-y value in the TV with name `amp_tv`. If the TV is empty or false-y, it will remove the Resource from the table. This provides primitive "remove" functionality until such time a CMP is made to manage ContextResources.
68 |
69 | ## Example Implementation
70 |
71 | In this example, we'll install Ampify into an almost fresh MODX install, and use [Context Gateway](https://github.com/modxcms/context-gateway/) for Context routing. Both can be installed via the Extras Installer:
72 |
73 | 
74 |
75 | ### Create a new Context.
76 |
77 | Hover over the cog icon in the top-right corner of the Manager, to reveal the "Contexts" menu item.
78 |
79 | 
80 |
81 | In the Contexts view, click "Create New".
82 |
83 | 
84 |
85 | Give the new Context a key, a user-friendly name, and optionally a description.
86 |
87 | 
88 |
89 | Once the Context is created, you'll see it in the grid-list of Contexts. Right-click on it and select "Update Context".
90 |
91 | 
92 |
93 | In the Context Edit view, select the tab "Context Settings".
94 |
95 | 
96 |
97 | If you're not familiar with Context Settings, here are the documentation pages for [Contexts](https://rtfm.modx.com/revolution/2.x/administering-your-site/contexts) and [System Settings](https://rtfm.modx.com/revolution/2.x/administering-your-site/settings), which you might find useful to review before moving on to the next step.
98 |
99 | Click the "Create New" button. You'll need to create 5 new Context Settings, at a minimum:
100 |
101 | 1. `ctx_alias` is a requirement of the Context Gateway router, and defines the URI-bit for this Context. You'll use this string again in other settings.
102 |
103 | 
104 |
105 | 2. `site_url` overrides the default System Setting, appending the `ctx_alias`.
106 |
107 | 
108 |
109 | Notice the syntax `{site_url}amp/`. The part in curly braces references the default MODX `site_url` dynamically.
110 |
111 | 3. `base_url` does essentially the same as `site_url` but for a specific component of the URL.
112 |
113 | 
114 |
115 | 4. `site_start` and `error_page` should both have, as their values, the ID of the Resource that MODX will render as the "homepage" of the new Context. If you haven't created a Resource in the new Context yet, you can do so without leaving the current view, by right-clicking on the Context node in the Resource Tree, and selecting the "Quick Create" » "Document" option:
116 |
117 | 
118 |
119 | Give the new Resource a title, and ensure it's published. Once you hit save, the Tree will refresh and you'll see the new Resource with it's ID in parenthesis:
120 |
121 | 
122 |
123 | ### Friendly URL System Setting
124 |
125 | If you haven't already enabled Friendly URLs for your site, you'll need to do so for Ampify and Context Gateway to work. Hover over the cog icon again and chooose "System Settings".
126 |
127 | 
128 |
129 | At the top of the grid, choose the "Friendly URL" option from the "Area" dropdown:
130 |
131 | 
132 |
133 | Locate the "Use Friendly URLs" setting and set it to "Yes".
134 |
135 | 
136 |
137 | ### Plugin Properties
138 |
139 | Next you'll setup the AMPIFY Plugin's properties, without which the Plugin doesn't fire. You'll need the ID of the AMP Template that you want to use. Ampify installs a sample Template.
140 |
141 | 
142 |
143 | In this installation the ID is `4`. In the "Elements" tab of the Tree, open the "Plugins" section if not already open, and locate the AMPIFY Plugin:
144 |
145 | 
146 |
147 | 
148 |
149 | In the Plugin Edit view, select the "Properties" tab:
150 |
151 | 
152 |
153 | Click the button "Add Property Set". It's recommended to use a custom property set that will not be overwritten when you update the Extra.
154 |
155 | 
156 |
157 | In the "Add Property Set" window, select "Create New Property Set" and give it a name:
158 |
159 | 
160 |
161 | Hit save. In the property set dropdown, select your new set:
162 |
163 | 
164 |
165 | Modify the property values, as per your desired configuration. In this implementation, we'll add the Context Key and Template ID:
166 |
167 | 
168 |
169 | Save the property set.
170 |
171 | 
172 |
173 | You'll also need to select the custom property set for the Plugin's Event triggers. Go to the "System Events" tab, and select the custom property set for both enabled Events:
174 |
175 | 
176 |
177 | Don't forget to "Save" the Plugin!
178 |
179 | 
180 |
181 | Now the Plugin should be running in 'context' mode. When you save a Resource, it will be added to the `ContextResource` table for the `amp` Context. The AMP view for the Resource will be a the Resource's URI, prefixed with the `ctx_alias`: `amp/`.
182 |
--------------------------------------------------------------------------------
/_build/build.config.php:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modxcms/ampify/c79e439ab738e780fe69362daddc3a438a596b7e/_build/build.config.php
--------------------------------------------------------------------------------
/_build/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "AMPIFY"
3 | ,"lowCaseName": "ampify"
4 | ,"description": "Ampify your MODX Resources."
5 | ,"author": "YJ Tso, Wayne Roddy"
6 | ,"version": "0.2.2-dev1"
7 | ,"package":{
8 | "elements": {
9 | "plugins": [{
10 | "name": "AMPIFY"
11 | ,"file": "ampify.plugin.php"
12 | ,"events": ["OnLoadWebDocument","OnDocFormSave"]
13 | ,"properties": [{
14 | "name": "amp_context"
15 | ,"description": "Key of the Context in which to render AMP pages"
16 | ,"value": ""
17 | },{
18 | "name": "amp_template"
19 | ,"description": "ID of Template with AMP markup"
20 | },{
21 | "name": "amp_tv"
22 | ,"description": "Optional: NAME of TV specifying AMP Template for each Resource e.g. amp_template"
23 | },{
24 | "name": "amp_url_param"
25 | ,"description": "Key of GET param to trigger AMP Template rendering. Overrides amp_context if set."
26 | }]
27 | }]
28 | ,"snippets": [{
29 | "name": "ampfilter",
30 | "file": "ampfilter.snippet.php",
31 | "description": "Output modifier to convert HTML to amp-compliant markup."
32 | }]
33 | ,"templates": [{
34 | "name": "Sample AMP Template"
35 | ,"file": "amp_template.template.tpl"
36 | }]
37 | ,"tvs": [{
38 | "name": "amp_template"
39 | ,"caption": "AMP Template ID"
40 | ,"description": "Select the AMP Template to be used for this Resource"
41 | ,"type": "listbox"
42 | ,"inputOptionValues": "@SELECT templatename, id FROM modx_site_templates"
43 | }]
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/_build/data/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modxcms/ampify/c79e439ab738e780fe69362daddc3a438a596b7e/_build/data/.gitignore
--------------------------------------------------------------------------------
/_build/gpm_resolvers/gpm.resolve.tv_templates.php:
--------------------------------------------------------------------------------
1 | xpdo) {
12 | $modx =& $object->xpdo;
13 | switch ($options[xPDOTransport::PACKAGE_ACTION]) {
14 | case xPDOTransport::ACTION_INSTALL:
15 | case xPDOTransport::ACTION_UPGRADE:
16 | /* list of tvs and templates for each */
17 | $tvs = array (
18 | 'amp_template' =>
19 | array (
20 | ),
21 | );
22 | foreach ($tvs as $tvName => $templateNames) {
23 | if (!is_array($templateNames) || empty($templateNames)) continue;
24 | $tv = $modx->getObject('modTemplateVar',array('name' => $tvName));
25 | if (empty($tv)) {
26 | $modx->log(xPDO::LOG_LEVEL_ERROR,'Could not find TV: '.$tvName.' to associate to Templates.');
27 | continue;
28 | }
29 | $rank = 0;
30 | foreach ($templateNames as $templateName) {
31 | $template = $modx->getObject('modTemplate',array('templatename' => $templateName));
32 | if (!empty($template)) {
33 | $templateVarTemplate = $modx->getObject('modTemplateVarTemplate',array(
34 | 'tmplvarid' => $tv->get('id'),
35 | 'templateid' => $template->get('id'),
36 | ));
37 | if (!$templateVarTemplate) {
38 | $templateVarTemplate = $modx->newObject('modTemplateVarTemplate');
39 | $templateVarTemplate->fromArray(array(
40 | 'tmplvarid' => $tv->get('id'),
41 | 'templateid' => $template->get('id'),
42 | 'rank' => $rank,
43 | ),'',true,true);
44 | if ($templateVarTemplate->save() == false) {
45 | $modx->log(xPDO::LOG_LEVEL_ERROR,'An unknown error occurred while trying to associate the TV '.$tvName.' to the Template '.$templateName);
46 | }
47 | }
48 | } else {
49 | $modx->log(xPDO::LOG_LEVEL_ERROR,'Could not find Template '.$templateName);
50 | }
51 | $rank++;
52 | }
53 | }
54 | break;
55 | }
56 | }
57 | return true;
--------------------------------------------------------------------------------
/_build/includes/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modxcms/ampify/c79e439ab738e780fe69362daddc3a438a596b7e/_build/includes/.gitignore
--------------------------------------------------------------------------------
/_build/resolvers/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modxcms/ampify/c79e439ab738e780fe69362daddc3a438a596b7e/_build/resolvers/.gitignore
--------------------------------------------------------------------------------
/_build/setup.options.php:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modxcms/ampify/c79e439ab738e780fe69362daddc3a438a596b7e/_build/setup.options.php
--------------------------------------------------------------------------------
/_packages/ampify-0.2.1-dev1.transport.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modxcms/ampify/c79e439ab738e780fe69362daddc3a438a596b7e/_packages/ampify-0.2.1-dev1.transport.zip
--------------------------------------------------------------------------------
/config.core.php:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modxcms/ampify/c79e439ab738e780fe69362daddc3a438a596b7e/config.core.php
--------------------------------------------------------------------------------
/core/components/ampify/docs/changelog.txt:
--------------------------------------------------------------------------------
1 | AMPIFY 0.0.1
2 | ============
3 | Initial dev version.
--------------------------------------------------------------------------------
/core/components/ampify/docs/license.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE Version 2, June 1991
2 |
3 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
4 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 licenses for most software are designed to take away your
11 | freedom to share and change it. By contrast, the GNU General Public
12 | License is intended to guarantee your freedom to share and change free
13 | software--to make sure the software is free for all its users. This
14 | General Public License applies to most of the Free Software
15 | Foundation's software and to any other program whose authors commit to
16 | using it. (Some other Free Software Foundation software is covered by
17 | the GNU Lesser General Public License instead.) You can apply it to
18 | your programs, too.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | this service if you wish), that you receive source code or can get it
24 | if you want it, that you can change the software or use pieces of it
25 | in new free programs; and that you know you can do these things.
26 |
27 | To protect your rights, we need to make restrictions that forbid
28 | anyone to deny you these rights or to ask you to surrender the rights.
29 | These restrictions translate to certain responsibilities for you if you
30 | distribute copies of the software, or if you modify it.
31 |
32 | For example, if you distribute copies of such a program, whether
33 | gratis or for a fee, you must give the recipients all the rights that
34 | you have. You must make sure that they, too, receive or can get the
35 | source code. And you must show them these terms so they know their
36 | rights.
37 |
38 | We protect your rights with two steps: (1) copyright the software, and
39 | (2) offer you this license which gives you legal permission to copy,
40 | distribute and/or modify the software.
41 |
42 | Also, for each author's protection and ours, we want to make certain
43 | that everyone understands that there is no warranty for this free
44 | software. If the software is modified by someone else and passed on, we
45 | want its recipients to know that what they have is not the original, so
46 | that any problems introduced by others will not reflect on the original
47 | authors' reputations.
48 |
49 | Finally, any free program is threatened constantly by software
50 | patents. We wish to avoid the danger that redistributors of a free
51 | program will individually obtain patent licenses, in effect making the
52 | program proprietary. To prevent this, we have made it clear that any
53 | patent must be licensed for everyone's free use or not licensed at all.
54 |
55 | The precise terms and conditions for copying, distribution and
56 | modification follow.
57 |
58 | GNU GENERAL PUBLIC LICENSE
59 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
60 |
61 | 0. This License applies to any program or other work which contains
62 | a notice placed by the copyright holder saying it may be distributed
63 | under the terms of this General Public License. The "Program", below,
64 | refers to any such program or work, and a "work based on the Program"
65 | means either the Program or any derivative work under copyright law:
66 | that is to say, a work containing the Program or a portion of it,
67 | either verbatim or with modifications and/or translated into another
68 | language. (Hereinafter, translation is included without limitation in
69 | the term "modification".) Each licensee is addressed as "you".
70 |
71 | Activities other than copying, distribution and modification are not
72 | covered by this License; they are outside its scope. The act of
73 | running the Program is not restricted, and the output from the Program
74 | is covered only if its contents constitute a work based on the
75 | Program (independent of having been made by running the Program).
76 | Whether that is true depends on what the Program does.
77 |
78 | 1. You may copy and distribute verbatim copies of the Program's
79 | source code as you receive it, in any medium, provided that you
80 | conspicuously and appropriately publish on each copy an appropriate
81 | copyright notice and disclaimer of warranty; keep intact all the
82 | notices that refer to this License and to the absence of any warranty;
83 | and give any other recipients of the Program a copy of this License
84 | along with the Program.
85 |
86 | You may charge a fee for the physical act of transferring a copy, and
87 | you may at your option offer warranty protection in exchange for a fee.
88 |
89 | 2. You may modify your copy or copies of the Program or any portion
90 | of it, thus forming a work based on the Program, and copy and
91 | distribute such modifications or work under the terms of Section 1
92 | above, provided that you also meet all of these conditions:
93 |
94 | a) You must cause the modified files to carry prominent notices
95 | stating that you changed the files and the date of any change.
96 |
97 | b) You must cause any work that you distribute or publish, that in
98 | whole or in part contains or is derived from the Program or any
99 | part thereof, to be licensed as a whole at no charge to all third
100 | parties under the terms of this License.
101 |
102 | c) If the modified program normally reads commands interactively
103 | when run, you must cause it, when started running for such
104 | interactive use in the most ordinary way, to print or display an
105 | announcement including an appropriate copyright notice and a
106 | notice that there is no warranty (or else, saying that you provide
107 | a warranty) and that users may redistribute the program under
108 | these conditions, and telling the user how to view a copy of this
109 | License. (Exception: if the Program itself is interactive but
110 | does not normally print such an announcement, your work based on
111 | the Program is not required to print an announcement.)
112 |
113 | These requirements apply to the modified work as a whole. If
114 | identifiable sections of that work are not derived from the Program,
115 | and can be reasonably considered independent and separate works in
116 | themselves, then this License, and its terms, do not apply to those
117 | sections when you distribute them as separate works. But when you
118 | distribute the same sections as part of a whole which is a work based
119 | on the Program, the distribution of the whole must be on the terms of
120 | this License, whose permissions for other licensees extend to the
121 | entire whole, and thus to each and every part regardless of who wrote it.
122 |
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 |
281 | How to Apply These Terms to Your New Programs
282 |
283 | If you develop a new program, and you want it to be of the greatest
284 | possible use to the public, the best way to achieve this is to make it
285 | free software which everyone can redistribute and change under these terms.
286 |
287 | To do so, attach the following notices to the program. It is safest
288 | to attach them to the start of each source file to most effectively
289 | convey the exclusion of warranty; and each file should have at least
290 | the "copyright" line and a pointer to where the full notice is found.
291 |
292 | {description}
293 | Copyright (C) {year} {fullname}
294 |
295 | This program is free software; you can redistribute it and/or modify
296 | it under the terms of the GNU General Public License as published by
297 | the Free Software Foundation; either version 2 of the License, or
298 | (at your option) any later version.
299 |
300 | This program is distributed in the hope that it will be useful,
301 | but WITHOUT ANY WARRANTY; without even the implied warranty of
302 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
303 | GNU General Public License for more details.
304 |
305 | You should have received a copy of the GNU General Public License along
306 | with this program; if not, write to the Free Software Foundation, Inc.,
307 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
308 |
309 | Also add information on how to contact you by electronic and paper mail.
310 |
311 | If the program is interactive, make it output a short notice like this
312 | when it starts in an interactive mode:
313 |
314 | Gnomovision version 69, Copyright (C) year name of author
315 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
316 | This is free software, and you are welcome to redistribute it
317 | under certain conditions; type `show c' for details.
318 |
319 | The hypothetical commands `show w' and `show c' should show the appropriate
320 | parts of the General Public License. Of course, the commands you use may
321 | be called something other than `show w' and `show c'; they could even be
322 | mouse-clicks or menu items--whatever suits your program.
323 |
324 | You should also get your employer (if you work as a programmer) or your
325 | school, if any, to sign a "copyright disclaimer" for the program, if
326 | necessary. Here is a sample; alter the names:
327 |
328 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
329 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
330 |
331 | {signature of Ty Coon}, 1 April 1989
332 | Ty Coon, President of Vice
333 |
334 | This General Public License does not permit incorporating your program into
335 | proprietary programs. If your program is a subroutine library, you may
336 | consider it more useful to permit linking proprietary applications with the
337 | library. If this is what you want to do, use the GNU Lesser General
338 | Public License instead of this License.
339 |
340 |
--------------------------------------------------------------------------------
/core/components/ampify/docs/readme.txt:
--------------------------------------------------------------------------------
1 | # Ampify
2 |
3 | Effortless Google [Accelerated Mobile Pages](https://www.ampproject.org/), aka "AMP", for MODX Revolution.
4 |
5 | ## What is it?
6 |
7 | **Ampify** is a MODX Revolution Extra that includes a toolset to easily serve AMP HTML for Google's search results pages. The package includes a Plugin, and a sample AMP Template.
8 |
9 | ## What does it do?
10 |
11 | When triggered, the Plugin switches the Template used by the currently requested Resource, to the specified AMP Template.
12 |
13 | ## I want details
14 |
15 | The Ampify Plugin fires in two different modes: 'param' and 'context'.
16 |
17 | ### Context Mode
18 |
19 | In 'context' mode, the Plugin action is triggered when a request is made to a specified AMP Context. (Context routing and setup are outside the scope of this Extra, but there's an [example implementation](#example-implementation) below.)
20 |
21 | The AMP Context will automatically route requests to Resources that have been added to the ContextResource table. Resources are added automatically when they are saved. In future versions, a CMP will be provided to add/remove Resources from the table, with bulk actions.
22 |
23 | This mode has the advantage of being able to include and exclude Resources from having an AMP view.
24 |
25 | However, it has the disadvantage that AMP views will be rendered at a different URI than the canonical. At the minimum, the Context's base_url will be prefixed, for example: `/amp/resource-alias.html` versus `/resource-alias.html`
26 |
27 | Also, if you have a lot of pre-existing Resources for which you want to provide an AMP view, you'll need to add them all to the ContextResource table by triggering the `OnDocFormSave` Event on all of them—or modify the ContextResource table yourself, programmatically. Until the CMP with bulk actions is developed (in a later version soon-to-come) this is a drawback of the 'context' mode.
28 |
29 | ### Param Mode
30 |
31 | In 'param' mode, the Plugin action is triggered when the GET param specified is set, in the URL string. This will override the `amp_context` property. In this mode:
32 |
33 | - If a request does not have the GET param specified, the Plugin will not fire, even if the request is in the specified `amp_context`.
34 | - The Plugin action will not be triggered on the `OnDocFormSave` Event, and the ContextResource table will not be modified while in this mode.
35 |
36 | This mode has the advantage of rendering the AMP view at the same URI as the requested Resource. Nothing about the Resource's URI needs to change, except the presence of the specified GET param.
37 |
38 | Also, the AMP view becomes immediately enabled for all your Resources, without any additional modifications of database records.
39 |
40 | However, it has the disadvantage that Resources cannot be specifically included or excluded from having an AMP view—the Plugin will fire for all Resources if the GET param is present.
41 |
42 | Another, perhaps more critical drawback, is that **the AMP view will not be cacheable**. This can cause serious performance issues, depending on the complexity of the AMP Template used. It's true that Google caches the AMP views, but it opens a door for anyone to trigger high loads on your site, if your AMP Template requires processing.
43 |
44 | A workaround for excluding Resources from the AMP view, would be to use the `amp_tv` property, and for Resources you want to exclude from having an AMP view, set the TV value to the same Template that the Resource uses natively. However, if the URL param is set, **the Resource will not be cacheable**. There's no workaround in this version of Ampify, for the caching limitation in 'param' mode.
45 |
46 | ### AMP TV
47 |
48 | If a value is provided in the `amp_tv` Plugin property, then the Resource will _only_ be added to the ContextResource table, if the Resource has a valid Template ID set in the TV. In that case, it will override the Template ID in the Plugin's `amp_template` property `OnLoadWebDocument` _for that Resource_.
49 |
50 | If the TV is empty for a given Resource, that Resource will be removed from the ContextResource table.
51 |
52 | In 'param' mode, no modifications happen to the ContextResource table, but the `amp_tv` value will be used to render the AMP view, falling back to the `amp_template` Plugin property as default.
53 |
54 | ## Installation
55 |
56 | Install via the MODX Revolution Extras Installer (aka "Package Manager").
57 |
58 | ## Usage
59 |
60 | The default Plugin property values are:
61 |
62 | - `amp_context` = `""` If this property is empty or doesn't contain a valid Context key, the Plugin will try to run in 'param' mode.
63 | - `amp_url_param` = `""` If this property is set, it will override the `amp_context` property and trigger the AMP Template view if a GET param with the specified key is set in the URL string. If this property is empty and `amp_context` is also empty, the Plugin effectively does nothing.
64 | - `amp_template` = `""` This property is required. At least 1 Template must be dedicated to an AMP view, and that Template's ID set here, in order for the Plugin to work at all.
65 | - `amp_tv` = `""` If a valid TV **name** is entered here, it will transform the Plugin's actions in the following way:
66 | - `OnLoadWebDocument` it will switch the Template of the Resource to the one specified in the TV with name `amp_tv`, falling back to the default set in `amp_template`
67 | - `OnDocFormSave` it will _only_ add the Resource to the table for automatic routing if there's a truth-y value in the TV with name `amp_tv`. If the TV is empty or false-y, it will remove the Resource from the table. This provides primitive "remove" functionality until such time a CMP is made to manage ContextResources.
68 |
69 | ## Example Implementation
70 |
71 | Check out the README on github.com: [https://github.com/modxcms/ampify](https://github.com/modxcms/ampify)
--------------------------------------------------------------------------------
/core/components/ampify/elements/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/modxcms/ampify/c79e439ab738e780fe69362daddc3a438a596b7e/core/components/ampify/elements/.gitignore
--------------------------------------------------------------------------------
/core/components/ampify/elements/plugins/ampify.plugin.php:
--------------------------------------------------------------------------------
1 | getOption('amp_url_param', $scriptProperties, '');
13 |
14 | // AMPIFY Context
15 | $ampContext = $modx->getOption('amp_context', $scriptProperties, '');
16 |
17 | // AMPIFY Mode
18 | $mode = 0;
19 | if (!empty($ampUrlParam)) {
20 | $mode = 'param';
21 | } elseif (!empty($ampContext)) {
22 | $countCtx = $modx->getCount('modContext', array('key' => $ampContext));
23 | if ($countCtx === 1) {
24 | $mode = 'context';
25 | }
26 | }
27 | if ($mode === 0) {
28 | $modx->log(modX::LOG_LEVEL_WARN, 'AMPIFY requires at least a valid amp_context or an amp_url_param specified.');
29 | return;
30 | }
31 |
32 | // AMPIFY Template
33 | $ampTemplate = $modx->getOption('amp_template', $scriptProperties, '');
34 | $countTpl = $modx->getCount('modTemplate', $ampTemplate);
35 | if ($countTpl !== 1) {
36 | $modx->log(modX::LOG_LEVEL_ERROR, 'AMPIFY requires a valid, default Template ID');
37 | return;
38 | }
39 |
40 | // AMPIFY TV
41 | $ampTv = $modx->getOption('amp_tv', $scriptProperties, '');
42 | $countTv = $modx->getCount('modTemplateVar', array('name' => $ampTv));
43 |
44 | $event = $modx->event->name;
45 | switch ($event) {
46 |
47 | case 'OnLoadWebDocument':
48 |
49 | // Escape conditions
50 | if ($mode === 'param' && !isset($_GET[$ampUrlParam])) {
51 | break;
52 | }
53 | if ($mode === 'context' && ($modx->context->get('key') !== $ampContext)) {
54 | break;
55 | }
56 | if (!($modx->resource instanceof modResource)) {
57 | break;
58 | }
59 |
60 | // Check Resource AMP TV
61 | if ($countTv === 1) {
62 | $tvValue = $modx->resource->getTVValue($ampTv);
63 | $countTvTpl = $modx->getCount('modTemplate', $tvValue);
64 | if ($countTvTpl === 1) $ampTemplate = $tvValue;
65 | }
66 |
67 | // Don't cache 'param' mode result
68 | if ($mode === 'param') $modx->resource->set('cacheable', 0);
69 |
70 | // Set runtime resource property
71 | $modx->resource->set('template', $ampTemplate);
72 |
73 | // Move on
74 | break;
75 |
76 | case 'OnDocFormSave':
77 |
78 | // Probably overly paranoid
79 | if ($modx->context->get('key') !== 'mgr') {
80 | break;
81 | }
82 |
83 | // If $mode isn't 'context', stop doing ContextResource actions
84 | if ($mode !== 'context') {
85 | break;
86 | }
87 |
88 | // Check Resource
89 | if (!($resource instanceof modResource)) {
90 | break;
91 | }
92 |
93 | // Check Resource AMP TV
94 | if ($countTv === 1) {
95 | $tvValue = $resource->getTVValue($ampTv);
96 | }
97 |
98 | // Set criteria for ContextResource object
99 | $criteria = array(
100 | 'context_key' => $ampContext,
101 | 'resource' => $resource->get('id'),
102 | );
103 |
104 | // Check ContextResource
105 | $ctxRes = $modx->getObject('modContextResource', $criteria);
106 |
107 | // Remove if using the AMP TV and there' no tvValue
108 | if ($countTv === 1 && !$tvValue && $ctxRes instanceof modContextResource) {
109 | $ctxRes->remove();
110 | break;
111 | }
112 |
113 | // Create if it doesn't exist
114 | if ($ctxRes === null) {
115 |
116 | $rc = $modx->newObject('modContextResource');
117 | $rc->fromArray($criteria, '', true); //set pk
118 | // Save
119 | if (!$rc->save()) {
120 | $modx->log(modX::LOG_LEVEL_ERROR, 'AMPIFY could not save modContextResource: ' . print_r($criteria, true));
121 | }
122 | // Trigger the Context Gateway
123 | $modx->cacheManager->refresh();
124 | }
125 |
126 | // We're done
127 | break;
128 |
129 | // Don't do anything on other events
130 | default:
131 | break;
132 |
133 | }
134 |
135 | // The Plugin returns nothing
136 | return;
--------------------------------------------------------------------------------
/core/components/ampify/elements/snippets/ampfilter.snippet.php:
--------------------------------------------------------------------------------
1 |
8 | * Copyright 2015 by YJ Tso
9 | *
10 | * This program is free software; you can redistribute it and/or modify it under
11 | * the terms of the GNU General Public License as published by the Free Software
12 | * Foundation; either version 2 of the License, or (at your option) any later
13 | * version.
14 | *
15 | * This program is distributed in the hope that it will be useful, but WITHOUT
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 | * details.
19 | *
20 | * You should have received a copy of the GNU General Public License along with
21 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 | * Place, Suite 330, Boston, MA 02111-1307 USA
23 | **/
24 |
25 | // Paths
26 | $ampifyPath = $modx->getOption('ampify.core_path', null, $modx->getOption('core_path') . 'components/ampify/');
27 | $ampifyPath .= 'model/ampify/';
28 |
29 | // Get Class
30 | if (file_exists($ampifyPath . 'ampify.class.php')) $ampify = $modx->getService('ampify', 'Ampify', $ampifyPath, $scriptProperties);
31 | if (!($ampify instanceof Ampify)) {
32 | $modx->log(modX::LOG_LEVEL_ERROR, '[ampfilter] could not load the required class!');
33 | return;
34 | }
35 |
36 | $sanitizers = $modx->fromJSON($modx->getOption('options', $scriptProperties, '{"img": []}', true));
37 | if (!is_array($sanitizers)) $sanitizers = array('img' => array());
38 |
39 | $amp = $ampify->getAmpSterc($input, array(), $sanitizers, array());
40 | return $amp->get_amp_content();
--------------------------------------------------------------------------------
/core/components/ampify/elements/templates/amp_template.template.tpl:
--------------------------------------------------------------------------------
1 |
2 |
3 |