' . sprintf( __('ERROR: %s', WP_GDPR_C_SLUG), __('Email Address is required.', WP_GDPR_C_SLUG) ) . '

' ); exit; } $this->setEmailAddress($emailAddress); } /** * @return array */ public static function getPossibleDataTypes() { return array('user', 'comment', 'woocommerce_order'); } /** * @param string $type * @return array */ private static function getOutputColumns($type = '') { $output = array(); switch ($type) { case 'user' : $output = array( __('Username', WP_GDPR_C_SLUG), __('Display Name', WP_GDPR_C_SLUG), __('Email Address', WP_GDPR_C_SLUG), __('Website', WP_GDPR_C_SLUG), __('Registered on', WP_GDPR_C_SLUG) ); break; case 'comment' : $output = array( __('Author', WP_GDPR_C_SLUG), __('Content', WP_GDPR_C_SLUG), __('Email Address', WP_GDPR_C_SLUG), __('IP Address', WP_GDPR_C_SLUG) ); break; case 'woocommerce_order' : $output = array( __('Order', WP_GDPR_C_SLUG), __('Email Address', WP_GDPR_C_SLUG), __('Name', WP_GDPR_C_SLUG), __('Address', WP_GDPR_C_SLUG), __('Postcode / ZIP', WP_GDPR_C_SLUG), __('City', WP_GDPR_C_SLUG) ); break; } $output['checkbox'] = ''; return $output; } /** * @param array $data * @param string $type * @param int $requestId * @return array */ private static function getOutputData($data = array(), $type = '', $requestId = 0) { $output = array(); $action = ''; switch ($type) { case 'user' : /** @var User $user */ foreach ($data as $user) { $request = DeleteRequest::getInstance()->getByTypeAndDataIdAndAccessRequestId($type, $user->getId(), $requestId); $output[$user->getId()] = array( $user->getUsername(), $user->getDisplayName(), $user->getEmailAddress(), $user->getWebsite(), $user->getRegisteredDate(), (($request === false) ? sprintf($action, $user->getId()) : ' ') ); } break; case 'comment' : /** @var Comment $comment */ foreach ($data as $comment) { $request = DeleteRequest::getInstance()->getByTypeAndDataIdAndAccessRequestId($type, $comment->getId(), $requestId); $output[$comment->getId()] = array( $comment->getAuthorName(), Helper::shortenStringByWords(wp_strip_all_tags($comment->getContent(), true), 5), $comment->getEmailAddress(), $comment->getIpAddress(), (($request === false) ? sprintf($action, $comment->getId()) : ' ') ); } break; case 'woocommerce_order' : /** @var WooCommerceOrder $woocommerceOrder */ foreach ($data as $woocommerceOrder) { $request = DeleteRequest::getInstance()->getByTypeAndDataIdAndAccessRequestId($type, $woocommerceOrder->getOrderId(), $requestId); $billingAddressTwo = $woocommerceOrder->getBillingAddressTwo(); $address = (!empty($billingAddressTwo)) ? sprintf('%s,
%s', $woocommerceOrder->getBillingAddressOne(), $billingAddressTwo) : $woocommerceOrder->getBillingAddressOne(); $output[$woocommerceOrder->getOrderId()] = array( sprintf('#%d', $woocommerceOrder->getOrderId()), $woocommerceOrder->getBillingEmailAddress(), sprintf('%s %s', $woocommerceOrder->getBillingFirstName(), $woocommerceOrder->getBillingLastName()), $address, $woocommerceOrder->getBillingPostCode(), $woocommerceOrder->getBillingCity(), (($request === false) ? sprintf($action, $woocommerceOrder->getOrderId()) : ' ') ); } break; } return $output; } /** * @param array $data * @param string $type * @param int $requestId * @return string */ public static function getOutput($data = array(), $type = '', $requestId = 0) { $output = ''; if (!empty($data)) { $output .= sprintf( '
', json_encode(array( 'type' => $type )) ); $output .= ''; $output .= ''; $output .= ''; $output .= ''; foreach (self::getOutputColumns($type) as $key => $column) { $class = (is_string($key)) ? $key : sanitize_title($column); $output .= sprintf('', $class, $column); } $output .= ''; $output .= ''; $output .= ''; foreach (self::getOutputData($data, $type, $requestId) as $id => $row) { $output .= sprintf('', $id); foreach ($row as $value) { $output .= sprintf('', $value); } $output .= ''; } $output .= ''; $output .= '
%s
%s
'; $output .= sprintf( '

', sprintf( __('Anonymise selected %s(s)', WP_GDPR_C_SLUG), str_replace('_', ' ', $type) ) ); $output .= '
'; } return $output; } /** * @return User[] */ public function getUsers() { global $wpdb; $output = array(); $query = "SELECT * FROM `" . $wpdb->users . "` WHERE `user_email` = %s"; $results = $wpdb->get_results($wpdb->prepare($query, $this->getEmailAddress())); if ($results !== null) { foreach ($results as $row) { $object = new User($row->ID); $output[] = $object; } } return $output; } /** * @return Comment[] */ public function getComments() { global $wpdb; $output = array(); $query = "SELECT * FROM " . $wpdb->comments . " WHERE `comment_author_email` = %s"; $results = $wpdb->get_results($wpdb->prepare($query, $this->getEmailAddress())); if ($results !== null) { foreach ($results as $row) { $object = new Comment(); $object->loadByRow($row); $output[] = $object; } } return $output; } /** * @return WooCommerceOrder[] */ public function getWooCommerceOrders() { global $wpdb; $output = array(); $query = "SELECT * FROM " . $wpdb->postmeta . " WHERE `meta_key` = '_billing_email' AND `meta_value` = %s"; $results = $wpdb->get_results($wpdb->prepare($query, $this->getEmailAddress())); if ($results !== null) { foreach ($results as $row) { $output[] = new WooCommerceOrder($row->post_id); } } return $output; } /** * @return string */ public function getEmailAddress() { return $this->emailAddress; } /** * @param string $emailAddress */ public function setEmailAddress($emailAddress) { $this->emailAddress = $emailAddress; } /** * @return null|Data */ public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new self(); } return self::$instance; } }