Skip to content

A Library for PHP and a WordPress Plugin for accessing NRP's Data Services API

License

Notifications You must be signed in to change notification settings

newclarity/npr-alternative

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPR Alternative

NPR Alternative is a PHP-based library and an included WordPress Plugin developed to be an alternative to the NPR Story API WordPress plugin offered by NPR Digital Services.

##Benefits over Official Plugin? We designed the NPR Alternative plugin to have these contrasts with the official plugin:

  1. Designed for PHP programmers (vs. WordPress end-users or site builders)
  2. Leverages modern PHP programming best practices such as:
  • Works with PHP 5.6
  • Uses PHP Namespaces (for most classes, but not all)
  • Provides an Class Autoloader (though not a PSR-4 autoloader, to keep deployment simple)
  • Supports Composer for PHP
  1. Uses True Object-oriented Programming Style
  • Class-based Architecture with named classes and declared properties for each XML element
  • Reslient to XML schema changes using PHP magic methods-based extra properties
  1. More flexible, more robust, and easier to diagnose and debug coding errors vs. bugs or changes in the NPR API XML schema (at least in our experience.)

We think the above benefits result in a library that will be more robust and easier to debug meaning less frustration with broken feeds and less time and money spent on diagnosing problems than when using the official plugin.

###Regarding End-User Features Even though we built this library primarily for PHP developers it should be easy and inexpensive to provide a great end-user experience on top of the robust core we have created.

##How to Use.

###For WordPress-specific Use

Clone this repository into your /mu-plugins/ directory, create a file in the same /mu-plugins/ directory (which we typically name) mu-plugin-loader.php and then include the following code being sure to use your own api_key and org_id:

<?php 
require __DIR__ . '/npr-alternative/npr-alt-wordpress.php';
NprAlt_WordPress::register_settings( array(
    'api_key' => '<Your NPR Digital Services issues API Key Goes Here>',
    'org_id'  => <Your Numeric OrgId goes here>,
));

For example:

<?php 
require __DIR__ . '/npr-alternative/npr-alt-wordpress.php';
NprAlt_WordPress::register_settings( array(
    'api_key' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!',
    'org_id'  => 123,
));

Then to call the NPR API you can call the following somewhere in your code:

$result = NprAlt_WordPress::process_api_queries();
print_r( $result );

From there it is up to you. And that's it!

Of course if you want more features or need help, just ask.

###For General PHP Use

Simply clone this repository and require npr-alternative.php:

require '/path/to/npr-alternative/npr-alternative.php';

You will likely also want to implement a "driver" and you can find examples here. Once you implement a driver you could set the driver as follows after first requiring npr-alternative.php as above:

NprAlt::set_driver( new \YourNamespace\YourDriver() );

You will probably also want to create a child class of NprAlt for your implementation so that you can implement the on_loaded and on_shutdown callbacks. The code for these child classes will be platform specific; e.g. a WordPress support class is different from a potential Drupal support class from a potential Joomla support class, et. al. Best we can do for your is to point you to our WordPress version as a inspiration and a bit of a guide.

Then to call the NPR API you can call the following somewhere in your code:

$result = NprAlt::process_api_queries();
print_r( $result );

From there it is up to you. And that's it!

Of course if you want more features or need help, just ask.

##Why Build an Alternative? Simply because the NPR Story API WordPress plugin did not meet our needs. Further we wanted a more robust solution so we would not have to spend as much time diagnosing unexplained issues with the content imported into WordPress.

##Current Status This library is currently a work-in-progress regarding features and is being developed for the needs of our clients who are NPR affiliates.

##Interested in More Features and/or Help Using It? If you are interested in using this library/plugin but would like us to add sme new features, or you would simply like our help in using it please contact us via [email protected].

###Integration to Other PHP-based CMS or Framework? We developed this library/plugin to be distinct from WordPress by adding a "driver" model and even included a WordPress driver. Thus it should not be terribly difficult to integrate with another PHP CMS or Framework — such as Drupal, Joomla or Laravel — by adding additional drivers to the library.

So if you are interested in using this library with a PHP-based CMS/Framework other than WordPress and would like help in doing so please contact us via [email protected].

About

A Library for PHP and a WordPress Plugin for accessing NRP's Data Services API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages