Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 21.53 KB | None | 0 0
  1. function add_search_to_wp_menu ( $items, $args ) {
  2.     if( 'primary' === $args -> theme_location ) {
  3.     $items .= '<li class="menu-item menu-item-search">';
  4.     $items .= '<form method="get" class="menu-search-form" action="/search">
  5.     <p>
  6.     <i class="fa fa-search" aria-hidden="true"></i>
  7.     <input class="text_input" type="text" value="" name="cs" id="cs"  />
  8.     </p></form>';
  9.     $items .= '</li>';
  10.         }
  11.     return $items;
  12. }
  13.  
  14. add_filter('wp_nav_menu_items','add_search_to_wp_menu',10,2);
  15.  
  16. function get_session_speakers($event_id){
  17.     global $wpdb;
  18.     $query = $wpdb->prepare( "SELECT * FROM in5_ci_sessions AS t1, in5_ci_speakers AS t2, in5_ci_events AS t3 WHERE t1.event_session_event_id = %d AND t1.event_session_speaker_id = t2.speaker_id AND t1.event_session_event_id = t3.event_id", $event_id );
  19.     $speakers = $wpdb->get_results($query, ARRAY_A);
  20.     return $speakers;
  21. }
  22.  
  23. function get_speaker_company($company_id) {
  24.     global $wpdb;
  25.     $query = $wpdb->prepare( "SELECT * FROM in5_ci_companies WHERE company_id = %d", $company_id );
  26.     $company = $wpdb->get_results($query, ARRAY_A);
  27.     return $company[0]['company_name'];
  28. }
  29.  
  30. function get_event_id_from_speaker_id($speaker_id) {
  31.     global $wpdb;
  32.     $query = $wpdb->prepare( "SELECT event_session_event_id FROM in5_ci_sessions WHERE event_session_speaker_id = %d", $speaker_id );
  33.     $event = $wpdb->get_results($query, ARRAY_A);
  34.     return $event[0]['event_session_event_id'];
  35. }
  36.  
  37. function build_sorter($key) {
  38.     return function ($a, $b) use ($key) {
  39.         return strnatcmp($a[$key], $b[$key]);
  40.     };
  41. }
  42.  
  43. function get_mentor($mentor_id) {
  44.     global $wpdb;
  45.     $query = $wpdb->prepare( "SELECT * FROM in5_ci_mentors WHERE mentor_id = %d", $mentor_id );
  46.     $mentor = $wpdb->get_results($query, ARRAY_A);
  47.     return $mentor[0]; 
  48. }
  49.  
  50. function wp_insert_rows($row_arrays = array(), $wp_table_name, $update=false, $primary_key=null) {
  51.     global $wpdb;
  52.     $wp_table_name = esc_sql($wp_table_name);
  53.     // Setup arrays for Actual Values, and Placeholders
  54.     $values = array();
  55.     $place_holders = array();
  56.     $query = "";
  57.     $query_columns = "";
  58.    
  59.     $query .= "INSERT INTO `{$wp_table_name}` (";
  60.    
  61.             foreach($row_arrays as $count => $row_array)
  62.             {
  63.    
  64.                 foreach($row_array as $key => $value) {
  65.    
  66.                     if($count == 0) {
  67.                         if($query_columns) {
  68.                         $query_columns .= ", ".$key."";
  69.                         } else {
  70.                         $query_columns .= "".$key."";
  71.                         }
  72.                     }
  73.    
  74.                     $values[] =  $value;
  75.    
  76.                     if(is_numeric($value)) {
  77.                         if(isset($place_holders[$count])) {
  78.                         $place_holders[$count] .= ", '%d'";
  79.                         } else {
  80.                         $place_holders[$count] = "( '%d'";
  81.                         }
  82.                     } else {
  83.                         if(isset($place_holders[$count])) {
  84.                         $place_holders[$count] .= ", '%s'";
  85.                         } else {
  86.                         $place_holders[$count] = "( '%s'";
  87.                         }
  88.                     }
  89.                 }
  90.                         // mind closing the GAP
  91.                         $place_holders[$count] .= ")";
  92.             }
  93.    
  94.     $query .= " $query_columns ) VALUES ";
  95.    
  96.     $query .= implode(', ', $place_holders);
  97.    
  98.   if ($update) 
  99.   {
  100.     $update=" ON DUPLICATE KEY UPDATE $primary_key=VALUES( $primary_key ),";
  101.     $cnt=0;
  102.     foreach($row_arrays[0] as $key => $value)
  103.     {
  104.       if($cnt==0) {
  105.         $update .= "$key=VALUES($key)";
  106.         $cnt=1;
  107.       } else {
  108.         $update .= ", $key=VALUES($key)";
  109.       }
  110.     }
  111.     $query .= $update;
  112.   }
  113.  
  114.   $sql=$wpdb->prepare($query, $values);
  115.   if($wpdb->query($sql)){
  116.     return true;
  117.   } else {
  118.     return false;
  119.   }
  120. }
  121.  
  122. function record_custom_search_in_db($terms) {
  123.     global $wpdb;
  124.     $wpdb->insert('custom_search_queries', array( 'query' => $terms), array( '%s'));
  125.     return;
  126. }
  127.  
  128. function custom_search($terms) {
  129.     $date = date('Y-m-d H:i:s');
  130.     global $wpdb;
  131.     //echo $terms;
  132.     $sql_query_events = "SELECT * FROM in5_ci_events WHERE MATCH(event_name, event_location, event_description, key_discussion_points, target_audience, speakers_profile)
  133.     AGAINST ('$terms' IN NATURAL LANGUAGE MODE) AND (`event_from` > '$date') AND (`event_status` = 1);";
  134.  
  135.     $sql_query_mentors = "SELECT * FROM in5_ci_mentors WHERE MATCH(mentor_name,company,job_position,profile,company_website,linkedin,expertise,expertise_other)
  136.     AGAINST ('$terms' IN NATURAL LANGUAGE MODE) AND (`publish_to_in5`='Yes') AND (`status`='1');";
  137.  
  138.     $sql_query_posts = "SELECT * FROM $wpdb->posts WHERE (MATCH(post_title, post_content) AGAINST ('$terms' IN NATURAL LANGUAGE MODE)) AND (`post_type` = 'post' OR `post_type` = 'page');";
  139.  
  140.     $sql_query_speakers = "SELECT t1.speaker_id, t1.speaker_name, t1.speaker_title, t1.speaker_designation, t1.speaker_overview, t1.speaker_linkedin_url FROM in5_ci_speakers AS t1, in5_ci_sessions AS t2, in5_ci_events AS t3 WHERE t2.event_session_speaker_id = t1.speaker_id AND t2.event_session_event_id = t3.event_id AND t3.event_from > '$date' AND t3.event_status = 1 AND MATCH(speaker_name, speaker_title,speaker_designation,speaker_overview,speaker_linkedin_url) AGAINST ('$terms' IN NATURAL LANGUAGE MODE);";
  141.  
  142.     $sql_query_companies = "SELECT * FROM in5_ci_companies AS t1, in5_ci_speakers AS t2, in5_ci_events AS t3, in5_ci_sessions AS t4 WHERE t2.speaker_company_id = t1.company_id AND t4.event_session_event_id = t3.event_id AND t4.event_session_speaker_id = t2.speaker_id AND t3.event_from > '$date' AND t3.event_status = 1 AND MATCH(company_name, company_url,company_linkedin_url,company_address,company_description) AGAINST ('$terms' IN NATURAL LANGUAGE MODE);";
  143.  
  144.     $results_events = $wpdb->get_results($sql_query_events, ARRAY_A);
  145.     $results_mentors = $wpdb->get_results($sql_query_mentors, ARRAY_A);
  146.  
  147.     $results_posts = $wpdb->get_results($sql_query_posts, ARRAY_A);
  148.     $results_speakers = $wpdb->get_results($sql_query_speakers, ARRAY_A);
  149.     $results_companies = $wpdb->get_results($sql_query_companies, ARRAY_A);
  150.  
  151.     $all_results = array(
  152.         'events' => $results_events,
  153.         'mentors' => $results_mentors,
  154.         'posts' => $results_posts,
  155.         'speakers' => $results_speakers,
  156.         'companies' => $results_companies
  157.         );
  158.  
  159.     //print_r($all_results);
  160.     $cleaned_results = array();
  161.  
  162.     $i = 0;
  163.  
  164.     foreach ($results_posts as $result) {
  165.         $cleaned_results[$i]['title'] = $result['post_title'];
  166.         $post_id = $result['ID'];
  167.  
  168.         $string = $result['post_content'];
  169.         $pattern = '/\[(.*?)\]/';
  170.         $replacement = '';
  171.         $cleaned_content = strip_tags(preg_replace($pattern, $replacement, $string));
  172.  
  173.         $cleaned_results[$i]['content'] = $cleaned_content;
  174.  
  175.         if (empty(get_field('page_excerpt'))) {
  176.             $cleaned_results[$i]['excerpt'] = wp_trim_words($cleaned_content);
  177.         }
  178.        
  179.         else {
  180.             $cleaned_results[$i]['excerpt'] = wp_trim_words(get_field('page_excerpt', $post_id));
  181.         }
  182.         $cleaned_results[$i]['id'] = $post_id;
  183.         $cleaned_results[$i]['type'] = 'post';
  184.         $cleaned_results[$i]['url'] = get_permalink($post_id);
  185.         $i++;      
  186.     }
  187.  
  188.     foreach ($results_events as $result) {
  189.         $cleaned_results[$i]['title'] = $result['event_name'];
  190.         $cleaned_results[$i]['excerpt'] = wp_trim_words($result['event_description']);
  191.  
  192.         $cleaned_results[$i]['content'] = $result['event_description'] . ' ' . $result['event_location'] . ' ' . $result['event_from'] . ' ' . $result['event_till'] . ' ' .
  193.         $result['key_discussion_points'] . ' ' . $result['target_audience'] . ' ' . $result['location_url'] . ' ' . $result['registration_url'];
  194.  
  195.         $cleaned_results[$i]['type'] = 'event';
  196.        
  197.         $cleaned_results[$i]['id'] = $result['event_id'];
  198.  
  199.         $id = $result['event_id'];
  200.         $cleaned_results[$i]['url'] = get_home_url() . "/events-details?event_id=$id";
  201.         $i++;
  202.     }
  203.  
  204.     foreach ($results_mentors as $result) {
  205.         $cleaned_results[$i]['title'] = $result['mentor_name'];
  206.         $cleaned_results[$i]['excerpt'] = wp_trim_words($result['profile']);
  207.  
  208.         $cleaned_results[$i]['content'] = $result['profile'] . ' ' . $result['company'] . ' ' . $result['job_position'] . ' ' . $result['company_website'] . ' ' .
  209.         $result['linkedin'] . ' ' . $result['target_audience'] . ' ' . $result['expertise'];
  210.  
  211.         $cleaned_results[$i]['type'] = 'mentor';
  212.         $cleaned_results[$i]['id'] = $result['mentor_id'];
  213.         $id = $result['mentor_id'];
  214.         $cleaned_results[$i]['url'] = $url = get_home_url() . "/mentor-details?mentor_id=$id";
  215.         $i++;
  216.     }
  217.  
  218.     foreach ($results_speakers as $result) {
  219.         $cleaned_results[$i]['title'] = $result['speaker_name'];
  220.         $cleaned_results[$i]['excerpt'] = wp_trim_words($result['speaker_overview']);
  221.  
  222.         $cleaned_results[$i]['content'] = $result['speaker_overview'] . ' ' . $result['speaker_designation'] . ' ' . $result['speaker_title'] . ' ' . $result['speaker_linkedin_url'];
  223.  
  224.         $cleaned_results[$i]['type'] = 'speaker';
  225.         $cleaned_results[$i]['id'] = $result['speaker_id'];
  226.         $id = get_event_id_from_speaker_id($result['speaker_id']);
  227.         $cleaned_results[$i]['url'] = $url = get_home_url() . "/events-details?event_id=$id";
  228.         $i++;
  229.     }
  230.  
  231.     foreach ($results_companies as $result) {
  232.         $cleaned_results[$i]['title'] = $result['company_name'];
  233.         $cleaned_results[$i]['excerpt'] = wp_trim_words($result['company_description']);
  234.  
  235.         $cleaned_results[$i]['content'] = $result['company_description'] . ' ' . $result['company_url'] . ' ' . $result['company_url'] . ' ' . $result['company_linkedin_url']
  236.         . ' ' . $result['company_address'] . ' ' . $result['company_phone'];
  237.  
  238.         $cleaned_results[$i]['type'] = 'company';
  239.         $id = $result['event_id'];
  240.         $cleaned_results[$i]['id'] = $id;
  241.         $cleaned_results[$i]['url'] = get_home_url() . "/events-details?event_id=$id";
  242.         $i++;
  243.     }
  244.  
  245.     $search_tmp_id = uniqid();
  246.  
  247.     foreach ($cleaned_results as $result) {
  248.         $insert_array[] = array('title' => $result['title'], 'excerpt' => $result['excerpt'], 'item_id'=>$result['id'], 'type' => $result['type'],'content' => $result['content'], 'url' => $result['url'], 'search_id' => $search_tmp_id  );
  249.     }
  250.  
  251.     if (!empty($insert_array)) {
  252.         wp_insert_rows($insert_array,'custom_search_queries_tmp');
  253.         $sql_sort = "SELECT * FROM custom_search_queries_tmp WHERE (MATCH(title, content) AGAINST ('$terms' IN NATURAL LANGUAGE MODE)) AND search_id = '$search_tmp_id' ;";
  254.         $sorted_cleaned_results = $wpdb->get_results($sql_sort, ARRAY_A);
  255.         $wpdb->query("DELETE FROM custom_search_queries_tmp WHERE search_id = '$search_tmp_id' ;");    
  256.     }
  257.  
  258.     return $sorted_cleaned_results;
  259. }
  260.  
  261.  
  262. function checkRemoteFile($url)
  263. {
  264.     $ch = curl_init();
  265.     curl_setopt($ch, CURLOPT_URL,$url);
  266.     // don't download content
  267.     curl_setopt($ch, CURLOPT_NOBODY, 1);
  268.     curl_setopt($ch, CURLOPT_FAILONERROR, 1);
  269.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  270.     if(curl_exec($ch)!==FALSE)
  271.     {
  272.         return true;
  273.     }
  274.     else
  275.     {
  276.         return false;
  277.     }
  278. }
  279.  
  280. function register_user_for_event($user_id, $event_id) {
  281.     global $wpdb;
  282.     $exists = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM `events_registration` WHERE ID = %d AND event_id = %d;", $user_id, $event_id) );
  283.     if (!$exists) {
  284.         $wpdb->insert('events_registration', array( 'ID' => $user_id, 'event_id' => $event_id), array( '%d', '%d' ));
  285.         return 'registered';
  286.     }
  287.     else {
  288.         return 'registered';
  289.     }
  290.    
  291. }
  292.  
  293. function custom_events_search($terms) {
  294.     $date = date('Y-m-d H:i:s');
  295.     $terms = esc_sql(strip_tags($terms));
  296.     global $wpdb;
  297.     //echo $terms;
  298.     $sql_query_events = "SELECT * FROM in5_ci_events WHERE ((event_name LIKE '%$terms%' ) OR (event_description LIKE '%$terms%')) AND (event_status = 1)
  299.     AND (event_from > '$date');";
  300.  
  301.     $results_events = $wpdb->get_results($sql_query_events, ARRAY_A);
  302.  
  303.     $all_results = array(
  304.         'events' => $results_events,
  305.         );
  306.  
  307.     //print_r($all_results);
  308.     $cleaned_results = array();
  309.  
  310.     $i = 0;
  311.  
  312.  
  313.     foreach ($results_events as $result) {
  314.         $cleaned_results[$i]['title'] = $result['event_name'];
  315.         $cleaned_results[$i]['excerpt'] = wp_trim_words($result['event_description']);
  316.  
  317.         $cleaned_results[$i]['content'] = $result['event_description'] . ' ' . $result['event_location'] . ' ' . $result['event_from'] . ' ' . $result['event_till'] . ' ' .
  318.         $result['key_discussion_points'] . ' ' . $result['target_audience'] . ' ' . $result['location_url'] . ' ' . $result['registration_url'];
  319.  
  320.         $cleaned_results[$i]['type'] = 'event';
  321.         $cleaned_results[$i]['id'] = $result['event_id'];
  322.         $id = $result['event_id'];
  323.         $cleaned_results[$i]['url'] = $id;
  324.         $i++;
  325.     }
  326.  
  327.  
  328.     $search_tmp_id = uniqid();
  329.  
  330.     foreach ($cleaned_results as $result) {
  331.         $insert_array[] = array('title' => $result['title'], 'excerpt' => $result['excerpt'], 'content' => $result['content'], 'url' => $result['url'], 'search_id' => $search_tmp_id  );
  332.     }
  333.  
  334.     if (!empty($insert_array)) {
  335.         wp_insert_rows($insert_array,'custom_search_queries_tmp');
  336.         $sql_sort = "SELECT * FROM custom_search_queries_tmp WHERE (MATCH(title, content) AGAINST ('$terms' IN NATURAL LANGUAGE MODE)) AND search_id = '$search_tmp_id' ;";
  337.         $sorted_cleaned_results = $wpdb->get_results($sql_sort, ARRAY_A);
  338.         $wpdb->query("DELETE FROM custom_search_queries_tmp WHERE search_id = '$search_tmp_id' ;");    
  339.     }
  340.  
  341.     return $sorted_cleaned_results;
  342. }
  343.  
  344.  
  345. function events_shortcode_ajax_wrapper() {
  346.   if ( !empty($_REQUEST['shortcode']) ) {
  347.  
  348.     $shortcode_name = 'events';
  349.  
  350.     $event_type = sanitize_text_field($_REQUEST['event_type']);
  351.     $event_type = ' event_type="' . $event_type . '"';
  352.     // Wrap the shortcode in tags. You might also want to add arguments here.
  353.     $full_shortcode = '[events' . $event_type . ']';
  354.  
  355.     // Perform the shortcode
  356.     //echo $full_shortcode;
  357.     echo do_shortcode( $full_shortcode );
  358.  
  359.     // Stop the script before WordPress tries to display a template file.
  360.     exit;
  361.   }
  362. }
  363. add_action('init', 'events_shortcode_ajax_wrapper');
  364.  
  365. function events_search_ajax_wrapper() {
  366.   if ( !empty($_REQUEST['ev_ajax_search']) ) {
  367.         $terms = sanitize_text_field($_REQUEST['ev_ajax_search']);
  368.         $events = custom_events_search($terms);
  369.         if (!empty($events)){
  370.             ?>
  371.         <section class="maineventsList">
  372.           <div>
  373.             <div class="blockBody">
  374.               <div class="events">
  375.  
  376.               <ul class="listingHolder">
  377.               <?php
  378.                 foreach ($events as $event) {
  379.                     echo event_html_wrapper($event['url']);
  380.                 }
  381.                 ?>
  382.                 </ul>
  383.  
  384.                 </div>
  385.             </div>
  386.             </div>
  387.  
  388.         </section>             
  389.         <?php }
  390.     exit;
  391.   }
  392. }
  393. add_action('init', 'events_search_ajax_wrapper');
  394.  
  395. /*
  396. function random_event_func() {
  397.     global $wpdb;
  398.     $query_event = "SELECT COUNT(event_id) FROM in5_ci_events;";
  399.     $event_query_result = $wpdb->get_results($query_event, ARRAY_N);
  400.     //$event_id;
  401.     $events_total = $event_query_result[0][0];
  402.     //echo $events_total;
  403.     $min=1;
  404.     $max=$events_total;
  405.     $random_event_id =  mt_rand($min,$max);
  406.     echo past_event_html_wrapper($random_event_id);
  407. }
  408. add_shortcode( 'random_event', 'random_event_func' );
  409. */
  410.  
  411. function random_event_of_type_func($inno_center_event_type) {
  412.     global $wpdb;
  413.     $date = date('Y-m-d H:i:s');
  414.     $zerodate = '2010-01-01 00:00:00';
  415.     if (!empty($inno_center_event_type)) {
  416.         $query_event = "SELECT * FROM in5_ci_events LEFT JOIN in5_ci_innovation_center_event_types on in5_ci_events.event_typeId = in5_ci_innovation_center_event_types.innovation_center_event_type_id WHERE in5_ci_innovation_center_event_types.innovation_center_id = $inno_center_event_type AND in5_ci_innovation_center_event_types.innovation_center_event_type_id = in5_ci_events.event_typeId AND in5_ci_events.event_from < '$date' AND in5_ci_events.event_from > '$zerodate' ORDER BY RAND() LIMIT 1;";
  417.         $event_query_result = $wpdb->get_results($query_event, ARRAY_A);
  418.         //echo $query_event;
  419.         $random_event_id = $event_query_result[0]['event_id'];
  420.         if ($random_event_id!=0 && !empty($random_event_id)) {
  421.             echo past_event_html_wrapper($random_event_id);
  422.         }
  423.                
  424.     }
  425.     else {
  426.         echo '';
  427.     }
  428. }
  429.  
  430. add_shortcode( 'random_event_of_type', 'random_event_of_type_func' );
  431.  
  432.  
  433. function random_events_of_type_shortcode_ajax_wrapper() {
  434.   if ( !empty($_REQUEST['rand_event']) ) {
  435.  
  436.     $event_type = $_GET['rand_event'];
  437.     echo random_event_of_type_func($event_type);
  438.  
  439.     // Stop the script before WordPress tries to display a template file.
  440.     exit;
  441.   }
  442. }
  443. add_action('init', 'random_events_of_type_shortcode_ajax_wrapper');
  444.  
  445.  
  446. function past_event_html_wrapper($event_id) {
  447.     //echo $event_id;
  448.     global $wpdb;
  449.     $query_event = $wpdb->prepare("SELECT * FROM `in5_ci_events` WHERE `event_id` = %d;", $event_id);
  450.     $event_query_result = $wpdb->get_results($query_event, ARRAY_A);
  451.     //print_r($event_query_result);
  452.     $event = $event_query_result[0];
  453.     $event_id = $event['event_id'];
  454.     $query_event = "SELECT event_typeId FROM `in5_ci_events` WHERE `event_id` = $event_id;";
  455.     $event_query_result = $wpdb->get_results($query_event, ARRAY_N);
  456.     $event_typeid = $event_query_result[0][0];
  457.     $query_event_type = "SELECT * FROM `in5_ci_event_type` WHERE `event_typeid` = $event_typeid;";
  458.     $event_type_query_result = $wpdb->get_results($query_event_type, ARRAY_A);
  459.     $event_type = $event_type_query_result[0]['desc_en'];
  460.     //check if image for the event exists, otherwise put a placeholder
  461.     $pageURL = get_home_url();
  462.     $imgurl= empty($event['event_banner'])? $pageURL . "/application/uploads/events/Events_home_hldr.png" : (  strpos($event['event_banner'], 'uploads/events/')!== false ? $pageURL . "/application/" . $event['event_banner']: $event['event_banner']) ;
  463.     if (!checkRemoteFile($imgurl)) {$imgurl = $pageURL . "/application/uploads/events/Events_home_hldr.png";}
  464.  
  465.                 $str .= '    <div class="listingItem">';
  466.  
  467.                 $event_url = "/events-details/?event_id=" . $event['event_id'];
  468.  
  469.                 $str .= '<div class="listingImage" data-mh="sameHeights"><a href="' . $event_url . '"><img src="' . esc_url($imgurl) . '"></a></div>';
  470.  
  471.                 $str .= '<div class="listingInfos" data-mh="sameHeights">';
  472.  
  473.                 $str .= '<div class = "event_type_wrapper_in_bottom_widget"><span class="eventCat">'.  $event_type . '</span></div>';
  474.                
  475.                 $str .= '<h3 class="listingTitle" data-mh="sameHeight">' . $event['event_name'] . '</h3>';
  476.  
  477.                 $str .= '</div>';
  478.  
  479.                 $str .= '<div class="catTitle">When: <strong>' . (strpos($event['event_from'], '3000')!==false ? 'TBC' : date('d M Y',strtotime($event['event_from'])))  . '</strong> | Where: <strong>' . $event['event_location'] . '</strong></div>';
  480.            
  481.                 $str .= '<div style="clear:both"></div>';                
  482.                 $str .= '</div>';
  483.            
  484.     return $str;
  485. }
  486.  
  487. function event_html_wrapper($event_id) {
  488.     //echo $event_id;
  489.     global $wpdb;
  490.     $query_event = $wpdb->prepare("SELECT * FROM `in5_ci_events` WHERE `event_id` = %d;", $event_id);
  491.     $event_query_result = $wpdb->get_results($query_event, ARRAY_A);
  492.     //print_r($event_query_result);
  493.     $event = $event_query_result[0];
  494.     $event_id = $event['event_id'];
  495.     $query_event = "SELECT event_typeId FROM `in5_ci_events` WHERE `event_id` = $event_id;";
  496.     $event_query_result = $wpdb->get_results($query_event, ARRAY_N);
  497.     $event_typeid = $event_query_result[0][0];
  498.     $query_event_type = "SELECT * FROM `in5_ci_event_type` WHERE `event_typeid` = $event_typeid;";
  499.     $event_type_query_result = $wpdb->get_results($query_event_type, ARRAY_A);
  500.     $event_type = $event_type_query_result[0]['desc_en'];
  501.     //check if image for the event exists, otherwise put a placeholder
  502.     $pageURL = get_home_url();
  503.     $imgurl= empty($event['event_banner'])? $pageURL . "/application/uploads/events/Events_home_hldr.png" : (  strpos($event['event_banner'], 'uploads/events/')!== false ? $pageURL . "/application/" . $event['event_banner']: $event['event_banner']) ;
  504.     if (!checkRemoteFile($imgurl)) {$imgurl = $pageURL . "/application/uploads/events/Events_home_hldr.png";}
  505.  
  506.     $str .= '  <li class="listingItemLI col-md-12">';
  507.  
  508.                 $str .= '  <input type="hidden" value="' . $event['event_id'] . '"/>';
  509.  
  510.                 $str .= '    <div class="listingItem">';
  511.  
  512.                 $event_url = "/events-details/?event_id=" . $event['event_id'];
  513.  
  514.                 $str .= '<div class="listingImage" data-mh="sameHeights"><img src="' . esc_url($imgurl) . '"></div>';
  515.  
  516.                 $str .= '<div class="listingInfos" data-mh="sameHeights">';
  517.  
  518.                // $str .= '<div class="catTitle">When: <strong>' . date('d M Y',strtotime($event['event_from'])) . '</strong> | Where: <strong>' . $event['event_location'] . '</strong></div>';
  519.  
  520.                 $str .= '<div class="catTitle">When: <strong>' . (strpos($event['event_from'], '3000')!==false ? 'TBC' : date('d M Y',strtotime($event['event_from'])))  . '</strong> | Where: <strong>' . $event['event_location'] . '</strong></div>';
  521.  
  522.                
  523.                 $str .= '<h3 class="listingTitle" data-mh="sameHeight">' . $event['event_name'] . '</h3>';
  524.  
  525.                 $str .= '<div class="listingDescription">' . mb_strimwidth($event['event_description'],0,460,"...<br><br>") . '</div>';
  526.  
  527.                 $str .= '</div>';
  528.  
  529.                 $str .= '<div class="bottomLinks">';
  530.  
  531.  
  532.                 $str .= '<span class="eventCat">'.  $event_type . '</span>';
  533.  
  534.                 $str .= '<p class = "event_link"><a href="' . $event_url . '">Learn More  <i class="fa fa-arrow-right" aria-hidden="true"></i></a></p>';
  535.                 $str .= '</div>';               $str .= '<div style="clear:both"></div>';                $str .= '</div>';
  536.  
  537.                 $str .= '</li>';
  538.  
  539.            
  540.     return $str;
  541. }
  542.  
  543.  
  544.  
  545.  
  546. function unregister_user_for_event($user_id, $event_id) {
  547.     global $wpdb;
  548.     $query = $wpdb->prepare("DELETE FROM `events_registration` WHERE ID = %d AND event_id = %d;", $user_id, $event_id);
  549.     $wpdb->query($query);
  550.     return;
  551. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement