· 10 years ago · Sep 23, 2016, 09:12 PM
1<?php
2/***** start session *****/
3ob_start();
4
5define( 'SHOW_MYCRED_IN_WOOCOMMERCE', true );
6
7/***** translatable theme *****/
8load_theme_textdomain( 'funding', get_template_directory() . '/langs');
9
10
11/***** include files *****/
12require_once (get_template_directory() . '/themeOptions/functions.php');
13require_once (get_template_directory() . '/pagebuilder/page-builder.php');
14require_once (get_template_directory() . '/functions/google-fonts.php');
15require_once (get_template_directory() . '/addons/heart/love/heart-love.php' );
16require_once (get_template_directory() . '/addons/pricetable/pricetable.php');
17require_once (get_template_directory() . '/addons/woosidebars/woosidebars.php');
18require_once (get_template_directory() . '/addons/smartmetabox/SmartMetaBox.php');
19require_once (get_template_directory() . '/addons/multiple-post-thumbnails/multi-post-thumbnails.php' );
20require_once (get_template_directory() . '/funding/funding.php');
21require_once (get_template_directory() . '/widgets/latest_twitter/latest_twitter_widget.php');
22require_once (get_template_directory() . '/pluginactivation.php');
23require_once (get_template_directory() . '/post_templates.php');
24require_once(get_template_directory() . '/widgets/rating/popular-widget.php');
25require_once(get_template_directory() . '/widgets/projectcategory/projectcat-widget.php');
26include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
27
28add_theme_support( 'menus' );
29add_theme_support( 'post-thumbnails' );
30add_theme_support( 'woocommerce' );
31add_theme_support( 'title-tag' );
32add_theme_support( 'automatic-feed-links' );
33add_theme_support( 'custom-header' );
34add_theme_support( 'custom-background' );
35
36
37
38/*post templates*/
39add_action( 'init', 'fundingpress_post_templates_plugin_init' );
40
41/*Post templates*/
42function fundingpress_post_templates_plugin_init() {
43 new fundingpress_Single_Post_Template_Plugin;
44}
45
46
47/***** add my-projects page *****/
48if(get_ID_by_slug('my-account') == ""){
49//create my-projects page
50$post = array(
51 'post_name' => 'my-account',
52 'post_status' => 'publish',
53 'post_title' => esc_html__('My account', 'funding'),
54 'post_type' => 'page'
55);
56wp_insert_post( $post );}
57
58
59/***** add all-projects page *****/
60if(get_ID_by_slug('all-projects') == ""){
61//create my-projects page
62$post = array(
63 'post_name' => 'all-projects',
64 'post_status' => 'publish',
65 'post_title' => esc_html__('All projects', 'funding'),
66 'post_type' => 'page'
67);
68wp_insert_post( $post );}
69
70
71/***** add launch a project page *****/
72if(get_ID_by_slug('launch-project') == ""){
73//create my-projects page
74$post = array(
75 'post_name' => 'launch-project',
76 'post_status' => 'publish',
77 'post_title' => esc_html__('Submit project', 'funding'),
78 'post_type' => 'page'
79);
80wp_insert_post( $post );}
81
82/***** get id by slug function *****/
83function get_ID_by_slug($page_slug) {
84 $page = get_page_by_path($page_slug);
85 if ($page) {
86 return $page->ID;
87 } else {
88 return null;
89 }
90}
91
92
93/***** add templates for pages *****/
94$id_page = get_ID_by_slug('my-account');
95update_post_meta($id_page, "_wp_page_template", "tmp-my-account.php");
96$id_page = get_ID_by_slug('all-projects');
97update_post_meta($id_page, "_wp_page_template", "tmp-all-projects.php");
98$id_page = get_ID_by_slug('launch-project');
99update_post_meta($id_page, "_wp_page_template", "tmp-submit-project.php");
100
101
102
103/**** add video meta box for posts *****/
104add_smart_meta_box('my-meta-box77', array(
105'title' => esc_html__('Video url', 'funding'), // the title of the meta box
106'pages' => array('post'),
107'context' => 'normal', // meta box context (see above)
108'priority' => 'high', // meta box priority (see above)
109'fields' => array( // array describing our fields
110array(
111'name' => esc_html__('Put your embed video URL here', 'funding'),
112'id' => 'video',
113'type' => 'textarea',
114),)));
115
116/***** add custom columns for projects in back end *****/
117add_filter( 'manage_edit-project_columns', 'funding_my_edit_project_columns' ) ;
118
119if ( current_user_can('contributor') && !current_user_can('upload_files') )
120
121add_action('admin_init', 'funding_allow_contributor_uploads');
122function funding_allow_contributor_uploads() {
123 $role = get_role('contributor');
124 $role->add_cap('upload_files');
125 $role->add_cap('delete_others_posts');
126 $role->add_cap('delete_posts');
127 $role->add_cap('delete_published_posts');
128 }
129
130function funding_my_edit_project_columns( $columns ) {
131 $columns = array(
132 "cb" => "<input type=\"checkbox\" />",
133 "title" => esc_html__( "Project Title", 'funding' ),
134 "status" => esc_html__( 'Project status', 'funding' ),
135 "funding-progress" => esc_html__( "Progress", 'funding' ),
136 "funding-time" => esc_html__( "Time Remaining", 'funding' ),
137 "ppal" => esc_html__( "Paypal", 'funding' ),
138 "wepay" => esc_html__( "Wepay", 'funding' ),
139 "author" => esc_html__( "Creator", 'funding' ),
140 "comments" => '<img src="'.site_url().'/wp-admin/images/comment-grey-bubble.png" alt="Comments" />',
141 'date' => esc_html__( 'Date', 'funding' ),
142 );
143 return $columns;
144}
145
146add_action( 'manage_project_posts_custom_column', 'funding_my_manage_project_columns', 10, 2 );
147function funding_my_manage_project_columns( $column, $post_id ) {
148 global $post;
149 switch( $column ) {
150 /* If displaying the 'duration' column. */
151 case 'funding-time' :
152 $project_settings = (array) get_post_meta($post_id, 'settings', true);
153 if(get_option('date_format') == 'm/d/Y' && strtotime($project_settings['date']) != false){
154 $array = explode('/', $project_settings['date']);
155 $tmp = $array[0];
156 $array[0] = $array[1];
157 $array[1] = $tmp;
158 unset($tmp);
159 if($array[0] == NULL){
160 $project_settings['date'] = $array[1];
161 }else{
162 $project_settings['date'] = implode('/', $array);
163 }
164 }
165
166 if(get_option('date_format') == 'd/m/Y' && strtotime($project_settings['date']) != false){
167 $array = explode('/', $project_settings['date']);
168 $tmp = $array[0];
169 $array[0] = $array[1];
170 $array[1] = $tmp;
171 unset($tmp);
172 if($array[0] == NULL){
173 $project_settings['date'] = $array[1];
174 }else{
175 $project_settings['date'] = implode('/', $array);
176 }
177 }
178
179
180 $target = $project_settings['target'];
181 if (strpos( $project_settings['date'] , "/") !== false) {
182 $parseddate = str_replace('/' , '.' , $project_settings['date']);
183 }else{
184 $parseddate = $project_settings['date'];
185 }
186 $project_expired = strtotime($parseddate) < time();
187 $funded_amount = 0;
188 $rewards = get_children(array('post_parent' => $post -> ID, 'post_type' => 'reward', 'order' => 'ASC', 'orderby' => 'meta_value_num', 'meta_key' => 'funding_amount', ));
189 $funders = array();
190 $funded_amount = 0;
191 $chosen_reward = null;
192 foreach ($rewards as $this_reward) {
193 $these_funders = get_children(array('post_parent' => $this_reward -> ID, 'post_type' => 'funder', 'post_status' => 'publish'));
194 foreach ($these_funders as $this_funder) {
195 $funding_amount = get_post_meta($this_funder -> ID, 'funding_amount', true);
196 $funders[] = $this_funder;
197 $funded_amount += $funding_amount;
198 }
199 }
200
201 if(!$project_expired) : ?>
202 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?> <strong> <?php esc_html_e('< 24', 'funding'); ?></strong> <?php }else{ ?>
203 <strong><?php print F_Controller::timesince(time(), strtotime($parseddate), 1, ''); } ?></strong>
204 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?>
205 <?php esc_html_e('hours to go', 'funding'); ?>
206 <?php }else{ ?>
207 <?php if(F_Controller::timesince(time(), strtotime($parseddate), 1, '') == 1){ ?>
208 <?php esc_html_e('day to go', 'funding'); ?>
209 <?php }else{ ?>
210 <?php esc_html_e('days to go', 'funding'); ?>
211 <?php } ?>
212
213
214 <?php } ?>
215 <?php endif;
216 break;
217 /* If displaying the 'genre' column. */
218 case 'status' :
219 $project_settings = (array) get_post_meta($post_id, 'settings', true);
220
221 if(get_option('date_format') == 'm/d/Y' && strtotime($project_settings['date']) != false){
222 $array = explode('/', $project_settings['date']);
223 $tmp = $array[0];
224 $array[0] = $array[1];
225 $array[1] = $tmp;
226 unset($tmp);
227 if($array[0] == NULL){
228 $project_settings['date'] = $array[1];
229 }else{
230 $project_settings['date'] = implode('/', $array);
231 }
232 }
233
234 if(get_option('date_format') == 'd/m/Y' && strtotime($project_settings['date']) != false){
235 $array = explode('/', $project_settings['date']);
236 $tmp = $array[0];
237 $array[0] = $array[1];
238 $array[1] = $tmp;
239 unset($tmp);
240 if($array[0] == NULL){
241 $project_settings['date'] = $array[1];
242 }else{
243 $project_settings['date'] = implode('/', $array);
244 }
245 }
246
247
248
249 $target = $project_settings['target'];
250 if (strpos( $project_settings['date'] , "/") !== false) {
251 $parseddate = str_replace('/' , '.' , $project_settings['date']);
252 }else{
253 $parseddate = $project_settings['date'];
254 }
255 $project_expired = strtotime($parseddate) < time();
256 $funded_amount = 0;
257 $rewards = get_children(array('post_parent' => $post -> ID, 'post_type' => 'reward', 'order' => 'ASC', 'orderby' => 'meta_value_num', 'meta_key' => 'funding_amount', ));
258 $funders = array();
259 $funded_amount = 0;
260 $chosen_reward = null;
261 foreach ($rewards as $this_reward) {
262 $these_funders = get_children(array('post_parent' => $this_reward -> ID, 'post_type' => 'funder', 'post_status' => 'publish'));
263 foreach ($these_funders as $this_funder) {
264 $funding_amount = get_post_meta($this_funder -> ID, 'funding_amount', true);
265 $funders[] = $this_funder;
266 $funded_amount += $funding_amount;
267 }
268 }
269 $status = get_post_meta($post_id, 'status', true);
270
271 if($status == 'review') { global $a; $a =1; ?>
272 <strong><?php esc_html_e('Pending!', 'funding') ?></strong>
273 <?php }elseif($status == 'draft'){ global $a; $a =2;?>
274 <strong><?php esc_html_e('Draft!', 'funding') ?></strong>
275 <?php }elseif( $funded_amount > $target or $funded_amount == $target){ global $a; $a =3;?>
276 <strong><?php esc_html_e('Successful!', 'funding') ?></strong>
277 <?php }elseif($project_expired){ global $a; $a =4;?>
278 <strong><?php esc_html_e('Unsuccessful!', 'funding') ?></strong>
279 <?php }else{ global $a; $a =5;?>
280 <strong><?php esc_html_e('Active!', 'funding') ?></strong>
281 <?php }
282 break;
283 case 'ppal':
284 $usr = get_userdata(get_the_author_meta( 'ID' )); echo esc_attr($usr->paypal_email);
285 break;
286 case 'wepay':
287 echo esc_attr(get_the_author_meta('wepay_account_id', get_the_author_meta( 'ID' )));
288 break;
289 case 'funding-progress':
290 $project_settings = (array) get_post_meta($post_id, 'settings', true);
291
292 if(get_option('date_format') == 'm/d/Y' && strtotime($project_settings['date']) != false){
293 $array = explode('/', $project_settings['date']);
294 $tmp = $array[0];
295 $array[0] = $array[1];
296 $array[1] = $tmp;
297 unset($tmp);
298 if($array[0] == NULL){
299 $project_settings['date'] = $array[1];
300 }else{
301 $project_settings['date'] = implode('/', $array);
302 }
303 }
304
305
306 if(get_option('date_format') == 'd/m/Y' && strtotime($project_settings['date']) != false){
307 $array = explode('/', $project_settings['date']);
308 $tmp = $array[0];
309 $array[0] = $array[1];
310 $array[1] = $tmp;
311 unset($tmp);
312 if($array[0] == NULL){
313 $project_settings['date'] = $array[1];
314 }else{
315 $project_settings['date'] = implode('/', $array);
316 }
317 }
318
319
320 $target = $project_settings['target'];
321 if(!isset($f_currency_signs[$project_settings['currency']]))$f_currency_signs[$project_settings['currency']] = '';
322 $project_currency_sign = $f_currency_signs[$project_settings['currency']];
323 if (strpos( $project_settings['date'] , "/") !== false) {
324 $parseddate = str_replace('/' , '.' , $project_settings['date']);
325 }else{
326 $parseddate = $project_settings['date'];
327 }
328 $project_expired = strtotime($parseddate) < time();
329 $funded_amount = 0;
330 $rewards = get_children(array('post_parent' => $post -> ID, 'post_type' => 'reward', 'order' => 'ASC', 'orderby' => 'meta_value_num', 'meta_key' => 'funding_amount', ));
331 $funders = array();
332 $funded_amount = 0;
333 $chosen_reward = null;
334 foreach ($rewards as $this_reward) {
335 $these_funders = get_children(array('post_parent' => $this_reward -> ID, 'post_type' => 'funder', 'post_status' => 'publish'));
336 foreach ($these_funders as $this_funder) {
337 $funding_amount = get_post_meta($this_funder -> ID, 'funding_amount', true);
338 $funders[] = $this_funder;
339 $funded_amount += $funding_amount;
340 }
341 }
342 if($funded_amount == 0)
343 {echo '0%';}else{
344 printf(esc_html__('%u%', 'funding'), round($funded_amount/$target*100), $project_currency_sign, round($target));echo '%';}
345 break;
346 /* Just break out of the switch statement for everything else. */
347 default :
348 break;
349 }
350}
351
352
353/***** add custom columns for projects in back end *****/
354add_filter('request', 'funding_fix_category_pagination');
355function funding_fix_category_pagination($qs){
356 if(isset($qs['category_name']) && isset($qs['paged'])){
357 $qs['post_type'] = get_post_types($args = array(
358 'public' => true,
359 '_builtin' => false
360 ));
361 array_push($qs['post_type'],'post');
362 }
363 return $qs;
364}
365
366
367
368/***** theme scripts *****/
369add_action('wp_enqueue_scripts', 'funding_my_scripts');
370function funding_my_scripts(){
371 wp_register_script( 'bootstrap1', get_template_directory_uri().'/js/bootstrap.js','','',true);
372 wp_enqueue_script('bootstrap1');
373 wp_register_script( 'bootstrap2', get_template_directory_uri().'/js/bootstrap-tooltip.js','','',true);
374 wp_enqueue_script('bootstrap2');
375 wp_register_script( 'bootstrap3', get_template_directory_uri().'/js/bootstrap-tab.js','','',true);
376 wp_enqueue_script('bootstrap3');
377 wp_register_script( 'tiny_js', get_template_directory_uri().'/js/jquery.carouFredSel-6.1.0.js');
378 wp_enqueue_script('tiny_js');
379 wp_register_script( 'easing', get_template_directory_uri().'/js/easing.js','','',true);
380 wp_enqueue_script('easing');
381 wp_register_script( 'totop', get_template_directory_uri().'/js/jquery.ui.totop.min.js','','',true);
382 wp_enqueue_script('totop');
383
384 if(of_get_option('scrollbar') == 1){
385 wp_register_script( 'custom_js1', get_template_directory_uri().'/js/theme.min.js','','',true);
386 wp_enqueue_script('custom_js1');
387 }
388
389 wp_register_script( 'imagescale', get_template_directory_uri().'/js/imagescale.js','','',true);
390 wp_enqueue_script('imagescale');
391 wp_register_script( 'custom_js2', get_template_directory_uri().'/js/login-with-ajax.js','','',true);
392 wp_enqueue_script('custom_js2');
393 wp_register_script( 'custom_js3', get_template_directory_uri().'/js/login-with-ajax.source.js','','',true);
394 wp_enqueue_script('custom_js3');
395 wp_register_script( 'custom_js4', get_template_directory_uri().'/js/jquery.validate.min.js','','',true);
396 wp_enqueue_script('custom_js4');
397 wp_register_script( 'custom_js5', get_template_directory_uri().'/js/verify.js','','',true);
398 wp_enqueue_script('custom_js5');
399 wp_register_script( 'custom_js6', get_template_directory_uri().'/js/jquery-ui-1.10.2.custom.js','','',true);
400 wp_enqueue_script('custom_js6');
401 wp_register_script( 'custom_js7', get_template_directory_uri().'/js/appear.js','','',true);
402 wp_enqueue_script('custom_js7');
403 wp_register_script( 'custom_js8', get_template_directory_uri().'/js/bxSlider.js','','',true);
404 wp_enqueue_script('custom_js8');
405 wp_register_script( 'custom_js9', get_template_directory_uri().'/js/parallax.js','','',true);
406 wp_enqueue_script('custom_js9');
407 wp_register_script( 'custom_js10', get_template_directory_uri().'/js/picker.js','','',true);
408 wp_enqueue_script('custom_js10');
409 wp_register_script( 'custom_js11', get_template_directory_uri().'/js/isotope.js','','',true);
410 wp_enqueue_script('custom_js11');
411 wp_register_script( 'custom_js12', get_template_directory_uri().'/js/transit.js','','',true);
412 wp_enqueue_script('custom_js12');
413 wp_register_script( 'custom_js99', get_template_directory_uri().'/js/global.js','','',true);
414 wp_enqueue_script('custom_js99');
415 wp_register_script( 'fball', '//connect.facebook.net/en_US/all.js','','',true);
416 wp_enqueue_script('fball');
417 $siteurl = get_site_url(); //set location to the auth folder script
418 if (substr($siteurl, -1) != "/") {
419 $siteurl .= "/";
420 } //add trailing slash
421 $baseurl = get_template_directory_uri().'/include/';
422 $settings = array('authlocation' => $baseurl, 'ajax' => admin_url( 'admin-ajax.php' )); //pass wp settings we need to array
423 wp_register_script( 'social_js', get_template_directory_uri().'/js/social.js','','',true);
424 wp_localize_script('social_js', 'settings', $settings); //pass any php settings to javascript
425 wp_enqueue_script('social_js');
426
427
428 if(is_page(get_ID_by_slug('my-account'))){
429 wp_register_script( 'custom_ajaxupload1', get_template_directory_uri().'/js/jquery.iframe-transport.js','','',true);
430 wp_enqueue_script('custom_ajaxupload1');
431 wp_register_script( 'custom_ajaxupload2', get_template_directory_uri().'/js/jquery.fileupload.js','','',true);
432 wp_enqueue_script('custom_ajaxupload2');
433 wp_register_script( 'custom_ajaxupload3', get_template_directory_uri().'/js/jquery.fileupload-ui.js','','',true);
434 wp_enqueue_script('custom_ajaxupload3');
435 wp_register_script( 'custom_ajaxupload4', get_template_directory_uri().'/js/jquery.fileupload-process.js','','',true);
436 wp_enqueue_script('custom_ajaxupload4');
437 wp_register_script( 'custom_jcrop', get_template_directory_uri().'/js/jquery.Jcrop.min.js','','',true);
438 wp_enqueue_script('custom_jcrop');
439 wp_register_style( 'custom-styleHcrop', get_template_directory_uri().'/css/jquery.Jcrop.css', array(), '20130401');
440 wp_enqueue_style( 'custom-styleHcrop' );
441 wp_register_script( 'campaign_script', get_template_directory_uri().'/js/addphoto.js','','',true);
442 $settingsCustom = array('dateformat' => of_get_option('datef'), 'NowDay' => date('d'), 'NowMonth' => date('m'), 'NowYear' => date('Y'),
443 'uploadfileformat' => esc_html__('Only JPG, JPEG and PNG files are allowed', 'funding'),
444 'uploadphotoscu' => esc_html__('Photo Is Uploading...', 'funding'),
445 'uploaderror' => esc_html__('Error!', 'funding'),
446 'pleasefinishcrop' => esc_html__('Please finish cropping the other image first!', 'funding'),
447 'urlcheckbad' => esc_html__('URL is not valid!', 'funding'),
448 'urlnumbercheck' => esc_html__('Valid number!', 'funding'),
449 'urlnumberrange' => esc_html__('Number must be in 1-500 range!', 'funding'),
450 'urlnumberinputcheck' => esc_html__('Input must be a number in 1-500 range!', 'funding')
451 ); //pass wp settings we need to array
452 $upload_dir = wp_upload_dir();
453 $settings1 = array('wp_upload_dir_path' => $upload_dir['path']."/", 'wp_upload_dir_url' => $upload_dir['url']."/"); //pass wp settings we need to array
454 wp_localize_script('campaign_script', 'uploadsettings', $settings1); //pass any php settings to javascript
455 wp_localize_script('campaign_script', 'settingsCustom', $settingsCustom); //pass any php settings to javascript
456 wp_enqueue_script('campaign_script');
457 wp_register_script( 'custom_ui3', get_template_directory_uri().'/js/jquery-ui-1.10.3.custom.min.js','','',true);
458 wp_enqueue_script('custom_ui3');
459 }
460
461
462 if(is_page(get_ID_by_slug('launch-project'))){
463 wp_register_script( 'custom_ajaxupload1', get_template_directory_uri().'/js/jquery.iframe-transport.js','','',true);
464 wp_enqueue_script('custom_ajaxupload1');
465 wp_register_script( 'custom_ajaxupload2', get_template_directory_uri().'/js/jquery.fileupload.js','','',true);
466 wp_enqueue_script('custom_ajaxupload2');
467 wp_register_script( 'custom_ajaxupload3', get_template_directory_uri().'/js/jquery.fileupload-ui.js','','',true);
468 wp_enqueue_script('custom_ajaxupload3');
469 wp_register_script( 'custom_ajaxupload4', get_template_directory_uri().'/js/jquery.fileupload-process.js','','',true);
470 wp_enqueue_script('custom_ajaxupload4');
471 wp_register_script( 'custom_jcrop', get_template_directory_uri().'/js/jquery.Jcrop.min.js','','',true);
472 wp_enqueue_script('custom_jcrop');
473 wp_register_style( 'custom-styleHcrop', get_template_directory_uri().'/css/jquery.Jcrop.css', array(), '20130401');
474 wp_enqueue_style( 'custom-styleHcrop' );
475 wp_register_script( 'campaign_script', get_template_directory_uri().'/js/submitproject.js','','',true);
476 $settingsCustom = array('dateformat' => of_get_option('datef'), 'NowDay' => date('d'), 'NowMonth' => date('m'), 'NowYear' => date('Y'),
477 'uploadfileformat' => esc_html__('Only JPG, JPEG and PNG files are allowed', 'funding'),
478 'uploadphotoscu' => esc_html__('Photo Is Uploading...', 'funding'),
479 'uploaderror' => esc_html__('Error!', 'funding'),
480 'pleasefinishcrop' => esc_html__('Please finish cropping the other image first!', 'funding'),
481 'urlcheckbad' => esc_html__('URL is not valid!', 'funding'),
482 'urlnumbercheck' => esc_html__('Valid number!', 'funding'),
483 'urlnumberrange' => esc_html__('Number must be in 1-500 range!', 'funding'),
484 'urlnumberinputcheck' => esc_html__('Input must be a number in 1-500 range!', 'funding'),
485 'minimumammount' => esc_html__('Minimum Amount', 'funding'),
486 'available' => esc_html__('Number Available', 'funding'),
487 'rewtitle' => esc_html__('Reward title', 'funding'),
488 'rewdesc' => esc_html__('Reward description', 'funding'),
489 'remove' => esc_html__('REMOVE ME', 'funding'),
490 ); //pass wp settings we need to array
491 $upload_dir = wp_upload_dir();
492 $settings1 = array('wp_upload_dir_path' => $upload_dir['path']."/", 'wp_upload_dir_url' => $upload_dir['url']."/"); //pass wp settings we need to array
493 wp_localize_script('campaign_script', 'uploadsettings', $settings1); //pass any php settings to javascript
494 wp_localize_script('campaign_script', 'settingsCustom', $settingsCustom); //pass any php settings to javascript
495 wp_enqueue_script('campaign_script');
496 wp_register_script( 'custom_ui3', get_template_directory_uri().'/js/jquery-ui-1.10.3.custom.min.js','','',true);
497 wp_enqueue_script('custom_ui3');
498 }
499}
500
501
502/***** admin scripts *****/
503add_action('admin_enqueue_scripts', 'funding_admin_scripts');
504function funding_admin_scripts(){
505wp_register_script( 'custom_js11', get_template_directory_uri().'/ckeditor/ckeditor.js');
506wp_enqueue_script('custom_js11');
507wp_register_script( 'custom22', get_template_directory_uri().'/js/admin.js','','',true);
508wp_enqueue_script('custom22');
509}
510
511
512/***** theme styles *****/
513add_action( 'wp_enqueue_scripts', 'funding_my_style' );
514function funding_my_style() {
515 wp_enqueue_style( 'mytheme-style', get_bloginfo( 'stylesheet_url' ), array(), '20150401' );
516
517 if ( is_rtl() )
518 {
519 wp_register_style('funding-rtl', get_template_directory_uri() . '/css/rtl.css', array(), '20150401');
520 wp_enqueue_style( 'funding-rtl' );
521 }
522}
523
524function funding_fonts() {
525 $protocol = is_ssl() ? 'https' : 'http';
526 wp_enqueue_style( 'funding-opens', "$protocol://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800,300italic,400italic,600italic,700italic" );
527}
528
529
530/***** admin styles *****/
531add_action('admin_init', 'funding_styles_admin');
532function funding_styles_admin(){
533 wp_register_style( 'custom-style11', get_template_directory_uri().'/css/font-awesome.css', array(), '20130401');
534 wp_enqueue_style( 'custom-style11' );
535 wp_register_style( 'custom-style22', get_template_directory_uri().'/css/gf-style.css', array(), '20130401');
536 wp_enqueue_style( 'custom-style22' );
537 wp_register_style( 'custom-style33', get_template_directory_uri().'/css/jquery-ui.min.css', array(), '20130401');
538 wp_enqueue_style( 'custom-style33' );
539}
540
541
542/***** add sidebars *****/
543if ( function_exists('register_sidebar') )
544register_sidebar(array(
545'name' => esc_html__( 'Footer area widgets', 'funding' ),
546'id' => 'one',
547'description' => esc_html__( 'Widgets in this area will be shown in the footer.' , 'funding'),
548'before_widget' => '<div class="footer_widget span3">',
549'after_widget' => '</div>',
550'before_title' => '<h3>',
551'after_title' => '</h3>', ));
552if ( function_exists('register_sidebar') )
553register_sidebar(array(
554'name' => esc_html__( 'Blog sidebar', 'funding' ),
555'id' => 'blog',
556'description' => esc_html__( 'Widgets in this area will be shown in the blog sidebar.' , 'funding'),
557'before_widget' => '<div class="widget">',
558'after_widget' => '</div>',
559'before_title' => '<h3>',
560'after_title' => '</h3>', ));
561
562
563
564/***** add Theme option menu in admin *****/
565add_action( 'admin_menu', 'fundingpress_create_menu' );
566function fundingpress_create_menu(){
567$themeicon1 = get_template_directory_uri()."/img/favicon.png";
568add_menu_page("Theme Options", "Theme Options", 'edit_theme_options', 'options-framework', 'optionsframework_page',$themeicon1,1800 );
569}
570
571
572/***** When this theme is activated send the user to the theme options *****/
573if (is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" ) {
574// Call action that sets
575add_action('admin_head','gp_setup');
576// Do redirect
577header( 'Location: '.admin_url().'themes.php?page=options-framework' ) ;
578}
579
580
581/***** Register menus *****/
582add_action( 'init', 'funding_register_my_menus' );
583function funding_register_my_menus() {
584 register_nav_menus(
585 array(
586 'header-menu' => esc_html__( 'Header Menu' , 'funding'),
587 )
588 );
589}
590
591
592/***** fix post counts *****/
593function funding_fix_post_counts($views) {
594 global $current_user, $wp_query;
595 unset($views['mine']);
596 $types = array(
597 array( 'status' => NULL ),
598 array( 'status' => 'publish' ),
599 array( 'status' => 'draft' ),
600 array( 'status' => 'pending' ),
601 array( 'status' => 'trash' ),
602 array( 'status' => 'review' )
603 );
604 foreach( $types as $type ) {
605 $query = array(
606 'author' => $current_user->ID,
607 'post_type' => 'post',
608 'post_status' => $type['status']
609 );
610 $result = new WP_Query($query);
611 if( $type['status'] == NULL ):
612 $class = ($wp_query->query_vars['post_status'] == NULL) ? ' class="current"' : '';
613 $views['all'] = sprintf(esc_html__('<a href="%s"'. $class .'>All <span class="count">(%d)</span></a>', 'funding'),
614 admin_url('edit.php?post_type=post'),
615 $result->found_posts);
616 elseif( $type['status'] == 'publish' ):
617 $class = ($wp_query->query_vars['post_status'] == 'publish') ? ' class="current"' : '';
618 $views['publish'] = sprintf(esc_html__('<a href="%s"'. $class .'>Published <span class="count">(%d)</span></a>', 'funding'),
619 admin_url('edit.php?post_status=publish&post_type=post'),
620 $result->found_posts);
621 elseif( $type['status'] == 'draft' ):
622 $class = ($wp_query->query_vars['post_status'] == 'draft') ? ' class="current"' : '';
623 $views['draft'] = sprintf(esc_html__('<a href="%s"'. $class .'>Draft'. ((sizeof($result->posts) > 1) ? "s" : "") .' <span class="count">(%d)</span></a>', 'funding'),
624 admin_url('edit.php?post_status=draft&post_type=post'),
625 $result->found_posts);
626 elseif( $type['status'] == 'pending' ):
627 $class = ($wp_query->query_vars['post_status'] == 'pending') ? ' class="current"' : '';
628 $views['pending'] = sprintf(esc_html__('<a href="%s"'. $class .'>Pending <span class="count">(%d)</span></a>', 'funding'),
629 admin_url('edit.php?post_status=pending&post_type=post'),
630 $result->found_posts);
631 elseif( $type['status'] == 'trash' ):
632 $class = ($wp_query->query_vars['post_status'] == 'trash') ? ' class="current"' : '';
633 $views['trash'] = sprintf(esc_html__('<a href="%s"'. $class .'>Trash <span class="count">(%d)</span></a>', 'funding'),
634 admin_url('edit.php?post_status=trash&post_type=post'),
635 $result->found_posts);
636 endif;
637 }
638 return $views;
639}
640
641
642/***** fix media counts *****/
643function funding_fix_media_counts($views) {
644 global $wpdb, $current_user, $post_mime_types, $avail_post_mime_types;
645 $views = array();
646 $count = $wpdb->get_results( "
647 SELECT post_mime_type, COUNT( * ) AS num_posts
648 FROM $wpdb->posts
649 WHERE post_type = 'attachment'
650 AND post_author = $current_user->ID
651 AND post_status != 'trash'
652 GROUP BY post_mime_type
653 ", ARRAY_A );
654 foreach( $count as $row )
655 $_num_posts[$row['post_mime_type']] = $row['num_posts'];
656 $_total_posts = array_sum($_num_posts);
657 $detached = isset( $_REQUEST['detached'] ) || isset( $_REQUEST['find_detached'] );
658 if ( !isset( $total_orphans ) )
659 $total_orphans = $wpdb->get_var("
660 SELECT COUNT( * )
661 FROM $wpdb->posts
662 WHERE post_type = 'attachment'
663 AND post_author = $current_user->ID
664 AND post_status != 'trash'
665 AND post_parent < 1
666 ");
667 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
668 foreach ( $matches as $type => $reals )
669 foreach ( $reals as $real )
670 $num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
671 $class = ( empty($_GET['post_mime_type']) && !$detached && !isset($_GET['status']) ) ? ' class="current"' : '';
672 $views['all'] = "<a href='upload.php'$class>" . sprintf( esc_html__('All <span class="count">(%s)</span>', 'funding' ), number_format_i18n( $_total_posts )) . '</a>';
673 foreach ( $post_mime_types as $mime_type => $label ) {
674 $class = '';
675 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
676 continue;
677 if ( !empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
678 $class = ' class="current"';
679 if ( !empty( $num_posts[$mime_type] ) )
680 $views[$mime_type] = "<a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), $num_posts[$mime_type] ) . '</a>';
681 }
682 $views['detached'] = '<a href="upload.php?detached=1"' . ( $detached ? ' class="current"' : '' ) . '>' . sprintf( esc_html__( 'Unattached <span class="count">(%s)</span>', 'funding' ), $total_orphans ) . '</a>';
683 return $views;
684}
685
686
687/***** login with ajax *****/
688class LoginWithAjax {
689 /**
690 * If logged in upon instantiation, it is a user object.
691 * @var WP_User
692 */
693 var $current_user;
694 /**
695 * List of templates available in the plugin dir and theme (populated in init())
696 * @var array
697 */
698 var $templates = array();
699 /**
700 * Name of selected template (if selected)
701 * @var string
702 */
703 var $template;
704 /**
705 * lwa_data option
706 * @var array
707 */
708 var $data;
709 /**
710 * Location of footer file if one is found when generating a widget, for use in loading template footers.
711 * @var string
712 */
713 var $footer_loc;
714 /**
715 * URL for the AJAX Login procedure in templates (including callback and template parameters)
716 * @var string
717 */
718 var $url_login;
719 /**
720 * URL for the AJAX Remember Password procedure in templates (including callback and template parameters)
721 * @var string
722 */
723 var $url_remember;
724 /**
725 * URL for the AJAX Registration procedure in templates (including callback and template parameters)
726 * @var string
727 */
728 var $url_register;
729 // Class initialization
730 function LoginWithAjax() {
731 //Set when to run the plugin
732 add_action('widgets_init', array(&$this, 'init'));
733 }
734 // Actions to take upon initial action hook
735 function init() {
736 //Load LWA options
737 $this -> data = get_option('lwa_data');
738 //Remember the current user, in case there is a logout
739 $this -> current_user = wp_get_current_user();
740 //Generate URLs for login, remember, and register
741 $this -> url_login = $this -> template_link(site_url('wp-login.php', 'login_post'));
742 $this -> url_register = $this -> template_link(site_url('wp-login.php?action=register', 'login_post'));
743 $this -> url_remember = $this -> template_link(site_url('wp-login.php?action=lostpassword', 'login_post'));
744 //Make decision on what to display
745 if (isset($_REQUEST["login-with-ajax"])) {//AJAX Request
746 $this -> ajax();
747 } elseif (isset($_REQUEST["login-with-ajax-widget"])) {//Widget Request via AJAX
748 $instance = (!empty($_REQUEST["template"])) ? array('template' => $_REQUEST["template"]) : array();
749 $instance['is_widget'] = false;
750 $instance['profile_link'] = (!empty($_REQUEST["lwa_profile_link"])) ? $_REQUEST['lwa_profile_link'] : 0;
751 $this -> widget(array(), $instance);
752 exit();
753 }
754 }
755 /*
756 * LOGIN OPERATIONS
757 */
758 // Decides what action to take from the ajax request
759 function ajax() {
760 switch ( $_REQUEST["login-with-ajax"] ) {
761 case 'login' :
762 //A login has been requested
763 $return = $this -> json_encode($this -> login());
764 break;
765 case 'register' :
766 //A login has been requested
767 $return = $this -> json_encode($this -> register());
768 break;
769 case 'remember' :
770 //Remember the password
771 $return = $this -> json_encode($this -> remember());
772 break;
773 default :
774 //Don't know
775 $return = $this -> json_encode(array('result' => 0, 'error' => 'Unknown command requested'));
776 break;
777 }
778 echo $return;
779 exit();
780 }
781 // Reads ajax login creds via POSt, calls the login script and interprets the result
782 function login() {
783 $return = array();
784 //What we send back
785 if (!empty($_REQUEST['log']) && !empty($_REQUEST['pwd']) && trim($_REQUEST['log']) != '' && trim($_REQUEST['pwd'] != '')) {
786 $loginResult = wp_signon();
787 $user_role = 'null';
788 if (strtolower(get_class($loginResult)) == 'wp_user') {
789 //User login successful
790 $this -> current_user = $loginResult;
791 /* @var $loginResult WP_User */
792 $return['result'] = true;
793 $return['message'] = esc_html__("Login Successful, redirecting...", 'funding');
794 //Do a redirect if necessary
795 $redirect = $this -> getLoginRedirect($this -> current_user);
796 if ($redirect != '') {
797 $return['redirect'] = $redirect;
798 }
799 //If the widget should just update with ajax, then supply the URL here.
800 if (!empty($this -> data['no_login_refresh']) && $this -> data['no_login_refresh'] == 1) {
801 //Is this coming from a template?
802 $query_vars = ($_GET['template'] != '') ? "&template={$_GET['template']}" : '';
803 $query_vars .= ($_REQUEST['lwa_profile_link'] == '1') ? "&lwa_profile_link=1" : '';
804 $return['widget'] = site_url(). "?login-with-ajax-widget=1$query_vars";
805 $return['message'] = esc_html__("Login successful, updating...", 'funding');
806 }
807 } elseif (strtolower(get_class($loginResult)) == 'wp_error') {
808 //User login failed
809 /* @var WP_Error $loginResult */
810 $return['result'] = false;
811 $return['error'] = $loginResult -> get_error_message();
812 } else {
813 //Undefined Error
814 $return['result'] = false;
815 $return['error'] = esc_html__('An undefined error has ocurred', 'funding');
816 }
817 } else {
818 $return['result'] = false;
819 $return['error'] = esc_html__('Please supply your username and password.', 'funding');
820 }
821 //Return the result array with errors etc.
822 return $return;
823 }
824 /**
825 * Checks post data and registers user
826 * @return string
827 */
828 function register() {
829 if (!empty($_REQUEST['lwa'])) {
830 $return = array();
831 if ('POST' == $_SERVER['REQUEST_METHOD']) {
832 require_once (ABSPATH . WPINC . '/registration.php');
833 $errors = register_new_user($_POST['user_login'], $_POST['user_email']);
834 if (!is_wp_error($errors)) {
835 //Success
836 $return['result'] = true;
837 $return['message'] = esc_html__('Registration complete. Please check your e-mail.', 'funding');
838 } else {
839 //Something's wrong
840 $return['result'] = false;
841 $return['error'] = $errors -> get_error_message();
842 }
843 }
844 echo $this -> json_encode($return);
845 exit();
846 }
847 }
848 // Reads ajax login creds via POSt, calls the login script and interprets the result
849 function remember() {
850 $return = array();
851 //What we send back
852 $result = retrieve_password();
853 if ($result === true) {
854 //Password correctly remembered
855 $return['result'] = true;
856 $return['message'] = esc_html__("We have sent you an email", 'funding');
857 } elseif (strtolower(get_class($result)) == 'wp_error') {
858 //Something went wrong
859 /* @var $result WP_Error */
860 $return['result'] = false;
861 $return['error'] = $result -> get_error_message();
862 } else {
863 //Undefined Error
864 $return['result'] = false;
865 $return['error'] = esc_html__('An undefined error has ocurred', 'funding');
866 }
867 //Return the result array with errors etc.
868 return $return;
869 }
870
871 /*
872 * Redirect Functions
873 */
874 function logoutRedirect() {
875 $redirect = $this -> getLogoutRedirect();
876 if ($redirect != '') {
877 wp_redirect($redirect);
878 exit();
879 }
880 }
881 function getLogoutRedirect() {
882 $data = $this -> data;
883 if (!empty($data['logout_redirect'])) {
884 $redirect = $data['logout_redirect'];
885 }
886 if (strtolower(get_class($this -> current_user)) == "wp_user") {
887 //Do a redirect if necessary
888 $data = $this -> data;
889 $user_role = array_shift($this -> current_user -> roles);
890 //Checking for role-based redirects
891 if (!empty($data["role_logout"]) && is_array($data["role_logout"]) && isset($data["role_logout"][$user_role])) {
892 $redirect = $data["role_logout"][$user_role];
893 }
894 }
895 $redirect = str_replace("%LASTURL%", $_SERVER['HTTP_REFERER'], $redirect);
896 return $redirect;
897 }
898 function loginRedirect($redirect, $redirect_notsurewhatthisis, $user) {
899 $data = $this -> data;
900 if (is_user_logged_in()) {
901 $lwa_redirect = $this -> getLoginRedirect($user);
902 if ($lwa_redirect != '') {
903 wp_redirect($lwa_redirect);
904 exit();
905 }
906 }
907 return $redirect;
908 }
909 function getLoginRedirect($user) {
910 $data = $this -> data;
911 if ($data['login_redirect'] != '') {
912 $redirect = $data["login_redirect"];
913 }
914 if (strtolower(get_class($user)) == "wp_user") {
915 $user_role = array_shift($user -> roles);
916 //Checking for role-based redirects
917 if (isset($data["role_login"][$user_role])) {
918 $redirect = $data["role_login"][$user_role];
919 }
920 }
921 //Do string replacements
922 $redirect = str_replace('%USERNAME%', $user -> user_login, $redirect);
923 $redirect = str_replace("%LASTURL%", $_SERVER['HTTP_REFERER'], $redirect);
924 return $redirect;
925 }
926 /*
927 * Auxillary Functions
928 */
929 //Checks a directory for folders and populates the template file
930 function find_templates($dir) {
931 if (is_dir($dir)) {
932 if ($dh = opendir($dir)) {
933 while (($file = readdir($dh)) !== false) {
934 if (is_dir($dir . $file) && $file != '.' && $file != '..' && $file != '.svn') {
935 //Template dir found, add it to the template array
936 $this -> templates[$file] = path_join($dir, $file);
937 }
938 }
939 closedir($dh);
940 }
941 }
942 }
943 //Add template link and JSON callback var to the URL
944 function template_link($content) {
945 if (strstr($content, '?')) {
946 $content .= '&callback=?&template=' . $this -> template;
947 } else {
948 $content .= '?callback=?&template=' . $this -> template;
949 }
950 return $content;
951 }
952 //PHP4 Safe JSON encoding
953 function json_encode($array) {
954 if (!function_exists("json_encode")) {
955 $return = json_encode($array);
956 } else {
957 $return = $this -> array_to_json($array);
958 }
959 if (isset($_REQUEST['callback']) && preg_match("/^jQuery[_a-zA-Z0-9]+$/", $_REQUEST['callback'])) {
960 $return = $_GET['callback'] . "($return)";
961 }
962 return $return;
963 }
964 //PHP4 Compatible json encoder function
965 function array_to_json($array) {
966 //PHP4 Comapatability - This encodes the array into JSON. Thanks go to Andy - http://www.php.net/manual/en/function.json-encode.php#89908
967 if (!is_array($array)) {
968 return false;
969 }
970 $associative = count(array_diff(array_keys($array), array_keys(array_keys($array))));
971 if ($associative) {
972 $construct = array();
973 foreach ($array as $key => $value) {
974 // We first copy each key/value pair into a staging array,
975 // formatting each key and value properly as we go.
976 // Format the key:
977 if (is_numeric($key)) {
978 $key = "key_$key";
979 }
980 $key = "'" . addslashes($key) . "'";
981 // Format the value:
982 if (is_array($value)) {
983 $value = $this -> array_to_json($value);
984 } else if (is_bool($value)) {
985 $value = ($value) ? "true" : "false";
986 } else if (!is_numeric($value) || is_string($value)) {
987 $value = "'" . addslashes($value) . "'";
988 }
989 // Add to staging array:
990 $construct[] = "$key: $value";
991 }
992 // Then we collapse the staging array into the JSON form:
993 $result = "{ " . implode(", ", $construct) . " }";
994 } else {// If the array is a vector (not associative):
995 $construct = array();
996 foreach ($array as $value) {
997 // Format the value:
998 if (is_array($value)) {
999 $value = $this -> array_to_json($value);
1000 } else if (!is_numeric($value) || is_string($value)) {
1001 $value = "'" . addslashes($value) . "'";
1002 }
1003 // Add to staging array:
1004 $construct[] = $value;
1005 }
1006 // Then we collapse the staging array into the JSON form:
1007 $result = "[ " . implode(", ", $construct) . " ]";
1008 }
1009 return $result;
1010 }
1011}//Template Tag
1012function login_with_ajax($atts = '') {
1013 global $LoginWithAjax;
1014 $atts = shortcode_parse_atts($atts);
1015 echo $LoginWithAjax -> shortcode($atts);
1016}// Start plugin
1017global $LoginWithAjax;
1018$LoginWithAjax = new LoginWithAjax();
1019
1020
1021/* Breadcrumbs */
1022function funding_breadcrumbs_inner(){
1023
1024 function funding_pg(){
1025 $pages = get_pages(array(
1026 'meta_key' => '_wp_page_template',
1027 'meta_value' => 'tmp-blog.php'
1028 ));
1029 foreach($pages as $page){
1030 return $page->post_name;
1031 }}
1032
1033 function funding_pg_projects(){
1034 $pages = get_pages(array(
1035 'meta_key' => '_wp_page_template',
1036 'meta_value' => 'tmp-all-projects.php'
1037 ));
1038 foreach($pages as $page){
1039 return $page->post_name;
1040 }}
1041 function funding_get_page_id($name){
1042 global $wpdb;
1043 /* get page id using custom query */
1044 $page_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE ( post_name = '".$name."' or post_title = '".$name."' ) and post_status = 'publish' and post_type='page' ");
1045 return $page_id;
1046 }
1047 function funding_get_page_permalink($name){
1048 $page_id = funding_get_page_id($name);
1049 return get_permalink($page_id);
1050 }
1051
1052 if (!is_home()) {
1053 echo '<a href="';
1054 echo esc_url(home_url());
1055 echo '">';
1056 echo esc_html__('Home', 'funding');
1057 echo "</a> / ";
1058 if(get_post_type() == 'project'){
1059 echo '<a href="';
1060 echo funding_get_page_permalink(''. funding_pg_projects());
1061 echo '">';
1062 echo esc_html__('Projects', 'funding');
1063 echo "</a> ";
1064 if (is_single()) {
1065 echo " / ";
1066 the_title();
1067 }elseif(is_tax()){
1068 echo " / ";
1069 echo str_replace('Categories', '', wp_title('',false,'left')) ;
1070 }elseif(is_search()){
1071 echo " / ";
1072 echo esc_html__('Search: ', 'funding');
1073 echo get_search_query();
1074 }
1075 }elseif (is_single()) {
1076 if(get_post_type( get_the_ID() ) == 'project'){
1077 echo esc_html__('Project', 'funding');
1078 if (is_single()) {
1079 echo " / ";
1080 the_title();
1081 }
1082 }else{
1083 echo '<a href="';
1084 echo funding_get_page_permalink(''. funding_pg());
1085 echo '">';
1086 echo esc_html__('Blog', 'funding');
1087 echo "</a> ";
1088 if (is_single()) {
1089 echo " / ";
1090 the_title();
1091 }
1092 }
1093 }elseif(is_category()){
1094 echo esc_html__('Category: ', 'funding');
1095 echo esc_attr(single_cat_title());
1096 }elseif(is_404()){
1097 echo '404';
1098 }elseif(is_search()){
1099 echo esc_html__('Search: ', 'funding');
1100 echo esc_attr(get_search_query());
1101 }elseif(is_author()){
1102 $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); echo esc_attr($curauth->user_nicename);
1103 } elseif (is_page()) {
1104 echo esc_attr(the_title());
1105 }elseif(is_tag()){
1106 echo esc_html__('Tag: ', 'funding');
1107 echo esc_attr(GetTagName(get_query_var('tag_id')));
1108 }elseif( function_exists( 'is_shop' ) && is_shop() ){
1109 esc_html_e('Shop', 'blackfyre ');
1110 }elseif( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
1111 ?><a href="<?php echo get_permalink(skywarrior_get_id_by_slug ('shop')); ?>"> <?php esc_html_e('Shop', 'blackfyre ');?></a> <?php
1112 echo " / ";
1113 the_title();
1114 } elseif(is_tax()){
1115 echo esc_html__('Category', 'funding');
1116 }elseif(is_archive()){
1117 echo esc_html__('Archive', 'funding');
1118 }
1119 }
1120}
1121
1122function funding_breadcrumbs(){
1123
1124if(function_exists('is_bbpress')){
1125 if(is_bbpress()){
1126 bbp_breadcrumb();
1127 }else{
1128 funding_breadcrumbs_inner();}
1129}else{
1130 funding_breadcrumbs_inner();
1131 }
1132}
1133
1134
1135/*get tag name*/
1136function GetTagName($meta){
1137 if (is_string($meta) || (is_numeric($meta) && !is_double($meta))
1138 || is_int($meta)){
1139 if (is_numeric($meta))
1140 $meta = (int)$meta;
1141 if (is_int($meta))
1142 $TagSlug = get_term_by('id', $meta, 'post_tag');
1143 else
1144 $TagSlug = get_term_by('slug', $meta, 'post_tag');
1145 return $TagSlug->name;
1146 }
1147}
1148
1149
1150/***** allow redirection, even if my theme starts to send output to the browser *****/
1151add_action('init', 'funding_do_output_buffer');
1152function funding_do_output_buffer() {
1153 ob_start();
1154}
1155
1156
1157/***** add admin body class *****/
1158add_action('admin_body_class', 'funding_adminclass');
1159function funding_adminclass(){
1160 $current_user= wp_get_current_user();
1161 $level = $current_user->user_level;
1162 if($level == 1){
1163 $classes = 'user_project';
1164 return $classes;
1165 }
1166}
1167
1168
1169/***** add country option to profile *****/
1170add_action('after_setup_theme', 'funding_country', 1 );
1171function funding_country() {
1172 include_once(TEMPLATEPATH.'/themeOptions/admin/country/usercountry.php');
1173}
1174
1175
1176/***** custom excerpt lenght *****/
1177add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
1178function custom_excerpt_length( $length ) {
1179 return 150;
1180}
1181
1182
1183/***** pagination *****/
1184function kriesi_pagination($pages = '', $range = 1)
1185{
1186$showitems = ($range * 1)+1;
1187$general_show_page = of_get_option('general_post_show');
1188global $paged;
1189global $paginate;
1190if(empty($paged)) $paged = 1;
1191if($pages == '')
1192{
1193global $wp_query;
1194$pages = $wp_query->max_num_pages;
1195if(!$pages)
1196{
1197$pages = 1;
1198}
1199}
1200if(1 != $pages)
1201{
1202$url= get_template_directory_uri();
1203$leftpager= '«';
1204$rightpager= '»';
1205if($paged > 2 && $paged > $range+1 && $showitems < $pages) $paginate.= "";
1206if($paged > 1 ) $paginate.= "<a class='page-selector' href='".get_pagenum_link($paged - 1)."'>". $leftpager. "</a>";
1207for ($i=1; $i <= $pages; $i++)
1208{
1209if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
1210{
1211$paginate.= ($paged == $i)? "<li><a href='".get_pagenum_link($i)."' class='active'>".$i."</a></li>":"<li><a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a></li>";
1212}
1213}
1214if ($paged < $pages ) $paginate.= "<li><a class='page-selector' href='".get_pagenum_link($paged + 1)."' >". $rightpager. "</a></li>";
1215}
1216return $paginate;
1217}
1218
1219
1220/***** add different image sizes *****/
1221if ( function_exists( 'add_image_size' ) ) {
1222 add_image_size( 'category-thumb', 320, 200, true );
1223 add_image_size( 'projects', 200, 150, true );
1224 add_image_size( 'medium-img', 200, 150, true );
1225}
1226
1227
1228function add_projects_custom_box() {
1229add_meta_box('postcustom', esc_html__('Update Fields', 'funding'), 'post_custom_meta_box', 'project', 'normal', 'core');
1230}
1231add_action( 'add_meta_boxes', 'add_projects_custom_box' );
1232add_filter( 'postmeta_form_limit', 'wpse_73543_hide_meta_start' );
1233function wpse_73543_hide_meta_start( $num )
1234{
1235 add_filter( 'query', 'wpse_73543_hide_meta_filter' );
1236 return $num;
1237}
1238function wpse_73543_hide_meta_filter( $query )
1239{
1240 // Protect further queries.
1241 remove_filter( current_filter(), __FUNCTION__ );
1242 $forbidden = array ( 'aq_block_1' ,'aq_block_2','aq_block_3','aq_block_4','aq_block_5','aq_block_6','aq_block_7','aq_block_8','aq_block_9','aq_block_10','project_video_link','preapproval_key',
1243 'allorany', 'charged', 'date','datum','field_1', 'field_2','hide_on_screen','layout','my_meta_box_check','my_meta_box_select','my_meta_box_text', 'notified','paypal_email','position',
1244 'available' ,'funder','funding_amount','page-option-choose-left-sidebar','page-option-choose-right-sidebar', 'page-option-item-xml', 'page-option-show-content','rule',
1245 'page-option-sidebar-template', 'page-option-show-title', 'page-option-top-slider-height', 'page-option-top-slider-types', 'page-option-top-slider-xml', 'reward', 'settings');
1246 $where = "WHERE meta_key NOT IN('" . join( "', '", $forbidden ) . "') ";
1247 $find = "GROUP BY";
1248 $query = str_replace( $find, "$where\n$find", $query );
1249 return $query;
1250}
1251function custom_comments($comment, $args, $depth) {
1252 $GLOBALS['comment'] = $comment;
1253 $GLOBALS['comment_depth'] = $depth;
1254 $allowed_tags = array(
1255 'span' => array(
1256 'class' => array()
1257 )
1258 );
1259 ?>
1260 <div class="project-comment row">
1261 <div class="comment-author span1 vcard"><?php commenter_avatar() ?></div>
1262 <?php if ($comment->comment_approved == '0') wp_kses(_e("\t\t\t\t\t<span class='unapproved'>Your comment is awaiting moderation.</span>\n", 'funding'), $allowed_tags ); ?>
1263 <div class="comment-content span6">
1264 <div class="comment-info"> <?php commenter_link() ?> <?php esc_html_e("on", 'funding');?> <?php the_title(); ?> <?php comment_time('M j, Y @ G:i'); ?> </div>
1265 <div class="comment-content"> <?php comment_text() ?></div>
1266 </div>
1267</div>
1268<?php } // end custom_comments
1269function custom_pings($comment, $args, $depth) {
1270 $GLOBALS['comment'] = $comment;
1271 $allowed_tags = array(
1272 'span' => array(
1273 'class' => array()
1274 )
1275 );
1276 ?>
1277 <div class="project-comment row">
1278 <div class="comment-author"><?php printf(esc_html__('By %1$s on %2$s at %3$s', 'funding'),
1279 get_comment_author_link(),
1280 get_comment_date(),
1281 get_comment_time() );
1282 edit_comment_link(esc_html__('Edit', 'funding'), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>'); ?></div>
1283 <?php if ($comment->comment_approved == '0') wp_kses(_e('\t\t\t\t\t<span class="unapproved">Your trackback is awaiting moderation.</span>\n', 'funding'), $allowed_tags ); ?>
1284 <div class="comment-content span6">
1285 <?php comment_text() ?>
1286 </div>
1287 </div>
1288<?php
1289} // end custom_pings
1290// Produces an avatar image with the hCard-compliant photo class
1291function commenter_link() {
1292 $commenter = get_comment_author_link();
1293 if ( preg_match( '/<a[^>]* class=[^>]+>/', $commenter ) ) {
1294 $commenter = preg_replace( '/(<a[^>]* class=[\'"]?)/', '\\1url ' , $commenter );
1295 } else {
1296 $commenter = preg_replace( '/(<a )/', '\\1class="url "/' , $commenter );
1297 }
1298 echo ' <span class="comment-info">' . $commenter . '</span>';
1299} // end commenter_link
1300function commenter_avatar() {
1301 $allowed_tags = array(
1302 'img' => array(
1303 'class' => array(),
1304 'src' => array(),
1305 ),
1306);
1307 $avatar_email = get_comment_author_email();
1308 $avatar = str_replace( "class='avatar", "class='photo avatar", get_avatar( $avatar_email, 100 ) );
1309 echo wp_kses($avatar, $allowed_tags );
1310} // end commenter_link
1311
1312
1313
1314/***** add meta boxes *****/
1315add_smart_meta_box('my-meta-box', array(
1316'title' => esc_html__('Video url', 'funding'), // the title of the meta box
1317'pages' => array('project'), // post types on which you want the metabox to appear
1318'context' => 'normal', // meta box context (see above)
1319'priority' => 'high', // meta box priority (see above)
1320'fields' => array( // array describing our fields
1321array(
1322'name' => esc_html__('Put your project embed video URL here', 'funding'),
1323'id' => 'video-link-field',
1324'type' => 'textarea',
1325),)));
1326
1327//add staff checkbox
1328add_smart_meta_box('my-meta-box2', array(
1329'title' => esc_html__('Staff picks', 'funding'), // the title of the meta box
1330'pages' => array('project'), // post types on which you want the metabox to appear
1331'context' => 'side', // meta box context (see above)
1332'priority' => 'core', // meta box priority (see above)
1333'fields' => array( // array describing our fields
1334array(
1335'name' => esc_html__('Staff picks', 'funding'),
1336'id' => 'staff-check-field',
1337'type' => 'checkbox',
1338),)));
1339
1340/*add featured checbox*/
1341add_smart_meta_box('my-meta-box3', array(
1342'title' => esc_html__('Featured', 'funding'), // the title of the meta box
1343'pages' => array('project'), // post types on which you want the metabox to appear
1344'context' => 'side', // meta box context (see above)
1345'priority' => 'core', // meta box priority (see above)
1346'fields' => array( // array describing our fields
1347array(
1348'name' => esc_html__('Featured', 'funding'),
1349'id' => 'featured',
1350'type' => 'checkbox',
1351),)));
1352
1353
1354/***** limit media to logged in user *****/
1355add_action('pre_get_posts','funding_restrict_media_library');
1356function funding_restrict_media_library( $wp_query_obj ) {
1357 global $current_user, $pagenow;
1358 if( !is_a( $current_user, 'WP_User') )
1359 return;
1360 if( 'admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments' )
1361 return;
1362 if( !current_user_can('manage_media_library') )
1363 $wp_query_obj->set('author', $current_user->ID );
1364 return;
1365}
1366
1367
1368/***** return thumb url *****/
1369function return_thumb_url(){
1370global $post;
1371$thumb_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID) , 'medium-img');
1372return $thumb_url[0]; }
1373
1374
1375
1376/*creates options for the hybridauth so they are flexible*/
1377function social_createoptions() {
1378 $siteurl = get_site_url();
1379 $holdtheme = get_template_directory();
1380 $thetheme = explode("/", $holdtheme);
1381 $nametheme = $thetheme[count($thetheme) -1];
1382 if (substr($siteurl, -1) != "/") {
1383 $siteurl .= "/";
1384 } //add trailing slash
1385 $baseurl = $siteurl.'wp-content/themes/'.$nametheme.'/include/';
1386 $redirecturl = $siteurl.'wp-content/themes/'.$nametheme.'/include/handler/index.php?initiatelogin=';
1387 //"keys" => array ( "key" => of_get_option('linkedin_app'), "secret" => of_get_option('linkedin_secret'))
1388 //"keys" => array ( "id" => of_get_option('vkontakte_app'), "secret" => of_get_option('vkontakte_secret'))
1389 //"keys" => array ( "id" => of_get_option('google_app'), "secret" => of_get_option('google_secret') ),
1390 return
1391 array(
1392 "base_url" => $baseurl,
1393 "redirect_url" => $redirecturl,
1394 "providers" => array (
1395 // openid providers
1396 "OpenID" => array (
1397 "enabled" => false
1398 ),
1399
1400 "AOL" => array (
1401 "enabled" => false
1402 ),
1403
1404 "Yahoo" => array (
1405 "enabled" => false,
1406 "keys" => array ( "id" => "", "secret" => "" )
1407 ),
1408
1409
1410 "Facebook" => array (
1411 "enabled" => true,
1412 "keys" => array ( "id" => of_get_option('facebook_app'), "secret" => of_get_option('facebook_secret') )
1413 ),
1414
1415 "Twitter" => array (
1416 "enabled" => true,
1417 "keys" => array ( "key" => of_get_option('twitter_app'), "secret" => of_get_option('twitter_secret'))
1418 ),
1419
1420 // Google+ish
1421 "Google" => array (
1422 "enabled" => true,
1423 "keys" => array ( "id" => of_get_option('google_app'), "secret" => of_get_option('google_secret') )
1424 ),
1425
1426 "MySpace" => array (
1427 "enabled" => false,
1428 "keys" => array ( "key" => "", "secret" => "" )
1429 ),
1430
1431 "LinkedIn" => array (
1432 "enabled" => false,
1433 "keys" => array ( "key" => of_get_option('linkedin_app'), "secret" => of_get_option('linkedin_secret'))
1434 ),
1435
1436 "Tumblr" => array (
1437 "enabled" => false,
1438 "keys" => array ( "key" => "", "secret" => "" )
1439 ),
1440 "Foursquare" => array (
1441 "enabled" => false,
1442 "keys" => array ( "id" => "", "secret" => "" )
1443 ),
1444 ),
1445
1446
1447 // if you want to enable logging, set 'debug_mode' to true then provide a writable file by the web server on "debug_file"
1448 "debug_mode" => false,
1449
1450 "debug_file" => ""
1451 );
1452}
1453function check_table() {
1454
1455 global $wpdb;
1456 //check if theme needs updating
1457 $table_name = $wpdb->prefix . "access_tokens";
1458 $count = $wpdb->get_var('SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = "'.$table_name.'" AND COLUMN_NAME = "access_token" AND TABLE_SCHEMA="'.DB_NAME.'"');
1459
1460 if ($count == 0) {
1461 $sql = "CREATE TABLE IF NOT EXISTS $table_name (
1462 `uid` int(11) NOT NULL AUTO_INCREMENT,
1463 `access_token` TEXT NULL DEFAULT NULL,
1464 `access_token_expires` int(11) DEFAULT NULL,
1465 `access_token_session` TEXT NULL DEFAULT NULL,
1466 `access_token_name` TEXT NULL DEFAULT NULL,
1467 `access_token_photo` TEXT NULL DEFAULT NULL,
1468 `access_token_id` TEXT NULL DEFAULT NULL,
1469 `access_token_provider` TEXT NULL DEFAULT NULL,
1470 `access_token_secret` TEXT NULL DEFAULT NULL,
1471 PRIMARY KEY (`uid`)
1472 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
1473 $wpdb->query($sql);
1474 // print_r ($wpdb);
1475 }
1476
1477}
1478
1479
1480/*handle sessions in wordpress*/
1481add_action('init', 'myStartSession', 1);
1482add_action('wp_logout', 'myEndSession');
1483add_action('wp_login', 'myEndSession');
1484function myStartSession() {
1485 global $wpdb; // hook the wp db
1486 if(!session_id()) { //if there's no session, start it
1487 @session_start();
1488 }
1489 if (!isset($_SESSION['auth_cfg'])) {
1490 //put config data for social auth in session variable, we do it once to reduce the site load on session construct
1491 $_SESSION['auth_cfg'] = social_createoptions();
1492 }
1493
1494 if (!isset($_SESSION['checkedtables'])) {
1495 check_table();
1496 }
1497 $table_name = $wpdb->prefix . "access_tokens";
1498 if (isset($_SESSION['social_login_new'])) {
1499 if (isset($_SESSION['social_user'])) {
1500 unset ($_SESSION['social_user']);
1501 }
1502 switch ($_SESSION['social_login_new']['provider']) {
1503 case "facebook":
1504 $provider = "facebook";
1505 break;
1506 case "twitter":
1507 $provider = "twitter";
1508 break;
1509 case "google":
1510 $provider = "google";
1511 break;
1512 }
1513 // provider and prefix set
1514 $numrows = $wpdb->get_results( "SELECT * FROM ". $table_name .' WHERE access_token_id = "'.$_SESSION['social_login_new']['id'].'" LIMIT 1');
1515 $_SESSION['social_user']['name'] = $_SESSION['social_login_new']['name'];
1516 $_SESSION['social_user']['firstName'] = $_SESSION['social_login_new']['firstName'];
1517 $_SESSION['social_user']['lastName'] = $_SESSION['social_login_new']['lastName'];
1518 $_SESSION['social_user']['photo'] = $_SESSION['social_login_new']['photo'];
1519 $_SESSION['social_user']['provider'] = $_SESSION['social_login_new']['provider'];
1520 if (count($numrows) != 0) {
1521 $_SESSION['social_user']['uid'] = $numrows[0]->uid;
1522 $db = $wpdb->query('UPDATE '.$table_name.' SET access_token = "'.$_SESSION['social_login_new']['token']['access_token'].'", access_token_session= "'.esc_sql($_SESSION['social_login_new']['sessiondata']).'", access_token_expires = "'.$_SESSION['social_login_new']['token']['expires_at'].'", access_token_name = "'.$_SESSION['social_login_new']['name'].'", access_token_photo = "'.$_SESSION['social_login_new']['photo'].'", access_token_id = "'.$_SESSION['social_login_new']['id'].'", access_token_provider = "'.$_SESSION['social_login_new']['provider'].'" WHERE uid = "'.$_SESSION['social_user']['uid'].'"'); //update db
1523 if (($_SESSION['social_login_new']['provider'] == "twitter") OR ($_SESSION['social_login_new']['provider'] == "tumblr") OR ($_SESSION['social_login_new']['provider'] == "google")) {
1524 $wpdb->query('UPDATE '.$table_name.' SET access_token_secret= "'.esc_sql($_SESSION['social_login_new']['token']['access_token_secret']).'" WHERE uid = "'.$_SESSION['social_user']['uid'].'"');
1525 }
1526 } else {
1527 $wpdb->insert($table_name, array("access_token"=>$_SESSION['social_login_new']['token']['access_token'], "access_token_expires" => $_SESSION['social_login_new']['token']['expires_at'], 'access_token_name' => $_SESSION['social_login_new']['name'], 'access_token_photo'=> $_SESSION['social_login_new']['photo'], "access_token_id" => $_SESSION['social_login_new']['id'], "access_token_session" => esc_sql($_SESSION['social_login_new']['sessiondata']), "access_token_provider" => $_SESSION['social_login_new']['provider'])); //update db
1528 $_SESSION['social_user']['uid'] = $wpdb->insert_id;
1529 if (($provider == "twitter") OR ($provider == "tumblr") OR ($provider == "linkedin")) {
1530 $wpdb->query('UPDATE '.$table_name.' SET '.$prefix.'_secret= "'.esc_sql($_SESSION['social_login_new']['token']['access_token_secret']).'" WHERE uid = "'.$_SESSION['social_user']['uid'].'"');
1531 }
1532 }
1533 do_the_login($_SESSION['social_user']['uid'] );
1534 //WE LOGGED IN HERE
1535 $_SESSION['needtorefresh'] = true;
1536 unset($_SESSION['social_login_new']); //everything done, remove the flag
1537
1538 $newuid = 10000 + $_SESSION['social_user']['uid'];
1539 $login = "socialuser"+ $_SESSION['social_user']['uid'];;
1540 $userobj = new WP_User();
1541 $user = $userobj->get_data_by( 'login', $login );
1542 $premium = get_user_meta( $user->ID, '_checkbox_premium_user', true);
1543 if ($premium == "yes") {
1544 $_SESSION['theuser']['premium'] = 1;
1545 } else {
1546 $_SESSION['theuser']['premium'] = 0;
1547 }
1548
1549 $current_photo = get_user_meta( $user->ID, 'profile_pic', true);
1550 if (strlen($current_photo) < 5) {
1551 update_user_meta($user->ID, 'profile_pic', $_SESSION['social_user']['photo']);
1552 }
1553
1554 }
1555
1556 if (isset($_SESSION['loggedout'])) {
1557 unset($_SESSION['loggedout']);
1558 wp_logout();
1559 $_SESSION['needtorefresh'] = true;
1560 }
1561
1562}
1563
1564
1565function do_the_login($uid) {
1566 //special uids set
1567 $newuid = 10000 + $uid;
1568 $login = "socialuser"+$uid;
1569 // External user exists, try to load the user info from the WordPress user table
1570 $userobj = new WP_User();
1571 $user = $userobj->get_data_by( 'login', $login ); // Does not return a WP_User object <img src="http://ben.lobaugh.net/blog/wp-includes/images/smilies/icon_sad.gif" alt=":(" class="wp-smiley" />
1572 $user = new WP_User($user->ID); // Attempt to load up the user with that ID
1573 if( $user->ID == 0 ) {
1574 // The user does not currently exist in the WordPress user table.
1575 // You have arrived at a fork in the road, choose your destiny wisely
1576
1577 // If you do not want to add new users to WordPress if they do not
1578 // already exist uncomment the following line and remove the user creation code
1579 //$user = new WP_Error( 'denied', esc_html__("<strong>ERROR</strong>: Not a valid user for this system") );
1580
1581 // Setup the minimum required user information for this example
1582 $userdata = array( 'user_email' => $newuid."@randomsocialuser.rnd",
1583 'user_login' => $login,
1584 'nickname' => $_SESSION['social_user']['name'],
1585 'first_name' =>$_SESSION['social_user']['firstName'],
1586 'last_name' =>$_SESSION['social_user']['lastName'],
1587 'display_name' => $_SESSION['social_user']['name'],
1588 'rich_editing' => true,
1589 'role' => 'contributor'
1590 );
1591 $new_user_id = wp_insert_user( $userdata ); // A new user has been created
1592
1593 // Load the new user info
1594 $user = new WP_User ($new_user_id);
1595 $user->add_cap( 'upload_files');
1596 $user->add_cap( 'read');
1597 $user->add_cap( 'edit_posts');
1598 $user->add_cap( 'edit_published_pages');
1599 $user->add_cap( 'edit_others_pages');
1600 $user->add_cap( 'level_0');
1601 $user->add_cap( 'level_1');
1602 $user->add_cap('delete_page');
1603 $premium = add_user_meta($user->ID , '_checkbox_premium_user', 'no');
1604 } else {
1605 $userdata = array( 'ID' => $user->ID,
1606 'rich_editing' => true,
1607 'role' => 'contributor'
1608 );
1609 $role = get_role( 'contributor' ); // gets the author role
1610 $role->add_cap('delete_posts'); // delete own posts
1611 $role->add_cap('delete_project'); // delete own posts
1612 $new_user_id = wp_update_user($userdata);
1613 $user = new WP_User ($new_user_id);
1614 }
1615
1616 wp_set_current_user( $user->ID, $user->user_login );
1617 wp_set_auth_cookie( $user->ID );
1618
1619
1620 return $user;
1621}
1622
1623/*ends session*/
1624function myEndSession() {
1625 session_destroy ();
1626}
1627
1628
1629
1630/***** plugin installation suggestion *****/
1631add_action( 'tgmpa_register', 'funding_register_required_plugins' );
1632function funding_register_required_plugins() {
1633 /**
1634 * Array of plugin arrays. Required keys are name and slug.
1635 * If the source is NOT from the .org repo, then source is also required.
1636 */
1637 $plugins = array(
1638 // This is an example of how to include a plugin pre-packaged with a theme
1639 array(
1640 'name' => 'LayerSlider', // The plugin name
1641 'slug' => 'LayerSlider', // The plugin slug (typically the folder name)
1642 'source' => 'http://skywarriorthemes.com/plugins/layerslider.zip', // The plugin source
1643 'required' => false, // If false, the plugin is only 'recommended' instead of required
1644 'version' => '', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
1645 'force_activation' => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
1646 'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
1647 'external_url' => '', // If set, overrides default API URL and points to an external URL
1648 ),
1649 );
1650 // Change this to your theme text domain, used for internationalising strings
1651 $theme_text_domain = 'funding';
1652 /**
1653 * Array of configuration settings. Amend each line as needed.
1654 * If you want the default strings to be available under your own theme domain,
1655 * leave the strings uncommented.
1656 * Some of the strings are added into a sprintf, so see the comments at the
1657 * end of each line for what each argument will be.
1658 */
1659 $config = array(
1660 'domain' => $theme_text_domain, // Text domain - likely want to be the same as your theme.
1661 'default_path' => '', // Default absolute path to pre-packaged plugins
1662 'parent_menu_slug' => 'themes.php', // Default parent menu slug
1663 'parent_url_slug' => 'themes.php', // Default parent URL slug
1664 'menu' => 'install-required-plugins', // Menu slug
1665 'has_notices' => true, // Show admin notices or not
1666 'is_automatic' => true, // Automatically activate plugins after installation or not
1667 'message' => '', // Message to output right before the plugins table
1668 'strings' => array(
1669 'page_title' => esc_html__( 'Install Required Plugins', 'funding' ),
1670 'menu_title' => esc_html__( 'Install Plugins', 'funding' ),
1671 'installing' => esc_html__( 'Installing Plugin: %s', 'funding' ), // %1$s = plugin name
1672 'oops' => esc_html__( 'Something went wrong with the plugin API.', 'funding' ),
1673 'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'funding' ), // %1$s = plugin name(s)
1674 'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'funding' ), // %1$s = plugin name(s)
1675 'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'funding' ), // %1$s = plugin name(s)
1676 'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.' , 'funding'), // %1$s = plugin name(s)
1677 'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'funding' ), // %1$s = plugin name(s)
1678 'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'funding' ), // %1$s = plugin name(s)
1679 'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'funding' ), // %1$s = plugin name(s)
1680 'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'funding' ), // %1$s = plugin name(s)
1681 'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'funding' ),
1682 'activate_link' => _n_noop( 'Activate installed plugin', 'Activate installed plugins', 'funding' ),
1683 'return' => esc_html__( 'Return to Required Plugins Installer', 'funding' ),
1684 'plugin_activated' => esc_html__( 'Plugin activated successfully.', 'funding' ),
1685 'complete' => esc_html__( 'All plugins installed and activated successfully. %s', 'funding' ), // %1$s = dashboard link
1686 'nag_type' => 'updated' // Determines admin notice type - can only be 'updated' or 'error'
1687 )
1688 );
1689 tgmpa( $plugins, $config );
1690}
1691
1692
1693
1694/***** Get post for ajax currency *****/
1695add_action( 'wp_ajax_nopriv_return_currency', 'return_currency' );
1696add_action( 'wp_ajax_return_currency', 'return_currency' );
1697function return_currency () {
1698
1699 global $f_currency_signs;
1700 $cur_id = $_POST[ 'curr' ];
1701 echo esc_attr($f_currency_signs[$cur_id]);
1702 die(1);
1703}
1704
1705
1706/***** Get post for ajax category *****/
1707add_action( 'wp_ajax_nopriv_load-filter', 'prefix_load_cat_posts' );
1708add_action( 'wp_ajax_load-filter', 'prefix_load_cat_posts' );
1709function prefix_load_cat_posts () {
1710
1711 global $post;
1712 $cat_id = $_POST[ 'cat' ];
1713 $term = get_term( $cat_id, 'project-category' );
1714 $args = array (
1715 'showposts' => -1,
1716 'post_type' => 'project',
1717 'orderby' => 'post_date',
1718 'post_status' => 'publish',
1719 'tax_query' => array(
1720 array(
1721 'taxonomy' => 'project-category',
1722 'field' => 'id',
1723 'terms' => $term->term_id
1724 )
1725 ));
1726 $posts = get_posts($args);
1727
1728 ob_start ();
1729if( $_SESSION['displ'] == 1){ //////////////////////////latest
1730
1731 foreach ( $posts as $post ) {
1732 global $post;
1733 global $f_currency_signs;
1734 $project_settings = (array) get_post_meta($post->ID, 'settings', true);
1735
1736 if(get_option('date_format') == 'm/d/Y' && strtotime($project_settings['date']) != false){
1737 $array = explode('/', $project_settings['date']);
1738 $tmp = $array[0];
1739 $array[0] = $array[1];
1740 $array[1] = $tmp;
1741 unset($tmp);
1742 if($array[0] == NULL){
1743 $project_settings['date'] = $array[1];
1744 }else{
1745 $project_settings['date'] = implode('/', $array);
1746 }
1747 }
1748
1749 if(get_option('date_format') == 'd/m/Y' && strtotime($project_settings['date']) != false){
1750 $array = explode('/', $project_settings['date']);
1751 $tmp = $array[0];
1752 $array[0] = $array[1];
1753 $array[1] = $tmp;
1754 unset($tmp);
1755 if($array[0] == NULL){
1756 $project_settings['date'] = $array[1];
1757 }else{
1758 $project_settings['date'] = implode('/', $array);
1759 }
1760 }
1761
1762
1763
1764
1765 if (strpos( $project_settings['date'] , "/") !== false) {
1766 $parseddate = str_replace('/' , '.' , $project_settings['date']);
1767 }else{
1768 $parseddate = $project_settings['date'];
1769 }
1770 $project_expired = strtotime($parseddate) < time();
1771 $project_currency_sign = $f_currency_signs[$project_settings['currency']];
1772 $target= $project_settings['target'];
1773 $rewards = get_children(array(
1774 'post_parent' => $post->ID,
1775 'post_type' => 'reward',
1776 'order' => 'ASC',
1777 'orderby' => 'meta_value_num',
1778 'meta_key' => 'funding_amount',
1779 ));
1780 $funders = array();
1781 $funded_amount = 0;
1782 $chosen_reward = null;
1783 foreach($rewards as $this_reward){
1784 $these_funders = get_children(array(
1785 'post_parent' => $this_reward->ID,
1786 'post_type' => 'funder',
1787 'post_status' => 'publish'
1788 ));
1789 foreach($these_funders as $this_funder){
1790 $funding_amount = get_post_meta($this_funder->ID, 'funding_amount', true);
1791 $funders[] = $this_funder;
1792 $funded_amount += $funding_amount;
1793 }
1794 }
1795 if(empty($target) or $target == 0){$target = 1;}
1796 setup_postdata( $post );?>
1797 <div id="post-<?php echo esc_attr($post->ID); ?> <?php post_class(); ?>>
1798 <?php if(has_post_thumbnail()){
1799 $thumb = get_post_thumbnail_id();
1800 $img_url = wp_get_attachment_url( $thumb,'full'); //get img URL
1801 $image = aq_resize( $img_url, 311, 210, true, '', true ); //resize & crop img
1802 ?>
1803 <div class="project-thumb-wrapper"><a href="<?php the_permalink(); ?>"><img src="<?php echo esc_url($image[0]); ?>" /></a></div>
1804 <?php
1805 }else{ ?>
1806 <div class="project-thumb-wrapper"><a href="<?php the_permalink(); ?>"><img class="pbimage" src="<?php echo esc_url(get_template_directory_uri()); ?>/img/defaults/default_project.jpg"></a></div>
1807 <?php } ?>
1808 <div class="category-container">
1809 <h3 class="posttitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
1810 <div class="post-author">
1811 <?php if(get_the_author_meta('first_name',get_the_author_meta('ID'))){ ?><?php esc_html_e('by ','funding');?> <a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>"><?php echo esc_attr(get_the_author_meta('first_name',get_the_author_meta('ID'))); ?></a><?php } ?>
1812
1813 </div>
1814 <div id="post-content">
1815 <?php $excerpt = get_the_excerpt();
1816 echo mb_substr($excerpt, 0,200);echo '...'; ?>
1817
1818 <p><?php $term_list = wp_get_post_terms($post->ID, 'project-category');
1819 if(!empty($term_list)){ ?><span class="icon-tag" ></span> <?php } $lastElement = end($term_list); foreach ( $term_list as $cat ) {?>
1820 <a id="click" class="<?php echo esc_attr($cat->slug); ?> ajax" href="<?php echo esc_url(get_term_link( $cat )); ?>" ><?php echo esc_attr($cat->name); ?></a>
1821 <?php if($cat != $lastElement){echo ', ';} } ?>
1822 <?php if(usercountry_name_display(get_the_author_meta( 'ID' )) != '' || get_the_author_meta('city', get_the_author_meta( 'ID' )) != ''){ ?>
1823 <span class="icon-map-marker" ></span> <b><?php echo esc_attr(usercountry_name_display(get_the_author_meta( 'ID' )));?></b>
1824 <?php if(get_the_author_meta('city', get_the_author_meta( 'ID' )) != ''){ echo ', '; } ?>
1825 <?php if ( get_the_author_meta('city', get_the_author_meta( 'ID' )) ) {echo esc_attr(get_the_author_meta('city',get_the_author_meta( 'ID' ))); } ?>
1826 <?php } ?>
1827 </p>
1828
1829 <?php if($funded_amount == $target or $funded_amount > $target){ ?>
1830 <div class="project-successful">
1831 <strong><?php esc_html_e('Successful!', 'funding') ?></strong>
1832 </div>
1833 <?php }elseif($project_expired){ ?>
1834 <div class="project-unsuccessful">
1835 <strong><?php esc_html_e('Unsuccessful!', 'funding') ?></strong>
1836 </div>
1837 <?php }else{ ?>
1838 <div class="progress progress-striped active bar-green"><div style="width: <?php printf(esc_html__('%u%', 'funding'), round($funded_amount/$target*100), $project_currency_sign, round($target)) ?>%" class="bar"></div></div>
1839 <?php } ?>
1840 <ul class="project-stats">
1841 <li class="first funded">
1842 <strong><?php printf(esc_html__('%u%%', 'funding'), round($funded_amount/$target*100), $project_currency_sign, number_format(round((int)$target), 0, '.', ',')) ?></strong><?php esc_html_e("funded", 'funding'); ?>
1843 </li>
1844 <li class="pledged">
1845 <strong>
1846 <?php print $project_currency_sign; print number_format(round((int)$target), 0, '.', ',');?></strong><?php esc_html_e("target", 'funding'); ?>
1847 </li>
1848 <li data-end_time="2013-02-24T08:41:18Z" class="last ksr_page_timer">
1849 <?php if(!$project_expired) : ?>
1850 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?> <strong> <?php esc_html_e('< 24', 'funding'); ?></strong> <?php }else{ ?>
1851 <strong><?php print F_Controller::timesince(time(), strtotime($parseddate), 1, ''); } ?></strong>
1852 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?>
1853 <?php esc_html_e('hours to go', 'funding'); ?>
1854 <?php }else{ ?>
1855 <?php if(F_Controller::timesince(time(), strtotime($parseddate), 1, '') == 1){ ?>
1856 <?php esc_html_e('day to go', 'funding'); ?>
1857 <?php }else{ ?>
1858 <?php esc_html_e('days to go', 'funding'); ?>
1859 <?php } ?>
1860
1861
1862 <?php } ?>
1863 <?php endif; ?>
1864 </li>
1865 </ul>
1866 <a class="edit-button button-small button-green" href="<?php echo get_permalink( get_page_by_path( 'all-games' ) ); ?>"><?php esc_html_e("View All Games", 'funding'); ?></a>
1867 </div> <!--post-content -->
1868 </div> <!-- category-container -->
1869 <?php
1870 break; }
1871 wp_reset_postdata();
1872 $response = ob_get_contents();
1873 ob_end_clean();
1874 echo $response;
1875 die(1);
1876 unset($_SESSION['displ']);
1877}elseif($_SESSION['displ'] == 2){ ///////////////////////////////////staff
1878
1879 foreach ( $posts as $post ) {
1880 global $post;
1881 global $f_currency_signs;
1882 $project_settings = (array) get_post_meta($post->ID, 'settings', true);
1883
1884 if(get_option('date_format') == 'm/d/Y' && strtotime($project_settings['date']) != false){
1885 $array = explode('/', $project_settings['date']);
1886 $tmp = $array[0];
1887 $array[0] = $array[1];
1888 $array[1] = $tmp;
1889 unset($tmp);
1890 if($array[0] == NULL){
1891 $project_settings['date'] = $array[1];
1892 }else{
1893 $project_settings['date'] = implode('/', $array);
1894 }
1895 }
1896
1897 if(get_option('date_format') == 'd/m/Y' && strtotime($project_settings['date']) != false){
1898 $array = explode('/', $project_settings['date']);
1899 $tmp = $array[0];
1900 $array[0] = $array[1];
1901 $array[1] = $tmp;
1902 unset($tmp);
1903 if($array[0] == NULL){
1904 $project_settings['date'] = $array[1];
1905 }else{
1906 $project_settings['date'] = implode('/', $array);
1907 }
1908 }
1909
1910
1911 if (strpos( $project_settings['date'] , "/") !== false) {
1912 $parseddate = str_replace('/' , '.' , $project_settings['date']);
1913 }else{
1914 $parseddate = $project_settings['date'];
1915 }
1916 $project_expired = strtotime($parseddate) < time();
1917 $project_currency_sign = $f_currency_signs[$project_settings['currency']];
1918 $target= $project_settings['target'];
1919 $rewards = get_children(array(
1920 'post_parent' => $post->ID,
1921 'post_type' => 'reward',
1922 'order' => 'ASC',
1923 'orderby' => 'meta_value_num',
1924 'meta_key' => 'funding_amount',
1925 ));
1926 $funders = array();
1927 $funded_amount = 0;
1928 $chosen_reward = null;
1929 foreach($rewards as $this_reward){
1930 $these_funders = get_children(array(
1931 'post_parent' => $this_reward->ID,
1932 'post_type' => 'funder',
1933 'post_status' => 'publish'
1934 ));
1935 foreach($these_funders as $this_funder){
1936 $funding_amount = get_post_meta($this_funder->ID, 'funding_amount', true);
1937 $funders[] = $this_funder;
1938 $funded_amount += $funding_amount;
1939 }
1940 }
1941 if(empty($target) or $target == 0){$target = 1;}
1942
1943 if(get_post_meta($post->ID, '_smartmeta_staff-check-field', true) == 'true'){
1944 setup_postdata( $post );?>
1945 <div id="post-<?php echo esc_attr($post->ID); ?> <?php post_class(); ?>>
1946 <?php if(has_post_thumbnail()){
1947 $thumb = get_post_thumbnail_id();
1948 $img_url = wp_get_attachment_url( $thumb,'full'); //get img URL
1949 $image = aq_resize( $img_url, 311, 210, true, '', true ); //resize & crop img
1950 ?>
1951 <div class="project-thumb-wrapper"><a href="<?php the_permalink(); ?>"><img src="<?php echo esc_url($image[0]); ?>" /></a></div>
1952 <?php
1953 }else{ ?>
1954 <div class="project-thumb-wrapper"><a href="<?php the_permalink(); ?>"><img class="pbimage" src="<?php echo esc_url(get_template_directory_uri()); ?>/img/defaults/default_project.jpg"></a></div>
1955 <?php } ?>
1956 <div class="category-container">
1957 <h3 class="posttitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
1958 <div class="post-author">
1959 <?php if(get_the_author_meta('first_name',get_the_author_meta('ID'))){ ?><?php esc_html_e('by ','funding');?> <a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>"><?php echo esc_attr(get_the_author_meta('first_name',get_the_author_meta('ID'))); ?></a><?php } ?>
1960
1961 </div>
1962 <div id="post-content">
1963 <?php $excerpt = get_the_excerpt();
1964 echo mb_substr($excerpt, 0,200);echo '...'; ?>
1965
1966 <p><?php $term_list = wp_get_post_terms($post->ID, 'project-category');
1967 if(!empty($term_list)){ ?><span class="icon-tag" ></span> <?php } $lastElement = end($term_list); foreach ( $term_list as $cat ) {?>
1968 <a id="click" class="<?php echo esc_attr($cat->slug); ?> ajax" href="<?php echo esc_url(get_term_link( $cat )); ?>" ><?php echo esc_attr($cat->name); ?></a>
1969 <?php if($cat != $lastElement){echo ', ';} } ?>
1970 <?php if(usercountry_name_display(get_the_author_meta( 'ID' )) != '' || get_the_author_meta('city', get_the_author_meta( 'ID' )) != ''){ ?>
1971 <span class="icon-map-marker" ></span> <b><?php echo esc_attr(usercountry_name_display(get_the_author_meta( 'ID' )));?></b>
1972 <?php if(get_the_author_meta('city', get_the_author_meta( 'ID' )) != ''){ echo ', '; } ?>
1973 <?php if ( get_the_author_meta('city', get_the_author_meta( 'ID' )) ) {echo esc_attr(get_the_author_meta('city',get_the_author_meta( 'ID' ))); } ?>
1974 <?php } ?>
1975 </p>
1976
1977 <?php if($funded_amount == $target or $funded_amount > $target){ ?>
1978 <div class="project-successful">
1979 <strong><?php esc_html_e('Successful!', 'funding') ?></strong>
1980 </div>
1981 <?php }elseif($project_expired){ ?>
1982 <div class="project-unsuccessful">
1983 <strong><?php esc_html_e('Unsuccessful!', 'funding') ?></strong>
1984 </div>
1985 <?php }else{ ?>
1986 <div class="progress progress-striped active bar-green"><div style="width: <?php printf(esc_html__('%u%', 'funding'), round($funded_amount/$target*100), $project_currency_sign, round($target)) ?>%" class="bar"></div></div>
1987 <?php } ?>
1988 <ul class="project-stats">
1989 <li class="first funded">
1990 <strong><?php printf(esc_html__('%u%%', 'funding'), round($funded_amount/$target*100), $project_currency_sign, number_format(round((int)$target), 0, '.', ',')) ?></strong><?php esc_html_e("funded", 'funding'); ?>
1991 </li>
1992 <li class="pledged">
1993 <strong>
1994 <?php print $project_currency_sign; print number_format(round((int)$target), 0, '.', ',');?></strong><?php esc_html_e("target", 'funding'); ?>
1995 </li>
1996 <li data-end_time="2013-02-24T08:41:18Z" class="last ksr_page_timer">
1997 <?php if(!$project_expired) : ?>
1998 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?> <strong> <?php esc_html_e('< 24', 'funding'); ?></strong> <?php }else{ ?>
1999 <strong><?php print F_Controller::timesince(time(), strtotime($parseddate), 1, ''); } ?></strong>
2000 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?>
2001 <?php esc_html_e('hours to go', 'funding'); ?>
2002 <?php }else{ ?>
2003 <?php if(F_Controller::timesince(time(), strtotime($parseddate), 1, '') == 1){ ?>
2004 <?php esc_html_e('day to go', 'funding'); ?>
2005 <?php }else{ ?>
2006 <?php esc_html_e('days to go', 'funding'); ?>
2007 <?php } ?>
2008
2009
2010 <?php } ?>
2011 <?php endif; ?>
2012 </li>
2013 </ul>
2014 <a class="edit-button button-small button-green" href="<?php echo get_permalink( get_page_by_path( 'all-games' ) ); ?>"><?php esc_html_e("View All Games", 'funding'); ?></a>
2015 </div> <!--post-content -->
2016 </div> <!-- category-container -->
2017 <?php
2018 break;
2019 }} wp_reset_postdata();
2020 $response = ob_get_contents();
2021 ob_end_clean();
2022 echo $response;
2023 die(1);
2024 unset($_SESSION['displ']);
2025
2026}elseif($_SESSION['displ'] == 3){ ///////////////////////////////////featured
2027 foreach ( $posts as $post ) {
2028 global $post;
2029 setup_postdata( $post );
2030
2031 if(get_post_meta($post->ID, '_smartmeta_featured', true) == 'true'){
2032 global $post;
2033 global $f_currency_signs;
2034 $project_settings = (array) get_post_meta($post->ID, 'settings', true);
2035
2036 if(get_option('date_format') == 'm/d/Y' && strtotime($project_settings['date']) != false){
2037 $array = explode('/', $project_settings['date']);
2038 $tmp = $array[0];
2039 $array[0] = $array[1];
2040 $array[1] = $tmp;
2041 unset($tmp);
2042 if($array[0] == NULL){
2043 $project_settings['date'] = $array[1];
2044 }else{
2045 $project_settings['date'] = implode('/', $array);
2046 }
2047 }
2048
2049 if(get_option('date_format') == 'd/m/Y' && strtotime($project_settings['date']) != false){
2050 $array = explode('/', $project_settings['date']);
2051 $tmp = $array[0];
2052 $array[0] = $array[1];
2053 $array[1] = $tmp;
2054 unset($tmp);
2055 if($array[0] == NULL){
2056 $project_settings['date'] = $array[1];
2057 }else{
2058 $project_settings['date'] = implode('/', $array);
2059 }
2060 }
2061
2062
2063
2064 if (strpos( $project_settings['date'] , "/") !== false) {
2065 $parseddate = str_replace('/' , '.' , $project_settings['date']);
2066 }else{
2067 $parseddate = $project_settings['date'];
2068 }
2069 $project_expired = strtotime($parseddate) < time();
2070 $project_currency_sign = $f_currency_signs[$project_settings['currency']];
2071 $target= $project_settings['target'];
2072 $rewards = get_children(array(
2073 'post_parent' => $post->ID,
2074 'post_type' => 'reward',
2075 'order' => 'ASC',
2076 'orderby' => 'meta_value_num',
2077 'meta_key' => 'funding_amount',
2078 ));
2079 $funders = array();
2080 $funded_amount = 0;
2081 $chosen_reward = null;
2082 foreach($rewards as $this_reward){
2083 $these_funders = get_children(array(
2084 'post_parent' => $this_reward->ID,
2085 'post_type' => 'funder',
2086 'post_status' => 'publish'
2087 ));
2088 foreach($these_funders as $this_funder){
2089 $funding_amount = get_post_meta($this_funder->ID, 'funding_amount', true);
2090 $funders[] = $this_funder;
2091 $funded_amount += $funding_amount;
2092 }
2093 }
2094 if(empty($target) or $target == 0){$target = 1;} ?>
2095
2096 <div id="post-<?php echo esc_attr($post->ID); ?> <?php post_class(); ?>>
2097 <?php if(has_post_thumbnail()){
2098 $thumb = get_post_thumbnail_id();
2099 $img_url = wp_get_attachment_url( $thumb,'full'); //get img URL
2100 $image = aq_resize( $img_url, 311, 210, true, '', true ); //resize & crop img
2101 ?>
2102 <div class="project-thumb-wrapper"><a href="<?php the_permalink(); ?>"><img src="<?php echo esc_url($image[0]); ?>" /></a></div>
2103 <?php
2104 }else{ ?>
2105 <div class="project-thumb-wrapper"><a href="<?php the_permalink(); ?>"><img class="pbimage" src="<?php echo esc_url(get_template_directory_uri()); ?>/img/defaults/default_project.jpg"></a></div>
2106 <?php } ?>
2107 <div class="category-container">
2108 <h3 class="posttitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
2109 <div class="post-author">
2110 <?php if(get_the_author_meta('first_name',get_the_author_meta('ID'))){ ?><?php esc_html_e('by ','funding');?> <a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>"><?php echo esc_attr(get_the_author_meta('first_name',get_the_author_meta('ID'))); ?></a><?php } ?>
2111
2112 </div>
2113 <div id="post-content">
2114 <?php $excerpt = get_the_excerpt();
2115 echo mb_substr($excerpt, 0,200);echo '...'; ?>
2116
2117 <p><?php $term_list = wp_get_post_terms($post->ID, 'project-category');
2118 if(!empty($term_list)){ ?><span class="icon-tag" ></span> <?php } $lastElement = end($term_list); foreach ( $term_list as $cat ) {?>
2119 <a id="click" class="<?php echo esc_attr($cat->slug); ?> ajax" href="<?php echo esc_url(get_term_link( $cat )); ?>" ><?php echo esc_attr($cat->name); ?></a>
2120 <?php if($cat != $lastElement){echo ', ';} } ?>
2121 <?php if(usercountry_name_display(get_the_author_meta( 'ID' )) != '' || get_the_author_meta('city', get_the_author_meta( 'ID' )) != ''){ ?>
2122 <span class="icon-map-marker" ></span> <b><?php echo esc_attr(usercountry_name_display(get_the_author_meta( 'ID' )));?></b>
2123 <?php if(get_the_author_meta('city', get_the_author_meta( 'ID' )) != ''){ echo ', '; } ?>
2124 <?php if ( get_the_author_meta('city', get_the_author_meta( 'ID' )) ) {echo esc_attr(get_the_author_meta('city',get_the_author_meta( 'ID' ))); } ?>
2125 <?php } ?>
2126 </p>
2127
2128 <?php if($funded_amount == $target or $funded_amount > $target){ ?>
2129 <div class="project-successful">
2130 <strong><?php esc_html_e('Successful!', 'funding') ?></strong>
2131 </div>
2132 <?php }elseif($project_expired){ ?>
2133 <div class="project-unsuccessful">
2134 <strong><?php esc_html_e('Unsuccessful!', 'funding') ?></strong>
2135 </div>
2136 <?php }else{ ?>
2137 <div class="progress progress-striped active bar-green"><div style="width: <?php printf(esc_html__('%u%', 'funding'), round($funded_amount/$target*100), $project_currency_sign, round($target)) ?>%" class="bar"></div></div>
2138 <?php } ?>
2139 <ul class="project-stats">
2140 <li class="first funded">
2141 <strong><?php printf(esc_html__('%u%%', 'funding'), round($funded_amount/$target*100), $project_currency_sign, number_format(round((int)$target), 0, '.', ',')) ?></strong><?php esc_html_e("funded", 'funding'); ?>
2142 </li>
2143 <li class="pledged">
2144 <strong>
2145 <?php print $project_currency_sign; print number_format(round((int)$target), 0, '.', ',');?></strong><?php esc_html_e("target", 'funding'); ?>
2146 </li>
2147 <li data-end_time="2013-02-24T08:41:18Z" class="last ksr_page_timer">
2148 <?php if(!$project_expired) : ?>
2149 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?> <strong> <?php esc_html_e('< 24', 'funding'); ?></strong> <?php }else{ ?>
2150 <strong><?php print F_Controller::timesince(time(), strtotime($parseddate), 1, ''); } ?></strong>
2151 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?>
2152 <?php esc_html_e('hours to go', 'funding'); ?>
2153 <?php }else{ ?>
2154 <?php if(F_Controller::timesince(time(), strtotime($parseddate), 1, '') == 1){ ?>
2155 <?php esc_html_e('day to go', 'funding'); ?>
2156 <?php }else{ ?>
2157 <?php esc_html_e('days to go', 'funding'); ?>
2158 <?php } ?>
2159
2160
2161 <?php } ?>
2162 <?php endif; ?>
2163 </li>
2164 </ul>
2165 <a class="edit-button button-small button-green" href="<?php echo get_permalink( get_page_by_path( 'all-games' ) ); ?>"><?php esc_html_e("View All Games", 'funding'); ?></a>
2166 </div> <!--post-content -->
2167 </div> <!-- category-container -->
2168
2169 <?php
2170 }break; }
2171 wp_reset_postdata();
2172 $response = ob_get_contents();
2173 ob_end_clean();
2174 echo $response;
2175 die(1);
2176 unset($_SESSION['displ']);
2177}elseif($_SESSION['displ'] == 4){ ////////////////////////////////////sucessful
2178?>
2179 <?php foreach ( $posts as $post ) {
2180
2181 global $post;
2182 setup_postdata( $post );
2183 global $f_currency_signs;
2184 $project_settings = (array) get_post_meta($post->ID, 'settings', true);
2185
2186 if(get_option('date_format') == 'm/d/Y' && strtotime($project_settings['date']) != false){
2187 $array = explode('/', $project_settings['date']);
2188 $tmp = $array[0];
2189 $array[0] = $array[1];
2190 $array[1] = $tmp;
2191 unset($tmp);
2192 if($array[0] == NULL){
2193 $project_settings['date'] = $array[1];
2194 }else{
2195 $project_settings['date'] = implode('/', $array);
2196 }
2197 }
2198
2199
2200 if(get_option('date_format') == 'd/m/Y' && strtotime($project_settings['date']) != false){
2201 $array = explode('/', $project_settings['date']);
2202 $tmp = $array[0];
2203 $array[0] = $array[1];
2204 $array[1] = $tmp;
2205 unset($tmp);
2206 if($array[0] == NULL){
2207 $project_settings['date'] = $array[1];
2208 }else{
2209 $project_settings['date'] = implode('/', $array);
2210 }
2211 }
2212
2213
2214
2215 if (strpos( $project_settings['date'] , "/") !== false) {
2216 $parseddate = str_replace('/' , '.' , $project_settings['date']);
2217 }else{
2218 $parseddate = $project_settings['date'];
2219 }
2220 $project_expired = strtotime($parseddate) < time();
2221 $project_currency_sign = $f_currency_signs[$project_settings['currency']];
2222 $target= $project_settings['target'];
2223 $rewards = get_children(array(
2224 'post_parent' => $post->ID,
2225 'post_type' => 'reward',
2226 'order' => 'ASC',
2227 'orderby' => 'meta_value_num',
2228 'meta_key' => 'funding_amount',
2229 ));
2230 $funders = array();
2231 $funded_amount = 0;
2232 $chosen_reward = null;
2233 foreach($rewards as $this_reward){
2234 $these_funders = get_children(array(
2235 'post_parent' => $this_reward->ID,
2236 'post_type' => 'funder',
2237 'post_status' => 'publish'
2238 ));
2239 foreach($these_funders as $this_funder){
2240 $funding_amount = get_post_meta($this_funder->ID, 'funding_amount', true);
2241 $funders[] = $this_funder;
2242 $funded_amount += $funding_amount;
2243 }
2244 }
2245 if(empty($target) or $target == 0){$target = 1;}
2246
2247
2248 if($funded_amount == $target or $funded_amount > $target){?>
2249 <div id="post-<?php echo esc_attr($post->ID); ?> <?php post_class(); ?>>
2250 <?php if(has_post_thumbnail()){
2251 $thumb = get_post_thumbnail_id();
2252 $img_url = wp_get_attachment_url( $thumb,'full'); //get img URL
2253 $image = aq_resize( $img_url, 311, 210, true, '', true ); //resize & crop img
2254 ?>
2255 <div class="project-thumb-wrapper"><a href="<?php the_permalink(); ?>"><img src="<?php echo esc_url($image[0]); ?>" /></a></div>
2256 <?php
2257 }else{ ?>
2258 <div class="project-thumb-wrapper"><a href="<?php the_permalink(); ?>"><img class="pbimage" src="<?php echo esc_url(get_template_directory_uri()); ?>/img/defaults/default_project.jpg"></a></div>
2259 <?php } ?>
2260 <div class="category-container">
2261 <h3 class="posttitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
2262 <div class="post-author">
2263 <?php if(get_the_author_meta('first_name',get_the_author_meta('ID'))){ ?><?php esc_html_e('by ','funding');?> <a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>"><?php echo esc_attr(get_the_author_meta('first_name',get_the_author_meta('ID'))); ?></a><?php } ?>
2264
2265 </div>
2266 <div id="post-content">
2267 <?php $excerpt = get_the_excerpt();
2268 echo mb_substr($excerpt, 0,200);echo '...'; ?>
2269
2270 <p><?php $term_list = wp_get_post_terms($post->ID, 'project-category');
2271 if(!empty($term_list)){ ?><span class="icon-tag" ></span> <?php } $lastElement = end($term_list); foreach ( $term_list as $cat ) {?>
2272 <a id="click" class="<?php echo esc_attr($cat->slug); ?> ajax" href="<?php echo esc_url(get_term_link( $cat )); ?>" ><?php echo esc_attr($cat->name); ?></a>
2273 <?php if($cat != $lastElement){echo ', ';} } ?>
2274 <?php if(usercountry_name_display(get_the_author_meta( 'ID' )) != '' || get_the_author_meta('city', get_the_author_meta( 'ID' )) != ''){ ?>
2275 <span class="icon-map-marker" ></span> <b><?php echo esc_attr(usercountry_name_display(get_the_author_meta( 'ID' )));?></b>
2276 <?php if(get_the_author_meta('city', get_the_author_meta( 'ID' )) != ''){ echo ', '; } ?>
2277 <?php if ( get_the_author_meta('city', get_the_author_meta( 'ID' )) ) {echo esc_attr(get_the_author_meta('city',get_the_author_meta( 'ID' ))); } ?>
2278 <?php } ?>
2279 </p>
2280
2281 <?php if($funded_amount == $target or $funded_amount > $target){ ?>
2282 <div class="project-successful">
2283 <strong><?php esc_html_e('Successful!', 'funding') ?></strong>
2284 </div>
2285 <?php }elseif($project_expired){ ?>
2286 <div class="project-unsuccessful">
2287 <strong><?php esc_html_e('Unsuccessful!', 'funding') ?></strong>
2288 </div>
2289 <?php }else{ ?>
2290 <div class="progress progress-striped active bar-green"><div style="width: <?php printf(esc_html__('%u%', 'funding'), round($funded_amount/$target*100), $project_currency_sign, round($target)) ?>%" class="bar"></div></div>
2291 <?php } ?>
2292 <ul class="project-stats">
2293 <li class="first funded">
2294 <strong><?php printf(esc_html__('%u%%', 'funding'), round($funded_amount/$target*100), $project_currency_sign, number_format(round((int)$target), 0, '.', ',')) ?></strong><?php esc_html_e("funded", 'funding'); ?>
2295 </li>
2296 <li class="pledged">
2297 <strong>
2298 <?php print $project_currency_sign; print number_format(round((int)$target), 0, '.', ',');?></strong><?php esc_html_e("target", 'funding'); ?>
2299 </li>
2300 <li data-end_time="2013-02-24T08:41:18Z" class="last ksr_page_timer">
2301 <?php if(!$project_expired) : ?>
2302 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?> <strong> <?php esc_html_e('< 24', 'funding'); ?></strong> <?php }else{ ?>
2303 <strong><?php print F_Controller::timesince(time(), strtotime($parseddate), 1, ''); } ?></strong>
2304 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?>
2305 <?php esc_html_e('hours to go', 'funding'); ?>
2306 <?php }else{ ?>
2307 <?php if(F_Controller::timesince(time(), strtotime($parseddate), 1, '') == 1){ ?>
2308 <?php esc_html_e('day to go', 'funding'); ?>
2309 <?php }else{ ?>
2310 <?php esc_html_e('days to go', 'funding'); ?>
2311 <?php } ?>
2312
2313
2314 <?php } ?>
2315 <?php endif; ?>
2316 </li>
2317 </ul>
2318 <a class="edit-button button-small button-green" href="<?php echo get_permalink( get_page_by_path( 'all-games' ) ); ?>"><?php esc_html_e("View All Games", 'funding'); ?></a>
2319 </div> <!--post-content -->
2320 </div> <!-- category-container -->
2321 <?php break;
2322 }
2323 } wp_reset_postdata();
2324 $response = ob_get_contents();
2325 ob_end_clean();
2326 echo $response;
2327 die(1);
2328 unset($_SESSION['displ']);
2329}elseif($_SESSION['displ'] == 5){//////////////////////////////ending
2330
2331 global $post;
2332 $cat_id = $_POST[ 'cat' ];
2333 $term = get_term( $cat_id, 'project-category' );
2334 $args = array (
2335 'showposts' => -1,
2336 'post_type' => 'project',
2337 'orderby' => 'meta_value',
2338 'meta_key' => 'datum',
2339 'order' => 'ASC',
2340 'post_status' => 'publish',
2341 'project-category' => $term->slug,
2342 'meta_query' => array(
2343 array(
2344 'key' => 'datum',
2345 'value' => date(get_option('date_format'),time()),
2346 'compare' => '>=',
2347 ))
2348 );
2349 $posts = get_posts( $args );
2350 ob_start ();
2351 foreach ( $posts as $post ) {
2352 global $post;
2353 global $f_currency_signs;
2354 $project_settings = (array) get_post_meta($post->ID, 'settings', true);
2355
2356
2357 if(get_option('date_format') == 'm/d/Y' && strtotime($project_settings['date']) != false){
2358 $array = explode('/', $project_settings['date']);
2359 $tmp = $array[0];
2360 $array[0] = $array[1];
2361 $array[1] = $tmp;
2362 unset($tmp);
2363 if($array[0] == NULL){
2364 $project_settings['date'] = $array[1];
2365 }else{
2366 $project_settings['date'] = implode('/', $array);
2367 }
2368 }
2369
2370 if(get_option('date_format') == 'd/m/Y' && strtotime($project_settings['date']) != false){
2371 $array = explode('/', $project_settings['date']);
2372 $tmp = $array[0];
2373 $array[0] = $array[1];
2374 $array[1] = $tmp;
2375 unset($tmp);
2376 if($array[0] == NULL){
2377 $project_settings['date'] = $array[1];
2378 }else{
2379 $project_settings['date'] = implode('/', $array);
2380 }
2381 }
2382
2383
2384 if (strpos( $project_settings['date'] , "/") !== false) {
2385 $parseddate = str_replace('/' , '.' , $project_settings['date']);
2386 }else{
2387 $parseddate = $project_settings['date'];
2388 }
2389 $project_expired = strtotime($parseddate) < time();
2390 $project_currency_sign = $f_currency_signs[$project_settings['currency']];
2391 $target= $project_settings['target'];
2392 $rewards = get_children(array(
2393 'post_parent' => $post->ID,
2394 'post_type' => 'reward',
2395 'order' => 'ASC',
2396 'orderby' => 'meta_value_num',
2397 'meta_key' => 'funding_amount',
2398 ));
2399 $funders = array();
2400 $funded_amount = 0;
2401 $chosen_reward = null;
2402 foreach($rewards as $this_reward){
2403 $these_funders = get_children(array(
2404 'post_parent' => $this_reward->ID,
2405 'post_type' => 'funder',
2406 'post_status' => 'publish'
2407 ));
2408 foreach($these_funders as $this_funder){
2409 $funding_amount = get_post_meta($this_funder->ID, 'funding_amount', true);
2410 $funders[] = $this_funder;
2411 $funded_amount += $funding_amount;
2412 }
2413 }
2414
2415 if(empty($target) or $target == 0){$target = 1;}
2416 setup_postdata( $post );?>
2417 <div id="post-<?php echo esc_attr($post->ID); ?> <?php post_class(); ?>">
2418 <?php if(has_post_thumbnail()){
2419 $thumb = get_post_thumbnail_id();
2420 $img_url = wp_get_attachment_url( $thumb,'full'); //get img URL
2421 $image = aq_resize( $img_url, 311, 210, true, '', true ); //resize & crop img
2422 ?>
2423 <div class="project-thumb-wrapper"><a href="<?php the_permalink(); ?>"><img src="<?php echo esc_url($image[0]); ?>" /></a></div>
2424 <?php
2425 }else{ ?>
2426 <div class="project-thumb-wrapper"><a href="<?php the_permalink(); ?>"><img class="pbimage" src="<?php echo esc_url(get_template_directory_uri()); ?>/img/defaults/default_project.jpg"></a></div>
2427 <?php } ?>
2428 <div class="category-container">
2429 <h3 class="posttitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
2430 <div class="post-author">
2431 <?php if(get_the_author_meta('first_name',get_the_author_meta('ID'))){ ?><?php esc_html_e('by ','funding');?> <a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>"><?php echo esc_attr(get_the_author_meta('first_name',get_the_author_meta('ID'))); ?></a><?php } ?>
2432
2433 </div>
2434 <div id="post-content">
2435 <?php $excerpt = get_the_excerpt();
2436 echo mb_substr($excerpt, 0,200);echo '...'; ?>
2437
2438 <p><?php $term_list = wp_get_post_terms($post->ID, 'project-category');
2439 if(!empty($term_list)){ ?><span class="icon-tag" ></span> <?php } $lastElement = end($term_list); foreach ( $term_list as $cat ) {?>
2440 <a id="click" class="<?php echo esc_attr($cat->slug); ?> ajax" href="<?php echo esc_url(get_term_link( $cat )); ?>" ><?php echo esc_attr($cat->name); ?></a>
2441 <?php if($cat != $lastElement){echo ', ';} } ?>
2442 <?php if(usercountry_name_display(get_the_author_meta( 'ID' )) != '' || get_the_author_meta('city', get_the_author_meta( 'ID' )) != ''){ ?>
2443 <span class="icon-map-marker" ></span> <b><?php echo esc_attr(usercountry_name_display(get_the_author_meta( 'ID' )));?></b>
2444 <?php if(get_the_author_meta('city', get_the_author_meta( 'ID' )) != ''){ echo ', '; } ?>
2445 <?php if ( get_the_author_meta('city', get_the_author_meta( 'ID' )) ) {echo esc_attr(get_the_author_meta('city',get_the_author_meta( 'ID' ))); } ?>
2446 <?php } ?>
2447 </p>
2448
2449 <?php if($funded_amount == $target or $funded_amount > $target){ ?>
2450 <div class="project-successful">
2451 <strong><?php esc_html_e('Successful!', 'funding') ?></strong>
2452 </div>
2453 <?php }elseif($project_expired){ ?>
2454 <div class="project-unsuccessful">
2455 <strong><?php esc_html_e('Unsuccessful!', 'funding') ?></strong>
2456 </div>
2457 <?php }else{ ?>
2458 <div class="progress progress-striped active bar-green"><div style="width: <?php printf(esc_html__('%u%', 'funding'), round($funded_amount/$target*100), $project_currency_sign, round($target)) ?>%" class="bar"></div></div>
2459 <?php } ?>
2460 <ul class="project-stats">
2461 <li class="first funded">
2462 <strong><?php printf(esc_html__('%u%%', 'funding'), round($funded_amount/$target*100), $project_currency_sign, number_format(round((int)$target), 0, '.', ',')) ?></strong><?php esc_html_e("funded", 'funding'); ?>
2463 </li>
2464 <li class="pledged">
2465 <strong>
2466 <?php print $project_currency_sign; print number_format(round((int)$target), 0, '.', ',');?></strong><?php esc_html_e("target", 'funding'); ?>
2467 </li>
2468 <li data-end_time="2013-02-24T08:41:18Z" class="last ksr_page_timer">
2469 <?php if(!$project_expired) : ?>
2470 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?> <strong> <?php esc_html_e('< 24', 'funding'); ?></strong> <?php }else{ ?>
2471 <strong><?php print F_Controller::timesince(time(), strtotime($parseddate), 1, ''); } ?></strong>
2472 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?>
2473 <?php esc_html_e('hours to go', 'funding'); ?>
2474 <?php }else{ ?>
2475 <?php if(F_Controller::timesince(time(), strtotime($parseddate), 1, '') == 1){ ?>
2476 <?php esc_html_e('day to go', 'funding'); ?>
2477 <?php }else{ ?>
2478 <?php esc_html_e('days to go', 'funding'); ?>
2479 <?php } ?>
2480
2481
2482 <?php } ?>
2483 <?php endif; ?>
2484 </li>
2485 </ul>
2486 <a class="edit-button button-small button-green" href="<?php echo get_permalink( get_page_by_path( 'all-games' ) ); ?>"><?php esc_html_e("View All Games", 'funding'); ?></a>
2487 </div> <!--post-content -->
2488 </div> <!-- category-container -->
2489 <?php
2490 break;} wp_reset_postdata();
2491 $response = ob_get_contents();
2492 ob_end_clean();
2493 echo $response;
2494 die(1);
2495 unset($_SESSION['displ']);
2496}}
2497
2498
2499/********load campaigns with ajax in all projects page*****/
2500//get post for ajax category
2501add_action( 'wp_ajax_nopriv_load-filter-all', 'funding_prefix_load_cat_posts_all' );
2502add_action( 'wp_ajax_load-filter-all', 'funding_prefix_load_cat_posts_all' );
2503function funding_prefix_load_cat_posts_all() { ?>
2504<div class="isoprblckall">
2505 <?php
2506 global $post;
2507 $cat_id = $_POST[ 'cat' ];
2508 $term = get_term( $cat_id, 'project-category' );
2509 $args = array (
2510 'showposts' => -1,
2511 'post_type' => 'project',
2512 'orderby' => 'post_date',
2513 'post_status' => 'publish',
2514 'project-category' => $term->slug,
2515 );
2516 $posts = get_posts($args);
2517
2518 ob_start ();
2519
2520 foreach ( $posts as $post ) {
2521 global $post;
2522 global $f_currency_signs;
2523 $project_settings = (array) get_post_meta($post->ID, 'settings', true);
2524
2525
2526 if(get_option('date_format') == 'm/d/Y' && strtotime($project_settings['date']) != false){
2527 $array = explode('/', $project_settings['date']);
2528 $tmp = $array[0];
2529 if(!isset($array[1]))$array[1]='';
2530 $array[0] = $array[1];
2531 $array[1] = $tmp;
2532 unset($tmp);
2533 if($array[0] == NULL){
2534 $project_settings['date'] = $array[1];
2535 }else{
2536 $project_settings['date'] = implode('/', $array);
2537 }
2538 }
2539
2540 if(get_option('date_format') == 'd/m/Y' && strtotime($project_settings['date']) != false){
2541 $array = explode('/', $project_settings['date']);
2542 $tmp = $array[0];
2543 if(!isset($array[1]))$array[1]='';
2544 $array[0] = $array[1];
2545 $array[1] = $tmp;
2546 unset($tmp);
2547 if($array[0] == NULL){
2548 $project_settings['date'] = $array[1];
2549 }else{
2550 $project_settings['date'] = implode('/', $array);
2551 }
2552 }
2553
2554
2555 if (strpos( $project_settings['date'] , "/") !== false) {
2556 $parseddate = str_replace('/' , '.' , $project_settings['date']);
2557 }else{
2558 $parseddate = $project_settings['date'];
2559 }
2560 $project_expired = strtotime($parseddate) < time();
2561 $project_currency_sign = $f_currency_signs[$project_settings['currency']];
2562 $target= $project_settings['target'];
2563 $rewards = get_children(array(
2564 'post_parent' => $post->ID,
2565 'post_type' => 'reward',
2566 'order' => 'ASC',
2567 'orderby' => 'meta_value_num',
2568 'meta_key' => 'funding_amount',
2569 ));
2570 $funders = array();
2571 $funded_amount = 0;
2572 $chosen_reward = null;
2573 foreach($rewards as $this_reward){
2574 $these_funders = get_children(array(
2575 'post_parent' => $this_reward->ID,
2576 'post_type' => 'funder',
2577 'post_status' => 'publish'
2578 ));
2579 foreach($these_funders as $this_funder){
2580 $funding_amount = get_post_meta($this_funder->ID, 'funding_amount', true);
2581 $funders[] = $this_funder;
2582 $funded_amount += $funding_amount;
2583 }
2584 }
2585
2586 if(empty($target) or $target == 0){$target = 1;}
2587 setup_postdata( $post );?>
2588 <div class="project-card span4">
2589 <?php if(has_post_thumbnail()){
2590 $thumb = get_post_thumbnail_id();
2591 $img_url = wp_get_attachment_url( $thumb,'full'); //get img URL
2592 $image = aq_resize( $img_url, 311, 210, true, '', true ); //resize & crop img
2593 ?>
2594 <div class="project-thumb-wrapper"><a href="<?php the_permalink(); ?>"><img src="<?php echo esc_url($image[0]); ?>" /></a></div>
2595 <?php
2596 }else{ ?>
2597 <div class="project-thumb-wrapper"><a href="<?php the_permalink(); ?>"><img class="pbimage" src="<?php echo esc_url(get_template_directory_uri()); ?>/img/defaults/default_project.jpg"></a></div>
2598 <?php } ?>
2599 <h5 class="bbcard_name"><a href="<?php the_permalink(); ?>"><?php $title = get_the_title(); echo esc_attr(mb_substr($title, 0,20)); if(strlen($title) > 23){echo '...';}?></a></h5>
2600 <?php if(get_the_author_meta('first_name',get_the_author_meta('ID')) or get_the_author_meta('last_name',get_the_author_meta('ID'))){ ?><span><?php esc_html_e("by", 'funding'); ?> <a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>"><?php echo esc_attr(get_the_author_meta('first_name',get_the_author_meta('ID')).' '.get_the_author_meta('last_name',get_the_author_meta('ID'))); ?></a></span> <?php } ?>
2601 <p> <?php
2602 $excerpt = get_the_excerpt();
2603 echo mb_substr($excerpt, 0,110);echo '...';
2604 ?></p>
2605 <?php
2606 global $post;
2607 global $f_currency_signs;
2608 $project_settings = (array) get_post_meta($post->ID, 'settings', true);
2609
2610 if(get_option('date_format') == 'd/m/Y' && strtotime($project_settings['date']) != false){
2611 $array = explode('/', $project_settings['date']);
2612 $tmp = $array[0];
2613 $array[0] = $array[1];
2614 $array[1] = $tmp;
2615 unset($tmp);
2616 if($array[0] == NULL){
2617 $project_settings['date'] = $array[1];
2618 }else{
2619 $project_settings['date'] = implode('/', $array);
2620 }
2621 }
2622
2623
2624 if(get_option('date_format') == 'm/d/Y' && strtotime($project_settings['date']) != false){
2625 $array = explode('/', $project_settings['date']);
2626 $tmp = $array[0];
2627 $array[0] = $array[1];
2628 $array[1] = $tmp;
2629 unset($tmp);
2630 if($array[0] == NULL){
2631 $project_settings['date'] = $array[1];
2632 }else{
2633 $project_settings['date'] = implode('/', $array);
2634 }
2635 }
2636
2637 if (strpos( $project_settings['date'] , "/") !== false) {
2638 $parseddate = str_replace('/' , '.' , $project_settings['date']);
2639 }else{
2640 $parseddate = $project_settings['date'];
2641 }
2642 $project_expired = strtotime($parseddate) < time();
2643 $project_currency_sign = $f_currency_signs[$project_settings['currency']];
2644 $target= $project_settings['target'];
2645 $rewards = get_children(array(
2646 'post_parent' => $post->ID,
2647 'post_type' => 'reward',
2648 'order' => 'ASC',
2649 'orderby' => 'meta_value_num',
2650 'meta_key' => 'funding_amount',
2651 ));
2652 $funders = array();
2653 $funded_amount = 0;
2654 $chosen_reward = null;
2655 foreach($rewards as $this_reward){
2656 $these_funders = get_children(array(
2657 'post_parent' => $this_reward->ID,
2658 'post_type' => 'funder',
2659 'post_status' => 'publish'
2660 ));
2661 foreach($these_funders as $this_funder){
2662 $funding_amount = get_post_meta($this_funder->ID, 'funding_amount', true);
2663 $funders[] = $this_funder;
2664 $funded_amount += $funding_amount;
2665 }
2666 }?>
2667 <p>
2668 <?php if(usercountry_name_display(get_the_author_meta( 'ID' )) != '' || get_the_author_meta('city', get_the_author_meta( 'ID' )) != ''){ ?>
2669 <span class="icon-map-marker" ></span> <b><?php echo esc_attr(usercountry_name_display(get_the_author_meta( 'ID' )));?></b>
2670 <?php if(get_the_author_meta('city', get_the_author_meta( 'ID' )) != ''){ echo ', '; } ?>
2671 <?php if ( get_the_author_meta('city', get_the_author_meta( 'ID' )) ) {echo esc_attr(get_the_author_meta('city',get_the_author_meta( 'ID' ))); } ?>
2672 <?php } ?>
2673 </p>
2674 <?php if($funded_amount == $target or $funded_amount > $target){ ?>
2675 <div class="project-successful">
2676 <strong><?php esc_html_e('Successful!', 'funding'); ?></strong>
2677 </div>
2678 <?php }elseif($project_expired){ ?>
2679 <div class="project-unsuccessful">
2680 <strong><?php esc_html_e('Unsuccessful!', 'funding'); ?></strong>
2681 </div>
2682 <?php }else{ ?>
2683 <div class="progress progress-striped active bar-green"><div style="width: <?php printf(esc_html__('%u%', 'funding'), round($funded_amount/$target*100), $project_currency_sign, number_format(round((int)$target), 0, '.', ',')) ?>%" class="bar"></div></div>
2684 <?php } ?>
2685 <ul class="project-stats">
2686 <li class="first funded">
2687 <strong><?php printf(esc_html__('%u%%', 'funding'), round($funded_amount/$target*100), $project_currency_sign, round($target)) ?></strong><?php esc_html_e('funded', 'funding'); ?>
2688 </li>
2689 <li class="pledged">
2690 <strong>
2691 <?php print $project_currency_sign; print number_format(round((int)$target), 0, '.', ',');?></strong><?php esc_html_e('target', 'funding'); ?>
2692 </li>
2693 <li data-end_time="2013-02-24T08:41:18Z" class="last ksr_page_timer">
2694 <?php if(!$project_expired) : ?>
2695 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?> <strong> <?php esc_html_e('< 24', 'funding'); ?></strong> <?php }else{ ?>
2696 <strong><?php print F_Controller::timesince(time(), strtotime($parseddate), 1, ''); } ?></strong>
2697 <?php if(strpos(F_Controller::timesince(time(), strtotime($parseddate), 1, ''), "hour")){ ?>
2698 <?php esc_html_e('hours to go', 'funding'); ?>
2699 <?php }else{ ?>
2700 <?php if(F_Controller::timesince(time(), strtotime($parseddate), 1, '') == 1){ ?>
2701 <?php esc_html_e('day to go', 'funding'); ?>
2702 <?php }else{ ?>
2703 <?php esc_html_e('days to go', 'funding'); ?>
2704 <?php } ?>
2705
2706
2707 <?php } ?>
2708 <?php endif; ?>
2709 </li>
2710 </ul>
2711 <div class="clear"></div>
2712 </div>
2713
2714 <?php
2715 } ?>
2716 </div><script>
2717
2718/******************** Isotope all project block***********************/
2719var blog = jQuery(".isoprblckall");
2720if(blog.length !== 0){
2721if(jQuery.isFunction(jQuery.fn.imagesLoaded)){
2722
2723 //isotope
2724 var container = jQuery('.isoprblckall');
2725
2726 container.imagesLoaded( function(){
2727
2728 // initialize Isotope
2729 container.isotope({
2730 // options...
2731 layoutMode : 'fitRows',
2732 resizable: false, // disable normal resizing
2733 // set columnWidth to a percentage of container width
2734 masonry: {
2735 columnWidth: container.width() / 3
2736 }
2737 });
2738 });
2739 // start new block
2740 jQuery('.cat a').click(function(){
2741
2742 var selector = jQuery(this).attr('href');
2743 container.isotope({ filter: selector });
2744 return false;
2745 });
2746 // end new block
2747
2748 // update columnWidth on window resize
2749 jQuery(window).smartresize(function(){
2750 //console.log(container.width());
2751 // set the widths on resize
2752 setWidthsAll();
2753 container.isotope({
2754 // update columnWidth to a percentage of container width
2755 masonry: {
2756 columnWidth: getUnitWidthAll()
2757 }
2758 });
2759 }).resize();
2760}
2761}
2762/* Isotope utility GetUnitWidth
2763 ========================================================================== */
2764function getUnitWidthAll() {
2765 var container = jQuery('.isoprblckall');
2766 var width;
2767 if (container.width() <= 320) {
2768 //console.log("320");
2769 width = Math.floor((container.width() - 20) / 1);
2770 } else if (container.width() >= 321 && container.width() <= 480) {
2771 //console.log("321 - 480");
2772 width = Math.floor((container.width() - 30) / 1);
2773 } else if (container.width() >= 481 && container.width() <= 662) {
2774 // console.log("481 - 768");
2775 width = Math.floor((container.width() - 100) / 2);
2776 } else if (container.width() >= 663 && container.width() <= 768) {
2777 //console.log("663 - 768");
2778 width = Math.floor((container.width() - 90) / 2);
2779 } else if (container.width() >= 769 && container.width() <= 979) {
2780 //console.log("769 - 979");
2781 width = Math.floor((container.width() - 135) /3);
2782 } else if (container.width() >= 980 && container.width() <= 1200) {
2783 //console.log("980 - 1200");
2784 width = Math.floor((container.width() - 135) / 3);
2785 } else if (container.width() >= 1201 && container.width() <= 1600) {
2786 // console.log("1201 - 1600");
2787 width = Math.floor((container.width() - 135) / 3);
2788 } else if (container.width() >= 1601 && container.width() <= 1824) {
2789 // console.log("1601 - 1824");
2790 width = Math.floor((container.width() - 135) / 3);
2791 } else if (container.width() >= 1825) {
2792 // console.log("1825");
2793 width = Math.floor((container.width() - 135) / 3);
2794 }
2795 return width;
2796}
2797/* Isotope utility SetWidths
2798 ========================================================================== */
2799function setWidthsAll() {
2800 var container = jQuery('.isoprblckall');
2801 var unitWidth = getUnitWidthAll() - 0;
2802 container.children(":not(.width2)").css({
2803 width: unitWidth
2804 });
2805
2806 if (container.width() >= 321 && container.width() <= 480) {
2807 //console.log("eccoci 321");
2808 container.children(".width2").css({
2809 width: unitWidth * 1
2810 });
2811 container.children(".width4").css({
2812 width: unitWidth * 2
2813 });
2814 container.children(".width6").css({
2815 width: unitWidth * 3
2816 });
2817 }
2818 if (container.width() >= 481) {
2819 //console.log("480");
2820 container.children(".width6").css({
2821 width: unitWidth * 4
2822 });
2823 container.children(".width4").css({
2824 width: unitWidth * 3
2825 });
2826 container.children(".width2").css({
2827 width: unitWidth * 2
2828 });
2829 } else {
2830 container.children(".width2").css({
2831 width: unitWidth
2832 });
2833 }
2834}
2835
2836 </script>
2837 <?php wp_reset_postdata();
2838 $response = ob_get_contents();
2839 ob_end_clean();
2840 echo $response;
2841 die(1);
2842
2843}
2844
2845
2846/*image resize*/
2847function aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
2848
2849 // Validate inputs.
2850 if ( ! $url || ( ! $width && ! $height ) ) return false;
2851
2852 // Caipt'n, ready to hook.
2853 if ( true === $upscale ) add_filter( 'image_resize_dimensions', 'aq_upscale', 10, 6 );
2854
2855 // Define upload path & dir.
2856 $upload_info = wp_upload_dir();
2857 $upload_dir = $upload_info['basedir'];
2858 $upload_url = $upload_info['baseurl'];
2859
2860 $http_prefix = "http://";
2861 $https_prefix = "https://";
2862
2863 /* if the $url scheme differs from $upload_url scheme, make them match
2864 if the schemes differe, images don't show up. */
2865 if(!strncmp($url,$https_prefix,strlen($https_prefix))){ //if url begins with https:// make $upload_url begin with https:// as well
2866 $upload_url = str_replace($http_prefix,$https_prefix,$upload_url);
2867 }
2868 elseif(!strncmp($url,$http_prefix,strlen($http_prefix))){ //if url begins with http:// make $upload_url begin with http:// as well
2869 $upload_url = str_replace($https_prefix,$http_prefix,$upload_url);
2870 }
2871
2872
2873 // Check if $img_url is local.
2874 if ( false === strpos( $url, $upload_url ) ) return false;
2875
2876 // Define path of image.
2877 $rel_path = str_replace( $upload_url, '', $url );
2878 $img_path = $upload_dir . $rel_path;
2879
2880 // Check if img path exists, and is an image indeed.
2881 if ( ! file_exists( $img_path ) or ! getimagesize( $img_path ) ) return false;
2882
2883 // Get image info.
2884 $info = pathinfo( $img_path );
2885 $ext = $info['extension'];
2886 list( $orig_w, $orig_h ) = getimagesize( $img_path );
2887
2888 // Get image size after cropping.
2889 $dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop );
2890 $dst_w = $dims[4];
2891 $dst_h = $dims[5];
2892
2893 // Return the original image only if it exactly fits the needed measures.
2894 if ( ! $dims && ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) {
2895 $img_url = $url;
2896 $dst_w = $orig_w;
2897 $dst_h = $orig_h;
2898 } else {
2899 // Use this to check if cropped image already exists, so we can return that instead.
2900 $suffix = "{$dst_w}x{$dst_h}";
2901 $dst_rel_path = str_replace( '.' . $ext, '', $rel_path );
2902 $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
2903
2904 if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) {
2905 // Can't resize, so return false saying that the action to do could not be processed as planned.
2906 return false;
2907 }
2908 // Else check if cache exists.
2909 elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) {
2910 $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
2911 }
2912 // Else, we resize the image and return the new resized image url.
2913 else {
2914
2915 // Note: This pre-3.5 fallback check will edited out in subsequent version.
2916 if ( function_exists( 'wp_get_image_editor' ) ) {
2917
2918 $editor = wp_get_image_editor( $img_path );
2919
2920 if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) )
2921 return false;
2922
2923 $resized_file = $editor->save();
2924
2925 if ( ! is_wp_error( $resized_file ) ) {
2926 $resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] );
2927 $img_url = $upload_url . $resized_rel_path;
2928 } else {
2929 return false;
2930 }
2931
2932 } else {
2933
2934 $resized_img_path = wp_get_image_editor( $img_path, $width, $height, $crop ); // Fallback foo.
2935 if ( ! is_wp_error( $resized_img_path ) ) {
2936 $resized_rel_path = str_replace( $upload_dir, '', $resized_img_path );
2937 $img_url = $upload_url . $resized_rel_path;
2938 } else {
2939 return false;
2940 }
2941
2942 }
2943
2944 }
2945 }
2946
2947 // Okay, leave the ship.
2948 if ( true === $upscale ) remove_filter( 'image_resize_dimensions', 'aq_upscale' );
2949
2950 // Return the output.
2951 if ( $single ) {
2952 // str return.
2953 $image = $img_url;
2954 } else {
2955 // array return.
2956 $image = array (
2957 0 => $img_url,
2958 1 => $dst_w,
2959 2 => $dst_h
2960 );
2961 }
2962
2963 return $image;
2964}
2965
2966
2967function aq_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
2968 if ( ! $crop ) return null; // Let the wordpress default function handle this.
2969
2970 // Here is the point we allow to use larger image size than the original one.
2971 $aspect_ratio = $orig_w / $orig_h;
2972 $new_w = $dest_w;
2973 $new_h = $dest_h;
2974
2975 if ( ! $new_w ) {
2976 $new_w = intval( $new_h * $aspect_ratio );
2977 }
2978
2979 if ( ! $new_h ) {
2980 $new_h = intval( $new_w / $aspect_ratio );
2981 }
2982
2983 $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
2984
2985 $crop_w = round( $new_w / $size_ratio );
2986 $crop_h = round( $new_h / $size_ratio );
2987
2988 $s_x = floor( ( $orig_w - $crop_w ) / 2 );
2989 $s_y = floor( ( $orig_h - $crop_h ) / 2 );
2990
2991 return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
2992}
2993
2994/*functions for user paypal*/
2995function funding_return_user_pp_address($user_id){
2996 global $wpdb;
2997
2998 $pp_address = $wpdb->get_var("SELECT paypal_email FROM ".$wpdb->prefix."users WHERE ID = '".$user_id."'");
2999 return $pp_address;
3000}
3001
3002function funding_save_user_pp_address($user_id, $user_email){
3003 global $wpdb;
3004 $result = $wpdb->query("UPDATE ".$wpdb->prefix."users SET paypal_email = '".$user_email."' WHERE ID = '".$user_id."'");
3005}
3006
3007/*funding comments form*/
3008function funding_comments($comment, $args, $depth) {
3009$GLOBALS['comment'] = $comment; ?>
3010 <li <?php comment_class(); ?> id="li-comment-update-<?php comment_ID() ?>">
3011 <div id="comment-<?php comment_ID(); ?>">
3012
3013 <?php if ($comment->comment_approved == '0') : ?>
3014 <em><?php esc_html_e('Your update is awaiting approval.', 'funding') ?></em>
3015 <br />
3016 <br />
3017 <?php endif; ?>
3018 <div class="update-date-stamp"><a><i class="fa fa-clock-o"></i></a> <?php date(get_option('date_format'), comment_date( $comment_ID )); ?>
3019 <?php date(get_option('time_format'), comment_time()); ?></div>
3020 <?php comment_text() ?>
3021
3022 </div>
3023 <?php funding_delete_comment_link(get_comment_ID()); ?>
3024 </li>
3025
3026<?php
3027 }
3028
3029
3030function funding_comments_child($comment, $args, $depth) {
3031 $owner_id = $comment->user_id;
3032 //get_current_user_id();
3033 $usermeta = get_user_meta($owner_id);
3034 if ((strlen($usermeta['first_name'][0]) == 0) AND (strlen($usermeta['last_name'][0]) == 0)) {
3035 $name = $usermeta['nickname'][0];
3036 } else {
3037 $name = $usermeta['first_name'][0]." ".$usermeta['last_name'][0];
3038 }
3039 $GLOBALS['comment'] = $comment;
3040 if (($comment->comment_approved == '0') AND ($owner_id != get_current_user_id())) {
3041 return true;
3042 }
3043
3044
3045 ?>
3046
3047 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
3048 <div id="comment-<?php comment_ID(); ?>">
3049
3050 <?php if ($comment->comment_approved == '0') {
3051 ?>
3052 <em><?php esc_html_e('This comment is awaiting approval:', 'funding') ?></em>
3053 <br />
3054
3055 <?php } ?>
3056 <div class="update-date-stamp"><a><i class="fa fa-clock-o"></i></a> <?php date(get_option('date_format'), comment_date( $comment_ID )); ?>
3057 <?php date(get_option('time_format'), comment_time()); ?></div>
3058<div class="comment_author_name"><?php echo esc_attr($name); ?></div>
3059 <?php comment_text() ?>
3060
3061 </div>
3062 <?php funding_delete_comment_link(get_comment_ID()); ?>
3063 </li>
3064
3065<?php
3066 }
3067
3068/***** add paypal_email to database *****/
3069add_action("after_switch_theme", "funding_add_pp", 10 , 2);
3070function funding_add_pp(){
3071global $wpdb;
3072$count = $wpdb->get_var("SELECT paypal_email FROM `".$wpdb->prefix."users` ");
3073if ($count == 0){ $wpdb->query("ALTER TABLE `".$wpdb->prefix."users` ADD `paypal_email` VARCHAR( 100 )");}
3074}
3075
3076function funding_custom_comments($comment, $args, $depth) {
3077 $GLOBALS['comment'] = $comment; ?>
3078 <li <?php comment_class(); ?> id="li-comment-custom-<?php comment_ID() ?>">
3079 <div id="comment-<?php comment_ID(); ?>">
3080
3081 <?php if ($comment->comment_approved == '0') : ?>
3082 <em><?php esc_html_e('Your update is awaiting approval.', 'funding') ?></em>
3083 <br />
3084 <br />
3085 <?php endif; ?>
3086 <div class="update-date-stamp"><a><i class="fa fa-clock-o"></i></a> <?php date(get_option('date_format'), comment_date( $comment_ID )); ?>
3087<?php date(get_option('time_format'), comment_time()); ?></div>
3088 <?php comment_text() ?>
3089
3090 </div>
3091 <?php funding_delete_comment_link(get_comment_ID()); ?>
3092 </li>
3093
3094<?php
3095 }
3096
3097
3098/*comments delete and spam link*/
3099function funding_delete_comment_link($id) {
3100 global $post;
3101 if ($post->post_author == get_current_user_id()) {
3102 echo '<a href="javascript:;" onclick="delpost('.get_comment_ID().')">'.esc_html__("Delete comment", "funding").'</a> ';
3103 }
3104}
3105
3106/*delete comments*/
3107add_action( 'wp_ajax_nopriv_delcomments', 'funding_delete_comments' );
3108add_action( 'wp_ajax_delcomments', 'funding_delete_comments' );
3109function funding_delete_comments() {
3110 global $wpdb, $post;
3111 $comment_id = $_POST['id'];
3112 $comment_id = mysql_real_escape_string($comment_id);
3113 $table_name = $wpdb->prefix . "comments";
3114 $wpdb->query($wpdb->prepare("DELETE FROM $table_name WHERE comment_ID = %d", $comment_id ));
3115 die();
3116
3117}
3118
3119/*remove empty p */
3120add_filter("the_content", "funding_the_content_filter");
3121function funding_the_content_filter($content) {
3122
3123 // array of custom shortcodes requiring the fix
3124 $block = join("|",array("col","shortcode2","shortcode3", "layerslider"));
3125
3126 // opening tag
3127 $rep = preg_replace("/(<p>)?\[($block)(\s[^\]]+)?\](<\/p>|<br \/>)?/","[$2$3]",$content);
3128
3129 // closing tag
3130 $rep = preg_replace("/(<p>)?\[\/($block)](<\/p>|<br \/>)?/","[/$2]",$rep);
3131
3132 return $rep;
3133
3134}
3135
3136
3137
3138
3139
3140add_action( 'admin_init', 'allow_admin_area_to_admins_only');
3141function allow_admin_area_to_admins_only() {
3142
3143 if( defined('DOING_AJAX') && DOING_AJAX ) {
3144 //Allow ajax calls
3145 return;
3146 }
3147
3148 $user = wp_get_current_user();
3149 if( empty( $user ) || !in_array( "administrator", (array) $user->roles ) ) {
3150 //Redirect to main page if no user or if the user has no "administrator" role assigned
3151 wp_redirect( get_site_url( ) );
3152 exit();
3153 }
3154
3155 }
3156
3157add_action( 'admin_init', 'funding_update_caps');
3158function funding_update_caps() {
3159 $role = get_role( 'contributor' );
3160 $caps_to_add = array(
3161 'edit_others_pages',
3162 'edit_published_pages',
3163 'upload_files'
3164 );
3165 foreach( $caps_to_add as $cap )
3166 $role->add_cap( $cap );
3167}
3168
3169
3170/***** Get wepay tokens and accounts *****/
3171add_action( 'wp_ajax_nopriv_get_wepay_token', 'get_wepay_token' );
3172add_action( 'wp_ajax_get_wepay_token', 'get_wepay_token' );
3173function get_wepay_token () {
3174 require 'funding/lib/WePay/wepay.php';
3175 global $f_paypal;
3176 $user = get_current_user_id();
3177 $code = $_POST['code'];
3178 $redirect_uri = $_POST['redirURL']; // this is the redirect_uri you used in step 1
3179
3180 // application settings
3181 $client_id = $f_paypal['wepay-client_id'];
3182 $client_secret = $f_paypal['wepay-client_secret'];
3183
3184 // change to useProduction for live environments
3185 if ($f_paypal['wepay-staging'] != 'Yes') {
3186 // change to useProduction for live environments
3187 Wepay::useProduction($client_id, $client_secret);
3188 } else {
3189 Wepay::useStaging($client_id, $client_secret);
3190 }
3191
3192
3193
3194 $wepay = new WePay(NULL); // we don't have an access_token yet so we can pass NULL here
3195
3196 // create an account for a user
3197 $response = WePay::getToken($code, $redirect_uri);
3198
3199 update_user_meta($user, "wepay_token", $response->access_token);
3200 $thetoken = $response->access_token;
3201
3202 $wepay2 = new WePay($thetoken);
3203 $response = $wepay2->request('account/create/', array(
3204 'name' => get_bloginfo('name'). ' account',
3205 'description' => 'Account for '.get_bloginfo('name').' withdrawls'
3206 ));
3207
3208 update_user_meta($user, "wepay_account_id", $response->account_id);
3209 update_user_meta($user, "linked_wepay", "1");
3210 echo "ok";
3211 die();
3212
3213}
3214
3215add_action( 'wp_ajax_nopriv_unlink_wepay', 'unlink_wepay' );
3216add_action( 'wp_ajax_unlink_wepay', 'unlink_wepay' );
3217function unlink_wepay () {
3218 $user = get_current_user_id();
3219 delete_user_meta($user, 'linked_wepay');
3220 echo "ok";
3221 die();
3222
3223}
3224
3225
3226add_action( 'wp_ajax_nopriv_delete_projects', 'delete_projects' );
3227add_action( 'wp_ajax_delete_projects', 'delete_projects' );
3228function delete_projects() {
3229 $prID = $_POST[ 'idp' ];
3230 wp_delete_post($prID);
3231 echo "ok";
3232 die();
3233
3234}
3235
3236/*hide admin bar for all users except admin*/
3237function skywarrior_admin_bar(){
3238
3239 if (!current_user_can('administrator') && !is_admin()) {
3240 show_admin_bar(false);
3241 }
3242
3243}
3244add_action( 'after_setup_theme' , 'skywarrior_admin_bar');
3245
3246/*set email header to use html*/
3247function funding_set_html_content_type() {
3248 return 'text/html';
3249}
3250remove_filter( 'wp_mail_content_type', 'funding_set_html_content_type' );
3251
3252/*function to convert dateformat to js for picker*/
3253function funding_date_format_php_to_js( $sFormat ) {
3254
3255 switch( $sFormat ) {
3256 //Predefined WP date formats
3257 case 'j F, Y':
3258 return( 'MM dd, yy' );
3259 break;
3260 case 'F j, Y':
3261 return( 'MM dd, yy' );
3262 break;
3263 case 'Y/m/d':
3264 return( 'yy/mm/dd' );
3265 break;
3266 case 'm/d/Y':
3267 return( 'mm/dd/yy' );
3268 break;
3269 case 'd/m/Y':
3270 return( 'dd/mm/yy' );
3271 break;
3272 case 'Y-m-d':
3273 return( 'yy-mm-dd' );
3274 break;
3275 default:
3276 return( 'MM dd, yy' );
3277 }
3278}
3279
3280
3281function funding_dateformat_var() {
3282 echo '<script>var formatdatuma = "'.funding_date_format_php_to_js(get_option("date_format")).'";</script>';
3283}
3284add_action( 'admin_head', 'funding_dateformat_var' );
3285
3286
3287function comments_holder() {
3288
3289 $args = array(
3290 'label' => esc_html__( 'comments_holder', 'funding' ),
3291 'description' => esc_html__( 'Holds comments', 'funding' ),
3292 'supports' => array( 'title', 'comments', ),
3293 'taxonomies' => array( 'comments_holder' ),
3294 'hierarchical' => false,
3295 'public' => true,
3296 'show_ui' => false,
3297 'show_in_menu' => false,
3298 'menu_position' => 5,
3299 'show_in_admin_bar' => false,
3300 'show_in_nav_menus' => false,
3301 'can_export' => false,
3302 'has_archive' => false,
3303 'exclude_from_search' => true,
3304 'publicly_queryable' => true,
3305 'capability_type' => 'page',
3306 );
3307 register_post_type( 'comments_holder', $args );
3308
3309}
3310add_action( 'init', 'comments_holder', 0 );
3311
3312
3313function skywarrior_get_id_by_slug($page_slug) {
3314 $page = get_page_by_path($page_slug);
3315 if ($page) {
3316 return $page->ID;
3317 } else {
3318 return null;
3319 }
3320}
3321
3322
3323function my_custom_post_status(){
3324 register_post_status( 'review', array(
3325 'label' => _x( 'Review', 'post' ),
3326 'public' => true,
3327 'exclude_from_search' => false,
3328 'show_in_admin_all_list' => true,
3329 'show_in_admin_status_list' => true
3330 ) );
3331}
3332add_action( 'init', 'my_custom_post_status' );
3333
3334
3335
3336
3337
3338
3339
3340
3341function your_theme_wp_editor(){
3342 ob_start();
3343 wp_editor( '', 'comment', array(
3344 'media_buttons' => false,
3345 'textarea_rows' => '3',
3346 'tinymce' => array(
3347 'plugins' => 'wordpress, wplink, wpdialogs',
3348 'theme_advanced_buttons1' => 'bold, italic, underline, strikethrough, forecolor, separator, bullist, numlist, separator, link, unlink, image',
3349 'theme_advanced_buttons2' => ''
3350 ),
3351 'quicktags' => array('buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close')
3352 )
3353 );
3354
3355 return ob_get_clean();
3356}
3357
3358function your_theme_comment_form_defaults($args) {
3359 $args['comment_field'] = your_theme_wp_editor();
3360
3361 return $args;
3362}
3363add_filter('comment_form_defaults', 'your_theme_comment_form_defaults');
3364
3365function your_theme_allowed_tags() {
3366 global $allowedtags;
3367 $allowedtags['ul'] = array();
3368 $allowedtags['ol'] = array();
3369 $allowedtags['li'] = array();
3370 $allowedtags['strong'] = array();
3371 $allowedtags['ins'] = array(
3372 'datetime' => true
3373 );
3374 $allowedtags['del'] = array(
3375 'datetime' => true
3376 );
3377 $allowedtags['pre'] = array(
3378 'lang' => true,
3379 'line' => true
3380 );
3381 $allowedtags['span'] = array(
3382 'style' => true
3383 );
3384 $allowedtags['img'] = array(
3385 'width' => true,
3386 'height' => true,
3387 'src' => true,
3388 'alt' => true
3389 );
3390 $allowedtags['a'] = array(
3391 'target' => true,
3392 'href' => true,
3393 'title' => true,
3394 );
3395}
3396add_action('init', 'your_theme_allowed_tags');
3397
3398function your_theme_scripts(){
3399 // Load minified or not
3400
3401 // Deregister WordPress comment-reply script
3402 wp_deregister_script('comment-reply');
3403
3404 // Register our own comment-reply script
3405 wp_register_script('comment-reply', get_bloginfo('template_url').'/js/comment-reply.js');
3406}
3407add_action('wp_enqueue_scripts', 'your_theme_scripts');
3408
3409add_filter( 'user_can_richedit', '__return_true' );
3410
3411 // Display 24 products per page. Goes in functions.php
3412add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 4;' ), 20 );
3413
3414add_filter( 'woocommerce_available_payment_gateways', '_wc_remove_braintree_pay_with_paypal' );
3415function _wc_remove_braintree_pay_with_paypal( $gateways ) {
3416 unset( $gateways['paypalbraintree_paypal'] );
3417 return $gateways;
3418}
3419
3420add_filter( 'wc_gateway_paypal_braintree_data', '_wc_remove_braintree_checkout_with_paypal' );
3421
3422function _wc_remove_braintree_checkout_with_paypal( $data ) {
3423 unset( $data['checkoutWithPayPal'] );
3424 return $data;
3425}
3426
3427
3428function insert_image_src_rel_in_head() {
3429global $post;
3430if ( !is_singular()) //if it is not a post or a page
3431return;
3432if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
3433$default_image="https://pixelfunder.com/wp-content/uploads/2016/09/13124716_487663071427729_15781.png"; //replace this with a default image on your server or an image in your media library
3434echo '<meta property="og:image" content="' . $default_image . '"/>';
3435
3436}
3437else{
3438$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
3439$real_thumb = str_replace(" ","%20",$thumbnail_src[0]);
3440
3441echo '<meta property="og:image" content="' . esc_attr( $real_thumb ) . '"/>';
3442}
3443
3444}
3445add_action( 'wp_head', 'insert_image_src_rel_in_head');
3446
3447
3448
3449//start function
3450
3451function user_role_update( $user_id, $new_role ) {
3452 $site_url = get_bloginfo('wpurl');
3453 $user_info = get_userdata( $user_id );
3454 $to = $user_info->user_email;
3455 $subject = "Welcome to PixelFunder!";
3456
3457$user = new WP_User( (int) $user_id );
3458$adt_rp_key = get_password_reset_key( $user );
3459$user_login = $user->user_login;
3460$rp_link = '<a href="' . network_site_url("wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode($user_login), 'login') . '">' . network_site_url("wp-login.php?action=rp&key=$adt_rp_key&login=" . rawurlencode($user_login), 'login') . '</a>';
3461
3462if ( is_wp_error( $key ) ) {
3463 return $key;
3464}
3465
3466
3467
3468
3469
3470if($new_role == "backer")
3471{
3472$message = "<a href=\"https://pixelfunder.com\"><img src=\"https://pixelfunder.com/wp-content/uploads/2014/07/pf3-300x71.gif\" border=\"0\" alt=\"PixelFunder\" title=\"PixelFunder\"></a>
3473<br><br>Hello " .$user_info->display_name . ",<br><br>
3474Thank you for registering with PixelFunder, it's just great to have you on Âboard! So close to backing your first game now!<br><br>
3475Give this link a little click to get your account verified: <br>" . $rp_link . "<br><br>
3476Not sure where to start on PixelFunder? Here's some ideas!<br><br>
3477<li>Dive into the forums and get chatting! You can talk to developers about their titles, share anything interesting you have found in the gaming universe and chat about gaming in general. Check out what the community are talking about or create your own topic!
3478<li>Every time a new game joins the site we have a live stream over on Twitch called PixelFunder Plays that you are welcome to watch and engage with! We also prepare and publish footage from the stream on our YouTube channel.
3479<li>Coins - do stuff, get rewarded. For doing certain actions on the PixelFunder website you will accumulate coins that you can use to buy merchandise!
3480<li>Level up! The more you do on the community the higher the rank you will get. Why rank up? Well, for the preferential treatment of course! Ranking up will get you exclusive offers, access to games in earlier development stages and loads more.
3481<br><br>
3482If you need any help with anything, <a href=\"https://pixelfunder.com/contact/\">give us a shout!</a>
3483<br><br>
3484Thanks and see you on the forums!
3485<br><br>
3486The <a href=\"https://pixelfunder.com/pixelfounders/\">PixelFounders</a>";
3487}
3488elseif($new_role == "developer")
3489{
3490$message = "<a href=\"https://pixelfunder.com\"><img src=\"https://pixelfunder.com/wp-content/uploads/2014/07/pf3-300x71.gif\" border=\"0\" alt=\"PixelFunder\" title=\"PixelFunder\"></a>
3491<br><br>Hello " .$user_info->display_name . ",<br><br>
3492Thank you for registering with PixelFunder, it's just great to have you onÂboard! We bet you're just itching to get your game published on the platform and you’re pretty darn close too.<br><br>
3493Give this link a little click to get your account verified: <br>" . $rp_link . "<br><br>
3494Here’s quick guide on how you can get your game published on the platform:
3495<br><br>
3496<li>Click on the \"<a href=\"https://pixelfunder.com/launch-project/\">Submit a Game</a>\" button in the top right hand corner. Make sure you have WePay or PayPal set up so you can get your funds when you've reached your goal!
3497<li>When preparing your project on PixelFunder, you need to have a game name and an image to use for your project, as well as an idea of the amount of backing you need to get your project funded.<br>
3498If you're unsure of whether your goal is achievable or if you’re asking for the right amount of backing, please reach out to us using the <a href=\"https://pixelfunder.com/contact/\">Contact Us</a> form. We can also help you think about the Rewards you offer to backers as well as the appropriate backing amount for each.
3499<li>It's important to remember that you don't need to fill in everything on the page to save your work as a draft. Fill in as much as you can and if you are stuck for ideas on how to write your Story or any other elements, we are just an email away. It's our goal to get your game the most exposure possible so please feel free to contact whenever you want!
3500<li>So you're happy with your draft now? Everything's looking ship shape! Well, there's only one thing left for it… hit that big 'ol \"Submit for Review\" button and your project will wing its way into our lovely inboxes!
3501<br><br>
3502If you need any help with anything, give us a shout! We'll be in touch when you submit you game either way, but we're on hand to help guide you with the process and give any advice where we can.
3503<br><br>
3504Thanks and we're looking forward to seeing your game soon!
3505<br><br>
3506The <a href=\"https://pixelfunder.com/pixelfounders/\">PixelFounders</a>";
3507}
3508else
3509{
3510// $message = "Hello " .$user_info->display_name . " your role has changed on ".$site_url.", congratulations you are now an " . $new_role;
3511}
3512
3513function wpdocs_set_html_mail_content_type() {
3514 return 'text/html';
3515}
3516add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
3517
3518$headers[] = 'From: PixelFunder <admin@pixelfunder.com>';
3519wp_mail($to, $subject, $message, $headers);
3520
3521// Reset content-type to avoid conflicts -- https://core.trac.wordpress.org/ticket/23578
3522remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
3523
3524}
3525add_action( 'set_user_role', 'user_role_update', 10, 2);
3526
3527
3528//end function
3529
3530// start role pulldown
3531add_action( 'register_form', 'myplugin_register_form' );
3532function myplugin_register_form() {
3533
3534 global $wp_roles;
3535 echo 'Please select how you will be using Pixel Funder:<br>';
3536 echo '<select name="role" class="input">';
3537 foreach ( $wp_roles->roles as $key=>$value ):
3538 if ($value["name"] === "Developer" || $value["name"] === "Backer"):
3539 echo '<option value="'.$key.'">'.$value['name'].'</option>';
3540 endif;
3541 endforeach;
3542 echo '</select>';
3543}
3544
3545add_filter( 'registration_errors', 'myplugin_registration_errors', 10, 3 );
3546function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {
3547
3548 if ( empty( $_POST['role'] ) || ! empty( $_POST['role'] ) && trim( $_POST['role'] ) == '' ) {
3549 $errors->add( 'role_error', __( '<strong>ERROR</strong>: You must include a role.', 'mydomain' ) );
3550 }
3551
3552 return $errors;
3553}
3554
3555add_action( 'user_register', 'myplugin_user_register' );
3556function myplugin_user_register( $user_id ) {
3557
3558 $user_id = wp_update_user( array( 'ID' => $user_id, 'role' => $_POST['role'] ) );
3559}
3560
3561add_filter( 'login_url', 'my_login_page', 10, 3 );
3562function my_login_page( $login_url, $redirect, $force_reauth ) {
3563 return home_url( 'http://www.pixelfunder.com/?redirect_to=' . $redirect );
3564}
3565
3566?>