コード例 #1
0
ファイル: inc.processes.php プロジェクト: realfluid/umbaugh
/**
 * Add or edit and entry.
 * 
 * @param array $data
 * @param string $action
 * @return bool
 */
function processEntry($data, $action)
{
	global $wpdb, $connections;
	$entry = new cnEntry();
	
	//if ( isset($_GET['action']) ) $action = $_GET['action'];
	
	// The modification file date that image will be deleted. to maintain compatibility with 0.6.2.1 and older.
	$compatiblityDate = mktime(0, 0, 0, 6, 1, 2010);
	
	// 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']) )
	{
		$entry->set(esc_attr($_GET['id']));
	}
						
	if ( isset($data['entry_type']) ) $entry->setEntryType($data['entry_type']);
	if ( isset($data['family_name']) ) $entry->setFamilyName($data['family_name']);
	if ( isset($data['family_member']) ) $entry->setFamilyMembers($data['family_member']);
	if ( isset($data['honorific_prefix']) ) $entry->setHonorificPrefix($data['honorific_prefix']);
	if ( isset($data['first_name']) ) $entry->setFirstName($data['first_name']);
	if ( isset($data['middle_name']) ) $entry->setMiddleName($data['middle_name']);
	if ( isset($data['last_name']) ) $entry->setLastName($data['last_name']);
	if ( isset($data['honorific_suffix']) ) $entry->setHonorificSuffix($data['honorific_suffix']);
	if ( isset($data['title']) ) $entry->setTitle($data['title']);
	if ( isset($data['organization']) ) $entry->setOrganization($data['organization']);
	if ( isset($data['department']) ) $entry->setDepartment($data['department']);
	if ( isset($data['contact_first_name']) ) $entry->setContactFirstName($data['contact_first_name']);
	if ( isset($data['contact_last_name']) ) $entry->setContactLastName($data['contact_last_name']);
	if ( isset($data['address']) ) $entry->setAddresses($data['address']);
	if ( isset($data['phone_numbers']) ) $entry->setPhoneNumbers($data['phone_numbers']);
	if ( isset($data['email']) ) $entry->setEmailAddresses($data['email']);
	if ( isset($data['im']) ) $entry->setIm($data['im']);
	if ( isset($data['social_media']) ) $entry->setSocialMedia($data['social_media']);
	if ( isset($data['website']) ) $entry->setWebsites($data['website']);
	if ( isset($data['birthday_day']) && isset($data['birthday_month']) ) $entry->setBirthday($data['birthday_day'], $data['birthday_month']);
	if ( isset($data['anniversary_day']) && isset($data['anniversary_month']) ) $entry->setAnniversary($data['anniversary_day'], $data['anniversary_month']);
	if ( isset($data['bio']) ) $entry->setBio($data['bio']);
	if ( isset($data['notes']) ) $entry->setNotes($data['notes']);
	if ( isset($data['visibility']) ) $entry->setVisibility($data['visibility']);
	
	
	/*
	 * Process the logo upload --> START <--
	 */
	if ($_FILES['original_logo']['error'] != 4)
	{
		// If an entry is being updated and a new logo is uploaded, the old logo needs to be deleted.
		if ($entry->getLogoName() != NULL)
		{
			unlink( CN_IMAGE_PATH . $entry->getLogoName() );
		}
		
		// Process the newly uploaded logo.
		$logoProcessResults = processLogo();
		
		// If there were no errors processing the logo, set the values.
		if ($logoProcessResults)
		{
			$entry->setLogoLinked(TRUE);
			$entry->setLogoDisplay(TRUE);
			$entry->setLogoName( $logoProcessResults['name'] );
		}
		else
		{
			$entry->setLogoLinked(FALSE);
			$entry->setLogoDisplay(FALSE);
		}
	}
	else
	{
		// Don't do this if an entry is being updated.
		if ( $action !== 'update' )
		{
			// If an entry is being copied and there is a logo, the logo will be duplicated for the new entry.
			// That way if an entry is deleted, only the entry specific logo will be deleted.
			if ($entry->getLogoName() != NULL) $entry->setLogoName( copyImage( $entry->getLogoName() ) );
		}
	}
	/*
	 * Process the logo upload --> END <--
	 */
	
	/*
	 * If copying an entry, the logo visibility property is set based on the user's choice.
	 * NOTE: This must come after the logo processing.
	 */
	if (isset($data['logoOptions']))
	{
		switch ($data['logoOptions'])
		{
			case 'remove':
				$entry->setLogoDisplay(FALSE);
				$entry->setLogoLinked(FALSE);
				
				/*
				 * Delete logo assigned to the entry.
				 */
				if ( is_file( CN_IMAGE_PATH . $entry->getLogoName() ) )
				{
					unlink( CN_IMAGE_PATH . $entry->getLogoName() );
				}
				
				$entry->setLogoName(NULL);
				
			break;
			
			case 'hidden':
				$entry->setLogoDisplay(FALSE);
			break;
			
			case 'show':
				$entry->setLogoDisplay(TRUE);
			break;
			
			default:
				$entry->setLogoDisplay(FALSE);
			break;
		}
	}
	
	
	
	
	// Process the entry image upload.						
	if ($_FILES['original_image']['error'] != 4)
	{
		// If an entry is being updated and a new image is uploaded, the old images need to be deleted.
		if ($entry->getImageNameOriginal() != NULL)
		{
			if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameOriginal() ) )
			{
				unlink( CN_IMAGE_PATH . $entry->getImageNameOriginal() );
			}
		}
		
		if ($entry->getImageNameThumbnail() != NULL)
		{
			if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameThumbnail() ) )
			{
				unlink( CN_IMAGE_PATH . $entry->getImageNameThumbnail() );
				
			}
		}
		
		if ($entry->getImageNameCard() != NULL)
		{
			if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameCard() ) )
			{
				unlink( CN_IMAGE_PATH . $entry->getImageNameCard() );
			}
		}
		
		if ($entry->getImageNameProfile() != NULL)
		{
			if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameProfile() ) )
			{
				unlink( CN_IMAGE_PATH . $entry->getImageNameProfile() );
			}
		}
		
		// Process the newly uploaded image.
		$image_proccess_results = processImages();
		
		// If there were no errors processing the image, set the values.
		if ($image_proccess_results)
		{
			$entry->setImageLinked(true);
			$entry->setImageDisplay(true);
			$entry->setImageNameThumbnail($image_proccess_results['image_names']['thumbnail']);
			$entry->setImageNameCard($image_proccess_results['image_names']['entry']);
			$entry->setImageNameProfile($image_proccess_results['image_names']['profile']);
			$entry->setImageNameOriginal($image_proccess_results['image_names']['original']);
		}
		else
		{
			$entry->setImageLinked(false);
			$entry->setImageDisplay(false);
		}
	}
	else
	{
		// Don't do this if an entry is being updated.
		if ( $action !== 'update' )
		{
			// If an entry is being copied and there is an image, the image will be duplicated for the new entry.
			// That way if an entry is deleted, only the entry specific images will be deleted.
			if ($entry->getImageNameOriginal() != NULL) $entry->setImageNameOriginal( copyImage( $entry->getImageNameOriginal() ) );
			if ($entry->getImageNameThumbnail() != NULL) $entry->setImageNameThumbnail( copyImage( $entry->getImageNameThumbnail() ) );
			if ($entry->getImageNameCard() != NULL) $entry->setImageNameCard( copyImage( $entry->getImageNameCard() ) );
			if ($entry->getImageNameProfile() != NULL) $entry->setImageNameProfile( copyImage( $entry->getImageNameProfile() ) );
		}
	}
	
	
	// If copying an entry, the image visibility property is set based on the user's choice.
	// NOTE: This must come after the image processing.
	if (isset($data['imgOptions']))
	{
		switch ($data['imgOptions'])
		{
			case 'remove':
				$entry->setImageDisplay(false);
				$entry->setImageLinked(false);
				
				/*
				 * Delete images assigned to the entry.
				 * 
				 * Versions previous to 0.6.2.1 did not not make a duplicate copy of images when
				 * copying an entry so it was possible multiple entries could share the same image.
				 * Only images created after the date that version .0.7.0.0 was released will be deleted,
				 * plus a couple weeks for good measure.
				 */
				
				
				if ( is_file( CN_IMAGE_PATH . $entry->getImageNameOriginal() ) )
				{
					if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameOriginal() ) )
					{
						unlink( CN_IMAGE_PATH . $entry->getImageNameOriginal() );
					}
				}
				
				if ( is_file( CN_IMAGE_PATH . $entry->getImageNameThumbnail() ) )
				{
					if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameThumbnail() ) )
					{
						unlink( CN_IMAGE_PATH . $entry->getImageNameThumbnail() );
						
					}
				}
				
				if ( is_file( CN_IMAGE_PATH . $entry->getImageNameCard() ) )
				{
					if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameCard() ) )
					{
						unlink( CN_IMAGE_PATH . $entry->getImageNameCard() );
					}
				}
				
				if ( is_file( CN_IMAGE_PATH . $entry->getImageNameProfile() ) )
				{
					if ( $compatiblityDate < filemtime( CN_IMAGE_PATH . $entry->getImageNameProfile() ) )
					{
						unlink( CN_IMAGE_PATH . $entry->getImageNameProfile() );
					}
				}
				
				$entry->setImageNameOriginal(NULL);
				$entry->setImageNameThumbnail(NULL);
				$entry->setImageNameCard(NULL);
				$entry->setImageNameProfile(NULL);
				
			break;
			
			case 'hidden':
				$entry->setImageDisplay(false);
			break;
			
			case 'show':
				$entry->setImageDisplay(true);
			break;
			
			default:
				$entry->setImageDisplay(false);
			break;
		}
	}
	
	switch ($action)
	{
		case 'add':
			if ($entry->save() == FALSE)
			{
				$connections->setErrorMessage('entry_added_failed');
				return FALSE;
			}
			else
			{
				$connections->setSuccessMessage('entry_added');
				$entryID = (int) $connections->lastInsertID;
			}
		break;
		
		case 'update':
			if ($entry->update() == FALSE)
			{
				$connections->setErrorMessage('entry_updated_failed');
				return FALSE;
			}
			else
			{
				$connections->setSuccessMessage('entry_updated');
				$entryID = (int) $entry->getId();
			}
		break;
	}
	
	/*
	 * Save the entry category(ies). If none were checked, send an empty array
	 * which will add the entry to the default category.
	 */	
	if ( isset($data['entry_category']) )
	{
		$connections->term->setTermRelationships($entryID, $data['entry_category'], 'category');
	}
	else
	{
		$connections->term->setTermRelationships($entryID, array(), 'category');
	}
		
	unset($entry);
	return TRUE;
	
}
コード例 #2
0
 /**
  * Add / Edit / Copy an entry.
  *
  * @access private
  * @since  0.7.8
  *
  * @uses   absint()
  *
  * @param  string $action Valid options are: add | update
  * @param  array  $data [optional] The data to be used when adding / editing / duplicating an entry.
  * @param  int    $id [optional] If editing/duplicating an entry, the entry ID.
  *
  * @return bool
  */
 private static function process($action, $data = array(), $id = 0)
 {
     global $connections;
     /** @var cnEntry $entry */
     $entry = new cnEntry();
     // If copying/editing an entry, the entry data is loaded into the class
     // properties and then properties are overwritten by the data as needed.
     if (!empty($id)) {
         $entry->set(absint($id));
     }
     if (isset($data['entry_type'])) {
         $entry->setEntryType($data['entry_type']);
     }
     if (isset($data['family_name'])) {
         $entry->setFamilyName($data['family_name']);
     }
     isset($data['family_member']) ? $entry->setFamilyMembers($data['family_member']) : $entry->setFamilyMembers(array());
     if (isset($data['honorific_prefix'])) {
         $entry->setHonorificPrefix($data['honorific_prefix']);
     }
     if (isset($data['first_name'])) {
         $entry->setFirstName($data['first_name']);
     }
     if (isset($data['middle_name'])) {
         $entry->setMiddleName($data['middle_name']);
     }
     if (isset($data['last_name'])) {
         $entry->setLastName($data['last_name']);
     }
     if (isset($data['honorific_suffix'])) {
         $entry->setHonorificSuffix($data['honorific_suffix']);
     }
     if (isset($data['title'])) {
         $entry->setTitle($data['title']);
     }
     if (isset($data['organization'])) {
         $entry->setOrganization($data['organization']);
     }
     if (isset($data['department'])) {
         $entry->setDepartment($data['department']);
     }
     if (isset($data['contact_first_name'])) {
         $entry->setContactFirstName($data['contact_first_name']);
     }
     if (isset($data['contact_last_name'])) {
         $entry->setContactLastName($data['contact_last_name']);
     }
     isset($data['address']) ? $entry->setAddresses($data['address']) : $entry->setAddresses(array());
     isset($data['phone']) ? $entry->setPhoneNumbers($data['phone']) : $entry->setPhoneNumbers(array());
     isset($data['email']) ? $entry->setEmailAddresses($data['email']) : $entry->setEmailAddresses(array());
     isset($data['im']) ? $entry->setIm($data['im']) : $entry->setIm(array());
     isset($data['social']) ? $entry->setSocialMedia($data['social']) : $entry->setSocialMedia(array());
     //( isset($data['website']) ) ? $entry->setWebsites($data['website']) : $entry->setWebsites( array() );
     isset($data['link']) ? $entry->setLinks($data['link']) : $entry->setLinks(array());
     isset($data['date']) ? $entry->setDates($data['date']) : $entry->setDates(array());
     if (isset($data['birthday_day']) && isset($data['birthday_month'])) {
         $entry->setBirthday($data['birthday_day'], $data['birthday_month']);
     }
     if (isset($data['anniversary_day']) && isset($data['anniversary_month'])) {
         $entry->setAnniversary($data['anniversary_day'], $data['anniversary_month']);
     }
     if (isset($data['bio'])) {
         $entry->setBio($data['bio']);
     }
     if (isset($data['notes'])) {
         $entry->setNotes($data['notes']);
     }
     if (isset($data['visibility'])) {
         $entry->setVisibility($data['visibility']);
     }
     isset($data['user']) ? $entry->setUser($data['user']) : $entry->setUser(0);
     switch ($action) {
         case 'add':
             // If the entry is being copied, the source slug needs copied because it is required
             // in order to copy the source entry images to the new entry.
             if (!empty($id)) {
                 $sourceEntrySlug = rawurldecode($entry->getSlug());
                 $entry->setSlug($entry->getName(array('format' => '%first%-%last%')));
                 // If a new entry is being added, set the unique slug.
             } else {
                 $entry->setSlug($entry->getName(array('format' => '%first%-%last%')));
             }
             break;
         case 'update':
             // If an entry is being edited, set the new slug, if a new slug was provided.
             if (isset($data['slug']) && $data['slug'] != $entry->getSlug()) {
                 $entry->setSlug($data['slug']);
             }
             break;
     }
     $slug = rawurldecode($entry->getSlug());
     // Run any registered filters before processing, passing the $entry object.
     // ? Should the logo, photo and category data be passed too?
     $entry = apply_filters('cn_pre_process_' . $action . '-entry', $entry, isset($data['entry_category']) ? $data['entry_category'] : array());
     /*
      * Process the logo upload --> START <--
      */
     if (isset($_FILES['original_logo']) && $_FILES['original_logo']['error'] != 4) {
         // If an entry is being updated and a new logo is uploaded, the old logo needs to be deleted.
         // Delete the entry logo.
         self::deleteImages($entry->getLogoName(), $slug);
         // Delete logo the legacy logo, pre 8.1.
         self::deleteLegacyLogo($entry);
         // Process the newly uploaded image.
         $result = self::processLogo($slug);
         // If there were no errors processing the logo, set the values.
         if ($result) {
             $entry->setLogoLinked(TRUE);
             $entry->setLogoDisplay(TRUE);
             $entry->setLogoName($result['name']);
             $entry->setOriginalLogoMeta($result);
         } else {
             $entry->setLogoLinked(FALSE);
             $entry->setLogoDisplay(FALSE);
         }
     }
     // Don't do this if an entry is being updated.
     if ($action !== 'update') {
         // If an entry is being copied and there is a logo, the logo will be duplicated for the new entry.
         // That way if an entry is deleted, only the entry specific logo will be deleted.
         if ($entry->getLogoName() != NULL && (isset($sourceEntrySlug) && !empty($sourceEntrySlug))) {
             self::copyImages($entry->getLogoName(), $sourceEntrySlug, $slug);
         }
     }
     /*
      * If copying an entry, the logo visibility property is set based on the user's choice.
      * NOTE: This must come after the logo processing.
      */
     if (isset($data['logoOptions'])) {
         switch ($data['logoOptions']) {
             case 'remove':
                 $entry->setLogoDisplay(FALSE);
                 $entry->setLogoLinked(FALSE);
                 // Delete the entry image and its variations.
                 self::deleteImages($entry->getLogoName(), $slug);
                 // Delete logo the legacy logo, pre 8.1.
                 self::deleteLegacyLogo($entry);
                 $entry->setLogoName(NULL);
                 break;
             case 'hidden':
                 $entry->setLogoDisplay(FALSE);
                 break;
             case 'show':
                 $entry->setLogoDisplay(TRUE);
                 break;
             default:
                 $entry->setLogoDisplay(FALSE);
                 break;
         }
     }
     /*
      * Process the logo upload --> END <--
      */
     /*
      * Process the image upload. --> START <--
      */
     if (isset($_FILES['original_image']) && $_FILES['original_image']['error'] != 4) {
         // Delete the entry image and its variations.
         self::deleteImages($entry->getImageNameOriginal(), $slug);
         // Delete any legacy images, pre 8.1, that may exist.
         self::deleteLegacyImages($entry);
         // Process the newly uploaded image.
         $result = self::processImage($slug);
         // If there were no errors processing the image, set the values.
         if ($result) {
             $entry->setImageLinked(TRUE);
             $entry->setImageDisplay(TRUE);
             $entry->setImageNameOriginal($result['image_names']['original']);
             $entry->setOriginalImageMeta($result['image']['original']['meta']);
         } else {
             $entry->setImageLinked(FALSE);
             $entry->setImageDisplay(FALSE);
         }
     }
     // Don't do this if an entry is being updated.
     if ($action !== 'update') {
         // If an entry is being copied and there is an image, the image will be duplicated for the new entry.
         // That way if an entry is deleted, only the entry specific images will be deleted.
         if ($entry->getImageNameOriginal() != NULL && (isset($sourceEntrySlug) && !empty($sourceEntrySlug))) {
             self::copyImages($entry->getImageNameOriginal(), $sourceEntrySlug, $slug);
         }
     }
     // If copying an entry, the image visibility property is set based on the user's choice.
     // NOTE: This must come after the image processing.
     if (isset($data['imgOptions'])) {
         switch ($data['imgOptions']) {
             case 'remove':
                 $entry->setImageDisplay(FALSE);
                 $entry->setImageLinked(FALSE);
                 // Delete the entry image and its variations.
                 self::deleteImages($entry->getImageNameOriginal(), $slug);
                 // Delete any legacy images, pre 8.1, that may exist.
                 self::deleteLegacyImages($entry);
                 $entry->setImageNameOriginal(NULL);
                 break;
             case 'hidden':
                 $entry->setImageDisplay(FALSE);
                 break;
             case 'show':
                 $entry->setImageDisplay(TRUE);
                 break;
             default:
                 $entry->setImageDisplay(FALSE);
                 break;
         }
     }
     /*
      * Process the image upload. --> END <--
      */
     switch ($action) {
         case 'add':
             // Set moderation status per role capability assigned to the current user.
             if (current_user_can('connections_add_entry')) {
                 $entry->setStatus('approved');
                 $messageID = 'entry_added';
             } elseif (current_user_can('connections_add_entry_moderated')) {
                 $entry->setStatus('pending');
                 $messageID = 'entry_added_moderated';
             } else {
                 $entry->setStatus('pending');
                 $messageID = 'entry_added_moderated';
             }
             // Save the entry to the database. On fail store error message.
             if ($entry->save() == FALSE) {
                 cnMessage::set('error', 'entry_added_failed');
                 return FALSE;
             } else {
                 cnMessage::set('success', $messageID);
                 $entryID = (int) $connections->lastInsertID;
                 $entry->setID($entryID);
             }
             break;
         case 'update':
             // Set moderation status per role capability assigned to the current user.
             if (current_user_can('connections_edit_entry')) {
                 if ($entry->getStatus() == 'pending' && current_user_can('connections_add_entry_moderated')) {
                     $entry->setStatus('pending');
                     $messageID = 'entry_updated_moderated';
                 } elseif ($entry->getStatus() == 'approved' && current_user_can('connections_add_entry_moderated')) {
                     $entry->setStatus('approved');
                     $messageID = 'entry_updated';
                 } elseif ($entry->getStatus() == 'pending' && current_user_can('connections_add_entry')) {
                     $entry->setStatus('approved');
                     $messageID = 'entry_updated';
                 } elseif ($entry->getStatus() == 'approved' && current_user_can('connections_add_entry')) {
                     $entry->setStatus('approved');
                     $messageID = 'entry_updated';
                 } else {
                     // $entry->setStatus( 'pending' );
                     // $messageID = 'entry_updated_moderated';
                     $messageID = 'entry_updated';
                 }
             } elseif (current_user_can('connections_edit_entry_moderated')) {
                 $entry->setStatus('pending');
                 $messageID = 'entry_updated_moderated';
             } else {
                 $entry->setStatus('pending');
                 $messageID = 'entry_updated_moderated';
             }
             // Update the entry to the database. On fail store error message.
             if ($entry->update() == FALSE) {
                 cnMessage::set('error', 'entry_updated_failed');
                 return FALSE;
             } else {
                 cnMessage::set('success', $messageID);
                 $entryID = (int) $entry->getId();
             }
             break;
     }
     do_action('cn_process_taxonomy-category', $action, $entryID);
     do_action('cn_process_meta-entry', $action, $entryID);
     // Refresh the cnEntry object with any updated taxonomy or meta data
     // that may have been added/updated via actions.
     $entry->set($entryID);
     // Run any registered post process actions.
     do_action("cn_post_process_{$action}-entry", $entry);
     return $entryID;
 }
コード例 #3
0
ファイル: doubles.php プロジェクト: mrjake79/my5280
 /**
  * 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;
 }