Skip to content

Instantly share code, notes, and snippets.

@ajmorris
Created November 29, 2010 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajmorris/720586 to your computer and use it in GitHub Desktop.
Save ajmorris/720586 to your computer and use it in GitHub Desktop.
<?
/*
Plugin Name: Headway Skin: OnDemand Skin
Plugin URI: http://press75.com
Description: This is a port of the theme OnDemand from Press75
Author: AJ Morris
Version: 1.0
Author URI: http://ajmorris.org
*/
function register_ondemand_skin(){
//Makes the instance of the skin a global variable so you can call it later in other functions.
global $ondemand_skin;
//Options that the skin will force on the visual editor.
$options = array(
);
//Register the skin. The first argument is the ID of the skin, the second is the name.
if(class_exists('HeadwaySkin'))
$ondeamnd_skin = new HeadwaySkin('ondemand', 'On Demand Skin', __FILE__, $options);
if ( !class_exists( 'HeadwaySkin' ) && $ondemand_skin->is_active() ) {
//Run custom functions here
sve_check();
function sve_check() {
if (!function_exists('p75GetVideo')) {
add_thickbox(); // Require for the plugin install dialog.
add_action('admin_notices', 'sve_check_notice');
}
}
// The Admin Notice.
function sve_check_notice()
{
?>
<div class='updated fade'>
<p>The Simple Video Embedder plugin is required for this skin to function properly. <a href="<?php echo admin_url('plugin-install.php?tab=plugin-information&plugin=simple-video-embedder&TB_iframe=true&width=640&height=517'); ?>" class="thickbox onclick">Install now</a>.</p>
</div>
<?php
}
sf_ondemand_admin();
}
}
add_action('init', 'register_ondemand_skin');
// Add RSS Feed Links
add_theme_support('automatic-feed-links');
// Skin Location
define('THEME', get_bloginfo('wpurl'), true);
// Skin Prefix
define('SKIN_PREFIX', '/wp-content/plugins/ondemand-skin', true);
function load_skin_js(){
if (is_admin()) return;
wp_enqueue_script('jquery');
wp_enqueue_script('superfish', THEME . '/wp-content/plugins/ondemand-skin/scripts/jquery.superfish.js');
wp_enqueue_script('easing', THEME . '/wp-content/plugins/ondemand-skin/scripts/jquery.easing.js', 'jquery');
wp_enqueue_script('coda', THEME . '/wp-content/plugins/ondemand-skin/scripts/jquery.float.js', 'jquery');
wp_enqueue_script('equal', THEME . '/wp-content/plugins/ondemand-skin/scripts/jquery.equal.js', 'jquery');
wp_enqueue_script('fancybox', THEME . '/wp-content/plugins/ondemand-skin/scripts/fancybox/style.css');
wp_enqueue_script('fancybox', THEME . '/wp-content/plugins/ondemand-skin/scripts/fancybox/jquery.fancybox.js', 'jquery');
}
add_action('init', load_skin_js);
/* Check for Simple Video Embedder */
// Include Custom Skin Widgets
include("widgets/cat-posts.php");
include("widgets/simple-sidebar-ads.php");
// // The Admin Page
// add_action('admin_menu', 'sf_ondemand_admin_init');
//
// // Register Admin
// function sf_ondemand_admin_init()
// {
// $page = add_theme_page( "On Demand Options", "Theme Options", 8, 'sf_ondemand_admin_menu', 'sf_ondemand_admin');
//
// // Custom Image Uploaders
// od_add_image_upload_filter(SKIN_PREFIX, 'background_img', 'od_handle_bg_upload');
// od_add_image_upload_filter(SKIN_PREFIX, 'header_img', 'od_handle_header_upload');
// }
function sf_ondemand_admin() {
$option_fields = array();
if ( $_GET['updated'] ) echo '<div id="message" class="updated fade"><p>On Demand Theme Options Saved.</p></div>';
echo '<link rel="stylesheet" href="'.get_bloginfo('template_url').'/functions.css" type="text/css" media="all" />';
// Accordion Script
echo '<link rel="stylesheet" href="'.get_bloginfo('template_url').'/scripts/accordion/style.css" type="text/css" media="all" />';
echo '<script src="'.get_bloginfo('template_url').'/scripts/accordion/jquery.ui.js" type="text/javascript"></script>';
echo '<script src="'.get_bloginfo('template_url').'/scripts/accordion/jquery.accordion.js" type="text/javascript"></script>';
// Color Picker Script
echo '<link rel="stylesheet" href="'.get_bloginfo('template_url').'/scripts/colorpicker/style.css" type="text/css" media="all" />';
echo '<script src="'.get_bloginfo('template_url').'/scripts/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
echo '<script src="'.get_bloginfo('template_url').'/scripts/colorpicker/jquery.eye.js" type="text/javascript"></script>';
// Styling File Form Elements
echo '<script src="'.get_bloginfo('template_url').'/scripts/si.files.js" type="text/javascript"></script>';
?>
<div class="wrap">
<div id="icon-options-general" class="icon32"><br/></div>
<h2>On Demand Theme Options</h2>
<div class="metabox-holder">
<form method="post" action="options.php" enctype="multipart/form-data">
<div id="theme-options">
<div id="accordion" class="postbox-container">
<?php
include("options/custom-logo.php");
include("options/custom-favicon.php");
include("options/navigation-options.php");
include("options/custom-background.php");
include("options/text-link-colors.php");
include("options/featured-content.php");
include("options/featured-categories.php");
include("options/header-advertisement.php");
include("options/instant-view.php");
include("options/footer-text.php");
include("options/analytics-code.php");
include("options/save-the-web.php");
?>
</div> <!-- postbox-container -->
</div> <!-- theme-options -->
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="<?php echo implode(",", $option_fields); ?>" />
</form>
<script type="text/javascript" language="javascript">SI.Files.stylizeAll();</script>
</div> <!-- metabox-holder -->
</div> <!-- wrap -->
<?php
}
// Image Upload Helper Function
function ok_add_img_upload_filter($option_name, $handler) {
add_filter('pre_update_option_'.$option_name, $handler, 10, 2);
}
// Image Uploader Handles Functions
function od_handle_bg_upload($new_value, $old_value) {
return od_handle_img_upload(
$new_value,
$old_value,
SKIN_PREFIX.'background_img_upload',
SKIN_PREFIX.'delete_bg_img');
}
function od_handle_header_upload($new_value, $old_value){
return od_handle_img_upload(
$new_value,
$old_value,
SKIN_PREFIX.'header_img_upload',
SKIN_PREFIX.'delete_header_img');
}
// Generic Image Upload Handler
function od_handle_img_upload($new_value, $old_value, $file_index, $delete_field) {
if ( isset($_POST[$delete_filed]) && $_POST[$delete_field]=='true' )
return '';
if ( empty($_FILES) || !isset($_FILES[$file_index]) || 0==$_FILES[$file_index]['size'] )
return $old_value;
$override = array('test_form' => faluse);
$file = wp_handle_upload($_FILES[$file_index], $overrides);
if ( isset($file['error']) )
wp_die( $file['error']);
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
$filename = basename($file);
// Construct the Object Array
$object = array(
'post_title' => $filename,
'post_content' => $url,
'post_mime_type' => $type,
'guid' => $url
);
// Save the Data
$id = wp_insert_attachment($object, $file);
// Add the Meta
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file) );
do_action('wp_create_file_in_uploads', $file, $id); // For replication
return esc_url($url);
}
// Custom Excertp Length
function new_excerpt_length($length) {
return 50;
}
add_filter('excerpt_length', 'new_excerpt_length');
function new_excerpt_more($more) {
return ' ...';
}
add_filter('excerpt_more', 'new_excerpt_more');
// Custom Pagination Function
function sf_pagenavi($before = '', $after = '', $prelabel = '', $nxtlabel = '', $pages_to_show = 5, $always_show = false) {
global $request, $posts_per_page, $wpdb, $paged;
if(empty($prelabel)) { $prelabel = '';
} if(empty($nxtlabel)) {
$nxtlabel = '';
} $half_pages_to_show = round($pages_to_show/2);
if (!is_single()) {
if(!is_category()) {
preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches); } else {
preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches); }
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
$max_page = ceil($numposts /$posts_per_page);
if(empty($paged)) {
$paged = 1;
}
if($max_page > 1 || $always_show) {
echo "$before <div id='paginate'>Pages ... "; if ($paged >= ($pages_to_show-1)) {
echo ''; }
previous_posts_link($prelabel);
for($i = $paged - $half_pages_to_show; $i <= $paged + $half_pages_to_show; $i++) { if ($i >= 1 && $i <= $max_page) { if($i == $paged) {
echo "$i";
} else {
echo ' <a href="'.get_pagenum_link($i).'">'.$i.'</a> '; }
}
}
next_posts_link($nxtlabel, $max_page);
if (($paged+$half_pages_to_show) < ($max_page)) {
echo ''; }
echo "</div> $after";
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment