Beispiel #1
0
function importLines($lines, $fields, $class_name, $parent)
{
	$count = 0;
	foreach ($lines as $line)
	{
		$line = trim($line);
	
		if (empty($line))
			continue;
	
		$array = explode(";", $line);
		
		$newobject = new mObject();
		$newobject->setClassName($class_name);
		$newobject->loadVars();

		$newobject->name = trim($array[$fields['name']]);
		$newobject->language = $_SESSION['murrix']['language'];
		$newobject->rights = $parent->getMeta("initial_rights", $parent->getRights());

		$vars = $newobject->getVars();

		foreach ($vars as $var)
		{
			if (!isset($fields[$var->name]))
				continue;
				
			$value = $array[$fields[$var->name]];
			$newobject->setVarValue($var->name, $value);
		}

		if ($newobject->save())
		{
			guessObjectType($newobject);
			clearNodeFileCache($parent->getNodeId());
			$newobject->linkWithNode($parent->getNodeId());
			$count++;
		}
		else
		{
			return mMsg::add("importLines", $object->getLastError(), true);
		}
	}
	
	return $count;
}
Beispiel #2
0
	function execute(&$system, $args)
	{
		$parent_id = $this->getNodeId($args);
		$parent = new mObject($parent_id);
		
		$class_name = "";
		if (!empty($args['class_name']))
			$class_name = $args['class_name'];

		if (empty($class_name))
			$class_name = $parent->getMeta("default_class_name", "folder");
		
		if ($parent->hasRight("create") || $parent->hasRight("comment") && $class_name == "comment")
		{
			if (isset($args['action']) && $args['action'] == "save")
			{
				if (!empty($class_name))
				{
					$languages = explode(",", $args['languages']);
					$languages_tosave = array();
				
					foreach ($languages as $language)
					{
						if (!empty($args[$language.'_name']))
						{
							if (!(strpos($args[$language.'_name'], "\\") === false) || !(strpos($args[$language.'_name'], "/") === false) || !(strpos($args[$language.'_name'], "+") === false))
							{
								$system->addAlert(ucf(i18n($language))." ".i18n("version").": ".ucf(i18n("you can not use '\\', '/' or '+' in the name")));
								return;
							}

							$languages_tosave[] = $language;
						}
					}

					if (count($languages_tosave) == 0)
					{
						$system->addAlert(ucf(i18n("nothing to save")));
						return;
					}

					$languages = $languages_tosave;
				
	
					$object = new mObject();
					$object->setClassName($class_name);
					$object->loadVars();
	
					$saved = false;
					foreach ($languages as $language)
					{
						$object->name = trim($args[$language.'_name']);
						$object->icon = trim($args[$language.'_icon']);
						$object->language = $language;
						$object->rights = $parent->getMeta("initial_rights", $parent->getRights());
	
						$vars = $object->getVars();
	
						foreach ($vars as $var)
						{
							$key = $language."_v".$var->id;
							$value = (isset($args[$key]) ? $args[$key] : "");
							
							if (empty($value) && $var->getRequired() && $var->getType() != "boolean")
							{
								$system->addAlert(utf8e(ucf(i18n($language))." ".i18n("version").": ".ucf(str_replace("_", " ", i18n($var->getName(true))))." ".i18n("is a required field")));
								return;
							}
							
							$object->setVarValue($var->name, $value);
						}
	
						if ($object->save())
						{
							guessObjectType($object);
							$saved = true;
						}
						else
						{
							$message = "Operation unsuccessfull.<br/>";
							$message .= "Error output:<br/>";
							$message .= $object->getLastError();
							$system->addAlert($message);
							return;
						}
					}
	
					if ($saved)
					{
						clearNodeFileCache($parent->getNodeId());
						$object->linkWithNode($parent->getNodeId());
						
						$system->addRedirect("exec=show&node_id=".$object->getNodeId());
					}
	
					return;
				}
			}
		}
		
		$args['class_name'] = $class_name;
		$this->draw($system, $args);
	}
