Пример #1
0
	function exec($args, $stdin, &$stdout, &$stderr, &$system)
	{
		$object = new mObject(getNode($_SESSION['murrix']['path']));

		$user = $object->getUser();
			
		$stdout .= "<table cellspacing=\"0\">";
		$stdout .= "<tr><td class=\"titlename\">Name</td><td>".cmd($object->getName(), "exec=show'&node_id=".$object->getNodeId())."</td></tr>";
		$stdout .= "<tr><td class=\"titlename\">Icon</td><td>".img(geticon($object->getIcon(), 16))."</td></tr>";
		$stdout .= "<tr><td class=\"titlename\">Id</td><td>".$object->getNodeId()."</td></tr>";
		$stdout .= "<tr><td class=\"titlename\">Revision</td><td>".$object->getVersion()."</td></tr>";
		$stdout .= "<tr><td class=\"titlename\">Language</td><td>".$object->getLanguage()."</td></tr>";
		$stdout .= "<tr><td class=\"titlename\">Class</td><td>".$object->getClassName()."</td></tr>";
		$stdout .= "<tr><td class=\"titlename\">Rights</td><td>".$object->getRights()."</td></tr>";
		$stdout .= "<tr><td class=\"titlename\">User</td><td>".$user->username."</td></tr>";
		$stdout .= "<tr><td class=\"titlename\">Time</td><td>".$object->getCreated()."</td></tr>";
		$stdout .= "</table>";
		
		return true;
	}
Пример #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);
	}
Пример #3
0
	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);
	}
Пример #4
0
	function sendMessage($subject, $text, $attachment)
	{
		if ($this->id <= 0)
			return false;
			
		$user_id = $_SESSION['murrix']['user']->id;
		$_SESSION['murrix']['user']->id = $this->id;
		
		$home = new mObject($this->home_id);
		
		$inbox_id = getNode($home->getPath()."/inbox", "eng");
		
		if ($inbox_id < 0)
		{
			$inbox = new mObject();
			$inbox->setClassName("folder");
			$inbox->loadVars();

			$inbox->name = "inbox";
			$inbox->language = $_SESSION['murrix']['language'];

			$inbox_id = $inbox->save();
			
			$inbox->rights = $home->getMeta("initial_rights", $home->getRights());
			
			clearNodeFileCache($home->getNodeId());
			$inbox->linkWithNode($home->getNodeId());
		}
		else
			$inbox = new mObject($inbox_id);
		
		$message = new mObject();
		$message->setClassName("message");
		$message->loadVars();
		
		$message->name = $subject;
		$message->language = $_SESSION['murrix']['language'];
		
		$message->setVarValue("text", $text);
		$message->setVarValue("attachment", $attachment);
		$message->setVarValue("sender", $_SESSION['murrix']['user']->name);

		$message->save();
		
		$message->rights = $inbox->getMeta("initial_rights", $inbox->getRights());
		
		clearNodeFileCache($inbox->getNodeId());
		$message->linkWithNode($inbox->getNodeId());
		
		$_SESSION['murrix']['user']->id = $user_id;
		
		return true;
	}
Пример #5
0
		
					$parent_new = new mObject(getNode($parent_path));
		
					$object = new mObject();
					$object->setClassName("file");
					$object->loadVars();
	
					$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/>");