From a7b3eb7c5cd56fbe54c86628249699f15936778f Mon Sep 17 00:00:00 2001 From: Andrew Eddie Date: Tue, 8 Apr 2014 22:32:59 +1000 Subject: [PATCH] Initial decoupling of Weblinks July made me do it! --- .gitignore | 3 + CONTRIBUTING.md | 48 +++ LICENSE | 340 ++++++++++++++++ README.md | 5 +- build.ini | 5 + build.xml | 115 ++++++ manifest.xml | 18 + src/com_weblinks/admin/access.xml | 19 + src/com_weblinks/admin/config.xml | 367 +++++++++++++++++ src/com_weblinks/admin/controller.php | 54 +++ .../admin/controllers/weblink.php | 126 ++++++ .../admin/controllers/weblinks.php | 52 +++ src/com_weblinks/admin/helpers/weblinks.php | 44 ++ .../language/en-GB/en-GB.com_weblinks.ini | 121 ++++++ .../language/en-GB/en-GB.com_weblinks.sys.ini | 21 + .../admin/models/forms/weblink.xml | 272 +++++++++++++ src/com_weblinks/admin/models/weblink.php | 343 ++++++++++++++++ src/com_weblinks/admin/models/weblinks.php | 232 +++++++++++ .../admin/sql/install.mysql.utf8.sql | 42 ++ .../admin/sql/uninstall.mysql.utf8.sql | 1 + src/com_weblinks/admin/tables/weblink.php | 286 +++++++++++++ .../admin/views/weblink/tmpl/edit.php | 80 ++++ .../views/weblink/tmpl/edit_metadata.php | 12 + .../admin/views/weblink/tmpl/edit_params.php | 28 ++ .../admin/views/weblink/view.html.php | 97 +++++ .../admin/views/weblinks/tmpl/default.php | 211 ++++++++++ .../views/weblinks/tmpl/default_batch.php | 56 +++ .../admin/views/weblinks/view.html.php | 164 ++++++++ src/com_weblinks/admin/weblinks.php | 20 + src/com_weblinks/admin/weblinks.xml | 71 ++++ src/com_weblinks/site/controller.php | 65 +++ src/com_weblinks/site/controllers/weblink.php | 313 +++++++++++++++ src/com_weblinks/site/helpers/association.php | 52 +++ src/com_weblinks/site/helpers/category.php | 28 ++ src/com_weblinks/site/helpers/icon.php | 77 ++++ src/com_weblinks/site/helpers/route.php | 241 +++++++++++ .../language/en-GB/en-GB.com_weblinks.ini | 34 ++ src/com_weblinks/site/metadata.xml | 3 + src/com_weblinks/site/models/categories.php | 124 ++++++ src/com_weblinks/site/models/category.php | 365 +++++++++++++++++ src/com_weblinks/site/models/form.php | 76 ++++ .../site/models/forms/weblink.xml | 140 +++++++ src/com_weblinks/site/models/weblink.php | 128 ++++++ src/com_weblinks/site/router.php | 229 +++++++++++ .../site/views/categories/tmpl/default.php | 17 + .../site/views/categories/tmpl/default.xml | 243 +++++++++++ .../views/categories/tmpl/default_items.php | 63 +++ .../site/views/categories/view.html.php | 85 ++++ .../site/views/category/metadata.xml | 6 + .../site/views/category/tmpl/default.php | 14 + .../site/views/category/tmpl/default.xml | 195 +++++++++ .../views/category/tmpl/default_children.php | 57 +++ .../views/category/tmpl/default_items.php | 177 ++++++++ .../site/views/category/view.feed.php | 26 ++ .../site/views/category/view.html.php | 105 +++++ src/com_weblinks/site/views/form/metadata.xml | 7 + .../site/views/form/tmpl/edit.php | 77 ++++ .../site/views/form/tmpl/edit.xml | 12 + .../site/views/form/view.html.php | 137 +++++++ src/com_weblinks/site/views/index.html | 1 + .../site/views/weblink/view.html.php | 47 +++ src/com_weblinks/site/weblinks.php | 16 + src/language/en-GB/en-GB.pkg_weblinks.sys.ini | 7 + src/mod_weblinks/helper.php | 116 ++++++ .../language/en-GB/en-GB.mod_weblinks.ini | 31 ++ .../language/en-GB/en-GB.mod_weblinks.sys.ini | 9 + src/mod_weblinks/mod_weblinks.php | 24 ++ src/mod_weblinks/mod_weblinks.xml | 171 ++++++++ src/mod_weblinks/tmpl/default.php | 55 +++ src/pkg_weblinks.xml | 30 ++ .../en-GB/en-GB.plg_finder_weblinks.ini | 10 + .../en-GB/en-GB.plg_finder_weblinks.sys.ini | 8 + src/plg_finder_weblinks/weblinks.php | 379 ++++++++++++++++++ src/plg_finder_weblinks/weblinks.xml | 21 + .../en-GB/en-GB.plg_search_weblinks.ini | 10 + .../en-GB/en-GB.plg_search_weblinks.sys.ini | 7 + src/plg_search_weblinks/weblinks.php | 220 ++++++++++ src/plg_search_weblinks/weblinks.xml | 53 +++ 78 files changed, 7561 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 build.ini create mode 100644 build.xml create mode 100644 manifest.xml create mode 100644 src/com_weblinks/admin/access.xml create mode 100644 src/com_weblinks/admin/config.xml create mode 100644 src/com_weblinks/admin/controller.php create mode 100644 src/com_weblinks/admin/controllers/weblink.php create mode 100644 src/com_weblinks/admin/controllers/weblinks.php create mode 100644 src/com_weblinks/admin/helpers/weblinks.php create mode 100644 src/com_weblinks/admin/language/en-GB/en-GB.com_weblinks.ini create mode 100644 src/com_weblinks/admin/language/en-GB/en-GB.com_weblinks.sys.ini create mode 100644 src/com_weblinks/admin/models/forms/weblink.xml create mode 100644 src/com_weblinks/admin/models/weblink.php create mode 100644 src/com_weblinks/admin/models/weblinks.php create mode 100644 src/com_weblinks/admin/sql/install.mysql.utf8.sql create mode 100644 src/com_weblinks/admin/sql/uninstall.mysql.utf8.sql create mode 100644 src/com_weblinks/admin/tables/weblink.php create mode 100644 src/com_weblinks/admin/views/weblink/tmpl/edit.php create mode 100644 src/com_weblinks/admin/views/weblink/tmpl/edit_metadata.php create mode 100644 src/com_weblinks/admin/views/weblink/tmpl/edit_params.php create mode 100644 src/com_weblinks/admin/views/weblink/view.html.php create mode 100644 src/com_weblinks/admin/views/weblinks/tmpl/default.php create mode 100644 src/com_weblinks/admin/views/weblinks/tmpl/default_batch.php create mode 100644 src/com_weblinks/admin/views/weblinks/view.html.php create mode 100644 src/com_weblinks/admin/weblinks.php create mode 100644 src/com_weblinks/admin/weblinks.xml create mode 100644 src/com_weblinks/site/controller.php create mode 100644 src/com_weblinks/site/controllers/weblink.php create mode 100644 src/com_weblinks/site/helpers/association.php create mode 100644 src/com_weblinks/site/helpers/category.php create mode 100644 src/com_weblinks/site/helpers/icon.php create mode 100644 src/com_weblinks/site/helpers/route.php create mode 100644 src/com_weblinks/site/language/en-GB/en-GB.com_weblinks.ini create mode 100644 src/com_weblinks/site/metadata.xml create mode 100644 src/com_weblinks/site/models/categories.php create mode 100644 src/com_weblinks/site/models/category.php create mode 100644 src/com_weblinks/site/models/form.php create mode 100644 src/com_weblinks/site/models/forms/weblink.xml create mode 100644 src/com_weblinks/site/models/weblink.php create mode 100644 src/com_weblinks/site/router.php create mode 100644 src/com_weblinks/site/views/categories/tmpl/default.php create mode 100644 src/com_weblinks/site/views/categories/tmpl/default.xml create mode 100644 src/com_weblinks/site/views/categories/tmpl/default_items.php create mode 100644 src/com_weblinks/site/views/categories/view.html.php create mode 100644 src/com_weblinks/site/views/category/metadata.xml create mode 100644 src/com_weblinks/site/views/category/tmpl/default.php create mode 100644 src/com_weblinks/site/views/category/tmpl/default.xml create mode 100644 src/com_weblinks/site/views/category/tmpl/default_children.php create mode 100644 src/com_weblinks/site/views/category/tmpl/default_items.php create mode 100644 src/com_weblinks/site/views/category/view.feed.php create mode 100644 src/com_weblinks/site/views/category/view.html.php create mode 100644 src/com_weblinks/site/views/form/metadata.xml create mode 100644 src/com_weblinks/site/views/form/tmpl/edit.php create mode 100644 src/com_weblinks/site/views/form/tmpl/edit.xml create mode 100644 src/com_weblinks/site/views/form/view.html.php create mode 100644 src/com_weblinks/site/views/index.html create mode 100644 src/com_weblinks/site/views/weblink/view.html.php create mode 100644 src/com_weblinks/site/weblinks.php create mode 100644 src/language/en-GB/en-GB.pkg_weblinks.sys.ini create mode 100644 src/mod_weblinks/helper.php create mode 100644 src/mod_weblinks/language/en-GB/en-GB.mod_weblinks.ini create mode 100644 src/mod_weblinks/language/en-GB/en-GB.mod_weblinks.sys.ini create mode 100644 src/mod_weblinks/mod_weblinks.php create mode 100644 src/mod_weblinks/mod_weblinks.xml create mode 100644 src/mod_weblinks/tmpl/default.php create mode 100644 src/pkg_weblinks.xml create mode 100644 src/plg_finder_weblinks/language/en-GB/en-GB.plg_finder_weblinks.ini create mode 100644 src/plg_finder_weblinks/language/en-GB/en-GB.plg_finder_weblinks.sys.ini create mode 100644 src/plg_finder_weblinks/weblinks.php create mode 100644 src/plg_finder_weblinks/weblinks.xml create mode 100644 src/plg_search_weblinks/language/en-GB/en-GB.plg_search_weblinks.ini create mode 100644 src/plg_search_weblinks/language/en-GB/en-GB.plg_search_weblinks.sys.ini create mode 100644 src/plg_search_weblinks/weblinks.php create mode 100644 src/plg_search_weblinks/weblinks.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e918fda --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +build +releases diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..9e5f665 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,48 @@ +# Joomla! Weblinks Contribution Guide + +Thanks for your interest in this extension for Joomla. Please review the following notes about contributing and maintaining this package. + +## Version Strategy + +* When in doubt, refer to the new Joomla development strategy modelled on Semver (link). +* The major version of this package is synchronised with the major version of Joomla it is designed to run under. + For example, Weblinks 3.x is designed to run under Joomla 3.x; Weblinks 4.x under Joomla 4.x; and so on. +* A new minor version will be released each time there is a new feature or a significant change made to the package. +* A new patch version will be released each time there is a bug or cosmetic fix made to the package. + +## Pull Requests + +First fork this repository under your own account and make the changes to the code that you want to make. +Then make a Pull Request against the `master` branch of this repository. + +### @since tags + +If adding new PHP class methods or properties, the `@since` tags should be given the value of `__DEPLOY_VERSION__`. +This special tag will be replaced when the new version is built. + +## Bugs and Issues + +You can browse existing issues [here](https://github.com/joomla-extensions/weblinks/issues). + +If you find any new bugs, or want to raise any type of support issue, please use raise a +[new issue](https://github.com/joomla-extensions/weblinks/issues/new). + +## Release Procedure + +This is the procedure and checklist for creating a new package. + +* Update the version number in `build.ini`. +* Run `phing set-version`. +* Pun `phing` to make the new package for the version. +* Run `phing tag`. +* Push the commits and tags up to Github. +* Go to the releases page on Github. +* Click on the new tag. + - Click the `Edit Tag` button. + - Fill in the title and description for the release. + - Attach the zip-file for the package to the release. Wait for the file to complete uploading! + - Click the `Publish Release` button. +* Create a new `` tag in the `manifest.xml` file. + - Change the `` tag to the new version. + - Change the `` tag to match the URL of the new release. + - Commit the change. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..df50810 --- /dev/null +++ b/LICENSE @@ -0,0 +1,340 @@ +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/README.md b/README.md index b35032b..7735fc2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -weblinks -======== +# Weblinks for Joomla! -This is a prototype for isolating the Joomla CMS Weblinks suite of extensions and managing it as a standalone extension. +This is a prototype for isolating the Joomla's Weblinks suite of extensions and managing it as a standalone extension. diff --git a/build.ini b/build.ini new file mode 100644 index 0000000..bf5ba4f --- /dev/null +++ b/build.ini @@ -0,0 +1,5 @@ +# The release version for the extension package. +version=3.0.0 + +# The name of the package. +package=weblinks diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..bca23d6 --- /dev/null +++ b/build.xml @@ -0,0 +1,115 @@ + + + + + + + + + + Use `$ phing -l` to list the available targets. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Replacing "__DEPLOY_VERSION__" with "${version}". + + + + + + + + + + + + + + + + + + Push tags manually with `$ git push --tags origin`. + + + + + + + + + + + + + + + + + + + + + + + diff --git a/manifest.xml b/manifest.xml new file mode 100644 index 0000000..d5d0a6f --- /dev/null +++ b/manifest.xml @@ -0,0 +1,18 @@ + + + + Weblinks Extension Package + Joomla! CMS Weblinks Package + pkg_weblinks + package + 3.0.0 + + https://github.com/joomla-extensions/weblinks + + + https://github.com/joomla-extensions/weblinks/releases/download/3.0.0/pkg_weblinks_3.0.0.zip + + + site + + diff --git a/src/com_weblinks/admin/access.xml b/src/com_weblinks/admin/access.xml new file mode 100644 index 0000000..fd789fa --- /dev/null +++ b/src/com_weblinks/admin/access.xml @@ -0,0 +1,19 @@ + + +
+ + + + + + + +
+
+ + + + + +
+
\ No newline at end of file diff --git a/src/com_weblinks/admin/config.xml b/src/com_weblinks/admin/config.xml new file mode 100644 index 0000000..1f6dc45 --- /dev/null +++ b/src/com_weblinks/admin/config.xml @@ -0,0 +1,367 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ + +
+
diff --git a/src/com_weblinks/admin/controller.php b/src/com_weblinks/admin/controller.php new file mode 100644 index 0000000..02d8915 --- /dev/null +++ b/src/com_weblinks/admin/controller.php @@ -0,0 +1,54 @@ +input->get('view', 'weblinks'); + $layout = $this->input->get('layout', 'default'); + $id = $this->input->getInt('id'); + + // Check for edit form. + if ($view == 'weblink' && $layout == 'edit' && !$this->checkEditId('com_weblinks.edit.weblink', $id)) + { + // Somehow the person just went to the form - we don't allow that. + $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); + $this->setMessage($this->getError(), 'error'); + $this->setRedirect(JRoute::_('index.php?option=com_weblinks&view=weblinks', false)); + + return false; + } + + parent::display(); + + return $this; + } +} diff --git a/src/com_weblinks/admin/controllers/weblink.php b/src/com_weblinks/admin/controllers/weblink.php new file mode 100644 index 0000000..2361894 --- /dev/null +++ b/src/com_weblinks/admin/controllers/weblink.php @@ -0,0 +1,126 @@ +input->getInt('filter_category_id'), 'int'); + $allow = null; + + if ($categoryId) + { + // If the category has been passed in the URL check it. + $allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId); + } + + if ($allow === null) + { + // In the absense of better information, revert to the component permissions. + return parent::allowAdd($data); + } + else + { + return $allow; + } + } + + /** + * Method to check if you can add a new record. + * + * @param array $data An array of input data. + * @param string $key The name of the key for the primary key. + * + * @return boolean + * + * @since 1.6 + */ + protected function allowEdit($data = array(), $key = 'id') + { + $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + $categoryId = 0; + + if ($recordId) + { + $categoryId = (int) $this->getModel()->getItem($recordId)->catid; + } + + if ($categoryId) + { + // The category has been set. Check the category permissions. + return JFactory::getUser()->authorise('core.edit', $this->option . '.category.' . $categoryId); + } + else + { + // Since there is no asset tracking, revert to the component permissions. + return parent::allowEdit($data, $key); + } + } + + /** + * Method to run batch operations. + * + * @param object $model The model. + * + * @return boolean True if successful, false otherwise and internal error is set. + * + * @since 1.7 + */ + public function batch($model = null) + { + JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + + // Set the model + $model = $this->getModel('Weblink', '', array()); + + // Preset the redirect + $this->setRedirect(JRoute::_('index.php?option=com_weblinks&view=weblinks' . $this->getRedirectToListAppend(), false)); + + return parent::batch($model); + } + + /** + * Function that allows child controller access to model data after the data has been saved. + * + * @param JModelLegacy $model The data model object. + * @param array $validData The validated data. + * + * @return void + * + * @since 1.6 + */ + protected function postSaveHook(JModelLegacy $model, $validData = array()) + { + $task = $this->getTask(); + + if ($task == 'save') + { + $this->setRedirect(JRoute::_('index.php?option=com_weblinks&view=weblinks', false)); + } + } +} diff --git a/src/com_weblinks/admin/controllers/weblinks.php b/src/com_weblinks/admin/controllers/weblinks.php new file mode 100644 index 0000000..f78b72b --- /dev/null +++ b/src/com_weblinks/admin/controllers/weblinks.php @@ -0,0 +1,52 @@ + true)) + { + $model = parent::getModel($name, $prefix, $config); + + return $model; + } + + /** + * Method to provide child classes the opportunity to process after the delete task. + * + * @param JModelLegacy $model The model for the component + * @param mixed $ids array of ids deleted. + * + * @return void + * + * @since 3.1 + */ + protected function postDeleteHook(JModelLegacy $model, $ids = null) + { + } +} diff --git a/src/com_weblinks/admin/helpers/weblinks.php b/src/com_weblinks/admin/helpers/weblinks.php new file mode 100644 index 0000000..550a87c --- /dev/null +++ b/src/com_weblinks/admin/helpers/weblinks.php @@ -0,0 +1,44 @@ +Inherited means that the permissions from global configuration and parent group will be used.
Denied means that no matter what the global configuration or parent group settings are, the group being edited cannot take this action on this component.
Allowed means that the group being edited will be able to take this action for this component (but if this is in conflict with the global configuration or parent group it will have no impact; a conflict will be indicated by Not Allowed (Locked) under Calculated Settings).
2. If you select a new setting, click Save to refresh the calculated settings." diff --git a/src/com_weblinks/admin/language/en-GB/en-GB.com_weblinks.sys.ini b/src/com_weblinks/admin/language/en-GB/en-GB.com_weblinks.sys.ini new file mode 100644 index 0000000..f092a6b --- /dev/null +++ b/src/com_weblinks/admin/language/en-GB/en-GB.com_weblinks.sys.ini @@ -0,0 +1,21 @@ +; Joomla! Project +; Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 + +COM_WEBLINKS="Weblinks" +COM_WEBLINKS_XML_DESCRIPTION="Component for web links management" +COM_WEBLINKS_LINKS="Links" +COM_WEBLINKS_CATEGORIES="Categories" +COM_WEBLINKS_CATEGORY_ADD_TITLE="Category Manager: Add A New Weblinks Category" +COM_WEBLINKS_CATEGORY_EDIT_TITLE="Category Manager: Edit A Weblinks Category" +COM_WEBLINKS_CATEGORY_VIEW_DEFAULT_DESC="Displays a list of Web Links for a category" +COM_WEBLINKS_CATEGORY_VIEW_DEFAULT_OPTION="Default" +COM_WEBLINKS_CATEGORY_VIEW_DEFAULT_TITLE="List Web Links in a Category" +COM_WEBLINKS_CATEGORIES_VIEW_DEFAULT_DESC="Show all the web link categories within a category." +COM_WEBLINKS_CATEGORIES_VIEW_DEFAULT_OPTION="Default" +COM_WEBLINKS_CATEGORIES_VIEW_DEFAULT_TITLE="List All Web Link Categories" +COM_WEBLINKS_FORM_VIEW_DEFAULT_DESC="Display a form to submit a web link in the frontend." +COM_WEBLINKS_FORM_VIEW_DEFAULT_OPTION="Default" +COM_WEBLINKS_FORM_VIEW_DEFAULT_TITLE="Submit a Web Link" + diff --git a/src/com_weblinks/admin/models/forms/weblink.xml b/src/com_weblinks/admin/models/forms/weblink.xml new file mode 100644 index 0000000..4940bce --- /dev/null +++ b/src/com_weblinks/admin/models/forms/weblink.xml @@ -0,0 +1,272 @@ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + + + + + + + +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ + + + + + + + + + +
+
+
diff --git a/src/com_weblinks/admin/models/weblink.php b/src/com_weblinks/admin/models/weblink.php new file mode 100644 index 0000000..5742581 --- /dev/null +++ b/src/com_weblinks/admin/models/weblink.php @@ -0,0 +1,343 @@ +id)) + { + if ($record->state != -2) + { + return; + } + $user = JFactory::getUser(); + + if ($record->catid) + { + return $user->authorise('core.delete', 'com_weblinks.category.'.(int) $record->catid); + } + else + { + return parent::canDelete($record); + } + } + } + + /** + * Method to test whether a record can be deleted. + * + * @param object $record A record object. + * + * @return boolean True if allowed to change the state of the record. Defaults to the permission for the component. + * + * @since 1.6 + */ + protected function canEditState($record) + { + $user = JFactory::getUser(); + + if (!empty($record->catid)) + { + return $user->authorise('core.edit.state', 'com_weblinks.category.'.(int) $record->catid); + } + else + { + return parent::canEditState($record); + } + } + + /** + * Method to get a table object, load it if necessary. + * + * @param string $type The table name. Optional. + * @param string $prefix The class prefix. Optional. + * @param array $config Configuration array for model. Optional. + * + * @return JTable A JTable object + * + * @since 1.6 + */ + public function getTable($type = 'Weblink', $prefix = 'WeblinksTable', $config = array()) + { + return JTable::getInstance($type, $prefix, $config); + } + + /** + * Abstract method for getting the form from the model. + * + * @param array $data Data for the form. + * @param boolean $loadData True if the form is to load its own data (default case), false if not. + * + * @return mixed A JForm object on success, false on failure + * + * @since 1.6 + */ + public function getForm($data = array(), $loadData = true) + { + // Get the form. + $form = $this->loadForm('com_weblinks.weblink', 'weblink', array('control' => 'jform', 'load_data' => $loadData)); + + if (empty($form)) + { + return false; + } + + // Determine correct permissions to check. + if ($this->getState('weblink.id')) + { + // Existing record. Can only edit in selected categories. + $form->setFieldAttribute('catid', 'action', 'core.edit'); + } + else + { + // New record. Can only create in selected categories. + $form->setFieldAttribute('catid', 'action', 'core.create'); + } + + // Modify the form based on access controls. + if (!$this->canEditState((object) $data)) + { + // Disable fields for display. + $form->setFieldAttribute('ordering', 'disabled', 'true'); + $form->setFieldAttribute('state', 'disabled', 'true'); + $form->setFieldAttribute('publish_up', 'disabled', 'true'); + $form->setFieldAttribute('publish_down', 'disabled', 'true'); + + // Disable fields while saving. + // The controller has already verified this is a record you can edit. + $form->setFieldAttribute('ordering', 'filter', 'unset'); + $form->setFieldAttribute('state', 'filter', 'unset'); + $form->setFieldAttribute('publish_up', 'filter', 'unset'); + $form->setFieldAttribute('publish_down', 'filter', 'unset'); + } + + return $form; + } + + /** + * Method to get the data that should be injected in the form. + * + * @return array The default data is an empty array. + * + * @since 1.6 + */ + protected function loadFormData() + { + // Check the session for previously entered form data. + $data = JFactory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array()); + + if (empty($data)) + { + $data = $this->getItem(); + + // Prime some default values. + if ($this->getState('weblink.id') == 0) + { + $app = JFactory::getApplication(); + $data->set('catid', $app->input->get('catid', $app->getUserState('com_weblinks.weblinks.filter.category_id'), 'int')); + } + } + + $this->preprocessData('com_weblinks.weblink', $data); + + return $data; + } + + /** + * Method to get a single record. + * + * @param integer $pk The id of the primary key. + * + * @return mixed Object on success, false on failure. + * + * @since 1.6 + */ + public function getItem($pk = null) + { + if ($item = parent::getItem($pk)) + { + // Convert the metadata field to an array. + $registry = new JRegistry; + $registry->loadString($item->metadata); + $item->metadata = $registry->toArray(); + + // Convert the images field to an array. + $registry = new JRegistry; + $registry->loadString($item->images); + $item->images = $registry->toArray(); + + if (!empty($item->id)) + { + $item->tags = new JHelperTags; + $item->tags->getTagIds($item->id, 'com_weblinks.weblink'); + $item->metadata['tags'] = $item->tags; + } + } + + return $item; + } + + /** + * Prepare and sanitise the table data prior to saving. + * + * @param JTable $table A reference to a JTable object. + * + * @return void + * + * @since 1.6 + */ + protected function prepareTable($table) + { + $date = JFactory::getDate(); + $user = JFactory::getUser(); + + $table->title = htmlspecialchars_decode($table->title, ENT_QUOTES); + $table->alias = JApplication::stringURLSafe($table->alias); + + if (empty($table->alias)) + { + $table->alias = JApplication::stringURLSafe($table->title); + } + + if (empty($table->id)) + { + // Set the values + + // Set ordering to the last item if not set + if (empty($table->ordering)) + { + $db = JFactory::getDbo(); + $query = $db->getQuery(true) + ->select('MAX(ordering)') + ->from($db->quoteName('#__weblinks')); + + $db->setQuery($query); + $max = $db->loadResult(); + + $table->ordering = $max + 1; + } + else + { + // Set the values + $table->modified = $date->toSql(); + $table->modified_by = $user->get('id'); + } + } + + // Increment the weblink version number. + $table->version++; + } + + /** + * A protected method to get a set of ordering conditions. + * + * @param JTable $table A JTable object. + * + * @return array An array of conditions to add to ordering queries. + * + * @since 1.6 + */ + protected function getReorderConditions($table) + { + $condition = array(); + $condition[] = 'catid = ' . (int) $table->catid; + + return $condition; + } + + /** + * Method to save the form data. + * + * @param array $data The form data. + * + * @return boolean True on success. + * + * @since 3.1 + */ + public function save($data) + { + $app = JFactory::getApplication(); + + // Alter the title for save as copy + if ($app->input->get('task') == 'save2copy') + { + list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); + $data['title'] = $name; + $data['alias'] = $alias; + $data['state'] = 0; + } + + return parent::save($data); + } + + /** + * Method to change the title & alias. + * + * @param integer $category_id The id of the parent. + * @param string $alias The alias. + * @param string $name The title. + * + * @return array Contains the modified title and alias. + * + * @since 3.1 + */ + protected function generateNewTitle($category_id, $alias, $name) + { + // Alter the title & alias + $table = $this->getTable(); + + while ($table->load(array('alias' => $alias, 'catid' => $category_id))) + { + if ($name == $table->title) + { + $name = JString::increment($name); + } + + $alias = JString::increment($alias, 'dash'); + } + + return array($name, $alias); + } +} diff --git a/src/com_weblinks/admin/models/weblinks.php b/src/com_weblinks/admin/models/weblinks.php new file mode 100644 index 0000000..407caef --- /dev/null +++ b/src/com_weblinks/admin/models/weblinks.php @@ -0,0 +1,232 @@ +getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); + $this->setState('filter.search', $search); + + $accessId = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', null, 'int'); + $this->setState('filter.access', $accessId); + + $published = $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'string'); + $this->setState('filter.state', $published); + + $categoryId = $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', ''); + $this->setState('filter.category_id', $categoryId); + + $language = $this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', ''); + $this->setState('filter.language', $language); + + $tag = $this->getUserStateFromRequest($this->context . '.filter.tag', 'filter_tag', ''); + $this->setState('filter.tag', $tag); + + // Load the parameters. + $params = JComponentHelper::getParams('com_weblinks'); + $this->setState('params', $params); + + // List state information. + parent::populateState('a.title', 'asc'); + } + + /** + * Method to get a store id based on model configuration state. + * + * This is necessary because the model is used by the component and + * different modules that might need different sets of data or different + * ordering requirements. + * + * @param string $id A prefix for the store id. + * @return string A store id. + * @since 1.6 + */ + protected function getStoreId($id = '') + { + // Compile the store id. + $id .= ':' . $this->getState('filter.search'); + $id .= ':' . $this->getState('filter.access'); + $id .= ':' . $this->getState('filter.state'); + $id .= ':' . $this->getState('filter.category_id'); + $id .= ':' . $this->getState('filter.language'); + + return parent::getStoreId($id); + } + + /** + * Build an SQL query to load the list data. + * + * @return JDatabaseQuery + * @since 1.6 + */ + protected function getListQuery() + { + // Create a new query object. + $db = $this->getDbo(); + $query = $db->getQuery(true); + $user = JFactory::getUser(); + + // Select the required fields from the table. + $query->select( + $this->getState( + 'list.select', + 'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid,' . + 'a.hits,' . + 'a.state, a.access, a.ordering,' . + 'a.language, a.publish_up, a.publish_down' + ) + ); + $query->from($db->quoteName('#__weblinks') . ' AS a'); + + // Join over the language + $query->select('l.title AS language_title') + ->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = a.language'); + + // Join over the users for the checked out user. + $query->select('uc.name AS editor') + ->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); + + // Join over the asset groups. + $query->select('ag.title AS access_level') + ->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); + + // Join over the categories. + $query->select('c.title AS category_title') + ->join('LEFT', '#__categories AS c ON c.id = a.catid'); + + // Filter by access level. + if ($access = $this->getState('filter.access')) + { + $query->where('a.access = ' . (int) $access); + } + + // Implement View Level Access + if (!$user->authorise('core.admin')) + { + $groups = implode(',', $user->getAuthorisedViewLevels()); + $query->where('a.access IN (' . $groups . ')'); + } + + // Filter by published state + $published = $this->getState('filter.state'); + if (is_numeric($published)) + { + $query->where('a.state = ' . (int) $published); + } + elseif ($published === '') + { + $query->where('(a.state IN (0, 1))'); + } + + // Filter by category. + $categoryId = $this->getState('filter.category_id'); + if (is_numeric($categoryId)) + { + $query->where('a.catid = ' . (int) $categoryId); + } + + // Filter by search in title + $search = $this->getState('filter.search'); + if (!empty($search)) + { + if (stripos($search, 'id:') === 0) + { + $query->where('a.id = ' . (int) substr($search, 3)); + } + else + { + $search = $db->quote('%' . $db->escape($search, true) . '%'); + $query->where('(a.title LIKE ' . $search . ' OR a.alias LIKE ' . $search . ')'); + } + } + + // Filter on the language. + if ($language = $this->getState('filter.language')) + { + $query->where('a.language = ' . $db->quote($language)); + } + + $tagId = $this->getState('filter.tag'); + // Filter by a single tag. + if (is_numeric($tagId)) + { + $query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId) + ->join( + 'LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap') + . ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id') + . ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_weblinks.weblink') + ); + } + + // Add the list ordering clause. + $orderCol = $this->state->get('list.ordering'); + $orderDirn = $this->state->get('list.direction'); + if ($orderCol == 'a.ordering' || $orderCol == 'category_title') + { + $orderCol = 'c.title ' . $orderDirn . ', a.ordering'; + } + $query->order($db->escape($orderCol . ' ' . $orderDirn)); + + //echo nl2br(str_replace('#__','jos_',$query)); + return $query; + } +} diff --git a/src/com_weblinks/admin/sql/install.mysql.utf8.sql b/src/com_weblinks/admin/sql/install.mysql.utf8.sql new file mode 100644 index 0000000..4723ee0 --- /dev/null +++ b/src/com_weblinks/admin/sql/install.mysql.utf8.sql @@ -0,0 +1,42 @@ +CREATE TABLE IF NOT EXISTS `#__weblinks` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `catid` int(11) NOT NULL DEFAULT '0', + `sid` int(11) NOT NULL DEFAULT '0', + `title` varchar(250) NOT NULL DEFAULT '', + `alias` varchar(255) NOT NULL DEFAULT '', + `url` varchar(250) NOT NULL DEFAULT '', + `description` text NOT NULL, + `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `hits` int(11) NOT NULL DEFAULT '0', + `state` tinyint(1) NOT NULL DEFAULT '0', + `checked_out` int(11) NOT NULL DEFAULT '0', + `checked_out_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `ordering` int(11) NOT NULL DEFAULT '0', + `archived` tinyint(1) NOT NULL DEFAULT '0', + `approved` tinyint(1) NOT NULL DEFAULT '1', + `access` int(11) NOT NULL DEFAULT '1', + `params` text NOT NULL, + `language` char(7) NOT NULL DEFAULT '', + `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `created_by` int(10) unsigned NOT NULL DEFAULT '0', + `created_by_alias` varchar(255) NOT NULL DEFAULT '', + `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `modified_by` int(10) unsigned NOT NULL DEFAULT '0', + `metakey` text NOT NULL, + `metadesc` text NOT NULL, + `metadata` text NOT NULL, + `featured` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'Set if link is featured.', + `xreference` varchar(50) NOT NULL COMMENT 'A reference to enable linkages to external data sets.', + `publish_up` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `publish_down` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY (`id`), + KEY `idx_access` (`access`), + KEY `idx_checkout` (`checked_out`), + KEY `idx_state` (`state`), + KEY `idx_catid` (`catid`), + KEY `idx_createdby` (`created_by`), + KEY `idx_featured_catid` (`featured`,`catid`), + KEY `idx_language` (`language`), + KEY `idx_xreference` (`xreference`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + diff --git a/src/com_weblinks/admin/sql/uninstall.mysql.utf8.sql b/src/com_weblinks/admin/sql/uninstall.mysql.utf8.sql new file mode 100644 index 0000000..b53cccc --- /dev/null +++ b/src/com_weblinks/admin/sql/uninstall.mysql.utf8.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS `#__weblinks`; \ No newline at end of file diff --git a/src/com_weblinks/admin/tables/weblink.php b/src/com_weblinks/admin/tables/weblink.php new file mode 100644 index 0000000..557555e --- /dev/null +++ b/src/com_weblinks/admin/tables/weblink.php @@ -0,0 +1,286 @@ +loadArray($array['params']); + $array['params'] = (string) $registry; + } + + if (isset($array['metadata']) && is_array($array['metadata'])) + { + $registry = new JRegistry; + $registry->loadArray($array['metadata']); + $array['metadata'] = (string) $registry; + } + + if (isset($array['images']) && is_array($array['images'])) + { + $registry = new JRegistry; + $registry->loadArray($array['images']); + $array['images'] = (string) $registry; + } + + return parent::bind($array, $ignore); + } + + /** + * Overload the store method for the Weblinks table. + * + * @param boolean Toggle whether null values should be updated. + * @return boolean True on success, false on failure. + * @since 1.6 + */ + public function store($updateNulls = false) + { + $date = JFactory::getDate(); + $user = JFactory::getUser(); + + if ($this->id) + { + // Existing item + $this->modified = $date->toSql(); + $this->modified_by = $user->get('id'); + } + else + { + // New weblink. A weblink created and created_by field can be set by the user, + // so we don't touch either of these if they are set. + if (!(int) $this->created) + { + $this->created = $date->toSql(); + } + if (empty($this->created_by)) + { + $this->created_by = $user->get('id'); + } + } + + // Set publish_up to null date if not set + if (!$this->publish_up) + { + $this->publish_up = $this->_db->getNullDate(); + } + + // Set publish_down to null date if not set + if (!$this->publish_down) + { + $this->publish_down = $this->_db->getNullDate(); + } + + // Verify that the alias is unique + $table = JTable::getInstance('Weblink', 'WeblinksTable'); + + if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) + { + $this->setError(JText::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS')); + return false; + } + + // Convert IDN urls to punycode + $this->url = JStringPunycode::urlToPunycode($this->url); + + return parent::store($updateNulls); + } + + /** + * Overloaded check method to ensure data integrity. + * + * @return boolean True on success. + */ + public function check() + { + if (JFilterInput::checkAttribute(array ('href', $this->url))) + { + $this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL')); + return false; + } + + // check for valid name + if (trim($this->title) == '') + { + $this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_TITLE')); + return false; + } + + // Check for existing name + $query = $this->_db->getQuery(true) + ->select($this->_db->quoteName('id')) + ->from($this->_db->quoteName('#__weblinks')) + ->where($this->_db->quoteName('title') . ' = ' . $this->_db->quote($this->title)) + ->where($this->_db->quoteName('catid') . ' = ' . (int) $this->catid); + $this->_db->setQuery($query); + + $xid = (int) $this->_db->loadResult(); + if ($xid && $xid != (int) $this->id) + { + $this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_NAME')); + return false; + } + + if (empty($this->alias)) + { + $this->alias = $this->title; + } + $this->alias = JApplication::stringURLSafe($this->alias); + if (trim(str_replace('-', '', $this->alias)) == '') + { + $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s"); + } + + // Check the publish down date is not earlier than publish up. + if ($this->publish_down > $this->_db->getNullDate() && $this->publish_down < $this->publish_up) + { + $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH')); + return false; + } + + // clean up keywords -- eliminate extra spaces between phrases + // and cr (\r) and lf (\n) characters from string + if (!empty($this->metakey)) + { + // only process if not empty + $bad_characters = array("\n", "\r", "\"", "<", ">"); // array of characters to remove + $after_clean = JString::str_ireplace($bad_characters, "", $this->metakey); // remove bad characters + $keys = explode(',', $after_clean); // create array using commas as delimiter + $clean_keys = array(); + + foreach ($keys as $key) + { + if (trim($key)) { // ignore blank keywords + $clean_keys[] = trim($key); + } + } + $this->metakey = implode(", ", $clean_keys); // put array back together delimited by ", " + } + + return true; + } + + /** + * Method to set the publishing state for a row or list of rows in the database + * table. The method respects checked out rows by other users and will attempt + * to checkin rows that it can after adjustments are made. + * + * @param mixed An optional array of primary key values to update. If not + * set the instance property value is used. + * @param integer The publishing state. eg. [0 = unpublished, 1 = published] + * @param integer The user id of the user performing the operation. + * @return boolean True on success. + * @since 1.0.4 + */ + public function publish($pks = null, $state = 1, $userId = 0) + { + $k = $this->_tbl_key; + + // Sanitize input. + JArrayHelper::toInteger($pks); + $userId = (int) $userId; + $state = (int) $state; + + // If there are no primary keys set check to see if the instance key is set. + if (empty($pks)) + { + if ($this->$k) + { + $pks = array($this->$k); + } + // Nothing to set publishing state on, return false. + else { + $this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED')); + return false; + } + } + + // Build the WHERE clause for the primary keys. + $where = $k.'='.implode(' OR '.$k.'=', $pks); + + // Determine if there is checkin support for the table. + if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time')) + { + $checkin = ''; + } + else + { + $checkin = ' AND (checked_out = 0 OR checked_out = '.(int) $userId.')'; + } + + // Update the publishing state for rows with the given primary keys. + $this->_db->setQuery( + 'UPDATE '.$this->_db->quoteName($this->_tbl) . + ' SET '.$this->_db->quoteName('state').' = '.(int) $state . + ' WHERE ('.$where.')' . + $checkin + ); + + try + { + $this->_db->execute(); + } + catch (RuntimeException $e) + { + $this->setError($e->getMessage()); + return false; + } + + // If checkin is supported and all rows were adjusted, check them in. + if ($checkin && (count($pks) == $this->_db->getAffectedRows())) + { + // Checkin the rows. + foreach ($pks as $pk) + { + $this->checkin($pk); + } + } + + // If the JTable instance value is in the list of primary keys that were set, set the instance. + if (in_array($this->$k, $pks)) + { + $this->state = $state; + } + + $this->setError(''); + return true; + } +} diff --git a/src/com_weblinks/admin/views/weblink/tmpl/edit.php b/src/com_weblinks/admin/views/weblink/tmpl/edit.php new file mode 100644 index 0000000..64ca6f0 --- /dev/null +++ b/src/com_weblinks/admin/views/weblink/tmpl/edit.php @@ -0,0 +1,80 @@ + + + + diff --git a/src/com_weblinks/admin/views/weblink/tmpl/edit_metadata.php b/src/com_weblinks/admin/views/weblink/tmpl/edit_metadata.php new file mode 100644 index 0000000..c7444b2 --- /dev/null +++ b/src/com_weblinks/admin/views/weblink/tmpl/edit_metadata.php @@ -0,0 +1,12 @@ +form->getFieldsets('params'); +foreach ($fieldSets as $name => $fieldSet) : + ?> +
+ description) && trim($fieldSet->description)) : + echo '

