there is an error
add_action('admin_notices', function() {
$message = get_option('_wpcc_site_notice');
if($message) {
echo Utils::view('partials/alert')->with([
'message' => $message,
'type' => 'error'
])->render();
update_option('_wpcc_site_notice', false);
}
});
}
/**
* Get counts of URLs grouped by site ID and whether they are saved or not.
*
* @return array An array with keys being site IDs and values being an array containing post counts. Each value
* array has count_saved, count_updated, count_queue, count_deleted, count_other, count_total.
* These values are either integer or null.
*/
public function getUrlTableCounts() {
// If it is already found before, return it.
if(static::$urlCounts) return static::$urlCounts;
// Find URL counts
global $wpdb;
$tableUrls = Factory::databaseService()->getDbTableUrlsName();
$query = "SELECT t_total.post_id, count_saved, count_updated, count_queue, count_deleted,
(IFNULL(count_total, 0) - IFNULL(count_saved, 0) - IFNULL(count_queue, 0) - IFNULL(count_deleted, 0)) as count_other, count_total
FROM
(SELECT post_id, count(*) as count_total FROM {$tableUrls} GROUP BY post_id) t_total
LEFT JOIN (
SELECT post_id, count(*) as count_queue
FROM {$tableUrls}
WHERE saved_post_id IS NULL
AND is_saved = FALSE
GROUP BY post_id) t_queue ON t_total.post_id = t_queue.post_id
LEFT JOIN (
SELECT post_id, count(*) as count_saved
FROM {$tableUrls}
WHERE saved_post_id IS NOT NULL
AND is_saved = TRUE
GROUP BY post_id) t_saved ON t_total.post_id = t_saved.post_id
LEFT JOIN (
SELECT post_id, count(*) as count_updated
FROM {$tableUrls}
WHERE saved_post_id IS NOT NULL
AND is_saved = TRUE
AND update_count > 0
GROUP BY post_id) t_updated ON t_total.post_id = t_updated.post_id
LEFT JOIN (
SELECT post_id, count(*) as count_deleted
FROM {$tableUrls}
WHERE saved_post_id IS NULL
AND deleted_at IS NOT NULL
GROUP BY post_id) t_deleted ON t_total.post_id = t_deleted.post_id";
$results = $wpdb->get_results($query, ARRAY_A);
$data = [];
foreach($results as $result) {
// Get post id from current result
$currentPostId = $result["post_id"];
// Unset the post id
unset($result["post_id"]);
// Add the result to the data under post ID key.
$data[$currentPostId] = $result;
}
static::$urlCounts = $data;
return static::$urlCounts;
}
/*
* EDITOR BUTTONS
*/
private function getEditorButtonsMain() {
if(!$this->editorButtonsMain) $this->editorButtonsMain = [
$this->createButtonInfo(ShortCodeName::WCC_MAIN_TITLE, _wpcc("Prepared post title"), true),
$this->createButtonInfo(ShortCodeName::WCC_MAIN_EXCERPT, _wpcc("Prepared post excerpt"), true),
$this->createButtonInfo(ShortCodeName::WCC_MAIN_CONTENT, _wpcc("Main post content")),
$this->createButtonInfo(ShortCodeName::WCC_MAIN_LIST, _wpcc("List items")),
$this->createButtonInfo(ShortCodeName::WCC_MAIN_GALLERY, _wpcc("Gallery items")),
$this->createButtonInfo(ShortCodeName::WCC_SOURCE_URL, sprintf(_wpcc('Full URL of the target page. You can use this to reference the source page. E.g. Source'), '[' . ShortCodeName::WCC_SOURCE_URL .']')),
];
return $this->editorButtonsMain;
}
private function getEditorButtonsTitle() {
if(!$this->editorButtonsTitle) $this->editorButtonsTitle = [
$this->createButtonInfo(ShortCodeName::WCC_MAIN_TITLE, _wpcc("Original post title"), true),
];
return $this->editorButtonsTitle;
}
private function getEditorButtonsExcerpt() {
if(!$this->editorButtonsExcerpt) $this->editorButtonsExcerpt = [
$this->createButtonInfo(ShortCodeName::WCC_MAIN_TITLE, _wpcc("Prepared post title"), true),
$this->createButtonInfo(ShortCodeName::WCC_MAIN_EXCERPT, _wpcc("Original post excerpt"), true),
];
return $this->editorButtonsExcerpt;
}
private function getEditorButtonsList() {
if(!$this->editorButtonsList) $this->editorButtonsList = [
$this->createButtonInfo(ShortCodeName::WCC_LIST_ITEM_TITLE, _wpcc("List item title")),
$this->createButtonInfo(ShortCodeName::WCC_LIST_ITEM_CONTENT, _wpcc("List item content")),
$this->createButtonInfo(ShortCodeName::WCC_LIST_ITEM_POSITION, _wpcc("The position of the item.")),
];
return $this->editorButtonsList;
}
private function getEditorButtonsGallery() {
if(!$this->editorButtonsGallery) $this->editorButtonsGallery = [
$this->createButtonInfo(ShortCodeName::WCC_GALLERY_ITEM_URL, _wpcc("Gallery item URL"))
];
return $this->editorButtonsGallery;
}
private function getEditorButtonsOptionsBoxTemplates() {
if (!$this->editorButtonsOptionsBoxTemplates) {
$this->editorButtonsOptionsBoxTemplates = array_merge([
$this->createButtonInfo(ShortCodeName::WCC_ITEM, _wpcc("Found item"))
], $this->getEditorButtonsMain());
}
return $this->editorButtonsOptionsBoxTemplates;
}
/**
* @param string $code Short code without square brackets
* @param string $description Description for what the short code does
* @param bool $fresh True if a fresh instance should be returned. Otherwise, if the code created before,
* the previously-created instance will be returned.
* @return ShortCodeButton Short code button
*/
private function createButtonInfo($code, $description = '', $fresh = false) {
return ShortCodeButton::getShortCodeButton($code, $description, $fresh);
}
/**
* Get an array of all predefined short codes
* @return array An array of short codes with square brackets
*/
public function getPredefinedShortCodes() {
if(!$this->allPredefinedShortCodes) {
$combinedButtons = array_merge(
$this->getEditorButtonsMain(),
$this->getEditorButtonsTitle(),
$this->getEditorButtonsExcerpt(),
$this->getEditorButtonsList(),
$this->getEditorButtonsGallery()
);
$result = [];
foreach ($combinedButtons as $btn) {
/** @var ShortCodeButton $btn */
$result[] = $btn->getCodeWithBrackets();
}
$this->allPredefinedShortCodes = $result;
}
return $this->allPredefinedShortCodes;
}
/*
*
*/
/**
* Get single meta keys
*
* @return array An array of keys
*/
public function getSingleMetaKeys() {
return $this->singleMetaKeys;
}
}