function get_npr_stories() { global $is_IE; $api = new NPR_API_Client(get_option(NPR_API_KEY_OPTION)); ?> <div class="wrap"> <?php screen_icon(); ?> <h2>Get NPR Stories</h2> <?php if (!$api) { ?> <div class="error"> <p>You don't currently have an API key set. <a href="<?php menu_page_url('npr_api'); ?> ">Set your API key here.</a></p> </div> <?php } if ((isset($_POST) and isset($_POST['story_id'])) || isset($_GET['create_draft']) && isset($_GET['story_id'])) { ?> <div class="updated"> <p><?php echo $this->created_message; ?> </p> </div> <?php } ?> <div style="float: left;"> <form action="" method="POST"> Enter an NPR Story ID: <input type="text" name="story_id" value="" /> <input type="submit" value="Create Draft" /> </form> </div> <div style="float: right; width: 450px;"> <p> <?php // @todo move inline style and javascript somewhere better ?> <!-- Thank you to Marco Arment of Instapaper, from where the bookmarklet style and UX have been lifted. --> <style> .bookmarklet { display: inline-block; font-family: 'Lucida Grande', Verdana, sans-serif; font-weight: bold; font-size: 11px; -webkit-border-radius: 8px; -moz-border-radius: 8px; border-radius: 8px; color: #fff; background-color: #626262; border: 1px solid #626262; padding: 0px 7px 1px 7px; text-shadow: #3b3b3b 1px 1px 0px; min-width: 62px; text-align: center; text-decoration: none; vertical-align: 2px; } </style> <script> function explain_bookmarklet() { <?php if ($is_IE) { ?> alert( 'To use this bookmarklet, right-click on this button and choose "Add to favorites."' ); <?php } else { ?> alert( 'To use this bookmarklet, drag it to your browser\'s bookmarks bar.' ); <?php } ?> return false; } </script> Import stories from NPR.org to your WordPress blog with this bookmarklet. To install:<br /> <strong><?php echo $is_IE ? 'Right-click this button' : 'Drag this button'; ?> </strong> <a class="bookmarklet" onClick="return explain_bookmarklet();" title="Import a story from NPR.org to your WordPress blog." href="javascript:(function(){document.body.appendChild(document.createElement('script')).src='<?php echo plugin_dir_url(__FILE__); ?> bookmarklet-handler.php';})();">Add NPR story to WP</a> <?php echo $is_IE ? ' and choose "Add to favorites."' : 'to your browser\'s bookmarks bar.'; ?> </p> </div> <?php if ($api) { $recent_stories = $api->recent_stories(); ?> <div class="tablenav"> <div class="alignleft actions"> <p class="displaying-num">Displaying <?php echo count($recent_stories); ?> recent stories.</p> </div> </div> <hr /> <table cellspacing="0" id="install-plugins" class="widefat" style="clear:none;"> <thead> <tr> <th scope="col">Title</th> <th scope="col">Date</th> <th scope="col">Description</th> <th scope="col">Actions</th> </tr> </thead> <tfoot> <tr> <th scope="col">Title</th> <th scope="col">Date</th> <th scope="col">Description</th> <th scope="col">Actions</th> </tr> </tfoot> <tbody> <?php foreach ($recent_stories as $story) { ?> <tr> <td class="name"> <strong><a href="<?php echo $story->html_link; ?> " title="<?php echo $story->title; ?> " target="_blank"> <?php echo $story->title; ?> </a></strong> </td> <td class='date'><?php echo strftime('%m/%d/%Y', $story->story_date); ?> <td class='description'><?php echo $story->teaser; ?> </td> <td class="actions" style="width:100px"> <a href="<?php echo add_query_arg(array('story_id' => $story->id, 'create_draft' => 'true'), menu_page_url('get-npr-stories', false)); ?> "> Save to Drafts </a> </td> </tr> <?php } ?> </tbody> </table> <?php } ?> </div> <?php }
function get_npr_stories() { // XXX: check to make sure the api key has been installed. if (get_option(NPR_API_KEY)) { $api = new NPR_API_Client(get_option(NPR_API_KEY_OPTION)); $recent_stories = $api->recent_stories(); } ?> <div class="wrap"> <?php screen_icon(); ?> <form action="" method="POST"> <h2>Get NPR Stories</h2> <?php if (!$api) { ?> <div class="error"> <p>You don't currently have an API key set. <a href="<?php menu_page_url('npr_api'); ?> ">Set your API key here.</a></p> </div> <?php } if ((isset($_POST) and isset($_POST['story_id'])) || isset($_GET['create_draft']) && isset($_GET['story_id'])) { ?> <div class="updated"> <p><?php echo $this->created_message; ?> </p> </div> <?php } ?> <p> Add the NPR API WordPress Plugin Bookmarklet to your browser. To do this, just drag this " <a title="Use this bookmarklet to automatically get the ID of a story at npr.org." href="javascript:(function(){document.body.appendChild(document.createElement('script')).src='http://<?php $domain = $_SERVER['HTTP_HOST']; echo $domain; ?> /wp-content/plugins/WP-NPR-API/sendvariables.php';})();">Add NPR Story to Wordpress!</a>" link into your browser's bookmarks bar. (In Internet Explorer, right-click on the link and choose "Add to favorites.") </p> Enter an NPR Story ID: <input type="text" name="story_id" value="" /> <input type="submit" value="Create Draft" /> </form> <script type="text/javascript"> var query = window.location.search.substring(1); // alert(query); // alert(query.split("&").length) if (query.split("&").length > '1'){ var pairs = query.split("&"); if (window['pairs'] != undefined){ var nprid = pairs[1].substring(6); // alert(nprid); if (nprid != '') document.forms[0].elements[0].value = nprid; // alert(document.forms[0].elements[0].value); } } </script> <?php if ($api) { ?> <div class="tablenav"> <div class="alignleft actions"> <p class="displaying-num">Displaying <?php echo count($recent_stories); ?> recent stories.</p> </div> </div> <hr /> <table cellspacing="0" id="install-plugins" class="widefat" style="clear:none;"> <thead> <tr> <th scope="col">Title</th> <th scope="col">Date</th> <th scope="col">Description</th> <th scope="col">Actions</th> </tr> </thead> <tfoot> <tr> <th scope="col">Title</th> <th scope="col">Date</th> <th scope="col">Description</th> <th scope="col">Actions</th> </tr> </tfoot> <tbody> <?php foreach ($recent_stories as $story) { ?> <tr> <td class="name"> <strong><a href="<?php echo $story->html_link; ?> " title="<?php echo $story->title; ?> " target="_blank"> <?php echo $story->title; ?> </a></strong> </td> <td class='date'><?php echo strftime('%m/%d/%Y', $story->story_date); ?> <td class='description'><?php echo $story->teaser; ?> </td> <td class="actions" style="width:100px"> <a href="<?php echo add_query_arg(array('story_id' => $story->id, 'create_draft' => 'true'), menu_page_url('get-npr-stories', false)); ?> "> Save to Drafts </a> </td> </tr> <?php } ?> </tbody> </table> <?php } ?> </div> <?php }