From 6e6e3617b7eb5b498cf90f43875e204c128178e7 Mon Sep 17 00:00:00 2001 From: Carl Alberto Date: Sun, 27 Oct 2019 22:45:21 +0800 Subject: [PATCH] updated to pass the initial plugin screen --- .DS_Store | Bin 0 -> 6148 bytes LICENSE | 339 +++++++++++++++ assets/css/admin.css | 1 + assets/css/admin.less | 0 assets/css/frontend.css | 1 + assets/css/frontend.less | 0 assets/js/admin.js | 11 + assets/js/admin.min.js | 1 + assets/js/frontend.js | 11 + assets/js/frontend.min.js | 1 + assets/js/settings.js | 96 +++++ assets/js/settings.min.js | 1 + .../class-tika-doc-pdf-indexer-functions.php | 283 ++++++++++++ .../class-tika-doc-pdf-indexer-settings.php | 330 ++++++++++++++ includes/class-tika-doc-pdf-indexer.php | 335 ++++++++++++++ .../class-tika-doc-pdf-indexer-admin-api.php | 356 +++++++++++++++ .../class-tika-doc-pdf-indexer-post-type.php | 202 +++++++++ index.php | 4 + lang/tika-doc-pdf-indexer.pot | 407 ++++++++++++++++++ readme.txt | 36 ++ tika-doc-pdf-indexer.php | 65 +++ uninstall.php | 16 + 22 files changed, 2496 insertions(+) create mode 100644 .DS_Store create mode 100644 LICENSE create mode 100644 assets/css/admin.css create mode 100644 assets/css/admin.less create mode 100644 assets/css/frontend.css create mode 100644 assets/css/frontend.less create mode 100644 assets/js/admin.js create mode 100644 assets/js/admin.min.js create mode 100644 assets/js/frontend.js create mode 100644 assets/js/frontend.min.js create mode 100644 assets/js/settings.js create mode 100644 assets/js/settings.min.js create mode 100644 includes/class-tika-doc-pdf-indexer-functions.php create mode 100644 includes/class-tika-doc-pdf-indexer-settings.php create mode 100644 includes/class-tika-doc-pdf-indexer.php create mode 100644 includes/lib/class-tika-doc-pdf-indexer-admin-api.php create mode 100644 includes/lib/class-tika-doc-pdf-indexer-post-type.php create mode 100644 index.php create mode 100644 lang/tika-doc-pdf-indexer.pot create mode 100644 readme.txt create mode 100644 tika-doc-pdf-indexer.php create mode 100644 uninstall.php diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f87f8dc189a1b91ca007aa026a160feb82f7cd47 GIT binary patch literal 6148 zcmeHK&2G~`5S~o~*hE4`;y|SyR^rf04&kRi+^o>{R0&j9?V&)h@rqco)|G#nLlnv4 z0eAqo()K}sci>5SW@dMTS_Q5ZMKjXuH=e(>KU=$A01(3_eGCu)fQL%h@p1TrP@Hr@ zI?h8VOpgXqP*5e4>UbfW9seQ&^zJ;!K*M{;;nMp{@*=_5MRJ^HRXrH|6rH8+t=o4z z|8CFk-Rt>pqH!^a>bP#IVO)-al_*P95|@WrT95aY-pl6M!|y@g|6dFtJ3tdJzgJXIxQx{qS0w(@?CRdzl!TI_VFHtN*Ydm&mRTL)9I7V z!CGIgtv{dj<#c0X(3j7iuFqz^=Pj@9?7eM1e)|07>*?9~x9_G51b($f?mL{r4>T57 zIf+W07y1Ln=5_OYMrME+U~%>(SyQ20)_@2n1O3$;1`y)V?h7_ literal 0 HcmV?d00001 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ecbc059 --- /dev/null +++ b/LICENSE @@ -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. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 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. + + , 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. \ No newline at end of file diff --git a/assets/css/admin.css b/assets/css/admin.css new file mode 100644 index 0000000..7203a73 --- /dev/null +++ b/assets/css/admin.css @@ -0,0 +1 @@ +/* phpcs:ignore */ \ No newline at end of file diff --git a/assets/css/admin.less b/assets/css/admin.less new file mode 100644 index 0000000..e69de29 diff --git a/assets/css/frontend.css b/assets/css/frontend.css new file mode 100644 index 0000000..7203a73 --- /dev/null +++ b/assets/css/frontend.css @@ -0,0 +1 @@ +/* phpcs:ignore */ \ No newline at end of file diff --git a/assets/css/frontend.less b/assets/css/frontend.less new file mode 100644 index 0000000..e69de29 diff --git a/assets/js/admin.js b/assets/js/admin.js new file mode 100644 index 0000000..09ef36f --- /dev/null +++ b/assets/js/admin.js @@ -0,0 +1,11 @@ +/** + * Plugin Template admin js. + * + * @package WordPress Plugin Template/JS + */ + +jQuery( document ).ready( + function ( e ) { + + } +); diff --git a/assets/js/admin.min.js b/assets/js/admin.min.js new file mode 100644 index 0000000..d3ad825 --- /dev/null +++ b/assets/js/admin.min.js @@ -0,0 +1 @@ +jQuery(document).ready(function(){}); \ No newline at end of file diff --git a/assets/js/frontend.js b/assets/js/frontend.js new file mode 100644 index 0000000..0d3ca93 --- /dev/null +++ b/assets/js/frontend.js @@ -0,0 +1,11 @@ +/** + * Plugin Template frontend js. + * + * @package WordPress Plugin Template/JS + */ + +jQuery( document ).ready( + function ( e ) { + + } +); diff --git a/assets/js/frontend.min.js b/assets/js/frontend.min.js new file mode 100644 index 0000000..d3ad825 --- /dev/null +++ b/assets/js/frontend.min.js @@ -0,0 +1 @@ +jQuery(document).ready(function(){}); \ No newline at end of file diff --git a/assets/js/settings.js b/assets/js/settings.js new file mode 100644 index 0000000..2529843 --- /dev/null +++ b/assets/js/settings.js @@ -0,0 +1,96 @@ +/** + * Plugin Template js settings. + * + * @package WordPress Plugin Template/Settings + */ + +jQuery( document ).ready( + function ($) { + + /***** Colour picker *****/ + + $( '.colorpicker' ).hide(); + $( '.colorpicker' ).each( + function () { + $( this ).farbtastic( $( this ).closest( '.color-picker' ).find( '.color' ) ); + } + ); + + $( '.color' ).click( + function () { + $( this ).closest( '.color-picker' ).find( '.colorpicker' ).fadeIn(); + } + ); + + $( document ).mousedown( + function () { + $( '.colorpicker' ).each( + function () { + var display = $( this ).css( 'display' ); + if (display == 'block') { + $( this ).fadeOut(); + } + } + ); + } + ); + + /***** Uploading images *****/ + + var file_frame; + + jQuery.fn.uploadMediaFile = function (button, preview_media) { + var button_id = button.attr( 'id' ); + var field_id = button_id.replace( '_button', '' ); + var preview_id = button_id.replace( '_button', '_preview' ); + + // If the media frame already exists, reopen it. + if (file_frame) { + file_frame.open(); + return; + } + + // Create the media frame. + file_frame = wp.media.frames.file_frame = wp.media( + { + title: jQuery( this ).data( 'uploader_title' ), + button: { + text: jQuery( this ).data( 'uploader_button_text' ), + }, + multiple: false + } + ); + + // When an image is selected, run a callback. + file_frame.on( + 'select', + function () { + attachment = file_frame.state().get( 'selection' ).first().toJSON(); + jQuery( "#" + field_id ).val( attachment.id ); + if (preview_media) { + jQuery( "#" + preview_id ).attr( 'src', attachment.sizes.thumbnail.url ); + } + file_frame = false; + } + ); + + // Finally, open the modal. + file_frame.open(); + } + + jQuery( '.image_upload_button' ).click( + function () { + jQuery.fn.uploadMediaFile( jQuery( this ), true ); + } + ); + + jQuery( '.image_delete_button' ).click( + function () { + jQuery( this ).closest( 'td' ).find( '.image_data_field' ).val( '' ); + jQuery( this ).closest( 'td' ).find( '.image_preview' ).remove(); + return false; + } + ); + + } +); diff --git a/assets/js/settings.min.js b/assets/js/settings.min.js new file mode 100644 index 0000000..f506a9c --- /dev/null +++ b/assets/js/settings.min.js @@ -0,0 +1 @@ +jQuery(document).ready(function(e){e(".colorpicker").hide();e(".colorpicker").each(function(){e(this).farbtastic(e(this).closest(".color-picker").find(".color"))});e(".color").click(function(){e(this).closest(".color-picker").find(".colorpicker").fadeIn()});e(document).mousedown(function(){e(".colorpicker").each(function(){var t=e(this).css("display");t=="block"&&e(this).fadeOut()})});var t;jQuery.fn.uploadMediaFile=function(e,n){var r=e.attr("id"),i=r.replace("_button",""),s=r.replace("_button","_preview");if(t){t.open();return}t=wp.media.frames.file_frame=wp.media({title:jQuery(this).data("uploader_title"),button:{text:jQuery(this).data("uploader_button_text")},multiple:!1});t.on("select",function(){attachment=t.state().get("selection").first().toJSON();jQuery("#"+i).val(attachment.id);n&&jQuery("#"+s).attr("src",attachment.sizes.thumbnail.url);t=!1});t.open()};jQuery(".image_upload_button").click(function(){jQuery.fn.uploadMediaFile(jQuery(this),!0)});jQuery(".image_delete_button").click(function(){jQuery(this).closest("td").find(".image_data_field").val("");jQuery(this).closest("td").find(".image_preview").remove();return!1})}); \ No newline at end of file diff --git a/includes/class-tika-doc-pdf-indexer-functions.php b/includes/class-tika-doc-pdf-indexer-functions.php new file mode 100644 index 0000000..519664e --- /dev/null +++ b/includes/class-tika-doc-pdf-indexer-functions.php @@ -0,0 +1,283 @@ + array( 'pipe', 'r' ), + 1 => array( 'pipe', 'w' ), + 2 => array( 'file', '/tmp/error-output.txt', 'a' ), + ); + // phpcs:disable -- Process handling by Tika + $process = proc_open( $command, $descriptorspec, $pipes ); + $file_data = ''; + while ( ! feof( $pipes[1] ) ) { + $file_data .= fgets( $pipes[1], 1024 ); + } + fclose( $pipes[1] ); + // phpcs:enable + + $return_value = proc_close( $process ); + $tika_data = $file_data; + set_time_limit( $og ); + + // Save metadata to parentid. + $parentid = wp_get_post_parent_id( $post_id ); + $my_post = array( + 'ID' => $parentid, + 'post_content' => $tika_data, + ); + wp_update_post( $my_post ); +} + +add_action( 'add_meta_boxes', 'tdpi_add_upload_file_metaboxes' ); + +/** + * Adds an upload metabox. + * + * @return void + */ +function tdpi_add_upload_file_metaboxes() { + add_meta_box( 'tdpi_file_upload', 'File Upload', 'tdpi_file_upload', 'tdpi_doc', 'normal', 'default' ); +} + +/** + * Restrict mimetypes on upload. + * + * @param [type] $mimes Returns the mimetypes. + * @return array Retuns the allowed mimetypes. + */ +function tdpi_restrict_mimetypes( $mimes ) { + $allowed = get_option( 'tdpi_supported_ext', array( 'pdf' ) ); + + $allowed_array = array(); + if ( in_array( 'pdf', $allowed, true ) ) { + $allowed_array[ 'pdf' ] = 'application/pdf'; + } + if ( in_array( 'txt', $allowed, true ) ) { + $allowed_array[ 'txt' ] = 'text/plain'; + } + if ( in_array( 'doc', $allowed, true ) ) { + $allowed_array[ 'doc' ] = 'application/msword'; + } + global $post_type; + if ( 'tdpi_doc' == $post_type ) { + $mimes = $allowed_array; + } + return $mimes; +} + +add_filter( 'upload_mimes', 'tdpi_restrict_mimetypes' ); + +/** + * Medua uplaoder metabox. + * + * @return void + */ +function tdpi_file_upload() { + global $post; + echo ''; + global $wpdb; + $filename = get_post_meta( $post->ID, $key = 'tdpi_file', true ); + $media_file = get_post_meta( $post->ID, $key = '_wp_attached_file', true ); + if ( ! empty( $media_file ) ) { + $filename = $media_file; + } ?> + + + +
+ + + + +
+ + +
+ +
+ ID; + } + } + + if ( ! current_user_can( 'edit_post', $post->ID ) ) { + return $post->ID; + } + + if ( isset( $_POST['tdpi_file'] ) ) { + $tika_meta['tdpi_file'] = sanitize_text_field( wp_unslash( $_POST['tdpi_file'] ) ); + + foreach ( $tika_meta as $key => $value ) { + if ( 'revision' === $post->post_type ) { + return; + } + $value = implode( ',', (array) $value ); + if ( get_post_meta( $post->ID, $key, false ) ) { + update_post_meta( $post->ID, $key, $value ); + } else { + add_post_meta( $post->ID, $key, $value ); + } + if ( ! $value ) { + delete_post_meta( $post->ID, $key ); + } + } + } +} +add_action( 'save_post', 'tdpi_save_tika_meta', 1, 2 ); + +// TODO: +// 1) convert to class +// cleanup code for metabox +// cleanup code tika meta +// load option file +// transfer tika meta from attachment to doc so it can be indexed +// eliminate notice +// restrict file uploads +// test solar if metas are now indexed +// Create a solr shortcode +// create solr block +// Extension must have at least one checked +// when uploading, media selection cannot choose other accepted file extension +// eliminate unneecessary functions +// on upload existing file, attach data. +// make the upload file required +// default to upload and restric from selcting uploaded file or the recent file should be indexed \ No newline at end of file diff --git a/includes/class-tika-doc-pdf-indexer-settings.php b/includes/class-tika-doc-pdf-indexer-settings.php new file mode 100644 index 0000000..ce5dbfa --- /dev/null +++ b/includes/class-tika-doc-pdf-indexer-settings.php @@ -0,0 +1,330 @@ +parent = $parent; + + $this->base = 'tdpi_'; + + // Initialise settings. + add_action( 'init', array( $this, 'init_settings' ), 11 ); + + // Register plugin settings. + add_action( 'admin_init', array( $this, 'register_settings' ) ); + + // Add settings page to menu. + add_action( 'admin_menu', array( $this, 'add_menu_item' ) ); + + // Add settings link to plugins page. + add_filter( 'plugin_action_links_' . plugin_basename( $this->parent->file ), array( $this, 'add_settings_link' ) ); + } + + /** + * Initialise settings + * + * @return void + */ + public function init_settings() { + $this->settings = $this->settings_fields(); + } + + /** + * Add settings page to admin menu + * + * @return void + */ + public function add_menu_item() { + $page = add_options_page( __( 'Tika Indexer Settings', 'tika-doc-pdf-indexer' ), __( 'Tika Indexer Settings', 'tika-doc-pdf-indexer' ), 'manage_options', $this->parent->_token . '_settings', array( $this, 'settings_page' ) ); + add_action( 'admin_print_styles-' . $page, array( $this, 'settings_assets' ) ); + } + + /** + * Load settings JS & CSS + * + * @return void + */ + public function settings_assets() { + + // We're including the farbtastic script & styles here because they're needed for the colour picker + // If you're not including a colour picker field then you can leave these calls out as well as the farbtastic dependency for the wpt-admin-js script below. + wp_enqueue_style( 'farbtastic' ); + wp_enqueue_script( 'farbtastic' ); + + // We're including the WP media scripts here because they're needed for the image upload field. + // If you're not including an image upload then you can leave this function call out. + wp_enqueue_media(); + + wp_register_script( $this->parent->_token . '-settings-js', $this->parent->assets_url . 'js/settings' . $this->parent->script_suffix . '.js', array( 'farbtastic', 'jquery' ), '1.0.0', true ); + wp_enqueue_script( $this->parent->_token . '-settings-js' ); + } + + /** + * Add settings link to plugin list table + * + * @param array $links Existing links. + * @return array Modified links. + */ + public function add_settings_link( $links ) { + $settings_link = '' . __( 'Settings', 'tika-doc-pdf-indexer' ) . ''; + array_push( $links, $settings_link ); + return $links; + } + + /** + * Build settings fields + * + * @return array Fields to be displayed on settings page + */ + private function settings_fields() { + + $settings['standard'] = array( + 'description' => __( 'Essential settings that will make the PDF Doc Indexer will work.', 'tika-doc-pdf-indexer' ), + 'fields' => array( + array( + 'id' => 'java_location', + 'label' => __( 'Java binaries location', 'tika-doc-pdf-indexer' ), + 'description' => __( 'This is where the java binary is located relative to server root eg. /usr/bin/java', 'tika-doc-pdf-indexer' ), + 'type' => 'text', + 'default' => '/usr/bin/java', + 'placeholder' => __( '/usr/bin/java', 'tika-doc-pdf-indexer' ), + ), + array( + 'id' => 'tika_jar_location', + 'label' => __( 'Tika jar file location', 'tika-doc-pdf-indexer' ), + 'description' => __( 'This is where the jar file location relative to server root eg. /srv/bin/tika-app-1.18.jar', 'tika-doc-pdf-indexer' ), + 'type' => 'text', + 'default' => '/srv/bin/tika-app-1.18.jar', + 'placeholder' => __( '/srv/bin/tika-app-1.18.jar', 'tika-doc-pdf-indexer' ), + ), + array( + 'id' => 'tika_wp_content', + 'label' => __( 'wp-content location override', 'tika-doc-pdf-indexer' ), + 'description' => __( 'Modify this if the wp-content folder is in a non standard location other than /wp-content/', 'tika-doc-pdf-indexer' ), + 'type' => 'text', + 'default' => '/wp-content/', + 'placeholder' => __( '/wp-content/', 'tika-doc-pdf-indexer' ), + ), + array( + 'id' => 'supported_ext', + 'label' => __( 'Supported Extensions', 'tika-doc-pdf-indexer' ), + 'description' => __( 'You can select multiple suported file types.', 'tika-doc-pdf-indexer' ), + 'type' => 'select_multi', + 'options' => array( + 'pdf' => 'PDF', + 'doc' => 'Doc', + 'txt' => 'Text', + ), + 'default' => array( 'pdf' ), + ), + array( + 'id' => 'php_timeout_override', + 'label' => __( 'PHP execution timeout override', 'tika-doc-pdf-indexer' ), + 'description' => __( 'This is the php execution timeout, depends on the server if this can be overridden. Consult with your host. Default is 60 seconds', 'tika-doc-pdf-indexer' ), + 'type' => 'text', + 'default' => '60', + 'placeholder' => __( '60 seconds', 'tika-doc-pdf-indexer' ), + ), + ), + ); + + $settings = apply_filters( $this->parent->_token . '_settings_fields', $settings ); + + return $settings; + } + + /** + * Register plugin settings + * + * @return void + */ + public function register_settings() { + if ( is_array( $this->settings ) ) { + + // Check posted/selected tab. + //phpcs:disable + $current_section = ''; + if ( isset( $_POST['tab'] ) && $_POST['tab'] ) { + $current_section = $_POST['tab']; + } else { + if ( isset( $_GET['tab'] ) && $_GET['tab'] ) { + $current_section = $_GET['tab']; + } + } + //phpcs:enable + + foreach ( $this->settings as $section => $data ) { + + if ( $current_section && $current_section !== $section ) { + continue; + } + + // Add section to page. + $data['title'] = ''; + add_settings_section( $section, $data['title'], array( $this, 'settings_section' ), $this->parent->_token . '_settings' ); + + foreach ( $data['fields'] as $field ) { + + // Validation callback for field. + $validation = ''; + if ( isset( $field['callback'] ) ) { + $validation = $field['callback']; + } + + // Register field. + $option_name = $this->base . $field['id']; + register_setting( $this->parent->_token . '_settings', $option_name, $validation ); + + // Add field to page. + add_settings_field( + $field['id'], + $field['label'], + array( $this->parent->admin, 'display_field' ), + $this->parent->_token . '_settings', + $section, + array( + 'field' => $field, + 'prefix' => $this->base, + ) + ); + } + + if ( ! $current_section ) { + break; + } + } + } + } + + /** + * Settings section. + * + * @param array $section Array of section ids. + * @return void + */ + public function settings_section( $section ) { + $html = '

