Skip to content

Commit

Permalink
add new TypeRocket name and change TypeRocketPro namespace to TypeRoc…
Browse files Browse the repository at this point in the history
…ket\Pro
  • Loading branch information
kevindees committed Nov 15, 2022
1 parent e95fc8d commit ff560ce
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Core/System.php
Expand Up @@ -24,7 +24,7 @@
class System
{
public const ALIAS = 'system';
public const ADVANCED = 'TypeRocketPro\Core\AdvancedSystem';
public const ADVANCED = 'TypeRocket\Pro\Core\AdvancedSystem';
public const STATE = '_typerocket_site_state_changed';

protected $stash = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Elements/Fields/Matrix.php
Expand Up @@ -94,8 +94,8 @@ public function enqueueScripts()
wp_enqueue_script( 'jquery-ui-datepicker', [ 'jquery' ], false, true );
wp_enqueue_script( 'wp-color-picker' );

if(class_exists('\TypeRocketPro\Core\AdvancedSystem')) {
call_user_func('\TypeRocketPro\Elements\Traits\EditorScripts::enqueueEditorScripts');
if(class_exists('\TypeRocket\Pro\Core\AdvancedSystem')) {
call_user_func('\TypeRocket\Pro\Elements\Traits\EditorScripts::enqueueEditorScripts');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Http/Response.php
Expand Up @@ -1064,8 +1064,8 @@ public function finish($forceResponseArray = false)
$response->exitJson($statusCode);
}

if(class_exists('\TypeRocketPro\Http\Download')) {
if( $returned instanceof \TypeRocketPro\Http\Download) {
if(class_exists('\TypeRocket\Pro\Http\Download')) {
if( $returned instanceof \TypeRocket\Pro\Http\Download) {
$returned->send();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Services/ErrorService.php
Expand Up @@ -6,7 +6,7 @@
class ErrorService extends Service
{
public const ALIAS = 'tr-error';
public const WHOOPS = 'TypeRocketPro\Features\Whoops';
public const WHOOPS = 'TypeRocket\Pro\Features\Whoops';

/**
* ErrorService constructor.
Expand Down
6 changes: 3 additions & 3 deletions src/Services/MailerService.php
Expand Up @@ -29,11 +29,11 @@ public function register() : Service
}

/**
* @param \TypeRocketPro\Utility\Mailers\MailDriver|null $driver
* @param \TypeRocket\Pro\Utility\Mailers\MailDriver|null $driver
*
* @return \TypeRocketPro\Utility\Mailers\MailDriver|null
* @return \TypeRocket\Pro\Utility\Mailers\MailDriver|null
*/
public function driver(\TypeRocketPro\Utility\Mailers\MailDriver $driver = null)
public function driver(\TypeRocket\Pro\Utility\Mailers\MailDriver $driver = null)
{
if(func_num_args() == 0) {
return $this->driver;
Expand Down
2 changes: 1 addition & 1 deletion src/Template/PostTypeModelComposer.php
Expand Up @@ -63,7 +63,7 @@ public function publishedOn($d = 'F j, Y') {
public function featuredImage($size = 'thumbnail', $classes = '', $from_cache = false)
{
if($from_cache && $this->data->meta->_thumbnail_id) {
$img = \TypeRocketPro\Utility\ImageCache::attachmentSrc($this->data->meta->_thumbnail_id, $size);
$img = \TypeRocket\Pro\Utility\ImageCache::attachmentSrc($this->data->meta->_thumbnail_id, $size);

if($img) {
return $img;
Expand Down
90 changes: 90 additions & 0 deletions src/Utility/Media.php
@@ -0,0 +1,90 @@
<?php

namespace TypeRocket\Utility;

class Media
{
/**
* Upload a file to the media library using a URL.
*
* Example usage: Upload photo from URL, display the attachment as html <img>
* $attachment_id = TypeRocket\Utility\Media::uploadFromUrl( "http://example.com/images/photo.png" );
* echo wp_get_attachment_image( $attachment_id, 'large' );
*
* @param string $url URL to be uploaded
* @param null|string $title If set, used as the post_title
* @param int $timeout How long to wait in seconds for download to complete
*
* @return int|null
*/
public static function uploadFromUrl(string $url, ?string $title = null, int $timeout = 300) : ?int
{
require_once( ABSPATH . "/wp-load.php");
require_once( ABSPATH . "/wp-admin/includes/image.php");
require_once( ABSPATH . "/wp-admin/includes/file.php");
require_once( ABSPATH . "/wp-admin/includes/media.php");

$tmp = download_url( $url, $timeout );
if ( is_wp_error( $tmp ) ) return null;

$filename = pathinfo($url, PATHINFO_FILENAME);
$extension = pathinfo($url, PATHINFO_EXTENSION);

if ( ! $extension ) {
$mime = mime_content_type( $tmp );
$mime = is_string($mime) ? sanitize_mime_type( $mime ) : false;


$mime_extensions = array(
'text/plain' => 'txt',
'text/csv' => 'csv',
'application/msword' => 'doc',
'image/jpg' => 'jpg',
'image/jpeg' => 'jpeg',
'image/gif' => 'gif',
'image/png' => 'png',
'video/mp4' => 'mp4',
);

if ( isset( $mime_extensions[$mime] ) ) {
$extension = $mime_extensions[$mime];
} else {
try {
unlink($tmp);
} catch (\Throwable $t) {}
return null;
}
}

if(str_contains($extension, '?')) {
$extension = explode('?', $extension, 2)[0];
}

$allowed = get_allowed_mime_types();
$extension = wp_check_filetype($extension, $allowed)['ext'];

if(! in_array($extension, $allowed)) {
return null;
}

// Upload by "sideloading": "the same way as an uploaded file is handled by media_handle_upload"
$args = [
'name' => "$filename.$extension",
'tmp_name' => $tmp,
];

// Do the upload
$attachment_id = media_handle_sideload($args, 0, $title);

// Cleanup temp file
try {
unlink($tmp);
} catch (\Throwable $t) {}

// Error uploading
if ( is_wp_error($attachment_id) ) return null;

// Success, return attachment ID (int)
return (int) $attachment_id;
}
}
2 changes: 1 addition & 1 deletion src/Utility/Str.php
Expand Up @@ -101,7 +101,7 @@ public static function ends($needle, $haystack) : bool
*/
public static function contains($needle, $haystack) : bool
{
return str_contains($haystack, $needle); // ( mb_strpos( (string) $subject, (string) $needle ) !== false );
return str_contains((string) $haystack, (string) $needle);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion templates/Controllers/Template.txt
@@ -1,7 +1,7 @@
<?php
namespace {{namespace}};

use TypeRocketPro\Controllers\TemplateController;
use TypeRocket\Pro\Controllers\TemplateController;

class {{controller}} extends TemplateController
{
Expand Down

0 comments on commit ff560ce

Please sign in to comment.