| @@ -97,8 +97,9 @@ | ||
| 97 | 97 | add_shortcode(EMBEDPRESS_SHORTCODE, ['\\EmbedPress\\Shortcode', 'do_shortcode']); |
| 98 | 98 | add_shortcode('embed_oembed_html', ['\\EmbedPress\\Shortcode', 'do_shortcode']); |
| 99 | 99 | add_shortcode('embedpress', ['\\EmbedPress\\Shortcode', 'do_shortcode']); |
| 100 | 100 | add_shortcode('embedpress_pdf', ['\\EmbedPress\\Shortcode', 'do_shortcode_pdf']); |
| 101 | + add_shortcode('embedpress_doc', ['\\EmbedPress\\Shortcode', 'do_shortcode_doc']); | |
| 101 | 102 | } |
| 102 | 103 | |
| 103 | 104 | /** |
| 104 | 105 | * Method that converts the plugin shortcoded-string into its complex content. |
| @@ -159,9 +160,9 @@ | ||
| 159 | 160 | |
| 160 | 161 | $lock_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><g fill="#6354a5" class="color134563 svgShape"><path d="M46.3 28.7h-3v-6.4C43.3 16.1 38.2 11 32 11c-6.2 0-11.3 5.1-11.3 11.3v6.4h-3v-6.4C17.7 14.4 24.1 8 32 8s14.3 6.4 14.3 14.3v6.4" fill="#6354a5" class="color000000 svgShape"></path><path d="M44.8 55.9H19.2c-2.6 0-4.8-2.2-4.8-4.8V31.9c0-2.6 2.2-4.8 4.8-4.8h25.6c2.6 0 4.8 2.2 4.8 4.8v19.2c0 2.7-2.2 4.8-4.8 4.8zM19.2 30.3c-.9 0-1.6.7-1.6 1.6v19.2c0 .9.7 1.6 1.6 1.6h25.6c.9 0 1.6-.7 1.6-1.6V31.9c0-.9-.7-1.6-1.6-1.6H19.2z" fill="#6354a5" class="color000000 svgShape"></path><path d="M35.2 36.7c0 1.8-1.4 3.2-3.2 3.2s-3.2-1.4-3.2-3.2 1.4-3.2 3.2-3.2 3.2 1.5 3.2 3.2" fill="#6354a5" class="color000000 svgShape"></path><path d="M32.8 36.7h-1.6l-1.6 9.6h4.8l-1.6-9.6" fill="#6354a5" class="color000000 svgShape"></path></g></svg>'; |
| 161 | 162 | |
| 162 | 163 | return ' |
| 163 | - <div id="ep-shortcode-content-'.$client_id.'" class="ep-shortcode-content"> | |
| 164 | + <div id="ep-shortcode-content-' . $client_id . '" class="ep-shortcode-content"> | |
| 164 | 165 | <div class="ep-embed-content-wraper"> |
| 165 | 166 | <div class="password-form-container"> |
| 166 | 167 | <h2>' . esc_html($lock_heading) . '</h2> |
| 167 | 168 | <p>' . esc_html($lock_subheading) . '</p> |
| @@ -226,14 +227,12 @@ | ||
| 226 | 227 | // Conditions for content protection |
| 227 | 228 | $password_protected = $protection_type == 'password' && !empty($protection_password); |
| 228 | 229 | |
| 229 | 230 | $password_verified = $password_protected && !empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct); |
| 230 | - $user_role_protected = $protection_type === 'user-role' && Helper::has_allowed_roles($user_role); | |
| 231 | + $user_role_protected = $protection_type === 'user-role' && Helper::has_allowed_roles($user_role); | |
| 231 | 232 | |
| 232 | 233 | if ( |
| 233 | - apply_filters('embedpress/is_allow_rander', false) && | |
| 234 | - ($protection_content == 'true') && | |
| 235 | - (($protection_type == 'password' && !$password_verified) || ($protection_type == 'user-role' && !Helper::has_allowed_roles($user_role)) ) | |
| 234 | + apply_filters('embedpress/is_allow_rander', false) && ($protection_content == 'true') && (($protection_type == 'password' && !$password_verified) || ($protection_type == 'user-role' && !Helper::has_allowed_roles($user_role))) | |
| 236 | 235 | ) { |
| 237 | 236 | return $password_protected |
| 238 | 237 | ? self::display_password_form($client_id, $embed->embed, $pass_hash_key, $attributes) |
| 239 | 238 | : self::content_protection_content($client_id, $protection_message, $user_role); |
| @@ -1093,9 +1092,8 @@ | ||
| 1093 | 1092 | return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8')); |
| 1094 | 1093 | } |
| 1095 | 1094 | |
| 1096 | 1095 | return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8')); |
| 1097 | - | |
| 1098 | 1096 | } |
| 1099 | 1097 | |
| 1100 | 1098 | public static function getUnit($value) |
| 1101 | 1099 | { |
| @@ -1167,13 +1165,11 @@ | ||
| 1167 | 1165 | $password_verified = $password_protected && !empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct); |
| 1168 | 1166 | $user_role_protected = $protection_type === 'user-role' && Helper::has_allowed_roles($user_role); |
| 1169 | 1167 | |
| 1170 | 1168 | if ( |
| 1171 | - apply_filters('embedpress/is_allow_rander', false) && | |
| 1172 | - ($protection_content == 'true') && | |
| 1173 | - (($protection_type == 'user-role' && !Helper::has_allowed_roles($user_role)) ) | |
| 1169 | + apply_filters('embedpress/is_allow_rander', false) && ($protection_content == 'true') && (($protection_type == 'user-role' && !Helper::has_allowed_roles($user_role))) | |
| 1174 | 1170 | ) { |
| 1175 | - | |
| 1171 | + | |
| 1176 | 1172 | return self::content_protection_content($client_id, $protection_message, $user_role); |
| 1177 | 1173 | } |
| 1178 | 1174 | |
| 1179 | 1175 | ?> |
| @@ -1216,8 +1212,90 @@ | ||
| 1216 | 1212 | <?php |
| 1217 | 1213 | |
| 1218 | 1214 | |
| 1219 | 1215 | return ob_get_clean(); |
| 1216 | + } | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + public static function do_shortcode_doc($attributes = [], $subject = null) | |
| 1220 | + { | |
| 1221 | + $plgSettings = Core::getSettings(); | |
| 1222 | + $url = preg_replace( | |
| 1223 | + '/(\[' . EMBEDPRESS_SHORTCODE . '(?:\]|.+?\])|\[\/' . EMBEDPRESS_SHORTCODE . '\])/i', | |
| 1224 | + "", | |
| 1225 | + $subject | |
| 1226 | + ); | |
| 1227 | + | |
| 1228 | + $url = esc_url($url); | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + $default = [ | |
| 1232 | + 'url' => $url, | |
| 1233 | + 'width' => !empty($plgSettings->enableEmbedResizeWidth) ? esc_attr($plgSettings->enableEmbedResizeWidth) : '100%', | |
| 1234 | + 'height' => !empty($plgSettings->enableEmbedResizeHeight) ? esc_attr($plgSettings->enableEmbedResizeHeight) : '500px', | |
| 1235 | + 'viewer' => !empty($plgSettings->embedpress_document_viewer) ? esc_attr($plgSettings->embedpress_document_viewer) : 'custom', | |
| 1236 | + 'powered_by' => (!isset($plgSettings->embedpress_document_powered_by) || $plgSettings->embedpress_document_powered_by === 'yes') ? 'yes' : 'no', | |
| 1237 | + ]; | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + $atts = shortcode_atts($default, $attributes); | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + $url = esc_url($atts['url']); | |
| 1244 | + if (empty($url)) return ''; | |
| 1245 | + | |
| 1246 | + $dimension = "width: {$atts['width']}px; height: {$atts['height']}px"; | |
| 1247 | + | |
| 1248 | + $embed_content = ''; | |
| 1249 | + | |
| 1250 | + // PDF Handling | |
| 1251 | + if (self::is_pdf($url)) { | |
| 1252 | + $embed_content .= '<div class="embedpress-document-embed ose-document embedpress-doc-wrap ep-doc-' . md5($url) . '" style="' . esc_attr($dimension) . '; max-width: 100%; display: block">'; | |
| 1253 | + $embed_content .= '<iframe src="' . esc_url($url) . '" style="' . esc_attr($dimension) . '; max-width: 100%;" frameborder="0" allowfullscreen></iframe>'; | |
| 1254 | + if ($atts['powered_by'] === 'yes') { | |
| 1255 | + $embed_content .= '<p class="embedpress-el-powered" style="text-align: center">Powered By EmbedPress</p>'; | |
| 1256 | + } | |
| 1257 | + $embed_content .= '</div>'; | |
| 1258 | + return $embed_content; | |
| 1259 | + } | |
| 1260 | + | |
| 1261 | + // Office or Google Viewer Handling | |
| 1262 | + if (self::is_file_url($url)) { | |
| 1263 | + $viewer_url = 'https://view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true'; | |
| 1264 | + } else { | |
| 1265 | + $viewer_url = 'https://drive.google.com/viewerng/viewer?url=' . urlencode($url) . '&embedded=true&chrome=false'; | |
| 1266 | + } | |
| 1267 | + | |
| 1268 | + if ($atts['viewer'] === 'google') { | |
| 1269 | + $viewer_url = '//docs.google.com/gview?embedded=true&url=' . urlencode($url); | |
| 1270 | + } elseif ($atts['viewer'] === 'custom') { | |
| 1271 | + $hostname = parse_url($url, PHP_URL_HOST); | |
| 1272 | + $domain = implode('.', array_slice(explode('.', $hostname), -2)); | |
| 1273 | + if ($domain === 'google.com') { | |
| 1274 | + $viewer_url = $url . '?embedded=true'; | |
| 1275 | + if (strpos($viewer_url, '/presentation/')) { | |
| 1276 | + $viewer_url = Helper::get_google_presentation_url($url); | |
| 1277 | + } | |
| 1278 | + } | |
| 1279 | + } | |
| 1280 | + | |
| 1281 | + $embed_content .= '<div class="embedpress-document-embed ose-document embedpress-doc-wrap ep-doc-' . md5($url) . '" style="' . esc_attr($dimension) . '; max-width: 100%; display: block">'; | |
| 1282 | + | |
| 1283 | + $embed_content .= '<iframe src="' . esc_url($viewer_url) . '" style="' . esc_attr($dimension) . '; max-width: 100%;" frameborder="0" allowfullscreen ></iframe>'; | |
| 1284 | + | |
| 1285 | + if ($atts['powered_by'] === 'yes') { | |
| 1286 | + $embed_content .= '<p class="embedpress-el-powered" style="text-align: center">Powered By EmbedPress</p>'; | |
| 1287 | + } | |
| 1288 | + | |
| 1289 | + $embed_content .= '</div>'; | |
| 1290 | + | |
| 1291 | + return $embed_content; | |
| 1292 | + } | |
| 1293 | + | |
| 1294 | + protected static function is_file_url($url) | |
| 1295 | + { | |
| 1296 | + $pattern = '/\.([0-9a-z]+)(?=[?#])|(\.)(?:[\w]+)$/i'; | |
| 1297 | + return preg_match($pattern, $url) === 1; | |
| 1220 | 1298 | } |
| 1221 | 1299 | |
| 1222 | 1300 | protected static function is_external_url($url) |
| 1223 | 1301 | { |