Пример #1
0
function maybeSubdivideCluster($cluster_id)
{
    global $clusters_by_id, $mean_child_count, $min_cluster_size, $min_divide_size;
    $this_cluster =& $clusters_by_id[$cluster_id];
    if (count($this_cluster['children']) > $min_divide_size) {
        $child_clusters = doClustering($this_cluster['children'], $mean_child_count);
        // Special case. If we only get a single cluster out of doClustering, then merge it with the parent
        // cluster and proceed.
        if (count($child_clusters) == 1) {
            $one_cluster = reset($child_clusters);
            // grab first and only item.
            $this_cluster['children'] = array_merge($this_cluster['children'], $one_cluster['children']);
        } else {
            $this_cluster['children'] = array();
            // Output of doClustering is an array of entities that each contain
            // id, latitude, longitude, and an array of children ids.
            foreach ($child_clusters as $child_id => $child_cluster) {
                // If one of the generated clusters only has a single child node, or its overall child_count
                // is below the acceptable threshold, then we can discard it and hook the single child directly
                // into the parent.
                $new_cluster = createCluster($child_id, $child_cluster['children']);
                if (count($child_cluster['children']) > 1 && $new_cluster['child_count'] >= $min_cluster_size) {
                    $this_cluster['children'][] = $child_id;
                    $clusters_by_id[$child_id] = $new_cluster;
                    maybeSubdivideCluster($child_id);
                } else {
                    $this_cluster['children'] = array_merge($this_cluster['children'], $new_cluster['children']);
                }
            }
        }
    }
}
Пример #2
0
/**
 * Import a cluster-variation form generated XML
 * @param string XML Input
 * @param integer GUID of the Cluster-Node
 * @param integer GUID of the CLuster-TEmpalte
 */
function XmlImportCluster($xmlString, $clnid, $clt)
{
    global $db;
    $xmlOptions = array(XML_OPTION_CASE_FOLDING => TRUE, XML_OPTION_SKIP_WHITE => TRUE);
    $xml =& new XPath(FALSE, $xmlOptions);
    $xml->importFromString($xmlString);
    $variationId = getDBCell("variations", "VARIATION_ID", "UPPER(NAME) = '" . strtoupper(urldecode($xml->getAttributes('/NX:CLUSTER[1]', 'VARIATION'))) . "'");
    if ($variationId != "") {
        $clid = createCluster($clnid, $variationId, "XMLAPI");
        if ($xml->hasChildNodes('/NX:CLUSTER[1]')) {
            $i = 1;
            while ($xml->getNode("/NX:CLUSTER[1]/NX:CLUSTERITEM[{$i}]")) {
                $child =& new XPath(FALSE, $xmlOptions);
                XmlImportClusterItem($xml->exportAsXml('/NX:CLUSTER[1]/NX:CLUSTERITEM[' . $i . ']', ''), $clid, $clt);
                $i++;
            }
        }
    }
}
Пример #3
0
/**
 * Creates a cluster and a cluster-node for the given clt. returns the clnid.
 * Can only import dynamic content and dynamic clusters (GUIDs of Cluster_node!).
 * @param string name of the cluster
 * @param string GUID of Cluster template
 * @param string ID od Variation to use
 * @param string array with data to post to plugins, like array("Headline" => "Test Headline", ...)
 * @param string Username to use for create
 */
