Архив

Архив Август 2017
30 августа 2017 Нет комментариев
mysql -u db_user -p -e "show full processlist" > ./out.txt

https://techglimpse.com/store-query-row-output-file-mysql/

Categories: MySQL Tags:
24 августа 2017 Нет комментариев

Для открытия в браузере:

header("Content-type:application/pdf");
header("Content-Disposition:inline;filename='agreement.pdf'");

Для скачивания:

header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename='agreement.pdf'");
Categories: PHP Tags:
23 августа 2017 Нет комментариев

Например, когда нужны маркеры разных цветов.
Параметр icon:

var marker=new google.maps.Marker({
	position:iLatlng,
	map:map,
	icon:'http://maps.google.com/mapfiles/ms/icons/green-dot.png',
	//icon:'http://maps.google.com/mapfiles/ms/icons/blue-dot.png',
	//icon:'http://maps.google.com/mapfiles/ms/icons/red-dot.png',
	title:'FullAddress'
});

Если нужно самому динамически указывать цвет:
http://www.googlemapsmarkers.com/v1/COLOR/
или
http://www.googlemapsmarkers.com/v1/LABEL/COLOR/
или
http://www.googlemapsmarkers.com/v1/LABEL/FILL COLOR/LABEL COLOR/STROKE COLOR/
подробнее: http://www.googlemapsmarkers.com/

var icon_green=new google.maps.MarkerImage("http://www.googlemapsmarkers.com/v1/C/008136/ffffff/008136/");
var marker=new google.maps.Marker({
	position:iLatlng,
	map:map,
	icon:icon_green,
	title:'FullAddress'
});
Categories: Javascript Tags:
14 августа 2017 Нет комментариев
systemctl enable mariadb.service

Для других служб аналогично.
Проверка:

systemctl list-unit-files | grep mariadb
Categories: Linux Tags: ,
8 августа 2017 Нет комментариев

При формировании XML:

$text=preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u',' ',$text);

Полная функция:

function prepare_to_xml($text){
	$text=preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u',' ',$text);
	$text=strip_tags($text);
	$text=htmlspecialchars($text);
	$text=str_replace("\t"," ",$text);
	$text=str_replace(" "," ",$text);
	$text=str_replace(" "," ",$text);
	$text=preg_replace("/[\r\n]+/i","",$text);
	$text=preg_replace('/ {2,}/',' ',$text);
	$text=trim($text);
	return $text;
}

Ну или просто:

function utf8_for_xml($string){
	return preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u',' ',$string);
}
Categories: PHP Tags: ,
3 августа 2017 Нет комментариев

Делаем экспорт каталога товаров имея дамп БД от Drupal.
В результате массив, который обрабатываем отталкиваясь от задачи.
Многие данные могут быть специфическими для конкретного проекта.

