280 lines
7.8 KiB
PHP
280 lines
7.8 KiB
PHP
<?php
|
|
/**
|
|
* app/plugins/notes/controllers/notes.php
|
|
*
|
|
* This is the notes controller.
|
|
*
|
|
* @package TP Notes
|
|
* @version 3.0
|
|
* @author Joey Kimsey <Joey@thetempusproject.com>
|
|
* @link https://TheTempusProject.com
|
|
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
|
*/
|
|
namespace TheTempusProject\Controllers;
|
|
|
|
use TheTempusProject\Classes\Controller;
|
|
use TheTempusProject\Classes\Plugin;
|
|
use TheTempusProject\Houdini\Classes\Views;
|
|
use TheTempusProject\Houdini\Classes\Template;
|
|
use TheTempusProject\Bedrock\Functions\Input;
|
|
use TheTempusProject\Bedrock\Functions\Date;
|
|
use TheTempusProject\TheTempusProject as App;
|
|
|
|
class Testing extends Controller {
|
|
protected static $notes;
|
|
protected static $notebooks;
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
self::$title = 'Testing- {SITENAME}';
|
|
self::$pageDescription = 'On this page you can create and manage tasks and lists.';
|
|
Template::setTemplate( 'testing' );
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function plugins() {
|
|
$filesharePlugin = 'TheTempusProject\Plugins\Contacts';
|
|
if ( class_exists( $filesharePlugin ) ) {
|
|
|
|
$plugins = new $filesharePlugin;
|
|
|
|
$x = $plugins->checkEnabled();
|
|
dv( $x );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Example usage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function dates() {
|
|
|
|
$timezone = Date::getTimezone();
|
|
$currentTime = time();
|
|
$out = date( 'H:i:s F d, Y', $currentTime );
|
|
dv( $out );
|
|
$currentDate = date( 'F d, Y', strtotime($currentTime) );
|
|
// Post
|
|
$time = Input::exists('time') ? Input::post('time') : '00:00';
|
|
|
|
|
|
|
|
|
|
|
|
$date = Input::exists('date') ? Input::post('date') : $currentDate;
|
|
// Get
|
|
$hour = Input::exists('hour') ? Input::get('hour') : '00';
|
|
$minute = Input::exists('minute') ? Input::get('minute') : '00';
|
|
$day = Input::exists('day') ? Input::get('day') : date( 'd', $currentTime );
|
|
$month = Input::exists('month') ? Input::get('month') : date( 'M', $currentTime );
|
|
$year = Input::exists('year') ? Input::get('year') : date( 'Y', $currentTime );
|
|
|
|
|
|
|
|
|
|
// Views::view( 'testing.testing' );
|
|
}
|
|
public function index() {
|
|
Views::view( 'testing.testing' );
|
|
}
|
|
public function timeTools() {
|
|
Views::view( 'testing.time' );
|
|
}
|
|
public function testBA() {
|
|
Views::view( 'testing.test2' );
|
|
}
|
|
|
|
public function generate_uuid() {
|
|
$data = random_bytes(16);
|
|
$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
|
|
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
|
|
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
|
|
|
|
// $uuid = generate_uuid();
|
|
// echo $uuid;
|
|
|
|
|
|
|
|
}
|
|
public function unshortener() {
|
|
// Example usage
|
|
$shortUrl = "http://bit.ly/example";
|
|
$finalUrl = resolveShortenedUrl($shortUrl);
|
|
echo "Final URL: " . $finalUrl;
|
|
Views::view( 'testing.test2' );
|
|
}
|
|
public function getUrlInfo() {
|
|
// Example usage
|
|
// $url = "https://www.google.com/intl/en/gmail/about/";
|
|
$url = "https://gmail.com";
|
|
// $url = "https://twitter.com/";
|
|
// $url = "https://x.com/";
|
|
// $url = "https://www.google.com/";
|
|
// $url = "https://www.apple.com/";
|
|
// $url = "https://www.php.net/manual/en/function.get-meta-tags.php";
|
|
// $url = "http://192.168.1.194:8028/";
|
|
|
|
|
|
|
|
$outUrl = $this->resolveShortenedUrl($url);
|
|
|
|
|
|
$outUrl = urldecode($outUrl);
|
|
|
|
$array = explode( '?', $outUrl );
|
|
|
|
$url = $array[0];
|
|
$params = explode( '&', $array[1] );
|
|
|
|
// echo "Decoded URL: $decoded_url";
|
|
|
|
|
|
|
|
dv( $params );
|
|
$metaInfo = $this->getMetaTagsAndFavicon($url);
|
|
// echo "Title: " . $metaInfo['title'] . "\n";
|
|
// echo "Description: " . $metaInfo['description'] . "\n";
|
|
// echo "Image: " . $metaInfo['image'] . "\n";
|
|
// echo "Favicon: " . $metaInfo['favicon'] . "\n";
|
|
}
|
|
|
|
private function getMetaTagsAndFavicon($url) {
|
|
// $url = 'https://www.google.com';
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
$html = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
|
|
// dv( $html );
|
|
|
|
|
|
if ($html === false) {
|
|
return null;
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch the HTML content of the URL
|
|
// $html = file_get_contents($url);
|
|
$meta = get_meta_tags( $url );
|
|
|
|
|
|
|
|
// $url = 'http://example.com/';
|
|
$dom = new \DOMDocument('1.0', 'utf-8');
|
|
$dom->strictErrorChecking = false;
|
|
$dom->loadHTML($html, LIBXML_NOERROR);
|
|
// $dom->loadHTML( $html );
|
|
$xml = simplexml_import_dom($dom);
|
|
$arr = $xml->xpath('//link[@rel="shortcut icon"]');
|
|
|
|
|
|
// dv('here');
|
|
|
|
if ( isset($arr) && is_array( $arr ) && isset($arr[0]) && is_array( $arr[0] )) {
|
|
// echo $arr[0]['href'];
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// dv( $arr );
|
|
|
|
|
|
|
|
|
|
// Check if the HTML was successfully fetched
|
|
// if ($html === false) {
|
|
// return null;
|
|
// }
|
|
|
|
// $html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
|
|
|
|
// Create a DOMDocument and load the HTML
|
|
// @ $dom->loadHTML($html);
|
|
// $xml = simplexml_import_dom($doc);
|
|
// $arr = $xml->xpath('//link[@rel="shortcut icon"]');
|
|
|
|
// Initialize the array to hold the meta information
|
|
$metaInfo = [
|
|
'title' => null,
|
|
'description' => null,
|
|
'image' => null,
|
|
'favicon' => null
|
|
];
|
|
|
|
// Get the title of the page
|
|
$titles = $dom->getElementsByTagName('title');
|
|
if ($titles->length > 0) {
|
|
$metaInfo['title'] = $titles->item(0)->nodeValue;
|
|
}
|
|
|
|
// Get the meta tags
|
|
$metaTags = $dom->getElementsByTagName('meta');
|
|
$metadata = [];
|
|
// dv( $metaTags );
|
|
foreach ($metaTags as $meta) {
|
|
$metadata[] = [
|
|
'name' => $meta->getAttribute('name'),
|
|
'property' => $meta->getAttribute('property'),
|
|
'content' => $meta->getAttribute('content')
|
|
];
|
|
if ($meta->getAttribute('name') === 'description') {
|
|
$metaInfo['description'] = $meta->getAttribute('content');
|
|
}
|
|
if ($meta->getAttribute('itemprop') === 'image') {
|
|
$metaInfo['google_image'] = $meta->getAttribute('content');
|
|
}
|
|
if ($meta->getAttribute('property') === 'og:image') {
|
|
$metaInfo['image'] = $meta->getAttribute('content');
|
|
}
|
|
}
|
|
|
|
// Get the link tags to find the favicon
|
|
$linkTags = $dom->getElementsByTagName('link');
|
|
$metadata['links'] = [];
|
|
foreach ($linkTags as $link) {
|
|
$metadata['links'][] = [ $link->getAttribute('rel') => $link->getAttribute('href') ];
|
|
if ($link->getAttribute('rel') === 'icon' || $link->getAttribute('rel') === 'shortcut icon') {
|
|
$metaInfo['favicon'] = $link->getAttribute('href');
|
|
break;
|
|
}
|
|
}
|
|
$metaInfo['metadata'] = $metadata;
|
|
dv( $metaInfo );
|
|
|
|
return $metaInfo;
|
|
}
|
|
private function resolveShortenedUrl($url) {
|
|
// Initialize the headers array
|
|
$headers = get_headers($url, 1);
|
|
|
|
// Check if the 'Location' header exists
|
|
if ( isset( $headers['Location'] ) ) {
|
|
// If there are multiple 'Location' headers, get the last one
|
|
if (is_array($headers['Location'])) {
|
|
return end($headers['Location']);
|
|
} else {
|
|
return $headers['Location'];
|
|
}
|
|
} else {
|
|
return $url; // No redirection, return the original URL
|
|
}
|
|
}
|
|
} |