| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services; |
| 4 |
|
| 5 |
use FluentCart\Api\StoreSettings; |
| 6 |
use FluentCart\Framework\Support\Arr; |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Entry MetaDat |
| 14 |
* @since 1.0.0 |
| 15 |
*/ |
| 16 |
class WpMetaHelper |
| 17 |
{ |
| 18 |
protected $entry; |
| 19 |
protected $userId; |
| 20 |
protected $queryVars = null; |
| 21 |
protected $user; |
| 22 |
|
| 23 |
public function __construct($entry) |
| 24 |
{ |
| 25 |
$this->entry = $entry; |
| 26 |
$this->userId = Arr::get($entry, 'user_id', null); |
| 27 |
} |
| 28 |
|
| 29 |
public function getWPValues($key) |
| 30 |
{ |
| 31 |
switch ($key) { |
| 32 |
case 'user_id': |
| 33 |
return $this->userId; |
| 34 |
case 'user_first_name': |
| 35 |
$user = $this->getUser(); |
| 36 |
if (!$user) { |
| 37 |
return ''; |
| 38 |
} |
| 39 |
return $user->user_firstname; |
| 40 |
case 'user_last_name': |
| 41 |
$user = $this->getUser(); |
| 42 |
if (!$user) { |
| 43 |
return ''; |
| 44 |
} |
| 45 |
return $user->user_lastname; |
| 46 |
case 'user_display_name': |
| 47 |
$user = $this->getUser(); |
| 48 |
if (!$user) { |
| 49 |
return ''; |
| 50 |
} |
| 51 |
return $user->display_name; |
| 52 |
case 'user_email': |
| 53 |
$user = $this->getUser(); |
| 54 |
if (!$user) { |
| 55 |
return ''; |
| 56 |
} |
| 57 |
return $user->user_email; |
| 58 |
case 'user_url': |
| 59 |
$user = $this->getUser(); |
| 60 |
if (!$user) { |
| 61 |
return ''; |
| 62 |
} |
| 63 |
return $user->user_url; |
| 64 |
case 'site_title': |
| 65 |
return get_bloginfo('name'); |
| 66 |
case 'site_url': |
| 67 |
return get_bloginfo('url'); |
| 68 |
case 'admin_email': |
| 69 |
return get_bloginfo('admin_email'); |
| 70 |
case 'store_logo'; |
| 71 |
return $this->getStoreLogo(); |
| 72 |
default: |
| 73 |
return ''; |
| 74 |
break; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
public function getuserMeta($key) |
| 79 |
{ |
| 80 |
$meta = get_user_meta($this->userId, $key, true); |
| 81 |
if (is_array($meta)) { |
| 82 |
return implode(', ', $meta); |
| 83 |
} |
| 84 |
return $meta; |
| 85 |
} |
| 86 |
|
| 87 |
public function getOtherData($key) |
| 88 |
{ |
| 89 |
if ($key == 'date') { |
| 90 |
$dateFormat = get_option('date_format'); |
| 91 |
return current_time($dateFormat); |
| 92 |
} |
| 93 |
|
| 94 |
if ($key == 'time') { |
| 95 |
$dateFormat = get_option('time_format'); |
| 96 |
return current_time($dateFormat); |
| 97 |
} |
| 98 |
if ($key == 'user_ip') { |
| 99 |
return $this->entry->ip_address; |
| 100 |
} |
| 101 |
|
| 102 |
return ''; |
| 103 |
} |
| 104 |
|
| 105 |
protected function getUser() |
| 106 |
{ |
| 107 |
if ($this->user) { |
| 108 |
return $this->user; |
| 109 |
} |
| 110 |
$this->user = get_user_by('ID', $this->userId); |
| 111 |
return $this->user; |
| 112 |
} |
| 113 |
|
| 114 |
public function getStoreLogo(): string |
| 115 |
{ |
| 116 |
$storeSettings = new StoreSettings(); |
| 117 |
$logoPath = $storeSettings->get('store_logo'); |
| 118 |
if (isset($logoPath) && !empty($logoPath)) { |
| 119 |
$html = '<img src="' . Arr::get($logoPath, 'url') . '" alt="Store Logo" style="max-height: 70px;">'; |
| 120 |
} else { |
| 121 |
$html = ''; |
| 122 |
} |
| 123 |
|
| 124 |
return $html; |
| 125 |
} |
| 126 |
} |