Архив

Архив раздела ‘CMS’
9 ноября 2017 Нет комментариев

Используются плагины: AMP for WP – Accelerated Mobile Pages for WordPress, WP-GeSHi-Highlight.
Синтаксис внутри pre подсвечиваться конечно не будет.
В файл functions.php активной темы:
</pre > заменить на </pre> т.е. без пробела

function echapcode($a){
	return "<pre $a[1]>".htmlspecialchars($a[2])."</pre >";
}
$texte=preg_replace_callback('#<pre (.*?)>(.*?)</pre >#ius','echapcode',$text);
add_filter('the_content','new_pre_content');
function new_pre_content($content){
	if(function_exists('ampforwp_is_amp_endpoint')&&ampforwp_is_amp_endpoint()){
		$content=preg_replace_callback('#<pre (.*?)>(.*?)</pre >#ius','echapcode',$content);
	}
	return $content;
}
Categories: CMS, PHP Tags: ,
25 сентября 2017 Нет комментариев

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

<?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;
	}
}
function get_one_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($result){
			if(mysql_num_rows($result)>0){
				return mysql_fetch_assoc($result);
			}
		}
	}
	return false;
}
//work functions
function make_tree($parent,$parent_chpu=''){
	$tree=array();
	$cats=get_from_base('*','wp_term_taxonomy',"`taxonomy`='product_cat' AND `parent`='".$parent."'",'term_taxonomy_id');
	if(count($cats)>0){
		$cat_chpu=$parent_chpu;
		for($i=0;$i<=count($cats)-1;$i++){
			//$tree[$i]=$cats[$i];
			$tree[$i]=array(
				'wid'=>$cats[$i]['term_id'],
				'description'=>$cats[$i]['description'],
			);
			$term=get_one_from_base('*','wp_terms',"`term_id`='".$cats[$i]['term_id']."'",'term_id');
			if($term['term_id']){
				//$tree[$i]['term']=$term;
				$tree[$i]['name']=$term['name'];
				$tree[$i]['chpu']=urldecode($term['slug']);
				$cat_chpu=$parent_chpu.'/'.urldecode($term['slug']);
			}
			$tree[$i]['link']='/product-category'.$cat_chpu;
			$tree[$i]['childs']=make_tree($cats[$i]['term_taxonomy_id'],$cat_chpu);
			$tree[$i]['items']=get_products($cats[$i]['term_taxonomy_id'],$cat_chpu);
		}
	}
	return $tree;
}
function get_products($parent,$parent_chpu=''){
	$products=array();
	$relationships=get_from_base('*','wp_term_relationships',"`term_taxonomy_id`='".$parent."'",'object_id');
	if(count($relationships)>0){
		foreach($relationships as $i=>$object){
			$product=get_one_from_base('*','wp_posts','`post_type`="product" and `ID`='.$object['object_id'],'ID');
			$product['meta']=get_from_base('*','wp_postmeta','`post_id`="'.$object['object_id'].'"','meta_id');
			//$products[]=$product;
			$products[$i]=array(
				'wid'=>$product['ID'],
				'name'=>$product['post_title'],
				'announce'=>prepare_html($product['post_excerpt']),
				'content'=>prepare_html($product['post_content']),
				'chpu'=>urldecode($product['post_name']),
				'link'=>'/shop'.$parent_chpu.'/'.urldecode($product['post_name']),
				//'meta'=>$product['meta'],
			);
			if(count($product['meta'])>0){
				foreach($product['meta'] as $meta){
					if($meta['meta_value']){
						switch($meta['meta_key']){
							case '_price':
								$products[$i]['price']=$meta['meta_value'];
							break;
							case '_thumbnail_id':
								$photo=get_one_from_base('*','wp_posts','`ID`='.$meta['meta_value'],'ID');
								if($photo['ID']){
									$photo_url=parse_url($photo['guid']);
									$products[$i]['photo']=$photo_url['path'];
								}
							break;
							case '_sku':
								$products[$i]['part']=$meta['meta_value'];
							break;
						}
					}
				}
			}
		}
	}
	return $products;
}
function prepare_html($html){
	$html=str_replace("\r\n\r\n","</p><p>",$html);
	$html=str_replace("\r\n","<br/>",$html);
	return "<p>".$html."</p>";
}
//work
$tree=make_tree(0);
echo '<pre>';print_r($tree);echo '</pre >';
?>
Categories: CMS 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: ,
10 января 2017 Нет комментариев
echo '<ul>';
wp_list_categories('orderby=order&title_li=');
echo '</ul>';

