Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# printable-gallery
WordPress plugin that creates a table of images where users can select individual images to be printed.

## v0.3
Implemented some rudimentary object oriented design.

## v0.2
Setting things up for object oriented conversion.

Empty file removed includes/class-pg-functions.php
Empty file.
Empty file removed includes/class-pg-settings.php
Empty file.
94 changes: 94 additions & 0 deletions includes/class-pg-table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
/**
* Table
*
* @package PG
* @copyright Copyright (c) 2015, Shane W. Coll
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 0.3
*/

/**
* Check whether or not the table page already exists.
*
* If the table page does not exist, it creates a new one.
*
* @since 0.1
* @param string $title_str the title of the page being checked
* @return void
*/
class PG_TABLE{
static function pg_exist_post_by_title( $title_str ) {
global $wpdb;
return $wpdb->get_row( "SELECT * FROM wp_posts WHERE post_title = '" . $title_str . "'", 'ARRAY_A');
}

/**
* Generates a table according to user specs and inserts it into a new post.
*
* @since 0.1
* @return void
*/
static function pg_generateTable( ) {
if(PG_TABLE::pg_exist_post_by_title('Table Page' ) == NULL ){
//Creating the $post array
$post = array(
'post_title' => 'Table Page',
'post_content'=> "<table>
<tbody>" .
PG_TABLE::pg_table_body()
. "</tbody>
</table>"
); wp_insert_post( $post );
}
}

/**
* Generates the body of the table.
*
* @since 0.1
* @param TODO Set default values for no option recall
* @return string $tableBody the body of the table
*/
static function pg_table_body() {
if(get_option('pg_rows_number') == NULL){
$rows= 4;
}
else {
$rows= get_option('pg_rows_number');
}

for( $i = 0; $i < $rows; $i++ ){
$tableRows[$i]= "<tr>" .
PG_TABLE::pg_table_data()
. "</tr>";
}
$tableBody = implode( $tableRows );
return $tableBody;
}

/**
* Generates the columns of the table and insets their data.
*
* @since 0.1
* @param TODO Set default values for no option recall
* @return string $data the data of each cell
*/
static function pg_table_data(){
if(get_option('pg_columns_number') == NULL){
$columns = 4;
}
else {
$columns = get_option('pg_columns_number');
}

for( $i = 0; $i < $columns; $i++ ){
$tableColumns[$i]= "<td>
Picture will go here
</td>";
}
$data = implode( $tableColumns );
return $data;
}

}
101 changes: 101 additions & 0 deletions includes/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/**
* Settings
*
* @package PG
* @copyright Copyright (c) 2015, Shane W. Coll
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 0.3
*/

/**
* Generates the settings page and handles user input.
*
* @since 0.1
*/
function pg_settings_api() {

add_settings_section('pg_settings_section',
'Printable Gallery Settings',
'pg_settings_section_callback_function',
'media');

add_settings_field('pg_gallery_name',
'Gallery Name:',
'pg_settings_gallery_name_callback',
'media',
'pg_settings_section');

add_settings_field('pg_rows_number',
'Rows of images:',
'pg_settings_rows_num_callback',
'media',
'pg_settings_section');

add_settings_field('pg_columns_number',
'Columns of images:',
'pg_settings_columns_num_callback',
'media',
'pg_settings_section');

register_setting('media', 'pg_columns_number');
register_setting('media', 'pg_gallery_name');
register_setting('media', 'pg_rows_number');
PG_TABLE::pg_generateTable();
}
/**
* Prints message in the Gallery settings section
*
* @since 0.1
*/
function pg_settings_section_callback_function(){
echo '<p>Set up your Printable Gallery</p>';
}

/**
* Generates the rows field
*
* If there is no option value, the it displays "4" as the default value
*
* @since 0.1
*/
function pg_settings_rows_num_callback(){
if(get_option('pg_rows_number') == NULL){
echo '<input name="pg_rows_number" type="number" value="4" max="10"/>';
}
else {
echo '<input name="pg_rows_number" type="number" value="' . get_option('pg_rows_number') . '" max="10"/>';
}
}

/**
* Generates the columns field
*
* If there is no option value, the it displays "4" as the default value
*
* @since 0.1
*/
function pg_settings_columns_num_callback(){
if(get_option('pg_columns_number') == NULL){
echo '<input name="pg_columns_number" type="number" value="4" max="10"/>';
}
else {
echo '<input name="pg_columns_number" type="number" value="' . get_option('pg_columns_number') . '" max="10"/>';
}
}

/**
* Generates the gallery name field
*
* If there is no option value, the it displays "Gallery Name" as the default value
*
* @since 0.1
*/
function pg_settings_gallery_name_callback(){
if(get_option('pg_gallery_name') == NULL){
echo '<input name="pg_gallery_name" type="text" value="Gallery Name" maxlength="20"/>';
}
else {
echo '<input name="pg_gallery_name" type="text" value="' . get_option('pg_gallery_name') . '" maxlength="20"/>';
}
}
Loading