pluginName = $pluginName; $this->version = $version; } /** * @param $content * @return string */ public function parse($content) { global $wp_embed; $content = $wp_embed->run_shortcode( $content); $codes = []; foreach ($this->getShortCodes($content) as $shortCode) { if (empty($shortCode)) { continue; } $shortCode = str_replace(['"', "'", '’'], "", html_entity_decode($shortCode)); $data = shortcode_parse_atts($shortCode); $imageId = get_option(JSV_360_ADMIN_NOTIFIER::NOTIFIER_IMAGE_ID, null); if ($imageId) { $image = wp_get_attachment_image_src($imageId); $data['notification-config_drag-to-rotate_show-start-to-rotate-default-notification'] = false; $data['notification-config_drag-to-rotate_image-url'] = $image[0]; } $this->applyDefault('license', get_option(JSV_360_ADMIN_LICENSE::NOTIFIER_LICENSE, null), $data); $this->applyDefault('auto-rotate', get_option(JSV_360_ADMIN_AUTOROTATE::AUTOROTATE, null), $data); if (empty($data)) { echo 'error in shortcode:' . $shortCode . PHP_EOL; continue; } $codes[] = $this->getHtml($data); }; return $this->replaceJsvShortCodes($content, $codes); } private function applyDefault($key, $value, &$data) { if (!isset($data[$key]) && !is_null($value)) { $data[$key] = $value; } } /** * @param $content * @return array|mixed */ private function getShortCodes($content) { $questions = []; $pattern = sprintf('/\[%s(.*?)\]/', self::SHORTCODE_ID); if (preg_match_all($pattern, $content, $questions)) { $questions = array_key_exists(1, $questions) ? $questions[1] : array(); } return $questions; } /** * @param $data * * @return string */ private function getHtml($data) { $holderId = $this->getRandomId('holder'); $imageId = $this->getRandomId('img'); $dataAttributes = $this->getDataAttributes($data, $holderId, $imageId); $src = $this->getImageUrl($data); $mw = $this->getAttribute($data, 'max-width'); $float = $this->getAttribute($data, 'float'); $marginLeft = $this->getAttribute($data, 'margin-left'); $marginRight = $this->getAttribute($data, 'margin-right'); $marginTop = $this->getAttribute($data, 'margin-top'); $marginBottom = $this->getAttribute($data, 'margin-bottom'); $style = ''; if ($mw || $float || $marginLeft) { $style = 'style="'; $style .= $mw ? sprintf('max-width:%spx; ', $mw) : ''; $style .= $float ? sprintf('float:%s; ', $float) : ''; $style .= $marginLeft ? sprintf('margin-left:%spx; ', $marginLeft) : ''; $style .= $marginRight ? sprintf('margin-right:%spx; ', $marginRight) : ''; $style .= $marginTop ? sprintf('margin-top:%spx; ', $marginTop) : ''; $style .= $marginBottom ? sprintf('margin-bottom:%spx; ', $marginBottom) : ''; $style .= '"'; } $code = '