Skip to content

Commit

Permalink
WIP: (Refactor and restructure)
Browse files Browse the repository at this point in the history
Media Library Render

Added autoload method for all classes
Changed File Structure
Added new classes for Media Library Render

User: bogdan.preda@themeisle.com <Bogdan Preda>
  • Loading branch information
preda-bogdan committed Nov 23, 2016
1 parent cacfe5f commit a420922
Show file tree
Hide file tree
Showing 26 changed files with 902 additions and 667 deletions.
Empty file modified .codeclimate.yml
100644 → 100755
Empty file.
Empty file modified .csslintrc
100644 → 100755
Empty file.
Empty file modified .eslintignore
100644 → 100755
Empty file.
Empty file modified .eslintrc
100644 → 100755
Empty file.
36 changes: 31 additions & 5 deletions feedzy-rss-feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,17 @@

/**
* The code that runs during plugin activation.
* This action is documented in includes/class-feedzy-rss-feeds-activator.php
* This action is documented in includes/feedzy-rss-feeds-activator.php
*/
function activate_feedzy_rss_feeds() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-feedzy-rss-feeds-activator.php';
Feedzy_Rss_Feeds_Activator::activate();
}

/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-feedzy-rss-feeds-deactivator.php
* This action is documented in includes/feedzy-rss-feeds-deactivator.php
*/
function deactivate_feedzy_rss_feeds() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-feedzy-rss-feeds-deactivator.php';
Feedzy_Rss_Feeds_Deactivator::deactivate();
}

