Skip to content

Commit

Permalink
Merge branch 'feature/2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
JDGrimes committed Mar 31, 2015
2 parents c50af9d + 5e4ca01 commit 4c58244
Show file tree
Hide file tree
Showing 4 changed files with 269 additions and 58 deletions.
8 changes: 4 additions & 4 deletions src/admin/screens/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@
<?php endif; ?>
</label>

<?php if ( isset( $options['description'] ) ) : ?>
<p class="description">
<?php if ( isset( $option['description'] ) ) : ?>
<p class="description" style="margin-bottom: 10px; margin-left: 25px;">
<?php echo esc_html( $option['description'] ); ?>
</p>
<?php else : ?>
<br style="margin-bottom: 10px" />
<?php endif; ?>

<br />

<?php endforeach; ?>

<?php endforeach; ?>
Expand Down
117 changes: 117 additions & 0 deletions src/includes/importers/cubepoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public function __construct( $name ) {
'label' => __( 'Excluded users', 'wordpoints-importer' ),
'function' => array( $this, 'import_excluded_users' ),
),
'settings' => array(
'label' => __( 'Points Hooks', 'wordpoints-importer' ),
'description' => __( 'If checked, the settings for the number of points to award for posts, comments, etc. are imported.', 'wordpoints-importer' ),
'function' => array( $this, 'import_points_settings' ),
),
'user_points' => array(
'label' => __( 'User points', 'wordpoints-importer' ),
'function' => array( $this, 'import_user_points' ),
Expand Down Expand Up @@ -117,6 +122,118 @@ protected function import_excluded_users() {
);
}

/**
* Import the points settings to the points hooks.
*
* @since 1.1.0
*
* @param array $settings The settings for the points component import.
*/
protected function import_points_settings( $settings ) {

$this->feedback->info( __( 'Importing points hooks&hellip;', 'wordpoints-importer' ) );

$options = array(
'cp_comment_points' => 'comment',
'cp_post_points' => 'post',
'cp_reg_points' => 'registration',
'cp_post_author_points' => 'comment_received',
);

// Don't import this module setting if the module isn't active.
if ( function_exists( 'cp_module_activated' ) && ! cp_module_activated( 'post_author_points' ) ) {
unset( $options['cp_post_author_points'] );
}

$imported = 0;

foreach ( $options as $option => $type ) {

$points = get_option( $option );

if ( wordpoints_posint( $points ) ) {

$added = $this->add_points_hook(
"wordpoints_{$type}_points_hook"
, $settings['points_type']
, array( 'points' => $points )
);

if ( $added ) {
$imported++;
}
}
}

if ( $this->import_daily_points_hook( $settings ) ) {
$imported++;
}

$this->feedback->success(
sprintf( __( 'Imported %s points hooks.', 'wordpoints-importer' ), $imported )
);
}

/**
* Import the settings for the Daily Points module to a points hook.
*
* @since 1.1.0
*
* @param array $settings The settings for the points component import.
*
* @return bool True if the settings were imported, false otherwise.
*/
protected function import_daily_points_hook( $settings ) {

// Don't import this module setting if the module isn't active.
if ( function_exists( 'cp_module_activated' ) && ! cp_module_activated( 'dailypoints' ) ) {
return false;
}

$points = get_option( 'cp_module_dailypoints_points' );
$period = get_option( 'cp_module_dailypoints_time' );

if ( ! wordpoints_int( $points ) || ! wordpoints_posint( $period ) ) {
return false;
}

return $this->add_points_hook(
'wordpoints_periodic_points_hook'
, $settings['points_type']
, array( 'points' => $points, 'period' => $period )
);
}

/**
* Programmatically create a new instance of a points hook.
*
* @since 1.0.0
*
* @param string $hook_type The type of hook to create.
* @param string $points_type The slug of the points type the hook is for.
* @param array $instance The arguments for the instance.
*
* @return bool True if added successfully, or false on failure.
*/
private function add_points_hook( $hook_type, $points_type, $instance = array() ) {

$hook = WordPoints_Points_Hooks::get_handler_by_id_base( $hook_type );

if ( ! $hook instanceof WordPoints_Points_Hook ) {
return false;
}

$number = $hook->next_hook_id_number();

$points_types_hooks = WordPoints_Points_Hooks::get_points_types_hooks();
$points_types_hooks[ $points_type ] = $hook->get_id( $number );
WordPoints_Points_Hooks::save_points_types_hooks( $points_types_hooks );

$hook->update_callback( $instance, $number );

return true;
}

/**
* Import the user points.
*
Expand Down
42 changes: 30 additions & 12 deletions src/languages/wordpoints-importer.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WordPoints Importer 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-02-28 16:41:37+00:00\n"
"POT-Creation-Date: 2015-03-31 15:51:56+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -122,50 +122,68 @@ msgid "Excluded users"
msgstr ""

#: includes/importers/cubepoints.php:31
msgid "Points Hooks"
msgstr ""

#: includes/importers/cubepoints.php:32
msgid ""
"If checked, the settings for the number of points to award for posts, "
"comments, etc. are imported."
msgstr ""

#: includes/importers/cubepoints.php:36
msgid "User points"
msgstr ""

#: includes/importers/cubepoints.php:35
#: includes/importers/cubepoints.php:40
msgid "Points logs"
msgstr ""

#: includes/importers/cubepoints.php:51
#: includes/importers/cubepoints.php:56
msgid "CubePoints is not installed"
msgstr ""

#: includes/importers/cubepoints.php:85
#: includes/importers/cubepoints.php:90
msgid "Importing excluded users&hellip;"
msgstr ""

#: includes/importers/cubepoints.php:90
#: includes/importers/cubepoints.php:95
msgid "No excluded users found."
msgstr ""

#: includes/importers/cubepoints.php:114
#: includes/importers/cubepoints.php:119
msgid "Imported %s excluded users."
msgstr ""

#: includes/importers/cubepoints.php:129
#: includes/importers/cubepoints.php:134
msgid "Importing points hooks&hellip;"
msgstr ""

#: includes/importers/cubepoints.php:173
msgid "Imported %s points hooks."
msgstr ""

#: includes/importers/cubepoints.php:246
msgid "Importing users&apos; points&hellip;"
msgstr ""

#: includes/importers/cubepoints.php:156
#: includes/importers/cubepoints.php:273
msgid "Imported points for %s users&hellip;"
msgstr ""

#: includes/importers/cubepoints.php:205
#: includes/importers/cubepoints.php:322
msgid "CubePoints must be active."
msgstr ""

#: includes/importers/cubepoints.php:221
#: includes/importers/cubepoints.php:338
msgid "Importing points logs&hellip;"
msgstr ""

#: includes/importers/cubepoints.php:251
#: includes/importers/cubepoints.php:368
msgid "Imported %s points log entries."
msgstr ""

#: includes/importers/cubepoints.php:338
#: includes/importers/cubepoints.php:455
msgid "Unable to retrieve the logs from CubePoints&hellip;"
msgstr ""

Expand Down
Loading

0 comments on commit 4c58244

Please sign in to comment.