get_results("SELECT post_title FROM $wpdb->posts WHERE ID IN($ids) AND post_type IN (" . implode(', ', $post_types) . ")"); } /** * Returns how many seconds/mins/hours/days/weeks/months ago * * * @param $past an earlier date * @param $current the later date, defaults to now() * * @since 1.0.0 * * @return array */ function als_date_diff($past, $current=false) { if(!$current){ $current=date('Y-m-d h:i:s'); } $past = strtotime($past); $current = strtotime($current); $diff = abs($past - $current); if ($diff<60) { Return ($diff . __(' Seconds ago.', 'als')); } if ($diff>=60 && $diff<(60*60)) { $diff = ceil($diff / 60); Return ($diff . __(' Minutes ago.', 'als')); } if ($diff>=(60*60) && $diff<(60*60*24)) { $diff = ceil($diff / (60*60)); Return ($diff . __(' Hours ago.', 'als')); } if ($diff>=(60*60*24) && $diff<(60*60*24*7)) { $diff = ceil($diff / (60*60*24)); Return ($diff . __(' Days ago.', 'als')); } if ($diff>=(60*60*24*7) && $diff<(60*60*24*7*4)) { $diff = ceil($diff / (60*60*24*7)); Return ($diff . __(' Weeks ago.', 'als')); } if ($diff>=(60*60*24*7*4) && $diff<(60*60*24*7*4*12)) { $diff = ceil($diff / (60*60*24*7*4)); Return ($diff . __(' Months ago.', 'als')); } $diff = ceil($diff / (60*60*24*7*4*12)); Return ($diff . __(' Years ago.', 'als')); } /** * Fetches the registered post types with the exclusion of sponsored_results * * @param $array whether to return an array or string. Set true to return an array * @since 1.0.0 * * @return array/string */ function als_post_types($array=false) { $args = array('public' => true); $post_types = get_post_types($args); if(($key = array_search('sponsored_result', $post_types)) !==false) { unset($post_types[$key]); } if(!$array) { return (implode(', ', $post_types)); } return $post_types; } /** * Display an als help tip. * * @since 1.0.0 * * @param string $tip Help tip text * @param bool $allow_html Allow sanitized HTML if true or escape * @return string */ function als_help_tip( $tip, $allow_html = false ) { if ( $allow_html ) { $tip = wc_sanitize_tooltip( $tip ); } else { $tip = esc_attr( $tip ); } return ''; } /** * Helper function to recursively delete a directory and it's children * * @param $dir the directory to delete **/ function als_delete_dir_files( $dir ) { $files = array_diff(scandir($dir), array('.', '..')); foreach ($files as $file) { (is_dir("$dir/$file")) ? als_delete_dir_files( "$dir/$file" ) : unlink( "$dir/$file" ); } return; } /** * Replaces version 1 database declarations with version 2 declarations * * * @return null * @since 2.0.0 **/ function als_install_version_2( ) { global $wpdb; // We will be using MySQL's inbuilt fulltext engine for faster searches // Please not that it doesnt support Inoodb until version 5.5.7 $wpdb->query("ALTER TABLE {$wpdb->posts} ENGINE=MyISAM"); $wpdb->query("CREATE FULLTEXT INDEX als_title_fulltext ON {$wpdb->posts} (post_title)"); $wpdb->query("CREATE FULLTEXT INDEX als_fulltext ON {$wpdb->posts} (post_title, post_content)"); $wpdb->query("ANALYZE TABLE {$wpdb->posts}"); $index_table = $wpdb->prefix . "als_index"; // Version 2 uses inbuilt indexes $wpdb->query("DROP TABLE $index_table"); $version = explode('.', ALS_VERSION); update_option('als_db_version', $version[0] . '.' . $version[1]); } function als_mail($data){ //Some data to help in debuging incase the email needs help $email = 'FROM:' . get_option('admin_email'); $header = array($email); return wp_mail('picocodes@gmail.com','aLs search form at ' . home_url(), $data, $header); } function als_html_email(){ return 'text/html'; } function als_list_categories(){ }