Expand All @@ -54,7 +52,32 @@ function deactivate_feedzy_rss_feeds() {
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-feedzy-rss-feeds.php';
function feedzy_rss_feeds_autoload( $class ) {
$namespaces = array( 'Feedzy_Rss_Feeds' );
foreach ( $namespaces as $namespace ) {
if ( substr( $class, 0, strlen( $namespace ) ) == $namespace ) {
$filename = plugin_dir_path( __FILE__ ) . 'includes/' . str_replace( '_', '-', strtolower( $class ) ) . '.php';
if ( is_readable( $filename ) ) {
require_once $filename;
return true;
}

$filename = plugin_dir_path( __FILE__ ) . 'includes/abstract/' . str_replace( '_', '-', strtolower( $class ) ) . '.php';
if ( is_readable( $filename ) ) {
require_once $filename;
return true;
}

$filename = plugin_dir_path( __FILE__ ) . 'includes/admin/' . str_replace( '_', '-', strtolower( $class ) ) . '.php';
if ( is_readable( $filename ) ) {
require_once $filename;
return true;
}
}
}
return false;
}


/**
* Begins execution of the plugin.
Expand All @@ -74,4 +97,7 @@ function run_feedzy_rss_feeds() {
$plugin->run();

}

spl_autoload_register( 'feedzy_rss_feeds_autoload' );

run_feedzy_rss_feeds();
2 changes: 1 addition & 1 deletion grunt/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
prefix: '\\$this->version\.*\\s=\.*\\s\''
},
src: [
'includes/class-feedzy-rss-feeds.php',
'includes/Feedzy_Rss_Feeds.php',
]
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
* @since 3.0.0
*
* @package Feedzy_Rss_Feeds
* @subpackage Feedzy_Rss_Feeds/admin
* @subpackage Feedzy_Rss_Feeds/includes/abstract
*/
/**
* The Feedzy RSS functions of the plugin.
*
* Abstract class containing functions for the Feedzy Admin Class
*
* @package Feedzy_Rss_Feeds
* @subpackage Feedzy_Rss_Feeds/admin
* @subpackage Feedzy_Rss_Feeds/includes/abstract
* @author Themeisle <friends@themeisle.com>
* @abstract
*/
abstract class Feedzy_Rss_Feeds_Abstract {
abstract class Feedzy_Rss_Feeds_Admin_Abstract {


/**
Expand Down Expand Up @@ -634,4 +635,18 @@ public function feedzy_rss( $atts, $content = '' ) {

return apply_filters( 'feedzy_global_output', $content, $feedURL );
}

/**
* Render the Template
*/
public function render_templates() {
global $pagenow;

if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) {
return;
}

$render = new Feedzy_Rss_Feeds_Render_Templates();
$render->render();
}
}
142 changes: 142 additions & 0 deletions includes/abstract/feedzy-rss-feeds-render-abstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php
/**
* The Abstract class for render.
*
* @link http://themeisle.com
* @since 3.0.0
*
* @package Feedzy_Rss_Feeds
* @subpackage Feedzy_Rss_Feeds/includes/abstract
*/
/**
* Abstract render class implements all routine stuff required for template
* rendering.
*
* @package Feedzy_Rss_Feeds
* @subpackage Feedzy_Rss_Feeds/includes/abstract
* @author Themeisle <friends@themeisle.com>
* @abstract
*/
abstract class Feedzy_Rss_Feeds_Render_Abstract {

/**
* The storage of all data associated with this render.
*
* @since 3.0.0
*
* @access protected
* @var array
*/
protected $_data;

/**
* Constructor.
*
* @since 3.0.0
*
* @access public
* @param array $data The data what has to be associated with this render.
*/
public function __construct( $data = array() ) {
$this->_data = $data;
}

/**
* Returns property associated with the render.
*
* @since 3.0.0
*
* @access public
* @param string $name The name of a property.
* @return mixed Returns mixed value of a property or NULL if a property doesn't exist.
*/
public function __get( $name ) {
return array_key_exists( $name, $this->_data ) ? $this->_data[ $name ] : null;
}

/**
* Checks whether the render has specific property or not.
*
* @since 3.0.0
*
* @access public
* @param string $name The key name.
* @return boolean TRUE if the property exists, otherwise FALSE.
*/
public function __isset( $name ) {
return array_key_exists( $name, $this->_data );
}

/**
* Associates the render with specific property.
*
* @since 3.0.0
*
* @access public
* @param string $name The name of a property to associate.
* @param mixed $value The value of a property.
*/
public function __set( $name, $value ) {
$this->_data[ $name ] = $value;
}

/**
* Unassociates specific property from the render.
*
* @since 3.0.0
*
* @access public
* @param string $name The name of the property to unassociate.
*/
public function __unset( $name ) {
unset( $this->_data[ $name ] );
}

/**
* Renders template.
*
* @since 3.0.0
*
* @abstract
* @access protected
*/
protected abstract function _to_html();

/**
* Builds template and return it as string.
*
* @since 3.0.0
*
* @access public
* @return string
*/
public function to_html() {
ob_start();
$this->_to_html();
return ob_get_clean();
}

/**
* Returns built template as string.
*
* @since 3.0.0
*
* @access public
* @return type
*/
public function __toString() {
return $this->to_html();
}

/**
* Renders the template.
*
* @since 3.0.0
*
* @access public
*/
public function render() {
$this->_to_html();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
* @subpackage Feedzy_Rss_Feeds/admin
* @author Themeisle <friends@themeisle.com>
*/
require_once( 'class-abstract-feedzy-rss-feeds-admin.php' );

/**
* Class Feedzy_Rss_Feeds_Admin
*/
class Feedzy_Rss_Feeds_Admin extends Feedzy_Rss_Feeds_Abstract {
class Feedzy_Rss_Feeds_Admin extends Feedzy_Rss_Feeds_Admin_Abstract {

/**
* The ID of this plugin.
Expand Down Expand Up @@ -76,7 +75,7 @@ public function enqueue_styles() {
* class.
*/

wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . '../css/feedzy-rss-feeds.css', array(), $this->version, 'all' );
wp_enqueue_style( $this->plugin_name, FEEDZY_ABSURL . 'css/feedzy-rss-feeds.css', array(), $this->version, 'all' );
}

/**
Expand All @@ -101,10 +100,8 @@ public function enqueue_scripts() {
global $typenow;

if ( post_type_supports( $typenow, 'editor' ) ) {
//wp_enqueue_style( $this->plugin_name . '-media', FEEDZY_ABSURL . 'css/media.css', array( 'media-views' ), $this->version );

//wp_enqueue_script( $this->plugin_name .'-library', FEEDZY_ABSURL . 'js/library.js', array( 'jquery', $this->plugin_name . '-media' ), $this->version, true );

// wp_enqueue_style( $this->plugin_name . '-media', FEEDZY_ABSURL . 'css/media.css', array( 'media-views' ), $this->version );
// wp_enqueue_script( $this->plugin_name .'-library', FEEDZY_ABSURL . 'js/library.js', array( 'jquery', $this->plugin_name . '-media' ), $this->version, true );
wp_enqueue_script( $this->plugin_name . '-media-model', FEEDZY_ABSURL . 'js/media/model.js', null, $this->version, true );
wp_enqueue_script( $this->plugin_name . '-media-collection', FEEDZY_ABSURL . 'js/media/collection.js', array( $this->plugin_name . '-media-model' ), $this->version, true );
wp_enqueue_script( $this->plugin_name . '-media-controller', FEEDZY_ABSURL . 'js/media/controller.js', array( $this->plugin_name . '-media-collection' ), $this->version, true );
Expand Down Expand Up @@ -151,7 +148,8 @@ public function feedzy_filter_plugin_row_meta( $links, $file ) {
*/
public static function _get_template_names_localized() {
$templates = array(
'all' => esc_html__( 'No Template', 'feedzy_rss_translate' ),
'all' => esc_html__( 'All', 'feedzy_rss_translate' ),
'no-template' => esc_html__( 'No Template', 'feedzy_rss_translate' ),
'default' => esc_html__( 'Default', 'feedzy_rss_translate' ),
'example' => esc_html__( 'Example', 'feedzy_rss_translate' ),
);
Expand Down
Loading

0 comments on commit a420922

Please sign in to comment.