'.$this->escape(JText::_($fieldSet->description)).'

'; + endif; + ?> + form->getFieldset($name) as $field) : ?> +
+
label; ?>
+
input; ?>
+
+ +
+ diff --git a/src/com_weblinks/admin/views/weblink/view.html.php b/src/com_weblinks/admin/views/weblink/view.html.php new file mode 100644 index 0000000..152243d --- /dev/null +++ b/src/com_weblinks/admin/views/weblink/view.html.php @@ -0,0 +1,97 @@ +state = $this->get('State'); + $this->item = $this->get('Item'); + $this->form = $this->get('Form'); + + // Check for errors. + if (count($errors = $this->get('Errors'))) + { + JError::raiseError(500, implode("\n", $errors)); + return false; + } + + $this->addToolbar(); + parent::display($tpl); + } + + /** + * Add the page title and toolbar. + * + * @since 1.6 + */ + protected function addToolbar() + { + JFactory::getApplication()->input->set('hidemainmenu', true); + + $user = JFactory::getUser(); + $isNew = ($this->item->id == 0); + $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id')); + + // Since we don't track these assets at the item level, use the category id. + $canDo = JHelperContent::getActions('com_weblinks', 'category', $this->item->catid); + + JToolbarHelper::title(JText::_('COM_WEBLINKS_MANAGER_WEBLINK'), 'link weblinks'); + + // If not checked out, can save the item. + if (!$checkedOut && ($canDo->get('core.edit')||(count($user->getAuthorisedCategories('com_weblinks', 'core.create'))))) + { + JToolbarHelper::apply('weblink.apply'); + JToolbarHelper::save('weblink.save'); + } + if (!$checkedOut && (count($user->getAuthorisedCategories('com_weblinks', 'core.create')))) + { + JToolbarHelper::save2new('weblink.save2new'); + } + // If an existing item, can save to a copy. + if (!$isNew && (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)) + { + JToolbarHelper::save2copy('weblink.save2copy'); + } + if (empty($this->item->id)) + { + JToolbarHelper::cancel('weblink.cancel'); + } + else + { + if ($this->state->params->get('save_history', 0) && $user->authorise('core.edit')) + { + JToolbarHelper::versions('com_weblinks.weblink', $this->item->id); + } + + JToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE'); + } + + JToolbarHelper::divider(); + JToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS_EDIT'); + } +} diff --git a/src/com_weblinks/admin/views/weblinks/tmpl/default.php b/src/com_weblinks/admin/views/weblinks/tmpl/default.php new file mode 100644 index 0000000..1b00ae8 --- /dev/null +++ b/src/com_weblinks/admin/views/weblinks/tmpl/default.php @@ -0,0 +1,211 @@ +get('id'); +$listOrder = $this->escape($this->state->get('list.ordering')); +$listDirn = $this->escape($this->state->get('list.direction')); +$canOrder = $user->authorise('core.edit.state', 'com_weblinks.category'); +$saveOrder = $listOrder == 'a.ordering'; +if ($saveOrder) +{ + $saveOrderingUrl = 'index.php?option=com_weblinks&task=weblinks.saveOrderAjax&tmpl=component'; + JHtml::_('sortablelist.sortable', 'weblinkList', 'adminForm', strtolower($listDirn), $saveOrderingUrl); +} +$sortFields = $this->getSortFields(); +?> + +
+sidebar)) : ?> +
+ sidebar; ?> +
+
+ +
+ +
+ +
+ + +
+
+ + pagination->getLimitBox(); ?> +
+
+ + +
+
+ + +
+
+
+ items)) : ?> +
+ +
+ + + + + + + + + + + + + + + + + + + + + items as $i => $item) : + $ordering = ($listOrder == 'a.ordering'); + $item->cat_link = JRoute::_('index.php?option=com_categories&extension=com_weblinks&task=edit&type=other&cid[]='. $item->catid); + $canCreate = $user->authorise('core.create', 'com_weblinks.category.' . $item->catid); + $canEdit = $user->authorise('core.edit', 'com_weblinks.category.' . $item->catid); + $canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $user->get('id') || $item->checked_out == 0; + $canChange = $user->authorise('core.edit.state', 'com_weblinks.category.' . $item->catid) && $canCheckin; + ?> + + + + + + + + + + + + + + + + + loadTemplate('batch'); ?> + + + + + + +
+ diff --git a/src/com_weblinks/admin/views/weblinks/tmpl/default_batch.php b/src/com_weblinks/admin/views/weblinks/tmpl/default_batch.php new file mode 100644 index 0000000..a634a5e --- /dev/null +++ b/src/com_weblinks/admin/views/weblinks/tmpl/default_batch.php @@ -0,0 +1,56 @@ +state->get('filter.state'); +?> + diff --git a/src/com_weblinks/admin/views/weblinks/view.html.php b/src/com_weblinks/admin/views/weblinks/view.html.php new file mode 100644 index 0000000..45abc86 --- /dev/null +++ b/src/com_weblinks/admin/views/weblinks/view.html.php @@ -0,0 +1,164 @@ +state = $this->get('State'); + $this->items = $this->get('Items'); + $this->pagination = $this->get('Pagination'); + + WeblinksHelper::addSubmenu('weblinks'); + + // Check for errors. + if (count($errors = $this->get('Errors'))) + { + JError::raiseError(500, implode("\n", $errors)); + return false; + } + + $this->addToolbar(); + $this->sidebar = JHtmlSidebar::render(); + parent::display($tpl); + } + + /** + * Add the page title and toolbar. + * + * @since 1.6 + */ + protected function addToolbar() + { + require_once JPATH_COMPONENT . '/helpers/weblinks.php'; + + $state = $this->get('State'); + $canDo = JHelperContent::getActions('com_weblinks', 'category', $state->get('filter.category_id')); + $user = JFactory::getUser(); + + // Get the toolbar object instance + $bar = JToolBar::getInstance('toolbar'); + + JToolbarHelper::title(JText::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks'); + if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0) + { + JToolbarHelper::addNew('weblink.add'); + } + if ($canDo->get('core.edit')) + { + JToolbarHelper::editList('weblink.edit'); + } + if ($canDo->get('core.edit.state')) { + + JToolbarHelper::publish('weblinks.publish', 'JTOOLBAR_PUBLISH', true); + JToolbarHelper::unpublish('weblinks.unpublish', 'JTOOLBAR_UNPUBLISH', true); + + JToolbarHelper::archiveList('weblinks.archive'); + JToolbarHelper::checkin('weblinks.checkin'); + } + if ($state->get('filter.state') == -2 && $canDo->get('core.delete')) + { + JToolbarHelper::deleteList('', 'weblinks.delete', 'JTOOLBAR_EMPTY_TRASH'); + } elseif ($canDo->get('core.edit.state')) + { + JToolbarHelper::trash('weblinks.trash'); + } + // Add a batch button + if ($user->authorise('core.create', 'com_weblinks') && $user->authorise('core.edit', 'com_weblinks') && $user->authorise('core.edit.state', 'com_weblinks')) + { + JHtml::_('bootstrap.modal', 'collapseModal'); + $title = JText::_('JTOOLBAR_BATCH'); + + // Instantiate a new JLayoutFile instance and render the batch button + $layout = new JLayoutFile('joomla.toolbar.batch'); + + $dhtml = $layout->render(array('title' => $title)); + $bar->appendButton('Custom', $dhtml, 'batch'); + } + if ($user->authorise('core.admin', 'com_weblinks')) + { + JToolbarHelper::preferences('com_weblinks'); + } + + JToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS'); + + JHtmlSidebar::setAction('index.php?option=com_weblinks&view=weblinks'); + + JHtmlSidebar::addFilter( + JText::_('JOPTION_SELECT_PUBLISHED'), + 'filter_state', + JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), 'value', 'text', $this->state->get('filter.state'), true) + ); + + JHtmlSidebar::addFilter( + JText::_('JOPTION_SELECT_CATEGORY'), + 'filter_category_id', + JHtml::_('select.options', JHtml::_('category.options', 'com_weblinks'), 'value', 'text', $this->state->get('filter.category_id')) + ); + + JHtmlSidebar::addFilter( + JText::_('JOPTION_SELECT_ACCESS'), + 'filter_access', + JHtml::_('select.options', JHtml::_('access.assetgroups'), 'value', 'text', $this->state->get('filter.access')) + ); + + JHtmlSidebar::addFilter( + JText::_('JOPTION_SELECT_LANGUAGE'), + 'filter_language', + JHtml::_('select.options', JHtml::_('contentlanguage.existing', true, true), 'value', 'text', $this->state->get('filter.language')) + ); + + JHtmlSidebar::addFilter( + JText::_('JOPTION_SELECT_TAG'), + 'filter_tag', + JHtml::_('select.options', JHtml::_('tag.options', true, true), 'value', 'text', $this->state->get('filter.tag')) + ); + + } + + /** + * Returns an array of fields the table can be sorted by + * + * @return array Array containing the field name to sort by as the key and display text as value + * + * @since 3.0 + */ + protected function getSortFields() + { + return array( + 'a.ordering' => JText::_('JGRID_HEADING_ORDERING'), + 'a.state' => JText::_('JSTATUS'), + 'a.title' => JText::_('JGLOBAL_TITLE'), + 'a.access' => JText::_('JGRID_HEADING_ACCESS'), + 'a.hits' => JText::_('JGLOBAL_HITS'), + 'a.language' => JText::_('JGRID_HEADING_LANGUAGE'), + 'a.id' => JText::_('JGRID_HEADING_ID') + ); + } +} diff --git a/src/com_weblinks/admin/weblinks.php b/src/com_weblinks/admin/weblinks.php new file mode 100644 index 0000000..7f3832a --- /dev/null +++ b/src/com_weblinks/admin/weblinks.php @@ -0,0 +1,20 @@ +authorise('core.manage', 'com_weblinks')) +{ + return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); +} + +$controller = JControllerLegacy::getInstance('Weblinks'); +$controller->execute(JFactory::getApplication()->input->get('task')); +$controller->redirect(); diff --git a/src/com_weblinks/admin/weblinks.xml b/src/com_weblinks/admin/weblinks.xml new file mode 100644 index 0000000..c8c1f6a --- /dev/null +++ b/src/com_weblinks/admin/weblinks.xml @@ -0,0 +1,71 @@ + + + com_weblinks + Joomla! Project + April 2006 + (C) 2005 - 2014 Open Source Matters. All rights reserved. + + GNU General Public License version 2 or later; see + LICENSE.txt + admin@joomla.org + www.joomla.org + 3.0.0 + COM_WEBLINKS_XML_DESCRIPTION + + + + sql/install.mysql.utf8.sql + + + + + sql/uninstall.mysql.utf8.sql + + + + + index.html + weblinks.php + controller.php + router.php + metadata.xml + views + models + controllers + helpers + + + language/en-GB.com_weblinks.ini + + + com_weblinks + + + com_weblinks_links + com_weblinks_categories + + + access.xml + config.xml + controller.php + index.html + weblinks.php + controllers + helpers + models + sql + tables + views + + + language/en-GB.com_weblinks.ini + language/en-GB.com_weblinks.sys.ini + + + + diff --git a/src/com_weblinks/site/controller.php b/src/com_weblinks/site/controller.php new file mode 100644 index 0000000..b0d0f86 --- /dev/null +++ b/src/com_weblinks/site/controller.php @@ -0,0 +1,65 @@ +input->getInt('w_id'); + $vName = $this->input->get('view', 'categories'); + $this->input->set('view', $vName); + + if ($user->get('id') ||($this->input->getMethod() == 'POST' && $vName = 'categories')) + { + $cachable = false; + } + + $safeurlparams = array( + 'id' => 'INT', + 'limit' => 'UINT', + 'limitstart' => 'UINT', + 'filter_order' => 'CMD', + 'filter_order_Dir' => 'CMD', + 'lang' => 'CMD' + ); + + // Check for edit form. + if ($vName == 'form' && !$this->checkEditId('com_weblinks.edit.weblink', $id)) + { + // Somehow the person just went to the form - we don't allow that. + return JError::raiseError(403, JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); + } + + return parent::display($cachable, $safeurlparams); + } +} diff --git a/src/com_weblinks/site/controllers/weblink.php b/src/com_weblinks/site/controllers/weblink.php new file mode 100644 index 0000000..f41de16 --- /dev/null +++ b/src/com_weblinks/site/controllers/weblink.php @@ -0,0 +1,313 @@ +setRedirect($this->getReturnPage()); + } + } + + /** + * Method override to check if you can add a new record. + * + * @param array $data An array of input data. + * @return boolean + * @since 1.6 + */ + protected function allowAdd($data = array()) + { + $user = JFactory::getUser(); + $categoryId = JArrayHelper::getValue($data, 'catid', $this->input->getInt('id'), 'int'); + $allow = null; + + if ($categoryId) + { + // If the category has been passed in the URL check it. + $allow = $user->authorise('core.create', $this->option.'.category.'.$categoryId); + } + + if ($allow === null) + { + // In the absense of better information, revert to the component permissions. + return parent::allowAdd($data); + } + else + { + return $allow; + } + } + + /** + * Method to check if you can add a new record. + * + * @param array $data An array of input data. + * @param string $key The name of the key for the primary key. + * + * @return boolean + * @since 1.6 + */ + protected function allowEdit($data = array(), $key = 'id') + { + $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + $categoryId = 0; + + if ($recordId) + { + $categoryId = (int) $this->getModel()->getItem($recordId)->catid; + } + + if ($categoryId) + { + // The category has been set. Check the category permissions. + return JFactory::getUser()->authorise('core.edit', $this->option.'.category.'.$categoryId); + } + else + { + // Since there is no asset tracking, revert to the component permissions. + return parent::allowEdit($data, $key); + } + } + + /** + * Method to cancel an edit. + * + * @param string $key The name of the primary key of the URL variable. + * + * @return Boolean True if access level checks pass, false otherwise. + * @since 1.6 + */ + public function cancel($key = 'w_id') + { + parent::cancel($key); + + // Redirect to the return page. + $this->setRedirect($this->getReturnPage()); + } + + /** + * Method to edit an existing record. + * + * @param string $key The name of the primary key of the URL variable. + * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions). + * + * @return Boolean True if access level check and checkout passes, false otherwise. + * @since 1.6 + */ + public function edit($key = null, $urlVar = 'w_id') + { + $result = parent::edit($key, $urlVar); + + return $result; + } + + /** + * Method to get a model object, loading it if required. + * + * @param string $name The model name. Optional. + * @param string $prefix The class prefix. Optional. + * @param array $config Configuration array for model. Optional. + * + * @return object The model. + * @since 1.5 + */ + public function getModel($name = 'form', $prefix = '', $config = array('ignore_request' => true)) + { + $model = parent::getModel($name, $prefix, $config); + + return $model; + } + + /** + * Gets the URL arguments to append to an item redirect. + * + * @param integer $recordId The primary key id for the item. + * @param string $urlVar The name of the URL variable for the id. + * + * @return string The arguments to append to the redirect URL. + * @since 1.6 + */ + protected function getRedirectToItemAppend($recordId = null, $urlVar = null) + { + $append = parent::getRedirectToItemAppend($recordId, $urlVar); + $itemId = $this->input->getInt('Itemid'); + $return = $this->getReturnPage(); + + if ($itemId) + { + $append .= '&Itemid='.$itemId; + } + + if ($return) + { + $append .= '&return='.base64_encode($return); + } + + return $append; + } + + /** + * Get the return URL. + * + * If a "return" variable has been passed in the request + * + * @return string The return URL. + * @since 1.6 + */ + protected function getReturnPage() + { + $return = $this->input->get('return', null, 'base64'); + + if (empty($return) || !JUri::isInternal(base64_decode($return))) + { + return JUri::base(); + } + else + { + return base64_decode($return); + } + } + + /** + * Function that allows child controller access to model data after the data has been saved. + * + * @param JModelLegacy $model The data model object. + * @param array $validData The validated data. + * + * @return void + * @since 1.6 + */ + protected function postSaveHook(JModelLegacy $model, $validData = array()) + { + return; + } + + /** + * Method to save a record. + * + * @param string $key The name of the primary key of the URL variable. + * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions). + * + * @return Boolean True if successful, false otherwise. + * @since 1.6 + */ + public function save($key = null, $urlVar = 'w_id') + { + $result = parent::save($key, $urlVar); + + // If ok, redirect to the return page. + if ($result) + { + $this->setRedirect($this->getReturnPage()); + } + + return $result; + } + + /** + * Go to a weblink + * + * @return void + * @since 1.6 + */ + public function go() + { + // Get the ID from the request + $id = $this->input->getInt('id'); + + // Get the model, requiring published items + $modelLink = $this->getModel('Weblink', '', array('ignore_request' => true)); + $modelLink->setState('filter.published', 1); + + // Get the item + $link = $modelLink->getItem($id); + + // Make sure the item was found. + if (empty($link)) + { + return JError::raiseWarning(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND')); + } + + // Check whether item access level allows access. + $user = JFactory::getUser(); + $groups = $user->getAuthorisedViewLevels(); + + if (!in_array($link->access, $groups)) + { + return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); + } + + // Check whether category access level allows access. + $modelCat = $this->getModel('Category', 'WeblinksModel', array('ignore_request' => true)); + $modelCat->setState('filter.published', 1); + + // Get the category + $category = $modelCat->getCategory($link->catid); + + // Make sure the category was found. + if (empty($category)) + { + return JError::raiseWarning(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND')); + } + + // Check whether item access level allows access. + if (!in_array($category->access, $groups)) + { + return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); + } + + // Redirect to the URL + // TODO: Probably should check for a valid http link + if ($link->url) + { + $modelLink->hit($id); + JFactory::getApplication()->redirect($link->url); + } + else + { + return JError::raiseWarning(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_URL_INVALID')); + } + } +} diff --git a/src/com_weblinks/site/helpers/association.php b/src/com_weblinks/site/helpers/association.php new file mode 100644 index 0000000..7dd8512 --- /dev/null +++ b/src/com_weblinks/site/helpers/association.php @@ -0,0 +1,52 @@ +input; + $view = is_null($view) ? $jinput->get('view') : $view; + $id = empty($id) ? $jinput->getInt('id') : $id; + + if ($view == 'category' || $view == 'categories') + { + return self::getCategoryAssociations($id, 'com_weblinks'); + } + + return array(); + + } +} diff --git a/src/com_weblinks/site/helpers/category.php b/src/com_weblinks/site/helpers/category.php new file mode 100644 index 0000000..66c1ce6 --- /dev/null +++ b/src/com_weblinks/site/helpers/category.php @@ -0,0 +1,28 @@ +' . $button . ''; + return $output; + } + + public static function edit($weblink, $params, $attribs = array()) + { + $uri = JUri::getInstance(); + + if ($params && $params->get('popup')) + { + return; + } + + if ($weblink->state < 0) + { + return; + } + + JHtml::_('bootstrap.tooltip'); + + $url = WeblinksHelperRoute::getFormRoute($weblink->id, base64_encode($uri)); + $icon = $weblink->state ? 'edit.png' : 'edit_unpublished.png'; + $text = JHtml::_('image', 'system/'.$icon, JText::_('JGLOBAL_EDIT'), null, true); + + if ($weblink->state == 0) + { + $overlib = JText::_('JUNPUBLISHED'); + } + else + { + $overlib = JText::_('JPUBLISHED'); + } + + $date = JHtml::_('date', $weblink->created); + $author = $weblink->created_by_alias ? $weblink->created_by_alias : $weblink->author; + + $overlib .= '<br />'; + $overlib .= $date; + $overlib .= '<br />'; + $overlib .= htmlspecialchars($author, ENT_COMPAT, 'UTF-8'); + + $button = JHtml::_('link', JRoute::_($url), $text); + + $output = '' . $button . ''; + + return $output; + } +} diff --git a/src/com_weblinks/site/helpers/route.php b/src/com_weblinks/site/helpers/route.php new file mode 100644 index 0000000..6aecedd --- /dev/null +++ b/src/com_weblinks/site/helpers/route.php @@ -0,0 +1,241 @@ + array((int) $id) + ); + + //Create the link + $link = 'index.php?option=com_weblinks&view=weblink&id='. $id; + + if ($catid > 1) + { + $categories = JCategories::getInstance('Weblinks'); + $category = $categories->get($catid); + + if ($category) + { + $needles['category'] = array_reverse($category->getPath()); + $needles['categories'] = $needles['category']; + $link .= '&catid='.$catid; + } + } + + if ($language && $language != "*" && JLanguageMultilang::isEnabled()) + { + self::buildLanguageLookup(); + + if (isset(self::$lang_lookup[$language])) + { + $link .= '&lang=' . self::$lang_lookup[$language]; + $needles['language'] = $language; + } + } + + if ($item = self::_findItem($needles)) + { + $link .= '&Itemid='.$item; + } + + return $link; + } + + /** + * @param integer $id The id of the weblink. + * @param string $return The return page variable. + */ + public static function getFormRoute($id, $return = null) + { + // Create the link. + if ($id) + { + $link = 'index.php?option=com_weblinks&task=weblink.edit&w_id='. $id; + } + else + { + $link = 'index.php?option=com_weblinks&task=weblink.add&w_id=0'; + } + + if ($return) + { + $link .= '&return='.$return; + } + + return $link; + } + + public static function getCategoryRoute($catid, $language = 0) + { + if ($catid instanceof JCategoryNode) + { + $id = $catid->id; + $category = $catid; + } + else + { + $id = (int) $catid; + $category = JCategories::getInstance('Weblinks')->get($id); + } + + if ($id < 1 || !($category instanceof JCategoryNode)) + { + $link = ''; + } + else + { + $needles = array(); + + // Create the link + $link = 'index.php?option=com_weblinks&view=category&id='.$id; + + $catids = array_reverse($category->getPath()); + $needles['category'] = $catids; + $needles['categories'] = $catids; + + if ($language && $language != "*" && JLanguageMultilang::isEnabled()) + { + self::buildLanguageLookup(); + + if (isset(self::$lang_lookup[$language])) + { + $link .= '&lang=' . self::$lang_lookup[$language]; + $needles['language'] = $language; + } + } + + if ($item = self::_findItem($needles)) + { + $link .= '&Itemid='.$item; + } + } + + return $link; + } + + protected static function buildLanguageLookup() + { + if (count(self::$lang_lookup) == 0) + { + $db = JFactory::getDbo(); + $query = $db->getQuery(true) + ->select('a.sef AS sef') + ->select('a.lang_code AS lang_code') + ->from('#__languages AS a'); + + $db->setQuery($query); + $langs = $db->loadObjectList(); + + foreach ($langs as $lang) + { + self::$lang_lookup[$lang->lang_code] = $lang->sef; + } + } + } + + protected static function _findItem($needles = null) + { + $app = JFactory::getApplication(); + $menus = $app->getMenu('site'); + $language = isset($needles['language']) ? $needles['language'] : '*'; + + // Prepare the reverse lookup array. + if (!isset(self::$lookup[$language])) + { + self::$lookup[$language] = array(); + + $component = JComponentHelper::getComponent('com_weblinks'); + + $attributes = array('component_id'); + $values = array($component->id); + + if ($language != '*') + { + $attributes[] = 'language'; + $values[] = array($needles['language'], '*'); + } + + $items = $menus->getItems($attributes, $values); + + if ($items) + { + foreach ($items as $item) + { + if (isset($item->query) && isset($item->query['view'])) + { + $view = $item->query['view']; + if (!isset(self::$lookup[$language][$view])) + { + self::$lookup[$language][$view] = array(); + } + if (isset($item->query['id'])) + { + + // here it will become a bit tricky + // language != * can override existing entries + // language == * cannot override existing entries + if (!isset(self::$lookup[$language][$view][$item->query['id']]) || $item->language != '*') + { + self::$lookup[$language][$view][$item->query['id']] = $item->id; + } + } + } + } + } + } + + if ($needles) + { + foreach ($needles as $view => $ids) + { + if (isset(self::$lookup[$language][$view])) + { + foreach ($ids as $id) + { + if (isset(self::$lookup[$language][$view][(int) $id])) + { + return self::$lookup[$language][$view][(int) $id]; + } + } + } + } + } + + // Check if the active menuitem matches the requested language + $active = $menus->getActive(); + if ($active && ($language == '*' || in_array($active->language, array('*', $language)) || !JLanguageMultilang::isEnabled())) + { + return $active->id; + } + + // If not found, return language specific home link + $default = $menus->getDefault($language); + return !empty($default->id) ? $default->id : null; + } +} diff --git a/src/com_weblinks/site/language/en-GB/en-GB.com_weblinks.ini b/src/com_weblinks/site/language/en-GB/en-GB.com_weblinks.ini new file mode 100644 index 0000000..2fa7de6 --- /dev/null +++ b/src/com_weblinks/site/language/en-GB/en-GB.com_weblinks.ini @@ -0,0 +1,34 @@ +; Joomla! Project +; Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 - No BOM + +COM_WEBLINKS_DEFAULT_PAGE_TITLE="Web Links" +COM_WEBLINKS_EDIT="Edit Web link" +COM_WEBLINKS_ERR_TABLES_NAME="There is already a Web Link with that name in this category. Please try again." +COM_WEBLINKS_ERR_TABLES_PROVIDE_URL="Please provide a valid URL" +COM_WEBLINKS_ERR_TABLES_TITLE="Your Web Link must contain a title." +COM_WEBLINKS_ERROR_CATEGORY_NOT_FOUND="Web link category not found" +COM_WEBLINKS_ERROR_UNIQUE_ALIAS="Another Web Link from this category has the same alias" +COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND="Web Link not found" +COM_WEBLINKS_ERROR_WEBLINK_URL_INVALID="Invalid Web link URL" +COM_WEBLINKS_FIELD_ALIAS_DESC="The alias is for internal use only. Leave this blank and Joomla will fill in a default value from the title. It has to be unique for each web link in the same category." +COM_WEBLINKS_FIELD_CATEGORY_DESC="You must select a Category." +COM_WEBLINKS_FIELD_DESCRIPTION_DESC="Enter a description for your Web link" +COM_WEBLINKS_FILTER_LABEL="Filter field" +COM_WEBLINKS_FILTER_SEARCH_DESC="Web Links Filter Search" +COM_WEBLINKS_FIELD_TITLE_DESC="Your Web Link must have a Title." +COM_WEBLINKS_FIELD_URL_DESC="You must enter a URL." +COM_WEBLINKS_FIELD_URL_LABEL="URL" +COM_WEBLINKS_FORM_CREATE_WEBLINK="Submit a Web Link" +COM_WEBLINKS_GRID_TITLE="Title" +COM_WEBLINKS_LINK="Web Link" +COM_WEBLINKS_NAME="Name" +COM_WEBLINKS_NO_WEBLINKS="There are no Web Links in this category" +COM_WEBLINKS_NUM="# of links:" +COM_WEBLINKS_FORM_EDIT_WEBLINK="Edit a Web Link" +COM_WEBLINKS_FORM_SUBMIT_WEBLINK="Submit a Web Link" +COM_WEBLINKS_SAVE_SUCCESS="Web link successfully saved" +COM_WEBLINKS_SUBMIT_SAVE_SUCCESS="Web Link successfully submitted" +COM_WEBLINKS_WEB_LINKS="Web links" +JGLOBAL_NEWITEMSLAST_DESC="New Web Links default to the last position. Ordering can be changed after this Web Link has been saved." diff --git a/src/com_weblinks/site/metadata.xml b/src/com_weblinks/site/metadata.xml new file mode 100644 index 0000000..9205b30 --- /dev/null +++ b/src/com_weblinks/site/metadata.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/com_weblinks/site/models/categories.php b/src/com_weblinks/site/models/categories.php new file mode 100644 index 0000000..34d38de --- /dev/null +++ b/src/com_weblinks/site/models/categories.php @@ -0,0 +1,124 @@ +setState('filter.extension', $this->_extension); + + // Get the parent id if defined. + $parentId = $app->input->getInt('id'); + $this->setState('filter.parentId', $parentId); + + $params = $app->getParams(); + $this->setState('params', $params); + + $this->setState('filter.published', 1); + $this->setState('filter.access', true); + } + + /** + * Method to get a store id based on model configuration state. + * + * This is necessary because the model is used by the component and + * different modules that might need different sets of data or different + * ordering requirements. + * + * @param string $id A prefix for the store id. + * + * @return string A store id. + */ + protected function getStoreId($id = '') + { + // Compile the store id. + $id .= ':'.$this->getState('filter.extension'); + $id .= ':'.$this->getState('filter.published'); + $id .= ':'.$this->getState('filter.access'); + $id .= ':'.$this->getState('filter.parentId'); + + return parent::getStoreId($id); + } + + /** + * redefine the function an add some properties to make the styling more easy + * + * @return mixed An array of data items on success, false on failure. + */ + public function getItems() + { + if (!count($this->_items)) + { + $app = JFactory::getApplication(); + $menu = $app->getMenu(); + $active = $menu->getActive(); + $params = new JRegistry; + if ($active) + { + $params->loadString($active->params); + } + $options = array(); + $options['countItems'] = $params->get('show_cat_num_links', 1) || !$params->get('show_empty_categories_cat', 0); + $categories = JCategories::getInstance('Weblinks', $options); + $this->_parent = $categories->get($this->getState('filter.parentId', 'root')); + if (is_object($this->_parent)) + { + $this->_items = $this->_parent->getChildren(); + } else { + $this->_items = false; + } + } + + return $this->_items; + } + + public function getParent() + { + if (!is_object($this->_parent)) + { + $this->getItems(); + } + return $this->_parent; + } +} diff --git a/src/com_weblinks/site/models/category.php b/src/com_weblinks/site/models/category.php new file mode 100644 index 0000000..f26867d --- /dev/null +++ b/src/com_weblinks/site/models/category.php @@ -0,0 +1,365 @@ +_params)) + { + $params = new JRegistry; + $params->loadString($item->params); + $item->params = $params; + } + // Get the tags + $item->tags = new JHelperTags; + $item->tags->getItemTags('com_weblinks.weblink', $item->id); + } + + return $items; + } + + /** + * Method to build an SQL query to load the list data. + * + * @return string An SQL query + * @since 1.6 + */ + protected function getListQuery() + { + $user = JFactory::getUser(); + $groups = implode(',', $user->getAuthorisedViewLevels()); + + // Create a new query object. + $db = $this->getDbo(); + $query = $db->getQuery(true); + + // Select required fields from the categories. + $query->select($this->getState('list.select', 'a.*')) + ->from($db->quoteName('#__weblinks') . ' AS a') + ->where('a.access IN (' . $groups . ')'); + + // Filter by category. + if ($categoryId = $this->getState('category.id')) + { + $query->where('a.catid = ' . (int) $categoryId) + ->join('LEFT', '#__categories AS c ON c.id = a.catid') + ->where('c.access IN (' . $groups . ')'); + + //Filter by published category + $cpublished = $this->getState('filter.c.published'); + if (is_numeric($cpublished)) + { + $query->where('c.published = ' . (int) $cpublished); + } + } + + // Join over the users for the author and modified_by names. + $query->select("CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author") + ->select("ua.email AS author_email") + + ->join('LEFT', '#__users AS ua ON ua.id = a.created_by') + ->join('LEFT', '#__users AS uam ON uam.id = a.modified_by'); + + // Filter by state + + $state = $this->getState('filter.state'); + if (is_numeric($state)) + { + $query->where('a.state = ' . (int) $state); + } + // do not show trashed links on the front-end + $query->where('a.state != -2'); + + // Filter by start and end dates. + $nullDate = $db->quote($db->getNullDate()); + $date = JFactory::getDate(); + $nowDate = $db->quote($date->toSql()); + + if ($this->getState('filter.publish_date')) + { + $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')') + ->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); + } + + // Filter by language + if ($this->getState('filter.language')) + { + $query->where('a.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); + } + + // Filter by search in title + $search = $this->getState('list.filter'); + if (!empty($search)) + { + $search = $db->quote('%' . $db->escape($search, true) . '%'); + $query->where('(a.title LIKE ' . $search . ')'); + } + + // Add the list ordering clause. + $query->order($db->escape($this->getState('list.ordering', 'a.ordering')) . ' ' . $db->escape($this->getState('list.direction', 'ASC'))); + return $query; + } + + /** + * Method to auto-populate the model state. + * + * Note. Calling getState in this method will result in recursion. + * + * @since 1.6 + */ + protected function populateState($ordering = null, $direction = null) + { + $app = JFactory::getApplication(); + $params = JComponentHelper::getParams('com_weblinks'); + + // List state information + $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'uint'); + $this->setState('list.limit', $limit); + + $limitstart = $app->input->get('limitstart', 0, 'uint'); + $this->setState('list.start', $limitstart); + + // Optional filter text + $this->setState('list.filter', $app->input->getString('filter-search')); + + $orderCol = $app->input->get('filter_order', 'ordering'); + if (!in_array($orderCol, $this->filter_fields)) + { + $orderCol = 'ordering'; + } + $this->setState('list.ordering', $orderCol); + + $listOrder = $app->input->get('filter_order_Dir', 'ASC'); + if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) + { + $listOrder = 'ASC'; + } + $this->setState('list.direction', $listOrder); + + $id = $app->input->get('id', 0, 'int'); + $this->setState('category.id', $id); + + $user = JFactory::getUser(); + if ((!$user->authorise('core.edit.state', 'com_weblinks')) && (!$user->authorise('core.edit', 'com_weblinks'))) + { + // limit to published for people who can't edit or edit.state. + $this->setState('filter.state', 1); + + // Filter by start and end dates. + $this->setState('filter.publish_date', true); + } + + $this->setState('filter.language', JLanguageMultilang::isEnabled()); + + // Load the parameters. + $this->setState('params', $params); + } + + /** + * Method to get category data for the current category + * + * @param integer An optional ID + * + * @return object + * @since 1.5 + */ + public function getCategory() + { + if (!is_object($this->_item)) + { + $app = JFactory::getApplication(); + $menu = $app->getMenu(); + $active = $menu->getActive(); + $params = new JRegistry; + + if ($active) + { + $params->loadString($active->params); + } + + $options = array(); + $options['countItems'] = $params->get('show_cat_num_links_cat', 1) || $params->get('show_empty_categories', 0); + $categories = JCategories::getInstance('Weblinks', $options); + $this->_item = $categories->get($this->getState('category.id', 'root')); + if (is_object($this->_item)) + { + $this->_children = $this->_item->getChildren(); + $this->_parent = false; + if ($this->_item->getParent()) + { + $this->_parent = $this->_item->getParent(); + } + $this->_rightsibling = $this->_item->getSibling(); + $this->_leftsibling = $this->_item->getSibling(false); + } + else + { + $this->_children = false; + $this->_parent = false; + } + } + + return $this->_item; + } + + /** + * Get the parent category + * + * @param integer An optional category id. If not supplied, the model state 'category.id' will be used. + * + * @return mixed An array of categories or false if an error occurs. + */ + public function getParent() + { + if (!is_object($this->_item)) + { + $this->getCategory(); + } + return $this->_parent; + } + + /** + * Get the sibling (adjacent) categories. + * + * @return mixed An array of categories or false if an error occurs. + */ + function &getLeftSibling() + { + if (!is_object($this->_item)) + { + $this->getCategory(); + } + return $this->_leftsibling; + } + + function &getRightSibling() + { + if (!is_object($this->_item)) + { + $this->getCategory(); + } + return $this->_rightsibling; + } + + /** + * Get the child categories. + * + * @param integer An optional category id. If not supplied, the model state 'category.id' will be used. + * + * @return mixed An array of categories or false if an error occurs. + */ + function &getChildren() + { + if (!is_object($this->_item)) + { + $this->getCategory(); + } + return $this->_children; + } + + /** + * Increment the hit counter for the category. + * + * @param int $pk Optional primary key of the category to increment. + * + * @return boolean True if successful; false otherwise and internal error set. + * + * @since 3.2 + */ + public function hit($pk = 0) + { + $input = JFactory::getApplication()->input; + $hitcount = $input->getInt('hitcount', 1); + + if ($hitcount) + { + $pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id'); + + $table = JTable::getInstance('Category', 'JTable'); + $table->load($pk); + $table->hit($pk); + } + + return true; + } +} diff --git a/src/com_weblinks/site/models/form.php b/src/com_weblinks/site/models/form.php new file mode 100644 index 0000000..52a34ed --- /dev/null +++ b/src/com_weblinks/site/models/form.php @@ -0,0 +1,76 @@ +getState('return_page')); + } + + /** + * Method to auto-populate the model state. + * + * Note. Calling getState in this method will result in recursion. + * + * @since 1.6 + */ + protected function populateState() + { + $app = JFactory::getApplication(); + + // Load state from the request. + $pk = $app->input->getInt('w_id'); + $this->setState('weblink.id', $pk); + // Add compatibility variable for default naming conventions. + $this->setState('form.id', $pk); + + $categoryId = $app->input->getInt('catid'); + $this->setState('weblink.catid', $categoryId); + + $return = $app->input->get('return', null, 'base64'); + + if (!JUri::isInternal(base64_decode($return))) + { + $return = null; + } + + $this->setState('return_page', base64_decode($return)); + + // Load the parameters. + $params = $app->getParams(); + $this->setState('params', $params); + + $this->setState('layout', $app->input->getString('layout')); + } +} diff --git a/src/com_weblinks/site/models/forms/weblink.xml b/src/com_weblinks/site/models/forms/weblink.xml new file mode 100644 index 0000000..369e9e9 --- /dev/null +++ b/src/com_weblinks/site/models/forms/weblink.xml @@ -0,0 +1,140 @@ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + +
+
+
diff --git a/src/com_weblinks/site/models/weblink.php b/src/com_weblinks/site/models/weblink.php new file mode 100644 index 0000000..fdc93ec --- /dev/null +++ b/src/com_weblinks/site/models/weblink.php @@ -0,0 +1,128 @@ +getParams(); + + // Load the object state. + $id = $app->input->getInt('id'); + $this->setState('weblink.id', $id); + + // Load the parameters. + $this->setState('params', $params); + } + + /** + * Method to get an object. + * + * @param integer The id of the object to get. + * + * @return mixed Object on success, false on failure. + */ + public function getItem($id = null) + { + if ($this->_item === null) + { + $this->_item = false; + + if (empty($id)) + { + $id = $this->getState('weblink.id'); + } + + // Get a level row instance. + $table = JTable::getInstance('Weblink', 'WeblinksTable'); + + // Attempt to load the row. + if ($table->load($id)) + { + // Check published state. + if ($published = $this->getState('filter.published')) + { + if ($table->state != $published) + { + return $this->_item; + } + } + + // Convert the JTable to a clean JObject. + $properties = $table->getProperties(1); + $this->_item = JArrayHelper::toObject($properties, 'JObject'); + } + elseif ($error = $table->getError()) + { + $this->setError($error); + } + } + + return $this->_item; + } + + /** + * Returns a reference to the a Table object, always creating it. + * + * @param type The table type to instantiate + * @param string A prefix for the table class name. Optional. + * @param array Configuration array for model. Optional. + * @return JTable A database object + * @since 1.6 + */ + public function getTable($type = 'Weblink', $prefix = 'WeblinksTable', $config = array()) + { + return JTable::getInstance($type, $prefix, $config); + } + + /** + * Method to increment the hit counter for the weblink + * + * @param integer $id Optional ID of the weblink. + * + * @return boolean True on success + */ + public function hit($id = null) + { + if (empty($id)) + { + $id = $this->getState('weblink.id'); + } + + $weblink = $this->getTable('Weblink', 'WeblinksTable'); + return $weblink->hit($id); + } +} diff --git a/src/com_weblinks/site/router.php b/src/com_weblinks/site/router.php new file mode 100644 index 0000000..25c3102 --- /dev/null +++ b/src/com_weblinks/site/router.php @@ -0,0 +1,229 @@ +getMenu(); + $params = JComponentHelper::getParams('com_weblinks'); + $advanced = $params->get('sef_advanced_link', 0); + + // we need a menu item. Either the one specified in the query, or the current active one if none specified + if (empty($query['Itemid'])) + { + $menuItem = $menu->getActive(); + } + else + { + $menuItem = $menu->getItem($query['Itemid']); + } + + $mView = (empty($menuItem->query['view'])) ? null : $menuItem->query['view']; + $mId = (empty($menuItem->query['id'])) ? null : $menuItem->query['id']; + + if (isset($query['view'])) + { + $view = $query['view']; + + if (empty($query['Itemid']) || empty($menuItem) || $menuItem->component != 'com_weblinks') + { + $segments[] = $query['view']; + } + + // We need to keep the view for forms since they never have their own menu item + if ($view != 'form') + { + unset($query['view']); + } + } + + // are we dealing with an weblink that is attached to a menu item? + if (isset($query['view']) && ($mView == $query['view']) and (isset($query['id'])) and ($mId == (int) $query['id'])) + { + unset($query['view']); + unset($query['catid']); + unset($query['id']); + + return $segments; + } + + if (isset($view) and ($view == 'category' or $view == 'weblink')) + { + if ($mId != (int) $query['id'] || $mView != $view) + { + if ($view == 'weblink' && isset($query['catid'])) + { + $catid = $query['catid']; + } + elseif (isset($query['id'])) + { + $catid = $query['id']; + } + + $menuCatid = $mId; + $categories = JCategories::getInstance('Weblinks'); + $category = $categories->get($catid); + + if ($category) + { + //TODO Throw error that the category either not exists or is unpublished + $path = $category->getPath(); + $path = array_reverse($path); + + $array = array(); + foreach ($path as $id) + { + if ((int) $id == (int) $menuCatid) + { + break; + } + + if ($advanced) + { + list($tmp, $id) = explode(':', $id, 2); + } + + $array[] = $id; + } + $segments = array_merge($segments, array_reverse($array)); + } + + if ($view == 'weblink') + { + if ($advanced) + { + list($tmp, $id) = explode(':', $query['id'], 2); + } + else + { + $id = $query['id']; + } + + $segments[] = $id; + } + } + + unset($query['id']); + unset($query['catid']); + } + + if (isset($query['layout'])) + { + if (!empty($query['Itemid']) && isset($menuItem->query['layout'])) + { + if ($query['layout'] == $menuItem->query['layout']) + { + unset($query['layout']); + } + } + else + { + if ($query['layout'] == 'default') + { + unset($query['layout']); + } + } + } + + return $segments; +} + +/** + * Parse the segments of a URL. + * + * @return array The segments of the URL to parse. + * + * @return array The URL attributes to be used by the application. + */ +function WeblinksParseRoute($segments) +{ + $vars = array(); + + //Get the active menu item. + $app = JFactory::getApplication(); + $menu = $app->getMenu(); + $item = $menu->getActive(); + $params = JComponentHelper::getParams('com_weblinks'); + $advanced = $params->get('sef_advanced_link', 0); + + // Count route segments + $count = count($segments); + + // Standard routing for weblinks. + if (!isset($item)) + { + $vars['view'] = $segments[0]; + $vars['id'] = $segments[$count - 1]; + return $vars; + } + + // From the categories view, we can only jump to a category. + $id = (isset($item->query['id']) && $item->query['id'] > 1) ? $item->query['id'] : 'root'; + + $category = JCategories::getInstance('Weblinks')->get($id); + + $categories = $category->getChildren(); + $found = 0; + + foreach ($segments as $segment) + { + foreach ($categories as $category) + { + if (($category->slug == $segment) || ($advanced && $category->alias == str_replace(':', '-', $segment))) + { + $vars['id'] = $category->id; + $vars['view'] = 'category'; + $categories = $category->getChildren(); + $found = 1; + + break; + } + } + + if ($found == 0) + { + if ($advanced) + { + $db = JFactory::getDbo(); + $query = $db->getQuery(true) + ->select($db->quoteName('id')) + ->from('#__weblinks') + ->where($db->quoteName('catid') . ' = ' . (int) $vars['catid']) + ->where($db->quoteName('alias') . ' = ' . $db->quote($db->quote(str_replace(':', '-', $segment)))); + $db->setQuery($query); + $id = $db->loadResult(); + } + else + { + $id = $segment; + } + + $vars['id'] = $id; + $vars['view'] = 'weblink'; + + break; + } + + $found = 0; + } + + return $vars; +} diff --git a/src/com_weblinks/site/views/categories/tmpl/default.php b/src/com_weblinks/site/views/categories/tmpl/default.php new file mode 100644 index 0000000..cf56a15 --- /dev/null +++ b/src/com_weblinks/site/views/categories/tmpl/default.php @@ -0,0 +1,17 @@ +loadTemplate('items'); +?> +
diff --git a/src/com_weblinks/site/views/categories/tmpl/default.xml b/src/com_weblinks/site/views/categories/tmpl/default.xml new file mode 100644 index 0000000..98c9da8 --- /dev/null +++ b/src/com_weblinks/site/views/categories/tmpl/default.xml @@ -0,0 +1,243 @@ + + + + + + + + + + + +
+ +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
diff --git a/src/com_weblinks/site/views/categories/tmpl/default_items.php b/src/com_weblinks/site/views/categories/tmpl/default_items.php new file mode 100644 index 0000000..7cc7d6d --- /dev/null +++ b/src/com_weblinks/site/views/categories/tmpl/default_items.php @@ -0,0 +1,63 @@ +items[$this->parent->id]) > 0 && $this->maxLevelcat != 0) : +?> + items[$this->parent->id] as $id => $item) : ?> + params->get('show_empty_categories_cat') || $item->numitems || count($item->getChildren())) : + if (!isset($this->items[$this->parent->id][$id + 1])) + { + $class = ' class="last"'; + } + ?> +
> + + + params->get('show_subcat_desc_cat') == 1) :?> + description) : ?> +
+ description, '', 'com_weblinks.categories'); ?> +
+ + + + getChildren()) > 0) :?> +
+ items[$item->id] = $item->getChildren(); + $this->parent = $item; + $this->maxLevelcat--; + echo $this->loadTemplate('items'); + $this->parent = $item->getParent(); + $this->maxLevelcat++; + ?> +
+ +
+ + + diff --git a/src/com_weblinks/site/views/categories/view.html.php b/src/com_weblinks/site/views/categories/view.html.php new file mode 100644 index 0000000..a4d52d7 --- /dev/null +++ b/src/com_weblinks/site/views/categories/view.html.php @@ -0,0 +1,85 @@ +get('State'); + $items = $this->get('Items'); + $parent = $this->get('Parent'); + + // Check for errors. + if (count($errors = $this->get('Errors'))) + { + JError::raiseWarning(500, implode("\n", $errors)); + return false; + } + + if ($items === false) + { + return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND')); + } + + if ($parent == false) + { + return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND')); + } + + $params = &$state->params; + + $items = array($parent->id => $items); + + // Escape strings for HTML output + $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); + + $this->maxLevelcat = $params->get('maxLevelcat', -1); + $this->params = &$params; + $this->parent = &$parent; + $this->items = &$items; + + return parent::display($tpl); + } +} diff --git a/src/com_weblinks/site/views/category/metadata.xml b/src/com_weblinks/site/views/category/metadata.xml new file mode 100644 index 0000000..33a5cfd --- /dev/null +++ b/src/com_weblinks/site/views/category/metadata.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/com_weblinks/site/views/category/tmpl/default.php b/src/com_weblinks/site/views/category/tmpl/default.php new file mode 100644 index 0000000..972ba0b --- /dev/null +++ b/src/com_weblinks/site/views/category/tmpl/default.php @@ -0,0 +1,14 @@ +subtemplatename = 'items'; +echo JLayoutHelper::render('joomla.content.category_default', $this); diff --git a/src/com_weblinks/site/views/category/tmpl/default.xml b/src/com_weblinks/site/views/category/tmpl/default.xml new file mode 100644 index 0000000..0a2b439 --- /dev/null +++ b/src/com_weblinks/site/views/category/tmpl/default.xml @@ -0,0 +1,195 @@ + + + + + + + + + + + +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + +
+
+
diff --git a/src/com_weblinks/site/views/category/tmpl/default_children.php b/src/com_weblinks/site/views/category/tmpl/default_children.php new file mode 100644 index 0000000..9a80d61 --- /dev/null +++ b/src/com_weblinks/site/views/category/tmpl/default_children.php @@ -0,0 +1,57 @@ +children[$this->category->id]) > 0 && $this->maxLevel != 0) : +?> +
    +children[$this->category->id] as $id => $child) : ?> + params->get('show_empty_categories') || $child->numitems || count($child->getChildren())) : + if (!isset($this->children[$this->category->id][$id + 1])) + { + $class = ' class="last"'; + } + ?> + > + + + escape($child->title); ?> + + + params->get('show_subcat_desc') == 1) :?> + description) : ?> +
    + description, '', 'com_weblinks.category'); ?> +
    + + + + params->get('show_cat_num_links') == 1) :?> + + + + getChildren()) > 0 ) : + $this->children[$child->id] = $child->getChildren(); + $this->category = $child; + $this->maxLevel--; + echo $this->loadTemplate('children'); + $this->category = $child->getParent(); + $this->maxLevel++; + endif; ?> + + + +
