Skip to content

Commit

Permalink
Merge branch 'release/1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkingorg committed Mar 20, 2012
2 parents 086d544 + b9a2341 commit dc6f31e
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 63 deletions.
75 changes: 59 additions & 16 deletions cf-post-formats.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
Plugin Name: CF Post Formats
Plugin URI: http://crowdfavorite.com
Description: Custom post format admin screens
Version: 1.0dev
Version: 1.0
Author: crowdfavorite
Author URI: http://crowdfavorite.com
*/

/**
* Copyright (c) 2011 Crowd Favorite, Ltd. All rights reserved.
* Copyright (c) 2011-2012 Crowd Favorite, Ltd. All rights reserved.
*
* Released under the GPL license
* http://www.opensource.org/licenses/gpl-license.php
Expand All @@ -30,12 +30,36 @@
* **********************************************************************
*/

define('CFPF_VERSION', '0.2');
if (!defined('CFPF_VERSION')) {

define('CFPF_VERSION', '1.0');

function cfpf_base_url() {
return trailingslashit(apply_filters('cfpf_base_url', plugins_url('', __FILE__)));
}

function cfpf_admin_init() {
$post_formats = get_theme_support('post-formats');
if (!empty($post_formats[0]) && is_array($post_formats[0])) {
if (in_array('link', $post_formats[0])) {
add_action('save_post', 'cfpf_format_link_save_post');
}
if (in_array('status', $post_formats[0])) {
add_action('save_post', 'cfpf_format_status_save_post', 10, 2);
}
if (in_array('quote', $post_formats[0])) {
add_action('save_post', 'cfpf_format_quote_save_post', 10, 2);
}
if (in_array('video', $post_formats[0])) {
add_action('save_post', 'cfpf_format_video_save_post');
}
if (in_array('audio', $post_formats[0])) {
add_action('save_post', 'cfpf_format_audio_save_post');
}
}
}
add_action('admin_init', 'cfpf_admin_init');

// we aren't really adding meta boxes here,
// but this gives us the info we need to get our stuff in.
function cfpf_add_meta_boxes($post_type) {
Expand All @@ -53,7 +77,6 @@ function cfpf_add_meta_boxes($post_type) {
)
);

// actions
add_action('edit_form_advanced', 'cfpf_post_admin_setup');
}
}
Expand All @@ -78,15 +101,23 @@ function cfpf_post_admin_setup() {
if (!empty($current_post_format) && !in_array($current_post_format, $post_formats[0])) {
array_push($post_formats[0], get_post_format_string($current_post_format));
}

array_unshift($post_formats[0], 'standard');

$post_formats = $post_formats[0];

include('views/tabs.php');
include('views/format-link.php');
include('views/format-quote.php');
include('views/format-video.php');
include('views/format-gallery.php');

$format_views = array(
'link',
'quote',
'video',
'gallery',
'audio',
);
foreach ($format_views as $format) {
if (in_array($format, $post_formats)) {
include('views/format-'.$format.'.php');
}
}
}
}

Expand All @@ -95,7 +126,7 @@ function cfpf_format_link_save_post($post_id) {
update_post_meta($post_id, '_format_link_url', $_POST['_format_link_url']);
}
}
add_action('save_post', 'cfpf_format_link_save_post');
// action added in cfpf_admin_init()

function cfpf_format_auto_title_post($post_id, $post) {
remove_action('save_post', 'cfpf_format_status_save_post', 10, 2);
Expand All @@ -121,7 +152,7 @@ function cfpf_format_status_save_post($post_id, $post) {
cfpf_format_auto_title_post($post_id, $post);
}
}
add_action('save_post', 'cfpf_format_status_save_post', 10, 2);
// action added in cfpf_admin_init()

function cfpf_format_quote_save_post($post_id, $post) {
if (!defined('XMLRPC_REQUEST')) {
Expand All @@ -139,18 +170,28 @@ function cfpf_format_quote_save_post($post_id, $post) {
cfpf_format_auto_title_post($post_id, $post);
}
}
add_action('save_post', 'cfpf_format_quote_save_post', 10, 2);
// action added in cfpf_admin_init()

function cfpf_format_video_save_post($post_id) {
if (!defined('XMLRPC_REQUEST') && isset($_POST['_format_video_embed'])) {
update_post_meta($post_id, '_format_video_embed', $_POST['_format_video_embed']);
}
}
add_action('save_post', 'cfpf_format_video_save_post');
// action added in cfpf_admin_init()

function cfpf_format_audio_save_post($post_id) {
if (!defined('XMLRPC_REQUEST') && isset($_POST['_format_audio_embed'])) {
update_post_meta($post_id, '_format_audio_embed', $_POST['_format_audio_embed']);
}
}
// action added in cfpf_admin_init()

function cfpf_gallery_preview() {
if (empty($_POST['id']) || !($post_id = intval($_POST['id']))) {
exit;
}
global $post;
$post->ID = intval($_POST['id']);
$post->ID = $post_id;
ob_start();
include('views/format-gallery.php');
$html = ob_get_clean();
Expand Down Expand Up @@ -185,4 +226,6 @@ function cfpf_pre_ping_post_links($post_links, $post_id) {
}
return $post_links;
}
add_filter('pre_ping_post_links', 'cfpf_pre_ping_post_links', 10, 2);
add_filter('pre_ping_post_links', 'cfpf_pre_ping_post_links', 10, 2);

} // end defined check
47 changes: 23 additions & 24 deletions css/admin.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#formatdiv, /* hide default radio button UI */
#titlewrap {
display: none;
Expand All @@ -12,11 +11,11 @@
.clearfix { zoom: 1; }


