0) {
$this->setId($id);
$this->load();
}
}
/**
* @param bool $insertPrivacyPolicyLink
* @return mixed
*/
public static function getModalTitle($insertPrivacyPolicyLink = true) {
$output = get_option(WP_GDPR_C_PREFIX . '_settings_consents_modal_title');
if (empty($output)) {
$output = __('Privacy Settings', WP_GDPR_C_SLUG);
}
$output = ($insertPrivacyPolicyLink === true) ? Integration::insertPrivacyPolicyLink($output) : $output;
return apply_filters('wpgdprc_consents_modal_title', wp_kses($output, Helper::getAllowedHTMLTags()));
}
/**
* @param bool $insertPrivacyPolicyLink
* @return mixed
*/
public static function getModalExplanationText($insertPrivacyPolicyLink = true) {
$output = get_option(WP_GDPR_C_PREFIX . '_settings_consents_modal_explanation_text');
if (empty($output)) {
$output = __('This site uses functional cookies and external scripts to improve your experience. Which cookies and scripts are used and how they impact your visit is specified on the left. You may change your settings at any time. Your choices will not impact your visit.', WP_GDPR_C_SLUG);
}
$output = ($insertPrivacyPolicyLink === true) ? Integration::insertPrivacyPolicyLink($output) : $output;
return apply_filters('wpgdprc_consents_modal_explanation_text', wp_kses($output, Helper::getAllowedHTMLTags()));
}
/**
* @param bool $insertPrivacyPolicyLink
* @return mixed
*/
public static function getBarExplanationText($insertPrivacyPolicyLink = true) {
$output = get_option(WP_GDPR_C_PREFIX . '_settings_consents_bar_explanation_text');
if (empty($output)) {
$output = __('This site uses functional cookies and external scripts to improve your experience.', WP_GDPR_C_SLUG);
}
$output = ($insertPrivacyPolicyLink === true) ? Integration::insertPrivacyPolicyLink($output) : $output;
return apply_filters('wpgdprc_consents_bar_explanation_text', wp_kses($output, Helper::getAllowedHTMLTags()));
}
/**
* @param array $consents
* @return string
*/
public static function output($consents = array()) {
$output = '';
if (!empty($consents)) {
/** @var Consent $consent */
foreach ($consents as $consent) {
if ($consent->getWrap()) {
$output .= sprintf(
'',
$consent->getSnippet()
);
} else {
$output .= sprintf('%s', $consent->getSnippet());
}
}
}
return $output;
}
/**
* @param array $filters
* @return int
*/
public function getTotal($filters = array()) {
global $wpdb;
$query = "SELECT COUNT(`ID`) FROM `" . self::getDatabaseTableName() . "` WHERE 1";
$query .= Helper::getQueryByFilters($filters);
$query .= sprintf(" AND `site_id` = '%d'", get_current_blog_id());
$result = $wpdb->get_var($query);
if ($result !== null) {
return absint($result);
}
return 0;
}
/**
* @param array $filters
* @param int $limit
* @param int $offset
* @return Consent[]
*/
public function getList($filters = array(), $limit = 0, $offset = 0) {
global $wpdb;
$output = array();
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE 1";
$query .= Helper::getQueryByFilters($filters);
$query .= sprintf(" AND `site_id` = '%d'", get_current_blog_id());
$query .= " ORDER BY `date_modified` DESC";
if (!empty($limit)) {
$query .= " LIMIT $offset, $limit";
}
$results = $wpdb->get_results($query);
if ($results !== null) {
foreach ($results as $row) {
$object = new self;
$object->loadByRow($row);
$output[] = $object;
}
}
return $output;
}
/**
* @param $row
*/
private function loadByRow($row) {
$this->setId($row->ID);
$this->setSiteId($row->site_id);
$this->setTitle($row->title);
$this->setDescription($row->description);
$this->setSnippet($row->snippet);
$this->setWrap($row->wrap);
$this->setPlacement($row->placement);
$this->setPlugins($row->plugins);
$this->setRequired($row->required);
$this->setActive($row->active);
$this->setDateModified($row->date_modified);
$this->setDateCreated($row->date_created);
}
public function load() {
global $wpdb;
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d";
$row = $wpdb->get_row($wpdb->prepare($query, $this->getId()));
if ($row !== null) {
$this->loadByRow($row);
}
}
/**
* @param int $id
* @return bool
*/
public function exists($id = 0) {
global $wpdb;
$row = $wpdb->get_row(
$wpdb->prepare(
"SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d",
intval($id)
)
);
return ($row !== null);
}
/**
* @return bool|int
*/
public function save() {
global $wpdb;
$data = array(
'title' => $this->getTitle(),
'description' => $this->getDescription(),
'snippet' => $this->getSnippet(),
'wrap' => $this->getWrap(),
'placement' => $this->getPlacement(),
'plugins' => $this->getPlugins(),
'required' => $this->getRequired(),
'active' => $this->getActive(),
);
$dataTypes = array('%s', '%s', '%s', '%d', '%s', '%s', '%d', '%d');
if ($this->exists($this->getId())) {
$wpdb->update(
self::getDatabaseTableName(),
$data,
array('ID' => $this->getId()),
$dataTypes,
array('%d')
);
return $this->getId();
} else {
$data['site_id'] = $this->getSiteId();
$data['date_created'] = date_i18n('Y-m-d H:i:s');
$dataTypes = array_merge($dataTypes, array('%d', '%s', '%d'));
$result = $wpdb->insert(
self::getDatabaseTableName(),
$data,
$dataTypes
);
if ($result !== false) {
$this->setId($wpdb->insert_id);
return $this->getId();
}
}
return false;
}
/**
* @param int $id
* @return bool
*/
public function delete($id = 0) {
if ((int)$id > 0) {
global $wpdb;
$result = $wpdb->delete(self::getDatabaseTableName(), array('ID' => $id), array('%d'));
if ($result !== false) {
return true;
}
}
return false;
}
/**
* @param int $id
* @param string $action
* @return string
*/
public static function getActionUrl($id = 0, $action = 'manage') {
return Helper::getPluginAdminUrl(
'consents',
array(
'action' => $action,
'id' => $id,
)
);
}
/**
* @return array
*/
public static function getPossibleCodeWraps() {
return array(
'1' => esc_html__('Wrap my code snippet with