<?php
//config
$mysql=array(
	'host'=>'localhost',
	'user'=>'db_user',
	'password'=>'db_password',
	'database'=>'db_name',
);
mysql_connect($mysql['host'],$mysql['user'],$mysql['password']) or die ('error mysql_connect');
mysql_select_db($mysql['database']) or die ('error mysql_select_db');
mysql_query("set names 'utf8'");
//database functions
function get_from_base($what,$from,$where='(1)',$order='id'){
	if(trim($what)!=''&&trim($from)!=''&&trim($where)!=''&&trim($order)!=''){
		$arr=array();
		$query="select ".$what." from ".$from." where ".$where." order by ".$order;
		$result=mysql_query($query);
		echo mysql_error();
		if(mysql_num_rows($result)>0){
			while($tmp=mysql_fetch_assoc($result)){
				$arr[]=$tmp;
			}
			return $arr;
		}
	}else{
		return false;
	}
}
//work functions
function make_tree($term_data,$parent){
	$tree=array();
	foreach($term_data as $data){
		if($data['parent']==$parent){
			$data['childs']=make_tree($term_data,$data['tid']);
			$data['items']=get_products($data['tid']);
			$tree[]=$data;
		}
	}
	return $tree;
}
function get_products($tid){
	$products=array();
	$products_list=get_from_base('*','term_node',"`tid`='".$tid."'",'tid');
	if(count($products_list)>0){
		foreach($products_list as $product){
			$nodes_product=get_from_base('*','node','type="product" and `vid`='.$product['vid'].' and `nid`='.$product['nid'],'created');
			foreach($nodes_product as $p){
				$content_type_product=get_from_base('*','content_type_product',"`vid`='".$p['vid']."' AND `nid`='".$p['nid']."'",'vid');
				$node_revisions=get_from_base('*','node_revisions',"`vid`='".$p['vid']."' AND `nid`='".$p['nid']."'",'vid');
				$photos=array();
				$content_field_product_images=get_from_base('*','content_field_product_images',"`vid`='".$p['vid']."' AND `nid`='".$p['nid']."'",'vid');
				for($i=0;$i<=count($content_field_product_images)-1;$i++){
					$content_field_product_images[$i]['files']=get_from_base('*','files',"`fid`='".$content_field_product_images[$i]['field_product_images_fid']."'",'fid');
					foreach($content_field_product_images[$i]['files'] as $file){
						$photos[]=$file['filepath'];
					}
				}
				$sizes=array();
				$colors=array();
				$parent='';
				$brand='';
				$other=array();
				$term_node=get_from_base('*','term_node',"`vid`='".$p['vid']."' AND `nid`='".$p['nid']."'",'vid');
				for($i=0;$i<=count($term_node)-1;$i++){
					$term_node[$i]['term_data']=get_from_base('*','term_data',"`tid`='".$term_node[$i]['tid']."'",'tid');
					foreach($term_node[$i]['term_data'] as $term_data){
						switch($term_data['vid']){
							case 4:
								$sizes[]=$term_data['name'];
							break;
							case 3:
								$parent=$term_data['tid'];
							break;
							case 6:
								$brand=$term_data['name'];
							break;
							case 5:
								$colors[]=$term_data['name'];
							break;
							default:
								$other[]=$term_data['name'];
							break;
						}
					}
				}
				$url_alias=get_from_base('*','url_alias',"`src`='node/".$p['nid']."'",'pid');
				$products[]=array(
					'vid'=>$p['vid'],
					'nid'=>$p['nid'],
					'name'=>$p['title'],
					'price'=>$content_type_product[0]['field_product_price_value'],
					'discount'=>$content_type_product[0]['field_product_discount_value'],
					'price_discount'=>$content_type_product[0]['field_product_price_discount_value'],
					'price_opt'=>$content_type_product[0]['field_product_price_opt_value'],
					'male'=>$content_type_product[0]['field_product_male_value'],
					'female'=>$content_type_product[0]['field_product_female_value'],
					'sport'=>$content_type_product[0]['field_product_sport_value'],
					'child'=>$content_type_product[0]['field_product_child_value'],
					'winter_season'=>$content_type_product[0]['field_product_winter_season_value'],
					'spring_season'=>$content_type_product[0]['field_product_spring_season_value'],
					'summer_season'=>$content_type_product[0]['field_product_summer_season_value'],
					'autumn_season'=>$content_type_product[0]['field_product_autumn_season_value'],
					'new'=>$content_type_product[0]['field_product_new_value'],
					'popular'=>$content_type_product[0]['field_product_popular_value'],
					'notavailable'=>$content_type_product[0]['field_product_notavailable_value'],
					'type'=>$content_type_product[0]['field_product_type_value'],
					//'content_type_product'=>$content_type_product,
					'content'=>$node_revisions[0]['body'],
					//'node_revisions'=>$node_revisions,
					'photos'=>$photos,
					//'content_field_product_images'=>$content_field_product_images,
					'sizes'=>$sizes,
					'parent'=>$parent,
					'brand'=>$brand,
					'colors'=>$colors,
					'other'=>$other,
					//'term_node'=>$term_node,
					'url_alias'=>$url_alias[0]['dst'],
				);
			}
		}
	}
	return $products;
}
//work
$tree=array();
echo '<pre>';
	$term_data=array();
	$cats=get_from_base('*','term_data','vid=3','weight');
	foreach($cats as $cat){
		$url_alias=get_from_base('*','url_alias',"`src`='cat/".$cat['tid']."'",'pid');
		$term_data[$cat['tid']]=array(
			'tid'=>$cat['tid'],
			'name'=>$cat['name'],
			'parent'=>0,
			'url_alias'=>$url_alias[0]['dst'],
		);
	}
	$hierarchy=get_from_base('*','term_hierarchy','`tid` in (select `tid` from `term_data`)','tid');
	foreach($hierarchy as $h){
		if(is_array($term_data[$h['tid']])){
			$term_data[$h['tid']]['parent']=$h['parent'];
		}
	}
	$tree=make_tree($term_data,0);
	print_r($tree);
echo '</pre >';
Categories: CMS Tags: ,