function drstk_item($atts) { $cache = get_transient(md5('DRSTK' . serialize($atts))); if ($cache) { return $cache; } $url = "https://repository.library.northeastern.edu/api/v1/files/" . $atts['id']; $data = get_response($url); $data = json_decode($data); if (isset($atts['image-size'])) { $num = $atts['image-size'] - 1; } else { $num = 3; } $thumbnail = $data->thumbnails[$num]; $master = $data->thumbnails[4]; foreach ($data->content_objects as $key => $val) { if ($val == 'Large Image') { $master = $key; } } $html = "<div class='drs-item'>"; $jwplayer = false; // note: unneeded if there is only one canonical_object type if (isset($atts['display-video']) && isset($data->canonical_object)) { foreach ($data->canonical_object as $key => $val) { if (($val == 'Video File' || $val == 'Audio File') && $atts['display-video'] == "true") { $html .= insert_jwplayer($key, $val, $data, $thumbnail); $jwplayer = true; } } } if (!$jwplayer) { $html .= "<a href='" . drstk_home_url() . "item/" . $atts['id'] . "'><img class='drs-item-img' id='" . $atts['id'] . "-img' src='" . $thumbnail . "'"; if (isset($atts['align'])) { $html .= " data-align='" . $atts['align'] . "'"; } if (isset($atts['zoom']) && $atts['zoom'] == 'on') { $html .= " data-zoom-image='" . $master . "' data-zoom='on'"; if (isset($atts['zoom_position'])) { $html .= " data-zoom-position='" . $atts['zoom_position'] . "'"; } } $html .= "/></a>"; } // start item meta data $img_metadata = ""; if (isset($atts['metadata'])) { $metadata = explode(",", $atts['metadata']); foreach ($metadata as $field) { $this_field = $data->mods->{$field}; if (is_array($this_field)) { foreach ($this_field as $field_val) { $img_metadata .= $field_val . "<br/>"; } } else { if (isset($this_field[0])) { $img_metadata .= $this_field[0] . "<br/>"; } } } $html .= "<div class='wp-caption-text drstk-caption'"; if (isset($atts['caption-align'])) { $html .= " data-caption-align='" . $atts['caption-align'] . "'"; } if (isset($atts['caption-position'])) { $html .= " data-caption-position='" . $atts['caption-position'] . "'"; } $html .= "><a href='" . drstk_home_url() . "item/" . $atts['id'] . "'>" . $img_metadata . "</a></div>"; } // start hidden fields $html .= "<div class=\"hidden\">"; $meta = $data->mods; foreach ($meta as $field) { if (is_array($field)) { foreach ($field as $field_val) { $html .= $field_val . "<br/>"; } } else { $html .= $field[0] . "<br/>"; } } $html .= "</div></div>"; $cache_output = $html; $cache_time = 1000; set_transient(md5('DRSTK' . serialize($atts)), $cache_output, $cache_time * 60); return $html; }
function get_item_image() { global $item_pid, $data, $errors; if (check_for_bad_data($data)) { echo check_for_bad_data($data); return false; } if (isset($data->thumbnails)) { $img = $data->thumbnails[count($data->thumbnails) - 2]; } if (isset($data->canonical_object)) { $val = current($data->canonical_object); $key = key($data->canonical_object); if ($val == 'Master Image') { $zoom_img = $data->thumbnails[count($data->thumbnails) - 1]; echo '<img id="drs-item-img" src="' . $img . '" data-zoom-image="' . $zoom_img . '"/>'; echo '<script type="text/javascript"> jQuery("#drs-item-img").elevateZoom();</script>'; } else { if ($val == 'PDF') { if (isset($data->mods->Location) && strpos($data->mods->Location[0], "issuu") !== FALSE) { $location_href = explode("'", strval(htmlentities($data->mods->Location[0]))); if (count($location_href) == 1) { $location_href = explode('"', strval(htmlentities($data->mods->Location[0]))); } $issu_id = explode('?', $location_href[1]); $issu_id = explode('=', $issu_id[1]); $issu_id = $issu_id[1]; echo '<div data-configid="' . $issu_id . '" style="width:100%; height:500px;" class="issuuembed"></div><script type="text/javascript" src="//e.issuu.com/embed.js" async="true"></script>'; } else { echo '<img id="drs-item-img" src="' . $img . '" />'; } } else { if ($val == 'Video File' || $val == 'Audio File') { print insert_jwplayer($key, $val, $data, $img); } } } } else { //case where there is no canonical_objects set echo '<img id="drs-item-img" src="' . $img . '" />'; } if (isset($data->page_objects)) { $pages = $data->page_objects; if (count($pages) > 0) { $gallery_html = '<div class="carousel slide" id="single_carousel">'; $img_html = ""; $i = 0; foreach ($pages as $img => $ordinal_value) { $img_html .= "<div class='item"; if ($i == 0) { $img_html .= " active"; } $img_html .= "'><a href='' data-toggle='modal' data-target='#drs_item_modal' class='drs_page_image' data-img='" . $img . "' data-ordinal_value='" . $ordinal_value . "'><img"; if ($i == 0) { $img_html .= " src='" . $img . "'"; } else { $img_html .= " data-src='" . $img . "'"; } $img_html .= "/></a><div class='carousel-caption'><a href='' data-toggle='modal' data-target='drs_item_modal' class='drs_item_modal' data-img='" . $img . "' data-ordinal_value='" . $ordinal_value . "'>Page " . $ordinal_value . "</a></div></div>"; $i++; } $gallery_html .= '<div class="carousel-inner">' . $img_html . '</div>'; $gallery_html .= '<a class="left carousel-control" href="#single_carousel" role="button" data-slide="prev"><i class="glyphicon-chevron-left fa fa-chevron-left" aria-hidden="true"></i><span class="sr-only">Previous</span></a><a class="right carousel-control" href="#single_carousel" role="button" data-slide="next"><i class="glyphicon-chevron-right fa fa-chevron-right" aria-hidden="true"></i><span class="sr-only">Next</span></a>'; $gallery_html .= '</div>'; $gallery_html .= '<div class="modal fade" id="drs_item_modal"><div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button><h4 class="modal-title">Page Images</h4></div><div class="modal-body"><nav class="pagination"><ul class="pagination"><li><a href="#" class="drs_page_image prev"><span class="fa fa-chevron-left"></span></a></li>'; foreach ($pages as $img => $ordinal_value) { $gallery_html .= "<li><a href='#' class='drs_page_image' data-img='" . $img . "' data-ordinal_value='" . $ordinal_value . "'>" . $ordinal_value . "</a></li>"; } $gallery_html .= '<li><a href="#" class="drs_page_image next"><span class="fa fa-chevron-right"></span></a></li></ul></nav><div class="body"></div></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div></div><!-- /.modal-content --></div><!-- /.modal-dialog --></div><!-- /.modal -->'; echo $gallery_html; } } }
function drstk_map($atts) { global $errors; $cache = get_transient(md5('PREFIX' . serialize($atts))); if ($cache) { return $cache; } $items = array_map('trim', explode(',', $atts['id'])); $map_api_key = $atts['map_api_key']; $map_project_key = $atts['map_project_key']; $story = $atts['story']; $map_html = ""; $shortcode = "<div id='map' data-story='" . $story . "' data-map_api_key='" . $map_api_key . "' data-map_project_key='" . $map_project_key . "'"; if (isset($atts['red_legend_desc']) && isset($atts['red'])) { $shortcode .= " data-red='" . $atts['red'] . "'"; $shortcode .= " data-red_legend_desc='" . $atts['red_legend_desc'] . "'"; } if (isset($atts['blue_legend_desc']) && isset($atts['blue'])) { $shortcode .= " data-blue='" . $atts['blue'] . "'"; $shortcode .= " data-blue_legend_desc='" . $atts['blue_legend_desc'] . "'"; } if (isset($atts['green_legend_desc']) && isset($atts['green'])) { $shortcode .= " data-green='" . $atts['green'] . "'"; $shortcode .= " data-green_legend_desc='" . $atts['green_legend_desc'] . "'"; } if (isset($atts['yellow_legend_desc']) && isset($atts['yellow'])) { $shortcode .= " data-yellow='" . $atts['yellow'] . "'"; $shortcode .= " data-yellow_legend_desc='" . $atts['yellow_legend_desc'] . "'"; } if (isset($atts['orange_legend_desc']) && isset($atts['orange'])) { $shortcode .= " data-orange='" . $atts['orange'] . "'"; $shortcode .= " data-orange_legend_desc='" . $atts['orange_legend_desc'] . "'"; } foreach ($items as $item) { $url = "https://repository.library.northeastern.edu/api/v1/files/" . $item; $data = get_response($url); $data = json_decode($data); if (!isset($data->error)) { $pid = $data->pid; $coordinates = ""; if (isset($data->coordinates)) { $coordinates = $data->coordinates; } else { $location = $data->geographic[0]; $locationUrl = "http://maps.google.com/maps/api/geocode/json?address=" . urlencode($location); $locationData = get_response($locationUrl); $locationData = json_decode($locationData); if (!isset($locationData->error)) { $coordinates = $locationData->results[0]->geometry->location->lat . "," . $locationData->results[0]->geometry->location->lng; } } $title = $data->mods->Title[0]; $permanentUrl = 'Permanent URL'; $permanentUrl = $data->mods->{$permanentUrl}; $map_html .= "<div class='coordinates' data-pid='" . $pid . "' data-url='" . $permanentUrl[0] . "' data-coordinates='" . $coordinates . "' data-title='" . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . "'"; if (isset($atts['metadata'])) { $map_metadata = ''; $metadata = explode(",", $atts['metadata']); foreach ($metadata as $field) { if (isset($data->mods->{$field})) { $this_field = $data->mods->{$field}; if (isset($this_field[0])) { $map_metadata .= $this_field[0] . "<br/>"; } } } $map_html .= " data-metadata='" . $map_metadata . "'"; } $canonical_object = ""; if (isset($data->canonical_object)) { foreach ($data->canonical_object as $key => $val) { if ($val == 'Video File' || $val == 'Audio File') { $canonical_object = insert_jwplayer($key, $val, $data, $data->thumbnails[2]); } else { $canonical_object = '<img src="' . $data->thumbnails[2] . '"/>'; } } } $map_html .= " data-media-content='" . $canonical_object . "'"; $map_html .= "></div>"; } else { $map_html = $errors['shortcodes']['fail']; } } if (isset($atts['custom_map_urls']) && $atts['custom_map_urls'] != '') { $custom_map_urls = explode(",", $atts['custom_map_urls']); $custom_map_titles = explode(",", $atts['custom_map_titles']); $custom_map_descriptions = explode(",", $atts['custom_map_descriptions']); $custom_map_locations = explode(",", $atts['custom_map_locations']); $custom_map_color_groups = explode(",", $atts['custom_map_color_groups']); foreach ($custom_map_urls as $key => $value) { $url = $value; $title = $custom_map_titles[$key]; $title = trim($title, '\''); $description = $custom_map_descriptions[$key]; $description = trim($description, '\''); $location = $custom_map_locations[$key]; $colorGroup = $custom_map_color_groups[$key]; $coordinates = ""; $locationUrl = "http://maps.google.com/maps/api/geocode/json?address=" . urlencode($location); $locationData = get_response($locationUrl); $locationData = json_decode($locationData); if (!isset($locationData->error)) { $coordinates = $locationData->results[0]->geometry->location->lat . "," . $locationData->results[0]->geometry->location->lng; } $map_html .= "<div class='custom-coordinates' data-url=" . $url . " data-coordinates='" . $coordinates . "' data-title='" . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . "' data-description='" . htmlspecialchars($description, ENT_QUOTES, 'UTF-8') . "' data-colorGroup=" . $colorGroup . ""; $map_html .= "></div>"; } } $shortcode .= ">" . $map_html . "</div>"; $cache_output = $shortcode; $cache_time = 1000; set_transient(md5('PREFIX' . serialize($atts)), $cache_output, $cache_time * 60); return $shortcode; }