Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions svn/trunk/ActionsFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Slickstream;

require_once 'LifeCycle.php';
require_once 'Plugin.php';
require_once PLUGIN_DIR_PATH(__FILE__) . 'LifeCycle.php';
require_once PLUGIN_DIR_PATH(__FILE__) . 'Plugin.php';

const GENESIS_AFTER_HEADER_POSTS = 'After header on posts (for Genesis themes)';
const GENESIS_BEFORE_CONTENT_POSTS = 'Before content on posts (for Genesis themes)';
Expand Down Expand Up @@ -45,7 +45,9 @@ public function getOptionMetaData(): array
];

if (function_exists('genesis')) {
$options = array_merge($options, [
$options = array_merge(
$options,
[
'InsertFilmstrip' => [
(string)__('Insert filmstrip', $domain),
'None',
Expand All @@ -58,7 +60,8 @@ public function getOptionMetaData(): array
GENESIS_AFTER_CONTENT,
GENESIS_BEFORE_FOOTER,
],
]);
]
);
}

return $options;
Expand Down Expand Up @@ -105,7 +108,7 @@ public function upgrade(): void

// Exclude slickstream scripts from JS delay in WP-Rocket
/**
* @param array<int, string> $excludedStrings
* @param array<int, string> $excludedStrings
* @return array<int, string>
*/
public function addWpRocketExclusions(array $excludedStrings = []): array
Expand Down Expand Up @@ -139,13 +142,15 @@ public function addActionsAndFilters(): void
add_action('wp_head', [$plugin, 'addSlickPageHeader']);
add_action('init', [$this, 'addTaxonomiesToPages']);

$this->addShortcodes([
$this->addShortcodes(
[
'slick-film-strip' => 'getFilmStripShortcode',
'slick-grid' => 'getSlickGridShortcode',
'slick-story' => 'getSlickStoryShortcode',
'slick-story-carousel' => 'getSlickStoryCarouselShortcode',
'slick-story-explorer' => 'getSlickStoryExplorerShortcode',
]);
]
);

$prefix = is_network_admin() ? 'network_admin_' : '';
$pluginFile = plugin_basename($this->getPluginDir() . DIRECTORY_SEPARATOR . $this->getMainPluginFileName());
Expand Down
10 changes: 5 additions & 5 deletions svn/trunk/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

declare(strict_types=1);

// Note: do not rename or this function or add a namespace to this file
// This is needed for compatibility with other plugins that check for this function
function SlickEngagement_init(): void
{

require_once 'PluginInit.php';
require_once 'ActionsFilters.php';
$slickActionsFilters = new Slickstream\ActionsFilters();
require_once PLUGIN_DIR_PATH(__FILE__) . 'PluginInit.php';
require_once PLUGIN_DIR_PATH(__FILE__) . 'ActionsFilters.php';
$slickActionsFilters = new \Slickstream\ActionsFilters();

// NOTE: this file gets run each time you *activate* the plugin.
// So in WP when you "install" the plugin, all that does it dump its files in the plugin-templates directory
Expand All @@ -17,7 +18,6 @@ function SlickEngagement_init(): void
if (!$slickActionsFilters->isInstalled()) {
$slickActionsFilters->install();
} else {
// Perform any version-upgrade activities prior to activation (e.g. database changes)
$slickActionsFilters->upgrade();
}

Expand Down
20 changes: 15 additions & 5 deletions svn/trunk/InstallIndicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Slickstream;

require_once 'OptionsManager.php';
require_once PLUGIN_DIR_PATH(__FILE__) . 'OptionsManager.php';

class InstallIndicator extends OptionsManager
{
Expand All @@ -26,6 +26,7 @@ public function isInstalled(): bool

/**
* Note in DB that the plugin is installed
*
* @return null
*/
protected function markAsInstalled(): ?bool
Expand All @@ -35,6 +36,7 @@ protected function markAsInstalled(): ?bool

/**
* Note in DB that the plugin is uninstalled
*
* @return bool returned form delete_option.
* true implies the plugin was installed at the time of this call,
* false implies it was not.
Expand All @@ -56,8 +58,9 @@ protected function getVersionSaved(): ?string

/**
* Set a version string in the options.
* @param $version string best practice: use a dot-delimited string like '1.2.3' so version strings can be easily
* compared using version_compare (http://php.net/manual/en/function.version-compare.php)
*
* @param $version string best practice: use a dot-delimited string like '1.2.3' so version strings can be easily
* compared using version_compare (http://php.net/manual/en/function.version-compare.php)
*/
protected function setVersionSaved(string $version): ?bool
{
Expand All @@ -70,13 +73,14 @@ protected function setVersionSaved(string $version): ?bool
*/
protected function getMainPluginFileName(): string
{
return basename(dirname(__FILE__)) . 'php';
return basename(__DIR__) . 'php';
}

/**
* Get a value for input key in the header section of main plugin file.
* E.g. "Plugin Name", "Version", "Description", "Text Domain", etc.
* @param $key string plugin header key
*
* @param $key string plugin header key
* @return string | null if found, otherwise null
*/
/**
Expand All @@ -103,6 +107,7 @@ public function getPluginHeaderValue(string $key): ?string
* If your subclass of this class lives in a different directory,
* override this method with the exact same code. Since __FILE__ will
* be different, you will then get the right dir returned.
*
* @return string
*/
protected function getPluginDir(): string
Expand All @@ -114,6 +119,7 @@ protected function getPluginDir(): string
* Version of this code.
* Best practice: define version strings to be easily compared using version_compare()
* NOTE: You should manually make this match the SVN tag for your main plugin file 'Version' release and 'Stable tag' in readme.txt
*
* @return string
*/
public function getVersion(): string
Expand All @@ -127,6 +133,7 @@ public function getVersion(): string
* Useful when checking for upgrades, can tell if the currently installed version is earlier than the
* newly installed code. This case indicates that an upgrade has been installed and this is the first time it
* has been activated, so any upgrade actions should be taken.
*
* @return bool true if the version saved in the options is earlier than the version declared in getVersion().
* true indicates that new code is installed and this is the first time it is activated, so upgrade actions
* should be taken. Assumes that version string comparable by version_compare, examples: '1', '1.1', '1.1.1', '2.0', etc.
Expand All @@ -138,6 +145,7 @@ public function isInstalledCodeAnUpgrade(): bool

/**
* Used to see if the installed code is an earlier version than the input version
*
* @param $aVersion string
* @return bool true if the saved version is earlier (by natural order) than the input version
*/
Expand All @@ -152,6 +160,7 @@ public function isSavedVersionLessThan(string $aVersion): bool
* but the last version (installed) was 2.3 (for example) you could check if
* For example, $this->isSavedVersionLessThanEqual('2.3') == true indicates that the saved version is not upgraded
* past 2.3 yet and therefore you would perform some appropriate upgrade action.
*
* @param $aVersion string
* @return bool true if the saved version is earlier (by natural order) than the input version
*/
Expand Down Expand Up @@ -184,6 +193,7 @@ public function isVersionLessThan(string $version1, string $version2): bool
* Record the installed version to options.
* This helps track was version is installed so when an upgrade is installed, it should call this when finished
* upgrading to record the new current version
*
* @return void
*/
protected function saveInstalledVersion(): void
Expand Down
7 changes: 6 additions & 1 deletion svn/trunk/LifeCycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Slickstream;

require_once 'InstallIndicator.php';
require_once PLUGIN_DIR_PATH(__FILE__) . 'InstallIndicator.php';

class PluginLifecycle extends InstallIndicator
{
Expand Down Expand Up @@ -42,6 +42,7 @@ public function uninstall(): void

/**
* Perform any version-upgrade activities prior to activation (e.g. database changes)
*
* @return void
*/
public function upgrade(): void
Expand Down Expand Up @@ -78,6 +79,7 @@ public function addActionsAndFilters(): void
* Best Practice:
* (1) Prefix all table names with $wpdb->prefix
* (2) make table names lower case only
*
* @return void
*/
protected function installDatabaseTables(): void
Expand All @@ -86,6 +88,7 @@ protected function installDatabaseTables(): void

/**
* Drop plugin-created tables on uninstall.
*
* @return void
*/
protected function unInstallDatabaseTables(): void
Expand All @@ -94,6 +97,7 @@ protected function unInstallDatabaseTables(): void

/**
* Override to add any additional actions to be done at install time
*
* @return void
*/
protected function otherInstall(): void
Expand All @@ -102,6 +106,7 @@ protected function otherInstall(): void

/**
* Override to add any additional actions to be done at uninstall time
*
* @return void
*/
protected function otherUninstall(): void
Expand Down
14 changes: 6 additions & 8 deletions svn/trunk/PageBootData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Slickstream;

require_once 'Utils.php';
require_once PLUGIN_DIR_PATH(__FILE__) . 'Utils.php';

class PageBootData extends OptionsManager
{
Expand Down Expand Up @@ -37,7 +37,7 @@ public function __construct(string $serverUrlBase, string $siteCode, string $scr
private function getPageBootDataForDevice(): object
{
if (isset($this->pageBootData->v2)) {
if ($this->utils->isMobile() && isset($this->pageBootData->v2->phone)) {
if ($this->utils->isPhone() && isset($this->pageBootData->v2->phone)) {
return $this->pageBootData->v2->phone ?? $this->pageBootData;
}
return $this->pageBootData->v2->desktop ?? $this->pageBootData;
Expand Down Expand Up @@ -67,8 +67,8 @@ private function echoClsContainerScript(): void
// NOTE: The source of the minified JavaScript below is: slickstream-client/blob/main/src/plugin/cls-inject.ts
// This script will insert the filmstrip, DCM, and email container elements into the page to eliminate CLS on those widgets.
// TODO: This should be pulled in over HTTP and cached in Wordpress, not embedded directly like this.
echo "\n<script>//cls-inject.ts v2.15.2\n";
echo "\"use strict\";(async(e,t,n)=>{const o=\"[slickstream]\";const r=\"cls-inject\";const s=200;const i=50;const c=6e3;const a={onPageEmailCapture:\"slick-on-page\",dcmInlineSearch:\"slick-inline-search\",filmstrip:\"slick-film-strip\"};let l=0;const d=e=>{if(!e){return null}try{return JSON.parse(e)}catch(t){console.error(o,r,\"Failed to parse config:\",e,t);return null}};const f=d(e);const u=d(t);const m=d(n);if(!f&&!u&&!m){return}const y=()=>{if(!document.body){l++;if(l<i){window.requestAnimationFrame(y)}else{console.warn(o,r,\"inject: document.body not found after max retries\")}return}void h().catch(e=>{console.error(o,r,\"injectAllClsDivs failed\",e)})};const g=async(e,t,n)=>{const o=document.createElement(\"div\");o.classList.add(t);o.classList.add(\"cls-inserted\");o.style.minHeight=n+\"px\";const r=[\"article p\",\"section.wp-block-template-part div.entry-content p\"];for(const t of r){const n=document.querySelectorAll(t);if((n===null||n===void 0?void 0:n.length)>=e){const t=n[e-1];t.insertAdjacentElement(\"afterend\",o);return o}}return null};const p=async e=>{const t=a.onPageEmailCapture;try{if(document.querySelector(`.\${t}`)){console.warn(o,r,`Container element already exists for \${t} class`);return}const n=S()?e.minHeightMobile||220:e.minHeight||200;if(e.cssSelector){await k(e.cssSelector,\"before selector\",t,n,\"\",undefined)}else{await g(e.pLocation||3,t,n)}}catch(e){console.error(o,r,`Failed to inject \${t} container`,e)}};const w=async e=>{if(e.selector){await k(e.selector,e.position||\"after selector\",a.filmstrip,e.minHeight||72,e.margin||e.marginLegacy||\"10px auto\")}else{console.warn(o,r,\"Filmstrip config missing selector property\")}};const b=async e=>{const t=Array.isArray(e)?e:[e];for(const e of t){if(e.selector){await k(e.selector,e.position||\"after selector\",a.dcmInlineSearch,e.minHeight||350,e.margin||e.marginLegacy||\"50px 15px\",e.id)}else{console.warn(o,r,\"DCM config is missing selector property:\",e)}}};const h=async()=>{if(f){await w(f)}if(u){await b(u)}if(m){await p(m)}};const S=()=>{const e=navigator.userAgent;const t=/Mobi|iP(hone|od)|Android.*Mobile|Opera Mini|IEMobile|WPDesktop|BlackBerry|BB10|webOS|Fennec/i.test(e);const n=/Tablet|iPad|Playbook|Nook|webOS|Kindle|Silk|SM-T|GT-P|SCH-I800|Xoom|Transformer|Tab|Slate|Pixel C|Nexus 7|Nexus 9|Nexus 10|SHIELD Tablet|Lenovo Tab|Mi Pad|Android(?!.*Mobile)/i.test(e);return t&&!n};const \$=async e=>new Promise(t=>{setTimeout(t,e)});const x=async(e,t,n,o,r)=>{const i=document.querySelector(e);if(i){return i}const c=Date.now();if(c-n>=t){console.error(o,r,`Timeout waiting for selector: \${e}`);return null}await \$(s);return x(e,t,n,o,r)};const A=async(e,t)=>{const n=Date.now();return x(e,t,n,o,r)};const k=async(e,t,n,s,i,a)=>{try{if(!e||e===\"undefined\"){console.warn(o,r,`Selector is empty or \"undefined\" for \${n} class; nothing to do`);return null}const l=await A(e,c);const d=a?document.querySelector(`.\${n}[data-config=\"\${a}\"]`):document.querySelector(`.\${n}`);if(d){console.warn(o,r,`Container element already exists for \${n} class with selector \${e}`);return null}if(!l){console.warn(o,r,`Target node not found for selector: \${e}`);return null}const f=document.createElement(\"div\");f.style.minHeight=`\${s}px`;f.style.margin=i;f.classList.add(n,\"cls-inserted\");if(a){f.dataset.config=a}const u={\"after selector\":\"afterend\",\"before selector\":\"beforebegin\",\"first child of selector\":\"afterbegin\",\"last child of selector\":\"beforeend\"};l.insertAdjacentElement(u[t]||\"afterend\",f);return f}catch(t){console.error(o,r,`Failed to inject \${n} for selector \${e}`,t);return null}};const P=()=>{window.requestAnimationFrame(y)};P()})";
echo "\n<script>//cls-inject.ts v2.15.3\n";
echo "\"use strict\";(async(e,t,n)=>{const o=\"[slickstream]\";const r=\"cls-inject\";const s=200;const i=50;const c=6e3;const a={onPageEmailCapture:\"slick-on-page\",dcmInlineSearch:\"slick-inline-search-panel\",filmstrip:\"slick-film-strip\"};let l=0;const d=e=>{if(!e){return null}try{return JSON.parse(e)}catch(t){console.error(o,r,\"Failed to parse config:\",e,t);return null}};const f=d(e);const u=d(t);const m=d(n);if(!f&&!u&&!m){return}const y=()=>{if(!document.body){l++;if(l<i){window.requestAnimationFrame(y)}else{console.warn(o,r,\"inject: document.body not found after max retries\")}return}void h().catch(e=>{console.error(o,r,\"injectAllClsDivs failed\",e)})};const p=async(e,t,n)=>{const o=document.createElement(\"div\");o.classList.add(t);o.classList.add(\"cls-inserted\");o.style.minHeight=n+\"px\";const r=[\"article p\",\"section.wp-block-template-part div.entry-content p\"];for(const t of r){const n=document.querySelectorAll(t);if((n===null||n===void 0?void 0:n.length)>=e){const t=n[e-1];t.insertAdjacentElement(\"afterend\",o);return o}}return null};const g=async e=>{const t=a.onPageEmailCapture;try{if(document.querySelector(`.\${t}`)){console.warn(o,r,`Container element already exists for \${t} class`);return}const n=S()?e.minHeightMobile||220:e.minHeight||200;if(e.cssSelector){await k(e.cssSelector,\"before selector\",t,n,\"\",undefined)}else{await p(e.pLocation||3,t,n)}}catch(e){console.error(o,r,`Failed to inject \${t} container`,e)}};const w=async e=>{if(e.selector){await k(e.selector,e.position||\"after selector\",a.filmstrip,e.minHeight||72,e.margin||e.marginLegacy||\"10px auto\")}else{console.warn(o,r,\"Filmstrip config missing selector property\")}};const b=async e=>{const t=Array.isArray(e)?e:[e];for(const e of t){if(e.selector){await k(e.selector,e.position||\"after selector\",a.dcmInlineSearch,e.minHeight||350,e.margin||e.marginLegacy||\"50px 15px\",e.id)}else{console.warn(o,r,\"DCM config is missing selector property:\",e)}}};const h=async()=>{if(f){await w(f)}if(u){await b(u)}if(m){await g(m)}};const S=()=>{const e=navigator.userAgent;const t=/Mobi|iP(hone|od)|Android.*Mobile|Opera Mini|IEMobile|WPDesktop|BlackBerry|BB10|webOS|Fennec/i.test(e);const n=/Tablet|iPad|Playbook|Nook|webOS|Kindle|Silk|SM-T|GT-P|SCH-I800|Xoom|Transformer|Tab|Slate|Pixel C|Nexus 7|Nexus 9|Nexus 10|SHIELD Tablet|Lenovo Tab|Mi Pad|Android(?!.*Mobile)/i.test(e);return t&&!n};const \$=async e=>new Promise(t=>{setTimeout(t,e)});const x=async(e,t,n,o,r)=>{const i=document.querySelector(e);if(i){return i}const c=Date.now();if(c-n>=t){console.error(o,r,`Timeout waiting for selector: \${e}`);return null}await \$(s);return x(e,t,n,o,r)};const A=async(e,t)=>{const n=Date.now();return x(e,t,n,o,r)};const k=async(e,t,n,s,i,a)=>{try{if(!e||e===\"undefined\"){console.warn(o,r,`Selector is empty or \"undefined\" for \${n} class; nothing to do`);return null}const l=await A(e,c);const d=a?document.querySelector(`.\${n}[data-config=\"\${a}\"]`):document.querySelector(`.\${n}`);if(d){console.warn(o,r,`Container element already exists for \${n} class with selector \${e}`);return null}if(!l){console.warn(o,r,`Target node not found for selector: \${e}`);return null}const f=document.createElement(\"div\");f.style.minHeight=`\${s}px`;f.style.margin=i;f.classList.add(n,\"cls-inserted\");if(a){f.dataset.config=a}const u={\"after selector\":\"afterend\",\"before selector\":\"beforebegin\",\"first child of selector\":\"afterbegin\",\"last child of selector\":\"beforeend\"};l.insertAdjacentElement(u[t]||\"afterend\",f);return f}catch(t){console.error(o,r,`Failed to inject \${n} for selector \${e}`,t);return null}};const P=()=>{window.requestAnimationFrame(y)};P()})";
echo "\n('" . addslashes($filmstripStr) . "','" .
addslashes($dcmStr) . "','" .
addslashes($emailCapStr) . "');" . "\n";
Expand All @@ -82,9 +82,7 @@ private function echoClsContainerScript(): void

private function getPageBootData(): ?object
{
if (
empty($this->pageGroupId) || empty($this->siteCode) || $this->urlPath === ''
) {
if (empty($this->pageGroupId) || empty($this->siteCode) || $this->urlPath === '') {
$this->utils->echoComment('getPageBootData Error: Missing Required Data; Skipping Page Boot Data. Details:');
$this->utils->echoComment('pageGroupId: ' . ($this->pageGroupId ?? 'null'));
$this->utils->echoComment("siteCode: {$this->siteCode}");
Expand Down Expand Up @@ -276,7 +274,7 @@ private function getPageGroupTransientName(): ?string
}

// Returns the Page Group ID Transient Name
private function getPageGroupIdTransientName(): ?string
private function getPageGroupIdTransientName(): string
{
$serverName = $_SERVER['SERVER_NAME'] ?? 'localhost';
return 'slick_page_group_id_' . md5("{$serverName}{$this->urlPath}");
Expand Down
Loading