Initial commit

This commit is contained in:
Joey Kimsey
2024-08-04 21:15:59 -04:00
parent c9d1fb983f
commit 0d469501ee
695 changed files with 70184 additions and 71 deletions

View File

@ -0,0 +1,280 @@
<?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
}
}
}

View File

@ -0,0 +1,3 @@
.region-shown {
background-color: red;
}

View File

@ -0,0 +1,55 @@
jQuery(document).ready(function($) {
var isWide = true;
const porkBlocked = ['EU', 'CA', 'UK']; // Example list of country codes
// Step 1: Function to get a cookie by name
function getCookie(name) {
let cookieArray = document.cookie.split(';');
for(let i = 0; i < cookieArray.length; i++) {
let cookiePair = cookieArray[i].split('=');
if(name == cookiePair[0].trim()) {
return decodeURIComponent(cookiePair[1]);
}
}
return null;
}
function setCookie(name, value, days) {
let expires = "";
if (days) {
let date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function checkRegionAndDisplayContent() {
let region = getCookie('region');
if (!region) {
// If region cookie doesn't exist, fetch the user's country code
$.getJSON('http://ip-api.com/json/', function(data) {
region = data.countryCode;
setCookie('userLocalRegion', region, 7); // Set the region cookie for 7 days
}).fail(function(error) {
console.error('Error fetching the user country code:', error);
});
} else {
}
region = 'CA';
hideOrShowContent(region, porkBlocked);
}
// Step 4: Function to hide or show content based on the country code
function hideOrShowContent(region, porkBlocked) {
if (porkBlocked.includes(region)) {
// Hide the content if the region is in the porkBlocked list
$('.region-shown').hide();
} else {
// Show the content otherwise
$('.region-shown').show();
}
}
checkRegionAndDisplayContent();
});

View File

@ -0,0 +1,140 @@
jQuery(document).ready(function($) {
var isWide = true;
const porkBlocked = ['EU', 'CA', 'US']; // Example list of country codes
// Step 1: Function to get a cookie by name
function getCookie(name) {
let cookieArray = document.cookie.split(';');
for(let i = 0; i < cookieArray.length; i++) {
let cookiePair = cookieArray[i].split('=');
if ( name == cookiePair[0].trim()) {
return decodeURIComponent(cookiePair[1]);
}
}
return null;
}
function setCookie(name, value, days) {
let expires = "";
if (days) {
let date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function checkRegionAndDisplayContent() {
let region = getCookie('region1');
if (!region) {
// If region cookie doesn't exist, fetch the user's country code
$.getJSON('https://pro.ip-api.com/json/?key=KvTJMTBtV44LTez', function(data) {
region = data.countryCode;
setCookie('userLocalRegion', region, 7); // Set the region cookie for 7 days
hideOrShowContent(region);
}).fail(function(jqXHR, textStatus, errorThrown) {
console.error('Error fetching the user country code:', errorThrown);
console.log('jqXHR:', jqXHR);
console.log('textStatus:', textStatus);
});
}
}
// Step 4: Function to hide or show content based on the country code
function hideOrShowContent(region) {
if (porkBlocked.includes(region)) {
$('.region-shown').hide();
} else {
$('.region-shown').show();
}
}
checkRegionAndDisplayContent();
$('#getTimestamp').submit(function(event) {
event.preventDefault();
var date = $('#date').val();
var time = $('#time').val();
var useUserTimezone = $('#timezone').prop('checked');
var timestamp;
if (useUserTimezone) {
var timezoneOffset = new Date().getTimezoneOffset();
var userDateTime = new Date(date + 'T' + time);
userDateTime.setMinutes(userDateTime.getMinutes() - timezoneOffset);
timestamp = userDateTime.getTime();
} else {
var utcDateTime = new Date(date + 'T' + time + 'Z');
timestamp = utcDateTime.getTime();
}
timestamp = Math.floor(timestamp / 1000);
$('#getTimestampResult').text('UTC Timestamp: ' + timestamp);
});
$('#getReadableDate').submit(function(event) {
event.preventDefault();
var timestamp = $('#timestamp').val();
// Check if the timestamp has exactly 10 digits
if (timestamp.length === 10) {
var date = new Date(parseInt(timestamp) * 1000); // Multiply by 1000 to convert seconds to milliseconds
var options = { year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: true, timeZone: 'UTC' };
var formattedDate = date.toLocaleString('en-US', options);
// Display the formatted date
$('#getReadableDateResult').text('Readable Date: ' + formattedDate);
} else {
// Display an error message if the timestamp is not 10 digits
$('#getReadableDateResult').text('Invalid timestamp. Please enter a 10-digit Unix timestamp.');
}
});
});

View File

@ -0,0 +1,101 @@
<?php
namespace Mirasco\Components\ShortCodes;
use Mirasco\Components\Products\ProductCategoryTaxonomy;
use Mirasco\Components\Products\ProductPostType;
class MirascoProductCategoryGridShortCode
{
const TAG = 'mirasco_product_category_grid';
public function __construct()
{
add_shortcode( static::TAG, [ $this, 'render_short_code' ] );
}
public function render_short_code( $atts )
{
$atts = wp_parse_args( $atts, [
'category' => 'beef'
]);
$taxonomy = ProductCategoryTaxonomy::getInstance()->getKey();
$the_term = get_term_by( 'slug', $atts['category'], $taxonomy );
$query = new \WP_Query([
'post_type' => ProductPostType::getInstance()->getKey(),
'posts_per_page' => -1,
'order' => 'ASC',
'tax_query' => [
[
'field' => 'slug',
'taxonomy' => $taxonomy,
'terms' => $atts['category'],
'orderby' => 'term_order'
]
]
]);
$posts = array_map( function( \WP_Post $post ) use ( $taxonomy ) {
// Get terms.
$post->terms = wp_get_object_terms( $post->ID, [
'taxonomy' => $taxonomy,
]);
// Get post thumbnail.
$thumb_id = get_post_thumbnail_id( $post->ID );
if ( ! empty( $thumb_id ) ) {
$url = wp_get_attachment_image_url( $thumb_id, 'large' );
} else {
$url = false;
}
$post->image = $url;
return $post;
}, $query->posts );
$terms = [];
// Extract post terms.
foreach( $posts as $post ) {
foreach ( $post->terms as $term ) {
if ( ! in_array( $term, $terms ) ) {
$terms[] = $term;
}
}
}
usort($terms ,'compareTermOrder');
echo "<script>
console.log('term list: '+" . json_encode($terms) . "')
</script>";
ob_start();
echo '<div class="product-category-grid">';
foreach( $terms as $term ){
if ( 0 == $term->parent || $the_term->term_id == $term->term_id ) {
continue;
}
echo '<div class="term-wrap">
<h3 class="cuts">'.$term->name.'</h3>';
foreach( $posts as $post ){
$terms = $post->terms;
$in_array = false;
foreach( $terms as $_term ) {
if ( $_term->term_id == $term->term_id ) {
$in_array = true;
}
}
if ( ! $in_array ) {
continue;
}
echo '<div class="post-item">';
if ( $post->image ) {
echo '<a href="' . $post->image . '" class="foobox" rel="foobox" data-width="400">
' . $post->post_title . '
<i class="fa fa-camera"></i>
</a>';
} else {
echo $post->post_title;
}
echo '</div>';
}
echo '</div>';
}
echo '</div>';
return ob_get_clean();
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* app/plugins/notes/models/notebooks.php
*
* This class is used for the manipulation of the notebooks database table.
*
* @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\Models;
use TheTempusProject\Bedrock\Classes\Config;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Canary\Canary as Debug;
use TheTempusProject\Classes\DatabaseModel;
use TheTempusProject\TheTempusProject as App;
use TheTempusProject\Houdini\Classes\Filters;
class Testing extends DatabaseModel {
/**
* The model constructor.
*/
public function __construct() {
parent::__construct();
}
}

View File

@ -0,0 +1,28 @@
<?php
/**
* app/plugins/testing/plugin.php
*
* This houses all of the main plugin info and functionality.
*
* @package TP Testing
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Plugins;
use TheTempusProject\Classes\Plugin;
class Testing extends Plugin {
public $pluginName = 'TP Testing';
public $pluginAuthor = 'JoeyK';
public $pluginWebsite = 'https://TheTempusProject.com';
public $modelVersion = '1.0';
public $pluginVersion = '3.0';
public $pluginDescription = 'A simple plugin for adding and running test code.';
public function __construct( $load = false ) {
parent::__construct( $load );
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* app/plugins/testing/templates/testing.inc.php
*
* This is the loader for the testing template.
*
* @package TP Testing
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Templates;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Houdini\Classes\Navigation;
class TestingLoader extends DefaultLoader {
public function __construct() {
$this->addJs( '<script language="JavaScript" crossorigin="anonymous" type="text/javascript" src="{ROOT_URL}app/plugins/testing/js/testing.js"></script>' );
parent::__construct();
}
}

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>{TITLE}</title>
<!-- Required CSS -->
<link rel="stylesheet" href="{FONT_AWESOME_URL}font-awesome.min.css" crossorigin="anonymous">
<link rel="stylesheet" href="{BOOTSTRAP_CDN}css/bootstrap-theme.min.css" crossorigin="anonymous">
<link rel="stylesheet" href="{BOOTSTRAP_CDN}css/bootstrap.min.css" crossorigin="anonymous">
<!-- Custom styles for this template -->
<link rel="stylesheet" href="{ROOT_URL}app/plugins/testing/css/testing.css" />
</head>
<body>
{CONTENT}
<!-- Bootstrap core JavaScript and jquery -->
<script language="JavaScript" crossorigin="anonymous" type="text/javascript" src="{JQUERY_CDN}jquery.min.js"></script>
<script language="JavaScript" crossorigin="anonymous" type="text/javascript" src="{BOOTSTRAP_CDN}js/bootstrap.min.js"></script>
<!-- Custom javascript for this template -->
{TEMPLATE_JS_INCLUDES}
</body>
</html>

View File

@ -0,0 +1,6 @@
<svg>
<path
d="m2.25 12 8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25"
>
</path>
</svg>

After

Width:  |  Height:  |  Size: 291 B

View File

@ -0,0 +1 @@
<div class="region-shown">testing this view</div>

View File

@ -0,0 +1,92 @@
<legend>time testing tools</legend>
<h3>Date input to unix timestamp</h3>
<form action="" method="post" class="form-horizontal" id="getTimestamp">
<input type="hidden" name="token" value="{TOKEN}">
<fieldset>
<div class="form-group">
<label for="day" class="col-lg-3 control-label">Time</label>
<div class="col-lg-3">
<input type="time" name="time" id="time" class="form-control" value="00:00" />
</div>
</div>
<div class="form-group">
<label for="month" class="col-lg-3 control-label">Date</label>
<div class="col-lg-3">
<input type="date" name="date" id="date" class="form-control" value="{date}" />
</div>
</div>
<div class="form-group">
<label for="timezone" class="col-lg-3 control-label">Include TimeZone</label>
<div class="col-lg-3">
<input type="checkbox" name="timezone" id="timezone" class="form-control" value="{timezone}" />
</div>
</div>
<div class="form-group">
<label for="submit" class="col-lg-3 control-label"></label>
<div class="col-lg-3">
<button name="submit" value="submit" class="btn btn-lg btn-primary center-block">generate</button><br>
</div>
</div>
</fieldset>
<div id="getTimestampResult"></div>
</form>
<h3>Unix timestamp to readable Date</h3>
<form action="" method="post" class="form-horizontal" id="getReadableDate">
<input type="hidden" name="token" value="{TOKEN}">
<fieldset>
<div class="form-group">
<label for="day" class="col-lg-3 control-label">Timestamp</label>
<div class="col-lg-3">
<input type="text" name="timestamp" id="timestamp" class="form-control" value="" />
</div>
</div>
<div class="form-group">
<label for="submit" class="col-lg-3 control-label"></label>
<div class="col-lg-3">
<button name="submit" value="submit" class="btn btn-lg btn-primary center-block">generate</button><br>
</div>
</div>
</fieldset>
<div id="getReadableDateResult"></div>
</form>
<!-- <select id="timezone">
<option value="UTC">UTC (Coordinated Universal Time)</option>
<option value="Etc/GMT+12">GMT+12:00</option>
<option value="Etc/GMT+11">GMT+11:00</option>
<option value="Pacific/Midway">GMT-11:00 (Midway Island, Samoa)</option>
<option value="Pacific/Honolulu">GMT-10:00 (Hawaii)</option>
<option value="America/Anchorage">GMT-09:00 (Alaska)</option>
<option value="America/Los_Angeles">GMT-08:00 (Pacific Time)</option>
<option value="America/Denver">GMT-07:00 (Mountain Time)</option>
<option value="America/Phoenix">GMT-07:00 (Mountain Standard Time - Arizona)</option>
<option value="America/Chicago">GMT-06:00 (Central Time)</option>
<option value="America/New_York">GMT-05:00 (Eastern Time)</option>
<option value="America/Argentina/Buenos_Aires">GMT-03:00 (Buenos Aires, Argentina)</option>
<option value="Atlantic/Cape_Verde">GMT-01:00 (Cape Verde)</option>
<option value="Europe/London">GMT (London, United Kingdom)</option>
<option value="Europe/Paris">GMT+01:00 (Paris, France)</option>
<option value="Europe/Istanbul">GMT+03:00 (Istanbul, Turkey)</option>
<option value="Asia/Dubai">GMT+04:00 (Dubai, United Arab Emirates)</option>
<option value="Asia/Kolkata">GMT+05:30 (India Standard Time)</option>
<option value="Asia/Hong_Kong">GMT+08:00 (Hong Kong)</option>
<option value="Asia/Tokyo">GMT+09:00 (Tokyo, Japan)</option>
<option value="Australia/Sydney">GMT+10:00 (Sydney, Australia)</option>
</select> -->