Elementor_Enhancer.php
3 years ago
EmbedPress_Core_Installer.php
6 years ago
EmbedPress_Notice.php
4 years ago
EmbedPress_Plugin_Usage_Tracker.php
3 years ago
Feature_Enhancer.php
3 years ago
Helper.php
3 years ago
Helper.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | namespace EmbedPress\Includes\Classes; |
| 4 | |
| 5 | if ( !defined('ABSPATH') ) { |
| 6 | exit; |
| 7 | } // Exit if accessed directly |
| 8 | |
| 9 | class Helper { |
| 10 | |
| 11 | /** |
| 12 | * Parse a query string into an associative array. |
| 13 | * |
| 14 | * If multiple values are found for the same key, the value of that key |
| 15 | * value pair will become an array. This function does not parse nested |
| 16 | * PHP style arrays into an associative array (e.g., foo[a]=1&foo[b]=2 will |
| 17 | * be parsed into ['foo[a]' => '1', 'foo[b]' => '2']). |
| 18 | * |
| 19 | * @param string $str Query string to parse |
| 20 | * @param int|bool $urlEncoding How the query string is encoded |
| 21 | * |
| 22 | * @return array |
| 23 | */ |
| 24 | public static function parse_query($str, $urlEncoding = true) |
| 25 | { |
| 26 | $result = []; |
| 27 | |
| 28 | if ($str === '') { |
| 29 | return $result; |
| 30 | } |
| 31 | |
| 32 | if ($urlEncoding === true) { |
| 33 | $decoder = function ($value) { |
| 34 | return rawurldecode(str_replace('+', ' ', $value)); |
| 35 | }; |
| 36 | } elseif ($urlEncoding === PHP_QUERY_RFC3986) { |
| 37 | $decoder = 'rawurldecode'; |
| 38 | } elseif ($urlEncoding === PHP_QUERY_RFC1738) { |
| 39 | $decoder = 'urldecode'; |
| 40 | } else { |
| 41 | $decoder = function ($str) { return $str; }; |
| 42 | } |
| 43 | |
| 44 | foreach (explode('&', $str) as $kvp) { |
| 45 | $parts = explode('=', $kvp, 2); |
| 46 | $key = $decoder($parts[0]); |
| 47 | $value = isset($parts[1]) ? $decoder($parts[1]) : null; |
| 48 | if (!isset($result[$key])) { |
| 49 | $result[$key] = $value; |
| 50 | } else { |
| 51 | if (!is_array($result[$key])) { |
| 52 | $result[$key] = [$result[$key]]; |
| 53 | } |
| 54 | $result[$key][] = $value; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return $result; |
| 59 | } |
| 60 | public static function get_pdf_renderer() { |
| 61 | $renderer = EMBEDPRESS_URL_ASSETS . 'pdf/web/viewer.html'; |
| 62 | // @TODO; apply settings query args here |
| 63 | return $renderer; |
| 64 | } |
| 65 | |
| 66 | public static function get_file_title($url){ |
| 67 | return get_the_title(attachment_url_to_postid( $url )); |
| 68 | } |
| 69 | } |
| 70 |