/** * Validates the class variables * * @access public * @global object $bp BuddyPress global settings * @global nxtdb $nxtdb NXTClass database object * @param DPA_Achievement $achievement The Achievement to validate * @param DPA_Achievement $old_achievement A copy of the Achievement which is about to be saved, for comparision purposes * @param nxt_Error $errors Holds any errors (by ref) * @since 2.0 * @static * @uses nxt_Error */ function validate_achievement_details($achievement, $old_achievement, &$errors) { global $bp, $nxtdb; $readonly_properties = array('id', 'is_active', 'action_count', 'action_id', 'achieved_at', 'site_id', 'group_id'); foreach ($achievement as $property => $value) { if (in_array($property, $readonly_properties)) { continue; } if (empty($value)) { if (is_int($value)) { $errors->add($property, __("This can't be zero.", 'dpa')); } else { $errors->add($property, __("This can't be blank.", 'dpa')); } } } $valid_action_ids = array(-1); // Badge $actions = dpa_get_actions(); foreach ($actions as $action) { $valid_action_ids[] = $action->id; } if (!in_array($achievement->action_id, $valid_action_ids)) { $errors->add('action_id', __("Choose an event.", 'dpa')); } if ($achievement->action_count < 0) { $errors->add('action_count', __("This needs to be at least one.", 'dpa')); } if (strlen($achievement->name) > 200) { $errors->add('name', __("This needs to be less than two hundred characters long.", 'dpa')); } if ($this->achievement_name_exists($achievement->name)) { $errors->add('name', __("The Achievement's name must be unique; this one is already in use.", 'dpa')); } if (empty($achievement->description)) { $errors->add('description', __("Missing Achievement description.", 'dpa')); } if (strlen($achievement->slug) > 200) { $errors->add('slug', __("This needs to be less than two hundred characters long.", 'dpa')); } $illegal_names = array_unique(array_merge((array) get_site_option("illegal_names"), apply_filters('validate_achievement_details_slug', array(DPA_SLUG, DPA_SLUG_CREATE, DPA_SLUG_MY_ACHIEVEMENTS, DPA_SLUG_ACHIEVEMENT_EDIT, DPA_SLUG_ACHIEVEMENT_DELETE, DPA_SLUG_ACHIEVEMENT_CHANGE_PICTURE, DPA_SLUG_ACHIEVEMENT_UNLOCKED_BY, DPA_SLUG_ACHIEVEMENT_GRANT)))); if ($achievement->slug && is_array($illegal_names) && in_array($achievement->slug, $illegal_names)) { $errors->add('slug', __("This slug conflicts with something important; please try another.", 'dpa')); } if ($this->achievement_slug_exists($achievement->slug)) { $errors->add('slug', __("The slug must be unique; this one is already in use.", 'dpa')); } }
/** * Returns the HTML for the actions dropdown box on the create/edit Achievement pages * * @since 2.0 * @global object $bp BuddyPress global settings * @return string * @todo Sort the option group labels alphabetically. */ function dpa_get_addedit_action_descriptions() { global $bp; $temp_actions = array(); $current_action_id = $bp->achievements->current_achievement->action_id; // Get the actions $actions = dpa_get_actions(); foreach ($actions as $action) { if (!isset($temp_actions[$action->category])) { $temp_actions[$action->category] = array(array('id' => $action->id, 'name' => $action->name, 'description' => $action->description, 'is_group_action' => (bool) $action->is_group_action)); } else { $temp_actions[$action->category][] = array('id' => $action->id, 'name' => $action->name, 'description' => $action->description, 'is_group_action' => (bool) $action->is_group_action); } } $actions = $temp_actions; // Get the option group titles $values = array(sprintf('<option value="0">%s</option>', __('----', 'dpa'))); foreach ($actions as $category => $category_actions) { $category_is_active = true; switch ($category) { // BP/nxt core case 'activitystream': $category_name = __('Activity Streams', 'dpa'); $category_is_active = bp_is_active('activity'); break; case 'blog': $category_name = __('Site', 'dpa'); break; case 'forum': $category_name = __('Forums', 'dpa'); $category_is_active = bp_is_active('forums'); break; case 'groups': $category_name = __('Groups', 'dpa'); $category_is_active = bp_is_active('groups'); break; case 'members': $category_name = __('Members', 'dpa'); $category_is_active = bp_is_active('friends'); break; case 'messaging': $category_name = __('Private Messaging', 'dpa'); $category_is_active = bp_is_active('messages'); break; case 'multisite': $category_name = __('NXTClass Multisite', 'dpa'); $category_is_active = is_multisite(); break; case 'profile': $category_name = __('Profile & Account', 'dpa'); $category_is_active = bp_is_active('xprofile'); break; // Plugins // Plugins case 'achievements': $category_name = __('Plugin: Achievements', 'dpa'); break; case 'bpmoderation': require_once ABSPATH . '/nxt-admin/includes/plugin.php'; $category_is_active = is_plugin_active('bp-moderation/bpModLoader.php'); $category_name = __('Plugin: BuddyPress Moderation', 'dpa'); break; case 'bpprivacy': $category_name = __("Plugin: BP-Privacy", 'dpa'); $category_is_active = defined('BP_PRIVACY_IS_INSTALLED'); break; case 'buddypresslinks': $category_name = __('Plugin: BuddyPress Links', 'dpa'); $category_is_active = is_plugin_active('buddypress-links/buddypress-links.php'); break; case 'buddystream': $category_name = __('Plugin: BuddyStream', 'dpa'); $category_is_active = defined('BP_BUDDYSTREAM_IS_INSTALLED'); break; case 'inviteanyone': $category_name = __('Plugin: Invite Anyone', 'dpa'); $category_is_active = defined('BP_INVITE_ANYONE_VER'); break; case 'eventpress': $category_name = __('Plugin: EventPress', 'dpa'); $category_is_active = defined('EP_BP'); break; case 'jes': $category_name = __('Plugin: Jet Event System for BuddyPress', 'dpa'); $category_is_active = defined('JES_EVENTS_VERSION'); break; default: $category_name = __('Other', 'dpa'); break; } // Make the <option> elements if (!($category_is_active = apply_filters('dpa_get_addedit_action_descriptions_category_is_active', $category_is_active, $category))) { continue; } $values[] = sprintf('<optgroup label="%s">', apply_filters('dpa_get_addedit_action_descriptions_category_name', $category_name, $category)); foreach ($category_actions as $category_action) { $selected = ''; $class = ''; if ($current_action_id == $category_action['id']) { $selected = ' selected="selected"'; } if ($category_action['is_group_action']) { $class = 'class="group"'; } $values[] = sprintf('<option %1$s value="%2$d"%3$s>%4$s</option>', $class, apply_filters('dpa_get_achievement_action_id', (int) $category_action['id']), $selected, apply_filters('dpa_get_addedit_action_description', $category_action['description'])); } $values[] = '</optgroup>'; } return implode('', apply_filters('dpa_get_addedit_action_descriptions', $values, $actions)); }