Next pass on internal linking. Functional, but needs styling. props koopersmith, see #11420.
git-svn-id: http://svn.automattic.com/wordpress/trunk@16393 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
27200382fa
commit
afcbc49e62
|
@ -13,8 +13,8 @@
|
||||||
ed.addCommand('WP_Link', function() {
|
ed.addCommand('WP_Link', function() {
|
||||||
ed.windowManager.open({
|
ed.windowManager.open({
|
||||||
file : tinymce.baseURL + '/wp-mce-link.php',
|
file : tinymce.baseURL + '/wp-mce-link.php',
|
||||||
width : 320,
|
width : 480,
|
||||||
height : 340,
|
height : 400,
|
||||||
inline : 1
|
inline : 1
|
||||||
}, {
|
}, {
|
||||||
plugin_url : url // Plugin absolute URL
|
plugin_url : url // Plugin absolute URL
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
(function(){tinymce.create("tinymce.plugins.wpLink",{init:function(a,b){a.addCommand("WP_Link",function(){a.windowManager.open({file:tinymce.baseURL+"/wp-mce-link.php",width:320,height:340,inline:1},{plugin_url:b})});a.addButton("link",{title:a.getLang("advanced.link_desc"),cmd:"WP_Link"});a.addShortcut("alt+shift+a",a.getLang("advanced.link_desc"),"WP_Link");a.onNodeChange.add(function(d,c,e){c.setActive("wplink",e.nodeName=="A")})},getInfo:function(){return{longname:"WordPress Link Dialog",author:"WordPress",authorurl:"http://wordpress.org",infourl:"",version:"1.0"}}});tinymce.PluginManager.add("wplink",tinymce.plugins.wpLink)})();
|
(function(){tinymce.create("tinymce.plugins.wpLink",{init:function(a,b){a.addCommand("WP_Link",function(){a.windowManager.open({file:tinymce.baseURL+"/wp-mce-link.php",width:480,height:400,inline:1},{plugin_url:b})});a.addButton("link",{title:a.getLang("advanced.link_desc"),cmd:"WP_Link"});a.addShortcut("alt+shift+a",a.getLang("advanced.link_desc"),"WP_Link");a.onNodeChange.add(function(d,c,e){c.setActive("wplink",e.nodeName=="A")})},getInfo:function(){return{longname:"WordPress Link Dialog",author:"WordPress",authorurl:"http://wordpress.org",infourl:"",version:"1.0"}}});tinymce.PluginManager.add("wplink",tinymce.plugins.wpLink)})();
|
|
@ -1,137 +1,50 @@
|
||||||
(function($){
|
(function($){
|
||||||
$.widget('wp.wpTabs', {
|
var inputs = {}, results = {}, ed,
|
||||||
options: {},
|
|
||||||
_create: function() {
|
|
||||||
var self = this,
|
|
||||||
ul = this.element,
|
|
||||||
lis = ul.children();
|
|
||||||
|
|
||||||
this.active = lis.filter('.wp-tab-active');
|
|
||||||
// Calculate panel IDs
|
|
||||||
lis.each(function() {
|
|
||||||
var panel = self._getPanel( $(this) );
|
|
||||||
if ( self.active[0] == this )
|
|
||||||
panel.show();
|
|
||||||
else
|
|
||||||
panel.hide();
|
|
||||||
});
|
|
||||||
|
|
||||||
ul.delegate('li', 'click.wpTabs', function(e) {
|
|
||||||
var li = $(this);
|
|
||||||
|
|
||||||
// Prevent any child link from redirecting the page.
|
|
||||||
e.preventDefault();
|
|
||||||
// Deactivate previous tab.
|
|
||||||
self._getPanel( self.active ).hide();
|
|
||||||
self.active.removeClass('wp-tab-active');
|
|
||||||
self._trigger("hide", e, self.widget() );
|
|
||||||
|
|
||||||
// Activate current tab.
|
|
||||||
self.active = li.addClass('wp-tab-active');
|
|
||||||
self._getPanel( self.active ).show();
|
|
||||||
self._trigger("show", e, self.widget() );
|
|
||||||
});
|
|
||||||
},
|
|
||||||
widget: function() {
|
|
||||||
return {
|
|
||||||
ul: this.element,
|
|
||||||
tab: this.active,
|
|
||||||
panel: this._getPanel( this.active )
|
|
||||||
};
|
|
||||||
},
|
|
||||||
_setPanel: function( $el ) {
|
|
||||||
var panel = $( '#' + $el.children('.wp-tab-for-id').val() );
|
|
||||||
$el.data( 'wp-tab-panel', panel );
|
|
||||||
return panel;
|
|
||||||
},
|
|
||||||
_getPanel: function( $el ) {
|
|
||||||
var panel = $el.data('wp-tab-panel');
|
|
||||||
return ( !panel || !panel.length ) ? this._setPanel( $el ) : panel;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Create tab bars by default.
|
|
||||||
$(function(){
|
|
||||||
$('.wp-tab-bar').wpTabs();
|
|
||||||
});
|
|
||||||
})(jQuery);
|
|
||||||
|
|
||||||
(function($){
|
|
||||||
var inputs = {}, panels, active, ed,
|
|
||||||
wpLink = {
|
wpLink = {
|
||||||
init : function() {
|
init : function() {
|
||||||
var e, etarget, eclass;
|
var e, etarget, eclass;
|
||||||
// Init shared vars
|
// Init shared vars
|
||||||
ed = tinyMCEPopup.editor;
|
ed = tinyMCEPopup.editor;
|
||||||
|
|
||||||
|
|
||||||
|
// URL
|
||||||
|
inputs.url = $('#url-field');
|
||||||
// Secondary options
|
// Secondary options
|
||||||
inputs.title = $('#link-title-field');
|
inputs.title = $('#link-title-field');
|
||||||
// Advanced Options
|
// Advanced Options
|
||||||
inputs.openInNewTab = $('#link-target-checkbox');
|
inputs.openInNewTab = $('#link-target-checkbox');
|
||||||
|
inputs.search = $('#search-field');
|
||||||
panels = $('.link-panel');
|
// Result lists
|
||||||
active = $('.link-panel-active');
|
results.search = $('#search-results');
|
||||||
$('#link-panel-tab-bar').wpTabs({
|
results.recent = $('#most-recent-results');
|
||||||
show: function(e, widget) {
|
|
||||||
active = widget.panel;
|
|
||||||
active.addClass('link-panel-active');
|
|
||||||
wpLink.maybeLoadPanel();
|
|
||||||
},
|
|
||||||
hide: function(e, widget) {
|
|
||||||
active.removeClass('link-panel-active');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
panels.each( function(){
|
|
||||||
var linkType = this.id.replace(/^link-panel-id-/,''),
|
|
||||||
parts = linkType.split('-');
|
|
||||||
$(this).data( 'link-type', {
|
|
||||||
full : linkType,
|
|
||||||
type : parts[0],
|
|
||||||
name : parts[1] || ''
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Bind event handlers
|
// Bind event handlers
|
||||||
$('#wp-update').click( wpLink.update );
|
$('#wp-update').click( wpLink.update );
|
||||||
$('#wp-cancel').click( function() { tinyMCEPopup.close(); } );
|
$('#wp-cancel').click( function() { tinyMCEPopup.close(); } );
|
||||||
$('.link-panel .wp-tab-bar').wpTabs('option', 'show', wpLink.maybeLoadPanel );
|
$('.query-results').delegate('li', 'click', wpLink.selectInternalLink );
|
||||||
$('.link-panel .wp-tab-panel').delegate('li', 'click', wpLink.selectInternalLink );
|
$('.wp-results-pagelinks').delegate('a', 'click', wpLink.selectPageLink );
|
||||||
$('.wp-tab-panel-pagelinks').delegate('a', 'click', wpLink.selectPageLink );
|
inputs.search.keyup( wpLink.searchInternalLinks );
|
||||||
$('.link-panel .link-search-field').keyup( wpLink.searchInternalLinks );
|
|
||||||
|
|
||||||
active.find('input.url-field').focus();
|
|
||||||
|
|
||||||
// If link exists, select proper values.
|
// If link exists, select proper values.
|
||||||
e = ed.dom.getParent(ed.selection.getNode(), 'A');
|
if ( e = ed.dom.getParent(ed.selection.getNode(), 'A') ) {
|
||||||
if ( ! e )
|
// Set URL and description.
|
||||||
return;
|
inputs.url.val( e.href );
|
||||||
|
|
||||||
active.find('input.url-field').val( e.href );
|
|
||||||
inputs.title.val( ed.dom.getAttrib(e, 'title') );
|
inputs.title.val( ed.dom.getAttrib(e, 'title') );
|
||||||
// Advanced Options
|
// Set open in new tab.
|
||||||
|
|
||||||
if ( "_blank" == ed.dom.getAttrib(e, 'target') )
|
if ( "_blank" == ed.dom.getAttrib(e, 'target') )
|
||||||
inputs.openInNewTab.attr('checked','checked');
|
inputs.openInNewTab.attr('checked','checked');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
update : function() {
|
update : function() {
|
||||||
var el,
|
var el,
|
||||||
ed = tinyMCEPopup.editor,
|
ed = tinyMCEPopup.editor,
|
||||||
attrs = {
|
attrs = {
|
||||||
|
href : inputs.url.val(),
|
||||||
title : inputs.title.val(),
|
title : inputs.title.val(),
|
||||||
target : inputs.openInNewTab.attr('checked') ? '_blank' : ''
|
target : inputs.openInNewTab.attr('checked') ? '_blank' : ''
|
||||||
}, defaultContent, e, b;
|
}, e, b,
|
||||||
|
defaultContent = attrs.title ? attrs.title : attrs.href;
|
||||||
if ( active.hasClass('link-panel-custom') ) {
|
|
||||||
attrs.href = active.find('input.url-field').val();
|
|
||||||
defaultContent = attrs.href;
|
|
||||||
} else {
|
|
||||||
el = active.find('li.selected:visible');
|
|
||||||
if ( !el.length )
|
|
||||||
return;
|
|
||||||
|
|
||||||
attrs.href = el.children('input').val();
|
|
||||||
defaultContent = el.text();
|
|
||||||
}
|
|
||||||
|
|
||||||
tinyMCEPopup.restoreSelection();
|
tinyMCEPopup.restoreSelection();
|
||||||
e = ed.dom.getParent(ed.selection.getNode(), 'A');
|
e = ed.dom.getParent(ed.selection.getNode(), 'A');
|
||||||
|
@ -190,47 +103,14 @@
|
||||||
tinyMCEPopup.close();
|
tinyMCEPopup.close();
|
||||||
},
|
},
|
||||||
|
|
||||||
maybeLoadPanel : function() {
|
|
||||||
var panel = active.find('.wp-tab-panel:visible');
|
|
||||||
if ( panel.length && panel.find('.wp-tab-panel-loading').length )
|
|
||||||
wpLink.linkPanelAJAX( panel );
|
|
||||||
},
|
|
||||||
|
|
||||||
linkPanelAJAX : function( $panel, params, callback ) {
|
|
||||||
if ( ! $panel.hasClass('wp-tab-panel') )
|
|
||||||
$panel = $panel.parents('.wp-tab-panel');
|
|
||||||
|
|
||||||
if ( ! $panel.length )
|
|
||||||
return;
|
|
||||||
|
|
||||||
var query = $panel.children('.wp-tab-panel-query').val();
|
|
||||||
|
|
||||||
wpLink.linkAJAX( $panel, $.extend({
|
|
||||||
preset : query,
|
|
||||||
page : 'all' == query ? 1 : 0
|
|
||||||
}, params), function(r, lt) {
|
|
||||||
var pagelinks = $panel.children('.wp-tab-panel-pagelinks');
|
|
||||||
|
|
||||||
// Set results
|
|
||||||
$panel.children('ul').html( wpLink.generateListMarkup( r['results'], lt ) );
|
|
||||||
|
|
||||||
// Handle page links
|
|
||||||
if ( r['page_links'] )
|
|
||||||
pagelinks.html( r['page_links'] ).show();
|
|
||||||
else
|
|
||||||
pagelinks.hide();
|
|
||||||
// Run callback
|
|
||||||
if ( callback )
|
|
||||||
callback(r, lt);
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
selectInternalLink : function() {
|
selectInternalLink : function() {
|
||||||
var t = $(this);
|
var t = $(this);
|
||||||
if ( t.hasClass('unselectable') )
|
if ( t.hasClass('unselectable') )
|
||||||
return;
|
return;
|
||||||
t.siblings('.selected').removeClass('selected');
|
t.siblings('.selected').removeClass('selected');
|
||||||
t.addClass('selected');
|
t.addClass('selected');
|
||||||
|
inputs.url.val( t.children('.item-permalink').val() );
|
||||||
|
inputs.title.val( t.children('.item-title').text() );
|
||||||
},
|
},
|
||||||
|
|
||||||
selectPageLink : function(e) {
|
selectPageLink : function(e) {
|
||||||
|
@ -239,37 +119,62 @@
|
||||||
page = page ? page[1] : 1; // If there's no match, it's the first page.
|
page = page ? page[1] : 1; // If there's no match, it's the first page.
|
||||||
e.preventDefault(); // Prevent the link from redirecting.
|
e.preventDefault(); // Prevent the link from redirecting.
|
||||||
|
|
||||||
wpLink.linkPanelAJAX( $(this), { page : page });
|
wpLink.linkAJAX( $(this), { page : page });
|
||||||
},
|
},
|
||||||
|
|
||||||
searchInternalLinks : function() {
|
searchInternalLinks : function() {
|
||||||
var t = $(this),
|
var t = $(this), waiting,
|
||||||
waiting = t.siblings('img.waiting').show();
|
title = t.val();
|
||||||
|
|
||||||
wpLink.linkPanelAJAX( t, { title : t.val() }, function(){ waiting.hide(); });
|
if ( title ) {
|
||||||
|
results.recent.hide();
|
||||||
|
results.search.show();
|
||||||
|
waiting = t.siblings('img.waiting').show();
|
||||||
|
wpLink.linkAJAX( results.search, { title : title }, function(){ waiting.hide(); });
|
||||||
|
} else {
|
||||||
|
results.search.hide();
|
||||||
|
results.recent.show();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
linkAJAX : function( el, params, callback ) {
|
linkAJAX : function( $panel, params, callback ) {
|
||||||
var linkType = el.parents('.link-panel').data('link-type');
|
if ( ! $panel.hasClass('query-results') )
|
||||||
|
$panel = $panel.parents('.query-results');
|
||||||
|
|
||||||
|
if ( ! $panel.length )
|
||||||
|
return;
|
||||||
|
|
||||||
$.post( ajaxurl, $.extend({
|
$.post( ajaxurl, $.extend({
|
||||||
action : 'wp-link-ajax',
|
action : 'wp-link-ajax'
|
||||||
type : linkType.type,
|
|
||||||
name : linkType.name
|
|
||||||
}, params ), function(r) {
|
}, params ), function(r) {
|
||||||
return callback(r, linkType);
|
var pagelinks = $panel.children('.wp-results-pagelinks');
|
||||||
|
|
||||||
|
// Set results
|
||||||
|
$panel.children('ul').html( wpLink.generateListMarkup( r['results'] ) );
|
||||||
|
|
||||||
|
// Handle page links
|
||||||
|
if ( r['page_links'] )
|
||||||
|
pagelinks.html( r['page_links'] ).show();
|
||||||
|
else
|
||||||
|
pagelinks.hide();
|
||||||
|
|
||||||
|
// Run callback
|
||||||
|
if ( callback )
|
||||||
|
callback( r['results'] );
|
||||||
}, "json" );
|
}, "json" );
|
||||||
},
|
},
|
||||||
|
|
||||||
generateListMarkup : function( results, linkType ) {
|
generateListMarkup : function( results ) {
|
||||||
var s = '';
|
var s = '';
|
||||||
|
|
||||||
if ( ! results )
|
if ( ! results )
|
||||||
return '<li class="no-matches-found unselectable"><em>' + wpLinkL10n.noMatchesFound + '</em></li>';
|
return '<li class="no-matches-found unselectable"><span class="item-title"><em>' + wpLinkL10n.noMatchesFound + '</em></span></li>';
|
||||||
|
|
||||||
$.each( results, function() {
|
$.each( results, function() {
|
||||||
s+= '<li id="link-to-' + linkType.full + '-' + this['ID'] + '">';
|
s+= '<li><input type="hidden" class="item-permalink" value="' + this['permalink'] + '" />';
|
||||||
s+= '<input type="hidden" value="' + this['permalink'] + '" />';
|
s+= '<span class="item-title">'
|
||||||
s+= this['title'] ? this['title'] : '<em>'+ wpLinkL10n.untitled + '</em>';
|
s+= this['title'] ? this['title'] : '<em>'+ wpLinkL10n.untitled + '</em>';
|
||||||
|
s+= '</span><span class="item-info">' + this['info'] + '</span>';
|
||||||
s+= '</li>';
|
s+= '</li>';
|
||||||
});
|
});
|
||||||
return s;
|
return s;
|
||||||
|
|
|
@ -1,151 +1,35 @@
|
||||||
<?php
|
<?php
|
||||||
|
// args expects optionally 'pagenum' and 's'
|
||||||
|
function wp_link_query( $args = array() ) {
|
||||||
|
$pts = get_post_types( array( 'publicly_queryable' => true ), 'objects' );
|
||||||
|
$pt_names = array_keys( $pts );
|
||||||
|
|
||||||
class WP_Tab_Bar {
|
$query = array(
|
||||||
var $tabs = array();
|
'post_type' => $pt_names,
|
||||||
|
|
||||||
var $id = '';
|
|
||||||
var $classes = array();
|
|
||||||
|
|
||||||
var $selected = '';
|
|
||||||
|
|
||||||
function add( $id, $label, $url='' ) {
|
|
||||||
array_push( $this->tabs, array(
|
|
||||||
'label' => $label,
|
|
||||||
'for' => $id,
|
|
||||||
'url' => $url
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
function select( $id ) {
|
|
||||||
$this->selected = $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
function render( $echo=true ) {
|
|
||||||
if ( empty( $this->selected ) )
|
|
||||||
$this->selected = $this->tabs[0]['for'];
|
|
||||||
|
|
||||||
array_unshift( $this->classes, 'wp-tab-bar' );
|
|
||||||
|
|
||||||
$out = "<ul id='$this->id' class='" . esc_attr( implode( ' ', $this->classes ) ) . "'>";
|
|
||||||
foreach( $this->tabs as $tab ) {
|
|
||||||
if ( !isset($tab['url']) )
|
|
||||||
$tab['url'] = '';
|
|
||||||
|
|
||||||
$out.= "<li class='";
|
|
||||||
$out.= $this->selected == $tab['for'] ? 'wp-tab-active' : '';
|
|
||||||
$out.= "'><input type='hidden' class='wp-tab-for-id' value='{$tab['for']}' />";
|
|
||||||
$out.= "<a href='{$tab['url']}#{$tab['for']}'>";
|
|
||||||
$out.= "{$tab['label']}</a></li>";
|
|
||||||
}
|
|
||||||
$out.= "</ul>";
|
|
||||||
|
|
||||||
if ( $echo )
|
|
||||||
echo $out;
|
|
||||||
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function wp_link_panel_custom() { ?>
|
|
||||||
<div id="link-panel-id-custom" class="link-panel link-panel-custom link-panel-active">
|
|
||||||
<input type="hidden" class="link-panel-type" value="custom" />
|
|
||||||
<label>
|
|
||||||
<span><?php _e('URL:'); ?></span><input class="url-field" type="text" />
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<?php }
|
|
||||||
|
|
||||||
function wp_link_panel_structure( $panel_type, $name, $queries ) {
|
|
||||||
$id = $panel_type . '-' . $name;
|
|
||||||
|
|
||||||
?>
|
|
||||||
<div id="link-panel-id-<?php echo $id; ?>" class="link-panel link-panel-<?php echo $panel_type; ?>">
|
|
||||||
<!-- <input type="hidden" class="link-panel-type" value="<?php echo $panel_type; ?>" /> -->
|
|
||||||
<!-- <input type="hidden" class="link-panel-id" value="" /> -->
|
|
||||||
<?php
|
|
||||||
|
|
||||||
$tb = new WP_Tab_Bar();
|
|
||||||
foreach( $queries as $i => $query ) {
|
|
||||||
$queries[$i]['id'] = "$id-{$query['preset']}";
|
|
||||||
$tb->add( $queries[$i]['id'], $query['label'] );
|
|
||||||
}
|
|
||||||
$tb->render();
|
|
||||||
|
|
||||||
foreach( $queries as $query ): ?>
|
|
||||||
<div id="<?php echo $query['id']; ?>" class="wp-tab-panel">
|
|
||||||
<input type="hidden" class="wp-tab-panel-query" value="<?php echo $query['preset']; ?>" />
|
|
||||||
|
|
||||||
<?php if ( 'search' == $query['preset'] ): ?>
|
|
||||||
<label for="<?php echo $id; ?>-search-field" class="link-search-wrapper">
|
|
||||||
<span><?php _e('Search:'); ?></span>
|
|
||||||
<input type="text" id="<?php echo $id; ?>-search-field" class="link-search-field" />
|
|
||||||
<img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
|
|
||||||
</label>
|
|
||||||
<ul id="<?php echo $id; ?>-search-results" class="link-search-results"></ul>
|
|
||||||
|
|
||||||
<?php else: ?>
|
|
||||||
<div class="wp-tab-panel-pagelinks wp-tab-panel-pagelinks-top"></div>
|
|
||||||
<ul>
|
|
||||||
<li class="wp-tab-panel-loading unselectable"><em><?php _e('Loading...'); ?></em></li>
|
|
||||||
</ul>
|
|
||||||
<div class="wp-tab-panel-pagelinks wp-tab-panel-pagelinks-bottom"></div>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</div>
|
|
||||||
<?php }
|
|
||||||
|
|
||||||
function wp_link_query_post_type( $pt_obj, $preset='all', $opts=array() ) {
|
|
||||||
$args_base = array(
|
|
||||||
'post_type' => $pt_obj->name,
|
|
||||||
'suppress_filters' => true,
|
'suppress_filters' => true,
|
||||||
'update_post_term_cache' => false,
|
'update_post_term_cache' => false,
|
||||||
'update_post_meta_cache' => false,
|
'update_post_meta_cache' => false,
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
);
|
|
||||||
|
|
||||||
switch( $preset ) {
|
|
||||||
case 'all':
|
|
||||||
$args = array_merge( $args_base, array(
|
|
||||||
'order' => 'ASC',
|
|
||||||
'orderby' => 'title',
|
|
||||||
'posts_per_page' => 20,
|
|
||||||
));
|
|
||||||
break;
|
|
||||||
case 'recent':
|
|
||||||
$args = array_merge( $args_base, array(
|
|
||||||
'order' => 'DESC',
|
'order' => 'DESC',
|
||||||
'orderby' => 'post_date',
|
'orderby' => 'post_date',
|
||||||
'posts_per_page' => 15,
|
'posts_per_page' => 20,
|
||||||
));
|
|
||||||
break;
|
|
||||||
case 'search':
|
|
||||||
$args = array_merge( $args_base, array(
|
|
||||||
's' => isset($opts['search']) ? $opts['search'] : '',
|
|
||||||
'posts_per_page' => 10
|
|
||||||
));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle pages if a page number is specified.
|
|
||||||
if ( isset( $opts['pagenum'] ) && isset( $args['posts_per_page'] ) ) {
|
|
||||||
$pages = array(
|
|
||||||
'current' => $opts['pagenum'],
|
|
||||||
'per_page' => $args['posts_per_page']
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( ! isset( $args['offset'] ) )
|
$args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
|
||||||
$args['offset'] = 0 < $opts['pagenum'] ? $args['posts_per_page'] * ( $opts['pagenum'] - 1 ) : 0;
|
|
||||||
$pages['offset'] = $args['offset'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow args to be extended.
|
if ( isset( $args['s'] ) )
|
||||||
if ( isset( $opts['args'] ) )
|
$query['s'] = $args['s'];
|
||||||
$args = array_merge( $args, $opts['args'] );
|
|
||||||
|
$pagination = array(
|
||||||
|
'current' => $args['pagenum'],
|
||||||
|
'per_page' => $query['posts_per_page'],
|
||||||
|
);
|
||||||
|
|
||||||
|
$query['offset'] = $pagination['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
|
||||||
|
|
||||||
// Do main query.
|
// Do main query.
|
||||||
$get_posts = new WP_Query;
|
$get_posts = new WP_Query;
|
||||||
$posts = $get_posts->query( $args );
|
$posts = $get_posts->query( $query );
|
||||||
// Check if any posts were found.
|
// Check if any posts were found.
|
||||||
if ( ! $get_posts->post_count )
|
if ( ! $get_posts->post_count )
|
||||||
return false;
|
return false;
|
||||||
|
@ -153,57 +37,49 @@ function wp_link_query_post_type( $pt_obj, $preset='all', $opts=array() ) {
|
||||||
// Build results.
|
// Build results.
|
||||||
$results = array();
|
$results = array();
|
||||||
foreach ( $posts as $post ) {
|
foreach ( $posts as $post ) {
|
||||||
|
if ( 'post' == $post->post_type )
|
||||||
|
$info = mysql2date( __( 'Y/m/d' ), $post->post_date );
|
||||||
|
else
|
||||||
|
$info = $pts[ $post->post_type ]->labels->singular_name;
|
||||||
|
|
||||||
$results[] = array(
|
$results[] = array(
|
||||||
'ID' => $post->ID,
|
'ID' => $post->ID,
|
||||||
'title' => $post->post_title,
|
'title' => esc_html( strip_tags($post->post_title) ),
|
||||||
'permalink' => get_permalink( $post->ID )
|
'permalink' => get_permalink( $post->ID ),
|
||||||
);
|
'info' => $info,
|
||||||
|
);;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remaining pagination values.
|
||||||
|
$pagination['max'] = $get_posts->max_num_pages;
|
||||||
|
$pagination['page_links'] = paginate_links( array(
|
||||||
|
'prev_text' => __('«'),
|
||||||
|
'next_text' => __('»'),
|
||||||
|
'total' => $pagination['max'],
|
||||||
|
'current' => $pagination['current']
|
||||||
|
) );
|
||||||
|
|
||||||
// Build response.
|
// Build response.
|
||||||
$resp = array(
|
$resp = array(
|
||||||
'query' => $get_posts,
|
'query' => $get_posts,
|
||||||
'objects' => $posts,
|
'objects' => $posts,
|
||||||
'results' => $results
|
'results' => $results,
|
||||||
|
'pages' => $pagination,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Set remaining pages values.
|
|
||||||
if ( isset( $pages ) ) {
|
|
||||||
$pages['max'] = $resp['query']->max_num_pages;
|
|
||||||
$pages['page_links'] = paginate_links( array(
|
|
||||||
'prev_text' => __('«'),
|
|
||||||
'next_text' => __('»'),
|
|
||||||
'total' => $pages['max'],
|
|
||||||
'current' => $pages['current']
|
|
||||||
));
|
|
||||||
$resp['pages'] = $pages;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $resp;
|
return $resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
function wp_link_ajax( $request ) {
|
function wp_link_ajax( $request ) {
|
||||||
if ( !isset($request['type']) || !isset($request['name']) || !isset($request['preset']) )
|
// Searches have a title term.
|
||||||
die('-1');
|
if ( isset( $request['title'] ) )
|
||||||
|
$args['s'] = stripslashes( $request['title'] );
|
||||||
|
$args['pagenum'] = ! empty( $request['page'] ) ? absint( $request['page'] ) : 1;
|
||||||
|
|
||||||
// Run only presets we recognize.
|
$resp = wp_link_query( $args );
|
||||||
if ( 'pt' != $request['type'] || ! in_array( $request['preset'], array('all','search','recent') ) )
|
|
||||||
die('-1');
|
|
||||||
// Searches must have a search term.
|
|
||||||
else if ( 'search' == $request['preset'] && !isset($request['title']) )
|
|
||||||
die('-1');
|
|
||||||
|
|
||||||
$opts = array();
|
|
||||||
if ( 'search' == $request['preset'] ) {
|
|
||||||
$opts['search'] = $request['title'];
|
|
||||||
} else if ( ! empty( $request['page'] ) ) {
|
|
||||||
$opts['pagenum'] = $request['page'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( 'pt' == $request['type'] && $obj = get_post_type_object($request['name']) )
|
|
||||||
$resp = wp_link_query_post_type( $obj, $request['preset'], $opts );
|
|
||||||
|
|
||||||
if ( ! isset( $resp ) )
|
if ( ! isset( $resp ) )
|
||||||
die('0');
|
die( '0' );
|
||||||
|
|
||||||
$json = array( 'results' => $resp['results'] );
|
$json = array( 'results' => $resp['results'] );
|
||||||
if ( isset( $resp['pages'] ) && !empty( $resp['pages']['page_links'] ) )
|
if ( isset( $resp['pages'] ) && !empty( $resp['pages']['page_links'] ) )
|
||||||
|
@ -212,4 +88,5 @@ function wp_link_ajax( $request ) {
|
||||||
echo json_encode( $json );
|
echo json_encode( $json );
|
||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -23,7 +23,11 @@ var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>',
|
||||||
<?php
|
<?php
|
||||||
wp_print_scripts( array('jquery', 'jquery-ui-widget') );
|
wp_print_scripts( array('jquery', 'jquery-ui-widget') );
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript" src="plugins/wplink/js/wplink.js?ver=20101023"></script>
|
<?php
|
||||||
|
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : '';
|
||||||
|
$src = "plugins/wplink/js/wplink$suffix.js?ver=20101023";
|
||||||
|
?>
|
||||||
|
<script type="text/javascript" src="<?php echo $src; ?>"></script>
|
||||||
<?php
|
<?php
|
||||||
wp_admin_css( 'global', true );
|
wp_admin_css( 'global', true );
|
||||||
wp_admin_css( 'wp-admin', true );
|
wp_admin_css( 'wp-admin', true );
|
||||||
|
@ -43,26 +47,11 @@ select {
|
||||||
height: 2em;
|
height: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#link-header,
|
|
||||||
#link-options,
|
#link-options,
|
||||||
#link-advanced-options {
|
#link-advanced-options {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border-bottom: 1px solid #dfdfdf;
|
border-bottom: 1px solid #dfdfdf;
|
||||||
}
|
}
|
||||||
#link-header {
|
|
||||||
padding-bottom: 0;
|
|
||||||
background: #fff;
|
|
||||||
}
|
|
||||||
#link-panel-tab-bar li {
|
|
||||||
font-weight: bold;
|
|
||||||
border: #dfdfdf solid;
|
|
||||||
margin-right: 5px;
|
|
||||||
border-width: 1px 1px 0;
|
|
||||||
}
|
|
||||||
#link-panel-tab-bar .wp-tab-active {
|
|
||||||
border-color:#ccc;
|
|
||||||
background-color: #f1f1f1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#link-type {
|
#link-type {
|
||||||
width: 140px;
|
width: 140px;
|
||||||
|
@ -77,12 +66,9 @@ select {
|
||||||
}
|
}
|
||||||
|
|
||||||
label input[type="text"] {
|
label input[type="text"] {
|
||||||
width: 220px;
|
width: 360px;
|
||||||
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
.wp-tab-panel label input[type="text"] {
|
|
||||||
float: left;
|
|
||||||
width: 200px;
|
|
||||||
}
|
|
||||||
|
|
||||||
label span {
|
label span {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
@ -90,20 +76,21 @@ label span {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
padding-right: 5px;
|
padding-right: 5px;
|
||||||
}
|
}
|
||||||
.wp-tab-panel label span {
|
|
||||||
width: auto;
|
|
||||||
text-align: left;
|
|
||||||
float: left;
|
|
||||||
margin-top: 3px;
|
|
||||||
}
|
|
||||||
.link-search-wrapper {
|
.link-search-wrapper {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border-bottom: solid 1px #dfdfdf;
|
|
||||||
display: block;
|
display: block;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.link-search-wrapper span {
|
||||||
|
float: left;
|
||||||
|
margin-top: 6px;
|
||||||
|
}
|
||||||
|
.link-search-wrapper input[type="text"] {
|
||||||
|
float: left;
|
||||||
|
width: 220px;
|
||||||
}
|
}
|
||||||
.link-search-wrapper img.waiting {
|
.link-search-wrapper img.waiting {
|
||||||
margin: 4px 1px 0 4px;
|
margin: 8px 1px 0 4px;
|
||||||
float: left;
|
float: left;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
@ -117,8 +104,52 @@ label span {
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.query-results {
|
||||||
|
border: #dfdfdf solid;
|
||||||
|
border-width: 1px 0;
|
||||||
|
margin: 5px 0;
|
||||||
|
background: #fff;
|
||||||
|
height: 220px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
.query-results li {
|
||||||
|
margin-bottom: 0;
|
||||||
|
border-bottom: 1px solid #dfdfdf;
|
||||||
|
color: #555;
|
||||||
|
padding: 4px 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.query-results li:hover {
|
||||||
|
background: #EAF2FA;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
.query-results li.selected {
|
||||||
|
background: #f1f1f1;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
.item-info {
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: #aaa;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 11px;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
#search-results {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wp-results-pagelinks {
|
||||||
|
padding:4px 0;
|
||||||
|
margin:0 auto;
|
||||||
|
text-align:center;
|
||||||
|
}
|
||||||
|
.wp-results-pagelinks-top {
|
||||||
|
border-bottom: 1px solid #dfdfdf;
|
||||||
|
}
|
||||||
|
|
||||||
.submitbox {
|
.submitbox {
|
||||||
padding: 5px;
|
padding: 5px 5px 0;
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
height: 29px;
|
height: 29px;
|
||||||
|
@ -134,71 +165,18 @@ label span {
|
||||||
#wp-update a {
|
#wp-update a {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
.wp-tab-active,
|
|
||||||
.wp-tab-panel {
|
|
||||||
background: #fff;
|
|
||||||
}
|
|
||||||
.wp-tab-panel {
|
|
||||||
height: 160px;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
.wp-tab-panel li {
|
|
||||||
margin-bottom: 0;
|
|
||||||
border-bottom: 1px solid #dfdfdf;
|
|
||||||
color: #555;
|
|
||||||
padding: 4px 6px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.wp-tab-panel li:hover {
|
|
||||||
background: #EAF2FA;
|
|
||||||
color: #333;
|
|
||||||
}
|
|
||||||
.wp-tab-panel li.selected {
|
|
||||||
background: #f1f1f1;
|
|
||||||
font-weight: bold;
|
|
||||||
color: #333;
|
|
||||||
}
|
|
||||||
.wp-tab-panel-pagelinks {
|
|
||||||
display: none;
|
|
||||||
padding:4px 0;
|
|
||||||
margin:0 auto;
|
|
||||||
text-align:center;
|
|
||||||
}
|
|
||||||
.wp-tab-panel-pagelinks-top {
|
|
||||||
border-bottom: 1px solid #dfdfdf;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<?php
|
<?php
|
||||||
// @TODO: Support custom post types.
|
|
||||||
// $pts = get_post_types( array( 'public' => true ), 'objects' );
|
|
||||||
$pts = array( get_post_type_object( 'post' ), get_post_type_object( 'page' ) );
|
|
||||||
$queries = array(
|
|
||||||
array( 'preset' => 'all', 'label' => __('View All') ),
|
|
||||||
array( 'preset' => 'recent', 'label' => __('Most Recent') ),
|
|
||||||
array( 'preset' => 'search', 'label' => __('Search') )
|
|
||||||
);
|
|
||||||
|
|
||||||
$tb = new WP_Tab_Bar();
|
|
||||||
$tb->id = 'link-panel-tab-bar';
|
|
||||||
$tb->add( 'link-panel-id-custom', __('External Link') );
|
|
||||||
foreach( $pts as $pt ) {
|
|
||||||
$tb->add( "link-panel-id-pt-$pt->name", $pt->labels->singular_name );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<body id="post-body">
|
<body id="post-body">
|
||||||
<div id="link-header">
|
|
||||||
<?php $tb->render(); ?>
|
|
||||||
</div>
|
|
||||||
<div id="link-selector">
|
<div id="link-selector">
|
||||||
<?php
|
|
||||||
wp_link_panel_custom();
|
|
||||||
foreach( $pts as $pt )
|
|
||||||
wp_link_panel_structure('pt', $pt->name, $queries);
|
|
||||||
?>
|
|
||||||
<div id="link-options">
|
<div id="link-options">
|
||||||
|
<label for="url-field">
|
||||||
|
<span><?php _e('URL:'); ?></span><input id="url-field" type="text" />
|
||||||
|
</label>
|
||||||
<label for="link-title-field">
|
<label for="link-title-field">
|
||||||
<span><?php _e('Description:'); ?></span><input id="link-title-field" type="text" />
|
<span><?php _e('Description:'); ?></span><input id="link-title-field" type="text" />
|
||||||
</label>
|
</label>
|
||||||
|
@ -206,6 +184,40 @@ foreach( $pts as $pt ) {
|
||||||
<input type="checkbox" id="link-target-checkbox" /><span><?php _e('Open in new tab'); ?></span>
|
<input type="checkbox" id="link-target-checkbox" /><span><?php _e('Open in new tab'); ?></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="search-panel">
|
||||||
|
<label for="search-field" class="link-search-wrapper">
|
||||||
|
<span><?php _e('Search:'); ?></span>
|
||||||
|
<input type="text" id="search-field" class="link-search-field" />
|
||||||
|
<img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div id="search-results" class="query-results">
|
||||||
|
<div class="wp-results-pagelinks wp-results-pagelinks-top"></div>
|
||||||
|
<ul>
|
||||||
|
<li class="wp-results-loading unselectable"><em><?php _e('Loading...'); ?></em></li>
|
||||||
|
</ul>
|
||||||
|
<div class="wp-results-pagelinks wp-results-pagelinks-bottom"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php $most_recent = wp_link_query(); ?>
|
||||||
|
<div id="most-recent-results" class="query-results">
|
||||||
|
<div class="wp-results-pagelinks wp-results-pagelinks-top">
|
||||||
|
<?php echo $most_recent['pages']['page_links']; ?>
|
||||||
|
</div>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ( $most_recent['results'] as $item ): ?>
|
||||||
|
<li>
|
||||||
|
<input type="hidden" class="item-permalink" value="<?php echo esc_url( $item['permalink'] ); ?>" />
|
||||||
|
<span class="item-title"><?php echo $item['title']; ?></span>
|
||||||
|
<span class="item-info"><?php echo esc_html( $item['info'] ); ?></span>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<div class="wp-results-pagelinks wp-results-pagelinks-bottom">
|
||||||
|
<?php echo $most_recent['pages']['page_links']; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="submitbox">
|
<div class="submitbox">
|
||||||
<div id="wp-cancel">
|
<div id="wp-cancel">
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue