@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The abstract class for the Calendar feeds tab.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
*
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Calendar-feed
|
||||
*/
|
||||
abstract class Ai1ec_Connector_Plugin extends Ai1ec_Base {
|
||||
|
||||
/**
|
||||
* An associative array where the keys are the name of the variables stored in the Settings object
|
||||
* while the values are the description in the admin Panel
|
||||
*
|
||||
* @var array;
|
||||
*
|
||||
*/
|
||||
protected $settings = array();
|
||||
|
||||
/**
|
||||
* An array of variables used by the plugin. Some of this variables are required:
|
||||
* title => The name of the tab in the calendar feeds settings
|
||||
* id => The id used in the href of the tab. Must be unique
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $variables = array();
|
||||
|
||||
/**
|
||||
* Handles any action the plugin requires when the users makes a POST in the calendar feeds page.
|
||||
*/
|
||||
abstract public function handle_feeds_page_post();
|
||||
|
||||
/**
|
||||
* Get title to be used for tab human-identification.
|
||||
*
|
||||
* @return string Localized string.
|
||||
*/
|
||||
abstract public function get_tab_title();
|
||||
|
||||
/**
|
||||
* Renders the content of the tab, where all the action takes place.
|
||||
*
|
||||
*/
|
||||
abstract public function render_tab_content();
|
||||
|
||||
/**
|
||||
* Let the plugin display an admin notice if neede.
|
||||
*
|
||||
*/
|
||||
abstract public function display_admin_notices();
|
||||
|
||||
/**
|
||||
* Run the code that cleans up the DB and CRON functions the plugin has installed.
|
||||
*
|
||||
*/
|
||||
abstract public function run_uninstall_procedures();
|
||||
|
||||
/**
|
||||
* Renders the HTML for the tabbed navigation
|
||||
*
|
||||
* @return void
|
||||
* Echoes the HTML string that act as tab header for the plugin
|
||||
*/
|
||||
public function render_tab_header() {
|
||||
// Use the standard view helper
|
||||
$args = array(
|
||||
'title' => $this->get_tab_title(),
|
||||
'id' => $this->variables['id'],
|
||||
);
|
||||
$loader = $this->_registry->get( 'theme.loader' );
|
||||
$file = $loader->get_file( 'plugins/tab_header.php', $args, true );
|
||||
$file->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the settings for the Plugin from the settings object.
|
||||
*
|
||||
* @param string $class_name The name of the Plugin for which we are
|
||||
* retrieving the settings.
|
||||
*
|
||||
* @return array An associative array with the settings stored in settings
|
||||
* object or an empty array if settings are not set.
|
||||
*/
|
||||
protected function get_plugin_settings( $class_name ) {
|
||||
$plugins_options = $this->_registry->get( 'model.settings' )
|
||||
->get( 'plugins_options' );
|
||||
return isset( $plugins_options[$class_name] )
|
||||
? $plugins_options[$class_name]
|
||||
: array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an arry which contains all settings data.
|
||||
*
|
||||
* Only data that will be processed by the admin view is considered.
|
||||
*
|
||||
* @return array An array of Associative arrays that hold everything that's
|
||||
* needed to render the settings field in the admin section.
|
||||
*/
|
||||
protected function generate_settings_array_for_admin_view() {
|
||||
// Get the plugin settings
|
||||
$plugin_settings = $this->get_plugin_settings( get_class( $this ) );
|
||||
// This is the array that will be returned
|
||||
$result = array();
|
||||
// Iterate over the settings
|
||||
foreach ( $this->settings as $setting ) {
|
||||
if ( $setting['admin-page'] === TRUE ) {
|
||||
// For each setting get it's value, description and id
|
||||
$result[] = array (
|
||||
"setting-description" => __( $setting['description'], AI1EC_PLUGIN_NAME ),
|
||||
"setting-value" => $plugin_settings[$setting['id']],
|
||||
"setting-id" => $setting['id'],
|
||||
);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* Check that at least one of the settings has ha value.
|
||||
*
|
||||
* @param array $settings
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function at_least_one_config_field_is_set( array $settings ) {
|
||||
foreach ( $settings as $setting ) {
|
||||
if( ! empty( $setting['setting-value'] ) ) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the plugin settings are not set they will be initialized to ''
|
||||
*
|
||||
*/
|
||||
public function initialize_settings_if_not_set() {
|
||||
// Get the class name.
|
||||
$class_name = get_class( $this );
|
||||
$settings = $this->_registry->get( 'model.settings' );
|
||||
$plugins_options = $settings->get( 'plugins_options' );
|
||||
// Check if the options have been set
|
||||
if ( ! isset( $plugins_options[$class_name] ) ) {
|
||||
// If not set them. The key is the class name, the value is an associative array
|
||||
$plugins_options[$class_name] = array();
|
||||
foreach ( $this->settings as $setting ) {
|
||||
$plugins_options[$class_name][$setting['id']] = '';
|
||||
}
|
||||
}
|
||||
$settings->set( 'plugins_options', $plugins_options );
|
||||
}
|
||||
/**
|
||||
* Retrieves the specified plugin setting
|
||||
*
|
||||
* @param string $variable_name The name of the variable to be retrieved
|
||||
*
|
||||
* @return mixed The variable value or FALSE if it's not set
|
||||
*/
|
||||
protected function get_plugin_variable( $variable_name ) {
|
||||
$plugin_settings = $this->get_plugin_settings( get_class( $this ) );
|
||||
return isset( $plugin_settings[$variable_name] ) ? $plugin_settings[$variable_name] : FALSE;
|
||||
}
|
||||
/**
|
||||
* Saves the variable int he plugin settings.
|
||||
*
|
||||
* @param string $variable_name The name of the variable to save.
|
||||
*
|
||||
* @param mixed $value The value of the variable to save.
|
||||
*/
|
||||
protected function save_plugin_variable( $variable_name, $value ) {
|
||||
$this->save_plugin_settings( array( $variable_name => $value ), TRUE );
|
||||
}
|
||||
/**
|
||||
* Saves the plugin settings in the settings object
|
||||
*
|
||||
* @param array $data
|
||||
* An associative array of data to be saved
|
||||
*
|
||||
* @param boolean $not_from_setting_page
|
||||
* True if the function is not called from the setting page and must trigger the saving, false otherwise
|
||||
*/
|
||||
public function save_plugin_settings( array $data, $not_from_setting_page = FALSE ) {
|
||||
$settings = $this->_registry->get( 'model.settings' );
|
||||
$plugins_options = $settings->get( 'plugins_options' );
|
||||
// Get the class name.
|
||||
$class_name = get_class( $this );
|
||||
// We need to save the old settings so that we can then let the Facebook plugin check if the user changed app-id / secret
|
||||
$old_settings = $this->get_plugin_settings( get_class( $this ) );
|
||||
|
||||
|
||||
// Check if the options have been set
|
||||
if ( isset( $plugins_options[$class_name] ) ) {
|
||||
// If the options for the plugin are set, iterate over the settings
|
||||
foreach ( $this->settings as $setting ) {
|
||||
// Always check that the key is set, data can come from $_POST or from an internal call
|
||||
if( isset( $data[$setting['id']] ) ) {
|
||||
$plugins_options[$class_name][$setting['id']] = $data[$setting['id']];
|
||||
}
|
||||
}
|
||||
}
|
||||
$settings->set( 'plugins_options', $plugins_options );
|
||||
if ( $not_from_setting_page === TRUE ) {
|
||||
$settings->persist( );
|
||||
} else {
|
||||
$old_settings['page'] = $data['page'];
|
||||
do_action( "ai1ec-$class_name-postsave-setting", $old_settings );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Prints an error message with standard formatting
|
||||
*
|
||||
* @param string $message The error message to be echoed to the screen
|
||||
*
|
||||
* @param boolean $close_tab_div TRUE if after the error message we should close the tab div
|
||||
*/
|
||||
protected function render_error_page( $message, $close_tab_div = FALSE ) {
|
||||
$args = array();
|
||||
$args['message'] = $message;
|
||||
$loader = $this->_registry->get( 'theme.loader' );
|
||||
$file = $loader->get_file( 'plugins/display_error_message.php', $args, true );
|
||||
$file->render();
|
||||
if( $close_tab_div === TRUE ) {
|
||||
$this->render_closing_div_of_tab();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the opening div of the tab and set the active status if this tab is the active one
|
||||
*
|
||||
* @param string $active_feed the tab that should be active.
|
||||
*/
|
||||
protected function render_opening_div_of_tab() {
|
||||
$args = array(
|
||||
'id' => $this->variables['id'],
|
||||
);
|
||||
$loader = $this->_registry->get( 'theme.loader' );
|
||||
$file = $loader->get_file( 'plugins/render_opening_div.php', $args, true );
|
||||
$file->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* This renders the closing div of the tab.
|
||||
*/
|
||||
protected function render_closing_div_of_tab( ) {
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The class which handles manual Feeds import.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.4
|
||||
*
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Calendar-feed
|
||||
*/
|
||||
class Ai1ecImportConnectorPlugin extends Ai1ec_Connector_Plugin {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* title: The title of the tab and the title of the configuration section
|
||||
* id: The id used in the generation of the tab
|
||||
*/
|
||||
protected $variables = array(
|
||||
'id' => 'import',
|
||||
);
|
||||
|
||||
public function get_tab_title() {
|
||||
return Ai1ec_I18n::__( 'Import Feeds' );
|
||||
}
|
||||
|
||||
public function __construct( Ai1ec_Registry_Object $registry ) {
|
||||
parent::__construct( $registry );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the translations array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_translations() {
|
||||
$categories = isset( $_POST['ai1ec_categories'] ) ? $_POST['ai1ec_categories'] : array();
|
||||
foreach ( $categories as &$cat ) {
|
||||
$term = get_term( $cat, 'events_categories' );
|
||||
$cat = $term->name;
|
||||
}
|
||||
$translations = array(
|
||||
'[feed_url]' => $_POST['ai1ec_calendar_url'],
|
||||
'[categories]' => implode( ', ', $categories ),
|
||||
'[user_email]' => $_POST['ai1ec_submitter_email'],
|
||||
'[site_title]' => get_bloginfo( 'name' ),
|
||||
'[site_url]' => ai1ec_site_url(),
|
||||
'[feeds_url]' => ai1ec_admin_url(
|
||||
AI1EC_FEED_SETTINGS_BASE_URL . '#ics'
|
||||
),
|
||||
);
|
||||
return $translations;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
*
|
||||
* @see Ai1ec_Connector_Plugin::render_tab_content()
|
||||
*/
|
||||
public function render_tab_content() {
|
||||
// Render the opening div
|
||||
$this->render_opening_div_of_tab();
|
||||
// Render the body of the tab
|
||||
$api = $this->_registry->get( 'model.api.api-feeds' );
|
||||
$api_signed = $api->is_signed();
|
||||
$settings = $this->_registry->get( 'model.settings' );
|
||||
$factory = $this->_registry->get(
|
||||
'factory.html'
|
||||
);
|
||||
$has_feature = $api->has_subscription_active(
|
||||
Ai1ec_Api_Features::CODE_IMPORT_FEEDS
|
||||
);
|
||||
$reached_limit = $api->subscription_has_reached_limit(
|
||||
Ai1ec_Api_Features::CODE_IMPORT_FEEDS
|
||||
);
|
||||
$select2_cats = $factory->create_select2_multiselect(
|
||||
array(
|
||||
'name' => 'ai1ec_feed_category[]',
|
||||
'id' => 'ai1ec_feed_category',
|
||||
'use_id' => true,
|
||||
'type' => 'category',
|
||||
'placeholder' => __(
|
||||
'Categories (optional)',
|
||||
AI1EC_PLUGIN_NAME
|
||||
)
|
||||
),
|
||||
get_terms(
|
||||
'events_categories',
|
||||
array(
|
||||
'hide_empty' => false
|
||||
)
|
||||
)
|
||||
);
|
||||
$select2_tags = $factory->create_select2_input(
|
||||
array( 'id' => 'ai1ec_feed_tags')
|
||||
);
|
||||
$loader = $this->_registry->get( 'theme.loader' );
|
||||
|
||||
$args = array(
|
||||
'event_categories' => $select2_cats,
|
||||
'event_tags' => $select2_tags,
|
||||
'api_signed' => $api->is_signed(),
|
||||
'has_feature' => $has_feature,
|
||||
'reached_limit' => $reached_limit,
|
||||
);
|
||||
|
||||
$import_feed = $loader->get_file(
|
||||
'plugins/ics/import_feed.php',
|
||||
$args,
|
||||
true
|
||||
);
|
||||
$import_feed->render();
|
||||
$this->render_closing_div_of_tab();
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
*
|
||||
* @see Ai1ec_Connector_Plugin::display_admin_notices()
|
||||
*/
|
||||
public function display_admin_notices() {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
*
|
||||
* @see Ai1ec_Connector_Plugin::run_uninstall_procedures()
|
||||
*/
|
||||
public function run_uninstall_procedures() {
|
||||
}
|
||||
|
||||
/**
|
||||
* add_ics_feed function
|
||||
*
|
||||
* Adds submitted ics feed to the database
|
||||
*
|
||||
* @return string JSON output
|
||||
*
|
||||
*/
|
||||
public function add_ics_feed() {
|
||||
}
|
||||
|
||||
public function handle_feeds_page_post() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The class which handles suggested feeds tab.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.4
|
||||
*
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Calendar-feed
|
||||
*/
|
||||
class Ai1ecSuggestedConnectorPlugin extends Ai1ec_Connector_Plugin {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* title: The title of the tab and the title of the configuration section
|
||||
* id: The id used in the generation of the tab
|
||||
*/
|
||||
protected $variables = array(
|
||||
'id' => 'suggested'
|
||||
);
|
||||
|
||||
public function get_tab_title() {
|
||||
return Ai1ec_I18n::__( 'Discover Events' );
|
||||
}
|
||||
|
||||
public function __construct( Ai1ec_Registry_Object $registry ) {
|
||||
parent::__construct( $registry );
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
*
|
||||
* @see Ai1ec_Connector_Plugin::handle_feeds_page_post()
|
||||
*/
|
||||
public function handle_feeds_page_post() {
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
*
|
||||
* @see Ai1ec_Connector_Plugin::render_tab_content()
|
||||
*/
|
||||
public function render_tab_content() {
|
||||
// Render the opening div
|
||||
$this->render_opening_div_of_tab();
|
||||
|
||||
$loader = $this->_registry->get( 'theme.loader' );
|
||||
$api = $this->_registry->get( 'model.api.api-feeds' );
|
||||
$event_actions = $loader->get_file(
|
||||
'plugins/suggested/event_actions.php',
|
||||
array(),
|
||||
true
|
||||
);
|
||||
$display_feeds = $loader->get_file(
|
||||
'plugins/suggested/display_feeds.php',
|
||||
array(
|
||||
'event_actions' => $event_actions,
|
||||
'api_signed' => $api->is_signed()
|
||||
),
|
||||
true
|
||||
);
|
||||
$display_feeds->render();
|
||||
|
||||
// Render the body of the tab
|
||||
$this->render_closing_div_of_tab();
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
*
|
||||
* @see Ai1ec_Connector_Plugin::display_admin_notices()
|
||||
*/
|
||||
public function display_admin_notices() {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Events search
|
||||
*/
|
||||
public function search_events() {
|
||||
$api = $this->_registry->get( 'model.api.api-feeds' );
|
||||
$events = $api->get_suggested_events();
|
||||
$imported = $api->get_feed_subscriptions();
|
||||
$loader = $this->_registry->get( 'theme.loader' );
|
||||
$event_actions = $loader->get_file(
|
||||
'plugins/suggested/event_actions.php',
|
||||
array(),
|
||||
true
|
||||
);
|
||||
if ( null === $events ) {
|
||||
echo json_encode(
|
||||
array(
|
||||
'list' => '',
|
||||
'total' => 0
|
||||
)
|
||||
);
|
||||
exit( 0 );
|
||||
}
|
||||
$page_links = paginate_links( array(
|
||||
'base' => add_query_arg( 'pagenum', '%#%' ),
|
||||
'format' => '',
|
||||
'prev_text' => __( '«', AI1EC_PLUGIN_NAME ),
|
||||
'next_text' => __( '»', AI1EC_PLUGIN_NAME ),
|
||||
'total' => $events->last_page,
|
||||
'current' => $events->current_page
|
||||
) );
|
||||
$avatar_url = $loader->get_file(
|
||||
'default-event-avatar.png',
|
||||
array(),
|
||||
false
|
||||
)->get_url();
|
||||
$feeds_list = $loader->get_file(
|
||||
'plugins/suggested/feeds_list.php',
|
||||
array(
|
||||
'suggested_feeds' => $events->data,
|
||||
'default_image' => $avatar_url,
|
||||
'event_actions' => $event_actions,
|
||||
'page_links' => $page_links
|
||||
),
|
||||
true
|
||||
);
|
||||
$feeds_list = array(
|
||||
'list' => $feeds_list->get_content(),
|
||||
'total' => $events->total,
|
||||
'imported' => $imported
|
||||
);
|
||||
echo json_encode( $feeds_list );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
*
|
||||
* @see Ai1ec_Connector_Plugin::run_uninstall_procedures()
|
||||
*/
|
||||
public function run_uninstall_procedures() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user