-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2cbf358
Showing
10 changed files
with
1,114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Content Views CiviCRM | ||
|
||
Plugin integrating [Content Views](https://wordpress.org/plugins/content-views-query-and-display-post-page/) with [CiviCRM](https://civicrm.org). | ||
Requires [Data Processor](https://lab.civicrm.org/extensions/dataprocessor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,255 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Content Views CiviCRM | ||
* Description: CiviCRM integraton for Content Views. | ||
* Version: 0.1 | ||
* Author: Agileware | ||
* Author URI: https://github.com/agileware/content-views-civicrm | ||
* Plugin URI: https://github.com/agileware/content-views-civicrm | ||
* GitHub Plugin URI: agileware/content-views-civicrm | ||
* Text Domain: content-views-civicrm | ||
* Domain Path: /languages | ||
*/ | ||
|
||
class Content_Views_CiviCRM { | ||
|
||
/** | ||
* Version. | ||
* @since 0.1 | ||
* @var string $version | ||
*/ | ||
protected $version = '0.1'; | ||
|
||
/** | ||
* Pro dependency. | ||
* @since 0.1 | ||
* @var bool $pro | ||
*/ | ||
private $pro; | ||
|
||
/** | ||
* Plugin path. | ||
* @since 0.1 | ||
* @var string $path | ||
*/ | ||
private $path; | ||
|
||
/** | ||
* Plugin url. | ||
* @since 0.1 | ||
* @var string $url | ||
*/ | ||
private $url; | ||
|
||
/** | ||
* Query management object. | ||
* @since 0.1 | ||
* @var object $query Content_Views_CiviCRM_Query | ||
*/ | ||
protected $query; | ||
|
||
/** | ||
* Settings management object. | ||
* @since 0.1 | ||
* @var object $settings Content_Views_CiviCRM_Settings | ||
*/ | ||
protected $settings; | ||
|
||
/** | ||
* Settings management object. | ||
* @since 0.1 | ||
* @var object $display Content_Views_CiviCRM_Display | ||
*/ | ||
protected $display; | ||
|
||
/** | ||
* Settings management object. | ||
* @since 0.1 | ||
* @var object $display Content_Views_CiviCRM_Filter | ||
*/ | ||
protected $filter; | ||
|
||
/** | ||
* CiviCRM Api object. | ||
* | ||
* @since 0.1 | ||
* @var Content_Views_CiviCRM_Api | ||
*/ | ||
public $api; | ||
|
||
/** | ||
* The plugin instance. | ||
* @since 0.1 | ||
* @var object $instance The plugin instance | ||
*/ | ||
private static $instance; | ||
|
||
/** | ||
* Returns a single instance of this object when called. | ||
* @return object $instance Content_Views_CiviCRM instance | ||
* @since 0.1.1 | ||
*/ | ||
public static function instance() { | ||
if ( ! isset( self::$instance ) ) { | ||
// instantiate | ||
self::$instance = new self; | ||
|
||
self::$instance->init(); | ||
|
||
/** | ||
* Broadcast that this plugin is loaded. | ||
* @since 0.1 | ||
*/ | ||
do_action( 'content_views_civicrm_loaded' ); | ||
|
||
} | ||
|
||
return self::$instance; | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* @since 0.1 | ||
*/ | ||
private function __construct() { | ||
// plugin path | ||
$this->path = plugin_dir_path( __FILE__ ); | ||
// plugin url | ||
$this->url = plugin_dir_url( __FILE__ ); | ||
} | ||
|
||
/** | ||
* Check plugin dependencies. | ||
* @return bool True if dependencies exist | ||
* @since 0.1 | ||
*/ | ||
private function check_dependencies() { | ||
// content views | ||
if ( ! class_exists( 'PT_Content_Views' ) ) { | ||
return false; | ||
} | ||
// civi | ||
if ( ! function_exists( 'civi_wp' ) ) { | ||
return false; | ||
} | ||
// data processor | ||
if ( ! function_exists( 'dataprocessor_get_factory' ) ) { | ||
return false; | ||
} | ||
|
||
// good to go | ||
return true; | ||
} | ||
|
||
/** | ||
* Intitialize. | ||
* @since 0.1 | ||
*/ | ||
private function init() { | ||
$this->include_files(); | ||
$this->setup_objects(); | ||
} | ||
|
||
/** | ||
* Include files. | ||
* @since 0.1 | ||
*/ | ||
private function include_files() { | ||
include $this->path . 'includes/class-cvc-query.php'; | ||
include $this->path . 'includes/class-cvc-settings.php'; | ||
include $this->path . 'includes/class-cvc-api.php'; | ||
include $this->path . 'includes/class-cvc-display.php'; | ||
include $this->path . 'includes/class-cvc-filter.php'; | ||
|
||
/** | ||
* Broadcast that this plugin's files have bee included. | ||
* | ||
* @since 0.1 | ||
*/ | ||
do_action( 'content_views_civicrm_files_included' ); | ||
} | ||
|
||
/** | ||
* Setup objects. | ||
* @since 0.1 | ||
*/ | ||
private function setup_objects() { | ||
|
||
/** | ||
* Filter CiviCRM Api object. | ||
* | ||
* Hook your own api wrapper implementation, the only | ||
* requirement is that it must have a 'call' and 'call_values' method. | ||
* | ||
* @since 0.1 | ||
*/ | ||
$this->api = apply_filters( 'content_views_civicrm_api_object', false ); | ||
|
||
if ( ! is_object( $this->api ) && ! $this->check_dependencies() ) { | ||
|
||
add_action( 'admin_notices', [ $this, 'show_notice' ] ); | ||
|
||
return; | ||
|
||
} | ||
|
||
$this->api = $this->api ? $this->api : ( new Content_Views_CiviCRM_Api ); | ||
$this->query = new Content_Views_CiviCRM_Query( $this ); | ||
$this->settings = new Content_Views_CiviCRM_Settings( $this ); | ||
$this->display = new Content_Views_CiviCRM_Display( $this ); | ||
$this->filter = new Content_Views_CiviCRM_Filter( $this ); | ||
|
||
} | ||
|
||
/** | ||
* Shows admin notice. | ||
* | ||
* @since 0.1 | ||
*/ | ||
public function show_notice() { | ||
|
||
printf( | ||
__( '<div class="notice notice-error"><p>It looks like CiviCRM is not activated, Content Views CiviCRM integration requires CiviCRM to be installed and activated, alternatively you can install the <a href="%s" title="Content Views CiviCRM Remote Settings">Content Views CiviCRM Remote plugin</a> to connect to a remote CiviCRM instance.</p></div>', 'content-views-civicrm' ), | ||
admin_url( 'https://github.com/mecachisenros/content-views-civicrm-remote' ) | ||
); | ||
|
||
} | ||
|
||
/** | ||
* Plugin path. | ||
* @return string $path | ||
* @since 0.1 | ||
*/ | ||
public function get_path() { | ||
return $this->path; | ||
} | ||
|
||
/** | ||
* Plugins url. | ||
* @return string $url | ||
* @since 0.1 | ||
*/ | ||
public function get_url() { | ||
return $this->url; | ||
} | ||
|
||
/** | ||
* Pro plugin enabled. | ||
* @return bool $pro | ||
* @since 0.1 | ||
*/ | ||
public function has_pro() { | ||
if ( ! isset( $this->pro ) ) { | ||
$this->pro = defined( 'PT_CV_VERSION_PRO' ); | ||
} | ||
return $this->pro; | ||
} | ||
|
||
} | ||
|
||
function CVC() { | ||
return Content_Views_CiviCRM::instance(); | ||
} | ||
|
||
// initialize | ||
add_action( 'init', 'CVC' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
/** | ||
* Content Views CiviCRM Api class. | ||
* | ||
* @since 0.1 | ||
*/ | ||
|
||
if ( ! class_exists( 'Content_Views_CiviCRM_Api' ) ) { | ||
|
||
class Content_Views_CiviCRM_Api { | ||
|
||
/** | ||
* Call CiviCRM API. | ||
* | ||
* @param string $entity | ||
* @param string $action | ||
* @param array $params | ||
* | ||
* @return array $result | ||
* @since 0.1 | ||
*/ | ||
public function call( $entity, $action, $params ) { | ||
|
||
try { | ||
|
||
return civicrm_api3( $entity, $action, $params ); | ||
|
||
} catch ( CiviCRM_API3_Exception $e ) { | ||
|
||
return WP_Error( 'CVC CiviCRM Api error', $e->getMessage(), $params ); | ||
|
||
} | ||
|
||
} | ||
|
||
/** | ||
* Get CiviCRM API values. | ||
* | ||
* @param string $entity | ||
* @param string $action | ||
* @param array $params | ||
* | ||
* @return array $result | ||
* @since 0.1 | ||
*/ | ||
public function call_values( $entity, $action, $params ) { | ||
|
||
return $this->call( $entity, $action, $params )['values']; | ||
|
||
} | ||
|
||
/** | ||
* Shorthand for getting data processor info | ||
* @param $id | ||
* | ||
* @return mixed | ||
*/ | ||
public function get_data_processor_by_id( $id ) { | ||
if ( empty( $id ) ) { | ||
throw new Exception( 'No id passed in.' ); | ||
} | ||
$dp = $this->call_values( 'DataProcessorOutput', 'get', [ | ||
'sequential' => 1, | ||
'type' => "api", | ||
'data_processor_id' => $id | ||
] ); | ||
return array_shift( $dp ); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
Oops, something went wrong.