New module 'Link checker'
This commit is contained in:
parent
f0de655d08
commit
78ad431fbe
10 changed files with 4559 additions and 0 deletions
178
sites/all/modules/linkchecker/CHANGELOG.txt
Normal file
178
sites/all/modules/linkchecker/CHANGELOG.txt
Normal file
|
@ -0,0 +1,178 @@
|
||||||
|
linkchecker 6.x-2.8, June 7, 2014
|
||||||
|
---------------------------------
|
||||||
|
|
||||||
|
* Issue #2280827: Notice: Undefined index: content-type in _linkchecker_status_handling()
|
||||||
|
* Issue #2125719 by hass: Links in unpublished nodes are still checked
|
||||||
|
* Issue #2088461 by fonant, hass: PDF link with #page= results in "URL fragment identifier not found in content"
|
||||||
|
* Added Smileys filter (http://drupal.org/project/smiley) to filter blacklist
|
||||||
|
* Issue #1306498 by hass, evolvingweb: Remove unnecessary hook_requirements in linkchecker.install
|
||||||
|
* Issue #1923328 by larowlan: Fragment check fails when source page contains spaces between attribute name, equals and value.
|
||||||
|
* Issue #1926558 by hass: Block extraction re-scans fail.
|
||||||
|
|
||||||
|
linkchecker 6.x-2.7, February 14, 2013
|
||||||
|
--------------------------------------
|
||||||
|
|
||||||
|
* Issue #1901018 by hass: ERROR - __clone method called on non-object.
|
||||||
|
* #1891900: Uninstall of variable 'linkchecker_check_connections_max' failed.
|
||||||
|
* #1719174: Editing node throws "Undefined property" stdClass::$nid in hook_node_prepare().
|
||||||
|
* #1875602: Check URL fragment identifiers in content
|
||||||
|
* Minor code style fixes
|
||||||
|
|
||||||
|
linkchecker 6.x-2.6, December 24, 2012
|
||||||
|
--------------------------------------
|
||||||
|
|
||||||
|
* Fixed some typos.
|
||||||
|
* Upgraded outdated HTTP user agents.
|
||||||
|
* #380052: Add support with non-blocking parallel link checking.
|
||||||
|
* linkchecker_update_6211 was missing an update message.
|
||||||
|
* #1869924: Strict warning: Creating default object from empty value.
|
||||||
|
* #1867460: Prevent save on automatic updates, if content has not changed.
|
||||||
|
* #1804842 follow up: Exit if all node types are disabled
|
||||||
|
* #1450672: Cron task does not impersonate to admin user on automatic content updates.
|
||||||
|
* Added Drupal 6.14 warning to known issues.
|
||||||
|
* #1804842: Lots of warnings when comment module is not installed
|
||||||
|
* #1811908: Allow extracting protocol relative url's
|
||||||
|
* #1586022: linkchecker generating bad User-Agent string
|
||||||
|
* Status code 500 on HEAD/GET does not increase fail_count
|
||||||
|
* #1488572: i18n: "Permission restrictions deny" all broken links in other languages
|
||||||
|
|
||||||
|
linkchecker 6.x-2.5, February 15, 2012
|
||||||
|
--------------------------------------
|
||||||
|
|
||||||
|
* Fix for access bypass vulnerability.
|
||||||
|
* #1429284: Don't follow redirects
|
||||||
|
* Removed block 'title' for consitency reasons. It's only a title in administration and should not contain URLs
|
||||||
|
* Show a recommendation next to blacklisted filter names.
|
||||||
|
* #1149596: Links with spaces are not extracted
|
||||||
|
* Backported some documentation fixes
|
||||||
|
* Batch redirect URL added for blocks
|
||||||
|
* #860700: Disable all non-http(s) links for link checking until we have curl implemented
|
||||||
|
* #1054118: After batch scan the target url is not pointing to the node view
|
||||||
|
* #1075390: Added HTTP range support (Performance)
|
||||||
|
* Links disabled for checking (blacklist, never checked) will be counted as as unchecked and the number of unchecked links will therefore never become zero.
|
||||||
|
* #1321378: Improve performance of queries
|
||||||
|
* #953958: User able to see other user broken links
|
||||||
|
* truncate is ***much*** more faster than delete.
|
||||||
|
* #725398: variable_get() may not be available in the install.php run
|
||||||
|
* First decode, than filter as URLs could theoretically consist of encoded blanks only.
|
||||||
|
* #1067160 by somimi: Minor grammar fixes to some of the descriptions in linkchecker.pages.inc
|
||||||
|
* Removing translation directories
|
||||||
|
* #903318: Internal Links in cck, weblinks and links fields are not extracted.
|
||||||
|
* Remove locale module setUp as notices in _linkchecker_add_node_links() has been fixed.
|
||||||
|
* Prevent notices if tests run without locale module.
|
||||||
|
* #780242 by AlexisWilke: Several E_NOTICE when dealing with the URLs
|
||||||
|
* #500090 by hass: Block removal of RFC domains in exclude links
|
||||||
|
* #685580 by wheyse: CCK field_name need to be checked with empty() as the value could be empty
|
||||||
|
* Upgrade line break converter from D5 filter/2 to D6 filter/1.
|
||||||
|
* #661484: Empty URL exclusion list disables link checking
|
||||||
|
|
||||||
|
linkchecker 6.x-2.4, November 24, 2009
|
||||||
|
--------------------------------------
|
||||||
|
|
||||||
|
* #566388 by wimh, hass: Re-check link status on next cron run
|
||||||
|
* #632732 by sleepcamel, hass: Add a message to $node->log when saving a new revision
|
||||||
|
* #627774 by charmer: Linkchecker Czech Translation
|
||||||
|
* Replace word "node" in text with "content" for easier translation
|
||||||
|
* #580248: Prevent link check failure if 'max_execution_time' = 0 (unlimited).
|
||||||
|
* Blacklisted "smileys/0" filter as the URLs are maintained in the Smiley module settings
|
||||||
|
* Fixed wrong variable name in single comment import function
|
||||||
|
* Updated README.txt
|
||||||
|
* Cleanup / refactoring _linkchecker_extract_links()
|
||||||
|
* #563464: Internal links reported as broken incorrectly on SSL only site. Use $base_root as site URL for prefixing absolute internal URLs.
|
||||||
|
* E_ALL saver...
|
||||||
|
* Better menu item description, D7 backport.
|
||||||
|
* Dynamic destination for user broken links page
|
||||||
|
* Use theme function for item_list
|
||||||
|
* Dynamic colspan for no data
|
||||||
|
* Joined wrong fields in user report with comments enabled
|
||||||
|
* Filters do not run on content as expected.
|
||||||
|
* db_last_insert_id('boxes', 'bid') could return a wrong value if other contrib modules add block hooks and insert something in other tables.
|
||||||
|
* Make all count() upper case
|
||||||
|
* Show items in a list
|
||||||
|
* Filter $link->error for arbitrary code
|
||||||
|
* #532178 by hass: Database update #6209 failed
|
||||||
|
* #196862 by hass: COUNT(*) is an expensive query in InnoDB.
|
||||||
|
* Added links extraction .test
|
||||||
|
* E_ALL: Fixed notice for undefined $node->language.
|
||||||
|
* E_ALL: Fixed notice caused by array_map(md5, $links)
|
||||||
|
* Typo fixed
|
||||||
|
* Changed unique key and column name 'token' into 'urlhash'.
|
||||||
|
* Added filter blacklist for link extraction.
|
||||||
|
* Remove reference to $form_state in hook_form_alter()
|
||||||
|
* Fix comments
|
||||||
|
* Add $node->type check
|
||||||
|
* Added support for node type 'weblinks' from 'weblinks' modules
|
||||||
|
* D5: check_plain() all '@' string values for the use with strtr().
|
||||||
|
|
||||||
|
|
||||||
|
linkchecker 6.x-2.3, August 1, 2009
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
By this release linkchecker no longer depends on job_queue!
|
||||||
|
|
||||||
|
* by wimh: Copy an paste error, used _linkchecker_node_links_missing() in _linkchecker_add_comment_links()
|
||||||
|
* #536744 by wimh, hass: Add broken links warning message to block edit page on view, but not after save.
|
||||||
|
* #536744 by wimh, hass: Fix comment edit form to show the broken links warning message only on 'view' and 'preview', but not after save.
|
||||||
|
* Fix inline documenation typos
|
||||||
|
* Code style, variable names, constant for limit, doc fixes, others
|
||||||
|
* #536672 by wimh, hass: Link references not updated when last link of a node/comment/block is removed
|
||||||
|
* More comments added.
|
||||||
|
* Updated translation files
|
||||||
|
* Use update_sql() for permission updates
|
||||||
|
* Save form settings on link scan and clear.
|
||||||
|
* #497096: Support links generated by input filter
|
||||||
|
* Remove duplicate lid's in SQL results
|
||||||
|
* #465414: Followup for relative links extracted incorrectly
|
||||||
|
* Note that custom link settings are lost on every clean and re-analyse task
|
||||||
|
* Added GUI for link check URL filter
|
||||||
|
* #524380: Do not check example.com/net/org domain links
|
||||||
|
* Updated installation steps in README.txt
|
||||||
|
* Added sample URLs for internal and external to description
|
||||||
|
* Changed permission name "access linkchecker" to "access broken links report"
|
||||||
|
* Added the status code 302 to the list of ignored response codes.
|
||||||
|
* Select from comment table only, if comment modules is active.
|
||||||
|
* Remove ignored links from broken links view
|
||||||
|
|
||||||
|
|
||||||
|
linkchecker 6.x-2.2, July 14, 2009
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
* Removed confusing watchdog message.
|
||||||
|
* Use default node type revision setting and save a revision on 301 auto-update.
|
||||||
|
* UX: Provide more descriptive help what the HTML tags are for.
|
||||||
|
* #451456: 301 auto-update could break links
|
||||||
|
* #452080: Update permanently moved internal links is broken
|
||||||
|
* Removed duplicate _linkchecker_add_xxx_links() calls. node_save automaticallly calls hook_nodeapi and comment_save automatically calls hook_comment with 'update'.
|
||||||
|
* Added a link to the job_queue module project page
|
||||||
|
* #465414: Stop incorrect extraction of relative links
|
||||||
|
* Typo fixed in batch finished message
|
||||||
|
* Removed unused default case
|
||||||
|
* Removed UI setting no longer having a real use case (and reduce complexity)
|
||||||
|
* Deleted the associated variable.
|
||||||
|
* One more chance to extract a URL (for e.g. Java Applet)
|
||||||
|
* Added support for HTML5 tags (video|audio|source)
|
||||||
|
* Uncomment cURL requirement until implemented.
|
||||||
|
* #402742: Integration with path_redirect
|
||||||
|
* #427906, #417354: Extract links from various configurable HTML tags (a|area|img|iframe|object|param|embed)
|
||||||
|
* #504332: Cannot install, HTTP request status fails
|
||||||
|
* Show edit link only if user have permission to change settings
|
||||||
|
* New permission to edit link settings
|
||||||
|
* Add UI to change request method
|
||||||
|
* Add ignore filter for links pointing to buggy servers
|
||||||
|
|
||||||
|
|
||||||
|
linkchecker 6.x-2.1, March 26, 2009
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
* #409324 by Dave Reid: _linkchecker_delete_node_links() expects a nid, but passed a node object
|
||||||
|
* #386612 by hass: Prevent possible cron failures caused by too many link checks
|
||||||
|
* #408860 by Dave Reid: PHP notice: Undefined property: stdClass::$moderate in linkchecker.module on line 428.
|
||||||
|
* #373485 by hass: DB errors when adding a new node
|
||||||
|
* #387228: linkchecker.module fails in PHP4 on line 910
|
||||||
|
* #375767: Wrong table aliases and column names for comments and boxes
|
||||||
|
* Added MySQL 5.0 requirement check
|
||||||
|
* Show broken link message on node prepare, not view
|
||||||
|
* #380548: No results after configuration changes
|
||||||
|
* #380476: Descriptive text in Admin confusing
|
||||||
|
* #381986: Broken link does not immediately disappear in broken links list after link has been fixed in content
|
||||||
|
* #380872 by hass: Show informative message about current check status on reports page.
|
339
sites/all/modules/linkchecker/LICENSE.txt
Normal file
339
sites/all/modules/linkchecker/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser 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.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
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.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 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 Lesser General
|
||||||
|
Public License instead of this License.
|
59
sites/all/modules/linkchecker/README.txt
Normal file
59
sites/all/modules/linkchecker/README.txt
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
|
||||||
|
Link Checker
|
||||||
|
------------
|
||||||
|
|
||||||
|
Installation:
|
||||||
|
|
||||||
|
1. Place the entire linkchecker folder into your modules directory.
|
||||||
|
2. Go to Administer -> Site building -> Modules and enable the Link checker module.
|
||||||
|
3. Go to Administer -> Site configuration -> Link checker and enable the node types to scan.
|
||||||
|
4. Check all HTML tags that should be scanned.
|
||||||
|
5. Adjust the other parameters if the defaults don't suit your needs.
|
||||||
|
6. Save configuration
|
||||||
|
7. Wait for cron to check all your links... this may take some time! :-)
|
||||||
|
|
||||||
|
If links are broken they appear under Administer -> Reports -> Broken links.
|
||||||
|
|
||||||
|
If not, make sure the cron is configured and running properly on your Drupal
|
||||||
|
installation. The Link checker module also logs somewhat useful info about it's
|
||||||
|
activity under Administer -> Reports -> Recent log entries.
|
||||||
|
|
||||||
|
|
||||||
|
Required:
|
||||||
|
|
||||||
|
1. For internal URL extraction you need to make sure that Cron always get called
|
||||||
|
with your real public site URL (for e.g. http://example.com/cron.php). Make
|
||||||
|
sure it's never executed with http://localhost/cron.php or any other
|
||||||
|
hostnames or ports, not available from public. Otherwise all links may be
|
||||||
|
reported as broken and cannot verified as they should be.
|
||||||
|
|
||||||
|
To make sure it always works - it's required to configure the $base_url in
|
||||||
|
the sites settings.php with your public sites URL. Better safe than sorry!
|
||||||
|
|
||||||
|
|
||||||
|
Known issues:
|
||||||
|
|
||||||
|
There are a lot of known issues in drupal_http_request(). These have been solved
|
||||||
|
in HTTPRL. As a workaround it's recommended to use HTTPRL in linkchecker.
|
||||||
|
|
||||||
|
Issues list:
|
||||||
|
|
||||||
|
* #997648: drupal_http_request() always calls fread() one more time than necessary
|
||||||
|
* #164365-12: drupal_http_request() does handle (invalid) non-absolute redirects
|
||||||
|
* #205969-11: drupal_http_request() assumes presence of Reason-Phrase in response Status-Line
|
||||||
|
* #371495: Error message from drupal_http_request() not UTF8 encoded
|
||||||
|
* #193073-11: drupal_http_request - socket not initialized
|
||||||
|
* #106506-8: drupal_http_request() does not handle 'chunked' responses - Make it support HTTP 1.1
|
||||||
|
* #1096890-15: drupal_http_request should return error if reaches max allowed redirects
|
||||||
|
* #875342-21: drupal_http_request() should pick up X-Drupal-Assertion-* HTTP headers
|
||||||
|
* #965078-31: HTTP request checking is unreliable and should be removed in favor of watchdog() calls
|
||||||
|
* #336367: HTTP client should protect commas when folding (compatibility with legacy HTTP/1.0)
|
||||||
|
* #45338: log fsockopen errors to watchdog
|
||||||
|
|
||||||
|
|
||||||
|
Other
|
||||||
|
|
||||||
|
* Drupal 6.14 only: A critical core bug has been introduced by #193383:
|
||||||
|
set_time_limit: Centralize calls and prevent warnings and errors that stops
|
||||||
|
link checker from verifying links. Apply the available D6 hotfix in #111 or
|
||||||
|
update to Drupal 6.15+ to fix your installation.
|
367
sites/all/modules/linkchecker/includes/linkchecker.admin.inc
Normal file
367
sites/all/modules/linkchecker/includes/linkchecker.admin.inc
Normal file
|
@ -0,0 +1,367 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Administrative page callbacks for the linkchecker module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function linkchecker_admin_settings_form(&$form_state) {
|
||||||
|
|
||||||
|
$form['settings'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('General settings'),
|
||||||
|
'#collapsible' => FALSE,
|
||||||
|
);
|
||||||
|
$form['settings']['linkchecker_scan_nodetypes'] = array(
|
||||||
|
'#type' => 'checkboxes',
|
||||||
|
'#title' => t('Scan node types for links'),
|
||||||
|
'#default_value' => variable_get('linkchecker_scan_nodetypes', array()),
|
||||||
|
'#options' => array_map('check_plain', node_get_types('names')),
|
||||||
|
'#description' => t('Enable link checking for the selected node type(s).'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$comment_dependencies = '<div class="admin-dependencies">';
|
||||||
|
$comment_dependencies .= t('Depends on: !dependencies', array('!dependencies' => (module_exists('comment') ? t('@module (<span class="admin-enabled">enabled</span>)', array('@module' => 'Comment')) : t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => 'Comment')))));
|
||||||
|
$comment_dependencies .= '</div>';
|
||||||
|
|
||||||
|
$form['settings']['linkchecker_scan_comments'] = array(
|
||||||
|
'#default_value' => variable_get('linkchecker_scan_comments', 0),
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Scan comments for links'),
|
||||||
|
'#description' => t('Enable this checkbox if links in comments of the above selected node type(s) should be checked.') . $comment_dependencies,
|
||||||
|
'#disabled' => module_exists('comment') ? FALSE : TRUE,
|
||||||
|
);
|
||||||
|
$form['settings']['linkchecker_scan_blocks'] = array(
|
||||||
|
'#default_value' => variable_get('linkchecker_scan_blocks', 0),
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Scan blocks for links'),
|
||||||
|
'#description' => t('Enable this checkbox if links in blocks should be checked.'),
|
||||||
|
);
|
||||||
|
$form['settings']['linkchecker_fqdn_only'] = array(
|
||||||
|
'#type' => 'select',
|
||||||
|
'#title' => t('What type of links should be checked?'),
|
||||||
|
'#description' => t('A full qualified link (http://example.com/foo/bar) to a page is considered external, whereas an absolute (/foo/bar) or relative link (node/123) without a domain is considered internal.'),
|
||||||
|
'#default_value' => variable_get('linkchecker_fqdn_only', 1),
|
||||||
|
'#options' => array(
|
||||||
|
'0' => t('Internal and external'),
|
||||||
|
'1' => t('External only (http://example.com/foo/bar)'),
|
||||||
|
'2' => t('Internal only (node/123)'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['tag'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('Link extraction'),
|
||||||
|
'#collapsible' => FALSE,
|
||||||
|
);
|
||||||
|
$form['tag']['linkchecker_extract_from_a'] = array(
|
||||||
|
'#default_value' => variable_get('linkchecker_extract_from_a', 1),
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Extract links in <code><a></code> and <code><area></code> tags'),
|
||||||
|
'#description' => t('Enable this checkbox if normal hyperlinks should be extracted. The anchor element defines a hyperlink, the named target destination for a hyperlink, or both. The area element defines a hot-spot region on an image, and associates it with a hypertext link.'),
|
||||||
|
);
|
||||||
|
$form['tag']['linkchecker_extract_from_audio'] = array(
|
||||||
|
'#default_value' => variable_get('linkchecker_extract_from_audio', 0),
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Extract links in <code><audio></code> tags'),
|
||||||
|
'#description' => t('Enable this checkbox if links in audio tags should be extracted. The audio element is used to embed audio content.'),
|
||||||
|
);
|
||||||
|
$form['tag']['linkchecker_extract_from_embed'] = array(
|
||||||
|
'#default_value' => variable_get('linkchecker_extract_from_embed', 0),
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Extract links in <code><embed></code> tags'),
|
||||||
|
'#description' => t('Enable this checkbox if links in embed tags should be extracted. This is an obsolete and non-standard element that was used for embedding plugins in past and should no longer used in modern websites.'),
|
||||||
|
);
|
||||||
|
$form['tag']['linkchecker_extract_from_iframe'] = array(
|
||||||
|
'#default_value' => variable_get('linkchecker_extract_from_iframe', 0),
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Extract links in <code><iframe></code> tags'),
|
||||||
|
'#description' => t('Enable this checkbox if links in iframe tags should be extracted. The iframe element is used to embed another HTML page into a page.'),
|
||||||
|
);
|
||||||
|
$form['tag']['linkchecker_extract_from_img'] = array(
|
||||||
|
'#default_value' => variable_get('linkchecker_extract_from_img', 0),
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Extract links in <code><img></code> tags'),
|
||||||
|
'#description' => t('Enable this checkbox if links in image tags should be extracted. The img element is used to add images to the content.'),
|
||||||
|
);
|
||||||
|
$form['tag']['linkchecker_extract_from_object'] = array(
|
||||||
|
'#default_value' => variable_get('linkchecker_extract_from_object', 0),
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Extract links in <code><object></code> and <code><param></code> tags'),
|
||||||
|
'#description' => t('Enable this checkbox if multimedia and other links in object and their param tags should be extracted. The object tag is used for flash, java, quicktime and other applets.'),
|
||||||
|
);
|
||||||
|
$form['tag']['linkchecker_extract_from_source'] = array(
|
||||||
|
'#default_value' => variable_get('linkchecker_extract_from_source', 0),
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Extract links in <code><source></code> tags'),
|
||||||
|
'#description' => t('Enable this checkbox if links in source tags should be extracted. The source element is used to specify multiple media resources for audio and video elements.'),
|
||||||
|
);
|
||||||
|
$form['tag']['linkchecker_extract_from_video'] = array(
|
||||||
|
'#default_value' => variable_get('linkchecker_extract_from_video', 0),
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Extract links in <code><video></code> tags'),
|
||||||
|
'#description' => t('Enable this checkbox if links in video tags should be extracted. The video element is used to embed video content.'),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get all filters available on the system.
|
||||||
|
$filters = filter_list_all();
|
||||||
|
$filter_options = array();
|
||||||
|
foreach ($filters as $filter) {
|
||||||
|
$name = $filter->module . '/' . $filter->delta;
|
||||||
|
if (in_array($name, explode('|', LINKCHECKER_DEFAULT_FILTER_BLACKLIST))) {
|
||||||
|
$filter_options[$name] = t('!title <span class="form-required">(Recommended)</span>', array('!title' => $filter->name));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$filter_options[$name] = $filter->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$form['tag']['linkchecker_filter_blacklist'] = array(
|
||||||
|
'#type' => 'checkboxes',
|
||||||
|
'#title' => t('Filters disabled for link extraction'),
|
||||||
|
'#default_value' => variable_get('linkchecker_filter_blacklist', explode('|', LINKCHECKER_DEFAULT_FILTER_BLACKLIST)),
|
||||||
|
'#options' => $filter_options,
|
||||||
|
'#description' => t('If a filter has been enabled for an input format it runs first and afterwards the link extraction. This helps the link checker module to find all links normally created by custom filters (e.g. Markdown filter, Bbcode). All filters used as inline references (e.g. Weblink filter <code>[link: id]</code>) to other content and filters only wasting processing time (e.g. Line break converter) should be disabled. This setting does not have any effect on how content is shown on a page. This feature optimizes the internal link extraction process for link checker and prevents false alarms about broken links in content not having the real data of a link.'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$count_lids_enabled = db_result(db_query("SELECT count(lid) FROM {linkchecker_links} WHERE status = %d", 1));
|
||||||
|
$count_lids_disabled = db_result(db_query("SELECT count(lid) FROM {linkchecker_links} WHERE status = %d", 0));
|
||||||
|
$form['check'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('Check settings'),
|
||||||
|
'#description' => t('For simultaneous link checks it is recommended to install the <a href="@httprl">HTTP Parallel Request & Threading Library</a>. This may be <strong>necessary</strong> on larger sites with very many links (30.000+), but will also improve overall link check duration on smaller sites. Currently the site has @count links (@count_enabled enabled / @count_disabled disabled).', array('@httprl' => 'http://drupal.org/project/httprl', '@count' => $count_lids_enabled+$count_lids_disabled, '@count_enabled' => $count_lids_enabled, '@count_disabled' => $count_lids_disabled)),
|
||||||
|
'#collapsible' => FALSE,
|
||||||
|
);
|
||||||
|
$form['check']['linkchecker_check_library'] = array(
|
||||||
|
'#type' => 'select',
|
||||||
|
'#title' => t('Check library'),
|
||||||
|
'#description' => t('Defines the library that is used for checking links.'),
|
||||||
|
'#default_value' => variable_get('linkchecker_check_library', 'core'),
|
||||||
|
'#options' => array(
|
||||||
|
'core' => t('Drupal core'),
|
||||||
|
'httprl' => t('HTTP Parallel Request & Threading Library'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$form['check']['linkchecker_check_connections_max'] = array(
|
||||||
|
'#type' => 'select',
|
||||||
|
'#title' => t('Number of simultaneous connections'),
|
||||||
|
'#description' => t('Defines the maximum number of simultaneous connections that can be opened by the server. <em>HTTP Parallel Request & Threading Library</em> make sure that a single domain is not overloaded beyond RFC limits. For small hosting plans with very limited CPU and RAM it may be required to reduce the default limit.'),
|
||||||
|
'#default_value' => variable_get('linkchecker_check_connections_max', 8),
|
||||||
|
'#options' => drupal_map_assoc(array(2, 4, 8, 16, 24, 32, 48, 64, 96, 128)),
|
||||||
|
);
|
||||||
|
$form['check']['linkchecker_check_useragent'] = array(
|
||||||
|
'#type' => 'select',
|
||||||
|
'#title' => t('User-Agent'),
|
||||||
|
'#description' => t('Defines the user agent that will be used for checking links on remote sites. If someone blocks the standard Drupal user agent you can try with a more common browser.'),
|
||||||
|
'#default_value' => variable_get('linkchecker_check_useragent', 'Drupal (+http://drupal.org/)'),
|
||||||
|
'#options' => array(
|
||||||
|
'Drupal (+http://drupal.org/)' => 'Drupal (+http://drupal.org/)',
|
||||||
|
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)' => 'Windows 7 (x64), Internet Explorer 9.0',
|
||||||
|
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0' => 'Windows 7 (x64), Mozilla Firefox 17.0',
|
||||||
|
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)' => 'Windows 8 (x64), Internet Explorer 10.0',
|
||||||
|
'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0' => 'Windows 8 (x64), Mozilla Firefox 17.0',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$form['check']['linkchecker_check_links_interval'] = array(
|
||||||
|
'#type' => 'select',
|
||||||
|
'#title' => t('Check interval for links'),
|
||||||
|
'#description' => t('This interval setting defines how often cron will re-check the status of links.'),
|
||||||
|
'#default_value' => variable_get('linkchecker_check_links_interval', 2419200),
|
||||||
|
'#options' => drupal_map_assoc(array(86400, 172800, 259200, 604800, 1209600, 2419200, 4838400), 'format_interval'),
|
||||||
|
);
|
||||||
|
$form['check']['linkchecker_disable_link_check_for_urls'] = array(
|
||||||
|
'#default_value' => variable_get('linkchecker_disable_link_check_for_urls', LINKCHECKER_RESERVED_DOCUMENTATION_DOMAINS),
|
||||||
|
'#type' => 'textarea',
|
||||||
|
'#title' => t('Do not check the link status of links containing these URLs'),
|
||||||
|
'#description' => t('By default this list contains the domain names reserved for use in documentation and not available for registration. See <a href="@rfc-2606">RFC 2606</a>, Section 3 for more information. URLs on this list are still extracted, but the link setting <em>Check link status</em> becomes automatically disabled to prevent false alarms. If you change this list you need to clear all link data and re-analyze your content. Otherwise this setting will only affect new links added after the configuration change.', array('@rfc-2606' => 'http://www.rfc-editor.org/rfc/rfc2606.txt')),
|
||||||
|
'#wysiwyg' => FALSE,
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['error'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('Error handling'),
|
||||||
|
'#description' => t('Defines error handling and custom actions to be executed if specific HTTP requests are failing.'),
|
||||||
|
'#collapsible' => FALSE,
|
||||||
|
);
|
||||||
|
$linkchecker_default_impersonate_user = user_load(1);
|
||||||
|
$form['error']['linkchecker_impersonate_user'] = array(
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#title' => t('Impersonate user account'),
|
||||||
|
'#description' => t('If below error handling actions are executed they can be impersonated with a custom user account. By default this is user %name, but you are able to assign a custom user to allow easier identification of these automatic revision updates. Make sure you select a user with <em>full</em> permissions on your site or the user may not able to access and save all content.', array('%name' => $linkchecker_default_impersonate_user->name)),
|
||||||
|
'#size' => 30,
|
||||||
|
'#maxlength' => 60,
|
||||||
|
'#autocomplete_path' => 'user/autocomplete',
|
||||||
|
'#default_value' => variable_get('linkchecker_impersonate_user', ''),
|
||||||
|
);
|
||||||
|
$form['error']['linkchecker_action_status_code_301'] = array(
|
||||||
|
'#title' => t('Update permanently moved links'),
|
||||||
|
'#description' => t('If enabled, outdated links in content providing a status <em>Moved Permanently</em> (status code 301) are automatically updated to the most recent URL. If used, it is recommended to use a value of <em>three</em> to make sure this is not only a temporarily change. This feature trust sites to provide a valid permanent redirect. A new node revision is automatically created on link updates if <em>create new revision</em> is enabled in the <a href="@node_types">node type</a> workflow settings. It is recommended to create new revisions for all link checker enabled node types. Link updates are nevertheless always logged in <a href="@dblog">recent log entries</a>.', array('@dblog' => url('admin/reports/dblog'), '@node_types' => url('admin/content/types'))),
|
||||||
|
'#type' => 'select',
|
||||||
|
'#default_value' => variable_get('linkchecker_action_status_code_301', 0),
|
||||||
|
'#options' => array(
|
||||||
|
0 => t('Disabled'),
|
||||||
|
1 => t('After one failed check'),
|
||||||
|
2 => t('After two failed checks'),
|
||||||
|
3 => t('After three failed checks'),
|
||||||
|
5 => t('After five failed checks'),
|
||||||
|
10 => t('After ten failed checks'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$form['error']['linkchecker_action_status_code_404'] = array(
|
||||||
|
'#title' => t('Unpublish node on file not found error'),
|
||||||
|
'#description' => t('If enabled, a node with one or more broken links (status code 404) will be unpublished and moved to moderation queue for review after the number of specified checks failed. If used, it is recommended to use a value of <em>three</em> to make sure this is not only a temporarily error.'),
|
||||||
|
'#type' => 'select',
|
||||||
|
'#default_value' => variable_get('linkchecker_action_status_code_404', 0),
|
||||||
|
'#options' => array(
|
||||||
|
0 => t('Disabled'),
|
||||||
|
1 => t('After one file not found error'),
|
||||||
|
2 => t('After two file not found errors'),
|
||||||
|
3 => t('After three file not found errors'),
|
||||||
|
5 => t('After five file not found errors'),
|
||||||
|
10 => t('After ten file not found errors'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$form['error']['linkchecker_ignore_response_codes'] = array(
|
||||||
|
'#default_value' => variable_get('linkchecker_ignore_response_codes', "200\n206\n302\n304\n401\n403"),
|
||||||
|
'#type' => 'textarea',
|
||||||
|
'#title' => t("Don't treat these response codes as errors"),
|
||||||
|
'#description' => t('One HTTP status code per line, e.g. 403.'),
|
||||||
|
'#wysiwyg' => FALSE,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Buttons are only required for testing and debugging reasons.
|
||||||
|
$description = '<p>' . t('These actions will either clear all link checker tables in the database and/or analyze all selected node types, blocks and cck fields (see settings above) for new/updated/removed links. Normally there is no need to press one of these buttons. Use this only for immediate cleanup tasks and to force a full re-build of the links to be checked in the linkchecker tables. Keep in mind that all custom link settings will be lost if you clear link data!') . '</p>';
|
||||||
|
$description .= '<p>' . t('<strong>Note</strong>: These functions ONLY collect the links, they do not evaluate the HTTP response codes, this will be done during normal cron runs.') . '</p>';
|
||||||
|
|
||||||
|
$form['clear'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('Maintenance'),
|
||||||
|
'#description' => $description,
|
||||||
|
'#collapsible' => TRUE,
|
||||||
|
'#collapsed' => TRUE,
|
||||||
|
);
|
||||||
|
$form['clear']['linkchecker_analyze'] = array(
|
||||||
|
'#type' => 'submit',
|
||||||
|
'#value' => t('Reanalyze content for links'),
|
||||||
|
'#submit' => array('linkchecker_analyze_links_submit'),
|
||||||
|
);
|
||||||
|
$form['clear']['linkchecker_clear_analyze'] = array(
|
||||||
|
'#type' => 'submit',
|
||||||
|
'#value' => t('Clear link data and analyze content for links'),
|
||||||
|
'#submit' => array('linkchecker_clear_analyze_links_submit'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
|
||||||
|
$form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
function linkchecker_admin_settings_form_validate($form, &$form_state) {
|
||||||
|
$form_state['values']['linkchecker_disable_link_check_for_urls'] = trim($form_state['values']['linkchecker_disable_link_check_for_urls']);
|
||||||
|
$form_state['values']['linkchecker_ignore_response_codes'] = trim($form_state['values']['linkchecker_ignore_response_codes']);
|
||||||
|
$ignore_response_codes = preg_split('/(\r\n?|\n)/', $form_state['values']['linkchecker_ignore_response_codes']);
|
||||||
|
foreach ($ignore_response_codes as $ignore_response_code) {
|
||||||
|
if (!_linkchecker_isvalid_response_code($ignore_response_code)) {
|
||||||
|
form_set_error('linkchecker_ignore_response_codes', t('Invalid response code %code found.', array('%code' => $ignore_response_code)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent the removal of RFC documentation domains. This are the official and
|
||||||
|
// reserved documentation domains and not "example" hostnames!
|
||||||
|
$linkchecker_disable_link_check_for_urls = array_filter(preg_split('/(\r\n?|\n)/', $form_state['values']['linkchecker_disable_link_check_for_urls']));
|
||||||
|
$form_state['values']['linkchecker_disable_link_check_for_urls'] = implode("\n", array_unique(array_merge(explode("\n", LINKCHECKER_RESERVED_DOCUMENTATION_DOMAINS), $linkchecker_disable_link_check_for_urls)));
|
||||||
|
|
||||||
|
// Validate impersonation user name.
|
||||||
|
$linkchecker_impersonate_user = user_load(array('name' => $form_state['values']['linkchecker_impersonate_user']));
|
||||||
|
if (empty($linkchecker_impersonate_user->uid)) {
|
||||||
|
form_set_error('linkchecker_impersonate_user', t('User account %name cannot found.', array('%name' => $form_state['values']['linkchecker_impersonate_user'])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function linkchecker_admin_settings_form_submit($form, &$form_state) {
|
||||||
|
// Exclude unnecessary elements.
|
||||||
|
unset($form_state['values']['linkchecker_analyze'], $form_state['values']['linkchecker_clear_analyze']);
|
||||||
|
|
||||||
|
// Save form settings.
|
||||||
|
system_settings_form_submit($form, $form_state);
|
||||||
|
|
||||||
|
// Re-scan items, if node types or comment or block selection have been changed.
|
||||||
|
$additional_nodetypes_selected = array_diff($form_state['values']['linkchecker_scan_nodetypes'], $form['settings']['linkchecker_scan_nodetypes']['#default_value']);
|
||||||
|
if (!empty($additional_nodetypes_selected) || $form_state['values']['linkchecker_scan_comments'] > $form['settings']['linkchecker_scan_comments']['#default_value']) {
|
||||||
|
$node_types = array_keys(array_filter($form_state['values']['linkchecker_scan_nodetypes']));
|
||||||
|
|
||||||
|
// If one or more node types have been selected.
|
||||||
|
if (!empty($node_types)) {
|
||||||
|
module_load_include('inc', 'linkchecker', '/includes/linkchecker.batch');
|
||||||
|
batch_set(_linkchecker_batch_import_nodes($node_types));
|
||||||
|
|
||||||
|
// If comment scanning of node types has been selected.
|
||||||
|
if ($form_state['values']['linkchecker_scan_comments'] > $form['settings']['linkchecker_scan_comments']['#default_value']) {
|
||||||
|
batch_set(_linkchecker_batch_import_comments($node_types));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If block scanning has been selected.
|
||||||
|
if ($form_state['values']['linkchecker_scan_blocks'] > $form['settings']['linkchecker_scan_blocks']['#default_value']) {
|
||||||
|
module_load_include('inc', 'linkchecker', '/includes/linkchecker.batch');
|
||||||
|
batch_set(_linkchecker_batch_import_boxes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit callback; Analyze all node types, boxes and cck fields.
|
||||||
|
*/
|
||||||
|
function linkchecker_analyze_links_submit($form, &$form_state) {
|
||||||
|
// Exclude unnecessary elements.
|
||||||
|
unset($form_state['values']['linkchecker_analyze'], $form_state['values']['linkchecker_clear_analyze']);
|
||||||
|
|
||||||
|
// Save form settings.
|
||||||
|
system_settings_form_submit($form, $form_state);
|
||||||
|
|
||||||
|
// Start batch and analyze all nodes.
|
||||||
|
$node_types = array_keys(array_filter(variable_get('linkchecker_scan_nodetypes', array())));
|
||||||
|
if (!empty($node_types)) {
|
||||||
|
module_load_include('inc', 'linkchecker', '/includes/linkchecker.batch');
|
||||||
|
batch_set(_linkchecker_batch_import_nodes($node_types));
|
||||||
|
if (variable_get('linkchecker_scan_comments', 0)) {
|
||||||
|
batch_set(_linkchecker_batch_import_comments($node_types));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (variable_get('linkchecker_scan_blocks', 0)) {
|
||||||
|
module_load_include('inc', 'linkchecker', '/includes/linkchecker.batch');
|
||||||
|
batch_set(_linkchecker_batch_import_boxes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit callback; Clear link data and analyze all node types, boxes and cck fields.
|
||||||
|
*/
|
||||||
|
function linkchecker_clear_analyze_links_submit($form, &$form_state) {
|
||||||
|
// Exclude unnecessary elements.
|
||||||
|
unset($form_state['values']['linkchecker_analyze'], $form_state['values']['linkchecker_clear_analyze']);
|
||||||
|
|
||||||
|
// Save form settings.
|
||||||
|
system_settings_form_submit($form, $form_state);
|
||||||
|
|
||||||
|
db_query("TRUNCATE TABLE {linkchecker_nodes}");
|
||||||
|
db_query("TRUNCATE TABLE {linkchecker_comments}");
|
||||||
|
db_query("TRUNCATE TABLE {linkchecker_boxes}");
|
||||||
|
db_query("TRUNCATE TABLE {linkchecker_links}");
|
||||||
|
|
||||||
|
// Start batch and analyze all nodes.
|
||||||
|
$node_types = array_keys(array_filter(variable_get('linkchecker_scan_nodetypes', array())));
|
||||||
|
if (!empty($node_types)) {
|
||||||
|
module_load_include('inc', 'linkchecker', '/includes/linkchecker.batch');
|
||||||
|
batch_set(_linkchecker_batch_import_nodes($node_types));
|
||||||
|
if (variable_get('linkchecker_scan_comments', 0)) {
|
||||||
|
batch_set(_linkchecker_batch_import_comments($node_types));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (variable_get('linkchecker_scan_blocks', 0)) {
|
||||||
|
module_load_include('inc', 'linkchecker', '/includes/linkchecker.batch');
|
||||||
|
batch_set(_linkchecker_batch_import_boxes());
|
||||||
|
}
|
||||||
|
}
|
280
sites/all/modules/linkchecker/includes/linkchecker.batch.inc
Normal file
280
sites/all/modules/linkchecker/includes/linkchecker.batch.inc
Normal file
|
@ -0,0 +1,280 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Batch API callbacks for the linkchecker module.
|
||||||
|
*
|
||||||
|
* TODO: Test with 500.000+ nodes/comments/blocks and review memory consumption.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Batch: Scan nodes for links.
|
||||||
|
*/
|
||||||
|
function _linkchecker_batch_import_nodes($node_types = array()) {
|
||||||
|
// Get all active {node}.nid's.
|
||||||
|
$result = db_query('SELECT n.nid FROM {node} n WHERE n.status = %d AND n.type IN (' . db_placeholders($node_types, 'varchar') . ') ORDER BY n.nid', array_merge(array(1), $node_types));
|
||||||
|
|
||||||
|
$operations = array();
|
||||||
|
while ($row = db_fetch_array($result)) {
|
||||||
|
$operations[] = array('_linkchecker_batch_node_import_op', array($row['nid']));
|
||||||
|
}
|
||||||
|
$batch = array(
|
||||||
|
'file' => drupal_get_path('module', 'linkchecker') .'/includes/linkchecker.batch.inc',
|
||||||
|
'finished' => '_linkchecker_batch_node_import_finished',
|
||||||
|
'operations' => $operations,
|
||||||
|
'title' => t('Scanning for links'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $batch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Batch operation: Scan ony by one node for links.
|
||||||
|
*/
|
||||||
|
function _linkchecker_batch_node_import_op($nid, &$context) {
|
||||||
|
// Load the node and scan for links.
|
||||||
|
$node = node_load($nid, NULL, TRUE);
|
||||||
|
_linkchecker_add_node_links($node);
|
||||||
|
|
||||||
|
// Store results for post-processing in the finished callback.
|
||||||
|
$context['results'][] = $node->nid;
|
||||||
|
$context['message'] = t('Node: @title', array('@title' => $node->title));
|
||||||
|
}
|
||||||
|
|
||||||
|
function _linkchecker_batch_node_import_finished($success, $results, $operations) {
|
||||||
|
if ($success) {
|
||||||
|
$message = format_plural(count($results), 'One node has been scanned.', '@count nodes have been scanned.');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$message = t('Scanning for links in nodes have failed with an error.');
|
||||||
|
}
|
||||||
|
drupal_set_message($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Batch: Scan comments for links.
|
||||||
|
*/
|
||||||
|
function _linkchecker_batch_import_comments($node_types = array()) {
|
||||||
|
// Get all active {comments}.cid's.
|
||||||
|
$result = db_query('SELECT c.cid FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid WHERE c.status = %d AND n.status = %d AND n.type IN (' . db_placeholders($node_types, 'varchar') . ') ORDER BY c.cid', array_merge(array(COMMENT_PUBLISHED, 1), $node_types));
|
||||||
|
|
||||||
|
$operations = array();
|
||||||
|
while ($row = db_fetch_array($result)) {
|
||||||
|
$operations[] = array('_linkchecker_batch_comments_import_op', array($row['cid']));
|
||||||
|
}
|
||||||
|
$batch = array(
|
||||||
|
'file' => drupal_get_path('module', 'linkchecker') .'/includes/linkchecker.batch.inc',
|
||||||
|
'finished' => '_linkchecker_batch_comments_import_finished',
|
||||||
|
'operations' => $operations,
|
||||||
|
'title' => t('Scanning for links'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $batch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Batch operation: Scan ony by one comment for links.
|
||||||
|
*/
|
||||||
|
function _linkchecker_batch_comments_import_op($cid, &$context) {
|
||||||
|
// Load the comment and scan for links.
|
||||||
|
$comment = _linkchecker_comment_load($cid);
|
||||||
|
_linkchecker_add_comment_links($comment);
|
||||||
|
|
||||||
|
// Store results for post-processing in the finished callback.
|
||||||
|
$context['results'][] = $comment['cid'];
|
||||||
|
$context['message'] = t('Comment: @title', array('@title' => $comment['subject']));
|
||||||
|
}
|
||||||
|
|
||||||
|
function _linkchecker_batch_comments_import_finished($success, $results, $operations) {
|
||||||
|
if ($success) {
|
||||||
|
$message = format_plural(count($results), 'One comment has been scanned.', '@count comments have been scanned.');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$message = t('Scanning for links in comments have failed with an error.');
|
||||||
|
}
|
||||||
|
drupal_set_message($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Batch: Scan blocks for links.
|
||||||
|
*/
|
||||||
|
function _linkchecker_batch_import_boxes() {
|
||||||
|
// Get all {boxes}.bid's as block module suxxx and has no usable hooks.
|
||||||
|
$result = db_query('SELECT b.bid FROM {boxes} b ORDER BY b.bid');
|
||||||
|
|
||||||
|
$operations = array();
|
||||||
|
while ($row = db_fetch_array($result)) {
|
||||||
|
$operations[] = array('_linkchecker_batch_import_boxes_op', array($row['bid']));
|
||||||
|
}
|
||||||
|
$batch = array(
|
||||||
|
'file' => drupal_get_path('module', 'linkchecker') .'/includes/linkchecker.batch.inc',
|
||||||
|
'finished' => '_linkchecker_batch_box_import_finished',
|
||||||
|
'operations' => $operations,
|
||||||
|
'title' => t('Scanning for links'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $batch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Batch operation: Scan ony by one block for links.
|
||||||
|
*/
|
||||||
|
function _linkchecker_batch_import_boxes_op($bid, &$context) {
|
||||||
|
// Load the box and scan for links.
|
||||||
|
$box = block_box_get($bid);
|
||||||
|
_linkchecker_add_box_links($box, $box['bid']);
|
||||||
|
|
||||||
|
// Store some result for post-processing in the finished callback.
|
||||||
|
$context['results'][] = $box['bid'];
|
||||||
|
$context['message'] = t('Block: @title', array('@title' => $box['info']));
|
||||||
|
}
|
||||||
|
|
||||||
|
function _linkchecker_batch_box_import_finished($success, $results, $operations) {
|
||||||
|
if ($success) {
|
||||||
|
$message = format_plural(count($results), 'One block has been scanned.', '@count blocks have been scanned.');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$message = t('Scanning for links in blocks have failed with an error.');
|
||||||
|
}
|
||||||
|
drupal_set_message($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recurring scans of a single node via batch API.
|
||||||
|
*
|
||||||
|
* @param int $nid
|
||||||
|
* The unique node id to scan for links.
|
||||||
|
* @param int $missing_links_count
|
||||||
|
* The number of links not yet added to linkchecker_links table. By this
|
||||||
|
* number the re-scan rounds are calulated.
|
||||||
|
* @return
|
||||||
|
* The batch task definition.
|
||||||
|
*/
|
||||||
|
function _linkchecker_batch_import_single_node($nid, $missing_links_count) {
|
||||||
|
$operations = array();
|
||||||
|
for ($i = 0; $i <= $missing_links_count; $i = $i+LINKCHECKER_SCAN_MAX_LINKS_PER_RUN) {
|
||||||
|
$operations[] = array('_linkchecker_batch_single_node_import_op', array($nid));
|
||||||
|
}
|
||||||
|
$batch = array(
|
||||||
|
'file' => drupal_get_path('module', 'linkchecker') .'/includes/linkchecker.batch.inc',
|
||||||
|
'finished' => '_linkchecker_batch_single_node_import_finished',
|
||||||
|
'operations' => $operations,
|
||||||
|
'title' => t('Scanning for links'),
|
||||||
|
'progress_message' => t('Remaining @remaining of @total scans.'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $batch;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _linkchecker_batch_single_node_import_op($nid, &$context) {
|
||||||
|
// Load the node and scan for links.
|
||||||
|
$node = node_load($nid, NULL, TRUE);
|
||||||
|
_linkchecker_add_node_links($node, TRUE);
|
||||||
|
|
||||||
|
// Store results for post-processing in the finished callback.
|
||||||
|
$context['results'][] = $node->nid;
|
||||||
|
$context['message'] = t('Node: @title', array('@title' => $node->title));
|
||||||
|
}
|
||||||
|
|
||||||
|
function _linkchecker_batch_single_node_import_finished($success, $results, $operations) {
|
||||||
|
if ($success) {
|
||||||
|
$message = format_plural(count($results), 'Node @nid has been re-scanned once to collect all links.', 'Node @nid has been re-scanned @count times to collect all links.', array('@nid' => $results[0]));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$message = t('Recurring scanning for links in node @nid have failed with an error.', array('@nid' => $results[0]));
|
||||||
|
}
|
||||||
|
drupal_set_message($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recurring scans of a single comment via batch API.
|
||||||
|
*
|
||||||
|
* @param int $cid
|
||||||
|
* The unique comment id to scan for links.
|
||||||
|
* @param int $missing_links_count
|
||||||
|
* The number of links not yet added to linkchecker_links table. By this
|
||||||
|
* number the re-scan rounds are calulated.
|
||||||
|
* @return
|
||||||
|
* The batch task definition.
|
||||||
|
*/
|
||||||
|
function _linkchecker_batch_import_single_comment($cid, $missing_links_count) {
|
||||||
|
$operations = array();
|
||||||
|
for ($i = 0; $i <= $missing_links_count; $i = $i+LINKCHECKER_SCAN_MAX_LINKS_PER_RUN) {
|
||||||
|
$operations[] = array('_linkchecker_batch_single_comment_import_op', array($cid));
|
||||||
|
}
|
||||||
|
$batch = array(
|
||||||
|
'file' => drupal_get_path('module', 'linkchecker') .'/includes/linkchecker.batch.inc',
|
||||||
|
'finished' => '_linkchecker_batch_single_comment_import_finished',
|
||||||
|
'operations' => $operations,
|
||||||
|
'title' => t('Scanning for links'),
|
||||||
|
'progress_message' => t('Remaining @remaining of @total scans.'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $batch;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _linkchecker_batch_single_comment_import_op($cid, &$context) {
|
||||||
|
$comment = _linkchecker_comment_load($cid);
|
||||||
|
_linkchecker_add_comment_links($comment, TRUE);
|
||||||
|
|
||||||
|
// Store results for post-processing in the finished callback.
|
||||||
|
$context['results'][] = $comment['cid'];
|
||||||
|
$context['message'] = t('Comment: @title', array('@title' => $comment['subject']));
|
||||||
|
}
|
||||||
|
|
||||||
|
function _linkchecker_batch_single_comment_import_finished($success, $results, $operations) {
|
||||||
|
if ($success) {
|
||||||
|
$message = format_plural(count($results), 'Comment @cid has been re-scanned once to collect all links.', 'Comment @cid has been re-scanned @count times to collect all links.', array('@cid' => $results[0]));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$message = t('Recurring scanning for links in comment @cid have failed with an error.', array('@cid' => $results[0]));
|
||||||
|
}
|
||||||
|
drupal_set_message($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recurring scans of a single block via batch API.
|
||||||
|
*
|
||||||
|
* @param int $bid
|
||||||
|
* The unique block id to scan for links.
|
||||||
|
* @param int $missing_links_count
|
||||||
|
* The number of links not yet added to linkchecker_links table. By this
|
||||||
|
* number the re-scan rounds are calulated.
|
||||||
|
* @return
|
||||||
|
* The batch task definition.
|
||||||
|
*/
|
||||||
|
function _linkchecker_batch_import_single_box($bid, $missing_links_count) {
|
||||||
|
$operations = array();
|
||||||
|
for ($i = 0; $i <= $missing_links_count; $i = $i+LINKCHECKER_SCAN_MAX_LINKS_PER_RUN) {
|
||||||
|
$operations[] = array('_linkchecker_batch_single_box_import_op', array($bid));
|
||||||
|
}
|
||||||
|
$batch = array(
|
||||||
|
'file' => drupal_get_path('module', 'linkchecker') .'/includes/linkchecker.batch.inc',
|
||||||
|
'finished' => '_linkchecker_batch_single_box_import_finished',
|
||||||
|
'operations' => $operations,
|
||||||
|
'title' => t('Scanning for links'),
|
||||||
|
'progress_message' => t('Remaining @remaining of @total scans.'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $batch;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _linkchecker_batch_single_box_import_op($bid, &$context) {
|
||||||
|
// Load the box and scan for links.
|
||||||
|
$box = block_box_get($bid);
|
||||||
|
_linkchecker_add_box_links($box, $box['bid'], TRUE);
|
||||||
|
|
||||||
|
// Store some result for post-processing in the finished callback.
|
||||||
|
$context['results'][] = $box['bid'];
|
||||||
|
$context['message'] = t('Block: @title', array('@title' => $box['info']));
|
||||||
|
}
|
||||||
|
|
||||||
|
function _linkchecker_batch_single_box_import_finished($success, $results, $operations) {
|
||||||
|
if ($success) {
|
||||||
|
$message = format_plural(count($results), 'Block @bid has been re-scanned once to collect all links.', 'Block @bid has been re-scanned @count times to collect all links.', array('@bid' => $results[0]));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$message = t('Recurring scanning for links in block @bid have failed with an error.', array('@bid' => $results[0]));
|
||||||
|
}
|
||||||
|
drupal_set_message($message);
|
||||||
|
}
|
256
sites/all/modules/linkchecker/includes/linkchecker.pages.inc
Normal file
256
sites/all/modules/linkchecker/includes/linkchecker.pages.inc
Normal file
|
@ -0,0 +1,256 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* User page callbacks for the linkchecker module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Menu callback for general reporting.
|
||||||
|
*/
|
||||||
|
function linkchecker_admin_report_page() {
|
||||||
|
|
||||||
|
$ignore_response_codes = preg_split('/(\r\n?|\n)/', variable_get('linkchecker_ignore_response_codes', "200\n206\n302\n304\n401\n403"));
|
||||||
|
|
||||||
|
// Search for broken links in nodes and comments and blocks of all users.
|
||||||
|
// TODO: Try to make subselect result smaller.
|
||||||
|
$links_report_sql = "SELECT ll.*
|
||||||
|
FROM {linkchecker_links} ll
|
||||||
|
INNER JOIN (
|
||||||
|
SELECT lid FROM (
|
||||||
|
SELECT DISTINCT lid FROM {linkchecker_boxes}
|
||||||
|
UNION
|
||||||
|
SELECT DISTINCT lid FROM {linkchecker_comments}
|
||||||
|
UNION
|
||||||
|
SELECT DISTINCT lid FROM {linkchecker_nodes}
|
||||||
|
) q1
|
||||||
|
) q2 ON q2.lid = ll.lid
|
||||||
|
WHERE ll.last_checked <> %d AND ll.status = %d AND ll.code NOT IN (" . db_placeholders($ignore_response_codes, 'int') . ")";
|
||||||
|
|
||||||
|
// Build the array variable with all parameters for the pager_query.
|
||||||
|
$links_report_parameters = array_merge(array(0, 1), $ignore_response_codes);
|
||||||
|
|
||||||
|
return _linkchecker_report_page($links_report_sql, $links_report_parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Menu callback for author specific reporting.
|
||||||
|
*/
|
||||||
|
function linkchecker_user_report_page($account) {
|
||||||
|
drupal_set_title(check_plain($account->name));
|
||||||
|
|
||||||
|
$ignore_response_codes = preg_split('/(\r\n?|\n)/', variable_get('linkchecker_ignore_response_codes', "200\n206\n302\n304\n401\n403"));
|
||||||
|
|
||||||
|
// Search for broken links in nodes and comments of the current user.
|
||||||
|
if (module_exists('comment') && variable_get('linkchecker_scan_comments', 0)) {
|
||||||
|
$links_report_sql = "SELECT ll.*
|
||||||
|
FROM {linkchecker_links} ll
|
||||||
|
INNER JOIN (
|
||||||
|
SELECT lid FROM (
|
||||||
|
SELECT DISTINCT ll.lid
|
||||||
|
FROM {node} n
|
||||||
|
INNER JOIN {node_revisions} r ON r.vid = n.vid
|
||||||
|
INNER JOIN {linkchecker_nodes} ln ON ln.nid = n.nid
|
||||||
|
INNER JOIN {linkchecker_links} ll ON ll.lid = ln.lid AND ll.last_checked <> %d AND ll.status = %d AND ll.code NOT IN (" . db_placeholders($ignore_response_codes, 'int') . ")
|
||||||
|
WHERE n.uid = %d OR r.uid = %d
|
||||||
|
UNION
|
||||||
|
SELECT DISTINCT ll.lid
|
||||||
|
FROM {comments} c
|
||||||
|
INNER JOIN {linkchecker_comments} lc ON lc.cid = c.cid
|
||||||
|
INNER JOIN {linkchecker_links} ll ON ll.lid = lc.lid AND ll.last_checked <> %d AND ll.status = %d AND ll.code NOT IN (" . db_placeholders($ignore_response_codes, 'int') . ")
|
||||||
|
WHERE c.uid = %d
|
||||||
|
) q1
|
||||||
|
) q2 ON q2.lid = ll.lid";
|
||||||
|
|
||||||
|
// Build the array variable with all parameters for the pager_query with comment module enabled.
|
||||||
|
$links_report_parameters = array_merge(array(0, 1), $ignore_response_codes, array($account->uid, $account->uid, 0, 1), $ignore_response_codes, array($account->uid));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Search for broken links in nodes of the current user.
|
||||||
|
$links_report_sql = "SELECT ll.*
|
||||||
|
FROM {linkchecker_links} ll
|
||||||
|
INNER JOIN (
|
||||||
|
SELECT lid FROM (
|
||||||
|
SELECT DISTINCT ll.lid
|
||||||
|
FROM {node} n
|
||||||
|
INNER JOIN {node_revisions} r ON r.vid = n.vid
|
||||||
|
INNER JOIN {linkchecker_nodes} ln ON ln.nid = n.nid
|
||||||
|
INNER JOIN {linkchecker_links} ll ON ll.lid = ln.lid AND ll.last_checked <> %d AND ll.status = %d AND ll.code NOT IN (" . db_placeholders($ignore_response_codes, 'int') . ")
|
||||||
|
WHERE n.uid = %d OR r.uid = %d
|
||||||
|
) q1
|
||||||
|
) q2 ON q2.lid = ll.lid";
|
||||||
|
|
||||||
|
// Build the array variable with all parameters for the pager_query with comment module disabled.
|
||||||
|
$links_report_parameters = array_merge(array(0, 1), $ignore_response_codes, array($account->uid, $account->uid));
|
||||||
|
}
|
||||||
|
|
||||||
|
return _linkchecker_report_page($links_report_sql, $links_report_parameters, $account);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _linkchecker_report_page($links_report_sql, $links_report_parameters = NULL, $account = NULL) {
|
||||||
|
|
||||||
|
$links_unchecked = db_result(db_query('SELECT COUNT(1) FROM {linkchecker_links} WHERE last_checked = %d AND status = %d', 0, 1));
|
||||||
|
if ($links_unchecked > 0) {
|
||||||
|
$links_all = db_result(db_query('SELECT COUNT(1) FROM {linkchecker_links} WHERE status = %d', 1));
|
||||||
|
drupal_set_message(format_plural($links_unchecked,
|
||||||
|
'There is 1 unchecked link of about @links_all links in the database. Please be patient until all links have been checked via cron.',
|
||||||
|
'There are @count unchecked links of about @links_all links in the database. Please be patient until all links have been checked via cron.',
|
||||||
|
array('@links_all' => $links_all)), 'warning');
|
||||||
|
}
|
||||||
|
|
||||||
|
$header = array(
|
||||||
|
array('data' => t('URL'), 'field' => 'url', 'sort' => 'desc'),
|
||||||
|
array('data' => t('Response'), 'field' => 'code', 'sort' => 'desc'),
|
||||||
|
array('data' => t('Error'), 'field' => 'error'),
|
||||||
|
array('data' => t('Operations')),
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = pager_query($links_report_sql . tablesort_sql($header), 50, 0, NULL, $links_report_parameters);
|
||||||
|
|
||||||
|
// Evaluate permission once for performance reasons.
|
||||||
|
$access_edit_link_settings = user_access('edit link settings');
|
||||||
|
$access_administer_blocks = user_access('administer blocks');
|
||||||
|
$access_administer_redirects = user_access('administer redirects');
|
||||||
|
|
||||||
|
$rows = array();
|
||||||
|
while ($link = db_fetch_object($result)) {
|
||||||
|
// Get the node, block and comment IDs that refer to this broken link and
|
||||||
|
// that the current user has access to.
|
||||||
|
$nids = _linkchecker_link_node_ids($link, $account);
|
||||||
|
$cids = _linkchecker_link_comment_ids($link, $account);
|
||||||
|
$bids = _linkchecker_link_block_ids($link);
|
||||||
|
|
||||||
|
// If the user does not have access to see this link anywhere, do not
|
||||||
|
// display it, for reasons explained in _linkchecker_link_access(). We
|
||||||
|
// still need to fill the table row, though, so as not to throw off the
|
||||||
|
// number of items in the pager.
|
||||||
|
if (empty($nids) && empty($cids) && empty($bids)) {
|
||||||
|
$rows[] = array(array('data' => t('Permission restrictions deny you access to this broken link.'), 'colspan' => count($header)));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$links = array();
|
||||||
|
|
||||||
|
// Show links to link settings.
|
||||||
|
if ($access_edit_link_settings) {
|
||||||
|
$links[] = l(t('Edit link settings'), 'linkchecker/' . $link->lid . '/edit', array('query' => drupal_get_destination()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show link to nodes having this broken link.
|
||||||
|
foreach ($nids as $nid) {
|
||||||
|
$links[] = l(t('Edit node @node', array('@node' => $nid)), 'node/' . $nid . '/edit', array('query' => drupal_get_destination()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show link to comments having this broken link.
|
||||||
|
if (module_exists('comment') && variable_get('linkchecker_scan_comments', 0)) {
|
||||||
|
foreach ($cids as $cid) {
|
||||||
|
$links[] = l(t('Edit comment @comment', array('@comment' => $cid)), 'comment/edit/' . $cid, array('query' => drupal_get_destination()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show link to blocks having this broken link.
|
||||||
|
if ($access_administer_blocks) {
|
||||||
|
foreach ($bids as $bid) {
|
||||||
|
$links[] = l(t('Edit block @block', array('@block' => $bid)), 'admin/build/block/configure/block/' . $bid, array('query' => drupal_get_destination()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show link to redirect this broken internal link.
|
||||||
|
if (module_exists('path_redirect') && $access_administer_redirects && _linkchecker_is_internal_url($link)) {
|
||||||
|
$links[] = l(t('Create redirection'), 'admin/build/path-redirect/add', array('query' => array('source' => $link->internal)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create table data for output. Use inline styles to prevent extra CSS file.
|
||||||
|
$rows[] = array(
|
||||||
|
l(_filter_url_trim($link->url, 40), $link->url),
|
||||||
|
$link->code,
|
||||||
|
check_plain($link->error),
|
||||||
|
theme('item_list', $links),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($rows)) {
|
||||||
|
$rows[] = array(array('data' => t('No broken links have been found.'), 'colspan' => count($header)));
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = theme('table', $header, $rows);
|
||||||
|
$output .= theme('pager', NULL, 3000, 0);
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
function linkchecker_link_edit_form(&$form_state, $link) {
|
||||||
|
|
||||||
|
$form['settings'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('Settings'),
|
||||||
|
'#collapsible' => FALSE,
|
||||||
|
'#description' => t('The link <a href="@url">@url</a> was last checked on @last_checked and failed @fail_count times.', array('@url' => $link['url'], '@fail_count' => $link['fail_count'], '@last_checked' => format_date($link['last_checked'])))
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['settings']['lid'] = array('#type' => 'hidden', '#value' => $link['lid']);
|
||||||
|
$form['settings']['url'] = array('#type' => 'hidden', '#value' => $link['url']);
|
||||||
|
|
||||||
|
$form['settings']['method'] = array(
|
||||||
|
'#type' => 'select',
|
||||||
|
'#title' => t('Select request method'),
|
||||||
|
'#default_value' => $link['method'],
|
||||||
|
'#options' => array(
|
||||||
|
'HEAD' => t('HEAD'),
|
||||||
|
'GET' => t('GET'),
|
||||||
|
),
|
||||||
|
'#description' => t('Select the request method used for link checks of this link. If you encounter issues like status code 500 errors with the HEAD request method you should try the GET request method before ignoring a link.'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['settings']['status'] = array(
|
||||||
|
'#default_value' => $link['status'],
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Check link status'),
|
||||||
|
'#description' => t("Uncheck if you wish to ignore this link. Use this setting only as a last resort if there is no other way to solve a failed link check."),
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['maintenance'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('Maintenance'),
|
||||||
|
'#collapsible' => FALSE,
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['maintenance']['recheck'] = array(
|
||||||
|
'#default_value' => 0,
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => t('Re-check link status on next cron run'),
|
||||||
|
'#description' => t('Enable this checkbox if you want to re-check the link during the next cron job rather than wait for the next scheduled check on @date.', array('@date' => format_date($link['last_checked'] + variable_get('linkchecker_check_links_interval', 2419200)))),
|
||||||
|
);
|
||||||
|
|
||||||
|
$form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
|
||||||
|
$form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults'));
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
function linkchecker_link_edit_form_submit($form, &$form_state) {
|
||||||
|
// Force asap link re-check.
|
||||||
|
if ($form_state['values']['recheck']) {
|
||||||
|
db_query("UPDATE {linkchecker_links} SET last_checked = %d WHERE lid = %d", 0, $form_state['values']['lid']);
|
||||||
|
drupal_set_message(t('The link %url will be checked again on the next cron run.', array('%url' => $form_state['values']['url'])));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($form_state['values']['method'] != $form['settings']['method']['#default_value']) {
|
||||||
|
// Update settings and reset statistics for a quick re-check.
|
||||||
|
db_query("UPDATE {linkchecker_links} SET method = '%s', fail_count = %d, last_checked = %d, status = %d WHERE lid = %d", $form_state['values']['method'], 0, 0, $form_state['values']['status'], $form_state['values']['lid']);
|
||||||
|
drupal_set_message(t('The link settings for %url have been saved and the fail counter has been reset.', array('%url' => $form_state['values']['url'])));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Update setting only.
|
||||||
|
db_query("UPDATE {linkchecker_links} SET method = '%s', status = %d WHERE lid = %d", $form_state['values']['method'], $form_state['values']['status'], $form_state['values']['lid']);
|
||||||
|
drupal_set_message(t('The link settings for %url have been saved.', array('%url' => $form_state['values']['url'])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _linkchecker_is_internal_url(&$link) {
|
||||||
|
global $base_url;
|
||||||
|
|
||||||
|
if (strpos($link->url, $base_url) === 0) {
|
||||||
|
$link->internal = trim(substr($link->url, strlen($base_url)), " \t\r\n\0\\/");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
10
sites/all/modules/linkchecker/linkchecker.info
Normal file
10
sites/all/modules/linkchecker/linkchecker.info
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
name = Link checker
|
||||||
|
description = "Periodically checks for broken links in node types, blocks and cck fields and reports the results."
|
||||||
|
core = 6.x
|
||||||
|
|
||||||
|
; Information added by Drupal.org packaging script on 2014-06-07
|
||||||
|
version = "6.x-2.8"
|
||||||
|
core = "6.x"
|
||||||
|
project = "linkchecker"
|
||||||
|
datestamp = "1402132729"
|
||||||
|
|
670
sites/all/modules/linkchecker/linkchecker.install
Normal file
670
sites/all/modules/linkchecker/linkchecker.install
Normal file
|
@ -0,0 +1,670 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Installation file for Link Checker module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the minimum MySQL version number this module supports.
|
||||||
|
*
|
||||||
|
* Previous versions do not support subselects, but for performance reasons
|
||||||
|
* the module makes use of them whenever possible. PgSQL do not have this
|
||||||
|
* kind of limitations in the versions supported by Drupal 6.
|
||||||
|
*/
|
||||||
|
define('LINKCHECKER_MINIMUM_MYSQL', '5.0');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of hook_install().
|
||||||
|
*/
|
||||||
|
function linkchecker_install() {
|
||||||
|
drupal_install_schema('linkchecker');
|
||||||
|
|
||||||
|
$linkchecker_default_impersonate_user = user_load(1);
|
||||||
|
variable_set('linkchecker_impersonate_user', $linkchecker_default_impersonate_user->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of hook_uninstall().
|
||||||
|
*/
|
||||||
|
function linkchecker_uninstall() {
|
||||||
|
drupal_uninstall_schema('linkchecker');
|
||||||
|
|
||||||
|
variable_del('linkchecker_action_status_code_301');
|
||||||
|
variable_del('linkchecker_action_status_code_404');
|
||||||
|
variable_del('linkchecker_check_connections_max');
|
||||||
|
variable_del('linkchecker_check_library');
|
||||||
|
variable_del('linkchecker_check_links_interval');
|
||||||
|
variable_del('linkchecker_check_useragent');
|
||||||
|
variable_del('linkchecker_cleanup_links_last');
|
||||||
|
variable_del('linkchecker_disable_link_check_for_urls');
|
||||||
|
variable_del('linkchecker_extract_from_a');
|
||||||
|
variable_del('linkchecker_extract_from_audio');
|
||||||
|
variable_del('linkchecker_extract_from_embed');
|
||||||
|
variable_del('linkchecker_extract_from_iframe');
|
||||||
|
variable_del('linkchecker_extract_from_img');
|
||||||
|
variable_del('linkchecker_extract_from_object');
|
||||||
|
variable_del('linkchecker_extract_from_source');
|
||||||
|
variable_del('linkchecker_extract_from_video');
|
||||||
|
variable_del('linkchecker_filter_blacklist');
|
||||||
|
variable_del('linkchecker_fqdn_only');
|
||||||
|
variable_del('linkchecker_ignore_response_codes');
|
||||||
|
variable_del('linkchecker_impersonate_user');
|
||||||
|
variable_del('linkchecker_scan_blocks');
|
||||||
|
variable_del('linkchecker_scan_comments');
|
||||||
|
variable_del('linkchecker_scan_nodetypes');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of hook_schema().
|
||||||
|
*/
|
||||||
|
function linkchecker_schema() {
|
||||||
|
|
||||||
|
$schema['linkchecker_links'] = array(
|
||||||
|
'description' => 'Stores all links.',
|
||||||
|
'fields' => array(
|
||||||
|
'lid' => array(
|
||||||
|
'type' => 'serial',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique link ID.',
|
||||||
|
),
|
||||||
|
'urlhash' => array(
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 32,
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'The indexable md5 hash of the {linkchecker_links}.url.',
|
||||||
|
),
|
||||||
|
'url' => array(
|
||||||
|
'type' => 'text',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'The full qualified link.',
|
||||||
|
),
|
||||||
|
'method' => array(
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 4,
|
||||||
|
'default' => 'HEAD',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'The method for checking links (HEAD, GET, POST).',
|
||||||
|
),
|
||||||
|
'code' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => -1,
|
||||||
|
'description' => 'HTTP status code from link checking.',
|
||||||
|
),
|
||||||
|
'error' => array(
|
||||||
|
'type' => 'text',
|
||||||
|
'not null' => FALSE,
|
||||||
|
'description' => 'The error message received from the remote server while doing link checking.',
|
||||||
|
),
|
||||||
|
'fail_count' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
'description' => 'Fail count of unsuccessful link checks. No flapping detection. (Successful = 0, Unsuccessful = fail_count+1).',
|
||||||
|
),
|
||||||
|
'last_checked' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
'description' => 'Timestamp of the last link check.',
|
||||||
|
),
|
||||||
|
'status' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 1,
|
||||||
|
'description' => 'Boolean indicating if a link should be checked or not.',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('lid'),
|
||||||
|
'unique keys' => array('urlhash' => array('urlhash')),
|
||||||
|
'indexes' => array(
|
||||||
|
'method' => array('method'),
|
||||||
|
'code' => array('code'),
|
||||||
|
'fail_count' => array('fail_count'),
|
||||||
|
'last_checked' => array('last_checked'),
|
||||||
|
'status' => array('status'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$schema['linkchecker_boxes'] = array(
|
||||||
|
'description' => 'Stores all link references for boxes.',
|
||||||
|
'fields' => array(
|
||||||
|
'bid' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique {boxes}.bid.',
|
||||||
|
),
|
||||||
|
'lid' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique {linkchecker_links}.lid.',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('bid', 'lid'),
|
||||||
|
'indexes' => array('lid' => array('lid')),
|
||||||
|
);
|
||||||
|
|
||||||
|
$schema['linkchecker_nodes'] = array(
|
||||||
|
'description' => 'Stores all link references for nodes.',
|
||||||
|
'fields' => array(
|
||||||
|
'nid' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique {node}.nid.',
|
||||||
|
),
|
||||||
|
'lid' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique {linkchecker_links}.lid.',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('nid', 'lid'),
|
||||||
|
'indexes' => array('lid' => array('lid')),
|
||||||
|
);
|
||||||
|
|
||||||
|
$schema['linkchecker_comments'] = array(
|
||||||
|
'description' => 'Stores all link references for comments.',
|
||||||
|
'fields' => array(
|
||||||
|
'cid' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique {comments}.cid.',
|
||||||
|
),
|
||||||
|
'lid' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique {linkchecker_links}.lid.',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('cid', 'lid'),
|
||||||
|
'indexes' => array('lid' => array('lid')),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of hook_requirements().
|
||||||
|
*/
|
||||||
|
function linkchecker_requirements($phase) {
|
||||||
|
$requirements = array();
|
||||||
|
$t = get_t();
|
||||||
|
|
||||||
|
switch ($phase) {
|
||||||
|
case 'install' :
|
||||||
|
// MySQL version with subselect support is required.
|
||||||
|
$version = db_version();
|
||||||
|
if (in_array($GLOBALS['db_type'], array('mysql', 'mysqli')) && version_compare($version, LINKCHECKER_MINIMUM_MYSQL) < 0) {
|
||||||
|
$requirements['linkchecker_minimum_mysql'] = array(
|
||||||
|
'title' => $t('MySQL database'),
|
||||||
|
'value' => $version,
|
||||||
|
'severity' => REQUIREMENT_ERROR,
|
||||||
|
'description' => $t('Your MySQL Server is too old. Link Checker requires at least MySQL %version.', array('%version' => LINKCHECKER_MINIMUM_MYSQL)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $requirements;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade module to new D5 schema.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_5200() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
// Module functions are required. Make sure the module is loaded.
|
||||||
|
drupal_load('module', 'linkchecker');
|
||||||
|
|
||||||
|
// Remove obsolete tables no longer required.
|
||||||
|
db_drop_table($ret, 'linkchecker_tasks');
|
||||||
|
db_drop_table($ret, 'linkchecker_results');
|
||||||
|
|
||||||
|
// Create new tables.
|
||||||
|
$schema['linkchecker_links'] = array(
|
||||||
|
'description' => 'Stores all links.',
|
||||||
|
'fields' => array(
|
||||||
|
'lid' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique link ID.',
|
||||||
|
),
|
||||||
|
'token' => array(
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 32,
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'The indexable md5 hash of the {linkchecker_links}.url.',
|
||||||
|
),
|
||||||
|
'url' => array(
|
||||||
|
'type' => 'text',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'The full qualified link URL.',
|
||||||
|
),
|
||||||
|
'method' => array(
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 4,
|
||||||
|
'default' => 'HEAD',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'The method for checking links (HEAD, GET, POST).',
|
||||||
|
),
|
||||||
|
'code' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
'description' => 'HTTP status code from link checking.',
|
||||||
|
),
|
||||||
|
'error' => array(
|
||||||
|
'type' => 'text',
|
||||||
|
'not null' => FALSE,
|
||||||
|
'description' => 'The error message received from the remote server while doing link checking.',
|
||||||
|
),
|
||||||
|
'fail_count' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
'description' => 'Fail count of unsuccessful link checks. No flapping detection. (Successful = 0, Unsuccessful = fail_count+1).',
|
||||||
|
),
|
||||||
|
'last_checked' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => 0,
|
||||||
|
'description' => 'Timestamp of the last link check.',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('lid'),
|
||||||
|
'unique keys' => array('token' => array('token')),
|
||||||
|
);
|
||||||
|
|
||||||
|
$schema['linkchecker_boxes'] = array(
|
||||||
|
'description' => 'Stores all link references for boxes.',
|
||||||
|
'fields' => array(
|
||||||
|
'bid' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique {boxes}.bid.',
|
||||||
|
),
|
||||||
|
'lid' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique {linkchecker_links}.lid.',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('bid', 'lid'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$schema['linkchecker_nodes'] = array(
|
||||||
|
'description' => 'Stores all link references for nodes.',
|
||||||
|
'fields' => array(
|
||||||
|
'nid' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique {node}.nid.',
|
||||||
|
),
|
||||||
|
'lid' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique {linkchecker_links}.lid.',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('nid', 'lid'),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create schema.
|
||||||
|
db_create_table($ret, 'linkchecker_links', $schema['linkchecker_links']);
|
||||||
|
db_create_table($ret, 'linkchecker_boxes', $schema['linkchecker_boxes']);
|
||||||
|
db_create_table($ret, 'linkchecker_nodes', $schema['linkchecker_nodes']);
|
||||||
|
|
||||||
|
// Upgrade settings. Could be less code, but is easier to follow.
|
||||||
|
$ignore_response_codes = preg_split('/(\r\n?|\n)/', variable_get('linkchecker_ignore_responses', "200\n304\n401\n403"));
|
||||||
|
|
||||||
|
// Filter all invalid responds codes and outdated error messages out.
|
||||||
|
$ignore_response_codes = array_filter($ignore_response_codes, '_linkchecker_isvalid_response_code');
|
||||||
|
|
||||||
|
// Make sure we have status code 200 and 304 in the ignore list.
|
||||||
|
$ignore_response_codes = array_merge(array('200', '304'), $ignore_response_codes);
|
||||||
|
$ignore_response_codes = array_unique($ignore_response_codes);
|
||||||
|
|
||||||
|
variable_set('linkchecker_ignore_response_codes', implode("\n", $ignore_response_codes));
|
||||||
|
$ret[] = array('success' => TRUE, 'query' => 'Ignored response codes have been upgraded to '. implode(",", $ignore_response_codes));
|
||||||
|
|
||||||
|
// Remove obsolete settings.
|
||||||
|
variable_del('linkchecker_ignore_responses');
|
||||||
|
variable_del('linkchecker_rebuild');
|
||||||
|
variable_del('linkchecker_maxtime');
|
||||||
|
variable_del('linkchecker_socket_timeout');
|
||||||
|
variable_del('linkchecker_max_links_per_node');
|
||||||
|
variable_del('linkchecker_remove_after');
|
||||||
|
variable_del('linkchecker_give_up');
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade module to new D6 schema.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6200() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
db_change_field($ret, 'linkchecker_links', 'lid', 'lid', array('type' => 'serial', 'not null' => TRUE));
|
||||||
|
|
||||||
|
// Upgrade line break converter from D5 filter/2 to D6 filter/1.
|
||||||
|
$linkchecker_filter_blacklist = variable_get('linkchecker_filter_blacklist', array());
|
||||||
|
if (!empty($linkchecker_filter_blacklist) && $linkchecker_filter_blacklist['filter/2']) {
|
||||||
|
$linkchecker_filter_blacklist['filter/2'] = 0;
|
||||||
|
$linkchecker_filter_blacklist['filter/1'] = 'filter/1';
|
||||||
|
variable_set('linkchecker_filter_blacklist', $linkchecker_filter_blacklist);
|
||||||
|
$ret[] = array('success' => TRUE, 'query' => 'Upgraded the default exclusion of line break converter filter from D5 filter/2 to D6 filter/1.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install linkchecker_comments table.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6201() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
// Create new tables.
|
||||||
|
$schema['linkchecker_comments'] = array(
|
||||||
|
'description' => 'Stores all link references for comments.',
|
||||||
|
'fields' => array(
|
||||||
|
'cid' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique {comments}.cid.',
|
||||||
|
),
|
||||||
|
'lid' => array(
|
||||||
|
'type' => 'int',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'description' => 'Primary Key: Unique {linkchecker_links}.lid.',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('cid', 'lid'),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Table may be created in 5201 by 5.x-2.x.
|
||||||
|
if (!db_table_exists('linkchecker_comments')) {
|
||||||
|
db_create_table($ret, 'linkchecker_comments', $schema['linkchecker_comments']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove unnecessary elements from custom submit buttons.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6202() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
variable_del('linkchecker_analyze');
|
||||||
|
variable_del('linkchecker_clear_analyze');
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make fields unsigned.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6204() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
// Make linkchecker_links.lid unsigned.
|
||||||
|
db_change_field($ret, 'linkchecker_links', 'lid', 'lid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE));
|
||||||
|
if ($GLOBALS['db_type'] == 'pgsql') {
|
||||||
|
db_add_primary_key($ret, 'linkchecker_links', array('lid'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make linkchecker_boxes.bid and linkchecker_boxes.lid unsigned.
|
||||||
|
db_drop_primary_key($ret, 'linkchecker_boxes');
|
||||||
|
db_change_field($ret, 'linkchecker_boxes', 'bid', 'bid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
|
||||||
|
db_change_field($ret, 'linkchecker_boxes', 'lid', 'lid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
|
||||||
|
db_add_primary_key($ret, 'linkchecker_boxes', array('bid', 'lid'));
|
||||||
|
|
||||||
|
// Make linkchecker_comments.cid and linkchecker_comments.lid unsigned.
|
||||||
|
db_drop_primary_key($ret, 'linkchecker_comments');
|
||||||
|
db_change_field($ret, 'linkchecker_comments', 'cid', 'cid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
|
||||||
|
db_change_field($ret, 'linkchecker_comments', 'lid', 'lid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
|
||||||
|
db_add_primary_key($ret, 'linkchecker_comments', array('cid', 'lid'));
|
||||||
|
|
||||||
|
// Make linkchecker_nodes.nid and linkchecker_nodes.lid unsigned.
|
||||||
|
db_drop_primary_key($ret, 'linkchecker_nodes');
|
||||||
|
db_change_field($ret, 'linkchecker_nodes', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
|
||||||
|
db_change_field($ret, 'linkchecker_nodes', 'lid', 'lid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
|
||||||
|
db_add_primary_key($ret, 'linkchecker_nodes', array('nid', 'lid'));
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove any references to nodes that are not published and also remove their comments references.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6205() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
$ret[] = update_sql("DELETE FROM {linkchecker_nodes} WHERE nid IN (SELECT nid FROM {node} WHERE status = 0)");
|
||||||
|
$ret[] = update_sql("DELETE FROM {linkchecker_comments} WHERE cid IN (SELECT c.cid FROM {node} n INNER JOIN {comments} c ON c.nid = n.nid WHERE n.status = 0)");
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add status column to links table.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6206() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
// Add the column only if not exists. Column may been added in D5 (5207).
|
||||||
|
if (!db_column_exists('linkchecker_links', 'status')) {
|
||||||
|
db_add_field($ret, 'linkchecker_links', 'status', array('type' => 'int', 'not null' => TRUE, 'default' => 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove obsolete variable.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6207() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
variable_del('linkchecker_cleanup_links_interval');
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change default value for linkchecker_links.code to -1.
|
||||||
|
*
|
||||||
|
* fsockopen may return 0 as an indication that the error occurred before
|
||||||
|
* the connect() call. This is most likely due to a problem initializing the
|
||||||
|
* socket.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6208() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
db_change_field($ret, 'linkchecker_links', 'code', 'code', array('type' => 'int', 'not null' => TRUE, 'default' => -1));
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the permissions table, to reflect changes to hook_perm.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6209() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
$res = db_query('SELECT rid, perm FROM {permission}');
|
||||||
|
$perms = array();
|
||||||
|
while ($p = db_fetch_object($res)) {
|
||||||
|
$perm = $p->perm;
|
||||||
|
$perm = preg_replace('/access linkchecker/', 'access broken links report', $perm);
|
||||||
|
$perms[$p->rid] = $perm;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($perms as $rid => $renamed_permission) {
|
||||||
|
db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $renamed_permission, $rid);
|
||||||
|
$ret[] = array('success' => TRUE, 'query' => 'UPDATE {permission} SET perm = ' . check_plain($renamed_permission) . ' WHERE rid = '. $rid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add status code 302 to the default list of ignored response codes.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6210() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
$ignore_response_codes = preg_split('/(\r\n?|\n)/', variable_get('linkchecker_ignore_response_codes', "200\n302\n304\n401\n403"));
|
||||||
|
if (!in_array('302', $ignore_response_codes)) {
|
||||||
|
$ignore_response_codes[] = '302';
|
||||||
|
sort($ignore_response_codes);
|
||||||
|
variable_set('linkchecker_ignore_response_codes', implode("\n", $ignore_response_codes));
|
||||||
|
$ret[] = array('success' => TRUE, 'query' => 'Added the status code 302 to the list of ignored response codes.');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$ret[] = array('success' => TRUE, 'query' => 'No action taken. The status code 302 was already on the list of ignored response codes.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove obsolete variable.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6211() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
variable_del('linkchecker_pathfilter_support');
|
||||||
|
$ret[] = array('success' => TRUE, 'query' => 'Removed obsolete linkchecker_pathfilter_support variable.');
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change unique key and column name 'token' into 'urlhash'.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6212() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
db_drop_unique_key($ret, 'linkchecker_links', 'token');
|
||||||
|
db_change_field($ret, 'linkchecker_links', 'token', 'urlhash', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE));
|
||||||
|
db_add_unique_key($ret, 'linkchecker_links', 'urlhash', array('urlhash'));
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add RFC documenation domains back if they have been removed.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6213() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
$linkchecker_disable_link_check_for_urls = array_filter(preg_split('/(\r\n?|\n)/', variable_get('linkchecker_disable_link_check_for_urls', LINKCHECKER_RESERVED_DOCUMENTATION_DOMAINS)));
|
||||||
|
variable_set('linkchecker_disable_link_check_for_urls', implode("\n", array_unique(array_merge(explode("\n", LINKCHECKER_RESERVED_DOCUMENTATION_DOMAINS), $linkchecker_disable_link_check_for_urls))));
|
||||||
|
$ret[] = array('success' => TRUE, 'query' => 'Added RFC documenation domains back if they have been removed.');
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* #1321378: Improve performance of queries.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6214() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
db_add_index($ret, 'linkchecker_boxes', 'lid', array('lid'));
|
||||||
|
db_add_index($ret, 'linkchecker_comments', 'lid', array('lid'));
|
||||||
|
db_add_index($ret, 'linkchecker_nodes', 'lid', array('lid'));
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add status code 206 to the default list of ignored response codes.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6215() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
$ignore_response_codes = preg_split('/(\r\n?|\n)/', variable_get('linkchecker_ignore_response_codes', "200\n206\n302\n304\n401\n403"));
|
||||||
|
if (!in_array('206', $ignore_response_codes)) {
|
||||||
|
$ignore_response_codes[] = '206';
|
||||||
|
sort($ignore_response_codes);
|
||||||
|
variable_set('linkchecker_ignore_response_codes', implode("\n", $ignore_response_codes));
|
||||||
|
$ret[] = array('success' => TRUE, 'query' => 'Added the status code 206 to the list of ignored response codes.');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$ret[] = array('success' => TRUE, 'query' => 'No action taken. The status code 206 was already on the list of ignored response codes.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* #965720: Add indexes to improve performance of views queries.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6216() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
db_add_index($ret, 'linkchecker_links', 'method', array('method'));
|
||||||
|
db_add_index($ret, 'linkchecker_links', 'code', array('code'));
|
||||||
|
db_add_index($ret, 'linkchecker_links', 'fail_count', array('fail_count'));
|
||||||
|
db_add_index($ret, 'linkchecker_links', 'last_checked', array('last_checked'));
|
||||||
|
db_add_index($ret, 'linkchecker_links', 'status', array('status'));
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* #1450672: Set user 1 as default user to impersonate content updates.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6217() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
$linkchecker_default_impersonate_user = user_load(1);
|
||||||
|
variable_set('linkchecker_impersonate_user', $linkchecker_default_impersonate_user->name);
|
||||||
|
$ret[] = array('success' => TRUE, 'query' => 'Set user 1 as default user to impersonate content updates.');
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removed obsolete linkchecker_check_links_max variable.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6218() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
variable_del('linkchecker_check_links_max');
|
||||||
|
$ret[] = array('success' => TRUE, 'query' => 'Removed obsolete linkchecker_check_links_max variable.');
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade outdated HTTP user agents.
|
||||||
|
*/
|
||||||
|
function linkchecker_update_6219() {
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
$linkchecker_check_useragent = variable_get('linkchecker_check_useragent', 'Drupal (+http://drupal.org/)');
|
||||||
|
|
||||||
|
$useragent_upgrade = array(
|
||||||
|
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;)' => 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
|
||||||
|
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;)' => 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)',
|
||||||
|
'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0',
|
||||||
|
'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5' => 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0',
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isset($useragent_upgrade[$linkchecker_check_useragent])) {
|
||||||
|
variable_set('linkchecker_check_useragent', $useragent_upgrade[$linkchecker_check_useragent]);
|
||||||
|
$ret[] = array('success' => TRUE, 'query' => 'Upgraded outdated HTTP user agent.');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$ret[] = array('success' => TRUE, 'query' => 'User agent already up to date.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
1959
sites/all/modules/linkchecker/linkchecker.module
Normal file
1959
sites/all/modules/linkchecker/linkchecker.module
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,441 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Test file for Link checker module.
|
||||||
|
*/
|
||||||
|
class LinkCheckerLinkExtractionTest extends DrupalWebTestCase {
|
||||||
|
|
||||||
|
public static function getInfo() {
|
||||||
|
return array(
|
||||||
|
'name' => t('Link extraction tests'),
|
||||||
|
'description' => t('Test Link checker module link extraction functionality.'),
|
||||||
|
'group' => 'Link checker',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp('linkchecker', 'path');
|
||||||
|
|
||||||
|
$permissions = array(
|
||||||
|
'create page content',
|
||||||
|
'edit own page content',
|
||||||
|
'administer url aliases',
|
||||||
|
'create url aliases',
|
||||||
|
);
|
||||||
|
|
||||||
|
$user = $this->drupalCreateUser($permissions);
|
||||||
|
$this->drupalLogin($user);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLinkCheckerCreateNodeWithLinks() {
|
||||||
|
|
||||||
|
// Enable all node type page for link extraction.
|
||||||
|
variable_set('linkchecker_scan_nodetypes', array('page'));
|
||||||
|
variable_set('linkchecker_scan_blocks', 1);
|
||||||
|
|
||||||
|
// Core enables the URL filter for "Full HTML" by default.
|
||||||
|
// -> Blacklist / Disable URL filter for testing.
|
||||||
|
variable_set('linkchecker_filter_blacklist', array('filter/2'));
|
||||||
|
|
||||||
|
// Extract from all link checker supported HTML tags.
|
||||||
|
variable_set('linkchecker_extract_from_a', 1);
|
||||||
|
variable_set('linkchecker_extract_from_audio', 1);
|
||||||
|
variable_set('linkchecker_extract_from_embed', 1);
|
||||||
|
variable_set('linkchecker_extract_from_iframe', 1);
|
||||||
|
variable_set('linkchecker_extract_from_img', 1);
|
||||||
|
variable_set('linkchecker_extract_from_object', 1);
|
||||||
|
variable_set('linkchecker_extract_from_source', 1);
|
||||||
|
variable_set('linkchecker_extract_from_video', 1);
|
||||||
|
|
||||||
|
$body = <<<EOT
|
||||||
|
<!-- UNSUPPORTED for link checking: -->
|
||||||
|
|
||||||
|
<a href="mailto:test@example.com">Send email</a>
|
||||||
|
<a href="javascript:foo()">Execute JavaScript</a>
|
||||||
|
|
||||||
|
<!-- SUPPORTED for link checking: -->
|
||||||
|
|
||||||
|
<!-- URL in HTML comment: http://example.com/test-if-url-filter-is-disabled -->
|
||||||
|
|
||||||
|
<!-- Relative URLs -->
|
||||||
|
<img src="test.png" alt="Test image 1" />
|
||||||
|
<img src="../foo1/test.png" alt="Test image 2" />
|
||||||
|
|
||||||
|
<a href="../foo1/bar1">../foo1/bar1</a>
|
||||||
|
<a href="./foo2/bar2">./foo2/bar2</a>
|
||||||
|
<a href="../foo3/../foo4/foo5">../foo3/../foo4/foo5</a>
|
||||||
|
<a href="./foo4/../foo5/foo6">./foo4/../foo5/foo6</a>
|
||||||
|
<a href="./foo4/./foo5/foo6">./foo4/./foo5/foo6</a>
|
||||||
|
|
||||||
|
<!-- URL with uncommon chars that could potentially fail to extract. See http://drupal.org/node/465462. -->
|
||||||
|
<a href="http://www.lagrandeepicerie.fr/#e-boutique/Les_produits_du_moment,2/coffret_vins_doux_naturels,149">URL with uncommon chars</a>
|
||||||
|
|
||||||
|
<!-- object tag: Embed SWF files -->
|
||||||
|
<object width="150" height="116"
|
||||||
|
type="application/x-shockwave-flash"
|
||||||
|
data="http://wetterservice.msn.de/phclip.swf?zip=60329&ort=Frankfurt">
|
||||||
|
<param name="movie" value="http://wetterservice.msn.de/phclip.swf?zip=60329&ort=Frankfurt" />
|
||||||
|
<img src="flash.png" width="150" height="116" alt="" /> <br />
|
||||||
|
No weather report visible? At <a href="http://www.msn.de/">MSN</a>
|
||||||
|
you are able to find the weather report missing here and the
|
||||||
|
Flash plugin can be found at <a href="http://www.adobe.com/">Adobe</a>.
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<!-- object tag: Embed Quicktime Movies on HTML pages -->
|
||||||
|
<object width="420" height="282"
|
||||||
|
classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
|
||||||
|
codebase="http://www.apple.com/qtactivex/qtplugin.cab">
|
||||||
|
<param name="src" value="http://example.net/video/foo1.mov" />
|
||||||
|
<param name="href" value="http://example.net/video/foo2.mov" />
|
||||||
|
<param name="controller" value="true" />
|
||||||
|
<param name="autoplay" value="false" />
|
||||||
|
<param name="scale" value="aspect" />
|
||||||
|
<!--[if gte IE 7]> <!-->
|
||||||
|
<object type="video/quicktime" data="http://example.net/video/foo3.mov" width="420" height="282">
|
||||||
|
<param name="controller" value="true" />
|
||||||
|
<param name="autoplay" value="false" />
|
||||||
|
</object>
|
||||||
|
<!--<![endif]-->
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<!-- object tag: Play MP4 videos on HTML pages -->
|
||||||
|
<object data="http://example.org/video/foo1.mp4" type="video/mp4" width="420" height="288">
|
||||||
|
<param name="src" value="http://example.org/video/foo2.mp4" />
|
||||||
|
<param name="autoplay" value="false" />
|
||||||
|
<param name="autoStart" value="0" />
|
||||||
|
<a href="http://example.org/video/foo3.mp4">/video/foo3.mp4</a>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<!-- object tag: Play MP4 videos with Quicktime -->
|
||||||
|
<object width="420" height="282" codebase="http://www.apple.com/qtactivex/qtplugin.cab">
|
||||||
|
<param name="src" value="http://example.org/video/foo4.mp4" />
|
||||||
|
<param name="href" value="http://example.org/video/foo5.mp4" />
|
||||||
|
<param name="controller" value="true" />
|
||||||
|
<param name="autoplay" value="false" />
|
||||||
|
<param name="scale" value="aspect" />
|
||||||
|
<!--[if gte IE 7]> <!-->
|
||||||
|
<object type="video/quicktime" data="http://example.org/video/foo6.mp4" width="420" height="282">
|
||||||
|
<param name="controller" value="true" />
|
||||||
|
<param name="autoplay" value="false" />
|
||||||
|
</object>
|
||||||
|
<!--<![endif]-->
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<!-- object tag: Play flash videos on HTML pages -->
|
||||||
|
<object type="application/x-shockwave-flash" data="http://example.org/video/player1.swf" width="420" height="270">
|
||||||
|
<param name="movie" value="http://example.org/video/player2.swf" />
|
||||||
|
<param src="movie" value="http://example.org/video/player3.swf" />
|
||||||
|
<param name="flashvars" value="file=http://example.org/video/foo1.flv&width=420&height=270" />
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<!-- Embed ActiveX control as objekt -->
|
||||||
|
<object width="267" height="175" classid="CLSID:05589FA1-C356-11CE-BF01-00AA0055595A">
|
||||||
|
<param name="filename" value="ritmo.mid">
|
||||||
|
</object>
|
||||||
|
|
||||||
|
<!-- Add inline frames -->
|
||||||
|
<iframe src="http://example.com/iframe/" name="ExampleIFrame" width="300" height="200">
|
||||||
|
<p>Your browser does not support inline frames.</p>
|
||||||
|
</iframe>
|
||||||
|
|
||||||
|
<!-- https://developer.mozilla.org/en/Using_audio_and_video_in_Firefox -->
|
||||||
|
|
||||||
|
<!-- http://www.theora.org/cortado/ -->
|
||||||
|
<video src="my_ogg_video.ogg" controls width="320" height="240">
|
||||||
|
<object type="application/x-java-applet" width="320" height="240">
|
||||||
|
<param name="archive" value="http://www.theora.org/cortado.jar">
|
||||||
|
<param name="code" value="com.fluendo.player.Cortado.class">
|
||||||
|
<param name="url" value="my_ogg_video.ogg">
|
||||||
|
<p>You need to install Java to play this file.</p>
|
||||||
|
</object>
|
||||||
|
</video>
|
||||||
|
|
||||||
|
<video src="video.ogv" controls>
|
||||||
|
<object data="flvplayer1.swf" type="application/x-shockwave-flash">
|
||||||
|
<param name="movie" value="flvplayer2.swf" />
|
||||||
|
</object>
|
||||||
|
</video>
|
||||||
|
|
||||||
|
<video controls>
|
||||||
|
<source src="http://v2v.cc/~j/theora_testsuite/pixel_aspect_ratio.ogg" type="video/ogg">
|
||||||
|
<source src="http://v2v.cc/~j/theora_testsuite/pixel_aspect_ratio.mov">
|
||||||
|
Your browser does not support the <code>video</code> element.
|
||||||
|
</video>
|
||||||
|
|
||||||
|
<video controls>
|
||||||
|
<source src="foo.ogg" type="video/ogg; codecs="dirac, speex"">
|
||||||
|
Your browser does not support the <code>video</code> element.
|
||||||
|
</video>
|
||||||
|
|
||||||
|
<video src="http://v2v.cc/~j/theora_testsuite/320x240.ogg" controls>
|
||||||
|
Your browser does not support the <code>video</code> element.
|
||||||
|
</video>
|
||||||
|
EOT;
|
||||||
|
|
||||||
|
// Save folder names in variables for reuse.
|
||||||
|
$folder1 = $this->randomName(10);
|
||||||
|
$folder2 = $this->randomName(5);
|
||||||
|
|
||||||
|
// Allow the user to use the 'Full HTML' format.
|
||||||
|
db_query("UPDATE {filter_formats} SET roles = '%s' WHERE format = %d", ',2,', 2);
|
||||||
|
|
||||||
|
// Fill node array.
|
||||||
|
$edit = array();
|
||||||
|
$edit['title'] = $this->randomName(32);
|
||||||
|
$edit['body'] = $body;
|
||||||
|
$edit['path'] = $folder1 . '/' . $folder2;
|
||||||
|
$edit['format'] = 2;
|
||||||
|
|
||||||
|
// Extract only full qualified URLs.
|
||||||
|
variable_set('linkchecker_fqdn_only', 1);
|
||||||
|
|
||||||
|
// Verify path input field appears on add "Basic page" form.
|
||||||
|
$this->drupalGet('node/add/page');
|
||||||
|
// Verify path input is present.
|
||||||
|
$this->assertFieldByName('path', '', t('Path input field present on add Basic page form.'));
|
||||||
|
|
||||||
|
// Save node.
|
||||||
|
$this->drupalPost('node/add/page', $edit, t('Save'));
|
||||||
|
$this->assertRaw(t('@type %title has been created.', array('@type' => 'Page', '%title' => $edit['title'])), t('Node was created.'));
|
||||||
|
|
||||||
|
// Verify if the content links are extracted correctly.
|
||||||
|
$urls_fqdn = array(
|
||||||
|
'http://www.lagrandeepicerie.fr/#e-boutique/Les_produits_du_moment,2/coffret_vins_doux_naturels,149',
|
||||||
|
'http://wetterservice.msn.de/phclip.swf?zip=60329&ort=Frankfurt',
|
||||||
|
'http://www.msn.de/',
|
||||||
|
'http://www.adobe.com/',
|
||||||
|
'http://www.apple.com/qtactivex/qtplugin.cab',
|
||||||
|
'http://example.net/video/foo1.mov',
|
||||||
|
'http://example.net/video/foo2.mov',
|
||||||
|
'http://example.net/video/foo3.mov',
|
||||||
|
'http://example.org/video/foo1.mp4',
|
||||||
|
'http://example.org/video/foo2.mp4',
|
||||||
|
'http://example.org/video/foo3.mp4',
|
||||||
|
'http://example.org/video/foo4.mp4',
|
||||||
|
'http://example.org/video/foo5.mp4',
|
||||||
|
'http://example.org/video/foo6.mp4',
|
||||||
|
'http://example.org/video/player1.swf',
|
||||||
|
'http://example.org/video/player2.swf',
|
||||||
|
'http://example.org/video/player3.swf',
|
||||||
|
'http://example.com/iframe/',
|
||||||
|
'http://www.theora.org/cortado.jar',
|
||||||
|
'http://v2v.cc/~j/theora_testsuite/pixel_aspect_ratio.ogg',
|
||||||
|
'http://v2v.cc/~j/theora_testsuite/pixel_aspect_ratio.mov',
|
||||||
|
'http://v2v.cc/~j/theora_testsuite/320x240.ogg',
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($urls_fqdn as $org_url => $check_url) {
|
||||||
|
$link = $this->getLinkCheckerLink($check_url);
|
||||||
|
if ($link) {
|
||||||
|
$this->assertIdentical($link->url, $check_url, t('Absolute URL %org_url matches expected result %check_url.', array('%org_url' => $org_url, '%check_url' => $check_url)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->fail(t('URL %check_url not found.', array('%check_url' => $check_url)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the number of links is correct.
|
||||||
|
// - Verifies if all HTML tag regexes matched.
|
||||||
|
// - Verifies that the linkchecker filter blacklist works well.
|
||||||
|
$urls_in_database = $this->getLinkCheckerLinksCount();
|
||||||
|
$urls_expected_count = count($urls_fqdn);
|
||||||
|
$this->assertEqual($urls_in_database, $urls_expected_count, t('Found @urls_in_database URLs in database matches expected result of @urls_expected_count.', array('@urls_in_database' => $urls_in_database, '@urls_expected_count' => $urls_expected_count)));
|
||||||
|
|
||||||
|
// Extract all URLs including relative path.
|
||||||
|
variable_set('clean_url', 1);
|
||||||
|
variable_set('linkchecker_fqdn_only', 0);
|
||||||
|
|
||||||
|
$node = $this->drupalGetNodeByTitle($edit['title']);
|
||||||
|
$this->assertTrue($node, t('Node found in database.'));
|
||||||
|
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
||||||
|
$this->assertRaw(t('@type %title has been updated.', array('@type' => 'Page', '%title' => $edit['title'])));
|
||||||
|
|
||||||
|
// FIXME: Path alias seems not saved!???
|
||||||
|
// $this->assertIdentical($node->path, $edit['path'], t('URL alias "@node-path" matches path "@edit-path".', array('@node-path' => $node->path, '@edit-path' => $edit['path'])));
|
||||||
|
|
||||||
|
// DEBUG
|
||||||
|
$linkchecker_links = db_query("SELECT * FROM {linkchecker_links}");
|
||||||
|
while ($row = db_fetch_array($linkchecker_links)) {
|
||||||
|
$rows[] = $row['url'];
|
||||||
|
}
|
||||||
|
$this->verbose(theme_item_list($rows, 'URLs in database:'));
|
||||||
|
// $this->fail('DEBUG: ' .implode('<br />', $rows));
|
||||||
|
|
||||||
|
// Verify if the content links are extracted correctly.
|
||||||
|
global $base_root, $base_path;
|
||||||
|
$urls_relative = array(
|
||||||
|
'../foo1/test.png' => $base_root . $base_path . 'foo1/test.png',
|
||||||
|
'test.png' => $base_root . $base_path . $folder1 . '/test.png',
|
||||||
|
'../foo1/bar1' => $base_root . $base_path . 'foo1/bar1',
|
||||||
|
'./foo2/bar2' => $base_root . $base_path . $folder1 . '/foo2/bar2',
|
||||||
|
'../foo3/../foo4/foo5' => $base_root . $base_path . 'foo4/foo5',
|
||||||
|
'./foo4/../foo5/foo6' => $base_root . $base_path . $folder1 . '/foo5/foo6',
|
||||||
|
'./foo4/./foo5/foo6' => $base_root . $base_path . $folder1 . '/foo4/foo5/foo6',
|
||||||
|
'flash.png' => $base_root . $base_path . $folder1 . '/flash.png',
|
||||||
|
'ritmo.mid' => $base_root . $base_path . $folder1 . '/ritmo.mid',
|
||||||
|
'my_ogg_video.ogg' => $base_root . $base_path . $folder1 . '/my_ogg_video.ogg',
|
||||||
|
'video.ogv' => $base_root . $base_path . $folder1 . '/video.ogv',
|
||||||
|
'flvplayer1.swf' => $base_root . $base_path . $folder1 . '/flvplayer1.swf',
|
||||||
|
'flvplayer2.swf' => $base_root . $base_path . $folder1 . '/flvplayer2.swf',
|
||||||
|
'foo.ogg' => $base_root . $base_path . $folder1 . '/foo.ogg',
|
||||||
|
);
|
||||||
|
$this->verbose(theme_item_list($urls_relative, 'Verify if following relative URLs exists:'));
|
||||||
|
|
||||||
|
foreach ($urls_relative as $org_url => $check_url) {
|
||||||
|
$link = $this->getLinkCheckerLink($check_url);
|
||||||
|
if ($link) {
|
||||||
|
$this->assertIdentical($link->url, $check_url, t('Relative URL %org_url matches expected result %check_url.', array('%org_url' => $org_url, '%check_url' => $check_url)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->fail(t('URL %check_url not found.', array('%check_url' => $check_url)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the number of links is correct.
|
||||||
|
$urls_in_database = $this->getLinkCheckerLinksCount();
|
||||||
|
$urls_expected_count = count($urls_fqdn + $urls_relative);
|
||||||
|
$this->assertEqual($urls_in_database, $urls_expected_count, t('Found @urls_in_database URLs in database matches expected result of @urls_expected_count.', array('@urls_in_database' => $urls_in_database, '@urls_expected_count' => $urls_expected_count)));
|
||||||
|
|
||||||
|
|
||||||
|
// Verify if link check has been enabled for normal URLs.
|
||||||
|
$urls = array(
|
||||||
|
'http://www.lagrandeepicerie.fr/#e-boutique/Les_produits_du_moment,2/coffret_vins_doux_naturels,149',
|
||||||
|
'http://wetterservice.msn.de/phclip.swf?zip=60329&ort=Frankfurt',
|
||||||
|
'http://www.msn.de/',
|
||||||
|
'http://www.adobe.com/',
|
||||||
|
'http://www.apple.com/qtactivex/qtplugin.cab',
|
||||||
|
'http://www.theora.org/cortado.jar',
|
||||||
|
'http://v2v.cc/~j/theora_testsuite/pixel_aspect_ratio.ogg',
|
||||||
|
'http://v2v.cc/~j/theora_testsuite/pixel_aspect_ratio.mov',
|
||||||
|
'http://v2v.cc/~j/theora_testsuite/320x240.ogg',
|
||||||
|
$base_root . $base_path . 'foo1/test.png',
|
||||||
|
$base_root . $base_path . $folder1 . '/test.png',
|
||||||
|
$base_root . $base_path . 'foo1/bar1',
|
||||||
|
$base_root . $base_path . $folder1 . '/foo2/bar2',
|
||||||
|
$base_root . $base_path . 'foo4/foo5',
|
||||||
|
$base_root . $base_path . $folder1 . '/foo5/foo6',
|
||||||
|
$base_root . $base_path . $folder1 . '/foo4/foo5/foo6',
|
||||||
|
$base_root . $base_path . $folder1 . '/flash.png',
|
||||||
|
$base_root . $base_path . $folder1 . '/ritmo.mid',
|
||||||
|
$base_root . $base_path . $folder1 . '/my_ogg_video.ogg',
|
||||||
|
$base_root . $base_path . $folder1 . '/video.ogv',
|
||||||
|
$base_root . $base_path . $folder1 . '/flvplayer1.swf',
|
||||||
|
$base_root . $base_path . $folder1 . '/flvplayer2.swf',
|
||||||
|
$base_root . $base_path . $folder1 . '/foo.ogg',
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($urls as $url) {
|
||||||
|
$this->assertTrue($this->getLinkcheckerLink($url)->status, t('Link check for %url is enabled.', array('%url' => $url)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Verify if link check has been disabled for example.com/net/org URLs.
|
||||||
|
$documentation_urls = array(
|
||||||
|
'http://example.net/video/foo1.mov',
|
||||||
|
'http://example.net/video/foo2.mov',
|
||||||
|
'http://example.net/video/foo3.mov',
|
||||||
|
'http://example.org/video/foo1.mp4',
|
||||||
|
'http://example.org/video/foo2.mp4',
|
||||||
|
'http://example.org/video/foo3.mp4',
|
||||||
|
'http://example.org/video/foo4.mp4',
|
||||||
|
'http://example.org/video/foo5.mp4',
|
||||||
|
'http://example.org/video/foo6.mp4',
|
||||||
|
'http://example.org/video/player1.swf',
|
||||||
|
'http://example.org/video/player2.swf',
|
||||||
|
'http://example.org/video/player3.swf',
|
||||||
|
'http://example.com/iframe/',
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($documentation_urls as $documentation_url) {
|
||||||
|
$this->assertFalse($this->getLinkcheckerLink($documentation_url)->status, t('Link check for %url is disabled.', array('%url' => $documentation_url)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get linkchecker link by url.
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* URL of the link to find.
|
||||||
|
* @return object
|
||||||
|
* Link object.
|
||||||
|
*/
|
||||||
|
function getLinkCheckerLink($url) {
|
||||||
|
return db_fetch_object(db_query("SELECT * FROM {linkchecker_links} WHERE urlhash = '%s'", md5($url)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current number of links in linkchecker_links table.
|
||||||
|
*/
|
||||||
|
function getLinkCheckerLinksCount() {
|
||||||
|
return db_result(db_query("SELECT COUNT(1) FROM {linkchecker_links}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test case for impersonating users.
|
||||||
|
*
|
||||||
|
* Based on http://drupal.org/node/287292#comment-3162350
|
||||||
|
*/
|
||||||
|
class LinkCheckerUserImpersonatingUserTestCase extends DrupalWebTestCase {
|
||||||
|
|
||||||
|
public static function getInfo() {
|
||||||
|
return array(
|
||||||
|
'name' => 'Link checker impersonate users',
|
||||||
|
'description' => 'Temporarily impersonate another user, and then restore the original user.',
|
||||||
|
'group' => 'Link checker',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setUp() {
|
||||||
|
parent::setUp('linkchecker');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLinkCheckerImpersonateUser() {
|
||||||
|
global $user;
|
||||||
|
$original_user = $user;
|
||||||
|
|
||||||
|
// If not currently logged in, use linkchecker_impersonate_user() to switch to
|
||||||
|
// user 1. If logged in, switch to the anonymous user instead.
|
||||||
|
if (user_is_anonymous()) {
|
||||||
|
linkchecker_impersonate_user(1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
linkchecker_impersonate_user(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify that the active user has changed, and that session saving is
|
||||||
|
// disabled.
|
||||||
|
$this->assertEqual($user->uid, ($original_user->uid == 0 ? 1 : 0), t('User switched'));
|
||||||
|
$this->assertFalse(session_save_session(), t('Session saving is disabled.'));
|
||||||
|
|
||||||
|
// Perform a second (nested) impersonation.
|
||||||
|
linkchecker_impersonate_user(1);
|
||||||
|
$this->assertEqual($user->uid, 1, t('User switched.'));
|
||||||
|
|
||||||
|
// Revert to the user which was active between the first and second
|
||||||
|
// impersonation attempt.
|
||||||
|
linkchecker_revert_user();
|
||||||
|
|
||||||
|
// Since we are still impersonating the user from the first attempt,
|
||||||
|
// session handling still needs to be disabled.
|
||||||
|
$this->assertEqual($user->uid, ($original_user->uid == 0 ? 1 : 0), t('User switched.'));
|
||||||
|
$this->assertFalse(session_save_session(), t('Session saving is disabled.'));
|
||||||
|
|
||||||
|
// Revert to the original user which was active before the first
|
||||||
|
// impersonation attempt.
|
||||||
|
linkchecker_revert_user();
|
||||||
|
|
||||||
|
// Assert that the original user is the active user again, and that session
|
||||||
|
// saving has been re-enabled.
|
||||||
|
$this->assertEqual($user->uid, $original_user->uid, t('Original user successfully restored.'));
|
||||||
|
|
||||||
|
// Simpletest uses linkchecker_impersonate_user() too, revert the impersonation by
|
||||||
|
// Simpletest to enable session saving again. This is safe because calling
|
||||||
|
// linkchecker_revert_user() too often simply results in returning the active user.
|
||||||
|
linkchecker_revert_user();
|
||||||
|
$this->assertTrue(session_save_session(), t('Session saving is enabled.'));
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue