Skip to content

Commit

Permalink
Better storage of Future Publish values. Added autocomplete for Tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
jchristopher committed Jan 24, 2013
1 parent ee842aa commit 32d3ac8
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 12 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ That's about it. Clicking Publish pushes the entry live instantly (or schedules
## Changelog

<dl>
<dt>0.6</dt>
<dd>Fixed an issue where Future Publish settings wouldn't properly unset after being set.</dd>
<dd>Added autocomplete to Tags</dd>

<dt>0.5.3</dt>
<dd>Fixed an edge case issue where Linkmarklet would show up as a 404 when invoked. Triggered by certain web hosts (in particular HostGator) that seem to interfere when a $_GET includes a protocol.</dd>

Expand Down
72 changes: 68 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ function linkmarklet_post()
$settings = get_option( LINKMARKLET_PREFIX . 'settings' );

// set our time (if applicable)
$timeframe_min = isset( $settings['future_publish']['min'] ) ? intval( $settings['future_publish']['min'] ) : false;
$timeframe_max = isset( $settings['future_publish']['max'] ) ? intval( $settings['future_publish']['max'] ) : false;
$publish_start = isset( $settings['future_publish']['start'] ) ? intval( $settings['future_publish']['start'] ) : false;
$publish_end = isset( $settings['future_publish']['end'] ) ? intval( $settings['future_publish']['end'] ) : false;
$timeframe_min = !isset( $settings['future_publish']['min'] ) || $settings['future_publish']['min'] === '' ? false : intval( $settings['future_publish']['min'] );
$timeframe_max = !isset( $settings['future_publish']['max'] ) || $settings['future_publish']['max'] === '' ? false : intval( $settings['future_publish']['max'] );
$publish_start = !isset( $settings['future_publish']['start'] ) || $settings['future_publish']['start'] === '' ? false : intval( $settings['future_publish']['start'] );
$publish_end = !isset( $settings['future_publish']['end'] ) || $settings['future_publish']['end'] === '' ? false : intval( $settings['future_publish']['end'] );

// by default it'll be right now
$timestamp = (int) current_time( 'timestamp' );
Expand Down Expand Up @@ -361,13 +361,16 @@ function linkmarklet_post()
return $post_ID;
}

wp_enqueue_script( 'jquery-ui-autocomplete' );
wp_enqueue_style( 'jquery-ui' );

?><!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Linkmarklet</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<?php do_action( 'admin_print_scripts' ); do_action('admin_head'); ?>
<style>
* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }
body {
Expand Down Expand Up @@ -471,6 +474,11 @@ function linkmarklet_post()
.message a {
color:#238FF1;
}
.ui-autocomplete {
/* By default the list is positioned according to the field, but we want a bit different */
width:200px !important;
left:110px !important;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -543,5 +551,61 @@ function reposition(){
reposition();
}
</script>
<?php if( !empty( $settings['support_tags'] ) ) : ?>
<?php
$args = array( 'hide_empty' => false );
$tags = get_tags( $args );
foreach( $tags as $tag )
$all_tags[] = '"' . str_replace( '"', '\"', $tag->name ) . '"';
?>

<?php
do_action('admin_footer');
do_action('admin_print_footer_scripts');
?>
<script type="text/javascript">
var LINKMARKLET_TAGS = [<?php echo implode( ',', $all_tags ); ?>];
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}

jQuery('#tags')
// don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === jQuery.ui.keyCode.TAB &&
jQuery( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 0,
source: function( request, response ) {
// delegate back to autocomplete, but extract the last term
response( jQuery.ui.autocomplete.filter(
LINKMARKLET_TAGS, extractLast( request.term ) ) );
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
});
</script>
<?php
endif;
?>
</body>
</html>
13 changes: 6 additions & 7 deletions linkmarklet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
Plugin URI: http://wordpress.org/extend/plugins/linkmarklet/
Description: Alternate to Press This! specifically geared to linkblogging. Quickly post while saving a link to a Custom Field.
Author: Jonathan Christopher
Version: 0.5.3
Version: 0.6
Author URI: http://mondaybynoon.com/
*/

if( !defined( 'IS_ADMIN' ) )
define( 'IS_ADMIN', is_admin() );

define( 'LINKMARKLET_VERSION', '0.5.3' );
define( 'LINKMARKLET_VERSION', '0.6' );
define( 'LINKMARKLET_PREFIX', '_iti_linkmarklet_' );
define( 'LINKMARKLET_DIR', WP_PLUGIN_DIR . '/' . basename( dirname( __FILE__ ) ) );
define( 'LINKMARKLET_URL', rtrim( plugin_dir_url( __FILE__ ), '/' ) );
Expand Down Expand Up @@ -177,11 +177,10 @@ function edit_custom_field()
function edit_future_publish()
{
$settings = get_option( LINKMARKLET_PREFIX . 'settings' );
$timeframe_min = isset( $settings['future_publish']['min'] ) ? intval( $settings['future_publish']['min'] ) : '';
$timeframe_max = isset( $settings['future_publish']['max'] ) ? intval( $settings['future_publish']['max'] ) : '';
$bumper = isset( $settings['future_publish']['bumper'] ) ? intval( $settings['future_publish']['bumper'] ) : '';
$publish_start = isset( $settings['future_publish']['start'] ) ? intval( $settings['future_publish']['start'] ) : '';
$publish_end = isset( $settings['future_publish']['end'] ) ? intval( $settings['future_publish']['end'] ) : '';
$timeframe_min = !isset( $settings['future_publish']['min'] ) || $settings['future_publish']['min'] === '' ? '' : intval( $settings['future_publish']['min'] );
$timeframe_max = !isset( $settings['future_publish']['max'] ) || $settings['future_publish']['max'] === '' ? '' : intval( $settings['future_publish']['max'] );
$publish_start = !isset( $settings['future_publish']['start'] ) || $settings['future_publish']['start'] === '' ? '' : intval( $settings['future_publish']['start'] );
$publish_end = !isset( $settings['future_publish']['end'] ) || $settings['future_publish']['end'] === '' ? '' : intval( $settings['future_publish']['end'] );
?>
Delay publishing by using a range of <input name="<?php echo LINKMARKLET_PREFIX; ?>settings[future_publish][min]" type="text" id="linkmarklet_future_publish_min" value="<?php echo $timeframe_min; ?>" class="small-text" /> to <input name="<?php echo LINKMARKLET_PREFIX; ?>settings[future_publish][max]" type="text" id="linkmarklet_future_publish_max" value="<?php echo $timeframe_max; ?>" class="small-text" /> minutes. I would also like to publish only between the hours of <input name="<?php echo LINKMARKLET_PREFIX; ?>settings[future_publish][start]" type="text" id="linkmarklet_future_publish_start" value="<?php echo $publish_start; ?>" class="small-text" /> and <input name="<?php echo LINKMARKLET_PREFIX; ?>settings[future_publish][end]" type="text" id="linkmarklet_future_publish_end" value="<?php echo $publish_end; ?>" class="small-text" /><br /><span class="description">Leave empty to disable. 24 hour clock.</span>
<?
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link:http://mondaybynoon.com/donate/
Tags: link, linkblog, press this
Requires at least: 3.3
Tested up to: 3.5
Stable tag: 0.5.3
Stable tag: 0.6
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -31,6 +31,10 @@ That's about it. Clicking Publish pushes the entry live instantly (or schedules

== Changelog ==

= 0.6 =
* Fixed an issue where Future Publish settings wouldn't properly unset after being set.
* Added autocomplete to Tags

= 0.5.3 =
* Fixed an edge case issue where Linkmarklet would show up as a 404 when invoked. Triggered by certain web hosts (in particular HostGator) that seem to interfere when a $_GET includes a protocol.

Expand Down

0 comments on commit 32d3ac8

Please sign in to comment.