Вместо, к примеру:

echo '<ul>';
wp_list_cats('sort_column=name&optioncount=0&depth=1');
echo '</ul>';
Categories: CMS Tags:
16 октября 2016 Нет комментариев
if(CModule::IncludeModule('iblock')){
	$dbResult=CIBlock::GetByID(81);
	if($arIBlock=$dbResult->GetNext()){
		echo $arIBlock['DESCRIPTION'];
	}
}
Categories: CMS Tags:
27 сентября 2016 Нет комментариев

Исключить ссылки на картинки в sitemap.xml (избавиться от предупреждений Yandex Webmaster: Неизвестный тег image:image)
в файле functions.php активной темы:

add_filter('wpseo_xml_sitemap_img',__return_false);
Categories: CMS Tags:
23 сентября 2016 Нет комментариев

result_modifier.php

$menuList=array();
$lev=0;
$lastInd=0;
$parents=array();
foreach($arResult as $arItem){
	$lev=$arItem['DEPTH_LEVEL'];
	if($arItem['IS_PARENT']){
		$arItem['CHILDREN']=array();
	}
	if($lev==1){
		$menuList[]=$arItem;
		$lastInd=count($menuList)-1;
		$parents[$lev]=&$menuList[$lastInd];
	}else{
		$parents[$lev-1]['CHILDREN'][]=$arItem;
		$lastInd=count($parents[$lev-1]['CHILDREN'])-1;
		$parents[$lev]=&$parents[$lev-1]['CHILDREN'][$lastInd];
	}
}
$arResult=$menuList;

template.php

if(empty($arResult))return;
foreach($arResult as $itemIndex=>$arItem){
	if($arItem['SELECTED']){
		echo '<ul>';
			foreach($arItem['CHILDREN'] as $arChild){
				$arChildActive=($arChild['SELECTED'])?' class="active"':'';
				echo '<li'.$arChildActive.'>';
					echo '<a href="'.$arChild['LINK'].'">'.$arChild['TEXT'].'</a>';
				echo '</li>';
			}
		echo '</ul>';
	}
}

.left1.menu.php

$aMenuLinks=Array();

.left1.menu_ext.php

if(!defined("B_PROLOG_INCLUDED")||B_PROLOG_INCLUDED!==true)die();
global $APPLICATION;
$aMenuLinksExt=$APPLICATION->IncludeComponent("bitrix:menu.sections","",array(
	"IS_SEF"=>"Y",
	"SEF_BASE_URL"=>"",
	"SECTION_PAGE_URL"=>"/section/#SECTION_CODE#/",
	"DETAIL_PAGE_URL"=>"/section/#SECTION_CODE#/#ELEMENT_CODE#",
	"IBLOCK_TYPE"=>"razdel",
	"IBLOCK_ID"=>"81",
	"DEPTH_LEVEL"=>"2",
	"CACHE_TYPE"=>"A",
	"CACHE_TIME"=>"0",
	"CACHE_TYPE"=>"A",
	"CACHE_TIME"=>"3600"
	),
	false
);
$aMenuLinks=array_merge($aMenuLinks,$aMenuLinksExt);

Вызов:

$APPLICATION->IncludeComponent("bitrix:menu","vert",array(
	"ROOT_MENU_TYPE"=>"left1",
	"MENU_CACHE_TYPE"=>"A",
	"MENU_CACHE_TIME"=>"3600",
	"MENU_CACHE_USE_GROUPS"=>"Y",
	"MENU_CACHE_GET_VARS"=>array(
	),
	"MAX_LEVEL"=>"2",
	"CHILD_MENU_TYPE"=>"left1",
	"USE_EXT"=>"Y",
	"DELAY"=>"N",
	"ALLOW_MULTI_SELECT"=>"N"
	),
	false
);
Categories: CMS Tags: