|
1 <?php |
|
2 class ContentTimelineAdmin { |
|
3 |
|
4 var $main, $path, $name, $url; |
|
5 |
|
6 function __construct($file) { |
|
7 $this->main = $file; |
|
8 $this->init(); |
|
9 return $this; |
|
10 } |
|
11 |
|
12 function init() { |
|
13 $this->path = dirname( __FILE__ ); |
|
14 $this->name = basename( $this->path ); |
|
15 $this->url = plugins_url( "/{$this->name}/" ); |
|
16 if( is_admin() ) { |
|
17 |
|
18 register_activation_hook( $this->main , array(&$this, 'activate') ); |
|
19 |
|
20 add_action('admin_menu', array(&$this, 'admin_menu')); |
|
21 |
|
22 // Ajax calls |
|
23 add_theme_support( 'post-thumbnails' ); |
|
24 add_action('wp_ajax_ctimeline_save', array(&$this, 'ajax_save')); |
|
25 add_action('wp_ajax_ctimeline_preview', array(&$this, 'ajax_preview')); |
|
26 add_action('wp_ajax_ctimeline_post_search', array(&$this, 'ajax_post_search')); |
|
27 add_action('wp_ajax_ctimeline_post_get', array(&$this, 'ajax_post_get')); |
|
28 add_action('wp_ajax_ctimeline_post_category_get', array(&$this, 'ajax_post_category_get')); |
|
29 add_action('wp_ajax_ctimeline_frontend_get', array(&$this, 'ajax_frontend_get')); |
|
30 add_action('wp_ajax_nopriv_ctimeline_frontend_get', array(&$this, 'ajax_frontend_get')); |
|
31 |
|
32 } |
|
33 else { |
|
34 add_action('wp', array(&$this, 'frontend_includes')); |
|
35 add_shortcode('content_timeline', array(&$this, 'shortcode') ); |
|
36 } |
|
37 } |
|
38 |
|
39 function activate() { |
|
40 global $wpdb; |
|
41 |
|
42 $table_name = $wpdb->base_prefix . 'ctimelines'; |
|
43 |
|
44 if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { |
|
45 $royal_sliders_sql = "CREATE TABLE " . $table_name ." ( |
|
46 id mediumint(9) NOT NULL AUTO_INCREMENT, |
|
47 name tinytext NOT NULL COLLATE utf8_general_ci, |
|
48 settings text NOT NULL COLLATE utf8_general_ci, |
|
49 items text NOT NULL COLLATE utf8_general_ci, |
|
50 PRIMARY KEY (id) |
|
51 );"; |
|
52 |
|
53 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
54 dbDelta($royal_sliders_sql); |
|
55 } |
|
56 |
|
57 } |
|
58 |
|
59 function admin_menu() { |
|
60 $ctmenu = add_menu_page( 'Content Timeline', 'Content Timeline', 'manage_options', 'contenttimeline', array(&$this, 'admin_page')); |
|
61 $submenu = add_submenu_page( 'contenttimeline', 'Content Timeline', 'Add New', 'manage_options', 'contenttimeline_edit', array(&$this, 'admin_edit_page')); |
|
62 |
|
63 add_action('load-'.$ctmenu, array(&$this, 'admin_menu_scripts')); |
|
64 add_action('load-'.$submenu, array(&$this, 'admin_menu_scripts')); |
|
65 add_action('load-'.$ctmenu, array(&$this, 'admin_menu_styles')); |
|
66 add_action('load-'.$submenu, array(&$this, 'admin_menu_styles')); |
|
67 } |
|
68 |
|
69 function admin_menu_scripts() { |
|
70 wp_enqueue_script('post'); |
|
71 wp_enqueue_script('farbtastic'); |
|
72 wp_enqueue_script('thickbox'); |
|
73 wp_enqueue_script('ctimeline-admin-js', $this->url . 'js/ctimeline_admin.js' ); |
|
74 wp_enqueue_script('jQuery-easing', $this->url . 'js/frontend/jquery.easing.1.3.js' ); |
|
75 wp_enqueue_script('jQuery-timeline', $this->url . 'js/frontend/jquery.timeline.js' ); |
|
76 |
|
77 wp_enqueue_script('jQuery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js' ); |
|
78 wp_enqueue_script('jQuery-mousew', $this->url . 'js/frontend/jquery.mousewheel.min.js' ); |
|
79 wp_enqueue_script('jQuery-customScroll', $this->url . 'js/frontend/jquery.mCustomScrollbar.min.js' ); |
|
80 } |
|
81 |
|
82 function admin_menu_styles() { |
|
83 wp_enqueue_style('farbtastic'); |
|
84 wp_enqueue_style('thickbox'); |
|
85 wp_enqueue_style( 'ctimeline-admin-css', $this->url . 'css/ctimeline_admin.css' ); |
|
86 wp_enqueue_style( 'ctimeline-thick-css', $this->url . 'css/thickbox.css' ); |
|
87 wp_enqueue_style( 'timeline-css', $this->url . 'css/frontend/timeline.css' ); |
|
88 wp_enqueue_style( 'customScroll-css', $this->url . 'css/frontend/jquery.mCustomScrollbar.css' ); |
|
89 } |
|
90 |
|
91 function ajax_save() { |
|
92 $id = false; |
|
93 $settings = ''; |
|
94 $items = ''; |
|
95 foreach( $_POST as $key => $value) { |
|
96 if ($key != 'action') { |
|
97 if ($key == 'timeline_id'){ |
|
98 if ($value != '') { |
|
99 $id = (int)$value; |
|
100 } |
|
101 } |
|
102 else if ($key == 'timeline_title'){ |
|
103 $name = stripslashes($value); |
|
104 } |
|
105 else if(strpos($key,'sort') === 0){ |
|
106 $items .= $key . '::' . stripslashes($value) . '||'; |
|
107 } |
|
108 else { |
|
109 $settings .= $key . '::' . stripslashes($value) . '||'; |
|
110 } |
|
111 } |
|
112 } |
|
113 if ($items != '') $items = substr($items,0,-2); |
|
114 if ($settings != '') $settings = substr($settings,0,-2); |
|
115 global $wpdb; |
|
116 $table_name = $wpdb->base_prefix . 'ctimelines'; |
|
117 if($id) { |
|
118 $wpdb->update( |
|
119 $table_name, |
|
120 array( |
|
121 'name'=>$name, |
|
122 'settings'=>$settings, |
|
123 'items'=>$items), |
|
124 array( 'id' => $id ), |
|
125 array( |
|
126 '%s', |
|
127 '%s', |
|
128 '%s'), |
|
129 array('%d') |
|
130 ); |
|
131 } |
|
132 else { |
|
133 $wpdb->insert( |
|
134 $table_name, |
|
135 array( |
|
136 'name'=>$name, |
|
137 'settings'=>$settings, |
|
138 'items'=>$items), |
|
139 array( |
|
140 '%s', |
|
141 '%s', |
|
142 '%s') |
|
143 |
|
144 ); |
|
145 $id = $wpdb->insert_id; |
|
146 } |
|
147 |
|
148 |
|
149 echo $id; |
|
150 die(); |
|
151 } |
|
152 |
|
153 function ajax_preview() { |
|
154 $tid = false; |
|
155 $tsettings = ''; |
|
156 $titems = ''; |
|
157 foreach( $_POST as $key => $value) { |
|
158 if ($key != 'action') { |
|
159 if ($key == 'timeline_id'){ |
|
160 if ($value != '') { |
|
161 $tid = (int)$value; |
|
162 } |
|
163 } |
|
164 else if ($key == 'timeline_title'){ |
|
165 $tname = $value; |
|
166 } |
|
167 else if(strpos($key,'sort') === 0){ |
|
168 $titems .= $key . '::' . $value . '||'; |
|
169 } |
|
170 else { |
|
171 $tsettings .= $key . '::' . $value . '||'; |
|
172 } |
|
173 } |
|
174 } |
|
175 if ($titems != '') $titems = substr($titems,0,-2); |
|
176 if ($tsettings != '') $tsettings = substr($tsettings,0,-2); |
|
177 |
|
178 include_once($this->path . '/pages/content_timeline_preview.php'); |
|
179 |
|
180 die(); |
|
181 } |
|
182 |
|
183 function ajax_post_search(){ |
|
184 if(isset($_POST['query']) && !empty($_POST['query'])){ |
|
185 $searchVal = strtolower($_POST['query']); |
|
186 } |
|
187 else { |
|
188 $searchVal = ''; |
|
189 } |
|
190 |
|
191 $query_args = array( 'posts_per_page' => -1, 'post_type' => 'any'); |
|
192 $query = new WP_Query( $query_args ); |
|
193 |
|
194 foreach ( $query->posts as $match) { |
|
195 if($searchVal != ''){ |
|
196 if(strpos(strtolower($match->post_name), $searchVal) !== false){ |
|
197 $thumbn = wp_get_attachment_image_src( get_post_thumbnail_id($match->ID) , 'full'); |
|
198 echo '<li><a href="'.$match->ID.'"><img style="margin-right:5px;" src="'.$this->url.'timthumb/timthumb.php?src='.$thumbn[0].'&w=150&h=150" width="32" height="32" alt="" /><span class="timelinePostCompleteName">'.$match->post_title .'</span><span class="clear"></span></a></li>'; |
|
199 } |
|
200 } |
|
201 } |
|
202 die(); |
|
203 } |
|
204 |
|
205 function ajax_post_get($post_id = false){ |
|
206 $id = (int) $_POST['post_id']; |
|
207 if ($post_id) $id = $post_id; |
|
208 $post = get_post($id); |
|
209 |
|
210 echo $post->post_title . '||'; |
|
211 echo substr($post->post_date, 8, 2) . '/' . substr($post->post_date, 5, 2) . '/' . substr($post->post_date, 0, 4) . '||'; |
|
212 $post_categories = get_the_category( $id ); |
|
213 |
|
214 echo $post_categories[0]->name . '||'; |
|
215 $excerpt = $post->post_excerpt; |
|
216 if ($excerpt == '' && $post->post_content != '') { |
|
217 echo substr($post->post_content,0,100) . '...'; |
|
218 } |
|
219 |
|
220 echo $excerpt . '||'; |
|
221 if ( has_post_thumbnail($id)) { |
|
222 echo wp_get_attachment_url( get_post_thumbnail_id($id , 'full')); |
|
223 } |
|
224 echo '||' . $post->post_content; |
|
225 |
|
226 if(!$post_id) { |
|
227 die(); |
|
228 } |
|
229 |
|
230 } |
|
231 |
|
232 function ajax_post_category_get() { |
|
233 $cat_name = $_POST['cat_name']; |
|
234 $term = get_term_by('name', $cat_name, 'category'); |
|
235 $cat_id = $term->term_id; |
|
236 |
|
237 $the_query = new WP_Query( array( 'cat' => $cat_id, 'post_type' => 'any', 'posts_per_page'=>-1, 'order' => 'ASC')); |
|
238 $start = true; |
|
239 while ( $the_query->have_posts() ) : $the_query->the_post(); |
|
240 if ($the_query->post->post_type != 'page') { |
|
241 if (!$start) { |
|
242 echo '||'; |
|
243 } |
|
244 $start = false; |
|
245 $this->ajax_post_get($the_query->post->ID); |
|
246 } |
|
247 endwhile; |
|
248 |
|
249 die(); |
|
250 } |
|
251 |
|
252 function ajax_frontend_get(){ |
|
253 $timelineId = $_GET['timeline']; |
|
254 $id = $_GET['id']; |
|
255 |
|
256 |
|
257 global $wpdb; |
|
258 if($timelineId) { |
|
259 $timeline = $wpdb->get_results('SELECT * FROM ' . $wpdb->base_prefix . 'ctimelines WHERE id='.$timelineId); |
|
260 $timeline = $timeline[0]; |
|
261 |
|
262 $cats = "["; |
|
263 $catArray = array(); |
|
264 $ccNumbers = array(); |
|
265 $catNumber = 0; |
|
266 |
|
267 foreach(explode('||',$timeline->settings) as $val) { |
|
268 $expl = explode('::',$val); |
|
269 if(substr($expl[0], 0, 8) == 'cat-name') { |
|
270 if($cats != "[") $cats .= ","; |
|
271 $cc = get_cat_name(intval(substr($expl[0], 9))); |
|
272 $cats .= "'".$cc."'"; |
|
273 array_push ($catArray,$cc); |
|
274 array_push ($ccNumbers, 0); |
|
275 $catNumber++; |
|
276 } |
|
277 else { |
|
278 $settings[$expl[0]] = $expl[1]; |
|
279 } |
|
280 |
|
281 } |
|
282 $cats .= "]"; |
|
283 |
|
284 |
|
285 if ($timeline->items != '') { |
|
286 $explode = explode('||',$timeline->items); |
|
287 $open_content_height = intval($settings['item-height']) - intval($settings['item-open-image-height']) - 2*intval($settings['item-open-content-padding']) -intval($settings['item-open-image-border-width']) - 6; |
|
288 |
|
289 foreach ($explode as $it) { |
|
290 $ex2 = explode('::', $it); |
|
291 $key = substr($ex2[0],0,strpos($ex2[0],'-')); |
|
292 $subkey = substr($ex2[0],strpos($ex2[0],'-')+1); |
|
293 $itemsArray[$key][$subkey] = $ex2[1]; |
|
294 } |
|
295 |
|
296 $arr = $itemsArray[$id]; |
|
297 |
|
298 |
|
299 $frontHtml =''; |
|
300 |
|
301 if ($arr['item-open-image'] != '') { |
|
302 $frontHtml .= ' |
|
303 <a class="timeline_rollover_bottom con_borderImage" href="'.(($arr['item-open-prettyPhoto'] != '')? $arr['item-open-prettyPhoto'] : $arr['item-open-image']).'" rel="prettyPhoto[timeline]"> |
|
304 <img src="'. $this->url . 'timthumb/timthumb.php?src=' . $arr['item-open-image'] . '&w='.$settings['item-open-width'].'&h='.$settings['item-open-image-height'].'" alt=""/></a> |
|
305 <div class="timeline_open_content'.(!$arr['desable-scroll'] ? ' scrollable-content' : '').'" style="height: '. $open_content_height.'px">'; |
|
306 |
|
307 } |
|
308 else { |
|
309 $frontHtml .= ' |
|
310 <div class="timeline_open_content'.(!$arr['desable-scroll'] ? ' scrollable-content' : '').'" style="height: '. (intval($settings['item-height']) - 2*intval($settings['item-open-content-padding'])).'px">'; |
|
311 } |
|
312 |
|
313 if ($arr['item-open-title'] != '') { |
|
314 $frontHtml .= ' |
|
315 <h2>'.$arr['item-open-title'].'</h2>'; |
|
316 } |
|
317 $frontHtml .= ' |
|
318 ' . $arr['item-open-content'].' |
|
319 </div>'; |
|
320 |
|
321 echo do_shortcode($frontHtml); |
|
322 } |
|
323 |
|
324 die(); |
|
325 } |
|
326 } |
|
327 |
|
328 |
|
329 |
|
330 function admin_page() { |
|
331 include_once($this->path . '/pages/content_timeline_index.php'); |
|
332 } |
|
333 |
|
334 function admin_edit_page() { |
|
335 include_once($this->path . '/pages/content_timeline_edit.php'); |
|
336 } |
|
337 |
|
338 function shortcode($atts) { |
|
339 extract(shortcode_atts(array( |
|
340 'id' => '' |
|
341 ), $atts)); |
|
342 |
|
343 include_once($this->path . '/pages/content_timeline_frontend.php'); |
|
344 $frontHtml = preg_replace('/\s+/', ' ',$frontHtml); |
|
345 |
|
346 return do_shortcode($frontHtml); |
|
347 } |
|
348 |
|
349 function frontend_includes() { |
|
350 wp_enqueue_script('jquery'); |
|
351 wp_enqueue_script('jQuery-easing', $this->url . 'js/frontend/jquery.easing.1.3.js' ); |
|
352 wp_enqueue_script('jQuery-timeline', $this->url . 'js/frontend/jquery.timeline.js' ); |
|
353 wp_enqueue_script('jQuery-mousew', $this->url . 'js/frontend/jquery.mousewheel.min.js' ); |
|
354 wp_enqueue_script('jQuery-customScroll', $this->url . 'js/frontend/jquery.mCustomScrollbar.min.js' ); |
|
355 wp_enqueue_script('jQuery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js' ); |
|
356 wp_enqueue_script('rollover', $this->url . 'js/frontend/rollover.js' ); |
|
357 wp_enqueue_script('jquery-prettyPhoto', $this->url . 'js/frontend/jquery.prettyPhoto.js' ); |
|
358 |
|
359 wp_enqueue_style( 'timeline-css', $this->url . 'css/frontend/timeline.css' ); |
|
360 wp_enqueue_style( 'customScroll-css', $this->url . 'css/frontend/jquery.mCustomScrollbar.css' ); |
|
361 wp_enqueue_style( 'prettyPhoto-css', $this->url . 'css/frontend/prettyPhoto.css' ); |
|
362 |
|
363 } |
|
364 } |
|
365 ?> |