File "provider_operations.class.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/unlimited-elements-for-elementor/provider/provider_operations.class.php
File
size: 6.22 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
class ProviderOperationsUC extends UCOperations
{
private function getSearchFromData($data)
{
$type = UniteFunctionsUC::getVal($data, "_type");
if ($type != "query") {
return null;
}
$searchTerm = UniteFunctionsUC::getVal($data, "q");
return $searchTerm;
}
public function getSelect2TermsTitles($data)
{
$arrIDs = UniteFunctionsUC::getVal($data, "post_ids");
if (empty($arrIDs)) {
return null;
}
if (is_string($arrIDs)) {
$arrIDs = explode(",", $arrIDs);
}
$firstID = $arrIDs[0];
if (is_numeric($firstID) == false) {
$args = array("slug" => $arrIDs);
} else {
$args = array("include" => $arrIDs);
}
$response = get_terms($args);
if (empty($response)) {
return null;
}
$output = array();
foreach ($response as $term) {
$termID = $term->term_id;
$title = $term->name;
$taxonomy = $term->taxonomy;
$title .= " ({$taxonomy})";
$item = array();
$item["id"] = $termID;
$item["text"] = $title;
$output[] = $item;
}
return $output;
}
public function getSelect2PostTitles($data)
{
$arrIDs = UniteFunctionsUC::getVal($data, "post_ids");
$arrTypesAssoc = UniteFunctionsWPUC::getPostTypesAssoc(array(), true);
if (empty($arrIDs)) {
return null;
}
$response = UniteFunctionsWPUC::getPostTitlesByIDs($arrIDs);
if (empty($response)) {
return null;
}
$output = array();
foreach ($response as $record) {
$id = UniteFunctionsUC::getVal($record, "id");
$title = UniteFunctionsUC::getVal($record, "title");
$postType = UniteFunctionsUC::getVal($record, "type");
$typeTitle = UniteFunctionsUC::getVal($arrTypesAssoc, $postType);
if (empty($typeTitle)) {
$typeTitle = $postType;
}
$title .= " ({$typeTitle})";
$item = array();
$item["id"] = $id;
$item["text"] = $title;
$output[] = $item;
}
return $output;
}
public function getTermsListForSelectFromData($data)
{
$limit = 10;
$search = $this->getSearchFromData($data);
$taxonomy = UniteFunctionsUC::getVal($data, "taxonomy");
$query = array();
$query["number"] = $limit;
$query["search"] = $search;
if (!empty($taxonomy)) {
$query["taxonomy"] = $taxonomy;
}
$response = get_terms($query);
if (empty($response) && count($search) == 1) {
unset($query["search"]);
$response = get_terms($query);
}
if (empty($response)) {
return null;
}
$arrResult = array();
foreach ($response as $term) {
$termID = $term->term_id;
$name = $term->name;
$taxonomy = $term->taxonomy;
$title = $name . " - ({$taxonomy})";
$arr = array();
$arr["id"] = $termID;
$arr["text"] = $title;
$arrResult[] = $arr;
}
$arrOutput = array();
$arrOutput["results"] = $arrResult;
$arrOutput["pagination"] = array("more" => false);
return $arrOutput;
}
public function getPostListForSelectFromData($data, $addNotSelected = false, $limit = 10)
{
$search = $this->getSearchFromData($data);
$filterPostType = UniteFunctionsUC::getVal($data, "post_type");
switch ($filterPostType) {
case "product":
$arrTypesAssoc = array("product" => __("Product", "unlimited-elements-for-elementor"));
break;
case "elementor_template":
$arrTypesAssoc = array("elementor_library" => __("Template", "unlimited-elements-for-elementor"));
break;
default:
$arrTypesAssoc = UniteFunctionsWPUC::getPostTypesAssoc(array(), true);
break;
}
$arrPostTypes = array_keys($arrTypesAssoc);
$strPostTypes = implode("','", $arrPostTypes);
$strPostTypes = "'{$strPostTypes}'";
$db = HelperUC::getDB();
$tablePosts = UniteProviderFunctionsUC::$tablePosts;
$search = $db->escape($search);
$where = "post_type in ({$strPostTypes})";
$where .= " and post_status in ('publish','draft','private')";
$isStartWord = strlen($search) == 1;
$whereStartWord = $where . " and post_title like '{$search}%'";
$whereRegular = $where . " and post_title like '%{$search}%'";
$sqlStartWord = "select * from {$tablePosts} where {$whereStartWord} limit {$limit}";
$sql = "select * from {$tablePosts} where {$whereRegular} limit {$limit}";
if ($isStartWord == true) {
$response = $db->fetchSql($sqlStartWord);
if (empty($response)) {
$response = $db->fetchSql($sql);
}
} else {
$response = $db->fetchSql($sql);
}
if (empty($response)) {
return array();
}
$arrResult = array();
if ($addNotSelected == true) {
$arr = array();
$arr["id"] = 0;
$arr["text"] = __("[please select post]", "unlimited-elements-for-elementor");
$arrResult[] = $arr;
}
foreach ($response as $post) {
$postID = $post["ID"];
$postTitle = $post["post_title"];
$postType = $post["post_type"];
$postTypeTitle = UniteFunctionsUC::getVal($arrTypesAssoc, $postType);
if (empty($postTypeTitle)) {
$postTypeTitle = $postType;
}
$title = $postTitle . " - ({$postTypeTitle})";
$arr = array();
$arr["id"] = $postID;
$arr["text"] = $title;
$arrResult[] = $arr;
}
$arrOutput = array();
$arrOutput["results"] = $arrResult;
$arrOutput["pagination"] = array("more" => false);
return $arrOutput;
}
}