Example #1
0
function get_associated_files()
{
    global $data, $errors, $assoc_meta_options;
    if (isset($data->associated) && $data->associated != NULL && get_option('drstk_assoc') == 'on') {
        $associated_html = '';
        $title = get_option('drstk_assoc_title') != '' ? get_option('drstk_assoc_title') : 'Associated Files';
        $associated_html .= "<div class='panel panel-default assoc_files'><div class='panel-heading'>" . $title . "</div><div class='panel-body'>";
        // foreach($data->associated as $assoc_pid => $assoc_title){ //disabling multivalued associated files until a new less resource intensive api call for associated files exists
        $assoc_pid = key(get_object_vars($data->associated));
        //using this just to get the first title
        $assoc_title = $data->associated->{$assoc_pid};
        //using this just to get the first title
        $url = "https://repository.library.northeastern.edu/api/v1/files/" . $assoc_pid . "?solr_only=true";
        $assoc_data = get_response($url);
        $assoc_data = json_decode($assoc_data);
        if (check_for_bad_data($assoc_data)) {
            return false;
        } else {
            if (isset($assoc_data->_source->fields_thumbnail_list_tesim)) {
                $associated_html .= "<a href='" . drstk_home_url() . "item/" . $assoc_data->_source->id . "'><img src='https://repository.library.northeastern.edu" . $assoc_data->_source->fields_thumbnail_list_tesim[1] . "'/></a>";
            }
            $associated_html .= get_item_details($assoc_data, $assoc_meta_options);
        }
        // }
        $associated_html .= "</div></div>";
        echo $associated_html;
    }
}
function drstk_tiles($atts)
{
    global $errors;
    $cache = get_transient(md5('DRSTK' . serialize($atts)));
    if ($cache) {
        return $cache;
    }
    $imgs = array_map('trim', explode(',', $atts['id']));
    $img_html = "";
    foreach ($imgs as $img) {
        $url = "https://repository.library.northeastern.edu/api/v1/files/" . $img . "?solr_only=true";
        $data = get_response($url);
        $data = json_decode($data);
        $data = $data->_source;
        $type = $atts['type'];
        if (!isset($data->error)) {
            $pid = $data->id;
            if (isset($atts['image-size'])) {
                $num = $atts['image-size'] - 1;
            } else {
                $num = 4;
            }
            $thumbnail = "http://repository.library.northeastern.edu" . $data->fields_thumbnail_list_tesim[$num];
            if (isset($atts['metadata'])) {
                $img_metadata = '';
                $metadata = explode(",", $atts['metadata']);
                foreach ($metadata as $field) {
                    if (isset($data->{$field})) {
                        $this_field = $data->{$field};
                        if (isset($this_field)) {
                            if (is_array($this_field)) {
                                foreach ($this_field as $val) {
                                    $img_metadata .= $val . "<br/>";
                                }
                            } else {
                                $img_metadata .= $this_field . "<br/>";
                            }
                        }
                    }
                }
            }
            if ($type == 'pinterest-below' || $type == 'pinterest') {
                $img_html .= "<div class='brick'><a href='" . drstk_home_url() . "item/" . $pid . "'><img src='" . $thumbnail . "'></a><div class='info wp-caption-text'><a href='" . drstk_home_url() . "item/" . $pid . "'>" . $img_metadata . "</a>";
            }
            if ($type == 'pinterest-hover') {
                $img_html .= "<div class='brick brick-hover'><img src='" . $thumbnail . "' style='width:100%'><div class='info wp-caption-text'><a href='" . drstk_home_url() . "item/" . $pid . "'>" . $img_metadata . "</a>";
            }
            if ($type == 'even-row' || $type == 'square') {
                $img_html .= "<div class='cell' data-thumbnail='" . $thumbnail . "'><div class='info wp-caption-text'><a href='" . drstk_home_url() . "item/" . $pid . "'>" . $img_metadata . "</a>";
            }
            $img_html .= "<div class=\"hidden\">";
            foreach ($data as $key => $field) {
                if ($key != "all_text_timv" && $key != "object_profile_ssm") {
                    if (is_array($field)) {
                        foreach ($field as $key => $field_val) {
                            $img_html .= $field_val . "<br/>";
                        }
                    } else {
                        $img_html .= $field . "<br/>";
                    }
                }
            }
            $img_html .= "</div>";
            $img_html .= "</div></div>";
        } else {
            $img_html = $errors['shortcodes']['fail'];
        }
    }
    $shortcode = "<div class='freewall' id='freewall' data-type='" . $type . "'";
    if (isset($atts['cell-height'])) {
        $shortcode .= " data-cell-height='" . $atts['cell-height'] . "'";
    } else {
        $shortcode .= " data-cell-height='200'";
    }
    if (isset($atts['cell-width'])) {
        $shortcode .= " data-cell-width='" . $atts['cell-width'] . "'";
    } else {
        $shortcode .= " data-cell-width='200'";
    }
    if (isset($atts['text-align'])) {
        $shortcode .= " data-text-align='" . $atts['text-align'] . "'";
    } else {
        $shortcode .= " data-text-align='center'";
    }
    $shortcode .= ">" . $img_html . "</div>";
    $cache_output = $shortcode;
    $cache_time = 1000;
    set_transient(md5('DRSTK' . serialize($atts)), $cache_output, $cache_time * 60);
    return $shortcode;
}
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 drstk_breadcrumb_script()
{
    global $wp_query;
    global $VERSION;
    global $sub_collection_pid;
    global $item_pid;
    wp_register_script('drstk_breadcrumb', plugins_url('/assets/js/breadcrumb.js', __FILE__), array('jquery'));
    wp_enqueue_script('drstk_breadcrumb');
    $breadcrumb_nonce = wp_create_nonce('breadcrumb_drs');
    wp_localize_script('drstk_breadcrumb', 'breadcrumb_obj', array('ajax_url' => admin_url('admin-ajax.php'), 'nonce' => $breadcrumb_nonce, 'template' => $wp_query->query_vars['drstk_template_type'], 'item_pid' => $item_pid, 'sub_collection_pid' => $sub_collection_pid, 'collection_pid' => drstk_get_pid(), 'home_url' => drstk_home_url()));
}
function drstk_map_shortcode_scripts()
{
    global $post, $wp_query;
    if (is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'drstk_map') && !isset($wp_query->query_vars['drstk_template_type'])) {
        wp_register_script('drstk_leaflet', plugins_url('../assets/js/leaflet/leaflet.js', __FILE__), array('jquery'));
        wp_enqueue_script('drstk_leaflet');
        wp_register_script('drstk_leaflet_marker_cluster', plugins_url('../assets/js/leaflet/leaflet.markercluster-src.js', __FILE__), array('jquery', 'drstk_leaflet'));
        wp_enqueue_script('drstk_leaflet_marker_cluster');
        wp_register_script('drstk_leaflet_message_box', plugins_url('../assets/js/leaflet/leaflet.messagebox-src.js', __FILE__), array('jquery', 'drstk_leaflet'));
        wp_enqueue_script('drstk_leaflet_message_box');
        wp_register_script('drstk_leaflet_easy_button', plugins_url('../assets/js/leaflet/leaflet.easybutton-src.js', __FILE__), array('jquery', 'drstk_leaflet'));
        wp_enqueue_script('drstk_leaflet_easy_button');
        wp_register_style('drstk_leaflet_css', plugins_url('../assets/css/leaflet.css', __FILE__));
        wp_enqueue_style('drstk_leaflet_css');
        wp_register_script('drstk_map', plugins_url('../assets/js/map.js', __FILE__), array('jquery'));
        wp_enqueue_script('drstk_map');
        $map_nonce = wp_create_nonce('map_nonce');
        $map_obj = array('ajax_url' => admin_url('admin-ajax.php'), 'nonce' => $map_nonce, 'home_url' => drstk_home_url());
        wp_localize_script('drstk_map', 'map_obj', $map_obj);
    }
}
function drstk_gallery($atts)
{
    global $errors;
    $cache = get_transient(md5('DRSTK' . serialize($atts)));
    if ($cache) {
        return $cache;
    }
    if (isset($atts['id'])) {
        $images = array_map('trim', explode(',', $atts['id']));
        $img_html = '';
        $height = $width = 0;
        $i = 0;
        foreach ($images as $id) {
            $url = "https://repository.library.northeastern.edu/api/v1/files/" . $id . "?solr_only=true";
            $data = get_response($url);
            $data = json_decode($data);
            $data = $data->_source;
            if (!isset($data->error)) {
                $pid = $data->id;
                if (isset($atts['image-size'])) {
                    $num = $atts['image-size'] - 1;
                } else {
                    $num = 4;
                }
                $thumbnail = "http://repository.library.northeastern.edu" . $data->fields_thumbnail_list_tesim[$num];
                $this_height = getimagesize($thumbnail);
                $this_height = $this_height[1];
                if ($this_height > $height) {
                    $height = $this_height;
                }
                $this_width = getimagesize($thumbnail);
                $this_width = $this_width[0];
                if ($this_width > $width) {
                    $width = $this_width;
                }
                $title = $data->full_title_ssi;
                $img_html .= "<div class='item";
                if ($i == 0) {
                    $img_html .= " active";
                }
                $img_html .= "'><a href='" . drstk_home_url() . "item/" . $pid . "'><img";
                if ($i == 0) {
                    $img_html .= " src='" . $thumbnail . "'";
                } else {
                    $img_html .= " data-src='" . $thumbnail . "'";
                }
                $img_html .= "  alt='" . $title . "'></a>";
                if (isset($atts['caption']) && $atts['caption'] == "on") {
                    $img_metadata = "";
                    if (isset($atts['metadata'])) {
                        $metadata = explode(",", $atts['metadata']);
                        foreach ($metadata as $field) {
                            if (isset($data->{$field})) {
                                $this_field = $data->{$field};
                                if (isset($this_field)) {
                                    if (is_array($this_field)) {
                                        foreach ($this_field as $val) {
                                            $img_metadata .= $val . "<br/>";
                                        }
                                    } else {
                                        $img_metadata .= $this_field . "<br/>";
                                    }
                                }
                            }
                        }
                    }
                    $img_html .= "<div class='carousel-caption'";
                    if (isset($atts['caption-align']) || isset($atts['caption-position'])) {
                        $img_html .= "style='";
                        if (isset($atts['caption-align'])) {
                            $img_html .= "text-align:" . $atts['caption-align'];
                        }
                        if (isset($atts['caption-position'])) {
                            $img_html .= "; position:" . $atts['caption-position'];
                        }
                        if (isset($atts['caption-width']) && $atts['caption-width'] == "100%") {
                            $img_html .= "; width:" . $atts['caption-width'];
                        }
                        $img_html .= "'";
                    }
                    if (isset($atts['caption-width']) && $atts['caption-width'] != "100%") {
                        $img_html .= " data-caption-width='image'";
                    }
                    $img_html .= "><a href='" . drstk_home_url() . "item/" . $pid . "'>" . $img_metadata . "</a></div>";
                    $img_html .= "<div class=\"hidden\">";
                    foreach ($data as $key => $field) {
                        if ($key != "all_text_timv" && $key != "object_profile_ssm") {
                            if (is_array($field)) {
                                foreach ($field as $key => $field_val) {
                                    $img_html .= $field_val . "<br/>";
                                }
                            } else {
                                $img_html .= $field . "<br/>";
                            }
                        }
                    }
                    $img_html .= "</div>";
                }
                $img_html .= "</div>";
            } else {
                $img_html .= $errors['shortcodes']['fail'];
            }
            $i++;
        }
        if (isset($atts['speed']) && $atts['speed'] > 1) {
            $interval = $atts['speed'];
        }
        if (isset($atts['auto']) && $atts['auto'] == 'on') {
            if (!isset($interval)) {
                $interval = 5000;
            }
        } else {
            if (isset($atts['auto']) && $atts['auto'] == 'off') {
                $interval = 'false';
            }
        }
        $rand = rand();
        $gallery_html = '<div class="carousel slide" id="carousel-' . $rand . '" data-height="' . $height . '" data-width="' . $width . '" data-interval="' . $interval . '"';
        if (isset($atts['max-height'])) {
            $gallery_html .= " data-max-height='" . $atts['max-height'] . "'";
        }
        if (isset($atts['max-width'])) {
            $gallery_html .= " data-max-width='" . $atts['max-width'] . "'";
        }
        $gallery_html .= '>';
        if (isset($atts['pager']) && $atts['pager'] == 'on') {
            $gallery_html .= '<ol class="carousel-indicators">';
            $i = 0;
            foreach ($images as $id) {
                $gallery_html .= '<li data-target="#carousel-' . $rand . '" data-slide-to="' . $i . '" class="';
                if ($i == 0) {
                    $gallery_html .= "active";
                }
                $gallery_html .= '"></li>';
                $i++;
            }
            $gallery_html .= '</ol>';
        }
        $gallery_html .= '<div class="carousel-inner">' . $img_html . '</div>';
        if (isset($atts['nav']) && $atts['nav'] == 'on') {
            $gallery_html .= '<a class="left carousel-control" href="#carousel-' . $rand . '" 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="#carousel-' . $rand . '" 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>';
        $cache_output = $gallery_html;
        $cache_time = 1000;
        set_transient(md5('DRSTK' . serialize($atts)), $cache_output, $cache_time * 60);
        return $gallery_html;
    }
}