' . $this->settings[ $section['id'] ]['description'] . '

' . "\n"; + echo $html; //phpcs:ignore + } + + /** + * Load settings page content. + * + * @return void + */ + public function settings_page() { + + // Build page HTML. + $html = '
' . "\n"; + $html .= '

' . __( 'Tika Doc PDF Indexer Settings', 'tika-doc-pdf-indexer' ) . '

' . "\n"; + + $tab = ''; + + $html .= '
' . "\n"; + + // Get settings fields. + ob_start(); + settings_fields( $this->parent->_token . '_settings' ); + do_settings_sections( $this->parent->_token . '_settings' ); + $html .= ob_get_clean(); + + $html .= '

' . "\n"; + $html .= '' . "\n"; + $html .= '' . "\n"; + $html .= '

' . "\n"; + $html .= '
' . "\n"; + $html .= '
' . "\n"; + + echo $html; //phpcs:ignore + } + + /** + * Main Tika_Doc_PDF_Indexer_Settings Instance + * + * Ensures only one instance of Tika_Doc_PDF_Indexer_Settings is loaded or can be loaded. + * + * @since 1.0.0 + * @static + * @see Tika_Doc_PDF_Indexer() + * @param object $parent Object instance. + * @return Main Tika_Doc_PDF_Indexer_Settings instance + */ + public static function instance( $parent ) { + if ( is_null( self::$_instance ) ) { + self::$_instance = new self( $parent ); + } + return self::$_instance; + } // End instance() + + /** + * Cloning is forbidden. + * + * @since 1.0.0 + */ + public function __clone() { + _doing_it_wrong( __FUNCTION__, esc_html( __( 'Cheatin’ huh?' ), $this->parent->_version ) ); + } // End __clone() + + /** + * Unserializing instances of this class is forbidden. + * + * @since 1.0.0 + */ + public function __wakeup() { + _doing_it_wrong( __FUNCTION__, esc_html( __( 'Cheatin’ huh?' ), $this->parent->_version ) ); + } // End __wakeup() + +} diff --git a/includes/class-tika-doc-pdf-indexer.php b/includes/class-tika-doc-pdf-indexer.php new file mode 100644 index 0000000..8b84d43 --- /dev/null +++ b/includes/class-tika-doc-pdf-indexer.php @@ -0,0 +1,335 @@ +_token . '-frontend', esc_url( $this->assets_url ) . 'css/frontend.css', array(), $this->_version ); + wp_enqueue_style( $this->_token . '-frontend' ); + } // End enqueue_styles () + + /** + * Load frontend Javascript. + * + * @access public + * @since 1.0.0 + * @return void + */ + public function enqueue_scripts() { + wp_register_script( $this->_token . '-frontend', esc_url( $this->assets_url ) . 'js/frontend' . $this->script_suffix . '.js', array( 'jquery' ), $this->_version, true ); + wp_enqueue_script( $this->_token . '-frontend' ); + } // End enqueue_scripts () + + /** + * Admin enqueue style. + * + * @param string $hook Hook parameter. + * @return void + */ + public function admin_enqueue_styles( $hook = '' ) { + wp_register_style( $this->_token . '-admin', esc_url( $this->assets_url ) . 'css/admin.css', array(), $this->_version ); + wp_enqueue_style( $this->_token . '-admin' ); + } // End admin_enqueue_styles () + + /** + * Load admin Javascript. + * + * @access public + * @param string $hook Hook parameter. + * @since 1.0.0 + * @return void + */ + public function admin_enqueue_scripts( $hook = '' ) { + wp_register_script( $this->_token . '-admin', esc_url( $this->assets_url ) . 'js/admin' . $this->script_suffix . '.js', array( 'jquery' ), $this->_version, true ); + wp_enqueue_script( $this->_token . '-admin' ); + } // End admin_enqueue_scripts () + + /** + * Load plugin localisation + * + * @access public + * @since 1.0.0 + * @return void + */ + public function load_localisation() { + load_plugin_textdomain( 'tika-doc-pdf-indexer', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); + } // End load_localisation () + + /** + * Load plugin textdomain + * + * @access public + * @since 1.0.0 + * @return void + */ + public function load_plugin_textdomain() { + $domain = 'tika-doc-pdf-indexer'; + + $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); + + load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); + load_plugin_textdomain( $domain, false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); + } // End load_plugin_textdomain () + + /** + * Main Tika_Doc_PDF_Indexer Instance + * + * Ensures only one instance of Tika_Doc_PDF_Indexer is loaded or can be loaded. + * + * @since 1.0.0 + * @static + * @param string $file File instance. + * @param string $version Version parameter. + * @see Tika_Doc_PDF_Indexer() + * @return Main Tika_Doc_PDF_Indexer instance + */ + public static function instance( $file = '', $version = '1.0.0' ) { + if ( is_null( self::$_instance ) ) { + self::$_instance = new self( $file, $version ); + } + return self::$_instance; + } // End instance () + + /** + * Cloning is forbidden. + * + * @since 1.0.0 + */ + public function __clone() { + _doing_it_wrong( __FUNCTION__, esc_html( __( 'Cheatin’ huh?' ), $this->parent->_version ) ); + } // End __clone () + + /** + * Unserializing instances of this class is forbidden. + * + * @since 1.0.0 + */ + public function __wakeup() { + _doing_it_wrong( __FUNCTION__, esc_html( __( 'Cheatin’ huh?' ), $this->parent->_version ) ); + } // End __wakeup () + + /** + * Installation. Runs on activation. + * + * @access public + * @since 1.0.0 + * @return void + */ + public function install() { + $this->_log_version_number(); + } // End install () + + /** + * Log the plugin version number. + * + * @access public + * @since 1.0.0 + * @return void + */ + private function _log_version_number() { //phpcs:ignore + update_option( $this->_token . '_version', $this->_version ); + } // End _log_version_number () + + public function register_doc_postype() { + $options = array( + 'menu_icon' => 'dashicons-media-document', + 'supports' => array( 'title', 'thumbnail' ), + ); + $description = ''; + + $this->register_post_type( + 'tdpi_doc', + __( 'Documents', 'tika-doc-pdf-indexer' ), + __( 'Document', 'tika-doc-pdf-indexer' ), + $description, + $options + ); + } + + /** + * Constructor funtion. + * + * @param string $file File constructor. + * @param string $version Plugin version. + */ + public function __construct( $file = '', $version = '1.0.0' ) { + $this->_version = $version; + $this->_token = 'tika_doc_pdf_indexer'; + + // Load plugin environment variables. + $this->file = $file; + $this->dir = dirname( $this->file ); + $this->assets_dir = trailingslashit( $this->dir ) . 'assets'; + $this->assets_url = esc_url( trailingslashit( plugins_url( '/assets/', $this->file ) ) ); + + $this->script_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + + register_activation_hook( $this->file, array( $this, 'install' ) ); + + // Load frontend JS & CSS. + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ), 10 ); + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 10 ); + + // Load admin JS & CSS. + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 10, 1 ); + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_styles' ), 10, 1 ); + + + // Load API for generic admin functions. + if ( is_admin() ) { + $this->admin = new Tika_Doc_PDF_Indexer_Admin_API(); + } + + $this->register_doc_postype(); + + // Handle localisation. + $this->load_plugin_textdomain(); + add_action( 'init', array( $this, 'load_localisation' ), 0 ); + } // End __construct () + +} + + + diff --git a/includes/lib/class-tika-doc-pdf-indexer-admin-api.php b/includes/lib/class-tika-doc-pdf-indexer-admin-api.php new file mode 100644 index 0000000..717bd36 --- /dev/null +++ b/includes/lib/class-tika-doc-pdf-indexer-admin-api.php @@ -0,0 +1,356 @@ +ID, $field['id'], true ); + + // Get data to display in field. + if ( isset( $option ) ) { + $data = $option; + } + } else { + + // Get saved option. + $option_name .= $field['id']; + $option = get_option( $option_name ); + + // Get data to display in field. + if ( isset( $option ) ) { + $data = $option; + } + } + + // Show default data if no option saved and default is supplied. + if ( false === $data && isset( $field['default'] ) ) { + $data = $field['default']; + } elseif ( false === $data ) { + $data = ''; + } + + $html = ''; + + switch ( $field['type'] ) { + + case 'text': + case 'url': + case 'email': + $html .= '' . "\n"; + break; + + case 'password': + case 'number': + case 'hidden': + $min = ''; + if ( isset( $field['min'] ) ) { + $min = ' min="' . esc_attr( $field['min'] ) . '"'; + } + + $max = ''; + if ( isset( $field['max'] ) ) { + $max = ' max="' . esc_attr( $field['max'] ) . '"'; + } + $html .= '' . "\n"; + break; + + case 'text_secret': + $html .= '' . "\n"; + break; + + case 'textarea': + $html .= '
' . "\n"; + break; + + case 'checkbox': + $checked = ''; + if ( $data && 'on' === $data ) { + $checked = 'checked="checked"'; + } + $html .= '' . "\n"; + break; + + case 'checkbox_multi': + foreach ( $field['options'] as $k => $v ) { + $checked = false; + if ( in_array( $k, (array) $data, true ) ) { + $checked = true; + } + $html .= '

