';
foreach ($impressjs_meta_fields as $field) {
// get value of this field if it exists for this post
$meta = get_post_meta($post->ID, $field['id'], true);
// begin a table row with
echo '
';
switch($field['type']) {
// case items will go here
// text
/*
case 'text':
echo '
'.$field['desc'].'';
break;
*/
case 'text':
echo '
'.$field['desc'].'';
break;
// textarea
case 'textarea':
echo '
'.$field['desc'].'';
break;
// checkbox
case 'checkbox':
echo '
';
break;
// select
case 'select':
echo ' '.$field['desc'].'';
break;
// radio
case 'radio':
foreach ( $field['options'] as $option ) {
echo '
';
}
break;
// checkbox_group
case 'checkbox_group':
foreach ($field['options'] as $option) {
echo '
';
}
echo ''.$field['desc'].'';
break;
// post_list
case 'post_list':
$items = get_posts( array (
//'post_type' => $field['post_type'],
'post_type' => 'impressjsstep',
'posts_per_page' => -1
));
echo ' '.$field['desc'].'';
break;
} //end switch
echo '
';
} // end foreach
echo '
'; // end table
}
// Save the Data
function save_impressjs_meta($post_id) {
global $impressjs_meta_fields;
// verify nonce
if (!wp_verify_nonce($_POST['impressjs_meta_box_nonce'], basename(__FILE__)))
return $post_id;
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
// check permissions
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id))
return $post_id;
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
// loop through fields and save the data
foreach ($impressjs_meta_fields as $field) {
$old = get_post_meta($post_id, $field['id'], true);
$new = $_POST[$field['id']];
if ($new && $new != $old) {
update_post_meta($post_id, $field['id'], $new);
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
} // end foreach
}
add_action('save_post', 'save_impressjs_meta');
// ------------------------------------------------------------------------
// PLUGIN PREFIX:
// ------------------------------------------------------------------------
// A PREFIX IS USED TO AVOID CONFLICTS WITH EXISTING PLUGIN FUNCTION NAMES.
// WHEN CREATING A NEW PLUGIN, CHANGE THE PREFIX AND USE YOUR TEXT EDITORS
// SEARCH/REPLACE FUNCTION TO RENAME THEM ALL QUICKLY.
// ------------------------------------------------------------------------
// 'lpg_impressjs_' is a prefix
// ------------------------------------------------------------------------
// REGISTER HOOKS & CALLBACK FUNCTIONS:
// ------------------------------------------------------------------------
// HOOKS TO SETUP DEFAULT PLUGIN OPTIONS, HANDLE CLEAN-UP OF OPTIONS WHEN
// PLUGIN IS DEACTIVATED AND DELETED, INITIALISE PLUGIN, ADD OPTIONS PAGE.
// ------------------------------------------------------------------------
// Set-up Action and Filter Hooks
register_activation_hook(__FILE__, 'lpg_impressjs_add_defaults');
//register_deactivation_hook( __FILE__, 'lpg_impressjs_deactivate' );
register_uninstall_hook(__FILE__, 'lpg_impressjs_delete_plugin_options');
add_action('admin_init', 'lpg_impressjs_init' );
add_action('admin_menu', 'lpg_impressjs_add_options_page');
add_filter( 'plugin_action_links', 'lpg_impressjs_plugin_action_links', 10, 2 );
// --------------------------------------------------------------------------------------
// CALLBACK FUNCTION FOR: register_uninstall_hook(__FILE__, 'lpg_impressjs_delete_plugin_options')
// --------------------------------------------------------------------------------------
// THIS FUNCTION RUNS WHEN THE USER DEACTIVATES AND DELETES THE PLUGIN. IT SIMPLY DELETES
// THE PLUGIN OPTIONS DB ENTRY (WHICH IS AN ARRAY STORING ALL THE PLUGIN OPTIONS).
// --------------------------------------------------------------------------------------
// Delete options table entries ONLY when plugin deactivated AND deleted
function lpg_impressjs_delete_plugin_options() {
delete_option('lpg_impressjs_options');
}
// ------------------------------------------------------------------------------
// CALLBACK FUNCTION FOR: register_activation_hook(__FILE__, 'lpg_impressjs_add_defaults')
// ------------------------------------------------------------------------------
// THIS FUNCTION RUNS WHEN THE PLUGIN IS ACTIVATED. IF THERE ARE NO THEME OPTIONS
// CURRENTLY SET, OR THE USER HAS SELECTED THE CHECKBOX TO RESET OPTIONS TO THEIR
// DEFAULTS THEN THE OPTIONS ARE SET/RESET.
//
// OTHERWISE, THE PLUGIN OPTIONS REMAIN UNCHANGED.
// ------------------------------------------------------------------------------
// Define default option settings
function lpg_impressjs_add_defaults() {
$tmp = get_option('lpg_impressjs_options');
if(($tmp['chk_default_options_db']=='1')||(!is_array($tmp))) {
delete_option('lpg_impressjs_options'); // so we don't have to reset all the 'off' checkboxes too! (don't think this is needed but leave for now)
$arr = array( "textarea_one" =>"http://fonts.googleapis.com/css?family=Open+Sans:regular,semibold,italic,italicsemibold|PT+Sans:400,700,400italic,700italic|PT+Serif:400,700,400italic,700italic",
"textarea_two" => file_get_contents (plugins_url( 'css/impress-demo.css' , __FILE__ )),
"textarea_three" =>"impress.js | presentation tool based on the power of CSS3 transforms and transitions in modern browsers | by Bartek Szopka @bartaz",
"textarea_four" =>"impress.js is a presentation tool based on the power of CSS3 transforms and transitions in modern browsers and inspired by the idea behind prezi.com.",
"textarea_five" =>"Bartek Szopka",
"chk_default_options_db" => "",
"chk_default_slides_db" => ""
);
update_option('lpg_impressjs_options', $arr);
};
if(($tmp['chk_default_slides_db']=='1')||(!is_array($tmp))) {
insert_impressjs_post_test();
};
}
function lpg_impressjs_deactivate() {
//flush_rewrite_rules();
}
function insert_impressjs_post_test() {
// delete all existing posts
$args = array(
'numberposts' => 50,
'post_type' =>'impressjsstep'
);
$posts = get_posts( $args );
if (is_array($posts)) {
foreach ($posts as $post) {
// what you want to do;
wp_delete_post( $post->ID, false);
//echo "Deleted Post: ".$post->title."\r\n";
}
}
$my_post_a1 = array(
'post_title' => "Aren't you just bored with...",
'post_content' => "Aren't you just bored with all those slides-based presentations?",
'post_status' => 'draft',
'post_type' => 'impressjsstep'
);
$mypost1 = wp_insert_post($my_post_a1);
add_post_meta($mypost1, 'impressjs_sequencenumber', 10);
add_post_meta($mypost1, 'impressjs_datax', -1000);
add_post_meta($mypost1, 'impressjs_datay', -1500);
add_post_meta($mypost1, 'impressjs_id', "bored");
add_post_meta($mypost1, 'impressjs_stepsel', "step slide");
$my_post_a2 = array(
'post_title' => "...Don't you think that presentations...",
'post_content' => "Don't you think that presentations given in modern browsers shouldn't copy the limits of 'classic' slide decks?",
'post_status' => 'draft',
'post_type' => 'impressjsstep'
);
$mypost2 = wp_insert_post($my_post_a2);
add_post_meta($mypost2, 'impressjs_sequencenumber', 20);
add_post_meta($mypost2, 'impressjs_datax', 0);
add_post_meta($mypost2, 'impressjs_datay', -1500);
add_post_meta($mypost2, 'impressjs_stepsel', "step slide");
$my_post_a3 = array(
'post_title' => "...Would you like to impress your audience...",
'post_content' => "Would you like to impress your audience with stunning visualization of your talk?",
'post_status' => 'draft',
'post_type' => 'impressjsstep'
);
$mypost3 = wp_insert_post($my_post_a3);
add_post_meta($mypost3, 'impressjs_sequencenumber', 30);
add_post_meta($mypost3, 'impressjs_datax', 1000);
add_post_meta($mypost3, 'impressjs_datay', -1500);
add_post_meta($mypost3, 'impressjs_stepsel', "step slide");
$my_post_a4 = array(
'post_title' => "...then you should try impress.js...",
'post_content' => "then you should try
impress.js*
* no rhyme intended",
'post_status' => 'draft',
'post_type' => 'impressjsstep'
);
$mypost4 = wp_insert_post($my_post_a4);
add_post_meta($mypost4, 'impressjs_sequencenumber', 40);
add_post_meta($mypost4, 'impressjs_datax', '0');
add_post_meta($mypost4, 'impressjs_datay', '0');
add_post_meta($mypost4, 'impressjs_id', "title");
add_post_meta($mypost4, 'impressjs_datascale', 4);
add_post_meta($mypost4, 'impressjs_stepsel', "step");
$my_post_a5 = array(
'post_title' => "...It's a presentation tool inspired by the idea behind prezi.com...",
'post_content' => "
It's a presentation tool inspired by the idea behind prezi.com and based on the power of CSS3 transforms and transitions in modern browsers.
* beat that, prezi ;)",
'post_status' => 'draft',
'post_type' => 'impressjsstep'
);
$mypost12 = wp_insert_post($my_post_a12);
add_post_meta($mypost12, 'impressjs_sequencenumber', 120);
add_post_meta($mypost12, 'impressjs_datax', 6200);
add_post_meta($mypost12, 'impressjs_datay', 4300);
add_post_meta($mypost12, 'impressjs_dataz', -100);
add_post_meta($mypost12, 'impressjs_datarotatex', -40);
add_post_meta($mypost12, 'impressjs_datarotatey', 10);
add_post_meta($mypost12, 'impressjs_id', "its-in-3d");
add_post_meta($mypost12, 'impressjs_datascale', 2);
add_post_meta($mypost12, 'impressjs_stepsel', "step");
$my_post_a13 = array(
'post_title' => "...",
'post_content' => "",
'post_status' => 'draft',
'post_type' => 'impressjsstep'
);
$mypost13 = wp_insert_post($my_post_a13);
add_post_meta($mypost13, 'impressjs_sequencenumber', 130);
add_post_meta($mypost13, 'impressjs_datax', 3000);
add_post_meta($mypost13, 'impressjs_datay', 1500);
add_post_meta($mypost13, 'impressjs_datascale', 10);
add_post_meta($mypost13, 'impressjs_id', "overview");
add_post_meta($mypost13, 'impressjs_stepsel', "step");
}
// ------------------------------------------------------------------------------
// CALLBACK FUNCTION FOR: add_action('admin_init', 'lpg_impressjs_init' )
// ------------------------------------------------------------------------------
// THIS FUNCTION RUNS WHEN THE 'admin_init' HOOK FIRES, AND REGISTERS YOUR PLUGIN
// SETTING WITH THE WORDPRESS SETTINGS API. YOU WON'T BE ABLE TO USE THE SETTINGS
// API UNTIL YOU DO.
// ------------------------------------------------------------------------------
// Init plugin options to white list our options
function lpg_impressjs_init(){
register_setting( 'lpg_impressjs_plugin_options', 'lpg_impressjs_options', 'lpg_impressjs_validate_options' );
}
// ------------------------------------------------------------------------------
// CALLBACK FUNCTION FOR: add_action('admin_menu', 'lpg_impressjs_add_options_page');
// ------------------------------------------------------------------------------
// THIS FUNCTION RUNS WHEN THE 'admin_menu' HOOK FIRES, AND ADDS A NEW OPTIONS
// PAGE FOR YOUR PLUGIN TO THE SETTINGS MENU.
// ------------------------------------------------------------------------------
// Add menu page
function lpg_impressjs_add_options_page() {
add_options_page('3D Presentation Options Page', '3D Presentation', 'manage_options', __FILE__, 'lpg_impressjs_render_form');
}
// ------------------------------------------------------------------------------
// CALLBACK FUNCTION SPECIFIED IN: add_options_page()
// ------------------------------------------------------------------------------
// THIS FUNCTION IS SPECIFIED IN add_options_page() AS THE CALLBACK FUNCTION THAT
// ACTUALLY RENDER THE PLUGIN OPTIONS FORM AS A SUB-MENU UNDER THE EXISTING
// SETTINGS ADMIN MENU.
// ------------------------------------------------------------------------------
// Render the Plugin options form
function lpg_impressjs_render_form() {
?>
3D Presentation Options Page
Please use the configuration parameters below to set up 3D Presentation options.
'.__('Settings').'';
// make the 'Settings' link appear first
array_unshift( $links, $lpg_impressjs_links );
}
return $links;
}
add_filter( 'manage_edit-impressjsstep_columns', 'my_edit_impressjsstep_columns' ) ;
function my_edit_impressjsstep_columns ( $columns ) {
$columns = array(
'cb' => '',
'impressjs_sequencenumber' => __( 'Sequence Number' ),
'title' => __( 'Step Title' ),
'impressjs_id' => __( 'id' ),
'impressjs_datax' => __( 'x' ),
'impressjs_datay' => __( 'y' ),
'impressjs_dataz' => __( 'z' ),
'impressjs_datascale' => __( 'scale' )
);
return $columns;
}
add_action( 'manage_impressjsstep_posts_custom_column', 'my_manage_impressjsstep_columns', 10, 2 );
function my_manage_impressjsstep_columns( $column, $post_id ) {
global $post;
switch( $column ) {
/* If displaying the 'sequencenumber' column. */
case 'impressjs_sequencenumber' :
/* Get the post meta. */
$sequencenumber = get_post_meta( $post->ID, 'impressjs_sequencenumber', true );
/* If no sequencenumber is found, output a default message. */
if ( empty( $sequencenumber ) )
echo __('Unknown');
/* If there is a duration, append 'minutes' to the text string. */
else
//printf( __( '' ), $sequencenumber );
echo __($sequencenumber);
break;
case 'impressjs_id' :
$idd = get_post_meta( $post->ID, 'impressjs_id', true );
if ( empty( $idd ) )
echo __('');
else
echo __($idd);
break;
case 'impressjs_datax' :
$cx = get_post_meta( $post->ID, 'impressjs_datax', true );
if ( empty( $cx ) )
echo __('');
else
echo __($cx);
break;
case 'impressjs_datay' :
$cy = get_post_meta( $post->ID, 'impressjs_datay', true );
if ( empty( $cy ) )
echo __('');
else
echo __($cy);
break;
case 'impressjs_dataz' :
$cz = get_post_meta( $post->ID, 'impressjs_dataz', true );
if ( empty( $cz ) )
echo __('');
else
echo __($cz);
break;
case 'impressjs_datascale' :
$cscale = get_post_meta( $post->ID, 'impressjs_datascale', true );
if ( empty( $cscale ) )
echo __('');
else
echo __($cscale);
break;
/* Just break out of the switch statement for everything else. */
default :
break;
}
}
add_filter( 'manage_edit-impressjsstep_sortable_columns', 'my_impressjsstep_sortable_columns' );
function my_impressjsstep_sortable_columns( $columns ) {
$columns['impressjs_sequencenumber'] = 'impressjs_sequencenumber';
return $columns;
}
/* Only run our customization on the 'edit.php' page in the admin. */
add_action( 'load-edit.php', 'my_edit_impressjsstep_load' );
function my_edit_impressjsstep_load() {
add_filter( 'request', 'my_sort_impressjssteps' );
}
/* Sorts the movies. */
function my_sort_impressjssteps( $vars ) {
/* Check if we're viewing the 'impressjsstep' post type. */
if ( isset( $vars['post_type'] ) && 'impressjsstep' == $vars['post_type'] ) {
/* Check if 'orderby' is set to 'sequencenumber'. */
//if ( isset( $vars['orderby'] ) && 'impressjs_sequencenumber' == $vars['orderby'] ) {
/* Merge the query vars with our custom variables. */
$vars = array_merge(
$vars,
array(
'meta_key' => 'impressjs_sequencenumber',
'orderby' => 'meta_value_num',
'order' => 'ASC'
)
);
//}
}
return $vars;
}
/*
add_action("template_redirect", 'my_theme_redirect');
function my_theme_redirect() {
global $wp;
$plugindir = dirname( __FILE__ );
//A Specific Custom Post Type
if ($wp->query_vars["post_type"] == 'impressjsslide') {
$templatefilename = 'single-impressjsstep.php';
if (file_exists(TEMPLATEPATH . '/' . $templatefilename)) {
$return_template = TEMPLATEPATH . '/' . $templatefilename;
} else {
$return_template = $plugindir . '/' . $templatefilename;
}
do_theme_redirect($return_template);
}
}
function do_theme_redirect($url) {
global $post, $wp_query;
if (have_posts()) {
include($url);
die();
} else {
$wp_query->is_404 = true;
}
}
*/
function get_step_post_type_template($single_template) {
global $post;
if ($post->post_type == 'impressjsstep') {
$single_template = dirname( __FILE__ ) . '/single-impressjsstep.php';
}
return $single_template;
}
add_filter( "single_template", "get_step_post_type_template" ) ;
add_action('admin_enqueue_scripts', 'add_my_js');
function add_my_js(){
wp_enqueue_script('my_validate', plugins_url( '/js/jquery.validate.js' , __FILE__ ), array('jquery'));
wp_enqueue_script('my_script_js', plugins_url( '/js/myvalidate.js'));
}
?>