/** * Add the [recras-arrangement] shortcode * * @param array $attributes * * @return string */ public static function addArrangementShortcode($attributes) { if (!isset($attributes['id'])) { return __('Error: no ID set', Plugin::TEXT_DOMAIN); } if (!ctype_digit($attributes['id'])) { return __('Error: ID is not a number', Plugin::TEXT_DOMAIN); } if (!isset($attributes['show'])) { return __('Error: "show" option not set', Plugin::TEXT_DOMAIN); } if (!in_array($attributes['show'], self::getValidOptions())) { return __('Error: invalid "show" option', Plugin::TEXT_DOMAIN); } $subdomain = Settings::getSubdomain($attributes); if (!$subdomain) { return Plugin::getNoSubdomainError(); } $json = get_transient('recras_' . $subdomain . '_arrangement_' . $attributes['id']); if ($json === false) { try { $json = Http::get($subdomain, 'arrangementen/' . $attributes['id']); } catch (\Exception $e) { return $e->getMessage(); } set_transient('recras_' . $subdomain . '_arrangement_' . $attributes['id'], $json, 86400); } switch ($attributes['show']) { case 'description': return $json->uitgebreide_beschrijving; case 'duration': return self::getDuration($json); case 'image_url': return $json->image_filename; case 'location': return self::getLocation($json); case 'persons': return '<span class="recras-persons">' . $json->aantal_personen . '</span>'; case 'price_pp_excl_vat': return Price::format($json->prijs_pp_exc); case 'price_pp_incl_vat': return Price::format($json->prijs_pp_inc); case 'price_total_excl_vat': return Price::format($json->prijs_totaal_exc); case 'price_total_incl_vat': return Price::format($json->prijs_totaal_inc); case 'program': case 'programme': $startTime = isset($attributes['starttime']) ? $attributes['starttime'] : '00:00'; $showHeader = !isset($attributes['showheader']) || Settings::parseBoolean($attributes['showheader']); return self::generateProgramme($json->programma, $startTime, $showHeader); case 'title': return '<span class="recras-title">' . $json->arrangement . '</span>'; default: return __('Error: unknown option', Plugin::TEXT_DOMAIN); } }
/** * Add the [recras-product] shortcode * * @param array $attributes * * @return string */ public static function addProductShortcode($attributes) { if (!isset($attributes['id'])) { return __('Error: no ID set', Plugin::TEXT_DOMAIN); } if (!ctype_digit($attributes['id'])) { return __('Error: ID is not a number', Plugin::TEXT_DOMAIN); } if (!isset($attributes['show'])) { return __('Error: "show" option not set', Plugin::TEXT_DOMAIN); } if (!in_array($attributes['show'], self::getValidOptions())) { return __('Error: invalid "show" option', Plugin::TEXT_DOMAIN); } $subdomain = Settings::getSubdomain($attributes); if (!$subdomain) { return Plugin::getNoSubdomainError(); } $products = self::getProducts($subdomain); if (!isset($products[$attributes['id']])) { return __('Error: product does not exist', Plugin::TEXT_DOMAIN); } $product = $products[$attributes['id']]; switch ($attributes['show']) { case 'description': return '<span class="recras-description">' . $product->beschrijving . '</span>'; case 'description_long': if ($product->uitgebreide_omschrijving) { return '<span class="recras-description">' . $product->uitgebreide_omschrijving . '</span>'; } else { return ''; } case 'duration': if ($product->duur) { return '<span class="recras-duration">' . $product->duur . '</span>'; } else { return ''; } case 'image_url': return $product->image_url; case 'minimum_amount': return '<span class="recras-amount">' . $product->minimum_aantal . '</span>'; case 'price_excl_vat': return Price::format($product->prijs_exc); case 'price_incl_vat': return Price::format($product->prijs_inc); case 'title': return '<span class="recras-title">' . $product->weergavenaam . '</span>'; default: return __('Error: unknown option', Plugin::TEXT_DOMAIN); } }