Skip to content

Instantly share code, notes, and snippets.

@franz-josef-kaiser
Created February 27, 2011 16:39
Show Gist options
  • Save franz-josef-kaiser/846312 to your computer and use it in GitHub Desktop.
Save franz-josef-kaiser/846312 to your computer and use it in GitHub Desktop.
The WordPress Help Plugin. First version of the [wpd hackers] first baby.
[post]
name = "Test Headline Post"
id = "_testid_post"
content = "
Zwei flinke Boxer jagen die quirlige Eva und ihren Mops durch Sylt. Franz jagt im komplett
verwahrlosten Taxi quer durch Bayern. Zwölf Boxkämpfer jagen Viktor quer über den großen Sylter
Deich. Vogel Quax zwickt Johnys Pferd Bim. Sylvia wagt quick den Jux bei Pforzheim. Polyfon
zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark. "Fix, Schwyz! " quäkt Jürgen blöd
vom Paß. Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich. Falsches Üben von
Xylophonmusik quält jeden größeren Zwerg. Heizölrückstoßabdämpfung.
"
[page]
name = "Test Headline Page"
id = "_testid_page"
content = "
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam
et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
takimata sanctus est Lorem ipsum dolor sit amet.
"
<?xml version="1.0" encoding="utf-8" ?>
<!-- test file -->
<help_context>
<screen_a>
<object>post</object>
<name>testname a</name>
<id>_testid_post</id>
<bool>true</bool>
<text>This is a help-text</text>
<content>
Zwei flinke Boxer jagen die quirlige Eva und ihren Mops durch Sylt. Franz jagt im komplett
verwahrlosten Taxi quer durch Bayern. Zwölf Boxkämpfer jagen Viktor quer über den großen Sylter
Deich. Vogel Quax zwickt Johnys Pferd Bim. Sylvia wagt quick den Jux bei Pforzheim. Polyfon
zwitschernd aßen Mäxchens Vögel Rüben, Joghurt und Quark. "Fix, Schwyz! " quäkt Jürgen blöd
vom Paß. Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich. Falsches Üben von
Xylophonmusik quält jeden größeren Zwerg. Heizölrückstoßabdämpfung.
</content>
</screen_a>
<screen_b>
<object>page</object>
<extends>post</extends>
<name>testname b</name>
<id>_testid_page</id>
<content>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam
et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
takimata sanctus est Lorem ipsum dolor sit amet.
</content>
</screen_b>
</help_context>
<?php
/*
Plugin Name: [wpd hackers] Help
Plugin URI: http://wordpress.org/extend/plugins/___/
Description: Offers help that was missing until... today.
Author: Thomas Scholz (toscho), Franz Josef Kaiser, Ralf Albert, ___
Author URI: http://___
Version: 0.1.1
License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
Text Domain: wpd_hackers_help
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Idea by Thomas Scholz a.k.a. toscho
* @link http://toscho.de/
*
* Changelog:
* v0.1
* + first version
* v0.1.1
* + added support for xml as alternate to ini file
*/
// SECURE
if ( !class_exists('WP') )
{
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
if ( !class_exists('wpdHackersHelp') )
{
class wpdHackersHelp
{
private $ini_file;
private $ini_content;
private $ini_args;
private $xml_file;
private $xml_content;
private $xml_args;
public function __construct()
{
/**
* INI FILE
* Inside a subdirectory & named according to WPLANG definition:
* @example: /de_DE/, /en_EN/
*/
$this->ini_file = 'help.ini';
$this->ini_file = plugins_url( '/wpd-hackers-help/'.WPLANG.'/'.$this->ini_file, dirname(__FILE__) );
$this->get_ini_contents( $this->ini_file );
/**
* XML FILE
* Enter description here ...
* @var unknown_type
*/
$this->xml_file = 'help.xml';
$this->xml_file = plugins_url( '/wpd-hackers-help/'.WPLANG.'/'.$this->xml_file, dirname(__FILE__) );
$this->get_xml_contents( $this->xml_file );
if ( is_admin() ) :
add_action( 'contextual_help', array(&$this, 'add_ini_help'), 1 );
add_action( 'contextual_help', array(&$this, 'add_xml_help'), 1 );
endif;
}
/**
* Output contextual help for admin ui screen
*
* @uses get_current_screen
* Available from $current_screen object:
* $current_screen->id (string)
* $current_screen->base (string)
* $current_screen->action (string)
* $current_screen->post_type (string)
* $current_screen->is_network (boolean)
* $current_screen->is_user (boolean)
* $current_screen->parent_file (string) filename.php
* $current_screen->parent_base (string)
*
* @param string $output
*/
public function add_ini_help( $args = array('headline' => null, 'content' => null) )
{
$current_screen = get_current_screen();
$args = $this->ini_content;
foreach ( $args as $screen => $content ) :
if ( $content['headline'] == null && $content['content'] == null )
return;
if ( $current_screen->id == $screen ) :
$output .= '<h3>'.$content['name'].'</h3>';
$output .= '<p id="'.$content['id'].'">'.$content['content'].'</p>';
endif;
endforeach;
return print $output;
}
public function add_xml_help( $xml_file )
{
$current_screen = get_current_screen();
$args = $this->xml_content;
foreach ( $args as $screen => $content ) :
foreach ( $content as $type => $data ) :
if ( $type == 'object' && $data == $current_screen->id ) :
$output .= '<h3>'.$content['name'].'</h3>';
$output .= '<p id="'.$content['id'].'">'.$content['content'].'</p>';
endif;
endforeach;
endforeach;
return print $output;
}
# ======================= XML FILE PARSER ======================= #
private function get_xml_contents( $xml_file )
{
$data = simplexml_load_file( $xml_file );
$this->xml_content = $data;
$args = $this->xml_content;
$output = array();
foreach ( $args->screen as $screen_data ) :
$screen = (string) $screen_data->object;
$extends = (string) $screen_data->extends;
$output[$screen] = (array) $screen_data;
if ( array_key_exists( 'extends', $screen_data ) && array_key_exists( $extends, $output ) ) :
$output[$screen] = array_merge( $output[$extends], $output[$screen] );
endif;
# var_dump($output);
endforeach;
return $this->xml_content = $output;
}
# ======================= INI FILE PARSER ======================= #
private function get_ini_contents( $file )
{
$this->ini_content = parse_ini_file( $this->ini_file, true );
$this->ini_content = $this->parse_ini_advanced( $this->ini_content );
$this->ini_content = $this->recursive_parse( $this->ini_content );
return $this->ini_content;
}
private function parse_ini_advanced( $input )
{
$output = array();
if ( is_array($input) )
{
foreach ( $input as $key => $value )
{
$e = explode( ':', $key );
if ( !empty($e[1]) )
{
$x = array();
foreach ( $e as $tk => $tv )
{
$x[$tk] = trim($tv);
}
$x = array_reverse( $x, true );
foreach ( $x as $k => $v )
{
$c = $x[0];
if ( empty($output[$c]) )
{
$output[$c] = array();
}
if ( isset($output[$x[1]]) )
{
$output[$c] = array_merge( $output[$c], $output[$x[1]] );
}
if ( $k === 0 )
{
$output[$c] = array_merge( $output[$c], $input[$key] );
}
}
}
else
{
$output[$key] = $input[$key];
}
}
}
return $output;
}
private function recursive_parse( $input )
{
$output = array();
if ( is_array($input) )
{
foreach ( $input as $key => $value )
{
if ( is_array($value) )
{
$input[$key] = $this->recursive_parse( $value );
}
$x = explode( '.', $key );
if ( !empty($x[1]) )
{
$x = array_reverse($x, true);
if ( isset($output[$key]) )
{
unset($output[$key]);
}
if ( !isset($output[$x[0]]) )
{
$output[$x[0]] = array();
}
$first = true;
foreach ( $x as $k => $v )
{
if ( $first === true )
{
$b = $input[$key];
$first = false;
}
$b = array( $v => $b );
}
$output[$x[0]] = array_merge( $output[$x[0]], $b[$x[0]] );
}
else
{
$output[$key] = $input[$key];
}
}
}
return $output;
}
} // END Class wpdHackersHelp
new wpdHackersHelp(); // init
} // endif;
?>
@franz-josef-kaiser
Copy link
Author

Discontinued in favor of the new repo. More information & link coming soon...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment