| 1 |
<?php |
| 2 |
|
| 3 |
namespace WordProof\SDK\Controllers; |
| 4 |
|
| 5 |
use WordProof\SDK\Helpers\AssetHelper; |
| 6 |
use WordProof\SDK\Helpers\CertificateHelper; |
| 7 |
use WordProof\SDK\Helpers\EnvironmentHelper; |
| 8 |
use WordProof\SDK\Helpers\PostMetaHelper; |
| 9 |
use WordProof\SDK\Helpers\SettingsHelper; |
| 10 |
|
| 11 |
class CertificateController |
| 12 |
{ |
| 13 |
/** |
| 14 |
* Enqueue the uikit script. |
| 15 |
* |
| 16 |
* @action wp_head |
| 17 |
*/ |
| 18 |
public function enqueue() |
| 19 |
{ |
| 20 |
if (CertificateHelper::show()) { |
| 21 |
AssetHelper::enqueue('uikit'); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Add scripts and schema to the head of the current page. |
| 27 |
* |
| 28 |
* @action wp_head |
| 29 |
*/ |
| 30 |
public function head() |
| 31 |
{ |
| 32 |
if (!CertificateHelper::show()) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
global $post; |
| 37 |
|
| 38 |
$schema = "\n"; |
| 39 |
$schema .= '<script type="application/ld+json" class="' . esc_attr('wordproof-schema-graph') . '">'; |
| 40 |
$schema .= json_encode(PostMetaHelper::get($post->ID, '_wordproof_schema'), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
| 41 |
$schema .= "</script>"; |
| 42 |
$schema .= "\n"; |
| 43 |
|
| 44 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 45 |
echo $schema; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Adds the certificate tag to the content before rendering it. |
| 50 |
* |
| 51 |
* @param $content |
| 52 |
* @return mixed|string Content string from 'the_content' filter |
| 53 |
* @filter the_content |
| 54 |
*/ |
| 55 |
public function certificateTag($content) |
| 56 |
{ |
| 57 |
if (!CertificateHelper::show()) { |
| 58 |
return $content; |
| 59 |
} |
| 60 |
|
| 61 |
if (SettingsHelper::hideCertificateLink()) { |
| 62 |
return $content; |
| 63 |
} |
| 64 |
|
| 65 |
global $post; |
| 66 |
$identifier = $post->ID; |
| 67 |
|
| 68 |
$text = SettingsHelper::certificateLinkText(); |
| 69 |
$showRevisions = SettingsHelper::showRevisions() ? 'true' : 'false'; |
| 70 |
$debug = EnvironmentHelper::development() ? 'true' : 'false'; |
| 71 |
$lastModified = get_the_modified_date('c', $post->ID); |
| 72 |
|
| 73 |
$content.= "\n" . '<w-certificate debug="' . $debug . '" shared-identifier="' . $identifier . '" render-without-button="true" show-revisions="' . $showRevisions . '" last-modified="' . $lastModified . '"></w-certificate>'; |
| 74 |
$content.= "\n" . '<p><w-certificate-button shared-identifier="' . $identifier . '" icon="shield" shape="text" text="' . $text . '"></w-certificate-button></p>'; |
| 75 |
$content.= "\n"; |
| 76 |
|
| 77 |
return $content; |
| 78 |
} |
| 79 |
} |
| 80 |
|