This repository has been archived by the owner on Nov 2, 2022. It is now read-only.
forked from sundaune/ebooksearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
finnebok.php
120 lines (100 loc) · 4.97 KB
/
finnebok.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
*
* @package Ebook Search by Webloft
* @author Håkon Sundaune <[email protected]>
* @license GPL-3.0+
* @link http://www.bibvenn.no
* @copyright 2014 Sundaune
*
* @wordpress-plugin
* Plugin Name: Ebook Search by Webloft
* Plugin URI: http://www.bibvenn.no/finnebok
* Description: Søker etter gratis PDF- og e-bøker / search for free PDFs and e-books
* Version: 1.0.3
* Author: Håkon Sundaune
* Author URI: http://www.sundaune.no
* Text Domain: finnebok-locale
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
* Domain Path: /languages
* WordPress-Plugin-Boilerplate: v2.6.1
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
// INCLUDE NECESSARY
add_action( 'wp_enqueue_scripts', 'ebok_register_assets' );
/**
* Only register stylesheet. Enqueue when needed.
*/
function ebok_register_assets() {
wp_register_style( 'finnebok-shortcode-style', plugins_url('/css/public.css', __FILE__) );
wp_register_script( 'finnebok-script', plugins_url( 'js/public.js', __FILE__ ), array('jquery') );
wp_register_script( 'webloft-tab-script', plugins_url( 'js/tabcontent.js', __FILE__ ), array('jquery') );
}
// FIRST COMES THE SHORTCODE... EH, CODE!
function finnebok_func ($atts){
extract(shortcode_atts(array(
'width' => "250px",
'dummy' => "dummytekst",
'makstreff' => "25",
'show_heading' => false,
'show_share_links' => false
), $atts));
if ( $show_heading === 'false' ) {
$show_heading = false;
}
$show_heading = (boolean) $show_heading;
if ( $show_share_links === 'false' ) {
$show_share_links = false;
}
$show_share_links = (boolean) $show_share_links;
if ($makstreff > 100) { // ikke vær dust'a
$makstreff = 100;
}
// DEFINE HTML TO OUTPUT WHEN SHORTCODE IS FOUND
$width = strip_tags(stripslashes($width));
$htmlout = '<script type="text/javascript">';
$htmlout .= "var pluginsUrl = '" . plugins_url('/search.php' , __FILE__) . "'";
$htmlout .= "/***********************************************";
$htmlout .= "* Tab Content script v2.2- © Dynamic Drive DHTML code library (www.dynamicdrive.com)";
$htmlout .= "* This notice MUST stay intact for legal use";
$htmlout .= "* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code";
$htmlout .= "***********************************************/";
$htmlout .= '</script>';
$htmlout .= '<div class="ebok_skjema" style="width: ' . $width . '">';
if ( $show_heading ) {
$htmlout .= '<h2>Søk i e-bok og PDF</h2>';
}
$htmlout .= '<form target="_blank" method="GET" action="' . plugins_url('ebok_fullpagesearch.php' , __FILE__) . '">';
$htmlout .= '<table style="width: 85%; border: 0; margin: 0; padding: 0;"><tr><td style="border: 0; padding: 0; margin: 0; vertical-align: middle; width: 80%;">';
$htmlout .= '<input name="query" type="text" autocomplete="off" id="finnebok_search" placeholder="Søk etter..." />';
$htmlout .= '</td></tr></table>';
$htmlout .= '<input type="hidden" name="makstreff" id="finnebok_makstreff" value="' . $makstreff . '" />';
$htmlout .= '<input type="hidden" name="show_share_links" id="finnebok_show_share_links" value="' . $show_share_links . '" />';
$htmlout .= '<div class="sjekkbokser">';
$htmlout .= '<input id="finnebok_epub" type="checkbox" style="vertical-align: middle;" name="epub" value="2" checked>';
$htmlout .= '<label for="finnebok_epub">.epub</label> ';
$htmlout .= '<input id="finnebok_pdf" type="checkbox" style="vertical-align: middle;" name="pdf" value="1" checked>';
$htmlout .= '<label for="finnebok_pdf">.pdf</label>';
$htmlout .= '</div>';
$htmlout .= '<br style="clear: both;">';
$htmlout .= '</div>';
$htmlout .= '<div id="ebs_loader" class="small"><div></div></div>';
$htmlout .= '<div id="results-text" style="display: none; width: ' . $width . '">';
$htmlout .= 'Viser maks. ' . $makstreff . ' treff for: <span id="finnebok_search-string"></span><br /><span>Søket oppdateres mens du skriver, og kan ta noen sekunder... vær tålmodig! Vil du åpne søket i et eget vindu og eventuelt vise flere treff, klikk <input style="font-size: 1em; padding: 3px; height: 2em; font-weight: bold; vertical-align: top;" type="submit" value="her!"></form></span></div>';
$htmlout .= '<div id="finnebok_results" style="width: ' . $width . '"></div>';
return $htmlout;
}; // end function
add_shortcode("finnebok_skjema", "finnebok_func");
function ebok_enqueue_style() {
global $post;
if ( is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'finnebok_skjema' ) ) {
wp_enqueue_style('finnebok-shortcode-style');
wp_enqueue_script( 'finnebok-script' );
wp_enqueue_script( 'webloft-tab-script' ); // in order to prevent enqueueing a script more than once if localhistory search is active
}
}
add_action( 'wp_enqueue_scripts', 'ebok_enqueue_style');