Example #1
0
 function replaceLang($_LANG, $db_string)
 {
     if (!$db_string) {
         return "";
     } else {
         foreach ($_LANG as $key => $value) {
             $db_string = replaceTree('{' . $key . '}', Sanitize($value), $db_string);
         }
         return $db_string;
     }
 }
Example #2
0
/**
 * Recursive alternative to str_replace that supports replacing keys as well
 *
 * The following code block can be utilized by PEAR's Testing_DocTest
 * <code>
 * // Input //
 * $settings = array(
 *     "Credits" => "@appname@ created by @author@",
 *     "Description" => "@appname@ can parse logfiles and store then in mysql",
 *     "@author@_mail" => "*****@*****.**"    
 * );    
 * $mapping = array(
 *     "@author@" => "kevin",
 *     "@appname@" => "logchopper"
 * );
 * 
 * // Execute //
 * $settings = replaceTree(
 *     array_keys($mapping), array_values($mapping), $settings, true
 * );
 * 
 * // Show //
 * print_r($settings);
 * 
 * // expects:
 * // Array
 * // (
 * //     [Credits] => logchopper created by kevin
 * //     [Description] => logchopper can parse logfiles and store then in mysql
 * //     [kevin_mail] => kevin@vanzonneveld.net
 * // )
 * </code>
 * 
 * @param string  $search
 * @param string  $replace
 * @param array   $array
 * @param boolean $keys_too
 * 
 * @return array
 */
function replaceTree($search = "", $replace = "", $array = false, $keys_too = false)
{
    if (!is_array($array)) {
        // Regular replace
        return str_replace($search, $replace, $array);
    }
    $newArr = array();
    foreach ($array as $k => $v) {
        // Replace keys as well?
        $add_key = $k;
        if ($keys_too) {
            $add_key = str_replace($search, $replace, $k);
        }
        // Recurse
        $newArr[$add_key] = replaceTree($search, $replace, $v, $keys_too);
    }
    return $newArr;
}
function ult_importer($theme,$defimport=false){
	global $wpdb;
	$table = $wpdb->prefix.ULTIMATUM_PREFIX.'_templates';
	$ltable = $wpdb->prefix.ULTIMATUM_PREFIX.'_layout';
	$atable = $wpdb->prefix.ULTIMATUM_PREFIX.'_layout_assign';
	$rtable = $wpdb->prefix.ULTIMATUM_PREFIX.'_rows';
	$ctable = $wpdb->prefix.ULTIMATUM_PREFIX.'_css';
	$classtable = $wpdb->prefix.ULTIMATUM_PREFIX.'_classes';	
	$extrarowstable = $wpdb->prefix.ULTIMATUM_PREFIX.'_extra_rows';
	// INSERT THE THEME
	if(!$defimport){	
		$themesql = "INSERT INTO $table 
		(`name`, `width`, `margin`, `mwidth`, `mmargin`, `swidth`, `smargin`, `gridwork`, `swatch`, `type`, `dcss`, `theme`,`default`) VALUES
		('".$theme['name']."', '".$theme['width']."', '".$theme['margin']."', '".$theme['mwidth']."', '".$theme['mmargin']."', '".$theme['swidth']."', '".$theme['smargin']."', '".$theme['gridwork']."', '".$theme['swatch']."', '".$theme['type']."', '".$theme['dcss']."', '".THEME_SLUG."','0')";
	} else {
		$themesql = "INSERT INTO $table
		(`name`, `width`, `margin`, `mwidth`, `mmargin`, `swidth`, `smargin`, `gridwork`, `swatch`, `type`, `dcss`, `theme`,`default`) VALUES
		('".$theme['name']."', '".$theme['width']."', '".$theme['margin']."', '".$theme['mwidth']."', '".$theme['mmargin']."', '".$theme['swidth']."', '".$theme['smargin']."', '".$theme['gridwork']."', '".$theme['swatch']."', '".$theme['type']."', '".$theme['dcss']."', '".THEME_SLUG."','".$theme['default']."')";
	}

	$wpdb->query($themesql);
	$themeid = $wpdb->insert_id;
	// INSERT EXTRA ROWS
	if(isset($theme['extrarows']) && is_array($theme['extrarows'])){
		foreach ($theme['extrarows'] as $extrarow){
			$extrarow['template_id']=$themeid;
			$extrarowsql = 'INSERT INTO `'.$extrarowstable."` VALUES ('".$extrarow['template_id']."','".$extrarow['name']."','".$extrarow['slug']."','".$extrarow['grid']."','".$extrarow['amount']."')";
			$wpdb->query($extrarowsql);
		}
	}
	// repcale themid in array
	$theme = replaceTree('{themeid}',$themeid,$theme);
	if(is_array($theme['css']) && count($theme['css'])!=0){
		$themeoptionname = THEME_SLUG.'_template_'.$themeid.'_css';
		update_option($themeoptionname,$theme['css']);
	}
	if(isset($theme['custom_css']) && strlen($theme['custom_css'])>0){
		update_option(THEME_SLUG.'_custom_template_css_'.$themeid,$theme['custom_css']);
	}
	//Start Layouts
	$partconv = array();
	foreach($theme['layouts'] as $layout){
		//insert Layout
		$layoutsql = "INSERT INTO $ltable  (`title`,`type`,`theme`,`default`) VALUES ('".$layout['name']."','".$layout['type']."','".$themeid."','".$layout['default']."')";
		$wpdb->query($layoutsql);
		$layoutid = $wpdb->insert_id;
		// Save partials array
		if($layout['type']=='part'){
			$old_lay_id= $layout['oldid'];
			$partconv[$old_lay_id]='layout-'.$layoutid;
			ult_do_layout_part_import($layoutid,$layout,'rows');
		}  else {
			ult_do_layout_part_import($layoutid,$layout,'before',$partconv);
			ult_do_layout_part_import($layoutid,$layout,'rows',$partconv);
			ult_do_layout_part_import($layoutid,$layout,'after',$partconv);
			$optionname = THEME_SLUG.'_'.$layoutid.'_css';
			update_option($optionname,$layout['css']);
			// Create Custom CSS file
			if(isset($layout['custom_css']) && strlen($layout['custom_css'])>0){
				update_option(THEME_SLUG.'_custom_css_'.$layoutid,$layout['custom_css']);
			}
		}
		
	}
	// Layouts finished
	return $themeid;
}