+item->params; +// Get the user object. +$user = JFactory::getUser(); +// Check if user is allowed to add/edit based on weblinks permissinos. +$canEdit = $user->authorise('core.edit', 'com_weblinks.category.'.$this->category->id); +$canCreate = $user->authorise('core.create', 'com_weblinks'); +$canEditState = $user->authorise('core.edit.state', 'com_weblinks'); + +$n = count($this->items); +$listOrder = $this->escape($this->state->get('list.ordering')); +$listDirn = $this->escape($this->state->get('list.direction')); +?> + +items)) : ?> +

+ + +
+ params->get('filter_field') != 'hide' || $this->params->get('show_pagination_limit')) :?> +
+ params->get('filter_field') != 'hide') :?> +
+ + +
+ + + params->get('show_pagination_limit')) : ?> +
+ + pagination->getLimitBox(); ?> +
+ +
+ +
    + + items as $i => $item) : ?> + access, $this->user->getAuthorisedViewLevels())) : ?> + items[$i]->state == 0) : ?> +
  • + +
  • + + params->get('show_link_hits', 1)) : ?> + + hits); ?> + + + + + + + + + +
    + params->get('icons', 1) == 0) : ?> + + params->get('icons', 1) == 1) : ?> + params->get('link_icons')) : ?> + + + params->get('link_icons').'" alt="'.JText::_('COM_WEBLINKS_LINK').'" />'; ?> + + + pageclass_sfx; + $link = $item->link; + $width = $item->params->get('width'); + $height = $item->params->get('height'); + if ($width == null || $height == null) + { + $width = 600; + $height = 500; + } + if ($this->items[$i]->state == 0) : ?> + Unpublished + + + params->get('target', $this->params->get('target'))) + { + case 1: + // open in a new window + echo ''. + $this->escape($item->title) .''; + break; + + case 2: + // open in a popup window + $attribs = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='.$this->escape($width).',height='.$this->escape($height).''; + echo "". + $this->escape($item->title).''; + break; + case 3: + // open in a modal window + JHtml::_('behavior.modal', 'a.modal'); + echo ''. + $this->escape($item->title). ' '; + break; + + default: + // open in parent window + echo ''. + $this->escape($item->title) . ' '; + break; + } + ?> +
    + tags->getItemTags('com_weblinks.weblink', $item->id); ?> + params->get('show_tags', 1)) : ?> + item->tagLayout = new JLayoutFile('joomla.content.tags'); ?> + item->tagLayout->render($tagsData); ?> + + + params->get('show_link_description')) and ($item->description != '')) : ?> + images); ?> + image_first) and !empty($images->image_first)) : ?> + float_first)) ? $this->params->get('float_first') : $images->float_first; ?> +
    image_first_caption): + echo 'class="caption"'.' title="' .htmlspecialchars($images->image_first_caption) .'"'; + endif; ?> + src="image_first); ?>" alt="image_first_alt); ?>"/>
    + + image_second) and !empty($images->image_second)) : ?> + float_second)) ? $this->params->get('float_second') : $images->float_second; ?> +
    image_second_caption): + echo 'class="caption"'.' title="' .htmlspecialchars($images->image_second_caption) .'"'; + endif; ?> + src="image_second); ?>" alt="image_second_alt); ?>"/>
    + + + description; ?> + + +
  • + + +