Beispiel #3
0
	
					$name = trim($paths['basename']);
					// replace '\\' with '/'
					$name = str_replace("\\", "", $name);
					$name = str_replace("/", "", $name);
					$name = str_replace("+", "", $name);
	
					$object->name = $name;
					$object->language = $_SESSION['murrix']['language'];
					$object->rights = $parent_new->getMeta("initial_rights", $parent_new->getRights());
		
					$object->setVarValue("file", trim($paths['basename']).":".$tempName);
		
					if ($object->save())
					{
						guessObjectType($object);
						$object->linkWithNode($parent_new->getNodeId());
						clearNodeFileCache($parent_new->getNodeId());
						printToLog("Created file". $object->getPath()."<br/>");
						$count++;
						$size += $file['size'];
					}
					else
					{
						printToLog("Failed to create file ". $object->getPath()."<br/>");
					}
				}
				
				printToLog("<br/>Successfully processed files<br/>");
				printToLog("$count of ".count($_FILES)." files<br/>");
				printToLog(DownloadSize($size)." total<br/>");
	function parseXML($args)
	{
		// Instantiate the serializer
		$Unserializer = &new XML_Unserializer();
		
		// Serialize the data structure
		$status = $Unserializer->unserialize($args['data']);
		
		// Check whether serialization worked
		if (PEAR::isError($status))
			die($status->getMessage());
		
		// Display the PHP data structure
		$import_data = $Unserializer->getUnserializedData();
		
		$parent = new mObject($args['node_id']);
		
		$logtext = "";
	
		if (isset($import_data['version']))
			$logtext .= "Version: ".$import_data['version']."<br/>";
		
		if (isset($import_data['name']))
			$logtext .= "Created: ".$import_data['created']."<br/>";
		
		if (isset($import_data['name']))
			$logtext .= "Name: ".$import_data['name']."<br/>";
			
		if (isset($import_data['description']))
			$logtext .= "Description: ".$import_data['description']."<br/>";
		
		$imported_classes = array();
		$imported_nodes = array();
		$imported_links = array();
		$imported_users = array();
		$imported_groups = array();
		
		if (isset($import_data['container']['xmldata']))
			$import_data['container'] = array($import_data['container']);
		
		foreach ($import_data['container'] as $container)
		{
			switch ($container['xmldata'])
			{
				case "node":
				$imported_nodes[] = $container;
				break;
				
				case "class":
				$imported_classes[] = $container;
				break;
				
				case "link":
				$imported_links[] = $container;
				break;
				
				case "user":
				$imported_users[] = $container;
				break;
				
				case "group":
				$imported_groups[] = $container;
				break;
			}
			
		}
		
		if (count($imported_classes) > 0)
			$logtext .= "Found ".count($imported_classes)." classes<br/>";
		if (count($imported_nodes) > 0)
			$logtext .= "Found ".count($imported_nodes)." nodes<br/>";
		if (count($imported_links) > 0)
			$logtext .= "Found ".count($imported_links)." links<br/>";
		if (count($imported_users) > 0)
			$logtext .= "Found ".count($imported_users)." users<br/>";
		if (count($imported_groups) > 0)
			$logtext .= "Found ".count($imported_groups)." groups<br/>";
		
		$class_table = new mTable("classes");
		$vars_table = new mTable("vars");
		$initial_meta_table = new mTable("initial_meta");
		
		foreach ($imported_classes as $class)
		{
			$logtext .= "Checking database for existing class ".$class['name']."<br/>";
			
			$existing_class = $class_table->get("`name`='".$class['name']."'");
			
			if (count($existing_class) == 0)
			{
				$logtext .= "No existing class named ".$class['name']." found, creating<br/>";
				
				$class_table->insert(array("name"=>$class['name'], "default_icon"=>$class['icon']));
				
				if (count($class['variables']) > 0)
				{
					foreach ($class['variables'] as $varname => $properties)
						$vars_table->insert(array("class_name"=>$class['name'], "name"=>$varname, "priority"=>$properties['priority'], "required"=>$properties['required'], "type"=>$properties['type'], "extra"=>$properties['extra'], "comment"=>$properties['comment']));
				}
				
				if (count($class['metadata']) > 0)
				{
					foreach ($class['metadata'] as $name => $value)
						$initial_meta_table->insert(array("class_name"=>$class['name'], "name"=>$name, "value"=>$value));
				}
				
				continue;
			}
			else
				$logtext .= "Class named ".$class['name']." found, checking variables<br/>";
			
			$class_object = new mObject();
			$class_object->setClassName($class['name']);
			$class_object->loadVars();
			
			foreach ($class['variables'] as $varname => $properties)
			{
				if ($class_object->checkVarExistance($varname) == 0)
				{
					$logtext .= "Could not resolve - $varname, skipping, this data will be ignored!<br/>";
					continue;
				}
			}
		}
		
		$nodes_to_link = array();
		$id_conversion = array();
		$added_node_ids = array();
		$linked_node_ids = array();
		
		$node_table = new mTable("nodes");
		
		foreach ($imported_nodes as $container)
		{
			if (!isset($container['created']))
				$container['created'] = date("Y-m-d H:i:s");
		
			if (isset($container['rights']))
				$rights = $container['rights'];
			else
				$rights = $parent->getRights();
		
			$node_id = $node_table->insert(array("created" => $container['created'], "rights" => $rights));
			
			$node = new mObject();
			$node->node_id = $node_id;
			
			$id_conversion[$container['id']] = $node_id;
			$added_node_ids[] = $node_id;
			
			if (is_array($container['metadata']))
			{
				foreach ($container['metadata'] as $key => $value)
				{
					$node->setMeta($key, $value);
					$logtext .= "Created metadata name=".$key.", value=".$value.", node_id=".$node_id."<br/>";
				}
			}
			
			foreach ($container['objects'] as $object_array)
			{
				$object = new mObject();
				$object->setClassName($object_array['class_name']);
				$object->loadVars();
				
				if (!isset($object_array['created']))
					$object_array['created'] = date("Y-m-d H:i:s");
				
				$object->node_id = $node_id;
				
				if (!empty($object_array['created']))
					$object->created = $object_array['created'];
				else
					$object->created = date("Y-m-d H:i:s");
					
				if (!empty($object_array['version']))
					$object->version = $object_array['version'];
				else
					$object->version = 1;
					
				$object->class_name = $object_array['class_name'];
				$object->name = $object_array['name'];
				$object->icon = $object_array['icon'];
				$object->language = $object_array['language'];
				
				if (isset($object_array['user']))
				{
					$user = new mUser();
					$user->setByUsername($object_array['user']);
					$object->user_id = $user->id;
				}
				else
					$object->user_id = $_SESSION['murrix']['user']->id;
				
				if (is_array($object_array['variables']))
				{
					foreach ($object_array['variables'] as $key => $value)
					{
						if ($object->checkVarExistance($key) == 0)
						{
							$logtext .= "Could not resolve - $key, skipping<br/>";
							continue;
						}
						
						if (!is_array($value['value']))
							$value['value'] = html_entity_decode($value['value']);
							
						if ($value['type'] == "file")
						{
							$extension = strtolower(pathinfo($value['value'], PATHINFO_EXTENSION));
							$oldfile = $args['filepath']."/".$value['fileid'].".$extension";
							
							if (!file_exists($oldfile))
								$logtext .= "Could not find file - $oldfile, skipping<br/>";
							else
								$object->setVarValue($key, $value['value'].":$oldfile");
						}
						else if ($value['type'] == "thumbnail")
						{
							if (!empty($value['thumb_id']))
							{
								$oldfile = $args['thumbpath']."/".$value['fileid'].".jpg";
								
								if (!file_exists($oldfile))
									$logtext .= "Could not find thumbfile - $oldfile, skipping<br/>";
								else
									$object->setVarValue($key, $value['fileid'].".jpg:$oldfile");
							}
						}
						else
							$object->setVarValue($key, $value['value']);
					}
				}
				
				$object->save(true);
				guessObjectType($object);
				$logtext .= "Created object name=".$object->name.", node_id=$node_id, id=".$object->id.",version=".$object->version.",language=".$object->language."<br/>";
			}
		}
		
		$link_table = new mTable("links");
		
		foreach ($imported_links as $container)
		{
			$link_array = array();
			$link_array['node_top'] = $id_conversion[$container['node_top']];
			$link_array['node_bottom'] = $id_conversion[$container['node_bottom']];
			$link_array['type'] = $container['type'];
			
			$link_table->insert($link_array);
			$logtext .= "Linked node_top=".$link_array['node_top']." to node_bottom=".$link_array['node_bottom'].", type=".$link_array['type']."<br/>";
			
			if ($link_array['type'] == "sub")
				$linked_node_ids[] = $id_conversion[$container['node_bottom']];
		}
		
		$added_node_ids = array_unique($added_node_ids);
		$linked_node_ids = array_unique($linked_node_ids);
		
		$node_ids_to_link = array_diff($added_node_ids, $linked_node_ids);
		
		foreach ($node_ids_to_link as $node_id)
		{
			$link_array = array();
			$link_array['node_top'] = $args['node_id'];
			$link_array['node_bottom'] = $node_id;
			$link_array['type'] = "sub";
			
			$link_table->insert($link_array);
			$logtext .= "Linked node_top=".$link_array['node_top']." to node_bottom=".$link_array['node_bottom'].", type=".$link_array['type']."<br/>";
		}
		
		return mMsg::add("mXml::parseXML", $logtext, false);
	}
Beispiel #5
0
	function execute(&$system, $args)
	{
		global $abspath, $wwwpath, $db_prefix;

		if ($args['action'] == "import" && isAdmin())
		{
			if (empty($args['node_id']))
			{
				$system->addAlert(ucf(i18n("you must specifiy a node")));
				return;
			}
			
			if (empty($args['file']))
			{
				$system->addAlert(ucf(i18n("you must upload a file to import")));
				return;
			}
			
			list($filename, $full_filename) = explode(":", $args['file']);
			
			ob_start();
			
			$xml = new mXml();
			
			echo ucf(i18n("log"))."<br/><hr/>";
			
			$data = "";
			
			$extension = pathinfo($filename, PATHINFO_EXTENSION);
			if ($extension == "bz2")
			{
				echo "Found bz2-compressed file.<br/>";
				$bz = bzopen($full_filename, "r");
				while (!feof($bz))
					$data .= bzread($bz, 4096);
				bzclose($bz);
			}
			else
			{
				echo "Found uncompressed file.<br/>";
				$bz = fopen($full_filename, "r");
				while (!feof($bz))
					$data .= fread($bz, 4096);
				fclose($bz);
			}
			
			$import_data = $xml->parseBackupXML($data);
			
			
			
			if (isset($import_data['verion']))
				echo "Version: ".$import_data['verion']."<br/>";
			
			if (isset($import_data['name']))
				echo "Created: ".$import_data['created']."<br/>";
			
			if (isset($import_data['name']))
				echo "Name: ".$import_data['name']."<br/>";
				
			if (isset($import_data['description']))
				echo "Description: ".$import_data['description']."<br/>";
			
			$this->imported_classes = array();
			$this->imported_nodes = array();
			$this->imported_links = array();
			
			//PrintPre($import_data['container']);
			
			foreach ($import_data['container'] as $container)
			{
				$xmldata = $container['xmldata'];
				unset($container['xmldata']);
				//PrintPre($container);
				//echo "<hr/>";
				switch ($xmldata)
				{
					case "node":
					$this->imported_nodes[] = $container;
					break;
					
					case "class":
					$this->imported_classes[] = $container;
					break;
					
					case "link":
					$this->imported_links[] = $container;
					break;
				}
			}
			
			$class_table = new mTable("classes");
			$vars_table = new mTable("vars");
			
			foreach ($this->imported_classes as $class)
			{
				echo "Checking database for existing class ".$class['name']."<br/>";
				
				$existing_class = $class_table->get("`name`='".$class['name']."'");
				
				if (count($existing_class) == 0)
				{
					echo "<span style=\"color:red\">No existing class named ".$class['name']." found</span><br/>";
					continue;
				}
				else
					echo "<span style=\"color:green\">Class named ".$class['name']." found, checking variables</span><br/>";
				
				$existing_vars = $vars_table->get("`class_name`='".$class['name']."'");
				
				foreach ($class['vars'] as $varname => $properties)
				{
					$found = false;
					foreach ($existing_vars as $existing_var)
					{
						if ($existing_var['name'] == $varname)
						{
							$found = true;
							break;
						}
					}
					
					if ($found)
						echo "<span style=\"color:green\">Found matching var named $varname, type ".$properties['type']."</span><br/>";
					else
						echo "<span style=\"color:red\">No matching var named $varname, type ".$properties['type']." found</span><br/>";
				}
			}
			
			$nodes_to_link = array();
			$id_conversion = array();
			$added_node_ids = array();
			$linked_node_ids = array();
			
			$node_table = new mTable("nodes");
			
			foreach ($this->imported_nodes as $container)
			{
				if (!isset($container['created']))
					$container['created'] = date("Y-m-d H:i:s");
							
				$node_id = $node_table->insert(array("created" => $container['created']));
				
				$node = new mObject();
				$node->node_id = $node_id;
				
				$id_conversion[$container['id']] = $node_id;
				$added_node_ids[] = $node_id;
				
				if (is_array($container['metadata']))
				{
					foreach ($container['metadata']['container'] as $metadata)
					{
						$node->setMeta($metadata['name'], $metadata['value']);
						echo "Created metadata name=".$metadata['name'].", value=".$metadata['value'].", node_id=".$node_id."<br/>";
					}
				}
				
				foreach ($container['objects'] as $objcontainer)
				{
					if (isset($objcontainer['xmldata']) && $objcontainer['xmldata'] == "object")
						$objects = array($objcontainer);
					else
						$objects = $objcontainer;
						
					usort(&$objects, array($this, "SortByVersion"));
					
					foreach ($objects as $object_array)
					{
						$object = new mObject();
						$object->setClassName($object_array['class_name']);
						$object->loadVars();
						
						if (!isset($object_array['created']))
							$object_array['created'] = date("Y-m-d H:i:s");
						
						$object->node_id = $node_id;
						$object->created = $object_array['created'];
						$object->version = $object_array['version'];
						$object->class_name = $object_array['class_name'];
						$object->name = $object_array['name'];
						$object->icon = $object_array['icon'];
						$object->language = $object_array['language'];
						
						if (isset($object_array['right']))
							$object->rights = $object_array['rights'];
						else
							$object->rights = "";
						
						if (isset($object_array['user']))
						{
							$user = new mUser();
							$user->setByUsername($object_array['user']);
							$object->user_id = $user->id;
						}
						else
							$object->user_id = $_SESSION['murrix']['user']->id;
						
						if (is_array($object_array['vars']))
						{
							foreach ($object_array['vars'] as $key => $value)
							{
								if ($object->checkVarExistance($key) == 0)
								{
									echo "<span style=\"color:red\">Could not resolve - $key, skipping<br/></span>";
									continue;
								}
								if (!is_array($value['value']))
									$value['value'] = html_entity_decode($value['value']);
									
								if ($value['type'] == "file")
								{
									$extension = strtolower(pathinfo($value['value'], PATHINFO_EXTENSION));
									$oldfile = $args['filepath']."/".$value['file_id'].".$extension";
									
									if (!file_exists($oldfile))
										echo "<span style=\"color:red\">Could not find file - $oldfile, skipping<br/></span>";
									else
										$object->setVarValue($key, $value['value'].":$oldfile");
								}
								else if ($value['type'] == "thumbnail")
								{
									if (!empty($value['thumb_id']))
									{
										$oldfile = $args['thumbpath']."/".$value['thumb_id'].".jpg";
										
										if (!file_exists($oldfile))
											echo "<span style=\"color:red\">Could not find thumbfile - $oldfile, skipping<br/></span>";
										else
											$object->setVarValue($key, $value['thumb_id'].".jpg:$oldfile");
									}
								}
								else
									$object->setVarValue($key, $value['value']);
							}
						}
						
						$object->save(true);
						guessObjectType($object);
						echo "Created object name=".$object->name.", node_id=$node_id, id=".$object->id.",version=".$object->version.",language=".$object->language."<br/>";
					}
				}
			}
			
			$link_table = new mTable("links");
			
			foreach ($this->imported_links as $container)
			{
				$link_array = array();
				$link_array['node_top'] = $id_conversion[$container['node_top']];
				$link_array['node_bottom'] = $id_conversion[$container['node_bottom']];
				$link_array['type'] = $container['type'];
				
				$link_table->insert($link_array);
				echo "Linked node_top=".$link_array['node_top']." to node_bottom=".$link_array['node_bottom'].", type=".$link_array['type']."<br/>";
				
				if ($link_array['type'] == "sub")
					$linked_node_ids[] = $id_conversion[$container['node_bottom']];
			}
			
			$added_node_ids = array_unique($added_node_ids);
			$linked_node_ids = array_unique($linked_node_ids);
			
			$node_ids_to_link = array_diff($added_node_ids, $linked_node_ids);
			
			foreach ($node_ids_to_link as $node_id)
			{
				$link_array = array();
				$link_array['node_top'] = $args['node_id'];
				$link_array['node_bottom'] = $node_id;
				$link_array['type'] = "sub";
				
				$link_table->insert($link_array);
				echo "Linked node_top=".$link_array['node_top']." to node_bottom=".$link_array['node_bottom'].", type=".$link_array['type']."<br/>";
			}
			
			//print_r($import_data);
			$system->setZoneData("zone_import_log", utf8e("<br/>".ob_get_end()));
			return;
		}
		
		$this->draw($system, $args);
	}