'; + } + break; + + case 'radio': + foreach ( $field['options'] as $k => $v ) { + $checked = false; + if ( $k === $data ) { + $checked = true; + } + $html .= ' '; + } + break; + + case 'select': + $html .= ' '; + break; + + case 'select_multi': + $html .= ' '; + break; + + case 'image': + $image_thumb = ''; + if ( $data ) { + $image_thumb = wp_get_attachment_thumb_url( $data ); + } + $html .= '
' . "\n"; + $html .= '' . "\n"; + $html .= '' . "\n"; + $html .= '
' . "\n"; + break; + + case 'color': + //phpcs:disable + ?>
+ +
+
+ $option_name, + ) + ); + break; + + } + + switch ( $field['type'] ) { + + case 'checkbox_multi': + case 'radio': + case 'select_multi': + $html .= '
' . $field['description'] . ''; + break; + + default: + if ( ! $post ) { + $html .= '' . "\n"; + } + break; + } + + if ( ! $echo ) { + return $html; + } + + echo $html; //phpcs:ignore + + } + + /** + * Validate form field + * + * @param string $data Submitted value. + * @param string $type Type of field to validate. + * @return string Validated value + */ + public function validate_field( $data = '', $type = 'text' ) { + + switch ( $type ) { + case 'text': + $data = esc_attr( $data ); + break; + case 'url': + $data = esc_url( $data ); + break; + case 'email': + $data = is_email( $data ); + break; + } + + return $data; + } + + /** + * Add meta box to the dashboard. + * + * @param string $id Unique ID for metabox. + * @param string $title Display title of metabox. + * @param array $post_types Post types to which this metabox applies. + * @param string $context Context in which to display this metabox ('advanced' or 'side'). + * @param string $priority Priority of this metabox ('default', 'low' or 'high'). + * @param array $callback_args Any axtra arguments that will be passed to the display function for this metabox. + * @return void + */ + public function add_meta_box( $id = '', $title = '', $post_types = array(), $context = 'advanced', $priority = 'default', $callback_args = null ) { + + // Get post type(s). + if ( ! is_array( $post_types ) ) { + $post_types = array( $post_types ); + } + + // Generate each metabox. + foreach ( $post_types as $post_type ) { + add_meta_box( $id, $title, array( $this, 'meta_box_content' ), $post_type, $context, $priority, $callback_args ); + } + } + + /** + * Display metabox content + * + * @param object $post Post object. + * @param array $args Arguments unique to this metabox. + * @return void + */ + public function meta_box_content( $post, $args ) { + + $fields = apply_filters( $post->post_type . '_custom_fields', array(), $post->post_type ); + + if ( ! is_array( $fields ) || 0 === count( $fields ) ) { + return; + } + + echo '
' . "\n"; + + foreach ( $fields as $field ) { + + if ( ! isset( $field['metabox'] ) ) { + continue; + } + + if ( ! is_array( $field['metabox'] ) ) { + $field['metabox'] = array( $field['metabox'] ); + } + + if ( in_array( $args['id'], $field['metabox'], true ) ) { + $this->display_meta_box_field( $field, $post ); + } + } + + echo '
' . "\n"; + + } + + /** + * Dispay field in metabox + * + * @param array $field Field data. + * @param object $post Post object. + * @return void + */ + public function display_meta_box_field( $field = array(), $post ) { + + if ( ! is_array( $field ) || 0 === count( $field ) ) { + return; + } + + $field = '

' . $this->display_field( $field, $post, false ) . '

' . "\n"; + + echo $field; //phpcs:ignore + } + + /** + * Save metabox fields. + * + * @param integer $post_id Post ID. + * @return void + */ + public function save_meta_boxes( $post_id = 0 ) { + + if ( ! $post_id ) { + return; + } + + $post_type = get_post_type( $post_id ); + + $fields = apply_filters( $post_type . '_custom_fields', array(), $post_type ); + + if ( ! is_array( $fields ) || 0 === count( $fields ) ) { + return; + } + + foreach ( $fields as $field ) { + if ( isset( $_REQUEST[ $field['id'] ] ) ) { //phpcs:ignore + update_post_meta( $post_id, $field['id'], $this->validate_field( $_REQUEST[ $field['id'] ], $field['type'] ) ); //phpcs:ignore + } else { + update_post_meta( $post_id, $field['id'], '' ); + } + } + } + +} diff --git a/includes/lib/class-tika-doc-pdf-indexer-post-type.php b/includes/lib/class-tika-doc-pdf-indexer-post-type.php new file mode 100644 index 0000000..e877230 --- /dev/null +++ b/includes/lib/class-tika-doc-pdf-indexer-post-type.php @@ -0,0 +1,202 @@ +post_type = $post_type; + $this->plural = $plural; + $this->single = $single; + $this->description = $description; + $this->options = $options; + + // Regsiter post type. + add_action( 'init', array( $this, 'register_post_type' ) ); + + // Display custom update messages for posts edits. + add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); + add_filter( 'bulk_post_updated_messages', array( $this, 'bulk_updated_messages' ), 10, 2 ); + } + + /** + * Register new post type + * + * @return void + */ + public function register_post_type() { + //phpcs:disable + $labels = array( + 'name' => $this->plural, + 'singular_name' => $this->single, + 'name_admin_bar' => $this->single, + 'add_new' => _x( 'Add New', $this->post_type, 'tika-doc-pdf-indexer' ), + /* translators: %s: Post type name */ + 'add_new_item' => sprintf( __( 'Add New %s', 'tika-doc-pdf-indexer' ), $this->single ), + /* translators: %s: Post type name */ + 'edit_item' => sprintf( __( 'Edit %s', 'tika-doc-pdf-indexer' ), $this->single ), + /* translators: %s: Post type name */ + 'new_item' => sprintf( __( 'New %s', 'tika-doc-pdf-indexer' ), $this->single ), + /* translators: %s: Post type name */ + 'all_items' => sprintf( __( 'All %s', 'tika-doc-pdf-indexer' ), $this->plural ), + /* translators: %s: Post type name */ + 'view_item' => sprintf( __( 'View %s', 'tika-doc-pdf-indexer' ), $this->single ), + /* translators: %s: Post type name */ + 'search_items' => sprintf( __( 'Search %s', 'tika-doc-pdf-indexer' ), $this->plural ), + /* translators: %s: Post type name */ + 'not_found' => sprintf( __( 'No %s Found', 'tika-doc-pdf-indexer' ), $this->plural ), + /* translators: %s: Post type name */ + 'not_found_in_trash' => sprintf( __( 'No %s Found In Trash', 'tika-doc-pdf-indexer' ), $this->plural ), + /* translators: %s: Post type name */ + 'parent_item_colon' => sprintf( __( 'Parent %s' ), $this->single ), + 'menu_name' => $this->plural, + ); + //phpcs:enable + + $args = array( + 'labels' => apply_filters( $this->post_type . '_labels', $labels ), + 'description' => $this->description, + 'public' => true, + 'publicly_queryable' => true, + 'exclude_from_search' => false, + 'show_ui' => true, + 'show_in_menu' => true, + 'show_in_nav_menus' => true, + 'query_var' => true, + 'can_export' => true, + 'rewrite' => true, + 'capability_type' => 'post', + 'has_archive' => true, + 'hierarchical' => true, + 'show_in_rest' => true, + 'rest_base' => $this->post_type, + 'rest_controller_class' => 'WP_REST_Posts_Controller', + 'supports' => array( 'title', 'editor', 'excerpt', 'comments', 'thumbnail' ), + 'menu_position' => 5, + 'menu_icon' => 'dashicons-admin-post', + ); + + $args = array_merge( $args, $this->options ); + + register_post_type( $this->post_type, apply_filters( $this->post_type . '_register_args', $args, $this->post_type ) ); + } + + /** + * Set up admin messages for post type + * + * @param array $messages Default message. + * @return array Modified messages. + */ + public function updated_messages( $messages = array() ) { + global $post, $post_ID; + //phpcs:disable + $messages[ $this->post_type ] = array( + 0 => '', + 1 => sprintf( __( '%1$s updated. %2$sView %3$s%4$s.', 'tika-doc-pdf-indexer' ), $this->single, '', $this->single, '' ), + 2 => __( 'Custom field updated.', 'tika-doc-pdf-indexer' ), + 3 => __( 'Custom field deleted.', 'tika-doc-pdf-indexer' ), + 4 => sprintf( __( '%1$s updated.', 'tika-doc-pdf-indexer' ), $this->single ), + 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s.', 'tika-doc-pdf-indexer' ), $this->single, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, + 6 => sprintf( __( '%1$s published. %2$sView %3$s%4$s.', 'tika-doc-pdf-indexer' ), $this->single, '', $this->single, '' ), + 7 => sprintf( __( '%1$s saved.', 'tika-doc-pdf-indexer' ), $this->single ), + 8 => sprintf( __( '%1$s submitted. %2$sPreview post%3$s%4$s.', 'tika-doc-pdf-indexer' ), $this->single, '', $this->single, '' ), + 9 => sprintf( __( '%1$s scheduled for: %2$s. %3$sPreview %4$s%5$s.', 'tika-doc-pdf-indexer' ), $this->single, '' . date_i18n( __( 'M j, Y @ G:i', 'tika-doc-pdf-indexer' ), strtotime( $post->post_date ) ) . '', '', $this->single, '' ), + 10 => sprintf( __( '%1$s draft updated. %2$sPreview %3$s%4$s.', 'tika-doc-pdf-indexer' ), $this->single, '', $this->single, '' ), + ); + //phpcs:enable + + return $messages; + } + + /** + * Set up bulk admin messages for post type + * + * @param array $bulk_messages Default bulk messages. + * @param array $bulk_counts Counts of selected posts in each status. + * @return array Modified messages. + */ + public function bulk_updated_messages( $bulk_messages = array(), $bulk_counts = array() ) { + + $bulk_messages[ $this->post_type ] = array( + //phpcs:disable + 'updated' => sprintf( _n( '%1$s %2$s updated.', '%1$s %3$s updated.', $bulk_counts['updated'], 'tika-doc-pdf-indexer' ), $bulk_counts['updated'], $this->single, $this->plural ), + 'locked' => sprintf( _n( '%1$s %2$s not updated, somebody is editing it.', '%1$s %3$s not updated, somebody is editing them.', $bulk_counts['locked'], 'tika-doc-pdf-indexer' ), $bulk_counts['locked'], $this->single, $this->plural ), + 'deleted' => sprintf( _n( '%1$s %2$s permanently deleted.', '%1$s %3$s permanently deleted.', $bulk_counts['deleted'], 'tika-doc-pdf-indexer' ), $bulk_counts['deleted'], $this->single, $this->plural ), + 'trashed' => sprintf( _n( '%1$s %2$s moved to the Trash.', '%1$s %3$s moved to the Trash.', $bulk_counts['trashed'], 'tika-doc-pdf-indexer' ), $bulk_counts['trashed'], $this->single, $this->plural ), + 'untrashed' => sprintf( _n( '%1$s %2$s restored from the Trash.', '%1$s %3$s restored from the Trash.', $bulk_counts['untrashed'], 'tika-doc-pdf-indexer' ), $bulk_counts['untrashed'], $this->single, $this->plural ), + ); + + return $bulk_messages; + } + +} diff --git a/index.php b/index.php new file mode 100644 index 0000000..bf3e6cb --- /dev/null +++ b/index.php @@ -0,0 +1,4 @@ +\n" +"Language-Team: LANGUAGE \n" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:52 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:42 +msgctxt "post type general name" +msgid "Post Type" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:53 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:43 +msgctxt "post type singular name" +msgid "Post Type" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:55 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:45 +msgid "Add New %s" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:55 +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:56 +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:57 +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:59 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:45 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:46 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:47 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:49 +msgid "Post" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:56 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:46 +msgid "Edit %s" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:57 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:47 +msgid "New %s" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:58 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:48 +msgid "All %s" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:58 +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:60 +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:61 +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:62 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:48 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:50 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:51 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:52 +msgid "Posts" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:59 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:49 +msgid "View %s" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:60 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:50 +msgid "Search %a" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:61 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:51 +msgid "No %s Found" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:62 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:52 +msgid "No %s Found In Trash" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:64 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:54 +msgid "*Posts" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:95 +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:105 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:85 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:95 +msgid "Terms" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:96 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:86 +msgid "Term" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:97 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:87 +msgid "Search Terms" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:98 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:88 +msgid "All Terms" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:99 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:89 +msgid "Parent Term" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:100 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:90 +msgid "Parent Term:" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:101 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:91 +msgid "Edit Term" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:102 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:92 +msgid "Update Term" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:103 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:93 +msgid "Add New Term" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:104 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:94 +msgid "New Term Name" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:125 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:115 +msgid "Custom Field" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:180 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:170 +msgid "Post updated. %sView post%s." +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:181 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:171 +msgid "Custom field updated." +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:182 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:172 +msgid "Custom field deleted." +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:183 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:173 +msgid "Post updated." +msgstr "" + +#. translators: %s: date and time of the revision + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:185 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:175 +msgid "Post restored to revision from %s." +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:186 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:176 +msgid "Post published. %sView post%s." +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:187 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:177 +msgid "Post saved." +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:188 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:178 +msgid "Post submitted. %sPreview post%s." +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:189 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:179 +msgid "Post scheduled for: %1$s. %2$sPreview post%3$s." +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:189 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:179 +msgid "M j, Y @ G:i" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:190 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:180 +msgid "Post draft updated. %sPreview post%s." +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:201 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:191 +msgid "Post Details" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:295 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:285 +msgid "Enter the post title here" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:308 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:298 +msgid "Custom field:" +msgstr "" + +#: classes/post-types/class-tika-doc-pdf-indexer-post_type.php:309 +#: includes/post-types/class-tika-doc-pdf-indexer-post_type.php:299 +msgid "Description of this custom field." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:70 +#: includes/class-tika-doc-pdf-indexer-settings.php:405 +msgid "Plugin Settings" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:99 +msgid "Settings" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:111 +msgid "Standard" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:112 +msgid "These are fairly standard form input fields." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:116 +msgid "Some Text" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:117 +msgid "This is a standard text field." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:120 +#: includes/class-tika-doc-pdf-indexer-settings.php:128 +#: includes/class-tika-doc-pdf-indexer-settings.php:136 +msgid "Placeholder text" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:124 +msgid "A Password" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:125 +msgid "This is a standard password field." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:132 +msgid "Some Secret Text" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:133 +msgid "This is a secret text field - any data saved here will not be displayed after the page has reloaded, but it will be saved." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:140 +msgid "A Text Block" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:141 +msgid "This is a standard text area." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:144 +msgid "Placeholder text for this textarea" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:148 +msgid "An Option" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:149 +msgid "A standard checkbox - if you save this option as checked then it will store the option as 'on', otherwise it will be an empty string." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:155 +msgid "A Select Box" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:156 +msgid "A standard select box." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:163 +msgid "Some Options" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:164 +msgid "A standard set of radio buttons." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:171 +msgid "Some Items" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:172 +msgid "You can select multiple items and they will be stored as an array." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:181 +msgid "Extra" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:182 +msgid "These are some extra input fields that maybe aren't as common as the others." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:186 +msgid "A Number" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:187 +msgid "This is a standard number field - if this field contains anything other than numbers then the form will not be submitted." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:190 +msgid "42" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:194 +msgid "Pick a colour" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:195 +msgid "This uses WordPress' built-in colour picker - the option is stored as the colour's hex code." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:201 +msgid "An Image" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:202 +msgid "This will upload an image to your media library and store the attachment ID in the option field. Once you have uploaded an imge the thumbnail will display above these buttons." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:209 +msgid "A Multi-Select Box" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:210 +msgid "A standard multi-select box - the saved data is stored as an array." +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:354 +msgid "Upload an image" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:354 +msgid "Use image" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:354 +msgid "Upload new image" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:355 +msgid "Remove image" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:410 +msgid "All" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:427 +msgid "Save Settings" +msgstr "" + +#: includes/class-tika-doc-pdf-indexer-settings.php:458 +#: includes/class-tika-doc-pdf-indexer-settings.php:467 +#: includes/class-tika-doc-pdf-indexer.php:207 +#: includes/class-tika-doc-pdf-indexer.php:216 +msgid "Cheatin’ huh?" +msgstr "" +#. Plugin Name of the plugin/theme +msgid "Tika Doc PDF Indexer" +msgstr "" + +#. Plugin URI of the plugin/theme +msgid "http://www.hughlashbrooke.com/" +msgstr "" + +#. Author of the plugin/theme +msgid "Hugh Lashbrooke" +msgstr "" + +#. Author URI of the plugin/theme +msgid "http://www.hughlashbrooke.com/" +msgstr "" diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..daa97b7 --- /dev/null +++ b/readme.txt @@ -0,0 +1,36 @@ +=== Tika Doc PDF Indexer === +Contributors: carl-alberto +Tags: wordpress, plugin +Requires at least: 4.8 +Tested up to: 5.2.3 +Stable tag: 1.0.0 +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +== Description == + +This creates a custom post type and let you upload your documents. Once a doc extract the text from it and put it in the wp_content table. This utilizes the Apache Tika Project https://tika.apache.org/ and this should be installed in your server. + +== Installation == + +Installing "Tika Doc PDF Indexer" can be done either by searching for "Tika Doc PDF Indexer" via the "Plugins > Add New" screen in your WordPress dashboard, or by using the following steps: + +1. Download the plugin via WordPress.org +2. Upload the ZIP file through the 'Plugins > Add New > Upload' screen in your WordPress dashboard +3. Activate the plugin through the 'Plugins' menu in WordPress + +== Usage == + +After plugin installation: + +1. Make sure the plugin has the correct path to the Tika installation and Java installation +2. Add a new document +3. Attach a document by uploading a valid file that can be read by Tika +4. Text data will be saved in the wp_content column + +== Changelog == + += 1.0.0 = +* 2019-10-21 +* Initial release +* Only support pdf at the moment diff --git a/tika-doc-pdf-indexer.php b/tika-doc-pdf-indexer.php new file mode 100644 index 0000000..2272b66 --- /dev/null +++ b/tika-doc-pdf-indexer.php @@ -0,0 +1,65 @@ +settings ) ) { + $instance->settings = Tika_Doc_PDF_Indexer_Settings::instance( $instance ); + } + + return $instance; +} + +tika_doc_pdf_indexer(); diff --git a/uninstall.php b/uninstall.php new file mode 100644 index 0000000..38b461d --- /dev/null +++ b/uninstall.php @@ -0,0 +1,16 @@ +