.cp-elm-block {
.cf-elm-block {
font-family: "Lucida Grande", Verdana, Arial, "Bitstream Vera Sans", sans-serif;
margin-bottom: 18px;
}
.cp-elm-block label {
.cf-elm-block label {
color: #666;
display: block;
font: italic normal 12px Georgia, Serif;
Expand All @@ -25,10 +24,10 @@
text-transform: uppercase;
text-shadow: 0 1px 1px #fff;
}
.cp-elm-block input[type="text"],
.cp-elm-block textarea,
.cp-elm-block select,
.cp-elm-block .cp-elm-container {
.cf-elm-block input[type="text"],
.cf-elm-block textarea,
.cf-elm-block select,
.cf-elm-block .cf-elm-container {
-moz-border-radius: 6px; /* FF1+ */
-webkit-border-radius: 6px; /* Saf3+, Chrome */
-khtml-border-radius: 6px; /* Konqueror */
Expand All @@ -37,50 +36,51 @@
border: 1px #dfdfdf solid;
font-family: "Lucida Grande", Verdana, Arial, "Bitstream Vera Sans", sans-serif;
}
.cp-elm-block input[type="text"],
.cp-elm-block textarea {
.cf-elm-block input[type="text"],
.cf-elm-block textarea {
font-size: 18px;
width: 100%;
}
.cp-elm-block textarea {
.cf-elm-block textarea {
height: 161px;
padding: 8px 11px;
}
.cp-elm-block input[type="text"] {
.cf-elm-block input[type="text"] {
padding: 5px 8px;
}
.cp-elm-block .description {
.cf-elm-block .description {
color: #999;
display: block;
font-size: 11px;
line-height: 1.6;
padding-left: 8px;
}
.cp-elm-block .cp-elm-source {
.cf-elm-block .cf-elm-source {
height: 96px;
}
.cp-elm-block .cp-elm-container {
.cf-elm-block .cf-elm-container {
background: #f0f0f0;
padding: 10px;
}
.cp-elm-block .cp-elm-container p.none {
.cf-elm-block .cf-elm-container p.none {
text-align: center;
}
.cp-elm-block .cp-elm-image-gallery {
.cf-elm-block .cf-elm-image-gallery {
margin: 0 0 -5px 0;
padding: 0;
}
.cp-elm-block .cp-elm-container .gallery {
.cf-elm-block .cf-elm-container .gallery {
margin: 0;
padding-bottom: 8px;
}
.cp-elm-block .cp-elm-container .gallery dl,
.cp-elm-block .cp-elm-container .gallery dt {
display: inline;
}
.cp-elm-block .cp-elm-image-gallery dt {
margin: 0 5px 5px 0;
.cf-elm-block .cf-elm-container .gallery li {
display: inline-block;
margin: 0 8px 8px 0;
padding: 0;
}
.cf-elm-block .cf-elm-container .gallery li img {
vertical-align: middle;
}

/* Video Field */
#cfpf-format-video-embed {
Expand All @@ -91,7 +91,6 @@
-------------------------------------------------- */
.cf-nav {
border-bottom: 1px solid #ccc;
float: left;
margin: 10px 0 20px 0;
width: 100%;
}
Expand Down
44 changes: 28 additions & 16 deletions js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ jQuery(function($) {
}
},

switchWPFormat: function(format_hash) {
$(format_hash).trigger('click');
switch (format_hash) {
switchWPFormat: function(formatHash) {
$(formatHash).trigger('click');
switch (formatHash) {
case '#post-format-0':
case '#post-format-aside':
case '#post-format-chat':
CF.postFormats.standard();
break;
case '#post-format-status':
Expand All @@ -26,36 +28,38 @@ jQuery(function($) {
case '#post-format-gallery':
case '#post-format-video':
case '#post-format-quote':
eval('CF.postFormats.' + format_hash.replace('#post-format-', '') + '();');
case '#post-format-audio':
CF.postFormats[formatHash.replace('#post-format-', '')]();
}
$(document).trigger('cf-post-formats-switch', formatHash);
},

standard: function() {
$('#cfpf-format-link-url, #cfpf-format-quote-fields, #cfpf-format-video-fields, #cfpf-format-gallery-preview').hide();
$('#cfpf-format-link-url, #cfpf-format-quote-fields, #cfpf-format-video-fields, #cfpf-format-audio-fields, #cfpf-format-gallery-preview').hide();
$('#titlewrap').show();
$('#postimagediv-placeholder').replaceWith($('#postimagediv'));
},

status: function() {
$('#titlewrap, #cfpf-format-link-url, #cfpf-format-quote-fields, #cfpf-format-video-fields, #cfpf-format-gallery-preview').hide();
$('#titlewrap, #cfpf-format-link-url, #cfpf-format-quote-fields, #cfpf-format-video-fields, #cfpf-format-audio-fields, #cfpf-format-gallery-preview').hide();
$('#postimagediv-placeholder').replaceWith($('#postimagediv'));
$('#content:visible').focus();
},

link: function() {
$('#cfpf-format-quote-field, #cfpf-format-video-fields, #cfpf-format-gallery-previews').hide();
$('#cfpf-format-quote-field, #cfpf-format-video-fields, #cfpf-format-audio-fields, #cfpf-format-gallery-preview').hide();
$('#titlewrap, #cfpf-format-link-url').show();
$('#postimagediv-placeholder').replaceWith($('#postimagediv'));
},

image: function() {
$('#cfpf-format-link-url, #cfpf-format-quote-fields, #cfpf-format-video-fields, #cfpf-format-gallery-preview').hide();
$('#cfpf-format-link-url, #cfpf-format-quote-fields, #cfpf-format-video-fields, #cfpf-format-audio-fields, #cfpf-format-gallery-preview').hide();
$('#titlewrap').show();
$('#postimagediv').after('<div id="postimagediv-placeholder"></div>').insertAfter('#titlediv');
},

gallery: function() {
$('#cfpf-format-link-url, #cfpf-format-quote-fields, #cfpf-format-video-fields').hide();
$('#cfpf-format-link-url, #cfpf-format-quote-fields, #cfpf-format-video-fields, #cfpf-format-audio-fields').hide();
$('#titlewrap, #cfpf-format-gallery-preview').show();
$('#postimagediv-placeholder').replaceWith($('#postimagediv'));
},
Expand All @@ -67,22 +71,30 @@ jQuery(function($) {
},

quote: function() {
$('#titlewrap, #cfpf-format-link-url, #cfpf-format-video-fields, #cfpf-format-gallery-preview').hide();
$('#titlewrap, #cfpf-format-link-url, #cfpf-format-video-fields, #cfpf-format-audio-fields, #cfpf-format-gallery-preview').hide();
$('#cfpf-format-quote-fields').show().find(':input:first').focus();
$('#postimagediv-placeholder').replaceWith($('#postimagediv'));
},

audio: function() {
$('#cfpf-format-link-url, #cfpf-format-quote-fields, #cfpf-format-video-fields, #cfpf-format-gallery-preview').hide();
$('#titlewrap, #cfpf-format-audio-fields').show();
$('#postimagediv-placeholder').replaceWith($('#postimagediv'));
}

};
}(jQuery);

// move tabs in to place
$('#cf-post-format-tabs').insertBefore($('form#post')).show();
$('#cfpf-format-link-url').insertAfter($('#titlediv'));
$('#cfpf-format-video-fields').insertAfter($('#titlediv'));
$('#cfpf-format-link-url, #cfpf-format-video-fields, #cfpf-format-audio-fields').insertAfter($('#titlediv'));
$('#cfpf-format-gallery-preview').find('dt a').each(function() {
$(this).replaceWith($(this.childNodes)); // remove links
}).end().insertAfter($('#titlediv'));
$('#cfpf-format-quote-fields').insertAfter($('#titlediv'));

$(document).trigger('cf-post-formats-init');

// tab switch
$('#cf-post-format-tabs a').live('click', function(e) {
CF.postFormats.switchTab(this);
Expand All @@ -93,13 +105,13 @@ jQuery(function($) {
});

// refresh gallery on lightbox close
$('#TB_window').live('unload', function() {
$('#TB_window').live('tb_unload unload', function() {
if (!$('#cfpf-format-gallery-preview').is(':visible')) {
return;
}
var $preview = $('#cfpf-format-gallery-preview');
// spinner
$preview.find('.cp-elm-container').html('<p><img src="' + cfpf_post_format.wpspin_light + '" alt="' + cfpf_post_format.loading + '" /></p>');
$preview.find('.cf-elm-container').html('<p><img src="' + cfpf_post_format.wpspin_light + '" alt="' + cfpf_post_format.loading + '" /></p>');
// AJAX call for gallery snippet
$.post(
ajaxurl,
Expand All @@ -119,8 +131,8 @@ jQuery(function($) {
});

$('#cfpf-format-gallery-preview .none a').live('click', function(e) {
$('#add_image, #content-add_media').click();
$('#add_image, #content-add_media').mousedown().mouseup().click();
e.preventDefault();
});

});
});
4 changes: 4 additions & 0 deletions views/format-audio.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="cf-elm-block" id="cfpf-format-audio-fields" style="display: none;">
<label for="cfpf-format-audio-embed"><?php _e('Audio URL (oEmbed) or Embed Code', 'cf-post-format'); ?></label>
<textarea name="_format_audio_embed" id="cfpf-format-audio-embed" tabindex="1"><?php echo esc_textarea(get_post_meta($post->ID, '_format_audio_embed', true)); ?></textarea>
</div>
Loading

0 comments on commit dc6f31e

Please sign in to comment.