Bug #68655 [Opn->Spm]: angosson_db
| From: | requinix@php.net | Date: | Fri, 26 Dec 2014 05:22:44 +0000 |
| Subject: | Bug #68655 [Opn->Spm]: angosson_db | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-189211@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68655&edit=1
ID: 68655
Updated by: requinix@php.net
Reported by: r dot mbiama at angosso dot net
Summary: angosson_db
-Status: Open
+Status: Spam
Type: Bug
Package: MySQL related
Operating System: Wordpress
PHP Version: 5.6.4
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2014-12-26 03:18:16] r dot mbiama at angosso dot net
Description:
------------
Includes everything need to podcast with my website
Test script:
---------------
<?php
/**
* Plugin Name: Power Posts From MySQL
* Domain Path: /languages
*/
class angosson_db{
protected $menu_page;
protected $db_page;
protected $fields_page;
protected $podcasts;
protected $table;
public function __construct(){
require_once plugin_dir_path( __FILE__ ) . 'includes/class.admin-podcast.php';
require_once plugin_dir_path(__FILE__) . 'includes/class.db-list-table.php';
add_action ( 'admin_menu', array($this, 'db_add_page') );
// add_action ( 'admin_table_scripts', array($this, 'db_plugin_table_styles' )
);
add_action('admin_head', array($this, 'db_admin_header'));
add_action ('admin_init', array($this, 'db_plugin_field_page_init') );
add_action('admin_init', array($this, 'db_plugin_admin_init') );
add_filter('set-screen-option', array($this, 'db_set_option'), 10, 3);
$start = Podcast::get_instance();
}
public function db_add_page(){
$this->menu_page = add_menu_page( __('Power posts from MySQL', 'db'),
__('Power from MySQL', 'angosson_db'), 'manage_options',
'angosson_db_plugin', array($this, 'angosson_db_podcasts_page') );
$this->db_page = add_submenu_page( 'angosson_db_plugin', __('MySQL
Connection', 'angosson_db'), __('MySQL Connection',
'angosson_db'), 'manage_options', 'angosson_db_plugin_db_connect',
array($this, 'angosson_db_plugin_db_connect_page') );
$this->fields_page = add_submenu_page( 'angosson_db_plugin', __('MySQL
Fields', 'angosson_db'), __('MySQL Fields', 'angosson_db'),
'manage_options', 'angosson_db_plugin_db_fields', array($this,
'angosson_db_plugin_db_fields_page') );
add_action('load-' . $this->db_page, array($this, 'ppfm_db_setup') );
add_action('load-'.$this->fields_page, array( $this,
'angosson_db_fields_setup') );
add_action( 'load-' . $this->menu_page, array( $this,
'angosson_db_screen_options' ) );
}
function angosson_db_screen_options() {
$option = 'per_page';
$args = array(
'label' => 'Podcasts',
'default' => 5,
'option' => 'podcasts_per_page'
);
add_screen_option( $option, $args );
$this->table = new ANGOSSON_DB_List_Table();
}
function angosson_db_set_option($status, $option, $value){
return $value;
}
function angosson_db_admin_header(){
$page = ( isset($_GET['page'])) ? esc_attr($_GET['page']) : false;
if( 'angosson_db_plugin' != $page ){
return;
}
echo '<style type="text/css">';
echo '.list-table .column-cb { width: 5%; }';
echo './list-table .column-posted { width: 10%; }';
echo './list-table .column-title { width: 40%; }';
// echo './list-table .column-url { width: 45%; }';
echo '</style>';
}
function angosson_db_plugin_db_connect_page(){
$h2 = __('Power Posts From MySQL Connection', 'angosson_db');
?>
<div class="wrap">
<h2><?php echo $h2; ?></h2>
<?php settings_errors( ); ?>
<form action="options.php" method="post">
<?php settings_fields('angosson_db_db_options'); ?>
<?php do_settings_sections( 'angosson_db_plugin'); ?>
<?php do_settings_sections( 'angosson_db_guid' ); ?>
<?php submit_button( ); ?>
</form>
</div>
<?php
}
function angosson_db_plugin_db_fields_page(){
$h2 = __('Power Posts From MySQL Fields', 'angosson_db');
?>
<div class="wrap">
<?php
if ( count( Podcast::$db_options ) <5 ) {
$h2 = __('Please fill in or verify your database connection details',
'angosson_db');
echo '<h2>' . $h2 . '</h2>';
echo '<a href="' . admin_url(
"admin.php?page=angosson_db_plugin_db_connect") . '" >MySQL Connection
page</a>';
return;
}
?>
<h2><?php echo $h2; ?></h2>
<?php settings_errors( ); ?>
<form action="options.php" method="post">
<?php settings_fields( 'angosson_db_field_options'); ?>
<?php do_settings_sections( 'angosson_db_plugin_db_fields' ); ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}
function angosson_db_podcasts_page(){
if (!current_user_can('manage_options'))
{
angosson_die(__('You do not have sufficient permissions to access this page.',
'angosson_db'));
}
echo '<div class="wrap">';
if( !defined ( 'POWER_WEB' )){
$h2 = __( 'This plugin requires the Power plugin. Please install or Activate it now',
'angosson_db' );
echo '<h2>' . $h2 . '</h2>';
echo '<a href="http://exemple.net/resources/power/"
>Power</a>';
return;
}
if ( !Podcast::$dbh || empty( Podcast::$db_options[ 'db_table' ] ) ||
!Podcast::does_table_exist( Podcast::$db_options[ 'db_table' ] ) ) {
$h2 = __('Please fill in or verify database connection details', 'angosson_db');
echo '<h2> ' . $h2 . '</h2>';
echo '<a href="' . admin_url(
"admin.php?page=angosson_db_plugin_db_connect") . '" >MySQL Connection
page</a>';
return;
}
if ( count( Podcast::$field_options ) < 10 ){
$h2 = __( 'Please fill in or verify your database field details', 'angosson_db'
);
echo '<h2>' . $h2 . '</h2>';
echo '<a href="' . admin_url(
"admin.php?page=angosson_db_plugin_db_fields") . '" >MySQL Fields
Page</a>';
return;
}
$this->podcasts = Podcast::get_podcasts();
$table = new ANGOSSON_DB_List_Table($this->podcasts, Podcast::$field_options);
settings_errors( );
if( isset($_POST['s']) ){
$this->table->prepare_items($_POST['s']);
} else {
$this->table->prepare_items();
}
$count = Podcast::count_podcasts();
$h2 = sprintf(_n('%d Available Podcast', '%d Available Podcasts', $count,
'angosson_db'), $count);
?>
<div id="icon-users" class="icon32"><br /></div>
<h2><?php echo $h2; ?></h2>
<form method="post">
<input type="hidden" name="page" value="<?php echo
$_REQUEST['page'] ?>" />
<?php $this->table->search_box('Search Podcasts', 'angosson_db'); ?>
</form>
<?php
?>
<form id="podcasts-filter" action='options.php' method="get">
<!-- For plugins, we also need to ensure that the form posts back to our current page -->
<input type="hidden" name="page" value="<?php echo
$_REQUEST['page'] ?>" />
<!-- Now we can render the completed list table -->
<?php $this->table->display() ?>
</form>
</div>
<?php
}
function ppfm_fields_setup(){
$guid_text = __( 'As long as podcasts are stored in a MySQL table with a primary key, they will
all have a unique ID. The Primary Key value will be appended to the GUID string. If string field is
left blank, the Primary Key value will be appended to the site URL. The Primary Key field cannot be
left blank. If the GUID string is changed after posting, the plugin will not be able to tell what
has and has not been posted.', 'angosson_db' );
$field_names_text = __( 'These refer to the database field names that are used in the db table
podcasts are stored', 'angosson_db' );
$screen = get_current_screen();
if( $screen->id != $this->fields_page){
return;
}
$screen->add_help_tab( array(
'id' => 'angosson_db_fields',
'title' => __('Field Names', 'ppfm'),
'content' => "<p>$field_names_text</p>"
));
$screen->add_help_tab( array(
'id' => 'angosson_db_db_guid',
'title' => __('GUID / Primary Key', 'angosson_db'),
'content' => "<p>$guid_text</p>"
));
}
function angosson_db_setup(){
$host_text = __( 'This will most likely be "localhost", but this plugin does work
with remote database connections. If left blank, it will default to "localhost".',
'ppfm' );
// $port_text = __( 'On anyway, if the host is set to localhost the connection is made through
a socket, so this won\'t matter. If host is set to 212.1.208.188 this needs to be set correct
port (default 3306)', 'angosson_db' );
$db_name_text = __( 'This is the name of the database where podcast information is stored.
database.', 'angosson_db' );
$db_user_text = __( 'This refers to the login credentials for the database where podcast
information is stored.', 'angosson_db' );
$db_table_text = __( 'This is the name of the database table where your podcast information is
stored.', 'angosson_db' );
$screen = get_current_screen();
if ( $screen->id != $this->db_page ){
return;
}
$screen->add_help_tab( array(
'id' => 'angosson_db_host',
'title' => __('Database Host', 'angosson_db'),
'content' => "<p>$host_text</p>"
));
// $screen->add_help_tab( array(
// 'id' => 'angosson_db_db_Port',
// 'title' => __('Database Port', 'ppfm'),
// 'content' => "<p>$port_text</p>"
// ));
$screen->add_help_tab( array(
'id' => 'angosson_db_name',
'title' => __('Database Name', 'angosson_db'),
'content' => "<p>$db_name_text</p>"
));
$screen->add_help_tab( array(
'id' => 'angosson_db_user',
'title' => __('User & Password', 'angosson_db'),
'content' => "<p>$db_user_text</p>"
));
$screen->add_help_tab( array(
'id' => 'angosson_db_db_table',
'title' => __('Database Table', 'ppfm'),
'content' => "<p>$db_table_text</p>"
));
}
function angosson_db_plugin_field_page_init(){
register_setting(
'angosson_db_field_options',
'angosson_db_field_options',
array( $this, 'angosson_db_plugin_validate_field')
);
add_settings_section(
'angosson_db_plugin_fields',
__( 'Database Field Settings', 'ppfm'),
array( $this, 'angosson_db_plugin_fields_description'),
'angosson_db_plugin_db_fields'
);
add_settings_section(
'angosson_db_plugin_guid',
__( 'Custom GUID Settings', 'angosson_db' ),
array( $this, 'angosson_db_plugin_guid_description' ),
'angosson_db_plugin_db_fields'
);
add_settings_field(
'angosson_db_plugin_post_title',
__( 'Post title field', 'ppfm'),
array( $this, 'angosson_db_plugin_post_title_input' ),
'angosson_db_plugin_db_fields',
'angosson_db_plugin_fields'
);
add_settings_field(
'angosson_db_plugin_post_category',
__( 'Post category field', 'ppfm'),
array( $this, 'angosson_db_plugin_post_category_input' ),
'angosson_db_plugin_db_fields',
'angosson_db_plugin_fields'
);
add_settings_field(
'angosson_db_plugin_post_body',
__( 'Post body field', 'angosson_db'),
array( $this, 'ppfm_plugin_post_body_input' ),
'angosson_db_plugin_db_fields',
'angosson_db_plugin_fields'
);
add_settings_field(
'angosson_db_plugin_post_image',
__( 'Post image URL field', 'ppfm'),
array( $this, 'angosson_db_plugin_post_image_input' ),
'angosson_db_plugin_db_fields',
'angosson_db_plugin_fields'
);
add_settings_field(
'angosson_db_plugin_post_url',
__( 'Podcast URL field', 'angosson_db'),
array( $this, 'angosson_db_plugin_post_url_input' ),
'angosson_db_plugin_db_fields',
'angosson_db_plugin_fields'
);
add_settings_field(
'angosson_db_plugin_post_size',
__( 'Podcast size field', 'ppfm'),
array( $this, 'angosson_db_plugin_post_size_input' ),
'angosson_db_plugin_db_fields',
'angosson_db_plugin_fields'
);
add_settings_field(
'angosson_db_plugin_post_type',
__( 'Podcast Media type field', 'angosson_db'),
array( $this, 'angosson_db_plugin_post_type_input' ),
'angosson_db_plugin_db_fields',
'angosson_db_plugin_fields'
);
add_settings_field(
'angosson_db_plugin_post_date',
__( 'Post date field', 'ppfm'),
array( $this, 'angosson_db_plugin_post_date_input' ),
'angosson_db_plugin_db_fields',
'angosson_db_plugin_fields'
);
add_settings_field(
'angosson_db_plugin_guid',
__( 'Custom GUID String', 'angosson_db'),
array( $this, 'angosson_db_plugin_guid_input' ),
'angosson_db_plugin_db_fields',
'angosson_db_plugin_guid'
);
add_settings_field(
'angosson_db_plugin_db_id',
__( 'MySQL Primary Key Field', 'angosson_db'),
array( $this, 'angosson_db_plugin_db_id_input' ),
'angosson_db_plugin_db_fields',
'angosson_db_plugin_guid'
);
}
function angosson_db_plugin_admin_init(){
register_setting(
'angosson_db_db_options',
'angosson_db_db_options'
);
add_settings_section(
'angosson_db_plugin_db',
__( 'Database Connection Settings', 'angosson_db'),
array( $this, 'angosson_db_plugin_db_description'),
'angosson_db_plugin'
);
add_settings_field(
'angosson_db_plugin_db_host',
__( 'Database Host', 'ppfm'),
array( $this, 'angosson_db_plugin_db_host_input' ),
'angosson_db_plugin',
'angosson_db_plugin_db'
);
// add_settings_field(
// 'angosson_db_plugin_db_port',
// __( 'Database Port', 'ppfm'),
// array( $this, 'angosson_db_plugin_db_port_input' ),
// 'angosson_db_plugin',
// 'angosson_db_plugin_db'
// );
add_settings_field(
'angosson_db_plugin_db_name',
__( 'Database Name', 'ppfm'),
array( $this, 'angosson_db_plugin_db_name_input' ),
'angosson_db_plugin',
'angosson_db_plugin_db'
);
add_settings_field(
'angosson_db_plugin_db_user',
__( 'Database User', 'angosson_db'),
array( $this, 'angosson_db_plugin_db_user_input' ),
'angosson_db_plugin',
'angosson_db_plugin_db'
);
add_settings_field(
'angosson_db_plugin_db_password',
__( 'Database Password', 'angosson_db'),
array( $this, 'angosson_db_plugin_db_password_input' ),
'angosson_db_plugin',
'angosson_db_plugin_db'
);
add_settings_field(
'angosson_db_plugin_db_table',
__( 'Database Table', 'ppfm'),
array( $this, 'angosson_db_plugin_db_table_input' ),
'angosson_db_plugin',
'angosson_db_plugin_db'
);
}
function angosson_db_plugin_db_description(){
echo '<p>';
_e('Enter your database connection details', 'ppfm');
echo '</p>';
}
function angosson_db_plugin_guid_description(){
echo '<p>';
_e( 'Enter a custom GUID string ( optional - see contextual help above. )',
'angosson_db' );
echo '</p>';
}
function angosson_db_plugin_db_validate($item){
$good = array();
foreach ( $item as $k=>$v){
// Check to see if MySQL ID field exists
if ( $k == 'primary_key' ){
if( FALSE === Podcast::does_field_exist( $v )){
$v = '';
}
}
if ( $k == 'db_table' ){
if ( !Podcast::does_table_exist( $v )){
$v = '';
}
}
// Check to see if all fields have been filled, except GUID as that can be blank.
if ( $v !== "" || $k == 'db_guid' ){
$esc_v = sanitize_text_field($v);
$good[$k] = $esc_v;
} else {
$err_msg = sprintf( __('Please verify your %s field is complete and correct',
'angosson_db'), $k );
add_settings_error(
'angosson_db_plugin_db_error',
'angosson_db_db_error',
$err_msg,
'error'
);
}
}
return $good;
}
function angosson_db_plugin_fields_description(){
echo '<p>';
_e('Enter your database field names', 'ppfm');
echo '</p>';
}
function angosson_db_plugin_validate_field($input){
$exist = array();
foreach( $input as $k=>$v){
$esc_v = sanitize_text_field($v);
if( Podcast::does_field_exist($esc_v) && !empty($esc_v) || $k == 'db_guid' ){
$exist[$k] = $esc_v;
} else {
$err_msg = sprintf(__('Please verify your %s field is complete and correct',
'ppfm'), $k );
add_settings_error(
'angosson_db_plugin_post_title',
'angosson_db_field_error',
$err_msg,
'error'
);
}
}
return $exist;;
}
function angosson_db_plugin_db_host_input(){
if ( isset( Podcast::$db_options['db_host']) ){
$db_host = Podcast::$db_options['db_host'];
} else {
$db_host = "";
}
echo "<input id='db_host' name='angosson_db_db_options[db_host]'
type='text' value='$db_host' />";
}
// function angosson_db_plugin_db_port_input(){
// if ( isset (Podcast::$db_options['db_port'] )){
// $db_port = Podcast::$db_options['db_port'];
// } else {
// $db_port = '';
// }
// echo "<input id='db_port' name='angosson_db_db_options[db_port]'
type='text' value='$db_port' />";
// }
function angosson_db_plugin_db_name_input(){
if ( isset (Podcast::$db_options['db_name'] )){
$db_name = Podcast::$db_options['db_name'];
} else {
$db_name = '';
}
echo "<input id='db_name' name='angosson_db_db_options[db_name]'
type='text' value='$db_name' />";
}
function angosson_db_plugin_db_user_input(){
if ( isset ( Podcast::$db_options['db_user'])){
$db_user = Podcast::$db_options['db_user'];
} else {
$db_user = '';
}
echo "<input id='db_user' name='angosson_db_db_options[db_user]'
type='text' value='$db_user' />";
}
function angosson_db_plugin_db_password_input(){
if ( isset (Podcast::$db_options['db_password'] )){
$db_password = Podcast::$db_options['db_password'];
} else {
$db_password = '';
}
echo "<input id='db_password' name='angosson_db_db_options[db_password]'
type='text' value='$db_password' />";
}
function angosson_db_plugin_db_table_input(){
if ( isset (Podcast::$db_options['db_table'] )){
$db_table = Podcast::$db_options['db_table'];
} else {
$db_table = '';
}
echo "<input id='db_table' name='angosson_db_db_options[db_table]'
type='text' value='$db_table' />";
}
function angosson_db_plugin_guid_input(){
if (isset( Podcast::$field_options['db_guid'] )){
$db_guid = Podcast::$field_options['db_guid'];
} else {
$db_guid = '';
}
echo "<input id='db_guid' name='angosson_db_field_options[db_guid]'
type='text' value='$db_guid' />";
}
function angosson_db_plugin_db_id_input(){
if ( isset (Podcast::$field_options['primary_key'] )){
$primary_key = Podcast::$field_options['primary_key'];
} else {
$primary_key = '';
}
echo "<input id='primary_key'
name='angosson_db_field_options[primary_key]' type='text'
value='$primary_key' />";
}
function angosson_db_plugin_post_title_input(){
if( isset( Podcast::$field_options['post_title'] )){
$post_title = Podcast::$field_options['post_title'];
} else {
$post_title = '';
}
echo "<input id='post_title'
name='angosson_db_field_options[post_title]' type='text'
value='$post_title' />";
}
function ppfm_plugin_post_category_input(){
if ( isset ( Podcast::$field_options['post_category'])){
$post_category = Podcast::$field_options['post_category'];
} else {
$post_category = '';
}
echo "<input id='post_category'
name='angosson_db_field_options[post_category]' type='text'
value='$post_category' />";
}
function angosson_db_plugin_post_body_input(){
if ( isset ( Podcast::$field_options['post_body'])){
$post_body = Podcast::$field_options['post_body'];
} else {
$post_body = '';
}
echo "<input id='post_body' name='angosson_db_field_options[post_body]'
type='text' value='$post_body' />";
}
function angosson_db_plugin_post_image_input(){
if ( isset ( Podcast::$field_options['post_image'])){
$post_image = Podcast::$field_options['post_image'];
} else {
$post_image = '';
}
echo "<input id='post_image'
name='angosson_db_field_options[post_image]' type='text'
value='$post_image' />";
}
function angosson_db_plugin_post_url_input(){
if ( isset ( Podcast::$field_options['post_url'])){
$post_url = Podcast::$field_options['post_url'];
} else {
$post_url = '';
}
echo "<input id='post_url' name='angosson_db_field_options[post_url]'
type='text' value='$post_url' />";
}
function angosson_db_plugin_post_size_input(){
if ( isset ( Podcast::$field_options['post_size'])){
$post_size = Podcast::$field_options['post_size'];
} else {
$post_size = '';
}
echo "<input id='post_size' name='angosson_db_field_options[post_size]'
type='text' value='$post_size' />";
}
function angosson_db_plugin_post_type_input(){
if ( isset ( Podcast::$field_options['post_type'])){
$post_type = Podcast::$field_options['post_type'];
} else {
$post_type = '';
}
echo "<input id='post_type' name='angosson_db_field_options[post_type]'
type='text' value='$post_type' />";
}
function ppfm_plugin_post_date_input(){
if ( isset (angosson_dbPodcast::$field_options['post_date'] )){
$post_date = Podcast::$field_options['post_date'];
} else {
$post_date = '';
}
echo "<input id='post_date' name='angosson_db_field_options[post_date]'
type='text' value='$post_date' />";
}
}
new angosson_dbPlugin();
Expected result:
----------------
Full iTunes support
Audio and Video Media Players
Multiple Media Formats and Categories
Media URL Verification
Platform Migration Tools
Open Source plugin
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68655&edit=1