/** * Add / Edit / Update / Copy an entry. * * @access private * @deprecated * @param (array) $data * @param (string) $action * @return (bool) */ function processEntry($data, $action) { // If copying/editing an entry, the entry data is loaded into the class // properties and then properties are overwritten by the POST data as needed. if (isset($_GET['id'])) { $id = absint($_GET['id']); } switch ($action) { case 'add': return cnEntry_Action::add($data); break; case 'copy': return cnEntry_Action::copy($id, $data); break; case 'update': return cnEntry_Action::update($id, $data); break; } }
/** * Delete entries in bulk. * * @access public * @since 0.7.8 * * @return void */ public static function deleteEntryBulk() { /* * Check whether the current user delete an entry. */ if (current_user_can('connections_delete_entry')) { // @TODO $POST['id'] should be passed to the method as an attribute. if (!isset($_POST['id']) || empty($_POST['id'])) { return; } cnEntry_Action::delete($_POST['id']); cnMessage::set('success', 'form_entry_delete_bulk'); } else { cnMessage::set('error', 'capability_delete'); } }
/** * Save the player. */ public function save(&$Error = null) { global $connections; // Determine if this is a new or existing player $entryId = $this->entry->getId(); if ($entryId == null) { if ($this->entry->save()) { // Retrieve the entry from Connections (again) $entryId = $connections->lastInsertID; } else { // There was a problem saving $Error = $connections->lastQueryError; print 'An error occurred. ' . $Error; exit; return false; } } else { if ($this->entry->update() === false) { // There was a problem saving global $wpdb; $Error = $wpdb->last_error; print 'An error occurred with ' . $this->entry->getName() . ': ' . $Error; exit; return false; } } $cnRetrieve = $connections->retrieve; $entry = $cnRetrieve->entry($entryId); $this->entry = new cnEntry($entry); $this->entry->setEntryType($entry->entry_type); // Handle meta data if ($this->meta !== null) { // Initialize the add and update arrays $add = array(); $update = array(); // Load existing meta for IDs $lookup = array(); $existing = $this->entry->getMeta(); if (is_array($existing)) { foreach ($existing as $key => $value) { $lookup[$key] = $value; } } // Build the update and add arrays foreach ($this->meta as $key => $value) { if (isset($lookup[$key])) { $update[] = array('key' => $key, 'value' => $value); } else { $add[] = array('key' => $key, 'value' => $value); } } // Save the meta data if (count($add)) { cnEntry_Action::meta('add', $this->entry->getId(), $add); } if (count($update)) { cnEntry_Action::meta('update', $this->entry->getId(), $update); } } return true; }
/** * Delete the entry. * * @access public * @since Unknown * * @param int $id The entry ID. */ public function delete($id) { /** * @var connectionsLoad $connections * @var wpdb $wpdb */ global $wpdb, $connections; do_action('cn_delete-entry', $this); do_action('cn_process_delete-entry', $this); // KEEP! This action must exist for Link, however, do not ever use it! // Get the core WP uploads info. // $uploadInfo = wp_upload_dir(); // The entry slug is saved in the db URL encoded, so it needs to be decoded. $slug = rawurldecode($this->getSlug()); // Ensure the entry slug is not empty in case a user added an entry with no name. // If this check is not done all the images in the CN_IMAGE_DIR_NAME will be deleted // by cnFileSystem::xrmdir() which would be very bad, indeed. if (!empty($slug)) { // Build path to the subfolder in which all the entry's images are saved. $path = CN_IMAGE_PATH . $slug . DIRECTORY_SEPARATOR; // Delete the entry image and its variations. cnEntry_Action::deleteImages($this->getImageNameOriginal(), $slug); // Delete any legacy images, pre 8.1, that may exist. cnEntry_Action::deleteLegacyImages($this); // Delete the entry logo. cnEntry_Action::deleteImages($this->getLogoName(), $slug); // Delete logo the legacy logo, pre 8.1. cnEntry_Action::deleteLegacyLogo($this); // Delete the entry subfolder from CN_IMAGE_DIR_NAME. cnFileSystem::xrmdir($path); } $wpdb->query($wpdb->prepare('DELETE FROM ' . CN_ENTRY_TABLE . ' WHERE id = %d', $id)); /** * * * @TODO Only delete the addresses if deleting the entry was successful */ $wpdb->query($wpdb->prepare('DELETE FROM ' . CN_ENTRY_ADDRESS_TABLE . ' WHERE entry_id = %d', $id)); /** * * * @TODO Only delete the phone numbers if deleting the entry was successful */ $wpdb->query($wpdb->prepare('DELETE FROM ' . CN_ENTRY_PHONE_TABLE . ' WHERE entry_id = %d', $id)); /** * * * @TODO Only delete the email addresses if deleting the entry was successful */ $wpdb->query($wpdb->prepare('DELETE FROM ' . CN_ENTRY_EMAIL_TABLE . ' WHERE entry_id = %d', $id)); /** * * * @TODO Only delete the IM IDs if deleting the entry was successful */ $wpdb->query($wpdb->prepare('DELETE FROM ' . CN_ENTRY_MESSENGER_TABLE . ' WHERE entry_id = %d', $id)); /** * * * @TODO Only delete the social network IDs if deleting the entry was successful */ $wpdb->query($wpdb->prepare('DELETE FROM ' . CN_ENTRY_SOCIAL_TABLE . ' WHERE entry_id = %d', $id)); /** * * * @TODO Only delete the links if deleting the entry was successful */ $wpdb->query($wpdb->prepare('DELETE FROM ' . CN_ENTRY_LINK_TABLE . ' WHERE entry_id = %d', $id)); /** * * * @TODO Only delete the dates if deleting the entry was successful */ $wpdb->query($wpdb->prepare('DELETE FROM ' . CN_ENTRY_DATE_TABLE . ' WHERE entry_id = %d', $id)); /** * * * @TODO Only delete the category relationships if deleting the entry was successful */ $connections->term->deleteTermRelationships($id); do_action('cn_deleted-entry', $this); }
/** * Save the doubles team. */ public function save(&$Error = null) { // Load existing data $this->load(); // Determine if we are creating or updating if (isset($this->cnData->id)) { // Use the existing entry $entry = new cnEntry($this->cnData); $entry->setEntryType($this->cnData->entry_type); } else { // Initialize the new entry $entry = new cnEntry(); $entry->setFamilyName($this->familyName); $entry->setEntryType('family'); $entry->setVisibility('private'); $entry->setStatus('approved'); // Add the family members $family = array(); foreach ($this->familyMembers as $player) { $id = $player->getId(); if (!$id) { $player->save(); $id = $player->getId(); } $family[] = array('entry_id' => $id, 'relation' => 'partner'); } $entry->setFamilyMembers($family); // Save the entry if ($entry->save() && $this->getId() === null) { global $connections; $this->cnData->id = $connections->lastInsertID; $isNew = true; } else { $isNew = false; } // Update meta data $meta = array(); foreach ($this->cnMeta as $name => $value) { $meta[] = array('key' => $name, 'value' => $value); } if (count($meta)) { cnEntry_Action::meta($isNew ? 'add' : 'update', $this->getId(), $meta); } } return true; }