-
Notifications
You must be signed in to change notification settings - Fork 7
/
infinitescroll.php
165 lines (127 loc) · 5.35 KB
/
infinitescroll.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
if (!defined('_PS_VERSION_'))
exit;
require_once dirname( __FILE__ ) . '/includes/options.php';
class InfiniteScroll extends Module{
static $instance;
public $options;
public $admin;
public $submit;
public $slug = 'infinitescroll'; //plugin slug, generally base filename and in url on wordpress.org
public $slug_ = 'infinitescroll'; //slug with underscores (PHP/JS safe)
public $prefix = 'infinitescroll_'; //prefix to append to all options, API calls, etc. w/ trailing underscore
public $file = null;
public $behaviors = array( //array of behaviors as key => array( label => js file ) (without extension)
'twitter' => array( 'label' => 'Manual Trigger', 'src' => 'manual-trigger' ),
'local' => array( 'label' => 'Local', 'src' => 'local' ),
'cufon' => array( 'label' => 'Cufon', 'src' => 'cufon' ),
'masonry' => array( 'label' => 'Masonry/Isotope', 'src' => 'masonry-isotope')
);
public function __construct(){
$this->name = 'infinitescroll';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'Prestastrap';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6');
parent::__construct();
$this->displayName = $this->l('Infinite Scroll');
$this->description = $this->l('Automatically loads the next page of products into the bottom of the initial page.');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
$this->options = new Infinite_Scroll_Options( $this );
$this->init_defaults();
}
public function install(){
if (!parent::install() OR !$this->registerHook('footer') OR !$this->registerHook('header'))
return false;
return true;
}
public function uninstall(){
if (!Configuration::deleteByName($this->slug_) || !parent::uninstall())
return false;
return true;
}
/**
* Init default options
*/
private function init_defaults() {
//option keys map to javascript options and are passed directly via wp_localize_script
$this->options->defaults = array(
'loading' => array(
'msgText' => '<em>' . $this->l( 'Loading...' ) . '</em>',
'finishedMsg' => '<em>' . $this->l( 'No additional posts.' ) . '</em>',
'img' => $this->_path.'img/ajax-loader.gif'
),
'nextSelector' => '#pagination_next > a',
'navSelector' => '.content_sortPagiBar',
'itemSelector' => '#product_list > li',
'contentSelector' => '#product_list',
'debug' => false,
'behavior' => '',
'callback' => ''
);
}
/**
* Enqueue front-end JS and pass options to json_encoded array
*/
public function hookHeader($params) {
if (!$this->shouldLoadJavascript()) {
return;
}
$options = $this->options->get_options();
$suffix = $options['debug'] ? '.dev' : '' ;
$file = "js/jquery.infinitescroll{$suffix}.js";
$this->context->controller->addJS(($this->_path).$file);
// If no behavior, we're done, kick
if ( !$options['behavior'] )
return;
//sanity check
if ( !array_key_exists( $options['behavior'], $this->behaviors ) )
return false;
$src = 'behaviors/' . $this->behaviors[ $options['behavior'] ]['src'] . '.js';
$this->context->controller->addJS(($this->_path).$src);
}
/**
* Load footer template to pass options array to JS
*/
public function hookFooter($params){
if (!$this->shouldLoadJavascript()) {
return;
}
$options = $this->options->get_options();
$options = $this->options->db_version_filter( $options );
$options = json_encode($options);
$this->smarty->assign(array('options' => $options));
return $this->display(__FILE__, 'views/templates/hook/footer.tpl');
}
/**
* Determines if the jQuery plugin and corresponding options should
* be output onto the page.
*
* @return bool
*/
function shouldLoadJavascript() {
$enabledControllers = array( 'best-sales', 'category', 'manufacturer', 'new-products',
'search', 'supplier');
if(isset($this->context->controller->php_self)){
if(in_array($this->context->controller->php_self, $enabledControllers)){
return true;
}
}
return false;
}
public function getContent(){
if (!empty($_POST)){
$this->postProcess();
}
$this->smarty->assign(array('options' => $this->options->get_options(), 'behaviors' => $this->behaviors, 'version' => $this->version ));
return $this->display(__FILE__, 'views/templates/admin/options.tpl');
}
public function postProcess(){
$errors = array();
if (Tools::isSubmit('btnSaveInfiniteScrollOptions')){
$this->options->set_options(Tools::getValue('infinite_scroll'));
}
}
}
?>