+ + + + params); ?> + + params->get('show_pagination')) : ?> + + +
+ diff --git a/src/com_weblinks/site/views/category/view.feed.php b/src/com_weblinks/site/views/category/view.feed.php new file mode 100644 index 0000000..6a281cc --- /dev/null +++ b/src/com_weblinks/site/views/category/view.feed.php @@ -0,0 +1,26 @@ +items as $item) + { + $item->slug = $item->alias ? ($item->id.':'.$item->alias) : $item->id; + + if ($item->params->get('count_clicks', $this->params->get('count_clicks')) == 1) + { + $item->link = JRoute::_('index.php?option=com_weblinks&task=weblink.go&id='. $item->id); + } + else + { + $item->link = $item->url; + } + + $temp = new JRegistry; + $temp->loadString($item->params); + $item->params = clone($this->params); + $item->params->merge($temp); + } + + return parent::display($tpl); + } + + /** + * Prepares the document + * + * @return void + */ + protected function prepareDocument() + { + $app = JFactory::getApplication(); + $menus = $app->getMenu(); + $pathway = $app->getPathway(); + $title = null; + + // Because the application sets a default page title, + // we need to get it from the menu item itself + $menu = $menus->getActive(); + + if ($menu) + { + $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); + } + else + { + $this->params->def('page_heading', JText::_('COM_WEBLINKS_DEFAULT_PAGE_TITLE')); + } + + $id = (int) @$menu->query['id']; + + if ($menu && ($menu->query['option'] != 'com_weblinks' || $id != $this->category->id)) + { + $this->params->set('page_subheading', $this->category->title); + $path = array(array('title' => $this->category->title, 'link' => '')); + $category = $this->category->getParent(); + + while (($menu->query['option'] != 'com_weblinks' || $id != $category->id) && $category->id > 1) + { + $path[] = array('title' => $category->title, 'link' => WeblinksHelperRoute::getCategoryRoute($category->id)); + $category = $category->getParent(); + } + + $path = array_reverse($path); + + foreach ($path as $item) + { + $pathway->addItem($item['title'], $item['link']); + } + } + + parent::addFeed(); + } +} diff --git a/src/com_weblinks/site/views/form/metadata.xml b/src/com_weblinks/site/views/form/metadata.xml new file mode 100644 index 0000000..a8bbd4e --- /dev/null +++ b/src/com_weblinks/site/views/form/metadata.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/src/com_weblinks/site/views/form/tmpl/edit.php b/src/com_weblinks/site/views/form/tmpl/edit.php new file mode 100644 index 0000000..dd9b5d9 --- /dev/null +++ b/src/com_weblinks/site/views/form/tmpl/edit.php @@ -0,0 +1,77 @@ +state->get('params'); +?> + + +
+ params->get('show_page_heading')) : ?> +

+ escape($this->params->get('page_heading')); ?> +

+ +
+
+
+ +
+
+ +
+ get('save_history', 0)) : ?> +
+ form->getInput('contenthistory'); ?> +
+ +
+ +
+ form->renderField('title'); ?> + form->renderField('alias'); ?> + form->renderField('catid'); ?> + form->renderField('url'); ?> + form->renderField('tags'); ?> + + get('save_history', 0)) : ?> + form->renderField('version_note'); ?> + + + user->authorise('core.edit.state', 'com_weblinks.weblink')) : ?> + form->renderField('state'); ?> + + form->renderField('language'); ?> + form->renderField('description'); ?> + + + + +
+
diff --git a/src/com_weblinks/site/views/form/tmpl/edit.xml b/src/com_weblinks/site/views/form/tmpl/edit.xml new file mode 100644 index 0000000..ab67ad2 --- /dev/null +++ b/src/com_weblinks/site/views/form/tmpl/edit.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/src/com_weblinks/site/views/form/view.html.php b/src/com_weblinks/site/views/form/view.html.php new file mode 100644 index 0000000..9689cc3 --- /dev/null +++ b/src/com_weblinks/site/views/form/view.html.php @@ -0,0 +1,137 @@ +state = $this->get('State'); + $this->item = $this->get('Item'); + $this->form = $this->get('Form'); + $this->return_page = $this->get('ReturnPage'); + + if (empty($this->item->id)) + { + $authorised = ($user->authorise('core.create', 'com_weblinks') || (count($user->getAuthorisedCategories('com_weblinks', 'core.create')))); + } + else + { + $authorised = $user->authorise('core.edit', 'com_weblinks.category.'.$this->item->catid); + + } + + if ($authorised !== true) + { + JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); + return false; + } + + if (!empty($this->item)) + { + $this->form->bind($this->item); + } + + // Check for errors. + if (count($errors = $this->get('Errors'))) + { + JError::raiseWarning(500, implode("\n", $errors)); + return false; + } + + // Create a shortcut to the parameters. + $params = &$this->state->params; + + //Escape strings for HTML output + $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); + + $this->params = $params; + $this->user = $user; + + $this->_prepareDocument(); + parent::display($tpl); + } + + /** + * Prepares the document + */ + protected function _prepareDocument() + { + $app = JFactory::getApplication(); + $menus = $app->getMenu(); + $title = null; + + // Because the application sets a default page title, + // we need to get it from the menu item itself + $menu = $menus->getActive(); + + if (empty($this->item->id)) + { + $head = JText::_('COM_WEBLINKS_FORM_SUBMIT_WEBLINK'); + } + else + { + $head = JText::_('COM_WEBLINKS_FORM_EDIT_WEBLINK'); + } + + if ($menu) + { + $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); + } + else + { + $this->params->def('page_heading', $head); + } + + $title = $this->params->def('page_title', $head); + if ($app->getCfg('sitename_pagetitles', 0) == 1) + { + $title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title); + } + elseif ($app->getCfg('sitename_pagetitles', 0) == 2) + { + $title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename')); + } + $this->document->setTitle($title); + + if ($this->params->get('menu-meta_description')) + { + $this->document->setDescription($this->params->get('menu-meta_description')); + } + + if ($this->params->get('menu-meta_keywords')) + { + $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); + } + + if ($this->params->get('robots')) + { + $this->document->setMetadata('robots', $this->params->get('robots')); + } + } +} diff --git a/src/com_weblinks/site/views/index.html b/src/com_weblinks/site/views/index.html new file mode 100644 index 0000000..2efb97f --- /dev/null +++ b/src/com_weblinks/site/views/index.html @@ -0,0 +1 @@ + diff --git a/src/com_weblinks/site/views/weblink/view.html.php b/src/com_weblinks/site/views/weblink/view.html.php new file mode 100644 index 0000000..e12bf6e --- /dev/null +++ b/src/com_weblinks/site/views/weblink/view.html.php @@ -0,0 +1,47 @@ +get('Item'); + + if ($this->getLayout() == 'edit') + { + $this->_displayEdit($tpl); + return; + } + + if ($item->url) + { + // redirects to url if matching id found + JFactory::getApplication()->redirect($item->url); + } + else + { + //TODO create proper error handling + JFactory::getApplication()->redirect(JRoute::_('index.php'), JText::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 'notice'); + } + } +} diff --git a/src/com_weblinks/site/weblinks.php b/src/com_weblinks/site/weblinks.php new file mode 100644 index 0000000..52833bb --- /dev/null +++ b/src/com_weblinks/site/weblinks.php @@ -0,0 +1,16 @@ +execute(JFactory::getApplication()->input->get('task')); +$controller->redirect(); diff --git a/src/language/en-GB/en-GB.pkg_weblinks.sys.ini b/src/language/en-GB/en-GB.pkg_weblinks.sys.ini new file mode 100644 index 0000000..430a028 --- /dev/null +++ b/src/language/en-GB/en-GB.pkg_weblinks.sys.ini @@ -0,0 +1,7 @@ +; Joomla! Project +; Copyright (C) 2005 - 2012 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 + +PKG_WEBLINKS="Weblinks Extension Package" +PKG_WEBLINKS_XML_DESCRIPTION="The Weblinks package includes the weblinks component, module, and search plugins for both of Joomla's search platforms." diff --git a/src/mod_weblinks/helper.php b/src/mod_weblinks/helper.php new file mode 100644 index 0000000..6fa0bec --- /dev/null +++ b/src/mod_weblinks/helper.php @@ -0,0 +1,116 @@ + true)); + + // Set application parameters in model + $app = JFactory::getApplication(); + $appParams = $app->getParams(); + $model->setState('params', $appParams); + + // Set the filters based on the module params + $model->setState('list.start', 0); + $model->setState('list.limit', (int) $params->get('count', 5)); + + $model->setState('filter.state', 1); + $model->setState('filter.publish_date', true); + + // Access filter + $access = !JComponentHelper::getParams('com_weblinks')->get('show_noauth'); + $model->setState('filter.access', $access); + + $ordering = $params->get('ordering', 'ordering'); + $model->setState('list.ordering', $ordering == 'order' ? 'ordering' : $ordering); + $model->setState('list.direction', $params->get('direction', 'asc')); + + $catid = (int) $params->get('catid', 0); + $model->setState('category.id', $catid); + + // Create query object + $db = JFactory::getDbo(); + $query = $db->getQuery(true); + + $case_when1 = ' CASE WHEN '; + $case_when1 .= $query->charLength('a.alias', '!=', '0'); + $case_when1 .= ' THEN '; + $a_id = $query->castAsChar('a.id'); + $case_when1 .= $query->concatenate(array($a_id, 'a.alias'), ':'); + $case_when1 .= ' ELSE '; + $case_when1 .= $a_id . ' END as slug'; + + $case_when2 = ' CASE WHEN '; + $case_when2 .= $query->charLength('c.alias', '!=', '0'); + $case_when2 .= ' THEN '; + $c_id = $query->castAsChar('c.id'); + $case_when2 .= $query->concatenate(array($c_id, 'c.alias'), ':'); + $case_when2 .= ' ELSE '; + $case_when2 .= $c_id . ' END as catslug'; + + $model->setState( + 'list.select', + 'a.*, c.published AS c_published,' . $case_when1 . ',' . $case_when2 . ',' . 'DATE_FORMAT(a.created, "%Y-%m-%d") AS created' + ); + + $model->setState('filter.c.published', 1); + + // Filter by language + $model->setState('filter.language', $app->getLanguageFilter()); + + $items = $model->getItems(); + + if ($items) + { + foreach ($items as $item) + { + if ($item->params->get('count_clicks', $params->get('count_clicks')) == 1) + { + $item->link = JRoute::_('index.php?option=com_weblinks&task=weblink.go&catid=' . $item->catslug . '&id=' . $item->slug); + } + else + { + $item->link = $item->url; + } + } + + return $items; + } + else + { + return; + } + } +} diff --git a/src/mod_weblinks/language/en-GB/en-GB.mod_weblinks.ini b/src/mod_weblinks/language/en-GB/en-GB.mod_weblinks.ini new file mode 100644 index 0000000..c941e43 --- /dev/null +++ b/src/mod_weblinks/language/en-GB/en-GB.mod_weblinks.ini @@ -0,0 +1,31 @@ +; Joomla! Project +; Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 - No BOM + +MOD_WEBLINKS="Weblinks" +MOD_WEBLINKS_FIELD_CATEGORY_DESC="Choose the Weblinks category to display" +MOD_WEBLINKS_FIELD_COUNT_DESC="Number of Web Links to display" +MOD_WEBLINKS_FIELD_COUNT_LABEL="Count" +MOD_WEBLINKS_FIELD_COUNTCLICKS_DESC="If set to yes, the number of times the link has been clicked will be recorded" +MOD_WEBLINKS_FIELD_COUNTCLICKS_LABEL="Count Clicks" +MOD_WEBLINKS_FIELD_DESCRIPTION_DESC="Display Web Link description" +MOD_WEBLINKS_FIELD_DESCRIPTION_LABEL="Description" +MOD_WEBLINKS_FIELD_FOLLOW_DESC="Robots index - allow to follow or not" +MOD_WEBLINKS_FIELD_FOLLOW_LABEL="Follow/No Follow" +MOD_WEBLINKS_FIELD_HITS_DESC="Show Hits" +MOD_WEBLINKS_FIELD_HITS_LABEL="Hits" +MOD_WEBLINKS_FIELD_ORDERDIRECTION_DESC="Set the ordering direction" +MOD_WEBLINKS_FIELD_ORDERDIRECTION_LABEL="Direction" +MOD_WEBLINKS_FIELD_ORDERING_DESC="Ordering for the Web Links" +MOD_WEBLINKS_FIELD_ORDERING_LABEL="Ordering" +MOD_WEBLINKS_FIELD_TARGET_DESC="Target browser window when the link is clicked" +MOD_WEBLINKS_FIELD_TARGET_LABEL="Target Window" +MOD_WEBLINKS_FIELD_VALUE_ASCENDING="Ascending" +MOD_WEBLINKS_FIELD_VALUE_DESCENDING="Descending" +MOD_WEBLINKS_FIELD_VALUE_FOLLOW="Follow" +MOD_WEBLINKS_FIELD_VALUE_HITS="Hits" +MOD_WEBLINKS_FIELD_VALUE_NOFOLLOW="No follow" +MOD_WEBLINKS_FIELD_VALUE_ORDER="Order" +MOD_WEBLINKS_HITS="Hits" +MOD_WEBLINKS_XML_DESCRIPTION="This modules displays weblinks from a category defined in the Weblinks component." diff --git a/src/mod_weblinks/language/en-GB/en-GB.mod_weblinks.sys.ini b/src/mod_weblinks/language/en-GB/en-GB.mod_weblinks.sys.ini new file mode 100644 index 0000000..0c5e244 --- /dev/null +++ b/src/mod_weblinks/language/en-GB/en-GB.mod_weblinks.sys.ini @@ -0,0 +1,9 @@ +; Joomla! Project +; Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 - No BOM + +MOD_WEBLINKS="Weblinks" +MOD_WEBLINKS_XML_DESCRIPTION="This modules displays Web Links from a category defined in the Weblinks component." +MOD_WEBLINKS_LAYOUT_DEFAULT="Default" + diff --git a/src/mod_weblinks/mod_weblinks.php b/src/mod_weblinks/mod_weblinks.php new file mode 100644 index 0000000..ed92344 --- /dev/null +++ b/src/mod_weblinks/mod_weblinks.php @@ -0,0 +1,24 @@ +get('moduleclass_sfx')); + +require JModuleHelper::getLayoutPath('mod_weblinks', $params->get('layout', 'default')); diff --git a/src/mod_weblinks/mod_weblinks.xml b/src/mod_weblinks/mod_weblinks.xml new file mode 100644 index 0000000..86a1b3b --- /dev/null +++ b/src/mod_weblinks/mod_weblinks.xml @@ -0,0 +1,171 @@ + + + mod_weblinks + Joomla! Project + July 2009 + Copyright (C) 2005 - 2014 Open Source Matters. All rights reserved. + GNU General Public License version 2 or later; see LICENSE.txt + admin@joomla.org + www.joomla.org + 3.0.0 + MOD_WEBLINKS_XML_DESCRIPTION + + mod_weblinks.php + tmpl + helper.php + index.html + mod_weblinks.xml + + + en-GB.mod_weblinks.ini + en-GB.mod_weblinks.sys.ini + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + +
+
+
+
diff --git a/src/mod_weblinks/tmpl/default.php b/src/mod_weblinks/tmpl/default.php new file mode 100644 index 0000000..d8ae0d2 --- /dev/null +++ b/src/mod_weblinks/tmpl/default.php @@ -0,0 +1,55 @@ + + diff --git a/src/pkg_weblinks.xml b/src/pkg_weblinks.xml new file mode 100644 index 0000000..d4320ad --- /dev/null +++ b/src/pkg_weblinks.xml @@ -0,0 +1,30 @@ + + + pkg_weblinks + weblinks + December 2012 + Joomla! Project + (C) 2005 - 2012 Open Source Matters. All rights reserved. + admin@joomla.org + www.joomla.org + Joomla! Project + admin@joomla.org + www.joomla.org + 3.0.0 + GNU General Public License version 2 or later; see LICENSE.txt + PKG_WEBLINKS_XML_DESCRIPTION + + + com_weblinks.zip + mod_weblinks.zip + plg_finder_weblinks.zip + plg_search_weblinks.zip + + + language/en-GB/en-GB.pkg_weblinks.sys.ini + + + + https://github.com/joomla-extensions/weblinks/master/manifest.xml + + diff --git a/src/plg_finder_weblinks/language/en-GB/en-GB.plg_finder_weblinks.ini b/src/plg_finder_weblinks/language/en-GB/en-GB.plg_finder_weblinks.ini new file mode 100644 index 0000000..b6084b4 --- /dev/null +++ b/src/plg_finder_weblinks/language/en-GB/en-GB.plg_finder_weblinks.ini @@ -0,0 +1,10 @@ +; Joomla! Project +; Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 + +PLG_FINDER_WEBLINKS="Smart Search - Weblinks" +PLG_FINDER_WEBLINKS_XML_DESCRIPTION="This plugin indexes Joomla! Weblinks." + +PLG_FINDER_QUERY_FILTER_BRANCH_S_WEB_LINK="Web link" +PLG_FINDER_QUERY_FILTER_BRANCH_P_WEB_LINK="Web links" diff --git a/src/plg_finder_weblinks/language/en-GB/en-GB.plg_finder_weblinks.sys.ini b/src/plg_finder_weblinks/language/en-GB/en-GB.plg_finder_weblinks.sys.ini new file mode 100644 index 0000000..729f6c4 --- /dev/null +++ b/src/plg_finder_weblinks/language/en-GB/en-GB.plg_finder_weblinks.sys.ini @@ -0,0 +1,8 @@ +; Joomla! Project +; Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 + +PLG_FINDER_WEBLINKS="Smart Search - Weblinks" +PLG_FINDER_WEBLINKS_ERROR_ACTIVATING_PLUGIN="Could not automatically activate the "_QQ_"Smart Search - Weblinks"_QQ_" plugin" +PLG_FINDER_WEBLINKS_XML_DESCRIPTION="This plugin indexes Joomla! Weblinks." diff --git a/src/plg_finder_weblinks/weblinks.php b/src/plg_finder_weblinks/weblinks.php new file mode 100644 index 0000000..d3b66e1 --- /dev/null +++ b/src/plg_finder_weblinks/weblinks.php @@ -0,0 +1,379 @@ +categoryStateChange($pks, $value); + } + } + + /** + * Method to remove the link information for items that have been deleted. + * + * @param string $context The context of the action being performed. + * @param JTable $table A JTable object containing the record to be deleted. + * + * @return boolean True on success. + * + * @since 2.5 + * @throws Exception on database error. + */ + public function onFinderAfterDelete($context, $table) + { + if ($context == 'com_weblinks.weblink') + { + $id = $table->id; + } + elseif ($context == 'com_finder.index') + { + $id = $table->link_id; + } + else + { + return true; + } + + // Remove the item from the index. + return $this->remove($id); + } + + /** + * Smart Search after content save method. + * Reindexes the link information for a weblink that has been saved. + * It also makes adjustments if the access level of a weblink item or + * the category to which it belongs has been changed. + * + * @param string $context The context of the content passed to the plugin. + * @param JTable $row A JTable object. + * @param boolean $isNew True if the content has just been created. + * + * @return boolean True on success. + * + * @since 2.5 + * @throws Exception on database error. + */ + public function onFinderAfterSave($context, $row, $isNew) + { + // We only want to handle web links here. We need to handle front end and back end editing. + if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.form' ) + { + // Check if the access levels are different. + if (!$isNew && $this->old_access != $row->access) + { + // Process the change. + $this->itemAccessChange($row); + } + + // Reindex the item. + $this->reindex($row->id); + } + + // Check for access changes in the category. + if ($context == 'com_categories.category') + { + // Check if the access levels are different. + if (!$isNew && $this->old_cataccess != $row->access) + { + $this->categoryAccessChange($row); + } + } + + return true; + } + + /** + * Smart Search before content save method. + * This event is fired before the data is actually saved. + * + * @param string $context The context of the content passed to the plugin. + * @param JTable $row A JTable object. + * @param boolean $isNew True if the content is just about to be created. + * + * @return boolean True on success. + * + * @since 2.5 + * @throws Exception on database error. + */ + public function onFinderBeforeSave($context, $row, $isNew) + { + // We only want to handle web links here. + if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.form') + { + // Query the database for the old access level if the item isn't new. + if (!$isNew) + { + $this->checkItemAccess($row); + } + } + + // Check for access levels from the category. + if ($context == 'com_categories.category') + { + // Query the database for the old access level if the item isn't new. + if (!$isNew) + { + $this->checkCategoryAccess($row); + } + } + + return true; + } + + /** + * Method to update the link information for items that have been changed + * from outside the edit screen. This is fired when the item is published, + * unpublished, archived, or unarchived from the list view. + * + * @param string $context The context for the content passed to the plugin. + * @param array $pks An array of primary key ids of the content that has changed state. + * @param integer $value The value of the state that the content has been changed to. + * + * @return void + * + * @since 2.5 + */ + public function onFinderChangeState($context, $pks, $value) + { + // We only want to handle web links here. + if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.form') + { + $this->itemStateChange($pks, $value); + } + + // Handle when the plugin is disabled. + if ($context == 'com_plugins.plugin' && $value === 0) + { + $this->pluginDisable($pks); + } + } + + /** + * Method to index an item. The item must be a FinderIndexerResult object. + * + * @param FinderIndexerResult $item The item to index as an FinderIndexerResult object. + * @param string $format The item format. Not used. + * + * @return void + * + * @since 2.5 + * @throws Exception on database error. + */ + protected function index(FinderIndexerResult $item, $format = 'html') + { + // Check if the extension is enabled + if (JComponentHelper::isEnabled($this->extension) == false) + { + return; + } + + $item->setLanguage(); + + // Initialise the item parameters. + $registry = new JRegistry; + $registry->loadString($item->params); + $item->params = $registry; + + $registry = new JRegistry; + $registry->loadString($item->metadata); + $item->metadata = $registry; + + // Build the necessary route and path information. + $item->url = $this->getURL($item->id, $this->extension, $this->layout); + $item->route = WeblinksHelperRoute::getWeblinkRoute($item->slug, $item->catslug, $item->language); + $item->path = FinderIndexerHelper::getContentPath($item->route); + + /* + * Add the meta-data processing instructions based on the newsfeeds + * configuration parameters. + */ + // Add the meta-author. + $item->metaauthor = $item->metadata->get('author'); + + // Handle the link to the meta-data. + $item->addInstruction(FinderIndexer::META_CONTEXT, 'link'); + $item->addInstruction(FinderIndexer::META_CONTEXT, 'metakey'); + $item->addInstruction(FinderIndexer::META_CONTEXT, 'metadesc'); + $item->addInstruction(FinderIndexer::META_CONTEXT, 'metaauthor'); + $item->addInstruction(FinderIndexer::META_CONTEXT, 'author'); + $item->addInstruction(FinderIndexer::META_CONTEXT, 'created_by_alias'); + + // Add the type taxonomy data. + $item->addTaxonomy('Type', 'Web Link'); + + // Add the category taxonomy data. + $item->addTaxonomy('Category', $item->category, $item->cat_state, $item->cat_access); + + // Add the language taxonomy data. + $item->addTaxonomy('Language', $item->language); + + // Get content extras. + FinderIndexerHelper::getContentExtras($item); + + // Index the item. + $this->indexer->index($item); + } + + /** + * Method to setup the indexer to be run. + * + * @return boolean True on success. + * + * @since 2.5 + */ + protected function setup() + { + // Load dependent classes. + require_once JPATH_SITE . '/components/com_weblinks/helpers/route.php'; + + return true; + } + + /** + * Method to get the SQL query used to retrieve the list of content items. + * + * @param mixed $query A JDatabaseQuery object or null. + * + * @return JDatabaseQuery A database object. + * + * @since 2.5 + */ + protected function getListQuery($query = null) + { + $db = JFactory::getDbo(); + + // Check if we can use the supplied SQL query. + $query = $query instanceof JDatabaseQuery ? $query : $db->getQuery(true) + ->select('a.id, a.catid, a.title, a.alias, a.url AS link, a.description AS summary') + ->select('a.metakey, a.metadesc, a.metadata, a.language, a.access, a.ordering') + ->select('a.created_by_alias, a.modified, a.modified_by') + ->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date') + ->select('a.state AS state, a.created AS start_date, a.params') + ->select('c.title AS category, c.published AS cat_state, c.access AS cat_access'); + + // Handle the alias CASE WHEN portion of the query. + $case_when_item_alias = ' CASE WHEN '; + $case_when_item_alias .= $query->charLength('a.alias', '!=', '0'); + $case_when_item_alias .= ' THEN '; + $a_id = $query->castAsChar('a.id'); + $case_when_item_alias .= $query->concatenate(array($a_id, 'a.alias'), ':'); + $case_when_item_alias .= ' ELSE '; + $case_when_item_alias .= $a_id . ' END as slug'; + $query->select($case_when_item_alias); + + $case_when_category_alias = ' CASE WHEN '; + $case_when_category_alias .= $query->charLength('c.alias', '!=', '0'); + $case_when_category_alias .= ' THEN '; + $c_id = $query->castAsChar('c.id'); + $case_when_category_alias .= $query->concatenate(array($c_id, 'c.alias'), ':'); + $case_when_category_alias .= ' ELSE '; + $case_when_category_alias .= $c_id . ' END as catslug'; + $query->select($case_when_category_alias) + + ->from('#__weblinks AS a') + ->join('LEFT', '#__categories AS c ON c.id = a.catid'); + + return $query; + } + + /** + * Method to get the query clause for getting items to update by time. + * + * @param string $time The modified timestamp. + * + * @return JDatabaseQuery A database object. + * + * @since 2.5 + */ + protected function getUpdateQueryByTime($time) + { + // Build an SQL query based on the modified time. + $query = $this->db->getQuery(true) + ->where('a.date >= ' . $this->db->quote($time)); + + return $query; + } +} diff --git a/src/plg_finder_weblinks/weblinks.xml b/src/plg_finder_weblinks/weblinks.xml new file mode 100644 index 0000000..37378c7 --- /dev/null +++ b/src/plg_finder_weblinks/weblinks.xml @@ -0,0 +1,21 @@ + + + plg_finder_weblinks + Joomla! Project + August 2011 + (C) 2005 - 2014 Open Source Matters. All rights reserved. + GNU General Public License version 2 or later; see LICENSE.txt + admin@joomla.org + www.joomla.org + 3.0.0 + PLG_FINDER_WEBLINKS_XML_DESCRIPTION + script.php + + weblinks.php + index.html + + + language/en-GB/en-GB.plg_finder_weblinks.ini + language/en-GB/en-GB.plg_finder_weblinks.sys.ini + + diff --git a/src/plg_search_weblinks/language/en-GB/en-GB.plg_search_weblinks.ini b/src/plg_search_weblinks/language/en-GB/en-GB.plg_search_weblinks.ini new file mode 100644 index 0000000..7e484fe --- /dev/null +++ b/src/plg_search_weblinks/language/en-GB/en-GB.plg_search_weblinks.ini @@ -0,0 +1,10 @@ +; Joomla! Project +; Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 + +PLG_SEARCH_WEBLINKS="Search - Weblinks" +PLG_SEARCH_WEBLINKS_FIELD_SEARCHLIMIT_DESC="Number of search items to return" +PLG_SEARCH_WEBLINKS_FIELD_SEARCHLIMIT_LABEL="Search Limit" +PLG_SEARCH_WEBLINKS_WEBLINKS="Weblinks" +PLG_SEARCH_WEBLINKS_XML_DESCRIPTION="Enables searching of Weblinks Component" diff --git a/src/plg_search_weblinks/language/en-GB/en-GB.plg_search_weblinks.sys.ini b/src/plg_search_weblinks/language/en-GB/en-GB.plg_search_weblinks.sys.ini new file mode 100644 index 0000000..5bf9676 --- /dev/null +++ b/src/plg_search_weblinks/language/en-GB/en-GB.plg_search_weblinks.sys.ini @@ -0,0 +1,7 @@ +; Joomla! Project +; Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 + +PLG_SEARCH_WEBLINKS="Search - Weblinks" +PLG_SEARCH_WEBLINKS_XML_DESCRIPTION="Enables searching of Weblinks Component" diff --git a/src/plg_search_weblinks/weblinks.php b/src/plg_search_weblinks/weblinks.php new file mode 100644 index 0000000..3aa89ce --- /dev/null +++ b/src/plg_search_weblinks/weblinks.php @@ -0,0 +1,220 @@ + 'PLG_SEARCH_WEBLINKS_WEBLINKS' + ); + + return $areas; + } + + /** + * Search content (weblinks). + * + * The SQL must return the following fields that are used in a common display + * routine: href, title, section, created, text, browsernav + * + * @param string $text Target search string. + * @param string $phrase Matching option (possible values: exact|any|all). Default is "any". + * @param string $ordering Ordering option (possible values: newest|oldest|popular|alpha|category). Default is "newest". + * @param mixed $areas An array if the search it to be restricted to areas or null to search all areas. + * + * @return array Search results. + * + * @since 1.6 + */ + public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) + { + $db = JFactory::getDbo(); + $app = JFactory::getApplication(); + $user = JFactory::getUser(); + $groups = implode(',', $user->getAuthorisedViewLevels()); + + $searchText = $text; + + if (is_array($areas)) + { + if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) + { + return array(); + } + } + + $sContent = $this->params->get('search_content', 1); + $sArchived = $this->params->get('search_archived', 1); + $limit = $this->params->def('search_limit', 50); + $state = array(); + + if ($sContent) + { + $state[] = 1; + } + + if ($sArchived) + { + $state[] = 2; + } + + if (empty($state)) + { + return array(); + } + + $text = trim($text); + + if ($text == '') + { + return array(); + } + + $searchWeblinks = JText::_('PLG_SEARCH_WEBLINKS'); + + switch ($phrase) + { + case 'exact': + $text = $db->quote('%' . $db->escape($text, true) . '%', false); + $wheres2 = array(); + $wheres2[] = 'a.url LIKE ' . $text; + $wheres2[] = 'a.description LIKE ' . $text; + $wheres2[] = 'a.title LIKE ' . $text; + $where = '(' . implode(') OR (', $wheres2) . ')'; + break; + + case 'all': + case 'any': + default: + $words = explode(' ', $text); + $wheres = array(); + + foreach ($words as $word) + { + $word = $db->quote('%' . $db->escape($word, true) . '%', false); + $wheres2 = array(); + $wheres2[] = 'a.url LIKE ' . $word; + $wheres2[] = 'a.description LIKE ' . $word; + $wheres2[] = 'a.title LIKE ' . $word; + $wheres[] = implode(' OR ', $wheres2); + } + + $where = '(' . implode(($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')'; + break; + } + + switch ($ordering) + { + case 'oldest': + $order = 'a.created ASC'; + break; + + case 'popular': + $order = 'a.hits DESC'; + break; + + case 'alpha': + $order = 'a.title ASC'; + break; + + case 'category': + $order = 'c.title ASC, a.title ASC'; + break; + + case 'newest': + default: + $order = 'a.created DESC'; + } + + $query = $db->getQuery(true); + + // SQLSRV changes. + $case_when = ' CASE WHEN '; + $case_when .= $query->charLength('a.alias', '!=', '0'); + $case_when .= ' THEN '; + $a_id = $query->castAsChar('a.id'); + $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':'); + $case_when .= ' ELSE '; + $case_when .= $a_id . ' END as slug'; + + $case_when1 = ' CASE WHEN '; + $case_when1 .= $query->charLength('c.alias', '!=', '0'); + $case_when1 .= ' THEN '; + $c_id = $query->castAsChar('c.id'); + $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':'); + $case_when1 .= ' ELSE '; + $case_when1 .= $c_id . ' END as catslug'; + + $query->select('a.title AS title, \'\' AS created, a.url, a.description AS text, ' . $case_when . "," . $case_when1) + ->select($query->concatenate(array($db->quote($searchWeblinks), 'c.title'), " / ") . ' AS section') + ->select('\'1\' AS browsernav') + ->from('#__weblinks AS a') + ->join('INNER', '#__categories as c ON c.id = a.catid') + ->where('(' . $where . ') AND a.state IN (' . implode(',', $state) . ') AND c.published = 1 AND c.access IN (' . $groups . ')') + ->order($order); + + // Filter by language. + if ($app->isSite() && JLanguageMultilang::isEnabled()) + { + $tag = JFactory::getLanguage()->getTag(); + $query->where('a.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')') + ->where('c.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')'); + } + + $db->setQuery($query, 0, $limit); + $rows = $db->loadObjectList(); + + $return = array(); + + if ($rows) + { + foreach ($rows as $key => $row) + { + $rows[$key]->href = WeblinksHelperRoute::getWeblinkRoute($row->slug, $row->catslug); + } + + foreach ($rows as $weblink) + { + if (searchHelper::checkNoHTML($weblink, $searchText, array('url', 'text', 'title'))) + { + $return[] = $weblink; + } + } + } + + return $return; + } +} diff --git a/src/plg_search_weblinks/weblinks.xml b/src/plg_search_weblinks/weblinks.xml new file mode 100644 index 0000000..68ad391 --- /dev/null +++ b/src/plg_search_weblinks/weblinks.xml @@ -0,0 +1,53 @@ + + + plg_search_weblinks + Joomla! Project + November 2005 + Copyright (C) 2005 - 2014 Open Source Matters. All rights reserved. + GNU General Public License version 2 or later; see LICENSE.txt + admin@joomla.org + www.joomla.org + 3.0.0 + PLG_SEARCH_WEBLINKS_XML_DESCRIPTION + + weblinks.php + index.html + + + en-GB.plg_search_weblinks.ini + en-GB.plg_search_weblinks.sys.ini + + + + +
+ + + + + + + + + + + +
+
+
+