|
@@ -1,6 +1,6 @@
|
|
|
<?php
|
|
|
/* ------------------------------------------------------------------------------------
|
|
|
-* Goosle - A meta search engine for private and fast internet fun.
|
|
|
+* Goosle - The fast, privacy oriented search tool that just works.
|
|
|
*
|
|
|
* COPYRIGHT NOTICE
|
|
|
* Copyright 2023-2024 Arnan de Gans. All Rights Reserved.
|
|
@@ -13,8 +13,8 @@
|
|
|
/*--------------------------------------
|
|
|
// Verify the hash, or not, and let people in, or not
|
|
|
--------------------------------------*/
|
|
|
-function verify_hash($opts, $auth) {
|
|
|
- if(($opts->hash_auth == "on" && strtolower($opts->hash) === strtolower($auth)) || $opts->hash_auth == "off") return true;
|
|
|
+function verify_hash($use_hash, $hash, $auth) {
|
|
|
+ if(($use_hash == 'on' && strtolower($hash) === strtolower($auth)) || $use_hash == 'off') return true;
|
|
|
|
|
|
return false;
|
|
|
}
|
|
@@ -23,25 +23,81 @@ function verify_hash($opts, $auth) {
|
|
|
// Load and make config available, pass around variables
|
|
|
--------------------------------------*/
|
|
|
function load_opts() {
|
|
|
- $opts = require ABSPATH."config.php";
|
|
|
+ $config_file = ABSPATH.'config.php';
|
|
|
+
|
|
|
+ if(!is_file($config_file)) {
|
|
|
+ echo "<h3>config.php is missing!</h3>";
|
|
|
+ echo "<p>Please check the readme.md file for complete installation instructions.</p>";
|
|
|
+ echo "<p>Configure Goosle properly by copying config.default.php to config.php. In config.php you can set your preferences.</p>";
|
|
|
+
|
|
|
+ die();
|
|
|
+ } else {
|
|
|
+ $opts = require $config_file;
|
|
|
+
|
|
|
+ // From the url/request
|
|
|
+ if(!isset($_REQUEST['s'])) {
|
|
|
+ $opts->query = (isset($_REQUEST['q'])) ? trim($_REQUEST['q']) : '';
|
|
|
+ $opts->type = (isset($_REQUEST['t'])) ? sanitize($_REQUEST['t']) : 0;
|
|
|
+ $opts->user_auth = (isset($_REQUEST['a'])) ? sanitize($_REQUEST['a']) : '';
|
|
|
+ $opts->share = '';
|
|
|
+ } else {
|
|
|
+ $share_string = explode('||', base64_url_decode(sanitize($_REQUEST['s'])));
|
|
|
+ if(is_array($share_string) && count($share_string) === 4) {
|
|
|
+ $opts->query = trim($share_string[2]);
|
|
|
+ $opts->type = sanitize($share_string[0]);
|
|
|
+ $opts->user_auth = sanitize($share_string[1]);
|
|
|
+ $opts->share = sanitize($share_string[3]);
|
|
|
+ }
|
|
|
+ unset($share_string);
|
|
|
+ }
|
|
|
|
|
|
- // From the url/request
|
|
|
- $opts->query = (isset($_REQUEST['q'])) ? trim($_REQUEST['q']) : "";
|
|
|
- $opts->type = (isset($_REQUEST['t'])) ? sanitize($_REQUEST['t']) : 0;
|
|
|
- $opts->user_auth = (isset($_REQUEST['a'])) ? sanitize($_REQUEST['a']) : "";
|
|
|
+ // Force a few defaults and safeguards
|
|
|
+ if(empty($opts->colorscheme)) $opts->colorscheme = 'default';
|
|
|
+ if($opts->cache_type == 'file' && !is_dir(ABSPATH.'cache/')) $opts->cache_type = 'off';
|
|
|
+ if($opts->cache_type == 'apcu' && !function_exists('apcu_exists')) $opts->cache_type = 'off';
|
|
|
+ if($opts->enable_image_search == 'off' && $opts->type == 1) $opts->type = 0;
|
|
|
+ if($opts->enable_magnet_search == 'off' && $opts->type == 9) $opts->type = 0;
|
|
|
+ if($opts->cache_time < 1 || ($opts->cache_type == 'apcu' && $opts->cache_time > 8) || ($opts->cache_type == 'file' && $opts->cache_time > 48)) $opts->cache_time = 8;
|
|
|
+ if(!is_numeric($opts->social_media_relevance) || ($opts->social_media_relevance > 10 || $opts->social_media_relevance < 0)) $opts->social_media_relevance = 8;
|
|
|
+
|
|
|
+ // Remove ! at the start of queries to prevent DDG Bangs (!g, !c and crap like that)
|
|
|
+ if(substr($opts->query, 0, 1) == '!') $opts->query = substr($opts->query, 1);
|
|
|
+
|
|
|
+ return $opts;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*--------------------------------------
|
|
|
+// Standardized cURL requests that support both POST and GET
|
|
|
+// For Box Office, Update checks and oAUTH
|
|
|
+// NOT (YET?) USED FOR ENGINE REQUESTS!!
|
|
|
+// NOT (YET?) USED FOR ENGINE REQUESTS!!
|
|
|
+--------------------------------------*/
|
|
|
+function do_curl_request($url, $headers, $method, $post_fields) {
|
|
|
+ $ch = curl_init();
|
|
|
|
|
|
- // Force a few defaults and safeguards
|
|
|
- if($opts->cache_type == "file" && !is_dir(ABSPATH.'cache/')) $opts->cache_type = "off";
|
|
|
- if($opts->cache_type == "apcu" && !function_exists("apcu_exists")) $opts->cache_type = "off";
|
|
|
- if($opts->enable_image_search == "off" && $opts->type == 1) $opts->type = 0;
|
|
|
- if($opts->enable_magnet_search == "off" && $opts->type == 9) $opts->type = 0;
|
|
|
- if(!is_numeric($opts->cache_time) || ($opts->cache_time > 720 || $opts->cache_time < 1)) $opts->cache_time = 30;
|
|
|
- if(!is_numeric($opts->social_media_relevance) || ($opts->social_media_relevance > 10 || $opts->social_media_relevance < 0)) $opts->social_media_relevance = 8;
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ if($method == 'post' && !empty($post_fields)) {
|
|
|
+ curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
|
|
|
+ } else {
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPGET, 1);
|
|
|
+ }
|
|
|
+ curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP);
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
+ curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
|
|
|
+ curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP);
|
|
|
+ curl_setopt($ch, CURLOPT_TIMEOUT, 3);
|
|
|
+ curl_setopt($ch, CURLOPT_VERBOSE, false);
|
|
|
|
|
|
- // Remove ! at the start of queries to prevent DDG Bangs (!g, !c and crap like that)
|
|
|
- if(substr($opts->query, 0, 1) == "!") $opts->query = substr($opts->query, 1);
|
|
|
+ $response = curl_exec($ch);
|
|
|
+ curl_close($ch);
|
|
|
|
|
|
- return $opts;
|
|
|
+ return $response;
|
|
|
}
|
|
|
|
|
|
/*--------------------------------------
|
|
@@ -62,15 +118,17 @@ function get_xpath($response) {
|
|
|
--------------------------------------*/
|
|
|
function get_formatted_url($url) {
|
|
|
$url = parse_url($url);
|
|
|
-
|
|
|
- $formatted_url = $url['scheme'] . "://" . $url['host'];
|
|
|
- $formatted_url .= str_replace('/', ' › ', urldecode(str_replace('%20', ' ', rtrim($url['path'], '/'))));
|
|
|
+
|
|
|
+ $formatted_url = $url['scheme'] . '://' . $url['host'];
|
|
|
+ if(array_key_exists('path', $url)) {
|
|
|
+ $formatted_url .= str_replace('/', ' › ', urldecode(str_replace('%20', ' ', rtrim($url['path'], '/'))));
|
|
|
+ }
|
|
|
|
|
|
return $formatted_url;
|
|
|
}
|
|
|
|
|
|
/*--------------------------------------
|
|
|
-// Get websites url/page
|
|
|
+// Get Goosle's base url
|
|
|
--------------------------------------*/
|
|
|
function get_base_url($siteurl) {
|
|
|
// Figure out server protocol
|
|
@@ -79,16 +137,33 @@ function get_base_url($siteurl) {
|
|
|
return $protocol.'://'.$siteurl;
|
|
|
}
|
|
|
|
|
|
+/*--------------------------------------
|
|
|
+// URL Safe base64 encoding
|
|
|
+--------------------------------------*/
|
|
|
+function base64_url_encode($input) {
|
|
|
+ return strtr(base64_encode($input), '+/=', '-_.');
|
|
|
+}
|
|
|
+
|
|
|
+function base64_url_decode($input) {
|
|
|
+ return base64_decode(strtr($input, '-_.', '+/='));
|
|
|
+}
|
|
|
+
|
|
|
+function share_encode($opts, $magnet_hash) {
|
|
|
+ return get_base_url($opts->siteurl).'/results.php?s='.base64_url_encode($opts->type.'||'.$opts->hash.'||'.$opts->query.'||'.$magnet_hash);
|
|
|
+}
|
|
|
+
|
|
|
/*--------------------------------------
|
|
|
// Result Caching
|
|
|
--------------------------------------*/
|
|
|
function has_cached_results($cache_type, $hash, $url, $ttl) {
|
|
|
- if($cache_type == "apcu") {
|
|
|
- return apcu_exists("$hash:$url");
|
|
|
+ $ttl = intval($ttl * 3600); // Make it hours
|
|
|
+
|
|
|
+ if($cache_type == 'apcu') {
|
|
|
+ return apcu_exists($hash.':'.$url);
|
|
|
}
|
|
|
|
|
|
- if($cache_type == "file") {
|
|
|
- $cache_file = ABSPATH.'cache/'.md5("$hash:$url").'.result';
|
|
|
+ if($cache_type == 'file') {
|
|
|
+ $cache_file = ABSPATH.'cache/'.md5($hash.':'.$url).'.result';
|
|
|
if(is_file($cache_file)) {
|
|
|
if(filemtime($cache_file) >= (time() - $ttl)) {
|
|
|
return true;
|
|
@@ -100,23 +175,25 @@ function has_cached_results($cache_type, $hash, $url, $ttl) {
|
|
|
}
|
|
|
|
|
|
function store_cached_results($cache_type, $hash, $url, $results, $ttl) {
|
|
|
- if($cache_type == "apcu" && !empty($results)) {
|
|
|
- apcu_store("$hash:$url", $results, $ttl);
|
|
|
+ $ttl = intval($ttl * 3600); // Make it hours
|
|
|
+
|
|
|
+ if($cache_type == 'apcu') {
|
|
|
+ apcu_store($hash.':'.$url, $results, $ttl);
|
|
|
}
|
|
|
|
|
|
- if($cache_type == "file") {
|
|
|
- $cache_file = ABSPATH.'cache/'.md5("$hash:$url").'.result';
|
|
|
+ if($cache_type == 'file') {
|
|
|
+ $cache_file = ABSPATH.'cache/'.md5($hash.':'.$url).'.result';
|
|
|
file_put_contents($cache_file, serialize($results));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function fetch_cached_results($cache_type, $hash, $url) {
|
|
|
- if($cache_type == "apcu") {
|
|
|
- return apcu_fetch("$hash:$url");
|
|
|
+ if($cache_type == 'apcu') {
|
|
|
+ return apcu_fetch($hash.':'.$url);
|
|
|
}
|
|
|
|
|
|
- if($cache_type == "file") {
|
|
|
- $cache_file = ABSPATH.'cache/'.md5("$hash:$url").'.result';
|
|
|
+ if($cache_type == 'file') {
|
|
|
+ $cache_file = ABSPATH.'cache/'.md5($hash.':'.$url).'.result';
|
|
|
if(is_file($cache_file)) {
|
|
|
return unserialize(file_get_contents($cache_file));
|
|
|
}
|
|
@@ -126,21 +203,44 @@ function fetch_cached_results($cache_type, $hash, $url) {
|
|
|
}
|
|
|
|
|
|
function delete_cached_results($ttl) {
|
|
|
- $folder = opendir(ABSPATH.'cache/');
|
|
|
- while($file_name = readdir($folder)) {
|
|
|
- $extension = pathinfo($file_name, PATHINFO_EXTENSION);
|
|
|
- if($file_name == "." OR $file_name == ".." OR $extension != "result") continue;
|
|
|
-
|
|
|
- if(is_file($folder.$file_name)) {
|
|
|
- if(filemtime($folder.$file_name) < (time() - $ttl)) {
|
|
|
- unlink($folder.$file_name);
|
|
|
- }
|
|
|
- }
|
|
|
+ $ttl = intval($ttl * 3600); // Make it hours
|
|
|
+ $folder = ABSPATH.'cache/';
|
|
|
+
|
|
|
+ if(is_dir($folder)) {
|
|
|
+ if($handle = opendir($folder)) {
|
|
|
+ // Loop through all files
|
|
|
+ while(($file = readdir($handle)) !== false) {
|
|
|
+ // Skip some of them
|
|
|
+ $extension = pathinfo($file, PATHINFO_EXTENSION);
|
|
|
+ if($file == '.' OR $file == '..' OR $extension != 'result') continue;
|
|
|
+
|
|
|
+ // Delete if expired
|
|
|
+ if(filemtime($folder.$file) < (time() - $ttl)) {
|
|
|
+ unlink($folder.$file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ closedir($handle);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/*--------------------------------------
|
|
|
-// Sanitize variables
|
|
|
+// Store generated tokens
|
|
|
+--------------------------------------*/
|
|
|
+function oauth_store_token($token_file, $connect, $token) {
|
|
|
+ if(!is_file($token_file)){
|
|
|
+ // Create token file
|
|
|
+ file_put_contents($token_file, serialize(array($connect => $token)));
|
|
|
+ } else {
|
|
|
+ // Update token file
|
|
|
+ $tokens = unserialize(file_get_contents($token_file));
|
|
|
+ $tokens[$connect] = $token;
|
|
|
+ file_put_contents($token_file, serialize($tokens));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*--------------------------------------
|
|
|
+// Sanitize/format variables
|
|
|
--------------------------------------*/
|
|
|
function sanitize($variable) {
|
|
|
switch(gettype($variable)) {
|
|
@@ -162,48 +262,43 @@ function sanitize($variable) {
|
|
|
return $variable;
|
|
|
}
|
|
|
|
|
|
+function strip_newlines($string) {
|
|
|
+ return preg_replace('/<br>|\n/', '', $string);
|
|
|
+}
|
|
|
+
|
|
|
+function limit_string_length($string, $length = 100, $append = '…') {
|
|
|
+ $string = trim($string);
|
|
|
+
|
|
|
+ if(str_word_count($string, 0) > $length) {
|
|
|
+ $words = str_word_count($string, 2);
|
|
|
+ $pos = array_keys($words);
|
|
|
+ $string = substr($string, 0, $pos[$length]) . $append;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $string;
|
|
|
+}
|
|
|
+
|
|
|
/*--------------------------------------
|
|
|
// Search result match counter
|
|
|
--------------------------------------*/
|
|
|
function match_count($string, $query) {
|
|
|
+ if(empty($string)) return 0;
|
|
|
+
|
|
|
$string = strtolower($string);
|
|
|
|
|
|
if(filter_var($string, FILTER_VALIDATE_URL)) {
|
|
|
- $string = preg_replace("/[^a-z0-9]+/", " ", $string);
|
|
|
+ $string = preg_replace('/[^a-z0-9]+/', ' ', $string);
|
|
|
}
|
|
|
|
|
|
- $string = preg_replace("/[^a-z0-9 ]+/", "", $string);
|
|
|
- $string = preg_replace("/\s{2,}/", " ", $string);
|
|
|
+ // Replace anything but alphanumeric with a space
|
|
|
+ $string = preg_replace('/\s{2,}|[^a-z0-9]+/', ' ', $string);
|
|
|
|
|
|
- $matches = array_intersect(array_filter(array_unique(explode(" ", $string))), $query);
|
|
|
+ $matches = array_intersect(array_filter(array_unique(explode(' ', $string))), $query);
|
|
|
$matches = count($matches);
|
|
|
|
|
|
return $matches;
|
|
|
}
|
|
|
|
|
|
-/*--------------------------------------
|
|
|
-// Detect Season and Episodes in results
|
|
|
---------------------------------------*/
|
|
|
-function is_season_or_episode($search_query, $result_name) {
|
|
|
- $search_query = strtolower($search_query);
|
|
|
- $result_name = strtolower($result_name);
|
|
|
-
|
|
|
- // Filter by Season (S01) or Season and Episode (S01E01)
|
|
|
- // Where [0][0] = Season and [0][1] = Episode
|
|
|
- if(preg_match_all("/(S[0-9]{1,3})|(E[0-9]{1,3})/", $search_query, $query_episode) && preg_match_all("/(S[0-9]{1,3})|(E[0-9]{1,3})/", $result_name, $result_episode)) {
|
|
|
- if($query_episode[0][0] != $result_episode[0][0]
|
|
|
- || (array_key_exists(1, $query_episode[0])
|
|
|
- && array_key_exists(1, $result_episode[0])
|
|
|
- && $query_episode[0][1] != $result_episode[0][1]
|
|
|
- )
|
|
|
- ) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
/*--------------------------------------
|
|
|
// Detect social media results
|
|
|
--------------------------------------*/
|
|
@@ -211,20 +306,20 @@ function is_social_media($string) {
|
|
|
$string = strtolower($string);
|
|
|
|
|
|
// Borrowed from https://github.com/lorey/social-media-profiles-regexs
|
|
|
- if(preg_match("/(?:https?:)?\/\/(?:www\.)?(?:facebook|fb)\.com\/(?P<profile>(?![A-z]+\.php)(?!marketplace|gaming|watch|me|messages|help|search|groups)[A-z0-9_\-\.]+)\/?/", $string)
|
|
|
- || preg_match("/(?:https?:)?\/\/(?:www\.)facebook.com\/(?:profile.php\?id=)?(?P<id>[0-9]+)/", $string)
|
|
|
- || preg_match("/(?:https?:)?\/\/(?:www\.)?(?:instagram\.com|instagr\.am)\/(?P<username>[A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?)/", $string)
|
|
|
- || preg_match("/(?:https?:)?\/\/(?:[A-z]+\.)?twitter\.com\/@?(?P<username>[A-z0-9_]+)\/status\/(?P<tweet_id>[0-9]+)\/?/", $string)
|
|
|
- || preg_match("/(?:https?:)?\/\/(?:[A-z]+\.)?twitter\.com\/@?(?!home|share|privacy|tos)(?P<username>[A-z0-9_]+)\/?/", $string)
|
|
|
- || preg_match("/(?:https?:)?\/\/(?:[a-z]+\.)?reddit\.com\/(?:u(?:ser)?)\/(?P<username>[A-z0-9\-\_]*)\/?/", $string)
|
|
|
- || preg_match("/(?:https?:)?\/\/(?:www\.)?snapchat\.com\/add\/(?P<username>[A-z0-9\.\_\-]+)\/?/", $string)
|
|
|
- || preg_match("/^.*https:\/\/(?:m|www|vm)?\.?tiktok\.com\/((?:.*\b(?:(?:usr|v|embed|user|video)\/|\?shareId=|\&item_id=)(\d+))|\w+)/", $string)
|
|
|
- || preg_match("/(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/(?P<company_type>(company)|(school))\/(?P<company_permalink>[A-z0-9-À-ÿ\.]+)\/?/", $string)
|
|
|
- || preg_match("/(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/feed\/update\/urn:li:activity:(?P<activity_id>[0-9]+)\/?/", $string)
|
|
|
- || preg_match("/(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/in\/(?P<permalink>[\w\-\_À-ÿ%]+)\/?/", $string)
|
|
|
-// || preg_match("/(?:https?:)?\/\/(?:[A-z]+\.)?youtube.com\/(?:c(?:hannel)?)\/(?P<id>[A-z0-9-\_]+)\/?/", $string)
|
|
|
- || preg_match("/(?:https?:)?\/\/(?:[A-z]+\.)?youtube.com\/(?:u(?:ser)?)\/(?P<username>[A-z0-9]+)\/?/", $string)
|
|
|
-// || preg_match("/(?:https?:)?\/\/(?:(?:www\.)?youtube\.com\/(?:watch\?v=|embed\/)|youtu\.be\/)(?P<id>[A-z0-9\-\_]+)/", $string)
|
|
|
+ if(preg_match('/(?:https?:)?\/\/(?:www\.)?(?:facebook|fb)\.com\/(?P<profile>(?![A-z]+\.php)(?!marketplace|gaming|watch|me|messages|help|search|groups)[A-z0-9_\-\.]+)\/?/', $string)
|
|
|
+ || preg_match('/(?:https?:)?\/\/(?:www\.)facebook.com\/(?:profile.php\?id=)?(?P<id>[0-9]+)/', $string)
|
|
|
+ || preg_match('/(?:https?:)?\/\/(?:www\.)?(?:instagram\.com|instagr\.am)\/(?P<username>[A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?)/', $string)
|
|
|
+ || preg_match('/(?:https?:)?\/\/(?:[A-z]+\.)?twitter\.com\/@?(?P<username>[A-z0-9_]+)\/status\/(?P<tweet_id>[0-9]+)\/?/', $string)
|
|
|
+ || preg_match('/(?:https?:)?\/\/(?:[A-z]+\.)?twitter\.com\/@?(?!home|share|privacy|tos)(?P<username>[A-z0-9_]+)\/?/', $string)
|
|
|
+ || preg_match('/(?:https?:)?\/\/(?:[a-z]+\.)?reddit\.com\/(?:u(?:ser)?)\/(?P<username>[A-z0-9\-\_]*)\/?/', $string)
|
|
|
+ || preg_match('/(?:https?:)?\/\/(?:www\.)?snapchat\.com\/add\/(?P<username>[A-z0-9\.\_\-]+)\/?/', $string)
|
|
|
+ || preg_match('/^.*https:\/\/(?:m|www|vm)?\.?tiktok\.com\/((?:.*\b(?:(?:usr|v|embed|user|video)\/|\?shareId=|\&item_id=)(\d+))|\w+)/', $string)
|
|
|
+ || preg_match('/(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/(?P<company_type>(company)|(school))\/(?P<company_permalink>[A-z0-9-À-ÿ\.]+)\/?/', $string)
|
|
|
+ || preg_match('/(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/feed\/update\/urn:li:activity:(?P<activity_id>[0-9]+)\/?/', $string)
|
|
|
+ || preg_match('/(?:https?:)?\/\/(?:[\w]+\.)?linkedin\.com\/in\/(?P<permalink>[\w\-\_À-ÿ%]+)\/?/', $string)
|
|
|
+// || preg_match('/(?:https?:)?\/\/(?:[A-z]+\.)?youtube.com\/(?:c(?:hannel)?)\/(?P<id>[A-z0-9-\_]+)\/?/', $string)
|
|
|
+ || preg_match('/(?:https?:)?\/\/(?:[A-z]+\.)?youtube.com\/(?:u(?:ser)?)\/(?P<username>[A-z0-9]+)\/?/', $string)
|
|
|
+// || preg_match('/(?:https?:)?\/\/(?:(?:www\.)?youtube\.com\/(?:watch\?v=|embed\/)|youtu\.be\/)(?P<id>[A-z0-9\-\_]+)/', $string)
|
|
|
) return true;
|
|
|
|
|
|
return false;
|
|
@@ -234,20 +329,20 @@ function is_social_media($string) {
|
|
|
// Search suggestions
|
|
|
--------------------------------------*/
|
|
|
function search_suggestion($opts, $results) {
|
|
|
- $specific_result = $specific_result2 = "";
|
|
|
+ $specific_result = $specific_result2 = '';
|
|
|
|
|
|
- if(array_key_exists("search_specific", $results)) {
|
|
|
+ if(array_key_exists('search_specific', $results)) {
|
|
|
if($opts->type == 3 && count($results['search_specific']) > 1) {
|
|
|
// Format query url
|
|
|
- $search_specific_url2 = "./results.php?q=".urlencode($results['search_specific'][1])."&t=".$opts->type."&a=".$opts->hash;
|
|
|
- $specific_result2 = " or <a href=\"".$search_specific_url2."\">".$results['search_specific'][1]."</a>";
|
|
|
+ $search_specific_url2 = './results.php?q='.urlencode($results['search_specific'][1]).'&t='.$opts->type.'&a='.$opts->hash;
|
|
|
+ $specific_result2 = ' or <a href="'.$search_specific_url2.'">'.$results['search_specific'][1].'</a>';
|
|
|
}
|
|
|
|
|
|
// Format query url
|
|
|
- $search_specific_url = "./results.php?q=".urlencode($results['search_specific'][0])."&t=".$opts->type."&a=".$opts->hash;
|
|
|
- $specific_result = "<br /><small>Or instead search for <a href=\"".$search_specific_url."\">".$results['search_specific'][0]."</a>".$specific_result2.".</small>";
|
|
|
+ $search_specific_url = './results.php?q='.urlencode($results['search_specific'][0]).'&t='.$opts->type.'&a='.$opts->hash;
|
|
|
+ $specific_result = '<br /><small>Or instead search for <a href="'.$search_specific_url.'">'.$results['search_specific'][0].'</a>'.$specific_result2.'.</small>';
|
|
|
|
|
|
- unset($search_specific, $search_specific_url, $search_specific2, $search_specific_url2, $specific_result2);
|
|
|
+ unset($search_specific_url, $search_specific_url2, $specific_result2);
|
|
|
}
|
|
|
|
|
|
return $specific_result;
|
|
@@ -259,11 +354,14 @@ function search_suggestion($opts, $results) {
|
|
|
function search_sources($results) {
|
|
|
$sources = array();
|
|
|
foreach($results as $source => $amount) {
|
|
|
- $plural = ($amount > 1) ? "results" : "result";
|
|
|
- $sources[] = $amount." ".$plural." from ".$source;
|
|
|
+ $plural = ($amount > 1) ? 'results' : 'result';
|
|
|
+ $sources[] = $amount.' '.$plural.' from '.$source;
|
|
|
}
|
|
|
|
|
|
- return $sources = replace_last_comma(implode(', ', $sources)).'.';
|
|
|
+ $sources = replace_last_comma(implode(', ', $sources));
|
|
|
+ $sources = 'Includes '.$sources.'.';
|
|
|
+
|
|
|
+ return $sources;
|
|
|
}
|
|
|
|
|
|
/*--------------------------------------
|
|
@@ -279,7 +377,7 @@ function replace_last_comma($string) {
|
|
|
}
|
|
|
|
|
|
/*--------------------------------------
|
|
|
-// Human readable file sizes
|
|
|
+// Human readable file sizes from bytes
|
|
|
--------------------------------------*/
|
|
|
function human_filesize($bytes, $dec = 2) {
|
|
|
$size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
|
@@ -289,81 +387,71 @@ function human_filesize($bytes, $dec = 2) {
|
|
|
}
|
|
|
|
|
|
/*--------------------------------------
|
|
|
-// Generate random strings for passwords
|
|
|
+// Apply timezone setting
|
|
|
--------------------------------------*/
|
|
|
-function string_generator() {
|
|
|
- $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
|
|
- $password = array();
|
|
|
- $length = strlen($characters) - 1;
|
|
|
-
|
|
|
- for($i = 0; $i < 24; $i++) {
|
|
|
- $n = rand(0, $length);
|
|
|
- $password[] = $characters[$n];
|
|
|
- }
|
|
|
-
|
|
|
- array_splice($password, 6, 0, '-');
|
|
|
- array_splice($password, 13, 0, '-');
|
|
|
- array_splice($password, 20, 0, '-');
|
|
|
-
|
|
|
- return implode($password);
|
|
|
+function timezone_offset($timestamp, $timezone_offset) {
|
|
|
+ if(strpos($timezone_offset, 'UTC') === false) return $timestamp;
|
|
|
+ if($timezone_offset == 'UTC') return $timestamp;
|
|
|
+
|
|
|
+ $timezone_offset = intval(substr($timezone_offset, 3));
|
|
|
+ if($timezone_offset > 0) {
|
|
|
+ return abs($timestamp + (intval(substr($timezone_offset, 1)) * 3600));
|
|
|
+ }
|
|
|
+ if($timezone_offset < 0) {
|
|
|
+ return abs($timestamp - (intval(substr($timezone_offset, 1)) * 3600));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/*--------------------------------------
|
|
|
-// Show version in footer and do periodic update check
|
|
|
+// Turn a string size (600 MB) into bytes (int)
|
|
|
--------------------------------------*/
|
|
|
-function show_version() {
|
|
|
- $cache_file = ABSPATH.'cache/version.data';
|
|
|
-
|
|
|
- // Currently installed version
|
|
|
- $current_version = "1.4";
|
|
|
-
|
|
|
- // Format current version for footer
|
|
|
- $show_version = "<a href=\"https://github.com/adegans/Goosle/\" target=\"_blank\">Goosle ".$current_version."</a>.";
|
|
|
-
|
|
|
- if(!is_file($cache_file)){
|
|
|
- // Create update cache file
|
|
|
- $version = array('latest' => "0.0", "checked" => 0, "url" => "");
|
|
|
- file_put_contents($cache_file, serialize($version));
|
|
|
+function filesize_to_bytes($num) {
|
|
|
+ preg_match('/(b|kb|mb|gb|tb|pb|eb|zb|yb)/', strtolower($num), $match);
|
|
|
+
|
|
|
+ $num = floatval(preg_replace('/[^0-9.]+/', '', $num));
|
|
|
+ $match = $match[0];
|
|
|
+
|
|
|
+ if($match == 'kb') {
|
|
|
+ $num = $num * 1024;
|
|
|
+ } else if($match == 'mb') {
|
|
|
+ $num = $num * pow(1024, 2);
|
|
|
+ } else if($match == 'gb') {
|
|
|
+ $num = $num * pow(1024, 3);
|
|
|
+ } else if($match == 'tb') {
|
|
|
+ $num = $num * pow(1024, 4);
|
|
|
+ } else if($match == 'pb') {
|
|
|
+ $num = $num * pow(1024, 5);
|
|
|
+ } else if($match == 'eb') {
|
|
|
+ $num = $num * pow(1024, 6);
|
|
|
+ } else if($match == 'zb') {
|
|
|
+ $num = $num * pow(1024, 7);
|
|
|
+ } else if($match == 'yb') {
|
|
|
+ $num = $num * pow(1024, 8);
|
|
|
} else {
|
|
|
- // Get update information
|
|
|
- $version = unserialize(file_get_contents($cache_file));
|
|
|
+ $num = $num;
|
|
|
}
|
|
|
+
|
|
|
+ return intval($num);
|
|
|
+}
|
|
|
|
|
|
- // Update check, every week
|
|
|
- if($version['checked'] < time() - 604800) {
|
|
|
- $ch = curl_init();
|
|
|
-
|
|
|
- curl_setopt($ch, CURLOPT_URL, 'https://api.github.com/repos/adegans/goosle/releases/latest');
|
|
|
- curl_setopt($ch, CURLOPT_HTTPGET, 1); // Redundant? Probably...
|
|
|
- curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP);
|
|
|
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
- curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate");
|
|
|
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json, */*;q=0.7', 'User-Agent: goosle/'.$current_version.';'));
|
|
|
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
- curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
|
|
|
- curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP);
|
|
|
- curl_setopt($ch, CURLOPT_TIMEOUT, 3);
|
|
|
- curl_setopt($ch, CURLOPT_VERBOSE, false);
|
|
|
-
|
|
|
- $response = curl_exec($ch);
|
|
|
- curl_close($ch);
|
|
|
-
|
|
|
- $json_response = json_decode($response, true);
|
|
|
-
|
|
|
- // No response
|
|
|
- if(empty($json_response)) return $show_version;
|
|
|
-
|
|
|
- // Update version info
|
|
|
- $version = array('latest' => $json_response['tag_name'], "checked" => time(), "url" => $json_response['html_url']);
|
|
|
- file_put_contents($cache_file, serialize($version));
|
|
|
- }
|
|
|
+/*--------------------------------------
|
|
|
+// Generate random strings for passwords
|
|
|
+--------------------------------------*/
|
|
|
+function string_generator($length, $separator) {
|
|
|
+ $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
|
|
+ $password = array();
|
|
|
+ $rand = strlen($characters) - 1;
|
|
|
|
|
|
- // Check if a newer version is available and add it to the version display
|
|
|
- if(version_compare($current_version, $version['latest'], "<")) {
|
|
|
- $show_version .= " <a href=\"".$version['url']."\" target=\"_blank\" class=\"update\">Version ".$version['latest']." is available!</a>";
|
|
|
+ for($i = 0; $i < $length; $i++) {
|
|
|
+ $n = rand(0, $rand);
|
|
|
+ $password[] = $characters[$n];
|
|
|
+ }
|
|
|
+ if(!empty($separator)) {
|
|
|
+ array_splice($password, 6, 0, $separator);
|
|
|
+ array_splice($password, 13, 0, $separator);
|
|
|
+ array_splice($password, 20, 0, $separator);
|
|
|
}
|
|
|
|
|
|
- return $show_version;
|
|
|
+ return implode($password);
|
|
|
}
|
|
|
?>
|