function dbRegexpSearch($table, $string, $only_in_ids = false, $only_in_those_table_fields = false) { $function_cache_id = serialize($table) . serialize($string) . serialize($only_in_ids); $function_cache_id = __FUNCTION__ . md5(__FUNCTION__ . $function_cache_id); $cache_content = $this->cacheGetContentAndDecode($function_cache_id); if ($cache_content != false) { return $cache_content; } $fields = $this->dbGetTableFields($table); if (!empty($only_in_those_table_fields)) { $fields = $only_in_those_table_fields; } //var_dump ( $fields ); //exit (); //var_dump($string, $string1, $string2, $stringg ); //exit; $q = "SELECT id FROM {$table} "; $where = false; if (!empty($fields)) { $where = " WHERE "; $string = str_replace("\\", ' ', $string); $string_array = explode('+', $string); $string = str_replace("+", ' ', $string); $string1 = string_cyr2lat($string); $string2 = string_lat2cyr($string); $string = mysql_real_escape_string($string); $string1 = mysql_real_escape_string($string1); $string2 = mysql_real_escape_string($string2); foreach ($fields as $item) { $where .= "{$item} REGEXP '{$string}' OR "; } if ($string2 != false) { foreach ($fields as $item) { $where .= "{$item} REGEXP '{$string2}' OR "; } } if ($string1 != false) { foreach ($fields as $item) { $where .= "{$item} REGEXP '{$string1}' OR "; } } $where .= " id='fake id' OR "; $where .= " id REGEXP '{$string}' "; if (!empty($string_array)) { $where = $where . " OR "; foreach ($string_array as $string) { $string = str_replace("\\", ' ', $string); $string1 = string_cyr2lat($string); $string2 = string_lat2cyr($string); $string = mysql_real_escape_string($string); $string1 = mysql_real_escape_string($string1); $string2 = mysql_real_escape_string($string2); foreach ($fields as $item) { $where .= "{$item} REGEXP '{$string}' OR "; } if ($string2 != false) { foreach ($fields as $item) { $where .= "{$item} REGEXP '{$string2}' OR "; } } if ($string1 != false) { foreach ($fields as $item) { $where .= "{$item} REGEXP '{$string1}' OR "; } } } $where .= " id IS NULL "; } } if ($where != false) { $q = $q . $where; } if (!empty($only_in_ids)) { $ids_q = implode(',', $only_in_ids); $q = $q . "and id in ({$ids_q}) "; } $q = $q . " group by id limit 0,100 "; //print $q; //exit; $result = $this->dbQuery($q); if (empty($result)) { return false; } else { $ids = array(); foreach ($result as $item) { if (!empty($only_in_ids)) { if (in_array($item['id'], $only_in_ids) == true) { $ids[] = $item['id']; } } else { $ids[] = $item['id']; } } } $ids = array_unique($ids); if (!empty($ids)) { $this->cacheWriteAndEncode($ids, $function_cache_id, $cache_group = 'global'); return $ids; } else { return false; } }
/** * @desc Generate unique content URL for post by specifying the id and the titile * @param the_id * @param the_content_title * @return string * @author Peter Ivanov * @version 1.0 * @since Version 1.0 */ function contentGenerateUniqueUrlTitleFromContentTitle($the_id, $the_content_title, $the_content_url_overide = false) { global $cms_db_tables; CI::helper('url'); if ($the_content_url_overide != false) { $the_content_url_overide = $the_content_url_overide; } $table = $cms_db_tables['table_content']; $the_content_title = trim($the_content_title); $the_content_title = mb_strtolower($the_content_title); //var_dump($the_content_title); if (function_exists('string_cyr2lat')) { $the_content_title = string_cyr2lat($the_content_title); } $the_id = intval($the_id); if (intval($the_id) != 0) { $q = "SELECT content_url, content_title from {$table} where id='{$data_to_save['id']}' "; $q = CI::model('core')->dbQuery($q); $thecontent_url = $q[0]['content_url']; $the_new_content_url = CI::model('core')->url_title($the_content_title, 'dash', true); $the_id = intval($the_id); $q = "SELECT content_url, content_title from {$table} where content_url='{$the_new_content_url}' and id!={$the_id} limit 0,1 "; $q = CI::model('core')->dbQuery($q); if (!empty($q)) { $the_new_content_url = $the_new_content_url . date("ymdhis"); } } else { $the_new_content_url = CI::model('core')->url_title($the_content_title, 'dash', true); $q = "SELECT content_url, content_title from {$table} where content_url='{$the_new_content_url}' limit 0,1 "; $q = CI::model('core')->dbQuery($q); if (!empty($q)) { $the_new_content_url = $the_new_content_url . date("ymdhis"); } } return $the_new_content_url; }