diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000..a9c5515 --- /dev/null +++ b/TODO.txt @@ -0,0 +1,12 @@ +Upload CSV (or other things that Exhibit can use) + +Use pre-uploaded files (and store them) + +URL of data somewhere else on the web (cross-site scripting via datapress) + +************************************************* + +- How does Wordpress upload/store files? +- What does Exhibit need for CSV files? +- Build GUI for uploading files +- Build GUI for using uploaded files diff --git a/admin_javascript.js.php b/admin_javascript.js.php index 0b3d212..5966ada 100644 --- a/admin_javascript.js.php +++ b/admin_javascript.js.php @@ -13,10 +13,8 @@ if (!$guessurl = site_url()) $guessurl = wp_guess_url(); - $baseuri = $guessurl; - $exhibituri = $baseuri . '/wp-content/plugins/datapress'; - $imageurl = $exhibituri . '/exhibit.png'; - $footnotesurl = $exhibituri . '/footnotes.png'; +$baseuri = $guessurl; +$exhibituri = $baseuri . '/wp-content/plugins/datapress'; print << - - - - - - - - - + + + +
URL    [ help with data importing ]
Name
Name

- -Add Data Link

+ + Add Data Link +

+ + diff --git a/facet_widget.php b/facet_widget.php index b540a9d..6e96335 100644 --- a/facet_widget.php +++ b/facet_widget.php @@ -30,4 +30,4 @@ function datapressFacet_init() register_sidebar_widget(__('DataPress Facets'), 'widget_datapressFacet'); } add_action("plugins_loaded", "datapressFacet_init"); -?> +?> \ No newline at end of file diff --git a/head-datasources.php b/head-datasources.php new file mode 100644 index 0000000..b2a4ed5 --- /dev/null +++ b/head-datasources.php @@ -0,0 +1,20 @@ + 0)) { + foreach ($exhibits_to_show as $exhibit_to_show) { + foreach($exhibit_to_show->get('datasources') as $datasource) { + echo($datasource->htmlContent() . "\n"); + } + // This isn't necessary becasue we're dynamically adding it now + // if(WpExhibitGeocoder::doesExhibitContainGeocodedData($exhibit_to_show->get('id'))) { + // echo("\n"); + // } +} +} +?> diff --git a/head-exhibit.php b/head-exhibit.php new file mode 100644 index 0000000..fa48faf --- /dev/null +++ b/head-exhibit.php @@ -0,0 +1,42 @@ +get('lightbox')) || (isset($lightboxed_exhibit))) { + $google_map_api_key = get_option( 'google_map_api_key' ); + $plugin_dir = trailingslashit( get_bloginfo('wpurl') ).PLUGINDIR.'/datapress'; + + ?> + + + + + + get('lenses') as $lens) { + if ($lens->get('decoration') != 'none') { + ?> + + + + get('css'); + if ($css != NULL) { + ?>'); + include('head-start-exhibit.js.php'); + echo(''); + } +} + +?> diff --git a/head-lightbox-library.php b/head-lightbox-library.php index 4afbbfc..03bff32 100644 --- a/head-lightbox-library.php +++ b/head-lightbox-library.php @@ -1,6 +1,4 @@ + +// Start Exhibit Manually + +Exhibit.Functions["contains"] = { + f: function(args) { + var result = args[0].size > 0; + var set = args[0].getSet(); + + args[1].forEachValue(function(v) { + if (!set.contains(v)) { + result = false; + return true; + } + }); + return new Exhibit.Expression._Collection([ result ? "true" : "false" ], "boolean"); + } +}; + +SimileAjax.jQuery(document).ready(function() { + 0)) { + foreach ($exhibits_to_show as $exhibit_to_show) { + if(WpExhibitGeocoder::doesExhibitContainGeocodedData($exhibit_to_show->get('id'))) { + $needGeocoding = true; + } + } +} +?> + + window.database = Exhibit.Database.create(); + + // If we don't need geocoding, load data links with onAllDataLoaded callback. + // IF we do need geocoding, load data links with updateGeocode callback + + window.database.loadDataLinks(updateGeocode); + + window.database.loadDataLinks(onAllDataLoaded); + +}); + +function getItemProps(propertyName) { + var ret = new Array(); + var items = window.database.getAllItems(); + items.visit(function(item) { + var obj = window.database.getObject(item, propertyName); + if(obj != null) { + ret[item] = obj; + } + // else { + // ret[item] = ""; + // } + }); + return ret; +} + +function updateGeocode() { + var geoExId = ""; + var geoAddressField = ""; + var geoIds = []; + var geoAddresses = []; + + 0)) { + foreach ($exhibits_to_show as $exhibit_to_show) { + $exhibit_id = $exhibit_to_show->get('id'); + $fields = WpExhibitGeocoder::getGeocodedFieldsForExhibit($exhibit_id); + foreach ($fields as $field) { + $callBacks += 1; + } + } + } +?> + var callBacks = ; + + 0)) { + foreach ($exhibits_to_show as $exhibit_to_show) { + + $exhibit_id = $exhibit_to_show->get('id'); + $fields = WpExhibitGeocoder::getGeocodedFieldsForExhibit($exhibit_id); + + foreach ($fields as $field) { + /* Step 2: Build up a big list of all the data (itemID, field, value) for these fields */ +?> + geoExId = ""; + geoAddressField = ""; + geoIds = Array(); + geoAddresses = Array(); + + // TOOD: getItemProps + var itemProps = getItemProps(geoAddressField); + var i = 0; + for(key2 in itemProps) { + geoAddresses[i] = itemProps[key2]; + geoIds[i] = key2; + i++; + } + + // Step 3: Call wp-exhibit-geocoder.php with that data + try { + var payload = {'exhibitid': geoExId, 'datumids[]': geoIds, 'addresses[]': geoAddresses, 'addressField': geoAddressField}; + console.log(payload); + SimileAjax.jQuery.post( + , + payload, + function(data) { + SimileAjax. jQuery('head').append("") ?>"); + callBacks -= 1; + if (callBacks == 0) { + window.database = Exhibit.Database.create(); + window.database.loadDataLinks(onAllDataLoaded); + } + } + ); + } catch(e) { + console.log(e); + } // Try catch + +}; + +function onAllDataLoaded() { window.exhibit = Exhibit.create(); + createCollections(); window.exhibit.configureFromDOM(); - }); -}); +}; + +function createCollections() { + var auto_union = new Exhibit.Collection.create2("auto_union", {}, window.exhibit.getUIContext()); + var collection_all = new Exhibit.Collection("collection_all", window.database); + + window.exhibit.setCollection("auto_union", auto_union); + window.exhibit.setCollection("collection_all", collection_all); + + /* + * For each type of item, create a collection + */ + var types = window.database._types; + var collections = {}; + + for (var key in types) { + // if (key != "Item") { + var id = types[key].getID(); + collections[id] = Exhibit.Collection.create2( + 'collection_'+id, + { + baseCollectionID: 'auto_union', + expression:"filter(value, contains(.type, '" + id + "'))" + }, + window.exhibit.getUIContext() + ); + window.exhibit.setCollection('collection_' + id, collections[id]); + // } + } + + collection_all._update = function() { + var dunnit = false; + for (var key in collections) { + if (!dunnit) { + this._items = new Exhibit.Set(collections[key].getRestrictedItems()); + dunnit = true; + } + else { + this._items.addSet(collections[key].getRestrictedItems()); + } + } + this._onRootItemsChanged(); + }; + + collection_all._listener = { onItemsChanged: function() { collection_all._update(); } }; + + for (var key in types) { + collections[id].addListener(collection_all._listener); + } + + collection_all._update(); +}; diff --git a/head.php b/head.php index e85de4b..88096af 100644 --- a/head.php +++ b/head.php @@ -1,145 +1,45 @@ element of a WordPress page load. - * It determines what content to place in the head, and uses the helper methods - * in head-lib.php to accomplish that. - */ -include('head-lib.php'); - -/* - * The wp_query variable lets us access the data for the current post. - */ -global $wp_query; - -/* - * The lightboxed_exhibit contains an Exhibit if we're currently in a lightbox. - */ +global $exhibits_to_show; global $lightboxed_exhibit; +global $wp_query; /* - * This is the helper library for putting things into the HEAD element. - * The task is to determine when and what to put in. - */ -$datapressHead = new DatapressHead(); - -/* - * We'll use this array to contain the exhibits we need to print info for. + * Figure out which exhibits to show */ -global $exhibits_to_show; $exhibits_to_show = array(); +if (isset($lightboxed_exhibit) && ($lightboxed_exhibit != NULL)) { + // We're inside a lightbox + array_push($exhibits_to_show, $lightboxed_exhibit); +} +else { + // We're inside a wordpress page + if ($wp_query->posts > 0) { + foreach($wp_query->posts as $post) { + if ($post->datapress_exhibit) { + array_push($exhibits_to_show, $post->datapress_exhibit); + } + } + } +} /* - * Currently Inside an Exhibit-Only Page - * This is true if we're currently inside a lightbox; - */ -$currently_inside_exhibit_only_page = (isset($lightboxed_exhibit) && ($lightboxed_exhibit != NULL)); - -/* ------------------------------------- - * Step 1: Load the Exhibits we're interested in. - * ------------------------------------- + * Now determine which sub-parts to include */ - if (isset($lightboxed_exhibit) && ($lightboxed_exhibit != NULL)) { - /* - * CASE 1: exhibit-only page (see: wp-exhibit-only.php) - * - * We're in an exhibit-only page while executing this. - * There's only one exhibit, so we just push it to the exhibits_to_show array. - */ - array_push($exhibits_to_show, $lightboxed_exhibit); -} else { - /* - * CASE 2: WordPress page - * - * We're in a regular wordpress page, so we have to inspect the posts that - * are being shown and add the exhibit for each post. - */ - - // Look at each post. - if ($wp_query->posts > 0) { - foreach($wp_query->posts as $post) { - if ($post->datapress_exhibit) { - array_push($exhibits_to_show, $post->datapress_exhibit); - } - } - } + // Weire inside the lightbox + include('head-exhibit.php'); + include('head-datasources.php'); } - -/* ------------------------------------- - * Step 2: Print the appropriate data to the HEAD of the page. - * ------------------------------------- - */ - -if (count($exhibits_to_show) == 0) { - /* - * CASE 1: No exhibits to show. - * - * Do nothing! - */ -} else if (count($exhibits_to_show) == 1) { - /* - * CASE 2: One exhibit to show. - */ - - $exhibit = $exhibits_to_show[0]; - if ($currently_inside_exhibit_only_page) { - // We're showing the exhibit so boot it up! - $datapressHead->print_exhibit_library_links(); - $datapressHead->print_exhibit_specific_links($exhibit); - $datapressHead->print_exhibit_specific_datasources($exhibit); - $datapressHead->print_exhibit_bootup_code(); - } else { - // We're in a WordPress page. - if ($exhibit->get('lightbox')) { - // Show the lightbox preview? If so, just include the libraries - $datapressHead->print_lightbox_library_links(); - // List the data links instead so others can scrape data sources - $datapressHead->print_exhibit_specific_datasources($exhibit); - } else { - // Show the exhibit directly on the page. - // Currently a NO-OP for the element, since this will happen - // inside an IFRAME. - // - // TODO(daniel): Possibly include all the exhibit stuff here: - $datapressHead->print_exhibit_library_links(); - $datapressHead->print_exhibit_specific_links($exhibit); - $datapressHead->print_exhibit_specific_datasources($exhibit); - $datapressHead->print_exhibit_bootup_code(); - // - // TODO(daniel): Make a corresponding change where the exhibit is - // actually printed to remove the IFRAME tag **for only this case** - } - } -} else { - /* - * CASE 3: More than one exhibit to show. - * - * When there is more than one exhibit to show, every exhibit is either a lightbox - * preview or embedded in an iframe. So we only need to 1) decide whether to show the - * lightbox preview links and 2) print out the datasouce links for the benefit of web - * scrapers. - */ - - $needLightboxLibrary = false; - - // Print out web scraping links. - foreach ($exhibits_to_show as $exhibit) { - $datapressHead->print_exhibit_specific_datasources($exhibit); - if ($exhibit->get('lightbox', true)) { - $needLightboxLibrary = true; - } - } - - // Maybe print the lightbox library - if ($needLightboxLibrary) { - $datapressHead->print_lightbox_library_links(); - } +else { + // We're not inside the lightbox + include('head-datasources.php'); + include('head-lightbox-library.php'); + // Taken out because now we're in an iframe. + // if (count($exhibits_to_show) == 1) { + // include('head-exhibit.php'); + // } } - ?> + diff --git a/model/facet.php b/model/facet.php index c23324e..3cb62cb 100644 --- a/model/facet.php +++ b/model/facet.php @@ -39,13 +39,10 @@ function getLinkCaption() { return $this->getShortKind() . ": " . $this->get('label'); } - function htmlContent($showLabel = true) { + function htmlContent() { $kind = $this->get('kind'); $field = $this->get('field'); - $label = $this->get('label'); - if (! $showLabel) { - $label = ""; - } + $label = $this->get('label'); $klass = $this->get('klass'); $collection_insert = ''; diff --git a/model/wp-exhibit-model.php b/model/wp-exhibit-model.php index b954290..2d316c1 100644 --- a/model/wp-exhibit-model.php +++ b/model/wp-exhibit-model.php @@ -30,9 +30,7 @@ function get($field, $nice=false) { else { if (! $nice) { die("Attempted to get a field that does not exist: $field."); - } else { - return null; - } + } } } diff --git a/proxy/import-datafiles.php b/proxy/import-datafiles.php index 300ffd1..53d5b4f 100644 --- a/proxy/import-datafiles.php +++ b/proxy/import-datafiles.php @@ -31,28 +31,39 @@ function is_exhibit($type) { function scrape_google_spreadsheet($url, $type, $contents, $name) { // match: https://docs.google.com/spreadsheet/pub?key=0AnWPOdSwW93adGtnM2lEY0R1TlNxcGJPZmJ2TkRPOHc&output=html $pattern = "/pub\?.*key=([^&]+)/"; + // match: https://docs.google.com/spreadsheets/d/1mbYtgzvP0Zv7Glc7pBjV3FBj2EIflPY37URRsfSikVQ/pubhtml + $pattern2 = "/\/d\/([^&]+)\/pubhtml/"; $linkdatas = array(); $errors = array(); $warnings = array(); $url = urldecode($url); $matched = preg_match_all($pattern, $url, $ids, PREG_PATTERN_ORDER); - if (!$matched) { - if (strpos($url, "json-in-script") === false) { - array_push($warnings, "Unable to parse spreadsheet ID. URL should be of the form https://docs.google.com/spreadsheet/pub?key=SPREADSHEET_ID&output=html"); + $matched2 = preg_match_all($pattern2, $url, $ids2, PREG_PATTERN_ORDER); + if (!$matched && !$matched2) { + if (strpos($url, "json-in-script") === false) { + array_push($warnings, "Unable to parse spreadsheet ID. URL should be of the form https://docs.google.com/ + spreadsheet/pub?key=SPREADSHEET_ID&output=html or https://docs.google.com/spreadsheets/d/SPREADSHEET_ID/pubhtml"); } else { $linkdata = array(); $linkdata["href"] = $url; - $linkdata["kind"] = "google-spreadsheet"; - $linkdata["alt"] = $name; - array_push($linkdatas, $linkdata); + $linkdata["kind"] = "google-spreadsheet"; + $linkdata["alt"] = $name; + array_push($linkdatas, $linkdata); } } else { - $linkdata = array(); - $linkdata["href"] = "https://spreadsheets.google.com/feeds/list/" . $ids[1][0] . "/od6/public/basic?hl=en_US&alt=json-in-script"; - $linkdata["kind"] = "google-spreadsheet"; - $linkdata["alt"] = $name; - array_push($linkdatas, $linkdata); + $linkdata = array(); + if(!$matched){ + //needs extra data to indicate desired sheet request + $linkdata["multisheet"] = true; + $linkdata["key"] = $ids2[1][0]; + $linkdata["sheets_xml"] = file_get_contents("http://spreadsheets.google.com/feeds/worksheets/" . $ids2[1][0] . "/public/full"); + } else { + $linkdata["href"] = "https://spreadsheets.google.com/feeds/list/" . $ids[1][0] . "/od6/public/basic?hl=en_US&alt=json-in-script"; + } + $linkdata["kind"] = "google-spreadsheet"; + $linkdata["alt"] = $name; + array_push($linkdatas, $linkdata); } send_back($linkdatas, $errors, $warnings); } diff --git a/wp-exhibit-insert-exhibit.php b/wp-exhibit-insert-exhibit.php index 41cc19c..cd2508b 100644 --- a/wp-exhibit-insert-exhibit.php +++ b/wp-exhibit-insert-exhibit.php @@ -5,33 +5,11 @@ class WpExhibitHtmlBuilder { static function insert_exhibit($exhibit, $content) { global $wp_query; - global $exhibits_to_show; - /* - our exhibit string is what actually gets printed to screen - this method will be called for each exhibit - */ + $exhibit_string = ''; if ($exhibit->get('lightbox')) { - /* - if we are displaying a lightbox then display the lightbox link - */ $exhibit_string = self::get_exhibit_lightbox_link($exhibit); - } - elseif (count($exhibits_to_show)==1){ - /* - the one exhibit case. We want to generate the exhibit data. This is called in the case of one exhibit in given configuration (did die test to check) - */ - $postid = $wp_query->post->ID; - $exhibitid = $exhibit->get('id'); - //DbMethods::loadFromDatabase($exhibit,$exhibitid); - $exhibit_html = $exhibit_html = self::get_exhibit_html($exhibit, "", $postid); - echo $exhibit_html; - //die; - } - else { - /* - if not showing lightbox and more than one exhibit, display exhibit itself in an iframe - */ + } else { $exhibit_string = self::get_inline_exhibit($exhibit); } if (is_feed()) { @@ -39,16 +17,10 @@ static function insert_exhibit($exhibit, $content) { $permalink = get_permalink($postid); $exhibit_string .= "

Note: This post contains a interactive data presentation that may not show up in your feed reader. For the full experience, visit this article in your web browser.

"; } - if (!$guessurl = site_url()) - $guessurl = wp_guess_url(); - $exhibituri = $guessurl . '/wp-content/plugins/datapress'; - $imageurl = $exhibituri . '/exhibit.png'; - $footnotesurl = $exhibituri . '/footnotes.png'; - - $content = str_replace('Your Exhibit', $exhibit_string, $content); + $content = str_replace("{{Exhibit}}", $exhibit_string, $content); $footnotes_string = self::get_data_footnotes_html($exhibit); - $content = str_replace('Your Footnotes', $footnotes_string, $content); + $content = str_replace("{{Footnotes}}", $footnotes_string, $content); return $content; } @@ -61,8 +33,8 @@ static function get_exhibit_lightbox_link($exhibit) { $exhibituri = $baseuri . '/wp-content/plugins/datapress'; $exhibitid = $exhibit->get('id'); $postid = $wp_query->post->ID; - $exhibit_html = ""; - $exhibit_html .= "
+ $exhibit_html .= ""; + $exhibit_html .= "
@@ -131,9 +103,8 @@ static function get_view_html($exhibit, $currentView, $postid) { return "$tracker_html $view_html"; } - static function get_exhibit_html($exhibit, $currentView, $postid, $includeWidgetFacets=false) { - $view_html = self::get_view_html($exhibit, $currentView, $postid); - $widgetIsntAvailable = false; + static function get_exhibit_html($exhibit, $currentView, $postid) { + $view_html = self::get_view_html($exhibit, $currentView, $postid); $lens_html = ""; foreach ($exhibit->get('lenses') as $lens) { @@ -148,9 +119,9 @@ static function get_exhibit_html($exhibit, $currentView, $postid, $includeWidget $bottom_facet_html = self::facet_html($exhibit->get('facets'), 'bottom'); $left_facet_html = self::facet_html($exhibit->get('facets'), 'left'); $right_facet_html = self::facet_html($exhibit->get('facets'), 'right'); - if ($includeWidgetFacets) { + if ($exhibit->get('lightbox')) { $right_facet_html .= self::facet_html($exhibit->get('facets'), 'widget'); - } + } $exhibit_colspan = 3; if (strlen($left_facet_html) > 0) { diff --git a/wp-exhibit-only.php b/wp-exhibit-only.php index 053f985..ae1b3c8 100644 --- a/wp-exhibit-only.php +++ b/wp-exhibit-only.php @@ -17,15 +17,13 @@ global $lightboxed_exhibit; $exhibitid = $_GET['exhibitid']; if (isset($exhibitid) && ($exhibitid != NULL)) { - // We are going to try to load just this one + // We are goiing to try to load just this one $lightboxed_exhibit = new WpPostExhibit(); DbMethods::loadFromDatabase($lightboxed_exhibit, $exhibitid); } $currentview = $_GET['currentview']; $postid = $_GET['postid']; - $exhibit_html = $exhibit_html = WpExhibitHtmlBuilder::get_exhibit_html($lightboxed_exhibit, $currentview, $postid, true); - //echo $exhibit_html; - //die; + $exhibit_html = $exhibit_html = WpExhibitHtmlBuilder::get_exhibit_html($lightboxed_exhibit, $currentview, $postid); ?>