register_plugin( 'headspace', __FILE__);
if (is_admin ()) {
$this->add_action( 'admin_menu' );
$this->add_action( 'load-settings_page_headspace', 'admin_head' );
$this->add_action( 'load-post.php', 'admin_head' );
$this->add_action( 'load-post-new.php', 'admin_head' );
$this->add_action( 'add_meta_boxes' );
$this->add_action( 'save_post', 'save_tags' );
$this->add_action( 'edit_category_form' );
$this->add_action( 'edit_category' );
add_action( 'edit_term', array( &$this, 'edit_category' ) );
$this->add_action( 'init', 'init', 15);
// WP 2.7 hooks
$this->add_action( 'manage_posts_columns' );
$this->add_action( 'manage_pages_columns', 'manage_posts_columns' );
$this->add_action( 'manage_posts_custom_column', 'manage_posts_custom_column', 10, 2);
$this->add_action( 'manage_pages_custom_column', 'manage_posts_custom_column', 10, 2);
$this->register_plugin_settings( __FILE__ );
// Ajax functions
if ( defined( 'DOING_AJAX' ) ) {
include_once dirname( __FILE__ ).'/ajax.php';
$this->ajax = new HeadspaceAjax();
}
}
}
function print_scripts_array( $scripts ) {
$farb = array_search( 'farbtastic', $scripts );
if ( $farb && ( ( isset( $_GET['page'] ) && $_GET['page'] == 'headspace.php') || $this->is_page() || $this->is_post_edit() || $this->is_category_edit() ) )
unset( $scripts[$farb] );
return $scripts;
}
function plugin_settings ($links) {
$settings_link = ''.__('Settings', 'headspace').'';
array_unshift( $links, $settings_link );
return $links;
}
function manage_posts_columns($columns) {
$headspace = HeadSpace2::get ();
$settings = $headspace->get_current_settings ();
$simple = $headspace->modules->get_restricted ($headspace->get_simple_modules (), $settings, 'page' );
$advanced = $headspace->modules->get_restricted ($headspace->get_advanced_modules (), $settings, 'page' );
$modules = array_merge ($simple, $advanced);
if (count ($modules) > 0) {
foreach ($modules AS $module) {
if ($module->can_quick_edit ())
$columns[strtolower (get_class ($module))] = $module->name ();
}
}
return $columns;
}
function manage_posts_custom_column($column, $id) {
$hs2 = HeadSpace2::get ();
$meta = $hs2->get_post_settings ($id);
$module = $hs2->modules->get (array ($column), $meta);
if (count ($module) > 0)
$module[0]->quick_view ();
}
function bulk_edit_custom_box($column_name, $type) {
}
function quick_edit_custom_box($column_name, $type) {
}
function init() {
// Allow some customisation over core features
if (file_exists (dirname (__FILE__).'/settings.php'))
include dirname (__FILE__).'/settings.php';
else
{
define ('HEADSPACE_MENU', __ ('HeadSpace', 'headspace'));
define ('HEADSPACE_META', __ ('Meta-data', 'headspace'));
define ('HEADSPACE_ROLE', 'manage_options' );
}
}
function is_page() {
if (strpos ($_SERVER['REQUEST_URI'], 'page-new.php') !== false || strpos ($_SERVER['REQUEST_URI'], 'edit-page.php') !== false || strpos ($_SERVER['REQUEST_URI'], 'page.php') !== false)
return true;
return false;
}
/**
* Add HeadSpace menu
*
* @return void
**/
function admin_menu() {
if (defined ('HEADSPACE_MANAGE'))
add_management_page (HEADSPACE_MENU, HEADSPACE_MENU, HEADSPACE_ROLE, basename (__FILE__), array ($this, 'admin_screen'));
else
add_options_page (HEADSPACE_MENU, HEADSPACE_MENU, HEADSPACE_ROLE, basename (__FILE__), array ($this, 'admin_screen'));
}
/**
* Hooks into the WP category display and adds a HS meta data section
*
* @param category Category to edit
* @return void
**/
function edit_category_form($cat) {
if ( !empty( $cat ) ) {
if ( !isset( $cat->cat_ID ) ) {
if ( isset( $cat->term_id ) )
$cat->cat_ID = $cat->term_id;
else
$cat->cat_ID = 0;
}
$headspace = HeadSpace2::get ();
$settings = $headspace->get_current_settings (get_option( 'headspace_cat_'.$cat->cat_ID));
$simple = $headspace->modules->get_restricted ($headspace->get_simple_modules (), $settings, 'category' );
$advanced = $headspace->modules->get_restricted ($headspace->get_advanced_modules (), $settings, 'category' );
$this->render_admin( 'edit_category', array ('simple' => $simple, 'advanced' => $advanced));
}
}
function metabox_tags($post) {
$headspace = HeadSpace2::get ();
$settings = $headspace->get_current_settings ();
$tags = $headspace->modules->get ('hsm_tags' );
if ($tags !== false)
$this->render_admin( 'edit_page', array ('post_ID' => $post->ID));
}
function metabox($post) {
$headspace = HeadSpace2::get ();
$settings = $headspace->get_current_settings ();
$simple = $headspace->modules->get_restricted ($headspace->get_simple_modules (), $settings, 'page' );
$advanced = $headspace->modules->get_restricted ($headspace->get_advanced_modules (), $settings, 'page' );
$this->render_admin( 'page-settings-edit', array ('simple' => $simple, 'advanced' => $advanced, 'width' => 140, 'area' => 'page' ) );
}
/**
* Extract meta-data when saving a post
*
* @param int $id Post ID
* @return void
**/
function save_tags($id) {
if ( isset( $_POST['headspace'] ) ) {
$headspace = HeadSpace2::get();
$headspace->save_post_settings( $id, $headspace->extract_module_settings( $_POST, 'page' ) );
}
}
/**
* Extract HS meta data when editing a category
*
* @param int $id Category ID
* @return void
**/
function edit_category( $id ) {
if ( isset( $_POST['cat_ID'] ) || isset( $_POST['tag_ID'] ) ) {
$headspace = HeadSpace2::get();
$settings = $headspace->extract_module_settings( $_POST, 'category' );
if ( empty( $settings ) )
delete_option( 'headspace_cat_'.$id );
else
update_option( 'headspace_cat_'.$id, $settings );
}
}
function submenu($inwrap = false) {
// Decide what to do
$sub = isset ($_GET['sub']) ? $_GET['sub'] : '';
if ( !in_array( $sub, array( 'modules', 'site', 'options', 'import' ) ) )
$sub = '';
if ($inwrap == true)
$this->render_admin( 'submenu', array ('sub' => $sub));
return $sub;
}
/**
* Checks the current theme footer.php and header.php to ensure it contains the appropriate function calls* to allow HS to work. Hopefully this will reduce support questions regarding this
*/
function check_theme_files() {
$base = get_template_directory ();
$messages = array ();
if (file_exists ($base.DIRECTORY_SEPARATOR.'header.php')) {
$theme_data = implode ('', file ($base.DIRECTORY_SEPARATOR.'header.php'));
if (strpos ($theme_data, 'wp_head') === false)
$messages[] = __ ('wp_head was not found in header.php (documentation)' );
}
if (file_exists ($base.DIRECTORY_SEPARATOR.'footer.php')) {
$theme_data = implode ('', file ($base.DIRECTORY_SEPARATOR.'footer.php'));
if (strpos ($theme_data, 'wp_footer') === false)
$messages[] = __ ('wp_footer was not found in footer.php (documentation)' );
}
if (count ($messages) > 0) {
$msg = '';
foreach ($messages AS $message)
$msg .= '
There are some issues with your theme that may prevent HeadSpace functioning correctly.