function createCluster2($name, $clt, $variationId, $data, $createUser = "******")
{
    $name = makeCopyName("cluster_node", "NAME", parseSQL($name), "CLT_ID = {$clt}");
    if (!is_numeric($clt)) {
        exit;
    }
    if (!is_numeric($variationId)) {
        exit;
    }
    $clnid = createClusterNode($name, $clt);
    $clid = createCluster($clnid, $variationId, $createUser);
    $datarows = array_keys($data);
    for ($i = 0; $i < count($datarows); $i++) {
        $type = getDBCell("cluster_template_items", "CLTITYPE_ID", "CLT_ID = {$clt} AND UPPER(NAME) = UPPER('" . $datarows[$i] . "')");
        $clti = getDBCell("cluster_template_items", "CLTI_ID", "CLT_ID = {$clt} AND UPPER(NAME) = UPPER('" . $datarows[$i] . "')");
        $clcid = getDBCell("cluster_content", "CLCID", "CLID={$clid} AND CLTI_ID = {$clti}");
        if ($type == 2) {
            $pgType = strtoupper(getDBCell("modules", "MODULE_NAME", "MODULE_ID = " . getDBCell("cluster_template_items", "FKID", "CLT_ID = {$clt} AND UPPER(NAME) = UPPER('" . $datarows[$i] . "')")));
            $moduleId = getDBCell("cluster_template_items", "FKID", "CLT_ID = {$clt} AND UPPER(NAME) = UPPER('" . $datarows[$i] . "')");
            if ($pgType == "TEXT" || $pgType == "LABEL") {
                $data[$datarows[$i]] = urlencode($data[$datarows[$i]]);
            }
            $xml = '<NX:CONTENT TYPE="' . $pgType . '">' . $data[$datarows[$i]] . '</NX:CONTENT>';
            $pgn = createPGNRef($moduleId, $clcid);
            $pgn->import($xml);
        } else {
            if ($type == 4) {
                if (is_numeric($data[$datarows[$i]])) {
                    $sql = "UPDATE cluster_content SET FKID=" . $data[$datarows[$i]] . " WHERE CLCID = {$clcid}";
                    global $db;
                    $query = new query($db, $sql);
                    $query->free();
                }
            }
        }
    }
    return $clnid;
}
			$form->registerActionHandler($handler);

			$page->add($form);
			// edit the properties of an object.
			$handled = true;

		} else if ($action != "foo" && ($action != "0"  || $view != "0")) {
			if ($action == "") $action = value("acstate");	

			if ($action == "createCluster") {
				$id = value("id");

				$clnid = createClusterNode(value("cluster_node_NAME".$id), $clt);
    		    $variations = createDBCArray("variations", "VARIATION_ID");
                for ($varX=0; $varX < count($variations); $varX++) {
                        $clid = createCluster($clnid, $variations[$varX], $auth->userName);
                }

	   		    $sql = "UPDATE cluster_content SET FKID = '$clnid' WHERE CLCID = '$id';";
				$query = new query($db, $sql);
				$query->getrow();
				
				// Trying to set action to Edit All, but it obviously doesn't work.
				$action = value("acstate");
			}
					
			$handled = true;
			$page_action = "UPDATE";

			// Fetch variables
			$view = value("view", "NUMERIC");
	/**
	 * Checks, whether the cluster already exists and creates it, if not.
	 */	 
	function checkIfCLNExists() {
	  global $db;
	  
	  // Check, if Clusternode exists.
	  if ($this->value == "0" || $this->value == "") {
	    // The Cluster in the variation will be created now.
	    $this->clnid = createClusterNode($this->clustername, $this->cltid);	  	
	    	// update the new clnid immediately to the database	  	
	  	$sql = "UPDATE $this->table SET $this->column=$this->clnid WHERE $this->row_identifier";	  	
	  	$query = new query($db, $sql);
	  	$query->free();
	  
	  }	else {
	  	// the cluster node already exists.
	  	$this->clnid = $this->value;
	  }
	  
	  // check, if clustervariation exists.
	  $clid = getDBCell("cluster_variations", "CLID", "CLNID=$this->clnid AND VARIATION_ID=$this->variation");
	  if ($clid == "") {
	  	// Cluster-Variation does not exists yet.
	  	$this->clid = createCluster($this->clnid, $this->variation);
	  } else {
	  	$this->clid = $clid;
	  }
	  
	  // sync the cluster variation
	  syncCluster($this->clid);	  
	  
	  // ensure correct CLT-ID
	  $this->cltid = getDBCell("cluster_node", "CLT_ID", "CLNID=".$this->clnid);	  
	}
	/**
	 * Draw the input boxes needed for editing the contents in the envelope.
	 * @param integer id of cluster_content.CLCID
	 */
	function getSingleEdit($id) {
		global $specialID, $lang, $c, $sid, $aclf, $db, $lang;
        global $forceLoadFromDB, $auth;

       $clt = getDBCell("cluster_template_items", "FKID", "CLTI_ID = ".$this->clti);

       if ($this->saction == "createCluster" && $id == value("id")) {
                $name = parseSQL(value("cluster_node_NAME".$id));
                if ($name=="0") $name = "Cluster";
                $name = makeCopyName("cluster_node", "NAME", $name, "1", "", false);
                $clnid = createClusterNode($name, $clt);
                $variations = createDBCArray("variations", "VARIATION_ID");
                for ($varX=0; $varX < count($variations); $varX++) {
                        $clid = createCluster($clnid, $variations[$varX], $auth->userName);
                }

                $sql = "UPDATE cluster_content SET FKID = $clnid WHERE CLCID = $id";
                $query = new query($db, $sql);
                $query->free();
                $forceLoadFromDB = "yes";
        }

        if ($this->editState && $this->editor) {
            $chclbox = new Container(4);
				$compoundEnvelope = new Container(3);
				$compoundContainer = new Container(3);

                $specialID = $id;
                $cpselector = new CPCLSelector($lang->get("select_cl"), "cluster_content", "FKID", "CLCID=$id", getModuleFromCLC($id), "", "");
                $cpselector->additionalAttribute = "onchange=\" if ( !confirm('".$lang->get("confirm_unsaved_changes_linkedcluster", "Note: When changing the linked cluster, any changes you apply on the currently linked cluster will be lost. If you want to save these canges, save your work first and change the linked cluster then. Proceed ?")."') ) { for(i=0; i<document.form1.cluster_content_FKID$specialID.length; i++)  if(document.form1.cluster_content_FKID$specialID.options[i].defaultSelected == true) document.form1.cluster_content_FKID$specialID.options[i].selected=true; }\"";
                $variation = variation();
                // force save in dbo.
                //$clnid = getDBCell("cluster_content", "FKID", "CLCID = ".$id);
                if (!isset($clnid)) {
                    $clnid = $cpselector->value;
                } else {
                    $cpselector->value = $clnid;
                }
                $clid = getClusterFromNode($clnid, $variation);
                $chclbox->add( $cpselector );
                $forceLoadFromDB = "no";


                if ($clnid != "" && $clnid != "0") {
				    $clid = getClusterFromNode($clnid, $variation);
                    $name = getDBCell("cluster_node", "NAME", "CLNID = $clnid");
                }
                
				$infoboxid = $id;
				$chclboxid = $id;

				$table = '<table width="100% border="0" cellpadding="0" cellspacing="0"><tr><td>';
				$table.= $lang->get("cllink", "This box is linked to ")."&nbsp; <b>".$name."</b>";
				$table.= '</td><td align="right">';
				// Add-Button
				$ShowInfoButton = new LinkButtonInline("toggle_info_".$infoboxid, "show info", "box", "button", "toggle('showinfo_".$infoboxid."')");
				$CHCLButton = new LinkButtonInline("toggle_chcl_".$chclboxid, "change cluster", "box", "button", "toggle('chcl_".$chclboxid."')");
				$table.= $ShowInfoButton->draw()."&nbsp;".$CHCLButton->draw();
				$table.= '</td></tr></table>';
				
				$this->add(new Label("lbl", $table, "headbox", 2));

				if (getDBCell("cluster_content", "FKID", "CLCID = ".$id) != $clnid)
					$forceLoadFromDB = "yes";
	

			    $chclbox->add(new Cell("spacer", "standardlight", 1));
			    $chclbox->add(new Label("lbl", "or create a new instance called", "standardlight"));
			    $chclbox->add(new Input("cluster_node_NAME$id", "", "standardlight", 32));
			    $chclbox->add(new SingleHidden("clt", ""));
			    $chclbox->add(new SingleHidden("id", ""));
			    $chclbox->add(new LinkButtonInCell("neueInstanz", "Create Instance", "standardlight navelement", "button", "javascript:if (confirm('".$lang->get("confirm_unsaved_changes")."')) { document.form1.saction.value='createCluster';document.form1.id.value='$id';document.form1.clt.value='$clt';document.form1.submit(); };", "form1", 1));

			    $sql = "SELECT * FROM variations WHERE 1";
			    $variations = new query($db, $sql);
			    while ($variations->getrow()) {
				    $chclbox->add(new Hidden("cluster_variations_VARIATION_ID_".$variations->field("VARIATION_ID"), "1"));
			    }

			    $specialID = "";
                $compoundContainer->add(new IDWrapper("chcl_".$chclboxid, $chclbox, "embedded", ' style="display:'.(($clid == 0) ? "" : "none" ).';" ', 3));

                if ($clid != "0" && $clid != "") {
        			// GET CONTENT OF THE CLUSTER
    				// set variables that will contain the content later to null.
    				$clusters = null;
    				$plugins = null;
    				$types = null;

    				// get the structure of the content.
    				$sql = "SELECT CLTI_ID, CLTITYPE_ID FROM cluster_template_items WHERE CLT_ID = $clt AND FKID!=0 ORDER BY POSITION";

    				$query = new query($db, $sql);

    				while ($query->getrow()) {
    					$cltitype = $query->field("CLTITYPE_ID");

    					$ni = count($plugins);
    					$plugins[$ni] = $query->field("CLTI_ID");
    					$types[$ni] = $cltitype;
    				}

    				$query->free();

    				// we don't want to draw an additional back link in clusters-editor
    				// if (! $sitepage && ! $isArticle) {
    				//	$compoundContainer->add(new LinkLabel("link1", $lang->get("back_to_cv", "Back to cluster overview"), "modules/cluster/clusterbrowser.php?sid=$sid&clt=$clt", "_self", "informationheader", 2));
    				// }

    				$infobox = new Container(3);

    				// draw some cluster-information.
    				$infobox->add(new Subtitle("", $lang->get("cluster_information", "Information about this record"), 3));
    				$infobox->add(new ClusterInformation($clid));

    				$compoundContainer->add(new IDWrapper("showinfo_".$infoboxid, $infobox, "embedded", ' style="display:none;" ', 3));
    				// draw plugin preview.

    				$len = count($plugins);
    				if ($clid) {
    					for ($i = 0; $i < $len; $i++) {

                            if ($types[$i] == 2)
    							$compoundContainer->add(new ContentEnvelope($plugins[$i], $clid, true));

    						if ($types[$i] == 4)
    							$compoundContainer->add(new ClusterEnvelope($plugins[$i], $clid, true));

    						if ($types[$i] == 5)
    							$compoundContainer->add(new LibraryEnvelope($plugins[$i], $clid, true));

    						if ($types[$i] == 6)
    							$compoundContainer->add(new CompoundClusterEnvelope($plugins[$i], $clid, true));

    				        if ($types[$i] == 8)
    				          $compoundContainer->add(new ChannelEnvelope($plugins[$i], $clid, true));
    					}
    					if ($isArticle || $action == $lang->get("edit_all") || ($action == $lang->get("save")) || $action == $lang->get("save_back")) {
    				       	$compoundContainer->add(new NonDisplayedValue("cluster_variations", "LAST_CHANGED", "CLID = ".$clid, "(NOW()+0)", "NUMBER"));
    						$compoundContainer->add(new NonDisplayedValue("cluster_variations", "LAST_USER", "CLID = ".$clid, $auth->userName, "TEXT"));
    					}
    				}
                }
                $compoundEnvelope->add(new IDWrapper("compoundEnvelope_$id", $compoundContainer, "embedded sub", '', 3));
                $this->add(new IDWrapper("compoundCluster_$id", $compoundEnvelope, "boxed", '', 3));

		} else {
			$name = "&lt;" . $lang->get("not_selected", "No item selected yet."). "&gt;";
			$myfk = getDBCell("cluster_content", "FKID", "CLCID = " . $id);
			if ($myfk != 0 && $myfk != "") {
				$clt = getDBCell("cluster_node", "CLT_ID", "CLNID = " . $myfk);
				$cltname = getDBCell("cluster_templates", "NAME", "CLT_ID = ".$clt);
				$cat = getDBCell("cluster_templates", "CATEGORY_ID", "CLT_ID = " . $clt);
				$name = "<br><b>" . $lang->get("cli"). "</b> " .$cltname."/".getDBCell("cluster_node", "NAME", "CLNID = " . $myfk);
				$buttons = "<br><a href=\"" . $c["docroot"] . "modules/cluster/clusterbrowser.php?sid=$sid&action=editobject&go=update&oid=$myfk&pnode=$cat&clt=$clt\" class=\"box\">".$lang->get("goto_cl", "Goto Cluster")."</a>";
				if ($aclf->checkAccessToFunction("B_PREVIEW_PAGE")) $buttons .= drawSpacer(10, 1). "<a href=\"#\" onClick=\"window.open('" . $c["docroot"] . "modules/cluster/previewcpcl.php?sid=$sid&oid=$myfk', 'cppreview', 'width=400,height=400,location=no,menubar=no,toolbar=no');return false;\"  class=\"box\">".$lang->get("preview")."</a>";
			}
			$this->add(new Label("lbl", $name, "", 1));
			$this->add(new AlignedLabel('lbl', $buttons, 'right', '', 1));
		}

	}