@@ -796,6 +796,13 @@ discard block |
||
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /* Internally used compute the label positions */ |
| 799 | + |
|
| 800 | + /** |
|
| 801 | + * @param double $X |
|
| 802 | + * @param double $Y |
|
| 803 | + * @param double $Angle |
|
| 804 | + * @param boolean $Stacked |
|
| 805 | + */ |
|
| 799 | 806 | function writePieLabel($X,$Y,$Label,$Angle,$Settings,$Stacked,$Xc=0,$Yc=0,$Radius=0,$Reversed=FALSE) |
| 800 | 807 | { |
| 801 | 808 | $LabelOffset = 30; |
@@ -847,6 +854,13 @@ discard block |
||
| 847 | 854 | } |
| 848 | 855 | |
| 849 | 856 | /* Internally used to shift label positions */ |
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * @param integer $StartAngle |
|
| 860 | + * @param integer $EndAngle |
|
| 861 | + * @param double $Offset |
|
| 862 | + * @param boolean $Reversed |
|
| 863 | + */ |
|
| 850 | 864 | function shift($StartAngle,$EndAngle,$Offset,$Reversed) |
| 851 | 865 | { |
| 852 | 866 | if ( $Reversed ) { $Offset = -$Offset; } |
@@ -1462,6 +1476,10 @@ discard block |
||
| 1462 | 1476 | } |
| 1463 | 1477 | |
| 1464 | 1478 | /* Reverse an array */ |
| 1479 | + |
|
| 1480 | + /** |
|
| 1481 | + * @param string $Plots |
|
| 1482 | + */ |
|
| 1465 | 1483 | function arrayReverse($Plots) |
| 1466 | 1484 | { |
| 1467 | 1485 | $Result = ""; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | - /* |
|
| 2 | + /* |
|
| 3 | 3 | pPie - class to draw pie charts |
| 4 | 4 | |
| 5 | 5 | Version : 2.1.3 |
@@ -13,1488 +13,1488 @@ discard block |
||
| 13 | 13 | You can find the whole class documentation on the pChart web site. |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | - /* Class return codes */ |
|
| 17 | - define("PIE_NO_ABSCISSA" , 140001); |
|
| 18 | - define("PIE_NO_DATASERIE" , 140002); |
|
| 19 | - define("PIE_SUMISNULL" , 140003); |
|
| 20 | - define("PIE_RENDERED" , 140000); |
|
| 16 | + /* Class return codes */ |
|
| 17 | + define("PIE_NO_ABSCISSA" , 140001); |
|
| 18 | + define("PIE_NO_DATASERIE" , 140002); |
|
| 19 | + define("PIE_SUMISNULL" , 140003); |
|
| 20 | + define("PIE_RENDERED" , 140000); |
|
| 21 | 21 | |
| 22 | - define("PIE_LABEL_COLOR_AUTO" , 140010); |
|
| 23 | - define("PIE_LABEL_COLOR_MANUAL", 140011); |
|
| 22 | + define("PIE_LABEL_COLOR_AUTO" , 140010); |
|
| 23 | + define("PIE_LABEL_COLOR_MANUAL", 140011); |
|
| 24 | 24 | |
| 25 | - define("PIE_VALUE_NATURAL" , 140020); |
|
| 26 | - define("PIE_VALUE_PERCENTAGE" , 140021); |
|
| 25 | + define("PIE_VALUE_NATURAL" , 140020); |
|
| 26 | + define("PIE_VALUE_PERCENTAGE" , 140021); |
|
| 27 | 27 | |
| 28 | - define("PIE_VALUE_INSIDE" , 140030); |
|
| 29 | - define("PIE_VALUE_OUTSIDE" , 140031); |
|
| 28 | + define("PIE_VALUE_INSIDE" , 140030); |
|
| 29 | + define("PIE_VALUE_OUTSIDE" , 140031); |
|
| 30 | 30 | |
| 31 | - /* pPie class definition */ |
|
| 32 | - class pPie |
|
| 33 | - { |
|
| 34 | - var $pChartObject; |
|
| 35 | - var $pDataObject; |
|
| 36 | - var $LabelPos = "" ; |
|
| 31 | + /* pPie class definition */ |
|
| 32 | + class pPie |
|
| 33 | + { |
|
| 34 | + var $pChartObject; |
|
| 35 | + var $pDataObject; |
|
| 36 | + var $LabelPos = "" ; |
|
| 37 | 37 | |
| 38 | - /* Class creator */ |
|
| 39 | - function pPie($Object,$pDataObject) |
|
| 38 | + /* Class creator */ |
|
| 39 | + function pPie($Object,$pDataObject) |
|
| 40 | 40 | { |
| 41 | - /* Cache the pChart object reference */ |
|
| 42 | - $this->pChartObject = $Object; |
|
| 41 | + /* Cache the pChart object reference */ |
|
| 42 | + $this->pChartObject = $Object; |
|
| 43 | 43 | |
| 44 | - /* Cache the pData object reference */ |
|
| 45 | - $this->pDataObject = $pDataObject; |
|
| 44 | + /* Cache the pData object reference */ |
|
| 45 | + $this->pDataObject = $pDataObject; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - /* Draw a pie chart */ |
|
| 49 | - function draw2DPie($X,$Y,$Format="") |
|
| 48 | + /* Draw a pie chart */ |
|
| 49 | + function draw2DPie($X,$Y,$Format="") |
|
| 50 | 50 | { |
| 51 | - $Radius = isset($Format["Radius"]) ? $Format["Radius"] : 60; |
|
| 52 | - $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; |
|
| 53 | - $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 0; |
|
| 54 | - $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 0; |
|
| 55 | - $SecondPass = isset($Format["SecondPass"]) ? $Format["SecondPass"] : TRUE; |
|
| 56 | - $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
|
| 57 | - $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255; |
|
| 58 | - $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255; |
|
| 59 | - $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255; |
|
| 60 | - $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
|
| 61 | - $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE; |
|
| 62 | - $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 63 | - $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL; |
|
| 64 | - $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0; |
|
| 65 | - $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0; |
|
| 66 | - $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0; |
|
| 67 | - $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 68 | - $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : NULL; |
|
| 69 | - $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE; |
|
| 70 | - $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 15; |
|
| 71 | - $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : ""; |
|
| 72 | - $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255; |
|
| 73 | - $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255; |
|
| 74 | - $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255; |
|
| 75 | - $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 76 | - $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 77 | - |
|
| 78 | - /* Data Processing */ |
|
| 79 | - $Data = $this->pDataObject->getData(); |
|
| 80 | - $Palette = $this->pDataObject->getPalette(); |
|
| 81 | - |
|
| 82 | - /* Do we have an abscissa serie defined? */ |
|
| 83 | - if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 84 | - |
|
| 85 | - /* Try to find the data serie */ |
|
| 86 | - $DataSerie = ""; |
|
| 87 | - foreach ($Data["Series"] as $SerieName => $SerieData) |
|
| 88 | - { if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 89 | - |
|
| 90 | - /* Do we have data to compute? */ |
|
| 91 | - if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); } |
|
| 92 | - |
|
| 93 | - /* Remove unused data */ |
|
| 94 | - list($Data,$Palette) = $this->clean0Values($Data,$Palette,$DataSerie,$Data["Abscissa"]); |
|
| 95 | - |
|
| 96 | - /* Compute the pie sum */ |
|
| 97 | - $SerieSum = $this->pDataObject->getSum($DataSerie); |
|
| 98 | - |
|
| 99 | - /* Do we have data to draw? */ |
|
| 100 | - if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); } |
|
| 101 | - |
|
| 102 | - /* Dump the real number of data to draw */ |
|
| 103 | - $Values = ""; |
|
| 104 | - foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value) |
|
| 105 | - { if ($Value != 0) { $Values[] = $Value; } } |
|
| 106 | - |
|
| 107 | - /* Compute the wasted angular space between series */ |
|
| 108 | - if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = count($Values) * $DataGapAngle; } |
|
| 109 | - |
|
| 110 | - /* Compute the scale */ |
|
| 111 | - $ScaleFactor = (360 - $WastedAngular) / $SerieSum; |
|
| 112 | - |
|
| 113 | - $RestoreShadow = $this->pChartObject->Shadow; |
|
| 114 | - if ( $this->pChartObject->Shadow ) |
|
| 115 | - { |
|
| 116 | - $this->pChartObject->Shadow = FALSE; |
|
| 117 | - |
|
| 118 | - $ShadowFormat = $Format; $ShadowFormat["Shadow"] = TRUE; |
|
| 119 | - $this->draw2DPie($X+$this->pChartObject->ShadowX,$Y+$this->pChartObject->ShadowY,$ShadowFormat); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /* Draw the polygon pie elements */ |
|
| 123 | - $Step = 360 / (2 * PI * $Radius); |
|
| 124 | - $Offset = 0; $ID = 0; |
|
| 125 | - foreach($Values as $Key => $Value) |
|
| 126 | - { |
|
| 127 | - if ( $Shadow ) |
|
| 51 | + $Radius = isset($Format["Radius"]) ? $Format["Radius"] : 60; |
|
| 52 | + $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; |
|
| 53 | + $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 0; |
|
| 54 | + $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 0; |
|
| 55 | + $SecondPass = isset($Format["SecondPass"]) ? $Format["SecondPass"] : TRUE; |
|
| 56 | + $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
|
| 57 | + $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255; |
|
| 58 | + $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255; |
|
| 59 | + $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255; |
|
| 60 | + $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
|
| 61 | + $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE; |
|
| 62 | + $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 63 | + $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL; |
|
| 64 | + $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0; |
|
| 65 | + $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0; |
|
| 66 | + $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0; |
|
| 67 | + $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 68 | + $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : NULL; |
|
| 69 | + $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE; |
|
| 70 | + $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 15; |
|
| 71 | + $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : ""; |
|
| 72 | + $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255; |
|
| 73 | + $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255; |
|
| 74 | + $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255; |
|
| 75 | + $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 76 | + $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 77 | + |
|
| 78 | + /* Data Processing */ |
|
| 79 | + $Data = $this->pDataObject->getData(); |
|
| 80 | + $Palette = $this->pDataObject->getPalette(); |
|
| 81 | + |
|
| 82 | + /* Do we have an abscissa serie defined? */ |
|
| 83 | + if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 84 | + |
|
| 85 | + /* Try to find the data serie */ |
|
| 86 | + $DataSerie = ""; |
|
| 87 | + foreach ($Data["Series"] as $SerieName => $SerieData) |
|
| 88 | + { if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 89 | + |
|
| 90 | + /* Do we have data to compute? */ |
|
| 91 | + if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); } |
|
| 92 | + |
|
| 93 | + /* Remove unused data */ |
|
| 94 | + list($Data,$Palette) = $this->clean0Values($Data,$Palette,$DataSerie,$Data["Abscissa"]); |
|
| 95 | + |
|
| 96 | + /* Compute the pie sum */ |
|
| 97 | + $SerieSum = $this->pDataObject->getSum($DataSerie); |
|
| 98 | + |
|
| 99 | + /* Do we have data to draw? */ |
|
| 100 | + if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); } |
|
| 101 | + |
|
| 102 | + /* Dump the real number of data to draw */ |
|
| 103 | + $Values = ""; |
|
| 104 | + foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value) |
|
| 105 | + { if ($Value != 0) { $Values[] = $Value; } } |
|
| 106 | + |
|
| 107 | + /* Compute the wasted angular space between series */ |
|
| 108 | + if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = count($Values) * $DataGapAngle; } |
|
| 109 | + |
|
| 110 | + /* Compute the scale */ |
|
| 111 | + $ScaleFactor = (360 - $WastedAngular) / $SerieSum; |
|
| 112 | + |
|
| 113 | + $RestoreShadow = $this->pChartObject->Shadow; |
|
| 114 | + if ( $this->pChartObject->Shadow ) |
|
| 115 | + { |
|
| 116 | + $this->pChartObject->Shadow = FALSE; |
|
| 117 | + |
|
| 118 | + $ShadowFormat = $Format; $ShadowFormat["Shadow"] = TRUE; |
|
| 119 | + $this->draw2DPie($X+$this->pChartObject->ShadowX,$Y+$this->pChartObject->ShadowY,$ShadowFormat); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /* Draw the polygon pie elements */ |
|
| 123 | + $Step = 360 / (2 * PI * $Radius); |
|
| 124 | + $Offset = 0; $ID = 0; |
|
| 125 | + foreach($Values as $Key => $Value) |
|
| 126 | + { |
|
| 127 | + if ( $Shadow ) |
|
| 128 | 128 | $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
| 129 | - else |
|
| 129 | + else |
|
| 130 | 130 | { |
| 131 | - if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
|
| 132 | - $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 131 | + if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
|
| 132 | + $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - if ( !$SecondPass && !$Shadow ) |
|
| 135 | + if ( !$SecondPass && !$Shadow ) |
|
| 136 | 136 | { |
| 137 | - if ( !$Border ) |
|
| 138 | - $Settings["Surrounding"] = 10; |
|
| 139 | - else |
|
| 140 | - { $Settings["BorderR"] = $BorderR; $Settings["BorderG"] = $BorderG; $Settings["BorderB"] = $BorderB; } |
|
| 137 | + if ( !$Border ) |
|
| 138 | + $Settings["Surrounding"] = 10; |
|
| 139 | + else |
|
| 140 | + { $Settings["BorderR"] = $BorderR; $Settings["BorderG"] = $BorderG; $Settings["BorderB"] = $BorderB; } |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - $Plots = ""; |
|
| 144 | - $EndAngle = $Offset+($Value*$ScaleFactor); if ( $EndAngle > 360 ) { $EndAngle = 360; } |
|
| 143 | + $Plots = ""; |
|
| 144 | + $EndAngle = $Offset+($Value*$ScaleFactor); if ( $EndAngle > 360 ) { $EndAngle = 360; } |
|
| 145 | 145 | |
| 146 | - $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 147 | - if ($DataGapAngle == 0) |
|
| 146 | + $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 147 | + if ($DataGapAngle == 0) |
|
| 148 | 148 | { $X0 = $X; $Y0 = $Y; } |
| 149 | - else |
|
| 149 | + else |
|
| 150 | 150 | { |
| 151 | - $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
|
| 152 | - $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius + $Y; |
|
| 151 | + $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
|
| 152 | + $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius + $Y; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - $Plots[] = $X0; $Plots[] = $Y0; |
|
| 155 | + $Plots[] = $X0; $Plots[] = $Y0; |
|
| 156 | 156 | |
| 157 | 157 | |
| 158 | - for($i=$Offset;$i<=$EndAngle;$i=$i+$Step) |
|
| 158 | + for($i=$Offset;$i<=$EndAngle;$i=$i+$Step) |
|
| 159 | 159 | { |
| 160 | - $Xc = cos(($i-90)*PI/180) * $Radius + $X; |
|
| 161 | - $Yc = sin(($i-90)*PI/180) * $Radius + $Y; |
|
| 160 | + $Xc = cos(($i-90)*PI/180) * $Radius + $X; |
|
| 161 | + $Yc = sin(($i-90)*PI/180) * $Radius + $Y; |
|
| 162 | 162 | |
| 163 | - if ( $SecondPass && ( $i<90 )) { $Yc++; } |
|
| 164 | - if ( $SecondPass && ( $i>180 && $i<270 )) { $Xc++; } |
|
| 165 | - if ( $SecondPass && ( $i>=270 )) { $Xc++; $Yc++; } |
|
| 163 | + if ( $SecondPass && ( $i<90 )) { $Yc++; } |
|
| 164 | + if ( $SecondPass && ( $i>180 && $i<270 )) { $Xc++; } |
|
| 165 | + if ( $SecondPass && ( $i>=270 )) { $Xc++; $Yc++; } |
|
| 166 | 166 | |
| 167 | - $Plots[] = $Xc; $Plots[] = $Yc; |
|
| 167 | + $Plots[] = $Xc; $Plots[] = $Yc; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - $this->pChartObject->drawPolygon($Plots,$Settings); |
|
| 171 | - if ( $RecordImageMap && !$Shadow ) { $this->pChartObject->addToImageMap("POLY",$this->arraySerialize($Plots),$this->pChartObject->toHTMLColor($Palette[$ID]["R"],$Palette[$ID]["G"],$Palette[$ID]["B"]),$Data["Series"][$Data["Abscissa"]]["Data"][$Key],$Value); } |
|
| 170 | + $this->pChartObject->drawPolygon($Plots,$Settings); |
|
| 171 | + if ( $RecordImageMap && !$Shadow ) { $this->pChartObject->addToImageMap("POLY",$this->arraySerialize($Plots),$this->pChartObject->toHTMLColor($Palette[$ID]["R"],$Palette[$ID]["G"],$Palette[$ID]["B"]),$Data["Series"][$Data["Abscissa"]]["Data"][$Key],$Value); } |
|
| 172 | 172 | |
| 173 | - if ( $DrawLabels && !$Shadow && !$SecondPass ) |
|
| 173 | + if ( $DrawLabels && !$Shadow && !$SecondPass ) |
|
| 174 | 174 | { |
| 175 | - if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 176 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 177 | - else |
|
| 178 | - { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
|
| 175 | + if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 176 | + { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 177 | + else |
|
| 178 | + { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
|
| 179 | 179 | |
| 180 | - $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 181 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 182 | - $Yc = sin(($Angle-90)*PI/180) * $Radius + $Y; |
|
| 180 | + $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 181 | + $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 182 | + $Yc = sin(($Angle-90)*PI/180) * $Radius + $Y; |
|
| 183 | 183 | |
| 184 | - $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
|
| 184 | + $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
|
| 185 | 185 | |
| 186 | - if ( $LabelStacked ) |
|
| 187 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$Radius); |
|
| 188 | - else |
|
| 189 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 186 | + if ( $LabelStacked ) |
|
| 187 | + $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$Radius); |
|
| 188 | + else |
|
| 189 | + $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - $Offset = $i + $DataGapAngle; $ID++; |
|
| 193 | - } |
|
| 192 | + $Offset = $i + $DataGapAngle; $ID++; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /* Second pass to smooth the angles */ |
|
| 196 | - if ( $SecondPass ) |
|
| 197 | - { |
|
| 198 | - $Step = 360 / (2 * PI * $Radius); |
|
| 199 | - $Offset = 0; $ID = 0; |
|
| 200 | - foreach($Values as $Key => $Value) |
|
| 195 | + /* Second pass to smooth the angles */ |
|
| 196 | + if ( $SecondPass ) |
|
| 197 | + { |
|
| 198 | + $Step = 360 / (2 * PI * $Radius); |
|
| 199 | + $Offset = 0; $ID = 0; |
|
| 200 | + foreach($Values as $Key => $Value) |
|
| 201 | 201 | { |
| 202 | - $FirstPoint = TRUE; |
|
| 203 | - if ( $Shadow ) |
|
| 204 | - $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 205 | - else |
|
| 206 | - { |
|
| 207 | - if ( $Border ) |
|
| 202 | + $FirstPoint = TRUE; |
|
| 203 | + if ( $Shadow ) |
|
| 204 | + $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 205 | + else |
|
| 206 | + { |
|
| 207 | + if ( $Border ) |
|
| 208 | 208 | $Settings = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB); |
| 209 | - else |
|
| 209 | + else |
|
| 210 | 210 | $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
| 211 | - } |
|
| 212 | - |
|
| 213 | - $EndAngle = $Offset+($Value*$ScaleFactor); if ( $EndAngle > 360 ) { $EndAngle = 360; } |
|
| 214 | - |
|
| 215 | - if ($DataGapAngle == 0) |
|
| 216 | - { $X0 = $X; $Y0 = $Y; } |
|
| 217 | - else |
|
| 218 | - { |
|
| 219 | - $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 220 | - $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
|
| 221 | - $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius + $Y; |
|
| 222 | - } |
|
| 223 | - $Plots[] = $X0; $Plots[] = $Y0; |
|
| 224 | - |
|
| 225 | - for($i=$Offset;$i<=$EndAngle;$i=$i+$Step) |
|
| 226 | - { |
|
| 227 | - $Xc = cos(($i-90)*PI/180) * $Radius + $X; |
|
| 228 | - $Yc = sin(($i-90)*PI/180) * $Radius + $Y; |
|
| 229 | - |
|
| 230 | - if ( $FirstPoint ) { $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); } { $FirstPoint = FALSE; } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $EndAngle = $Offset+($Value*$ScaleFactor); if ( $EndAngle > 360 ) { $EndAngle = 360; } |
|
| 214 | + |
|
| 215 | + if ($DataGapAngle == 0) |
|
| 216 | + { $X0 = $X; $Y0 = $Y; } |
|
| 217 | + else |
|
| 218 | + { |
|
| 219 | + $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 220 | + $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
|
| 221 | + $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius + $Y; |
|
| 222 | + } |
|
| 223 | + $Plots[] = $X0; $Plots[] = $Y0; |
|
| 224 | + |
|
| 225 | + for($i=$Offset;$i<=$EndAngle;$i=$i+$Step) |
|
| 226 | + { |
|
| 227 | + $Xc = cos(($i-90)*PI/180) * $Radius + $X; |
|
| 228 | + $Yc = sin(($i-90)*PI/180) * $Radius + $Y; |
|
| 229 | + |
|
| 230 | + if ( $FirstPoint ) { $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); } { $FirstPoint = FALSE; } |
|
| 231 | 231 | |
| 232 | - $this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings); |
|
| 233 | - } |
|
| 234 | - $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); |
|
| 232 | + $this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings); |
|
| 233 | + } |
|
| 234 | + $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); |
|
| 235 | 235 | |
| 236 | - if ( $DrawLabels && !$Shadow ) |
|
| 237 | - { |
|
| 238 | - if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 236 | + if ( $DrawLabels && !$Shadow ) |
|
| 237 | + { |
|
| 238 | + if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 239 | 239 | { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
| 240 | - else |
|
| 240 | + else |
|
| 241 | 241 | { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
| 242 | 242 | |
| 243 | - $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 244 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 245 | - $Yc = sin(($Angle-90)*PI/180) * $Radius + $Y; |
|
| 243 | + $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 244 | + $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 245 | + $Yc = sin(($Angle-90)*PI/180) * $Radius + $Y; |
|
| 246 | 246 | |
| 247 | - $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
|
| 247 | + $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
|
| 248 | 248 | |
| 249 | - if ( $LabelStacked ) |
|
| 249 | + if ( $LabelStacked ) |
|
| 250 | 250 | $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$Radius); |
| 251 | - else |
|
| 251 | + else |
|
| 252 | 252 | $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
| 253 | - } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - $Offset = $i + $DataGapAngle; $ID++; |
|
| 255 | + $Offset = $i + $DataGapAngle; $ID++; |
|
| 256 | + } |
|
| 256 | 257 | } |
| 257 | - } |
|
| 258 | 258 | |
| 259 | - if ( $WriteValues != NULL && !$Shadow ) |
|
| 260 | - { |
|
| 261 | - $Step = 360 / (2 * PI * $Radius); |
|
| 262 | - $Offset = 0; $ID = count($Values)-1; |
|
| 263 | - $Settings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"R"=>$ValueR,"G"=>$ValueG,"B"=>$ValueB,"Alpha"=>$ValueAlpha); |
|
| 264 | - foreach($Values as $Key => $Value) |
|
| 259 | + if ( $WriteValues != NULL && !$Shadow ) |
|
| 260 | + { |
|
| 261 | + $Step = 360 / (2 * PI * $Radius); |
|
| 262 | + $Offset = 0; $ID = count($Values)-1; |
|
| 263 | + $Settings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"R"=>$ValueR,"G"=>$ValueG,"B"=>$ValueB,"Alpha"=>$ValueAlpha); |
|
| 264 | + foreach($Values as $Key => $Value) |
|
| 265 | 265 | { |
| 266 | - $EndAngle = ($Value*$ScaleFactor) + $Offset; if ( $EndAngle > 360 ) { $EndAngle = 0; } |
|
| 267 | - $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 266 | + $EndAngle = ($Value*$ScaleFactor) + $Offset; if ( $EndAngle > 360 ) { $EndAngle = 0; } |
|
| 267 | + $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 268 | 268 | |
| 269 | - if ( $ValuePosition == PIE_VALUE_OUTSIDE ) |
|
| 270 | - { |
|
| 271 | - $Xc = cos(($Angle-90)*PI/180) * ($Radius+$ValuePadding) + $X; |
|
| 272 | - $Yc = sin(($Angle-90)*PI/180) * ($Radius+$ValuePadding) + $Y; |
|
| 273 | - } |
|
| 274 | - else |
|
| 275 | - { |
|
| 276 | - $Xc = cos(($Angle-90)*PI/180) * ($Radius)/2 + $X; |
|
| 277 | - $Yc = sin(($Angle-90)*PI/180) * ($Radius)/2 + $Y; |
|
| 278 | - } |
|
| 269 | + if ( $ValuePosition == PIE_VALUE_OUTSIDE ) |
|
| 270 | + { |
|
| 271 | + $Xc = cos(($Angle-90)*PI/180) * ($Radius+$ValuePadding) + $X; |
|
| 272 | + $Yc = sin(($Angle-90)*PI/180) * ($Radius+$ValuePadding) + $Y; |
|
| 273 | + } |
|
| 274 | + else |
|
| 275 | + { |
|
| 276 | + $Xc = cos(($Angle-90)*PI/180) * ($Radius)/2 + $X; |
|
| 277 | + $Yc = sin(($Angle-90)*PI/180) * ($Radius)/2 + $Y; |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 281 | - $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 282 | - elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 283 | - $Display = $Value.$ValueSuffix; |
|
| 280 | + if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 281 | + $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 282 | + elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 283 | + $Display = $Value.$ValueSuffix; |
|
| 284 | 284 | |
| 285 | - $this->pChartObject->drawText($Xc,$Yc,$Display,$Settings); |
|
| 285 | + $this->pChartObject->drawText($Xc,$Yc,$Display,$Settings); |
|
| 286 | 286 | |
| 287 | - $Offset = $EndAngle + $DataGapAngle; $ID--; |
|
| 287 | + $Offset = $EndAngle + $DataGapAngle; $ID--; |
|
| 288 | + } |
|
| 288 | 289 | } |
| 289 | - } |
|
| 290 | 290 | |
| 291 | - if ( $DrawLabels && $LabelStacked ) { $this->writeShiftedLabels(); } |
|
| 291 | + if ( $DrawLabels && $LabelStacked ) { $this->writeShiftedLabels(); } |
|
| 292 | 292 | |
| 293 | - $this->pChartObject->Shadow = $RestoreShadow; |
|
| 293 | + $this->pChartObject->Shadow = $RestoreShadow; |
|
| 294 | 294 | |
| 295 | - return(PIE_RENDERED); |
|
| 295 | + return(PIE_RENDERED); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - /* Draw a 3D pie chart */ |
|
| 299 | - function draw3DPie($X,$Y,$Format="") |
|
| 298 | + /* Draw a 3D pie chart */ |
|
| 299 | + function draw3DPie($X,$Y,$Format="") |
|
| 300 | 300 | { |
| 301 | - /* Rendering layout */ |
|
| 302 | - $Radius = isset($Format["Radius"]) ? $Format["Radius"] : 80; |
|
| 303 | - $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; |
|
| 304 | - $SkewFactor = isset($Format["SkewFactor"]) ? $Format["SkewFactor"] : .5; |
|
| 305 | - $SliceHeight = isset($Format["SliceHeight"]) ? $Format["SliceHeight"] : 20; |
|
| 306 | - $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 0; |
|
| 307 | - $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 0; |
|
| 308 | - $SecondPass = isset($Format["SecondPass"]) ? $Format["SecondPass"] : TRUE; |
|
| 309 | - $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
|
| 310 | - $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
|
| 311 | - $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE; |
|
| 312 | - $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 313 | - $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL; |
|
| 314 | - $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0; |
|
| 315 | - $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0; |
|
| 316 | - $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0; |
|
| 317 | - $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 318 | - $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : NULL; //PIE_VALUE_PERCENTAGE |
|
| 319 | - $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_INSIDE; |
|
| 320 | - $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 15; |
|
| 321 | - $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : ""; |
|
| 322 | - $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255; |
|
| 323 | - $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255; |
|
| 324 | - $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255; |
|
| 325 | - $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 326 | - $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 327 | - |
|
| 328 | - /* Error correction for overlaying rounded corners */ |
|
| 329 | - if ( $SkewFactor < .5 ) { $SkewFactor = .5; } |
|
| 330 | - |
|
| 331 | - /* Data Processing */ |
|
| 332 | - $Data = $this->pDataObject->getData(); |
|
| 333 | - $Palette = $this->pDataObject->getPalette(); |
|
| 334 | - |
|
| 335 | - /* Do we have an abscissa serie defined? */ |
|
| 336 | - if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 337 | - |
|
| 338 | - /* Try to find the data serie */ |
|
| 339 | - $DataSerie = ""; |
|
| 340 | - foreach ($Data["Series"] as $SerieName => $SerieData) |
|
| 341 | - { if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 342 | - |
|
| 343 | - /* Do we have data to compute? */ |
|
| 344 | - if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); } |
|
| 345 | - |
|
| 346 | - /* Remove unused data */ |
|
| 347 | - list($Data,$Palette) = $this->clean0Values($Data,$Palette,$DataSerie,$Data["Abscissa"]); |
|
| 348 | - |
|
| 349 | - /* Compute the pie sum */ |
|
| 350 | - $SerieSum = $this->pDataObject->getSum($DataSerie); |
|
| 351 | - |
|
| 352 | - /* Do we have data to draw? */ |
|
| 353 | - if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); } |
|
| 354 | - |
|
| 355 | - /* Dump the real number of data to draw */ |
|
| 356 | - $Values = ""; |
|
| 357 | - foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value) |
|
| 358 | - { if ($Value != 0) { $Values[] = $Value; } } |
|
| 359 | - |
|
| 360 | - /* Compute the wasted angular space between series */ |
|
| 361 | - if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = count($Values) * $DataGapAngle; } |
|
| 362 | - |
|
| 363 | - /* Compute the scale */ |
|
| 364 | - $ScaleFactor = (360 - $WastedAngular) / $SerieSum; |
|
| 365 | - |
|
| 366 | - $RestoreShadow = $this->pChartObject->Shadow; |
|
| 367 | - if ( $this->pChartObject->Shadow ) { $this->pChartObject->Shadow = FALSE; } |
|
| 368 | - |
|
| 369 | - /* Draw the polygon pie elements */ |
|
| 370 | - $Step = 360 / (2 * PI * $Radius); |
|
| 371 | - $Offset = 360; $ID = count($Values)-1; |
|
| 372 | - $Values = array_reverse($Values); |
|
| 373 | - $Slice = 0; $Slices = ""; $SliceColors = ""; $Visible = ""; $SliceAngle = ""; |
|
| 374 | - foreach($Values as $Key => $Value) |
|
| 375 | - { |
|
| 376 | - if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
|
| 377 | - $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 378 | - |
|
| 379 | - $SliceColors[$Slice] = $Settings; |
|
| 380 | - |
|
| 381 | - $StartAngle = $Offset; |
|
| 382 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 383 | - |
|
| 384 | - if ( $StartAngle > 180 ) { $Visible[$Slice]["Start"] = TRUE; } else { $Visible[$Slice]["Start"] = TRUE; } |
|
| 385 | - if ( $EndAngle < 180 ) { $Visible[$Slice]["End"] = FALSE; } else { $Visible[$Slice]["End"] = TRUE; } |
|
| 386 | - |
|
| 387 | - if ($DataGapAngle == 0) |
|
| 301 | + /* Rendering layout */ |
|
| 302 | + $Radius = isset($Format["Radius"]) ? $Format["Radius"] : 80; |
|
| 303 | + $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; |
|
| 304 | + $SkewFactor = isset($Format["SkewFactor"]) ? $Format["SkewFactor"] : .5; |
|
| 305 | + $SliceHeight = isset($Format["SliceHeight"]) ? $Format["SliceHeight"] : 20; |
|
| 306 | + $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 0; |
|
| 307 | + $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 0; |
|
| 308 | + $SecondPass = isset($Format["SecondPass"]) ? $Format["SecondPass"] : TRUE; |
|
| 309 | + $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
|
| 310 | + $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
|
| 311 | + $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE; |
|
| 312 | + $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 313 | + $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL; |
|
| 314 | + $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0; |
|
| 315 | + $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0; |
|
| 316 | + $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0; |
|
| 317 | + $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 318 | + $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : NULL; //PIE_VALUE_PERCENTAGE |
|
| 319 | + $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_INSIDE; |
|
| 320 | + $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 15; |
|
| 321 | + $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : ""; |
|
| 322 | + $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255; |
|
| 323 | + $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255; |
|
| 324 | + $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255; |
|
| 325 | + $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 326 | + $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 327 | + |
|
| 328 | + /* Error correction for overlaying rounded corners */ |
|
| 329 | + if ( $SkewFactor < .5 ) { $SkewFactor = .5; } |
|
| 330 | + |
|
| 331 | + /* Data Processing */ |
|
| 332 | + $Data = $this->pDataObject->getData(); |
|
| 333 | + $Palette = $this->pDataObject->getPalette(); |
|
| 334 | + |
|
| 335 | + /* Do we have an abscissa serie defined? */ |
|
| 336 | + if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 337 | + |
|
| 338 | + /* Try to find the data serie */ |
|
| 339 | + $DataSerie = ""; |
|
| 340 | + foreach ($Data["Series"] as $SerieName => $SerieData) |
|
| 341 | + { if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 342 | + |
|
| 343 | + /* Do we have data to compute? */ |
|
| 344 | + if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); } |
|
| 345 | + |
|
| 346 | + /* Remove unused data */ |
|
| 347 | + list($Data,$Palette) = $this->clean0Values($Data,$Palette,$DataSerie,$Data["Abscissa"]); |
|
| 348 | + |
|
| 349 | + /* Compute the pie sum */ |
|
| 350 | + $SerieSum = $this->pDataObject->getSum($DataSerie); |
|
| 351 | + |
|
| 352 | + /* Do we have data to draw? */ |
|
| 353 | + if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); } |
|
| 354 | + |
|
| 355 | + /* Dump the real number of data to draw */ |
|
| 356 | + $Values = ""; |
|
| 357 | + foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value) |
|
| 358 | + { if ($Value != 0) { $Values[] = $Value; } } |
|
| 359 | + |
|
| 360 | + /* Compute the wasted angular space between series */ |
|
| 361 | + if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = count($Values) * $DataGapAngle; } |
|
| 362 | + |
|
| 363 | + /* Compute the scale */ |
|
| 364 | + $ScaleFactor = (360 - $WastedAngular) / $SerieSum; |
|
| 365 | + |
|
| 366 | + $RestoreShadow = $this->pChartObject->Shadow; |
|
| 367 | + if ( $this->pChartObject->Shadow ) { $this->pChartObject->Shadow = FALSE; } |
|
| 368 | + |
|
| 369 | + /* Draw the polygon pie elements */ |
|
| 370 | + $Step = 360 / (2 * PI * $Radius); |
|
| 371 | + $Offset = 360; $ID = count($Values)-1; |
|
| 372 | + $Values = array_reverse($Values); |
|
| 373 | + $Slice = 0; $Slices = ""; $SliceColors = ""; $Visible = ""; $SliceAngle = ""; |
|
| 374 | + foreach($Values as $Key => $Value) |
|
| 375 | + { |
|
| 376 | + if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
|
| 377 | + $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 378 | + |
|
| 379 | + $SliceColors[$Slice] = $Settings; |
|
| 380 | + |
|
| 381 | + $StartAngle = $Offset; |
|
| 382 | + $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 383 | + |
|
| 384 | + if ( $StartAngle > 180 ) { $Visible[$Slice]["Start"] = TRUE; } else { $Visible[$Slice]["Start"] = TRUE; } |
|
| 385 | + if ( $EndAngle < 180 ) { $Visible[$Slice]["End"] = FALSE; } else { $Visible[$Slice]["End"] = TRUE; } |
|
| 386 | + |
|
| 387 | + if ($DataGapAngle == 0) |
|
| 388 | 388 | { $X0 = $X; $Y0 = $Y; } |
| 389 | - else |
|
| 389 | + else |
|
| 390 | 390 | { |
| 391 | - $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 392 | - $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
|
| 393 | - $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius*$SkewFactor + $Y; |
|
| 391 | + $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 392 | + $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
|
| 393 | + $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius*$SkewFactor + $Y; |
|
| 394 | 394 | } |
| 395 | - $Slices[$Slice][] = $X0; $Slices[$Slice][] = $Y0; $SliceAngle[$Slice][] = 0; |
|
| 395 | + $Slices[$Slice][] = $X0; $Slices[$Slice][] = $Y0; $SliceAngle[$Slice][] = 0; |
|
| 396 | 396 | |
| 397 | - for($i=$Offset;$i>=$EndAngle;$i=$i-$Step) |
|
| 397 | + for($i=$Offset;$i>=$EndAngle;$i=$i-$Step) |
|
| 398 | 398 | { |
| 399 | - $Xc = cos(($i-90)*PI/180) * $Radius + $X; |
|
| 400 | - $Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 399 | + $Xc = cos(($i-90)*PI/180) * $Radius + $X; |
|
| 400 | + $Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 401 | 401 | |
| 402 | - if ( ($SecondPass || $RestoreShadow ) && ( $i<90 )) { $Yc++; } |
|
| 403 | - if ( ($SecondPass || $RestoreShadow ) && ( $i>90 && $i<180 )) { $Xc++; } |
|
| 404 | - if ( ($SecondPass || $RestoreShadow ) && ( $i>180 && $i<270 )) { $Xc++; } |
|
| 405 | - if ( ($SecondPass || $RestoreShadow ) && ( $i>=270 )) { $Xc++; $Yc++; } |
|
| 402 | + if ( ($SecondPass || $RestoreShadow ) && ( $i<90 )) { $Yc++; } |
|
| 403 | + if ( ($SecondPass || $RestoreShadow ) && ( $i>90 && $i<180 )) { $Xc++; } |
|
| 404 | + if ( ($SecondPass || $RestoreShadow ) && ( $i>180 && $i<270 )) { $Xc++; } |
|
| 405 | + if ( ($SecondPass || $RestoreShadow ) && ( $i>=270 )) { $Xc++; $Yc++; } |
|
| 406 | 406 | |
| 407 | - $Slices[$Slice][] = $Xc; $Slices[$Slice][] = $Yc; $SliceAngle[$Slice][] = $i; |
|
| 407 | + $Slices[$Slice][] = $Xc; $Slices[$Slice][] = $Yc; $SliceAngle[$Slice][] = $i; |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - $Offset = $i - $DataGapAngle; $ID--; $Slice++; |
|
| 411 | - } |
|
| 410 | + $Offset = $i - $DataGapAngle; $ID--; $Slice++; |
|
| 411 | + } |
|
| 412 | 412 | |
| 413 | - /* Draw the bottom shadow if needed */ |
|
| 414 | - if ( $RestoreShadow && ($this->pChartObject->ShadowX != 0 || $this->pChartObject->ShadowY !=0 )) |
|
| 415 | - { |
|
| 416 | - foreach($Slices as $SliceID => $Plots) |
|
| 413 | + /* Draw the bottom shadow if needed */ |
|
| 414 | + if ( $RestoreShadow && ($this->pChartObject->ShadowX != 0 || $this->pChartObject->ShadowY !=0 )) |
|
| 415 | + { |
|
| 416 | + foreach($Slices as $SliceID => $Plots) |
|
| 417 | 417 | { |
| 418 | - $ShadowPie = ""; |
|
| 419 | - for($i=0;$i<count($Plots);$i=$i+2) |
|
| 420 | - { $ShadowPie[] = $Plots[$i]+$this->pChartObject->ShadowX; $ShadowPie[] = $Plots[$i+1]+$this->pChartObject->ShadowY; } |
|
| 418 | + $ShadowPie = ""; |
|
| 419 | + for($i=0;$i<count($Plots);$i=$i+2) |
|
| 420 | + { $ShadowPie[] = $Plots[$i]+$this->pChartObject->ShadowX; $ShadowPie[] = $Plots[$i+1]+$this->pChartObject->ShadowY; } |
|
| 421 | 421 | |
| 422 | - $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa,"NoBorder"=>TRUE); |
|
| 423 | - $this->pChartObject->drawPolygon($ShadowPie,$Settings); |
|
| 422 | + $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa,"NoBorder"=>TRUE); |
|
| 423 | + $this->pChartObject->drawPolygon($ShadowPie,$Settings); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - $Step = 360 / (2 * PI * $Radius); |
|
| 427 | - $Offset = 360; |
|
| 428 | - foreach($Values as $Key => $Value) |
|
| 426 | + $Step = 360 / (2 * PI * $Radius); |
|
| 427 | + $Offset = 360; |
|
| 428 | + foreach($Values as $Key => $Value) |
|
| 429 | 429 | { |
| 430 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 430 | + $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 431 | 431 | |
| 432 | - for($i=$Offset;$i>=$EndAngle;$i=$i-$Step) |
|
| 433 | - { |
|
| 434 | - $Xc = cos(($i-90)*PI/180) * $Radius + $X + $this->pChartObject->ShadowX; |
|
| 435 | - $Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y + $this->pChartObject->ShadowY; |
|
| 432 | + for($i=$Offset;$i>=$EndAngle;$i=$i-$Step) |
|
| 433 | + { |
|
| 434 | + $Xc = cos(($i-90)*PI/180) * $Radius + $X + $this->pChartObject->ShadowX; |
|
| 435 | + $Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y + $this->pChartObject->ShadowY; |
|
| 436 | 436 | |
| 437 | - $this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings); |
|
| 438 | - } |
|
| 437 | + $this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings); |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - $Offset = $i - $DataGapAngle; $ID--; |
|
| 440 | + $Offset = $i - $DataGapAngle; $ID--; |
|
| 441 | + } |
|
| 441 | 442 | } |
| 442 | - } |
|
| 443 | 443 | |
| 444 | - /* Draw the bottom pie splice */ |
|
| 445 | - foreach($Slices as $SliceID => $Plots) |
|
| 446 | - { |
|
| 447 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 448 | - $this->pChartObject->drawPolygon($Plots,$Settings); |
|
| 444 | + /* Draw the bottom pie splice */ |
|
| 445 | + foreach($Slices as $SliceID => $Plots) |
|
| 446 | + { |
|
| 447 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 448 | + $this->pChartObject->drawPolygon($Plots,$Settings); |
|
| 449 | 449 | |
| 450 | - if ( $SecondPass ) |
|
| 450 | + if ( $SecondPass ) |
|
| 451 | 451 | { |
| 452 | - $Settings = $SliceColors[$SliceID]; |
|
| 453 | - if ( $Border ) |
|
| 454 | - { $Settings["R"]+= 30; $Settings["G"]+= 30; $Settings["B"]+= 30;; } |
|
| 452 | + $Settings = $SliceColors[$SliceID]; |
|
| 453 | + if ( $Border ) |
|
| 454 | + { $Settings["R"]+= 30; $Settings["G"]+= 30; $Settings["B"]+= 30;; } |
|
| 455 | 455 | |
| 456 | - if ( isset($SliceAngle[$SliceID][1]) ) /* Empty error handling */ |
|
| 457 | - { |
|
| 458 | - $Angle = $SliceAngle[$SliceID][1]; |
|
| 459 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 460 | - $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 461 | - $this->pChartObject->drawLine($Plots[0],$Plots[1],$Xc,$Yc,$Settings); |
|
| 462 | - |
|
| 463 | - $Angle = $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1]; |
|
| 464 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 465 | - $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 466 | - $this->pChartObject->drawLine($Plots[0],$Plots[1],$Xc,$Yc,$Settings); |
|
| 467 | - } |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - /* Draw the two vertical edges */ |
|
| 472 | - $Slices = array_reverse($Slices); |
|
| 473 | - $SliceColors = array_reverse($SliceColors); |
|
| 474 | - foreach($Slices as $SliceID => $Plots) |
|
| 475 | - { |
|
| 476 | - $Settings = $SliceColors[$SliceID]; |
|
| 477 | - $Settings["R"]+= 10; $Settings["G"]+= 10; $Settings["B"]+= 10; $Settings["NoBorder"] = TRUE; |
|
| 478 | - |
|
| 479 | - if ( $Visible[$SliceID]["Start"] && isset($Plots[2])) /* Empty error handling */ |
|
| 480 | - { |
|
| 481 | - $this->pChartObject->drawLine($Plots[2],$Plots[3],$Plots[2],$Plots[3]- $SliceHeight,array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"])); |
|
| 482 | - $Border = ""; |
|
| 483 | - $Border[] = $Plots[0]; $Border[] = $Plots[1]; $Border[] = $Plots[0]; $Border[] = $Plots[1] - $SliceHeight; |
|
| 484 | - $Border[] = $Plots[2]; $Border[] = $Plots[3] - $SliceHeight; $Border[] = $Plots[2]; $Border[] = $Plots[3]; |
|
| 485 | - $this->pChartObject->drawPolygon($Border,$Settings); |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - $Slices = array_reverse($Slices); |
|
| 490 | - $SliceColors = array_reverse($SliceColors); |
|
| 491 | - foreach($Slices as $SliceID => $Plots) |
|
| 492 | - { |
|
| 493 | - $Settings = $SliceColors[$SliceID]; |
|
| 494 | - $Settings["R"]+= 10; $Settings["G"]+= 10; $Settings["B"]+= 10; $Settings["NoBorder"] = TRUE; |
|
| 495 | - if ( $Visible[$SliceID]["End"] ) |
|
| 496 | - { |
|
| 497 | - $this->pChartObject->drawLine($Plots[count($Plots)-2],$Plots[count($Plots)-1],$Plots[count($Plots)-2],$Plots[count($Plots)-1]- $SliceHeight,array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"])); |
|
| 498 | - |
|
| 499 | - $Border = ""; |
|
| 500 | - $Border[] = $Plots[0]; $Border[] = $Plots[1]; $Border[] = $Plots[0]; $Border[] = $Plots[1] - $SliceHeight; |
|
| 501 | - $Border[] = $Plots[count($Plots)-2]; $Border[] = $Plots[count($Plots)-1] - $SliceHeight; $Border[] = $Plots[count($Plots)-2]; $Border[] = $Plots[count($Plots)-1]; |
|
| 502 | - $this->pChartObject->drawPolygon($Border,$Settings); |
|
| 503 | - } |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /* Draw the rounded edges */ |
|
| 507 | - foreach($Slices as $SliceID => $Plots) |
|
| 508 | - { |
|
| 509 | - $Settings = $SliceColors[$SliceID]; |
|
| 510 | - $Settings["R"]+= 10; $Settings["G"]+= 10; $Settings["B"]+= 10; $Settings["NoBorder"] = TRUE; |
|
| 511 | - |
|
| 512 | - for ($j=2;$j<count($Plots)-2;$j=$j+2) |
|
| 513 | - { |
|
| 514 | - $Angle = $SliceAngle[$SliceID][$j/2]; |
|
| 515 | - if ( $Angle < 270 && $Angle > 90 ) |
|
| 516 | - { |
|
| 517 | - $Border = ""; |
|
| 518 | - $Border[] = $Plots[$j]; $Border[] = $Plots[$j+1]; |
|
| 519 | - $Border[] = $Plots[$j+2]; $Border[] = $Plots[$j+3]; |
|
| 520 | - $Border[] = $Plots[$j+2]; $Border[] = $Plots[$j+3] - $SliceHeight; |
|
| 521 | - $Border[] = $Plots[$j]; $Border[] = $Plots[$j+1] - $SliceHeight; |
|
| 522 | - $this->pChartObject->drawPolygon($Border,$Settings); |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - if ( $SecondPass ) |
|
| 527 | - { |
|
| 528 | - $Settings = $SliceColors[$SliceID]; |
|
| 529 | - if ( $Border ) |
|
| 530 | - { $Settings["R"]+= 30; $Settings["G"]+= 30; $Settings["B"]+= 30; } |
|
| 456 | + if ( isset($SliceAngle[$SliceID][1]) ) /* Empty error handling */ |
|
| 457 | + { |
|
| 458 | + $Angle = $SliceAngle[$SliceID][1]; |
|
| 459 | + $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 460 | + $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 461 | + $this->pChartObject->drawLine($Plots[0],$Plots[1],$Xc,$Yc,$Settings); |
|
| 462 | + |
|
| 463 | + $Angle = $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1]; |
|
| 464 | + $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 465 | + $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 466 | + $this->pChartObject->drawLine($Plots[0],$Plots[1],$Xc,$Yc,$Settings); |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + /* Draw the two vertical edges */ |
|
| 472 | + $Slices = array_reverse($Slices); |
|
| 473 | + $SliceColors = array_reverse($SliceColors); |
|
| 474 | + foreach($Slices as $SliceID => $Plots) |
|
| 475 | + { |
|
| 476 | + $Settings = $SliceColors[$SliceID]; |
|
| 477 | + $Settings["R"]+= 10; $Settings["G"]+= 10; $Settings["B"]+= 10; $Settings["NoBorder"] = TRUE; |
|
| 478 | + |
|
| 479 | + if ( $Visible[$SliceID]["Start"] && isset($Plots[2])) /* Empty error handling */ |
|
| 480 | + { |
|
| 481 | + $this->pChartObject->drawLine($Plots[2],$Plots[3],$Plots[2],$Plots[3]- $SliceHeight,array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"])); |
|
| 482 | + $Border = ""; |
|
| 483 | + $Border[] = $Plots[0]; $Border[] = $Plots[1]; $Border[] = $Plots[0]; $Border[] = $Plots[1] - $SliceHeight; |
|
| 484 | + $Border[] = $Plots[2]; $Border[] = $Plots[3] - $SliceHeight; $Border[] = $Plots[2]; $Border[] = $Plots[3]; |
|
| 485 | + $this->pChartObject->drawPolygon($Border,$Settings); |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + $Slices = array_reverse($Slices); |
|
| 490 | + $SliceColors = array_reverse($SliceColors); |
|
| 491 | + foreach($Slices as $SliceID => $Plots) |
|
| 492 | + { |
|
| 493 | + $Settings = $SliceColors[$SliceID]; |
|
| 494 | + $Settings["R"]+= 10; $Settings["G"]+= 10; $Settings["B"]+= 10; $Settings["NoBorder"] = TRUE; |
|
| 495 | + if ( $Visible[$SliceID]["End"] ) |
|
| 496 | + { |
|
| 497 | + $this->pChartObject->drawLine($Plots[count($Plots)-2],$Plots[count($Plots)-1],$Plots[count($Plots)-2],$Plots[count($Plots)-1]- $SliceHeight,array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"])); |
|
| 498 | + |
|
| 499 | + $Border = ""; |
|
| 500 | + $Border[] = $Plots[0]; $Border[] = $Plots[1]; $Border[] = $Plots[0]; $Border[] = $Plots[1] - $SliceHeight; |
|
| 501 | + $Border[] = $Plots[count($Plots)-2]; $Border[] = $Plots[count($Plots)-1] - $SliceHeight; $Border[] = $Plots[count($Plots)-2]; $Border[] = $Plots[count($Plots)-1]; |
|
| 502 | + $this->pChartObject->drawPolygon($Border,$Settings); |
|
| 503 | + } |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /* Draw the rounded edges */ |
|
| 507 | + foreach($Slices as $SliceID => $Plots) |
|
| 508 | + { |
|
| 509 | + $Settings = $SliceColors[$SliceID]; |
|
| 510 | + $Settings["R"]+= 10; $Settings["G"]+= 10; $Settings["B"]+= 10; $Settings["NoBorder"] = TRUE; |
|
| 511 | + |
|
| 512 | + for ($j=2;$j<count($Plots)-2;$j=$j+2) |
|
| 513 | + { |
|
| 514 | + $Angle = $SliceAngle[$SliceID][$j/2]; |
|
| 515 | + if ( $Angle < 270 && $Angle > 90 ) |
|
| 516 | + { |
|
| 517 | + $Border = ""; |
|
| 518 | + $Border[] = $Plots[$j]; $Border[] = $Plots[$j+1]; |
|
| 519 | + $Border[] = $Plots[$j+2]; $Border[] = $Plots[$j+3]; |
|
| 520 | + $Border[] = $Plots[$j+2]; $Border[] = $Plots[$j+3] - $SliceHeight; |
|
| 521 | + $Border[] = $Plots[$j]; $Border[] = $Plots[$j+1] - $SliceHeight; |
|
| 522 | + $this->pChartObject->drawPolygon($Border,$Settings); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + if ( $SecondPass ) |
|
| 527 | + { |
|
| 528 | + $Settings = $SliceColors[$SliceID]; |
|
| 529 | + if ( $Border ) |
|
| 530 | + { $Settings["R"]+= 30; $Settings["G"]+= 30; $Settings["B"]+= 30; } |
|
| 531 | 531 | |
| 532 | - if ( isset($SliceAngle[$SliceID][1]) ) /* Empty error handling */ |
|
| 533 | - { |
|
| 534 | - $Angle = $SliceAngle[$SliceID][1]; |
|
| 535 | - if ( $Angle < 270 && $Angle > 90 ) |
|
| 532 | + if ( isset($SliceAngle[$SliceID][1]) ) /* Empty error handling */ |
|
| 533 | + { |
|
| 534 | + $Angle = $SliceAngle[$SliceID][1]; |
|
| 535 | + if ( $Angle < 270 && $Angle > 90 ) |
|
| 536 | + { |
|
| 537 | + $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 538 | + $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 539 | + $this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings); |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + $Angle = $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1]; |
|
| 544 | + if ( $Angle < 270 && $Angle > 90 ) |
|
| 545 | + { |
|
| 546 | + $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 547 | + $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 548 | + $this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + if ( isset($SliceAngle[$SliceID][1]) && $SliceAngle[$SliceID][1] > 270 && $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1] < 270 ) |
|
| 552 | + { |
|
| 553 | + $Xc = cos((270-90)*PI/180) * $Radius + $X; |
|
| 554 | + $Yc = sin((270-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 555 | + $this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + if ( isset($SliceAngle[$SliceID][1]) && $SliceAngle[$SliceID][1] > 90 && $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1] < 90 ) |
|
| 536 | 559 | { |
| 537 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 538 | - $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 539 | - $this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings); |
|
| 560 | + $Xc = cos((0)*PI/180) * $Radius + $X; |
|
| 561 | + $Yc = sin((0)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 562 | + $this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings); |
|
| 540 | 563 | } |
| 541 | - } |
|
| 542 | - |
|
| 543 | - $Angle = $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1]; |
|
| 544 | - if ( $Angle < 270 && $Angle > 90 ) |
|
| 545 | - { |
|
| 546 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 547 | - $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 548 | - $this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - if ( isset($SliceAngle[$SliceID][1]) && $SliceAngle[$SliceID][1] > 270 && $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1] < 270 ) |
|
| 552 | - { |
|
| 553 | - $Xc = cos((270-90)*PI/180) * $Radius + $X; |
|
| 554 | - $Yc = sin((270-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 555 | - $this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - if ( isset($SliceAngle[$SliceID][1]) && $SliceAngle[$SliceID][1] > 90 && $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1] < 90 ) |
|
| 559 | - { |
|
| 560 | - $Xc = cos((0)*PI/180) * $Radius + $X; |
|
| 561 | - $Yc = sin((0)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 562 | - $this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - /* Draw the top splice */ |
|
| 569 | - foreach($Slices as $SliceID => $Plots) |
|
| 570 | - { |
|
| 571 | - $Settings = $SliceColors[$SliceID]; |
|
| 572 | - $Settings["R"]+= 20; $Settings["G"]+= 20; $Settings["B"]+= 20; |
|
| 573 | - |
|
| 574 | - $Top = ""; |
|
| 575 | - for($j=0;$j<count($Plots);$j=$j+2) { $Top[] = $Plots[$j]; $Top[] = $Plots[$j+1]- $SliceHeight; } |
|
| 576 | - $this->pChartObject->drawPolygon($Top,$Settings); |
|
| 577 | - |
|
| 578 | - if ( $RecordImageMap && !$Shadow ) { $this->pChartObject->addToImageMap("POLY",$this->arraySerialize($Top),$this->pChartObject->toHTMLColor($Settings["R"],$Settings["G"],$Settings["B"]),$Data["Series"][$Data["Abscissa"]]["Data"][count($Slices)-$SliceID-1],$Values[$SliceID]); } |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - |
|
| 582 | - /* Second pass to smooth the angles */ |
|
| 583 | - if ( $SecondPass ) |
|
| 584 | - { |
|
| 585 | - $Step = 360 / (2 * PI * $Radius); |
|
| 586 | - $Offset = 360; $ID = count($Values)-1; |
|
| 587 | - foreach($Values as $Key => $Value) |
|
| 588 | - { |
|
| 589 | - $FirstPoint = TRUE; |
|
| 590 | - if ( $Shadow ) |
|
| 591 | - $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 592 | - else |
|
| 593 | - { |
|
| 594 | - if ( $Border ) |
|
| 564 | + |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + /* Draw the top splice */ |
|
| 569 | + foreach($Slices as $SliceID => $Plots) |
|
| 570 | + { |
|
| 571 | + $Settings = $SliceColors[$SliceID]; |
|
| 572 | + $Settings["R"]+= 20; $Settings["G"]+= 20; $Settings["B"]+= 20; |
|
| 573 | + |
|
| 574 | + $Top = ""; |
|
| 575 | + for($j=0;$j<count($Plots);$j=$j+2) { $Top[] = $Plots[$j]; $Top[] = $Plots[$j+1]- $SliceHeight; } |
|
| 576 | + $this->pChartObject->drawPolygon($Top,$Settings); |
|
| 577 | + |
|
| 578 | + if ( $RecordImageMap && !$Shadow ) { $this->pChartObject->addToImageMap("POLY",$this->arraySerialize($Top),$this->pChartObject->toHTMLColor($Settings["R"],$Settings["G"],$Settings["B"]),$Data["Series"][$Data["Abscissa"]]["Data"][count($Slices)-$SliceID-1],$Values[$SliceID]); } |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + |
|
| 582 | + /* Second pass to smooth the angles */ |
|
| 583 | + if ( $SecondPass ) |
|
| 584 | + { |
|
| 585 | + $Step = 360 / (2 * PI * $Radius); |
|
| 586 | + $Offset = 360; $ID = count($Values)-1; |
|
| 587 | + foreach($Values as $Key => $Value) |
|
| 588 | + { |
|
| 589 | + $FirstPoint = TRUE; |
|
| 590 | + if ( $Shadow ) |
|
| 591 | + $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 592 | + else |
|
| 593 | + { |
|
| 594 | + if ( $Border ) |
|
| 595 | 595 | { $Settings = array("R"=>$Palette[$ID]["R"]+30,"G"=>$Palette[$ID]["G"]+30,"B"=>$Palette[$ID]["B"]+30,"Alpha"=>$Palette[$ID]["Alpha"]); } |
| 596 | - else |
|
| 596 | + else |
|
| 597 | 597 | $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
| 598 | - } |
|
| 599 | - |
|
| 600 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 601 | - |
|
| 602 | - if ($DataGapAngle == 0) |
|
| 603 | - { $X0 = $X; $Y0 = $Y- $SliceHeight; } |
|
| 604 | - else |
|
| 605 | - { |
|
| 606 | - $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 607 | - $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
|
| 608 | - $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius*$SkewFactor + $Y - $SliceHeight; |
|
| 609 | - } |
|
| 610 | - $Plots[] = $X0; $Plots[] = $Y0; |
|
| 611 | - |
|
| 612 | - for($i=$Offset;$i>=$EndAngle;$i=$i-$Step) |
|
| 613 | - { |
|
| 614 | - $Xc = cos(($i-90)*PI/180) * $Radius + $X; |
|
| 615 | - $Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y - $SliceHeight; |
|
| 616 | - |
|
| 617 | - if ( $FirstPoint ) { $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); } { $FirstPoint = FALSE; } |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 601 | + |
|
| 602 | + if ($DataGapAngle == 0) |
|
| 603 | + { $X0 = $X; $Y0 = $Y- $SliceHeight; } |
|
| 604 | + else |
|
| 605 | + { |
|
| 606 | + $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 607 | + $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
|
| 608 | + $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius*$SkewFactor + $Y - $SliceHeight; |
|
| 609 | + } |
|
| 610 | + $Plots[] = $X0; $Plots[] = $Y0; |
|
| 611 | + |
|
| 612 | + for($i=$Offset;$i>=$EndAngle;$i=$i-$Step) |
|
| 613 | + { |
|
| 614 | + $Xc = cos(($i-90)*PI/180) * $Radius + $X; |
|
| 615 | + $Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y - $SliceHeight; |
|
| 616 | + |
|
| 617 | + if ( $FirstPoint ) { $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); } { $FirstPoint = FALSE; } |
|
| 618 | 618 | |
| 619 | - $this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings); |
|
| 620 | - if ($i < 270 && $i > 90 ) { $this->pChartObject->drawAntialiasPixel($Xc,$Yc+$SliceHeight,$Settings); } |
|
| 621 | - } |
|
| 622 | - $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); |
|
| 619 | + $this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings); |
|
| 620 | + if ($i < 270 && $i > 90 ) { $this->pChartObject->drawAntialiasPixel($Xc,$Yc+$SliceHeight,$Settings); } |
|
| 621 | + } |
|
| 622 | + $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); |
|
| 623 | 623 | |
| 624 | - $Offset = $i - $DataGapAngle; $ID--; |
|
| 624 | + $Offset = $i - $DataGapAngle; $ID--; |
|
| 625 | + } |
|
| 625 | 626 | } |
| 626 | - } |
|
| 627 | 627 | |
| 628 | - if ( $WriteValues != NULL ) |
|
| 629 | - { |
|
| 630 | - $Step = 360 / (2 * PI * $Radius); |
|
| 631 | - $Offset = 360; $ID = count($Values)-1; |
|
| 632 | - $Settings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"R"=>$ValueR,"G"=>$ValueG,"B"=>$ValueB,"Alpha"=>$ValueAlpha); |
|
| 633 | - foreach($Values as $Key => $Value) |
|
| 628 | + if ( $WriteValues != NULL ) |
|
| 634 | 629 | { |
| 635 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 630 | + $Step = 360 / (2 * PI * $Radius); |
|
| 631 | + $Offset = 360; $ID = count($Values)-1; |
|
| 632 | + $Settings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"R"=>$ValueR,"G"=>$ValueG,"B"=>$ValueB,"Alpha"=>$ValueAlpha); |
|
| 633 | + foreach($Values as $Key => $Value) |
|
| 634 | + { |
|
| 635 | + $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 636 | 636 | |
| 637 | - $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 637 | + $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 638 | 638 | |
| 639 | - if ( $ValuePosition == PIE_VALUE_OUTSIDE ) |
|
| 640 | - { |
|
| 641 | - $Xc = cos(($Angle-90)*PI/180) * ($Radius+$ValuePadding) + $X; |
|
| 642 | - $Yc = sin(($Angle-90)*PI/180) * (($Radius*$SkewFactor)+$ValuePadding) + $Y - $SliceHeight; |
|
| 643 | - } |
|
| 644 | - else |
|
| 645 | - { |
|
| 646 | - $Xc = cos(($Angle-90)*PI/180) * ($Radius)/2 + $X; |
|
| 647 | - $Yc = sin(($Angle-90)*PI/180) * ($Radius*$SkewFactor)/2 + $Y - $SliceHeight; |
|
| 648 | - } |
|
| 639 | + if ( $ValuePosition == PIE_VALUE_OUTSIDE ) |
|
| 640 | + { |
|
| 641 | + $Xc = cos(($Angle-90)*PI/180) * ($Radius+$ValuePadding) + $X; |
|
| 642 | + $Yc = sin(($Angle-90)*PI/180) * (($Radius*$SkewFactor)+$ValuePadding) + $Y - $SliceHeight; |
|
| 643 | + } |
|
| 644 | + else |
|
| 645 | + { |
|
| 646 | + $Xc = cos(($Angle-90)*PI/180) * ($Radius)/2 + $X; |
|
| 647 | + $Yc = sin(($Angle-90)*PI/180) * ($Radius*$SkewFactor)/2 + $Y - $SliceHeight; |
|
| 648 | + } |
|
| 649 | 649 | |
| 650 | - if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 651 | - $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 652 | - elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 653 | - $Display = $Value.$ValueSuffix; |
|
| 650 | + if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 651 | + $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 652 | + elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 653 | + $Display = $Value.$ValueSuffix; |
|
| 654 | 654 | |
| 655 | - $this->pChartObject->drawText($Xc,$Yc,$Display,$Settings); |
|
| 655 | + $this->pChartObject->drawText($Xc,$Yc,$Display,$Settings); |
|
| 656 | 656 | |
| 657 | - $Offset = $EndAngle - $DataGapAngle; $ID--; |
|
| 657 | + $Offset = $EndAngle - $DataGapAngle; $ID--; |
|
| 658 | + } |
|
| 658 | 659 | } |
| 659 | - } |
|
| 660 | 660 | |
| 661 | - if ( $DrawLabels ) |
|
| 662 | - { |
|
| 663 | - $Step = 360 / (2 * PI * $Radius); |
|
| 664 | - $Offset = 360; $ID = count($Values)-1; |
|
| 665 | - foreach($Values as $Key => $Value) |
|
| 661 | + if ( $DrawLabels ) |
|
| 666 | 662 | { |
| 667 | - if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 668 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 669 | - else |
|
| 670 | - { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
|
| 663 | + $Step = 360 / (2 * PI * $Radius); |
|
| 664 | + $Offset = 360; $ID = count($Values)-1; |
|
| 665 | + foreach($Values as $Key => $Value) |
|
| 666 | + { |
|
| 667 | + if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 668 | + { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 669 | + else |
|
| 670 | + { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
|
| 671 | 671 | |
| 672 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 672 | + $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 673 | 673 | |
| 674 | - $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 675 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 676 | - $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y - $SliceHeight; |
|
| 674 | + $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 675 | + $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 676 | + $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y - $SliceHeight; |
|
| 677 | 677 | |
| 678 | - if ( isset($Data["Series"][$Data["Abscissa"]]["Data"][$ID]) ) |
|
| 679 | - { |
|
| 680 | - $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$ID]; |
|
| 678 | + if ( isset($Data["Series"][$Data["Abscissa"]]["Data"][$ID]) ) |
|
| 679 | + { |
|
| 680 | + $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$ID]; |
|
| 681 | 681 | |
| 682 | - if ( $LabelStacked ) |
|
| 682 | + if ( $LabelStacked ) |
|
| 683 | 683 | $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$Radius,TRUE); |
| 684 | - else |
|
| 684 | + else |
|
| 685 | 685 | $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
| 686 | - } |
|
| 686 | + } |
|
| 687 | 687 | |
| 688 | - $Offset = $EndAngle - $DataGapAngle; $ID--; |
|
| 688 | + $Offset = $EndAngle - $DataGapAngle; $ID--; |
|
| 689 | + } |
|
| 689 | 690 | } |
| 690 | - } |
|
| 691 | 691 | |
| 692 | - if ( $DrawLabels && $LabelStacked ) { $this->writeShiftedLabels(); } |
|
| 692 | + if ( $DrawLabels && $LabelStacked ) { $this->writeShiftedLabels(); } |
|
| 693 | 693 | |
| 694 | - $this->pChartObject->Shadow = $RestoreShadow; |
|
| 694 | + $this->pChartObject->Shadow = $RestoreShadow; |
|
| 695 | 695 | |
| 696 | - return(PIE_RENDERED); |
|
| 696 | + return(PIE_RENDERED); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | - /* Draw the legend of pie chart */ |
|
| 700 | - function drawPieLegend($X,$Y,$Format="") |
|
| 699 | + /* Draw the legend of pie chart */ |
|
| 700 | + function drawPieLegend($X,$Y,$Format="") |
|
| 701 | 701 | { |
| 702 | - $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName; |
|
| 703 | - $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize; |
|
| 704 | - $FontR = isset($Format["FontR"]) ? $Format["FontR"] : $this->pChartObject->FontColorR; |
|
| 705 | - $FontG = isset($Format["FontG"]) ? $Format["FontG"] : $this->pChartObject->FontColorG; |
|
| 706 | - $FontB = isset($Format["FontB"]) ? $Format["FontB"] : $this->pChartObject->FontColorB; |
|
| 707 | - $BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5; |
|
| 708 | - $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5; |
|
| 709 | - $R = isset($Format["R"]) ? $Format["R"] : 200; |
|
| 710 | - $G = isset($Format["G"]) ? $Format["G"] : 200; |
|
| 711 | - $B = isset($Format["B"]) ? $Format["B"] : 200; |
|
| 712 | - $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100; |
|
| 713 | - $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255; |
|
| 714 | - $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255; |
|
| 715 | - $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255; |
|
| 716 | - $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL; |
|
| 717 | - $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND; |
|
| 718 | - $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL; |
|
| 719 | - |
|
| 720 | - if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; } |
|
| 721 | - |
|
| 722 | - $YStep = max($this->pChartObject->FontSize,$BoxSize) + 5; |
|
| 723 | - $XStep = $BoxSize + 5; |
|
| 724 | - |
|
| 725 | - /* Data Processing */ |
|
| 726 | - $Data = $this->pDataObject->getData(); |
|
| 727 | - $Palette = $this->pDataObject->getPalette(); |
|
| 728 | - |
|
| 729 | - /* Do we have an abscissa serie defined? */ |
|
| 730 | - if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 731 | - |
|
| 732 | - $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X; |
|
| 733 | - foreach($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value) |
|
| 734 | - { |
|
| 735 | - $BoxArray = $this->pChartObject->getTextBox($vX+$BoxSize+4,$vY+$BoxSize/2,$FontName,$FontSize,0,$Value); |
|
| 736 | - |
|
| 737 | - if ( $Mode == LEGEND_VERTICAL ) |
|
| 738 | - { |
|
| 739 | - if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$BoxSize/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$BoxSize/2; } |
|
| 740 | - if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; } |
|
| 741 | - if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$BoxSize/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$BoxSize/2; } |
|
| 742 | - $vY=$vY+$YStep; |
|
| 743 | - } |
|
| 744 | - elseif ( $Mode == LEGEND_HORIZONTAL ) |
|
| 745 | - { |
|
| 746 | - if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$BoxSize/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$BoxSize/2; } |
|
| 747 | - if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; } |
|
| 748 | - if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$BoxSize/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$BoxSize/2; } |
|
| 749 | - $vX=$Boundaries["R"]+$XStep; |
|
| 750 | - } |
|
| 751 | - } |
|
| 752 | - $vY=$vY-$YStep; $vX=$vX-$XStep; |
|
| 753 | - |
|
| 754 | - $TopOffset = $Y - $Boundaries["T"]; |
|
| 755 | - if ( $Boundaries["B"]-($vY+$BoxSize) < $TopOffset ) { $Boundaries["B"] = $vY+$BoxSize+$TopOffset; } |
|
| 756 | - |
|
| 757 | - if ( $Style == LEGEND_ROUND ) |
|
| 758 | - $this->pChartObject->drawRoundedFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB)); |
|
| 759 | - elseif ( $Style == LEGEND_BOX ) |
|
| 760 | - $this->pChartObject->drawFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB)); |
|
| 761 | - |
|
| 762 | - $RestoreShadow = $this->pChartObject->Shadow; $this->pChartObject->Shadow = FALSE; |
|
| 763 | - foreach($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value) |
|
| 764 | - { |
|
| 765 | - $R = $Palette[$Key]["R"]; $G = $Palette[$Key]["G"]; $B = $Palette[$Key]["B"]; |
|
| 766 | - |
|
| 767 | - $this->pChartObject->drawFilledRectangle($X+1,$Y+1,$X+$BoxSize+1,$Y+$BoxSize+1,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20)); |
|
| 768 | - $this->pChartObject->drawFilledRectangle($X,$Y,$X+$BoxSize,$Y+$BoxSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20)); |
|
| 769 | - if ( $Mode == LEGEND_VERTICAL ) |
|
| 770 | - { |
|
| 771 | - $this->pChartObject->drawText($X+$BoxSize+4,$Y+$BoxSize/2,$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT,"FontName"=>$FontName,"FontSize"=>$FontSize)); |
|
| 772 | - $Y=$Y+$YStep; |
|
| 773 | - } |
|
| 774 | - elseif ( $Mode == LEGEND_HORIZONTAL ) |
|
| 775 | - { |
|
| 776 | - $BoxArray = $this->pChartObject->drawText($X+$BoxSize+4,$Y+$BoxSize/2,$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT,"FontName"=>$FontName,"FontSize"=>$FontSize)); |
|
| 777 | - $X=$BoxArray[1]["X"]+2+$XStep; |
|
| 778 | - } |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - $this->Shadow = $RestoreShadow; |
|
| 702 | + $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName; |
|
| 703 | + $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize; |
|
| 704 | + $FontR = isset($Format["FontR"]) ? $Format["FontR"] : $this->pChartObject->FontColorR; |
|
| 705 | + $FontG = isset($Format["FontG"]) ? $Format["FontG"] : $this->pChartObject->FontColorG; |
|
| 706 | + $FontB = isset($Format["FontB"]) ? $Format["FontB"] : $this->pChartObject->FontColorB; |
|
| 707 | + $BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5; |
|
| 708 | + $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5; |
|
| 709 | + $R = isset($Format["R"]) ? $Format["R"] : 200; |
|
| 710 | + $G = isset($Format["G"]) ? $Format["G"] : 200; |
|
| 711 | + $B = isset($Format["B"]) ? $Format["B"] : 200; |
|
| 712 | + $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100; |
|
| 713 | + $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255; |
|
| 714 | + $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255; |
|
| 715 | + $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255; |
|
| 716 | + $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL; |
|
| 717 | + $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND; |
|
| 718 | + $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL; |
|
| 719 | + |
|
| 720 | + if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; } |
|
| 721 | + |
|
| 722 | + $YStep = max($this->pChartObject->FontSize,$BoxSize) + 5; |
|
| 723 | + $XStep = $BoxSize + 5; |
|
| 724 | + |
|
| 725 | + /* Data Processing */ |
|
| 726 | + $Data = $this->pDataObject->getData(); |
|
| 727 | + $Palette = $this->pDataObject->getPalette(); |
|
| 728 | + |
|
| 729 | + /* Do we have an abscissa serie defined? */ |
|
| 730 | + if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 731 | + |
|
| 732 | + $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X; |
|
| 733 | + foreach($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value) |
|
| 734 | + { |
|
| 735 | + $BoxArray = $this->pChartObject->getTextBox($vX+$BoxSize+4,$vY+$BoxSize/2,$FontName,$FontSize,0,$Value); |
|
| 736 | + |
|
| 737 | + if ( $Mode == LEGEND_VERTICAL ) |
|
| 738 | + { |
|
| 739 | + if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$BoxSize/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$BoxSize/2; } |
|
| 740 | + if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; } |
|
| 741 | + if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$BoxSize/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$BoxSize/2; } |
|
| 742 | + $vY=$vY+$YStep; |
|
| 743 | + } |
|
| 744 | + elseif ( $Mode == LEGEND_HORIZONTAL ) |
|
| 745 | + { |
|
| 746 | + if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$BoxSize/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$BoxSize/2; } |
|
| 747 | + if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; } |
|
| 748 | + if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$BoxSize/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$BoxSize/2; } |
|
| 749 | + $vX=$Boundaries["R"]+$XStep; |
|
| 750 | + } |
|
| 751 | + } |
|
| 752 | + $vY=$vY-$YStep; $vX=$vX-$XStep; |
|
| 753 | + |
|
| 754 | + $TopOffset = $Y - $Boundaries["T"]; |
|
| 755 | + if ( $Boundaries["B"]-($vY+$BoxSize) < $TopOffset ) { $Boundaries["B"] = $vY+$BoxSize+$TopOffset; } |
|
| 756 | + |
|
| 757 | + if ( $Style == LEGEND_ROUND ) |
|
| 758 | + $this->pChartObject->drawRoundedFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB)); |
|
| 759 | + elseif ( $Style == LEGEND_BOX ) |
|
| 760 | + $this->pChartObject->drawFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB)); |
|
| 761 | + |
|
| 762 | + $RestoreShadow = $this->pChartObject->Shadow; $this->pChartObject->Shadow = FALSE; |
|
| 763 | + foreach($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value) |
|
| 764 | + { |
|
| 765 | + $R = $Palette[$Key]["R"]; $G = $Palette[$Key]["G"]; $B = $Palette[$Key]["B"]; |
|
| 766 | + |
|
| 767 | + $this->pChartObject->drawFilledRectangle($X+1,$Y+1,$X+$BoxSize+1,$Y+$BoxSize+1,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20)); |
|
| 768 | + $this->pChartObject->drawFilledRectangle($X,$Y,$X+$BoxSize,$Y+$BoxSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20)); |
|
| 769 | + if ( $Mode == LEGEND_VERTICAL ) |
|
| 770 | + { |
|
| 771 | + $this->pChartObject->drawText($X+$BoxSize+4,$Y+$BoxSize/2,$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT,"FontName"=>$FontName,"FontSize"=>$FontSize)); |
|
| 772 | + $Y=$Y+$YStep; |
|
| 773 | + } |
|
| 774 | + elseif ( $Mode == LEGEND_HORIZONTAL ) |
|
| 775 | + { |
|
| 776 | + $BoxArray = $this->pChartObject->drawText($X+$BoxSize+4,$Y+$BoxSize/2,$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT,"FontName"=>$FontName,"FontSize"=>$FontSize)); |
|
| 777 | + $X=$BoxArray[1]["X"]+2+$XStep; |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + $this->Shadow = $RestoreShadow; |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | - /* Set the color of the specified slice */ |
|
| 785 | - function setSliceColor($SliceID,$Format="") |
|
| 784 | + /* Set the color of the specified slice */ |
|
| 785 | + function setSliceColor($SliceID,$Format="") |
|
| 786 | 786 | { |
| 787 | - $R = isset($Format["R"]) ? $Format["R"] : 0; |
|
| 788 | - $G = isset($Format["G"]) ? $Format["G"] : 0; |
|
| 789 | - $B = isset($Format["B"]) ? $Format["B"] : 0; |
|
| 790 | - $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100; |
|
| 791 | - |
|
| 792 | - $this->pDataObject->Palette[$SliceID]["R"] = $R; |
|
| 793 | - $this->pDataObject->Palette[$SliceID]["G"] = $G; |
|
| 794 | - $this->pDataObject->Palette[$SliceID]["B"] = $B; |
|
| 795 | - $this->pDataObject->Palette[$SliceID]["Alpha"] = $Alpha; |
|
| 787 | + $R = isset($Format["R"]) ? $Format["R"] : 0; |
|
| 788 | + $G = isset($Format["G"]) ? $Format["G"] : 0; |
|
| 789 | + $B = isset($Format["B"]) ? $Format["B"] : 0; |
|
| 790 | + $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100; |
|
| 791 | + |
|
| 792 | + $this->pDataObject->Palette[$SliceID]["R"] = $R; |
|
| 793 | + $this->pDataObject->Palette[$SliceID]["G"] = $G; |
|
| 794 | + $this->pDataObject->Palette[$SliceID]["B"] = $B; |
|
| 795 | + $this->pDataObject->Palette[$SliceID]["Alpha"] = $Alpha; |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | - /* Internally used compute the label positions */ |
|
| 799 | - function writePieLabel($X,$Y,$Label,$Angle,$Settings,$Stacked,$Xc=0,$Yc=0,$Radius=0,$Reversed=FALSE) |
|
| 798 | + /* Internally used compute the label positions */ |
|
| 799 | + function writePieLabel($X,$Y,$Label,$Angle,$Settings,$Stacked,$Xc=0,$Yc=0,$Radius=0,$Reversed=FALSE) |
|
| 800 | 800 | { |
| 801 | - $LabelOffset = 30; |
|
| 802 | - $FontName = $this->pChartObject->FontName; |
|
| 803 | - $FontSize = $this->pChartObject->FontSize; |
|
| 804 | - |
|
| 805 | - if ( !$Stacked ) |
|
| 806 | - { |
|
| 807 | - $Settings["Angle"] = 360-$Angle; |
|
| 808 | - $Settings["Length"] = 25; |
|
| 809 | - $Settings["Size"] = 8; |
|
| 810 | - |
|
| 811 | - $this->pChartObject->drawArrowLabel($X,$Y," ".$Label." ",$Settings); |
|
| 812 | - } |
|
| 813 | - else |
|
| 814 | - { |
|
| 815 | - $X2 = cos(deg2rad($Angle-90))*20+$X; |
|
| 816 | - $Y2 = sin(deg2rad($Angle-90))*20+$Y; |
|
| 817 | - |
|
| 818 | - $TxtPos = $this->pChartObject->getTextBox($X,$Y,$FontName,$FontSize,0,$Label); |
|
| 819 | - $Height = $TxtPos[0]["Y"] - $TxtPos[2]["Y"]; |
|
| 820 | - $YTop = $Y2 - $Height/2 - 2; |
|
| 821 | - $YBottom = $Y2 + $Height/2 + 2; |
|
| 822 | - |
|
| 823 | - if ( $this->LabelPos != "" ) |
|
| 824 | - { |
|
| 825 | - $Done = FALSE; |
|
| 826 | - foreach($this->LabelPos as $Key => $Settings) |
|
| 827 | - { |
|
| 828 | - if ( !$Done ) |
|
| 801 | + $LabelOffset = 30; |
|
| 802 | + $FontName = $this->pChartObject->FontName; |
|
| 803 | + $FontSize = $this->pChartObject->FontSize; |
|
| 804 | + |
|
| 805 | + if ( !$Stacked ) |
|
| 806 | + { |
|
| 807 | + $Settings["Angle"] = 360-$Angle; |
|
| 808 | + $Settings["Length"] = 25; |
|
| 809 | + $Settings["Size"] = 8; |
|
| 810 | + |
|
| 811 | + $this->pChartObject->drawArrowLabel($X,$Y," ".$Label." ",$Settings); |
|
| 812 | + } |
|
| 813 | + else |
|
| 814 | + { |
|
| 815 | + $X2 = cos(deg2rad($Angle-90))*20+$X; |
|
| 816 | + $Y2 = sin(deg2rad($Angle-90))*20+$Y; |
|
| 817 | + |
|
| 818 | + $TxtPos = $this->pChartObject->getTextBox($X,$Y,$FontName,$FontSize,0,$Label); |
|
| 819 | + $Height = $TxtPos[0]["Y"] - $TxtPos[2]["Y"]; |
|
| 820 | + $YTop = $Y2 - $Height/2 - 2; |
|
| 821 | + $YBottom = $Y2 + $Height/2 + 2; |
|
| 822 | + |
|
| 823 | + if ( $this->LabelPos != "" ) |
|
| 824 | + { |
|
| 825 | + $Done = FALSE; |
|
| 826 | + foreach($this->LabelPos as $Key => $Settings) |
|
| 827 | + { |
|
| 828 | + if ( !$Done ) |
|
| 829 | 829 | { |
| 830 | - if ( $Angle <= 90 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 831 | - { $this->shift(0,180,-($Height+2),$Reversed); $Done = TRUE; } |
|
| 832 | - if ( $Angle > 90 && $Angle <= 180 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 833 | - { $this->shift(0,180,-($Height+2),$Reversed); $Done = TRUE; } |
|
| 834 | - if ( $Angle > 180 && $Angle <= 270 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 835 | - { $this->shift(180,360,($Height+2),$Reversed); $Done = TRUE; } |
|
| 836 | - if ( $Angle > 270 && $Angle <= 360 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 837 | - { $this->shift(180,360,($Height+2),$Reversed); $Done = TRUE; } |
|
| 830 | + if ( $Angle <= 90 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 831 | + { $this->shift(0,180,-($Height+2),$Reversed); $Done = TRUE; } |
|
| 832 | + if ( $Angle > 90 && $Angle <= 180 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 833 | + { $this->shift(0,180,-($Height+2),$Reversed); $Done = TRUE; } |
|
| 834 | + if ( $Angle > 180 && $Angle <= 270 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 835 | + { $this->shift(180,360,($Height+2),$Reversed); $Done = TRUE; } |
|
| 836 | + if ( $Angle > 270 && $Angle <= 360 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 837 | + { $this->shift(180,360,($Height+2),$Reversed); $Done = TRUE; } |
|
| 838 | + } |
|
| 838 | 839 | } |
| 839 | - } |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | - $LabelSettings = array("YTop"=>$YTop,"YBottom"=>$YBottom,"Label"=>$Label,"Angle"=>$Angle,"X1"=>$X,"Y1"=>$Y,"X2"=>$X2,"Y2"=>$Y2); |
|
| 843 | - if ( $Angle <= 180 ) { $LabelSettings["X3"] = $Xc+$Radius+$LabelOffset; } |
|
| 844 | - if ( $Angle > 180 ) { $LabelSettings["X3"] = $Xc-$Radius-$LabelOffset; } |
|
| 845 | - $this->LabelPos[] = $LabelSettings; |
|
| 846 | - } |
|
| 842 | + $LabelSettings = array("YTop"=>$YTop,"YBottom"=>$YBottom,"Label"=>$Label,"Angle"=>$Angle,"X1"=>$X,"Y1"=>$Y,"X2"=>$X2,"Y2"=>$Y2); |
|
| 843 | + if ( $Angle <= 180 ) { $LabelSettings["X3"] = $Xc+$Radius+$LabelOffset; } |
|
| 844 | + if ( $Angle > 180 ) { $LabelSettings["X3"] = $Xc-$Radius-$LabelOffset; } |
|
| 845 | + $this->LabelPos[] = $LabelSettings; |
|
| 846 | + } |
|
| 847 | 847 | } |
| 848 | 848 | |
| 849 | - /* Internally used to shift label positions */ |
|
| 850 | - function shift($StartAngle,$EndAngle,$Offset,$Reversed) |
|
| 849 | + /* Internally used to shift label positions */ |
|
| 850 | + function shift($StartAngle,$EndAngle,$Offset,$Reversed) |
|
| 851 | 851 | { |
| 852 | - if ( $Reversed ) { $Offset = -$Offset; } |
|
| 853 | - foreach($this->LabelPos as $Key => $Settings) |
|
| 854 | - { |
|
| 855 | - if ( $Settings["Angle"] > $StartAngle && $Settings["Angle"] <= $EndAngle ) { $this->LabelPos[$Key]["YTop"] = $Settings["YTop"] + $Offset; $this->LabelPos[$Key]["YBottom"] = $Settings["YBottom"] + $Offset; $this->LabelPos[$Key]["Y2"] = $Settings["Y2"] + $Offset; } |
|
| 856 | - } |
|
| 852 | + if ( $Reversed ) { $Offset = -$Offset; } |
|
| 853 | + foreach($this->LabelPos as $Key => $Settings) |
|
| 854 | + { |
|
| 855 | + if ( $Settings["Angle"] > $StartAngle && $Settings["Angle"] <= $EndAngle ) { $this->LabelPos[$Key]["YTop"] = $Settings["YTop"] + $Offset; $this->LabelPos[$Key]["YBottom"] = $Settings["YBottom"] + $Offset; $this->LabelPos[$Key]["Y2"] = $Settings["Y2"] + $Offset; } |
|
| 856 | + } |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | - /* Internally used to write the re-computed labels */ |
|
| 860 | - function writeShiftedLabels() |
|
| 859 | + /* Internally used to write the re-computed labels */ |
|
| 860 | + function writeShiftedLabels() |
|
| 861 | 861 | { |
| 862 | - if ( $this->LabelPos == "" ) { return(0); } |
|
| 863 | - foreach($this->LabelPos as $Key => $Settings) |
|
| 864 | - { |
|
| 865 | - $X1 = $Settings["X1"]; $Y1 = $Settings["Y1"]; |
|
| 866 | - $X2 = $Settings["X2"]; $Y2 = $Settings["Y2"]; |
|
| 867 | - $X3 = $Settings["X3"]; |
|
| 868 | - $Angle = $Settings["Angle"]; |
|
| 869 | - $Label = $Settings["Label"]; |
|
| 870 | - |
|
| 871 | - $this->pChartObject->drawArrow($X2,$Y2,$X1,$Y1,array("Size"=>8)); |
|
| 872 | - if ( $Angle <= 180 ) |
|
| 862 | + if ( $this->LabelPos == "" ) { return(0); } |
|
| 863 | + foreach($this->LabelPos as $Key => $Settings) |
|
| 873 | 864 | { |
| 874 | - $this->pChartObject->drawLine($X2,$Y2,$X3,$Y2); |
|
| 875 | - $this->pChartObject->drawText($X3+2,$Y2,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT)); |
|
| 865 | + $X1 = $Settings["X1"]; $Y1 = $Settings["Y1"]; |
|
| 866 | + $X2 = $Settings["X2"]; $Y2 = $Settings["Y2"]; |
|
| 867 | + $X3 = $Settings["X3"]; |
|
| 868 | + $Angle = $Settings["Angle"]; |
|
| 869 | + $Label = $Settings["Label"]; |
|
| 870 | + |
|
| 871 | + $this->pChartObject->drawArrow($X2,$Y2,$X1,$Y1,array("Size"=>8)); |
|
| 872 | + if ( $Angle <= 180 ) |
|
| 873 | + { |
|
| 874 | + $this->pChartObject->drawLine($X2,$Y2,$X3,$Y2); |
|
| 875 | + $this->pChartObject->drawText($X3+2,$Y2,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT)); |
|
| 876 | 876 | } |
| 877 | - else |
|
| 877 | + else |
|
| 878 | 878 | { |
| 879 | - $this->pChartObject->drawLine($X2,$Y2,$X3,$Y2); |
|
| 880 | - $this->pChartObject->drawText($X3-2,$Y2,$Label,array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); |
|
| 879 | + $this->pChartObject->drawLine($X2,$Y2,$X3,$Y2); |
|
| 880 | + $this->pChartObject->drawText($X3-2,$Y2,$Label,array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); |
|
| 881 | + } |
|
| 881 | 882 | } |
| 882 | - } |
|
| 883 | 883 | } |
| 884 | 884 | |
| 885 | - /* Draw a ring chart */ |
|
| 886 | - function draw2DRing($X,$Y,$Format="") |
|
| 885 | + /* Draw a ring chart */ |
|
| 886 | + function draw2DRing($X,$Y,$Format="") |
|
| 887 | 887 | { |
| 888 | - $OuterRadius = isset($Format["Radius"]) ? $Format["Radius"] : 60; |
|
| 889 | - $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; |
|
| 890 | - $InnerRadius = isset($Format["Radius"]) ? $Format["Radius"] : 30; |
|
| 891 | - $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
|
| 892 | - $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255; |
|
| 893 | - $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255; |
|
| 894 | - $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255; |
|
| 895 | - $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 100; |
|
| 896 | - $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
|
| 897 | - $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE; |
|
| 898 | - $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 899 | - $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL; |
|
| 900 | - $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0; |
|
| 901 | - $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0; |
|
| 902 | - $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0; |
|
| 903 | - $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 904 | - $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : NULL; //PIE_VALUE_PERCENTAGE |
|
| 905 | - $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 5; |
|
| 906 | - $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE; |
|
| 907 | - $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : ""; |
|
| 908 | - $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255; |
|
| 909 | - $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255; |
|
| 910 | - $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255; |
|
| 911 | - $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 912 | - $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 913 | - |
|
| 914 | - /* Data Processing */ |
|
| 915 | - $Data = $this->pDataObject->getData(); |
|
| 916 | - $Palette = $this->pDataObject->getPalette(); |
|
| 888 | + $OuterRadius = isset($Format["Radius"]) ? $Format["Radius"] : 60; |
|
| 889 | + $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; |
|
| 890 | + $InnerRadius = isset($Format["Radius"]) ? $Format["Radius"] : 30; |
|
| 891 | + $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
|
| 892 | + $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255; |
|
| 893 | + $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255; |
|
| 894 | + $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255; |
|
| 895 | + $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 100; |
|
| 896 | + $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
|
| 897 | + $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE; |
|
| 898 | + $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 899 | + $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL; |
|
| 900 | + $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0; |
|
| 901 | + $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0; |
|
| 902 | + $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0; |
|
| 903 | + $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 904 | + $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : NULL; //PIE_VALUE_PERCENTAGE |
|
| 905 | + $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 5; |
|
| 906 | + $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE; |
|
| 907 | + $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : ""; |
|
| 908 | + $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255; |
|
| 909 | + $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255; |
|
| 910 | + $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255; |
|
| 911 | + $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 912 | + $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 913 | + |
|
| 914 | + /* Data Processing */ |
|
| 915 | + $Data = $this->pDataObject->getData(); |
|
| 916 | + $Palette = $this->pDataObject->getPalette(); |
|
| 917 | + |
|
| 918 | + /* Do we have an abscissa serie defined? */ |
|
| 919 | + if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 920 | + |
|
| 921 | + /* Try to find the data serie */ |
|
| 922 | + $DataSerie = ""; |
|
| 923 | + foreach ($Data["Series"] as $SerieName => $SerieData) |
|
| 924 | + { if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 925 | + |
|
| 926 | + /* Do we have data to compute? */ |
|
| 927 | + if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); } |
|
| 928 | + |
|
| 929 | + /* Remove unused data */ |
|
| 930 | + list($Data,$Palette) = $this->clean0Values($Data,$Palette,$DataSerie,$Data["Abscissa"]); |
|
| 931 | + |
|
| 932 | + /* Compute the pie sum */ |
|
| 933 | + $SerieSum = $this->pDataObject->getSum($DataSerie); |
|
| 934 | + |
|
| 935 | + /* Do we have data to draw? */ |
|
| 936 | + if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); } |
|
| 937 | + |
|
| 938 | + /* Dump the real number of data to draw */ |
|
| 939 | + $Values = ""; |
|
| 940 | + foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value) |
|
| 941 | + { if ($Value != 0) { $Values[] = $Value; } } |
|
| 942 | + |
|
| 943 | + /* Compute the wasted angular space between series */ |
|
| 944 | + if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = 0; } // count($Values) |
|
| 945 | + |
|
| 946 | + /* Compute the scale */ |
|
| 947 | + $ScaleFactor = (360 - $WastedAngular) / $SerieSum; |
|
| 948 | + |
|
| 949 | + $RestoreShadow = $this->pChartObject->Shadow; |
|
| 950 | + if ( $this->pChartObject->Shadow ) |
|
| 951 | + { |
|
| 952 | + $this->pChartObject->Shadow = FALSE; |
|
| 917 | 953 | |
| 918 | - /* Do we have an abscissa serie defined? */ |
|
| 919 | - if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 954 | + $ShadowFormat = $Format; $ShadowFormat["Shadow"] = TRUE; |
|
| 955 | + $this->draw2DRing($X+$this->pChartObject->ShadowX,$Y+$this->pChartObject->ShadowY,$ShadowFormat); |
|
| 956 | + } |
|
| 920 | 957 | |
| 921 | - /* Try to find the data serie */ |
|
| 922 | - $DataSerie = ""; |
|
| 923 | - foreach ($Data["Series"] as $SerieName => $SerieData) |
|
| 924 | - { if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 958 | + /* Draw the polygon pie elements */ |
|
| 959 | + $Step = 360 / (2 * PI * $OuterRadius); |
|
| 960 | + $Offset = 0; $ID = 0; |
|
| 961 | + foreach($Values as $Key => $Value) |
|
| 962 | + { |
|
| 963 | + if ( $Shadow ) |
|
| 964 | + { |
|
| 965 | + $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 966 | + $BorderColor = $Settings; |
|
| 967 | + } |
|
| 968 | + else |
|
| 969 | + { |
|
| 970 | + if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
|
| 971 | + $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 925 | 972 | |
| 926 | - /* Do we have data to compute? */ |
|
| 927 | - if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); } |
|
| 973 | + if ( $Border ) |
|
| 974 | + $BorderColor = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha); |
|
| 975 | + else |
|
| 976 | + $BorderColor = $Settings; |
|
| 977 | + } |
|
| 928 | 978 | |
| 929 | - /* Remove unused data */ |
|
| 930 | - list($Data,$Palette) = $this->clean0Values($Data,$Palette,$DataSerie,$Data["Abscissa"]); |
|
| 931 | - |
|
| 932 | - /* Compute the pie sum */ |
|
| 933 | - $SerieSum = $this->pDataObject->getSum($DataSerie); |
|
| 979 | + $Plots = ""; $Boundaries = ""; $AAPixels = ""; |
|
| 980 | + $EndAngle = $Offset+($Value*$ScaleFactor); if ( $EndAngle > 360 ) { $EndAngle = 360; } |
|
| 981 | + for($i=$Offset;$i<=$EndAngle;$i=$i+$Step) |
|
| 982 | + { |
|
| 983 | + $Xc = cos(($i-90)*PI/180) * $OuterRadius + $X; |
|
| 984 | + $Yc = sin(($i-90)*PI/180) * $OuterRadius + $Y; |
|
| 934 | 985 | |
| 935 | - /* Do we have data to draw? */ |
|
| 936 | - if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); } |
|
| 986 | + if ( !isset($Boundaries[0]["X1"]) ) { $Boundaries[0]["X1"] = $Xc; $Boundaries[0]["Y1"] = $Yc; } |
|
| 987 | + $AAPixels[] = array($Xc,$Yc); |
|
| 937 | 988 | |
| 938 | - /* Dump the real number of data to draw */ |
|
| 939 | - $Values = ""; |
|
| 940 | - foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value) |
|
| 941 | - { if ($Value != 0) { $Values[] = $Value; } } |
|
| 989 | + if ( $i<90 ) { $Yc++; } |
|
| 990 | + if ( $i>180 && $i<270 ) { $Xc++; } |
|
| 991 | + if ( $i>=270 ) { $Xc++; $Yc++; } |
|
| 942 | 992 | |
| 943 | - /* Compute the wasted angular space between series */ |
|
| 944 | - if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = 0; } // count($Values) |
|
| 993 | + $Plots[] = $Xc; $Plots[] = $Yc; |
|
| 994 | + } |
|
| 995 | + $Boundaries[1]["X1"] = $Xc; $Boundaries[1]["Y1"] = $Yc; |
|
| 996 | + $Lasti = $EndAngle; |
|
| 945 | 997 | |
| 946 | - /* Compute the scale */ |
|
| 947 | - $ScaleFactor = (360 - $WastedAngular) / $SerieSum; |
|
| 998 | + for($i=$EndAngle;$i>=$Offset;$i=$i-$Step) |
|
| 999 | + { |
|
| 1000 | + $Xc = cos(($i-90)*PI/180) * ($InnerRadius-1) + $X; |
|
| 1001 | + $Yc = sin(($i-90)*PI/180) * ($InnerRadius-1) + $Y; |
|
| 948 | 1002 | |
| 949 | - $RestoreShadow = $this->pChartObject->Shadow; |
|
| 950 | - if ( $this->pChartObject->Shadow ) |
|
| 951 | - { |
|
| 952 | - $this->pChartObject->Shadow = FALSE; |
|
| 1003 | + if ( !isset($Boundaries[1]["X2"]) ) { $Boundaries[1]["X2"] = $Xc; $Boundaries[1]["Y2"] = $Yc; } |
|
| 1004 | + $AAPixels[] = array($Xc,$Yc); |
|
| 953 | 1005 | |
| 954 | - $ShadowFormat = $Format; $ShadowFormat["Shadow"] = TRUE; |
|
| 955 | - $this->draw2DRing($X+$this->pChartObject->ShadowX,$Y+$this->pChartObject->ShadowY,$ShadowFormat); |
|
| 956 | - } |
|
| 1006 | + $Xc = cos(($i-90)*PI/180) * $InnerRadius + $X; |
|
| 1007 | + $Yc = sin(($i-90)*PI/180) * $InnerRadius + $Y; |
|
| 957 | 1008 | |
| 958 | - /* Draw the polygon pie elements */ |
|
| 959 | - $Step = 360 / (2 * PI * $OuterRadius); |
|
| 960 | - $Offset = 0; $ID = 0; |
|
| 961 | - foreach($Values as $Key => $Value) |
|
| 962 | - { |
|
| 963 | - if ( $Shadow ) |
|
| 964 | - { |
|
| 965 | - $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 966 | - $BorderColor = $Settings; |
|
| 967 | - } |
|
| 968 | - else |
|
| 969 | - { |
|
| 970 | - if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
|
| 971 | - $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 972 | - |
|
| 973 | - if ( $Border ) |
|
| 974 | - $BorderColor = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha); |
|
| 975 | - else |
|
| 976 | - $BorderColor = $Settings; |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - $Plots = ""; $Boundaries = ""; $AAPixels = ""; |
|
| 980 | - $EndAngle = $Offset+($Value*$ScaleFactor); if ( $EndAngle > 360 ) { $EndAngle = 360; } |
|
| 981 | - for($i=$Offset;$i<=$EndAngle;$i=$i+$Step) |
|
| 982 | - { |
|
| 983 | - $Xc = cos(($i-90)*PI/180) * $OuterRadius + $X; |
|
| 984 | - $Yc = sin(($i-90)*PI/180) * $OuterRadius + $Y; |
|
| 985 | - |
|
| 986 | - if ( !isset($Boundaries[0]["X1"]) ) { $Boundaries[0]["X1"] = $Xc; $Boundaries[0]["Y1"] = $Yc; } |
|
| 987 | - $AAPixels[] = array($Xc,$Yc); |
|
| 988 | - |
|
| 989 | - if ( $i<90 ) { $Yc++; } |
|
| 990 | - if ( $i>180 && $i<270 ) { $Xc++; } |
|
| 991 | - if ( $i>=270 ) { $Xc++; $Yc++; } |
|
| 1009 | + if ( $i<90 ) { $Yc++; } |
|
| 1010 | + if ( $i>180 && $i<270 ) { $Xc++; } |
|
| 1011 | + if ( $i>=270 ) { $Xc++; $Yc++; } |
|
| 992 | 1012 | |
| 993 | - $Plots[] = $Xc; $Plots[] = $Yc; |
|
| 1013 | + $Plots[] = $Xc; $Plots[] = $Yc; |
|
| 994 | 1014 | } |
| 995 | - $Boundaries[1]["X1"] = $Xc; $Boundaries[1]["Y1"] = $Yc; |
|
| 996 | - $Lasti = $EndAngle; |
|
| 1015 | + $Boundaries[0]["X2"] = $Xc; $Boundaries[0]["Y2"] = $Yc; |
|
| 997 | 1016 | |
| 998 | - for($i=$EndAngle;$i>=$Offset;$i=$i-$Step) |
|
| 999 | - { |
|
| 1000 | - $Xc = cos(($i-90)*PI/180) * ($InnerRadius-1) + $X; |
|
| 1001 | - $Yc = sin(($i-90)*PI/180) * ($InnerRadius-1) + $Y; |
|
| 1017 | + /* Draw the polygon */ |
|
| 1018 | + $this->pChartObject->drawPolygon($Plots,$Settings); |
|
| 1019 | + if ( $RecordImageMap && !$Shadow ) { $this->pChartObject->addToImageMap("POLY",$this->arraySerialize($Plots),$this->pChartObject->toHTMLColor($Palette[$ID]["R"],$Palette[$ID]["G"],$Palette[$ID]["B"]),$Data["Series"][$Data["Abscissa"]]["Data"][$Key],$Value); } |
|
| 1020 | + |
|
| 1021 | + /* Smooth the edges using AA */ |
|
| 1022 | + foreach($AAPixels as $iKey => $Pos ) { $this->pChartObject->drawAntialiasPixel($Pos[0],$Pos[1],$BorderColor); } |
|
| 1023 | + $this->pChartObject->drawLine($Boundaries[0]["X1"],$Boundaries[0]["Y1"],$Boundaries[0]["X2"],$Boundaries[0]["Y2"],$BorderColor); |
|
| 1024 | + $this->pChartObject->drawLine($Boundaries[1]["X1"],$Boundaries[1]["Y1"],$Boundaries[1]["X2"],$Boundaries[1]["Y2"],$BorderColor); |
|
| 1002 | 1025 | |
| 1003 | - if ( !isset($Boundaries[1]["X2"]) ) { $Boundaries[1]["X2"] = $Xc; $Boundaries[1]["Y2"] = $Yc; } |
|
| 1004 | - $AAPixels[] = array($Xc,$Yc); |
|
| 1026 | + if ( $DrawLabels && !$Shadow ) |
|
| 1027 | + { |
|
| 1028 | + if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 1029 | + { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 1030 | + else |
|
| 1031 | + { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
|
| 1005 | 1032 | |
| 1006 | - $Xc = cos(($i-90)*PI/180) * $InnerRadius + $X; |
|
| 1007 | - $Yc = sin(($i-90)*PI/180) * $InnerRadius + $Y; |
|
| 1033 | + $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 1034 | + $Xc = cos(($Angle-90)*PI/180) * $OuterRadius + $X; |
|
| 1035 | + $Yc = sin(($Angle-90)*PI/180) * $OuterRadius + $Y; |
|
| 1008 | 1036 | |
| 1009 | - if ( $i<90 ) { $Yc++; } |
|
| 1010 | - if ( $i>180 && $i<270 ) { $Xc++; } |
|
| 1011 | - if ( $i>=270 ) { $Xc++; $Yc++; } |
|
| 1037 | + $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
|
| 1012 | 1038 | |
| 1013 | - $Plots[] = $Xc; $Plots[] = $Yc; |
|
| 1039 | + if ( $LabelStacked ) |
|
| 1040 | + $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$OuterRadius); |
|
| 1041 | + else |
|
| 1042 | + $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 1014 | 1043 | } |
| 1015 | - $Boundaries[0]["X2"] = $Xc; $Boundaries[0]["Y2"] = $Yc; |
|
| 1016 | 1044 | |
| 1017 | - /* Draw the polygon */ |
|
| 1018 | - $this->pChartObject->drawPolygon($Plots,$Settings); |
|
| 1019 | - if ( $RecordImageMap && !$Shadow ) { $this->pChartObject->addToImageMap("POLY",$this->arraySerialize($Plots),$this->pChartObject->toHTMLColor($Palette[$ID]["R"],$Palette[$ID]["G"],$Palette[$ID]["B"]),$Data["Series"][$Data["Abscissa"]]["Data"][$Key],$Value); } |
|
| 1045 | + $Offset = $Lasti; $ID++; |
|
| 1046 | + } |
|
| 1020 | 1047 | |
| 1021 | - /* Smooth the edges using AA */ |
|
| 1022 | - foreach($AAPixels as $iKey => $Pos ) { $this->pChartObject->drawAntialiasPixel($Pos[0],$Pos[1],$BorderColor); } |
|
| 1023 | - $this->pChartObject->drawLine($Boundaries[0]["X1"],$Boundaries[0]["Y1"],$Boundaries[0]["X2"],$Boundaries[0]["Y2"],$BorderColor); |
|
| 1024 | - $this->pChartObject->drawLine($Boundaries[1]["X1"],$Boundaries[1]["Y1"],$Boundaries[1]["X2"],$Boundaries[1]["Y2"],$BorderColor); |
|
| 1048 | + if ( $DrawLabels && $LabelStacked ) { $this->writeShiftedLabels(); } |
|
| 1025 | 1049 | |
| 1026 | - if ( $DrawLabels && !$Shadow ) |
|
| 1050 | + if ( $WriteValues && !$Shadow ) |
|
| 1051 | + { |
|
| 1052 | + $Step = 360 / (2 * PI * $OuterRadius); |
|
| 1053 | + $Offset = 0; |
|
| 1054 | + foreach($Values as $Key => $Value) |
|
| 1027 | 1055 | { |
| 1028 | - if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 1029 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 1030 | - else |
|
| 1031 | - { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
|
| 1056 | + $EndAngle = $Offset+($Value*$ScaleFactor); |
|
| 1057 | + if ( $EndAngle > 360 ) { $EndAngle = 360; } |
|
| 1032 | 1058 | |
| 1033 | - $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 1034 | - $Xc = cos(($Angle-90)*PI/180) * $OuterRadius + $X; |
|
| 1035 | - $Yc = sin(($Angle-90)*PI/180) * $OuterRadius + $Y; |
|
| 1059 | + $Angle = $Offset+($Value*$ScaleFactor)/2; |
|
| 1060 | + if ( $ValuePosition == PIE_VALUE_OUTSIDE ) |
|
| 1061 | + { |
|
| 1062 | + $Xc = cos(($Angle-90)*PI/180) * ($OuterRadius+$ValuePadding) + $X; |
|
| 1063 | + $Yc = sin(($Angle-90)*PI/180) * ($OuterRadius+$ValuePadding) + $Y; |
|
| 1064 | + if ( $Angle >=0 && $Angle <= 90 ) { $Align = TEXT_ALIGN_BOTTOMLEFT; } |
|
| 1065 | + if ( $Angle > 90 && $Angle <= 180 ) { $Align = TEXT_ALIGN_TOPLEFT; } |
|
| 1066 | + if ( $Angle > 180 && $Angle <= 270 ) { $Align = TEXT_ALIGN_TOPRIGHT; } |
|
| 1067 | + if ( $Angle > 270 ) { $Align = TEXT_ALIGN_BOTTOMRIGHT; } |
|
| 1068 | + } |
|
| 1069 | + else |
|
| 1070 | + { |
|
| 1071 | + $Xc = cos(($Angle-90)*PI/180) * (($OuterRadius-$InnerRadius)/2+$InnerRadius) + $X; |
|
| 1072 | + $Yc = sin(($Angle-90)*PI/180) * (($OuterRadius-$InnerRadius)/2+$InnerRadius) + $Y; |
|
| 1073 | + $Align = TEXT_ALIGN_MIDDLEMIDDLE; |
|
| 1074 | + } |
|
| 1036 | 1075 | |
| 1037 | - $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
|
| 1076 | + if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 1077 | + $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 1078 | + elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 1079 | + $Display = $Value.$ValueSuffix; |
|
| 1080 | + else |
|
| 1081 | + $Label = ""; |
|
| 1038 | 1082 | |
| 1039 | - if ( $LabelStacked ) |
|
| 1040 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$OuterRadius); |
|
| 1041 | - else |
|
| 1042 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 1083 | + $this->pChartObject->drawText($Xc,$Yc,$Display,array("Align"=>$Align,"R"=>$ValueR,"G"=>$ValueG,"B"=>$ValueB)); |
|
| 1084 | + $Offset = $EndAngle; |
|
| 1085 | + } |
|
| 1043 | 1086 | } |
| 1044 | 1087 | |
| 1045 | - $Offset = $Lasti; $ID++; |
|
| 1046 | - } |
|
| 1088 | + $this->pChartObject->Shadow = $RestoreShadow; |
|
| 1047 | 1089 | |
| 1048 | - if ( $DrawLabels && $LabelStacked ) { $this->writeShiftedLabels(); } |
|
| 1090 | + return(PIE_RENDERED); |
|
| 1091 | + } |
|
| 1049 | 1092 | |
| 1050 | - if ( $WriteValues && !$Shadow ) |
|
| 1051 | - { |
|
| 1052 | - $Step = 360 / (2 * PI * $OuterRadius); |
|
| 1053 | - $Offset = 0; |
|
| 1054 | - foreach($Values as $Key => $Value) |
|
| 1093 | + /* Draw a 3D ring chart */ |
|
| 1094 | + function draw3DRing($X,$Y,$Format="") |
|
| 1095 | + { |
|
| 1096 | + $OuterRadius = isset($Format["OuterRadius"]) ? $Format["OuterRadius"] : 100; |
|
| 1097 | + $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; |
|
| 1098 | + $InnerRadius = isset($Format["InnerRadius"]) ? $Format["InnerRadius"] : 30; |
|
| 1099 | + $SkewFactor = isset($Format["SkewFactor"]) ? $Format["SkewFactor"] : .6; |
|
| 1100 | + $SliceHeight = isset($Format["SliceHeight"]) ? $Format["SliceHeight"] : 10; |
|
| 1101 | + $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 10; |
|
| 1102 | + $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 10; |
|
| 1103 | + $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
|
| 1104 | + $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
|
| 1105 | + $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE; |
|
| 1106 | + $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 1107 | + $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL; |
|
| 1108 | + $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0; |
|
| 1109 | + $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0; |
|
| 1110 | + $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0; |
|
| 1111 | + $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 1112 | + $Cf = isset($Format["Cf"]) ? $Format["Cf"] : 20; |
|
| 1113 | + $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : PIE_VALUE_NATURAL; |
|
| 1114 | + $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : $SliceHeight + 15; |
|
| 1115 | + $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE; |
|
| 1116 | + $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : ""; |
|
| 1117 | + $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255; |
|
| 1118 | + $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255; |
|
| 1119 | + $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255; |
|
| 1120 | + $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 1121 | + $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 1122 | + |
|
| 1123 | + /* Error correction for overlaying rounded corners */ |
|
| 1124 | + if ( $SkewFactor < .5 ) { $SkewFactor = .5; } |
|
| 1125 | + |
|
| 1126 | + /* Data Processing */ |
|
| 1127 | + $Data = $this->pDataObject->getData(); |
|
| 1128 | + $Palette = $this->pDataObject->getPalette(); |
|
| 1129 | + |
|
| 1130 | + /* Do we have an abscissa serie defined? */ |
|
| 1131 | + if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 1132 | + |
|
| 1133 | + /* Try to find the data serie */ |
|
| 1134 | + $DataSerie = ""; |
|
| 1135 | + foreach ($Data["Series"] as $SerieName => $SerieData) |
|
| 1136 | + { if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 1137 | + |
|
| 1138 | + /* Do we have data to compute? */ |
|
| 1139 | + if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); } |
|
| 1140 | + |
|
| 1141 | + /* Remove unused data */ |
|
| 1142 | + list($Data,$Palette) = $this->clean0Values($Data,$Palette,$DataSerie,$Data["Abscissa"]); |
|
| 1143 | + |
|
| 1144 | + /* Compute the pie sum */ |
|
| 1145 | + $SerieSum = $this->pDataObject->getSum($DataSerie); |
|
| 1146 | + |
|
| 1147 | + /* Do we have data to draw? */ |
|
| 1148 | + if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); } |
|
| 1149 | + |
|
| 1150 | + /* Dump the real number of data to draw */ |
|
| 1151 | + $Values = ""; |
|
| 1152 | + foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value) |
|
| 1153 | + { if ($Value != 0) { $Values[] = $Value; } } |
|
| 1154 | + |
|
| 1155 | + /* Compute the wasted angular space between series */ |
|
| 1156 | + if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = count($Values) * $DataGapAngle; } |
|
| 1157 | + |
|
| 1158 | + /* Compute the scale */ |
|
| 1159 | + $ScaleFactor = (360 - $WastedAngular) / $SerieSum; |
|
| 1160 | + |
|
| 1161 | + $RestoreShadow = $this->pChartObject->Shadow; |
|
| 1162 | + if ( $this->pChartObject->Shadow ) { $this->pChartObject->Shadow = FALSE; } |
|
| 1163 | + |
|
| 1164 | + /* Draw the polygon ring elements */ |
|
| 1165 | + $Offset = 360; $ID = count($Values)-1; |
|
| 1166 | + $Values = array_reverse($Values); |
|
| 1167 | + $Slice = 0; $Slices = ""; $SliceColors = ""; $Visible = ""; $SliceAngle = ""; |
|
| 1168 | + foreach($Values as $Key => $Value) |
|
| 1055 | 1169 | { |
| 1056 | - $EndAngle = $Offset+($Value*$ScaleFactor); |
|
| 1057 | - if ( $EndAngle > 360 ) { $EndAngle = 360; } |
|
| 1170 | + if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
|
| 1171 | + $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 1058 | 1172 | |
| 1059 | - $Angle = $Offset+($Value*$ScaleFactor)/2; |
|
| 1060 | - if ( $ValuePosition == PIE_VALUE_OUTSIDE ) |
|
| 1061 | - { |
|
| 1062 | - $Xc = cos(($Angle-90)*PI/180) * ($OuterRadius+$ValuePadding) + $X; |
|
| 1063 | - $Yc = sin(($Angle-90)*PI/180) * ($OuterRadius+$ValuePadding) + $Y; |
|
| 1064 | - if ( $Angle >=0 && $Angle <= 90 ) { $Align = TEXT_ALIGN_BOTTOMLEFT; } |
|
| 1065 | - if ( $Angle > 90 && $Angle <= 180 ) { $Align = TEXT_ALIGN_TOPLEFT; } |
|
| 1066 | - if ( $Angle > 180 && $Angle <= 270 ) { $Align = TEXT_ALIGN_TOPRIGHT; } |
|
| 1067 | - if ( $Angle > 270 ) { $Align = TEXT_ALIGN_BOTTOMRIGHT; } |
|
| 1068 | - } |
|
| 1069 | - else |
|
| 1070 | - { |
|
| 1071 | - $Xc = cos(($Angle-90)*PI/180) * (($OuterRadius-$InnerRadius)/2+$InnerRadius) + $X; |
|
| 1072 | - $Yc = sin(($Angle-90)*PI/180) * (($OuterRadius-$InnerRadius)/2+$InnerRadius) + $Y; |
|
| 1073 | - $Align = TEXT_ALIGN_MIDDLEMIDDLE; |
|
| 1074 | - } |
|
| 1173 | + $SliceColors[$Slice] = $Settings; |
|
| 1075 | 1174 | |
| 1076 | - if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 1077 | - $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 1078 | - elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 1079 | - $Display = $Value.$ValueSuffix; |
|
| 1080 | - else |
|
| 1081 | - $Label = ""; |
|
| 1175 | + $StartAngle = $Offset; |
|
| 1176 | + $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 1082 | 1177 | |
| 1083 | - $this->pChartObject->drawText($Xc,$Yc,$Display,array("Align"=>$Align,"R"=>$ValueR,"G"=>$ValueG,"B"=>$ValueB)); |
|
| 1084 | - $Offset = $EndAngle; |
|
| 1085 | - } |
|
| 1086 | - } |
|
| 1178 | + if ( $StartAngle > 180 ) { $Visible[$Slice]["Start"] = TRUE; } else { $Visible[$Slice]["Start"] = TRUE; } |
|
| 1179 | + if ( $EndAngle < 180 ) { $Visible[$Slice]["End"] = FALSE; } else { $Visible[$Slice]["End"] = TRUE; } |
|
| 1087 | 1180 | |
| 1088 | - $this->pChartObject->Shadow = $RestoreShadow; |
|
| 1181 | + $Step = (360 / (2 * PI * $OuterRadius))/2; |
|
| 1182 | + $OutX1 = VOID; $OutY1 = VOID; |
|
| 1183 | + for($i=$Offset;$i>=$EndAngle;$i=$i-$Step) |
|
| 1184 | + { |
|
| 1185 | + $Xc = cos(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius-2) + $X; |
|
| 1186 | + $Yc = sin(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius-2)*$SkewFactor + $Y; |
|
| 1187 | + $Slices[$Slice]["AA"][] = array($Xc,$Yc); |
|
| 1089 | 1188 | |
| 1090 | - return(PIE_RENDERED); |
|
| 1091 | - } |
|
| 1189 | + $Xc = cos(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius-1) + $X; |
|
| 1190 | + $Yc = sin(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius-1)*$SkewFactor + $Y; |
|
| 1191 | + $Slices[$Slice]["AA"][] = array($Xc,$Yc); |
|
| 1092 | 1192 | |
| 1093 | - /* Draw a 3D ring chart */ |
|
| 1094 | - function draw3DRing($X,$Y,$Format="") |
|
| 1095 | - { |
|
| 1096 | - $OuterRadius = isset($Format["OuterRadius"]) ? $Format["OuterRadius"] : 100; |
|
| 1097 | - $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; |
|
| 1098 | - $InnerRadius = isset($Format["InnerRadius"]) ? $Format["InnerRadius"] : 30; |
|
| 1099 | - $SkewFactor = isset($Format["SkewFactor"]) ? $Format["SkewFactor"] : .6; |
|
| 1100 | - $SliceHeight = isset($Format["SliceHeight"]) ? $Format["SliceHeight"] : 10; |
|
| 1101 | - $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 10; |
|
| 1102 | - $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 10; |
|
| 1103 | - $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
|
| 1104 | - $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
|
| 1105 | - $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE; |
|
| 1106 | - $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 1107 | - $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL; |
|
| 1108 | - $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0; |
|
| 1109 | - $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0; |
|
| 1110 | - $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0; |
|
| 1111 | - $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 1112 | - $Cf = isset($Format["Cf"]) ? $Format["Cf"] : 20; |
|
| 1113 | - $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : PIE_VALUE_NATURAL; |
|
| 1114 | - $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : $SliceHeight + 15; |
|
| 1115 | - $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE; |
|
| 1116 | - $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : ""; |
|
| 1117 | - $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255; |
|
| 1118 | - $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255; |
|
| 1119 | - $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255; |
|
| 1120 | - $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 1121 | - $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 1122 | - |
|
| 1123 | - /* Error correction for overlaying rounded corners */ |
|
| 1124 | - if ( $SkewFactor < .5 ) { $SkewFactor = .5; } |
|
| 1125 | - |
|
| 1126 | - /* Data Processing */ |
|
| 1127 | - $Data = $this->pDataObject->getData(); |
|
| 1128 | - $Palette = $this->pDataObject->getPalette(); |
|
| 1129 | - |
|
| 1130 | - /* Do we have an abscissa serie defined? */ |
|
| 1131 | - if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 1132 | - |
|
| 1133 | - /* Try to find the data serie */ |
|
| 1134 | - $DataSerie = ""; |
|
| 1135 | - foreach ($Data["Series"] as $SerieName => $SerieData) |
|
| 1136 | - { if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 1137 | - |
|
| 1138 | - /* Do we have data to compute? */ |
|
| 1139 | - if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); } |
|
| 1140 | - |
|
| 1141 | - /* Remove unused data */ |
|
| 1142 | - list($Data,$Palette) = $this->clean0Values($Data,$Palette,$DataSerie,$Data["Abscissa"]); |
|
| 1143 | - |
|
| 1144 | - /* Compute the pie sum */ |
|
| 1145 | - $SerieSum = $this->pDataObject->getSum($DataSerie); |
|
| 1146 | - |
|
| 1147 | - /* Do we have data to draw? */ |
|
| 1148 | - if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); } |
|
| 1149 | - |
|
| 1150 | - /* Dump the real number of data to draw */ |
|
| 1151 | - $Values = ""; |
|
| 1152 | - foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value) |
|
| 1153 | - { if ($Value != 0) { $Values[] = $Value; } } |
|
| 1154 | - |
|
| 1155 | - /* Compute the wasted angular space between series */ |
|
| 1156 | - if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = count($Values) * $DataGapAngle; } |
|
| 1157 | - |
|
| 1158 | - /* Compute the scale */ |
|
| 1159 | - $ScaleFactor = (360 - $WastedAngular) / $SerieSum; |
|
| 1160 | - |
|
| 1161 | - $RestoreShadow = $this->pChartObject->Shadow; |
|
| 1162 | - if ( $this->pChartObject->Shadow ) { $this->pChartObject->Shadow = FALSE; } |
|
| 1163 | - |
|
| 1164 | - /* Draw the polygon ring elements */ |
|
| 1165 | - $Offset = 360; $ID = count($Values)-1; |
|
| 1166 | - $Values = array_reverse($Values); |
|
| 1167 | - $Slice = 0; $Slices = ""; $SliceColors = ""; $Visible = ""; $SliceAngle = ""; |
|
| 1168 | - foreach($Values as $Key => $Value) |
|
| 1169 | - { |
|
| 1170 | - if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
|
| 1171 | - $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 1172 | - |
|
| 1173 | - $SliceColors[$Slice] = $Settings; |
|
| 1174 | - |
|
| 1175 | - $StartAngle = $Offset; |
|
| 1176 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 1177 | - |
|
| 1178 | - if ( $StartAngle > 180 ) { $Visible[$Slice]["Start"] = TRUE; } else { $Visible[$Slice]["Start"] = TRUE; } |
|
| 1179 | - if ( $EndAngle < 180 ) { $Visible[$Slice]["End"] = FALSE; } else { $Visible[$Slice]["End"] = TRUE; } |
|
| 1180 | - |
|
| 1181 | - $Step = (360 / (2 * PI * $OuterRadius))/2; |
|
| 1182 | - $OutX1 = VOID; $OutY1 = VOID; |
|
| 1183 | - for($i=$Offset;$i>=$EndAngle;$i=$i-$Step) |
|
| 1184 | - { |
|
| 1185 | - $Xc = cos(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius-2) + $X; |
|
| 1186 | - $Yc = sin(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius-2)*$SkewFactor + $Y; |
|
| 1187 | - $Slices[$Slice]["AA"][] = array($Xc,$Yc); |
|
| 1188 | - |
|
| 1189 | - $Xc = cos(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius-1) + $X; |
|
| 1190 | - $Yc = sin(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius-1)*$SkewFactor + $Y; |
|
| 1191 | - $Slices[$Slice]["AA"][] = array($Xc,$Yc); |
|
| 1192 | - |
|
| 1193 | - $Xc = cos(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius) + $X; |
|
| 1194 | - $Yc = sin(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius)*$SkewFactor + $Y; |
|
| 1195 | - $this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings); |
|
| 1196 | - |
|
| 1197 | - if ( $OutX1 == VOID ) { $OutX1 = $Xc; $OutY1 = $Yc; } |
|
| 1198 | - |
|
| 1199 | - if ( $i<90 ) { $Yc++; } |
|
| 1200 | - if ( $i>90 && $i<180 ) { $Xc++; } |
|
| 1201 | - if ( $i>180 && $i<270 ) { $Xc++; } |
|
| 1202 | - if ( $i>=270 ) { $Xc++; $Yc++; } |
|
| 1203 | - |
|
| 1204 | - $Slices[$Slice]["BottomPoly"][] = floor($Xc); $Slices[$Slice]["BottomPoly"][] = floor($Yc); |
|
| 1205 | - $Slices[$Slice]["TopPoly"][] = floor($Xc); $Slices[$Slice]["TopPoly"][] = floor($Yc)-$SliceHeight; |
|
| 1206 | - $Slices[$Slice]["Angle"][] = $i; |
|
| 1193 | + $Xc = cos(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius) + $X; |
|
| 1194 | + $Yc = sin(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius)*$SkewFactor + $Y; |
|
| 1195 | + $this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings); |
|
| 1196 | + |
|
| 1197 | + if ( $OutX1 == VOID ) { $OutX1 = $Xc; $OutY1 = $Yc; } |
|
| 1198 | + |
|
| 1199 | + if ( $i<90 ) { $Yc++; } |
|
| 1200 | + if ( $i>90 && $i<180 ) { $Xc++; } |
|
| 1201 | + if ( $i>180 && $i<270 ) { $Xc++; } |
|
| 1202 | + if ( $i>=270 ) { $Xc++; $Yc++; } |
|
| 1203 | + |
|
| 1204 | + $Slices[$Slice]["BottomPoly"][] = floor($Xc); $Slices[$Slice]["BottomPoly"][] = floor($Yc); |
|
| 1205 | + $Slices[$Slice]["TopPoly"][] = floor($Xc); $Slices[$Slice]["TopPoly"][] = floor($Yc)-$SliceHeight; |
|
| 1206 | + $Slices[$Slice]["Angle"][] = $i; |
|
| 1207 | 1207 | } |
| 1208 | - $OutX2 = $Xc; $OutY2 = $Yc; |
|
| 1208 | + $OutX2 = $Xc; $OutY2 = $Yc; |
|
| 1209 | 1209 | |
| 1210 | - $Slices[$Slice]["Angle"][] = VOID; |
|
| 1211 | - $Lasti = $i; |
|
| 1210 | + $Slices[$Slice]["Angle"][] = VOID; |
|
| 1211 | + $Lasti = $i; |
|
| 1212 | 1212 | |
| 1213 | - $Step = (360 / (2 * PI * $InnerRadius))/2; |
|
| 1214 | - $InX1 = VOID; $InY1 = VOID; |
|
| 1215 | - for($i=$EndAngle;$i<=$Offset;$i=$i+$Step) |
|
| 1213 | + $Step = (360 / (2 * PI * $InnerRadius))/2; |
|
| 1214 | + $InX1 = VOID; $InY1 = VOID; |
|
| 1215 | + for($i=$EndAngle;$i<=$Offset;$i=$i+$Step) |
|
| 1216 | 1216 | { |
| 1217 | - $Xc = cos(($i-90)*PI/180) * ($InnerRadius+$DataGapRadius-1) + $X; |
|
| 1218 | - $Yc = sin(($i-90)*PI/180) * ($InnerRadius+$DataGapRadius-1)*$SkewFactor + $Y; |
|
| 1219 | - $Slices[$Slice]["AA"][] = array($Xc,$Yc); |
|
| 1217 | + $Xc = cos(($i-90)*PI/180) * ($InnerRadius+$DataGapRadius-1) + $X; |
|
| 1218 | + $Yc = sin(($i-90)*PI/180) * ($InnerRadius+$DataGapRadius-1)*$SkewFactor + $Y; |
|
| 1219 | + $Slices[$Slice]["AA"][] = array($Xc,$Yc); |
|
| 1220 | 1220 | |
| 1221 | - $Xc = cos(($i-90)*PI/180) * ($InnerRadius+$DataGapRadius) + $X; |
|
| 1222 | - $Yc = sin(($i-90)*PI/180) * ($InnerRadius+$DataGapRadius)*$SkewFactor + $Y; |
|
| 1223 | - $Slices[$Slice]["AA"][] = array($Xc,$Yc); |
|
| 1221 | + $Xc = cos(($i-90)*PI/180) * ($InnerRadius+$DataGapRadius) + $X; |
|
| 1222 | + $Yc = sin(($i-90)*PI/180) * ($InnerRadius+$DataGapRadius)*$SkewFactor + $Y; |
|
| 1223 | + $Slices[$Slice]["AA"][] = array($Xc,$Yc); |
|
| 1224 | 1224 | |
| 1225 | - if ( $InX1 == VOID ) { $InX1 = $Xc; $InY1 = $Yc; } |
|
| 1225 | + if ( $InX1 == VOID ) { $InX1 = $Xc; $InY1 = $Yc; } |
|
| 1226 | 1226 | |
| 1227 | - if ( $i<90 ) { $Yc++; } |
|
| 1228 | - if ( $i>90 && $i<180 ) { $Xc++; } |
|
| 1229 | - if ( $i>180 && $i<270 ) { $Xc++; } |
|
| 1230 | - if ( $i>=270 ) { $Xc++; $Yc++; } |
|
| 1227 | + if ( $i<90 ) { $Yc++; } |
|
| 1228 | + if ( $i>90 && $i<180 ) { $Xc++; } |
|
| 1229 | + if ( $i>180 && $i<270 ) { $Xc++; } |
|
| 1230 | + if ( $i>=270 ) { $Xc++; $Yc++; } |
|
| 1231 | 1231 | |
| 1232 | - $Slices[$Slice]["BottomPoly"][] = floor($Xc); $Slices[$Slice]["BottomPoly"][] = floor($Yc); |
|
| 1233 | - $Slices[$Slice]["TopPoly"][] = floor($Xc); $Slices[$Slice]["TopPoly"][] = floor($Yc)-$SliceHeight; |
|
| 1234 | - $Slices[$Slice]["Angle"][] = $i; |
|
| 1232 | + $Slices[$Slice]["BottomPoly"][] = floor($Xc); $Slices[$Slice]["BottomPoly"][] = floor($Yc); |
|
| 1233 | + $Slices[$Slice]["TopPoly"][] = floor($Xc); $Slices[$Slice]["TopPoly"][] = floor($Yc)-$SliceHeight; |
|
| 1234 | + $Slices[$Slice]["Angle"][] = $i; |
|
| 1235 | 1235 | } |
| 1236 | - $InX2 = $Xc; $InY2 = $Yc; |
|
| 1236 | + $InX2 = $Xc; $InY2 = $Yc; |
|
| 1237 | 1237 | |
| 1238 | - $Slices[$Slice]["InX1"] = $InX1; $Slices[$Slice]["InY1"] = $InY1; |
|
| 1239 | - $Slices[$Slice]["InX2"] = $InX2; $Slices[$Slice]["InY2"] = $InY2; |
|
| 1240 | - $Slices[$Slice]["OutX1"] = $OutX1; $Slices[$Slice]["OutY1"] = $OutY1; |
|
| 1241 | - $Slices[$Slice]["OutX2"] = $OutX2; $Slices[$Slice]["OutY2"] = $OutY2; |
|
| 1238 | + $Slices[$Slice]["InX1"] = $InX1; $Slices[$Slice]["InY1"] = $InY1; |
|
| 1239 | + $Slices[$Slice]["InX2"] = $InX2; $Slices[$Slice]["InY2"] = $InY2; |
|
| 1240 | + $Slices[$Slice]["OutX1"] = $OutX1; $Slices[$Slice]["OutY1"] = $OutY1; |
|
| 1241 | + $Slices[$Slice]["OutX2"] = $OutX2; $Slices[$Slice]["OutY2"] = $OutY2; |
|
| 1242 | 1242 | |
| 1243 | - $Offset = $Lasti - $DataGapAngle; $ID--; $Slice++; |
|
| 1244 | - } |
|
| 1243 | + $Offset = $Lasti - $DataGapAngle; $ID--; $Slice++; |
|
| 1244 | + } |
|
| 1245 | 1245 | |
| 1246 | - /* Draw the bottom pie splice */ |
|
| 1247 | - foreach($Slices as $SliceID => $Plots) |
|
| 1248 | - { |
|
| 1249 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1250 | - $this->pChartObject->drawPolygon($Plots["BottomPoly"],$Settings); |
|
| 1246 | + /* Draw the bottom pie splice */ |
|
| 1247 | + foreach($Slices as $SliceID => $Plots) |
|
| 1248 | + { |
|
| 1249 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1250 | + $this->pChartObject->drawPolygon($Plots["BottomPoly"],$Settings); |
|
| 1251 | 1251 | |
| 1252 | - foreach($Plots["AA"] as $Key => $Pos) |
|
| 1252 | + foreach($Plots["AA"] as $Key => $Pos) |
|
| 1253 | 1253 | $this->pChartObject->drawAntialiasPixel($Pos[0],$Pos[1],$Settings); |
| 1254 | 1254 | |
| 1255 | - $this->pChartObject->drawLine($Plots["InX1"],$Plots["InY1"],$Plots["OutX2"],$Plots["OutY2"],$Settings); |
|
| 1256 | - $this->pChartObject->drawLine($Plots["InX2"],$Plots["InY2"],$Plots["OutX1"],$Plots["OutY1"],$Settings); |
|
| 1257 | - } |
|
| 1255 | + $this->pChartObject->drawLine($Plots["InX1"],$Plots["InY1"],$Plots["OutX2"],$Plots["OutY2"],$Settings); |
|
| 1256 | + $this->pChartObject->drawLine($Plots["InX2"],$Plots["InY2"],$Plots["OutX1"],$Plots["OutY1"],$Settings); |
|
| 1257 | + } |
|
| 1258 | 1258 | |
| 1259 | - $Slices = array_reverse($Slices); |
|
| 1260 | - $SliceColors = array_reverse($SliceColors); |
|
| 1259 | + $Slices = array_reverse($Slices); |
|
| 1260 | + $SliceColors = array_reverse($SliceColors); |
|
| 1261 | 1261 | |
| 1262 | - /* Draw the vertical edges (semi-visible) */ |
|
| 1263 | - foreach($Slices as $SliceID => $Plots) |
|
| 1264 | - { |
|
| 1265 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1266 | - $Settings["R"] = $Settings["R"]+$Cf; $Settings["G"] = $Settings["G"]+$Cf; $Settings["B"] = $Settings["B"]+$Cf; |
|
| 1262 | + /* Draw the vertical edges (semi-visible) */ |
|
| 1263 | + foreach($Slices as $SliceID => $Plots) |
|
| 1264 | + { |
|
| 1265 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1266 | + $Settings["R"] = $Settings["R"]+$Cf; $Settings["G"] = $Settings["G"]+$Cf; $Settings["B"] = $Settings["B"]+$Cf; |
|
| 1267 | 1267 | |
| 1268 | - $StartAngle = $Plots["Angle"][0]; |
|
| 1269 | - foreach($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key-1]; } } |
|
| 1268 | + $StartAngle = $Plots["Angle"][0]; |
|
| 1269 | + foreach($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key-1]; } } |
|
| 1270 | 1270 | |
| 1271 | - if ( $StartAngle >= 270 || $StartAngle <= 90 ) |
|
| 1271 | + if ( $StartAngle >= 270 || $StartAngle <= 90 ) |
|
| 1272 | 1272 | $this->pChartObject->drawLine($Plots["OutX1"],$Plots["OutY1"],$Plots["OutX1"],$Plots["OutY1"]-$SliceHeight,$Settings); |
| 1273 | - if ( $StartAngle >= 270 || $StartAngle <= 90 ) |
|
| 1273 | + if ( $StartAngle >= 270 || $StartAngle <= 90 ) |
|
| 1274 | 1274 | $this->pChartObject->drawLine($Plots["OutX2"],$Plots["OutY2"],$Plots["OutX2"],$Plots["OutY2"]-$SliceHeight,$Settings); |
| 1275 | 1275 | |
| 1276 | 1276 | $this->pChartObject->drawLine($Plots["InX1"],$Plots["InY1"],$Plots["InX1"],$Plots["InY1"]-$SliceHeight,$Settings); |
| 1277 | 1277 | $this->pChartObject->drawLine($Plots["InX2"],$Plots["InY2"],$Plots["InX2"],$Plots["InY2"]-$SliceHeight,$Settings); |
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - /* Draw the inner vertical slices */ |
|
| 1281 | - foreach($Slices as $SliceID => $Plots) |
|
| 1282 | - { |
|
| 1283 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1284 | - $Settings["R"] = $Settings["R"]+$Cf; $Settings["G"] = $Settings["G"]+$Cf; $Settings["B"] = $Settings["B"]+$Cf; |
|
| 1285 | - |
|
| 1286 | - $Outer = TRUE; $Inner = FALSE; |
|
| 1287 | - $InnerPlotsA = ""; $InnerPlotsB = ""; |
|
| 1288 | - foreach($Plots["Angle"] as $ID => $Angle) |
|
| 1289 | - { |
|
| 1290 | - if ( $Angle == VOID ) |
|
| 1291 | - { $Outer = FALSE; $Inner = TRUE; } |
|
| 1292 | - elseif( $Inner ) |
|
| 1293 | - { |
|
| 1294 | - if (( $Angle < 90 || $Angle > 270 ) && isset($Plots["BottomPoly"][$ID*2]) ) |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + /* Draw the inner vertical slices */ |
|
| 1281 | + foreach($Slices as $SliceID => $Plots) |
|
| 1282 | + { |
|
| 1283 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1284 | + $Settings["R"] = $Settings["R"]+$Cf; $Settings["G"] = $Settings["G"]+$Cf; $Settings["B"] = $Settings["B"]+$Cf; |
|
| 1285 | + |
|
| 1286 | + $Outer = TRUE; $Inner = FALSE; |
|
| 1287 | + $InnerPlotsA = ""; $InnerPlotsB = ""; |
|
| 1288 | + foreach($Plots["Angle"] as $ID => $Angle) |
|
| 1289 | + { |
|
| 1290 | + if ( $Angle == VOID ) |
|
| 1291 | + { $Outer = FALSE; $Inner = TRUE; } |
|
| 1292 | + elseif( $Inner ) |
|
| 1295 | 1293 | { |
| 1296 | - $Xo = $Plots["BottomPoly"][$ID*2]; |
|
| 1297 | - $Yo = $Plots["BottomPoly"][$ID*2+1]; |
|
| 1294 | + if (( $Angle < 90 || $Angle > 270 ) && isset($Plots["BottomPoly"][$ID*2]) ) |
|
| 1295 | + { |
|
| 1296 | + $Xo = $Plots["BottomPoly"][$ID*2]; |
|
| 1297 | + $Yo = $Plots["BottomPoly"][$ID*2+1]; |
|
| 1298 | 1298 | |
| 1299 | - $InnerPlotsA[] = $Xo; $InnerPlotsA[] = $Yo; |
|
| 1300 | - $InnerPlotsB[] = $Xo; $InnerPlotsB[] = $Yo-$SliceHeight; |
|
| 1299 | + $InnerPlotsA[] = $Xo; $InnerPlotsA[] = $Yo; |
|
| 1300 | + $InnerPlotsB[] = $Xo; $InnerPlotsB[] = $Yo-$SliceHeight; |
|
| 1301 | + } |
|
| 1301 | 1302 | } |
| 1302 | - } |
|
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | - if ( $InnerPlotsA != "" ) |
|
| 1305 | + if ( $InnerPlotsA != "" ) |
|
| 1306 | 1306 | { $InnerPlots = array_merge($InnerPlotsA,$this->arrayReverse($InnerPlotsB)); $this->pChartObject->drawPolygon($InnerPlots,$Settings); } |
| 1307 | - } |
|
| 1307 | + } |
|
| 1308 | 1308 | |
| 1309 | - /* Draw the splice top and left poly */ |
|
| 1310 | - foreach($Slices as $SliceID => $Plots) |
|
| 1311 | - { |
|
| 1312 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1313 | - $Settings["R"] = $Settings["R"]+$Cf*1.5; $Settings["G"] = $Settings["G"]+$Cf*1.5; $Settings["B"] = $Settings["B"]+$Cf*1.5; |
|
| 1309 | + /* Draw the splice top and left poly */ |
|
| 1310 | + foreach($Slices as $SliceID => $Plots) |
|
| 1311 | + { |
|
| 1312 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1313 | + $Settings["R"] = $Settings["R"]+$Cf*1.5; $Settings["G"] = $Settings["G"]+$Cf*1.5; $Settings["B"] = $Settings["B"]+$Cf*1.5; |
|
| 1314 | 1314 | |
| 1315 | - $StartAngle = $Plots["Angle"][0]; |
|
| 1316 | - foreach($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key-1]; } } |
|
| 1315 | + $StartAngle = $Plots["Angle"][0]; |
|
| 1316 | + foreach($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key-1]; } } |
|
| 1317 | 1317 | |
| 1318 | - if ( $StartAngle < 180 ) |
|
| 1318 | + if ( $StartAngle < 180 ) |
|
| 1319 | 1319 | { |
| 1320 | - $Points = ""; |
|
| 1321 | - $Points[] = $Plots["InX2"]; |
|
| 1322 | - $Points[] = $Plots["InY2"]; |
|
| 1323 | - $Points[] = $Plots["InX2"]; |
|
| 1324 | - $Points[] = $Plots["InY2"]-$SliceHeight; |
|
| 1325 | - $Points[] = $Plots["OutX1"]; |
|
| 1326 | - $Points[] = $Plots["OutY1"]-$SliceHeight; |
|
| 1327 | - $Points[] = $Plots["OutX1"]; |
|
| 1328 | - $Points[] = $Plots["OutY1"]; |
|
| 1329 | - |
|
| 1330 | - $this->pChartObject->drawPolygon($Points,$Settings); |
|
| 1320 | + $Points = ""; |
|
| 1321 | + $Points[] = $Plots["InX2"]; |
|
| 1322 | + $Points[] = $Plots["InY2"]; |
|
| 1323 | + $Points[] = $Plots["InX2"]; |
|
| 1324 | + $Points[] = $Plots["InY2"]-$SliceHeight; |
|
| 1325 | + $Points[] = $Plots["OutX1"]; |
|
| 1326 | + $Points[] = $Plots["OutY1"]-$SliceHeight; |
|
| 1327 | + $Points[] = $Plots["OutX1"]; |
|
| 1328 | + $Points[] = $Plots["OutY1"]; |
|
| 1329 | + |
|
| 1330 | + $this->pChartObject->drawPolygon($Points,$Settings); |
|
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | - if ( $EndAngle > 180 ) |
|
| 1333 | + if ( $EndAngle > 180 ) |
|
| 1334 | 1334 | { |
| 1335 | - $Points = ""; |
|
| 1336 | - $Points[] = $Plots["InX1"]; |
|
| 1337 | - $Points[] = $Plots["InY1"]; |
|
| 1338 | - $Points[] = $Plots["InX1"]; |
|
| 1339 | - $Points[] = $Plots["InY1"]-$SliceHeight; |
|
| 1340 | - $Points[] = $Plots["OutX2"]; |
|
| 1341 | - $Points[] = $Plots["OutY2"]-$SliceHeight; |
|
| 1342 | - $Points[] = $Plots["OutX2"]; |
|
| 1343 | - $Points[] = $Plots["OutY2"]; |
|
| 1344 | - |
|
| 1345 | - $this->pChartObject->drawPolygon($Points,$Settings); |
|
| 1335 | + $Points = ""; |
|
| 1336 | + $Points[] = $Plots["InX1"]; |
|
| 1337 | + $Points[] = $Plots["InY1"]; |
|
| 1338 | + $Points[] = $Plots["InX1"]; |
|
| 1339 | + $Points[] = $Plots["InY1"]-$SliceHeight; |
|
| 1340 | + $Points[] = $Plots["OutX2"]; |
|
| 1341 | + $Points[] = $Plots["OutY2"]-$SliceHeight; |
|
| 1342 | + $Points[] = $Plots["OutX2"]; |
|
| 1343 | + $Points[] = $Plots["OutY2"]; |
|
| 1344 | + |
|
| 1345 | + $this->pChartObject->drawPolygon($Points,$Settings); |
|
| 1346 | + } |
|
| 1346 | 1347 | } |
| 1347 | - } |
|
| 1348 | 1348 | |
| 1349 | 1349 | |
| 1350 | - /* Draw the vertical edges (visible) */ |
|
| 1351 | - foreach($Slices as $SliceID => $Plots) |
|
| 1352 | - { |
|
| 1353 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1354 | - $Settings["R"] = $Settings["R"]+$Cf; $Settings["G"] = $Settings["G"]+$Cf; $Settings["B"] = $Settings["B"]+$Cf; |
|
| 1350 | + /* Draw the vertical edges (visible) */ |
|
| 1351 | + foreach($Slices as $SliceID => $Plots) |
|
| 1352 | + { |
|
| 1353 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1354 | + $Settings["R"] = $Settings["R"]+$Cf; $Settings["G"] = $Settings["G"]+$Cf; $Settings["B"] = $Settings["B"]+$Cf; |
|
| 1355 | 1355 | |
| 1356 | - $StartAngle = $Plots["Angle"][0]; |
|
| 1357 | - foreach($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key-1]; } } |
|
| 1356 | + $StartAngle = $Plots["Angle"][0]; |
|
| 1357 | + foreach($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key-1]; } } |
|
| 1358 | 1358 | |
| 1359 | - if ( $StartAngle <= 270 && $StartAngle >= 90 ) |
|
| 1359 | + if ( $StartAngle <= 270 && $StartAngle >= 90 ) |
|
| 1360 | 1360 | $this->pChartObject->drawLine($Plots["OutX1"],$Plots["OutY1"],$Plots["OutX1"],$Plots["OutY1"]-$SliceHeight,$Settings); |
| 1361 | - if ( $EndAngle <= 270 && $EndAngle >= 90 ) |
|
| 1361 | + if ( $EndAngle <= 270 && $EndAngle >= 90 ) |
|
| 1362 | 1362 | $this->pChartObject->drawLine($Plots["OutX2"],$Plots["OutY2"],$Plots["OutX2"],$Plots["OutY2"]-$SliceHeight,$Settings); |
| 1363 | - } |
|
| 1363 | + } |
|
| 1364 | 1364 | |
| 1365 | 1365 | |
| 1366 | - /* Draw the outer vertical slices */ |
|
| 1367 | - foreach($Slices as $SliceID => $Plots) |
|
| 1368 | - { |
|
| 1369 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1370 | - $Settings["R"] = $Settings["R"]+$Cf; $Settings["G"] = $Settings["G"]+$Cf; $Settings["B"] = $Settings["B"]+$Cf; |
|
| 1366 | + /* Draw the outer vertical slices */ |
|
| 1367 | + foreach($Slices as $SliceID => $Plots) |
|
| 1368 | + { |
|
| 1369 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1370 | + $Settings["R"] = $Settings["R"]+$Cf; $Settings["G"] = $Settings["G"]+$Cf; $Settings["B"] = $Settings["B"]+$Cf; |
|
| 1371 | 1371 | |
| 1372 | - $Outer = TRUE; $Inner = FALSE; |
|
| 1373 | - $OuterPlotsA = ""; $OuterPlotsB = ""; $InnerPlotsA = ""; $InnerPlotsB = ""; |
|
| 1374 | - foreach($Plots["Angle"] as $ID => $Angle) |
|
| 1372 | + $Outer = TRUE; $Inner = FALSE; |
|
| 1373 | + $OuterPlotsA = ""; $OuterPlotsB = ""; $InnerPlotsA = ""; $InnerPlotsB = ""; |
|
| 1374 | + foreach($Plots["Angle"] as $ID => $Angle) |
|
| 1375 | 1375 | { |
| 1376 | - if ( $Angle == VOID ) |
|
| 1377 | - { $Outer = FALSE; $Inner = TRUE; } |
|
| 1378 | - elseif( $Outer ) |
|
| 1379 | - { |
|
| 1380 | - if ( ( $Angle > 90 && $Angle < 270 ) && isset($Plots["BottomPoly"][$ID*2]) ) |
|
| 1376 | + if ( $Angle == VOID ) |
|
| 1377 | + { $Outer = FALSE; $Inner = TRUE; } |
|
| 1378 | + elseif( $Outer ) |
|
| 1381 | 1379 | { |
| 1382 | - $Xo = $Plots["BottomPoly"][$ID*2]; |
|
| 1383 | - $Yo = $Plots["BottomPoly"][$ID*2+1]; |
|
| 1380 | + if ( ( $Angle > 90 && $Angle < 270 ) && isset($Plots["BottomPoly"][$ID*2]) ) |
|
| 1381 | + { |
|
| 1382 | + $Xo = $Plots["BottomPoly"][$ID*2]; |
|
| 1383 | + $Yo = $Plots["BottomPoly"][$ID*2+1]; |
|
| 1384 | 1384 | |
| 1385 | - $OuterPlotsA[] = $Xo; $OuterPlotsA[] = $Yo; |
|
| 1386 | - $OuterPlotsB[] = $Xo; $OuterPlotsB[] = $Yo-$SliceHeight; |
|
| 1385 | + $OuterPlotsA[] = $Xo; $OuterPlotsA[] = $Yo; |
|
| 1386 | + $OuterPlotsB[] = $Xo; $OuterPlotsB[] = $Yo-$SliceHeight; |
|
| 1387 | + } |
|
| 1387 | 1388 | } |
| 1388 | - } |
|
| 1389 | 1389 | } |
| 1390 | - if ( $OuterPlotsA != "" ) |
|
| 1390 | + if ( $OuterPlotsA != "" ) |
|
| 1391 | 1391 | { $OuterPlots = array_merge($OuterPlotsA,$this->arrayReverse($OuterPlotsB)); $this->pChartObject->drawPolygon($OuterPlots,$Settings); } |
| 1392 | - } |
|
| 1392 | + } |
|
| 1393 | 1393 | |
| 1394 | - $Slices = array_reverse($Slices); |
|
| 1395 | - $SliceColors = array_reverse($SliceColors); |
|
| 1394 | + $Slices = array_reverse($Slices); |
|
| 1395 | + $SliceColors = array_reverse($SliceColors); |
|
| 1396 | 1396 | |
| 1397 | 1397 | |
| 1398 | - /* Draw the top pie splice */ |
|
| 1399 | - foreach($Slices as $SliceID => $Plots) |
|
| 1400 | - { |
|
| 1401 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1402 | - $Settings["R"] = $Settings["R"]+$Cf*2; $Settings["G"] = $Settings["G"]+$Cf*2; $Settings["B"] = $Settings["B"]+$Cf*2; |
|
| 1398 | + /* Draw the top pie splice */ |
|
| 1399 | + foreach($Slices as $SliceID => $Plots) |
|
| 1400 | + { |
|
| 1401 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1402 | + $Settings["R"] = $Settings["R"]+$Cf*2; $Settings["G"] = $Settings["G"]+$Cf*2; $Settings["B"] = $Settings["B"]+$Cf*2; |
|
| 1403 | 1403 | |
| 1404 | - $this->pChartObject->drawPolygon($Plots["TopPoly"],$Settings); |
|
| 1404 | + $this->pChartObject->drawPolygon($Plots["TopPoly"],$Settings); |
|
| 1405 | 1405 | |
| 1406 | - if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("POLY",$this->arraySerialize($Plots["TopPoly"]),$this->pChartObject->toHTMLColor($Settings["R"],$Settings["G"],$Settings["B"]),$Data["Series"][$Data["Abscissa"]]["Data"][$SliceID],$Data["Series"][$DataSerie]["Data"][count($Slices)-$SliceID-1]); } |
|
| 1406 | + if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("POLY",$this->arraySerialize($Plots["TopPoly"]),$this->pChartObject->toHTMLColor($Settings["R"],$Settings["G"],$Settings["B"]),$Data["Series"][$Data["Abscissa"]]["Data"][$SliceID],$Data["Series"][$DataSerie]["Data"][count($Slices)-$SliceID-1]); } |
|
| 1407 | 1407 | |
| 1408 | - foreach($Plots["AA"] as $Key => $Pos) |
|
| 1408 | + foreach($Plots["AA"] as $Key => $Pos) |
|
| 1409 | 1409 | $this->pChartObject->drawAntialiasPixel($Pos[0],$Pos[1]-$SliceHeight,$Settings); |
| 1410 | 1410 | |
| 1411 | - $this->pChartObject->drawLine($Plots["InX1"],$Plots["InY1"]-$SliceHeight,$Plots["OutX2"],$Plots["OutY2"]-$SliceHeight,$Settings); |
|
| 1412 | - $this->pChartObject->drawLine($Plots["InX2"],$Plots["InY2"]-$SliceHeight,$Plots["OutX1"],$Plots["OutY1"]-$SliceHeight,$Settings); |
|
| 1413 | - } |
|
| 1411 | + $this->pChartObject->drawLine($Plots["InX1"],$Plots["InY1"]-$SliceHeight,$Plots["OutX2"],$Plots["OutY2"]-$SliceHeight,$Settings); |
|
| 1412 | + $this->pChartObject->drawLine($Plots["InX2"],$Plots["InY2"]-$SliceHeight,$Plots["OutX1"],$Plots["OutY1"]-$SliceHeight,$Settings); |
|
| 1413 | + } |
|
| 1414 | 1414 | |
| 1415 | - if ( $DrawLabels ) |
|
| 1416 | - { |
|
| 1417 | - $Offset = 360; |
|
| 1418 | - foreach($Values as $Key => $Value) |
|
| 1415 | + if ( $DrawLabels ) |
|
| 1416 | + { |
|
| 1417 | + $Offset = 360; |
|
| 1418 | + foreach($Values as $Key => $Value) |
|
| 1419 | 1419 | { |
| 1420 | - $StartAngle = $Offset; |
|
| 1421 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 1420 | + $StartAngle = $Offset; |
|
| 1421 | + $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 1422 | 1422 | |
| 1423 | - if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 1424 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 1425 | - else |
|
| 1426 | - { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
|
| 1423 | + if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 1424 | + { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 1425 | + else |
|
| 1426 | + { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
|
| 1427 | 1427 | |
| 1428 | - $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 1429 | - $Xc = cos(($Angle-90)*PI/180) * ($OuterRadius+$DataGapRadius) + $X; |
|
| 1430 | - $Yc = sin(($Angle-90)*PI/180) * ($OuterRadius+$DataGapRadius)*$SkewFactor + $Y; |
|
| 1428 | + $Angle = ($EndAngle - $Offset)/2 + $Offset; |
|
| 1429 | + $Xc = cos(($Angle-90)*PI/180) * ($OuterRadius+$DataGapRadius) + $X; |
|
| 1430 | + $Yc = sin(($Angle-90)*PI/180) * ($OuterRadius+$DataGapRadius)*$SkewFactor + $Y; |
|
| 1431 | 1431 | |
| 1432 | - if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 1433 | - $Label = $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 1434 | - elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 1435 | - $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
|
| 1436 | - else |
|
| 1437 | - $Label = ""; |
|
| 1432 | + if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 1433 | + $Label = $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 1434 | + elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 1435 | + $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
|
| 1436 | + else |
|
| 1437 | + $Label = ""; |
|
| 1438 | 1438 | |
| 1439 | - if ( $LabelStacked ) |
|
| 1440 | - $this->writePieLabel($Xc,$Yc-$SliceHeight,$Label,$Angle,$Settings,TRUE,$X,$Y,$OuterRadius); |
|
| 1441 | - else |
|
| 1442 | - $this->writePieLabel($Xc,$Yc-$SliceHeight,$Label,$Angle,$Settings,FALSE); |
|
| 1439 | + if ( $LabelStacked ) |
|
| 1440 | + $this->writePieLabel($Xc,$Yc-$SliceHeight,$Label,$Angle,$Settings,TRUE,$X,$Y,$OuterRadius); |
|
| 1441 | + else |
|
| 1442 | + $this->writePieLabel($Xc,$Yc-$SliceHeight,$Label,$Angle,$Settings,FALSE); |
|
| 1443 | 1443 | |
| 1444 | - $Offset = $EndAngle - $DataGapAngle; $ID--; $Slice++; |
|
| 1444 | + $Offset = $EndAngle - $DataGapAngle; $ID--; $Slice++; |
|
| 1445 | + } |
|
| 1445 | 1446 | } |
| 1446 | - } |
|
| 1447 | - if ( $DrawLabels && $LabelStacked ) { $this->writeShiftedLabels(); } |
|
| 1447 | + if ( $DrawLabels && $LabelStacked ) { $this->writeShiftedLabels(); } |
|
| 1448 | 1448 | |
| 1449 | - $this->pChartObject->Shadow = $RestoreShadow; |
|
| 1449 | + $this->pChartObject->Shadow = $RestoreShadow; |
|
| 1450 | 1450 | |
| 1451 | - return(PIE_RENDERED); |
|
| 1451 | + return(PIE_RENDERED); |
|
| 1452 | 1452 | } |
| 1453 | 1453 | |
| 1454 | - /* Serialize an array */ |
|
| 1455 | - function arraySerialize($Data) |
|
| 1456 | - { |
|
| 1454 | + /* Serialize an array */ |
|
| 1455 | + function arraySerialize($Data) |
|
| 1456 | + { |
|
| 1457 | 1457 | $Result = ""; |
| 1458 | 1458 | foreach($Data as $Key => $Value) |
| 1459 | - { if ($Result == "") { $Result = floor($Value); } else { $Result = $Result.",".floor($Value); } } |
|
| 1459 | + { if ($Result == "") { $Result = floor($Value); } else { $Result = $Result.",".floor($Value); } } |
|
| 1460 | 1460 | |
| 1461 | 1461 | return($Result); |
| 1462 | - } |
|
| 1462 | + } |
|
| 1463 | 1463 | |
| 1464 | - /* Reverse an array */ |
|
| 1465 | - function arrayReverse($Plots) |
|
| 1466 | - { |
|
| 1464 | + /* Reverse an array */ |
|
| 1465 | + function arrayReverse($Plots) |
|
| 1466 | + { |
|
| 1467 | 1467 | $Result = ""; |
| 1468 | 1468 | |
| 1469 | 1469 | for($i=count($Plots)-1;$i>=0;$i=$i-2) |
| 1470 | - { $Result[] = $Plots[$i-1]; $Result[] = $Plots[$i]; } |
|
| 1470 | + { $Result[] = $Plots[$i-1]; $Result[] = $Plots[$i]; } |
|
| 1471 | 1471 | |
| 1472 | 1472 | return($Result); |
| 1473 | - } |
|
| 1473 | + } |
|
| 1474 | 1474 | |
| 1475 | - /* Remove unused series & values */ |
|
| 1476 | - function clean0Values($Data,$Palette,$DataSerie,$AbscissaSerie) |
|
| 1477 | - { |
|
| 1475 | + /* Remove unused series & values */ |
|
| 1476 | + function clean0Values($Data,$Palette,$DataSerie,$AbscissaSerie) |
|
| 1477 | + { |
|
| 1478 | 1478 | $NewPalette = ""; $NewData = ""; $NewAbscissa = ""; |
| 1479 | 1479 | |
| 1480 | 1480 | /* Remove unused series */ |
| 1481 | 1481 | foreach($Data["Series"] as $SerieName => $SerieSettings) |
| 1482 | - { if ( $SerieName != $DataSerie && $SerieName != $AbscissaSerie ) { unset($Data["Series"][$SerieName]); } } |
|
| 1482 | + { if ( $SerieName != $DataSerie && $SerieName != $AbscissaSerie ) { unset($Data["Series"][$SerieName]); } } |
|
| 1483 | 1483 | |
| 1484 | 1484 | /* Remove NULL values */ |
| 1485 | 1485 | foreach($Data["Series"][$DataSerie]["Data"] as $Key => $Value) |
| 1486 | - { |
|
| 1487 | - if ($Value != 0 ) |
|
| 1488 | - { |
|
| 1486 | + { |
|
| 1487 | + if ($Value != 0 ) |
|
| 1488 | + { |
|
| 1489 | 1489 | $NewData[] = $Value; |
| 1490 | 1490 | $NewAbscissa[] = $Data["Series"][$AbscissaSerie]["Data"][$Key]; |
| 1491 | 1491 | if ( isset($Palette[$Key]) ) { $NewPalette[] = $Palette[$Key]; } |
| 1492 | - } |
|
| 1493 | - } |
|
| 1492 | + } |
|
| 1493 | + } |
|
| 1494 | 1494 | $Data["Series"][$DataSerie]["Data"] = $NewData; |
| 1495 | 1495 | $Data["Series"][$AbscissaSerie]["Data"] = $NewAbscissa; |
| 1496 | 1496 | |
| 1497 | 1497 | return(array($Data,$NewPalette)); |
| 1498 | - } |
|
| 1499 | - } |
|
| 1498 | + } |
|
| 1499 | + } |
|
| 1500 | 1500 | ?> |
| 1501 | 1501 | \ No newline at end of file |
@@ -14,29 +14,29 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | 16 | /* Class return codes */ |
| 17 | - define("PIE_NO_ABSCISSA" , 140001); |
|
| 18 | - define("PIE_NO_DATASERIE" , 140002); |
|
| 19 | - define("PIE_SUMISNULL" , 140003); |
|
| 20 | - define("PIE_RENDERED" , 140000); |
|
| 17 | + define("PIE_NO_ABSCISSA", 140001); |
|
| 18 | + define("PIE_NO_DATASERIE", 140002); |
|
| 19 | + define("PIE_SUMISNULL", 140003); |
|
| 20 | + define("PIE_RENDERED", 140000); |
|
| 21 | 21 | |
| 22 | - define("PIE_LABEL_COLOR_AUTO" , 140010); |
|
| 22 | + define("PIE_LABEL_COLOR_AUTO", 140010); |
|
| 23 | 23 | define("PIE_LABEL_COLOR_MANUAL", 140011); |
| 24 | 24 | |
| 25 | - define("PIE_VALUE_NATURAL" , 140020); |
|
| 26 | - define("PIE_VALUE_PERCENTAGE" , 140021); |
|
| 25 | + define("PIE_VALUE_NATURAL", 140020); |
|
| 26 | + define("PIE_VALUE_PERCENTAGE", 140021); |
|
| 27 | 27 | |
| 28 | - define("PIE_VALUE_INSIDE" , 140030); |
|
| 29 | - define("PIE_VALUE_OUTSIDE" , 140031); |
|
| 28 | + define("PIE_VALUE_INSIDE", 140030); |
|
| 29 | + define("PIE_VALUE_OUTSIDE", 140031); |
|
| 30 | 30 | |
| 31 | 31 | /* pPie class definition */ |
| 32 | 32 | class pPie |
| 33 | 33 | { |
| 34 | 34 | var $pChartObject; |
| 35 | 35 | var $pDataObject; |
| 36 | - var $LabelPos = "" ; |
|
| 36 | + var $LabelPos = ""; |
|
| 37 | 37 | |
| 38 | 38 | /* Class creator */ |
| 39 | - function pPie($Object,$pDataObject) |
|
| 39 | + function pPie($Object, $pDataObject) |
|
| 40 | 40 | { |
| 41 | 41 | /* Cache the pChart object reference */ |
| 42 | 42 | $this->pChartObject = $Object; |
@@ -46,58 +46,58 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /* Draw a pie chart */ |
| 49 | - function draw2DPie($X,$Y,$Format="") |
|
| 49 | + function draw2DPie($X, $Y, $Format = "") |
|
| 50 | 50 | { |
| 51 | - $Radius = isset($Format["Radius"]) ? $Format["Radius"] : 60; |
|
| 51 | + $Radius = isset($Format["Radius"]) ? $Format["Radius"] : 60; |
|
| 52 | 52 | $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; |
| 53 | - $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 0; |
|
| 54 | - $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 0; |
|
| 53 | + $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 0; |
|
| 54 | + $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 0; |
|
| 55 | 55 | $SecondPass = isset($Format["SecondPass"]) ? $Format["SecondPass"] : TRUE; |
| 56 | - $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
|
| 56 | + $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
|
| 57 | 57 | $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255; |
| 58 | 58 | $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255; |
| 59 | 59 | $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255; |
| 60 | - $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
|
| 60 | + $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
|
| 61 | 61 | $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE; |
| 62 | - $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 62 | + $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 63 | 63 | $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL; |
| 64 | 64 | $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0; |
| 65 | 65 | $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0; |
| 66 | 66 | $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0; |
| 67 | - $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 67 | + $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 68 | 68 | $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : NULL; |
| 69 | - $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE; |
|
| 70 | - $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 15; |
|
| 69 | + $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE; |
|
| 70 | + $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 15; |
|
| 71 | 71 | $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : ""; |
| 72 | 72 | $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255; |
| 73 | 73 | $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255; |
| 74 | 74 | $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255; |
| 75 | - $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 76 | - $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 75 | + $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 76 | + $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 77 | 77 | |
| 78 | 78 | /* Data Processing */ |
| 79 | 79 | $Data = $this->pDataObject->getData(); |
| 80 | 80 | $Palette = $this->pDataObject->getPalette(); |
| 81 | 81 | |
| 82 | 82 | /* Do we have an abscissa serie defined? */ |
| 83 | - if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 83 | + if ($Data["Abscissa"] == "") { return(PIE_NO_ABSCISSA); } |
|
| 84 | 84 | |
| 85 | 85 | /* Try to find the data serie */ |
| 86 | 86 | $DataSerie = ""; |
| 87 | 87 | foreach ($Data["Series"] as $SerieName => $SerieData) |
| 88 | - { if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 88 | + { if ($SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 89 | 89 | |
| 90 | 90 | /* Do we have data to compute? */ |
| 91 | - if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); } |
|
| 91 | + if ($DataSerie == "") { return(PIE_NO_DATASERIE); } |
|
| 92 | 92 | |
| 93 | 93 | /* Remove unused data */ |
| 94 | - list($Data,$Palette) = $this->clean0Values($Data,$Palette,$DataSerie,$Data["Abscissa"]); |
|
| 94 | + list($Data, $Palette) = $this->clean0Values($Data, $Palette, $DataSerie, $Data["Abscissa"]); |
|
| 95 | 95 | |
| 96 | 96 | /* Compute the pie sum */ |
| 97 | 97 | $SerieSum = $this->pDataObject->getSum($DataSerie); |
| 98 | 98 | |
| 99 | 99 | /* Do we have data to draw? */ |
| 100 | - if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); } |
|
| 100 | + if ($SerieSum == 0) { return(PIE_SUMISNULL); } |
|
| 101 | 101 | |
| 102 | 102 | /* Dump the real number of data to draw */ |
| 103 | 103 | $Values = ""; |
@@ -105,190 +105,190 @@ discard block |
||
| 105 | 105 | { if ($Value != 0) { $Values[] = $Value; } } |
| 106 | 106 | |
| 107 | 107 | /* Compute the wasted angular space between series */ |
| 108 | - if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = count($Values) * $DataGapAngle; } |
|
| 108 | + if (count($Values) == 1) { $WastedAngular = 0; } else { $WastedAngular = count($Values)*$DataGapAngle; } |
|
| 109 | 109 | |
| 110 | 110 | /* Compute the scale */ |
| 111 | - $ScaleFactor = (360 - $WastedAngular) / $SerieSum; |
|
| 111 | + $ScaleFactor = (360 - $WastedAngular)/$SerieSum; |
|
| 112 | 112 | |
| 113 | 113 | $RestoreShadow = $this->pChartObject->Shadow; |
| 114 | - if ( $this->pChartObject->Shadow ) |
|
| 114 | + if ($this->pChartObject->Shadow) |
|
| 115 | 115 | { |
| 116 | 116 | $this->pChartObject->Shadow = FALSE; |
| 117 | 117 | |
| 118 | 118 | $ShadowFormat = $Format; $ShadowFormat["Shadow"] = TRUE; |
| 119 | - $this->draw2DPie($X+$this->pChartObject->ShadowX,$Y+$this->pChartObject->ShadowY,$ShadowFormat); |
|
| 119 | + $this->draw2DPie($X + $this->pChartObject->ShadowX, $Y + $this->pChartObject->ShadowY, $ShadowFormat); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /* Draw the polygon pie elements */ |
| 123 | - $Step = 360 / (2 * PI * $Radius); |
|
| 123 | + $Step = 360/(2*PI*$Radius); |
|
| 124 | 124 | $Offset = 0; $ID = 0; |
| 125 | - foreach($Values as $Key => $Value) |
|
| 125 | + foreach ($Values as $Key => $Value) |
|
| 126 | 126 | { |
| 127 | - if ( $Shadow ) |
|
| 128 | - $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 127 | + if ($Shadow) |
|
| 128 | + $Settings = array("R"=>$this->pChartObject->ShadowR, "G"=>$this->pChartObject->ShadowG, "B"=>$this->pChartObject->ShadowB, "Alpha"=>$this->pChartObject->Shadowa); |
|
| 129 | 129 | else |
| 130 | 130 | { |
| 131 | - if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
|
| 132 | - $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 131 | + if (!isset($Palette[$ID]["R"])) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID, $Color); } |
|
| 132 | + $Settings = array("R"=>$Palette[$ID]["R"], "G"=>$Palette[$ID]["G"], "B"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - if ( !$SecondPass && !$Shadow ) |
|
| 135 | + if (!$SecondPass && !$Shadow) |
|
| 136 | 136 | { |
| 137 | - if ( !$Border ) |
|
| 137 | + if (!$Border) |
|
| 138 | 138 | $Settings["Surrounding"] = 10; |
| 139 | 139 | else |
| 140 | 140 | { $Settings["BorderR"] = $BorderR; $Settings["BorderG"] = $BorderG; $Settings["BorderB"] = $BorderB; } |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | $Plots = ""; |
| 144 | - $EndAngle = $Offset+($Value*$ScaleFactor); if ( $EndAngle > 360 ) { $EndAngle = 360; } |
|
| 144 | + $EndAngle = $Offset + ($Value*$ScaleFactor); if ($EndAngle > 360) { $EndAngle = 360; } |
|
| 145 | 145 | |
| 146 | 146 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 147 | 147 | if ($DataGapAngle == 0) |
| 148 | 148 | { $X0 = $X; $Y0 = $Y; } |
| 149 | 149 | else |
| 150 | 150 | { |
| 151 | - $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
|
| 152 | - $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius + $Y; |
|
| 151 | + $X0 = cos(($Angle - 90)*PI/180)*$DataGapRadius + $X; |
|
| 152 | + $Y0 = sin(($Angle - 90)*PI/180)*$DataGapRadius + $Y; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | $Plots[] = $X0; $Plots[] = $Y0; |
| 156 | 156 | |
| 157 | 157 | |
| 158 | - for($i=$Offset;$i<=$EndAngle;$i=$i+$Step) |
|
| 158 | + for ($i = $Offset; $i <= $EndAngle; $i = $i + $Step) |
|
| 159 | 159 | { |
| 160 | - $Xc = cos(($i-90)*PI/180) * $Radius + $X; |
|
| 161 | - $Yc = sin(($i-90)*PI/180) * $Radius + $Y; |
|
| 160 | + $Xc = cos(($i - 90)*PI/180)*$Radius + $X; |
|
| 161 | + $Yc = sin(($i - 90)*PI/180)*$Radius + $Y; |
|
| 162 | 162 | |
| 163 | - if ( $SecondPass && ( $i<90 )) { $Yc++; } |
|
| 164 | - if ( $SecondPass && ( $i>180 && $i<270 )) { $Xc++; } |
|
| 165 | - if ( $SecondPass && ( $i>=270 )) { $Xc++; $Yc++; } |
|
| 163 | + if ($SecondPass && ($i < 90)) { $Yc++; } |
|
| 164 | + if ($SecondPass && ($i > 180 && $i < 270)) { $Xc++; } |
|
| 165 | + if ($SecondPass && ($i >= 270)) { $Xc++; $Yc++; } |
|
| 166 | 166 | |
| 167 | 167 | $Plots[] = $Xc; $Plots[] = $Yc; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - $this->pChartObject->drawPolygon($Plots,$Settings); |
|
| 171 | - if ( $RecordImageMap && !$Shadow ) { $this->pChartObject->addToImageMap("POLY",$this->arraySerialize($Plots),$this->pChartObject->toHTMLColor($Palette[$ID]["R"],$Palette[$ID]["G"],$Palette[$ID]["B"]),$Data["Series"][$Data["Abscissa"]]["Data"][$Key],$Value); } |
|
| 170 | + $this->pChartObject->drawPolygon($Plots, $Settings); |
|
| 171 | + if ($RecordImageMap && !$Shadow) { $this->pChartObject->addToImageMap("POLY", $this->arraySerialize($Plots), $this->pChartObject->toHTMLColor($Palette[$ID]["R"], $Palette[$ID]["G"], $Palette[$ID]["B"]), $Data["Series"][$Data["Abscissa"]]["Data"][$Key], $Value); } |
|
| 172 | 172 | |
| 173 | - if ( $DrawLabels && !$Shadow && !$SecondPass ) |
|
| 173 | + if ($DrawLabels && !$Shadow && !$SecondPass) |
|
| 174 | 174 | { |
| 175 | - if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 176 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 175 | + if ($LabelColor == PIE_LABEL_COLOR_AUTO) |
|
| 176 | + { $Settings = array("FillR"=>$Palette[$ID]["R"], "FillG"=>$Palette[$ID]["G"], "FillB"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"]); } |
|
| 177 | 177 | else |
| 178 | - { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
|
| 178 | + { $Settings = array("FillR"=>$LabelR, "FillG"=>$LabelG, "FillB"=>$LabelB, "Alpha"=>$LabelAlpha); } |
|
| 179 | 179 | |
| 180 | 180 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 181 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 182 | - $Yc = sin(($Angle-90)*PI/180) * $Radius + $Y; |
|
| 181 | + $Xc = cos(($Angle - 90)*PI/180)*$Radius + $X; |
|
| 182 | + $Yc = sin(($Angle - 90)*PI/180)*$Radius + $Y; |
|
| 183 | 183 | |
| 184 | 184 | $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
| 185 | 185 | |
| 186 | - if ( $LabelStacked ) |
|
| 187 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$Radius); |
|
| 186 | + if ($LabelStacked) |
|
| 187 | + $this->writePieLabel($Xc, $Yc, $Label, $Angle, $Settings, TRUE, $X, $Y, $Radius); |
|
| 188 | 188 | else |
| 189 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 189 | + $this->writePieLabel($Xc, $Yc, $Label, $Angle, $Settings, FALSE); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | $Offset = $i + $DataGapAngle; $ID++; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /* Second pass to smooth the angles */ |
| 196 | - if ( $SecondPass ) |
|
| 196 | + if ($SecondPass) |
|
| 197 | 197 | { |
| 198 | - $Step = 360 / (2 * PI * $Radius); |
|
| 198 | + $Step = 360/(2*PI*$Radius); |
|
| 199 | 199 | $Offset = 0; $ID = 0; |
| 200 | - foreach($Values as $Key => $Value) |
|
| 200 | + foreach ($Values as $Key => $Value) |
|
| 201 | 201 | { |
| 202 | 202 | $FirstPoint = TRUE; |
| 203 | - if ( $Shadow ) |
|
| 204 | - $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 203 | + if ($Shadow) |
|
| 204 | + $Settings = array("R"=>$this->pChartObject->ShadowR, "G"=>$this->pChartObject->ShadowG, "B"=>$this->pChartObject->ShadowB, "Alpha"=>$this->pChartObject->Shadowa); |
|
| 205 | 205 | else |
| 206 | 206 | { |
| 207 | - if ( $Border ) |
|
| 208 | - $Settings = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB); |
|
| 207 | + if ($Border) |
|
| 208 | + $Settings = array("R"=>$BorderR, "G"=>$BorderG, "B"=>$BorderB); |
|
| 209 | 209 | else |
| 210 | - $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 210 | + $Settings = array("R"=>$Palette[$ID]["R"], "G"=>$Palette[$ID]["G"], "B"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - $EndAngle = $Offset+($Value*$ScaleFactor); if ( $EndAngle > 360 ) { $EndAngle = 360; } |
|
| 213 | + $EndAngle = $Offset + ($Value*$ScaleFactor); if ($EndAngle > 360) { $EndAngle = 360; } |
|
| 214 | 214 | |
| 215 | 215 | if ($DataGapAngle == 0) |
| 216 | 216 | { $X0 = $X; $Y0 = $Y; } |
| 217 | 217 | else |
| 218 | 218 | { |
| 219 | 219 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 220 | - $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
|
| 221 | - $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius + $Y; |
|
| 220 | + $X0 = cos(($Angle - 90)*PI/180)*$DataGapRadius + $X; |
|
| 221 | + $Y0 = sin(($Angle - 90)*PI/180)*$DataGapRadius + $Y; |
|
| 222 | 222 | } |
| 223 | 223 | $Plots[] = $X0; $Plots[] = $Y0; |
| 224 | 224 | |
| 225 | - for($i=$Offset;$i<=$EndAngle;$i=$i+$Step) |
|
| 225 | + for ($i = $Offset; $i <= $EndAngle; $i = $i + $Step) |
|
| 226 | 226 | { |
| 227 | - $Xc = cos(($i-90)*PI/180) * $Radius + $X; |
|
| 228 | - $Yc = sin(($i-90)*PI/180) * $Radius + $Y; |
|
| 227 | + $Xc = cos(($i - 90)*PI/180)*$Radius + $X; |
|
| 228 | + $Yc = sin(($i - 90)*PI/180)*$Radius + $Y; |
|
| 229 | 229 | |
| 230 | - if ( $FirstPoint ) { $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); } { $FirstPoint = FALSE; } |
|
| 230 | + if ($FirstPoint) { $this->pChartObject->drawLine($Xc, $Yc, $X0, $Y0, $Settings); } { $FirstPoint = FALSE; } |
|
| 231 | 231 | |
| 232 | - $this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings); |
|
| 232 | + $this->pChartObject->drawAntialiasPixel($Xc, $Yc, $Settings); |
|
| 233 | 233 | } |
| 234 | - $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); |
|
| 234 | + $this->pChartObject->drawLine($Xc, $Yc, $X0, $Y0, $Settings); |
|
| 235 | 235 | |
| 236 | - if ( $DrawLabels && !$Shadow ) |
|
| 236 | + if ($DrawLabels && !$Shadow) |
|
| 237 | 237 | { |
| 238 | - if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 239 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 238 | + if ($LabelColor == PIE_LABEL_COLOR_AUTO) |
|
| 239 | + { $Settings = array("FillR"=>$Palette[$ID]["R"], "FillG"=>$Palette[$ID]["G"], "FillB"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"]); } |
|
| 240 | 240 | else |
| 241 | - { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
|
| 241 | + { $Settings = array("FillR"=>$LabelR, "FillG"=>$LabelG, "FillB"=>$LabelB, "Alpha"=>$LabelAlpha); } |
|
| 242 | 242 | |
| 243 | 243 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 244 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 245 | - $Yc = sin(($Angle-90)*PI/180) * $Radius + $Y; |
|
| 244 | + $Xc = cos(($Angle - 90)*PI/180)*$Radius + $X; |
|
| 245 | + $Yc = sin(($Angle - 90)*PI/180)*$Radius + $Y; |
|
| 246 | 246 | |
| 247 | 247 | $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
| 248 | 248 | |
| 249 | - if ( $LabelStacked ) |
|
| 250 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$Radius); |
|
| 249 | + if ($LabelStacked) |
|
| 250 | + $this->writePieLabel($Xc, $Yc, $Label, $Angle, $Settings, TRUE, $X, $Y, $Radius); |
|
| 251 | 251 | else |
| 252 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 252 | + $this->writePieLabel($Xc, $Yc, $Label, $Angle, $Settings, FALSE); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | $Offset = $i + $DataGapAngle; $ID++; |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - if ( $WriteValues != NULL && !$Shadow ) |
|
| 259 | + if ($WriteValues != NULL && !$Shadow) |
|
| 260 | 260 | { |
| 261 | - $Step = 360 / (2 * PI * $Radius); |
|
| 262 | - $Offset = 0; $ID = count($Values)-1; |
|
| 263 | - $Settings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"R"=>$ValueR,"G"=>$ValueG,"B"=>$ValueB,"Alpha"=>$ValueAlpha); |
|
| 264 | - foreach($Values as $Key => $Value) |
|
| 261 | + $Step = 360/(2*PI*$Radius); |
|
| 262 | + $Offset = 0; $ID = count($Values) - 1; |
|
| 263 | + $Settings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE, "R"=>$ValueR, "G"=>$ValueG, "B"=>$ValueB, "Alpha"=>$ValueAlpha); |
|
| 264 | + foreach ($Values as $Key => $Value) |
|
| 265 | 265 | { |
| 266 | - $EndAngle = ($Value*$ScaleFactor) + $Offset; if ( $EndAngle > 360 ) { $EndAngle = 0; } |
|
| 266 | + $EndAngle = ($Value*$ScaleFactor) + $Offset; if ($EndAngle > 360) { $EndAngle = 0; } |
|
| 267 | 267 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 268 | 268 | |
| 269 | - if ( $ValuePosition == PIE_VALUE_OUTSIDE ) |
|
| 269 | + if ($ValuePosition == PIE_VALUE_OUTSIDE) |
|
| 270 | 270 | { |
| 271 | - $Xc = cos(($Angle-90)*PI/180) * ($Radius+$ValuePadding) + $X; |
|
| 272 | - $Yc = sin(($Angle-90)*PI/180) * ($Radius+$ValuePadding) + $Y; |
|
| 271 | + $Xc = cos(($Angle - 90)*PI/180)*($Radius + $ValuePadding) + $X; |
|
| 272 | + $Yc = sin(($Angle - 90)*PI/180)*($Radius + $ValuePadding) + $Y; |
|
| 273 | 273 | } |
| 274 | 274 | else |
| 275 | 275 | { |
| 276 | - $Xc = cos(($Angle-90)*PI/180) * ($Radius)/2 + $X; |
|
| 277 | - $Yc = sin(($Angle-90)*PI/180) * ($Radius)/2 + $Y; |
|
| 276 | + $Xc = cos(($Angle - 90)*PI/180)*($Radius)/2 + $X; |
|
| 277 | + $Yc = sin(($Angle - 90)*PI/180)*($Radius)/2 + $Y; |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 281 | - $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 282 | - elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 280 | + if ($WriteValues == PIE_VALUE_PERCENTAGE) |
|
| 281 | + $Display = round((100/$SerieSum)*$Value, $Precision)."%"; |
|
| 282 | + elseif ($WriteValues == PIE_VALUE_NATURAL) |
|
| 283 | 283 | $Display = $Value.$ValueSuffix; |
| 284 | 284 | |
| 285 | - $this->pChartObject->drawText($Xc,$Yc,$Display,$Settings); |
|
| 285 | + $this->pChartObject->drawText($Xc, $Yc, $Display, $Settings); |
|
| 286 | 286 | |
| 287 | 287 | $Offset = $EndAngle + $DataGapAngle; $ID--; |
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - if ( $DrawLabels && $LabelStacked ) { $this->writeShiftedLabels(); } |
|
| 291 | + if ($DrawLabels && $LabelStacked) { $this->writeShiftedLabels(); } |
|
| 292 | 292 | |
| 293 | 293 | $this->pChartObject->Shadow = $RestoreShadow; |
| 294 | 294 | |
@@ -296,61 +296,61 @@ discard block |
||
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /* Draw a 3D pie chart */ |
| 299 | - function draw3DPie($X,$Y,$Format="") |
|
| 299 | + function draw3DPie($X, $Y, $Format = "") |
|
| 300 | 300 | { |
| 301 | 301 | /* Rendering layout */ |
| 302 | - $Radius = isset($Format["Radius"]) ? $Format["Radius"] : 80; |
|
| 302 | + $Radius = isset($Format["Radius"]) ? $Format["Radius"] : 80; |
|
| 303 | 303 | $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; |
| 304 | 304 | $SkewFactor = isset($Format["SkewFactor"]) ? $Format["SkewFactor"] : .5; |
| 305 | - $SliceHeight = isset($Format["SliceHeight"]) ? $Format["SliceHeight"] : 20; |
|
| 306 | - $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 0; |
|
| 307 | - $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 0; |
|
| 305 | + $SliceHeight = isset($Format["SliceHeight"]) ? $Format["SliceHeight"] : 20; |
|
| 306 | + $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 0; |
|
| 307 | + $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 0; |
|
| 308 | 308 | $SecondPass = isset($Format["SecondPass"]) ? $Format["SecondPass"] : TRUE; |
| 309 | 309 | $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
| 310 | 310 | $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
| 311 | 311 | $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE; |
| 312 | - $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 312 | + $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 313 | 313 | $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL; |
| 314 | 314 | $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0; |
| 315 | 315 | $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0; |
| 316 | 316 | $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0; |
| 317 | - $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 317 | + $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 318 | 318 | $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : NULL; //PIE_VALUE_PERCENTAGE |
| 319 | - $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_INSIDE; |
|
| 320 | - $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 15; |
|
| 319 | + $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_INSIDE; |
|
| 320 | + $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 15; |
|
| 321 | 321 | $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : ""; |
| 322 | 322 | $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255; |
| 323 | 323 | $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255; |
| 324 | 324 | $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255; |
| 325 | - $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 326 | - $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 325 | + $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 326 | + $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 327 | 327 | |
| 328 | 328 | /* Error correction for overlaying rounded corners */ |
| 329 | - if ( $SkewFactor < .5 ) { $SkewFactor = .5; } |
|
| 329 | + if ($SkewFactor < .5) { $SkewFactor = .5; } |
|
| 330 | 330 | |
| 331 | 331 | /* Data Processing */ |
| 332 | 332 | $Data = $this->pDataObject->getData(); |
| 333 | 333 | $Palette = $this->pDataObject->getPalette(); |
| 334 | 334 | |
| 335 | 335 | /* Do we have an abscissa serie defined? */ |
| 336 | - if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 336 | + if ($Data["Abscissa"] == "") { return(PIE_NO_ABSCISSA); } |
|
| 337 | 337 | |
| 338 | 338 | /* Try to find the data serie */ |
| 339 | 339 | $DataSerie = ""; |
| 340 | 340 | foreach ($Data["Series"] as $SerieName => $SerieData) |
| 341 | - { if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 341 | + { if ($SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 342 | 342 | |
| 343 | 343 | /* Do we have data to compute? */ |
| 344 | - if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); } |
|
| 344 | + if ($DataSerie == "") { return(PIE_NO_DATASERIE); } |
|
| 345 | 345 | |
| 346 | 346 | /* Remove unused data */ |
| 347 | - list($Data,$Palette) = $this->clean0Values($Data,$Palette,$DataSerie,$Data["Abscissa"]); |
|
| 347 | + list($Data, $Palette) = $this->clean0Values($Data, $Palette, $DataSerie, $Data["Abscissa"]); |
|
| 348 | 348 | |
| 349 | 349 | /* Compute the pie sum */ |
| 350 | 350 | $SerieSum = $this->pDataObject->getSum($DataSerie); |
| 351 | 351 | |
| 352 | 352 | /* Do we have data to draw? */ |
| 353 | - if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); } |
|
| 353 | + if ($SerieSum == 0) { return(PIE_SUMISNULL); } |
|
| 354 | 354 | |
| 355 | 355 | /* Dump the real number of data to draw */ |
| 356 | 356 | $Values = ""; |
@@ -358,51 +358,51 @@ discard block |
||
| 358 | 358 | { if ($Value != 0) { $Values[] = $Value; } } |
| 359 | 359 | |
| 360 | 360 | /* Compute the wasted angular space between series */ |
| 361 | - if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = count($Values) * $DataGapAngle; } |
|
| 361 | + if (count($Values) == 1) { $WastedAngular = 0; } else { $WastedAngular = count($Values)*$DataGapAngle; } |
|
| 362 | 362 | |
| 363 | 363 | /* Compute the scale */ |
| 364 | - $ScaleFactor = (360 - $WastedAngular) / $SerieSum; |
|
| 364 | + $ScaleFactor = (360 - $WastedAngular)/$SerieSum; |
|
| 365 | 365 | |
| 366 | 366 | $RestoreShadow = $this->pChartObject->Shadow; |
| 367 | - if ( $this->pChartObject->Shadow ) { $this->pChartObject->Shadow = FALSE; } |
|
| 367 | + if ($this->pChartObject->Shadow) { $this->pChartObject->Shadow = FALSE; } |
|
| 368 | 368 | |
| 369 | 369 | /* Draw the polygon pie elements */ |
| 370 | - $Step = 360 / (2 * PI * $Radius); |
|
| 371 | - $Offset = 360; $ID = count($Values)-1; |
|
| 370 | + $Step = 360/(2*PI*$Radius); |
|
| 371 | + $Offset = 360; $ID = count($Values) - 1; |
|
| 372 | 372 | $Values = array_reverse($Values); |
| 373 | 373 | $Slice = 0; $Slices = ""; $SliceColors = ""; $Visible = ""; $SliceAngle = ""; |
| 374 | - foreach($Values as $Key => $Value) |
|
| 374 | + foreach ($Values as $Key => $Value) |
|
| 375 | 375 | { |
| 376 | - if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
|
| 377 | - $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 376 | + if (!isset($Palette[$ID]["R"])) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID, $Color); } |
|
| 377 | + $Settings = array("R"=>$Palette[$ID]["R"], "G"=>$Palette[$ID]["G"], "B"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 378 | 378 | |
| 379 | 379 | $SliceColors[$Slice] = $Settings; |
| 380 | 380 | |
| 381 | 381 | $StartAngle = $Offset; |
| 382 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 382 | + $EndAngle = $Offset - ($Value*$ScaleFactor); if ($EndAngle < 0) { $EndAngle = 0; } |
|
| 383 | 383 | |
| 384 | - if ( $StartAngle > 180 ) { $Visible[$Slice]["Start"] = TRUE; } else { $Visible[$Slice]["Start"] = TRUE; } |
|
| 385 | - if ( $EndAngle < 180 ) { $Visible[$Slice]["End"] = FALSE; } else { $Visible[$Slice]["End"] = TRUE; } |
|
| 384 | + if ($StartAngle > 180) { $Visible[$Slice]["Start"] = TRUE; } else { $Visible[$Slice]["Start"] = TRUE; } |
|
| 385 | + if ($EndAngle < 180) { $Visible[$Slice]["End"] = FALSE; } else { $Visible[$Slice]["End"] = TRUE; } |
|
| 386 | 386 | |
| 387 | 387 | if ($DataGapAngle == 0) |
| 388 | 388 | { $X0 = $X; $Y0 = $Y; } |
| 389 | 389 | else |
| 390 | 390 | { |
| 391 | 391 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 392 | - $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
|
| 393 | - $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius*$SkewFactor + $Y; |
|
| 392 | + $X0 = cos(($Angle - 90)*PI/180)*$DataGapRadius + $X; |
|
| 393 | + $Y0 = sin(($Angle - 90)*PI/180)*$DataGapRadius*$SkewFactor + $Y; |
|
| 394 | 394 | } |
| 395 | 395 | $Slices[$Slice][] = $X0; $Slices[$Slice][] = $Y0; $SliceAngle[$Slice][] = 0; |
| 396 | 396 | |
| 397 | - for($i=$Offset;$i>=$EndAngle;$i=$i-$Step) |
|
| 397 | + for ($i = $Offset; $i >= $EndAngle; $i = $i - $Step) |
|
| 398 | 398 | { |
| 399 | - $Xc = cos(($i-90)*PI/180) * $Radius + $X; |
|
| 400 | - $Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 399 | + $Xc = cos(($i - 90)*PI/180)*$Radius + $X; |
|
| 400 | + $Yc = sin(($i - 90)*PI/180)*$Radius*$SkewFactor + $Y; |
|
| 401 | 401 | |
| 402 | - if ( ($SecondPass || $RestoreShadow ) && ( $i<90 )) { $Yc++; } |
|
| 403 | - if ( ($SecondPass || $RestoreShadow ) && ( $i>90 && $i<180 )) { $Xc++; } |
|
| 404 | - if ( ($SecondPass || $RestoreShadow ) && ( $i>180 && $i<270 )) { $Xc++; } |
|
| 405 | - if ( ($SecondPass || $RestoreShadow ) && ( $i>=270 )) { $Xc++; $Yc++; } |
|
| 402 | + if (($SecondPass || $RestoreShadow) && ($i < 90)) { $Yc++; } |
|
| 403 | + if (($SecondPass || $RestoreShadow) && ($i > 90 && $i < 180)) { $Xc++; } |
|
| 404 | + if (($SecondPass || $RestoreShadow) && ($i > 180 && $i < 270)) { $Xc++; } |
|
| 405 | + if (($SecondPass || $RestoreShadow) && ($i >= 270)) { $Xc++; $Yc++; } |
|
| 406 | 406 | |
| 407 | 407 | $Slices[$Slice][] = $Xc; $Slices[$Slice][] = $Yc; $SliceAngle[$Slice][] = $i; |
| 408 | 408 | } |
@@ -411,30 +411,30 @@ discard block |
||
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /* Draw the bottom shadow if needed */ |
| 414 | - if ( $RestoreShadow && ($this->pChartObject->ShadowX != 0 || $this->pChartObject->ShadowY !=0 )) |
|
| 414 | + if ($RestoreShadow && ($this->pChartObject->ShadowX != 0 || $this->pChartObject->ShadowY != 0)) |
|
| 415 | 415 | { |
| 416 | - foreach($Slices as $SliceID => $Plots) |
|
| 416 | + foreach ($Slices as $SliceID => $Plots) |
|
| 417 | 417 | { |
| 418 | 418 | $ShadowPie = ""; |
| 419 | - for($i=0;$i<count($Plots);$i=$i+2) |
|
| 420 | - { $ShadowPie[] = $Plots[$i]+$this->pChartObject->ShadowX; $ShadowPie[] = $Plots[$i+1]+$this->pChartObject->ShadowY; } |
|
| 419 | + for ($i = 0; $i < count($Plots); $i = $i + 2) |
|
| 420 | + { $ShadowPie[] = $Plots[$i] + $this->pChartObject->ShadowX; $ShadowPie[] = $Plots[$i + 1] + $this->pChartObject->ShadowY; } |
|
| 421 | 421 | |
| 422 | - $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa,"NoBorder"=>TRUE); |
|
| 423 | - $this->pChartObject->drawPolygon($ShadowPie,$Settings); |
|
| 422 | + $Settings = array("R"=>$this->pChartObject->ShadowR, "G"=>$this->pChartObject->ShadowG, "B"=>$this->pChartObject->ShadowB, "Alpha"=>$this->pChartObject->Shadowa, "NoBorder"=>TRUE); |
|
| 423 | + $this->pChartObject->drawPolygon($ShadowPie, $Settings); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - $Step = 360 / (2 * PI * $Radius); |
|
| 426 | + $Step = 360/(2*PI*$Radius); |
|
| 427 | 427 | $Offset = 360; |
| 428 | - foreach($Values as $Key => $Value) |
|
| 428 | + foreach ($Values as $Key => $Value) |
|
| 429 | 429 | { |
| 430 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 430 | + $EndAngle = $Offset - ($Value*$ScaleFactor); if ($EndAngle < 0) { $EndAngle = 0; } |
|
| 431 | 431 | |
| 432 | - for($i=$Offset;$i>=$EndAngle;$i=$i-$Step) |
|
| 432 | + for ($i = $Offset; $i >= $EndAngle; $i = $i - $Step) |
|
| 433 | 433 | { |
| 434 | - $Xc = cos(($i-90)*PI/180) * $Radius + $X + $this->pChartObject->ShadowX; |
|
| 435 | - $Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y + $this->pChartObject->ShadowY; |
|
| 434 | + $Xc = cos(($i - 90)*PI/180)*$Radius + $X + $this->pChartObject->ShadowX; |
|
| 435 | + $Yc = sin(($i - 90)*PI/180)*$Radius*$SkewFactor + $Y + $this->pChartObject->ShadowY; |
|
| 436 | 436 | |
| 437 | - $this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings); |
|
| 437 | + $this->pChartObject->drawAntialiasPixel($Xc, $Yc, $Settings); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | $Offset = $i - $DataGapAngle; $ID--; |
@@ -442,28 +442,28 @@ discard block |
||
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | /* Draw the bottom pie splice */ |
| 445 | - foreach($Slices as $SliceID => $Plots) |
|
| 445 | + foreach ($Slices as $SliceID => $Plots) |
|
| 446 | 446 | { |
| 447 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 448 | - $this->pChartObject->drawPolygon($Plots,$Settings); |
|
| 447 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 448 | + $this->pChartObject->drawPolygon($Plots, $Settings); |
|
| 449 | 449 | |
| 450 | - if ( $SecondPass ) |
|
| 450 | + if ($SecondPass) |
|
| 451 | 451 | { |
| 452 | 452 | $Settings = $SliceColors[$SliceID]; |
| 453 | - if ( $Border ) |
|
| 454 | - { $Settings["R"]+= 30; $Settings["G"]+= 30; $Settings["B"]+= 30;; } |
|
| 453 | + if ($Border) |
|
| 454 | + { $Settings["R"] += 30; $Settings["G"] += 30; $Settings["B"] += 30; ; } |
|
| 455 | 455 | |
| 456 | - if ( isset($SliceAngle[$SliceID][1]) ) /* Empty error handling */ |
|
| 456 | + if (isset($SliceAngle[$SliceID][1])) /* Empty error handling */ |
|
| 457 | 457 | { |
| 458 | 458 | $Angle = $SliceAngle[$SliceID][1]; |
| 459 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 460 | - $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 461 | - $this->pChartObject->drawLine($Plots[0],$Plots[1],$Xc,$Yc,$Settings); |
|
| 462 | - |
|
| 463 | - $Angle = $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1]; |
|
| 464 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 465 | - $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 466 | - $this->pChartObject->drawLine($Plots[0],$Plots[1],$Xc,$Yc,$Settings); |
|
| 459 | + $Xc = cos(($Angle - 90)*PI/180)*$Radius + $X; |
|
| 460 | + $Yc = sin(($Angle - 90)*PI/180)*$Radius*$SkewFactor + $Y; |
|
| 461 | + $this->pChartObject->drawLine($Plots[0], $Plots[1], $Xc, $Yc, $Settings); |
|
| 462 | + |
|
| 463 | + $Angle = $SliceAngle[$SliceID][count($SliceAngle[$SliceID]) - 1]; |
|
| 464 | + $Xc = cos(($Angle - 90)*PI/180)*$Radius + $X; |
|
| 465 | + $Yc = sin(($Angle - 90)*PI/180)*$Radius*$SkewFactor + $Y; |
|
| 466 | + $this->pChartObject->drawLine($Plots[0], $Plots[1], $Xc, $Yc, $Settings); |
|
| 467 | 467 | } |
| 468 | 468 | } |
| 469 | 469 | } |
@@ -471,225 +471,225 @@ discard block |
||
| 471 | 471 | /* Draw the two vertical edges */ |
| 472 | 472 | $Slices = array_reverse($Slices); |
| 473 | 473 | $SliceColors = array_reverse($SliceColors); |
| 474 | - foreach($Slices as $SliceID => $Plots) |
|
| 474 | + foreach ($Slices as $SliceID => $Plots) |
|
| 475 | 475 | { |
| 476 | 476 | $Settings = $SliceColors[$SliceID]; |
| 477 | - $Settings["R"]+= 10; $Settings["G"]+= 10; $Settings["B"]+= 10; $Settings["NoBorder"] = TRUE; |
|
| 477 | + $Settings["R"] += 10; $Settings["G"] += 10; $Settings["B"] += 10; $Settings["NoBorder"] = TRUE; |
|
| 478 | 478 | |
| 479 | - if ( $Visible[$SliceID]["Start"] && isset($Plots[2])) /* Empty error handling */ |
|
| 479 | + if ($Visible[$SliceID]["Start"] && isset($Plots[2])) /* Empty error handling */ |
|
| 480 | 480 | { |
| 481 | - $this->pChartObject->drawLine($Plots[2],$Plots[3],$Plots[2],$Plots[3]- $SliceHeight,array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"])); |
|
| 481 | + $this->pChartObject->drawLine($Plots[2], $Plots[3], $Plots[2], $Plots[3] - $SliceHeight, array("R"=>$Settings["R"], "G"=>$Settings["G"], "B"=>$Settings["B"])); |
|
| 482 | 482 | $Border = ""; |
| 483 | 483 | $Border[] = $Plots[0]; $Border[] = $Plots[1]; $Border[] = $Plots[0]; $Border[] = $Plots[1] - $SliceHeight; |
| 484 | 484 | $Border[] = $Plots[2]; $Border[] = $Plots[3] - $SliceHeight; $Border[] = $Plots[2]; $Border[] = $Plots[3]; |
| 485 | - $this->pChartObject->drawPolygon($Border,$Settings); |
|
| 485 | + $this->pChartObject->drawPolygon($Border, $Settings); |
|
| 486 | 486 | } |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | $Slices = array_reverse($Slices); |
| 490 | 490 | $SliceColors = array_reverse($SliceColors); |
| 491 | - foreach($Slices as $SliceID => $Plots) |
|
| 491 | + foreach ($Slices as $SliceID => $Plots) |
|
| 492 | 492 | { |
| 493 | 493 | $Settings = $SliceColors[$SliceID]; |
| 494 | - $Settings["R"]+= 10; $Settings["G"]+= 10; $Settings["B"]+= 10; $Settings["NoBorder"] = TRUE; |
|
| 495 | - if ( $Visible[$SliceID]["End"] ) |
|
| 494 | + $Settings["R"] += 10; $Settings["G"] += 10; $Settings["B"] += 10; $Settings["NoBorder"] = TRUE; |
|
| 495 | + if ($Visible[$SliceID]["End"]) |
|
| 496 | 496 | { |
| 497 | - $this->pChartObject->drawLine($Plots[count($Plots)-2],$Plots[count($Plots)-1],$Plots[count($Plots)-2],$Plots[count($Plots)-1]- $SliceHeight,array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"])); |
|
| 497 | + $this->pChartObject->drawLine($Plots[count($Plots) - 2], $Plots[count($Plots) - 1], $Plots[count($Plots) - 2], $Plots[count($Plots) - 1] - $SliceHeight, array("R"=>$Settings["R"], "G"=>$Settings["G"], "B"=>$Settings["B"])); |
|
| 498 | 498 | |
| 499 | 499 | $Border = ""; |
| 500 | 500 | $Border[] = $Plots[0]; $Border[] = $Plots[1]; $Border[] = $Plots[0]; $Border[] = $Plots[1] - $SliceHeight; |
| 501 | - $Border[] = $Plots[count($Plots)-2]; $Border[] = $Plots[count($Plots)-1] - $SliceHeight; $Border[] = $Plots[count($Plots)-2]; $Border[] = $Plots[count($Plots)-1]; |
|
| 502 | - $this->pChartObject->drawPolygon($Border,$Settings); |
|
| 501 | + $Border[] = $Plots[count($Plots) - 2]; $Border[] = $Plots[count($Plots) - 1] - $SliceHeight; $Border[] = $Plots[count($Plots) - 2]; $Border[] = $Plots[count($Plots) - 1]; |
|
| 502 | + $this->pChartObject->drawPolygon($Border, $Settings); |
|
| 503 | 503 | } |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | /* Draw the rounded edges */ |
| 507 | - foreach($Slices as $SliceID => $Plots) |
|
| 507 | + foreach ($Slices as $SliceID => $Plots) |
|
| 508 | 508 | { |
| 509 | 509 | $Settings = $SliceColors[$SliceID]; |
| 510 | - $Settings["R"]+= 10; $Settings["G"]+= 10; $Settings["B"]+= 10; $Settings["NoBorder"] = TRUE; |
|
| 510 | + $Settings["R"] += 10; $Settings["G"] += 10; $Settings["B"] += 10; $Settings["NoBorder"] = TRUE; |
|
| 511 | 511 | |
| 512 | - for ($j=2;$j<count($Plots)-2;$j=$j+2) |
|
| 512 | + for ($j = 2; $j < count($Plots) - 2; $j = $j + 2) |
|
| 513 | 513 | { |
| 514 | 514 | $Angle = $SliceAngle[$SliceID][$j/2]; |
| 515 | - if ( $Angle < 270 && $Angle > 90 ) |
|
| 515 | + if ($Angle < 270 && $Angle > 90) |
|
| 516 | 516 | { |
| 517 | 517 | $Border = ""; |
| 518 | - $Border[] = $Plots[$j]; $Border[] = $Plots[$j+1]; |
|
| 519 | - $Border[] = $Plots[$j+2]; $Border[] = $Plots[$j+3]; |
|
| 520 | - $Border[] = $Plots[$j+2]; $Border[] = $Plots[$j+3] - $SliceHeight; |
|
| 521 | - $Border[] = $Plots[$j]; $Border[] = $Plots[$j+1] - $SliceHeight; |
|
| 522 | - $this->pChartObject->drawPolygon($Border,$Settings); |
|
| 518 | + $Border[] = $Plots[$j]; $Border[] = $Plots[$j + 1]; |
|
| 519 | + $Border[] = $Plots[$j + 2]; $Border[] = $Plots[$j + 3]; |
|
| 520 | + $Border[] = $Plots[$j + 2]; $Border[] = $Plots[$j + 3] - $SliceHeight; |
|
| 521 | + $Border[] = $Plots[$j]; $Border[] = $Plots[$j + 1] - $SliceHeight; |
|
| 522 | + $this->pChartObject->drawPolygon($Border, $Settings); |
|
| 523 | 523 | } |
| 524 | 524 | } |
| 525 | 525 | |
| 526 | - if ( $SecondPass ) |
|
| 526 | + if ($SecondPass) |
|
| 527 | 527 | { |
| 528 | 528 | $Settings = $SliceColors[$SliceID]; |
| 529 | - if ( $Border ) |
|
| 530 | - { $Settings["R"]+= 30; $Settings["G"]+= 30; $Settings["B"]+= 30; } |
|
| 529 | + if ($Border) |
|
| 530 | + { $Settings["R"] += 30; $Settings["G"] += 30; $Settings["B"] += 30; } |
|
| 531 | 531 | |
| 532 | - if ( isset($SliceAngle[$SliceID][1]) ) /* Empty error handling */ |
|
| 532 | + if (isset($SliceAngle[$SliceID][1])) /* Empty error handling */ |
|
| 533 | 533 | { |
| 534 | 534 | $Angle = $SliceAngle[$SliceID][1]; |
| 535 | - if ( $Angle < 270 && $Angle > 90 ) |
|
| 535 | + if ($Angle < 270 && $Angle > 90) |
|
| 536 | 536 | { |
| 537 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 538 | - $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 539 | - $this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings); |
|
| 537 | + $Xc = cos(($Angle - 90)*PI/180)*$Radius + $X; |
|
| 538 | + $Yc = sin(($Angle - 90)*PI/180)*$Radius*$SkewFactor + $Y; |
|
| 539 | + $this->pChartObject->drawLine($Xc, $Yc, $Xc, $Yc - $SliceHeight, $Settings); |
|
| 540 | 540 | } |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - $Angle = $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1]; |
|
| 544 | - if ( $Angle < 270 && $Angle > 90 ) |
|
| 543 | + $Angle = $SliceAngle[$SliceID][count($SliceAngle[$SliceID]) - 1]; |
|
| 544 | + if ($Angle < 270 && $Angle > 90) |
|
| 545 | 545 | { |
| 546 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 547 | - $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 548 | - $this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings); |
|
| 546 | + $Xc = cos(($Angle - 90)*PI/180)*$Radius + $X; |
|
| 547 | + $Yc = sin(($Angle - 90)*PI/180)*$Radius*$SkewFactor + $Y; |
|
| 548 | + $this->pChartObject->drawLine($Xc, $Yc, $Xc, $Yc - $SliceHeight, $Settings); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | - if ( isset($SliceAngle[$SliceID][1]) && $SliceAngle[$SliceID][1] > 270 && $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1] < 270 ) |
|
| 551 | + if (isset($SliceAngle[$SliceID][1]) && $SliceAngle[$SliceID][1] > 270 && $SliceAngle[$SliceID][count($SliceAngle[$SliceID]) - 1] < 270) |
|
| 552 | 552 | { |
| 553 | - $Xc = cos((270-90)*PI/180) * $Radius + $X; |
|
| 554 | - $Yc = sin((270-90)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 555 | - $this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings); |
|
| 553 | + $Xc = cos((270 - 90)*PI/180)*$Radius + $X; |
|
| 554 | + $Yc = sin((270 - 90)*PI/180)*$Radius*$SkewFactor + $Y; |
|
| 555 | + $this->pChartObject->drawLine($Xc, $Yc, $Xc, $Yc - $SliceHeight, $Settings); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | - if ( isset($SliceAngle[$SliceID][1]) && $SliceAngle[$SliceID][1] > 90 && $SliceAngle[$SliceID][count($SliceAngle[$SliceID])-1] < 90 ) |
|
| 558 | + if (isset($SliceAngle[$SliceID][1]) && $SliceAngle[$SliceID][1] > 90 && $SliceAngle[$SliceID][count($SliceAngle[$SliceID]) - 1] < 90) |
|
| 559 | 559 | { |
| 560 | - $Xc = cos((0)*PI/180) * $Radius + $X; |
|
| 561 | - $Yc = sin((0)*PI/180) * $Radius*$SkewFactor + $Y; |
|
| 562 | - $this->pChartObject->drawLine($Xc,$Yc,$Xc,$Yc-$SliceHeight,$Settings); |
|
| 560 | + $Xc = cos((0)*PI/180)*$Radius + $X; |
|
| 561 | + $Yc = sin((0)*PI/180)*$Radius*$SkewFactor + $Y; |
|
| 562 | + $this->pChartObject->drawLine($Xc, $Yc, $Xc, $Yc - $SliceHeight, $Settings); |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | } |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | /* Draw the top splice */ |
| 569 | - foreach($Slices as $SliceID => $Plots) |
|
| 569 | + foreach ($Slices as $SliceID => $Plots) |
|
| 570 | 570 | { |
| 571 | 571 | $Settings = $SliceColors[$SliceID]; |
| 572 | - $Settings["R"]+= 20; $Settings["G"]+= 20; $Settings["B"]+= 20; |
|
| 572 | + $Settings["R"] += 20; $Settings["G"] += 20; $Settings["B"] += 20; |
|
| 573 | 573 | |
| 574 | 574 | $Top = ""; |
| 575 | - for($j=0;$j<count($Plots);$j=$j+2) { $Top[] = $Plots[$j]; $Top[] = $Plots[$j+1]- $SliceHeight; } |
|
| 576 | - $this->pChartObject->drawPolygon($Top,$Settings); |
|
| 575 | + for ($j = 0; $j < count($Plots); $j = $j + 2) { $Top[] = $Plots[$j]; $Top[] = $Plots[$j + 1] - $SliceHeight; } |
|
| 576 | + $this->pChartObject->drawPolygon($Top, $Settings); |
|
| 577 | 577 | |
| 578 | - if ( $RecordImageMap && !$Shadow ) { $this->pChartObject->addToImageMap("POLY",$this->arraySerialize($Top),$this->pChartObject->toHTMLColor($Settings["R"],$Settings["G"],$Settings["B"]),$Data["Series"][$Data["Abscissa"]]["Data"][count($Slices)-$SliceID-1],$Values[$SliceID]); } |
|
| 578 | + if ($RecordImageMap && !$Shadow) { $this->pChartObject->addToImageMap("POLY", $this->arraySerialize($Top), $this->pChartObject->toHTMLColor($Settings["R"], $Settings["G"], $Settings["B"]), $Data["Series"][$Data["Abscissa"]]["Data"][count($Slices) - $SliceID - 1], $Values[$SliceID]); } |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | |
| 582 | 582 | /* Second pass to smooth the angles */ |
| 583 | - if ( $SecondPass ) |
|
| 583 | + if ($SecondPass) |
|
| 584 | 584 | { |
| 585 | - $Step = 360 / (2 * PI * $Radius); |
|
| 586 | - $Offset = 360; $ID = count($Values)-1; |
|
| 587 | - foreach($Values as $Key => $Value) |
|
| 585 | + $Step = 360/(2*PI*$Radius); |
|
| 586 | + $Offset = 360; $ID = count($Values) - 1; |
|
| 587 | + foreach ($Values as $Key => $Value) |
|
| 588 | 588 | { |
| 589 | 589 | $FirstPoint = TRUE; |
| 590 | - if ( $Shadow ) |
|
| 591 | - $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 590 | + if ($Shadow) |
|
| 591 | + $Settings = array("R"=>$this->pChartObject->ShadowR, "G"=>$this->pChartObject->ShadowG, "B"=>$this->pChartObject->ShadowB, "Alpha"=>$this->pChartObject->Shadowa); |
|
| 592 | 592 | else |
| 593 | 593 | { |
| 594 | - if ( $Border ) |
|
| 595 | - { $Settings = array("R"=>$Palette[$ID]["R"]+30,"G"=>$Palette[$ID]["G"]+30,"B"=>$Palette[$ID]["B"]+30,"Alpha"=>$Palette[$ID]["Alpha"]); } |
|
| 594 | + if ($Border) |
|
| 595 | + { $Settings = array("R"=>$Palette[$ID]["R"] + 30, "G"=>$Palette[$ID]["G"] + 30, "B"=>$Palette[$ID]["B"] + 30, "Alpha"=>$Palette[$ID]["Alpha"]); } |
|
| 596 | 596 | else |
| 597 | - $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 597 | + $Settings = array("R"=>$Palette[$ID]["R"], "G"=>$Palette[$ID]["G"], "B"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 600 | + $EndAngle = $Offset - ($Value*$ScaleFactor); if ($EndAngle < 0) { $EndAngle = 0; } |
|
| 601 | 601 | |
| 602 | 602 | if ($DataGapAngle == 0) |
| 603 | - { $X0 = $X; $Y0 = $Y- $SliceHeight; } |
|
| 603 | + { $X0 = $X; $Y0 = $Y - $SliceHeight; } |
|
| 604 | 604 | else |
| 605 | 605 | { |
| 606 | 606 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 607 | - $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
|
| 608 | - $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius*$SkewFactor + $Y - $SliceHeight; |
|
| 607 | + $X0 = cos(($Angle - 90)*PI/180)*$DataGapRadius + $X; |
|
| 608 | + $Y0 = sin(($Angle - 90)*PI/180)*$DataGapRadius*$SkewFactor + $Y - $SliceHeight; |
|
| 609 | 609 | } |
| 610 | 610 | $Plots[] = $X0; $Plots[] = $Y0; |
| 611 | 611 | |
| 612 | - for($i=$Offset;$i>=$EndAngle;$i=$i-$Step) |
|
| 612 | + for ($i = $Offset; $i >= $EndAngle; $i = $i - $Step) |
|
| 613 | 613 | { |
| 614 | - $Xc = cos(($i-90)*PI/180) * $Radius + $X; |
|
| 615 | - $Yc = sin(($i-90)*PI/180) * $Radius*$SkewFactor + $Y - $SliceHeight; |
|
| 614 | + $Xc = cos(($i - 90)*PI/180)*$Radius + $X; |
|
| 615 | + $Yc = sin(($i - 90)*PI/180)*$Radius*$SkewFactor + $Y - $SliceHeight; |
|
| 616 | 616 | |
| 617 | - if ( $FirstPoint ) { $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); } { $FirstPoint = FALSE; } |
|
| 617 | + if ($FirstPoint) { $this->pChartObject->drawLine($Xc, $Yc, $X0, $Y0, $Settings); } { $FirstPoint = FALSE; } |
|
| 618 | 618 | |
| 619 | - $this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings); |
|
| 620 | - if ($i < 270 && $i > 90 ) { $this->pChartObject->drawAntialiasPixel($Xc,$Yc+$SliceHeight,$Settings); } |
|
| 619 | + $this->pChartObject->drawAntialiasPixel($Xc, $Yc, $Settings); |
|
| 620 | + if ($i < 270 && $i > 90) { $this->pChartObject->drawAntialiasPixel($Xc, $Yc + $SliceHeight, $Settings); } |
|
| 621 | 621 | } |
| 622 | - $this->pChartObject->drawLine($Xc,$Yc,$X0,$Y0,$Settings); |
|
| 622 | + $this->pChartObject->drawLine($Xc, $Yc, $X0, $Y0, $Settings); |
|
| 623 | 623 | |
| 624 | 624 | $Offset = $i - $DataGapAngle; $ID--; |
| 625 | 625 | } |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | - if ( $WriteValues != NULL ) |
|
| 628 | + if ($WriteValues != NULL) |
|
| 629 | 629 | { |
| 630 | - $Step = 360 / (2 * PI * $Radius); |
|
| 631 | - $Offset = 360; $ID = count($Values)-1; |
|
| 632 | - $Settings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"R"=>$ValueR,"G"=>$ValueG,"B"=>$ValueB,"Alpha"=>$ValueAlpha); |
|
| 633 | - foreach($Values as $Key => $Value) |
|
| 630 | + $Step = 360/(2*PI*$Radius); |
|
| 631 | + $Offset = 360; $ID = count($Values) - 1; |
|
| 632 | + $Settings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE, "R"=>$ValueR, "G"=>$ValueG, "B"=>$ValueB, "Alpha"=>$ValueAlpha); |
|
| 633 | + foreach ($Values as $Key => $Value) |
|
| 634 | 634 | { |
| 635 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 635 | + $EndAngle = $Offset - ($Value*$ScaleFactor); if ($EndAngle < 0) { $EndAngle = 0; } |
|
| 636 | 636 | |
| 637 | 637 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 638 | 638 | |
| 639 | - if ( $ValuePosition == PIE_VALUE_OUTSIDE ) |
|
| 639 | + if ($ValuePosition == PIE_VALUE_OUTSIDE) |
|
| 640 | 640 | { |
| 641 | - $Xc = cos(($Angle-90)*PI/180) * ($Radius+$ValuePadding) + $X; |
|
| 642 | - $Yc = sin(($Angle-90)*PI/180) * (($Radius*$SkewFactor)+$ValuePadding) + $Y - $SliceHeight; |
|
| 641 | + $Xc = cos(($Angle - 90)*PI/180)*($Radius + $ValuePadding) + $X; |
|
| 642 | + $Yc = sin(($Angle - 90)*PI/180)*(($Radius*$SkewFactor) + $ValuePadding) + $Y - $SliceHeight; |
|
| 643 | 643 | } |
| 644 | 644 | else |
| 645 | 645 | { |
| 646 | - $Xc = cos(($Angle-90)*PI/180) * ($Radius)/2 + $X; |
|
| 647 | - $Yc = sin(($Angle-90)*PI/180) * ($Radius*$SkewFactor)/2 + $Y - $SliceHeight; |
|
| 646 | + $Xc = cos(($Angle - 90)*PI/180)*($Radius)/2 + $X; |
|
| 647 | + $Yc = sin(($Angle - 90)*PI/180)*($Radius*$SkewFactor)/2 + $Y - $SliceHeight; |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 651 | - $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 652 | - elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 650 | + if ($WriteValues == PIE_VALUE_PERCENTAGE) |
|
| 651 | + $Display = round((100/$SerieSum)*$Value, $Precision)."%"; |
|
| 652 | + elseif ($WriteValues == PIE_VALUE_NATURAL) |
|
| 653 | 653 | $Display = $Value.$ValueSuffix; |
| 654 | 654 | |
| 655 | - $this->pChartObject->drawText($Xc,$Yc,$Display,$Settings); |
|
| 655 | + $this->pChartObject->drawText($Xc, $Yc, $Display, $Settings); |
|
| 656 | 656 | |
| 657 | 657 | $Offset = $EndAngle - $DataGapAngle; $ID--; |
| 658 | 658 | } |
| 659 | 659 | } |
| 660 | 660 | |
| 661 | - if ( $DrawLabels ) |
|
| 661 | + if ($DrawLabels) |
|
| 662 | 662 | { |
| 663 | - $Step = 360 / (2 * PI * $Radius); |
|
| 664 | - $Offset = 360; $ID = count($Values)-1; |
|
| 665 | - foreach($Values as $Key => $Value) |
|
| 663 | + $Step = 360/(2*PI*$Radius); |
|
| 664 | + $Offset = 360; $ID = count($Values) - 1; |
|
| 665 | + foreach ($Values as $Key => $Value) |
|
| 666 | 666 | { |
| 667 | - if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 668 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 667 | + if ($LabelColor == PIE_LABEL_COLOR_AUTO) |
|
| 668 | + { $Settings = array("FillR"=>$Palette[$ID]["R"], "FillG"=>$Palette[$ID]["G"], "FillB"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"]); } |
|
| 669 | 669 | else |
| 670 | - { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
|
| 670 | + { $Settings = array("FillR"=>$LabelR, "FillG"=>$LabelG, "FillB"=>$LabelB, "Alpha"=>$LabelAlpha); } |
|
| 671 | 671 | |
| 672 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 672 | + $EndAngle = $Offset - ($Value*$ScaleFactor); if ($EndAngle < 0) { $EndAngle = 0; } |
|
| 673 | 673 | |
| 674 | 674 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 675 | - $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
|
| 676 | - $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y - $SliceHeight; |
|
| 675 | + $Xc = cos(($Angle - 90)*PI/180)*$Radius + $X; |
|
| 676 | + $Yc = sin(($Angle - 90)*PI/180)*$Radius*$SkewFactor + $Y - $SliceHeight; |
|
| 677 | 677 | |
| 678 | - if ( isset($Data["Series"][$Data["Abscissa"]]["Data"][$ID]) ) |
|
| 678 | + if (isset($Data["Series"][$Data["Abscissa"]]["Data"][$ID])) |
|
| 679 | 679 | { |
| 680 | 680 | $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$ID]; |
| 681 | 681 | |
| 682 | - if ( $LabelStacked ) |
|
| 683 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$Radius,TRUE); |
|
| 682 | + if ($LabelStacked) |
|
| 683 | + $this->writePieLabel($Xc, $Yc, $Label, $Angle, $Settings, TRUE, $X, $Y, $Radius, TRUE); |
|
| 684 | 684 | else |
| 685 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 685 | + $this->writePieLabel($Xc, $Yc, $Label, $Angle, $Settings, FALSE); |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | $Offset = $EndAngle - $DataGapAngle; $ID--; |
| 689 | 689 | } |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | - if ( $DrawLabels && $LabelStacked ) { $this->writeShiftedLabels(); } |
|
| 692 | + if ($DrawLabels && $LabelStacked) { $this->writeShiftedLabels(); } |
|
| 693 | 693 | |
| 694 | 694 | $this->pChartObject->Shadow = $RestoreShadow; |
| 695 | 695 | |
@@ -697,29 +697,29 @@ discard block |
||
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | /* Draw the legend of pie chart */ |
| 700 | - function drawPieLegend($X,$Y,$Format="") |
|
| 700 | + function drawPieLegend($X, $Y, $Format = "") |
|
| 701 | 701 | { |
| 702 | 702 | $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName; |
| 703 | 703 | $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize; |
| 704 | 704 | $FontR = isset($Format["FontR"]) ? $Format["FontR"] : $this->pChartObject->FontColorR; |
| 705 | 705 | $FontG = isset($Format["FontG"]) ? $Format["FontG"] : $this->pChartObject->FontColorG; |
| 706 | 706 | $FontB = isset($Format["FontB"]) ? $Format["FontB"] : $this->pChartObject->FontColorB; |
| 707 | - $BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5; |
|
| 708 | - $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5; |
|
| 707 | + $BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5; |
|
| 708 | + $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5; |
|
| 709 | 709 | $R = isset($Format["R"]) ? $Format["R"] : 200; |
| 710 | 710 | $G = isset($Format["G"]) ? $Format["G"] : 200; |
| 711 | 711 | $B = isset($Format["B"]) ? $Format["B"] : 200; |
| 712 | - $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100; |
|
| 712 | + $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100; |
|
| 713 | 713 | $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255; |
| 714 | 714 | $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255; |
| 715 | 715 | $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255; |
| 716 | - $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL; |
|
| 717 | - $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND; |
|
| 718 | - $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL; |
|
| 716 | + $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL; |
|
| 717 | + $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND; |
|
| 718 | + $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL; |
|
| 719 | 719 | |
| 720 | - if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; } |
|
| 720 | + if ($Surrounding != NULL) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; } |
|
| 721 | 721 | |
| 722 | - $YStep = max($this->pChartObject->FontSize,$BoxSize) + 5; |
|
| 722 | + $YStep = max($this->pChartObject->FontSize, $BoxSize) + 5; |
|
| 723 | 723 | $XStep = $BoxSize + 5; |
| 724 | 724 | |
| 725 | 725 | /* Data Processing */ |
@@ -727,54 +727,54 @@ discard block |
||
| 727 | 727 | $Palette = $this->pDataObject->getPalette(); |
| 728 | 728 | |
| 729 | 729 | /* Do we have an abscissa serie defined? */ |
| 730 | - if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 730 | + if ($Data["Abscissa"] == "") { return(PIE_NO_ABSCISSA); } |
|
| 731 | 731 | |
| 732 | 732 | $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X; |
| 733 | - foreach($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value) |
|
| 733 | + foreach ($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value) |
|
| 734 | 734 | { |
| 735 | - $BoxArray = $this->pChartObject->getTextBox($vX+$BoxSize+4,$vY+$BoxSize/2,$FontName,$FontSize,0,$Value); |
|
| 735 | + $BoxArray = $this->pChartObject->getTextBox($vX + $BoxSize + 4, $vY + $BoxSize/2, $FontName, $FontSize, 0, $Value); |
|
| 736 | 736 | |
| 737 | - if ( $Mode == LEGEND_VERTICAL ) |
|
| 737 | + if ($Mode == LEGEND_VERTICAL) |
|
| 738 | 738 | { |
| 739 | - if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$BoxSize/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$BoxSize/2; } |
|
| 740 | - if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; } |
|
| 741 | - if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$BoxSize/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$BoxSize/2; } |
|
| 742 | - $vY=$vY+$YStep; |
|
| 739 | + if ($Boundaries["T"] > $BoxArray[2]["Y"] + $BoxSize/2) { $Boundaries["T"] = $BoxArray[2]["Y"] + $BoxSize/2; } |
|
| 740 | + if ($Boundaries["R"] < $BoxArray[1]["X"] + 2) { $Boundaries["R"] = $BoxArray[1]["X"] + 2; } |
|
| 741 | + if ($Boundaries["B"] < $BoxArray[1]["Y"] + 2 + $BoxSize/2) { $Boundaries["B"] = $BoxArray[1]["Y"] + 2 + $BoxSize/2; } |
|
| 742 | + $vY = $vY + $YStep; |
|
| 743 | 743 | } |
| 744 | - elseif ( $Mode == LEGEND_HORIZONTAL ) |
|
| 744 | + elseif ($Mode == LEGEND_HORIZONTAL) |
|
| 745 | 745 | { |
| 746 | - if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$BoxSize/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$BoxSize/2; } |
|
| 747 | - if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; } |
|
| 748 | - if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$BoxSize/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$BoxSize/2; } |
|
| 749 | - $vX=$Boundaries["R"]+$XStep; |
|
| 746 | + if ($Boundaries["T"] > $BoxArray[2]["Y"] + $BoxSize/2) { $Boundaries["T"] = $BoxArray[2]["Y"] + $BoxSize/2; } |
|
| 747 | + if ($Boundaries["R"] < $BoxArray[1]["X"] + 2) { $Boundaries["R"] = $BoxArray[1]["X"] + 2; } |
|
| 748 | + if ($Boundaries["B"] < $BoxArray[1]["Y"] + 2 + $BoxSize/2) { $Boundaries["B"] = $BoxArray[1]["Y"] + 2 + $BoxSize/2; } |
|
| 749 | + $vX = $Boundaries["R"] + $XStep; |
|
| 750 | 750 | } |
| 751 | 751 | } |
| 752 | - $vY=$vY-$YStep; $vX=$vX-$XStep; |
|
| 752 | + $vY = $vY - $YStep; $vX = $vX - $XStep; |
|
| 753 | 753 | |
| 754 | - $TopOffset = $Y - $Boundaries["T"]; |
|
| 755 | - if ( $Boundaries["B"]-($vY+$BoxSize) < $TopOffset ) { $Boundaries["B"] = $vY+$BoxSize+$TopOffset; } |
|
| 754 | + $TopOffset = $Y - $Boundaries["T"]; |
|
| 755 | + if ($Boundaries["B"] - ($vY + $BoxSize) < $TopOffset) { $Boundaries["B"] = $vY + $BoxSize + $TopOffset; } |
|
| 756 | 756 | |
| 757 | - if ( $Style == LEGEND_ROUND ) |
|
| 758 | - $this->pChartObject->drawRoundedFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB)); |
|
| 759 | - elseif ( $Style == LEGEND_BOX ) |
|
| 760 | - $this->pChartObject->drawFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB)); |
|
| 757 | + if ($Style == LEGEND_ROUND) |
|
| 758 | + $this->pChartObject->drawRoundedFilledRectangle($Boundaries["L"] - $Margin, $Boundaries["T"] - $Margin, $Boundaries["R"] + $Margin, $Boundaries["B"] + $Margin, $Margin, array("R"=>$R, "G"=>$G, "B"=>$B, "Alpha"=>$Alpha, "BorderR"=>$BorderR, "BorderG"=>$BorderG, "BorderB"=>$BorderB)); |
|
| 759 | + elseif ($Style == LEGEND_BOX) |
|
| 760 | + $this->pChartObject->drawFilledRectangle($Boundaries["L"] - $Margin, $Boundaries["T"] - $Margin, $Boundaries["R"] + $Margin, $Boundaries["B"] + $Margin, array("R"=>$R, "G"=>$G, "B"=>$B, "Alpha"=>$Alpha, "BorderR"=>$BorderR, "BorderG"=>$BorderG, "BorderB"=>$BorderB)); |
|
| 761 | 761 | |
| 762 | 762 | $RestoreShadow = $this->pChartObject->Shadow; $this->pChartObject->Shadow = FALSE; |
| 763 | - foreach($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value) |
|
| 763 | + foreach ($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value) |
|
| 764 | 764 | { |
| 765 | 765 | $R = $Palette[$Key]["R"]; $G = $Palette[$Key]["G"]; $B = $Palette[$Key]["B"]; |
| 766 | 766 | |
| 767 | - $this->pChartObject->drawFilledRectangle($X+1,$Y+1,$X+$BoxSize+1,$Y+$BoxSize+1,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20)); |
|
| 768 | - $this->pChartObject->drawFilledRectangle($X,$Y,$X+$BoxSize,$Y+$BoxSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20)); |
|
| 769 | - if ( $Mode == LEGEND_VERTICAL ) |
|
| 767 | + $this->pChartObject->drawFilledRectangle($X + 1, $Y + 1, $X + $BoxSize + 1, $Y + $BoxSize + 1, array("R"=>0, "G"=>0, "B"=>0, "Alpha"=>20)); |
|
| 768 | + $this->pChartObject->drawFilledRectangle($X, $Y, $X + $BoxSize, $Y + $BoxSize, array("R"=>$R, "G"=>$G, "B"=>$B, "Surrounding"=>20)); |
|
| 769 | + if ($Mode == LEGEND_VERTICAL) |
|
| 770 | 770 | { |
| 771 | - $this->pChartObject->drawText($X+$BoxSize+4,$Y+$BoxSize/2,$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT,"FontName"=>$FontName,"FontSize"=>$FontSize)); |
|
| 772 | - $Y=$Y+$YStep; |
|
| 771 | + $this->pChartObject->drawText($X + $BoxSize + 4, $Y + $BoxSize/2, $Value, array("R"=>$FontR, "G"=>$FontG, "B"=>$FontB, "Align"=>TEXT_ALIGN_MIDDLELEFT, "FontName"=>$FontName, "FontSize"=>$FontSize)); |
|
| 772 | + $Y = $Y + $YStep; |
|
| 773 | 773 | } |
| 774 | - elseif ( $Mode == LEGEND_HORIZONTAL ) |
|
| 774 | + elseif ($Mode == LEGEND_HORIZONTAL) |
|
| 775 | 775 | { |
| 776 | - $BoxArray = $this->pChartObject->drawText($X+$BoxSize+4,$Y+$BoxSize/2,$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT,"FontName"=>$FontName,"FontSize"=>$FontSize)); |
|
| 777 | - $X=$BoxArray[1]["X"]+2+$XStep; |
|
| 776 | + $BoxArray = $this->pChartObject->drawText($X + $BoxSize + 4, $Y + $BoxSize/2, $Value, array("R"=>$FontR, "G"=>$FontG, "B"=>$FontB, "Align"=>TEXT_ALIGN_MIDDLELEFT, "FontName"=>$FontName, "FontSize"=>$FontSize)); |
|
| 777 | + $X = $BoxArray[1]["X"] + 2 + $XStep; |
|
| 778 | 778 | } |
| 779 | 779 | } |
| 780 | 780 | |
@@ -782,12 +782,12 @@ discard block |
||
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | /* Set the color of the specified slice */ |
| 785 | - function setSliceColor($SliceID,$Format="") |
|
| 785 | + function setSliceColor($SliceID, $Format = "") |
|
| 786 | 786 | { |
| 787 | 787 | $R = isset($Format["R"]) ? $Format["R"] : 0; |
| 788 | 788 | $G = isset($Format["G"]) ? $Format["G"] : 0; |
| 789 | 789 | $B = isset($Format["B"]) ? $Format["B"] : 0; |
| 790 | - $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100; |
|
| 790 | + $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100; |
|
| 791 | 791 | |
| 792 | 792 | $this->pDataObject->Palette[$SliceID]["R"] = $R; |
| 793 | 793 | $this->pDataObject->Palette[$SliceID]["G"] = $G; |
@@ -796,71 +796,71 @@ discard block |
||
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /* Internally used compute the label positions */ |
| 799 | - function writePieLabel($X,$Y,$Label,$Angle,$Settings,$Stacked,$Xc=0,$Yc=0,$Radius=0,$Reversed=FALSE) |
|
| 799 | + function writePieLabel($X, $Y, $Label, $Angle, $Settings, $Stacked, $Xc = 0, $Yc = 0, $Radius = 0, $Reversed = FALSE) |
|
| 800 | 800 | { |
| 801 | - $LabelOffset = 30; |
|
| 801 | + $LabelOffset = 30; |
|
| 802 | 802 | $FontName = $this->pChartObject->FontName; |
| 803 | 803 | $FontSize = $this->pChartObject->FontSize; |
| 804 | 804 | |
| 805 | - if ( !$Stacked ) |
|
| 805 | + if (!$Stacked) |
|
| 806 | 806 | { |
| 807 | - $Settings["Angle"] = 360-$Angle; |
|
| 807 | + $Settings["Angle"] = 360 - $Angle; |
|
| 808 | 808 | $Settings["Length"] = 25; |
| 809 | 809 | $Settings["Size"] = 8; |
| 810 | 810 | |
| 811 | - $this->pChartObject->drawArrowLabel($X,$Y," ".$Label." ",$Settings); |
|
| 811 | + $this->pChartObject->drawArrowLabel($X, $Y, " ".$Label." ", $Settings); |
|
| 812 | 812 | } |
| 813 | 813 | else |
| 814 | 814 | { |
| 815 | - $X2 = cos(deg2rad($Angle-90))*20+$X; |
|
| 816 | - $Y2 = sin(deg2rad($Angle-90))*20+$Y; |
|
| 815 | + $X2 = cos(deg2rad($Angle - 90))*20 + $X; |
|
| 816 | + $Y2 = sin(deg2rad($Angle - 90))*20 + $Y; |
|
| 817 | 817 | |
| 818 | - $TxtPos = $this->pChartObject->getTextBox($X,$Y,$FontName,$FontSize,0,$Label); |
|
| 818 | + $TxtPos = $this->pChartObject->getTextBox($X, $Y, $FontName, $FontSize, 0, $Label); |
|
| 819 | 819 | $Height = $TxtPos[0]["Y"] - $TxtPos[2]["Y"]; |
| 820 | 820 | $YTop = $Y2 - $Height/2 - 2; |
| 821 | 821 | $YBottom = $Y2 + $Height/2 + 2; |
| 822 | 822 | |
| 823 | - if ( $this->LabelPos != "" ) |
|
| 823 | + if ($this->LabelPos != "") |
|
| 824 | 824 | { |
| 825 | 825 | $Done = FALSE; |
| 826 | - foreach($this->LabelPos as $Key => $Settings) |
|
| 826 | + foreach ($this->LabelPos as $Key => $Settings) |
|
| 827 | 827 | { |
| 828 | - if ( !$Done ) |
|
| 828 | + if (!$Done) |
|
| 829 | 829 | { |
| 830 | - if ( $Angle <= 90 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 831 | - { $this->shift(0,180,-($Height+2),$Reversed); $Done = TRUE; } |
|
| 832 | - if ( $Angle > 90 && $Angle <= 180 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 833 | - { $this->shift(0,180,-($Height+2),$Reversed); $Done = TRUE; } |
|
| 834 | - if ( $Angle > 180 && $Angle <= 270 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 835 | - { $this->shift(180,360,($Height+2),$Reversed); $Done = TRUE; } |
|
| 836 | - if ( $Angle > 270 && $Angle <= 360 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 837 | - { $this->shift(180,360,($Height+2),$Reversed); $Done = TRUE; } |
|
| 830 | + if ($Angle <= 90 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 831 | + { $this->shift(0, 180, -($Height + 2), $Reversed); $Done = TRUE; } |
|
| 832 | + if ($Angle > 90 && $Angle <= 180 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 833 | + { $this->shift(0, 180, -($Height + 2), $Reversed); $Done = TRUE; } |
|
| 834 | + if ($Angle > 180 && $Angle <= 270 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 835 | + { $this->shift(180, 360, ($Height + 2), $Reversed); $Done = TRUE; } |
|
| 836 | + if ($Angle > 270 && $Angle <= 360 && (($YTop >= $Settings["YTop"] && $YTop <= $Settings["YBottom"]) || ($YBottom >= $Settings["YTop"] && $YBottom <= $Settings["YBottom"]))) |
|
| 837 | + { $this->shift(180, 360, ($Height + 2), $Reversed); $Done = TRUE; } |
|
| 838 | 838 | } |
| 839 | 839 | } |
| 840 | 840 | } |
| 841 | 841 | |
| 842 | - $LabelSettings = array("YTop"=>$YTop,"YBottom"=>$YBottom,"Label"=>$Label,"Angle"=>$Angle,"X1"=>$X,"Y1"=>$Y,"X2"=>$X2,"Y2"=>$Y2); |
|
| 843 | - if ( $Angle <= 180 ) { $LabelSettings["X3"] = $Xc+$Radius+$LabelOffset; } |
|
| 844 | - if ( $Angle > 180 ) { $LabelSettings["X3"] = $Xc-$Radius-$LabelOffset; } |
|
| 842 | + $LabelSettings = array("YTop"=>$YTop, "YBottom"=>$YBottom, "Label"=>$Label, "Angle"=>$Angle, "X1"=>$X, "Y1"=>$Y, "X2"=>$X2, "Y2"=>$Y2); |
|
| 843 | + if ($Angle <= 180) { $LabelSettings["X3"] = $Xc + $Radius + $LabelOffset; } |
|
| 844 | + if ($Angle > 180) { $LabelSettings["X3"] = $Xc - $Radius - $LabelOffset; } |
|
| 845 | 845 | $this->LabelPos[] = $LabelSettings; |
| 846 | 846 | } |
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | /* Internally used to shift label positions */ |
| 850 | - function shift($StartAngle,$EndAngle,$Offset,$Reversed) |
|
| 850 | + function shift($StartAngle, $EndAngle, $Offset, $Reversed) |
|
| 851 | 851 | { |
| 852 | - if ( $Reversed ) { $Offset = -$Offset; } |
|
| 853 | - foreach($this->LabelPos as $Key => $Settings) |
|
| 852 | + if ($Reversed) { $Offset = -$Offset; } |
|
| 853 | + foreach ($this->LabelPos as $Key => $Settings) |
|
| 854 | 854 | { |
| 855 | - if ( $Settings["Angle"] > $StartAngle && $Settings["Angle"] <= $EndAngle ) { $this->LabelPos[$Key]["YTop"] = $Settings["YTop"] + $Offset; $this->LabelPos[$Key]["YBottom"] = $Settings["YBottom"] + $Offset; $this->LabelPos[$Key]["Y2"] = $Settings["Y2"] + $Offset; } |
|
| 855 | + if ($Settings["Angle"] > $StartAngle && $Settings["Angle"] <= $EndAngle) { $this->LabelPos[$Key]["YTop"] = $Settings["YTop"] + $Offset; $this->LabelPos[$Key]["YBottom"] = $Settings["YBottom"] + $Offset; $this->LabelPos[$Key]["Y2"] = $Settings["Y2"] + $Offset; } |
|
| 856 | 856 | } |
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | /* Internally used to write the re-computed labels */ |
| 860 | 860 | function writeShiftedLabels() |
| 861 | 861 | { |
| 862 | - if ( $this->LabelPos == "" ) { return(0); } |
|
| 863 | - foreach($this->LabelPos as $Key => $Settings) |
|
| 862 | + if ($this->LabelPos == "") { return(0); } |
|
| 863 | + foreach ($this->LabelPos as $Key => $Settings) |
|
| 864 | 864 | { |
| 865 | 865 | $X1 = $Settings["X1"]; $Y1 = $Settings["Y1"]; |
| 866 | 866 | $X2 = $Settings["X2"]; $Y2 = $Settings["Y2"]; |
@@ -868,72 +868,72 @@ discard block |
||
| 868 | 868 | $Angle = $Settings["Angle"]; |
| 869 | 869 | $Label = $Settings["Label"]; |
| 870 | 870 | |
| 871 | - $this->pChartObject->drawArrow($X2,$Y2,$X1,$Y1,array("Size"=>8)); |
|
| 872 | - if ( $Angle <= 180 ) |
|
| 871 | + $this->pChartObject->drawArrow($X2, $Y2, $X1, $Y1, array("Size"=>8)); |
|
| 872 | + if ($Angle <= 180) |
|
| 873 | 873 | { |
| 874 | - $this->pChartObject->drawLine($X2,$Y2,$X3,$Y2); |
|
| 875 | - $this->pChartObject->drawText($X3+2,$Y2,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT)); |
|
| 874 | + $this->pChartObject->drawLine($X2, $Y2, $X3, $Y2); |
|
| 875 | + $this->pChartObject->drawText($X3 + 2, $Y2, $Label, array("Align"=>TEXT_ALIGN_MIDDLELEFT)); |
|
| 876 | 876 | } |
| 877 | 877 | else |
| 878 | 878 | { |
| 879 | - $this->pChartObject->drawLine($X2,$Y2,$X3,$Y2); |
|
| 880 | - $this->pChartObject->drawText($X3-2,$Y2,$Label,array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); |
|
| 879 | + $this->pChartObject->drawLine($X2, $Y2, $X3, $Y2); |
|
| 880 | + $this->pChartObject->drawText($X3 - 2, $Y2, $Label, array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); |
|
| 881 | 881 | } |
| 882 | 882 | } |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | /* Draw a ring chart */ |
| 886 | - function draw2DRing($X,$Y,$Format="") |
|
| 886 | + function draw2DRing($X, $Y, $Format = "") |
|
| 887 | 887 | { |
| 888 | 888 | $OuterRadius = isset($Format["Radius"]) ? $Format["Radius"] : 60; |
| 889 | - $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; |
|
| 889 | + $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; |
|
| 890 | 890 | $InnerRadius = isset($Format["Radius"]) ? $Format["Radius"] : 30; |
| 891 | - $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
|
| 891 | + $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
|
| 892 | 892 | $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255; |
| 893 | 893 | $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255; |
| 894 | 894 | $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255; |
| 895 | - $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 100; |
|
| 896 | - $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
|
| 895 | + $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 100; |
|
| 896 | + $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
|
| 897 | 897 | $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE; |
| 898 | - $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 898 | + $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 899 | 899 | $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL; |
| 900 | 900 | $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0; |
| 901 | 901 | $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0; |
| 902 | 902 | $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0; |
| 903 | - $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 903 | + $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 904 | 904 | $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : NULL; //PIE_VALUE_PERCENTAGE |
| 905 | - $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 5; |
|
| 906 | - $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE; |
|
| 905 | + $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 5; |
|
| 906 | + $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE; |
|
| 907 | 907 | $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : ""; |
| 908 | 908 | $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255; |
| 909 | 909 | $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255; |
| 910 | 910 | $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255; |
| 911 | - $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 912 | - $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 911 | + $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 912 | + $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 913 | 913 | |
| 914 | 914 | /* Data Processing */ |
| 915 | 915 | $Data = $this->pDataObject->getData(); |
| 916 | 916 | $Palette = $this->pDataObject->getPalette(); |
| 917 | 917 | |
| 918 | 918 | /* Do we have an abscissa serie defined? */ |
| 919 | - if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 919 | + if ($Data["Abscissa"] == "") { return(PIE_NO_ABSCISSA); } |
|
| 920 | 920 | |
| 921 | 921 | /* Try to find the data serie */ |
| 922 | 922 | $DataSerie = ""; |
| 923 | 923 | foreach ($Data["Series"] as $SerieName => $SerieData) |
| 924 | - { if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 924 | + { if ($SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 925 | 925 | |
| 926 | 926 | /* Do we have data to compute? */ |
| 927 | - if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); } |
|
| 927 | + if ($DataSerie == "") { return(PIE_NO_DATASERIE); } |
|
| 928 | 928 | |
| 929 | 929 | /* Remove unused data */ |
| 930 | - list($Data,$Palette) = $this->clean0Values($Data,$Palette,$DataSerie,$Data["Abscissa"]); |
|
| 930 | + list($Data, $Palette) = $this->clean0Values($Data, $Palette, $DataSerie, $Data["Abscissa"]); |
|
| 931 | 931 | |
| 932 | 932 | /* Compute the pie sum */ |
| 933 | 933 | $SerieSum = $this->pDataObject->getSum($DataSerie); |
| 934 | 934 | |
| 935 | 935 | /* Do we have data to draw? */ |
| 936 | - if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); } |
|
| 936 | + if ($SerieSum == 0) { return(PIE_SUMISNULL); } |
|
| 937 | 937 | |
| 938 | 938 | /* Dump the real number of data to draw */ |
| 939 | 939 | $Values = ""; |
@@ -941,146 +941,146 @@ discard block |
||
| 941 | 941 | { if ($Value != 0) { $Values[] = $Value; } } |
| 942 | 942 | |
| 943 | 943 | /* Compute the wasted angular space between series */ |
| 944 | - if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = 0; } // count($Values) |
|
| 944 | + if (count($Values) == 1) { $WastedAngular = 0; } else { $WastedAngular = 0; } // count($Values) |
|
| 945 | 945 | |
| 946 | 946 | /* Compute the scale */ |
| 947 | - $ScaleFactor = (360 - $WastedAngular) / $SerieSum; |
|
| 947 | + $ScaleFactor = (360 - $WastedAngular)/$SerieSum; |
|
| 948 | 948 | |
| 949 | 949 | $RestoreShadow = $this->pChartObject->Shadow; |
| 950 | - if ( $this->pChartObject->Shadow ) |
|
| 950 | + if ($this->pChartObject->Shadow) |
|
| 951 | 951 | { |
| 952 | 952 | $this->pChartObject->Shadow = FALSE; |
| 953 | 953 | |
| 954 | 954 | $ShadowFormat = $Format; $ShadowFormat["Shadow"] = TRUE; |
| 955 | - $this->draw2DRing($X+$this->pChartObject->ShadowX,$Y+$this->pChartObject->ShadowY,$ShadowFormat); |
|
| 955 | + $this->draw2DRing($X + $this->pChartObject->ShadowX, $Y + $this->pChartObject->ShadowY, $ShadowFormat); |
|
| 956 | 956 | } |
| 957 | 957 | |
| 958 | 958 | /* Draw the polygon pie elements */ |
| 959 | - $Step = 360 / (2 * PI * $OuterRadius); |
|
| 959 | + $Step = 360/(2*PI*$OuterRadius); |
|
| 960 | 960 | $Offset = 0; $ID = 0; |
| 961 | - foreach($Values as $Key => $Value) |
|
| 961 | + foreach ($Values as $Key => $Value) |
|
| 962 | 962 | { |
| 963 | - if ( $Shadow ) |
|
| 963 | + if ($Shadow) |
|
| 964 | 964 | { |
| 965 | - $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 965 | + $Settings = array("R"=>$this->pChartObject->ShadowR, "G"=>$this->pChartObject->ShadowG, "B"=>$this->pChartObject->ShadowB, "Alpha"=>$this->pChartObject->Shadowa); |
|
| 966 | 966 | $BorderColor = $Settings; |
| 967 | 967 | } |
| 968 | 968 | else |
| 969 | 969 | { |
| 970 | - if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
|
| 971 | - $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 970 | + if (!isset($Palette[$ID]["R"])) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID, $Color); } |
|
| 971 | + $Settings = array("R"=>$Palette[$ID]["R"], "G"=>$Palette[$ID]["G"], "B"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 972 | 972 | |
| 973 | - if ( $Border ) |
|
| 974 | - $BorderColor = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha); |
|
| 973 | + if ($Border) |
|
| 974 | + $BorderColor = array("R"=>$BorderR, "G"=>$BorderG, "B"=>$BorderB, "Alpha"=>$BorderAlpha); |
|
| 975 | 975 | else |
| 976 | 976 | $BorderColor = $Settings; |
| 977 | 977 | } |
| 978 | 978 | |
| 979 | 979 | $Plots = ""; $Boundaries = ""; $AAPixels = ""; |
| 980 | - $EndAngle = $Offset+($Value*$ScaleFactor); if ( $EndAngle > 360 ) { $EndAngle = 360; } |
|
| 981 | - for($i=$Offset;$i<=$EndAngle;$i=$i+$Step) |
|
| 980 | + $EndAngle = $Offset + ($Value*$ScaleFactor); if ($EndAngle > 360) { $EndAngle = 360; } |
|
| 981 | + for ($i = $Offset; $i <= $EndAngle; $i = $i + $Step) |
|
| 982 | 982 | { |
| 983 | - $Xc = cos(($i-90)*PI/180) * $OuterRadius + $X; |
|
| 984 | - $Yc = sin(($i-90)*PI/180) * $OuterRadius + $Y; |
|
| 983 | + $Xc = cos(($i - 90)*PI/180)*$OuterRadius + $X; |
|
| 984 | + $Yc = sin(($i - 90)*PI/180)*$OuterRadius + $Y; |
|
| 985 | 985 | |
| 986 | - if ( !isset($Boundaries[0]["X1"]) ) { $Boundaries[0]["X1"] = $Xc; $Boundaries[0]["Y1"] = $Yc; } |
|
| 987 | - $AAPixels[] = array($Xc,$Yc); |
|
| 986 | + if (!isset($Boundaries[0]["X1"])) { $Boundaries[0]["X1"] = $Xc; $Boundaries[0]["Y1"] = $Yc; } |
|
| 987 | + $AAPixels[] = array($Xc, $Yc); |
|
| 988 | 988 | |
| 989 | - if ( $i<90 ) { $Yc++; } |
|
| 990 | - if ( $i>180 && $i<270 ) { $Xc++; } |
|
| 991 | - if ( $i>=270 ) { $Xc++; $Yc++; } |
|
| 989 | + if ($i < 90) { $Yc++; } |
|
| 990 | + if ($i > 180 && $i < 270) { $Xc++; } |
|
| 991 | + if ($i >= 270) { $Xc++; $Yc++; } |
|
| 992 | 992 | |
| 993 | 993 | $Plots[] = $Xc; $Plots[] = $Yc; |
| 994 | 994 | } |
| 995 | 995 | $Boundaries[1]["X1"] = $Xc; $Boundaries[1]["Y1"] = $Yc; |
| 996 | 996 | $Lasti = $EndAngle; |
| 997 | 997 | |
| 998 | - for($i=$EndAngle;$i>=$Offset;$i=$i-$Step) |
|
| 998 | + for ($i = $EndAngle; $i >= $Offset; $i = $i - $Step) |
|
| 999 | 999 | { |
| 1000 | - $Xc = cos(($i-90)*PI/180) * ($InnerRadius-1) + $X; |
|
| 1001 | - $Yc = sin(($i-90)*PI/180) * ($InnerRadius-1) + $Y; |
|
| 1000 | + $Xc = cos(($i - 90)*PI/180)*($InnerRadius - 1) + $X; |
|
| 1001 | + $Yc = sin(($i - 90)*PI/180)*($InnerRadius - 1) + $Y; |
|
| 1002 | 1002 | |
| 1003 | - if ( !isset($Boundaries[1]["X2"]) ) { $Boundaries[1]["X2"] = $Xc; $Boundaries[1]["Y2"] = $Yc; } |
|
| 1004 | - $AAPixels[] = array($Xc,$Yc); |
|
| 1003 | + if (!isset($Boundaries[1]["X2"])) { $Boundaries[1]["X2"] = $Xc; $Boundaries[1]["Y2"] = $Yc; } |
|
| 1004 | + $AAPixels[] = array($Xc, $Yc); |
|
| 1005 | 1005 | |
| 1006 | - $Xc = cos(($i-90)*PI/180) * $InnerRadius + $X; |
|
| 1007 | - $Yc = sin(($i-90)*PI/180) * $InnerRadius + $Y; |
|
| 1006 | + $Xc = cos(($i - 90)*PI/180)*$InnerRadius + $X; |
|
| 1007 | + $Yc = sin(($i - 90)*PI/180)*$InnerRadius + $Y; |
|
| 1008 | 1008 | |
| 1009 | - if ( $i<90 ) { $Yc++; } |
|
| 1010 | - if ( $i>180 && $i<270 ) { $Xc++; } |
|
| 1011 | - if ( $i>=270 ) { $Xc++; $Yc++; } |
|
| 1009 | + if ($i < 90) { $Yc++; } |
|
| 1010 | + if ($i > 180 && $i < 270) { $Xc++; } |
|
| 1011 | + if ($i >= 270) { $Xc++; $Yc++; } |
|
| 1012 | 1012 | |
| 1013 | 1013 | $Plots[] = $Xc; $Plots[] = $Yc; |
| 1014 | 1014 | } |
| 1015 | 1015 | $Boundaries[0]["X2"] = $Xc; $Boundaries[0]["Y2"] = $Yc; |
| 1016 | 1016 | |
| 1017 | 1017 | /* Draw the polygon */ |
| 1018 | - $this->pChartObject->drawPolygon($Plots,$Settings); |
|
| 1019 | - if ( $RecordImageMap && !$Shadow ) { $this->pChartObject->addToImageMap("POLY",$this->arraySerialize($Plots),$this->pChartObject->toHTMLColor($Palette[$ID]["R"],$Palette[$ID]["G"],$Palette[$ID]["B"]),$Data["Series"][$Data["Abscissa"]]["Data"][$Key],$Value); } |
|
| 1018 | + $this->pChartObject->drawPolygon($Plots, $Settings); |
|
| 1019 | + if ($RecordImageMap && !$Shadow) { $this->pChartObject->addToImageMap("POLY", $this->arraySerialize($Plots), $this->pChartObject->toHTMLColor($Palette[$ID]["R"], $Palette[$ID]["G"], $Palette[$ID]["B"]), $Data["Series"][$Data["Abscissa"]]["Data"][$Key], $Value); } |
|
| 1020 | 1020 | |
| 1021 | 1021 | /* Smooth the edges using AA */ |
| 1022 | - foreach($AAPixels as $iKey => $Pos ) { $this->pChartObject->drawAntialiasPixel($Pos[0],$Pos[1],$BorderColor); } |
|
| 1023 | - $this->pChartObject->drawLine($Boundaries[0]["X1"],$Boundaries[0]["Y1"],$Boundaries[0]["X2"],$Boundaries[0]["Y2"],$BorderColor); |
|
| 1024 | - $this->pChartObject->drawLine($Boundaries[1]["X1"],$Boundaries[1]["Y1"],$Boundaries[1]["X2"],$Boundaries[1]["Y2"],$BorderColor); |
|
| 1022 | + foreach ($AAPixels as $iKey => $Pos) { $this->pChartObject->drawAntialiasPixel($Pos[0], $Pos[1], $BorderColor); } |
|
| 1023 | + $this->pChartObject->drawLine($Boundaries[0]["X1"], $Boundaries[0]["Y1"], $Boundaries[0]["X2"], $Boundaries[0]["Y2"], $BorderColor); |
|
| 1024 | + $this->pChartObject->drawLine($Boundaries[1]["X1"], $Boundaries[1]["Y1"], $Boundaries[1]["X2"], $Boundaries[1]["Y2"], $BorderColor); |
|
| 1025 | 1025 | |
| 1026 | - if ( $DrawLabels && !$Shadow ) |
|
| 1026 | + if ($DrawLabels && !$Shadow) |
|
| 1027 | 1027 | { |
| 1028 | - if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 1029 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 1028 | + if ($LabelColor == PIE_LABEL_COLOR_AUTO) |
|
| 1029 | + { $Settings = array("FillR"=>$Palette[$ID]["R"], "FillG"=>$Palette[$ID]["G"], "FillB"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"]); } |
|
| 1030 | 1030 | else |
| 1031 | - { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
|
| 1031 | + { $Settings = array("FillR"=>$LabelR, "FillG"=>$LabelG, "FillB"=>$LabelB, "Alpha"=>$LabelAlpha); } |
|
| 1032 | 1032 | |
| 1033 | 1033 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 1034 | - $Xc = cos(($Angle-90)*PI/180) * $OuterRadius + $X; |
|
| 1035 | - $Yc = sin(($Angle-90)*PI/180) * $OuterRadius + $Y; |
|
| 1034 | + $Xc = cos(($Angle - 90)*PI/180)*$OuterRadius + $X; |
|
| 1035 | + $Yc = sin(($Angle - 90)*PI/180)*$OuterRadius + $Y; |
|
| 1036 | 1036 | |
| 1037 | 1037 | $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
| 1038 | 1038 | |
| 1039 | - if ( $LabelStacked ) |
|
| 1040 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$OuterRadius); |
|
| 1039 | + if ($LabelStacked) |
|
| 1040 | + $this->writePieLabel($Xc, $Yc, $Label, $Angle, $Settings, TRUE, $X, $Y, $OuterRadius); |
|
| 1041 | 1041 | else |
| 1042 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 1042 | + $this->writePieLabel($Xc, $Yc, $Label, $Angle, $Settings, FALSE); |
|
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | 1045 | $Offset = $Lasti; $ID++; |
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | - if ( $DrawLabels && $LabelStacked ) { $this->writeShiftedLabels(); } |
|
| 1048 | + if ($DrawLabels && $LabelStacked) { $this->writeShiftedLabels(); } |
|
| 1049 | 1049 | |
| 1050 | - if ( $WriteValues && !$Shadow ) |
|
| 1050 | + if ($WriteValues && !$Shadow) |
|
| 1051 | 1051 | { |
| 1052 | - $Step = 360 / (2 * PI * $OuterRadius); |
|
| 1052 | + $Step = 360/(2*PI*$OuterRadius); |
|
| 1053 | 1053 | $Offset = 0; |
| 1054 | - foreach($Values as $Key => $Value) |
|
| 1054 | + foreach ($Values as $Key => $Value) |
|
| 1055 | 1055 | { |
| 1056 | - $EndAngle = $Offset+($Value*$ScaleFactor); |
|
| 1057 | - if ( $EndAngle > 360 ) { $EndAngle = 360; } |
|
| 1056 | + $EndAngle = $Offset + ($Value*$ScaleFactor); |
|
| 1057 | + if ($EndAngle > 360) { $EndAngle = 360; } |
|
| 1058 | 1058 | |
| 1059 | - $Angle = $Offset+($Value*$ScaleFactor)/2; |
|
| 1060 | - if ( $ValuePosition == PIE_VALUE_OUTSIDE ) |
|
| 1059 | + $Angle = $Offset + ($Value*$ScaleFactor)/2; |
|
| 1060 | + if ($ValuePosition == PIE_VALUE_OUTSIDE) |
|
| 1061 | 1061 | { |
| 1062 | - $Xc = cos(($Angle-90)*PI/180) * ($OuterRadius+$ValuePadding) + $X; |
|
| 1063 | - $Yc = sin(($Angle-90)*PI/180) * ($OuterRadius+$ValuePadding) + $Y; |
|
| 1064 | - if ( $Angle >=0 && $Angle <= 90 ) { $Align = TEXT_ALIGN_BOTTOMLEFT; } |
|
| 1065 | - if ( $Angle > 90 && $Angle <= 180 ) { $Align = TEXT_ALIGN_TOPLEFT; } |
|
| 1066 | - if ( $Angle > 180 && $Angle <= 270 ) { $Align = TEXT_ALIGN_TOPRIGHT; } |
|
| 1067 | - if ( $Angle > 270 ) { $Align = TEXT_ALIGN_BOTTOMRIGHT; } |
|
| 1062 | + $Xc = cos(($Angle - 90)*PI/180)*($OuterRadius + $ValuePadding) + $X; |
|
| 1063 | + $Yc = sin(($Angle - 90)*PI/180)*($OuterRadius + $ValuePadding) + $Y; |
|
| 1064 | + if ($Angle >= 0 && $Angle <= 90) { $Align = TEXT_ALIGN_BOTTOMLEFT; } |
|
| 1065 | + if ($Angle > 90 && $Angle <= 180) { $Align = TEXT_ALIGN_TOPLEFT; } |
|
| 1066 | + if ($Angle > 180 && $Angle <= 270) { $Align = TEXT_ALIGN_TOPRIGHT; } |
|
| 1067 | + if ($Angle > 270) { $Align = TEXT_ALIGN_BOTTOMRIGHT; } |
|
| 1068 | 1068 | } |
| 1069 | 1069 | else |
| 1070 | 1070 | { |
| 1071 | - $Xc = cos(($Angle-90)*PI/180) * (($OuterRadius-$InnerRadius)/2+$InnerRadius) + $X; |
|
| 1072 | - $Yc = sin(($Angle-90)*PI/180) * (($OuterRadius-$InnerRadius)/2+$InnerRadius) + $Y; |
|
| 1071 | + $Xc = cos(($Angle - 90)*PI/180)*(($OuterRadius - $InnerRadius)/2 + $InnerRadius) + $X; |
|
| 1072 | + $Yc = sin(($Angle - 90)*PI/180)*(($OuterRadius - $InnerRadius)/2 + $InnerRadius) + $Y; |
|
| 1073 | 1073 | $Align = TEXT_ALIGN_MIDDLEMIDDLE; |
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | - if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 1077 | - $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 1078 | - elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 1076 | + if ($WriteValues == PIE_VALUE_PERCENTAGE) |
|
| 1077 | + $Display = round((100/$SerieSum)*$Value, $Precision)."%"; |
|
| 1078 | + elseif ($WriteValues == PIE_VALUE_NATURAL) |
|
| 1079 | 1079 | $Display = $Value.$ValueSuffix; |
| 1080 | 1080 | else |
| 1081 | 1081 | $Label = ""; |
| 1082 | 1082 | |
| 1083 | - $this->pChartObject->drawText($Xc,$Yc,$Display,array("Align"=>$Align,"R"=>$ValueR,"G"=>$ValueG,"B"=>$ValueB)); |
|
| 1083 | + $this->pChartObject->drawText($Xc, $Yc, $Display, array("Align"=>$Align, "R"=>$ValueR, "G"=>$ValueG, "B"=>$ValueB)); |
|
| 1084 | 1084 | $Offset = $EndAngle; |
| 1085 | 1085 | } |
| 1086 | 1086 | } |
@@ -1091,61 +1091,61 @@ discard block |
||
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | /* Draw a 3D ring chart */ |
| 1094 | - function draw3DRing($X,$Y,$Format="") |
|
| 1094 | + function draw3DRing($X, $Y, $Format = "") |
|
| 1095 | 1095 | { |
| 1096 | 1096 | $OuterRadius = isset($Format["OuterRadius"]) ? $Format["OuterRadius"] : 100; |
| 1097 | 1097 | $Precision = isset($Format["Precision"]) ? $Format["Precision"] : 0; |
| 1098 | 1098 | $InnerRadius = isset($Format["InnerRadius"]) ? $Format["InnerRadius"] : 30; |
| 1099 | 1099 | $SkewFactor = isset($Format["SkewFactor"]) ? $Format["SkewFactor"] : .6; |
| 1100 | 1100 | $SliceHeight = isset($Format["SliceHeight"]) ? $Format["SliceHeight"] : 10; |
| 1101 | - $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 10; |
|
| 1102 | - $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 10; |
|
| 1101 | + $DataGapAngle = isset($Format["DataGapAngle"]) ? $Format["DataGapAngle"] : 10; |
|
| 1102 | + $DataGapRadius = isset($Format["DataGapRadius"]) ? $Format["DataGapRadius"] : 10; |
|
| 1103 | 1103 | $Border = isset($Format["Border"]) ? $Format["Border"] : FALSE; |
| 1104 | 1104 | $Shadow = isset($Format["Shadow"]) ? $Format["Shadow"] : FALSE; |
| 1105 | 1105 | $DrawLabels = isset($Format["DrawLabels"]) ? $Format["DrawLabels"] : FALSE; |
| 1106 | - $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 1106 | + $LabelStacked = isset($Format["LabelStacked"]) ? $Format["LabelStacked"] : FALSE; |
|
| 1107 | 1107 | $LabelColor = isset($Format["LabelColor"]) ? $Format["LabelColor"] : PIE_LABEL_COLOR_MANUAL; |
| 1108 | 1108 | $LabelR = isset($Format["LabelR"]) ? $Format["LabelR"] : 0; |
| 1109 | 1109 | $LabelG = isset($Format["LabelG"]) ? $Format["LabelG"] : 0; |
| 1110 | 1110 | $LabelB = isset($Format["LabelB"]) ? $Format["LabelB"] : 0; |
| 1111 | - $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 1112 | - $Cf = isset($Format["Cf"]) ? $Format["Cf"] : 20; |
|
| 1111 | + $LabelAlpha = isset($Format["LabelAlpha"]) ? $Format["LabelAlpha"] : 100; |
|
| 1112 | + $Cf = isset($Format["Cf"]) ? $Format["Cf"] : 20; |
|
| 1113 | 1113 | $WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : PIE_VALUE_NATURAL; |
| 1114 | - $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : $SliceHeight + 15; |
|
| 1115 | - $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE; |
|
| 1114 | + $ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : $SliceHeight + 15; |
|
| 1115 | + $ValuePosition = isset($Format["ValuePosition"]) ? $Format["ValuePosition"] : PIE_VALUE_OUTSIDE; |
|
| 1116 | 1116 | $ValueSuffix = isset($Format["ValueSuffix"]) ? $Format["ValueSuffix"] : ""; |
| 1117 | 1117 | $ValueR = isset($Format["ValueR"]) ? $Format["ValueR"] : 255; |
| 1118 | 1118 | $ValueG = isset($Format["ValueG"]) ? $Format["ValueG"] : 255; |
| 1119 | 1119 | $ValueB = isset($Format["ValueB"]) ? $Format["ValueB"] : 255; |
| 1120 | - $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 1121 | - $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 1120 | + $ValueAlpha = isset($Format["ValueAlpha"]) ? $Format["ValueAlpha"] : 100; |
|
| 1121 | + $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE; |
|
| 1122 | 1122 | |
| 1123 | 1123 | /* Error correction for overlaying rounded corners */ |
| 1124 | - if ( $SkewFactor < .5 ) { $SkewFactor = .5; } |
|
| 1124 | + if ($SkewFactor < .5) { $SkewFactor = .5; } |
|
| 1125 | 1125 | |
| 1126 | 1126 | /* Data Processing */ |
| 1127 | 1127 | $Data = $this->pDataObject->getData(); |
| 1128 | 1128 | $Palette = $this->pDataObject->getPalette(); |
| 1129 | 1129 | |
| 1130 | 1130 | /* Do we have an abscissa serie defined? */ |
| 1131 | - if ( $Data["Abscissa"] == "" ) { return(PIE_NO_ABSCISSA); } |
|
| 1131 | + if ($Data["Abscissa"] == "") { return(PIE_NO_ABSCISSA); } |
|
| 1132 | 1132 | |
| 1133 | 1133 | /* Try to find the data serie */ |
| 1134 | 1134 | $DataSerie = ""; |
| 1135 | 1135 | foreach ($Data["Series"] as $SerieName => $SerieData) |
| 1136 | - { if ( $SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 1136 | + { if ($SerieName != $Data["Abscissa"]) { $DataSerie = $SerieName; } } |
|
| 1137 | 1137 | |
| 1138 | 1138 | /* Do we have data to compute? */ |
| 1139 | - if ( $DataSerie == "" ) { return(PIE_NO_DATASERIE); } |
|
| 1139 | + if ($DataSerie == "") { return(PIE_NO_DATASERIE); } |
|
| 1140 | 1140 | |
| 1141 | 1141 | /* Remove unused data */ |
| 1142 | - list($Data,$Palette) = $this->clean0Values($Data,$Palette,$DataSerie,$Data["Abscissa"]); |
|
| 1142 | + list($Data, $Palette) = $this->clean0Values($Data, $Palette, $DataSerie, $Data["Abscissa"]); |
|
| 1143 | 1143 | |
| 1144 | 1144 | /* Compute the pie sum */ |
| 1145 | 1145 | $SerieSum = $this->pDataObject->getSum($DataSerie); |
| 1146 | 1146 | |
| 1147 | 1147 | /* Do we have data to draw? */ |
| 1148 | - if ( $SerieSum == 0 ) { return(PIE_SUMISNULL); } |
|
| 1148 | + if ($SerieSum == 0) { return(PIE_SUMISNULL); } |
|
| 1149 | 1149 | |
| 1150 | 1150 | /* Dump the real number of data to draw */ |
| 1151 | 1151 | $Values = ""; |
@@ -1153,56 +1153,56 @@ discard block |
||
| 1153 | 1153 | { if ($Value != 0) { $Values[] = $Value; } } |
| 1154 | 1154 | |
| 1155 | 1155 | /* Compute the wasted angular space between series */ |
| 1156 | - if (count($Values)==1) { $WastedAngular = 0; } else { $WastedAngular = count($Values) * $DataGapAngle; } |
|
| 1156 | + if (count($Values) == 1) { $WastedAngular = 0; } else { $WastedAngular = count($Values)*$DataGapAngle; } |
|
| 1157 | 1157 | |
| 1158 | 1158 | /* Compute the scale */ |
| 1159 | - $ScaleFactor = (360 - $WastedAngular) / $SerieSum; |
|
| 1159 | + $ScaleFactor = (360 - $WastedAngular)/$SerieSum; |
|
| 1160 | 1160 | |
| 1161 | 1161 | $RestoreShadow = $this->pChartObject->Shadow; |
| 1162 | - if ( $this->pChartObject->Shadow ) { $this->pChartObject->Shadow = FALSE; } |
|
| 1162 | + if ($this->pChartObject->Shadow) { $this->pChartObject->Shadow = FALSE; } |
|
| 1163 | 1163 | |
| 1164 | 1164 | /* Draw the polygon ring elements */ |
| 1165 | - $Offset = 360; $ID = count($Values)-1; |
|
| 1165 | + $Offset = 360; $ID = count($Values) - 1; |
|
| 1166 | 1166 | $Values = array_reverse($Values); |
| 1167 | 1167 | $Slice = 0; $Slices = ""; $SliceColors = ""; $Visible = ""; $SliceAngle = ""; |
| 1168 | - foreach($Values as $Key => $Value) |
|
| 1168 | + foreach ($Values as $Key => $Value) |
|
| 1169 | 1169 | { |
| 1170 | - if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
|
| 1171 | - $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 1170 | + if (!isset($Palette[$ID]["R"])) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID, $Color); } |
|
| 1171 | + $Settings = array("R"=>$Palette[$ID]["R"], "G"=>$Palette[$ID]["G"], "B"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 1172 | 1172 | |
| 1173 | 1173 | $SliceColors[$Slice] = $Settings; |
| 1174 | 1174 | |
| 1175 | 1175 | $StartAngle = $Offset; |
| 1176 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 1176 | + $EndAngle = $Offset - ($Value*$ScaleFactor); if ($EndAngle < 0) { $EndAngle = 0; } |
|
| 1177 | 1177 | |
| 1178 | - if ( $StartAngle > 180 ) { $Visible[$Slice]["Start"] = TRUE; } else { $Visible[$Slice]["Start"] = TRUE; } |
|
| 1179 | - if ( $EndAngle < 180 ) { $Visible[$Slice]["End"] = FALSE; } else { $Visible[$Slice]["End"] = TRUE; } |
|
| 1178 | + if ($StartAngle > 180) { $Visible[$Slice]["Start"] = TRUE; } else { $Visible[$Slice]["Start"] = TRUE; } |
|
| 1179 | + if ($EndAngle < 180) { $Visible[$Slice]["End"] = FALSE; } else { $Visible[$Slice]["End"] = TRUE; } |
|
| 1180 | 1180 | |
| 1181 | - $Step = (360 / (2 * PI * $OuterRadius))/2; |
|
| 1181 | + $Step = (360/(2*PI*$OuterRadius))/2; |
|
| 1182 | 1182 | $OutX1 = VOID; $OutY1 = VOID; |
| 1183 | - for($i=$Offset;$i>=$EndAngle;$i=$i-$Step) |
|
| 1183 | + for ($i = $Offset; $i >= $EndAngle; $i = $i - $Step) |
|
| 1184 | 1184 | { |
| 1185 | - $Xc = cos(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius-2) + $X; |
|
| 1186 | - $Yc = sin(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius-2)*$SkewFactor + $Y; |
|
| 1187 | - $Slices[$Slice]["AA"][] = array($Xc,$Yc); |
|
| 1185 | + $Xc = cos(($i - 90)*PI/180)*($OuterRadius + $DataGapRadius - 2) + $X; |
|
| 1186 | + $Yc = sin(($i - 90)*PI/180)*($OuterRadius + $DataGapRadius - 2)*$SkewFactor + $Y; |
|
| 1187 | + $Slices[$Slice]["AA"][] = array($Xc, $Yc); |
|
| 1188 | 1188 | |
| 1189 | - $Xc = cos(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius-1) + $X; |
|
| 1190 | - $Yc = sin(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius-1)*$SkewFactor + $Y; |
|
| 1191 | - $Slices[$Slice]["AA"][] = array($Xc,$Yc); |
|
| 1189 | + $Xc = cos(($i - 90)*PI/180)*($OuterRadius + $DataGapRadius - 1) + $X; |
|
| 1190 | + $Yc = sin(($i - 90)*PI/180)*($OuterRadius + $DataGapRadius - 1)*$SkewFactor + $Y; |
|
| 1191 | + $Slices[$Slice]["AA"][] = array($Xc, $Yc); |
|
| 1192 | 1192 | |
| 1193 | - $Xc = cos(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius) + $X; |
|
| 1194 | - $Yc = sin(($i-90)*PI/180) * ($OuterRadius+$DataGapRadius)*$SkewFactor + $Y; |
|
| 1195 | - $this->pChartObject->drawAntialiasPixel($Xc,$Yc,$Settings); |
|
| 1193 | + $Xc = cos(($i - 90)*PI/180)*($OuterRadius + $DataGapRadius) + $X; |
|
| 1194 | + $Yc = sin(($i - 90)*PI/180)*($OuterRadius + $DataGapRadius)*$SkewFactor + $Y; |
|
| 1195 | + $this->pChartObject->drawAntialiasPixel($Xc, $Yc, $Settings); |
|
| 1196 | 1196 | |
| 1197 | - if ( $OutX1 == VOID ) { $OutX1 = $Xc; $OutY1 = $Yc; } |
|
| 1197 | + if ($OutX1 == VOID) { $OutX1 = $Xc; $OutY1 = $Yc; } |
|
| 1198 | 1198 | |
| 1199 | - if ( $i<90 ) { $Yc++; } |
|
| 1200 | - if ( $i>90 && $i<180 ) { $Xc++; } |
|
| 1201 | - if ( $i>180 && $i<270 ) { $Xc++; } |
|
| 1202 | - if ( $i>=270 ) { $Xc++; $Yc++; } |
|
| 1199 | + if ($i < 90) { $Yc++; } |
|
| 1200 | + if ($i > 90 && $i < 180) { $Xc++; } |
|
| 1201 | + if ($i > 180 && $i < 270) { $Xc++; } |
|
| 1202 | + if ($i >= 270) { $Xc++; $Yc++; } |
|
| 1203 | 1203 | |
| 1204 | 1204 | $Slices[$Slice]["BottomPoly"][] = floor($Xc); $Slices[$Slice]["BottomPoly"][] = floor($Yc); |
| 1205 | - $Slices[$Slice]["TopPoly"][] = floor($Xc); $Slices[$Slice]["TopPoly"][] = floor($Yc)-$SliceHeight; |
|
| 1205 | + $Slices[$Slice]["TopPoly"][] = floor($Xc); $Slices[$Slice]["TopPoly"][] = floor($Yc) - $SliceHeight; |
|
| 1206 | 1206 | $Slices[$Slice]["Angle"][] = $i; |
| 1207 | 1207 | } |
| 1208 | 1208 | $OutX2 = $Xc; $OutY2 = $Yc; |
@@ -1210,33 +1210,33 @@ discard block |
||
| 1210 | 1210 | $Slices[$Slice]["Angle"][] = VOID; |
| 1211 | 1211 | $Lasti = $i; |
| 1212 | 1212 | |
| 1213 | - $Step = (360 / (2 * PI * $InnerRadius))/2; |
|
| 1213 | + $Step = (360/(2*PI*$InnerRadius))/2; |
|
| 1214 | 1214 | $InX1 = VOID; $InY1 = VOID; |
| 1215 | - for($i=$EndAngle;$i<=$Offset;$i=$i+$Step) |
|
| 1215 | + for ($i = $EndAngle; $i <= $Offset; $i = $i + $Step) |
|
| 1216 | 1216 | { |
| 1217 | - $Xc = cos(($i-90)*PI/180) * ($InnerRadius+$DataGapRadius-1) + $X; |
|
| 1218 | - $Yc = sin(($i-90)*PI/180) * ($InnerRadius+$DataGapRadius-1)*$SkewFactor + $Y; |
|
| 1219 | - $Slices[$Slice]["AA"][] = array($Xc,$Yc); |
|
| 1217 | + $Xc = cos(($i - 90)*PI/180)*($InnerRadius + $DataGapRadius - 1) + $X; |
|
| 1218 | + $Yc = sin(($i - 90)*PI/180)*($InnerRadius + $DataGapRadius - 1)*$SkewFactor + $Y; |
|
| 1219 | + $Slices[$Slice]["AA"][] = array($Xc, $Yc); |
|
| 1220 | 1220 | |
| 1221 | - $Xc = cos(($i-90)*PI/180) * ($InnerRadius+$DataGapRadius) + $X; |
|
| 1222 | - $Yc = sin(($i-90)*PI/180) * ($InnerRadius+$DataGapRadius)*$SkewFactor + $Y; |
|
| 1223 | - $Slices[$Slice]["AA"][] = array($Xc,$Yc); |
|
| 1221 | + $Xc = cos(($i - 90)*PI/180)*($InnerRadius + $DataGapRadius) + $X; |
|
| 1222 | + $Yc = sin(($i - 90)*PI/180)*($InnerRadius + $DataGapRadius)*$SkewFactor + $Y; |
|
| 1223 | + $Slices[$Slice]["AA"][] = array($Xc, $Yc); |
|
| 1224 | 1224 | |
| 1225 | - if ( $InX1 == VOID ) { $InX1 = $Xc; $InY1 = $Yc; } |
|
| 1225 | + if ($InX1 == VOID) { $InX1 = $Xc; $InY1 = $Yc; } |
|
| 1226 | 1226 | |
| 1227 | - if ( $i<90 ) { $Yc++; } |
|
| 1228 | - if ( $i>90 && $i<180 ) { $Xc++; } |
|
| 1229 | - if ( $i>180 && $i<270 ) { $Xc++; } |
|
| 1230 | - if ( $i>=270 ) { $Xc++; $Yc++; } |
|
| 1227 | + if ($i < 90) { $Yc++; } |
|
| 1228 | + if ($i > 90 && $i < 180) { $Xc++; } |
|
| 1229 | + if ($i > 180 && $i < 270) { $Xc++; } |
|
| 1230 | + if ($i >= 270) { $Xc++; $Yc++; } |
|
| 1231 | 1231 | |
| 1232 | 1232 | $Slices[$Slice]["BottomPoly"][] = floor($Xc); $Slices[$Slice]["BottomPoly"][] = floor($Yc); |
| 1233 | - $Slices[$Slice]["TopPoly"][] = floor($Xc); $Slices[$Slice]["TopPoly"][] = floor($Yc)-$SliceHeight; |
|
| 1233 | + $Slices[$Slice]["TopPoly"][] = floor($Xc); $Slices[$Slice]["TopPoly"][] = floor($Yc) - $SliceHeight; |
|
| 1234 | 1234 | $Slices[$Slice]["Angle"][] = $i; |
| 1235 | 1235 | } |
| 1236 | 1236 | $InX2 = $Xc; $InY2 = $Yc; |
| 1237 | 1237 | |
| 1238 | - $Slices[$Slice]["InX1"] = $InX1; $Slices[$Slice]["InY1"] = $InY1; |
|
| 1239 | - $Slices[$Slice]["InX2"] = $InX2; $Slices[$Slice]["InY2"] = $InY2; |
|
| 1238 | + $Slices[$Slice]["InX1"] = $InX1; $Slices[$Slice]["InY1"] = $InY1; |
|
| 1239 | + $Slices[$Slice]["InX2"] = $InX2; $Slices[$Slice]["InY2"] = $InY2; |
|
| 1240 | 1240 | $Slices[$Slice]["OutX1"] = $OutX1; $Slices[$Slice]["OutY1"] = $OutY1; |
| 1241 | 1241 | $Slices[$Slice]["OutX2"] = $OutX2; $Slices[$Slice]["OutY2"] = $OutY2; |
| 1242 | 1242 | |
@@ -1244,151 +1244,151 @@ discard block |
||
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | 1246 | /* Draw the bottom pie splice */ |
| 1247 | - foreach($Slices as $SliceID => $Plots) |
|
| 1247 | + foreach ($Slices as $SliceID => $Plots) |
|
| 1248 | 1248 | { |
| 1249 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1250 | - $this->pChartObject->drawPolygon($Plots["BottomPoly"],$Settings); |
|
| 1249 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1250 | + $this->pChartObject->drawPolygon($Plots["BottomPoly"], $Settings); |
|
| 1251 | 1251 | |
| 1252 | - foreach($Plots["AA"] as $Key => $Pos) |
|
| 1253 | - $this->pChartObject->drawAntialiasPixel($Pos[0],$Pos[1],$Settings); |
|
| 1252 | + foreach ($Plots["AA"] as $Key => $Pos) |
|
| 1253 | + $this->pChartObject->drawAntialiasPixel($Pos[0], $Pos[1], $Settings); |
|
| 1254 | 1254 | |
| 1255 | - $this->pChartObject->drawLine($Plots["InX1"],$Plots["InY1"],$Plots["OutX2"],$Plots["OutY2"],$Settings); |
|
| 1256 | - $this->pChartObject->drawLine($Plots["InX2"],$Plots["InY2"],$Plots["OutX1"],$Plots["OutY1"],$Settings); |
|
| 1255 | + $this->pChartObject->drawLine($Plots["InX1"], $Plots["InY1"], $Plots["OutX2"], $Plots["OutY2"], $Settings); |
|
| 1256 | + $this->pChartObject->drawLine($Plots["InX2"], $Plots["InY2"], $Plots["OutX1"], $Plots["OutY1"], $Settings); |
|
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | 1259 | $Slices = array_reverse($Slices); |
| 1260 | 1260 | $SliceColors = array_reverse($SliceColors); |
| 1261 | 1261 | |
| 1262 | 1262 | /* Draw the vertical edges (semi-visible) */ |
| 1263 | - foreach($Slices as $SliceID => $Plots) |
|
| 1263 | + foreach ($Slices as $SliceID => $Plots) |
|
| 1264 | 1264 | { |
| 1265 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1266 | - $Settings["R"] = $Settings["R"]+$Cf; $Settings["G"] = $Settings["G"]+$Cf; $Settings["B"] = $Settings["B"]+$Cf; |
|
| 1265 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1266 | + $Settings["R"] = $Settings["R"] + $Cf; $Settings["G"] = $Settings["G"] + $Cf; $Settings["B"] = $Settings["B"] + $Cf; |
|
| 1267 | 1267 | |
| 1268 | 1268 | $StartAngle = $Plots["Angle"][0]; |
| 1269 | - foreach($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key-1]; } } |
|
| 1269 | + foreach ($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key - 1]; } } |
|
| 1270 | 1270 | |
| 1271 | - if ( $StartAngle >= 270 || $StartAngle <= 90 ) |
|
| 1272 | - $this->pChartObject->drawLine($Plots["OutX1"],$Plots["OutY1"],$Plots["OutX1"],$Plots["OutY1"]-$SliceHeight,$Settings); |
|
| 1273 | - if ( $StartAngle >= 270 || $StartAngle <= 90 ) |
|
| 1274 | - $this->pChartObject->drawLine($Plots["OutX2"],$Plots["OutY2"],$Plots["OutX2"],$Plots["OutY2"]-$SliceHeight,$Settings); |
|
| 1271 | + if ($StartAngle >= 270 || $StartAngle <= 90) |
|
| 1272 | + $this->pChartObject->drawLine($Plots["OutX1"], $Plots["OutY1"], $Plots["OutX1"], $Plots["OutY1"] - $SliceHeight, $Settings); |
|
| 1273 | + if ($StartAngle >= 270 || $StartAngle <= 90) |
|
| 1274 | + $this->pChartObject->drawLine($Plots["OutX2"], $Plots["OutY2"], $Plots["OutX2"], $Plots["OutY2"] - $SliceHeight, $Settings); |
|
| 1275 | 1275 | |
| 1276 | - $this->pChartObject->drawLine($Plots["InX1"],$Plots["InY1"],$Plots["InX1"],$Plots["InY1"]-$SliceHeight,$Settings); |
|
| 1277 | - $this->pChartObject->drawLine($Plots["InX2"],$Plots["InY2"],$Plots["InX2"],$Plots["InY2"]-$SliceHeight,$Settings); |
|
| 1276 | + $this->pChartObject->drawLine($Plots["InX1"], $Plots["InY1"], $Plots["InX1"], $Plots["InY1"] - $SliceHeight, $Settings); |
|
| 1277 | + $this->pChartObject->drawLine($Plots["InX2"], $Plots["InY2"], $Plots["InX2"], $Plots["InY2"] - $SliceHeight, $Settings); |
|
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | 1280 | /* Draw the inner vertical slices */ |
| 1281 | - foreach($Slices as $SliceID => $Plots) |
|
| 1281 | + foreach ($Slices as $SliceID => $Plots) |
|
| 1282 | 1282 | { |
| 1283 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1284 | - $Settings["R"] = $Settings["R"]+$Cf; $Settings["G"] = $Settings["G"]+$Cf; $Settings["B"] = $Settings["B"]+$Cf; |
|
| 1283 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1284 | + $Settings["R"] = $Settings["R"] + $Cf; $Settings["G"] = $Settings["G"] + $Cf; $Settings["B"] = $Settings["B"] + $Cf; |
|
| 1285 | 1285 | |
| 1286 | 1286 | $Outer = TRUE; $Inner = FALSE; |
| 1287 | 1287 | $InnerPlotsA = ""; $InnerPlotsB = ""; |
| 1288 | - foreach($Plots["Angle"] as $ID => $Angle) |
|
| 1288 | + foreach ($Plots["Angle"] as $ID => $Angle) |
|
| 1289 | 1289 | { |
| 1290 | - if ( $Angle == VOID ) |
|
| 1290 | + if ($Angle == VOID) |
|
| 1291 | 1291 | { $Outer = FALSE; $Inner = TRUE; } |
| 1292 | - elseif( $Inner ) |
|
| 1292 | + elseif ($Inner) |
|
| 1293 | 1293 | { |
| 1294 | - if (( $Angle < 90 || $Angle > 270 ) && isset($Plots["BottomPoly"][$ID*2]) ) |
|
| 1294 | + if (($Angle < 90 || $Angle > 270) && isset($Plots["BottomPoly"][$ID*2])) |
|
| 1295 | 1295 | { |
| 1296 | 1296 | $Xo = $Plots["BottomPoly"][$ID*2]; |
| 1297 | - $Yo = $Plots["BottomPoly"][$ID*2+1]; |
|
| 1297 | + $Yo = $Plots["BottomPoly"][$ID*2 + 1]; |
|
| 1298 | 1298 | |
| 1299 | 1299 | $InnerPlotsA[] = $Xo; $InnerPlotsA[] = $Yo; |
| 1300 | - $InnerPlotsB[] = $Xo; $InnerPlotsB[] = $Yo-$SliceHeight; |
|
| 1300 | + $InnerPlotsB[] = $Xo; $InnerPlotsB[] = $Yo - $SliceHeight; |
|
| 1301 | 1301 | } |
| 1302 | 1302 | } |
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | - if ( $InnerPlotsA != "" ) |
|
| 1306 | - { $InnerPlots = array_merge($InnerPlotsA,$this->arrayReverse($InnerPlotsB)); $this->pChartObject->drawPolygon($InnerPlots,$Settings); } |
|
| 1305 | + if ($InnerPlotsA != "") |
|
| 1306 | + { $InnerPlots = array_merge($InnerPlotsA, $this->arrayReverse($InnerPlotsB)); $this->pChartObject->drawPolygon($InnerPlots, $Settings); } |
|
| 1307 | 1307 | } |
| 1308 | 1308 | |
| 1309 | 1309 | /* Draw the splice top and left poly */ |
| 1310 | - foreach($Slices as $SliceID => $Plots) |
|
| 1310 | + foreach ($Slices as $SliceID => $Plots) |
|
| 1311 | 1311 | { |
| 1312 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1313 | - $Settings["R"] = $Settings["R"]+$Cf*1.5; $Settings["G"] = $Settings["G"]+$Cf*1.5; $Settings["B"] = $Settings["B"]+$Cf*1.5; |
|
| 1312 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1313 | + $Settings["R"] = $Settings["R"] + $Cf*1.5; $Settings["G"] = $Settings["G"] + $Cf*1.5; $Settings["B"] = $Settings["B"] + $Cf*1.5; |
|
| 1314 | 1314 | |
| 1315 | 1315 | $StartAngle = $Plots["Angle"][0]; |
| 1316 | - foreach($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key-1]; } } |
|
| 1316 | + foreach ($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key - 1]; } } |
|
| 1317 | 1317 | |
| 1318 | - if ( $StartAngle < 180 ) |
|
| 1318 | + if ($StartAngle < 180) |
|
| 1319 | 1319 | { |
| 1320 | 1320 | $Points = ""; |
| 1321 | 1321 | $Points[] = $Plots["InX2"]; |
| 1322 | 1322 | $Points[] = $Plots["InY2"]; |
| 1323 | 1323 | $Points[] = $Plots["InX2"]; |
| 1324 | - $Points[] = $Plots["InY2"]-$SliceHeight; |
|
| 1324 | + $Points[] = $Plots["InY2"] - $SliceHeight; |
|
| 1325 | 1325 | $Points[] = $Plots["OutX1"]; |
| 1326 | - $Points[] = $Plots["OutY1"]-$SliceHeight; |
|
| 1326 | + $Points[] = $Plots["OutY1"] - $SliceHeight; |
|
| 1327 | 1327 | $Points[] = $Plots["OutX1"]; |
| 1328 | 1328 | $Points[] = $Plots["OutY1"]; |
| 1329 | 1329 | |
| 1330 | - $this->pChartObject->drawPolygon($Points,$Settings); |
|
| 1330 | + $this->pChartObject->drawPolygon($Points, $Settings); |
|
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | - if ( $EndAngle > 180 ) |
|
| 1333 | + if ($EndAngle > 180) |
|
| 1334 | 1334 | { |
| 1335 | 1335 | $Points = ""; |
| 1336 | 1336 | $Points[] = $Plots["InX1"]; |
| 1337 | 1337 | $Points[] = $Plots["InY1"]; |
| 1338 | 1338 | $Points[] = $Plots["InX1"]; |
| 1339 | - $Points[] = $Plots["InY1"]-$SliceHeight; |
|
| 1339 | + $Points[] = $Plots["InY1"] - $SliceHeight; |
|
| 1340 | 1340 | $Points[] = $Plots["OutX2"]; |
| 1341 | - $Points[] = $Plots["OutY2"]-$SliceHeight; |
|
| 1341 | + $Points[] = $Plots["OutY2"] - $SliceHeight; |
|
| 1342 | 1342 | $Points[] = $Plots["OutX2"]; |
| 1343 | 1343 | $Points[] = $Plots["OutY2"]; |
| 1344 | 1344 | |
| 1345 | - $this->pChartObject->drawPolygon($Points,$Settings); |
|
| 1345 | + $this->pChartObject->drawPolygon($Points, $Settings); |
|
| 1346 | 1346 | } |
| 1347 | 1347 | } |
| 1348 | 1348 | |
| 1349 | 1349 | |
| 1350 | 1350 | /* Draw the vertical edges (visible) */ |
| 1351 | - foreach($Slices as $SliceID => $Plots) |
|
| 1351 | + foreach ($Slices as $SliceID => $Plots) |
|
| 1352 | 1352 | { |
| 1353 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1354 | - $Settings["R"] = $Settings["R"]+$Cf; $Settings["G"] = $Settings["G"]+$Cf; $Settings["B"] = $Settings["B"]+$Cf; |
|
| 1353 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1354 | + $Settings["R"] = $Settings["R"] + $Cf; $Settings["G"] = $Settings["G"] + $Cf; $Settings["B"] = $Settings["B"] + $Cf; |
|
| 1355 | 1355 | |
| 1356 | 1356 | $StartAngle = $Plots["Angle"][0]; |
| 1357 | - foreach($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key-1]; } } |
|
| 1357 | + foreach ($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key - 1]; } } |
|
| 1358 | 1358 | |
| 1359 | - if ( $StartAngle <= 270 && $StartAngle >= 90 ) |
|
| 1360 | - $this->pChartObject->drawLine($Plots["OutX1"],$Plots["OutY1"],$Plots["OutX1"],$Plots["OutY1"]-$SliceHeight,$Settings); |
|
| 1361 | - if ( $EndAngle <= 270 && $EndAngle >= 90 ) |
|
| 1362 | - $this->pChartObject->drawLine($Plots["OutX2"],$Plots["OutY2"],$Plots["OutX2"],$Plots["OutY2"]-$SliceHeight,$Settings); |
|
| 1359 | + if ($StartAngle <= 270 && $StartAngle >= 90) |
|
| 1360 | + $this->pChartObject->drawLine($Plots["OutX1"], $Plots["OutY1"], $Plots["OutX1"], $Plots["OutY1"] - $SliceHeight, $Settings); |
|
| 1361 | + if ($EndAngle <= 270 && $EndAngle >= 90) |
|
| 1362 | + $this->pChartObject->drawLine($Plots["OutX2"], $Plots["OutY2"], $Plots["OutX2"], $Plots["OutY2"] - $SliceHeight, $Settings); |
|
| 1363 | 1363 | } |
| 1364 | 1364 | |
| 1365 | 1365 | |
| 1366 | 1366 | /* Draw the outer vertical slices */ |
| 1367 | - foreach($Slices as $SliceID => $Plots) |
|
| 1367 | + foreach ($Slices as $SliceID => $Plots) |
|
| 1368 | 1368 | { |
| 1369 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1370 | - $Settings["R"] = $Settings["R"]+$Cf; $Settings["G"] = $Settings["G"]+$Cf; $Settings["B"] = $Settings["B"]+$Cf; |
|
| 1369 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1370 | + $Settings["R"] = $Settings["R"] + $Cf; $Settings["G"] = $Settings["G"] + $Cf; $Settings["B"] = $Settings["B"] + $Cf; |
|
| 1371 | 1371 | |
| 1372 | 1372 | $Outer = TRUE; $Inner = FALSE; |
| 1373 | 1373 | $OuterPlotsA = ""; $OuterPlotsB = ""; $InnerPlotsA = ""; $InnerPlotsB = ""; |
| 1374 | - foreach($Plots["Angle"] as $ID => $Angle) |
|
| 1374 | + foreach ($Plots["Angle"] as $ID => $Angle) |
|
| 1375 | 1375 | { |
| 1376 | - if ( $Angle == VOID ) |
|
| 1376 | + if ($Angle == VOID) |
|
| 1377 | 1377 | { $Outer = FALSE; $Inner = TRUE; } |
| 1378 | - elseif( $Outer ) |
|
| 1378 | + elseif ($Outer) |
|
| 1379 | 1379 | { |
| 1380 | - if ( ( $Angle > 90 && $Angle < 270 ) && isset($Plots["BottomPoly"][$ID*2]) ) |
|
| 1380 | + if (($Angle > 90 && $Angle < 270) && isset($Plots["BottomPoly"][$ID*2])) |
|
| 1381 | 1381 | { |
| 1382 | 1382 | $Xo = $Plots["BottomPoly"][$ID*2]; |
| 1383 | - $Yo = $Plots["BottomPoly"][$ID*2+1]; |
|
| 1383 | + $Yo = $Plots["BottomPoly"][$ID*2 + 1]; |
|
| 1384 | 1384 | |
| 1385 | 1385 | $OuterPlotsA[] = $Xo; $OuterPlotsA[] = $Yo; |
| 1386 | - $OuterPlotsB[] = $Xo; $OuterPlotsB[] = $Yo-$SliceHeight; |
|
| 1386 | + $OuterPlotsB[] = $Xo; $OuterPlotsB[] = $Yo - $SliceHeight; |
|
| 1387 | 1387 | } |
| 1388 | 1388 | } |
| 1389 | 1389 | } |
| 1390 | - if ( $OuterPlotsA != "" ) |
|
| 1391 | - { $OuterPlots = array_merge($OuterPlotsA,$this->arrayReverse($OuterPlotsB)); $this->pChartObject->drawPolygon($OuterPlots,$Settings); } |
|
| 1390 | + if ($OuterPlotsA != "") |
|
| 1391 | + { $OuterPlots = array_merge($OuterPlotsA, $this->arrayReverse($OuterPlotsB)); $this->pChartObject->drawPolygon($OuterPlots, $Settings); } |
|
| 1392 | 1392 | } |
| 1393 | 1393 | |
| 1394 | 1394 | $Slices = array_reverse($Slices); |
@@ -1396,55 +1396,55 @@ discard block |
||
| 1396 | 1396 | |
| 1397 | 1397 | |
| 1398 | 1398 | /* Draw the top pie splice */ |
| 1399 | - foreach($Slices as $SliceID => $Plots) |
|
| 1399 | + foreach ($Slices as $SliceID => $Plots) |
|
| 1400 | 1400 | { |
| 1401 | - $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1402 | - $Settings["R"] = $Settings["R"]+$Cf*2; $Settings["G"] = $Settings["G"]+$Cf*2; $Settings["B"] = $Settings["B"]+$Cf*2; |
|
| 1401 | + $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
|
| 1402 | + $Settings["R"] = $Settings["R"] + $Cf*2; $Settings["G"] = $Settings["G"] + $Cf*2; $Settings["B"] = $Settings["B"] + $Cf*2; |
|
| 1403 | 1403 | |
| 1404 | - $this->pChartObject->drawPolygon($Plots["TopPoly"],$Settings); |
|
| 1404 | + $this->pChartObject->drawPolygon($Plots["TopPoly"], $Settings); |
|
| 1405 | 1405 | |
| 1406 | - if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("POLY",$this->arraySerialize($Plots["TopPoly"]),$this->pChartObject->toHTMLColor($Settings["R"],$Settings["G"],$Settings["B"]),$Data["Series"][$Data["Abscissa"]]["Data"][$SliceID],$Data["Series"][$DataSerie]["Data"][count($Slices)-$SliceID-1]); } |
|
| 1406 | + if ($RecordImageMap) { $this->pChartObject->addToImageMap("POLY", $this->arraySerialize($Plots["TopPoly"]), $this->pChartObject->toHTMLColor($Settings["R"], $Settings["G"], $Settings["B"]), $Data["Series"][$Data["Abscissa"]]["Data"][$SliceID], $Data["Series"][$DataSerie]["Data"][count($Slices) - $SliceID - 1]); } |
|
| 1407 | 1407 | |
| 1408 | - foreach($Plots["AA"] as $Key => $Pos) |
|
| 1409 | - $this->pChartObject->drawAntialiasPixel($Pos[0],$Pos[1]-$SliceHeight,$Settings); |
|
| 1408 | + foreach ($Plots["AA"] as $Key => $Pos) |
|
| 1409 | + $this->pChartObject->drawAntialiasPixel($Pos[0], $Pos[1] - $SliceHeight, $Settings); |
|
| 1410 | 1410 | |
| 1411 | - $this->pChartObject->drawLine($Plots["InX1"],$Plots["InY1"]-$SliceHeight,$Plots["OutX2"],$Plots["OutY2"]-$SliceHeight,$Settings); |
|
| 1412 | - $this->pChartObject->drawLine($Plots["InX2"],$Plots["InY2"]-$SliceHeight,$Plots["OutX1"],$Plots["OutY1"]-$SliceHeight,$Settings); |
|
| 1411 | + $this->pChartObject->drawLine($Plots["InX1"], $Plots["InY1"] - $SliceHeight, $Plots["OutX2"], $Plots["OutY2"] - $SliceHeight, $Settings); |
|
| 1412 | + $this->pChartObject->drawLine($Plots["InX2"], $Plots["InY2"] - $SliceHeight, $Plots["OutX1"], $Plots["OutY1"] - $SliceHeight, $Settings); |
|
| 1413 | 1413 | } |
| 1414 | 1414 | |
| 1415 | - if ( $DrawLabels ) |
|
| 1415 | + if ($DrawLabels) |
|
| 1416 | 1416 | { |
| 1417 | 1417 | $Offset = 360; |
| 1418 | - foreach($Values as $Key => $Value) |
|
| 1418 | + foreach ($Values as $Key => $Value) |
|
| 1419 | 1419 | { |
| 1420 | 1420 | $StartAngle = $Offset; |
| 1421 | - $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
|
| 1421 | + $EndAngle = $Offset - ($Value*$ScaleFactor); if ($EndAngle < 0) { $EndAngle = 0; } |
|
| 1422 | 1422 | |
| 1423 | - if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
|
| 1424 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 1423 | + if ($LabelColor == PIE_LABEL_COLOR_AUTO) |
|
| 1424 | + { $Settings = array("FillR"=>$Palette[$ID]["R"], "FillG"=>$Palette[$ID]["G"], "FillB"=>$Palette[$ID]["B"], "Alpha"=>$Palette[$ID]["Alpha"]); } |
|
| 1425 | 1425 | else |
| 1426 | - { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
|
| 1426 | + { $Settings = array("FillR"=>$LabelR, "FillG"=>$LabelG, "FillB"=>$LabelB, "Alpha"=>$LabelAlpha); } |
|
| 1427 | 1427 | |
| 1428 | 1428 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 1429 | - $Xc = cos(($Angle-90)*PI/180) * ($OuterRadius+$DataGapRadius) + $X; |
|
| 1430 | - $Yc = sin(($Angle-90)*PI/180) * ($OuterRadius+$DataGapRadius)*$SkewFactor + $Y; |
|
| 1429 | + $Xc = cos(($Angle - 90)*PI/180)*($OuterRadius + $DataGapRadius) + $X; |
|
| 1430 | + $Yc = sin(($Angle - 90)*PI/180)*($OuterRadius + $DataGapRadius)*$SkewFactor + $Y; |
|
| 1431 | 1431 | |
| 1432 | - if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 1433 | - $Label = $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 1434 | - elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 1432 | + if ($WriteValues == PIE_VALUE_PERCENTAGE) |
|
| 1433 | + $Label = $Display = round((100/$SerieSum)*$Value, $Precision)."%"; |
|
| 1434 | + elseif ($WriteValues == PIE_VALUE_NATURAL) |
|
| 1435 | 1435 | $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
| 1436 | 1436 | else |
| 1437 | 1437 | $Label = ""; |
| 1438 | 1438 | |
| 1439 | - if ( $LabelStacked ) |
|
| 1440 | - $this->writePieLabel($Xc,$Yc-$SliceHeight,$Label,$Angle,$Settings,TRUE,$X,$Y,$OuterRadius); |
|
| 1439 | + if ($LabelStacked) |
|
| 1440 | + $this->writePieLabel($Xc, $Yc - $SliceHeight, $Label, $Angle, $Settings, TRUE, $X, $Y, $OuterRadius); |
|
| 1441 | 1441 | else |
| 1442 | - $this->writePieLabel($Xc,$Yc-$SliceHeight,$Label,$Angle,$Settings,FALSE); |
|
| 1442 | + $this->writePieLabel($Xc, $Yc - $SliceHeight, $Label, $Angle, $Settings, FALSE); |
|
| 1443 | 1443 | |
| 1444 | 1444 | $Offset = $EndAngle - $DataGapAngle; $ID--; $Slice++; |
| 1445 | 1445 | } |
| 1446 | 1446 | } |
| 1447 | - if ( $DrawLabels && $LabelStacked ) { $this->writeShiftedLabels(); } |
|
| 1447 | + if ($DrawLabels && $LabelStacked) { $this->writeShiftedLabels(); } |
|
| 1448 | 1448 | |
| 1449 | 1449 | $this->pChartObject->Shadow = $RestoreShadow; |
| 1450 | 1450 | |
@@ -1455,7 +1455,7 @@ discard block |
||
| 1455 | 1455 | function arraySerialize($Data) |
| 1456 | 1456 | { |
| 1457 | 1457 | $Result = ""; |
| 1458 | - foreach($Data as $Key => $Value) |
|
| 1458 | + foreach ($Data as $Key => $Value) |
|
| 1459 | 1459 | { if ($Result == "") { $Result = floor($Value); } else { $Result = $Result.",".floor($Value); } } |
| 1460 | 1460 | |
| 1461 | 1461 | return($Result); |
@@ -1466,35 +1466,35 @@ discard block |
||
| 1466 | 1466 | { |
| 1467 | 1467 | $Result = ""; |
| 1468 | 1468 | |
| 1469 | - for($i=count($Plots)-1;$i>=0;$i=$i-2) |
|
| 1470 | - { $Result[] = $Plots[$i-1]; $Result[] = $Plots[$i]; } |
|
| 1469 | + for ($i = count($Plots) - 1; $i >= 0; $i = $i - 2) |
|
| 1470 | + { $Result[] = $Plots[$i - 1]; $Result[] = $Plots[$i]; } |
|
| 1471 | 1471 | |
| 1472 | 1472 | return($Result); |
| 1473 | 1473 | } |
| 1474 | 1474 | |
| 1475 | 1475 | /* Remove unused series & values */ |
| 1476 | - function clean0Values($Data,$Palette,$DataSerie,$AbscissaSerie) |
|
| 1476 | + function clean0Values($Data, $Palette, $DataSerie, $AbscissaSerie) |
|
| 1477 | 1477 | { |
| 1478 | 1478 | $NewPalette = ""; $NewData = ""; $NewAbscissa = ""; |
| 1479 | 1479 | |
| 1480 | 1480 | /* Remove unused series */ |
| 1481 | - foreach($Data["Series"] as $SerieName => $SerieSettings) |
|
| 1482 | - { if ( $SerieName != $DataSerie && $SerieName != $AbscissaSerie ) { unset($Data["Series"][$SerieName]); } } |
|
| 1481 | + foreach ($Data["Series"] as $SerieName => $SerieSettings) |
|
| 1482 | + { if ($SerieName != $DataSerie && $SerieName != $AbscissaSerie) { unset($Data["Series"][$SerieName]); } } |
|
| 1483 | 1483 | |
| 1484 | 1484 | /* Remove NULL values */ |
| 1485 | - foreach($Data["Series"][$DataSerie]["Data"] as $Key => $Value) |
|
| 1485 | + foreach ($Data["Series"][$DataSerie]["Data"] as $Key => $Value) |
|
| 1486 | 1486 | { |
| 1487 | - if ($Value != 0 ) |
|
| 1487 | + if ($Value != 0) |
|
| 1488 | 1488 | { |
| 1489 | 1489 | $NewData[] = $Value; |
| 1490 | 1490 | $NewAbscissa[] = $Data["Series"][$AbscissaSerie]["Data"][$Key]; |
| 1491 | - if ( isset($Palette[$Key]) ) { $NewPalette[] = $Palette[$Key]; } |
|
| 1491 | + if (isset($Palette[$Key])) { $NewPalette[] = $Palette[$Key]; } |
|
| 1492 | 1492 | } |
| 1493 | 1493 | } |
| 1494 | 1494 | $Data["Series"][$DataSerie]["Data"] = $NewData; |
| 1495 | 1495 | $Data["Series"][$AbscissaSerie]["Data"] = $NewAbscissa; |
| 1496 | 1496 | |
| 1497 | - return(array($Data,$NewPalette)); |
|
| 1497 | + return(array($Data, $NewPalette)); |
|
| 1498 | 1498 | } |
| 1499 | 1499 | } |
| 1500 | 1500 | ?> |
| 1501 | 1501 | \ No newline at end of file |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | $Offset = 0; $ID = 0; |
| 125 | 125 | foreach($Values as $Key => $Value) |
| 126 | 126 | { |
| 127 | - if ( $Shadow ) |
|
| 128 | - $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 129 | - else |
|
| 127 | + if ( $Shadow ) { |
|
| 128 | + $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 129 | + } else |
|
| 130 | 130 | { |
| 131 | 131 | if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
| 132 | 132 | $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
@@ -134,9 +134,9 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | if ( !$SecondPass && !$Shadow ) |
| 136 | 136 | { |
| 137 | - if ( !$Border ) |
|
| 138 | - $Settings["Surrounding"] = 10; |
|
| 139 | - else |
|
| 137 | + if ( !$Border ) { |
|
| 138 | + $Settings["Surrounding"] = 10; |
|
| 139 | + } else |
|
| 140 | 140 | { $Settings["BorderR"] = $BorderR; $Settings["BorderG"] = $BorderG; $Settings["BorderB"] = $BorderB; } |
| 141 | 141 | } |
| 142 | 142 | |
@@ -145,8 +145,7 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 147 | 147 | if ($DataGapAngle == 0) |
| 148 | - { $X0 = $X; $Y0 = $Y; } |
|
| 149 | - else |
|
| 148 | + { $X0 = $X; $Y0 = $Y; } else |
|
| 150 | 149 | { |
| 151 | 150 | $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
| 152 | 151 | $Y0 = sin(($Angle-90)*PI/180) * $DataGapRadius + $Y; |
@@ -173,8 +172,7 @@ discard block |
||
| 173 | 172 | if ( $DrawLabels && !$Shadow && !$SecondPass ) |
| 174 | 173 | { |
| 175 | 174 | if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
| 176 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 177 | - else |
|
| 175 | + { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} else |
|
| 178 | 176 | { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
| 179 | 177 | |
| 180 | 178 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
@@ -183,10 +181,11 @@ discard block |
||
| 183 | 181 | |
| 184 | 182 | $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
| 185 | 183 | |
| 186 | - if ( $LabelStacked ) |
|
| 187 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$Radius); |
|
| 188 | - else |
|
| 189 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 184 | + if ( $LabelStacked ) { |
|
| 185 | + $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$Radius); |
|
| 186 | + } else { |
|
| 187 | + $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 188 | + } |
|
| 190 | 189 | } |
| 191 | 190 | |
| 192 | 191 | $Offset = $i + $DataGapAngle; $ID++; |
@@ -200,21 +199,21 @@ discard block |
||
| 200 | 199 | foreach($Values as $Key => $Value) |
| 201 | 200 | { |
| 202 | 201 | $FirstPoint = TRUE; |
| 203 | - if ( $Shadow ) |
|
| 204 | - $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 205 | - else |
|
| 202 | + if ( $Shadow ) { |
|
| 203 | + $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 204 | + } else |
|
| 206 | 205 | { |
| 207 | - if ( $Border ) |
|
| 208 | - $Settings = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB); |
|
| 209 | - else |
|
| 210 | - $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 206 | + if ( $Border ) { |
|
| 207 | + $Settings = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB); |
|
| 208 | + } else { |
|
| 209 | + $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 210 | + } |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | $EndAngle = $Offset+($Value*$ScaleFactor); if ( $EndAngle > 360 ) { $EndAngle = 360; } |
| 214 | 214 | |
| 215 | 215 | if ($DataGapAngle == 0) |
| 216 | - { $X0 = $X; $Y0 = $Y; } |
|
| 217 | - else |
|
| 216 | + { $X0 = $X; $Y0 = $Y; } else |
|
| 218 | 217 | { |
| 219 | 218 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 220 | 219 | $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
@@ -236,8 +235,7 @@ discard block |
||
| 236 | 235 | if ( $DrawLabels && !$Shadow ) |
| 237 | 236 | { |
| 238 | 237 | if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
| 239 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 240 | - else |
|
| 238 | + { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} else |
|
| 241 | 239 | { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
| 242 | 240 | |
| 243 | 241 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
@@ -246,10 +244,11 @@ discard block |
||
| 246 | 244 | |
| 247 | 245 | $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
| 248 | 246 | |
| 249 | - if ( $LabelStacked ) |
|
| 250 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$Radius); |
|
| 251 | - else |
|
| 252 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 247 | + if ( $LabelStacked ) { |
|
| 248 | + $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$Radius); |
|
| 249 | + } else { |
|
| 250 | + $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 251 | + } |
|
| 253 | 252 | } |
| 254 | 253 | |
| 255 | 254 | $Offset = $i + $DataGapAngle; $ID++; |
@@ -270,17 +269,17 @@ discard block |
||
| 270 | 269 | { |
| 271 | 270 | $Xc = cos(($Angle-90)*PI/180) * ($Radius+$ValuePadding) + $X; |
| 272 | 271 | $Yc = sin(($Angle-90)*PI/180) * ($Radius+$ValuePadding) + $Y; |
| 273 | - } |
|
| 274 | - else |
|
| 272 | + } else |
|
| 275 | 273 | { |
| 276 | 274 | $Xc = cos(($Angle-90)*PI/180) * ($Radius)/2 + $X; |
| 277 | 275 | $Yc = sin(($Angle-90)*PI/180) * ($Radius)/2 + $Y; |
| 278 | 276 | } |
| 279 | 277 | |
| 280 | - if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 281 | - $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 282 | - elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 283 | - $Display = $Value.$ValueSuffix; |
|
| 278 | + if ( $WriteValues == PIE_VALUE_PERCENTAGE ) { |
|
| 279 | + $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 280 | + } elseif ( $WriteValues == PIE_VALUE_NATURAL ) { |
|
| 281 | + $Display = $Value.$ValueSuffix; |
|
| 282 | + } |
|
| 284 | 283 | |
| 285 | 284 | $this->pChartObject->drawText($Xc,$Yc,$Display,$Settings); |
| 286 | 285 | |
@@ -385,8 +384,7 @@ discard block |
||
| 385 | 384 | if ( $EndAngle < 180 ) { $Visible[$Slice]["End"] = FALSE; } else { $Visible[$Slice]["End"] = TRUE; } |
| 386 | 385 | |
| 387 | 386 | if ($DataGapAngle == 0) |
| 388 | - { $X0 = $X; $Y0 = $Y; } |
|
| 389 | - else |
|
| 387 | + { $X0 = $X; $Y0 = $Y; } else |
|
| 390 | 388 | { |
| 391 | 389 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 392 | 390 | $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
@@ -453,9 +451,11 @@ discard block |
||
| 453 | 451 | if ( $Border ) |
| 454 | 452 | { $Settings["R"]+= 30; $Settings["G"]+= 30; $Settings["B"]+= 30;; } |
| 455 | 453 | |
| 456 | - if ( isset($SliceAngle[$SliceID][1]) ) /* Empty error handling */ |
|
| 454 | + if ( isset($SliceAngle[$SliceID][1]) ) { |
|
| 455 | + /* Empty error handling */ |
|
| 457 | 456 | { |
| 458 | 457 | $Angle = $SliceAngle[$SliceID][1]; |
| 458 | + } |
|
| 459 | 459 | $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
| 460 | 460 | $Yc = sin(($Angle-90)*PI/180) * $Radius*$SkewFactor + $Y; |
| 461 | 461 | $this->pChartObject->drawLine($Plots[0],$Plots[1],$Xc,$Yc,$Settings); |
@@ -476,9 +476,11 @@ discard block |
||
| 476 | 476 | $Settings = $SliceColors[$SliceID]; |
| 477 | 477 | $Settings["R"]+= 10; $Settings["G"]+= 10; $Settings["B"]+= 10; $Settings["NoBorder"] = TRUE; |
| 478 | 478 | |
| 479 | - if ( $Visible[$SliceID]["Start"] && isset($Plots[2])) /* Empty error handling */ |
|
| 479 | + if ( $Visible[$SliceID]["Start"] && isset($Plots[2])) { |
|
| 480 | + /* Empty error handling */ |
|
| 480 | 481 | { |
| 481 | 482 | $this->pChartObject->drawLine($Plots[2],$Plots[3],$Plots[2],$Plots[3]- $SliceHeight,array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"])); |
| 483 | + } |
|
| 482 | 484 | $Border = ""; |
| 483 | 485 | $Border[] = $Plots[0]; $Border[] = $Plots[1]; $Border[] = $Plots[0]; $Border[] = $Plots[1] - $SliceHeight; |
| 484 | 486 | $Border[] = $Plots[2]; $Border[] = $Plots[3] - $SliceHeight; $Border[] = $Plots[2]; $Border[] = $Plots[3]; |
@@ -529,9 +531,11 @@ discard block |
||
| 529 | 531 | if ( $Border ) |
| 530 | 532 | { $Settings["R"]+= 30; $Settings["G"]+= 30; $Settings["B"]+= 30; } |
| 531 | 533 | |
| 532 | - if ( isset($SliceAngle[$SliceID][1]) ) /* Empty error handling */ |
|
| 534 | + if ( isset($SliceAngle[$SliceID][1]) ) { |
|
| 535 | + /* Empty error handling */ |
|
| 533 | 536 | { |
| 534 | 537 | $Angle = $SliceAngle[$SliceID][1]; |
| 538 | + } |
|
| 535 | 539 | if ( $Angle < 270 && $Angle > 90 ) |
| 536 | 540 | { |
| 537 | 541 | $Xc = cos(($Angle-90)*PI/180) * $Radius + $X; |
@@ -587,21 +591,20 @@ discard block |
||
| 587 | 591 | foreach($Values as $Key => $Value) |
| 588 | 592 | { |
| 589 | 593 | $FirstPoint = TRUE; |
| 590 | - if ( $Shadow ) |
|
| 591 | - $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 592 | - else |
|
| 594 | + if ( $Shadow ) { |
|
| 595 | + $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
|
| 596 | + } else |
|
| 593 | 597 | { |
| 594 | 598 | if ( $Border ) |
| 595 | - { $Settings = array("R"=>$Palette[$ID]["R"]+30,"G"=>$Palette[$ID]["G"]+30,"B"=>$Palette[$ID]["B"]+30,"Alpha"=>$Palette[$ID]["Alpha"]); } |
|
| 596 | - else |
|
| 597 | - $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 599 | + { $Settings = array("R"=>$Palette[$ID]["R"]+30,"G"=>$Palette[$ID]["G"]+30,"B"=>$Palette[$ID]["B"]+30,"Alpha"=>$Palette[$ID]["Alpha"]); } else { |
|
| 600 | + $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
|
| 601 | + } |
|
| 598 | 602 | } |
| 599 | 603 | |
| 600 | 604 | $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
| 601 | 605 | |
| 602 | 606 | if ($DataGapAngle == 0) |
| 603 | - { $X0 = $X; $Y0 = $Y- $SliceHeight; } |
|
| 604 | - else |
|
| 607 | + { $X0 = $X; $Y0 = $Y- $SliceHeight; } else |
|
| 605 | 608 | { |
| 606 | 609 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 607 | 610 | $X0 = cos(($Angle-90)*PI/180) * $DataGapRadius + $X; |
@@ -640,17 +643,17 @@ discard block |
||
| 640 | 643 | { |
| 641 | 644 | $Xc = cos(($Angle-90)*PI/180) * ($Radius+$ValuePadding) + $X; |
| 642 | 645 | $Yc = sin(($Angle-90)*PI/180) * (($Radius*$SkewFactor)+$ValuePadding) + $Y - $SliceHeight; |
| 643 | - } |
|
| 644 | - else |
|
| 646 | + } else |
|
| 645 | 647 | { |
| 646 | 648 | $Xc = cos(($Angle-90)*PI/180) * ($Radius)/2 + $X; |
| 647 | 649 | $Yc = sin(($Angle-90)*PI/180) * ($Radius*$SkewFactor)/2 + $Y - $SliceHeight; |
| 648 | 650 | } |
| 649 | 651 | |
| 650 | - if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 651 | - $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 652 | - elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 653 | - $Display = $Value.$ValueSuffix; |
|
| 652 | + if ( $WriteValues == PIE_VALUE_PERCENTAGE ) { |
|
| 653 | + $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 654 | + } elseif ( $WriteValues == PIE_VALUE_NATURAL ) { |
|
| 655 | + $Display = $Value.$ValueSuffix; |
|
| 656 | + } |
|
| 654 | 657 | |
| 655 | 658 | $this->pChartObject->drawText($Xc,$Yc,$Display,$Settings); |
| 656 | 659 | |
@@ -665,8 +668,7 @@ discard block |
||
| 665 | 668 | foreach($Values as $Key => $Value) |
| 666 | 669 | { |
| 667 | 670 | if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
| 668 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 669 | - else |
|
| 671 | + { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} else |
|
| 670 | 672 | { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
| 671 | 673 | |
| 672 | 674 | $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
@@ -679,10 +681,11 @@ discard block |
||
| 679 | 681 | { |
| 680 | 682 | $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$ID]; |
| 681 | 683 | |
| 682 | - if ( $LabelStacked ) |
|
| 683 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$Radius,TRUE); |
|
| 684 | - else |
|
| 685 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 684 | + if ( $LabelStacked ) { |
|
| 685 | + $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$Radius,TRUE); |
|
| 686 | + } else { |
|
| 687 | + $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 688 | + } |
|
| 686 | 689 | } |
| 687 | 690 | |
| 688 | 691 | $Offset = $EndAngle - $DataGapAngle; $ID--; |
@@ -740,8 +743,7 @@ discard block |
||
| 740 | 743 | if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; } |
| 741 | 744 | if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$BoxSize/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$BoxSize/2; } |
| 742 | 745 | $vY=$vY+$YStep; |
| 743 | - } |
|
| 744 | - elseif ( $Mode == LEGEND_HORIZONTAL ) |
|
| 746 | + } elseif ( $Mode == LEGEND_HORIZONTAL ) |
|
| 745 | 747 | { |
| 746 | 748 | if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$BoxSize/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$BoxSize/2; } |
| 747 | 749 | if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; } |
@@ -754,10 +756,11 @@ discard block |
||
| 754 | 756 | $TopOffset = $Y - $Boundaries["T"]; |
| 755 | 757 | if ( $Boundaries["B"]-($vY+$BoxSize) < $TopOffset ) { $Boundaries["B"] = $vY+$BoxSize+$TopOffset; } |
| 756 | 758 | |
| 757 | - if ( $Style == LEGEND_ROUND ) |
|
| 758 | - $this->pChartObject->drawRoundedFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB)); |
|
| 759 | - elseif ( $Style == LEGEND_BOX ) |
|
| 760 | - $this->pChartObject->drawFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB)); |
|
| 759 | + if ( $Style == LEGEND_ROUND ) { |
|
| 760 | + $this->pChartObject->drawRoundedFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB)); |
|
| 761 | + } elseif ( $Style == LEGEND_BOX ) { |
|
| 762 | + $this->pChartObject->drawFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB)); |
|
| 763 | + } |
|
| 761 | 764 | |
| 762 | 765 | $RestoreShadow = $this->pChartObject->Shadow; $this->pChartObject->Shadow = FALSE; |
| 763 | 766 | foreach($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $Value) |
@@ -770,8 +773,7 @@ discard block |
||
| 770 | 773 | { |
| 771 | 774 | $this->pChartObject->drawText($X+$BoxSize+4,$Y+$BoxSize/2,$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT,"FontName"=>$FontName,"FontSize"=>$FontSize)); |
| 772 | 775 | $Y=$Y+$YStep; |
| 773 | - } |
|
| 774 | - elseif ( $Mode == LEGEND_HORIZONTAL ) |
|
| 776 | + } elseif ( $Mode == LEGEND_HORIZONTAL ) |
|
| 775 | 777 | { |
| 776 | 778 | $BoxArray = $this->pChartObject->drawText($X+$BoxSize+4,$Y+$BoxSize/2,$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT,"FontName"=>$FontName,"FontSize"=>$FontSize)); |
| 777 | 779 | $X=$BoxArray[1]["X"]+2+$XStep; |
@@ -809,8 +811,7 @@ discard block |
||
| 809 | 811 | $Settings["Size"] = 8; |
| 810 | 812 | |
| 811 | 813 | $this->pChartObject->drawArrowLabel($X,$Y," ".$Label." ",$Settings); |
| 812 | - } |
|
| 813 | - else |
|
| 814 | + } else |
|
| 814 | 815 | { |
| 815 | 816 | $X2 = cos(deg2rad($Angle-90))*20+$X; |
| 816 | 817 | $Y2 = sin(deg2rad($Angle-90))*20+$Y; |
@@ -873,8 +874,7 @@ discard block |
||
| 873 | 874 | { |
| 874 | 875 | $this->pChartObject->drawLine($X2,$Y2,$X3,$Y2); |
| 875 | 876 | $this->pChartObject->drawText($X3+2,$Y2,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT)); |
| 876 | - } |
|
| 877 | - else |
|
| 877 | + } else |
|
| 878 | 878 | { |
| 879 | 879 | $this->pChartObject->drawLine($X2,$Y2,$X3,$Y2); |
| 880 | 880 | $this->pChartObject->drawText($X3-2,$Y2,$Label,array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); |
@@ -964,16 +964,16 @@ discard block |
||
| 964 | 964 | { |
| 965 | 965 | $Settings = array("R"=>$this->pChartObject->ShadowR,"G"=>$this->pChartObject->ShadowG,"B"=>$this->pChartObject->ShadowB,"Alpha"=>$this->pChartObject->Shadowa); |
| 966 | 966 | $BorderColor = $Settings; |
| 967 | - } |
|
| 968 | - else |
|
| 967 | + } else |
|
| 969 | 968 | { |
| 970 | 969 | if ( !isset($Palette[$ID]["R"]) ) { $Color = $this->pChartObject->getRandomColor(); $Palette[$ID] = $Color; $this->pDataObject->savePalette($ID,$Color); } |
| 971 | 970 | $Settings = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]); |
| 972 | 971 | |
| 973 | - if ( $Border ) |
|
| 974 | - $BorderColor = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha); |
|
| 975 | - else |
|
| 976 | - $BorderColor = $Settings; |
|
| 972 | + if ( $Border ) { |
|
| 973 | + $BorderColor = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha); |
|
| 974 | + } else { |
|
| 975 | + $BorderColor = $Settings; |
|
| 976 | + } |
|
| 977 | 977 | } |
| 978 | 978 | |
| 979 | 979 | $Plots = ""; $Boundaries = ""; $AAPixels = ""; |
@@ -1026,8 +1026,7 @@ discard block |
||
| 1026 | 1026 | if ( $DrawLabels && !$Shadow ) |
| 1027 | 1027 | { |
| 1028 | 1028 | if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
| 1029 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 1030 | - else |
|
| 1029 | + { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} else |
|
| 1031 | 1030 | { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
| 1032 | 1031 | |
| 1033 | 1032 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
@@ -1036,10 +1035,11 @@ discard block |
||
| 1036 | 1035 | |
| 1037 | 1036 | $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
| 1038 | 1037 | |
| 1039 | - if ( $LabelStacked ) |
|
| 1040 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$OuterRadius); |
|
| 1041 | - else |
|
| 1042 | - $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 1038 | + if ( $LabelStacked ) { |
|
| 1039 | + $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,TRUE,$X,$Y,$OuterRadius); |
|
| 1040 | + } else { |
|
| 1041 | + $this->writePieLabel($Xc,$Yc,$Label,$Angle,$Settings,FALSE); |
|
| 1042 | + } |
|
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | 1045 | $Offset = $Lasti; $ID++; |
@@ -1065,20 +1065,20 @@ discard block |
||
| 1065 | 1065 | if ( $Angle > 90 && $Angle <= 180 ) { $Align = TEXT_ALIGN_TOPLEFT; } |
| 1066 | 1066 | if ( $Angle > 180 && $Angle <= 270 ) { $Align = TEXT_ALIGN_TOPRIGHT; } |
| 1067 | 1067 | if ( $Angle > 270 ) { $Align = TEXT_ALIGN_BOTTOMRIGHT; } |
| 1068 | - } |
|
| 1069 | - else |
|
| 1068 | + } else |
|
| 1070 | 1069 | { |
| 1071 | 1070 | $Xc = cos(($Angle-90)*PI/180) * (($OuterRadius-$InnerRadius)/2+$InnerRadius) + $X; |
| 1072 | 1071 | $Yc = sin(($Angle-90)*PI/180) * (($OuterRadius-$InnerRadius)/2+$InnerRadius) + $Y; |
| 1073 | 1072 | $Align = TEXT_ALIGN_MIDDLEMIDDLE; |
| 1074 | 1073 | } |
| 1075 | 1074 | |
| 1076 | - if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 1077 | - $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 1078 | - elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 1079 | - $Display = $Value.$ValueSuffix; |
|
| 1080 | - else |
|
| 1081 | - $Label = ""; |
|
| 1075 | + if ( $WriteValues == PIE_VALUE_PERCENTAGE ) { |
|
| 1076 | + $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 1077 | + } elseif ( $WriteValues == PIE_VALUE_NATURAL ) { |
|
| 1078 | + $Display = $Value.$ValueSuffix; |
|
| 1079 | + } else { |
|
| 1080 | + $Label = ""; |
|
| 1081 | + } |
|
| 1082 | 1082 | |
| 1083 | 1083 | $this->pChartObject->drawText($Xc,$Yc,$Display,array("Align"=>$Align,"R"=>$ValueR,"G"=>$ValueG,"B"=>$ValueB)); |
| 1084 | 1084 | $Offset = $EndAngle; |
@@ -1249,8 +1249,9 @@ discard block |
||
| 1249 | 1249 | $Settings = $SliceColors[$SliceID]; $Settings["NoBorder"] = TRUE; |
| 1250 | 1250 | $this->pChartObject->drawPolygon($Plots["BottomPoly"],$Settings); |
| 1251 | 1251 | |
| 1252 | - foreach($Plots["AA"] as $Key => $Pos) |
|
| 1253 | - $this->pChartObject->drawAntialiasPixel($Pos[0],$Pos[1],$Settings); |
|
| 1252 | + foreach($Plots["AA"] as $Key => $Pos) { |
|
| 1253 | + $this->pChartObject->drawAntialiasPixel($Pos[0],$Pos[1],$Settings); |
|
| 1254 | + } |
|
| 1254 | 1255 | |
| 1255 | 1256 | $this->pChartObject->drawLine($Plots["InX1"],$Plots["InY1"],$Plots["OutX2"],$Plots["OutY2"],$Settings); |
| 1256 | 1257 | $this->pChartObject->drawLine($Plots["InX2"],$Plots["InY2"],$Plots["OutX1"],$Plots["OutY1"],$Settings); |
@@ -1268,10 +1269,12 @@ discard block |
||
| 1268 | 1269 | $StartAngle = $Plots["Angle"][0]; |
| 1269 | 1270 | foreach($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key-1]; } } |
| 1270 | 1271 | |
| 1271 | - if ( $StartAngle >= 270 || $StartAngle <= 90 ) |
|
| 1272 | - $this->pChartObject->drawLine($Plots["OutX1"],$Plots["OutY1"],$Plots["OutX1"],$Plots["OutY1"]-$SliceHeight,$Settings); |
|
| 1273 | - if ( $StartAngle >= 270 || $StartAngle <= 90 ) |
|
| 1274 | - $this->pChartObject->drawLine($Plots["OutX2"],$Plots["OutY2"],$Plots["OutX2"],$Plots["OutY2"]-$SliceHeight,$Settings); |
|
| 1272 | + if ( $StartAngle >= 270 || $StartAngle <= 90 ) { |
|
| 1273 | + $this->pChartObject->drawLine($Plots["OutX1"],$Plots["OutY1"],$Plots["OutX1"],$Plots["OutY1"]-$SliceHeight,$Settings); |
|
| 1274 | + } |
|
| 1275 | + if ( $StartAngle >= 270 || $StartAngle <= 90 ) { |
|
| 1276 | + $this->pChartObject->drawLine($Plots["OutX2"],$Plots["OutY2"],$Plots["OutX2"],$Plots["OutY2"]-$SliceHeight,$Settings); |
|
| 1277 | + } |
|
| 1275 | 1278 | |
| 1276 | 1279 | $this->pChartObject->drawLine($Plots["InX1"],$Plots["InY1"],$Plots["InX1"],$Plots["InY1"]-$SliceHeight,$Settings); |
| 1277 | 1280 | $this->pChartObject->drawLine($Plots["InX2"],$Plots["InY2"],$Plots["InX2"],$Plots["InY2"]-$SliceHeight,$Settings); |
@@ -1288,8 +1291,7 @@ discard block |
||
| 1288 | 1291 | foreach($Plots["Angle"] as $ID => $Angle) |
| 1289 | 1292 | { |
| 1290 | 1293 | if ( $Angle == VOID ) |
| 1291 | - { $Outer = FALSE; $Inner = TRUE; } |
|
| 1292 | - elseif( $Inner ) |
|
| 1294 | + { $Outer = FALSE; $Inner = TRUE; } elseif( $Inner ) |
|
| 1293 | 1295 | { |
| 1294 | 1296 | if (( $Angle < 90 || $Angle > 270 ) && isset($Plots["BottomPoly"][$ID*2]) ) |
| 1295 | 1297 | { |
@@ -1356,10 +1358,12 @@ discard block |
||
| 1356 | 1358 | $StartAngle = $Plots["Angle"][0]; |
| 1357 | 1359 | foreach($Plots["Angle"] as $Key =>$Angle) { if ($Angle == VOID) { $EndAngle = $Plots["Angle"][$Key-1]; } } |
| 1358 | 1360 | |
| 1359 | - if ( $StartAngle <= 270 && $StartAngle >= 90 ) |
|
| 1360 | - $this->pChartObject->drawLine($Plots["OutX1"],$Plots["OutY1"],$Plots["OutX1"],$Plots["OutY1"]-$SliceHeight,$Settings); |
|
| 1361 | - if ( $EndAngle <= 270 && $EndAngle >= 90 ) |
|
| 1362 | - $this->pChartObject->drawLine($Plots["OutX2"],$Plots["OutY2"],$Plots["OutX2"],$Plots["OutY2"]-$SliceHeight,$Settings); |
|
| 1361 | + if ( $StartAngle <= 270 && $StartAngle >= 90 ) { |
|
| 1362 | + $this->pChartObject->drawLine($Plots["OutX1"],$Plots["OutY1"],$Plots["OutX1"],$Plots["OutY1"]-$SliceHeight,$Settings); |
|
| 1363 | + } |
|
| 1364 | + if ( $EndAngle <= 270 && $EndAngle >= 90 ) { |
|
| 1365 | + $this->pChartObject->drawLine($Plots["OutX2"],$Plots["OutY2"],$Plots["OutX2"],$Plots["OutY2"]-$SliceHeight,$Settings); |
|
| 1366 | + } |
|
| 1363 | 1367 | } |
| 1364 | 1368 | |
| 1365 | 1369 | |
@@ -1374,8 +1378,7 @@ discard block |
||
| 1374 | 1378 | foreach($Plots["Angle"] as $ID => $Angle) |
| 1375 | 1379 | { |
| 1376 | 1380 | if ( $Angle == VOID ) |
| 1377 | - { $Outer = FALSE; $Inner = TRUE; } |
|
| 1378 | - elseif( $Outer ) |
|
| 1381 | + { $Outer = FALSE; $Inner = TRUE; } elseif( $Outer ) |
|
| 1379 | 1382 | { |
| 1380 | 1383 | if ( ( $Angle > 90 && $Angle < 270 ) && isset($Plots["BottomPoly"][$ID*2]) ) |
| 1381 | 1384 | { |
@@ -1405,8 +1408,9 @@ discard block |
||
| 1405 | 1408 | |
| 1406 | 1409 | if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("POLY",$this->arraySerialize($Plots["TopPoly"]),$this->pChartObject->toHTMLColor($Settings["R"],$Settings["G"],$Settings["B"]),$Data["Series"][$Data["Abscissa"]]["Data"][$SliceID],$Data["Series"][$DataSerie]["Data"][count($Slices)-$SliceID-1]); } |
| 1407 | 1410 | |
| 1408 | - foreach($Plots["AA"] as $Key => $Pos) |
|
| 1409 | - $this->pChartObject->drawAntialiasPixel($Pos[0],$Pos[1]-$SliceHeight,$Settings); |
|
| 1411 | + foreach($Plots["AA"] as $Key => $Pos) { |
|
| 1412 | + $this->pChartObject->drawAntialiasPixel($Pos[0],$Pos[1]-$SliceHeight,$Settings); |
|
| 1413 | + } |
|
| 1410 | 1414 | |
| 1411 | 1415 | $this->pChartObject->drawLine($Plots["InX1"],$Plots["InY1"]-$SliceHeight,$Plots["OutX2"],$Plots["OutY2"]-$SliceHeight,$Settings); |
| 1412 | 1416 | $this->pChartObject->drawLine($Plots["InX2"],$Plots["InY2"]-$SliceHeight,$Plots["OutX1"],$Plots["OutY1"]-$SliceHeight,$Settings); |
@@ -1421,25 +1425,26 @@ discard block |
||
| 1421 | 1425 | $EndAngle = $Offset-($Value*$ScaleFactor); if ( $EndAngle < 0 ) { $EndAngle = 0; } |
| 1422 | 1426 | |
| 1423 | 1427 | if ( $LabelColor == PIE_LABEL_COLOR_AUTO ) |
| 1424 | - { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} |
|
| 1425 | - else |
|
| 1428 | + { $Settings = array("FillR"=>$Palette[$ID]["R"],"FillG"=>$Palette[$ID]["G"],"FillB"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"]);} else |
|
| 1426 | 1429 | { $Settings = array("FillR"=>$LabelR,"FillG"=>$LabelG,"FillB"=>$LabelB,"Alpha"=>$LabelAlpha); } |
| 1427 | 1430 | |
| 1428 | 1431 | $Angle = ($EndAngle - $Offset)/2 + $Offset; |
| 1429 | 1432 | $Xc = cos(($Angle-90)*PI/180) * ($OuterRadius+$DataGapRadius) + $X; |
| 1430 | 1433 | $Yc = sin(($Angle-90)*PI/180) * ($OuterRadius+$DataGapRadius)*$SkewFactor + $Y; |
| 1431 | 1434 | |
| 1432 | - if ( $WriteValues == PIE_VALUE_PERCENTAGE ) |
|
| 1433 | - $Label = $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 1434 | - elseif ( $WriteValues == PIE_VALUE_NATURAL ) |
|
| 1435 | - $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
|
| 1436 | - else |
|
| 1437 | - $Label = ""; |
|
| 1438 | - |
|
| 1439 | - if ( $LabelStacked ) |
|
| 1440 | - $this->writePieLabel($Xc,$Yc-$SliceHeight,$Label,$Angle,$Settings,TRUE,$X,$Y,$OuterRadius); |
|
| 1441 | - else |
|
| 1442 | - $this->writePieLabel($Xc,$Yc-$SliceHeight,$Label,$Angle,$Settings,FALSE); |
|
| 1435 | + if ( $WriteValues == PIE_VALUE_PERCENTAGE ) { |
|
| 1436 | + $Label = $Display = round(( 100 / $SerieSum ) * $Value,$Precision)."%"; |
|
| 1437 | + } elseif ( $WriteValues == PIE_VALUE_NATURAL ) { |
|
| 1438 | + $Label = $Data["Series"][$Data["Abscissa"]]["Data"][$Key]; |
|
| 1439 | + } else { |
|
| 1440 | + $Label = ""; |
|
| 1441 | + } |
|
| 1442 | + |
|
| 1443 | + if ( $LabelStacked ) { |
|
| 1444 | + $this->writePieLabel($Xc,$Yc-$SliceHeight,$Label,$Angle,$Settings,TRUE,$X,$Y,$OuterRadius); |
|
| 1445 | + } else { |
|
| 1446 | + $this->writePieLabel($Xc,$Yc-$SliceHeight,$Label,$Angle,$Settings,FALSE); |
|
| 1447 | + } |
|
| 1443 | 1448 | |
| 1444 | 1449 | $Offset = $EndAngle - $DataGapAngle; $ID--; $Slice++; |
| 1445 | 1450 | } |
@@ -258,6 +258,11 @@ discard block |
||
| 258 | 258 | $this->Data[$SourceID]["Connections"][] = $TargetID; |
| 259 | 259 | } |
| 260 | 260 | /* Get the median linked nodes position */ |
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @param double $X |
|
| 264 | + * @param double $Y |
|
| 265 | + */ |
|
| 261 | 266 | function getMedianOffset($Key,$X,$Y) |
| 262 | 267 | { |
| 263 | 268 | $Cpt = 1; |
@@ -277,6 +282,10 @@ discard block |
||
| 277 | 282 | } |
| 278 | 283 | |
| 279 | 284 | /* Return the ID of the attached partner with the biggest weight */ |
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @return double |
|
| 288 | + */ |
|
| 280 | 289 | function getBiggestPartner($Key) |
| 281 | 290 | { |
| 282 | 291 | if ( !isset($this->Data[$Key]["Connections"]) ) { return(""); } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | - /* |
|
| 2 | + /* |
|
| 3 | 3 | pSpring - class to draw spring graphs |
| 4 | 4 | |
| 5 | 5 | Version : 2.1.3 |
@@ -13,856 +13,856 @@ discard block |
||
| 13 | 13 | You can find the whole class documentation on the pChart web site. |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | - define("NODE_TYPE_FREE" , 690001); |
|
| 17 | - define("NODE_TYPE_CENTRAL" , 690002); |
|
| 18 | - |
|
| 19 | - define("NODE_SHAPE_CIRCLE" , 690011); |
|
| 20 | - define("NODE_SHAPE_TRIANGLE" , 690012); |
|
| 21 | - define("NODE_SHAPE_SQUARE" , 690013); |
|
| 22 | - |
|
| 23 | - define("ALGORITHM_RANDOM" , 690021); |
|
| 24 | - define("ALGORITHM_WEIGHTED" , 690022); |
|
| 25 | - define("ALGORITHM_CIRCULAR" , 690023); |
|
| 26 | - define("ALGORITHM_CENTRAL" , 690024); |
|
| 27 | - |
|
| 28 | - define("LABEL_CLASSIC" , 690031); |
|
| 29 | - define("LABEL_LIGHT" , 690032); |
|
| 30 | - |
|
| 31 | - /* pSpring class definition */ |
|
| 32 | - class pSpring |
|
| 33 | - { |
|
| 34 | - var $History; |
|
| 35 | - var $pChartObject; |
|
| 36 | - var $Data; |
|
| 37 | - var $Links; |
|
| 38 | - var $X1; |
|
| 39 | - var $Y1; |
|
| 40 | - var $X2; |
|
| 41 | - var $Y2; |
|
| 42 | - var $AutoComputeFreeZone; |
|
| 43 | - var $Labels; |
|
| 44 | - |
|
| 45 | - /* Class creator */ |
|
| 46 | - function pSpring() |
|
| 16 | + define("NODE_TYPE_FREE" , 690001); |
|
| 17 | + define("NODE_TYPE_CENTRAL" , 690002); |
|
| 18 | + |
|
| 19 | + define("NODE_SHAPE_CIRCLE" , 690011); |
|
| 20 | + define("NODE_SHAPE_TRIANGLE" , 690012); |
|
| 21 | + define("NODE_SHAPE_SQUARE" , 690013); |
|
| 22 | + |
|
| 23 | + define("ALGORITHM_RANDOM" , 690021); |
|
| 24 | + define("ALGORITHM_WEIGHTED" , 690022); |
|
| 25 | + define("ALGORITHM_CIRCULAR" , 690023); |
|
| 26 | + define("ALGORITHM_CENTRAL" , 690024); |
|
| 27 | + |
|
| 28 | + define("LABEL_CLASSIC" , 690031); |
|
| 29 | + define("LABEL_LIGHT" , 690032); |
|
| 30 | + |
|
| 31 | + /* pSpring class definition */ |
|
| 32 | + class pSpring |
|
| 47 | 33 | { |
| 48 | - /* Initialise data arrays */ |
|
| 49 | - $this->Data = ""; |
|
| 50 | - $this->Links = ""; |
|
| 51 | - |
|
| 52 | - /* Set nodes defaults */ |
|
| 53 | - $this->Default["R"] = 255; |
|
| 54 | - $this->Default["G"] = 255; |
|
| 55 | - $this->Default["B"] = 255; |
|
| 56 | - $this->Default["Alpha"] = 100; |
|
| 57 | - $this->Default["BorderR"] = 0; |
|
| 58 | - $this->Default["BorderG"] = 0; |
|
| 59 | - $this->Default["BorderB"] = 0; |
|
| 60 | - $this->Default["BorderAlpha"] = 100; |
|
| 61 | - $this->Default["Surrounding"] = NULL; |
|
| 62 | - $this->Default["BackgroundR"] = 255; |
|
| 63 | - $this->Default["BackgroundG"] = 255; |
|
| 64 | - $this->Default["BackgroundB"] = 255; |
|
| 65 | - $this->Default["BackgroundAlpha"] = 0; |
|
| 66 | - $this->Default["Force"] = 1; |
|
| 67 | - $this->Default["NodeType"] = NODE_TYPE_FREE; |
|
| 68 | - $this->Default["Size"] = 5; |
|
| 69 | - $this->Default["Shape"] = NODE_SHAPE_CIRCLE; |
|
| 70 | - $this->Default["FreeZone"] = 40; |
|
| 71 | - $this->Default["LinkR"] = 0; |
|
| 72 | - $this->Default["LinkG"] = 0; |
|
| 73 | - $this->Default["LinkB"] = 0; |
|
| 74 | - $this->Default["LinkAlpha"] = 0; |
|
| 75 | - |
|
| 76 | - $this->Labels["Type"] = LABEL_CLASSIC; |
|
| 77 | - $this->Labels["R"] = 0; |
|
| 78 | - $this->Labels["G"] = 0; |
|
| 79 | - $this->Labels["B"] = 0; |
|
| 80 | - $this->Labels["Alpha"] = 100; |
|
| 81 | - |
|
| 82 | - $this->AutoComputeFreeZone = FALSE; |
|
| 34 | + var $History; |
|
| 35 | + var $pChartObject; |
|
| 36 | + var $Data; |
|
| 37 | + var $Links; |
|
| 38 | + var $X1; |
|
| 39 | + var $Y1; |
|
| 40 | + var $X2; |
|
| 41 | + var $Y2; |
|
| 42 | + var $AutoComputeFreeZone; |
|
| 43 | + var $Labels; |
|
| 44 | + |
|
| 45 | + /* Class creator */ |
|
| 46 | + function pSpring() |
|
| 47 | + { |
|
| 48 | + /* Initialise data arrays */ |
|
| 49 | + $this->Data = ""; |
|
| 50 | + $this->Links = ""; |
|
| 51 | + |
|
| 52 | + /* Set nodes defaults */ |
|
| 53 | + $this->Default["R"] = 255; |
|
| 54 | + $this->Default["G"] = 255; |
|
| 55 | + $this->Default["B"] = 255; |
|
| 56 | + $this->Default["Alpha"] = 100; |
|
| 57 | + $this->Default["BorderR"] = 0; |
|
| 58 | + $this->Default["BorderG"] = 0; |
|
| 59 | + $this->Default["BorderB"] = 0; |
|
| 60 | + $this->Default["BorderAlpha"] = 100; |
|
| 61 | + $this->Default["Surrounding"] = NULL; |
|
| 62 | + $this->Default["BackgroundR"] = 255; |
|
| 63 | + $this->Default["BackgroundG"] = 255; |
|
| 64 | + $this->Default["BackgroundB"] = 255; |
|
| 65 | + $this->Default["BackgroundAlpha"] = 0; |
|
| 66 | + $this->Default["Force"] = 1; |
|
| 67 | + $this->Default["NodeType"] = NODE_TYPE_FREE; |
|
| 68 | + $this->Default["Size"] = 5; |
|
| 69 | + $this->Default["Shape"] = NODE_SHAPE_CIRCLE; |
|
| 70 | + $this->Default["FreeZone"] = 40; |
|
| 71 | + $this->Default["LinkR"] = 0; |
|
| 72 | + $this->Default["LinkG"] = 0; |
|
| 73 | + $this->Default["LinkB"] = 0; |
|
| 74 | + $this->Default["LinkAlpha"] = 0; |
|
| 75 | + |
|
| 76 | + $this->Labels["Type"] = LABEL_CLASSIC; |
|
| 77 | + $this->Labels["R"] = 0; |
|
| 78 | + $this->Labels["G"] = 0; |
|
| 79 | + $this->Labels["B"] = 0; |
|
| 80 | + $this->Labels["Alpha"] = 100; |
|
| 81 | + |
|
| 82 | + $this->AutoComputeFreeZone = FALSE; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - /* Set default links options */ |
|
| 86 | - function setLinkDefaults($Settings="") |
|
| 85 | + /* Set default links options */ |
|
| 86 | + function setLinkDefaults($Settings="") |
|
| 87 | 87 | { |
| 88 | - if ( isset($Settings["R"]) ) { $this->Default["LinkR"] = $Settings["R"]; } |
|
| 89 | - if ( isset($Settings["G"]) ) { $this->Default["LinkG"] = $Settings["G"]; } |
|
| 90 | - if ( isset($Settings["B"]) ) { $this->Default["LinkB"] = $Settings["B"]; } |
|
| 91 | - if ( isset($Settings["Alpha"]) ) { $this->Default["LinkAlpha"] = $Settings["Alpha"]; } |
|
| 88 | + if ( isset($Settings["R"]) ) { $this->Default["LinkR"] = $Settings["R"]; } |
|
| 89 | + if ( isset($Settings["G"]) ) { $this->Default["LinkG"] = $Settings["G"]; } |
|
| 90 | + if ( isset($Settings["B"]) ) { $this->Default["LinkB"] = $Settings["B"]; } |
|
| 91 | + if ( isset($Settings["Alpha"]) ) { $this->Default["LinkAlpha"] = $Settings["Alpha"]; } |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - /* Set default links options */ |
|
| 95 | - function setLabelsSettings($Settings="") |
|
| 94 | + /* Set default links options */ |
|
| 95 | + function setLabelsSettings($Settings="") |
|
| 96 | 96 | { |
| 97 | - if ( isset($Settings["Type"]) ) { $this->Labels["Type"] = $Settings["Type"]; } |
|
| 98 | - if ( isset($Settings["R"]) ) { $this->Labels["R"] = $Settings["R"]; } |
|
| 99 | - if ( isset($Settings["G"]) ) { $this->Labels["G"] = $Settings["G"]; } |
|
| 100 | - if ( isset($Settings["B"]) ) { $this->Labels["B"] = $Settings["B"]; } |
|
| 101 | - if ( isset($Settings["Alpha"]) ) { $this->Labels["Alpha"] = $Settings["Alpha"]; } |
|
| 97 | + if ( isset($Settings["Type"]) ) { $this->Labels["Type"] = $Settings["Type"]; } |
|
| 98 | + if ( isset($Settings["R"]) ) { $this->Labels["R"] = $Settings["R"]; } |
|
| 99 | + if ( isset($Settings["G"]) ) { $this->Labels["G"] = $Settings["G"]; } |
|
| 100 | + if ( isset($Settings["B"]) ) { $this->Labels["B"] = $Settings["B"]; } |
|
| 101 | + if ( isset($Settings["Alpha"]) ) { $this->Labels["Alpha"] = $Settings["Alpha"]; } |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - /* Auto compute the FreeZone size based on the number of connections */ |
|
| 105 | - function autoFreeZone() |
|
| 104 | + /* Auto compute the FreeZone size based on the number of connections */ |
|
| 105 | + function autoFreeZone() |
|
| 106 | 106 | { |
| 107 | - /* Check connections reciprocity */ |
|
| 108 | - foreach($this->Data as $Key => $Settings) |
|
| 109 | - { |
|
| 110 | - if ( isset($Settings["Connections"]) ) |
|
| 107 | + /* Check connections reciprocity */ |
|
| 108 | + foreach($this->Data as $Key => $Settings) |
|
| 109 | + { |
|
| 110 | + if ( isset($Settings["Connections"]) ) |
|
| 111 | 111 | { $this->Data[$Key]["FreeZone"] = count($Settings["Connections"])*10 + 20; } |
| 112 | - else |
|
| 112 | + else |
|
| 113 | 113 | { $this->Data[$Key]["FreeZone"] = 20; } |
| 114 | - } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - /* Set link properties */ |
|
| 119 | - function linkProperties($FromNode,$ToNode,$Settings) |
|
| 118 | + /* Set link properties */ |
|
| 119 | + function linkProperties($FromNode,$ToNode,$Settings) |
|
| 120 | 120 | { |
| 121 | - if ( !isset($this->Data[$FromNode]) ) { return(0); } |
|
| 122 | - if ( !isset($this->Data[$ToNode]) ) { return(0); } |
|
| 123 | - |
|
| 124 | - $R = isset($Settings["R"]) ? $Settings["R"] : 0; |
|
| 125 | - $G = isset($Settings["G"]) ? $Settings["G"] : 0; |
|
| 126 | - $B = isset($Settings["B"]) ? $Settings["B"] : 0; |
|
| 127 | - $Alpha = isset($Settings["Alpha"]) ? $Settings["Alpha"] : 100; |
|
| 128 | - $Name = isset($Settings["Name"]) ? $Settings["Name"] : NULL; |
|
| 129 | - $Ticks = isset($Settings["Ticks"]) ? $Settings["Ticks"] : NULL; |
|
| 130 | - |
|
| 131 | - $this->Links[$FromNode][$ToNode]["R"] = $R; $this->Links[$ToNode][$FromNode]["R"] = $R; |
|
| 132 | - $this->Links[$FromNode][$ToNode]["G"] = $G; $this->Links[$ToNode][$FromNode]["G"] = $G; |
|
| 133 | - $this->Links[$FromNode][$ToNode]["B"] = $B; $this->Links[$ToNode][$FromNode]["B"] = $B; |
|
| 134 | - $this->Links[$FromNode][$ToNode]["Alpha"] = $Alpha; $this->Links[$ToNode][$FromNode]["Alpha"] = $Alpha; |
|
| 135 | - $this->Links[$FromNode][$ToNode]["Name"] = $Name; $this->Links[$ToNode][$FromNode]["Name"] = $Name; |
|
| 136 | - $this->Links[$FromNode][$ToNode]["Ticks"] = $Ticks; $this->Links[$ToNode][$FromNode]["Ticks"] = $Ticks; |
|
| 121 | + if ( !isset($this->Data[$FromNode]) ) { return(0); } |
|
| 122 | + if ( !isset($this->Data[$ToNode]) ) { return(0); } |
|
| 123 | + |
|
| 124 | + $R = isset($Settings["R"]) ? $Settings["R"] : 0; |
|
| 125 | + $G = isset($Settings["G"]) ? $Settings["G"] : 0; |
|
| 126 | + $B = isset($Settings["B"]) ? $Settings["B"] : 0; |
|
| 127 | + $Alpha = isset($Settings["Alpha"]) ? $Settings["Alpha"] : 100; |
|
| 128 | + $Name = isset($Settings["Name"]) ? $Settings["Name"] : NULL; |
|
| 129 | + $Ticks = isset($Settings["Ticks"]) ? $Settings["Ticks"] : NULL; |
|
| 130 | + |
|
| 131 | + $this->Links[$FromNode][$ToNode]["R"] = $R; $this->Links[$ToNode][$FromNode]["R"] = $R; |
|
| 132 | + $this->Links[$FromNode][$ToNode]["G"] = $G; $this->Links[$ToNode][$FromNode]["G"] = $G; |
|
| 133 | + $this->Links[$FromNode][$ToNode]["B"] = $B; $this->Links[$ToNode][$FromNode]["B"] = $B; |
|
| 134 | + $this->Links[$FromNode][$ToNode]["Alpha"] = $Alpha; $this->Links[$ToNode][$FromNode]["Alpha"] = $Alpha; |
|
| 135 | + $this->Links[$FromNode][$ToNode]["Name"] = $Name; $this->Links[$ToNode][$FromNode]["Name"] = $Name; |
|
| 136 | + $this->Links[$FromNode][$ToNode]["Ticks"] = $Ticks; $this->Links[$ToNode][$FromNode]["Ticks"] = $Ticks; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - function setNodeDefaults($Settings="") |
|
| 139 | + function setNodeDefaults($Settings="") |
|
| 140 | 140 | { |
| 141 | - if ( isset($Settings["R"]) ) { $this->Default["R"] = $Settings["R"]; } |
|
| 142 | - if ( isset($Settings["G"]) ) { $this->Default["G"] = $Settings["G"]; } |
|
| 143 | - if ( isset($Settings["B"]) ) { $this->Default["B"] = $Settings["B"]; } |
|
| 144 | - if ( isset($Settings["Alpha"]) ) { $this->Default["Alpha"] = $Settings["Alpha"]; } |
|
| 145 | - if ( isset($Settings["BorderR"]) ) { $this->Default["BorderR"] = $Settings["BorderR"]; } |
|
| 146 | - if ( isset($Settings["BorderG"]) ) { $this->Default["BorderG"] = $Settings["BorderG"]; } |
|
| 147 | - if ( isset($Settings["BorderB"]) ) { $this->Default["BorderB"] = $Settings["BorderB"]; } |
|
| 148 | - if ( isset($Settings["BorderAlpha"]) ) { $this->Default["BorderAlpha"] = $Settings["BorderAlpha"]; } |
|
| 149 | - if ( isset($Settings["Surrounding"]) ) { $this->Default["Surrounding"] = $Settings["Surrounding"]; } |
|
| 150 | - if ( isset($Settings["BackgroundR"]) ) { $this->Default["BackgroundR"] = $Settings["BackgroundR"]; } |
|
| 151 | - if ( isset($Settings["BackgroundG"]) ) { $this->Default["BackgroundG"] = $Settings["BackgroundG"]; } |
|
| 152 | - if ( isset($Settings["BackgroundB"]) ) { $this->Default["BackgroundB"] = $Settings["BackgroundB"]; } |
|
| 153 | - if ( isset($Settings["BackgroundAlpha"]) ) { $this->Default["BackgroundAlpha"] = $Settings["BackgroundAlpha"]; } |
|
| 154 | - if ( isset($Settings["NodeType"]) ) { $this->Default["NodeType"] = $Settings["NodeType"]; } |
|
| 155 | - if ( isset($Settings["Size"]) ) { $this->Default["Size"] = $Settings["Size"]; } |
|
| 156 | - if ( isset($Settings["Shape"]) ) { $this->Default["Shape"] = $Settings["Shape"]; } |
|
| 157 | - if ( isset($Settings["FreeZone"]) ) { $this->Default["FreeZone"] = $Settings["FreeZone"]; } |
|
| 141 | + if ( isset($Settings["R"]) ) { $this->Default["R"] = $Settings["R"]; } |
|
| 142 | + if ( isset($Settings["G"]) ) { $this->Default["G"] = $Settings["G"]; } |
|
| 143 | + if ( isset($Settings["B"]) ) { $this->Default["B"] = $Settings["B"]; } |
|
| 144 | + if ( isset($Settings["Alpha"]) ) { $this->Default["Alpha"] = $Settings["Alpha"]; } |
|
| 145 | + if ( isset($Settings["BorderR"]) ) { $this->Default["BorderR"] = $Settings["BorderR"]; } |
|
| 146 | + if ( isset($Settings["BorderG"]) ) { $this->Default["BorderG"] = $Settings["BorderG"]; } |
|
| 147 | + if ( isset($Settings["BorderB"]) ) { $this->Default["BorderB"] = $Settings["BorderB"]; } |
|
| 148 | + if ( isset($Settings["BorderAlpha"]) ) { $this->Default["BorderAlpha"] = $Settings["BorderAlpha"]; } |
|
| 149 | + if ( isset($Settings["Surrounding"]) ) { $this->Default["Surrounding"] = $Settings["Surrounding"]; } |
|
| 150 | + if ( isset($Settings["BackgroundR"]) ) { $this->Default["BackgroundR"] = $Settings["BackgroundR"]; } |
|
| 151 | + if ( isset($Settings["BackgroundG"]) ) { $this->Default["BackgroundG"] = $Settings["BackgroundG"]; } |
|
| 152 | + if ( isset($Settings["BackgroundB"]) ) { $this->Default["BackgroundB"] = $Settings["BackgroundB"]; } |
|
| 153 | + if ( isset($Settings["BackgroundAlpha"]) ) { $this->Default["BackgroundAlpha"] = $Settings["BackgroundAlpha"]; } |
|
| 154 | + if ( isset($Settings["NodeType"]) ) { $this->Default["NodeType"] = $Settings["NodeType"]; } |
|
| 155 | + if ( isset($Settings["Size"]) ) { $this->Default["Size"] = $Settings["Size"]; } |
|
| 156 | + if ( isset($Settings["Shape"]) ) { $this->Default["Shape"] = $Settings["Shape"]; } |
|
| 157 | + if ( isset($Settings["FreeZone"]) ) { $this->Default["FreeZone"] = $Settings["FreeZone"]; } |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - /* Add a node */ |
|
| 161 | - function addNode($NodeID,$Settings="") |
|
| 160 | + /* Add a node */ |
|
| 161 | + function addNode($NodeID,$Settings="") |
|
| 162 | 162 | { |
| 163 | - /* if the node already exists, ignore */ |
|
| 164 | - if (isset($this->Data[$NodeID])) { return(0); } |
|
| 165 | - |
|
| 166 | - $Name = isset($Settings["Name"]) ? $Settings["Name"] : "Node ".$NodeID; |
|
| 167 | - $Connections = isset($Settings["Connections"]) ? $Settings["Connections"] : NULL; |
|
| 168 | - |
|
| 169 | - $R = isset($Settings["R"]) ? $Settings["R"] : $this->Default["R"]; |
|
| 170 | - $G = isset($Settings["G"]) ? $Settings["G"] : $this->Default["G"]; |
|
| 171 | - $B = isset($Settings["B"]) ? $Settings["B"] : $this->Default["B"]; |
|
| 172 | - $Alpha = isset($Settings["Alpha"]) ? $Settings["Alpha"] : $this->Default["Alpha"]; |
|
| 173 | - $BorderR = isset($Settings["BorderR"]) ? $Settings["BorderR"] : $this->Default["BorderR"]; |
|
| 174 | - $BorderG = isset($Settings["BorderG"]) ? $Settings["BorderG"] : $this->Default["BorderG"]; |
|
| 175 | - $BorderB = isset($Settings["BorderB"]) ? $Settings["BorderB"] : $this->Default["BorderB"]; |
|
| 176 | - $BorderAlpha = isset($Settings["BorderAlpha"]) ? $Settings["BorderAlpha"] : $this->Default["BorderAlpha"]; |
|
| 177 | - $Surrounding = isset($Settings["Surrounding"]) ? $Settings["Surrounding"] : $this->Default["Surrounding"]; |
|
| 178 | - $BackgroundR = isset($Settings["BackgroundR"]) ? $Settings["BackgroundR"] : $this->Default["BackgroundR"]; |
|
| 179 | - $BackgroundG = isset($Settings["BackgroundG"]) ? $Settings["BackgroundG"] : $this->Default["BackgroundG"]; |
|
| 180 | - $BackgroundB = isset($Settings["BackgroundB"]) ? $Settings["BackgroundB"] : $this->Default["BackgroundB"]; |
|
| 181 | - $BackgroundAlpha = isset($Settings["BackgroundAlpha"]) ? $Settings["BackgroundAlpha"] : $this->Default["BackgroundAlpha"]; |
|
| 182 | - $Force = isset($Settings["Force"]) ? $Settings["Force"] : $this->Default["Force"]; |
|
| 183 | - $NodeType = isset($Settings["NodeType"]) ? $Settings["NodeType"] : $this->Default["NodeType"]; |
|
| 184 | - $Size = isset($Settings["Size"]) ? $Settings["Size"] : $this->Default["Size"]; |
|
| 185 | - $Shape = isset($Settings["Shape"]) ? $Settings["Shape"] : $this->Default["Shape"]; |
|
| 186 | - $FreeZone = isset($Settings["FreeZone"]) ? $Settings["FreeZone"] : $this->Default["FreeZone"]; |
|
| 187 | - |
|
| 188 | - if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; } |
|
| 189 | - |
|
| 190 | - $this->Data[$NodeID]["R"] = $R; $this->Data[$NodeID]["G"] = $G; $this->Data[$NodeID]["B"] = $B; $this->Data[$NodeID]["Alpha"] = $Alpha; |
|
| 191 | - $this->Data[$NodeID]["BorderR"] = $BorderR; $this->Data[$NodeID]["BorderG"] = $BorderG; $this->Data[$NodeID]["BorderB"] = $BorderB; $this->Data[$NodeID]["BorderAlpha"] = $BorderAlpha; |
|
| 192 | - $this->Data[$NodeID]["BackgroundR"] = $BackgroundR; $this->Data[$NodeID]["BackgroundG"] = $BackgroundG; $this->Data[$NodeID]["BackgroundB"] = $BackgroundB; $this->Data[$NodeID]["BackgroundAlpha"] = $BackgroundAlpha; |
|
| 193 | - $this->Data[$NodeID]["Name"] = $Name; |
|
| 194 | - $this->Data[$NodeID]["Force"] = $Force; |
|
| 195 | - $this->Data[$NodeID]["Type"] = $NodeType; |
|
| 196 | - $this->Data[$NodeID]["Size"] = $Size; |
|
| 197 | - $this->Data[$NodeID]["Shape"] = $Shape; |
|
| 198 | - $this->Data[$NodeID]["FreeZone"] = $FreeZone; |
|
| 199 | - if ( $Connections != NULL ) |
|
| 200 | - { |
|
| 201 | - if ( is_array($Connections ) ) |
|
| 202 | - { |
|
| 203 | - foreach($Connections as $Key => $Value) |
|
| 204 | - $this->Data[$NodeID]["Connections"][] = $Value; |
|
| 205 | - } |
|
| 206 | - else |
|
| 163 | + /* if the node already exists, ignore */ |
|
| 164 | + if (isset($this->Data[$NodeID])) { return(0); } |
|
| 165 | + |
|
| 166 | + $Name = isset($Settings["Name"]) ? $Settings["Name"] : "Node ".$NodeID; |
|
| 167 | + $Connections = isset($Settings["Connections"]) ? $Settings["Connections"] : NULL; |
|
| 168 | + |
|
| 169 | + $R = isset($Settings["R"]) ? $Settings["R"] : $this->Default["R"]; |
|
| 170 | + $G = isset($Settings["G"]) ? $Settings["G"] : $this->Default["G"]; |
|
| 171 | + $B = isset($Settings["B"]) ? $Settings["B"] : $this->Default["B"]; |
|
| 172 | + $Alpha = isset($Settings["Alpha"]) ? $Settings["Alpha"] : $this->Default["Alpha"]; |
|
| 173 | + $BorderR = isset($Settings["BorderR"]) ? $Settings["BorderR"] : $this->Default["BorderR"]; |
|
| 174 | + $BorderG = isset($Settings["BorderG"]) ? $Settings["BorderG"] : $this->Default["BorderG"]; |
|
| 175 | + $BorderB = isset($Settings["BorderB"]) ? $Settings["BorderB"] : $this->Default["BorderB"]; |
|
| 176 | + $BorderAlpha = isset($Settings["BorderAlpha"]) ? $Settings["BorderAlpha"] : $this->Default["BorderAlpha"]; |
|
| 177 | + $Surrounding = isset($Settings["Surrounding"]) ? $Settings["Surrounding"] : $this->Default["Surrounding"]; |
|
| 178 | + $BackgroundR = isset($Settings["BackgroundR"]) ? $Settings["BackgroundR"] : $this->Default["BackgroundR"]; |
|
| 179 | + $BackgroundG = isset($Settings["BackgroundG"]) ? $Settings["BackgroundG"] : $this->Default["BackgroundG"]; |
|
| 180 | + $BackgroundB = isset($Settings["BackgroundB"]) ? $Settings["BackgroundB"] : $this->Default["BackgroundB"]; |
|
| 181 | + $BackgroundAlpha = isset($Settings["BackgroundAlpha"]) ? $Settings["BackgroundAlpha"] : $this->Default["BackgroundAlpha"]; |
|
| 182 | + $Force = isset($Settings["Force"]) ? $Settings["Force"] : $this->Default["Force"]; |
|
| 183 | + $NodeType = isset($Settings["NodeType"]) ? $Settings["NodeType"] : $this->Default["NodeType"]; |
|
| 184 | + $Size = isset($Settings["Size"]) ? $Settings["Size"] : $this->Default["Size"]; |
|
| 185 | + $Shape = isset($Settings["Shape"]) ? $Settings["Shape"] : $this->Default["Shape"]; |
|
| 186 | + $FreeZone = isset($Settings["FreeZone"]) ? $Settings["FreeZone"] : $this->Default["FreeZone"]; |
|
| 187 | + |
|
| 188 | + if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; } |
|
| 189 | + |
|
| 190 | + $this->Data[$NodeID]["R"] = $R; $this->Data[$NodeID]["G"] = $G; $this->Data[$NodeID]["B"] = $B; $this->Data[$NodeID]["Alpha"] = $Alpha; |
|
| 191 | + $this->Data[$NodeID]["BorderR"] = $BorderR; $this->Data[$NodeID]["BorderG"] = $BorderG; $this->Data[$NodeID]["BorderB"] = $BorderB; $this->Data[$NodeID]["BorderAlpha"] = $BorderAlpha; |
|
| 192 | + $this->Data[$NodeID]["BackgroundR"] = $BackgroundR; $this->Data[$NodeID]["BackgroundG"] = $BackgroundG; $this->Data[$NodeID]["BackgroundB"] = $BackgroundB; $this->Data[$NodeID]["BackgroundAlpha"] = $BackgroundAlpha; |
|
| 193 | + $this->Data[$NodeID]["Name"] = $Name; |
|
| 194 | + $this->Data[$NodeID]["Force"] = $Force; |
|
| 195 | + $this->Data[$NodeID]["Type"] = $NodeType; |
|
| 196 | + $this->Data[$NodeID]["Size"] = $Size; |
|
| 197 | + $this->Data[$NodeID]["Shape"] = $Shape; |
|
| 198 | + $this->Data[$NodeID]["FreeZone"] = $FreeZone; |
|
| 199 | + if ( $Connections != NULL ) |
|
| 200 | + { |
|
| 201 | + if ( is_array($Connections ) ) |
|
| 202 | + { |
|
| 203 | + foreach($Connections as $Key => $Value) |
|
| 204 | + $this->Data[$NodeID]["Connections"][] = $Value; |
|
| 205 | + } |
|
| 206 | + else |
|
| 207 | 207 | $this->Data[$NodeID]["Connections"][] = $Connections; |
| 208 | - } |
|
| 208 | + } |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - /* Set color attribute for a list of nodes */ |
|
| 212 | - function setNodesColor($Nodes,$Settings="") |
|
| 211 | + /* Set color attribute for a list of nodes */ |
|
| 212 | + function setNodesColor($Nodes,$Settings="") |
|
| 213 | 213 | { |
| 214 | - if ( is_array($Nodes) ) |
|
| 215 | - { |
|
| 216 | - foreach ($Nodes as $Key => $NodeID) |
|
| 217 | - { |
|
| 218 | - if (isset($this->Data[$NodeID]) ) |
|
| 219 | - { |
|
| 220 | - if ( isset($Settings["R"]) ) { $this->Data[$NodeID]["R"] = $Settings["R"]; } |
|
| 221 | - if ( isset($Settings["G"]) ) { $this->Data[$NodeID]["G"] = $Settings["G"]; } |
|
| 222 | - if ( isset($Settings["B"]) ) { $this->Data[$NodeID]["B"] = $Settings["B"]; } |
|
| 223 | - if ( isset($Settings["Alpha"]) ) { $this->Data[$NodeID]["Alpha"] = $Settings["Alpha"]; } |
|
| 224 | - if ( isset($Settings["BorderR"]) ) { $this->Data[$NodeID]["BorderR"] = $Settings["BorderR"]; } |
|
| 225 | - if ( isset($Settings["BorderG"]) ) { $this->Data[$NodeID]["BorderG"] = $Settings["BorderG"]; } |
|
| 226 | - if ( isset($Settings["BorderB"]) ) { $this->Data[$NodeID]["BorderB"] = $Settings["BorderB"]; } |
|
| 227 | - if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$NodeID]["BorderAlpha"] = $Settings["BorderAlpha"]; } |
|
| 228 | - if ( isset($Settings["Surrounding"]) ) { $this->Data[$NodeID]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - else |
|
| 233 | - { |
|
| 234 | - if ( isset($Settings["R"]) ) { $this->Data[$Nodes]["R"] = $Settings["R"]; } |
|
| 235 | - if ( isset($Settings["G"]) ) { $this->Data[$Nodes]["G"] = $Settings["G"]; } |
|
| 236 | - if ( isset($Settings["B"]) ) { $this->Data[$Nodes]["B"] = $Settings["B"]; } |
|
| 237 | - if ( isset($Settings["Alpha"]) ) { $this->Data[$Nodes]["Alpha"] = $Settings["Alpha"]; } |
|
| 238 | - if ( isset($Settings["BorderR"]) ) { $this->Data[$Nodes]["BorderR"] = $Settings["BorderR"]; } |
|
| 239 | - if ( isset($Settings["BorderG"]) ) { $this->Data[$Nodes]["BorderG"] = $Settings["BorderG"]; } |
|
| 240 | - if ( isset($Settings["BorderB"]) ) { $this->Data[$Nodes]["BorderB"] = $Settings["BorderB"]; } |
|
| 241 | - if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$Nodes]["BorderAlpha"] = $Settings["BorderAlpha"]; } |
|
| 242 | - if ( isset($Settings["Surrounding"]) ) { $this->Data[$Nodes]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; } |
|
| 243 | - } |
|
| 214 | + if ( is_array($Nodes) ) |
|
| 215 | + { |
|
| 216 | + foreach ($Nodes as $Key => $NodeID) |
|
| 217 | + { |
|
| 218 | + if (isset($this->Data[$NodeID]) ) |
|
| 219 | + { |
|
| 220 | + if ( isset($Settings["R"]) ) { $this->Data[$NodeID]["R"] = $Settings["R"]; } |
|
| 221 | + if ( isset($Settings["G"]) ) { $this->Data[$NodeID]["G"] = $Settings["G"]; } |
|
| 222 | + if ( isset($Settings["B"]) ) { $this->Data[$NodeID]["B"] = $Settings["B"]; } |
|
| 223 | + if ( isset($Settings["Alpha"]) ) { $this->Data[$NodeID]["Alpha"] = $Settings["Alpha"]; } |
|
| 224 | + if ( isset($Settings["BorderR"]) ) { $this->Data[$NodeID]["BorderR"] = $Settings["BorderR"]; } |
|
| 225 | + if ( isset($Settings["BorderG"]) ) { $this->Data[$NodeID]["BorderG"] = $Settings["BorderG"]; } |
|
| 226 | + if ( isset($Settings["BorderB"]) ) { $this->Data[$NodeID]["BorderB"] = $Settings["BorderB"]; } |
|
| 227 | + if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$NodeID]["BorderAlpha"] = $Settings["BorderAlpha"]; } |
|
| 228 | + if ( isset($Settings["Surrounding"]) ) { $this->Data[$NodeID]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + else |
|
| 233 | + { |
|
| 234 | + if ( isset($Settings["R"]) ) { $this->Data[$Nodes]["R"] = $Settings["R"]; } |
|
| 235 | + if ( isset($Settings["G"]) ) { $this->Data[$Nodes]["G"] = $Settings["G"]; } |
|
| 236 | + if ( isset($Settings["B"]) ) { $this->Data[$Nodes]["B"] = $Settings["B"]; } |
|
| 237 | + if ( isset($Settings["Alpha"]) ) { $this->Data[$Nodes]["Alpha"] = $Settings["Alpha"]; } |
|
| 238 | + if ( isset($Settings["BorderR"]) ) { $this->Data[$Nodes]["BorderR"] = $Settings["BorderR"]; } |
|
| 239 | + if ( isset($Settings["BorderG"]) ) { $this->Data[$Nodes]["BorderG"] = $Settings["BorderG"]; } |
|
| 240 | + if ( isset($Settings["BorderB"]) ) { $this->Data[$Nodes]["BorderB"] = $Settings["BorderB"]; } |
|
| 241 | + if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$Nodes]["BorderAlpha"] = $Settings["BorderAlpha"]; } |
|
| 242 | + if ( isset($Settings["Surrounding"]) ) { $this->Data[$Nodes]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; } |
|
| 243 | + } |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - /* Returns all the nodes details */ |
|
| 247 | - function dumpNodes() |
|
| 246 | + /* Returns all the nodes details */ |
|
| 247 | + function dumpNodes() |
|
| 248 | 248 | { return($this->Data); } |
| 249 | 249 | |
| 250 | - /* Check if a connection exists and create it if required */ |
|
| 251 | - function checkConnection($SourceID, $TargetID) |
|
| 250 | + /* Check if a connection exists and create it if required */ |
|
| 251 | + function checkConnection($SourceID, $TargetID) |
|
| 252 | 252 | { |
| 253 | - if ( isset($this->Data[$SourceID]["Connections"]) ) |
|
| 254 | - { |
|
| 255 | - foreach ($this->Data[$SourceID]["Connections"] as $Key => $ConnectionID) |
|
| 253 | + if ( isset($this->Data[$SourceID]["Connections"]) ) |
|
| 254 | + { |
|
| 255 | + foreach ($this->Data[$SourceID]["Connections"] as $Key => $ConnectionID) |
|
| 256 | 256 | { if ( $TargetID == $ConnectionID ) { return(TRUE); } } |
| 257 | - } |
|
| 258 | - $this->Data[$SourceID]["Connections"][] = $TargetID; |
|
| 257 | + } |
|
| 258 | + $this->Data[$SourceID]["Connections"][] = $TargetID; |
|
| 259 | 259 | } |
| 260 | - /* Get the median linked nodes position */ |
|
| 261 | - function getMedianOffset($Key,$X,$Y) |
|
| 260 | + /* Get the median linked nodes position */ |
|
| 261 | + function getMedianOffset($Key,$X,$Y) |
|
| 262 | 262 | { |
| 263 | - $Cpt = 1; |
|
| 264 | - if ( isset($this->Data[$Key]["Connections"]) ) |
|
| 265 | - { |
|
| 266 | - foreach($this->Data[$Key]["Connections"] as $ID => $NodeID) |
|
| 267 | - { |
|
| 268 | - if ( isset($this->Data[$NodeID]["X"]) && isset($this->Data[$NodeID]["Y"]) ) |
|
| 269 | - { |
|
| 270 | - $X = $X + $this->Data[$NodeID]["X"]; |
|
| 271 | - $Y = $Y + $this->Data[$NodeID]["Y"]; |
|
| 272 | - $Cpt++; |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - return(array("X"=>$X/$Cpt,"Y"=>$Y/$Cpt)); |
|
| 263 | + $Cpt = 1; |
|
| 264 | + if ( isset($this->Data[$Key]["Connections"]) ) |
|
| 265 | + { |
|
| 266 | + foreach($this->Data[$Key]["Connections"] as $ID => $NodeID) |
|
| 267 | + { |
|
| 268 | + if ( isset($this->Data[$NodeID]["X"]) && isset($this->Data[$NodeID]["Y"]) ) |
|
| 269 | + { |
|
| 270 | + $X = $X + $this->Data[$NodeID]["X"]; |
|
| 271 | + $Y = $Y + $this->Data[$NodeID]["Y"]; |
|
| 272 | + $Cpt++; |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + return(array("X"=>$X/$Cpt,"Y"=>$Y/$Cpt)); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - /* Return the ID of the attached partner with the biggest weight */ |
|
| 280 | - function getBiggestPartner($Key) |
|
| 279 | + /* Return the ID of the attached partner with the biggest weight */ |
|
| 280 | + function getBiggestPartner($Key) |
|
| 281 | 281 | { |
| 282 | - if ( !isset($this->Data[$Key]["Connections"]) ) { return(""); } |
|
| 282 | + if ( !isset($this->Data[$Key]["Connections"]) ) { return(""); } |
|
| 283 | 283 | |
| 284 | - $MaxWeight = 0; $Result = ""; |
|
| 285 | - foreach($this->Data[$Key]["Connections"] as $Key => $PeerID) |
|
| 286 | - { |
|
| 287 | - if ( $this->Data[$PeerID]["Weight"] > $MaxWeight ) |
|
| 284 | + $MaxWeight = 0; $Result = ""; |
|
| 285 | + foreach($this->Data[$Key]["Connections"] as $Key => $PeerID) |
|
| 286 | + { |
|
| 287 | + if ( $this->Data[$PeerID]["Weight"] > $MaxWeight ) |
|
| 288 | 288 | { $MaxWeight = $this->Data[$PeerID]["Weight"]; $Result = $PeerID; } |
| 289 | - } |
|
| 290 | - return($Result); |
|
| 289 | + } |
|
| 290 | + return($Result); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - /* Do the initial node positions computing pass */ |
|
| 294 | - function firstPass($Algorithm) |
|
| 293 | + /* Do the initial node positions computing pass */ |
|
| 294 | + function firstPass($Algorithm) |
|
| 295 | 295 | { |
| 296 | - $CenterX = ($this->X2 - $this->X1) / 2 + $this->X1; |
|
| 297 | - $CenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1; |
|
| 296 | + $CenterX = ($this->X2 - $this->X1) / 2 + $this->X1; |
|
| 297 | + $CenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1; |
|
| 298 | 298 | |
| 299 | - /* Check connections reciprocity */ |
|
| 300 | - foreach($this->Data as $Key => $Settings) |
|
| 301 | - { |
|
| 302 | - if ( isset($Settings["Connections"]) ) |
|
| 299 | + /* Check connections reciprocity */ |
|
| 300 | + foreach($this->Data as $Key => $Settings) |
|
| 301 | + { |
|
| 302 | + if ( isset($Settings["Connections"]) ) |
|
| 303 | 303 | { |
| 304 | - foreach($Settings["Connections"] as $ID => $ConnectionID) |
|
| 305 | - $this->checkConnection($ConnectionID,$Key); |
|
| 304 | + foreach($Settings["Connections"] as $ID => $ConnectionID) |
|
| 305 | + $this->checkConnection($ConnectionID,$Key); |
|
| 306 | + } |
|
| 306 | 307 | } |
| 307 | - } |
|
| 308 | 308 | |
| 309 | - if ( $this->AutoComputeFreeZone ) { $this->autoFreeZone(); } |
|
| 309 | + if ( $this->AutoComputeFreeZone ) { $this->autoFreeZone(); } |
|
| 310 | 310 | |
| 311 | - /* Get the max number of connections */ |
|
| 312 | - $MaxConnections = 0; |
|
| 313 | - foreach($this->Data as $Key => $Settings) |
|
| 314 | - { if ( isset($Settings["Connections"]) ) { if ( $MaxConnections < count($Settings["Connections"] ) ) { $MaxConnections = count($Settings["Connections"]); } } } |
|
| 311 | + /* Get the max number of connections */ |
|
| 312 | + $MaxConnections = 0; |
|
| 313 | + foreach($this->Data as $Key => $Settings) |
|
| 314 | + { if ( isset($Settings["Connections"]) ) { if ( $MaxConnections < count($Settings["Connections"] ) ) { $MaxConnections = count($Settings["Connections"]); } } } |
|
| 315 | 315 | |
| 316 | - if ( $Algorithm == ALGORITHM_WEIGHTED ) |
|
| 317 | - { |
|
| 318 | - foreach($this->Data as $Key => $Settings) |
|
| 316 | + if ( $Algorithm == ALGORITHM_WEIGHTED ) |
|
| 317 | + { |
|
| 318 | + foreach($this->Data as $Key => $Settings) |
|
| 319 | 319 | { |
| 320 | - if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 321 | - if ( $Settings["Type"] == NODE_TYPE_FREE ) |
|
| 322 | - { |
|
| 323 | - if ( isset($Settings["Connections"]) ) |
|
| 320 | + if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 321 | + if ( $Settings["Type"] == NODE_TYPE_FREE ) |
|
| 322 | + { |
|
| 323 | + if ( isset($Settings["Connections"]) ) |
|
| 324 | 324 | { $Connections = count($Settings["Connections"]); } |
| 325 | - else |
|
| 325 | + else |
|
| 326 | 326 | { $Connections = 0; } |
| 327 | 327 | |
| 328 | - $Ring = $MaxConnections - $Connections; |
|
| 329 | - $Angle = rand(0,360); |
|
| 328 | + $Ring = $MaxConnections - $Connections; |
|
| 329 | + $Angle = rand(0,360); |
|
| 330 | 330 | |
| 331 | - $this->Data[$Key]["X"] = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX; |
|
| 332 | - $this->Data[$Key]["Y"] = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY; |
|
| 333 | - } |
|
| 331 | + $this->Data[$Key]["X"] = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX; |
|
| 332 | + $this->Data[$Key]["Y"] = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY; |
|
| 333 | + } |
|
| 334 | 334 | } |
| 335 | - } |
|
| 336 | - elseif ( $Algorithm == ALGORITHM_CENTRAL ) |
|
| 337 | - { |
|
| 338 | - /* Put a weight on each nodes */ |
|
| 339 | - foreach($this->Data as $Key => $Settings) |
|
| 335 | + } |
|
| 336 | + elseif ( $Algorithm == ALGORITHM_CENTRAL ) |
|
| 337 | + { |
|
| 338 | + /* Put a weight on each nodes */ |
|
| 339 | + foreach($this->Data as $Key => $Settings) |
|
| 340 | 340 | { |
| 341 | - if ( isset($Settings["Connections"]) ) |
|
| 342 | - $this->Data[$Key]["Weight"] = count($Settings["Connections"]); |
|
| 343 | - else |
|
| 344 | - $this->Data[$Key]["Weight"] = 0; |
|
| 341 | + if ( isset($Settings["Connections"]) ) |
|
| 342 | + $this->Data[$Key]["Weight"] = count($Settings["Connections"]); |
|
| 343 | + else |
|
| 344 | + $this->Data[$Key]["Weight"] = 0; |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - $MaxConnections = $MaxConnections + 1; |
|
| 348 | - for($i=$MaxConnections;$i>=0;$i--) |
|
| 347 | + $MaxConnections = $MaxConnections + 1; |
|
| 348 | + for($i=$MaxConnections;$i>=0;$i--) |
|
| 349 | 349 | { |
| 350 | - foreach($this->Data as $Key => $Settings) |
|
| 351 | - { |
|
| 352 | - if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 353 | - if ( $Settings["Type"] == NODE_TYPE_FREE ) |
|
| 350 | + foreach($this->Data as $Key => $Settings) |
|
| 354 | 351 | { |
| 355 | - if ( isset($Settings["Connections"]) ) |
|
| 356 | - { $Connections = count($Settings["Connections"]); } |
|
| 357 | - else |
|
| 358 | - { $Connections = 0; } |
|
| 359 | - |
|
| 360 | - if ( $Connections == $i ) |
|
| 361 | - { |
|
| 362 | - $BiggestPartner = $this->getBiggestPartner($Key); |
|
| 363 | - if ( $BiggestPartner != "" ) |
|
| 352 | + if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 353 | + if ( $Settings["Type"] == NODE_TYPE_FREE ) |
|
| 354 | + { |
|
| 355 | + if ( isset($Settings["Connections"]) ) |
|
| 356 | + { $Connections = count($Settings["Connections"]); } |
|
| 357 | + else |
|
| 358 | + { $Connections = 0; } |
|
| 359 | + |
|
| 360 | + if ( $Connections == $i ) |
|
| 364 | 361 | { |
| 365 | - $Ring = $this->Data[$BiggestPartner]["FreeZone"]; |
|
| 366 | - $Weight = $this->Data[$BiggestPartner]["Weight"]; |
|
| 367 | - $AngleDivision = 360 / $this->Data[$BiggestPartner]["Weight"]; |
|
| 368 | - $Done = FALSE; $Tries = 0; |
|
| 369 | - while (!$Done && $Tries <= $Weight*2) |
|
| 370 | - { |
|
| 371 | - $Tries++; |
|
| 372 | - $Angle = floor(rand(0,$Weight)*$AngleDivision); |
|
| 373 | - if ( !isset($this->Data[$BiggestPartner]["Angular"][$Angle]) || !isset($this->Data[$BiggestPartner]["Angular"]) ) |
|
| 362 | + $BiggestPartner = $this->getBiggestPartner($Key); |
|
| 363 | + if ( $BiggestPartner != "" ) |
|
| 364 | + { |
|
| 365 | + $Ring = $this->Data[$BiggestPartner]["FreeZone"]; |
|
| 366 | + $Weight = $this->Data[$BiggestPartner]["Weight"]; |
|
| 367 | + $AngleDivision = 360 / $this->Data[$BiggestPartner]["Weight"]; |
|
| 368 | + $Done = FALSE; $Tries = 0; |
|
| 369 | + while (!$Done && $Tries <= $Weight*2) |
|
| 370 | + { |
|
| 371 | + $Tries++; |
|
| 372 | + $Angle = floor(rand(0,$Weight)*$AngleDivision); |
|
| 373 | + if ( !isset($this->Data[$BiggestPartner]["Angular"][$Angle]) || !isset($this->Data[$BiggestPartner]["Angular"]) ) |
|
| 374 | 374 | { |
| 375 | - $this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle; |
|
| 376 | - $Done = TRUE; |
|
| 375 | + $this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle; |
|
| 376 | + $Done = TRUE; |
|
| 377 | 377 | } |
| 378 | - } |
|
| 379 | - if ( !$Done ) |
|
| 380 | - { $Angle = rand(0,360); $this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle; } |
|
| 378 | + } |
|
| 379 | + if ( !$Done ) |
|
| 380 | + { $Angle = rand(0,360); $this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle; } |
|
| 381 | 381 | |
| 382 | - $X = cos(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["X"]; |
|
| 383 | - $Y = sin(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["Y"]; |
|
| 382 | + $X = cos(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["X"]; |
|
| 383 | + $Y = sin(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["Y"]; |
|
| 384 | 384 | |
| 385 | - $this->Data[$Key]["X"] = $X; |
|
| 386 | - $this->Data[$Key]["Y"] = $Y; |
|
| 385 | + $this->Data[$Key]["X"] = $X; |
|
| 386 | + $this->Data[$Key]["Y"] = $Y; |
|
| 387 | + } |
|
| 387 | 388 | } |
| 388 | - } |
|
| 389 | 389 | } |
| 390 | - } |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - elseif ( $Algorithm == ALGORITHM_CIRCULAR ) |
|
| 394 | - { |
|
| 395 | - $MaxConnections = $MaxConnections + 1; |
|
| 396 | - for($i=$MaxConnections;$i>=0;$i--) |
|
| 397 | - { |
|
| 398 | - foreach($this->Data as $Key => $Settings) |
|
| 399 | - { |
|
| 400 | - if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 401 | - if ( $Settings["Type"] == NODE_TYPE_FREE ) |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + elseif ( $Algorithm == ALGORITHM_CIRCULAR ) |
|
| 394 | + { |
|
| 395 | + $MaxConnections = $MaxConnections + 1; |
|
| 396 | + for($i=$MaxConnections;$i>=0;$i--) |
|
| 397 | + { |
|
| 398 | + foreach($this->Data as $Key => $Settings) |
|
| 399 | + { |
|
| 400 | + if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 401 | + if ( $Settings["Type"] == NODE_TYPE_FREE ) |
|
| 402 | 402 | { |
| 403 | - if ( isset($Settings["Connections"]) ) |
|
| 404 | - { $Connections = count($Settings["Connections"]); } |
|
| 405 | - else |
|
| 406 | - { $Connections = 0; } |
|
| 403 | + if ( isset($Settings["Connections"]) ) |
|
| 404 | + { $Connections = count($Settings["Connections"]); } |
|
| 405 | + else |
|
| 406 | + { $Connections = 0; } |
|
| 407 | 407 | |
| 408 | - if ( $Connections == $i ) |
|
| 409 | - { |
|
| 410 | - $Ring = $MaxConnections - $Connections; |
|
| 411 | - $Angle = rand(0,360); |
|
| 408 | + if ( $Connections == $i ) |
|
| 409 | + { |
|
| 410 | + $Ring = $MaxConnections - $Connections; |
|
| 411 | + $Angle = rand(0,360); |
|
| 412 | 412 | |
| 413 | - $X = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX; |
|
| 414 | - $Y = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY; |
|
| 413 | + $X = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX; |
|
| 414 | + $Y = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY; |
|
| 415 | 415 | |
| 416 | - $MedianOffset = $this->getMedianOffset($Key,$X,$Y); |
|
| 416 | + $MedianOffset = $this->getMedianOffset($Key,$X,$Y); |
|
| 417 | 417 | |
| 418 | - $this->Data[$Key]["X"] = $MedianOffset["X"]; |
|
| 419 | - $this->Data[$Key]["Y"] = $MedianOffset["Y"]; |
|
| 420 | - } |
|
| 418 | + $this->Data[$Key]["X"] = $MedianOffset["X"]; |
|
| 419 | + $this->Data[$Key]["Y"] = $MedianOffset["Y"]; |
|
| 420 | + } |
|
| 421 | 421 | } |
| 422 | - } |
|
| 422 | + } |
|
| 423 | + } |
|
| 423 | 424 | } |
| 424 | - } |
|
| 425 | - elseif ( $Algorithm == ALGORITHM_RANDOM ) |
|
| 426 | - { |
|
| 427 | - foreach($this->Data as $Key => $Settings) |
|
| 425 | + elseif ( $Algorithm == ALGORITHM_RANDOM ) |
|
| 428 | 426 | { |
| 429 | - if ( $Settings["Type"] == NODE_TYPE_FREE ) |
|
| 430 | - { |
|
| 431 | - $this->Data[$Key]["X"] = $CenterX + rand(-20,20); |
|
| 432 | - $this->Data[$Key]["Y"] = $CenterY + rand(-20,20); |
|
| 433 | - } |
|
| 434 | - if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 427 | + foreach($this->Data as $Key => $Settings) |
|
| 428 | + { |
|
| 429 | + if ( $Settings["Type"] == NODE_TYPE_FREE ) |
|
| 430 | + { |
|
| 431 | + $this->Data[$Key]["X"] = $CenterX + rand(-20,20); |
|
| 432 | + $this->Data[$Key]["Y"] = $CenterY + rand(-20,20); |
|
| 433 | + } |
|
| 434 | + if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 435 | + } |
|
| 435 | 436 | } |
| 436 | - } |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | - /* Compute one pass */ |
|
| 440 | - function doPass() |
|
| 439 | + /* Compute one pass */ |
|
| 440 | + function doPass() |
|
| 441 | 441 | { |
| 442 | - /* Compute vectors */ |
|
| 443 | - foreach($this->Data as $Key => $Settings) |
|
| 444 | - { |
|
| 445 | - if ( $Settings["Type"] != NODE_TYPE_CENTRAL ) |
|
| 442 | + /* Compute vectors */ |
|
| 443 | + foreach($this->Data as $Key => $Settings) |
|
| 446 | 444 | { |
| 447 | - unset($this->Data[$Key]["Vectors"]); |
|
| 445 | + if ( $Settings["Type"] != NODE_TYPE_CENTRAL ) |
|
| 446 | + { |
|
| 447 | + unset($this->Data[$Key]["Vectors"]); |
|
| 448 | 448 | |
| 449 | - $X1 = $Settings["X"]; |
|
| 450 | - $Y1 = $Settings["Y"]; |
|
| 449 | + $X1 = $Settings["X"]; |
|
| 450 | + $Y1 = $Settings["Y"]; |
|
| 451 | 451 | |
| 452 | - /* Repulsion vectors */ |
|
| 453 | - foreach($this->Data as $Key2 => $Settings2) |
|
| 454 | - { |
|
| 455 | - if ( $Key != $Key2 ) |
|
| 452 | + /* Repulsion vectors */ |
|
| 453 | + foreach($this->Data as $Key2 => $Settings2) |
|
| 454 | + { |
|
| 455 | + if ( $Key != $Key2 ) |
|
| 456 | 456 | { |
| 457 | - $X2 = $this->Data[$Key2]["X"]; |
|
| 458 | - $Y2 = $this->Data[$Key2]["Y"]; |
|
| 459 | - $FreeZone = $this->Data[$Key2]["FreeZone"]; |
|
| 460 | - |
|
| 461 | - $Distance = $this->getDistance($X1,$Y1,$X2,$Y2); |
|
| 462 | - $Angle = $this->getAngle($X1,$Y1,$X2,$Y2) + 180; |
|
| 463 | - |
|
| 464 | - /* Nodes too close, repulsion occurs */ |
|
| 465 | - if ( $Distance < $FreeZone ) |
|
| 466 | - { |
|
| 467 | - $Force = log(pow(2,$FreeZone-$Distance)); |
|
| 468 | - if ( $Force > 1 ) |
|
| 457 | + $X2 = $this->Data[$Key2]["X"]; |
|
| 458 | + $Y2 = $this->Data[$Key2]["Y"]; |
|
| 459 | + $FreeZone = $this->Data[$Key2]["FreeZone"]; |
|
| 460 | + |
|
| 461 | + $Distance = $this->getDistance($X1,$Y1,$X2,$Y2); |
|
| 462 | + $Angle = $this->getAngle($X1,$Y1,$X2,$Y2) + 180; |
|
| 463 | + |
|
| 464 | + /* Nodes too close, repulsion occurs */ |
|
| 465 | + if ( $Distance < $FreeZone ) |
|
| 466 | + { |
|
| 467 | + $Force = log(pow(2,$FreeZone-$Distance)); |
|
| 468 | + if ( $Force > 1 ) |
|
| 469 | 469 | { $this->Data[$Key]["Vectors"][] = array("Type"=>"R","Angle"=>$Angle % 360,"Force"=>$Force); } |
| 470 | - } |
|
| 470 | + } |
|
| 471 | + } |
|
| 471 | 472 | } |
| 472 | - } |
|
| 473 | 473 | |
| 474 | - /* Attraction vectors */ |
|
| 475 | - if ( isset($Settings["Connections"]) ) |
|
| 476 | - { |
|
| 477 | - foreach($Settings["Connections"] as $ID => $NodeID) |
|
| 474 | + /* Attraction vectors */ |
|
| 475 | + if ( isset($Settings["Connections"]) ) |
|
| 478 | 476 | { |
| 479 | - if ( isset($this->Data[$NodeID]) ) |
|
| 480 | - { |
|
| 481 | - $X2 = $this->Data[$NodeID]["X"]; |
|
| 482 | - $Y2 = $this->Data[$NodeID]["Y"]; |
|
| 483 | - $FreeZone = $this->Data[$Key2]["FreeZone"]; |
|
| 477 | + foreach($Settings["Connections"] as $ID => $NodeID) |
|
| 478 | + { |
|
| 479 | + if ( isset($this->Data[$NodeID]) ) |
|
| 480 | + { |
|
| 481 | + $X2 = $this->Data[$NodeID]["X"]; |
|
| 482 | + $Y2 = $this->Data[$NodeID]["Y"]; |
|
| 483 | + $FreeZone = $this->Data[$Key2]["FreeZone"]; |
|
| 484 | 484 | |
| 485 | - $Distance = $this->getDistance($X1,$Y1,$X2,$Y2); |
|
| 486 | - $Angle = $this->getAngle($X1,$Y1,$X2,$Y2); |
|
| 485 | + $Distance = $this->getDistance($X1,$Y1,$X2,$Y2); |
|
| 486 | + $Angle = $this->getAngle($X1,$Y1,$X2,$Y2); |
|
| 487 | 487 | |
| 488 | - if ( $Distance > $FreeZone ) |
|
| 488 | + if ( $Distance > $FreeZone ) |
|
| 489 | 489 | $Force = log(($Distance-$FreeZone)+1); |
| 490 | - else |
|
| 490 | + else |
|
| 491 | 491 | { $Force = log(($FreeZone-$Distance)+1); ($Angle = $Angle + 180); } |
| 492 | 492 | |
| 493 | - if ( $Force > 1 ) |
|
| 493 | + if ( $Force > 1 ) |
|
| 494 | 494 | $this->Data[$Key]["Vectors"][] = array("Type"=>"A","Angle"=>$Angle % 360,"Force"=>$Force); |
| 495 | - } |
|
| 495 | + } |
|
| 496 | + } |
|
| 496 | 497 | } |
| 497 | - } |
|
| 498 | 498 | } |
| 499 | - } |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | - /* Move the nodes accoding to the vectors */ |
|
| 502 | - foreach($this->Data as $Key => $Settings) |
|
| 503 | - { |
|
| 504 | - $X = $Settings["X"]; |
|
| 505 | - $Y = $Settings["Y"]; |
|
| 501 | + /* Move the nodes accoding to the vectors */ |
|
| 502 | + foreach($this->Data as $Key => $Settings) |
|
| 503 | + { |
|
| 504 | + $X = $Settings["X"]; |
|
| 505 | + $Y = $Settings["Y"]; |
|
| 506 | 506 | |
| 507 | - if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL ) |
|
| 507 | + if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL ) |
|
| 508 | 508 | { |
| 509 | - foreach($Settings["Vectors"] as $ID => $Vector) |
|
| 510 | - { |
|
| 511 | - $Type = $Vector["Type"]; |
|
| 512 | - $Force = $Vector["Force"]; |
|
| 513 | - $Angle = $Vector["Angle"]; |
|
| 514 | - $Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR; |
|
| 509 | + foreach($Settings["Vectors"] as $ID => $Vector) |
|
| 510 | + { |
|
| 511 | + $Type = $Vector["Type"]; |
|
| 512 | + $Force = $Vector["Force"]; |
|
| 513 | + $Angle = $Vector["Angle"]; |
|
| 514 | + $Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR; |
|
| 515 | 515 | |
| 516 | - $X = cos(deg2rad($Angle)) * $Force * $Factor + $X; |
|
| 517 | - $Y = sin(deg2rad($Angle)) * $Force * $Factor + $Y; |
|
| 518 | - } |
|
| 516 | + $X = cos(deg2rad($Angle)) * $Force * $Factor + $X; |
|
| 517 | + $Y = sin(deg2rad($Angle)) * $Force * $Factor + $Y; |
|
| 518 | + } |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - $this->Data[$Key]["X"] = $X; |
|
| 522 | - $this->Data[$Key]["Y"] = $Y; |
|
| 523 | - } |
|
| 521 | + $this->Data[$Key]["X"] = $X; |
|
| 522 | + $this->Data[$Key]["Y"] = $Y; |
|
| 523 | + } |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | - function lastPass() |
|
| 526 | + function lastPass() |
|
| 527 | 527 | { |
| 528 | - /* Put everything inside the graph area */ |
|
| 529 | - foreach($this->Data as $Key => $Settings) |
|
| 530 | - { |
|
| 531 | - $X = $Settings["X"]; |
|
| 532 | - $Y = $Settings["Y"]; |
|
| 533 | - |
|
| 534 | - if ( $X < $this->X1 ) { $X = $this->X1; } |
|
| 535 | - if ( $X > $this->X2 ) { $X = $this->X2; } |
|
| 536 | - if ( $Y < $this->Y1 ) { $Y = $this->Y1; } |
|
| 537 | - if ( $Y > $this->Y2 ) { $Y = $this->Y2; } |
|
| 538 | - |
|
| 539 | - $this->Data[$Key]["X"] = $X; |
|
| 540 | - $this->Data[$Key]["Y"] = $Y; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - /* Dump all links */ |
|
| 544 | - $Links = ""; |
|
| 545 | - foreach($this->Data as $Key => $Settings) |
|
| 546 | - { |
|
| 547 | - $X1 = $Settings["X"]; |
|
| 548 | - $Y1 = $Settings["Y"]; |
|
| 549 | - |
|
| 550 | - if ( isset($Settings["Connections"]) ) |
|
| 551 | - { |
|
| 552 | - foreach ($Settings["Connections"] as $ID => $NodeID) |
|
| 553 | - { |
|
| 554 | - if ( isset($this->Data[$NodeID]) ) |
|
| 528 | + /* Put everything inside the graph area */ |
|
| 529 | + foreach($this->Data as $Key => $Settings) |
|
| 530 | + { |
|
| 531 | + $X = $Settings["X"]; |
|
| 532 | + $Y = $Settings["Y"]; |
|
| 533 | + |
|
| 534 | + if ( $X < $this->X1 ) { $X = $this->X1; } |
|
| 535 | + if ( $X > $this->X2 ) { $X = $this->X2; } |
|
| 536 | + if ( $Y < $this->Y1 ) { $Y = $this->Y1; } |
|
| 537 | + if ( $Y > $this->Y2 ) { $Y = $this->Y2; } |
|
| 538 | + |
|
| 539 | + $this->Data[$Key]["X"] = $X; |
|
| 540 | + $this->Data[$Key]["Y"] = $Y; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + /* Dump all links */ |
|
| 544 | + $Links = ""; |
|
| 545 | + foreach($this->Data as $Key => $Settings) |
|
| 546 | + { |
|
| 547 | + $X1 = $Settings["X"]; |
|
| 548 | + $Y1 = $Settings["Y"]; |
|
| 549 | + |
|
| 550 | + if ( isset($Settings["Connections"]) ) |
|
| 551 | + { |
|
| 552 | + foreach ($Settings["Connections"] as $ID => $NodeID) |
|
| 553 | + { |
|
| 554 | + if ( isset($this->Data[$NodeID]) ) |
|
| 555 | 555 | { |
| 556 | - $X2 = $this->Data[$NodeID]["X"]; |
|
| 557 | - $Y2 = $this->Data[$NodeID]["Y"]; |
|
| 556 | + $X2 = $this->Data[$NodeID]["X"]; |
|
| 557 | + $Y2 = $this->Data[$NodeID]["Y"]; |
|
| 558 | 558 | |
| 559 | - $Links[] = array("X1"=>$X1,"Y1"=>$Y1,"X2"=>$X2,"Y2"=>$Y2,"Source"=>$Settings["Name"],"Destination"=>$this->Data[$NodeID]["Name"]); |
|
| 559 | + $Links[] = array("X1"=>$X1,"Y1"=>$Y1,"X2"=>$X2,"Y2"=>$Y2,"Source"=>$Settings["Name"],"Destination"=>$this->Data[$NodeID]["Name"]); |
|
| 560 | 560 | } |
| 561 | - } |
|
| 561 | + } |
|
| 562 | + } |
|
| 562 | 563 | } |
| 563 | - } |
|
| 564 | 564 | |
| 565 | - /* Check collisions */ |
|
| 566 | - $Conflicts = 0; |
|
| 567 | - foreach($this->Data as $Key => $Settings) |
|
| 568 | - { |
|
| 569 | - $X1 = $Settings["X"]; |
|
| 570 | - $Y1 = $Settings["Y"]; |
|
| 565 | + /* Check collisions */ |
|
| 566 | + $Conflicts = 0; |
|
| 567 | + foreach($this->Data as $Key => $Settings) |
|
| 568 | + { |
|
| 569 | + $X1 = $Settings["X"]; |
|
| 570 | + $Y1 = $Settings["Y"]; |
|
| 571 | 571 | |
| 572 | - if ( isset($Settings["Connections"]) ) |
|
| 572 | + if ( isset($Settings["Connections"]) ) |
|
| 573 | 573 | { |
| 574 | - foreach ($Settings["Connections"] as $ID => $NodeID) |
|
| 575 | - { |
|
| 576 | - if ( isset($this->Data[$NodeID]) ) |
|
| 574 | + foreach ($Settings["Connections"] as $ID => $NodeID) |
|
| 575 | + { |
|
| 576 | + if ( isset($this->Data[$NodeID]) ) |
|
| 577 | 577 | { |
| 578 | - $X2 = $this->Data[$NodeID]["X"]; |
|
| 579 | - $Y2 = $this->Data[$NodeID]["Y"]; |
|
| 578 | + $X2 = $this->Data[$NodeID]["X"]; |
|
| 579 | + $Y2 = $this->Data[$NodeID]["Y"]; |
|
| 580 | 580 | |
| 581 | - foreach($Links as $IDLinks => $Link) |
|
| 582 | - { |
|
| 583 | - $X3 = $Link["X1"]; $Y3 = $Link["Y1"]; $X4 = $Link["X2"]; $Y4 = $Link["Y2"]; |
|
| 581 | + foreach($Links as $IDLinks => $Link) |
|
| 582 | + { |
|
| 583 | + $X3 = $Link["X1"]; $Y3 = $Link["Y1"]; $X4 = $Link["X2"]; $Y4 = $Link["Y2"]; |
|
| 584 | 584 | |
| 585 | - if ( !($X1 == $X3 && $X2 == $X4 && $Y1 == $Y3 && $Y2 == $Y4 ) ) |
|
| 585 | + if ( !($X1 == $X3 && $X2 == $X4 && $Y1 == $Y3 && $Y2 == $Y4 ) ) |
|
| 586 | 586 | { |
| 587 | - if ( $this->intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4) ) |
|
| 588 | - { |
|
| 589 | - if ( $Link["Source"] != $Settings["Name"] && $Link["Source"] != $this->Data[$NodeID]["Name"] && $Link["Destination"] != $Settings["Name"] && $Link["Destination"] != $this->Data[$NodeID]["Name"] ) |
|
| 587 | + if ( $this->intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4) ) |
|
| 588 | + { |
|
| 589 | + if ( $Link["Source"] != $Settings["Name"] && $Link["Source"] != $this->Data[$NodeID]["Name"] && $Link["Destination"] != $Settings["Name"] && $Link["Destination"] != $this->Data[$NodeID]["Name"] ) |
|
| 590 | 590 | { $Conflicts++; } |
| 591 | - } |
|
| 591 | + } |
|
| 592 | + } |
|
| 592 | 593 | } |
| 593 | - } |
|
| 594 | 594 | } |
| 595 | - } |
|
| 595 | + } |
|
| 596 | + } |
|
| 596 | 597 | } |
| 597 | - } |
|
| 598 | - return($Conflicts/2); |
|
| 598 | + return($Conflicts/2); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | - /* Center the graph */ |
|
| 602 | - function center() |
|
| 601 | + /* Center the graph */ |
|
| 602 | + function center() |
|
| 603 | 603 | { |
| 604 | - /* Determine the real center */ |
|
| 605 | - $TargetCenterX = ($this->X2 - $this->X1) / 2 + $this->X1; |
|
| 606 | - $TargetCenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1; |
|
| 607 | - |
|
| 608 | - /* Get current boundaries */ |
|
| 609 | - $XMin = $this->X2; $XMax = $this->X1; |
|
| 610 | - $YMin = $this->Y2; $YMax = $this->Y1; |
|
| 611 | - foreach($this->Data as $Key => $Settings) |
|
| 612 | - { |
|
| 613 | - $X = $Settings["X"]; |
|
| 614 | - $Y = $Settings["Y"]; |
|
| 615 | - |
|
| 616 | - if ( $X < $XMin) { $XMin = $X; } |
|
| 617 | - if ( $X > $XMax) { $XMax = $X; } |
|
| 618 | - if ( $Y < $YMin) { $YMin = $Y; } |
|
| 619 | - if ( $Y > $YMax) { $YMax = $Y; } |
|
| 620 | - } |
|
| 621 | - $CurrentCenterX = ($XMax - $XMin) / 2 + $XMin; |
|
| 622 | - $CurrentCenterY = ($YMax - $YMin) / 2 + $YMin; |
|
| 623 | - |
|
| 624 | - /* Compute the offset to apply */ |
|
| 625 | - $XOffset = $TargetCenterX - $CurrentCenterX; |
|
| 626 | - $YOffset = $TargetCenterY - $CurrentCenterY; |
|
| 627 | - |
|
| 628 | - /* Correct the points position */ |
|
| 629 | - foreach($this->Data as $Key => $Settings) |
|
| 630 | - { |
|
| 631 | - $this->Data[$Key]["X"] = $Settings["X"] + $XOffset; |
|
| 632 | - $this->Data[$Key]["Y"] = $Settings["Y"] + $YOffset; |
|
| 633 | - } |
|
| 634 | - } |
|
| 604 | + /* Determine the real center */ |
|
| 605 | + $TargetCenterX = ($this->X2 - $this->X1) / 2 + $this->X1; |
|
| 606 | + $TargetCenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1; |
|
| 607 | + |
|
| 608 | + /* Get current boundaries */ |
|
| 609 | + $XMin = $this->X2; $XMax = $this->X1; |
|
| 610 | + $YMin = $this->Y2; $YMax = $this->Y1; |
|
| 611 | + foreach($this->Data as $Key => $Settings) |
|
| 612 | + { |
|
| 613 | + $X = $Settings["X"]; |
|
| 614 | + $Y = $Settings["Y"]; |
|
| 635 | 615 | |
| 636 | - /* Create the encoded string */ |
|
| 637 | - function drawSpring($Object,$Settings="") |
|
| 638 | - { |
|
| 639 | - $this->pChartObject = $Object; |
|
| 616 | + if ( $X < $XMin) { $XMin = $X; } |
|
| 617 | + if ( $X > $XMax) { $XMax = $X; } |
|
| 618 | + if ( $Y < $YMin) { $YMin = $Y; } |
|
| 619 | + if ( $Y > $YMax) { $YMax = $Y; } |
|
| 620 | + } |
|
| 621 | + $CurrentCenterX = ($XMax - $XMin) / 2 + $XMin; |
|
| 622 | + $CurrentCenterY = ($YMax - $YMin) / 2 + $YMin; |
|
| 640 | 623 | |
| 641 | - $Pass = isset($Settings["Pass"]) ? $Settings["Pass"] : 50; |
|
| 642 | - $Retries = isset($Settings["Retry"]) ? $Settings["Retry"] : 10; |
|
| 643 | - $this->MagneticForceA = isset($Settings["MagneticForceA"]) ? $Settings["MagneticForceA"] : 1.5; |
|
| 644 | - $this->MagneticForceR = isset($Settings["MagneticForceR"]) ? $Settings["MagneticForceR"] : 2; |
|
| 645 | - $this->RingSize = isset($Settings["RingSize"]) ? $Settings["RingSize"] : 40; |
|
| 646 | - $DrawVectors = isset($Settings["DrawVectors"]) ? $Settings["DrawVectors"] : FALSE; |
|
| 647 | - $DrawQuietZone = isset($Settings["DrawQuietZone"]) ? $Settings["DrawQuietZone"] : FALSE; |
|
| 648 | - $CenterGraph = isset($Settings["CenterGraph"]) ? $Settings["CenterGraph"] : TRUE; |
|
| 649 | - $TextPadding = isset($Settings["TextPadding"]) ? $Settings["TextPadding"] : 4; |
|
| 650 | - $Algorithm = isset($Settings["Algorithm"]) ? $Settings["Algorithm"] : ALGORITHM_WEIGHTED; |
|
| 624 | + /* Compute the offset to apply */ |
|
| 625 | + $XOffset = $TargetCenterX - $CurrentCenterX; |
|
| 626 | + $YOffset = $TargetCenterY - $CurrentCenterY; |
|
| 651 | 627 | |
| 652 | - $FontSize = $Object->FontSize; |
|
| 653 | - $this->X1 = $Object->GraphAreaX1; |
|
| 654 | - $this->Y1 = $Object->GraphAreaY1; |
|
| 655 | - $this->X2 = $Object->GraphAreaX2; |
|
| 656 | - $this->Y2 = $Object->GraphAreaY2; |
|
| 628 | + /* Correct the points position */ |
|
| 629 | + foreach($this->Data as $Key => $Settings) |
|
| 630 | + { |
|
| 631 | + $this->Data[$Key]["X"] = $Settings["X"] + $XOffset; |
|
| 632 | + $this->Data[$Key]["Y"] = $Settings["Y"] + $YOffset; |
|
| 633 | + } |
|
| 634 | + } |
|
| 657 | 635 | |
| 658 | - $Conflicts = 1; $Jobs = 0; $this->History["MinimumConflicts"] = -1; |
|
| 659 | - while ($Conflicts != 0 && $Jobs < $Retries ) |
|
| 660 | - { |
|
| 661 | - $Jobs++; |
|
| 636 | + /* Create the encoded string */ |
|
| 637 | + function drawSpring($Object,$Settings="") |
|
| 638 | + { |
|
| 639 | + $this->pChartObject = $Object; |
|
| 640 | + |
|
| 641 | + $Pass = isset($Settings["Pass"]) ? $Settings["Pass"] : 50; |
|
| 642 | + $Retries = isset($Settings["Retry"]) ? $Settings["Retry"] : 10; |
|
| 643 | + $this->MagneticForceA = isset($Settings["MagneticForceA"]) ? $Settings["MagneticForceA"] : 1.5; |
|
| 644 | + $this->MagneticForceR = isset($Settings["MagneticForceR"]) ? $Settings["MagneticForceR"] : 2; |
|
| 645 | + $this->RingSize = isset($Settings["RingSize"]) ? $Settings["RingSize"] : 40; |
|
| 646 | + $DrawVectors = isset($Settings["DrawVectors"]) ? $Settings["DrawVectors"] : FALSE; |
|
| 647 | + $DrawQuietZone = isset($Settings["DrawQuietZone"]) ? $Settings["DrawQuietZone"] : FALSE; |
|
| 648 | + $CenterGraph = isset($Settings["CenterGraph"]) ? $Settings["CenterGraph"] : TRUE; |
|
| 649 | + $TextPadding = isset($Settings["TextPadding"]) ? $Settings["TextPadding"] : 4; |
|
| 650 | + $Algorithm = isset($Settings["Algorithm"]) ? $Settings["Algorithm"] : ALGORITHM_WEIGHTED; |
|
| 651 | + |
|
| 652 | + $FontSize = $Object->FontSize; |
|
| 653 | + $this->X1 = $Object->GraphAreaX1; |
|
| 654 | + $this->Y1 = $Object->GraphAreaY1; |
|
| 655 | + $this->X2 = $Object->GraphAreaX2; |
|
| 656 | + $this->Y2 = $Object->GraphAreaY2; |
|
| 657 | + |
|
| 658 | + $Conflicts = 1; $Jobs = 0; $this->History["MinimumConflicts"] = -1; |
|
| 659 | + while ($Conflicts != 0 && $Jobs < $Retries ) |
|
| 660 | + { |
|
| 661 | + $Jobs++; |
|
| 662 | 662 | |
| 663 | - /* Compute the initial settings */ |
|
| 664 | - $this->firstPass($Algorithm); |
|
| 663 | + /* Compute the initial settings */ |
|
| 664 | + $this->firstPass($Algorithm); |
|
| 665 | 665 | |
| 666 | - /* Apply the vectors */ |
|
| 667 | - if ( $Pass > 0 ) |
|
| 666 | + /* Apply the vectors */ |
|
| 667 | + if ( $Pass > 0 ) |
|
| 668 | 668 | { |
| 669 | - for ($i=0; $i<=$Pass; $i++) { $this->doPass(); } |
|
| 669 | + for ($i=0; $i<=$Pass; $i++) { $this->doPass(); } |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | - $Conflicts = $this->lastPass(); |
|
| 673 | - if ( $this->History["MinimumConflicts"] == -1 || $Conflicts < $this->History["MinimumConflicts"] ) |
|
| 672 | + $Conflicts = $this->lastPass(); |
|
| 673 | + if ( $this->History["MinimumConflicts"] == -1 || $Conflicts < $this->History["MinimumConflicts"] ) |
|
| 674 | 674 | { $this->History["MinimumConflicts"] = $Conflicts; $this->History["Result"] = $this->Data; } |
| 675 | - } |
|
| 675 | + } |
|
| 676 | 676 | |
| 677 | - $Conflicts = $this->History["MinimumConflicts"]; |
|
| 678 | - $this->Data = $this->History["Result"]; |
|
| 677 | + $Conflicts = $this->History["MinimumConflicts"]; |
|
| 678 | + $this->Data = $this->History["Result"]; |
|
| 679 | 679 | |
| 680 | - if ( $CenterGraph ) { $this->center(); } |
|
| 680 | + if ( $CenterGraph ) { $this->center(); } |
|
| 681 | 681 | |
| 682 | - /* Draw the connections */ |
|
| 683 | - $Drawn = ""; |
|
| 684 | - foreach($this->Data as $Key => $Settings) |
|
| 685 | - { |
|
| 686 | - $X = $Settings["X"]; |
|
| 687 | - $Y = $Settings["Y"]; |
|
| 682 | + /* Draw the connections */ |
|
| 683 | + $Drawn = ""; |
|
| 684 | + foreach($this->Data as $Key => $Settings) |
|
| 685 | + { |
|
| 686 | + $X = $Settings["X"]; |
|
| 687 | + $Y = $Settings["Y"]; |
|
| 688 | 688 | |
| 689 | - if ( isset($Settings["Connections"]) ) |
|
| 689 | + if ( isset($Settings["Connections"]) ) |
|
| 690 | 690 | { |
| 691 | - foreach ($Settings["Connections"] as $ID => $NodeID) |
|
| 692 | - { |
|
| 693 | - if ( !isset($Drawn[$Key]) ) { $Drawn[$Key] = ""; } |
|
| 694 | - if ( !isset($Drawn[$NodeID]) ) { $Drawn[$NodeID] = ""; } |
|
| 691 | + foreach ($Settings["Connections"] as $ID => $NodeID) |
|
| 692 | + { |
|
| 693 | + if ( !isset($Drawn[$Key]) ) { $Drawn[$Key] = ""; } |
|
| 694 | + if ( !isset($Drawn[$NodeID]) ) { $Drawn[$NodeID] = ""; } |
|
| 695 | 695 | |
| 696 | - if ( isset($this->Data[$NodeID]) && !isset($Drawn[$Key][$NodeID]) && !isset($Drawn[$NodeID][$Key]) ) |
|
| 696 | + if ( isset($this->Data[$NodeID]) && !isset($Drawn[$Key][$NodeID]) && !isset($Drawn[$NodeID][$Key]) ) |
|
| 697 | 697 | { |
| 698 | - $Color = array("R"=>$this->Default["LinkR"],"G"=>$this->Default["LinkG"],"B"=>$this->Default["LinkB"],"Alpha"=>$this->Default["Alpha"]); |
|
| 698 | + $Color = array("R"=>$this->Default["LinkR"],"G"=>$this->Default["LinkG"],"B"=>$this->Default["LinkB"],"Alpha"=>$this->Default["Alpha"]); |
|
| 699 | 699 | |
| 700 | - if ( $this->Links != "" ) |
|
| 701 | - { |
|
| 702 | - if ( isset($this->Links[$Key][$NodeID]["R"]) ) |
|
| 700 | + if ( $this->Links != "" ) |
|
| 701 | + { |
|
| 702 | + if ( isset($this->Links[$Key][$NodeID]["R"]) ) |
|
| 703 | 703 | { $Color = array("R"=>$this->Links[$Key][$NodeID]["R"],"G"=>$this->Links[$Key][$NodeID]["G"],"B"=>$this->Links[$Key][$NodeID]["B"],"Alpha"=>$this->Links[$Key][$NodeID]["Alpha"]); } |
| 704 | 704 | |
| 705 | - if ( isset($this->Links[$Key][$NodeID]["Ticks"]) ) |
|
| 706 | - { $Color["Ticks"] = $this->Links[$Key][$NodeID]["Ticks"]; } |
|
| 707 | - } |
|
| 705 | + if ( isset($this->Links[$Key][$NodeID]["Ticks"]) ) |
|
| 706 | + { $Color["Ticks"] = $this->Links[$Key][$NodeID]["Ticks"]; } |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | - $X2 = $this->Data[$NodeID]["X"]; |
|
| 710 | - $Y2 = $this->Data[$NodeID]["Y"]; |
|
| 711 | - $this->pChartObject->drawLine($X,$Y,$X2,$Y2,$Color); |
|
| 712 | - $Drawn[$Key][$NodeID] = TRUE; |
|
| 709 | + $X2 = $this->Data[$NodeID]["X"]; |
|
| 710 | + $Y2 = $this->Data[$NodeID]["Y"]; |
|
| 711 | + $this->pChartObject->drawLine($X,$Y,$X2,$Y2,$Color); |
|
| 712 | + $Drawn[$Key][$NodeID] = TRUE; |
|
| 713 | 713 | |
| 714 | - if ( isset($this->Links) && $this->Links != "" ) |
|
| 715 | - { |
|
| 716 | - if ( isset($this->Links[$Key][$NodeID]["Name"]) || isset($this->Links[$NodeID][$Key]["Name"]) ) |
|
| 714 | + if ( isset($this->Links) && $this->Links != "" ) |
|
| 715 | + { |
|
| 716 | + if ( isset($this->Links[$Key][$NodeID]["Name"]) || isset($this->Links[$NodeID][$Key]["Name"]) ) |
|
| 717 | 717 | { |
| 718 | - $Name = isset($this->Links[$Key][$NodeID]["Name"]) ? $this->Links[$Key][$NodeID]["Name"] : $this->Links[$NodeID][$Key]["Name"]; |
|
| 719 | - $TxtX = ($X2 - $X)/2 + $X; |
|
| 720 | - $TxtY = ($Y2 - $Y)/2 + $Y; |
|
| 721 | - |
|
| 722 | - if ( $X <= $X2 ) |
|
| 723 | - $Angle = (360-$this->getAngle($X,$Y,$X2,$Y2)) % 360; |
|
| 724 | - else |
|
| 725 | - $Angle = (360-$this->getAngle($X2,$Y2,$X,$Y)) % 360; |
|
| 726 | - |
|
| 727 | - $Settings = $Color; |
|
| 728 | - $Settings["Angle"] = $Angle; |
|
| 729 | - $Settings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; |
|
| 730 | - $this->pChartObject->drawText($TxtX,$TxtY,$Name,$Settings); |
|
| 718 | + $Name = isset($this->Links[$Key][$NodeID]["Name"]) ? $this->Links[$Key][$NodeID]["Name"] : $this->Links[$NodeID][$Key]["Name"]; |
|
| 719 | + $TxtX = ($X2 - $X)/2 + $X; |
|
| 720 | + $TxtY = ($Y2 - $Y)/2 + $Y; |
|
| 721 | + |
|
| 722 | + if ( $X <= $X2 ) |
|
| 723 | + $Angle = (360-$this->getAngle($X,$Y,$X2,$Y2)) % 360; |
|
| 724 | + else |
|
| 725 | + $Angle = (360-$this->getAngle($X2,$Y2,$X,$Y)) % 360; |
|
| 726 | + |
|
| 727 | + $Settings = $Color; |
|
| 728 | + $Settings["Angle"] = $Angle; |
|
| 729 | + $Settings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; |
|
| 730 | + $this->pChartObject->drawText($TxtX,$TxtY,$Name,$Settings); |
|
| 731 | 731 | } |
| 732 | - } |
|
| 732 | + } |
|
| 733 | + } |
|
| 733 | 734 | } |
| 734 | - } |
|
| 735 | 735 | } |
| 736 | - } |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | - /* Draw the quiet zones */ |
|
| 739 | - if ( $DrawQuietZone ) |
|
| 740 | - { |
|
| 741 | - foreach($this->Data as $Key => $Settings) |
|
| 738 | + /* Draw the quiet zones */ |
|
| 739 | + if ( $DrawQuietZone ) |
|
| 740 | + { |
|
| 741 | + foreach($this->Data as $Key => $Settings) |
|
| 742 | 742 | { |
| 743 | - $X = $Settings["X"]; |
|
| 744 | - $Y = $Settings["Y"]; |
|
| 745 | - $FreeZone = $Settings["FreeZone"]; |
|
| 743 | + $X = $Settings["X"]; |
|
| 744 | + $Y = $Settings["Y"]; |
|
| 745 | + $FreeZone = $Settings["FreeZone"]; |
|
| 746 | 746 | |
| 747 | - $this->pChartObject->drawFilledCircle($X,$Y,$FreeZone,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>2)); |
|
| 747 | + $this->pChartObject->drawFilledCircle($X,$Y,$FreeZone,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>2)); |
|
| 748 | + } |
|
| 748 | 749 | } |
| 749 | - } |
|
| 750 | 750 | |
| 751 | 751 | |
| 752 | - /* Draw the nodes */ |
|
| 753 | - foreach($this->Data as $Key => $Settings) |
|
| 754 | - { |
|
| 755 | - $X = $Settings["X"]; |
|
| 756 | - $Y = $Settings["Y"]; |
|
| 757 | - $Name = $Settings["Name"]; |
|
| 758 | - $FreeZone = $Settings["FreeZone"]; |
|
| 759 | - $Shape = $Settings["Shape"]; |
|
| 760 | - $Size = $Settings["Size"]; |
|
| 752 | + /* Draw the nodes */ |
|
| 753 | + foreach($this->Data as $Key => $Settings) |
|
| 754 | + { |
|
| 755 | + $X = $Settings["X"]; |
|
| 756 | + $Y = $Settings["Y"]; |
|
| 757 | + $Name = $Settings["Name"]; |
|
| 758 | + $FreeZone = $Settings["FreeZone"]; |
|
| 759 | + $Shape = $Settings["Shape"]; |
|
| 760 | + $Size = $Settings["Size"]; |
|
| 761 | 761 | |
| 762 | - $Color = array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"],"Alpha"=>$Settings["Alpha"],"BorderR"=>$Settings["BorderR"],"BorderG"=>$Settings["BorderG"],"BorderB"=>$Settings["BorderB"],"BorderApha"=>$Settings["BorderAlpha"]); |
|
| 762 | + $Color = array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"],"Alpha"=>$Settings["Alpha"],"BorderR"=>$Settings["BorderR"],"BorderG"=>$Settings["BorderG"],"BorderB"=>$Settings["BorderB"],"BorderApha"=>$Settings["BorderAlpha"]); |
|
| 763 | 763 | |
| 764 | - if ( $Shape == NODE_SHAPE_CIRCLE ) |
|
| 764 | + if ( $Shape == NODE_SHAPE_CIRCLE ) |
|
| 765 | 765 | { |
| 766 | - $this->pChartObject->drawFilledCircle($X,$Y,$Size,$Color); |
|
| 766 | + $this->pChartObject->drawFilledCircle($X,$Y,$Size,$Color); |
|
| 767 | 767 | } |
| 768 | - elseif ( $Shape == NODE_SHAPE_TRIANGLE ) |
|
| 768 | + elseif ( $Shape == NODE_SHAPE_TRIANGLE ) |
|
| 769 | 769 | { |
| 770 | - $Points = ""; |
|
| 771 | - $Points[] = cos(deg2rad(270)) * $Size + $X; $Points[] = sin(deg2rad(270)) * $Size + $Y; |
|
| 772 | - $Points[] = cos(deg2rad(45)) * $Size + $X; $Points[] = sin(deg2rad(45)) * $Size + $Y; |
|
| 773 | - $Points[] = cos(deg2rad(135)) * $Size + $X; $Points[] = sin(deg2rad(135)) * $Size + $Y; |
|
| 774 | - $this->pChartObject->drawPolygon($Points,$Color); |
|
| 770 | + $Points = ""; |
|
| 771 | + $Points[] = cos(deg2rad(270)) * $Size + $X; $Points[] = sin(deg2rad(270)) * $Size + $Y; |
|
| 772 | + $Points[] = cos(deg2rad(45)) * $Size + $X; $Points[] = sin(deg2rad(45)) * $Size + $Y; |
|
| 773 | + $Points[] = cos(deg2rad(135)) * $Size + $X; $Points[] = sin(deg2rad(135)) * $Size + $Y; |
|
| 774 | + $this->pChartObject->drawPolygon($Points,$Color); |
|
| 775 | 775 | } |
| 776 | - elseif ( $Shape == NODE_SHAPE_SQUARE ) |
|
| 776 | + elseif ( $Shape == NODE_SHAPE_SQUARE ) |
|
| 777 | 777 | { |
| 778 | - $Offset = $Size/2; $Size = $Size / 2; |
|
| 779 | - $this->pChartObject->drawFilledRectangle($X-$Offset,$Y-$Offset,$X+$Offset,$Y+$Offset,$Color); |
|
| 778 | + $Offset = $Size/2; $Size = $Size / 2; |
|
| 779 | + $this->pChartObject->drawFilledRectangle($X-$Offset,$Y-$Offset,$X+$Offset,$Y+$Offset,$Color); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | - if ( $Name != "" ) |
|
| 782 | + if ( $Name != "" ) |
|
| 783 | 783 | { |
| 784 | - $LabelOptions = array("R"=>$this->Labels["R"],"G"=>$this->Labels["G"],"B"=>$this->Labels["B"],"Alpha"=>$this->Labels["Alpha"]); |
|
| 784 | + $LabelOptions = array("R"=>$this->Labels["R"],"G"=>$this->Labels["G"],"B"=>$this->Labels["B"],"Alpha"=>$this->Labels["Alpha"]); |
|
| 785 | 785 | |
| 786 | - if ( $this->Labels["Type"] == LABEL_LIGHT ) |
|
| 787 | - { |
|
| 788 | - $LabelOptions["Align"] = TEXT_ALIGN_BOTTOMLEFT; |
|
| 789 | - $this->pChartObject->drawText($X,$Y,$Name,$LabelOptions); |
|
| 790 | - } |
|
| 791 | - elseif ( $this->Labels["Type"] == LABEL_CLASSIC ) |
|
| 792 | - { |
|
| 793 | - $LabelOptions["Align"] = TEXT_ALIGN_TOPMIDDLE; |
|
| 794 | - $LabelOptions["DrawBox"] = TRUE; |
|
| 795 | - $LabelOptions["BoxAlpha"] = 50; |
|
| 796 | - $LabelOptions["BorderOffset"] = 4; |
|
| 797 | - $LabelOptions["RoundedRadius"] = 3; |
|
| 798 | - $LabelOptions["BoxRounded"] = TRUE; |
|
| 799 | - $LabelOptions["NoShadow"] = TRUE; |
|
| 800 | - |
|
| 801 | - $this->pChartObject->drawText($X,$Y+$Size+$TextPadding,$Name,$LabelOptions); |
|
| 802 | - } |
|
| 786 | + if ( $this->Labels["Type"] == LABEL_LIGHT ) |
|
| 787 | + { |
|
| 788 | + $LabelOptions["Align"] = TEXT_ALIGN_BOTTOMLEFT; |
|
| 789 | + $this->pChartObject->drawText($X,$Y,$Name,$LabelOptions); |
|
| 790 | + } |
|
| 791 | + elseif ( $this->Labels["Type"] == LABEL_CLASSIC ) |
|
| 792 | + { |
|
| 793 | + $LabelOptions["Align"] = TEXT_ALIGN_TOPMIDDLE; |
|
| 794 | + $LabelOptions["DrawBox"] = TRUE; |
|
| 795 | + $LabelOptions["BoxAlpha"] = 50; |
|
| 796 | + $LabelOptions["BorderOffset"] = 4; |
|
| 797 | + $LabelOptions["RoundedRadius"] = 3; |
|
| 798 | + $LabelOptions["BoxRounded"] = TRUE; |
|
| 799 | + $LabelOptions["NoShadow"] = TRUE; |
|
| 800 | + |
|
| 801 | + $this->pChartObject->drawText($X,$Y+$Size+$TextPadding,$Name,$LabelOptions); |
|
| 802 | + } |
|
| 803 | + } |
|
| 803 | 804 | } |
| 804 | - } |
|
| 805 | 805 | |
| 806 | - /* Draw the vectors */ |
|
| 807 | - if ( $DrawVectors ) |
|
| 808 | - { |
|
| 809 | - foreach($this->Data as $Key => $Settings) |
|
| 806 | + /* Draw the vectors */ |
|
| 807 | + if ( $DrawVectors ) |
|
| 810 | 808 | { |
| 811 | - $X1 = $Settings["X"]; |
|
| 812 | - $Y1 = $Settings["Y"]; |
|
| 809 | + foreach($this->Data as $Key => $Settings) |
|
| 810 | + { |
|
| 811 | + $X1 = $Settings["X"]; |
|
| 812 | + $Y1 = $Settings["Y"]; |
|
| 813 | 813 | |
| 814 | - if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL ) |
|
| 815 | - { |
|
| 816 | - foreach($Settings["Vectors"] as $ID => $Vector) |
|
| 814 | + if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL ) |
|
| 815 | + { |
|
| 816 | + foreach($Settings["Vectors"] as $ID => $Vector) |
|
| 817 | 817 | { |
| 818 | - $Type = $Vector["Type"]; |
|
| 819 | - $Force = $Vector["Force"]; |
|
| 820 | - $Angle = $Vector["Angle"]; |
|
| 821 | - $Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR; |
|
| 822 | - $Color = $Type == "A" ? array("FillR"=>255,"FillG"=>0,"FillB"=>0) : array("FillR"=>0,"FillG"=>255,"FillB"=>0); |
|
| 818 | + $Type = $Vector["Type"]; |
|
| 819 | + $Force = $Vector["Force"]; |
|
| 820 | + $Angle = $Vector["Angle"]; |
|
| 821 | + $Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR; |
|
| 822 | + $Color = $Type == "A" ? array("FillR"=>255,"FillG"=>0,"FillB"=>0) : array("FillR"=>0,"FillG"=>255,"FillB"=>0); |
|
| 823 | 823 | |
| 824 | - $X2 = cos(deg2rad($Angle)) * $Force * $Factor + $X1; |
|
| 825 | - $Y2 = sin(deg2rad($Angle)) * $Force * $Factor + $Y1; |
|
| 824 | + $X2 = cos(deg2rad($Angle)) * $Force * $Factor + $X1; |
|
| 825 | + $Y2 = sin(deg2rad($Angle)) * $Force * $Factor + $Y1; |
|
| 826 | 826 | |
| 827 | - $this->pChartObject->drawArrow($X1,$Y1,$X2,$Y2,$Color); |
|
| 827 | + $this->pChartObject->drawArrow($X1,$Y1,$X2,$Y2,$Color); |
|
| 828 | 828 | } |
| 829 | - } |
|
| 829 | + } |
|
| 830 | + } |
|
| 830 | 831 | } |
| 831 | - } |
|
| 832 | 832 | |
| 833 | - return(array("Pass"=>$Jobs,"Conflicts"=>$Conflicts)); |
|
| 833 | + return(array("Pass"=>$Jobs,"Conflicts"=>$Conflicts)); |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | - /* Return the distance between two points */ |
|
| 837 | - function getDistance($X1,$Y1,$X2,$Y2) |
|
| 836 | + /* Return the distance between two points */ |
|
| 837 | + function getDistance($X1,$Y1,$X2,$Y2) |
|
| 838 | 838 | { return (sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1))); } |
| 839 | 839 | |
| 840 | - /* Return the angle made by a line and the X axis */ |
|
| 841 | - function getAngle($X1,$Y1,$X2,$Y2) |
|
| 840 | + /* Return the angle made by a line and the X axis */ |
|
| 841 | + function getAngle($X1,$Y1,$X2,$Y2) |
|
| 842 | 842 | { |
| 843 | - $Opposite = $Y2 - $Y1; $Adjacent = $X2 - $X1;$Angle = rad2deg(atan2($Opposite,$Adjacent)); |
|
| 844 | - if ($Angle > 0) { return($Angle); } else { return(360-abs($Angle)); } |
|
| 843 | + $Opposite = $Y2 - $Y1; $Adjacent = $X2 - $X1;$Angle = rad2deg(atan2($Opposite,$Adjacent)); |
|
| 844 | + if ($Angle > 0) { return($Angle); } else { return(360-abs($Angle)); } |
|
| 845 | 845 | } |
| 846 | 846 | |
| 847 | - function intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4) |
|
| 847 | + function intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4) |
|
| 848 | 848 | { |
| 849 | - $A = (($X3 * $Y4 - $X4 * $Y3) * ($X1 - $X2) - ($X1 * $Y2 - $X2 * $Y1) * ($X3 - $X4)); |
|
| 850 | - $B = (($Y1 - $Y2) * ($X3 - $X4) - ($Y3 - $Y4) * ($X1 - $X2)); |
|
| 849 | + $A = (($X3 * $Y4 - $X4 * $Y3) * ($X1 - $X2) - ($X1 * $Y2 - $X2 * $Y1) * ($X3 - $X4)); |
|
| 850 | + $B = (($Y1 - $Y2) * ($X3 - $X4) - ($Y3 - $Y4) * ($X1 - $X2)); |
|
| 851 | 851 | |
| 852 | - if ( $B == 0 ) { return(FALSE); } |
|
| 853 | - $Xi = $A / $B; |
|
| 852 | + if ( $B == 0 ) { return(FALSE); } |
|
| 853 | + $Xi = $A / $B; |
|
| 854 | 854 | |
| 855 | - $C = ($X1 - $X2); |
|
| 856 | - if ( $C == 0 ) { return(FALSE); } |
|
| 857 | - $Yi = $Xi * (($Y1 - $Y2)/$C) + (($X1 * $Y2 - $X2 * $Y1)/$C); |
|
| 855 | + $C = ($X1 - $X2); |
|
| 856 | + if ( $C == 0 ) { return(FALSE); } |
|
| 857 | + $Yi = $Xi * (($Y1 - $Y2)/$C) + (($X1 * $Y2 - $X2 * $Y1)/$C); |
|
| 858 | 858 | |
| 859 | - if ( $Xi >= min($X1,$X2) && $Xi >= min($X3,$X4) && $Xi <= max($X1,$X2) && $Xi <= max($X3,$X4)) |
|
| 860 | - { |
|
| 861 | - if ( $Yi >= min($Y1,$Y2) && $Yi >= min($Y3,$Y4) && $Yi <= max($Y1,$Y2) && $Yi <= max($Y3,$Y4)) |
|
| 859 | + if ( $Xi >= min($X1,$X2) && $Xi >= min($X3,$X4) && $Xi <= max($X1,$X2) && $Xi <= max($X3,$X4)) |
|
| 860 | + { |
|
| 861 | + if ( $Yi >= min($Y1,$Y2) && $Yi >= min($Y3,$Y4) && $Yi <= max($Y1,$Y2) && $Yi <= max($Y3,$Y4)) |
|
| 862 | 862 | { return(TRUE); } |
| 863 | - } |
|
| 863 | + } |
|
| 864 | 864 | |
| 865 | - return(FALSE); |
|
| 865 | + return(FALSE); |
|
| 866 | + } |
|
| 866 | 867 | } |
| 867 | - } |
|
| 868 | 868 | ?> |
| 869 | 869 | \ No newline at end of file |
@@ -13,20 +13,20 @@ discard block |
||
| 13 | 13 | You can find the whole class documentation on the pChart web site. |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | - define("NODE_TYPE_FREE" , 690001); |
|
| 17 | - define("NODE_TYPE_CENTRAL" , 690002); |
|
| 16 | + define("NODE_TYPE_FREE", 690001); |
|
| 17 | + define("NODE_TYPE_CENTRAL", 690002); |
|
| 18 | 18 | |
| 19 | - define("NODE_SHAPE_CIRCLE" , 690011); |
|
| 20 | - define("NODE_SHAPE_TRIANGLE" , 690012); |
|
| 21 | - define("NODE_SHAPE_SQUARE" , 690013); |
|
| 19 | + define("NODE_SHAPE_CIRCLE", 690011); |
|
| 20 | + define("NODE_SHAPE_TRIANGLE", 690012); |
|
| 21 | + define("NODE_SHAPE_SQUARE", 690013); |
|
| 22 | 22 | |
| 23 | - define("ALGORITHM_RANDOM" , 690021); |
|
| 24 | - define("ALGORITHM_WEIGHTED" , 690022); |
|
| 25 | - define("ALGORITHM_CIRCULAR" , 690023); |
|
| 26 | - define("ALGORITHM_CENTRAL" , 690024); |
|
| 23 | + define("ALGORITHM_RANDOM", 690021); |
|
| 24 | + define("ALGORITHM_WEIGHTED", 690022); |
|
| 25 | + define("ALGORITHM_CIRCULAR", 690023); |
|
| 26 | + define("ALGORITHM_CENTRAL", 690024); |
|
| 27 | 27 | |
| 28 | - define("LABEL_CLASSIC" , 690031); |
|
| 29 | - define("LABEL_LIGHT" , 690032); |
|
| 28 | + define("LABEL_CLASSIC", 690031); |
|
| 29 | + define("LABEL_LIGHT", 690032); |
|
| 30 | 30 | |
| 31 | 31 | /* pSpring class definition */ |
| 32 | 32 | class pSpring |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $this->Default["R"] = 255; |
| 54 | 54 | $this->Default["G"] = 255; |
| 55 | 55 | $this->Default["B"] = 255; |
| 56 | - $this->Default["Alpha"] = 100; |
|
| 56 | + $this->Default["Alpha"] = 100; |
|
| 57 | 57 | $this->Default["BorderR"] = 0; |
| 58 | 58 | $this->Default["BorderG"] = 0; |
| 59 | 59 | $this->Default["BorderB"] = 0; |
@@ -62,52 +62,52 @@ discard block |
||
| 62 | 62 | $this->Default["BackgroundR"] = 255; |
| 63 | 63 | $this->Default["BackgroundG"] = 255; |
| 64 | 64 | $this->Default["BackgroundB"] = 255; |
| 65 | - $this->Default["BackgroundAlpha"] = 0; |
|
| 65 | + $this->Default["BackgroundAlpha"] = 0; |
|
| 66 | 66 | $this->Default["Force"] = 1; |
| 67 | 67 | $this->Default["NodeType"] = NODE_TYPE_FREE; |
| 68 | - $this->Default["Size"] = 5; |
|
| 68 | + $this->Default["Size"] = 5; |
|
| 69 | 69 | $this->Default["Shape"] = NODE_SHAPE_CIRCLE; |
| 70 | 70 | $this->Default["FreeZone"] = 40; |
| 71 | 71 | $this->Default["LinkR"] = 0; |
| 72 | 72 | $this->Default["LinkG"] = 0; |
| 73 | 73 | $this->Default["LinkB"] = 0; |
| 74 | - $this->Default["LinkAlpha"] = 0; |
|
| 74 | + $this->Default["LinkAlpha"] = 0; |
|
| 75 | 75 | |
| 76 | - $this->Labels["Type"] = LABEL_CLASSIC; |
|
| 76 | + $this->Labels["Type"] = LABEL_CLASSIC; |
|
| 77 | 77 | $this->Labels["R"] = 0; |
| 78 | 78 | $this->Labels["G"] = 0; |
| 79 | 79 | $this->Labels["B"] = 0; |
| 80 | - $this->Labels["Alpha"] = 100; |
|
| 80 | + $this->Labels["Alpha"] = 100; |
|
| 81 | 81 | |
| 82 | - $this->AutoComputeFreeZone = FALSE; |
|
| 82 | + $this->AutoComputeFreeZone = FALSE; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /* Set default links options */ |
| 86 | - function setLinkDefaults($Settings="") |
|
| 86 | + function setLinkDefaults($Settings = "") |
|
| 87 | 87 | { |
| 88 | - if ( isset($Settings["R"]) ) { $this->Default["LinkR"] = $Settings["R"]; } |
|
| 89 | - if ( isset($Settings["G"]) ) { $this->Default["LinkG"] = $Settings["G"]; } |
|
| 90 | - if ( isset($Settings["B"]) ) { $this->Default["LinkB"] = $Settings["B"]; } |
|
| 91 | - if ( isset($Settings["Alpha"]) ) { $this->Default["LinkAlpha"] = $Settings["Alpha"]; } |
|
| 88 | + if (isset($Settings["R"])) { $this->Default["LinkR"] = $Settings["R"]; } |
|
| 89 | + if (isset($Settings["G"])) { $this->Default["LinkG"] = $Settings["G"]; } |
|
| 90 | + if (isset($Settings["B"])) { $this->Default["LinkB"] = $Settings["B"]; } |
|
| 91 | + if (isset($Settings["Alpha"])) { $this->Default["LinkAlpha"] = $Settings["Alpha"]; } |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /* Set default links options */ |
| 95 | - function setLabelsSettings($Settings="") |
|
| 95 | + function setLabelsSettings($Settings = "") |
|
| 96 | 96 | { |
| 97 | - if ( isset($Settings["Type"]) ) { $this->Labels["Type"] = $Settings["Type"]; } |
|
| 98 | - if ( isset($Settings["R"]) ) { $this->Labels["R"] = $Settings["R"]; } |
|
| 99 | - if ( isset($Settings["G"]) ) { $this->Labels["G"] = $Settings["G"]; } |
|
| 100 | - if ( isset($Settings["B"]) ) { $this->Labels["B"] = $Settings["B"]; } |
|
| 101 | - if ( isset($Settings["Alpha"]) ) { $this->Labels["Alpha"] = $Settings["Alpha"]; } |
|
| 97 | + if (isset($Settings["Type"])) { $this->Labels["Type"] = $Settings["Type"]; } |
|
| 98 | + if (isset($Settings["R"])) { $this->Labels["R"] = $Settings["R"]; } |
|
| 99 | + if (isset($Settings["G"])) { $this->Labels["G"] = $Settings["G"]; } |
|
| 100 | + if (isset($Settings["B"])) { $this->Labels["B"] = $Settings["B"]; } |
|
| 101 | + if (isset($Settings["Alpha"])) { $this->Labels["Alpha"] = $Settings["Alpha"]; } |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /* Auto compute the FreeZone size based on the number of connections */ |
| 105 | 105 | function autoFreeZone() |
| 106 | 106 | { |
| 107 | 107 | /* Check connections reciprocity */ |
| 108 | - foreach($this->Data as $Key => $Settings) |
|
| 108 | + foreach ($this->Data as $Key => $Settings) |
|
| 109 | 109 | { |
| 110 | - if ( isset($Settings["Connections"]) ) |
|
| 110 | + if (isset($Settings["Connections"])) |
|
| 111 | 111 | { $this->Data[$Key]["FreeZone"] = count($Settings["Connections"])*10 + 20; } |
| 112 | 112 | else |
| 113 | 113 | { $this->Data[$Key]["FreeZone"] = 20; } |
@@ -116,60 +116,60 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /* Set link properties */ |
| 119 | - function linkProperties($FromNode,$ToNode,$Settings) |
|
| 119 | + function linkProperties($FromNode, $ToNode, $Settings) |
|
| 120 | 120 | { |
| 121 | - if ( !isset($this->Data[$FromNode]) ) { return(0); } |
|
| 122 | - if ( !isset($this->Data[$ToNode]) ) { return(0); } |
|
| 121 | + if (!isset($this->Data[$FromNode])) { return(0); } |
|
| 122 | + if (!isset($this->Data[$ToNode])) { return(0); } |
|
| 123 | 123 | |
| 124 | 124 | $R = isset($Settings["R"]) ? $Settings["R"] : 0; |
| 125 | 125 | $G = isset($Settings["G"]) ? $Settings["G"] : 0; |
| 126 | 126 | $B = isset($Settings["B"]) ? $Settings["B"] : 0; |
| 127 | 127 | $Alpha = isset($Settings["Alpha"]) ? $Settings["Alpha"] : 100; |
| 128 | - $Name = isset($Settings["Name"]) ? $Settings["Name"] : NULL; |
|
| 128 | + $Name = isset($Settings["Name"]) ? $Settings["Name"] : NULL; |
|
| 129 | 129 | $Ticks = isset($Settings["Ticks"]) ? $Settings["Ticks"] : NULL; |
| 130 | 130 | |
| 131 | - $this->Links[$FromNode][$ToNode]["R"] = $R; $this->Links[$ToNode][$FromNode]["R"] = $R; |
|
| 132 | - $this->Links[$FromNode][$ToNode]["G"] = $G; $this->Links[$ToNode][$FromNode]["G"] = $G; |
|
| 133 | - $this->Links[$FromNode][$ToNode]["B"] = $B; $this->Links[$ToNode][$FromNode]["B"] = $B; |
|
| 131 | + $this->Links[$FromNode][$ToNode]["R"] = $R; $this->Links[$ToNode][$FromNode]["R"] = $R; |
|
| 132 | + $this->Links[$FromNode][$ToNode]["G"] = $G; $this->Links[$ToNode][$FromNode]["G"] = $G; |
|
| 133 | + $this->Links[$FromNode][$ToNode]["B"] = $B; $this->Links[$ToNode][$FromNode]["B"] = $B; |
|
| 134 | 134 | $this->Links[$FromNode][$ToNode]["Alpha"] = $Alpha; $this->Links[$ToNode][$FromNode]["Alpha"] = $Alpha; |
| 135 | - $this->Links[$FromNode][$ToNode]["Name"] = $Name; $this->Links[$ToNode][$FromNode]["Name"] = $Name; |
|
| 135 | + $this->Links[$FromNode][$ToNode]["Name"] = $Name; $this->Links[$ToNode][$FromNode]["Name"] = $Name; |
|
| 136 | 136 | $this->Links[$FromNode][$ToNode]["Ticks"] = $Ticks; $this->Links[$ToNode][$FromNode]["Ticks"] = $Ticks; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - function setNodeDefaults($Settings="") |
|
| 139 | + function setNodeDefaults($Settings = "") |
|
| 140 | 140 | { |
| 141 | - if ( isset($Settings["R"]) ) { $this->Default["R"] = $Settings["R"]; } |
|
| 142 | - if ( isset($Settings["G"]) ) { $this->Default["G"] = $Settings["G"]; } |
|
| 143 | - if ( isset($Settings["B"]) ) { $this->Default["B"] = $Settings["B"]; } |
|
| 144 | - if ( isset($Settings["Alpha"]) ) { $this->Default["Alpha"] = $Settings["Alpha"]; } |
|
| 145 | - if ( isset($Settings["BorderR"]) ) { $this->Default["BorderR"] = $Settings["BorderR"]; } |
|
| 146 | - if ( isset($Settings["BorderG"]) ) { $this->Default["BorderG"] = $Settings["BorderG"]; } |
|
| 147 | - if ( isset($Settings["BorderB"]) ) { $this->Default["BorderB"] = $Settings["BorderB"]; } |
|
| 148 | - if ( isset($Settings["BorderAlpha"]) ) { $this->Default["BorderAlpha"] = $Settings["BorderAlpha"]; } |
|
| 149 | - if ( isset($Settings["Surrounding"]) ) { $this->Default["Surrounding"] = $Settings["Surrounding"]; } |
|
| 150 | - if ( isset($Settings["BackgroundR"]) ) { $this->Default["BackgroundR"] = $Settings["BackgroundR"]; } |
|
| 151 | - if ( isset($Settings["BackgroundG"]) ) { $this->Default["BackgroundG"] = $Settings["BackgroundG"]; } |
|
| 152 | - if ( isset($Settings["BackgroundB"]) ) { $this->Default["BackgroundB"] = $Settings["BackgroundB"]; } |
|
| 153 | - if ( isset($Settings["BackgroundAlpha"]) ) { $this->Default["BackgroundAlpha"] = $Settings["BackgroundAlpha"]; } |
|
| 154 | - if ( isset($Settings["NodeType"]) ) { $this->Default["NodeType"] = $Settings["NodeType"]; } |
|
| 155 | - if ( isset($Settings["Size"]) ) { $this->Default["Size"] = $Settings["Size"]; } |
|
| 156 | - if ( isset($Settings["Shape"]) ) { $this->Default["Shape"] = $Settings["Shape"]; } |
|
| 157 | - if ( isset($Settings["FreeZone"]) ) { $this->Default["FreeZone"] = $Settings["FreeZone"]; } |
|
| 141 | + if (isset($Settings["R"])) { $this->Default["R"] = $Settings["R"]; } |
|
| 142 | + if (isset($Settings["G"])) { $this->Default["G"] = $Settings["G"]; } |
|
| 143 | + if (isset($Settings["B"])) { $this->Default["B"] = $Settings["B"]; } |
|
| 144 | + if (isset($Settings["Alpha"])) { $this->Default["Alpha"] = $Settings["Alpha"]; } |
|
| 145 | + if (isset($Settings["BorderR"])) { $this->Default["BorderR"] = $Settings["BorderR"]; } |
|
| 146 | + if (isset($Settings["BorderG"])) { $this->Default["BorderG"] = $Settings["BorderG"]; } |
|
| 147 | + if (isset($Settings["BorderB"])) { $this->Default["BorderB"] = $Settings["BorderB"]; } |
|
| 148 | + if (isset($Settings["BorderAlpha"])) { $this->Default["BorderAlpha"] = $Settings["BorderAlpha"]; } |
|
| 149 | + if (isset($Settings["Surrounding"])) { $this->Default["Surrounding"] = $Settings["Surrounding"]; } |
|
| 150 | + if (isset($Settings["BackgroundR"])) { $this->Default["BackgroundR"] = $Settings["BackgroundR"]; } |
|
| 151 | + if (isset($Settings["BackgroundG"])) { $this->Default["BackgroundG"] = $Settings["BackgroundG"]; } |
|
| 152 | + if (isset($Settings["BackgroundB"])) { $this->Default["BackgroundB"] = $Settings["BackgroundB"]; } |
|
| 153 | + if (isset($Settings["BackgroundAlpha"])) { $this->Default["BackgroundAlpha"] = $Settings["BackgroundAlpha"]; } |
|
| 154 | + if (isset($Settings["NodeType"])) { $this->Default["NodeType"] = $Settings["NodeType"]; } |
|
| 155 | + if (isset($Settings["Size"])) { $this->Default["Size"] = $Settings["Size"]; } |
|
| 156 | + if (isset($Settings["Shape"])) { $this->Default["Shape"] = $Settings["Shape"]; } |
|
| 157 | + if (isset($Settings["FreeZone"])) { $this->Default["FreeZone"] = $Settings["FreeZone"]; } |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /* Add a node */ |
| 161 | - function addNode($NodeID,$Settings="") |
|
| 161 | + function addNode($NodeID, $Settings = "") |
|
| 162 | 162 | { |
| 163 | 163 | /* if the node already exists, ignore */ |
| 164 | 164 | if (isset($this->Data[$NodeID])) { return(0); } |
| 165 | 165 | |
| 166 | - $Name = isset($Settings["Name"]) ? $Settings["Name"] : "Node ".$NodeID; |
|
| 167 | - $Connections = isset($Settings["Connections"]) ? $Settings["Connections"] : NULL; |
|
| 166 | + $Name = isset($Settings["Name"]) ? $Settings["Name"] : "Node ".$NodeID; |
|
| 167 | + $Connections = isset($Settings["Connections"]) ? $Settings["Connections"] : NULL; |
|
| 168 | 168 | |
| 169 | 169 | $R = isset($Settings["R"]) ? $Settings["R"] : $this->Default["R"]; |
| 170 | 170 | $G = isset($Settings["G"]) ? $Settings["G"] : $this->Default["G"]; |
| 171 | 171 | $B = isset($Settings["B"]) ? $Settings["B"] : $this->Default["B"]; |
| 172 | - $Alpha = isset($Settings["Alpha"]) ? $Settings["Alpha"] : $this->Default["Alpha"]; |
|
| 172 | + $Alpha = isset($Settings["Alpha"]) ? $Settings["Alpha"] : $this->Default["Alpha"]; |
|
| 173 | 173 | $BorderR = isset($Settings["BorderR"]) ? $Settings["BorderR"] : $this->Default["BorderR"]; |
| 174 | 174 | $BorderG = isset($Settings["BorderG"]) ? $Settings["BorderG"] : $this->Default["BorderG"]; |
| 175 | 175 | $BorderB = isset($Settings["BorderB"]) ? $Settings["BorderB"] : $this->Default["BorderB"]; |
@@ -178,29 +178,29 @@ discard block |
||
| 178 | 178 | $BackgroundR = isset($Settings["BackgroundR"]) ? $Settings["BackgroundR"] : $this->Default["BackgroundR"]; |
| 179 | 179 | $BackgroundG = isset($Settings["BackgroundG"]) ? $Settings["BackgroundG"] : $this->Default["BackgroundG"]; |
| 180 | 180 | $BackgroundB = isset($Settings["BackgroundB"]) ? $Settings["BackgroundB"] : $this->Default["BackgroundB"]; |
| 181 | - $BackgroundAlpha = isset($Settings["BackgroundAlpha"]) ? $Settings["BackgroundAlpha"] : $this->Default["BackgroundAlpha"]; |
|
| 182 | - $Force = isset($Settings["Force"]) ? $Settings["Force"] : $this->Default["Force"]; |
|
| 181 | + $BackgroundAlpha = isset($Settings["BackgroundAlpha"]) ? $Settings["BackgroundAlpha"] : $this->Default["BackgroundAlpha"]; |
|
| 182 | + $Force = isset($Settings["Force"]) ? $Settings["Force"] : $this->Default["Force"]; |
|
| 183 | 183 | $NodeType = isset($Settings["NodeType"]) ? $Settings["NodeType"] : $this->Default["NodeType"]; |
| 184 | - $Size = isset($Settings["Size"]) ? $Settings["Size"] : $this->Default["Size"]; |
|
| 184 | + $Size = isset($Settings["Size"]) ? $Settings["Size"] : $this->Default["Size"]; |
|
| 185 | 185 | $Shape = isset($Settings["Shape"]) ? $Settings["Shape"] : $this->Default["Shape"]; |
| 186 | 186 | $FreeZone = isset($Settings["FreeZone"]) ? $Settings["FreeZone"] : $this->Default["FreeZone"]; |
| 187 | 187 | |
| 188 | - if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; } |
|
| 188 | + if ($Surrounding != NULL) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; } |
|
| 189 | 189 | |
| 190 | 190 | $this->Data[$NodeID]["R"] = $R; $this->Data[$NodeID]["G"] = $G; $this->Data[$NodeID]["B"] = $B; $this->Data[$NodeID]["Alpha"] = $Alpha; |
| 191 | 191 | $this->Data[$NodeID]["BorderR"] = $BorderR; $this->Data[$NodeID]["BorderG"] = $BorderG; $this->Data[$NodeID]["BorderB"] = $BorderB; $this->Data[$NodeID]["BorderAlpha"] = $BorderAlpha; |
| 192 | - $this->Data[$NodeID]["BackgroundR"] = $BackgroundR; $this->Data[$NodeID]["BackgroundG"] = $BackgroundG; $this->Data[$NodeID]["BackgroundB"] = $BackgroundB; $this->Data[$NodeID]["BackgroundAlpha"] = $BackgroundAlpha; |
|
| 192 | + $this->Data[$NodeID]["BackgroundR"] = $BackgroundR; $this->Data[$NodeID]["BackgroundG"] = $BackgroundG; $this->Data[$NodeID]["BackgroundB"] = $BackgroundB; $this->Data[$NodeID]["BackgroundAlpha"] = $BackgroundAlpha; |
|
| 193 | 193 | $this->Data[$NodeID]["Name"] = $Name; |
| 194 | 194 | $this->Data[$NodeID]["Force"] = $Force; |
| 195 | 195 | $this->Data[$NodeID]["Type"] = $NodeType; |
| 196 | 196 | $this->Data[$NodeID]["Size"] = $Size; |
| 197 | 197 | $this->Data[$NodeID]["Shape"] = $Shape; |
| 198 | - $this->Data[$NodeID]["FreeZone"] = $FreeZone; |
|
| 199 | - if ( $Connections != NULL ) |
|
| 198 | + $this->Data[$NodeID]["FreeZone"] = $FreeZone; |
|
| 199 | + if ($Connections != NULL) |
|
| 200 | 200 | { |
| 201 | - if ( is_array($Connections ) ) |
|
| 201 | + if (is_array($Connections)) |
|
| 202 | 202 | { |
| 203 | - foreach($Connections as $Key => $Value) |
|
| 203 | + foreach ($Connections as $Key => $Value) |
|
| 204 | 204 | $this->Data[$NodeID]["Connections"][] = $Value; |
| 205 | 205 | } |
| 206 | 206 | else |
@@ -209,37 +209,37 @@ discard block |
||
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /* Set color attribute for a list of nodes */ |
| 212 | - function setNodesColor($Nodes,$Settings="") |
|
| 212 | + function setNodesColor($Nodes, $Settings = "") |
|
| 213 | 213 | { |
| 214 | - if ( is_array($Nodes) ) |
|
| 214 | + if (is_array($Nodes)) |
|
| 215 | 215 | { |
| 216 | 216 | foreach ($Nodes as $Key => $NodeID) |
| 217 | 217 | { |
| 218 | - if (isset($this->Data[$NodeID]) ) |
|
| 218 | + if (isset($this->Data[$NodeID])) |
|
| 219 | 219 | { |
| 220 | - if ( isset($Settings["R"]) ) { $this->Data[$NodeID]["R"] = $Settings["R"]; } |
|
| 221 | - if ( isset($Settings["G"]) ) { $this->Data[$NodeID]["G"] = $Settings["G"]; } |
|
| 222 | - if ( isset($Settings["B"]) ) { $this->Data[$NodeID]["B"] = $Settings["B"]; } |
|
| 223 | - if ( isset($Settings["Alpha"]) ) { $this->Data[$NodeID]["Alpha"] = $Settings["Alpha"]; } |
|
| 224 | - if ( isset($Settings["BorderR"]) ) { $this->Data[$NodeID]["BorderR"] = $Settings["BorderR"]; } |
|
| 225 | - if ( isset($Settings["BorderG"]) ) { $this->Data[$NodeID]["BorderG"] = $Settings["BorderG"]; } |
|
| 226 | - if ( isset($Settings["BorderB"]) ) { $this->Data[$NodeID]["BorderB"] = $Settings["BorderB"]; } |
|
| 227 | - if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$NodeID]["BorderAlpha"] = $Settings["BorderAlpha"]; } |
|
| 228 | - if ( isset($Settings["Surrounding"]) ) { $this->Data[$NodeID]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; } |
|
| 220 | + if (isset($Settings["R"])) { $this->Data[$NodeID]["R"] = $Settings["R"]; } |
|
| 221 | + if (isset($Settings["G"])) { $this->Data[$NodeID]["G"] = $Settings["G"]; } |
|
| 222 | + if (isset($Settings["B"])) { $this->Data[$NodeID]["B"] = $Settings["B"]; } |
|
| 223 | + if (isset($Settings["Alpha"])) { $this->Data[$NodeID]["Alpha"] = $Settings["Alpha"]; } |
|
| 224 | + if (isset($Settings["BorderR"])) { $this->Data[$NodeID]["BorderR"] = $Settings["BorderR"]; } |
|
| 225 | + if (isset($Settings["BorderG"])) { $this->Data[$NodeID]["BorderG"] = $Settings["BorderG"]; } |
|
| 226 | + if (isset($Settings["BorderB"])) { $this->Data[$NodeID]["BorderB"] = $Settings["BorderB"]; } |
|
| 227 | + if (isset($Settings["BorderAlpha"])) { $this->Data[$NodeID]["BorderAlpha"] = $Settings["BorderAlpha"]; } |
|
| 228 | + if (isset($Settings["Surrounding"])) { $this->Data[$NodeID]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; } |
|
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | else |
| 233 | 233 | { |
| 234 | - if ( isset($Settings["R"]) ) { $this->Data[$Nodes]["R"] = $Settings["R"]; } |
|
| 235 | - if ( isset($Settings["G"]) ) { $this->Data[$Nodes]["G"] = $Settings["G"]; } |
|
| 236 | - if ( isset($Settings["B"]) ) { $this->Data[$Nodes]["B"] = $Settings["B"]; } |
|
| 237 | - if ( isset($Settings["Alpha"]) ) { $this->Data[$Nodes]["Alpha"] = $Settings["Alpha"]; } |
|
| 238 | - if ( isset($Settings["BorderR"]) ) { $this->Data[$Nodes]["BorderR"] = $Settings["BorderR"]; } |
|
| 239 | - if ( isset($Settings["BorderG"]) ) { $this->Data[$Nodes]["BorderG"] = $Settings["BorderG"]; } |
|
| 240 | - if ( isset($Settings["BorderB"]) ) { $this->Data[$Nodes]["BorderB"] = $Settings["BorderB"]; } |
|
| 241 | - if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$Nodes]["BorderAlpha"] = $Settings["BorderAlpha"]; } |
|
| 242 | - if ( isset($Settings["Surrounding"]) ) { $this->Data[$Nodes]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; } |
|
| 234 | + if (isset($Settings["R"])) { $this->Data[$Nodes]["R"] = $Settings["R"]; } |
|
| 235 | + if (isset($Settings["G"])) { $this->Data[$Nodes]["G"] = $Settings["G"]; } |
|
| 236 | + if (isset($Settings["B"])) { $this->Data[$Nodes]["B"] = $Settings["B"]; } |
|
| 237 | + if (isset($Settings["Alpha"])) { $this->Data[$Nodes]["Alpha"] = $Settings["Alpha"]; } |
|
| 238 | + if (isset($Settings["BorderR"])) { $this->Data[$Nodes]["BorderR"] = $Settings["BorderR"]; } |
|
| 239 | + if (isset($Settings["BorderG"])) { $this->Data[$Nodes]["BorderG"] = $Settings["BorderG"]; } |
|
| 240 | + if (isset($Settings["BorderB"])) { $this->Data[$Nodes]["BorderB"] = $Settings["BorderB"]; } |
|
| 241 | + if (isset($Settings["BorderAlpha"])) { $this->Data[$Nodes]["BorderAlpha"] = $Settings["BorderAlpha"]; } |
|
| 242 | + if (isset($Settings["Surrounding"])) { $this->Data[$Nodes]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; } |
|
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | |
@@ -250,22 +250,22 @@ discard block |
||
| 250 | 250 | /* Check if a connection exists and create it if required */ |
| 251 | 251 | function checkConnection($SourceID, $TargetID) |
| 252 | 252 | { |
| 253 | - if ( isset($this->Data[$SourceID]["Connections"]) ) |
|
| 253 | + if (isset($this->Data[$SourceID]["Connections"])) |
|
| 254 | 254 | { |
| 255 | 255 | foreach ($this->Data[$SourceID]["Connections"] as $Key => $ConnectionID) |
| 256 | - { if ( $TargetID == $ConnectionID ) { return(TRUE); } } |
|
| 256 | + { if ($TargetID == $ConnectionID) { return(TRUE); } } |
|
| 257 | 257 | } |
| 258 | 258 | $this->Data[$SourceID]["Connections"][] = $TargetID; |
| 259 | 259 | } |
| 260 | 260 | /* Get the median linked nodes position */ |
| 261 | - function getMedianOffset($Key,$X,$Y) |
|
| 261 | + function getMedianOffset($Key, $X, $Y) |
|
| 262 | 262 | { |
| 263 | 263 | $Cpt = 1; |
| 264 | - if ( isset($this->Data[$Key]["Connections"]) ) |
|
| 264 | + if (isset($this->Data[$Key]["Connections"])) |
|
| 265 | 265 | { |
| 266 | - foreach($this->Data[$Key]["Connections"] as $ID => $NodeID) |
|
| 266 | + foreach ($this->Data[$Key]["Connections"] as $ID => $NodeID) |
|
| 267 | 267 | { |
| 268 | - if ( isset($this->Data[$NodeID]["X"]) && isset($this->Data[$NodeID]["Y"]) ) |
|
| 268 | + if (isset($this->Data[$NodeID]["X"]) && isset($this->Data[$NodeID]["Y"])) |
|
| 269 | 269 | { |
| 270 | 270 | $X = $X + $this->Data[$NodeID]["X"]; |
| 271 | 271 | $Y = $Y + $this->Data[$NodeID]["Y"]; |
@@ -273,18 +273,18 @@ discard block |
||
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | - return(array("X"=>$X/$Cpt,"Y"=>$Y/$Cpt)); |
|
| 276 | + return(array("X"=>$X/$Cpt, "Y"=>$Y/$Cpt)); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /* Return the ID of the attached partner with the biggest weight */ |
| 280 | 280 | function getBiggestPartner($Key) |
| 281 | 281 | { |
| 282 | - if ( !isset($this->Data[$Key]["Connections"]) ) { return(""); } |
|
| 282 | + if (!isset($this->Data[$Key]["Connections"])) { return(""); } |
|
| 283 | 283 | |
| 284 | 284 | $MaxWeight = 0; $Result = ""; |
| 285 | - foreach($this->Data[$Key]["Connections"] as $Key => $PeerID) |
|
| 285 | + foreach ($this->Data[$Key]["Connections"] as $Key => $PeerID) |
|
| 286 | 286 | { |
| 287 | - if ( $this->Data[$PeerID]["Weight"] > $MaxWeight ) |
|
| 287 | + if ($this->Data[$PeerID]["Weight"] > $MaxWeight) |
|
| 288 | 288 | { $MaxWeight = $this->Data[$PeerID]["Weight"]; $Result = $PeerID; } |
| 289 | 289 | } |
| 290 | 290 | return($Result); |
@@ -293,94 +293,94 @@ discard block |
||
| 293 | 293 | /* Do the initial node positions computing pass */ |
| 294 | 294 | function firstPass($Algorithm) |
| 295 | 295 | { |
| 296 | - $CenterX = ($this->X2 - $this->X1) / 2 + $this->X1; |
|
| 297 | - $CenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1; |
|
| 296 | + $CenterX = ($this->X2 - $this->X1)/2 + $this->X1; |
|
| 297 | + $CenterY = ($this->Y2 - $this->Y1)/2 + $this->Y1; |
|
| 298 | 298 | |
| 299 | 299 | /* Check connections reciprocity */ |
| 300 | - foreach($this->Data as $Key => $Settings) |
|
| 300 | + foreach ($this->Data as $Key => $Settings) |
|
| 301 | 301 | { |
| 302 | - if ( isset($Settings["Connections"]) ) |
|
| 302 | + if (isset($Settings["Connections"])) |
|
| 303 | 303 | { |
| 304 | - foreach($Settings["Connections"] as $ID => $ConnectionID) |
|
| 305 | - $this->checkConnection($ConnectionID,$Key); |
|
| 304 | + foreach ($Settings["Connections"] as $ID => $ConnectionID) |
|
| 305 | + $this->checkConnection($ConnectionID, $Key); |
|
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if ( $this->AutoComputeFreeZone ) { $this->autoFreeZone(); } |
|
| 309 | + if ($this->AutoComputeFreeZone) { $this->autoFreeZone(); } |
|
| 310 | 310 | |
| 311 | 311 | /* Get the max number of connections */ |
| 312 | 312 | $MaxConnections = 0; |
| 313 | - foreach($this->Data as $Key => $Settings) |
|
| 314 | - { if ( isset($Settings["Connections"]) ) { if ( $MaxConnections < count($Settings["Connections"] ) ) { $MaxConnections = count($Settings["Connections"]); } } } |
|
| 313 | + foreach ($this->Data as $Key => $Settings) |
|
| 314 | + { if (isset($Settings["Connections"])) { if ($MaxConnections < count($Settings["Connections"])) { $MaxConnections = count($Settings["Connections"]); } } } |
|
| 315 | 315 | |
| 316 | - if ( $Algorithm == ALGORITHM_WEIGHTED ) |
|
| 316 | + if ($Algorithm == ALGORITHM_WEIGHTED) |
|
| 317 | 317 | { |
| 318 | - foreach($this->Data as $Key => $Settings) |
|
| 318 | + foreach ($this->Data as $Key => $Settings) |
|
| 319 | 319 | { |
| 320 | - if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 321 | - if ( $Settings["Type"] == NODE_TYPE_FREE ) |
|
| 320 | + if ($Settings["Type"] == NODE_TYPE_CENTRAL) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 321 | + if ($Settings["Type"] == NODE_TYPE_FREE) |
|
| 322 | 322 | { |
| 323 | - if ( isset($Settings["Connections"]) ) |
|
| 323 | + if (isset($Settings["Connections"])) |
|
| 324 | 324 | { $Connections = count($Settings["Connections"]); } |
| 325 | 325 | else |
| 326 | 326 | { $Connections = 0; } |
| 327 | 327 | |
| 328 | 328 | $Ring = $MaxConnections - $Connections; |
| 329 | - $Angle = rand(0,360); |
|
| 329 | + $Angle = rand(0, 360); |
|
| 330 | 330 | |
| 331 | - $this->Data[$Key]["X"] = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX; |
|
| 332 | - $this->Data[$Key]["Y"] = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY; |
|
| 331 | + $this->Data[$Key]["X"] = cos(deg2rad($Angle))*($Ring*$this->RingSize) + $CenterX; |
|
| 332 | + $this->Data[$Key]["Y"] = sin(deg2rad($Angle))*($Ring*$this->RingSize) + $CenterY; |
|
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | - elseif ( $Algorithm == ALGORITHM_CENTRAL ) |
|
| 336 | + elseif ($Algorithm == ALGORITHM_CENTRAL) |
|
| 337 | 337 | { |
| 338 | 338 | /* Put a weight on each nodes */ |
| 339 | - foreach($this->Data as $Key => $Settings) |
|
| 339 | + foreach ($this->Data as $Key => $Settings) |
|
| 340 | 340 | { |
| 341 | - if ( isset($Settings["Connections"]) ) |
|
| 341 | + if (isset($Settings["Connections"])) |
|
| 342 | 342 | $this->Data[$Key]["Weight"] = count($Settings["Connections"]); |
| 343 | 343 | else |
| 344 | 344 | $this->Data[$Key]["Weight"] = 0; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | $MaxConnections = $MaxConnections + 1; |
| 348 | - for($i=$MaxConnections;$i>=0;$i--) |
|
| 348 | + for ($i = $MaxConnections; $i >= 0; $i--) |
|
| 349 | 349 | { |
| 350 | - foreach($this->Data as $Key => $Settings) |
|
| 350 | + foreach ($this->Data as $Key => $Settings) |
|
| 351 | 351 | { |
| 352 | - if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 353 | - if ( $Settings["Type"] == NODE_TYPE_FREE ) |
|
| 352 | + if ($Settings["Type"] == NODE_TYPE_CENTRAL) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 353 | + if ($Settings["Type"] == NODE_TYPE_FREE) |
|
| 354 | 354 | { |
| 355 | - if ( isset($Settings["Connections"]) ) |
|
| 355 | + if (isset($Settings["Connections"])) |
|
| 356 | 356 | { $Connections = count($Settings["Connections"]); } |
| 357 | 357 | else |
| 358 | 358 | { $Connections = 0; } |
| 359 | 359 | |
| 360 | - if ( $Connections == $i ) |
|
| 360 | + if ($Connections == $i) |
|
| 361 | 361 | { |
| 362 | 362 | $BiggestPartner = $this->getBiggestPartner($Key); |
| 363 | - if ( $BiggestPartner != "" ) |
|
| 363 | + if ($BiggestPartner != "") |
|
| 364 | 364 | { |
| 365 | 365 | $Ring = $this->Data[$BiggestPartner]["FreeZone"]; |
| 366 | 366 | $Weight = $this->Data[$BiggestPartner]["Weight"]; |
| 367 | - $AngleDivision = 360 / $this->Data[$BiggestPartner]["Weight"]; |
|
| 367 | + $AngleDivision = 360/$this->Data[$BiggestPartner]["Weight"]; |
|
| 368 | 368 | $Done = FALSE; $Tries = 0; |
| 369 | 369 | while (!$Done && $Tries <= $Weight*2) |
| 370 | 370 | { |
| 371 | 371 | $Tries++; |
| 372 | - $Angle = floor(rand(0,$Weight)*$AngleDivision); |
|
| 373 | - if ( !isset($this->Data[$BiggestPartner]["Angular"][$Angle]) || !isset($this->Data[$BiggestPartner]["Angular"]) ) |
|
| 372 | + $Angle = floor(rand(0, $Weight)*$AngleDivision); |
|
| 373 | + if (!isset($this->Data[$BiggestPartner]["Angular"][$Angle]) || !isset($this->Data[$BiggestPartner]["Angular"])) |
|
| 374 | 374 | { |
| 375 | 375 | $this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle; |
| 376 | 376 | $Done = TRUE; |
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | - if ( !$Done ) |
|
| 380 | - { $Angle = rand(0,360); $this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle; } |
|
| 379 | + if (!$Done) |
|
| 380 | + { $Angle = rand(0, 360); $this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle; } |
|
| 381 | 381 | |
| 382 | - $X = cos(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["X"]; |
|
| 383 | - $Y = sin(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["Y"]; |
|
| 382 | + $X = cos(deg2rad($Angle))*($Ring) + $this->Data[$BiggestPartner]["X"]; |
|
| 383 | + $Y = sin(deg2rad($Angle))*($Ring) + $this->Data[$BiggestPartner]["Y"]; |
|
| 384 | 384 | |
| 385 | 385 | $this->Data[$Key]["X"] = $X; |
| 386 | 386 | $this->Data[$Key]["Y"] = $Y; |
@@ -390,30 +390,30 @@ discard block |
||
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | - elseif ( $Algorithm == ALGORITHM_CIRCULAR ) |
|
| 393 | + elseif ($Algorithm == ALGORITHM_CIRCULAR) |
|
| 394 | 394 | { |
| 395 | 395 | $MaxConnections = $MaxConnections + 1; |
| 396 | - for($i=$MaxConnections;$i>=0;$i--) |
|
| 396 | + for ($i = $MaxConnections; $i >= 0; $i--) |
|
| 397 | 397 | { |
| 398 | - foreach($this->Data as $Key => $Settings) |
|
| 398 | + foreach ($this->Data as $Key => $Settings) |
|
| 399 | 399 | { |
| 400 | - if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 401 | - if ( $Settings["Type"] == NODE_TYPE_FREE ) |
|
| 400 | + if ($Settings["Type"] == NODE_TYPE_CENTRAL) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 401 | + if ($Settings["Type"] == NODE_TYPE_FREE) |
|
| 402 | 402 | { |
| 403 | - if ( isset($Settings["Connections"]) ) |
|
| 403 | + if (isset($Settings["Connections"])) |
|
| 404 | 404 | { $Connections = count($Settings["Connections"]); } |
| 405 | 405 | else |
| 406 | 406 | { $Connections = 0; } |
| 407 | 407 | |
| 408 | - if ( $Connections == $i ) |
|
| 408 | + if ($Connections == $i) |
|
| 409 | 409 | { |
| 410 | 410 | $Ring = $MaxConnections - $Connections; |
| 411 | - $Angle = rand(0,360); |
|
| 411 | + $Angle = rand(0, 360); |
|
| 412 | 412 | |
| 413 | - $X = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX; |
|
| 414 | - $Y = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY; |
|
| 413 | + $X = cos(deg2rad($Angle))*($Ring*$this->RingSize) + $CenterX; |
|
| 414 | + $Y = sin(deg2rad($Angle))*($Ring*$this->RingSize) + $CenterY; |
|
| 415 | 415 | |
| 416 | - $MedianOffset = $this->getMedianOffset($Key,$X,$Y); |
|
| 416 | + $MedianOffset = $this->getMedianOffset($Key, $X, $Y); |
|
| 417 | 417 | |
| 418 | 418 | $this->Data[$Key]["X"] = $MedianOffset["X"]; |
| 419 | 419 | $this->Data[$Key]["Y"] = $MedianOffset["Y"]; |
@@ -422,16 +422,16 @@ discard block |
||
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | - elseif ( $Algorithm == ALGORITHM_RANDOM ) |
|
| 425 | + elseif ($Algorithm == ALGORITHM_RANDOM) |
|
| 426 | 426 | { |
| 427 | - foreach($this->Data as $Key => $Settings) |
|
| 427 | + foreach ($this->Data as $Key => $Settings) |
|
| 428 | 428 | { |
| 429 | - if ( $Settings["Type"] == NODE_TYPE_FREE ) |
|
| 429 | + if ($Settings["Type"] == NODE_TYPE_FREE) |
|
| 430 | 430 | { |
| 431 | - $this->Data[$Key]["X"] = $CenterX + rand(-20,20); |
|
| 432 | - $this->Data[$Key]["Y"] = $CenterY + rand(-20,20); |
|
| 431 | + $this->Data[$Key]["X"] = $CenterX + rand(-20, 20); |
|
| 432 | + $this->Data[$Key]["Y"] = $CenterY + rand(-20, 20); |
|
| 433 | 433 | } |
| 434 | - if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 434 | + if ($Settings["Type"] == NODE_TYPE_CENTRAL) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; } |
|
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | 437 | } |
@@ -440,9 +440,9 @@ discard block |
||
| 440 | 440 | function doPass() |
| 441 | 441 | { |
| 442 | 442 | /* Compute vectors */ |
| 443 | - foreach($this->Data as $Key => $Settings) |
|
| 443 | + foreach ($this->Data as $Key => $Settings) |
|
| 444 | 444 | { |
| 445 | - if ( $Settings["Type"] != NODE_TYPE_CENTRAL ) |
|
| 445 | + if ($Settings["Type"] != NODE_TYPE_CENTRAL) |
|
| 446 | 446 | { |
| 447 | 447 | unset($this->Data[$Key]["Vectors"]); |
| 448 | 448 | |
@@ -450,48 +450,48 @@ discard block |
||
| 450 | 450 | $Y1 = $Settings["Y"]; |
| 451 | 451 | |
| 452 | 452 | /* Repulsion vectors */ |
| 453 | - foreach($this->Data as $Key2 => $Settings2) |
|
| 453 | + foreach ($this->Data as $Key2 => $Settings2) |
|
| 454 | 454 | { |
| 455 | - if ( $Key != $Key2 ) |
|
| 455 | + if ($Key != $Key2) |
|
| 456 | 456 | { |
| 457 | 457 | $X2 = $this->Data[$Key2]["X"]; |
| 458 | 458 | $Y2 = $this->Data[$Key2]["Y"]; |
| 459 | 459 | $FreeZone = $this->Data[$Key2]["FreeZone"]; |
| 460 | 460 | |
| 461 | - $Distance = $this->getDistance($X1,$Y1,$X2,$Y2); |
|
| 462 | - $Angle = $this->getAngle($X1,$Y1,$X2,$Y2) + 180; |
|
| 461 | + $Distance = $this->getDistance($X1, $Y1, $X2, $Y2); |
|
| 462 | + $Angle = $this->getAngle($X1, $Y1, $X2, $Y2) + 180; |
|
| 463 | 463 | |
| 464 | 464 | /* Nodes too close, repulsion occurs */ |
| 465 | - if ( $Distance < $FreeZone ) |
|
| 465 | + if ($Distance < $FreeZone) |
|
| 466 | 466 | { |
| 467 | - $Force = log(pow(2,$FreeZone-$Distance)); |
|
| 468 | - if ( $Force > 1 ) |
|
| 469 | - { $this->Data[$Key]["Vectors"][] = array("Type"=>"R","Angle"=>$Angle % 360,"Force"=>$Force); } |
|
| 467 | + $Force = log(pow(2, $FreeZone - $Distance)); |
|
| 468 | + if ($Force > 1) |
|
| 469 | + { $this->Data[$Key]["Vectors"][] = array("Type"=>"R", "Angle"=>$Angle%360, "Force"=>$Force); } |
|
| 470 | 470 | } |
| 471 | 471 | } |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | /* Attraction vectors */ |
| 475 | - if ( isset($Settings["Connections"]) ) |
|
| 475 | + if (isset($Settings["Connections"])) |
|
| 476 | 476 | { |
| 477 | - foreach($Settings["Connections"] as $ID => $NodeID) |
|
| 477 | + foreach ($Settings["Connections"] as $ID => $NodeID) |
|
| 478 | 478 | { |
| 479 | - if ( isset($this->Data[$NodeID]) ) |
|
| 479 | + if (isset($this->Data[$NodeID])) |
|
| 480 | 480 | { |
| 481 | 481 | $X2 = $this->Data[$NodeID]["X"]; |
| 482 | 482 | $Y2 = $this->Data[$NodeID]["Y"]; |
| 483 | 483 | $FreeZone = $this->Data[$Key2]["FreeZone"]; |
| 484 | 484 | |
| 485 | - $Distance = $this->getDistance($X1,$Y1,$X2,$Y2); |
|
| 486 | - $Angle = $this->getAngle($X1,$Y1,$X2,$Y2); |
|
| 485 | + $Distance = $this->getDistance($X1, $Y1, $X2, $Y2); |
|
| 486 | + $Angle = $this->getAngle($X1, $Y1, $X2, $Y2); |
|
| 487 | 487 | |
| 488 | - if ( $Distance > $FreeZone ) |
|
| 489 | - $Force = log(($Distance-$FreeZone)+1); |
|
| 488 | + if ($Distance > $FreeZone) |
|
| 489 | + $Force = log(($Distance - $FreeZone) + 1); |
|
| 490 | 490 | else |
| 491 | - { $Force = log(($FreeZone-$Distance)+1); ($Angle = $Angle + 180); } |
|
| 491 | + { $Force = log(($FreeZone - $Distance) + 1); ($Angle = $Angle + 180); } |
|
| 492 | 492 | |
| 493 | - if ( $Force > 1 ) |
|
| 494 | - $this->Data[$Key]["Vectors"][] = array("Type"=>"A","Angle"=>$Angle % 360,"Force"=>$Force); |
|
| 493 | + if ($Force > 1) |
|
| 494 | + $this->Data[$Key]["Vectors"][] = array("Type"=>"A", "Angle"=>$Angle%360, "Force"=>$Force); |
|
| 495 | 495 | } |
| 496 | 496 | } |
| 497 | 497 | } |
@@ -499,22 +499,22 @@ discard block |
||
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | /* Move the nodes accoding to the vectors */ |
| 502 | - foreach($this->Data as $Key => $Settings) |
|
| 502 | + foreach ($this->Data as $Key => $Settings) |
|
| 503 | 503 | { |
| 504 | 504 | $X = $Settings["X"]; |
| 505 | 505 | $Y = $Settings["Y"]; |
| 506 | 506 | |
| 507 | - if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL ) |
|
| 507 | + if (isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL) |
|
| 508 | 508 | { |
| 509 | - foreach($Settings["Vectors"] as $ID => $Vector) |
|
| 509 | + foreach ($Settings["Vectors"] as $ID => $Vector) |
|
| 510 | 510 | { |
| 511 | 511 | $Type = $Vector["Type"]; |
| 512 | 512 | $Force = $Vector["Force"]; |
| 513 | 513 | $Angle = $Vector["Angle"]; |
| 514 | 514 | $Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR; |
| 515 | 515 | |
| 516 | - $X = cos(deg2rad($Angle)) * $Force * $Factor + $X; |
|
| 517 | - $Y = sin(deg2rad($Angle)) * $Force * $Factor + $Y; |
|
| 516 | + $X = cos(deg2rad($Angle))*$Force*$Factor + $X; |
|
| 517 | + $Y = sin(deg2rad($Angle))*$Force*$Factor + $Y; |
|
| 518 | 518 | } |
| 519 | 519 | } |
| 520 | 520 | |
@@ -526,15 +526,15 @@ discard block |
||
| 526 | 526 | function lastPass() |
| 527 | 527 | { |
| 528 | 528 | /* Put everything inside the graph area */ |
| 529 | - foreach($this->Data as $Key => $Settings) |
|
| 529 | + foreach ($this->Data as $Key => $Settings) |
|
| 530 | 530 | { |
| 531 | 531 | $X = $Settings["X"]; |
| 532 | 532 | $Y = $Settings["Y"]; |
| 533 | 533 | |
| 534 | - if ( $X < $this->X1 ) { $X = $this->X1; } |
|
| 535 | - if ( $X > $this->X2 ) { $X = $this->X2; } |
|
| 536 | - if ( $Y < $this->Y1 ) { $Y = $this->Y1; } |
|
| 537 | - if ( $Y > $this->Y2 ) { $Y = $this->Y2; } |
|
| 534 | + if ($X < $this->X1) { $X = $this->X1; } |
|
| 535 | + if ($X > $this->X2) { $X = $this->X2; } |
|
| 536 | + if ($Y < $this->Y1) { $Y = $this->Y1; } |
|
| 537 | + if ($Y > $this->Y2) { $Y = $this->Y2; } |
|
| 538 | 538 | |
| 539 | 539 | $this->Data[$Key]["X"] = $X; |
| 540 | 540 | $this->Data[$Key]["Y"] = $Y; |
@@ -542,21 +542,21 @@ discard block |
||
| 542 | 542 | |
| 543 | 543 | /* Dump all links */ |
| 544 | 544 | $Links = ""; |
| 545 | - foreach($this->Data as $Key => $Settings) |
|
| 545 | + foreach ($this->Data as $Key => $Settings) |
|
| 546 | 546 | { |
| 547 | 547 | $X1 = $Settings["X"]; |
| 548 | 548 | $Y1 = $Settings["Y"]; |
| 549 | 549 | |
| 550 | - if ( isset($Settings["Connections"]) ) |
|
| 550 | + if (isset($Settings["Connections"])) |
|
| 551 | 551 | { |
| 552 | 552 | foreach ($Settings["Connections"] as $ID => $NodeID) |
| 553 | 553 | { |
| 554 | - if ( isset($this->Data[$NodeID]) ) |
|
| 554 | + if (isset($this->Data[$NodeID])) |
|
| 555 | 555 | { |
| 556 | 556 | $X2 = $this->Data[$NodeID]["X"]; |
| 557 | 557 | $Y2 = $this->Data[$NodeID]["Y"]; |
| 558 | 558 | |
| 559 | - $Links[] = array("X1"=>$X1,"Y1"=>$Y1,"X2"=>$X2,"Y2"=>$Y2,"Source"=>$Settings["Name"],"Destination"=>$this->Data[$NodeID]["Name"]); |
|
| 559 | + $Links[] = array("X1"=>$X1, "Y1"=>$Y1, "X2"=>$X2, "Y2"=>$Y2, "Source"=>$Settings["Name"], "Destination"=>$this->Data[$NodeID]["Name"]); |
|
| 560 | 560 | } |
| 561 | 561 | } |
| 562 | 562 | } |
@@ -564,29 +564,29 @@ discard block |
||
| 564 | 564 | |
| 565 | 565 | /* Check collisions */ |
| 566 | 566 | $Conflicts = 0; |
| 567 | - foreach($this->Data as $Key => $Settings) |
|
| 567 | + foreach ($this->Data as $Key => $Settings) |
|
| 568 | 568 | { |
| 569 | 569 | $X1 = $Settings["X"]; |
| 570 | 570 | $Y1 = $Settings["Y"]; |
| 571 | 571 | |
| 572 | - if ( isset($Settings["Connections"]) ) |
|
| 572 | + if (isset($Settings["Connections"])) |
|
| 573 | 573 | { |
| 574 | 574 | foreach ($Settings["Connections"] as $ID => $NodeID) |
| 575 | 575 | { |
| 576 | - if ( isset($this->Data[$NodeID]) ) |
|
| 576 | + if (isset($this->Data[$NodeID])) |
|
| 577 | 577 | { |
| 578 | 578 | $X2 = $this->Data[$NodeID]["X"]; |
| 579 | 579 | $Y2 = $this->Data[$NodeID]["Y"]; |
| 580 | 580 | |
| 581 | - foreach($Links as $IDLinks => $Link) |
|
| 581 | + foreach ($Links as $IDLinks => $Link) |
|
| 582 | 582 | { |
| 583 | 583 | $X3 = $Link["X1"]; $Y3 = $Link["Y1"]; $X4 = $Link["X2"]; $Y4 = $Link["Y2"]; |
| 584 | 584 | |
| 585 | - if ( !($X1 == $X3 && $X2 == $X4 && $Y1 == $Y3 && $Y2 == $Y4 ) ) |
|
| 585 | + if (!($X1 == $X3 && $X2 == $X4 && $Y1 == $Y3 && $Y2 == $Y4)) |
|
| 586 | 586 | { |
| 587 | - if ( $this->intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4) ) |
|
| 587 | + if ($this->intersect($X1, $Y1, $X2, $Y2, $X3, $Y3, $X4, $Y4)) |
|
| 588 | 588 | { |
| 589 | - if ( $Link["Source"] != $Settings["Name"] && $Link["Source"] != $this->Data[$NodeID]["Name"] && $Link["Destination"] != $Settings["Name"] && $Link["Destination"] != $this->Data[$NodeID]["Name"] ) |
|
| 589 | + if ($Link["Source"] != $Settings["Name"] && $Link["Source"] != $this->Data[$NodeID]["Name"] && $Link["Destination"] != $Settings["Name"] && $Link["Destination"] != $this->Data[$NodeID]["Name"]) |
|
| 590 | 590 | { $Conflicts++; } |
| 591 | 591 | } |
| 592 | 592 | } |
@@ -602,31 +602,31 @@ discard block |
||
| 602 | 602 | function center() |
| 603 | 603 | { |
| 604 | 604 | /* Determine the real center */ |
| 605 | - $TargetCenterX = ($this->X2 - $this->X1) / 2 + $this->X1; |
|
| 606 | - $TargetCenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1; |
|
| 605 | + $TargetCenterX = ($this->X2 - $this->X1)/2 + $this->X1; |
|
| 606 | + $TargetCenterY = ($this->Y2 - $this->Y1)/2 + $this->Y1; |
|
| 607 | 607 | |
| 608 | 608 | /* Get current boundaries */ |
| 609 | 609 | $XMin = $this->X2; $XMax = $this->X1; |
| 610 | 610 | $YMin = $this->Y2; $YMax = $this->Y1; |
| 611 | - foreach($this->Data as $Key => $Settings) |
|
| 611 | + foreach ($this->Data as $Key => $Settings) |
|
| 612 | 612 | { |
| 613 | 613 | $X = $Settings["X"]; |
| 614 | 614 | $Y = $Settings["Y"]; |
| 615 | 615 | |
| 616 | - if ( $X < $XMin) { $XMin = $X; } |
|
| 617 | - if ( $X > $XMax) { $XMax = $X; } |
|
| 618 | - if ( $Y < $YMin) { $YMin = $Y; } |
|
| 619 | - if ( $Y > $YMax) { $YMax = $Y; } |
|
| 616 | + if ($X < $XMin) { $XMin = $X; } |
|
| 617 | + if ($X > $XMax) { $XMax = $X; } |
|
| 618 | + if ($Y < $YMin) { $YMin = $Y; } |
|
| 619 | + if ($Y > $YMax) { $YMax = $Y; } |
|
| 620 | 620 | } |
| 621 | - $CurrentCenterX = ($XMax - $XMin) / 2 + $XMin; |
|
| 622 | - $CurrentCenterY = ($YMax - $YMin) / 2 + $YMin; |
|
| 621 | + $CurrentCenterX = ($XMax - $XMin)/2 + $XMin; |
|
| 622 | + $CurrentCenterY = ($YMax - $YMin)/2 + $YMin; |
|
| 623 | 623 | |
| 624 | 624 | /* Compute the offset to apply */ |
| 625 | 625 | $XOffset = $TargetCenterX - $CurrentCenterX; |
| 626 | 626 | $YOffset = $TargetCenterY - $CurrentCenterY; |
| 627 | 627 | |
| 628 | 628 | /* Correct the points position */ |
| 629 | - foreach($this->Data as $Key => $Settings) |
|
| 629 | + foreach ($this->Data as $Key => $Settings) |
|
| 630 | 630 | { |
| 631 | 631 | $this->Data[$Key]["X"] = $Settings["X"] + $XOffset; |
| 632 | 632 | $this->Data[$Key]["Y"] = $Settings["Y"] + $YOffset; |
@@ -634,20 +634,20 @@ discard block |
||
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | /* Create the encoded string */ |
| 637 | - function drawSpring($Object,$Settings="") |
|
| 637 | + function drawSpring($Object, $Settings = "") |
|
| 638 | 638 | { |
| 639 | 639 | $this->pChartObject = $Object; |
| 640 | 640 | |
| 641 | - $Pass = isset($Settings["Pass"]) ? $Settings["Pass"] : 50; |
|
| 642 | - $Retries = isset($Settings["Retry"]) ? $Settings["Retry"] : 10; |
|
| 641 | + $Pass = isset($Settings["Pass"]) ? $Settings["Pass"] : 50; |
|
| 642 | + $Retries = isset($Settings["Retry"]) ? $Settings["Retry"] : 10; |
|
| 643 | 643 | $this->MagneticForceA = isset($Settings["MagneticForceA"]) ? $Settings["MagneticForceA"] : 1.5; |
| 644 | 644 | $this->MagneticForceR = isset($Settings["MagneticForceR"]) ? $Settings["MagneticForceR"] : 2; |
| 645 | - $this->RingSize = isset($Settings["RingSize"]) ? $Settings["RingSize"] : 40; |
|
| 645 | + $this->RingSize = isset($Settings["RingSize"]) ? $Settings["RingSize"] : 40; |
|
| 646 | 646 | $DrawVectors = isset($Settings["DrawVectors"]) ? $Settings["DrawVectors"] : FALSE; |
| 647 | - $DrawQuietZone = isset($Settings["DrawQuietZone"]) ? $Settings["DrawQuietZone"] : FALSE; |
|
| 647 | + $DrawQuietZone = isset($Settings["DrawQuietZone"]) ? $Settings["DrawQuietZone"] : FALSE; |
|
| 648 | 648 | $CenterGraph = isset($Settings["CenterGraph"]) ? $Settings["CenterGraph"] : TRUE; |
| 649 | 649 | $TextPadding = isset($Settings["TextPadding"]) ? $Settings["TextPadding"] : 4; |
| 650 | - $Algorithm = isset($Settings["Algorithm"]) ? $Settings["Algorithm"] : ALGORITHM_WEIGHTED; |
|
| 650 | + $Algorithm = isset($Settings["Algorithm"]) ? $Settings["Algorithm"] : ALGORITHM_WEIGHTED; |
|
| 651 | 651 | |
| 652 | 652 | $FontSize = $Object->FontSize; |
| 653 | 653 | $this->X1 = $Object->GraphAreaX1; |
@@ -656,7 +656,7 @@ discard block |
||
| 656 | 656 | $this->Y2 = $Object->GraphAreaY2; |
| 657 | 657 | |
| 658 | 658 | $Conflicts = 1; $Jobs = 0; $this->History["MinimumConflicts"] = -1; |
| 659 | - while ($Conflicts != 0 && $Jobs < $Retries ) |
|
| 659 | + while ($Conflicts != 0 && $Jobs < $Retries) |
|
| 660 | 660 | { |
| 661 | 661 | $Jobs++; |
| 662 | 662 | |
@@ -664,70 +664,70 @@ discard block |
||
| 664 | 664 | $this->firstPass($Algorithm); |
| 665 | 665 | |
| 666 | 666 | /* Apply the vectors */ |
| 667 | - if ( $Pass > 0 ) |
|
| 667 | + if ($Pass > 0) |
|
| 668 | 668 | { |
| 669 | - for ($i=0; $i<=$Pass; $i++) { $this->doPass(); } |
|
| 669 | + for ($i = 0; $i <= $Pass; $i++) { $this->doPass(); } |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | $Conflicts = $this->lastPass(); |
| 673 | - if ( $this->History["MinimumConflicts"] == -1 || $Conflicts < $this->History["MinimumConflicts"] ) |
|
| 673 | + if ($this->History["MinimumConflicts"] == -1 || $Conflicts < $this->History["MinimumConflicts"]) |
|
| 674 | 674 | { $this->History["MinimumConflicts"] = $Conflicts; $this->History["Result"] = $this->Data; } |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | $Conflicts = $this->History["MinimumConflicts"]; |
| 678 | 678 | $this->Data = $this->History["Result"]; |
| 679 | 679 | |
| 680 | - if ( $CenterGraph ) { $this->center(); } |
|
| 680 | + if ($CenterGraph) { $this->center(); } |
|
| 681 | 681 | |
| 682 | 682 | /* Draw the connections */ |
| 683 | 683 | $Drawn = ""; |
| 684 | - foreach($this->Data as $Key => $Settings) |
|
| 684 | + foreach ($this->Data as $Key => $Settings) |
|
| 685 | 685 | { |
| 686 | 686 | $X = $Settings["X"]; |
| 687 | 687 | $Y = $Settings["Y"]; |
| 688 | 688 | |
| 689 | - if ( isset($Settings["Connections"]) ) |
|
| 689 | + if (isset($Settings["Connections"])) |
|
| 690 | 690 | { |
| 691 | 691 | foreach ($Settings["Connections"] as $ID => $NodeID) |
| 692 | 692 | { |
| 693 | - if ( !isset($Drawn[$Key]) ) { $Drawn[$Key] = ""; } |
|
| 694 | - if ( !isset($Drawn[$NodeID]) ) { $Drawn[$NodeID] = ""; } |
|
| 693 | + if (!isset($Drawn[$Key])) { $Drawn[$Key] = ""; } |
|
| 694 | + if (!isset($Drawn[$NodeID])) { $Drawn[$NodeID] = ""; } |
|
| 695 | 695 | |
| 696 | - if ( isset($this->Data[$NodeID]) && !isset($Drawn[$Key][$NodeID]) && !isset($Drawn[$NodeID][$Key]) ) |
|
| 696 | + if (isset($this->Data[$NodeID]) && !isset($Drawn[$Key][$NodeID]) && !isset($Drawn[$NodeID][$Key])) |
|
| 697 | 697 | { |
| 698 | - $Color = array("R"=>$this->Default["LinkR"],"G"=>$this->Default["LinkG"],"B"=>$this->Default["LinkB"],"Alpha"=>$this->Default["Alpha"]); |
|
| 698 | + $Color = array("R"=>$this->Default["LinkR"], "G"=>$this->Default["LinkG"], "B"=>$this->Default["LinkB"], "Alpha"=>$this->Default["Alpha"]); |
|
| 699 | 699 | |
| 700 | - if ( $this->Links != "" ) |
|
| 700 | + if ($this->Links != "") |
|
| 701 | 701 | { |
| 702 | - if ( isset($this->Links[$Key][$NodeID]["R"]) ) |
|
| 703 | - { $Color = array("R"=>$this->Links[$Key][$NodeID]["R"],"G"=>$this->Links[$Key][$NodeID]["G"],"B"=>$this->Links[$Key][$NodeID]["B"],"Alpha"=>$this->Links[$Key][$NodeID]["Alpha"]); } |
|
| 702 | + if (isset($this->Links[$Key][$NodeID]["R"])) |
|
| 703 | + { $Color = array("R"=>$this->Links[$Key][$NodeID]["R"], "G"=>$this->Links[$Key][$NodeID]["G"], "B"=>$this->Links[$Key][$NodeID]["B"], "Alpha"=>$this->Links[$Key][$NodeID]["Alpha"]); } |
|
| 704 | 704 | |
| 705 | - if ( isset($this->Links[$Key][$NodeID]["Ticks"]) ) |
|
| 705 | + if (isset($this->Links[$Key][$NodeID]["Ticks"])) |
|
| 706 | 706 | { $Color["Ticks"] = $this->Links[$Key][$NodeID]["Ticks"]; } |
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | $X2 = $this->Data[$NodeID]["X"]; |
| 710 | 710 | $Y2 = $this->Data[$NodeID]["Y"]; |
| 711 | - $this->pChartObject->drawLine($X,$Y,$X2,$Y2,$Color); |
|
| 711 | + $this->pChartObject->drawLine($X, $Y, $X2, $Y2, $Color); |
|
| 712 | 712 | $Drawn[$Key][$NodeID] = TRUE; |
| 713 | 713 | |
| 714 | - if ( isset($this->Links) && $this->Links != "" ) |
|
| 714 | + if (isset($this->Links) && $this->Links != "") |
|
| 715 | 715 | { |
| 716 | - if ( isset($this->Links[$Key][$NodeID]["Name"]) || isset($this->Links[$NodeID][$Key]["Name"]) ) |
|
| 716 | + if (isset($this->Links[$Key][$NodeID]["Name"]) || isset($this->Links[$NodeID][$Key]["Name"])) |
|
| 717 | 717 | { |
| 718 | 718 | $Name = isset($this->Links[$Key][$NodeID]["Name"]) ? $this->Links[$Key][$NodeID]["Name"] : $this->Links[$NodeID][$Key]["Name"]; |
| 719 | 719 | $TxtX = ($X2 - $X)/2 + $X; |
| 720 | 720 | $TxtY = ($Y2 - $Y)/2 + $Y; |
| 721 | 721 | |
| 722 | - if ( $X <= $X2 ) |
|
| 723 | - $Angle = (360-$this->getAngle($X,$Y,$X2,$Y2)) % 360; |
|
| 722 | + if ($X <= $X2) |
|
| 723 | + $Angle = (360 - $this->getAngle($X, $Y, $X2, $Y2))%360; |
|
| 724 | 724 | else |
| 725 | - $Angle = (360-$this->getAngle($X2,$Y2,$X,$Y)) % 360; |
|
| 725 | + $Angle = (360 - $this->getAngle($X2, $Y2, $X, $Y))%360; |
|
| 726 | 726 | |
| 727 | 727 | $Settings = $Color; |
| 728 | 728 | $Settings["Angle"] = $Angle; |
| 729 | 729 | $Settings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; |
| 730 | - $this->pChartObject->drawText($TxtX,$TxtY,$Name,$Settings); |
|
| 730 | + $this->pChartObject->drawText($TxtX, $TxtY, $Name, $Settings); |
|
| 731 | 731 | } |
| 732 | 732 | } |
| 733 | 733 | } |
@@ -736,59 +736,59 @@ discard block |
||
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | /* Draw the quiet zones */ |
| 739 | - if ( $DrawQuietZone ) |
|
| 739 | + if ($DrawQuietZone) |
|
| 740 | 740 | { |
| 741 | - foreach($this->Data as $Key => $Settings) |
|
| 741 | + foreach ($this->Data as $Key => $Settings) |
|
| 742 | 742 | { |
| 743 | 743 | $X = $Settings["X"]; |
| 744 | 744 | $Y = $Settings["Y"]; |
| 745 | 745 | $FreeZone = $Settings["FreeZone"]; |
| 746 | 746 | |
| 747 | - $this->pChartObject->drawFilledCircle($X,$Y,$FreeZone,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>2)); |
|
| 747 | + $this->pChartObject->drawFilledCircle($X, $Y, $FreeZone, array("R"=>0, "G"=>0, "B"=>0, "Alpha"=>2)); |
|
| 748 | 748 | } |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | |
| 752 | 752 | /* Draw the nodes */ |
| 753 | - foreach($this->Data as $Key => $Settings) |
|
| 753 | + foreach ($this->Data as $Key => $Settings) |
|
| 754 | 754 | { |
| 755 | 755 | $X = $Settings["X"]; |
| 756 | 756 | $Y = $Settings["Y"]; |
| 757 | - $Name = $Settings["Name"]; |
|
| 757 | + $Name = $Settings["Name"]; |
|
| 758 | 758 | $FreeZone = $Settings["FreeZone"]; |
| 759 | 759 | $Shape = $Settings["Shape"]; |
| 760 | 760 | $Size = $Settings["Size"]; |
| 761 | 761 | |
| 762 | - $Color = array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"],"Alpha"=>$Settings["Alpha"],"BorderR"=>$Settings["BorderR"],"BorderG"=>$Settings["BorderG"],"BorderB"=>$Settings["BorderB"],"BorderApha"=>$Settings["BorderAlpha"]); |
|
| 762 | + $Color = array("R"=>$Settings["R"], "G"=>$Settings["G"], "B"=>$Settings["B"], "Alpha"=>$Settings["Alpha"], "BorderR"=>$Settings["BorderR"], "BorderG"=>$Settings["BorderG"], "BorderB"=>$Settings["BorderB"], "BorderApha"=>$Settings["BorderAlpha"]); |
|
| 763 | 763 | |
| 764 | - if ( $Shape == NODE_SHAPE_CIRCLE ) |
|
| 764 | + if ($Shape == NODE_SHAPE_CIRCLE) |
|
| 765 | 765 | { |
| 766 | - $this->pChartObject->drawFilledCircle($X,$Y,$Size,$Color); |
|
| 766 | + $this->pChartObject->drawFilledCircle($X, $Y, $Size, $Color); |
|
| 767 | 767 | } |
| 768 | - elseif ( $Shape == NODE_SHAPE_TRIANGLE ) |
|
| 768 | + elseif ($Shape == NODE_SHAPE_TRIANGLE) |
|
| 769 | 769 | { |
| 770 | 770 | $Points = ""; |
| 771 | - $Points[] = cos(deg2rad(270)) * $Size + $X; $Points[] = sin(deg2rad(270)) * $Size + $Y; |
|
| 772 | - $Points[] = cos(deg2rad(45)) * $Size + $X; $Points[] = sin(deg2rad(45)) * $Size + $Y; |
|
| 773 | - $Points[] = cos(deg2rad(135)) * $Size + $X; $Points[] = sin(deg2rad(135)) * $Size + $Y; |
|
| 774 | - $this->pChartObject->drawPolygon($Points,$Color); |
|
| 771 | + $Points[] = cos(deg2rad(270))*$Size + $X; $Points[] = sin(deg2rad(270))*$Size + $Y; |
|
| 772 | + $Points[] = cos(deg2rad(45))*$Size + $X; $Points[] = sin(deg2rad(45))*$Size + $Y; |
|
| 773 | + $Points[] = cos(deg2rad(135))*$Size + $X; $Points[] = sin(deg2rad(135))*$Size + $Y; |
|
| 774 | + $this->pChartObject->drawPolygon($Points, $Color); |
|
| 775 | 775 | } |
| 776 | - elseif ( $Shape == NODE_SHAPE_SQUARE ) |
|
| 776 | + elseif ($Shape == NODE_SHAPE_SQUARE) |
|
| 777 | 777 | { |
| 778 | - $Offset = $Size/2; $Size = $Size / 2; |
|
| 779 | - $this->pChartObject->drawFilledRectangle($X-$Offset,$Y-$Offset,$X+$Offset,$Y+$Offset,$Color); |
|
| 778 | + $Offset = $Size/2; $Size = $Size/2; |
|
| 779 | + $this->pChartObject->drawFilledRectangle($X - $Offset, $Y - $Offset, $X + $Offset, $Y + $Offset, $Color); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | - if ( $Name != "" ) |
|
| 782 | + if ($Name != "") |
|
| 783 | 783 | { |
| 784 | - $LabelOptions = array("R"=>$this->Labels["R"],"G"=>$this->Labels["G"],"B"=>$this->Labels["B"],"Alpha"=>$this->Labels["Alpha"]); |
|
| 784 | + $LabelOptions = array("R"=>$this->Labels["R"], "G"=>$this->Labels["G"], "B"=>$this->Labels["B"], "Alpha"=>$this->Labels["Alpha"]); |
|
| 785 | 785 | |
| 786 | - if ( $this->Labels["Type"] == LABEL_LIGHT ) |
|
| 786 | + if ($this->Labels["Type"] == LABEL_LIGHT) |
|
| 787 | 787 | { |
| 788 | 788 | $LabelOptions["Align"] = TEXT_ALIGN_BOTTOMLEFT; |
| 789 | - $this->pChartObject->drawText($X,$Y,$Name,$LabelOptions); |
|
| 789 | + $this->pChartObject->drawText($X, $Y, $Name, $LabelOptions); |
|
| 790 | 790 | } |
| 791 | - elseif ( $this->Labels["Type"] == LABEL_CLASSIC ) |
|
| 791 | + elseif ($this->Labels["Type"] == LABEL_CLASSIC) |
|
| 792 | 792 | { |
| 793 | 793 | $LabelOptions["Align"] = TEXT_ALIGN_TOPMIDDLE; |
| 794 | 794 | $LabelOptions["DrawBox"] = TRUE; |
@@ -798,67 +798,67 @@ discard block |
||
| 798 | 798 | $LabelOptions["BoxRounded"] = TRUE; |
| 799 | 799 | $LabelOptions["NoShadow"] = TRUE; |
| 800 | 800 | |
| 801 | - $this->pChartObject->drawText($X,$Y+$Size+$TextPadding,$Name,$LabelOptions); |
|
| 801 | + $this->pChartObject->drawText($X, $Y + $Size + $TextPadding, $Name, $LabelOptions); |
|
| 802 | 802 | } |
| 803 | 803 | } |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | /* Draw the vectors */ |
| 807 | - if ( $DrawVectors ) |
|
| 807 | + if ($DrawVectors) |
|
| 808 | 808 | { |
| 809 | - foreach($this->Data as $Key => $Settings) |
|
| 809 | + foreach ($this->Data as $Key => $Settings) |
|
| 810 | 810 | { |
| 811 | 811 | $X1 = $Settings["X"]; |
| 812 | 812 | $Y1 = $Settings["Y"]; |
| 813 | 813 | |
| 814 | - if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL ) |
|
| 814 | + if (isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL) |
|
| 815 | 815 | { |
| 816 | - foreach($Settings["Vectors"] as $ID => $Vector) |
|
| 816 | + foreach ($Settings["Vectors"] as $ID => $Vector) |
|
| 817 | 817 | { |
| 818 | 818 | $Type = $Vector["Type"]; |
| 819 | 819 | $Force = $Vector["Force"]; |
| 820 | 820 | $Angle = $Vector["Angle"]; |
| 821 | 821 | $Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR; |
| 822 | - $Color = $Type == "A" ? array("FillR"=>255,"FillG"=>0,"FillB"=>0) : array("FillR"=>0,"FillG"=>255,"FillB"=>0); |
|
| 822 | + $Color = $Type == "A" ? array("FillR"=>255, "FillG"=>0, "FillB"=>0) : array("FillR"=>0, "FillG"=>255, "FillB"=>0); |
|
| 823 | 823 | |
| 824 | - $X2 = cos(deg2rad($Angle)) * $Force * $Factor + $X1; |
|
| 825 | - $Y2 = sin(deg2rad($Angle)) * $Force * $Factor + $Y1; |
|
| 824 | + $X2 = cos(deg2rad($Angle))*$Force*$Factor + $X1; |
|
| 825 | + $Y2 = sin(deg2rad($Angle))*$Force*$Factor + $Y1; |
|
| 826 | 826 | |
| 827 | - $this->pChartObject->drawArrow($X1,$Y1,$X2,$Y2,$Color); |
|
| 827 | + $this->pChartObject->drawArrow($X1, $Y1, $X2, $Y2, $Color); |
|
| 828 | 828 | } |
| 829 | 829 | } |
| 830 | 830 | } |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | - return(array("Pass"=>$Jobs,"Conflicts"=>$Conflicts)); |
|
| 833 | + return(array("Pass"=>$Jobs, "Conflicts"=>$Conflicts)); |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | /* Return the distance between two points */ |
| 837 | - function getDistance($X1,$Y1,$X2,$Y2) |
|
| 838 | - { return (sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1))); } |
|
| 837 | + function getDistance($X1, $Y1, $X2, $Y2) |
|
| 838 | + { return (sqrt(($X2 - $X1)*($X2 - $X1) + ($Y2 - $Y1)*($Y2 - $Y1))); } |
|
| 839 | 839 | |
| 840 | 840 | /* Return the angle made by a line and the X axis */ |
| 841 | - function getAngle($X1,$Y1,$X2,$Y2) |
|
| 841 | + function getAngle($X1, $Y1, $X2, $Y2) |
|
| 842 | 842 | { |
| 843 | - $Opposite = $Y2 - $Y1; $Adjacent = $X2 - $X1;$Angle = rad2deg(atan2($Opposite,$Adjacent)); |
|
| 844 | - if ($Angle > 0) { return($Angle); } else { return(360-abs($Angle)); } |
|
| 843 | + $Opposite = $Y2 - $Y1; $Adjacent = $X2 - $X1; $Angle = rad2deg(atan2($Opposite, $Adjacent)); |
|
| 844 | + if ($Angle > 0) { return($Angle); } else { return(360 - abs($Angle)); } |
|
| 845 | 845 | } |
| 846 | 846 | |
| 847 | - function intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4) |
|
| 847 | + function intersect($X1, $Y1, $X2, $Y2, $X3, $Y3, $X4, $Y4) |
|
| 848 | 848 | { |
| 849 | - $A = (($X3 * $Y4 - $X4 * $Y3) * ($X1 - $X2) - ($X1 * $Y2 - $X2 * $Y1) * ($X3 - $X4)); |
|
| 850 | - $B = (($Y1 - $Y2) * ($X3 - $X4) - ($Y3 - $Y4) * ($X1 - $X2)); |
|
| 849 | + $A = (($X3*$Y4 - $X4*$Y3)*($X1 - $X2) - ($X1*$Y2 - $X2*$Y1)*($X3 - $X4)); |
|
| 850 | + $B = (($Y1 - $Y2)*($X3 - $X4) - ($Y3 - $Y4)*($X1 - $X2)); |
|
| 851 | 851 | |
| 852 | - if ( $B == 0 ) { return(FALSE); } |
|
| 853 | - $Xi = $A / $B; |
|
| 852 | + if ($B == 0) { return(FALSE); } |
|
| 853 | + $Xi = $A/$B; |
|
| 854 | 854 | |
| 855 | 855 | $C = ($X1 - $X2); |
| 856 | - if ( $C == 0 ) { return(FALSE); } |
|
| 857 | - $Yi = $Xi * (($Y1 - $Y2)/$C) + (($X1 * $Y2 - $X2 * $Y1)/$C); |
|
| 856 | + if ($C == 0) { return(FALSE); } |
|
| 857 | + $Yi = $Xi*(($Y1 - $Y2)/$C) + (($X1*$Y2 - $X2*$Y1)/$C); |
|
| 858 | 858 | |
| 859 | - if ( $Xi >= min($X1,$X2) && $Xi >= min($X3,$X4) && $Xi <= max($X1,$X2) && $Xi <= max($X3,$X4)) |
|
| 859 | + if ($Xi >= min($X1, $X2) && $Xi >= min($X3, $X4) && $Xi <= max($X1, $X2) && $Xi <= max($X3, $X4)) |
|
| 860 | 860 | { |
| 861 | - if ( $Yi >= min($Y1,$Y2) && $Yi >= min($Y3,$Y4) && $Yi <= max($Y1,$Y2) && $Yi <= max($Y3,$Y4)) |
|
| 861 | + if ($Yi >= min($Y1, $Y2) && $Yi >= min($Y3, $Y4) && $Yi <= max($Y1, $Y2) && $Yi <= max($Y3, $Y4)) |
|
| 862 | 862 | { return(TRUE); } |
| 863 | 863 | } |
| 864 | 864 | |
@@ -108,8 +108,7 @@ discard block |
||
| 108 | 108 | foreach($this->Data as $Key => $Settings) |
| 109 | 109 | { |
| 110 | 110 | if ( isset($Settings["Connections"]) ) |
| 111 | - { $this->Data[$Key]["FreeZone"] = count($Settings["Connections"])*10 + 20; } |
|
| 112 | - else |
|
| 111 | + { $this->Data[$Key]["FreeZone"] = count($Settings["Connections"])*10 + 20; } else |
|
| 113 | 112 | { $this->Data[$Key]["FreeZone"] = 20; } |
| 114 | 113 | } |
| 115 | 114 | |
@@ -200,11 +199,12 @@ discard block |
||
| 200 | 199 | { |
| 201 | 200 | if ( is_array($Connections ) ) |
| 202 | 201 | { |
| 203 | - foreach($Connections as $Key => $Value) |
|
| 204 | - $this->Data[$NodeID]["Connections"][] = $Value; |
|
| 205 | - } |
|
| 206 | - else |
|
| 207 | - $this->Data[$NodeID]["Connections"][] = $Connections; |
|
| 202 | + foreach($Connections as $Key => $Value) { |
|
| 203 | + $this->Data[$NodeID]["Connections"][] = $Value; |
|
| 204 | + } |
|
| 205 | + } else { |
|
| 206 | + $this->Data[$NodeID]["Connections"][] = $Connections; |
|
| 207 | + } |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
@@ -228,8 +228,7 @@ discard block |
||
| 228 | 228 | if ( isset($Settings["Surrounding"]) ) { $this->Data[$NodeID]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; } |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | - } |
|
| 232 | - else |
|
| 231 | + } else |
|
| 233 | 232 | { |
| 234 | 233 | if ( isset($Settings["R"]) ) { $this->Data[$Nodes]["R"] = $Settings["R"]; } |
| 235 | 234 | if ( isset($Settings["G"]) ) { $this->Data[$Nodes]["G"] = $Settings["G"]; } |
@@ -301,8 +300,9 @@ discard block |
||
| 301 | 300 | { |
| 302 | 301 | if ( isset($Settings["Connections"]) ) |
| 303 | 302 | { |
| 304 | - foreach($Settings["Connections"] as $ID => $ConnectionID) |
|
| 305 | - $this->checkConnection($ConnectionID,$Key); |
|
| 303 | + foreach($Settings["Connections"] as $ID => $ConnectionID) { |
|
| 304 | + $this->checkConnection($ConnectionID,$Key); |
|
| 305 | + } |
|
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | |
@@ -321,8 +321,7 @@ discard block |
||
| 321 | 321 | if ( $Settings["Type"] == NODE_TYPE_FREE ) |
| 322 | 322 | { |
| 323 | 323 | if ( isset($Settings["Connections"]) ) |
| 324 | - { $Connections = count($Settings["Connections"]); } |
|
| 325 | - else |
|
| 324 | + { $Connections = count($Settings["Connections"]); } else |
|
| 326 | 325 | { $Connections = 0; } |
| 327 | 326 | |
| 328 | 327 | $Ring = $MaxConnections - $Connections; |
@@ -332,16 +331,16 @@ discard block |
||
| 332 | 331 | $this->Data[$Key]["Y"] = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY; |
| 333 | 332 | } |
| 334 | 333 | } |
| 335 | - } |
|
| 336 | - elseif ( $Algorithm == ALGORITHM_CENTRAL ) |
|
| 334 | + } elseif ( $Algorithm == ALGORITHM_CENTRAL ) |
|
| 337 | 335 | { |
| 338 | 336 | /* Put a weight on each nodes */ |
| 339 | 337 | foreach($this->Data as $Key => $Settings) |
| 340 | 338 | { |
| 341 | - if ( isset($Settings["Connections"]) ) |
|
| 342 | - $this->Data[$Key]["Weight"] = count($Settings["Connections"]); |
|
| 343 | - else |
|
| 344 | - $this->Data[$Key]["Weight"] = 0; |
|
| 339 | + if ( isset($Settings["Connections"]) ) { |
|
| 340 | + $this->Data[$Key]["Weight"] = count($Settings["Connections"]); |
|
| 341 | + } else { |
|
| 342 | + $this->Data[$Key]["Weight"] = 0; |
|
| 343 | + } |
|
| 345 | 344 | } |
| 346 | 345 | |
| 347 | 346 | $MaxConnections = $MaxConnections + 1; |
@@ -353,8 +352,7 @@ discard block |
||
| 353 | 352 | if ( $Settings["Type"] == NODE_TYPE_FREE ) |
| 354 | 353 | { |
| 355 | 354 | if ( isset($Settings["Connections"]) ) |
| 356 | - { $Connections = count($Settings["Connections"]); } |
|
| 357 | - else |
|
| 355 | + { $Connections = count($Settings["Connections"]); } else |
|
| 358 | 356 | { $Connections = 0; } |
| 359 | 357 | |
| 360 | 358 | if ( $Connections == $i ) |
@@ -389,8 +387,7 @@ discard block |
||
| 389 | 387 | } |
| 390 | 388 | } |
| 391 | 389 | } |
| 392 | - } |
|
| 393 | - elseif ( $Algorithm == ALGORITHM_CIRCULAR ) |
|
| 390 | + } elseif ( $Algorithm == ALGORITHM_CIRCULAR ) |
|
| 394 | 391 | { |
| 395 | 392 | $MaxConnections = $MaxConnections + 1; |
| 396 | 393 | for($i=$MaxConnections;$i>=0;$i--) |
@@ -401,8 +398,7 @@ discard block |
||
| 401 | 398 | if ( $Settings["Type"] == NODE_TYPE_FREE ) |
| 402 | 399 | { |
| 403 | 400 | if ( isset($Settings["Connections"]) ) |
| 404 | - { $Connections = count($Settings["Connections"]); } |
|
| 405 | - else |
|
| 401 | + { $Connections = count($Settings["Connections"]); } else |
|
| 406 | 402 | { $Connections = 0; } |
| 407 | 403 | |
| 408 | 404 | if ( $Connections == $i ) |
@@ -421,8 +417,7 @@ discard block |
||
| 421 | 417 | } |
| 422 | 418 | } |
| 423 | 419 | } |
| 424 | - } |
|
| 425 | - elseif ( $Algorithm == ALGORITHM_RANDOM ) |
|
| 420 | + } elseif ( $Algorithm == ALGORITHM_RANDOM ) |
|
| 426 | 421 | { |
| 427 | 422 | foreach($this->Data as $Key => $Settings) |
| 428 | 423 | { |
@@ -485,13 +480,14 @@ discard block |
||
| 485 | 480 | $Distance = $this->getDistance($X1,$Y1,$X2,$Y2); |
| 486 | 481 | $Angle = $this->getAngle($X1,$Y1,$X2,$Y2); |
| 487 | 482 | |
| 488 | - if ( $Distance > $FreeZone ) |
|
| 489 | - $Force = log(($Distance-$FreeZone)+1); |
|
| 490 | - else |
|
| 483 | + if ( $Distance > $FreeZone ) { |
|
| 484 | + $Force = log(($Distance-$FreeZone)+1); |
|
| 485 | + } else |
|
| 491 | 486 | { $Force = log(($FreeZone-$Distance)+1); ($Angle = $Angle + 180); } |
| 492 | 487 | |
| 493 | - if ( $Force > 1 ) |
|
| 494 | - $this->Data[$Key]["Vectors"][] = array("Type"=>"A","Angle"=>$Angle % 360,"Force"=>$Force); |
|
| 488 | + if ( $Force > 1 ) { |
|
| 489 | + $this->Data[$Key]["Vectors"][] = array("Type"=>"A","Angle"=>$Angle % 360,"Force"=>$Force); |
|
| 490 | + } |
|
| 495 | 491 | } |
| 496 | 492 | } |
| 497 | 493 | } |
@@ -719,10 +715,11 @@ discard block |
||
| 719 | 715 | $TxtX = ($X2 - $X)/2 + $X; |
| 720 | 716 | $TxtY = ($Y2 - $Y)/2 + $Y; |
| 721 | 717 | |
| 722 | - if ( $X <= $X2 ) |
|
| 723 | - $Angle = (360-$this->getAngle($X,$Y,$X2,$Y2)) % 360; |
|
| 724 | - else |
|
| 725 | - $Angle = (360-$this->getAngle($X2,$Y2,$X,$Y)) % 360; |
|
| 718 | + if ( $X <= $X2 ) { |
|
| 719 | + $Angle = (360-$this->getAngle($X,$Y,$X2,$Y2)) % 360; |
|
| 720 | + } else { |
|
| 721 | + $Angle = (360-$this->getAngle($X2,$Y2,$X,$Y)) % 360; |
|
| 722 | + } |
|
| 726 | 723 | |
| 727 | 724 | $Settings = $Color; |
| 728 | 725 | $Settings["Angle"] = $Angle; |
@@ -764,16 +761,14 @@ discard block |
||
| 764 | 761 | if ( $Shape == NODE_SHAPE_CIRCLE ) |
| 765 | 762 | { |
| 766 | 763 | $this->pChartObject->drawFilledCircle($X,$Y,$Size,$Color); |
| 767 | - } |
|
| 768 | - elseif ( $Shape == NODE_SHAPE_TRIANGLE ) |
|
| 764 | + } elseif ( $Shape == NODE_SHAPE_TRIANGLE ) |
|
| 769 | 765 | { |
| 770 | 766 | $Points = ""; |
| 771 | 767 | $Points[] = cos(deg2rad(270)) * $Size + $X; $Points[] = sin(deg2rad(270)) * $Size + $Y; |
| 772 | 768 | $Points[] = cos(deg2rad(45)) * $Size + $X; $Points[] = sin(deg2rad(45)) * $Size + $Y; |
| 773 | 769 | $Points[] = cos(deg2rad(135)) * $Size + $X; $Points[] = sin(deg2rad(135)) * $Size + $Y; |
| 774 | 770 | $this->pChartObject->drawPolygon($Points,$Color); |
| 775 | - } |
|
| 776 | - elseif ( $Shape == NODE_SHAPE_SQUARE ) |
|
| 771 | + } elseif ( $Shape == NODE_SHAPE_SQUARE ) |
|
| 777 | 772 | { |
| 778 | 773 | $Offset = $Size/2; $Size = $Size / 2; |
| 779 | 774 | $this->pChartObject->drawFilledRectangle($X-$Offset,$Y-$Offset,$X+$Offset,$Y+$Offset,$Color); |
@@ -787,8 +782,7 @@ discard block |
||
| 787 | 782 | { |
| 788 | 783 | $LabelOptions["Align"] = TEXT_ALIGN_BOTTOMLEFT; |
| 789 | 784 | $this->pChartObject->drawText($X,$Y,$Name,$LabelOptions); |
| 790 | - } |
|
| 791 | - elseif ( $this->Labels["Type"] == LABEL_CLASSIC ) |
|
| 785 | + } elseif ( $this->Labels["Type"] == LABEL_CLASSIC ) |
|
| 792 | 786 | { |
| 793 | 787 | $LabelOptions["Align"] = TEXT_ALIGN_TOPMIDDLE; |
| 794 | 788 | $LabelOptions["DrawBox"] = TRUE; |
@@ -168,6 +168,7 @@ discard block |
||
| 168 | 168 | /** |
| 169 | 169 | * Implementation of hook_node_view(); add custom actions when a node |
| 170 | 170 | * is viewed (forward compatible to Drupal 7) |
| 171 | + * @param string $view_mode |
|
| 171 | 172 | */ |
| 172 | 173 | function boinctranslate_node_view($node, $view_mode, $langcode) { |
| 173 | 174 | switch($node->type) { |
@@ -706,6 +707,7 @@ discard block |
||
| 706 | 707 | |
| 707 | 708 | /** |
| 708 | 709 | * |
| 710 | + * @param string $type |
|
| 709 | 711 | */ |
| 710 | 712 | function boinctranslate_export_po_generate($language = NULL, $strings = array(), $header = NULL, $type = NULL) { |
| 711 | 713 | |
@@ -1060,6 +1062,7 @@ discard block |
||
| 1060 | 1062 | |
| 1061 | 1063 | /** |
| 1062 | 1064 | * |
| 1065 | + * @param stdClass $file |
|
| 1063 | 1066 | */ |
| 1064 | 1067 | function _boinctranslate_locale_import_po($file, $langcode, $mode, $group = NULL) { |
| 1065 | 1068 | // Try to allocate enough time to parse and import the data. |
@@ -1106,6 +1109,7 @@ discard block |
||
| 1106 | 1109 | |
| 1107 | 1110 | /** |
| 1108 | 1111 | * |
| 1112 | + * @param string $op |
|
| 1109 | 1113 | */ |
| 1110 | 1114 | function _boinctranslate_locale_import_read_po($op, $file, $mode = NULL, $lang = NULL, $group = 'default') { |
| 1111 | 1115 | |
@@ -1449,6 +1453,7 @@ discard block |
||
| 1449 | 1453 | /** |
| 1450 | 1454 | * Modify the _locale_import_one_string_db() function so that it does not add |
| 1451 | 1455 | * translation strings that do not exist on the site |
| 1456 | + * @param string $textgroup |
|
| 1452 | 1457 | */ |
| 1453 | 1458 | function _boinctranslate_locale_import_one_string_db(&$report, $langcode, $source, $translation, $textgroup, $location, $mode, $plid = NULL, $plural = NULL) { |
| 1454 | 1459 | $lid = db_result(db_query("SELECT lid FROM {locales_source} WHERE location = '%s' AND source = '%s' AND textgroup = '%s'", $location, $source, $textgroup)); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * with defined URL paths |
| 29 | 29 | */ |
| 30 | 30 | function boinctranslate_menu() { |
| 31 | - $items['admin/boinc/translation'] = array( |
|
| 31 | + $items['admin/boinc/translation'] = array( |
|
| 32 | 32 | 'title' => 'Environment: Translation', |
| 33 | 33 | 'description' => 'Configure URLs for translation files (i.e. integration |
| 34 | 34 | with BOINC Translation Services).', |
@@ -37,38 +37,38 @@ discard block |
||
| 37 | 37 | 'access arguments' => array('administer site configuration'), |
| 38 | 38 | 'type' => MENU_NORMAL_ITEM, |
| 39 | 39 | 'file' => 'boinctranslate.admin.inc' |
| 40 | - ); |
|
| 41 | - $items['admin/boinc/translation/export'] = array( |
|
| 40 | + ); |
|
| 41 | + $items['admin/boinc/translation/export'] = array( |
|
| 42 | 42 | 'title' => 'Export translations', |
| 43 | 43 | 'page callback' => 'boinctranslate_export_translations', |
| 44 | 44 | 'access arguments' => array('administer site configuration'), |
| 45 | 45 | 'type' => MENU_CALLBACK, |
| 46 | - ); |
|
| 47 | - $items['admin/boinc/translation/import'] = array( |
|
| 46 | + ); |
|
| 47 | + $items['admin/boinc/translation/import'] = array( |
|
| 48 | 48 | 'title' => 'Import translations', |
| 49 | 49 | 'page callback' => 'boinctranslate_refresh_translations', |
| 50 | 50 | 'access arguments' => array('administer site configuration'), |
| 51 | 51 | 'type' => MENU_CALLBACK, |
| 52 | - ); |
|
| 53 | - $items['admin/boinc/translation/initialize-languages'] = array( |
|
| 52 | + ); |
|
| 53 | + $items['admin/boinc/translation/initialize-languages'] = array( |
|
| 54 | 54 | 'title' => 'Install official BOINC languages', |
| 55 | 55 | 'page callback' => 'boinctranslate_initialize_languages', |
| 56 | 56 | 'access arguments' => array('administer site configuration'), |
| 57 | 57 | 'type' => MENU_CALLBACK, |
| 58 | - ); |
|
| 59 | - $items['admin/boinc/translation/update-official-boinc'] = array( |
|
| 58 | + ); |
|
| 59 | + $items['admin/boinc/translation/update-official-boinc'] = array( |
|
| 60 | 60 | 'title' => 'Update official BOINC translations', |
| 61 | 61 | 'page callback' => 'boinctranslate_update_official_boinc_translations', |
| 62 | 62 | 'access arguments' => array('update official BOINC translations'), |
| 63 | 63 | 'type' => MENU_CALLBACK, |
| 64 | - ); |
|
| 65 | - $items['admin/boinc/translation/download-pot'] = array( |
|
| 64 | + ); |
|
| 65 | + $items['admin/boinc/translation/download-pot'] = array( |
|
| 66 | 66 | 'title' => 'Download translation template', |
| 67 | 67 | 'page callback' => 'boinctranslate_download_pot', |
| 68 | 68 | 'access arguments' => array('administer site configuration'), |
| 69 | 69 | 'type' => MENU_CALLBACK, |
| 70 | - ); |
|
| 71 | - return $items; |
|
| 70 | + ); |
|
| 71 | + return $items; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -76,18 +76,18 @@ discard block |
||
| 76 | 76 | * Obsolete in Drupal 7... |
| 77 | 77 | */ |
| 78 | 78 | function boinctranslate_nodeapi(&$node, $op, $a3 = null, $a4 = null) { |
| 79 | - // In Drupal 7, these operation cases will all exist as their own hooks, |
|
| 80 | - // so let's approximate that here so that this function can simply be removed |
|
| 81 | - // upon migration to 7 |
|
| 82 | - switch($op) { |
|
| 83 | - case 'update': |
|
| 79 | + // In Drupal 7, these operation cases will all exist as their own hooks, |
|
| 80 | + // so let's approximate that here so that this function can simply be removed |
|
| 81 | + // upon migration to 7 |
|
| 82 | + switch($op) { |
|
| 83 | + case 'update': |
|
| 84 | 84 | boinctranslate_node_update($node); |
| 85 | 85 | break; |
| 86 | - case 'view': |
|
| 86 | + case 'view': |
|
| 87 | 87 | global $language; |
| 88 | 88 | boinctranslate_node_view($node, 'full', $language->language); |
| 89 | 89 | break; |
| 90 | - default: |
|
| 90 | + default: |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | * is updated (forward compatible to Drupal 7) |
| 97 | 97 | */ |
| 98 | 98 | function boinctranslate_node_update($node) { |
| 99 | - switch($node->type) { |
|
| 100 | - case 'page': |
|
| 99 | + switch($node->type) { |
|
| 100 | + case 'page': |
|
| 101 | 101 | // Add page content to translation table |
| 102 | 102 | $textgroup = 'project'; |
| 103 | 103 | $location = "node:{$node->nid}:body"; |
@@ -105,62 +105,62 @@ discard block |
||
| 105 | 105 | $lid = db_result(db_query(" |
| 106 | 106 | SELECT lid FROM {locales_source} |
| 107 | 107 | WHERE location = '%s' AND textgroup = '%s'", |
| 108 | - $location, $textgroup |
|
| 108 | + $location, $textgroup |
|
| 109 | 109 | )); |
| 110 | 110 | if ($lid) { |
| 111 | - $result = db_query(" |
|
| 111 | + $result = db_query(" |
|
| 112 | 112 | UPDATE {locales_source} |
| 113 | 113 | SET source = '%s' |
| 114 | 114 | WHERE lid = %d", |
| 115 | 115 | $node->body, $lid |
| 116 | - ); |
|
| 117 | - if ($result) { |
|
| 116 | + ); |
|
| 117 | + if ($result) { |
|
| 118 | 118 | watchdog( |
| 119 | - 'boinctranslate', |
|
| 120 | - 'Updated translation source strings for node @nid.', |
|
| 121 | - array('@nid' => $node->nid) |
|
| 119 | + 'boinctranslate', |
|
| 120 | + 'Updated translation source strings for node @nid.', |
|
| 121 | + array('@nid' => $node->nid) |
|
| 122 | 122 | ); |
| 123 | - } |
|
| 124 | - else { |
|
| 123 | + } |
|
| 124 | + else { |
|
| 125 | 125 | drupal_set_message( |
| 126 | - t('Unable to update translation source strings.'), 'error' |
|
| 126 | + t('Unable to update translation source strings.'), 'error' |
|
| 127 | 127 | ); |
| 128 | 128 | watchdog( |
| 129 | - 'boinctranslate', |
|
| 130 | - 'Unable to update translation source strings for node @nid.', |
|
| 131 | - array('@nid' => $node->nid), |
|
| 132 | - WATCHDOG_ERROR |
|
| 129 | + 'boinctranslate', |
|
| 130 | + 'Unable to update translation source strings for node @nid.', |
|
| 131 | + array('@nid' => $node->nid), |
|
| 132 | + WATCHDOG_ERROR |
|
| 133 | 133 | ); |
| 134 | - } |
|
| 134 | + } |
|
| 135 | 135 | } |
| 136 | 136 | else { |
| 137 | - $result = db_query(" |
|
| 137 | + $result = db_query(" |
|
| 138 | 138 | INSERT INTO {locales_source} |
| 139 | 139 | SET location = '%s', textgroup = '%s', source = '%s'", |
| 140 | 140 | $location, $textgroup, $node->body |
| 141 | - ); |
|
| 142 | - if ($result) { |
|
| 141 | + ); |
|
| 142 | + if ($result) { |
|
| 143 | 143 | watchdog( |
| 144 | - 'boinctranslate', |
|
| 145 | - 'Added translation source strings for node @nid.', |
|
| 146 | - array('@nid' => $node->nid) |
|
| 144 | + 'boinctranslate', |
|
| 145 | + 'Added translation source strings for node @nid.', |
|
| 146 | + array('@nid' => $node->nid) |
|
| 147 | 147 | ); |
| 148 | - } |
|
| 149 | - else { |
|
| 148 | + } |
|
| 149 | + else { |
|
| 150 | 150 | drupal_set_message( |
| 151 | - t('Unable to add translation source strings.'), 'error' |
|
| 151 | + t('Unable to add translation source strings.'), 'error' |
|
| 152 | 152 | ); |
| 153 | 153 | watchdog( |
| 154 | - 'boinctranslate', |
|
| 155 | - 'Unable to add translation source strings for node @nid.', |
|
| 156 | - array('@nid' => $node->nid), |
|
| 157 | - WATCHDOG_ERROR |
|
| 154 | + 'boinctranslate', |
|
| 155 | + 'Unable to add translation source strings for node @nid.', |
|
| 156 | + array('@nid' => $node->nid), |
|
| 157 | + WATCHDOG_ERROR |
|
| 158 | 158 | ); |
| 159 | - } |
|
| 159 | + } |
|
| 160 | 160 | } |
| 161 | 161 | break; |
| 162 | 162 | |
| 163 | - default: |
|
| 163 | + default: |
|
| 164 | 164 | |
| 165 | 165 | } |
| 166 | 166 | } |
@@ -170,14 +170,14 @@ discard block |
||
| 170 | 170 | * is viewed (forward compatible to Drupal 7) |
| 171 | 171 | */ |
| 172 | 172 | function boinctranslate_node_view($node, $view_mode, $langcode) { |
| 173 | - switch($node->type) { |
|
| 174 | - case 'page': |
|
| 173 | + switch($node->type) { |
|
| 174 | + case 'page': |
|
| 175 | 175 | // Replace the node body with translated content, if available |
| 176 | 176 | $node->content['body']['#value'] = bts( |
| 177 | - $node->body, array(), $langcode, "project:node:{$node->nid}:body", FALSE |
|
| 177 | + $node->body, array(), $langcode, "project:node:{$node->nid}:body", FALSE |
|
| 178 | 178 | ); |
| 179 | 179 | break; |
| 180 | - default: |
|
| 180 | + default: |
|
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | |
@@ -187,17 +187,17 @@ discard block |
||
| 187 | 187 | * This workaround makes panel page titles and pane titles translatable |
| 188 | 188 | */ |
| 189 | 189 | function boinctranslate_panels_pane_content_alter($content, $pane, $args, $context) { |
| 190 | - if ($content->title) { |
|
| 190 | + if ($content->title) { |
|
| 191 | 191 | $content->title = t($content->title); |
| 192 | - } |
|
| 193 | - return $content; |
|
| 192 | + } |
|
| 193 | + return $content; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
| 197 | 197 | * Implementation of hook_perm() |
| 198 | 198 | */ |
| 199 | 199 | function boinctranslate_perm() { |
| 200 | - return array('update official BOINC translations'); |
|
| 200 | + return array('update official BOINC translations'); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * |
@@ -209,30 +209,30 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | function boinctranslate_initialize_languages() { |
| 211 | 211 | |
| 212 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 212 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 213 | 213 | |
| 214 | - $api_base_url = 'https://www.transifex.com/api/2'; |
|
| 215 | - $project_name = variable_get( |
|
| 214 | + $api_base_url = 'https://www.transifex.com/api/2'; |
|
| 215 | + $project_name = variable_get( |
|
| 216 | 216 | 'boinc_translate_transifex_project_name', '' |
| 217 | - ); |
|
| 218 | - $operations = array(); |
|
| 217 | + ); |
|
| 218 | + $operations = array(); |
|
| 219 | 219 | |
| 220 | - if ($project_name) { |
|
| 220 | + if ($project_name) { |
|
| 221 | 221 | // Get all languages configured for this project at Transifex |
| 222 | 222 | $path = "project/{$project_name}/languages"; |
| 223 | 223 | $response = boinctranslate_transifex_request($path); |
| 224 | 224 | |
| 225 | 225 | if ($response == '404 NOT FOUND') { |
| 226 | - drupal_set_message( |
|
| 226 | + drupal_set_message( |
|
| 227 | 227 | t('Unable to get languages for %project.', |
| 228 | - array( |
|
| 228 | + array( |
|
| 229 | 229 | '%project' => $project_name, |
| 230 | - ) |
|
| 230 | + ) |
|
| 231 | 231 | ), 'warning' |
| 232 | - ); |
|
| 232 | + ); |
|
| 233 | 233 | } |
| 234 | 234 | elseif ($response) { |
| 235 | - if (is_array($response)) { |
|
| 235 | + if (is_array($response)) { |
|
| 236 | 236 | |
| 237 | 237 | $installed_languages = language_list(); |
| 238 | 238 | $available_languages = _locale_get_predefined_list(); |
@@ -242,13 +242,13 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | // Set up Transifex languages in Drupal |
| 244 | 244 | foreach ($response as $language) { |
| 245 | - $posix_code = $language['language_code']; |
|
| 246 | - $rfc_code = strtolower(str_replace('_', '-', $posix_code)); |
|
| 247 | - $transifex_languages[$rfc_code] = $language; |
|
| 248 | - if (!isset($installed_languages[$rfc_code])) { |
|
| 245 | + $posix_code = $language['language_code']; |
|
| 246 | + $rfc_code = strtolower(str_replace('_', '-', $posix_code)); |
|
| 247 | + $transifex_languages[$rfc_code] = $language; |
|
| 248 | + if (!isset($installed_languages[$rfc_code])) { |
|
| 249 | 249 | // See if this language can be installed from a predefined list |
| 250 | 250 | if (isset($available_languages[$rfc_code])) { |
| 251 | - locale_add_language( |
|
| 251 | + locale_add_language( |
|
| 252 | 252 | $rfc_code, |
| 253 | 253 | NULL, |
| 254 | 254 | NULL, |
@@ -256,30 +256,30 @@ discard block |
||
| 256 | 256 | NULL, |
| 257 | 257 | NULL, |
| 258 | 258 | FALSE |
| 259 | - ); |
|
| 260 | - drupal_set_message( |
|
| 259 | + ); |
|
| 260 | + drupal_set_message( |
|
| 261 | 261 | 'Added predefined language: '.$available_languages[$rfc_code][0] |
| 262 | - ); |
|
| 263 | - db_query("UPDATE {languages} SET enabled = 1 WHERE language = '%s'", $rfc_code); |
|
| 262 | + ); |
|
| 263 | + db_query("UPDATE {languages} SET enabled = 1 WHERE language = '%s'", $rfc_code); |
|
| 264 | 264 | } |
| 265 | 265 | else { |
| 266 | - // Retrieve language details from Transifex |
|
| 267 | - $path = "language/{$posix_code}"; |
|
| 268 | - $response = boinctranslate_transifex_request($path); |
|
| 266 | + // Retrieve language details from Transifex |
|
| 267 | + $path = "language/{$posix_code}"; |
|
| 268 | + $response = boinctranslate_transifex_request($path); |
|
| 269 | 269 | |
| 270 | - if ($response == '404 NOT FOUND') { |
|
| 270 | + if ($response == '404 NOT FOUND') { |
|
| 271 | 271 | drupal_set_message( |
| 272 | - t('Unable to get details for language %code.', |
|
| 272 | + t('Unable to get details for language %code.', |
|
| 273 | 273 | array( |
| 274 | - '%code' => $posix_code, |
|
| 274 | + '%code' => $posix_code, |
|
| 275 | 275 | ) |
| 276 | - ), 'warning' |
|
| 276 | + ), 'warning' |
|
| 277 | 277 | ); |
| 278 | - } |
|
| 279 | - elseif ($response) { |
|
| 278 | + } |
|
| 279 | + elseif ($response) { |
|
| 280 | 280 | if (!empty($response['name'])) { |
| 281 | - // Add a custom language to Drupal and enable |
|
| 282 | - locale_add_language( |
|
| 281 | + // Add a custom language to Drupal and enable |
|
| 282 | + locale_add_language( |
|
| 283 | 283 | $rfc_code, |
| 284 | 284 | $response['name'], |
| 285 | 285 | $response['name'], |
@@ -287,362 +287,362 @@ discard block |
||
| 287 | 287 | NULL, |
| 288 | 288 | NULL, |
| 289 | 289 | TRUE |
| 290 | - ); |
|
| 291 | - drupal_set_message( |
|
| 290 | + ); |
|
| 291 | + drupal_set_message( |
|
| 292 | 292 | 'Added new language: '.$response['name'] |
| 293 | - ); |
|
| 293 | + ); |
|
| 294 | 294 | } |
| 295 | 295 | else { |
| 296 | - $variables = array( |
|
| 296 | + $variables = array( |
|
| 297 | 297 | '%code' => $posix_code, |
| 298 | - ); |
|
| 299 | - drupal_set_message( |
|
| 298 | + ); |
|
| 299 | + drupal_set_message( |
|
| 300 | 300 | t('Unable to get details for language %code.', $variables), |
| 301 | 301 | 'error' |
| 302 | - ); |
|
| 303 | - watchdog( |
|
| 302 | + ); |
|
| 303 | + watchdog( |
|
| 304 | 304 | 'boinctranslate', |
| 305 | 305 | 'Unable to get details for language %code.', |
| 306 | 306 | $variables, |
| 307 | 307 | WATCHDOG_ERROR |
| 308 | - ); |
|
| 308 | + ); |
|
| 309 | + } |
|
| 309 | 310 | } |
| 310 | - } |
|
| 311 | - else { |
|
| 312 | - $variables = array( |
|
| 313 | - '%code' => $posix_code, |
|
| 311 | + else { |
|
| 312 | + $variables = array( |
|
| 313 | + '%code' => $posix_code, |
|
| 314 | 314 | ); |
| 315 | 315 | drupal_set_message( |
| 316 | - t('Invalid response while getting details for language %code.', $variables), |
|
| 317 | - 'error' |
|
| 316 | + t('Invalid response while getting details for language %code.', $variables), |
|
| 317 | + 'error' |
|
| 318 | 318 | ); |
| 319 | 319 | watchdog( |
| 320 | - 'boinctranslate', |
|
| 321 | - 'Invalid response while getting details for language %code.', |
|
| 322 | - $variables, |
|
| 323 | - WATCHDOG_ERROR |
|
| 320 | + 'boinctranslate', |
|
| 321 | + 'Invalid response while getting details for language %code.', |
|
| 322 | + $variables, |
|
| 323 | + WATCHDOG_ERROR |
|
| 324 | 324 | ); |
| 325 | - } |
|
| 325 | + } |
|
| 326 | 326 | } |
| 327 | 327 | // Import any language files for the newly added language |
| 328 | 328 | if ($batch = locale_batch_by_language($rfc_code, '_locale_batch_language_finished')) { |
| 329 | - $operations = array_merge($operations, $batch['operations']); |
|
| 330 | - $process_batches = TRUE; |
|
| 329 | + $operations = array_merge($operations, $batch['operations']); |
|
| 330 | + $process_batches = TRUE; |
|
| 331 | + } |
|
| 331 | 332 | } |
| 332 | - } |
|
| 333 | 333 | } |
| 334 | 334 | drupal_set_message('Finished installing official BOINC languages.'); |
| 335 | 335 | // Disable languages that are not in Transifex |
| 336 | 336 | foreach ($installed_languages as $langcode => $language) { |
| 337 | - if (!isset($transifex_languages[$langcode])) { |
|
| 337 | + if (!isset($transifex_languages[$langcode])) { |
|
| 338 | 338 | $disabled_languages[$langcode] = $langcode; |
| 339 | 339 | db_query("UPDATE {languages} SET enabled = 0 WHERE language = '%s'", $langcode); |
| 340 | - } |
|
| 340 | + } |
|
| 341 | 341 | } |
| 342 | 342 | if ($disabled_languages) { |
| 343 | - drupal_set_message('The following languages were not found in Transifex and were disabled: ' . implode(' ', $disabled_languages)); |
|
| 343 | + drupal_set_message('The following languages were not found in Transifex and were disabled: ' . implode(' ', $disabled_languages)); |
|
| 344 | 344 | } |
| 345 | 345 | if ($process_batches) { |
| 346 | - $batch = array( |
|
| 346 | + $batch = array( |
|
| 347 | 347 | 'operations' => $operations, |
| 348 | - ); |
|
| 349 | - batch_set($batch); |
|
| 350 | - batch_process('admin/boinc/translation'); |
|
| 348 | + ); |
|
| 349 | + batch_set($batch); |
|
| 350 | + batch_process('admin/boinc/translation'); |
|
| 351 | + } |
|
| 351 | 352 | } |
| 352 | - } |
|
| 353 | - else { |
|
| 353 | + else { |
|
| 354 | 354 | $variables = array( |
| 355 | - '%project' => $project, |
|
| 355 | + '%project' => $project, |
|
| 356 | 356 | ); |
| 357 | 357 | drupal_set_message( |
| 358 | - t('No languages found for %project. (Does the configured account have sufficient privileges at Transifex?)', $variables), |
|
| 359 | - 'error' |
|
| 358 | + t('No languages found for %project. (Does the configured account have sufficient privileges at Transifex?)', $variables), |
|
| 359 | + 'error' |
|
| 360 | 360 | ); |
| 361 | 361 | watchdog( |
| 362 | - 'boinctranslate', |
|
| 363 | - 'No languages found for %project. (Does the configured account have sufficient privileges at Transifex?)', |
|
| 364 | - $variables, |
|
| 365 | - WATCHDOG_ERROR |
|
| 362 | + 'boinctranslate', |
|
| 363 | + 'No languages found for %project. (Does the configured account have sufficient privileges at Transifex?)', |
|
| 364 | + $variables, |
|
| 365 | + WATCHDOG_ERROR |
|
| 366 | 366 | ); |
| 367 | - } |
|
| 367 | + } |
|
| 368 | 368 | } |
| 369 | 369 | else { |
| 370 | - $variables = array( |
|
| 370 | + $variables = array( |
|
| 371 | 371 | '%project' => $project, |
| 372 | - ); |
|
| 373 | - drupal_set_message( |
|
| 372 | + ); |
|
| 373 | + drupal_set_message( |
|
| 374 | 374 | t('Invalid response while getting languages for %project.', $variables), |
| 375 | 375 | 'error' |
| 376 | - ); |
|
| 377 | - watchdog( |
|
| 376 | + ); |
|
| 377 | + watchdog( |
|
| 378 | 378 | 'boinctranslate', |
| 379 | 379 | 'Invalid response while getting languages for %project.', |
| 380 | 380 | $variables, |
| 381 | 381 | WATCHDOG_ERROR |
| 382 | - ); |
|
| 382 | + ); |
|
| 383 | 383 | } |
| 384 | - } |
|
| 385 | - drupal_goto('admin/boinc/translation'); |
|
| 384 | + } |
|
| 385 | + drupal_goto('admin/boinc/translation'); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
| 389 | 389 | * |
| 390 | 390 | */ |
| 391 | 391 | function boinctranslate_export_translations() { |
| 392 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 393 | - $project_name = variable_get( |
|
| 392 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 393 | + $project_name = variable_get( |
|
| 394 | 394 | 'boinc_translate_transifex_project_name', '' |
| 395 | - ); |
|
| 396 | - // Get resource names from local config |
|
| 397 | - $resource_config = (variable_get( |
|
| 395 | + ); |
|
| 396 | + // Get resource names from local config |
|
| 397 | + $resource_config = (variable_get( |
|
| 398 | 398 | 'boinc_translate_transifex_project_resources', '' |
| 399 | - )); |
|
| 400 | - $resource_names = boinctranslate_parse_resources($resource_config); |
|
| 401 | - $primary_resource = reset($resource_names); |
|
| 399 | + )); |
|
| 400 | + $resource_names = boinctranslate_parse_resources($resource_config); |
|
| 401 | + $primary_resource = reset($resource_names); |
|
| 402 | 402 | |
| 403 | - if ($project_name AND $primary_resource) { |
|
| 403 | + if ($project_name AND $primary_resource) { |
|
| 404 | 404 | // Create or update the translation source, if needed |
| 405 | 405 | $source_exists = FALSE; |
| 406 | 406 | $path = "project/{$project_name}/resources"; |
| 407 | 407 | $resources = boinctranslate_transifex_request($path); |
| 408 | 408 | if ($resources AND is_array($resources)) { |
| 409 | - foreach ($resources as $resource) { |
|
| 409 | + foreach ($resources as $resource) { |
|
| 410 | 410 | if ($resource['slug'] == $primary_resource) { |
| 411 | - $source_exists = TRUE; |
|
| 412 | - break; |
|
| 411 | + $source_exists = TRUE; |
|
| 412 | + break; |
|
| 413 | + } |
|
| 413 | 414 | } |
| 414 | - } |
|
| 415 | - if (!$source_exists) { |
|
| 415 | + if (!$source_exists) { |
|
| 416 | 416 | // Create the source |
| 417 | 417 | $path = "project/{$project_name}/resources"; |
| 418 | 418 | $post = array( |
| 419 | - 'slug' => $primary_resource, |
|
| 420 | - 'name' => 'Drupal-Project', |
|
| 421 | - 'i18n_type' => 'PO', |
|
| 422 | - 'category' => 'Drupal', |
|
| 423 | - 'content' => boinctranslate_get_po('en', 'project'), |
|
| 419 | + 'slug' => $primary_resource, |
|
| 420 | + 'name' => 'Drupal-Project', |
|
| 421 | + 'i18n_type' => 'PO', |
|
| 422 | + 'category' => 'Drupal', |
|
| 423 | + 'content' => boinctranslate_get_po('en', 'project'), |
|
| 424 | 424 | ); |
| 425 | 425 | $result = boinctranslate_transifex_request($path, $post); |
| 426 | - } |
|
| 427 | - else { |
|
| 426 | + } |
|
| 427 | + else { |
|
| 428 | 428 | // Update the source |
| 429 | 429 | $path = "project/{$project_name}/resource/{$primary_resource}/content"; |
| 430 | 430 | $post = array( |
| 431 | - 'content' => boinctranslate_get_po('en', 'project') |
|
| 431 | + 'content' => boinctranslate_get_po('en', 'project') |
|
| 432 | 432 | ); |
| 433 | 433 | $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE); |
| 434 | - } |
|
| 434 | + } |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | if (is_array($result) OR substr($result, 0, 6) != 'ERROR:') { |
| 438 | - $enabled_languages = locale_language_list(); |
|
| 439 | - if ($source_exists) { |
|
| 438 | + $enabled_languages = locale_language_list(); |
|
| 439 | + if ($source_exists) { |
|
| 440 | 440 | drupal_set_message('Updated source translation strings at Transifex'); |
| 441 | - } |
|
| 442 | - else { |
|
| 441 | + } |
|
| 442 | + else { |
|
| 443 | 443 | drupal_set_message('Established new translation resource at Transifex'); |
| 444 | - } |
|
| 445 | - // Try to export translations for all enabled languages |
|
| 446 | - foreach ($enabled_languages as $langcode => $language_name) { |
|
| 444 | + } |
|
| 445 | + // Try to export translations for all enabled languages |
|
| 446 | + foreach ($enabled_languages as $langcode => $language_name) { |
|
| 447 | 447 | if ($langcode == 'en') { |
| 448 | - continue; |
|
| 448 | + continue; |
|
| 449 | 449 | } |
| 450 | 450 | $po_file = boinctranslate_get_po($langcode, 'project'); |
| 451 | 451 | if ($po_file) { |
| 452 | - $path = "project/{$project_name}/resource/{$primary_resource}/translation/{$langcode}"; |
|
| 453 | - $post = array( |
|
| 452 | + $path = "project/{$project_name}/resource/{$primary_resource}/translation/{$langcode}"; |
|
| 453 | + $post = array( |
|
| 454 | 454 | 'content' => $po_file, |
| 455 | - ); |
|
| 456 | - $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE); |
|
| 457 | - if (!is_array($result) |
|
| 455 | + ); |
|
| 456 | + $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE); |
|
| 457 | + if (!is_array($result) |
|
| 458 | 458 | AND substr($result, 0, 6) == 'ERROR:') { |
| 459 | 459 | drupal_set_message( |
| 460 | - "Unable to update {$language_name} translations: {$result}", |
|
| 461 | - 'warning' |
|
| 460 | + "Unable to update {$language_name} translations: {$result}", |
|
| 461 | + 'warning' |
|
| 462 | 462 | ); |
| 463 | - } |
|
| 464 | - else { |
|
| 463 | + } |
|
| 464 | + else { |
|
| 465 | 465 | drupal_set_message("Updated {$language_name} translations"); |
| 466 | 466 | //drupal_set_message('DEBUG: <pre>'.print_r($result,1).'</pre>'); |
| 467 | - } |
|
| 467 | + } |
|
| 468 | 468 | } |
| 469 | 469 | else { |
| 470 | - drupal_set_message("No translations to export for {$language_name}"); |
|
| 470 | + drupal_set_message("No translations to export for {$language_name}"); |
|
| 471 | + } |
|
| 471 | 472 | } |
| 472 | - } |
|
| 473 | 473 | } |
| 474 | 474 | else { |
| 475 | - drupal_set_message( |
|
| 475 | + drupal_set_message( |
|
| 476 | 476 | "Unable to update the translation source: {$result}", |
| 477 | 477 | 'warning' |
| 478 | - ); |
|
| 478 | + ); |
|
| 479 | 479 | } |
| 480 | - } |
|
| 481 | - else { |
|
| 480 | + } |
|
| 481 | + else { |
|
| 482 | 482 | drupal_set_message( |
| 483 | - 'Failed to export translations: Transifex settings are not intiailized.', |
|
| 484 | - 'error' |
|
| 483 | + 'Failed to export translations: Transifex settings are not intiailized.', |
|
| 484 | + 'error' |
|
| 485 | 485 | ); |
| 486 | - } |
|
| 487 | - drupal_goto('admin/boinc/translation'); |
|
| 486 | + } |
|
| 487 | + drupal_goto('admin/boinc/translation'); |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | /** |
| 491 | 491 | * |
| 492 | 492 | */ |
| 493 | 493 | function boinctranslate_update_official_boinc_translations() { |
| 494 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 495 | - $project_name = variable_get( |
|
| 494 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 495 | + $project_name = variable_get( |
|
| 496 | 496 | 'boinc_translate_transifex_standard_name', '' |
| 497 | - ); |
|
| 498 | - $drupal_resource = variable_get( |
|
| 497 | + ); |
|
| 498 | + $drupal_resource = variable_get( |
|
| 499 | 499 | 'boinc_translate_transifex_boinc_drupal_resource', '' |
| 500 | - ); |
|
| 500 | + ); |
|
| 501 | 501 | |
| 502 | - if ($project_name AND $drupal_resource) { |
|
| 502 | + if ($project_name AND $drupal_resource) { |
|
| 503 | 503 | // Create or update the translation source, if needed |
| 504 | 504 | $source_exists = FALSE; |
| 505 | 505 | $path = "project/{$project_name}/resources"; |
| 506 | 506 | $resources = boinctranslate_transifex_request($path); |
| 507 | 507 | if ($resources AND is_array($resources)) { |
| 508 | - foreach ($resources as $resource) { |
|
| 508 | + foreach ($resources as $resource) { |
|
| 509 | 509 | if ($resource['slug'] == $drupal_resource) { |
| 510 | - $source_exists = TRUE; |
|
| 511 | - break; |
|
| 510 | + $source_exists = TRUE; |
|
| 511 | + break; |
|
| 512 | + } |
|
| 512 | 513 | } |
| 513 | - } |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | if ($source_exists) { |
| 517 | - $enabled_languages = locale_language_list(); |
|
| 518 | - // Try to export translations for all enabled languages |
|
| 519 | - foreach ($enabled_languages as $langcode => $language_name) { |
|
| 517 | + $enabled_languages = locale_language_list(); |
|
| 518 | + // Try to export translations for all enabled languages |
|
| 519 | + foreach ($enabled_languages as $langcode => $language_name) { |
|
| 520 | 520 | if ($langcode == 'en') { |
| 521 | - continue; |
|
| 521 | + continue; |
|
| 522 | 522 | } |
| 523 | 523 | $po_file = boinctranslate_get_po($langcode, 'boinc'); |
| 524 | 524 | if ($po_file) { |
| 525 | - $path = "project/{$project_name}/resource/{$drupal_resource}/translation/{$langcode}"; |
|
| 526 | - $post = array( |
|
| 525 | + $path = "project/{$project_name}/resource/{$drupal_resource}/translation/{$langcode}"; |
|
| 526 | + $post = array( |
|
| 527 | 527 | 'content' => $po_file, |
| 528 | - ); |
|
| 529 | - $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE); |
|
| 528 | + ); |
|
| 529 | + $result = boinctranslate_transifex_request($path, $post, TRUE, TRUE); |
|
| 530 | 530 | |
| 531 | - if (!is_array($result)) { |
|
| 531 | + if (!is_array($result)) { |
|
| 532 | 532 | if (substr($result, 0, 6) == 'ERROR:') { |
| 533 | - drupal_set_message( |
|
| 533 | + drupal_set_message( |
|
| 534 | 534 | "Unable to update {$language_name} official BOINC translations: {$result}", |
| 535 | 535 | 'warning' |
| 536 | - ); |
|
| 536 | + ); |
|
| 537 | 537 | } |
| 538 | 538 | elseif ($result == '401 UNAUTHORIZED') { |
| 539 | - drupal_set_message( |
|
| 539 | + drupal_set_message( |
|
| 540 | 540 | 'Not authorized to update official BOINC translations', |
| 541 | 541 | 'warning' |
| 542 | - ); |
|
| 543 | - break; |
|
| 542 | + ); |
|
| 543 | + break; |
|
| 544 | 544 | } |
| 545 | 545 | elseif ($result == 'success') { |
| 546 | - drupal_set_message("Updated {$language_name} official BOINC translations"); |
|
| 546 | + drupal_set_message("Updated {$language_name} official BOINC translations"); |
|
| 547 | 547 | } |
| 548 | 548 | else { |
| 549 | - drupal_set_message( |
|
| 549 | + drupal_set_message( |
|
| 550 | 550 | "Unexpected response for {$language_name}: {$result}", |
| 551 | 551 | 'warning' |
| 552 | - ); |
|
| 552 | + ); |
|
| 553 | 553 | } |
| 554 | - } |
|
| 555 | - else { |
|
| 554 | + } |
|
| 555 | + else { |
|
| 556 | 556 | drupal_set_message("Updated {$language_name} official BOINC translations"); |
| 557 | 557 | //drupal_set_message('DEBUG: <pre>'.print_r($result,1).'</pre>'); |
| 558 | - } |
|
| 558 | + } |
|
| 559 | 559 | } |
| 560 | 560 | else { |
| 561 | - drupal_set_message("No official BOINC translations to export for {$language_name}"); |
|
| 561 | + drupal_set_message("No official BOINC translations to export for {$language_name}"); |
|
| 562 | + } |
|
| 562 | 563 | } |
| 563 | - } |
|
| 564 | 564 | } |
| 565 | 565 | else { |
| 566 | - drupal_set_message( |
|
| 566 | + drupal_set_message( |
|
| 567 | 567 | "The {$drupal_resource} resource does not exist in the {$project_name} project at Transifex", |
| 568 | 568 | 'warning' |
| 569 | - ); |
|
| 569 | + ); |
|
| 570 | 570 | } |
| 571 | - } |
|
| 572 | - else { |
|
| 571 | + } |
|
| 572 | + else { |
|
| 573 | 573 | drupal_set_message( |
| 574 | - 'Failed to export official BOINC translations: Transifex settings are not intiailized.', |
|
| 575 | - 'error' |
|
| 574 | + 'Failed to export official BOINC translations: Transifex settings are not intiailized.', |
|
| 575 | + 'error' |
|
| 576 | 576 | ); |
| 577 | - } |
|
| 578 | - drupal_goto('admin/boinc/translation'); |
|
| 577 | + } |
|
| 578 | + drupal_goto('admin/boinc/translation'); |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | /** |
| 582 | 582 | * |
| 583 | 583 | */ |
| 584 | 584 | function boinctranslate_download_pot($type = 'boinc') { |
| 585 | - $po = boinctranslate_get_po(NULL, $type); |
|
| 586 | - _locale_export_po(NULL, $po); |
|
| 585 | + $po = boinctranslate_get_po(NULL, $type); |
|
| 586 | + _locale_export_po(NULL, $po); |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | /** |
| 590 | 590 | * |
| 591 | 591 | */ |
| 592 | 592 | function boinctranslate_transifex_request($path, $post = NULL, $json = TRUE, $use_put = FALSE, $username = '', $password = '') { |
| 593 | - $debug_mode = variable_get('boinc_debug_mode', 0); |
|
| 593 | + $debug_mode = variable_get('boinc_debug_mode', 0); |
|
| 594 | 594 | |
| 595 | - // Transifex details |
|
| 596 | - $api_base_url = 'https://www.transifex.com/api/2'; |
|
| 597 | - if (!$username) $username = variable_get('boinc_translate_transifex_user', ''); |
|
| 598 | - if (!$password) $password = variable_get('boinc_translate_transifex_pass', ''); |
|
| 595 | + // Transifex details |
|
| 596 | + $api_base_url = 'https://www.transifex.com/api/2'; |
|
| 597 | + if (!$username) $username = variable_get('boinc_translate_transifex_user', ''); |
|
| 598 | + if (!$password) $password = variable_get('boinc_translate_transifex_pass', ''); |
|
| 599 | 599 | |
| 600 | - $url = "{$api_base_url}/{$path}"; |
|
| 601 | - $headers = array( |
|
| 600 | + $url = "{$api_base_url}/{$path}"; |
|
| 601 | + $headers = array( |
|
| 602 | 602 | 'Authorization' => 'Basic ' . base64_encode($username . ":" . $password), |
| 603 | - ); |
|
| 604 | - $data = NULL; |
|
| 603 | + ); |
|
| 604 | + $data = NULL; |
|
| 605 | 605 | |
| 606 | - if ($post) { |
|
| 606 | + if ($post) { |
|
| 607 | 607 | if ($json) { |
| 608 | - $headers['Content-Type'] = 'application/json'; |
|
| 609 | - $data = json_encode($post); |
|
| 608 | + $headers['Content-Type'] = 'application/json'; |
|
| 609 | + $data = json_encode($post); |
|
| 610 | 610 | } |
| 611 | 611 | else { |
| 612 | - $data = drupal_query_string_encode($post); |
|
| 612 | + $data = drupal_query_string_encode($post); |
|
| 613 | 613 | } |
| 614 | 614 | $method = ($use_put) ? 'PUT' : 'POST'; |
| 615 | - } |
|
| 616 | - else { |
|
| 615 | + } |
|
| 616 | + else { |
|
| 617 | 617 | $method = 'GET'; |
| 618 | - } |
|
| 618 | + } |
|
| 619 | 619 | |
| 620 | - $response = drupal_http_request($url, $headers, $method, $data, 1, 10); |
|
| 620 | + $response = drupal_http_request($url, $headers, $method, $data, 1, 10); |
|
| 621 | 621 | |
| 622 | - switch ($response->code) { |
|
| 623 | - case 200: |
|
| 622 | + switch ($response->code) { |
|
| 623 | + case 200: |
|
| 624 | 624 | case 304: |
| 625 | 625 | if ($json) { |
| 626 | - // Process as JSON |
|
| 627 | - return json_decode($response->data, TRUE); |
|
| 626 | + // Process as JSON |
|
| 627 | + return json_decode($response->data, TRUE); |
|
| 628 | 628 | } |
| 629 | 629 | else { |
| 630 | - return (string) $response->data; |
|
| 630 | + return (string) $response->data; |
|
| 631 | 631 | } |
| 632 | 632 | break; |
| 633 | - case 404: |
|
| 633 | + case 404: |
|
| 634 | 634 | return '404 NOT FOUND'; |
| 635 | - case 401: |
|
| 635 | + case 401: |
|
| 636 | 636 | return '401 UNAUTHORIZED'; |
| 637 | - case 400: |
|
| 637 | + case 400: |
|
| 638 | 638 | if ($debug_mode) watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING); |
| 639 | 639 | return "ERROR: {$response->data}"; |
| 640 | - case 405: |
|
| 640 | + case 405: |
|
| 641 | 641 | if ($debug_mode) watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING); |
| 642 | 642 | return "ERROR: User not allowed to perform this action"; |
| 643 | - } |
|
| 643 | + } |
|
| 644 | 644 | |
| 645 | - return NULL; |
|
| 645 | + return NULL; |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | /** |
@@ -650,58 +650,58 @@ discard block |
||
| 650 | 650 | */ |
| 651 | 651 | function boinctranslate_get_po($langcode, $type = 'standard') { |
| 652 | 652 | |
| 653 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 653 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 654 | 654 | |
| 655 | - $all_languages = language_list(); |
|
| 656 | - $language = $langcode ? $all_languages[$langcode] : NULL; |
|
| 657 | - $textgroups = array(); |
|
| 658 | - $strings = array(); |
|
| 655 | + $all_languages = language_list(); |
|
| 656 | + $language = $langcode ? $all_languages[$langcode] : NULL; |
|
| 657 | + $textgroups = array(); |
|
| 658 | + $strings = array(); |
|
| 659 | 659 | |
| 660 | - switch ($type) { |
|
| 661 | - case 'standard': |
|
| 660 | + switch ($type) { |
|
| 661 | + case 'standard': |
|
| 662 | 662 | $textgroups = array( |
| 663 | - 'default', |
|
| 664 | - 'taxonomy', |
|
| 665 | - 'views', |
|
| 663 | + 'default', |
|
| 664 | + 'taxonomy', |
|
| 665 | + 'views', |
|
| 666 | 666 | ); |
| 667 | 667 | break; |
| 668 | - case 'boinc': |
|
| 668 | + case 'boinc': |
|
| 669 | 669 | $textgroups = array( |
| 670 | - 'boinc', |
|
| 670 | + 'boinc', |
|
| 671 | 671 | ); |
| 672 | 672 | break; |
| 673 | - case 'project': |
|
| 673 | + case 'project': |
|
| 674 | 674 | $textgroups = array( |
| 675 | - 'blocks', |
|
| 676 | - 'menu', |
|
| 677 | - 'project', |
|
| 675 | + 'blocks', |
|
| 676 | + 'menu', |
|
| 677 | + 'project', |
|
| 678 | 678 | ); |
| 679 | 679 | break; |
| 680 | - default: |
|
| 680 | + default: |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | - // Merge textgroup strings together for export as one file |
|
| 684 | - foreach ($textgroups as $textgroup) { |
|
| 683 | + // Merge textgroup strings together for export as one file |
|
| 684 | + foreach ($textgroups as $textgroup) { |
|
| 685 | 685 | $strings += _locale_export_get_strings($language, $textgroup); |
| 686 | - } |
|
| 687 | - ksort($strings); |
|
| 688 | - foreach ($strings as $id => $string) { |
|
| 686 | + } |
|
| 687 | + ksort($strings); |
|
| 688 | + foreach ($strings as $id => $string) { |
|
| 689 | 689 | // Set the string context |
| 690 | 690 | $strings[$id]['context'] = trim($string['comment']); |
| 691 | - } |
|
| 692 | - if ($langcode AND $langcode != 'en') { |
|
| 691 | + } |
|
| 692 | + if ($langcode AND $langcode != 'en') { |
|
| 693 | 693 | // If not the source language, remove untranslated strings from the ouput |
| 694 | 694 | foreach ($strings as $i => $string) { |
| 695 | - if (!$string['translation']) { |
|
| 695 | + if (!$string['translation']) { |
|
| 696 | 696 | unset($strings[$i]); |
| 697 | - } |
|
| 697 | + } |
|
| 698 | 698 | } |
| 699 | - } |
|
| 700 | - if ($strings) { |
|
| 699 | + } |
|
| 700 | + if ($strings) { |
|
| 701 | 701 | return boinctranslate_export_po_generate($language, $strings, NULL, $type); |
| 702 | - } |
|
| 702 | + } |
|
| 703 | 703 | |
| 704 | - return NULL; |
|
| 704 | + return NULL; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | /** |
@@ -709,21 +709,21 @@ discard block |
||
| 709 | 709 | */ |
| 710 | 710 | function boinctranslate_export_po_generate($language = NULL, $strings = array(), $header = NULL, $type = NULL) { |
| 711 | 711 | |
| 712 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 713 | - global $user; |
|
| 712 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 713 | + global $user; |
|
| 714 | 714 | |
| 715 | - // unset $language to indicate template creation |
|
| 716 | - if (isset($language) && $language->language == "en") { |
|
| 715 | + // unset $language to indicate template creation |
|
| 716 | + if (isset($language) && $language->language == "en") { |
|
| 717 | 717 | $language = NULL; |
| 718 | - } |
|
| 718 | + } |
|
| 719 | 719 | |
| 720 | - if (!isset($header)) { |
|
| 720 | + if (!isset($header)) { |
|
| 721 | 721 | if (isset($type) && $type == "project") { |
| 722 | - $header = "# ".variable_get('site_name', 'Drupal')." drupal localization template\n"; |
|
| 723 | - $header .= "# Copyright (C) ".date("Y")." ".variable_get('site_name', 'Drupal')."\n"; |
|
| 722 | + $header = "# ".variable_get('site_name', 'Drupal')." drupal localization template\n"; |
|
| 723 | + $header .= "# Copyright (C) ".date("Y")." ".variable_get('site_name', 'Drupal')."\n"; |
|
| 724 | 724 | } else { |
| 725 | - $header = "# BOINC drupal localization template\n"; |
|
| 726 | - $header .= "# Copyright (C) ".date("Y")." University of California\n"; |
|
| 725 | + $header = "# BOINC drupal localization template\n"; |
|
| 726 | + $header .= "# Copyright (C) ".date("Y")." University of California\n"; |
|
| 727 | 727 | } |
| 728 | 728 | $header .= '# Generated by ' . $user->name . ' <' . $user->mail . ">\n"; |
| 729 | 729 | $header .= "#\n"; |
@@ -732,180 +732,180 @@ discard block |
||
| 732 | 732 | $header .= "msgid \"\"\n"; |
| 733 | 733 | $header .= "msgstr \"\"\n"; |
| 734 | 734 | if (isset($type) && $type == "project") { |
| 735 | - $header .= "\"Project-Id-Version: ".variable_get('site_name', 'Drupal')." ".date("Y-m-d-H:iO")."\\n\"\n"; |
|
| 735 | + $header .= "\"Project-Id-Version: ".variable_get('site_name', 'Drupal')." ".date("Y-m-d-H:iO")."\\n\"\n"; |
|
| 736 | 736 | } else { |
| 737 | - $header .= "\"Project-Id-Version: BOINC unknown\\n\"\n"; // TODO: add SHA1 of source checkout here |
|
| 737 | + $header .= "\"Project-Id-Version: BOINC unknown\\n\"\n"; // TODO: add SHA1 of source checkout here |
|
| 738 | 738 | } |
| 739 | 739 | $header .= "\"Report-Msgid-Bugs-To: BOINC translation team <[email protected]>\\n\"\n"; |
| 740 | 740 | $header .= "\"POT-Creation-Date: " . date("Y-m-d H:iO") . "\\n\"\n"; |
| 741 | 741 | if (isset($language)) { |
| 742 | - $header .= "\"PO-Revision-Date: " . date("Y-m-d H:iO") . "\\n\"\n"; |
|
| 742 | + $header .= "\"PO-Revision-Date: " . date("Y-m-d H:iO") . "\\n\"\n"; |
|
| 743 | 743 | } |
| 744 | 744 | $header .= "\"Last-Translator: Generated automatically from Drupal translate interface\\n\"\n"; |
| 745 | 745 | $header .= "\"MIME-Version: 1.0\\n\"\n"; |
| 746 | 746 | $header .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n"; |
| 747 | 747 | $header .= "\"Content-Transfer-Encoding: 8bit\\n\"\n"; |
| 748 | 748 | if (isset($language)) { |
| 749 | - $header .= "\"Language: ".$language->language."\\n\""; |
|
| 750 | - if ($language->formula && $language->plurals) { |
|
| 749 | + $header .= "\"Language: ".$language->language."\\n\""; |
|
| 750 | + if ($language->formula && $language->plurals) { |
|
| 751 | 751 | $header .= "\"Plural-Forms: nplurals=" . $language->plurals . "; plural=" . strtr($language->formula, array('$' => '')) . ";\\n\"\n"; |
| 752 | - } |
|
| 752 | + } |
|
| 753 | 753 | } |
| 754 | 754 | $header .= "\"X-Poedit-SourceCharset: utf-8\\n\"\n"; |
| 755 | - } |
|
| 755 | + } |
|
| 756 | 756 | |
| 757 | - $output = $header . "\n"; |
|
| 757 | + $output = $header . "\n"; |
|
| 758 | 758 | |
| 759 | - foreach ($strings as $lid => $string) { |
|
| 759 | + foreach ($strings as $lid => $string) { |
|
| 760 | 760 | // Only process non-children, children are output below their parent. |
| 761 | 761 | if (!isset($string['child'])) { |
| 762 | - if ($string['comment']) { |
|
| 762 | + if ($string['comment']) { |
|
| 763 | 763 | $output .= '#: ' . $string['comment'] . "\n"; |
| 764 | - } |
|
| 765 | - if ($string['context']) { |
|
| 764 | + } |
|
| 765 | + if ($string['context']) { |
|
| 766 | 766 | $output .= 'msgctxt "' . $string['context'] . "\"\n"; |
| 767 | - } |
|
| 768 | - $output .= 'msgid ' . _locale_export_string($string['source']); |
|
| 769 | - if (!empty($string['plural'])) { |
|
| 767 | + } |
|
| 768 | + $output .= 'msgid ' . _locale_export_string($string['source']); |
|
| 769 | + if (!empty($string['plural'])) { |
|
| 770 | 770 | $plural = $string['plural']; |
| 771 | 771 | $output .= 'msgid_plural ' . _locale_export_string($strings[$plural]['source']); |
| 772 | 772 | if (isset($language)) { |
| 773 | - $translation = $string['translation']; |
|
| 774 | - for ($i = 0; $i < $language->plurals; $i++) { |
|
| 773 | + $translation = $string['translation']; |
|
| 774 | + for ($i = 0; $i < $language->plurals; $i++) { |
|
| 775 | 775 | $output .= 'msgstr[' . $i . '] ' . _locale_export_string($translation); |
| 776 | 776 | if ($plural) { |
| 777 | - $translation = _locale_export_remove_plural($strings[$plural]['translation']); |
|
| 778 | - $plural = isset($strings[$plural]['plural']) ? $strings[$plural]['plural'] : 0; |
|
| 777 | + $translation = _locale_export_remove_plural($strings[$plural]['translation']); |
|
| 778 | + $plural = isset($strings[$plural]['plural']) ? $strings[$plural]['plural'] : 0; |
|
| 779 | 779 | } |
| 780 | 780 | else { |
| 781 | - $translation = ''; |
|
| 781 | + $translation = ''; |
|
| 782 | + } |
|
| 782 | 783 | } |
| 783 | - } |
|
| 784 | 784 | } |
| 785 | 785 | else { |
| 786 | - $output .= 'msgstr[0] ""' . "\n"; |
|
| 787 | - $output .= 'msgstr[1] ""' . "\n"; |
|
| 786 | + $output .= 'msgstr[0] ""' . "\n"; |
|
| 787 | + $output .= 'msgstr[1] ""' . "\n"; |
|
| 788 | + } |
|
| 788 | 789 | } |
| 789 | - } |
|
| 790 | - else { |
|
| 790 | + else { |
|
| 791 | 791 | $output .= 'msgstr ' . _locale_export_string($string['translation']); |
| 792 | - } |
|
| 793 | - $output .= "\n"; |
|
| 792 | + } |
|
| 793 | + $output .= "\n"; |
|
| 794 | 794 | } |
| 795 | - } |
|
| 796 | - return $output; |
|
| 795 | + } |
|
| 796 | + return $output; |
|
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | /** |
| 800 | 800 | * |
| 801 | 801 | */ |
| 802 | 802 | function boinctranslate_refresh_translations() { |
| 803 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 804 | - $errors = array(); |
|
| 805 | - $languages = locale_language_list(); |
|
| 806 | - $translation_resources = array(); |
|
| 807 | - $operations = array(); |
|
| 808 | - $debug_mode = variable_get('boinc_debug_mode', 0); |
|
| 803 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 804 | + $errors = array(); |
|
| 805 | + $languages = locale_language_list(); |
|
| 806 | + $translation_resources = array(); |
|
| 807 | + $operations = array(); |
|
| 808 | + $debug_mode = variable_get('boinc_debug_mode', 0); |
|
| 809 | 809 | |
| 810 | - $boinc_name = variable_get( |
|
| 810 | + $boinc_name = variable_get( |
|
| 811 | 811 | 'boinc_translate_transifex_standard_name', '' |
| 812 | - ); |
|
| 813 | - $boinc_resources = boinctranslate_parse_resources( |
|
| 812 | + ); |
|
| 813 | + $boinc_resources = boinctranslate_parse_resources( |
|
| 814 | 814 | variable_get('boinc_translate_transifex_standard_resources', array()) |
| 815 | - ); |
|
| 816 | - // Add the Official BOINC resource to the list of BOINC resources; |
|
| 817 | - // The official resource overrides any additional resources provided, so it |
|
| 818 | - // should be added to the end so as to be processed last |
|
| 819 | - $drupal_resource = variable_get( |
|
| 815 | + ); |
|
| 816 | + // Add the Official BOINC resource to the list of BOINC resources; |
|
| 817 | + // The official resource overrides any additional resources provided, so it |
|
| 818 | + // should be added to the end so as to be processed last |
|
| 819 | + $drupal_resource = variable_get( |
|
| 820 | 820 | 'boinc_translate_transifex_boinc_drupal_resource', '' |
| 821 | - ); |
|
| 822 | - $boinc_resources[] = $drupal_resource; |
|
| 823 | - if ($boinc_name AND $boinc_resources) { |
|
| 821 | + ); |
|
| 822 | + $boinc_resources[] = $drupal_resource; |
|
| 823 | + if ($boinc_name AND $boinc_resources) { |
|
| 824 | 824 | $translation_resources[$boinc_name] = array( |
| 825 | - 'resources' => $boinc_resources, |
|
| 826 | - 'textgroups' => array( |
|
| 825 | + 'resources' => $boinc_resources, |
|
| 826 | + 'textgroups' => array( |
|
| 827 | 827 | 'boinc', |
| 828 | 828 | 'default', |
| 829 | 829 | 'taxonomy', |
| 830 | 830 | 'views', |
| 831 | - ), |
|
| 831 | + ), |
|
| 832 | 832 | ); |
| 833 | - } |
|
| 834 | - $project_name = variable_get( |
|
| 833 | + } |
|
| 834 | + $project_name = variable_get( |
|
| 835 | 835 | 'boinc_translate_transifex_project_name', '' |
| 836 | - ); |
|
| 837 | - $project_resources = boinctranslate_parse_resources( |
|
| 836 | + ); |
|
| 837 | + $project_resources = boinctranslate_parse_resources( |
|
| 838 | 838 | variable_get('boinc_translate_transifex_project_resources', array()) |
| 839 | - ); |
|
| 840 | - if ($project_name AND $project_resources) { |
|
| 839 | + ); |
|
| 840 | + if ($project_name AND $project_resources) { |
|
| 841 | 841 | $translation_resources[$project_name] = array( |
| 842 | - 'resources' => $project_resources, |
|
| 843 | - 'textgroups' => array( |
|
| 842 | + 'resources' => $project_resources, |
|
| 843 | + 'textgroups' => array( |
|
| 844 | 844 | 'blocks', |
| 845 | 845 | 'menu', |
| 846 | 846 | 'project', |
| 847 | - ), |
|
| 847 | + ), |
|
| 848 | 848 | ); |
| 849 | 849 | // Be sure any strings from the override file are added to the boinc group |
| 850 | 850 | $override_file = './' . drupal_get_path('module', 'boinctranslate') . '/includes/other-boinc-translation-strings.txt'; |
| 851 | 851 | $other_strings = file($override_file); |
| 852 | 852 | if ($other_strings) { |
| 853 | - foreach ($other_strings as $string) { |
|
| 853 | + foreach ($other_strings as $string) { |
|
| 854 | 854 | $string = trim($string); |
| 855 | 855 | if ($string) { |
| 856 | - bts($string); |
|
| 856 | + bts($string); |
|
| 857 | + } |
|
| 857 | 858 | } |
| 858 | - } |
|
| 859 | 859 | } |
| 860 | - } |
|
| 860 | + } |
|
| 861 | 861 | |
| 862 | - foreach ($languages as $langcode => $language) { |
|
| 862 | + foreach ($languages as $langcode => $language) { |
|
| 863 | 863 | if ($langcode == 'en') { |
| 864 | - continue; |
|
| 864 | + continue; |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | $import_stats = array( |
| 868 | - 'new' => 0, |
|
| 869 | - 'updated' => 0, |
|
| 870 | - 'deleted' => 0, |
|
| 871 | - 'skipped' => 0, |
|
| 868 | + 'new' => 0, |
|
| 869 | + 'updated' => 0, |
|
| 870 | + 'deleted' => 0, |
|
| 871 | + 'skipped' => 0, |
|
| 872 | 872 | ); |
| 873 | 873 | |
| 874 | 874 | foreach ($translation_resources as $project => $translation) { |
| 875 | - foreach ($translation['resources'] as $resource) { |
|
| 875 | + foreach ($translation['resources'] as $resource) { |
|
| 876 | 876 | |
| 877 | 877 | // Add this language to the batch operations |
| 878 | 878 | $operations[] = array( |
| 879 | - 'boinctranslate_refresh_translations_op', |
|
| 880 | - array( |
|
| 879 | + 'boinctranslate_refresh_translations_op', |
|
| 880 | + array( |
|
| 881 | 881 | $project, $resource, $langcode, $language, $translation['textgroups'], $debug_mode |
| 882 | - ), |
|
| 882 | + ), |
|
| 883 | 883 | ); |
| 884 | - } |
|
| 884 | + } |
|
| 885 | 885 | } |
| 886 | 886 | if ($batch = locale_batch_by_language($langcode)) { |
| 887 | - foreach ($batch['operations'] as $op) { |
|
| 887 | + foreach ($batch['operations'] as $op) { |
|
| 888 | 888 | $operations[] = array( |
| 889 | - 'boinctranslate_refresh_translations_op', |
|
| 890 | - array( |
|
| 889 | + 'boinctranslate_refresh_translations_op', |
|
| 890 | + array( |
|
| 891 | 891 | NULL, $op[1][0], $langcode, $language, array('default'), $debug_mode |
| 892 | - ), |
|
| 892 | + ), |
|
| 893 | 893 | ); |
| 894 | - } |
|
| 894 | + } |
|
| 895 | + } |
|
| 895 | 896 | } |
| 896 | - } |
|
| 897 | 897 | |
| 898 | - $batch = array( |
|
| 898 | + $batch = array( |
|
| 899 | 899 | 'operations' => $operations, |
| 900 | 900 | 'finished' => 'boinctranslate_refresh_translations_finished', |
| 901 | 901 | 'title' => t('Importing translations'), |
| 902 | 902 | 'init_message' => t('Beginning translation import...'), |
| 903 | 903 | 'progress_message' => t('Applied @current out of @total translation updates.'), |
| 904 | 904 | 'error_message' => t('Translation import has encountered an error.'), |
| 905 | - ); |
|
| 905 | + ); |
|
| 906 | 906 | |
| 907 | - batch_set($batch); |
|
| 908 | - batch_process(); |
|
| 907 | + batch_set($batch); |
|
| 908 | + batch_process(); |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | |
@@ -914,18 +914,18 @@ discard block |
||
| 914 | 914 | */ |
| 915 | 915 | function boinctranslate_refresh_translations_op($project, $resource, $langcode, $language, $textgroups, $debug_mode, &$context) { |
| 916 | 916 | |
| 917 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 917 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 918 | 918 | |
| 919 | - if ($debug_mode) { |
|
| 919 | + if ($debug_mode) { |
|
| 920 | 920 | watchdog( |
| 921 | - 'boinctranslate', |
|
| 922 | - 'Checking for @language updates in @project:@resource', |
|
| 923 | - array('@language' => $language, '@project' => $project, '@resource' => $resource), |
|
| 924 | - WATCHDOG_INFO |
|
| 921 | + 'boinctranslate', |
|
| 922 | + 'Checking for @language updates in @project:@resource', |
|
| 923 | + array('@language' => $language, '@project' => $project, '@resource' => $resource), |
|
| 924 | + WATCHDOG_INFO |
|
| 925 | 925 | ); |
| 926 | - } |
|
| 926 | + } |
|
| 927 | 927 | |
| 928 | - if ($project) { |
|
| 928 | + if ($project) { |
|
| 929 | 929 | // Import the configured resources |
| 930 | 930 | $success = FALSE; |
| 931 | 931 | $message = ''; |
@@ -933,10 +933,10 @@ discard block |
||
| 933 | 933 | $response = boinctranslate_transifex_request($path); |
| 934 | 934 | |
| 935 | 935 | if ($response == '404 NOT FOUND') { |
| 936 | - $message = "Project resource {$project}:{$resource} not found in {$language}."; |
|
| 936 | + $message = "Project resource {$project}:{$resource} not found in {$language}."; |
|
| 937 | 937 | } |
| 938 | 938 | elseif ($response) { |
| 939 | - if (!empty($response['content'])) { |
|
| 939 | + if (!empty($response['content'])) { |
|
| 940 | 940 | $po_text = $response['content']; |
| 941 | 941 | |
| 942 | 942 | // Write the translation file to a temporary location |
@@ -944,164 +944,164 @@ discard block |
||
| 944 | 944 | $file->filepath = file_save_data($po_text, NULL); |
| 945 | 945 | $file->filename = basename($file->filepath); |
| 946 | 946 | if (!$file->filepath) { |
| 947 | - $message = 'Unable to create temporary file in ' |
|
| 947 | + $message = 'Unable to create temporary file in ' |
|
| 948 | 948 | . file_directory_temp() . " for {$language} translation " |
| 949 | 949 | . "resource {$project}:{$resource}"; |
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | foreach ($textgroups as $textgroup) { |
| 953 | - // Import the translations from the file to each related textgroup |
|
| 954 | - if (!$results = _boinctranslate_locale_import_po($file, $langcode, LOCALE_IMPORT_OVERWRITE, $textgroup)) { |
|
| 953 | + // Import the translations from the file to each related textgroup |
|
| 954 | + if (!$results = _boinctranslate_locale_import_po($file, $langcode, LOCALE_IMPORT_OVERWRITE, $textgroup)) { |
|
| 955 | 955 | $message = "The {$language} translation import of" |
| 956 | - . " {$project}:{$resource} failed."; |
|
| 956 | + . " {$project}:{$resource} failed."; |
|
| 957 | 957 | $success = FALSE; |
| 958 | 958 | break; |
| 959 | - } |
|
| 960 | - else { |
|
| 959 | + } |
|
| 960 | + else { |
|
| 961 | 961 | $success = TRUE; |
| 962 | - } |
|
| 962 | + } |
|
| 963 | + } |
|
| 963 | 964 | } |
| 964 | - } |
|
| 965 | - else { |
|
| 965 | + else { |
|
| 966 | 966 | $message = "Unable to read response for {$language} translation import" |
| 967 | - . " of {$project}:{$resource}."; |
|
| 968 | - } |
|
| 967 | + . " of {$project}:{$resource}."; |
|
| 968 | + } |
|
| 969 | 969 | } |
| 970 | 970 | else { |
| 971 | - $message = "Translation data not found in response for {$language}" |
|
| 971 | + $message = "Translation data not found in response for {$language}" |
|
| 972 | 972 | . " translation import of {$project}:{$resource}."; |
| 973 | 973 | } |
| 974 | - } |
|
| 975 | - else { |
|
| 974 | + } |
|
| 975 | + else { |
|
| 976 | 976 | // If project isn't specified, import as a local Drupal resource |
| 977 | 977 | $project = 'drupal.local'; |
| 978 | 978 | $file = new stdClass(); |
| 979 | 979 | $file->filepath = $resource; |
| 980 | 980 | $file->filename = basename($file->filepath); |
| 981 | 981 | if (!$results = _boinctranslate_locale_import_po($file, $langcode, LOCALE_IMPORT_OVERWRITE, $textgroup)) { |
| 982 | - $message = "The {$language} translation import of" |
|
| 982 | + $message = "The {$language} translation import of" |
|
| 983 | 983 | . " local file {$resource} failed."; |
| 984 | - $success = FALSE; |
|
| 985 | - break; |
|
| 984 | + $success = FALSE; |
|
| 985 | + break; |
|
| 986 | 986 | } |
| 987 | 987 | else { |
| 988 | - $success = TRUE; |
|
| 988 | + $success = TRUE; |
|
| 989 | + } |
|
| 989 | 990 | } |
| 990 | - } |
|
| 991 | 991 | |
| 992 | - if ($success) { |
|
| 992 | + if ($success) { |
|
| 993 | 993 | // Store some result for post-processing in the finished callback. |
| 994 | 994 | $context['results']['success'][] = "{$langcode}:{$textgroup}"; |
| 995 | 995 | $message = "Imported {$language} translations in {$project}:{$resource} ({$results['new']} added, {$results['updated']} refreshed, {$results['deleted']} removed)"; |
| 996 | 996 | |
| 997 | 997 | if ($debug_mode) { |
| 998 | - watchdog( |
|
| 998 | + watchdog( |
|
| 999 | 999 | 'boinctranslate', |
| 1000 | 1000 | $message, |
| 1001 | 1001 | array(), |
| 1002 | 1002 | WATCHDOG_INFO |
| 1003 | - ); |
|
| 1003 | + ); |
|
| 1004 | 1004 | } |
| 1005 | - } |
|
| 1006 | - else { |
|
| 1005 | + } |
|
| 1006 | + else { |
|
| 1007 | 1007 | $context['results']['failure'][] = "{$langcode}:{$textgroup}"; |
| 1008 | 1008 | watchdog( |
| 1009 | - 'boinctranslate', |
|
| 1010 | - $message, |
|
| 1011 | - array(), |
|
| 1012 | - WATCHDOG_WARNING |
|
| 1009 | + 'boinctranslate', |
|
| 1010 | + $message, |
|
| 1011 | + array(), |
|
| 1012 | + WATCHDOG_WARNING |
|
| 1013 | 1013 | ); |
| 1014 | - } |
|
| 1014 | + } |
|
| 1015 | 1015 | |
| 1016 | - // Update our progress information. |
|
| 1017 | - $context['sandbox']['progress']++; |
|
| 1018 | - $context['sandbox']['language'] = $langcode; |
|
| 1019 | - $context['message'] = $message; |
|
| 1016 | + // Update our progress information. |
|
| 1017 | + $context['sandbox']['progress']++; |
|
| 1018 | + $context['sandbox']['language'] = $langcode; |
|
| 1019 | + $context['message'] = $message; |
|
| 1020 | 1020 | |
| 1021 | - // Update the progress for the batch engine |
|
| 1022 | - if ($context['sandbox']['progress'] >= $context['sandbox']['max']) { |
|
| 1021 | + // Update the progress for the batch engine |
|
| 1022 | + if ($context['sandbox']['progress'] >= $context['sandbox']['max']) { |
|
| 1023 | 1023 | $context['finished'] = 1; |
| 1024 | - } |
|
| 1025 | - else { |
|
| 1024 | + } |
|
| 1025 | + else { |
|
| 1026 | 1026 | $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; |
| 1027 | - } |
|
| 1027 | + } |
|
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | 1030 | /** |
| 1031 | 1031 | * Batch 'finished' callback |
| 1032 | 1032 | */ |
| 1033 | 1033 | function boinctranslate_refresh_translations_finished($success, $results, $operations) { |
| 1034 | - if ($success) { |
|
| 1034 | + if ($success) { |
|
| 1035 | 1035 | // Let's count our successes |
| 1036 | 1036 | $count = count($results['success']); |
| 1037 | 1037 | $message = "Successfully completed {$count} import operations"; |
| 1038 | 1038 | watchdog( |
| 1039 | - 'boinctranslate', |
|
| 1040 | - 'Successfully completed @count import operations.', |
|
| 1041 | - array('@count' => $count), |
|
| 1042 | - WATCHDOG_INFO |
|
| 1039 | + 'boinctranslate', |
|
| 1040 | + 'Successfully completed @count import operations.', |
|
| 1041 | + array('@count' => $count), |
|
| 1042 | + WATCHDOG_INFO |
|
| 1043 | 1043 | ); |
| 1044 | - } |
|
| 1045 | - else { |
|
| 1044 | + } |
|
| 1045 | + else { |
|
| 1046 | 1046 | // An error occurred. |
| 1047 | 1047 | // $operations contains the operations that remained unprocessed. |
| 1048 | 1048 | $error_operation = reset($operations); |
| 1049 | 1049 | $message = 'An error occurred while processing ' . $error_operation[0] . ' with arguments :' . print_r($error_operation[0], TRUE); |
| 1050 | 1050 | watchdog( |
| 1051 | - 'boinctranslate', |
|
| 1052 | - $message, |
|
| 1053 | - array(), |
|
| 1054 | - WATCHDOG_WARNING |
|
| 1051 | + 'boinctranslate', |
|
| 1052 | + $message, |
|
| 1053 | + array(), |
|
| 1054 | + WATCHDOG_WARNING |
|
| 1055 | 1055 | ); |
| 1056 | - } |
|
| 1057 | - drupal_set_message($message); |
|
| 1058 | - drupal_goto('admin/boinc/translation'); |
|
| 1056 | + } |
|
| 1057 | + drupal_set_message($message); |
|
| 1058 | + drupal_goto('admin/boinc/translation'); |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | /** |
| 1062 | 1062 | * |
| 1063 | 1063 | */ |
| 1064 | 1064 | function _boinctranslate_locale_import_po($file, $langcode, $mode, $group = NULL) { |
| 1065 | - // Try to allocate enough time to parse and import the data. |
|
| 1066 | - if (function_exists('set_time_limit')) { |
|
| 1065 | + // Try to allocate enough time to parse and import the data. |
|
| 1066 | + if (function_exists('set_time_limit')) { |
|
| 1067 | 1067 | @set_time_limit(240); |
| 1068 | - } |
|
| 1068 | + } |
|
| 1069 | 1069 | |
| 1070 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 1070 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 1071 | 1071 | |
| 1072 | - // Check if we have the language already in the database. |
|
| 1073 | - if (!db_fetch_object(db_query("SELECT language FROM {languages} WHERE language = '%s'", $langcode))) { |
|
| 1072 | + // Check if we have the language already in the database. |
|
| 1073 | + if (!db_fetch_object(db_query("SELECT language FROM {languages} WHERE language = '%s'", $langcode))) { |
|
| 1074 | 1074 | drupal_set_message(t('The language selected for import is not supported.'), 'error'); |
| 1075 | 1075 | return FALSE; |
| 1076 | - } |
|
| 1076 | + } |
|
| 1077 | 1077 | |
| 1078 | - // Get strings from file (returns on failure after a partial import, or on success) |
|
| 1079 | - $status = _boinctranslate_locale_import_read_po('db-store', $file, $mode, $langcode, $group); |
|
| 1080 | - if ($status === FALSE) { |
|
| 1078 | + // Get strings from file (returns on failure after a partial import, or on success) |
|
| 1079 | + $status = _boinctranslate_locale_import_read_po('db-store', $file, $mode, $langcode, $group); |
|
| 1080 | + if ($status === FALSE) { |
|
| 1081 | 1081 | // Error messages are set in _locale_import_read_po(). |
| 1082 | 1082 | return FALSE; |
| 1083 | - } |
|
| 1083 | + } |
|
| 1084 | 1084 | |
| 1085 | - // Get status information on import process. |
|
| 1086 | - list($headerdone, $additions, $updates, $deletes, $skips) = _boinctranslate_locale_import_one_string('db-report'); |
|
| 1085 | + // Get status information on import process. |
|
| 1086 | + list($headerdone, $additions, $updates, $deletes, $skips) = _boinctranslate_locale_import_one_string('db-report'); |
|
| 1087 | 1087 | |
| 1088 | - if (!$headerdone) { |
|
| 1088 | + if (!$headerdone) { |
|
| 1089 | 1089 | drupal_set_message(t('The translation file %filename appears to have a missing or malformed header.', array('%filename' => $file->filename)), 'error'); |
| 1090 | - } |
|
| 1090 | + } |
|
| 1091 | 1091 | |
| 1092 | - // Clear cache and force refresh of JavaScript translations. |
|
| 1093 | - _locale_invalidate_js($langcode); |
|
| 1094 | - cache_clear_all('locale:', 'cache', TRUE); |
|
| 1092 | + // Clear cache and force refresh of JavaScript translations. |
|
| 1093 | + _locale_invalidate_js($langcode); |
|
| 1094 | + cache_clear_all('locale:', 'cache', TRUE); |
|
| 1095 | 1095 | |
| 1096 | - // Rebuild the menu, strings may have changed. |
|
| 1097 | - menu_rebuild(); |
|
| 1096 | + // Rebuild the menu, strings may have changed. |
|
| 1097 | + menu_rebuild(); |
|
| 1098 | 1098 | |
| 1099 | - return array( |
|
| 1099 | + return array( |
|
| 1100 | 1100 | 'new' => $additions, |
| 1101 | 1101 | 'updated' => $updates, |
| 1102 | 1102 | 'deleted' => $deletes, |
| 1103 | 1103 | 'skipped' => $skips, |
| 1104 | - ); |
|
| 1104 | + ); |
|
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | 1107 | /** |
@@ -1109,253 +1109,253 @@ discard block |
||
| 1109 | 1109 | */ |
| 1110 | 1110 | function _boinctranslate_locale_import_read_po($op, $file, $mode = NULL, $lang = NULL, $group = 'default') { |
| 1111 | 1111 | |
| 1112 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 1112 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 1113 | 1113 | |
| 1114 | - $fd = fopen($file->filepath, "rb"); // File will get closed by PHP on return |
|
| 1115 | - if (!$fd) { |
|
| 1114 | + $fd = fopen($file->filepath, "rb"); // File will get closed by PHP on return |
|
| 1115 | + if (!$fd) { |
|
| 1116 | 1116 | watchdog( |
| 1117 | - 'boinctranslate', |
|
| 1118 | - 'The translation import for %lang failed, because %filename could not be read.', |
|
| 1119 | - array('%lang' => $lang, '%filename' => $file->filename), |
|
| 1120 | - WATCHDOG_WARNING |
|
| 1117 | + 'boinctranslate', |
|
| 1118 | + 'The translation import for %lang failed, because %filename could not be read.', |
|
| 1119 | + array('%lang' => $lang, '%filename' => $file->filename), |
|
| 1120 | + WATCHDOG_WARNING |
|
| 1121 | 1121 | ); |
| 1122 | 1122 | _locale_import_message('The translation import failed, because the file %filename could not be read.', $file); |
| 1123 | 1123 | return FALSE; |
| 1124 | - } |
|
| 1124 | + } |
|
| 1125 | 1125 | |
| 1126 | - $context = "COMMENT"; // Parser context: COMMENT, MSGID, MSGID_PLURAL, MSGSTR and MSGSTR_ARR |
|
| 1127 | - $current = array(); // Current entry being read |
|
| 1128 | - $plural = 0; // Current plural form |
|
| 1129 | - $lineno = 0; // Current line |
|
| 1126 | + $context = "COMMENT"; // Parser context: COMMENT, MSGID, MSGID_PLURAL, MSGSTR and MSGSTR_ARR |
|
| 1127 | + $current = array(); // Current entry being read |
|
| 1128 | + $plural = 0; // Current plural form |
|
| 1129 | + $lineno = 0; // Current line |
|
| 1130 | 1130 | |
| 1131 | - while (!feof($fd)) { |
|
| 1131 | + while (!feof($fd)) { |
|
| 1132 | 1132 | $line = fgets($fd, 10 * 1024); // A line should not be this long |
| 1133 | 1133 | if ($lineno == 0) { |
| 1134 | - // The first line might come with a UTF-8 BOM, which should be removed. |
|
| 1135 | - $line = str_replace("\xEF\xBB\xBF", '', $line); |
|
| 1134 | + // The first line might come with a UTF-8 BOM, which should be removed. |
|
| 1135 | + $line = str_replace("\xEF\xBB\xBF", '', $line); |
|
| 1136 | 1136 | } |
| 1137 | 1137 | $lineno++; |
| 1138 | 1138 | $line = trim(strtr($line, array("\\\n" => ""))); |
| 1139 | 1139 | |
| 1140 | 1140 | if (!strncmp("#", $line, 1)) { // A comment |
| 1141 | - if ($context == "COMMENT") { // Already in comment context: add |
|
| 1141 | + if ($context == "COMMENT") { // Already in comment context: add |
|
| 1142 | 1142 | $current["#"][] = substr($line, 1); |
| 1143 | - } |
|
| 1144 | - elseif (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 1143 | + } |
|
| 1144 | + elseif (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 1145 | 1145 | _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group); |
| 1146 | 1146 | $current = array(); |
| 1147 | 1147 | $current["#"][] = substr($line, 1); |
| 1148 | 1148 | $context = "COMMENT"; |
| 1149 | - } |
|
| 1150 | - else { // Parse error |
|
| 1149 | + } |
|
| 1150 | + else { // Parse error |
|
| 1151 | 1151 | watchdog( |
| 1152 | - 'boinctranslate', |
|
| 1153 | - 'The translation file %filename for %lang contains an error: "msgstr" was expected but not found on line %line.', |
|
| 1154 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1155 | - WATCHDOG_WARNING |
|
| 1152 | + 'boinctranslate', |
|
| 1153 | + 'The translation file %filename for %lang contains an error: "msgstr" was expected but not found on line %line.', |
|
| 1154 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1155 | + WATCHDOG_WARNING |
|
| 1156 | 1156 | ); |
| 1157 | 1157 | _locale_import_message('The translation file %filename contains an error: "msgstr" was expected but not found on line %line.', $file, $lineno); |
| 1158 | 1158 | return FALSE; |
| 1159 | - } |
|
| 1159 | + } |
|
| 1160 | 1160 | } |
| 1161 | 1161 | elseif (!strncmp("msgctxt", $line, 7)) { |
| 1162 | - if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 1162 | + if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 1163 | 1163 | _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group); |
| 1164 | 1164 | $current = array(); |
| 1165 | - } |
|
| 1166 | - elseif (($context == "MSGID") || ($context == "MSGCTXT")) { // Already in this context? Parse error |
|
| 1165 | + } |
|
| 1166 | + elseif (($context == "MSGID") || ($context == "MSGCTXT")) { // Already in this context? Parse error |
|
| 1167 | 1167 | watchdog( |
| 1168 | - 'boinctranslate', |
|
| 1169 | - 'The translation file %filename for %lang contains an error: "msgctxt" is unexpected on line %line.', |
|
| 1170 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1171 | - WATCHDOG_WARNING |
|
| 1168 | + 'boinctranslate', |
|
| 1169 | + 'The translation file %filename for %lang contains an error: "msgctxt" is unexpected on line %line.', |
|
| 1170 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1171 | + WATCHDOG_WARNING |
|
| 1172 | 1172 | ); |
| 1173 | 1173 | _locale_import_message('The translation file %filename contains an error: "msgid" is unexpected on line %line.', $file, $lineno); |
| 1174 | 1174 | return FALSE; |
| 1175 | - } |
|
| 1176 | - $line = trim(substr($line, 7)); |
|
| 1177 | - $quoted = _locale_import_parse_quoted($line); |
|
| 1178 | - if ($quoted === FALSE) { |
|
| 1175 | + } |
|
| 1176 | + $line = trim(substr($line, 7)); |
|
| 1177 | + $quoted = _locale_import_parse_quoted($line); |
|
| 1178 | + if ($quoted === FALSE) { |
|
| 1179 | 1179 | watchdog( |
| 1180 | - 'boinctranslate', |
|
| 1181 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1182 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1183 | - WATCHDOG_WARNING |
|
| 1180 | + 'boinctranslate', |
|
| 1181 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1182 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1183 | + WATCHDOG_WARNING |
|
| 1184 | 1184 | ); |
| 1185 | 1185 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1186 | 1186 | return FALSE; |
| 1187 | - } |
|
| 1188 | - $current["msgctxt"] = $quoted; |
|
| 1189 | - $context = "MSGCTXT"; |
|
| 1187 | + } |
|
| 1188 | + $current["msgctxt"] = $quoted; |
|
| 1189 | + $context = "MSGCTXT"; |
|
| 1190 | 1190 | } |
| 1191 | 1191 | elseif (!strncmp("msgid_plural", $line, 12)) { |
| 1192 | - if ($context != "MSGID") { // Must be plural form for current entry |
|
| 1192 | + if ($context != "MSGID") { // Must be plural form for current entry |
|
| 1193 | 1193 | watchdog( |
| 1194 | - 'boinctranslate', |
|
| 1195 | - 'The translation file %filename for %lang contains an error: "msgid_plural" was expected but not found on line %line.', |
|
| 1196 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1197 | - WATCHDOG_WARNING |
|
| 1194 | + 'boinctranslate', |
|
| 1195 | + 'The translation file %filename for %lang contains an error: "msgid_plural" was expected but not found on line %line.', |
|
| 1196 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1197 | + WATCHDOG_WARNING |
|
| 1198 | 1198 | ); |
| 1199 | 1199 | _locale_import_message('The translation file %filename contains an error: "msgid_plural" was expected but not found on line %line.', $file, $lineno); |
| 1200 | 1200 | return FALSE; |
| 1201 | - } |
|
| 1202 | - $line = trim(substr($line, 12)); |
|
| 1203 | - $quoted = _locale_import_parse_quoted($line); |
|
| 1204 | - if ($quoted === FALSE) { |
|
| 1201 | + } |
|
| 1202 | + $line = trim(substr($line, 12)); |
|
| 1203 | + $quoted = _locale_import_parse_quoted($line); |
|
| 1204 | + if ($quoted === FALSE) { |
|
| 1205 | 1205 | watchdog( |
| 1206 | - 'boinctranslate', |
|
| 1207 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1208 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1209 | - WATCHDOG_WARNING |
|
| 1206 | + 'boinctranslate', |
|
| 1207 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1208 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1209 | + WATCHDOG_WARNING |
|
| 1210 | 1210 | ); |
| 1211 | 1211 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1212 | 1212 | return FALSE; |
| 1213 | - } |
|
| 1214 | - $current["msgid"] = $current["msgid"] . "\0" . $quoted; |
|
| 1215 | - $context = "MSGID_PLURAL"; |
|
| 1213 | + } |
|
| 1214 | + $current["msgid"] = $current["msgid"] . "\0" . $quoted; |
|
| 1215 | + $context = "MSGID_PLURAL"; |
|
| 1216 | 1216 | } |
| 1217 | 1217 | elseif (!strncmp("msgid", $line, 5)) { |
| 1218 | - if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 1218 | + if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 1219 | 1219 | _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group); |
| 1220 | 1220 | $current = array(); |
| 1221 | - } |
|
| 1222 | - elseif ($context == "MSGID") { // Already in this context? Parse error |
|
| 1221 | + } |
|
| 1222 | + elseif ($context == "MSGID") { // Already in this context? Parse error |
|
| 1223 | 1223 | watchdog( |
| 1224 | - 'boinctranslate', |
|
| 1225 | - 'The translation file %filename for %lang contains an error: "msgid" is unexpected on line %line.', |
|
| 1226 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1227 | - WATCHDOG_WARNING |
|
| 1224 | + 'boinctranslate', |
|
| 1225 | + 'The translation file %filename for %lang contains an error: "msgid" is unexpected on line %line.', |
|
| 1226 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1227 | + WATCHDOG_WARNING |
|
| 1228 | 1228 | ); |
| 1229 | 1229 | _locale_import_message('The translation file %filename contains an error: "msgid" is unexpected on line %line.', $file, $lineno); |
| 1230 | 1230 | return FALSE; |
| 1231 | - } |
|
| 1232 | - $line = trim(substr($line, 5)); |
|
| 1233 | - $quoted = _locale_import_parse_quoted($line); |
|
| 1234 | - if ($quoted === FALSE) { |
|
| 1231 | + } |
|
| 1232 | + $line = trim(substr($line, 5)); |
|
| 1233 | + $quoted = _locale_import_parse_quoted($line); |
|
| 1234 | + if ($quoted === FALSE) { |
|
| 1235 | 1235 | watchdog( |
| 1236 | - 'boinctranslate', |
|
| 1237 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1238 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1239 | - WATCHDOG_WARNING |
|
| 1236 | + 'boinctranslate', |
|
| 1237 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1238 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1239 | + WATCHDOG_WARNING |
|
| 1240 | 1240 | ); |
| 1241 | 1241 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1242 | 1242 | return FALSE; |
| 1243 | - } |
|
| 1244 | - $current["msgid"] = $quoted; |
|
| 1245 | - $context = "MSGID"; |
|
| 1243 | + } |
|
| 1244 | + $current["msgid"] = $quoted; |
|
| 1245 | + $context = "MSGID"; |
|
| 1246 | 1246 | } |
| 1247 | 1247 | elseif (!strncmp("msgstr[", $line, 7)) { |
| 1248 | - if (($context != "MSGID") && ($context != "MSGID_PLURAL") && ($context != "MSGSTR_ARR")) { // Must come after msgid, msgid_plural, or msgstr[] |
|
| 1248 | + if (($context != "MSGID") && ($context != "MSGID_PLURAL") && ($context != "MSGSTR_ARR")) { // Must come after msgid, msgid_plural, or msgstr[] |
|
| 1249 | 1249 | watchdog( |
| 1250 | - 'boinctranslate', |
|
| 1251 | - 'The translation file %filename for %lang contains an error: "msgstr[]" is unexpected on line %line.', |
|
| 1252 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1253 | - WATCHDOG_WARNING |
|
| 1250 | + 'boinctranslate', |
|
| 1251 | + 'The translation file %filename for %lang contains an error: "msgstr[]" is unexpected on line %line.', |
|
| 1252 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1253 | + WATCHDOG_WARNING |
|
| 1254 | 1254 | ); |
| 1255 | 1255 | _locale_import_message('The translation file %filename contains an error: "msgstr[]" is unexpected on line %line.', $file, $lineno); |
| 1256 | 1256 | return FALSE; |
| 1257 | - } |
|
| 1258 | - if (strpos($line, "]") === FALSE) { |
|
| 1257 | + } |
|
| 1258 | + if (strpos($line, "]") === FALSE) { |
|
| 1259 | 1259 | watchdog( |
| 1260 | - 'boinctranslate', |
|
| 1261 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1262 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1263 | - WATCHDOG_WARNING |
|
| 1260 | + 'boinctranslate', |
|
| 1261 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1262 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1263 | + WATCHDOG_WARNING |
|
| 1264 | 1264 | ); |
| 1265 | 1265 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1266 | 1266 | return FALSE; |
| 1267 | - } |
|
| 1268 | - $frombracket = strstr($line, "["); |
|
| 1269 | - $plural = substr($frombracket, 1, strpos($frombracket, "]") - 1); |
|
| 1270 | - $line = trim(strstr($line, " ")); |
|
| 1271 | - $quoted = _locale_import_parse_quoted($line); |
|
| 1272 | - if ($quoted === FALSE) { |
|
| 1267 | + } |
|
| 1268 | + $frombracket = strstr($line, "["); |
|
| 1269 | + $plural = substr($frombracket, 1, strpos($frombracket, "]") - 1); |
|
| 1270 | + $line = trim(strstr($line, " ")); |
|
| 1271 | + $quoted = _locale_import_parse_quoted($line); |
|
| 1272 | + if ($quoted === FALSE) { |
|
| 1273 | 1273 | watchdog( |
| 1274 | - 'boinctranslate', |
|
| 1275 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1276 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1277 | - WATCHDOG_WARNING |
|
| 1274 | + 'boinctranslate', |
|
| 1275 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1276 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1277 | + WATCHDOG_WARNING |
|
| 1278 | 1278 | ); |
| 1279 | 1279 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1280 | 1280 | return FALSE; |
| 1281 | - } |
|
| 1282 | - $current["msgstr"][$plural] = $quoted; |
|
| 1283 | - $context = "MSGSTR_ARR"; |
|
| 1281 | + } |
|
| 1282 | + $current["msgstr"][$plural] = $quoted; |
|
| 1283 | + $context = "MSGSTR_ARR"; |
|
| 1284 | 1284 | } |
| 1285 | 1285 | elseif (!strncmp("msgstr", $line, 6)) { |
| 1286 | - if ($context != "MSGID") { // Should come just after a msgid block |
|
| 1286 | + if ($context != "MSGID") { // Should come just after a msgid block |
|
| 1287 | 1287 | watchdog( |
| 1288 | - 'boinctranslate', |
|
| 1289 | - 'The translation file %filename for %lang contains an error: "msgstr" is unexpected on line %line.', |
|
| 1290 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1291 | - WATCHDOG_WARNING |
|
| 1288 | + 'boinctranslate', |
|
| 1289 | + 'The translation file %filename for %lang contains an error: "msgstr" is unexpected on line %line.', |
|
| 1290 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1291 | + WATCHDOG_WARNING |
|
| 1292 | 1292 | ); |
| 1293 | 1293 | _locale_import_message('The translation file %filename contains an error: "msgstr" is unexpected on line %line.', $file, $lineno); |
| 1294 | 1294 | return FALSE; |
| 1295 | - } |
|
| 1296 | - $line = trim(substr($line, 6)); |
|
| 1297 | - $quoted = _locale_import_parse_quoted($line); |
|
| 1298 | - if ($quoted === FALSE) { |
|
| 1295 | + } |
|
| 1296 | + $line = trim(substr($line, 6)); |
|
| 1297 | + $quoted = _locale_import_parse_quoted($line); |
|
| 1298 | + if ($quoted === FALSE) { |
|
| 1299 | 1299 | watchdog( |
| 1300 | - 'boinctranslate', |
|
| 1301 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1302 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1303 | - WATCHDOG_WARNING |
|
| 1300 | + 'boinctranslate', |
|
| 1301 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1302 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1303 | + WATCHDOG_WARNING |
|
| 1304 | 1304 | ); |
| 1305 | 1305 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1306 | 1306 | return FALSE; |
| 1307 | - } |
|
| 1308 | - $current["msgstr"] = $quoted; |
|
| 1309 | - $context = "MSGSTR"; |
|
| 1307 | + } |
|
| 1308 | + $current["msgstr"] = $quoted; |
|
| 1309 | + $context = "MSGSTR"; |
|
| 1310 | 1310 | } |
| 1311 | 1311 | elseif ($line != "") { |
| 1312 | - $quoted = _locale_import_parse_quoted($line); |
|
| 1313 | - if ($quoted === FALSE) { |
|
| 1312 | + $quoted = _locale_import_parse_quoted($line); |
|
| 1313 | + if ($quoted === FALSE) { |
|
| 1314 | 1314 | watchdog( |
| 1315 | - 'boinctranslate', |
|
| 1316 | - 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1317 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1318 | - WATCHDOG_WARNING |
|
| 1315 | + 'boinctranslate', |
|
| 1316 | + 'The translation file %filename for language %lang contains a syntax error on line %line.', |
|
| 1317 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1318 | + WATCHDOG_WARNING |
|
| 1319 | 1319 | ); |
| 1320 | 1320 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1321 | 1321 | return FALSE; |
| 1322 | - } |
|
| 1323 | - if (($context == "MSGID") || ($context == "MSGID_PLURAL")) { |
|
| 1322 | + } |
|
| 1323 | + if (($context == "MSGID") || ($context == "MSGID_PLURAL")) { |
|
| 1324 | 1324 | $current["msgid"] .= $quoted; |
| 1325 | - } |
|
| 1326 | - elseif ($context == "MSGSTR") { |
|
| 1325 | + } |
|
| 1326 | + elseif ($context == "MSGSTR") { |
|
| 1327 | 1327 | $current["msgstr"] .= $quoted; |
| 1328 | - } |
|
| 1329 | - elseif ($context == "MSGSTR_ARR") { |
|
| 1328 | + } |
|
| 1329 | + elseif ($context == "MSGSTR_ARR") { |
|
| 1330 | 1330 | $current["msgstr"][$plural] .= $quoted; |
| 1331 | - } |
|
| 1332 | - else { |
|
| 1331 | + } |
|
| 1332 | + else { |
|
| 1333 | 1333 | watchdog( |
| 1334 | - 'boinctranslate', |
|
| 1335 | - 'The translation file %filename for %lang contains an error: there is an unexpected string on line %line.', |
|
| 1336 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1337 | - WATCHDOG_WARNING |
|
| 1334 | + 'boinctranslate', |
|
| 1335 | + 'The translation file %filename for %lang contains an error: there is an unexpected string on line %line.', |
|
| 1336 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1337 | + WATCHDOG_WARNING |
|
| 1338 | 1338 | ); |
| 1339 | 1339 | _locale_import_message('The translation file %filename contains an error: there is an unexpected string on line %line.', $file, $lineno); |
| 1340 | 1340 | return FALSE; |
| 1341 | - } |
|
| 1341 | + } |
|
| 1342 | + } |
|
| 1342 | 1343 | } |
| 1343 | - } |
|
| 1344 | 1344 | |
| 1345 | - // End of PO file, flush last entry |
|
| 1346 | - if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { |
|
| 1345 | + // End of PO file, flush last entry |
|
| 1346 | + if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { |
|
| 1347 | 1347 | _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group); |
| 1348 | - } |
|
| 1349 | - elseif ($context != "COMMENT") { |
|
| 1348 | + } |
|
| 1349 | + elseif ($context != "COMMENT") { |
|
| 1350 | 1350 | watchdog( |
| 1351 | - 'boinctranslate', |
|
| 1352 | - 'The translation file %filename for %lang ended unexpectedly at line %line.', |
|
| 1353 | - array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1354 | - WATCHDOG_WARNING |
|
| 1351 | + 'boinctranslate', |
|
| 1352 | + 'The translation file %filename for %lang ended unexpectedly at line %line.', |
|
| 1353 | + array('%filename' => $file->filename, '%lang' => $lang, '%line' => $lineno), |
|
| 1354 | + WATCHDOG_WARNING |
|
| 1355 | 1355 | ); |
| 1356 | 1356 | _locale_import_message('The translation file %filename ended unexpectedly at line %line.', $file, $lineno); |
| 1357 | 1357 | return FALSE; |
| 1358 | - } |
|
| 1358 | + } |
|
| 1359 | 1359 | |
| 1360 | 1360 | } |
| 1361 | 1361 | |
@@ -1364,28 +1364,28 @@ discard block |
||
| 1364 | 1364 | */ |
| 1365 | 1365 | function _boinctranslate_locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NULL, $file = NULL, $group = 'default') { |
| 1366 | 1366 | |
| 1367 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 1367 | + require_once(getcwd() . '/includes/locale.inc'); |
|
| 1368 | 1368 | |
| 1369 | - static $report = array( |
|
| 1369 | + static $report = array( |
|
| 1370 | 1370 | 'additions' => 0, |
| 1371 | 1371 | 'updates' => 0, |
| 1372 | 1372 | 'deletes' => 0, |
| 1373 | 1373 | 'skips' => 0, |
| 1374 | - ); |
|
| 1375 | - static $headerdone = FALSE; |
|
| 1376 | - static $strings = array(); |
|
| 1374 | + ); |
|
| 1375 | + static $headerdone = FALSE; |
|
| 1376 | + static $strings = array(); |
|
| 1377 | 1377 | |
| 1378 | - switch ($op) { |
|
| 1378 | + switch ($op) { |
|
| 1379 | 1379 | // Return stored strings |
| 1380 | 1380 | case 'mem-report': |
| 1381 | 1381 | return $strings; |
| 1382 | 1382 | |
| 1383 | - // Store string in memory (only supports single strings) |
|
| 1383 | + // Store string in memory (only supports single strings) |
|
| 1384 | 1384 | case 'mem-store': |
| 1385 | 1385 | $strings[$value['msgid']] = $value['msgstr']; |
| 1386 | - return; |
|
| 1386 | + return; |
|
| 1387 | 1387 | |
| 1388 | - // Called at end of import to inform the user |
|
| 1388 | + // Called at end of import to inform the user |
|
| 1389 | 1389 | case 'db-report': |
| 1390 | 1390 | return array( |
| 1391 | 1391 | $headerdone, |
@@ -1393,115 +1393,115 @@ discard block |
||
| 1393 | 1393 | $report['updates'], |
| 1394 | 1394 | $report['deletes'], |
| 1395 | 1395 | $report['skips'], |
| 1396 | - ); |
|
| 1396 | + ); |
|
| 1397 | 1397 | |
| 1398 | - // Store the string we got in the database. |
|
| 1398 | + // Store the string we got in the database. |
|
| 1399 | 1399 | case 'db-store': |
| 1400 | 1400 | // We got header information. |
| 1401 | 1401 | if ($value['msgid'] == '') { |
| 1402 | 1402 | $languages = language_list(); |
| 1403 | 1403 | if (($mode != LOCALE_IMPORT_KEEP) || empty($languages[$lang]->plurals)) { |
| 1404 | - // Since we only need to parse the header if we ought to update the |
|
| 1405 | - // plural formula, only run this if we don't need to keep existing |
|
| 1406 | - // data untouched or if we don't have an existing plural formula. |
|
| 1407 | - $header = _locale_import_parse_header($value['msgstr']); |
|
| 1404 | + // Since we only need to parse the header if we ought to update the |
|
| 1405 | + // plural formula, only run this if we don't need to keep existing |
|
| 1406 | + // data untouched or if we don't have an existing plural formula. |
|
| 1407 | + $header = _locale_import_parse_header($value['msgstr']); |
|
| 1408 | 1408 | |
| 1409 | - // Get and store the plural formula if available. |
|
| 1410 | - if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->filename)) { |
|
| 1409 | + // Get and store the plural formula if available. |
|
| 1410 | + if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->filename)) { |
|
| 1411 | 1411 | list($nplurals, $plural) = $p; |
| 1412 | 1412 | db_query("UPDATE {languages} SET plurals = %d, formula = '%s' WHERE language = '%s'", $nplurals, $plural, $lang); |
| 1413 | - } |
|
| 1413 | + } |
|
| 1414 | 1414 | } |
| 1415 | 1415 | $headerdone = TRUE; |
| 1416 | - } |
|
| 1416 | + } |
|
| 1417 | 1417 | |
| 1418 | - else { |
|
| 1418 | + else { |
|
| 1419 | 1419 | // Some real string to import. |
| 1420 | 1420 | $comments = _locale_import_shorten_comments(empty($value['#']) ? array() : $value['#']); |
| 1421 | 1421 | |
| 1422 | 1422 | if (strpos($value['msgid'], "\0")) { |
| 1423 | - // This string has plural versions. |
|
| 1424 | - $english = explode("\0", $value['msgid'], 2); |
|
| 1425 | - $entries = array_keys($value['msgstr']); |
|
| 1426 | - for ($i = 3; $i <= count($entries); $i++) { |
|
| 1423 | + // This string has plural versions. |
|
| 1424 | + $english = explode("\0", $value['msgid'], 2); |
|
| 1425 | + $entries = array_keys($value['msgstr']); |
|
| 1426 | + for ($i = 3; $i <= count($entries); $i++) { |
|
| 1427 | 1427 | $english[] = $english[1]; |
| 1428 | - } |
|
| 1429 | - $translation = array_map('_locale_import_append_plural', $value['msgstr'], $entries); |
|
| 1430 | - $english = array_map('_locale_import_append_plural', $english, $entries); |
|
| 1431 | - foreach ($translation as $key => $trans) { |
|
| 1428 | + } |
|
| 1429 | + $translation = array_map('_locale_import_append_plural', $value['msgstr'], $entries); |
|
| 1430 | + $english = array_map('_locale_import_append_plural', $english, $entries); |
|
| 1431 | + foreach ($translation as $key => $trans) { |
|
| 1432 | 1432 | if ($key == 0) { |
| 1433 | - $plid = 0; |
|
| 1433 | + $plid = 0; |
|
| 1434 | 1434 | } |
| 1435 | 1435 | $plid = _boinctranslate_locale_import_one_string_db($report, $lang, $english[$key], $trans, $group, $comments, $mode, $plid, $key); |
| 1436 | - } |
|
| 1436 | + } |
|
| 1437 | 1437 | } |
| 1438 | 1438 | |
| 1439 | 1439 | else { |
| 1440 | - // A simple string to import. |
|
| 1441 | - $english = $value['msgid']; |
|
| 1442 | - $translation = $value['msgstr']; |
|
| 1443 | - _boinctranslate_locale_import_one_string_db($report, $lang, $english, $translation, $group, $comments, $mode); |
|
| 1440 | + // A simple string to import. |
|
| 1441 | + $english = $value['msgid']; |
|
| 1442 | + $translation = $value['msgstr']; |
|
| 1443 | + _boinctranslate_locale_import_one_string_db($report, $lang, $english, $translation, $group, $comments, $mode); |
|
| 1444 | 1444 | } |
| 1445 | - } |
|
| 1446 | - } // end of db-store operation |
|
| 1445 | + } |
|
| 1446 | + } // end of db-store operation |
|
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | 1449 | /** |
| 1450 | 1450 | * Modify the _locale_import_one_string_db() function so that it does not add |
| 1451 | 1451 | * translation strings that do not exist on the site |
| 1452 | 1452 | */ |
| 1453 | - function _boinctranslate_locale_import_one_string_db(&$report, $langcode, $source, $translation, $textgroup, $location, $mode, $plid = NULL, $plural = NULL) { |
|
| 1454 | - $lid = db_result(db_query("SELECT lid FROM {locales_source} WHERE location = '%s' AND source = '%s' AND textgroup = '%s'", $location, $source, $textgroup)); |
|
| 1453 | + function _boinctranslate_locale_import_one_string_db(&$report, $langcode, $source, $translation, $textgroup, $location, $mode, $plid = NULL, $plural = NULL) { |
|
| 1454 | + $lid = db_result(db_query("SELECT lid FROM {locales_source} WHERE location = '%s' AND source = '%s' AND textgroup = '%s'", $location, $source, $textgroup)); |
|
| 1455 | 1455 | |
| 1456 | - if (!empty($translation)) { |
|
| 1456 | + if (!empty($translation)) { |
|
| 1457 | 1457 | // Skip this string unless it passes a check for dangerous code. |
| 1458 | 1458 | // Text groups other than default still can contain HTML tags |
| 1459 | 1459 | // (i.e. translatable blocks). |
| 1460 | 1460 | if ($textgroup == "default" && !locale_string_is_safe($translation)) { |
| 1461 | - $report['skips']++; |
|
| 1462 | - $lid = 0; |
|
| 1461 | + $report['skips']++; |
|
| 1462 | + $lid = 0; |
|
| 1463 | 1463 | } |
| 1464 | 1464 | elseif ($lid) { |
| 1465 | - // We have this source string saved already. |
|
| 1466 | - // Don't update location, that just makes Drupal add the same strings |
|
| 1467 | - // over and over |
|
| 1468 | - //db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $location, $lid); |
|
| 1469 | - $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode)); |
|
| 1470 | - if (!$exists) { |
|
| 1465 | + // We have this source string saved already. |
|
| 1466 | + // Don't update location, that just makes Drupal add the same strings |
|
| 1467 | + // over and over |
|
| 1468 | + //db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $location, $lid); |
|
| 1469 | + $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode)); |
|
| 1470 | + if (!$exists) { |
|
| 1471 | 1471 | // No translation in this language. |
| 1472 | 1472 | db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural); |
| 1473 | 1473 | $report['additions']++; |
| 1474 | - } |
|
| 1475 | - else if ($mode == LOCALE_IMPORT_OVERWRITE) { |
|
| 1474 | + } |
|
| 1475 | + else if ($mode == LOCALE_IMPORT_OVERWRITE) { |
|
| 1476 | 1476 | // Translation exists, only overwrite if instructed. |
| 1477 | 1477 | db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE language = '%s' AND lid = %d", $translation, $plid, $plural, $langcode, $lid); |
| 1478 | 1478 | $report['updates']++; |
| 1479 | - } |
|
| 1479 | + } |
|
| 1480 | 1480 | } |
| 1481 | 1481 | else { |
| 1482 | - // No such source string in the database yet. |
|
| 1483 | - // Do not insert the source string if it does not belong on the site! |
|
| 1484 | - /* |
|
| 1482 | + // No such source string in the database yet. |
|
| 1483 | + // Do not insert the source string if it does not belong on the site! |
|
| 1484 | + /* |
|
| 1485 | 1485 | db_query("INSERT INTO {locales_source} (location, source, textgroup) VALUES ('%s', '%s', '%s')", $location, $source, $textgroup); |
| 1486 | 1486 | $lid = db_result(db_query("SELECT lid FROM {locales_source} WHERE source = '%s' AND textgroup = '%s'", $source, $textgroup)); |
| 1487 | 1487 | db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural); |
| 1488 | 1488 | $report['additions']++; |
| 1489 | 1489 | */ |
| 1490 | 1490 | } |
| 1491 | - } |
|
| 1492 | - elseif ($mode == LOCALE_IMPORT_OVERWRITE AND $lid) { |
|
| 1491 | + } |
|
| 1492 | + elseif ($mode == LOCALE_IMPORT_OVERWRITE AND $lid) { |
|
| 1493 | 1493 | $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode)); |
| 1494 | 1494 | if ($exists) { |
| 1495 | - // Empty translation, remove existing if instructed. |
|
| 1496 | - db_query("DELETE FROM {locales_target} WHERE language = '%s' AND lid = %d AND plid = %d AND plural = %d", $langcode, $lid, $plid, $plural); |
|
| 1497 | - $report['deletes']++; |
|
| 1495 | + // Empty translation, remove existing if instructed. |
|
| 1496 | + db_query("DELETE FROM {locales_target} WHERE language = '%s' AND lid = %d AND plid = %d AND plural = %d", $langcode, $lid, $plid, $plural); |
|
| 1497 | + $report['deletes']++; |
|
| 1498 | 1498 | } |
| 1499 | - } |
|
| 1500 | - else { |
|
| 1499 | + } |
|
| 1500 | + else { |
|
| 1501 | 1501 | $report['skips']++; |
| 1502 | - } |
|
| 1502 | + } |
|
| 1503 | 1503 | |
| 1504 | - return $lid; |
|
| 1504 | + return $lid; |
|
| 1505 | 1505 | } |
| 1506 | 1506 | |
| 1507 | 1507 | |
@@ -1510,15 +1510,15 @@ discard block |
||
| 1510 | 1510 | * Parse valid resources out of configuration |
| 1511 | 1511 | */ |
| 1512 | 1512 | function boinctranslate_parse_resources($resource_text) { |
| 1513 | - $resources = array(); |
|
| 1514 | - $resource_array = explode( |
|
| 1513 | + $resources = array(); |
|
| 1514 | + $resource_array = explode( |
|
| 1515 | 1515 | "\n", $resource_text |
| 1516 | - ); |
|
| 1517 | - foreach ($resource_array as $resource) { |
|
| 1516 | + ); |
|
| 1517 | + foreach ($resource_array as $resource) { |
|
| 1518 | 1518 | $resource = trim($resource); |
| 1519 | 1519 | if ($resource AND $resource[0] != '#') { |
| 1520 | - $resources[] = $resource; |
|
| 1520 | + $resources[] = $resource; |
|
| 1521 | 1521 | } |
| 1522 | - } |
|
| 1523 | - return $resources; |
|
| 1522 | + } |
|
| 1523 | + return $resources; |
|
| 1524 | 1524 | } |
@@ -1377,72 +1377,72 @@ |
||
| 1377 | 1377 | |
| 1378 | 1378 | switch ($op) { |
| 1379 | 1379 | // Return stored strings |
| 1380 | - case 'mem-report': |
|
| 1381 | - return $strings; |
|
| 1380 | + case 'mem-report': |
|
| 1381 | + return $strings; |
|
| 1382 | 1382 | |
| 1383 | - // Store string in memory (only supports single strings) |
|
| 1384 | - case 'mem-store': |
|
| 1385 | - $strings[$value['msgid']] = $value['msgstr']; |
|
| 1386 | - return; |
|
| 1383 | + // Store string in memory (only supports single strings) |
|
| 1384 | + case 'mem-store': |
|
| 1385 | + $strings[$value['msgid']] = $value['msgstr']; |
|
| 1386 | + return; |
|
| 1387 | 1387 | |
| 1388 | - // Called at end of import to inform the user |
|
| 1389 | - case 'db-report': |
|
| 1390 | - return array( |
|
| 1391 | - $headerdone, |
|
| 1392 | - $report['additions'], |
|
| 1393 | - $report['updates'], |
|
| 1394 | - $report['deletes'], |
|
| 1395 | - $report['skips'], |
|
| 1396 | - ); |
|
| 1388 | + // Called at end of import to inform the user |
|
| 1389 | + case 'db-report': |
|
| 1390 | + return array( |
|
| 1391 | + $headerdone, |
|
| 1392 | + $report['additions'], |
|
| 1393 | + $report['updates'], |
|
| 1394 | + $report['deletes'], |
|
| 1395 | + $report['skips'], |
|
| 1396 | + ); |
|
| 1397 | 1397 | |
| 1398 | - // Store the string we got in the database. |
|
| 1399 | - case 'db-store': |
|
| 1400 | - // We got header information. |
|
| 1401 | - if ($value['msgid'] == '') { |
|
| 1402 | - $languages = language_list(); |
|
| 1403 | - if (($mode != LOCALE_IMPORT_KEEP) || empty($languages[$lang]->plurals)) { |
|
| 1404 | - // Since we only need to parse the header if we ought to update the |
|
| 1405 | - // plural formula, only run this if we don't need to keep existing |
|
| 1406 | - // data untouched or if we don't have an existing plural formula. |
|
| 1407 | - $header = _locale_import_parse_header($value['msgstr']); |
|
| 1398 | + // Store the string we got in the database. |
|
| 1399 | + case 'db-store': |
|
| 1400 | + // We got header information. |
|
| 1401 | + if ($value['msgid'] == '') { |
|
| 1402 | + $languages = language_list(); |
|
| 1403 | + if (($mode != LOCALE_IMPORT_KEEP) || empty($languages[$lang]->plurals)) { |
|
| 1404 | + // Since we only need to parse the header if we ought to update the |
|
| 1405 | + // plural formula, only run this if we don't need to keep existing |
|
| 1406 | + // data untouched or if we don't have an existing plural formula. |
|
| 1407 | + $header = _locale_import_parse_header($value['msgstr']); |
|
| 1408 | 1408 | |
| 1409 | - // Get and store the plural formula if available. |
|
| 1410 | - if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->filename)) { |
|
| 1411 | - list($nplurals, $plural) = $p; |
|
| 1412 | - db_query("UPDATE {languages} SET plurals = %d, formula = '%s' WHERE language = '%s'", $nplurals, $plural, $lang); |
|
| 1413 | - } |
|
| 1409 | + // Get and store the plural formula if available. |
|
| 1410 | + if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->filename)) { |
|
| 1411 | + list($nplurals, $plural) = $p; |
|
| 1412 | + db_query("UPDATE {languages} SET plurals = %d, formula = '%s' WHERE language = '%s'", $nplurals, $plural, $lang); |
|
| 1414 | 1413 | } |
| 1415 | - $headerdone = TRUE; |
|
| 1416 | 1414 | } |
| 1415 | + $headerdone = TRUE; |
|
| 1416 | + } |
|
| 1417 | 1417 | |
| 1418 | - else { |
|
| 1419 | - // Some real string to import. |
|
| 1420 | - $comments = _locale_import_shorten_comments(empty($value['#']) ? array() : $value['#']); |
|
| 1418 | + else { |
|
| 1419 | + // Some real string to import. |
|
| 1420 | + $comments = _locale_import_shorten_comments(empty($value['#']) ? array() : $value['#']); |
|
| 1421 | 1421 | |
| 1422 | - if (strpos($value['msgid'], "\0")) { |
|
| 1423 | - // This string has plural versions. |
|
| 1424 | - $english = explode("\0", $value['msgid'], 2); |
|
| 1425 | - $entries = array_keys($value['msgstr']); |
|
| 1426 | - for ($i = 3; $i <= count($entries); $i++) { |
|
| 1427 | - $english[] = $english[1]; |
|
| 1428 | - } |
|
| 1429 | - $translation = array_map('_locale_import_append_plural', $value['msgstr'], $entries); |
|
| 1430 | - $english = array_map('_locale_import_append_plural', $english, $entries); |
|
| 1431 | - foreach ($translation as $key => $trans) { |
|
| 1432 | - if ($key == 0) { |
|
| 1433 | - $plid = 0; |
|
| 1434 | - } |
|
| 1435 | - $plid = _boinctranslate_locale_import_one_string_db($report, $lang, $english[$key], $trans, $group, $comments, $mode, $plid, $key); |
|
| 1422 | + if (strpos($value['msgid'], "\0")) { |
|
| 1423 | + // This string has plural versions. |
|
| 1424 | + $english = explode("\0", $value['msgid'], 2); |
|
| 1425 | + $entries = array_keys($value['msgstr']); |
|
| 1426 | + for ($i = 3; $i <= count($entries); $i++) { |
|
| 1427 | + $english[] = $english[1]; |
|
| 1428 | + } |
|
| 1429 | + $translation = array_map('_locale_import_append_plural', $value['msgstr'], $entries); |
|
| 1430 | + $english = array_map('_locale_import_append_plural', $english, $entries); |
|
| 1431 | + foreach ($translation as $key => $trans) { |
|
| 1432 | + if ($key == 0) { |
|
| 1433 | + $plid = 0; |
|
| 1436 | 1434 | } |
| 1435 | + $plid = _boinctranslate_locale_import_one_string_db($report, $lang, $english[$key], $trans, $group, $comments, $mode, $plid, $key); |
|
| 1437 | 1436 | } |
| 1437 | + } |
|
| 1438 | 1438 | |
| 1439 | - else { |
|
| 1440 | - // A simple string to import. |
|
| 1441 | - $english = $value['msgid']; |
|
| 1442 | - $translation = $value['msgstr']; |
|
| 1443 | - _boinctranslate_locale_import_one_string_db($report, $lang, $english, $translation, $group, $comments, $mode); |
|
| 1444 | - } |
|
| 1439 | + else { |
|
| 1440 | + // A simple string to import. |
|
| 1441 | + $english = $value['msgid']; |
|
| 1442 | + $translation = $value['msgstr']; |
|
| 1443 | + _boinctranslate_locale_import_one_string_db($report, $lang, $english, $translation, $group, $comments, $mode); |
|
| 1445 | 1444 | } |
| 1445 | + } |
|
| 1446 | 1446 | } // end of db-store operation |
| 1447 | 1447 | } |
| 1448 | 1448 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | // In Drupal 7, these operation cases will all exist as their own hooks, |
| 80 | 80 | // so let's approximate that here so that this function can simply be removed |
| 81 | 81 | // upon migration to 7 |
| 82 | - switch($op) { |
|
| 82 | + switch ($op) { |
|
| 83 | 83 | case 'update': |
| 84 | 84 | boinctranslate_node_update($node); |
| 85 | 85 | break; |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * is updated (forward compatible to Drupal 7) |
| 97 | 97 | */ |
| 98 | 98 | function boinctranslate_node_update($node) { |
| 99 | - switch($node->type) { |
|
| 99 | + switch ($node->type) { |
|
| 100 | 100 | case 'page': |
| 101 | 101 | // Add page content to translation table |
| 102 | 102 | $textgroup = 'project'; |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * is viewed (forward compatible to Drupal 7) |
| 171 | 171 | */ |
| 172 | 172 | function boinctranslate_node_view($node, $view_mode, $langcode) { |
| 173 | - switch($node->type) { |
|
| 173 | + switch ($node->type) { |
|
| 174 | 174 | case 'page': |
| 175 | 175 | // Replace the node body with translated content, if available |
| 176 | 176 | $node->content['body']['#value'] = bts( |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | function boinctranslate_initialize_languages() { |
| 211 | 211 | |
| 212 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 212 | + require_once(getcwd().'/includes/locale.inc'); |
|
| 213 | 213 | |
| 214 | 214 | $api_base_url = 'https://www.transifex.com/api/2'; |
| 215 | 215 | $project_name = variable_get( |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | if ($disabled_languages) { |
| 343 | - drupal_set_message('The following languages were not found in Transifex and were disabled: ' . implode(' ', $disabled_languages)); |
|
| 343 | + drupal_set_message('The following languages were not found in Transifex and were disabled: '.implode(' ', $disabled_languages)); |
|
| 344 | 344 | } |
| 345 | 345 | if ($process_batches) { |
| 346 | 346 | $batch = array( |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | * |
| 390 | 390 | */ |
| 391 | 391 | function boinctranslate_export_translations() { |
| 392 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 392 | + require_once(getcwd().'/includes/locale.inc'); |
|
| 393 | 393 | $project_name = variable_get( |
| 394 | 394 | 'boinc_translate_transifex_project_name', '' |
| 395 | 395 | ); |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | * |
| 492 | 492 | */ |
| 493 | 493 | function boinctranslate_update_official_boinc_translations() { |
| 494 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 494 | + require_once(getcwd().'/includes/locale.inc'); |
|
| 495 | 495 | $project_name = variable_get( |
| 496 | 496 | 'boinc_translate_transifex_standard_name', '' |
| 497 | 497 | ); |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | |
| 600 | 600 | $url = "{$api_base_url}/{$path}"; |
| 601 | 601 | $headers = array( |
| 602 | - 'Authorization' => 'Basic ' . base64_encode($username . ":" . $password), |
|
| 602 | + 'Authorization' => 'Basic '.base64_encode($username.":".$password), |
|
| 603 | 603 | ); |
| 604 | 604 | $data = NULL; |
| 605 | 605 | |
@@ -627,7 +627,7 @@ discard block |
||
| 627 | 627 | return json_decode($response->data, TRUE); |
| 628 | 628 | } |
| 629 | 629 | else { |
| 630 | - return (string) $response->data; |
|
| 630 | + return (string)$response->data; |
|
| 631 | 631 | } |
| 632 | 632 | break; |
| 633 | 633 | case 404: |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | */ |
| 651 | 651 | function boinctranslate_get_po($langcode, $type = 'standard') { |
| 652 | 652 | |
| 653 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 653 | + require_once(getcwd().'/includes/locale.inc'); |
|
| 654 | 654 | |
| 655 | 655 | $all_languages = language_list(); |
| 656 | 656 | $language = $langcode ? $all_languages[$langcode] : NULL; |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | */ |
| 710 | 710 | function boinctranslate_export_po_generate($language = NULL, $strings = array(), $header = NULL, $type = NULL) { |
| 711 | 711 | |
| 712 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 712 | + require_once(getcwd().'/includes/locale.inc'); |
|
| 713 | 713 | global $user; |
| 714 | 714 | |
| 715 | 715 | // unset $language to indicate template creation |
@@ -725,7 +725,7 @@ discard block |
||
| 725 | 725 | $header = "# BOINC drupal localization template\n"; |
| 726 | 726 | $header .= "# Copyright (C) ".date("Y")." University of California\n"; |
| 727 | 727 | } |
| 728 | - $header .= '# Generated by ' . $user->name . ' <' . $user->mail . ">\n"; |
|
| 728 | + $header .= '# Generated by '.$user->name.' <'.$user->mail.">\n"; |
|
| 729 | 729 | $header .= "#\n"; |
| 730 | 730 | $header .= "# This file is distributed under the same license as BOINC.\n"; |
| 731 | 731 | $header .= "#\n"; |
@@ -737,9 +737,9 @@ discard block |
||
| 737 | 737 | $header .= "\"Project-Id-Version: BOINC unknown\\n\"\n"; // TODO: add SHA1 of source checkout here |
| 738 | 738 | } |
| 739 | 739 | $header .= "\"Report-Msgid-Bugs-To: BOINC translation team <[email protected]>\\n\"\n"; |
| 740 | - $header .= "\"POT-Creation-Date: " . date("Y-m-d H:iO") . "\\n\"\n"; |
|
| 740 | + $header .= "\"POT-Creation-Date: ".date("Y-m-d H:iO")."\\n\"\n"; |
|
| 741 | 741 | if (isset($language)) { |
| 742 | - $header .= "\"PO-Revision-Date: " . date("Y-m-d H:iO") . "\\n\"\n"; |
|
| 742 | + $header .= "\"PO-Revision-Date: ".date("Y-m-d H:iO")."\\n\"\n"; |
|
| 743 | 743 | } |
| 744 | 744 | $header .= "\"Last-Translator: Generated automatically from Drupal translate interface\\n\"\n"; |
| 745 | 745 | $header .= "\"MIME-Version: 1.0\\n\"\n"; |
@@ -748,31 +748,31 @@ discard block |
||
| 748 | 748 | if (isset($language)) { |
| 749 | 749 | $header .= "\"Language: ".$language->language."\\n\""; |
| 750 | 750 | if ($language->formula && $language->plurals) { |
| 751 | - $header .= "\"Plural-Forms: nplurals=" . $language->plurals . "; plural=" . strtr($language->formula, array('$' => '')) . ";\\n\"\n"; |
|
| 751 | + $header .= "\"Plural-Forms: nplurals=".$language->plurals."; plural=".strtr($language->formula, array('$' => '')).";\\n\"\n"; |
|
| 752 | 752 | } |
| 753 | 753 | } |
| 754 | 754 | $header .= "\"X-Poedit-SourceCharset: utf-8\\n\"\n"; |
| 755 | 755 | } |
| 756 | 756 | |
| 757 | - $output = $header . "\n"; |
|
| 757 | + $output = $header."\n"; |
|
| 758 | 758 | |
| 759 | 759 | foreach ($strings as $lid => $string) { |
| 760 | 760 | // Only process non-children, children are output below their parent. |
| 761 | 761 | if (!isset($string['child'])) { |
| 762 | 762 | if ($string['comment']) { |
| 763 | - $output .= '#: ' . $string['comment'] . "\n"; |
|
| 763 | + $output .= '#: '.$string['comment']."\n"; |
|
| 764 | 764 | } |
| 765 | 765 | if ($string['context']) { |
| 766 | - $output .= 'msgctxt "' . $string['context'] . "\"\n"; |
|
| 766 | + $output .= 'msgctxt "'.$string['context']."\"\n"; |
|
| 767 | 767 | } |
| 768 | - $output .= 'msgid ' . _locale_export_string($string['source']); |
|
| 768 | + $output .= 'msgid '._locale_export_string($string['source']); |
|
| 769 | 769 | if (!empty($string['plural'])) { |
| 770 | 770 | $plural = $string['plural']; |
| 771 | - $output .= 'msgid_plural ' . _locale_export_string($strings[$plural]['source']); |
|
| 771 | + $output .= 'msgid_plural '._locale_export_string($strings[$plural]['source']); |
|
| 772 | 772 | if (isset($language)) { |
| 773 | 773 | $translation = $string['translation']; |
| 774 | 774 | for ($i = 0; $i < $language->plurals; $i++) { |
| 775 | - $output .= 'msgstr[' . $i . '] ' . _locale_export_string($translation); |
|
| 775 | + $output .= 'msgstr['.$i.'] '._locale_export_string($translation); |
|
| 776 | 776 | if ($plural) { |
| 777 | 777 | $translation = _locale_export_remove_plural($strings[$plural]['translation']); |
| 778 | 778 | $plural = isset($strings[$plural]['plural']) ? $strings[$plural]['plural'] : 0; |
@@ -783,12 +783,12 @@ discard block |
||
| 783 | 783 | } |
| 784 | 784 | } |
| 785 | 785 | else { |
| 786 | - $output .= 'msgstr[0] ""' . "\n"; |
|
| 787 | - $output .= 'msgstr[1] ""' . "\n"; |
|
| 786 | + $output .= 'msgstr[0] ""'."\n"; |
|
| 787 | + $output .= 'msgstr[1] ""'."\n"; |
|
| 788 | 788 | } |
| 789 | 789 | } |
| 790 | 790 | else { |
| 791 | - $output .= 'msgstr ' . _locale_export_string($string['translation']); |
|
| 791 | + $output .= 'msgstr '._locale_export_string($string['translation']); |
|
| 792 | 792 | } |
| 793 | 793 | $output .= "\n"; |
| 794 | 794 | } |
@@ -800,7 +800,7 @@ discard block |
||
| 800 | 800 | * |
| 801 | 801 | */ |
| 802 | 802 | function boinctranslate_refresh_translations() { |
| 803 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 803 | + require_once(getcwd().'/includes/locale.inc'); |
|
| 804 | 804 | $errors = array(); |
| 805 | 805 | $languages = locale_language_list(); |
| 806 | 806 | $translation_resources = array(); |
@@ -847,7 +847,7 @@ discard block |
||
| 847 | 847 | ), |
| 848 | 848 | ); |
| 849 | 849 | // Be sure any strings from the override file are added to the boinc group |
| 850 | - $override_file = './' . drupal_get_path('module', 'boinctranslate') . '/includes/other-boinc-translation-strings.txt'; |
|
| 850 | + $override_file = './'.drupal_get_path('module', 'boinctranslate').'/includes/other-boinc-translation-strings.txt'; |
|
| 851 | 851 | $other_strings = file($override_file); |
| 852 | 852 | if ($other_strings) { |
| 853 | 853 | foreach ($other_strings as $string) { |
@@ -914,7 +914,7 @@ discard block |
||
| 914 | 914 | */ |
| 915 | 915 | function boinctranslate_refresh_translations_op($project, $resource, $langcode, $language, $textgroups, $debug_mode, &$context) { |
| 916 | 916 | |
| 917 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 917 | + require_once(getcwd().'/includes/locale.inc'); |
|
| 918 | 918 | |
| 919 | 919 | if ($debug_mode) { |
| 920 | 920 | watchdog( |
@@ -945,7 +945,7 @@ discard block |
||
| 945 | 945 | $file->filename = basename($file->filepath); |
| 946 | 946 | if (!$file->filepath) { |
| 947 | 947 | $message = 'Unable to create temporary file in ' |
| 948 | - . file_directory_temp() . " for {$language} translation " |
|
| 948 | + . file_directory_temp()." for {$language} translation " |
|
| 949 | 949 | . "resource {$project}:{$resource}"; |
| 950 | 950 | } |
| 951 | 951 | |
@@ -1023,7 +1023,7 @@ discard block |
||
| 1023 | 1023 | $context['finished'] = 1; |
| 1024 | 1024 | } |
| 1025 | 1025 | else { |
| 1026 | - $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; |
|
| 1026 | + $context['finished'] = $context['sandbox']['progress']/$context['sandbox']['max']; |
|
| 1027 | 1027 | } |
| 1028 | 1028 | } |
| 1029 | 1029 | |
@@ -1046,7 +1046,7 @@ discard block |
||
| 1046 | 1046 | // An error occurred. |
| 1047 | 1047 | // $operations contains the operations that remained unprocessed. |
| 1048 | 1048 | $error_operation = reset($operations); |
| 1049 | - $message = 'An error occurred while processing ' . $error_operation[0] . ' with arguments :' . print_r($error_operation[0], TRUE); |
|
| 1049 | + $message = 'An error occurred while processing '.$error_operation[0].' with arguments :'.print_r($error_operation[0], TRUE); |
|
| 1050 | 1050 | watchdog( |
| 1051 | 1051 | 'boinctranslate', |
| 1052 | 1052 | $message, |
@@ -1067,7 +1067,7 @@ discard block |
||
| 1067 | 1067 | @set_time_limit(240); |
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 1070 | + require_once(getcwd().'/includes/locale.inc'); |
|
| 1071 | 1071 | |
| 1072 | 1072 | // Check if we have the language already in the database. |
| 1073 | 1073 | if (!db_fetch_object(db_query("SELECT language FROM {languages} WHERE language = '%s'", $langcode))) { |
@@ -1109,7 +1109,7 @@ discard block |
||
| 1109 | 1109 | */ |
| 1110 | 1110 | function _boinctranslate_locale_import_read_po($op, $file, $mode = NULL, $lang = NULL, $group = 'default') { |
| 1111 | 1111 | |
| 1112 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 1112 | + require_once(getcwd().'/includes/locale.inc'); |
|
| 1113 | 1113 | |
| 1114 | 1114 | $fd = fopen($file->filepath, "rb"); // File will get closed by PHP on return |
| 1115 | 1115 | if (!$fd) { |
@@ -1129,7 +1129,7 @@ discard block |
||
| 1129 | 1129 | $lineno = 0; // Current line |
| 1130 | 1130 | |
| 1131 | 1131 | while (!feof($fd)) { |
| 1132 | - $line = fgets($fd, 10 * 1024); // A line should not be this long |
|
| 1132 | + $line = fgets($fd, 10*1024); // A line should not be this long |
|
| 1133 | 1133 | if ($lineno == 0) { |
| 1134 | 1134 | // The first line might come with a UTF-8 BOM, which should be removed. |
| 1135 | 1135 | $line = str_replace("\xEF\xBB\xBF", '', $line); |
@@ -1211,7 +1211,7 @@ discard block |
||
| 1211 | 1211 | _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); |
| 1212 | 1212 | return FALSE; |
| 1213 | 1213 | } |
| 1214 | - $current["msgid"] = $current["msgid"] . "\0" . $quoted; |
|
| 1214 | + $current["msgid"] = $current["msgid"]."\0".$quoted; |
|
| 1215 | 1215 | $context = "MSGID_PLURAL"; |
| 1216 | 1216 | } |
| 1217 | 1217 | elseif (!strncmp("msgid", $line, 5)) { |
@@ -1364,7 +1364,7 @@ discard block |
||
| 1364 | 1364 | */ |
| 1365 | 1365 | function _boinctranslate_locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NULL, $file = NULL, $group = 'default') { |
| 1366 | 1366 | |
| 1367 | - require_once(getcwd() . '/includes/locale.inc'); |
|
| 1367 | + require_once(getcwd().'/includes/locale.inc'); |
|
| 1368 | 1368 | |
| 1369 | 1369 | static $report = array( |
| 1370 | 1370 | 'additions' => 0, |
@@ -1466,7 +1466,7 @@ discard block |
||
| 1466 | 1466 | // Don't update location, that just makes Drupal add the same strings |
| 1467 | 1467 | // over and over |
| 1468 | 1468 | //db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $location, $lid); |
| 1469 | - $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode)); |
|
| 1469 | + $exists = (bool)db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode)); |
|
| 1470 | 1470 | if (!$exists) { |
| 1471 | 1471 | // No translation in this language. |
| 1472 | 1472 | db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural); |
@@ -1490,7 +1490,7 @@ discard block |
||
| 1490 | 1490 | } |
| 1491 | 1491 | } |
| 1492 | 1492 | elseif ($mode == LOCALE_IMPORT_OVERWRITE AND $lid) { |
| 1493 | - $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode)); |
|
| 1493 | + $exists = (bool)db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode)); |
|
| 1494 | 1494 | if ($exists) { |
| 1495 | 1495 | // Empty translation, remove existing if instructed. |
| 1496 | 1496 | db_query("DELETE FROM {locales_target} WHERE language = '%s' AND lid = %d AND plid = %d AND plural = %d", $langcode, $lid, $plid, $plural); |
@@ -120,8 +120,7 @@ discard block |
||
| 120 | 120 | 'Updated translation source strings for node @nid.', |
| 121 | 121 | array('@nid' => $node->nid) |
| 122 | 122 | ); |
| 123 | - } |
|
| 124 | - else { |
|
| 123 | + } else { |
|
| 125 | 124 | drupal_set_message( |
| 126 | 125 | t('Unable to update translation source strings.'), 'error' |
| 127 | 126 | ); |
@@ -132,8 +131,7 @@ discard block |
||
| 132 | 131 | WATCHDOG_ERROR |
| 133 | 132 | ); |
| 134 | 133 | } |
| 135 | - } |
|
| 136 | - else { |
|
| 134 | + } else { |
|
| 137 | 135 | $result = db_query(" |
| 138 | 136 | INSERT INTO {locales_source} |
| 139 | 137 | SET location = '%s', textgroup = '%s', source = '%s'", |
@@ -145,8 +143,7 @@ discard block |
||
| 145 | 143 | 'Added translation source strings for node @nid.', |
| 146 | 144 | array('@nid' => $node->nid) |
| 147 | 145 | ); |
| 148 | - } |
|
| 149 | - else { |
|
| 146 | + } else { |
|
| 150 | 147 | drupal_set_message( |
| 151 | 148 | t('Unable to add translation source strings.'), 'error' |
| 152 | 149 | ); |
@@ -230,8 +227,7 @@ discard block |
||
| 230 | 227 | ) |
| 231 | 228 | ), 'warning' |
| 232 | 229 | ); |
| 233 | - } |
|
| 234 | - elseif ($response) { |
|
| 230 | + } elseif ($response) { |
|
| 235 | 231 | if (is_array($response)) { |
| 236 | 232 | |
| 237 | 233 | $installed_languages = language_list(); |
@@ -261,8 +257,7 @@ discard block |
||
| 261 | 257 | 'Added predefined language: '.$available_languages[$rfc_code][0] |
| 262 | 258 | ); |
| 263 | 259 | db_query("UPDATE {languages} SET enabled = 1 WHERE language = '%s'", $rfc_code); |
| 264 | - } |
|
| 265 | - else { |
|
| 260 | + } else { |
|
| 266 | 261 | // Retrieve language details from Transifex |
| 267 | 262 | $path = "language/{$posix_code}"; |
| 268 | 263 | $response = boinctranslate_transifex_request($path); |
@@ -275,8 +270,7 @@ discard block |
||
| 275 | 270 | ) |
| 276 | 271 | ), 'warning' |
| 277 | 272 | ); |
| 278 | - } |
|
| 279 | - elseif ($response) { |
|
| 273 | + } elseif ($response) { |
|
| 280 | 274 | if (!empty($response['name'])) { |
| 281 | 275 | // Add a custom language to Drupal and enable |
| 282 | 276 | locale_add_language( |
@@ -291,8 +285,7 @@ discard block |
||
| 291 | 285 | drupal_set_message( |
| 292 | 286 | 'Added new language: '.$response['name'] |
| 293 | 287 | ); |
| 294 | - } |
|
| 295 | - else { |
|
| 288 | + } else { |
|
| 296 | 289 | $variables = array( |
| 297 | 290 | '%code' => $posix_code, |
| 298 | 291 | ); |
@@ -307,8 +300,7 @@ discard block |
||
| 307 | 300 | WATCHDOG_ERROR |
| 308 | 301 | ); |
| 309 | 302 | } |
| 310 | - } |
|
| 311 | - else { |
|
| 303 | + } else { |
|
| 312 | 304 | $variables = array( |
| 313 | 305 | '%code' => $posix_code, |
| 314 | 306 | ); |
@@ -349,8 +341,7 @@ discard block |
||
| 349 | 341 | batch_set($batch); |
| 350 | 342 | batch_process('admin/boinc/translation'); |
| 351 | 343 | } |
| 352 | - } |
|
| 353 | - else { |
|
| 344 | + } else { |
|
| 354 | 345 | $variables = array( |
| 355 | 346 | '%project' => $project, |
| 356 | 347 | ); |
@@ -365,8 +356,7 @@ discard block |
||
| 365 | 356 | WATCHDOG_ERROR |
| 366 | 357 | ); |
| 367 | 358 | } |
| 368 | - } |
|
| 369 | - else { |
|
| 359 | + } else { |
|
| 370 | 360 | $variables = array( |
| 371 | 361 | '%project' => $project, |
| 372 | 362 | ); |
@@ -423,8 +413,7 @@ discard block |
||
| 423 | 413 | 'content' => boinctranslate_get_po('en', 'project'), |
| 424 | 414 | ); |
| 425 | 415 | $result = boinctranslate_transifex_request($path, $post); |
| 426 | - } |
|
| 427 | - else { |
|
| 416 | + } else { |
|
| 428 | 417 | // Update the source |
| 429 | 418 | $path = "project/{$project_name}/resource/{$primary_resource}/content"; |
| 430 | 419 | $post = array( |
@@ -438,8 +427,7 @@ discard block |
||
| 438 | 427 | $enabled_languages = locale_language_list(); |
| 439 | 428 | if ($source_exists) { |
| 440 | 429 | drupal_set_message('Updated source translation strings at Transifex'); |
| 441 | - } |
|
| 442 | - else { |
|
| 430 | + } else { |
|
| 443 | 431 | drupal_set_message('Established new translation resource at Transifex'); |
| 444 | 432 | } |
| 445 | 433 | // Try to export translations for all enabled languages |
@@ -460,25 +448,21 @@ discard block |
||
| 460 | 448 | "Unable to update {$language_name} translations: {$result}", |
| 461 | 449 | 'warning' |
| 462 | 450 | ); |
| 463 | - } |
|
| 464 | - else { |
|
| 451 | + } else { |
|
| 465 | 452 | drupal_set_message("Updated {$language_name} translations"); |
| 466 | 453 | //drupal_set_message('DEBUG: <pre>'.print_r($result,1).'</pre>'); |
| 467 | 454 | } |
| 468 | - } |
|
| 469 | - else { |
|
| 455 | + } else { |
|
| 470 | 456 | drupal_set_message("No translations to export for {$language_name}"); |
| 471 | 457 | } |
| 472 | 458 | } |
| 473 | - } |
|
| 474 | - else { |
|
| 459 | + } else { |
|
| 475 | 460 | drupal_set_message( |
| 476 | 461 | "Unable to update the translation source: {$result}", |
| 477 | 462 | 'warning' |
| 478 | 463 | ); |
| 479 | 464 | } |
| 480 | - } |
|
| 481 | - else { |
|
| 465 | + } else { |
|
| 482 | 466 | drupal_set_message( |
| 483 | 467 | 'Failed to export translations: Transifex settings are not intiailized.', |
| 484 | 468 | 'error' |
@@ -534,42 +518,35 @@ discard block |
||
| 534 | 518 | "Unable to update {$language_name} official BOINC translations: {$result}", |
| 535 | 519 | 'warning' |
| 536 | 520 | ); |
| 537 | - } |
|
| 538 | - elseif ($result == '401 UNAUTHORIZED') { |
|
| 521 | + } elseif ($result == '401 UNAUTHORIZED') { |
|
| 539 | 522 | drupal_set_message( |
| 540 | 523 | 'Not authorized to update official BOINC translations', |
| 541 | 524 | 'warning' |
| 542 | 525 | ); |
| 543 | 526 | break; |
| 544 | - } |
|
| 545 | - elseif ($result == 'success') { |
|
| 527 | + } elseif ($result == 'success') { |
|
| 546 | 528 | drupal_set_message("Updated {$language_name} official BOINC translations"); |
| 547 | - } |
|
| 548 | - else { |
|
| 529 | + } else { |
|
| 549 | 530 | drupal_set_message( |
| 550 | 531 | "Unexpected response for {$language_name}: {$result}", |
| 551 | 532 | 'warning' |
| 552 | 533 | ); |
| 553 | 534 | } |
| 554 | - } |
|
| 555 | - else { |
|
| 535 | + } else { |
|
| 556 | 536 | drupal_set_message("Updated {$language_name} official BOINC translations"); |
| 557 | 537 | //drupal_set_message('DEBUG: <pre>'.print_r($result,1).'</pre>'); |
| 558 | 538 | } |
| 559 | - } |
|
| 560 | - else { |
|
| 539 | + } else { |
|
| 561 | 540 | drupal_set_message("No official BOINC translations to export for {$language_name}"); |
| 562 | 541 | } |
| 563 | 542 | } |
| 564 | - } |
|
| 565 | - else { |
|
| 543 | + } else { |
|
| 566 | 544 | drupal_set_message( |
| 567 | 545 | "The {$drupal_resource} resource does not exist in the {$project_name} project at Transifex", |
| 568 | 546 | 'warning' |
| 569 | 547 | ); |
| 570 | 548 | } |
| 571 | - } |
|
| 572 | - else { |
|
| 549 | + } else { |
|
| 573 | 550 | drupal_set_message( |
| 574 | 551 | 'Failed to export official BOINC translations: Transifex settings are not intiailized.', |
| 575 | 552 | 'error' |
@@ -594,8 +571,12 @@ discard block |
||
| 594 | 571 | |
| 595 | 572 | // Transifex details |
| 596 | 573 | $api_base_url = 'https://www.transifex.com/api/2'; |
| 597 | - if (!$username) $username = variable_get('boinc_translate_transifex_user', ''); |
|
| 598 | - if (!$password) $password = variable_get('boinc_translate_transifex_pass', ''); |
|
| 574 | + if (!$username) { |
|
| 575 | + $username = variable_get('boinc_translate_transifex_user', ''); |
|
| 576 | + } |
|
| 577 | + if (!$password) { |
|
| 578 | + $password = variable_get('boinc_translate_transifex_pass', ''); |
|
| 579 | + } |
|
| 599 | 580 | |
| 600 | 581 | $url = "{$api_base_url}/{$path}"; |
| 601 | 582 | $headers = array( |
@@ -607,13 +588,11 @@ discard block |
||
| 607 | 588 | if ($json) { |
| 608 | 589 | $headers['Content-Type'] = 'application/json'; |
| 609 | 590 | $data = json_encode($post); |
| 610 | - } |
|
| 611 | - else { |
|
| 591 | + } else { |
|
| 612 | 592 | $data = drupal_query_string_encode($post); |
| 613 | 593 | } |
| 614 | 594 | $method = ($use_put) ? 'PUT' : 'POST'; |
| 615 | - } |
|
| 616 | - else { |
|
| 595 | + } else { |
|
| 617 | 596 | $method = 'GET'; |
| 618 | 597 | } |
| 619 | 598 | |
@@ -625,8 +604,7 @@ discard block |
||
| 625 | 604 | if ($json) { |
| 626 | 605 | // Process as JSON |
| 627 | 606 | return json_decode($response->data, TRUE); |
| 628 | - } |
|
| 629 | - else { |
|
| 607 | + } else { |
|
| 630 | 608 | return (string) $response->data; |
| 631 | 609 | } |
| 632 | 610 | break; |
@@ -635,10 +613,14 @@ discard block |
||
| 635 | 613 | case 401: |
| 636 | 614 | return '401 UNAUTHORIZED'; |
| 637 | 615 | case 400: |
| 638 | - if ($debug_mode) watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING); |
|
| 616 | + if ($debug_mode) { |
|
| 617 | + watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING); |
|
| 618 | + } |
|
| 639 | 619 | return "ERROR: {$response->data}"; |
| 640 | 620 | case 405: |
| 641 | - if ($debug_mode) watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING); |
|
| 621 | + if ($debug_mode) { |
|
| 622 | + watchdog('boinctranslate', "The following response was received when trying to communicate with the Transifex system: \n{$response}", array(), WATCHDOG_WARNING); |
|
| 623 | + } |
|
| 642 | 624 | return "ERROR: User not allowed to perform this action"; |
| 643 | 625 | } |
| 644 | 626 | |
@@ -776,18 +758,15 @@ discard block |
||
| 776 | 758 | if ($plural) { |
| 777 | 759 | $translation = _locale_export_remove_plural($strings[$plural]['translation']); |
| 778 | 760 | $plural = isset($strings[$plural]['plural']) ? $strings[$plural]['plural'] : 0; |
| 779 | - } |
|
| 780 | - else { |
|
| 761 | + } else { |
|
| 781 | 762 | $translation = ''; |
| 782 | 763 | } |
| 783 | 764 | } |
| 784 | - } |
|
| 785 | - else { |
|
| 765 | + } else { |
|
| 786 | 766 | $output .= 'msgstr[0] ""' . "\n"; |
| 787 | 767 | $output .= 'msgstr[1] ""' . "\n"; |
| 788 | 768 | } |
| 789 | - } |
|
| 790 | - else { |
|
| 769 | + } else { |
|
| 791 | 770 | $output .= 'msgstr ' . _locale_export_string($string['translation']); |
| 792 | 771 | } |
| 793 | 772 | $output .= "\n"; |
@@ -934,8 +913,7 @@ discard block |
||
| 934 | 913 | |
| 935 | 914 | if ($response == '404 NOT FOUND') { |
| 936 | 915 | $message = "Project resource {$project}:{$resource} not found in {$language}."; |
| 937 | - } |
|
| 938 | - elseif ($response) { |
|
| 916 | + } elseif ($response) { |
|
| 939 | 917 | if (!empty($response['content'])) { |
| 940 | 918 | $po_text = $response['content']; |
| 941 | 919 | |
@@ -956,23 +934,19 @@ discard block |
||
| 956 | 934 | . " {$project}:{$resource} failed."; |
| 957 | 935 | $success = FALSE; |
| 958 | 936 | break; |
| 959 | - } |
|
| 960 | - else { |
|
| 937 | + } else { |
|
| 961 | 938 | $success = TRUE; |
| 962 | 939 | } |
| 963 | 940 | } |
| 964 | - } |
|
| 965 | - else { |
|
| 941 | + } else { |
|
| 966 | 942 | $message = "Unable to read response for {$language} translation import" |
| 967 | 943 | . " of {$project}:{$resource}."; |
| 968 | 944 | } |
| 969 | - } |
|
| 970 | - else { |
|
| 945 | + } else { |
|
| 971 | 946 | $message = "Translation data not found in response for {$language}" |
| 972 | 947 | . " translation import of {$project}:{$resource}."; |
| 973 | 948 | } |
| 974 | - } |
|
| 975 | - else { |
|
| 949 | + } else { |
|
| 976 | 950 | // If project isn't specified, import as a local Drupal resource |
| 977 | 951 | $project = 'drupal.local'; |
| 978 | 952 | $file = new stdClass(); |
@@ -983,8 +957,7 @@ discard block |
||
| 983 | 957 | . " local file {$resource} failed."; |
| 984 | 958 | $success = FALSE; |
| 985 | 959 | break; |
| 986 | - } |
|
| 987 | - else { |
|
| 960 | + } else { |
|
| 988 | 961 | $success = TRUE; |
| 989 | 962 | } |
| 990 | 963 | } |
@@ -1002,8 +975,7 @@ discard block |
||
| 1002 | 975 | WATCHDOG_INFO |
| 1003 | 976 | ); |
| 1004 | 977 | } |
| 1005 | - } |
|
| 1006 | - else { |
|
| 978 | + } else { |
|
| 1007 | 979 | $context['results']['failure'][] = "{$langcode}:{$textgroup}"; |
| 1008 | 980 | watchdog( |
| 1009 | 981 | 'boinctranslate', |
@@ -1021,8 +993,7 @@ discard block |
||
| 1021 | 993 | // Update the progress for the batch engine |
| 1022 | 994 | if ($context['sandbox']['progress'] >= $context['sandbox']['max']) { |
| 1023 | 995 | $context['finished'] = 1; |
| 1024 | - } |
|
| 1025 | - else { |
|
| 996 | + } else { |
|
| 1026 | 997 | $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; |
| 1027 | 998 | } |
| 1028 | 999 | } |
@@ -1041,8 +1012,7 @@ discard block |
||
| 1041 | 1012 | array('@count' => $count), |
| 1042 | 1013 | WATCHDOG_INFO |
| 1043 | 1014 | ); |
| 1044 | - } |
|
| 1045 | - else { |
|
| 1015 | + } else { |
|
| 1046 | 1016 | // An error occurred. |
| 1047 | 1017 | // $operations contains the operations that remained unprocessed. |
| 1048 | 1018 | $error_operation = reset($operations); |
@@ -1140,14 +1110,12 @@ discard block |
||
| 1140 | 1110 | if (!strncmp("#", $line, 1)) { // A comment |
| 1141 | 1111 | if ($context == "COMMENT") { // Already in comment context: add |
| 1142 | 1112 | $current["#"][] = substr($line, 1); |
| 1143 | - } |
|
| 1144 | - elseif (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 1113 | + } elseif (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
|
| 1145 | 1114 | _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group); |
| 1146 | 1115 | $current = array(); |
| 1147 | 1116 | $current["#"][] = substr($line, 1); |
| 1148 | 1117 | $context = "COMMENT"; |
| 1149 | - } |
|
| 1150 | - else { // Parse error |
|
| 1118 | + } else { // Parse error |
|
| 1151 | 1119 | watchdog( |
| 1152 | 1120 | 'boinctranslate', |
| 1153 | 1121 | 'The translation file %filename for %lang contains an error: "msgstr" was expected but not found on line %line.', |
@@ -1157,13 +1125,11 @@ discard block |
||
| 1157 | 1125 | _locale_import_message('The translation file %filename contains an error: "msgstr" was expected but not found on line %line.', $file, $lineno); |
| 1158 | 1126 | return FALSE; |
| 1159 | 1127 | } |
| 1160 | - } |
|
| 1161 | - elseif (!strncmp("msgctxt", $line, 7)) { |
|
| 1128 | + } elseif (!strncmp("msgctxt", $line, 7)) { |
|
| 1162 | 1129 | if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
| 1163 | 1130 | _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group); |
| 1164 | 1131 | $current = array(); |
| 1165 | - } |
|
| 1166 | - elseif (($context == "MSGID") || ($context == "MSGCTXT")) { // Already in this context? Parse error |
|
| 1132 | + } elseif (($context == "MSGID") || ($context == "MSGCTXT")) { // Already in this context? Parse error |
|
| 1167 | 1133 | watchdog( |
| 1168 | 1134 | 'boinctranslate', |
| 1169 | 1135 | 'The translation file %filename for %lang contains an error: "msgctxt" is unexpected on line %line.', |
@@ -1187,8 +1153,7 @@ discard block |
||
| 1187 | 1153 | } |
| 1188 | 1154 | $current["msgctxt"] = $quoted; |
| 1189 | 1155 | $context = "MSGCTXT"; |
| 1190 | - } |
|
| 1191 | - elseif (!strncmp("msgid_plural", $line, 12)) { |
|
| 1156 | + } elseif (!strncmp("msgid_plural", $line, 12)) { |
|
| 1192 | 1157 | if ($context != "MSGID") { // Must be plural form for current entry |
| 1193 | 1158 | watchdog( |
| 1194 | 1159 | 'boinctranslate', |
@@ -1213,13 +1178,11 @@ discard block |
||
| 1213 | 1178 | } |
| 1214 | 1179 | $current["msgid"] = $current["msgid"] . "\0" . $quoted; |
| 1215 | 1180 | $context = "MSGID_PLURAL"; |
| 1216 | - } |
|
| 1217 | - elseif (!strncmp("msgid", $line, 5)) { |
|
| 1181 | + } elseif (!strncmp("msgid", $line, 5)) { |
|
| 1218 | 1182 | if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one |
| 1219 | 1183 | _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group); |
| 1220 | 1184 | $current = array(); |
| 1221 | - } |
|
| 1222 | - elseif ($context == "MSGID") { // Already in this context? Parse error |
|
| 1185 | + } elseif ($context == "MSGID") { // Already in this context? Parse error |
|
| 1223 | 1186 | watchdog( |
| 1224 | 1187 | 'boinctranslate', |
| 1225 | 1188 | 'The translation file %filename for %lang contains an error: "msgid" is unexpected on line %line.', |
@@ -1243,8 +1206,7 @@ discard block |
||
| 1243 | 1206 | } |
| 1244 | 1207 | $current["msgid"] = $quoted; |
| 1245 | 1208 | $context = "MSGID"; |
| 1246 | - } |
|
| 1247 | - elseif (!strncmp("msgstr[", $line, 7)) { |
|
| 1209 | + } elseif (!strncmp("msgstr[", $line, 7)) { |
|
| 1248 | 1210 | if (($context != "MSGID") && ($context != "MSGID_PLURAL") && ($context != "MSGSTR_ARR")) { // Must come after msgid, msgid_plural, or msgstr[] |
| 1249 | 1211 | watchdog( |
| 1250 | 1212 | 'boinctranslate', |
@@ -1281,8 +1243,7 @@ discard block |
||
| 1281 | 1243 | } |
| 1282 | 1244 | $current["msgstr"][$plural] = $quoted; |
| 1283 | 1245 | $context = "MSGSTR_ARR"; |
| 1284 | - } |
|
| 1285 | - elseif (!strncmp("msgstr", $line, 6)) { |
|
| 1246 | + } elseif (!strncmp("msgstr", $line, 6)) { |
|
| 1286 | 1247 | if ($context != "MSGID") { // Should come just after a msgid block |
| 1287 | 1248 | watchdog( |
| 1288 | 1249 | 'boinctranslate', |
@@ -1307,8 +1268,7 @@ discard block |
||
| 1307 | 1268 | } |
| 1308 | 1269 | $current["msgstr"] = $quoted; |
| 1309 | 1270 | $context = "MSGSTR"; |
| 1310 | - } |
|
| 1311 | - elseif ($line != "") { |
|
| 1271 | + } elseif ($line != "") { |
|
| 1312 | 1272 | $quoted = _locale_import_parse_quoted($line); |
| 1313 | 1273 | if ($quoted === FALSE) { |
| 1314 | 1274 | watchdog( |
@@ -1322,14 +1282,11 @@ discard block |
||
| 1322 | 1282 | } |
| 1323 | 1283 | if (($context == "MSGID") || ($context == "MSGID_PLURAL")) { |
| 1324 | 1284 | $current["msgid"] .= $quoted; |
| 1325 | - } |
|
| 1326 | - elseif ($context == "MSGSTR") { |
|
| 1285 | + } elseif ($context == "MSGSTR") { |
|
| 1327 | 1286 | $current["msgstr"] .= $quoted; |
| 1328 | - } |
|
| 1329 | - elseif ($context == "MSGSTR_ARR") { |
|
| 1287 | + } elseif ($context == "MSGSTR_ARR") { |
|
| 1330 | 1288 | $current["msgstr"][$plural] .= $quoted; |
| 1331 | - } |
|
| 1332 | - else { |
|
| 1289 | + } else { |
|
| 1333 | 1290 | watchdog( |
| 1334 | 1291 | 'boinctranslate', |
| 1335 | 1292 | 'The translation file %filename for %lang contains an error: there is an unexpected string on line %line.', |
@@ -1345,8 +1302,7 @@ discard block |
||
| 1345 | 1302 | // End of PO file, flush last entry |
| 1346 | 1303 | if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { |
| 1347 | 1304 | _boinctranslate_locale_import_one_string($op, $current, $mode, $lang, $file, $group); |
| 1348 | - } |
|
| 1349 | - elseif ($context != "COMMENT") { |
|
| 1305 | + } elseif ($context != "COMMENT") { |
|
| 1350 | 1306 | watchdog( |
| 1351 | 1307 | 'boinctranslate', |
| 1352 | 1308 | 'The translation file %filename for %lang ended unexpectedly at line %line.', |
@@ -1413,9 +1369,7 @@ discard block |
||
| 1413 | 1369 | } |
| 1414 | 1370 | } |
| 1415 | 1371 | $headerdone = TRUE; |
| 1416 | - } |
|
| 1417 | - |
|
| 1418 | - else { |
|
| 1372 | + } else { |
|
| 1419 | 1373 | // Some real string to import. |
| 1420 | 1374 | $comments = _locale_import_shorten_comments(empty($value['#']) ? array() : $value['#']); |
| 1421 | 1375 | |
@@ -1434,9 +1388,7 @@ discard block |
||
| 1434 | 1388 | } |
| 1435 | 1389 | $plid = _boinctranslate_locale_import_one_string_db($report, $lang, $english[$key], $trans, $group, $comments, $mode, $plid, $key); |
| 1436 | 1390 | } |
| 1437 | - } |
|
| 1438 | - |
|
| 1439 | - else { |
|
| 1391 | + } else { |
|
| 1440 | 1392 | // A simple string to import. |
| 1441 | 1393 | $english = $value['msgid']; |
| 1442 | 1394 | $translation = $value['msgstr']; |
@@ -1460,8 +1412,7 @@ discard block |
||
| 1460 | 1412 | if ($textgroup == "default" && !locale_string_is_safe($translation)) { |
| 1461 | 1413 | $report['skips']++; |
| 1462 | 1414 | $lid = 0; |
| 1463 | - } |
|
| 1464 | - elseif ($lid) { |
|
| 1415 | + } elseif ($lid) { |
|
| 1465 | 1416 | // We have this source string saved already. |
| 1466 | 1417 | // Don't update location, that just makes Drupal add the same strings |
| 1467 | 1418 | // over and over |
@@ -1471,14 +1422,12 @@ discard block |
||
| 1471 | 1422 | // No translation in this language. |
| 1472 | 1423 | db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural); |
| 1473 | 1424 | $report['additions']++; |
| 1474 | - } |
|
| 1475 | - else if ($mode == LOCALE_IMPORT_OVERWRITE) { |
|
| 1425 | + } else if ($mode == LOCALE_IMPORT_OVERWRITE) { |
|
| 1476 | 1426 | // Translation exists, only overwrite if instructed. |
| 1477 | 1427 | db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE language = '%s' AND lid = %d", $translation, $plid, $plural, $langcode, $lid); |
| 1478 | 1428 | $report['updates']++; |
| 1479 | 1429 | } |
| 1480 | - } |
|
| 1481 | - else { |
|
| 1430 | + } else { |
|
| 1482 | 1431 | // No such source string in the database yet. |
| 1483 | 1432 | // Do not insert the source string if it does not belong on the site! |
| 1484 | 1433 | /* |
@@ -1488,16 +1437,14 @@ discard block |
||
| 1488 | 1437 | $report['additions']++; |
| 1489 | 1438 | */ |
| 1490 | 1439 | } |
| 1491 | - } |
|
| 1492 | - elseif ($mode == LOCALE_IMPORT_OVERWRITE AND $lid) { |
|
| 1440 | + } elseif ($mode == LOCALE_IMPORT_OVERWRITE AND $lid) { |
|
| 1493 | 1441 | $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode)); |
| 1494 | 1442 | if ($exists) { |
| 1495 | 1443 | // Empty translation, remove existing if instructed. |
| 1496 | 1444 | db_query("DELETE FROM {locales_target} WHERE language = '%s' AND lid = %d AND plid = %d AND plural = %d", $langcode, $lid, $plid, $plural); |
| 1497 | 1445 | $report['deletes']++; |
| 1498 | 1446 | } |
| 1499 | - } |
|
| 1500 | - else { |
|
| 1447 | + } else { |
|
| 1501 | 1448 | $report['skips']++; |
| 1502 | 1449 | } |
| 1503 | 1450 | |
@@ -26,6 +26,8 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * Get an image object from a given file and cck field |
| 29 | + * @param string $field_name |
|
| 30 | + * @param string $content_type |
|
| 29 | 31 | */ |
| 30 | 32 | function get_cck_image_object($image_path, $field_name, $content_type, $ignore_resolution = FALSE) { |
| 31 | 33 | $field = content_fields($field_name, $content_type); |
@@ -237,6 +239,7 @@ discard block |
||
| 237 | 239 | /** |
| 238 | 240 | * Include BOINC code |
| 239 | 241 | * The path from the BOINC html root must be included (e.g. user/file.php) |
| 242 | + * @param string $file |
|
| 240 | 243 | */ |
| 241 | 244 | function include_boinc($file) { |
| 242 | 245 | if ($include_dir = boinc_get_path()) { |
@@ -252,6 +255,7 @@ discard block |
||
| 252 | 255 | |
| 253 | 256 | /** |
| 254 | 257 | * Get the BOINC include path |
| 258 | + * @return string |
|
| 255 | 259 | */ |
| 256 | 260 | function boinc_get_path($type = 'root') { |
| 257 | 261 | $dir = "boinc_{$type}_dir"; |
@@ -11,12 +11,12 @@ discard block |
||
| 11 | 11 | * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 12 | 12 | |
| 13 | 13 | if (!function_exists('user_load_by_mail')) { |
| 14 | - /** |
|
| 15 | - * user_load_by_mail will be broken out of user_load |
|
| 16 | - */ |
|
| 17 | - function user_load_by_mail($mail) { |
|
| 14 | + /** |
|
| 15 | + * user_load_by_mail will be broken out of user_load |
|
| 16 | + */ |
|
| 17 | + function user_load_by_mail($mail) { |
|
| 18 | 18 | return user_load(array('mail' => $mail)); |
| 19 | - } |
|
| 19 | + } |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -28,14 +28,14 @@ discard block |
||
| 28 | 28 | * Get an image object from a given file and cck field |
| 29 | 29 | */ |
| 30 | 30 | function get_cck_image_object($image_path, $field_name, $content_type, $ignore_resolution = FALSE) { |
| 31 | - $field = content_fields($field_name, $content_type); |
|
| 32 | - $validators = array_merge(filefield_widget_upload_validators($field), imagefield_widget_upload_validators($field)); |
|
| 33 | - if ($ignore_resolution) { |
|
| 31 | + $field = content_fields($field_name, $content_type); |
|
| 32 | + $validators = array_merge(filefield_widget_upload_validators($field), imagefield_widget_upload_validators($field)); |
|
| 33 | + if ($ignore_resolution) { |
|
| 34 | 34 | unset($validators['filefield_validate_image_resolution']); |
| 35 | - } |
|
| 36 | - $target_path = filefield_widget_file_path($field); |
|
| 37 | - // Create the image object |
|
| 38 | - return field_file_save_file($image_path, $validators, $target_path, FILE_EXISTS_REPLACE); |
|
| 35 | + } |
|
| 36 | + $target_path = filefield_widget_file_path($field); |
|
| 37 | + // Create the image object |
|
| 38 | + return field_file_save_file($image_path, $validators, $target_path, FILE_EXISTS_REPLACE); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
@@ -47,62 +47,62 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | */ |
| 49 | 49 | function boincuser_check_credit_requirements() { |
| 50 | - global $user; |
|
| 51 | - if (!$user->uid) { |
|
| 50 | + global $user; |
|
| 51 | + if (!$user->uid) { |
|
| 52 | 52 | return FALSE; |
| 53 | - } |
|
| 54 | - $account = user_load($user->uid); |
|
| 55 | - $min_credit_to_post = variable_get('boinc_comment_min_credit', 0); |
|
| 56 | - $community_role = array_search('community member', user_roles(true)); |
|
| 57 | - $unrestricted_role = array_search('verified contributor', user_roles(true)); |
|
| 53 | + } |
|
| 54 | + $account = user_load($user->uid); |
|
| 55 | + $min_credit_to_post = variable_get('boinc_comment_min_credit', 0); |
|
| 56 | + $community_role = array_search('community member', user_roles(true)); |
|
| 57 | + $unrestricted_role = array_search('verified contributor', user_roles(true)); |
|
| 58 | 58 | |
| 59 | - // Set user roles based on current penalty status and total credit |
|
| 60 | - if ($account->boincuser_penalty_expiration > time()) { |
|
| 59 | + // Set user roles based on current penalty status and total credit |
|
| 60 | + if ($account->boincuser_penalty_expiration > time()) { |
|
| 61 | 61 | drupal_set_message(bts( |
| 62 | - 'You are banned from community participation until @date', |
|
| 63 | - array('@date' => format_date($account->boincuser_penalty_expiration)) |
|
| 62 | + 'You are banned from community participation until @date', |
|
| 63 | + array('@date' => format_date($account->boincuser_penalty_expiration)) |
|
| 64 | 64 | ), 'warning', FALSE); |
| 65 | 65 | if (isset($account->roles[$community_role])) { |
| 66 | - // Remove from the community role, if not already |
|
| 67 | - unset($account->roles[$community_role]); |
|
| 66 | + // Remove from the community role, if not already |
|
| 67 | + unset($account->roles[$community_role]); |
|
| 68 | 68 | } |
| 69 | 69 | if (isset($account->roles[$unrestricted_role])) { |
| 70 | - // Likewise, revoke extra privileges |
|
| 71 | - unset($account->roles[$unrestricted_role]); |
|
| 70 | + // Likewise, revoke extra privileges |
|
| 71 | + unset($account->roles[$unrestricted_role]); |
|
| 72 | 72 | } |
| 73 | 73 | user_save($account, array('roles' => $account->roles)); |
| 74 | - } |
|
| 75 | - elseif ($account->boincuser_total_credit >= $min_credit_to_post) { |
|
| 74 | + } |
|
| 75 | + elseif ($account->boincuser_total_credit >= $min_credit_to_post) { |
|
| 76 | 76 | if (!isset($account->roles[$unrestricted_role])) { |
| 77 | - // This user is now above the credit threshold and is allowed full |
|
| 78 | - // privileges |
|
| 79 | - $account->roles[$unrestricted_role] = 'verified contributor'; |
|
| 80 | - user_save($account, array('roles' => $account->roles)); |
|
| 77 | + // This user is now above the credit threshold and is allowed full |
|
| 78 | + // privileges |
|
| 79 | + $account->roles[$unrestricted_role] = 'verified contributor'; |
|
| 80 | + user_save($account, array('roles' => $account->roles)); |
|
| 81 | 81 | } |
| 82 | - } |
|
| 83 | - else { |
|
| 82 | + } |
|
| 83 | + else { |
|
| 84 | 84 | drupal_set_message(bts( |
| 85 | - 'You must earn @count more credits to be able to post comments on this site.', |
|
| 86 | - array('@count' => $min_credit_to_post - $account->boincuser_total_credit) |
|
| 85 | + 'You must earn @count more credits to be able to post comments on this site.', |
|
| 86 | + array('@count' => $min_credit_to_post - $account->boincuser_total_credit) |
|
| 87 | 87 | ), 'warning', FALSE); |
| 88 | 88 | if (isset($account->roles[$unrestricted_role])) { |
| 89 | - // Either the threshold has been raised or credits have been revoked; |
|
| 90 | - // this user no longer qualifies for full privileges |
|
| 91 | - unset($account->roles[$unrestricted_role]); |
|
| 92 | - user_save($account, array('roles' => $account->roles)); |
|
| 89 | + // Either the threshold has been raised or credits have been revoked; |
|
| 90 | + // this user no longer qualifies for full privileges |
|
| 91 | + unset($account->roles[$unrestricted_role]); |
|
| 92 | + user_save($account, array('roles' => $account->roles)); |
|
| 93 | + } |
|
| 93 | 94 | } |
| 94 | - } |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | 98 | * Get the cid of the first comment the user has not seen on a given node |
| 99 | 99 | */ |
| 100 | 100 | function boincuser_get_first_unread_comment_id($nid, $uid = NULL) { |
| 101 | - if (!$uid) { |
|
| 101 | + if (!$uid) { |
|
| 102 | 102 | global $user; |
| 103 | 103 | $uid = $user->uid; |
| 104 | - } |
|
| 105 | - return db_result(db_query(" |
|
| 104 | + } |
|
| 105 | + return db_result(db_query(" |
|
| 106 | 106 | SELECT c.cid |
| 107 | 107 | FROM {node} n |
| 108 | 108 | INNER JOIN {comments} c ON c.nid = n.nid |
@@ -113,40 +113,40 @@ discard block |
||
| 113 | 113 | ORDER BY c.timestamp ASC |
| 114 | 114 | LIMIT 1", |
| 115 | 115 | $uid, $nid |
| 116 | - )); |
|
| 116 | + )); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * Choose and set the user of the day |
| 121 | 121 | */ |
| 122 | 122 | function boincuser_select_user_of_the_day() { |
| 123 | - // First get a list of users with recent credit |
|
| 124 | - db_set_active('boinc'); |
|
| 125 | - $users_with_credit = db_query(" |
|
| 123 | + // First get a list of users with recent credit |
|
| 124 | + db_set_active('boinc'); |
|
| 125 | + $users_with_credit = db_query(" |
|
| 126 | 126 | SELECT |
| 127 | 127 | id |
| 128 | 128 | FROM {user} u |
| 129 | 129 | JOIN {profile} p ON p.userid = u.id |
| 130 | 130 | WHERE expavg_credit > 1 |
| 131 | 131 | ORDER BY uotd_time ASC, RAND()" |
| 132 | - ); |
|
| 133 | - db_set_active('default'); |
|
| 134 | - $active_users = array(); |
|
| 135 | - while ($user_with_credit = db_fetch_object($users_with_credit)) { |
|
| 132 | + ); |
|
| 133 | + db_set_active('default'); |
|
| 134 | + $active_users = array(); |
|
| 135 | + while ($user_with_credit = db_fetch_object($users_with_credit)) { |
|
| 136 | 136 | $active_users[] = $user_with_credit->id; |
| 137 | - } |
|
| 138 | - $active_users = implode(',', $active_users); |
|
| 139 | - // Limit to users who have never been user of the day, if there are any |
|
| 140 | - $never_been_picked = db_result(db_query(" |
|
| 137 | + } |
|
| 138 | + $active_users = implode(',', $active_users); |
|
| 139 | + // Limit to users who have never been user of the day, if there are any |
|
| 140 | + $never_been_picked = db_result(db_query(" |
|
| 141 | 141 | SELECT COUNT(*) |
| 142 | 142 | FROM {boincuser} bu |
| 143 | 143 | WHERE bu.uotd_time = 0 |
| 144 | 144 | " . ($active_users ? " AND bu.boinc_id IN ({$active_users}) " : '') |
| 145 | - )); |
|
| 146 | - $new_uotd_uid = 0; |
|
| 147 | - while (!$new_uotd_uid) { |
|
| 145 | + )); |
|
| 146 | + $new_uotd_uid = 0; |
|
| 147 | + while (!$new_uotd_uid) { |
|
| 148 | 148 | // Select a user of the day randomly from the pool |
| 149 | - $new_uotd_uid = db_result(db_query(" |
|
| 149 | + $new_uotd_uid = db_result(db_query(" |
|
| 150 | 150 | SELECT |
| 151 | 151 | n.uid |
| 152 | 152 | FROM {node} n |
@@ -160,56 +160,56 @@ discard block |
||
| 160 | 160 | LIMIT 1" |
| 161 | 161 | )); |
| 162 | 162 | if (!$new_uotd_uid) { |
| 163 | - // Can't find a user with a profile; remove constraints on the pool |
|
| 164 | - if ($never_been_picked) { |
|
| 163 | + // Can't find a user with a profile; remove constraints on the pool |
|
| 164 | + if ($never_been_picked) { |
|
| 165 | 165 | // Allow users who have been previously selected |
| 166 | 166 | $never_been_picked = FALSE; |
| 167 | - } |
|
| 168 | - elseif ($active_users) { |
|
| 167 | + } |
|
| 168 | + elseif ($active_users) { |
|
| 169 | 169 | // Allow users who are not even active (getting desperate) |
| 170 | 170 | $active_users = FALSE; |
| 171 | - } |
|
| 172 | - else { |
|
| 171 | + } |
|
| 172 | + else { |
|
| 173 | 173 | // Process failed... |
| 174 | 174 | return FALSE; |
| 175 | - } |
|
| 175 | + } |
|
| 176 | 176 | } |
| 177 | - } |
|
| 178 | - $uotd = user_load($new_uotd_uid); |
|
| 179 | - if ($uotd->uid) { |
|
| 177 | + } |
|
| 178 | + $uotd = user_load($new_uotd_uid); |
|
| 179 | + if ($uotd->uid) { |
|
| 180 | 180 | db_query(" |
| 181 | 181 | UPDATE {boincuser} |
| 182 | 182 | SET uotd_time = '%d' |
| 183 | 183 | WHERE uid = '%d'", |
| 184 | - time(), $uotd->uid |
|
| 184 | + time(), $uotd->uid |
|
| 185 | 185 | ); |
| 186 | - } |
|
| 187 | - return $uotd; |
|
| 186 | + } |
|
| 187 | + return $uotd; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | 191 | * Determine the first unique name from a given base |
| 192 | 192 | */ |
| 193 | 193 | function find_unique_name($requested_name) { |
| 194 | - if (!$requested_name) { |
|
| 194 | + if (!$requested_name) { |
|
| 195 | 195 | // If the name is empty, set it |
| 196 | 196 | $requested_name = 'anonymous'; |
| 197 | - } |
|
| 198 | - $same_name_tally = 1; |
|
| 199 | - $cleaned_name = preg_replace('/[^a-zA-Z0-9_ \.-]/s', '_', $requested_name); |
|
| 200 | - $name_length = strlen($cleaned_name); |
|
| 201 | - if ($name_length > 56) { |
|
| 197 | + } |
|
| 198 | + $same_name_tally = 1; |
|
| 199 | + $cleaned_name = preg_replace('/[^a-zA-Z0-9_ \.-]/s', '_', $requested_name); |
|
| 200 | + $name_length = strlen($cleaned_name); |
|
| 201 | + if ($name_length > 56) { |
|
| 202 | 202 | // Name is limited to 60 characters, but we want to leave space to add a |
| 203 | 203 | // tally if needed (for users with duplicate names); Limit to 56 chars and |
| 204 | 204 | // replace the middle of the string with "..." if too long |
| 205 | 205 | $cleaned_name = substr_replace($cleaned_name, '...', 28, ($name_length-56)+3); |
| 206 | - } |
|
| 207 | - $unique_name = $cleaned_name; |
|
| 208 | - while (db_result(db_query("SELECT uid FROM {users} WHERE name = '{$unique_name}' LIMIT 1"))) { |
|
| 206 | + } |
|
| 207 | + $unique_name = $cleaned_name; |
|
| 208 | + while (db_result(db_query("SELECT uid FROM {users} WHERE name = '{$unique_name}' LIMIT 1"))) { |
|
| 209 | 209 | $same_name_tally++; |
| 210 | 210 | $unique_name = "{$cleaned_name}_{$same_name_tally}"; |
| 211 | - } |
|
| 212 | - return $unique_name; |
|
| 211 | + } |
|
| 212 | + return $unique_name; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -221,17 +221,17 @@ discard block |
||
| 221 | 221 | * Require BOINC library |
| 222 | 222 | */ |
| 223 | 223 | function require_boinc($libraries) { |
| 224 | - if ($include_dir = boinc_get_path('html_inc')) { |
|
| 224 | + if ($include_dir = boinc_get_path('html_inc')) { |
|
| 225 | 225 | $working_dir = getcwd(); |
| 226 | 226 | chdir($include_dir); |
| 227 | 227 | if (!is_array($libraries)) { |
| 228 | - $libraries = array($libraries); |
|
| 228 | + $libraries = array($libraries); |
|
| 229 | 229 | } |
| 230 | 230 | foreach ($libraries as $library) { |
| 231 | - require_once("{$library}.inc"); |
|
| 231 | + require_once("{$library}.inc"); |
|
| 232 | 232 | } |
| 233 | 233 | chdir($working_dir); |
| 234 | - } |
|
| 234 | + } |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * The path from the BOINC html root must be included (e.g. user/file.php) |
| 240 | 240 | */ |
| 241 | 241 | function include_boinc($file) { |
| 242 | - if ($include_dir = boinc_get_path()) { |
|
| 242 | + if ($include_dir = boinc_get_path()) { |
|
| 243 | 243 | $include_dir .= '/html'; |
| 244 | 244 | $workingDir = getcwd(); |
| 245 | 245 | $path = dirname($file); |
@@ -247,84 +247,84 @@ discard block |
||
| 247 | 247 | chdir("{$include_dir}/{$path}"); |
| 248 | 248 | include($file); |
| 249 | 249 | chdir($workingDir); |
| 250 | - } |
|
| 250 | + } |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
| 254 | 254 | * Get the BOINC include path |
| 255 | 255 | */ |
| 256 | 256 | function boinc_get_path($type = 'root') { |
| 257 | - $dir = "boinc_{$type}_dir"; |
|
| 258 | - if ($include_dir = variable_get("boinc_{$type}_dir", '')) { |
|
| 257 | + $dir = "boinc_{$type}_dir"; |
|
| 258 | + if ($include_dir = variable_get("boinc_{$type}_dir", '')) { |
|
| 259 | 259 | return $include_dir; |
| 260 | - } |
|
| 261 | - else { |
|
| 260 | + } |
|
| 261 | + else { |
|
| 262 | 262 | // Don't show errors on blacklisted pages |
| 263 | 263 | $page_blacklist = array( |
| 264 | - 'admin/boinc/environment' |
|
| 264 | + 'admin/boinc/environment' |
|
| 265 | 265 | ); |
| 266 | 266 | if (!in_array($_GET['q'], $page_blacklist)) { |
| 267 | - watchdog('boincuser', 'The BOINC environment is not configured. Please |
|
| 267 | + watchdog('boincuser', 'The BOINC environment is not configured. Please |
|
| 268 | 268 | !configure_it', array('!configure_it' => l(t('configure it now'), |
| 269 | 269 | 'admin/boinc/environment')), WATCHDOG_WARNING); |
| 270 | - if (user_access('administer site configuration')) { |
|
| 270 | + if (user_access('administer site configuration')) { |
|
| 271 | 271 | drupal_set_message(t('The BOINC environment is not configured. Please |
| 272 | 272 | !configure_it', array('!configure_it' => l(t('configure it now'), |
| 273 | 273 | 'admin/boinc/environment'))), 'warning', FALSE); |
| 274 | - } |
|
| 275 | - else { |
|
| 274 | + } |
|
| 275 | + else { |
|
| 276 | 276 | drupal_set_message(t('There is a problem with the site. Please contact |
| 277 | 277 | the system administrator.'), 'error', FALSE); |
| 278 | - } |
|
| 279 | - // Redirect home to display the error message and avoid fatal errors |
|
| 280 | - // (unless on a blacklisted page) |
|
| 281 | - $redirect_blacklist = array( |
|
| 278 | + } |
|
| 279 | + // Redirect home to display the error message and avoid fatal errors |
|
| 280 | + // (unless on a blacklisted page) |
|
| 281 | + $redirect_blacklist = array( |
|
| 282 | 282 | 'admin/settings/performance', |
| 283 | 283 | 'admin/boinc/environment', |
| 284 | 284 | 'home', |
| 285 | 285 | '' |
| 286 | - ); |
|
| 287 | - if (!in_array($_GET['q'], $redirect_blacklist)) { |
|
| 286 | + ); |
|
| 287 | + if (!in_array($_GET['q'], $redirect_blacklist)) { |
|
| 288 | 288 | drupal_goto(''); |
| 289 | - } |
|
| 289 | + } |
|
| 290 | 290 | } |
| 291 | 291 | else { |
| 292 | - // Clear the messages on the environment config page |
|
| 293 | - drupal_get_messages(); |
|
| 292 | + // Clear the messages on the environment config page |
|
| 293 | + drupal_get_messages(); |
|
| 294 | 294 | } |
| 295 | - } |
|
| 296 | - return FALSE; |
|
| 295 | + } |
|
| 296 | + return FALSE; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
| 300 | 300 | * Get the configured scheduler tags |
| 301 | 301 | */ |
| 302 | 302 | function boinc_get_scheduler_tags() { |
| 303 | - // Don't generate messages for blacklisted pages |
|
| 304 | - $page_blacklist = array( |
|
| 303 | + // Don't generate messages for blacklisted pages |
|
| 304 | + $page_blacklist = array( |
|
| 305 | 305 | 'admin/boinc/environment', |
| 306 | 306 | 'admin/boinc/scheduler' |
| 307 | - ); |
|
| 308 | - if ($url_config = variable_get('boinc_scheduler_urls', '')) { |
|
| 307 | + ); |
|
| 308 | + if ($url_config = variable_get('boinc_scheduler_urls', '')) { |
|
| 309 | 309 | return explode("\r\n", $url_config); |
| 310 | - } |
|
| 311 | - elseif (!in_array($_GET['q'], $page_blacklist)) { |
|
| 310 | + } |
|
| 311 | + elseif (!in_array($_GET['q'], $page_blacklist)) { |
|
| 312 | 312 | watchdog('boincuser', 'The BOINC scheduling server settings are not yet |
| 313 | 313 | configured. Please !verify for the settings to become effective.', |
| 314 | - array('!verify' => l(t('verify the default values') . ' <strong>' . |
|
| 314 | + array('!verify' => l(t('verify the default values') . ' <strong>' . |
|
| 315 | 315 | t('and') . '</strong> ' . t('save the configuration'), |
| 316 | 316 | 'admin/boinc/scheduler', array('html' => TRUE)) |
| 317 | - ), WATCHDOG_WARNING); |
|
| 317 | + ), WATCHDOG_WARNING); |
|
| 318 | 318 | if (user_access('administer site configuration')) { |
| 319 | - drupal_set_message(t('The BOINC scheduling server settings are not yet |
|
| 319 | + drupal_set_message(t('The BOINC scheduling server settings are not yet |
|
| 320 | 320 | configured. Please !verify for the settings to become effective', |
| 321 | 321 | array('!verify' => l(t('verify the default values') . ' <strong>' . |
| 322 | - t('and') . '</strong> ' . t('save the configuration'), |
|
| 323 | - 'admin/boinc/scheduler', array('html' => TRUE)) |
|
| 322 | + t('and') . '</strong> ' . t('save the configuration'), |
|
| 323 | + 'admin/boinc/scheduler', array('html' => TRUE)) |
|
| 324 | 324 | )), 'warning', FALSE); |
| 325 | 325 | } |
| 326 | - } |
|
| 327 | - return array(); |
|
| 326 | + } |
|
| 327 | + return array(); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * |
@@ -336,41 +336,41 @@ discard block |
||
| 336 | 336 | * Determine if a BOINC ID matches the logged in user |
| 337 | 337 | */ |
| 338 | 338 | function is_current_boinc_user($boinc_id) { |
| 339 | - global $user; |
|
| 340 | - if (!$user->uid) { |
|
| 339 | + global $user; |
|
| 340 | + if (!$user->uid) { |
|
| 341 | 341 | return FALSE; |
| 342 | - } |
|
| 343 | - // boincuser_id is not stored in the global user, so load a new instance |
|
| 344 | - $drupuser = user_load($user->uid); |
|
| 345 | - return ($boinc_id == $drupuser->boincuser_id); |
|
| 342 | + } |
|
| 343 | + // boincuser_id is not stored in the global user, so load a new instance |
|
| 344 | + $drupuser = user_load($user->uid); |
|
| 345 | + return ($boinc_id == $drupuser->boincuser_id); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | /** |
| 349 | 349 | * Convert a BOINC ID to a Drupal ID |
| 350 | 350 | */ |
| 351 | 351 | function boincuser_lookup_uid($boinc_id) { |
| 352 | - $drupal_id = db_result(db_query("SELECT uid FROM {boincuser} WHERE boinc_id='%d'", $boinc_id)); |
|
| 353 | - return $drupal_id; |
|
| 352 | + $drupal_id = db_result(db_query("SELECT uid FROM {boincuser} WHERE boinc_id='%d'", $boinc_id)); |
|
| 353 | + return $drupal_id; |
|
| 354 | 354 | } |
| 355 | 355 | function get_drupal_id($boinc_id) { |
| 356 | - return boincuser_lookup_uid($boinc_id); |
|
| 356 | + return boincuser_lookup_uid($boinc_id); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
| 360 | 360 | * Get a BOINC user object |
| 361 | 361 | */ |
| 362 | 362 | function boincuser_load($user_id = NULL, $is_drupal_id = FALSE) { |
| 363 | - if (!$user_id) { |
|
| 363 | + if (!$user_id) { |
|
| 364 | 364 | global $user; |
| 365 | 365 | $user_id = $user->uid; |
| 366 | 366 | $is_drupal_id = TRUE; |
| 367 | - } |
|
| 368 | - if ($is_drupal_id) { |
|
| 367 | + } |
|
| 368 | + if ($is_drupal_id) { |
|
| 369 | 369 | $account = user_load($user_id); |
| 370 | 370 | $user_id = $account->boincuser_id; |
| 371 | - } |
|
| 372 | - require_boinc('boinc_db'); |
|
| 373 | - return BoincUser::lookup_id($user_id); |
|
| 371 | + } |
|
| 372 | + require_boinc('boinc_db'); |
|
| 373 | + return BoincUser::lookup_id($user_id); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | |
@@ -382,8 +382,8 @@ discard block |
||
| 382 | 382 | * Wrapper for boinc_version() function |
| 383 | 383 | */ |
| 384 | 384 | function get_boinc_version($x) { |
| 385 | - require_boinc('host'); |
|
| 386 | - return function_exists('boinc_version') ? boinc_version($x) : 'err!'; |
|
| 385 | + require_boinc('host'); |
|
| 386 | + return function_exists('boinc_version') ? boinc_version($x) : 'err!'; |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | |
@@ -392,13 +392,13 @@ discard block |
||
| 392 | 392 | * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 393 | 393 | |
| 394 | 394 | /** |
| 395 | - * Generate the friend block header |
|
| 396 | - */ |
|
| 395 | + * Generate the friend block header |
|
| 396 | + */ |
|
| 397 | 397 | function boincuser_views_friends_block_header($context = null) { |
| 398 | - // Get the friend count for the user being viewed |
|
| 399 | - $view = views_get_current_view(); |
|
| 400 | - $account_id = $view->args[0]; |
|
| 401 | - $friend_count = flag_friend_get_friend_count($account_id); |
|
| 402 | - return '<h2 class="pane-title">' . bts('Friends (@count)', |
|
| 398 | + // Get the friend count for the user being viewed |
|
| 399 | + $view = views_get_current_view(); |
|
| 400 | + $account_id = $view->args[0]; |
|
| 401 | + $friend_count = flag_friend_get_friend_count($account_id); |
|
| 402 | + return '<h2 class="pane-title">' . bts('Friends (@count)', |
|
| 403 | 403 | array('@count' => $friend_count)) . '</h2>'; |
| 404 | 404 | } |
@@ -154,8 +154,8 @@ discard block |
||
| 154 | 154 | WHERE n.type = 'profile' |
| 155 | 155 | AND n.status = 1 |
| 156 | 156 | AND n.moderate = 0 |
| 157 | - " . ($never_been_picked ? " AND bu.uotd_time = 0 " : '') . " |
|
| 158 | - " . ($active_users ? " AND bu.boinc_id IN ({$active_users}) " : '') . " |
|
| 157 | + " . ($never_been_picked ? " AND bu.uotd_time = 0 " : '')." |
|
| 158 | + " . ($active_users ? " AND bu.boinc_id IN ({$active_users}) " : '')." |
|
| 159 | 159 | ORDER BY RAND() |
| 160 | 160 | LIMIT 1" |
| 161 | 161 | )); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | // Name is limited to 60 characters, but we want to leave space to add a |
| 203 | 203 | // tally if needed (for users with duplicate names); Limit to 56 chars and |
| 204 | 204 | // replace the middle of the string with "..." if too long |
| 205 | - $cleaned_name = substr_replace($cleaned_name, '...', 28, ($name_length-56)+3); |
|
| 205 | + $cleaned_name = substr_replace($cleaned_name, '...', 28, ($name_length - 56) + 3); |
|
| 206 | 206 | } |
| 207 | 207 | $unique_name = $cleaned_name; |
| 208 | 208 | while (db_result(db_query("SELECT uid FROM {users} WHERE name = '{$unique_name}' LIMIT 1"))) { |
@@ -311,15 +311,15 @@ discard block |
||
| 311 | 311 | elseif (!in_array($_GET['q'], $page_blacklist)) { |
| 312 | 312 | watchdog('boincuser', 'The BOINC scheduling server settings are not yet |
| 313 | 313 | configured. Please !verify for the settings to become effective.', |
| 314 | - array('!verify' => l(t('verify the default values') . ' <strong>' . |
|
| 315 | - t('and') . '</strong> ' . t('save the configuration'), |
|
| 314 | + array('!verify' => l(t('verify the default values').' <strong>'. |
|
| 315 | + t('and').'</strong> '.t('save the configuration'), |
|
| 316 | 316 | 'admin/boinc/scheduler', array('html' => TRUE)) |
| 317 | 317 | ), WATCHDOG_WARNING); |
| 318 | 318 | if (user_access('administer site configuration')) { |
| 319 | 319 | drupal_set_message(t('The BOINC scheduling server settings are not yet |
| 320 | 320 | configured. Please !verify for the settings to become effective', |
| 321 | - array('!verify' => l(t('verify the default values') . ' <strong>' . |
|
| 322 | - t('and') . '</strong> ' . t('save the configuration'), |
|
| 321 | + array('!verify' => l(t('verify the default values').' <strong>'. |
|
| 322 | + t('and').'</strong> '.t('save the configuration'), |
|
| 323 | 323 | 'admin/boinc/scheduler', array('html' => TRUE)) |
| 324 | 324 | )), 'warning', FALSE); |
| 325 | 325 | } |
@@ -399,6 +399,6 @@ discard block |
||
| 399 | 399 | $view = views_get_current_view(); |
| 400 | 400 | $account_id = $view->args[0]; |
| 401 | 401 | $friend_count = flag_friend_get_friend_count($account_id); |
| 402 | - return '<h2 class="pane-title">' . bts('Friends (@count)', |
|
| 403 | - array('@count' => $friend_count)) . '</h2>'; |
|
| 402 | + return '<h2 class="pane-title">'.bts('Friends (@count)', |
|
| 403 | + array('@count' => $friend_count)).'</h2>'; |
|
| 404 | 404 | } |
@@ -71,16 +71,14 @@ discard block |
||
| 71 | 71 | unset($account->roles[$unrestricted_role]); |
| 72 | 72 | } |
| 73 | 73 | user_save($account, array('roles' => $account->roles)); |
| 74 | - } |
|
| 75 | - elseif ($account->boincuser_total_credit >= $min_credit_to_post) { |
|
| 74 | + } elseif ($account->boincuser_total_credit >= $min_credit_to_post) { |
|
| 76 | 75 | if (!isset($account->roles[$unrestricted_role])) { |
| 77 | 76 | // This user is now above the credit threshold and is allowed full |
| 78 | 77 | // privileges |
| 79 | 78 | $account->roles[$unrestricted_role] = 'verified contributor'; |
| 80 | 79 | user_save($account, array('roles' => $account->roles)); |
| 81 | 80 | } |
| 82 | - } |
|
| 83 | - else { |
|
| 81 | + } else { |
|
| 84 | 82 | drupal_set_message(bts( |
| 85 | 83 | 'You must earn @count more credits to be able to post comments on this site.', |
| 86 | 84 | array('@count' => $min_credit_to_post - $account->boincuser_total_credit) |
@@ -164,12 +162,10 @@ discard block |
||
| 164 | 162 | if ($never_been_picked) { |
| 165 | 163 | // Allow users who have been previously selected |
| 166 | 164 | $never_been_picked = FALSE; |
| 167 | - } |
|
| 168 | - elseif ($active_users) { |
|
| 165 | + } elseif ($active_users) { |
|
| 169 | 166 | // Allow users who are not even active (getting desperate) |
| 170 | 167 | $active_users = FALSE; |
| 171 | - } |
|
| 172 | - else { |
|
| 168 | + } else { |
|
| 173 | 169 | // Process failed... |
| 174 | 170 | return FALSE; |
| 175 | 171 | } |
@@ -257,8 +253,7 @@ discard block |
||
| 257 | 253 | $dir = "boinc_{$type}_dir"; |
| 258 | 254 | if ($include_dir = variable_get("boinc_{$type}_dir", '')) { |
| 259 | 255 | return $include_dir; |
| 260 | - } |
|
| 261 | - else { |
|
| 256 | + } else { |
|
| 262 | 257 | // Don't show errors on blacklisted pages |
| 263 | 258 | $page_blacklist = array( |
| 264 | 259 | 'admin/boinc/environment' |
@@ -271,8 +266,7 @@ discard block |
||
| 271 | 266 | drupal_set_message(t('The BOINC environment is not configured. Please |
| 272 | 267 | !configure_it', array('!configure_it' => l(t('configure it now'), |
| 273 | 268 | 'admin/boinc/environment'))), 'warning', FALSE); |
| 274 | - } |
|
| 275 | - else { |
|
| 269 | + } else { |
|
| 276 | 270 | drupal_set_message(t('There is a problem with the site. Please contact |
| 277 | 271 | the system administrator.'), 'error', FALSE); |
| 278 | 272 | } |
@@ -287,8 +281,7 @@ discard block |
||
| 287 | 281 | if (!in_array($_GET['q'], $redirect_blacklist)) { |
| 288 | 282 | drupal_goto(''); |
| 289 | 283 | } |
| 290 | - } |
|
| 291 | - else { |
|
| 284 | + } else { |
|
| 292 | 285 | // Clear the messages on the environment config page |
| 293 | 286 | drupal_get_messages(); |
| 294 | 287 | } |
@@ -307,8 +300,7 @@ discard block |
||
| 307 | 300 | ); |
| 308 | 301 | if ($url_config = variable_get('boinc_scheduler_urls', '')) { |
| 309 | 302 | return explode("\r\n", $url_config); |
| 310 | - } |
|
| 311 | - elseif (!in_array($_GET['q'], $page_blacklist)) { |
|
| 303 | + } elseif (!in_array($_GET['q'], $page_blacklist)) { |
|
| 312 | 304 | watchdog('boincuser', 'The BOINC scheduling server settings are not yet |
| 313 | 305 | configured. Please !verify for the settings to become effective.', |
| 314 | 306 | array('!verify' => l(t('verify the default values') . ' <strong>' . |
@@ -13,6 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * The structure of the general preferences form |
| 16 | + * @param string $prefs_preset |
|
| 16 | 17 | */ |
| 17 | 18 | function boincwork_generalprefs_form(&$form_state, $venue, $prefs_preset = null, $advanced = FALSE) { |
| 18 | 19 | $form = array(); |
@@ -754,6 +755,7 @@ discard block |
||
| 754 | 755 | |
| 755 | 756 | /** |
| 756 | 757 | * Perform the database updates to merge the old host into the new host |
| 758 | + * @param string $message |
|
| 757 | 759 | */ |
| 758 | 760 | function boincwork_host_merge($old_host, $new_host, &$message = NULL) { |
| 759 | 761 | // Decay the average credit of the two hosts |
@@ -15,16 +15,16 @@ discard block |
||
| 15 | 15 | * The structure of the general preferences form |
| 16 | 16 | */ |
| 17 | 17 | function boincwork_generalprefs_form(&$form_state, $venue, $prefs_preset = null, $advanced = FALSE) { |
| 18 | - $form = array(); |
|
| 19 | - $prefs = null; |
|
| 20 | - $established = TRUE; |
|
| 18 | + $form = array(); |
|
| 19 | + $prefs = null; |
|
| 20 | + $established = TRUE; |
|
| 21 | 21 | |
| 22 | - // Enable AHAH form support for dynamically updating content based on preset |
|
| 23 | - ahah_helper_register($form, $form_state); |
|
| 22 | + // Enable AHAH form support for dynamically updating content based on preset |
|
| 23 | + ahah_helper_register($form, $form_state); |
|
| 24 | 24 | |
| 25 | - if (!$prefs_preset) { |
|
| 25 | + if (!$prefs_preset) { |
|
| 26 | 26 | if (isset($form_state['storage']['prefs']['preset'])) { |
| 27 | - $prefs_preset = $form_state['storage']['prefs']['preset']; |
|
| 27 | + $prefs_preset = $form_state['storage']['prefs']['preset']; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // Load preferences from BOINC account |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | // Take note if this is not an established preference set on the account |
| 34 | 34 | if (isset($prefs['@attributes']['cleared'])) { |
| 35 | - $established = FALSE; |
|
| 35 | + $established = FALSE; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // Determine if a preset is selected or if these are custom settings |
@@ -47,45 +47,45 @@ discard block |
||
| 47 | 47 | $prefs_preset = $prefs['preset']['@value']; |
| 48 | 48 | } |
| 49 | 49 | }// if !$prefs_preset |
| 50 | - } |
|
| 51 | - // Extract mod_time tag if present, because it will be erased with |
|
| 52 | - // boincwork_get_preset_prefs() below. |
|
| 53 | - $mod_time = null; |
|
| 54 | - if (isset($prefs['mod_time']['@value'])) { |
|
| 55 | - $mod_time = $prefs['mod_time']['@value']; |
|
| 56 | - } |
|
| 50 | + } |
|
| 51 | + // Extract mod_time tag if present, because it will be erased with |
|
| 52 | + // boincwork_get_preset_prefs() below. |
|
| 53 | + $mod_time = null; |
|
| 54 | + if (isset($prefs['mod_time']['@value'])) { |
|
| 55 | + $mod_time = $prefs['mod_time']['@value']; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - if (isset($form_state['storage']['wip'])) { |
|
| 59 | - switch ($prefs_preset) { |
|
| 60 | - case 'standard': |
|
| 58 | + if (isset($form_state['storage']['wip'])) { |
|
| 59 | + switch ($prefs_preset) { |
|
| 60 | + case 'standard': |
|
| 61 | 61 | case 'maximum': |
| 62 | 62 | case 'green': |
| 63 | 63 | case 'minimum': |
| 64 | 64 | $prefs = boincwork_get_preset_prefs($prefs_preset); |
| 65 | - break; |
|
| 66 | - case 'custom': |
|
| 65 | + break; |
|
| 66 | + case 'custom': |
|
| 67 | 67 | default: |
| 68 | 68 | // Just keeps prefs as they are |
| 69 | 69 | unset($prefs['preset']); |
| 70 | - break; |
|
| 71 | - }// switch |
|
| 72 | - } else { |
|
| 73 | - $form_state['storage']['wip'] = TRUE; |
|
| 74 | - if ( !in_array($prefs_preset, array('standard','maximum','green','minimum','custom')) ) { |
|
| 75 | - if ($established) { |
|
| 76 | - $prefs_preset = 'custom'; |
|
| 77 | - } else { |
|
| 78 | - $prefs_preset = 'standard'; |
|
| 79 | - $prefs = boincwork_get_preset_prefs($prefs_preset); |
|
| 80 | - }// if $established |
|
| 81 | - }// if $prefs_preset |
|
| 82 | - }// if WIP |
|
| 83 | - |
|
| 84 | - // This set of preferences is used in the form if no preferences |
|
| 85 | - // have been set above, in variable $prefs. |
|
| 86 | - require_boinc(array('db', 'prefs')); |
|
| 87 | - $disk_space_config = get_disk_space_config(); |
|
| 88 | - $default = array( |
|
| 70 | + break; |
|
| 71 | + }// switch |
|
| 72 | + } else { |
|
| 73 | + $form_state['storage']['wip'] = TRUE; |
|
| 74 | + if ( !in_array($prefs_preset, array('standard','maximum','green','minimum','custom')) ) { |
|
| 75 | + if ($established) { |
|
| 76 | + $prefs_preset = 'custom'; |
|
| 77 | + } else { |
|
| 78 | + $prefs_preset = 'standard'; |
|
| 79 | + $prefs = boincwork_get_preset_prefs($prefs_preset); |
|
| 80 | + }// if $established |
|
| 81 | + }// if $prefs_preset |
|
| 82 | + }// if WIP |
|
| 83 | + |
|
| 84 | + // This set of preferences is used in the form if no preferences |
|
| 85 | + // have been set above, in variable $prefs. |
|
| 86 | + require_boinc(array('db', 'prefs')); |
|
| 87 | + $disk_space_config = get_disk_space_config(); |
|
| 88 | + $default = array( |
|
| 89 | 89 | 'preset' => $prefs_preset, |
| 90 | 90 | // Processing... |
| 91 | 91 | 'run_on_batteries' => 0, |
@@ -120,385 +120,385 @@ discard block |
||
| 120 | 120 | 'daily_xfer_limit_mb' => 0, |
| 121 | 121 | 'daily_xfer_period_days' => 0, |
| 122 | 122 | 'dont_verify_images' => 0 |
| 123 | - ); |
|
| 124 | - foreach ($default as $name => $value) { |
|
| 123 | + ); |
|
| 124 | + foreach ($default as $name => $value) { |
|
| 125 | 125 | if (isset($prefs[$name])) { |
| 126 | - if (is_array($prefs[$name])) { |
|
| 126 | + if (is_array($prefs[$name])) { |
|
| 127 | 127 | if (isset($prefs[$name]['@value'])) { |
| 128 | - $default[$name] = $prefs[$name]['@value']; |
|
| 128 | + $default[$name] = $prefs[$name]['@value']; |
|
| 129 | 129 | } |
| 130 | - } |
|
| 131 | - else { |
|
| 130 | + } |
|
| 131 | + else { |
|
| 132 | 132 | $default[$name] = $prefs[$name]; |
| 133 | - } |
|
| 133 | + } |
|
| 134 | + } |
|
| 134 | 135 | } |
| 135 | - } |
|
| 136 | 136 | |
| 137 | - // Standard option sets |
|
| 138 | - $form['boolean_options'] = array( |
|
| 137 | + // Standard option sets |
|
| 138 | + $form['boolean_options'] = array( |
|
| 139 | 139 | '#type' => 'value', |
| 140 | 140 | '#value' => array(1 => bts('yes'), 0 => bts('no')) |
| 141 | - ); |
|
| 142 | - $form['hour_options'] = array( |
|
| 141 | + ); |
|
| 142 | + $form['hour_options'] = array( |
|
| 143 | 143 | '#type' => 'value', |
| 144 | 144 | '#value' => array('0:00','1:00','2:00','3:00','4:00', |
| 145 | - '5:00','6:00','7:00','8:00','9:00','10:00','11:00', |
|
| 146 | - '12:00','13:00','14:00','15:00','16:00','17:00', |
|
| 147 | - '18:00','19:00','20:00','21:00','22:00','23:00') |
|
| 148 | - ); |
|
| 149 | - |
|
| 150 | - // Identify preference sets that are established to distinguish what has been |
|
| 151 | - // saved to the database from what is just showing default values |
|
| 152 | - $form['#established'] = $established; |
|
| 145 | + '5:00','6:00','7:00','8:00','9:00','10:00','11:00', |
|
| 146 | + '12:00','13:00','14:00','15:00','16:00','17:00', |
|
| 147 | + '18:00','19:00','20:00','21:00','22:00','23:00') |
|
| 148 | + ); |
|
| 149 | + |
|
| 150 | + // Identify preference sets that are established to distinguish what has been |
|
| 151 | + // saved to the database from what is just showing default values |
|
| 152 | + $form['#established'] = $established; |
|
| 153 | 153 | |
| 154 | - // Set up the preference container for AHAH |
|
| 155 | - $form['prefs'] = array( |
|
| 154 | + // Set up the preference container for AHAH |
|
| 155 | + $form['prefs'] = array( |
|
| 156 | 156 | '#title' => '', |
| 157 | 157 | '#type' => 'fieldset', |
| 158 | 158 | '#prefix' => '<div id="prefs-wrapper">', // This is our wrapper div. |
| 159 | 159 | '#attributes' => array('class' => 'ahah-container'), |
| 160 | 160 | '#suffix' => '</div>', |
| 161 | 161 | '#tree' => TRUE |
| 162 | - ); |
|
| 163 | - //$form['prefs']['debug'] = array('#value' => '<pre>' . print_r($form_state, true) . '</pre>'); |
|
| 162 | + ); |
|
| 163 | + //$form['prefs']['debug'] = array('#value' => '<pre>' . print_r($form_state, true) . '</pre>'); |
|
| 164 | 164 | |
| 165 | - // Hidden elements |
|
| 166 | - $form['prefs']['modified'] = array( |
|
| 165 | + // Hidden elements |
|
| 166 | + $form['prefs']['modified'] = array( |
|
| 167 | 167 | '#type' => 'hidden', |
| 168 | 168 | '#value' => $mod_time |
| 169 | - ); |
|
| 170 | - $form['prefs']['venue'] = array( |
|
| 169 | + ); |
|
| 170 | + $form['prefs']['venue'] = array( |
|
| 171 | 171 | '#type' => 'hidden', |
| 172 | 172 | '#value' => $venue |
| 173 | - ); |
|
| 173 | + ); |
|
| 174 | 174 | |
| 175 | - $form['prefs']['separator_top'] = array( |
|
| 175 | + $form['prefs']['separator_top'] = array( |
|
| 176 | 176 | '#value' => '<div class="separator"></div>' |
| 177 | - ); |
|
| 177 | + ); |
|
| 178 | 178 | |
| 179 | - // Simplified selectors |
|
| 180 | - $form['prefs']['preset'] = array( |
|
| 179 | + // Simplified selectors |
|
| 180 | + $form['prefs']['preset'] = array( |
|
| 181 | 181 | '#title' => bts('Presets'), |
| 182 | 182 | '#type' => 'radios', |
| 183 | 183 | '#description' => ' ', |
| 184 | 184 | '#options' => array( |
| 185 | - 'standard' => bts('Standard'), |
|
| 186 | - 'maximum' => bts('Maximum'), |
|
| 187 | - 'green' => bts('Green'), |
|
| 188 | - 'minimum' => bts('Minimum'), |
|
| 189 | - 'custom' => bts('Custom') |
|
| 185 | + 'standard' => bts('Standard'), |
|
| 186 | + 'maximum' => bts('Maximum'), |
|
| 187 | + 'green' => bts('Green'), |
|
| 188 | + 'minimum' => bts('Minimum'), |
|
| 189 | + 'custom' => bts('Custom') |
|
| 190 | 190 | ), |
| 191 | 191 | '#prefix' => '<div class="simple-form-controls">', |
| 192 | 192 | '#suffix' => '</div>', |
| 193 | 193 | '#default_value' => $default['preset'], |
| 194 | 194 | '#ahah' => array( |
| 195 | - 'event' => 'change', |
|
| 196 | - 'path' => ahah_helper_path(array('prefs')), |
|
| 197 | - 'wrapper' => 'prefs-wrapper' |
|
| 195 | + 'event' => 'change', |
|
| 196 | + 'path' => ahah_helper_path(array('prefs')), |
|
| 197 | + 'wrapper' => 'prefs-wrapper' |
|
| 198 | 198 | ) |
| 199 | - ); |
|
| 200 | - $form['prefs']['select preset'] = array( |
|
| 199 | + ); |
|
| 200 | + $form['prefs']['select preset'] = array( |
|
| 201 | 201 | '#type' => 'submit', |
| 202 | 202 | '#value' => bts('Update preset'), |
| 203 | 203 | '#submit' => array('ahah_helper_generic_submit'), |
| 204 | 204 | // The 'no-js' class only displays this button if javascript is disabled |
| 205 | 205 | '#attributes' => array('class' => 'no-js'), |
| 206 | - ); |
|
| 206 | + ); |
|
| 207 | 207 | |
| 208 | - // Advanced preferences |
|
| 209 | - $form['prefs']['advanced'] = array( |
|
| 208 | + // Advanced preferences |
|
| 209 | + $form['prefs']['advanced'] = array( |
|
| 210 | 210 | '#title' => bts('Advanced settings'), |
| 211 | 211 | '#type' => 'fieldset', |
| 212 | 212 | '#description' => '', |
| 213 | 213 | '#collapsible' => TRUE, |
| 214 | 214 | '#collapsed' => !$advanced, |
| 215 | 215 | '#attributes' => array('class' => 'advanced-settings'), |
| 216 | - ); |
|
| 216 | + ); |
|
| 217 | 217 | |
| 218 | - // Processing preferences |
|
| 218 | + // Processing preferences |
|
| 219 | 219 | |
| 220 | - $form['prefs']['advanced']['anchor'] = array( |
|
| 220 | + $form['prefs']['advanced']['anchor'] = array( |
|
| 221 | 221 | '#value' => '<a name="advanced"></a>' |
| 222 | - ); |
|
| 222 | + ); |
|
| 223 | 223 | |
| 224 | - $form['prefs']['advanced']['separator_top'] = array( |
|
| 224 | + $form['prefs']['advanced']['separator_top'] = array( |
|
| 225 | 225 | '#value' => '<div class="separator"></div>' |
| 226 | - ); |
|
| 226 | + ); |
|
| 227 | 227 | |
| 228 | - $form['prefs']['advanced']['processor'] = array( |
|
| 228 | + $form['prefs']['advanced']['processor'] = array( |
|
| 229 | 229 | '#title' => bts('Processor usage'), |
| 230 | 230 | '#type' => 'fieldset', |
| 231 | 231 | '#description' => '', |
| 232 | 232 | '#collapsible' => FALSE, |
| 233 | 233 | '#collapsed' => FALSE |
| 234 | - ); |
|
| 235 | - $form['prefs']['advanced']['processor']['run_on_batteries'] = array( |
|
| 234 | + ); |
|
| 235 | + $form['prefs']['advanced']['processor']['run_on_batteries'] = array( |
|
| 236 | 236 | '#title' => bts('Suspend when computer is on battery?'), |
| 237 | 237 | '#type' => 'radios', |
| 238 | 238 | '#description' => bts('Suspends computing on portables when running on battery power.'), |
| 239 | 239 | '#options' => $form['boolean_options']['#value'], |
| 240 | 240 | '#attributes' => array('class' => 'fancy'), |
| 241 | 241 | '#default_value' => ($default['run_on_batteries']) ? 0 : 1 // intentional inversion of setting |
| 242 | - ); |
|
| 243 | - $form['prefs']['advanced']['processor']['run_if_user_active'] = array( |
|
| 242 | + ); |
|
| 243 | + $form['prefs']['advanced']['processor']['run_if_user_active'] = array( |
|
| 244 | 244 | '#title' => bts('Suspend when computer is in use?'), |
| 245 | 245 | '#type' => 'radios', |
| 246 | 246 | '#description' => bts("Suspends computing and file transfers when you're using the computer."), |
| 247 | 247 | '#options' => $form['boolean_options']['#value'], |
| 248 | 248 | '#attributes' => array('class' => 'fancy'), |
| 249 | 249 | '#default_value' => ($default['run_if_user_active']) ? 0 : 1 // intentional inversion of setting |
| 250 | - ); |
|
| 251 | - $form['prefs']['advanced']['processor']['run_gpu_if_user_active'] = array( |
|
| 250 | + ); |
|
| 251 | + $form['prefs']['advanced']['processor']['run_gpu_if_user_active'] = array( |
|
| 252 | 252 | '#title' => bts('Suspend GPU computing when computer is in use?'), |
| 253 | 253 | '#type' => 'radios', |
| 254 | 254 | '#description' => bts("Suspends GPU computing when you're using the computer."), |
| 255 | 255 | '#options' => $form['boolean_options']['#value'], |
| 256 | 256 | '#attributes' => array('class' => 'fancy'), |
| 257 | 257 | '#default_value' => ($default['run_gpu_if_user_active']) ? 0 : 1 // intentional inversion of setting |
| 258 | - ); |
|
| 259 | - $form['prefs']['advanced']['processor']['idle_time_to_run'] = array( |
|
| 258 | + ); |
|
| 259 | + $form['prefs']['advanced']['processor']['idle_time_to_run'] = array( |
|
| 260 | 260 | '#title' => bts('"In use" means mouse/keyboard input in last'), |
| 261 | 261 | '#type' => 'textfield', |
| 262 | 262 | '#field_suffix' => bts('minutes'), |
| 263 | 263 | '#default_value' => $default['idle_time_to_run'], |
| 264 | 264 | '#size' => 1, |
| 265 | 265 | '#description' => bts('This determines when the computer is considered "in use".') |
| 266 | - ); |
|
| 267 | - $form['prefs']['advanced']['processor']['suspend_if_no_recent_input'] = array( |
|
| 266 | + ); |
|
| 267 | + $form['prefs']['advanced']['processor']['suspend_if_no_recent_input'] = array( |
|
| 268 | 268 | '#title' => bts('Suspend when no mouse/keyboard input in last'), |
| 269 | 269 | '#type' => 'textfield', |
| 270 | 270 | '#field_suffix' => bts('minutes'), |
| 271 | 271 | '#default_value' => $default['suspend_if_no_recent_input'], |
| 272 | 272 | '#size' => 1, |
| 273 | 273 | '#description' => bts('This allows some computers to enter low-power mode when not in use.') |
| 274 | - ); |
|
| 275 | - $form['prefs']['advanced']['processor']['suspend_cpu_usage'] = array( |
|
| 274 | + ); |
|
| 275 | + $form['prefs']['advanced']['processor']['suspend_cpu_usage'] = array( |
|
| 276 | 276 | '#title' => bts('Suspend when non-BOINC CPU usage is above'), |
| 277 | 277 | '#type' => 'textfield', |
| 278 | 278 | '#field_suffix' => '%', |
| 279 | 279 | '#default_value' => $default['suspend_cpu_usage'], |
| 280 | 280 | '#size' => 1, |
| 281 | 281 | '#description' => bts('Suspend computing when your computer is busy running other programs.'), |
| 282 | - ); |
|
| 283 | - $form['prefs']['advanced']['processor']['hour_label'] = array( |
|
| 282 | + ); |
|
| 283 | + $form['prefs']['advanced']['processor']['hour_label'] = array( |
|
| 284 | 284 | '#value' => '<div class="form-item"><label>' . bts('Compute only between:') . '</label></div>' |
| 285 | - ); |
|
| 286 | - $form['prefs']['advanced']['processor']['start_hour'] = array( |
|
| 285 | + ); |
|
| 286 | + $form['prefs']['advanced']['processor']['start_hour'] = array( |
|
| 287 | 287 | '#type' => 'select', |
| 288 | 288 | '#options' => $form['hour_options']['#value'], |
| 289 | 289 | '#default_value' => $default['start_hour'] |
| 290 | - ); |
|
| 291 | - $form['prefs']['advanced']['processor']['hour_delimiter'] = array( |
|
| 290 | + ); |
|
| 291 | + $form['prefs']['advanced']['processor']['hour_delimiter'] = array( |
|
| 292 | 292 | '#value' => '<span>' . bts('and') . '</span>' |
| 293 | - ); |
|
| 294 | - $form['prefs']['advanced']['processor']['end_hour'] = array( |
|
| 293 | + ); |
|
| 294 | + $form['prefs']['advanced']['processor']['end_hour'] = array( |
|
| 295 | 295 | '#type' => 'select', |
| 296 | 296 | '#options' => $form['hour_options']['#value'], |
| 297 | 297 | '#default_value' => $default['end_hour'] |
| 298 | - ); |
|
| 299 | - $form['prefs']['advanced']['processor']['hour_description'] = array( |
|
| 298 | + ); |
|
| 299 | + $form['prefs']['advanced']['processor']['hour_description'] = array( |
|
| 300 | 300 | '#value' => '<div class="form-item slim"><div class="description">' . bts('Compute only during a particular period each day.') . '</div></div>' |
| 301 | - ); |
|
| 302 | - $form['prefs']['advanced']['processor']['leave_apps_in_memory'] = array( |
|
| 301 | + ); |
|
| 302 | + $form['prefs']['advanced']['processor']['leave_apps_in_memory'] = array( |
|
| 303 | 303 | '#title' => bts('Leave non-GPU tasks in memory while suspended?'), |
| 304 | 304 | '#type' => 'radios', |
| 305 | 305 | '#options' => $form['boolean_options']['#value'], |
| 306 | 306 | '#attributes' => array('class' => 'fancy'), |
| 307 | 307 | '#default_value' => $default['leave_apps_in_memory'], |
| 308 | 308 | '#description' => bts('If "Yes", suspended tasks stay in memory, and resume with no work lost. If "No", suspended tasks are removed from memory, and resume from their last checkpoint.') |
| 309 | - ); |
|
| 310 | - $form['prefs']['advanced']['processor']['cpu_scheduling_period_minutes'] = array( |
|
| 309 | + ); |
|
| 310 | + $form['prefs']['advanced']['processor']['cpu_scheduling_period_minutes'] = array( |
|
| 311 | 311 | '#title' => bts('Switch between tasks every'), |
| 312 | 312 | '#type' => 'textfield', |
| 313 | 313 | '#field_suffix' => bts('minutes'), |
| 314 | 314 | '#default_value' => $default['cpu_scheduling_period_minutes'], |
| 315 | 315 | '#size' => 1, |
| 316 | 316 | '#description' => bts('If you run several projects, BOINC may switch between them this often.') |
| 317 | - ); |
|
| 318 | - $form['prefs']['advanced']['processor']['max_ncpus_pct'] = array( |
|
| 317 | + ); |
|
| 318 | + $form['prefs']['advanced']['processor']['max_ncpus_pct'] = array( |
|
| 319 | 319 | '#title' => bts('Use at most'), |
| 320 | 320 | '#type' => 'textfield', |
| 321 | 321 | '#field_suffix' => bts('% of the processors'), |
| 322 | 322 | '#default_value' => $default['max_ncpus_pct'], |
| 323 | 323 | '#size' => 1, |
| 324 | 324 | '#description' => bts('Keep some CPUs free for other applications. Example: 75% means use 6 cores on an 8-core CPU.'), |
| 325 | - ); |
|
| 326 | - $form['prefs']['advanced']['processor']['cpu_usage_limit'] = array( |
|
| 325 | + ); |
|
| 326 | + $form['prefs']['advanced']['processor']['cpu_usage_limit'] = array( |
|
| 327 | 327 | '#title' => bts('Use at most'), |
| 328 | 328 | '#type' => 'textfield', |
| 329 | 329 | '#field_suffix' => bts('% of the CPU time'), |
| 330 | 330 | '#default_value' => $default['cpu_usage_limit'], |
| 331 | 331 | '#size' => 1, |
| 332 | 332 | '#description' => bts('Suspend/resume computing every few seconds to reduce CPU temperature and energy usage. Example: 75% means compute for 3 seconds, wait for 1 second, and repeat.') |
| 333 | - ); |
|
| 333 | + ); |
|
| 334 | 334 | |
| 335 | - // Disk and memory preferences |
|
| 336 | - $form['prefs']['advanced']['storage'] = array( |
|
| 335 | + // Disk and memory preferences |
|
| 336 | + $form['prefs']['advanced']['storage'] = array( |
|
| 337 | 337 | '#title' => bts('Disk and memory usage'), |
| 338 | 338 | '#type' => 'fieldset', |
| 339 | 339 | '#description' => '', |
| 340 | 340 | '#collapsible' => FALSE, |
| 341 | 341 | '#collapsed' => FALSE |
| 342 | - ); |
|
| 343 | - $form['prefs']['advanced']['storage']['disk_max_used_gb'] = array( |
|
| 342 | + ); |
|
| 343 | + $form['prefs']['advanced']['storage']['disk_max_used_gb'] = array( |
|
| 344 | 344 | '#title' => bts('Disk: use no more than'), |
| 345 | 345 | '#type' => 'textfield', |
| 346 | 346 | '#field_suffix' => 'GB', |
| 347 | 347 | '#default_value' => $default['disk_max_used_gb'], |
| 348 | 348 | '#size' => 1, |
| 349 | 349 | '#description' => bts('Limit the total amount of disk space used by BOINC.'), |
| 350 | - ); |
|
| 351 | - $form['prefs']['advanced']['storage']['disk_min_free_gb'] = array( |
|
| 350 | + ); |
|
| 351 | + $form['prefs']['advanced']['storage']['disk_min_free_gb'] = array( |
|
| 352 | 352 | '#title' => bts('Disk: leave at least'), |
| 353 | 353 | '#type' => 'textfield', |
| 354 | 354 | '#field_suffix' => 'GB free', |
| 355 | 355 | '#default_value' => $default['disk_min_free_gb'], |
| 356 | 356 | '#size' => 1, |
| 357 | 357 | '#description' => bts('Limit disk usage to leave this much free space on the volume where BOINC stores data.'), |
| 358 | - ); |
|
| 359 | - $form['prefs']['advanced']['storage']['disk_max_used_pct'] = array( |
|
| 358 | + ); |
|
| 359 | + $form['prefs']['advanced']['storage']['disk_max_used_pct'] = array( |
|
| 360 | 360 | '#title' => bts('Disk: use no more than'), |
| 361 | 361 | '#type' => 'textfield', |
| 362 | 362 | '#field_suffix' => bts('% of total'), |
| 363 | 363 | '#default_value' => $default['disk_max_used_pct'], |
| 364 | 364 | '#size' => 1, |
| 365 | 365 | '#description' => bts('Limit the percentage of disk space used by BOINC on the volume where it stores data.') |
| 366 | - ); |
|
| 367 | - $form['prefs']['advanced']['storage']['disk_interval'] = array( |
|
| 366 | + ); |
|
| 367 | + $form['prefs']['advanced']['storage']['disk_interval'] = array( |
|
| 368 | 368 | '#title' => bts('Request tasks to checkpoint at most every'), |
| 369 | 369 | '#type' => 'textfield', |
| 370 | 370 | '#field_suffix' => bts('seconds'), |
| 371 | 371 | '#default_value' => $default['disk_interval'], |
| 372 | 372 | '#size' => 1, |
| 373 | 373 | '#description' => bts('This controls how often tasks save their state to disk, so that later they can be continued from that point.') |
| 374 | - ); |
|
| 375 | - $form['prefs']['advanced']['storage']['vm_max_used_pct'] = array( |
|
| 374 | + ); |
|
| 375 | + $form['prefs']['advanced']['storage']['vm_max_used_pct'] = array( |
|
| 376 | 376 | '#title' => bts('Page/swap file: use at most'), |
| 377 | 377 | '#type' => 'textfield', |
| 378 | 378 | '#field_suffix' => bts('% of total'), |
| 379 | 379 | '#default_value' => $default['vm_max_used_pct'], |
| 380 | 380 | '#size' => 1, |
| 381 | 381 | '#description' => bts('Limit the swap space (page file) used by BOINC.') |
| 382 | - ); |
|
| 383 | - $form['prefs']['advanced']['storage']['ram_max_used_busy_pct'] = array( |
|
| 382 | + ); |
|
| 383 | + $form['prefs']['advanced']['storage']['ram_max_used_busy_pct'] = array( |
|
| 384 | 384 | '#title' => bts('Memory: when computer is in use, use at most'), |
| 385 | 385 | '#type' => 'textfield', |
| 386 | 386 | '#field_suffix' => bts('% of total'), |
| 387 | 387 | '#default_value' => $default['ram_max_used_busy_pct'], |
| 388 | 388 | '#size' => 1, |
| 389 | 389 | '#description' => bts("Limit the memory used by BOINC when you're using the computer.") |
| 390 | - ); |
|
| 391 | - $form['prefs']['advanced']['storage']['ram_max_used_idle_pct'] = array( |
|
| 390 | + ); |
|
| 391 | + $form['prefs']['advanced']['storage']['ram_max_used_idle_pct'] = array( |
|
| 392 | 392 | '#title' => bts('Memory: when computer is not in use, use at most'), |
| 393 | 393 | '#type' => 'textfield', |
| 394 | 394 | '#field_suffix' => bts('% of total'), |
| 395 | 395 | '#default_value' => $default['ram_max_used_idle_pct'], |
| 396 | 396 | '#size' => 1, |
| 397 | 397 | '#description' => bts("Limit the memory used by BOINC when you're not using the computer.") |
| 398 | - ); |
|
| 398 | + ); |
|
| 399 | 399 | |
| 400 | - // Network preferences |
|
| 401 | - $form['prefs']['advanced']['network'] = array( |
|
| 400 | + // Network preferences |
|
| 401 | + $form['prefs']['advanced']['network'] = array( |
|
| 402 | 402 | '#title' => bts('Network usage'), |
| 403 | 403 | '#type' => 'fieldset', |
| 404 | 404 | '#description' => '', |
| 405 | 405 | '#collapsible' => FALSE, |
| 406 | 406 | '#collapsed' => FALSE |
| 407 | - ); |
|
| 408 | - $form['prefs']['advanced']['network']['work_buf_min_days'] = array( |
|
| 407 | + ); |
|
| 408 | + $form['prefs']['advanced']['network']['work_buf_min_days'] = array( |
|
| 409 | 409 | '#title' => bts('Store at least'), |
| 410 | 410 | '#type' => 'textfield', |
| 411 | 411 | '#field_suffix' => bts('days of work'), |
| 412 | 412 | '#default_value' => $default['work_buf_min_days'], |
| 413 | 413 | '#size' => 1, |
| 414 | 414 | '#description' => bts('Store at least enough tasks to keep the computer busy for this long.') |
| 415 | - ); |
|
| 416 | - $form['prefs']['advanced']['network']['work_buf_additional_days'] = array( |
|
| 415 | + ); |
|
| 416 | + $form['prefs']['advanced']['network']['work_buf_additional_days'] = array( |
|
| 417 | 417 | '#title' => bts('Store up to an additional'), |
| 418 | 418 | '#type' => 'textfield', |
| 419 | 419 | '#field_suffix' => bts('days'), |
| 420 | 420 | '#default_value' => $default['work_buf_additional_days'], |
| 421 | 421 | '#size' => 1, |
| 422 | 422 | '#description' => bts('Store additional tasks above the minimum level. Determines how much work is requested when contacting a project.') |
| 423 | - ); |
|
| 424 | - $form['prefs']['advanced']['network']['confirm_before_connecting'] = array( |
|
| 423 | + ); |
|
| 424 | + $form['prefs']['advanced']['network']['confirm_before_connecting'] = array( |
|
| 425 | 425 | '#title' => bts('Confirm before connecting to Internet?'), |
| 426 | 426 | '#type' => 'radios', |
| 427 | 427 | '#options' => $form['boolean_options']['#value'], |
| 428 | 428 | '#attributes' => array('class' => 'fancy'), |
| 429 | 429 | '#default_value' => $default['confirm_before_connecting'], |
| 430 | 430 | '#description' => bts('Useful only if you have a modem, ISDN or VPN connection.') |
| 431 | - ); |
|
| 432 | - $form['prefs']['advanced']['network']['hangup_if_dialed'] = array( |
|
| 431 | + ); |
|
| 432 | + $form['prefs']['advanced']['network']['hangup_if_dialed'] = array( |
|
| 433 | 433 | '#title' => bts('Disconnect when done?'), |
| 434 | 434 | '#type' => 'radios', |
| 435 | 435 | '#options' => $form['boolean_options']['#value'], |
| 436 | 436 | '#attributes' => array('class' => 'fancy'), |
| 437 | 437 | '#default_value' => $default['hangup_if_dialed'], |
| 438 | 438 | '#description' => bts('Useful only if you have a modem, ISDN or VPN connection.') |
| 439 | - ); |
|
| 440 | - $form['prefs']['advanced']['network']['max_bytes_sec_down'] = array( |
|
| 439 | + ); |
|
| 440 | + $form['prefs']['advanced']['network']['max_bytes_sec_down'] = array( |
|
| 441 | 441 | '#title' => bts('Limit download rate to'), |
| 442 | 442 | '#type' => 'textfield', |
| 443 | 443 | '#field_suffix' => 'Kbytes/sec', |
| 444 | 444 | '#default_value' => $default['max_bytes_sec_down']/1000, |
| 445 | 445 | '#size' => 1, |
| 446 | 446 | '#description' => bts('Limit the download rate of file transfers.') |
| 447 | - ); |
|
| 448 | - $form['prefs']['advanced']['network']['max_bytes_sec_up'] = array( |
|
| 447 | + ); |
|
| 448 | + $form['prefs']['advanced']['network']['max_bytes_sec_up'] = array( |
|
| 449 | 449 | '#title' => bts('Limit upload rate to'), |
| 450 | 450 | '#type' => 'textfield', |
| 451 | 451 | '#field_suffix' => 'Kbytes/sec', |
| 452 | 452 | '#default_value' => $default['max_bytes_sec_up']/1000, |
| 453 | 453 | '#size' => 1, |
| 454 | 454 | '#description' => bts('Limit the upload rate of file transfers.') |
| 455 | - ); |
|
| 456 | - $form['prefs']['advanced']['network']['hour_label'] = array( |
|
| 455 | + ); |
|
| 456 | + $form['prefs']['advanced']['network']['hour_label'] = array( |
|
| 457 | 457 | '#value' => '<div class="form-item"><label>' . bts('Transfer files only between') . '</label></div>' |
| 458 | - ); |
|
| 459 | - $form['prefs']['advanced']['network']['net_start_hour'] = array( |
|
| 458 | + ); |
|
| 459 | + $form['prefs']['advanced']['network']['net_start_hour'] = array( |
|
| 460 | 460 | '#type' => 'select', |
| 461 | 461 | '#options' => $form['hour_options']['#value'], |
| 462 | 462 | '#default_value' => $default['net_start_hour'] |
| 463 | - ); |
|
| 464 | - $form['prefs']['advanced']['network']['hour_delimiter'] = array( |
|
| 463 | + ); |
|
| 464 | + $form['prefs']['advanced']['network']['hour_delimiter'] = array( |
|
| 465 | 465 | '#value' => '<span>' . bts('and') . '</span>' |
| 466 | - ); |
|
| 467 | - $form['prefs']['advanced']['network']['net_end_hour'] = array( |
|
| 466 | + ); |
|
| 467 | + $form['prefs']['advanced']['network']['net_end_hour'] = array( |
|
| 468 | 468 | '#type' => 'select', |
| 469 | 469 | '#options' => $form['hour_options']['#value'], |
| 470 | 470 | '#default_value' => $default['net_end_hour'] |
| 471 | - ); |
|
| 472 | - $form['prefs']['advanced']['network']['hour_description'] = array( |
|
| 471 | + ); |
|
| 472 | + $form['prefs']['advanced']['network']['hour_description'] = array( |
|
| 473 | 473 | '#value' => '<div class="form-item slim"><div class="description">' . bts('Transfer files only during a particular period each day.') . '</div></div>' |
| 474 | - ); |
|
| 475 | - $form['prefs']['advanced']['network']['daily_xfer_limit_mb'] = array( |
|
| 474 | + ); |
|
| 475 | + $form['prefs']['advanced']['network']['daily_xfer_limit_mb'] = array( |
|
| 476 | 476 | '#title' => bts('Limit usage to'), |
| 477 | 477 | '#type' => 'textfield', |
| 478 | 478 | '#field_suffix' => 'Mbytes', |
| 479 | 479 | '#default_value' => $default['daily_xfer_limit_mb'], |
| 480 | 480 | '#size' => 1 |
| 481 | - ); |
|
| 482 | - $form['prefs']['advanced']['network']['daily_xfer_period_days'] = array( |
|
| 481 | + ); |
|
| 482 | + $form['prefs']['advanced']['network']['daily_xfer_period_days'] = array( |
|
| 483 | 483 | '#field_prefix' => 'every', |
| 484 | 484 | '#type' => 'textfield', |
| 485 | 485 | '#field_suffix' => bts('days'), |
| 486 | 486 | '#default_value' => $default['daily_xfer_period_days'], |
| 487 | 487 | '#size' => 1, |
| 488 | 488 | '#description' => bts('Example: BOINC should transfer at most 2000 MB of data every 30 days.'), |
| 489 | - ); |
|
| 490 | - $form['prefs']['advanced']['network']['dont_verify_images'] = array( |
|
| 489 | + ); |
|
| 490 | + $form['prefs']['advanced']['network']['dont_verify_images'] = array( |
|
| 491 | 491 | '#title' => bts('Skip data verification for image files?'), |
| 492 | 492 | '#type' => 'radios', |
| 493 | 493 | '#options' => $form['boolean_options']['#value'], |
| 494 | 494 | '#attributes' => array('class' => 'fancy'), |
| 495 | 495 | '#default_value' => $default['dont_verify_images'], |
| 496 | 496 | '#description' => bts('Only select "Yes" if your Internet provider modifies image files. Skipping verification reduces the security of BOINC.') |
| 497 | - ); |
|
| 497 | + ); |
|
| 498 | 498 | |
| 499 | - // The "fancy radios" are made via javascript on document load. In order for |
|
| 500 | - // these to work with AHAH, we need this crazy setTimeout() call. |
|
| 501 | - $form['prefs']['fancy-radios'] = array( |
|
| 499 | + // The "fancy radios" are made via javascript on document load. In order for |
|
| 500 | + // these to work with AHAH, we need this crazy setTimeout() call. |
|
| 501 | + $form['prefs']['fancy-radios'] = array( |
|
| 502 | 502 | '#value' => ' |
| 503 | 503 | <script> |
| 504 | 504 | setTimeout( |
@@ -509,177 +509,177 @@ discard block |
||
| 509 | 509 | 300 |
| 510 | 510 | ) |
| 511 | 511 | </script>' |
| 512 | - ); |
|
| 513 | - $form['prefs']['view advanced'] = array( |
|
| 512 | + ); |
|
| 513 | + $form['prefs']['view advanced'] = array( |
|
| 514 | 514 | '#type' => 'hidden', |
| 515 | 515 | '#value' => 1 |
| 516 | - ); |
|
| 516 | + ); |
|
| 517 | 517 | |
| 518 | - $form['prefs']['separator_bottom'] = array( |
|
| 518 | + $form['prefs']['separator_bottom'] = array( |
|
| 519 | 519 | '#value' => '<div class="separator buttons"></div>' |
| 520 | - ); |
|
| 520 | + ); |
|
| 521 | 521 | |
| 522 | - // Form control |
|
| 523 | - $form['prefs']['form control tabs prefix'] = array( |
|
| 522 | + // Form control |
|
| 523 | + $form['prefs']['form control tabs prefix'] = array( |
|
| 524 | 524 | '#value' => '<ul class="form-control tab-list">' |
| 525 | - ); |
|
| 526 | - $form['prefs']['submit'] = array( |
|
| 525 | + ); |
|
| 526 | + $form['prefs']['submit'] = array( |
|
| 527 | 527 | '#prefix' => '<li class="first tab">', |
| 528 | 528 | '#type' => 'submit', |
| 529 | 529 | '#value' => bts('Save changes'), |
| 530 | 530 | '#suffix' => '</li>' |
| 531 | - ); |
|
| 532 | - $form['prefs']['form control tabs'] = array( |
|
| 531 | + ); |
|
| 532 | + $form['prefs']['form control tabs'] = array( |
|
| 533 | 533 | '#value' => '<li class="tab">' . l(bts('Cancel'), drupal_get_path_alias("account/prefs/computing/edit")) . '</li>' |
| 534 | - ); |
|
| 535 | - if ($venue AND $venue != 'generic') { |
|
| 534 | + ); |
|
| 535 | + if ($venue AND $venue != 'generic') { |
|
| 536 | 536 | global $base_path; |
| 537 | 537 | $form['prefs']['form control tabs']['#value'] .= '<li class="tab">' . |
| 538 | - l(bts('Clear'), "account/prefs/computing/clear/{$venue}", |
|
| 538 | + l(bts('Clear'), "account/prefs/computing/clear/{$venue}", |
|
| 539 | 539 | array( |
| 540 | - 'query' => 'destination=' . urlencode(drupal_get_path_alias('account/prefs/computing/combined')), |
|
| 541 | - 'attributes' => array( |
|
| 540 | + 'query' => 'destination=' . urlencode(drupal_get_path_alias('account/prefs/computing/combined')), |
|
| 541 | + 'attributes' => array( |
|
| 542 | 542 | 'onclick' => 'return confirm(\'' . bts('This will remove all of your settings from the @name preference set. Are you sure?', |
| 543 | - array('@name' => $venue)) . '\')' |
|
| 544 | - ) |
|
| 543 | + array('@name' => $venue)) . '\')' |
|
| 544 | + ) |
|
| 545 | 545 | ) |
| 546 | - ) . '</li>'; |
|
| 547 | - } |
|
| 548 | - $form['prefs']['view control'] = array( |
|
| 546 | + ) . '</li>'; |
|
| 547 | + } |
|
| 548 | + $form['prefs']['view control'] = array( |
|
| 549 | 549 | '#value' => '<li class="first alt tab">' . l('(' . bts('Show comparison view') . ')', 'account/prefs/computing/combined') . '</li>' |
| 550 | - ); |
|
| 551 | - $form['prefs']['form control tabs suffix'] = array( |
|
| 550 | + ); |
|
| 551 | + $form['prefs']['form control tabs suffix'] = array( |
|
| 552 | 552 | '#value' => '</ul>' |
| 553 | - ); |
|
| 554 | - $form['#submit'][] = 'boincwork_generalprefs_form_submit'; |
|
| 553 | + ); |
|
| 554 | + $form['#submit'][] = 'boincwork_generalprefs_form_submit'; |
|
| 555 | 555 | |
| 556 | - return $form; |
|
| 556 | + return $form; |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | /** |
| 560 | - * Validate the general preferences form. |
|
| 561 | - */ |
|
| 560 | + * Validate the general preferences form. |
|
| 561 | + */ |
|
| 562 | 562 | function boincwork_generalprefs_form_validate($form, &$form_state) { |
| 563 | - require_boinc('util'); |
|
| 564 | - $values = $form_state['values']['prefs']['advanced']; |
|
| 565 | - |
|
| 566 | - //drupal_set_message('<pre>' . print_r($form_state['values'], true) . '</pre>'); |
|
| 567 | - // Verify all non-boolean user input values and notify form API of failures |
|
| 568 | - |
|
| 569 | - // Processing preferences |
|
| 570 | - if (!verify_numeric($values['processor']['idle_time_to_run'], 1, 9999)) form_set_error('idle_time_to_run', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['idle_time_to_run']['#title']} [x] {$form['prefs']['advanced']['processor']['idle_time_to_run']['#field_suffix']}"))); |
|
| 571 | - if (!verify_numeric($values['processor']['suspend_if_no_recent_input'], 0, 9999)) form_set_error('suspend_if_no_recent_input', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['suspend_if_no_recent_input']['#title']} [x] {$form['prefs']['advanced']['processor']['suspend_if_no_recent_input']['#field_suffix']}"))); |
|
| 572 | - if (!verify_numeric($values['processor']['suspend_cpu_usage'], 0, 100)) form_set_error('suspend_cpu_usage', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['suspend_cpu_usage']['#title']} [x] {$form['prefs']['advanced']['processor']['suspend_cpu_usage']['#field_suffix']}"))); |
|
| 573 | - if (!verify_numeric($values['processor']['start_hour'], 0, 23)) form_set_error('start_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['start_hour']['#title']} [x] {$form['prefs']['advanced']['processor']['start_hour']['#field_suffix']}"))); |
|
| 574 | - if (!verify_numeric($values['processor']['end_hour'], 0, 23)) form_set_error('end_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['end_hour']['#title']} [x] {$form['prefs']['advanced']['processor']['end_hour']['#field_suffix']}"))); |
|
| 575 | - if (!verify_numeric($values['processor']['cpu_scheduling_period_minutes'], 1, 9999)) form_set_error('cpu_scheduling_period_minutes', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['cpu_scheduling_period_minutes']['#title']} [x] {$form['prefs']['advanced']['processor']['cpu_scheduling_period_minutes']['#field_suffix']}"))); |
|
| 576 | - if (!verify_numeric($values['processor']['max_ncpus_pct'], 0, 100)) form_set_error('max_ncpus_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['max_ncpus_pct']['#title']} [x] {$form['prefs']['advanced']['processor']['max_ncpus_pct']['#field_suffix']}"))); |
|
| 577 | - if (!verify_numeric($values['processor']['cpu_usage_limit'], 0, 100)) form_set_error('cpu_usage_limit', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['cpu_usage_limit']['#title']} [x] {$form['prefs']['advanced']['processor']['cpu_usage_limit']['#field_suffix']}"))); |
|
| 563 | + require_boinc('util'); |
|
| 564 | + $values = $form_state['values']['prefs']['advanced']; |
|
| 565 | + |
|
| 566 | + //drupal_set_message('<pre>' . print_r($form_state['values'], true) . '</pre>'); |
|
| 567 | + // Verify all non-boolean user input values and notify form API of failures |
|
| 568 | + |
|
| 569 | + // Processing preferences |
|
| 570 | + if (!verify_numeric($values['processor']['idle_time_to_run'], 1, 9999)) form_set_error('idle_time_to_run', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['idle_time_to_run']['#title']} [x] {$form['prefs']['advanced']['processor']['idle_time_to_run']['#field_suffix']}"))); |
|
| 571 | + if (!verify_numeric($values['processor']['suspend_if_no_recent_input'], 0, 9999)) form_set_error('suspend_if_no_recent_input', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['suspend_if_no_recent_input']['#title']} [x] {$form['prefs']['advanced']['processor']['suspend_if_no_recent_input']['#field_suffix']}"))); |
|
| 572 | + if (!verify_numeric($values['processor']['suspend_cpu_usage'], 0, 100)) form_set_error('suspend_cpu_usage', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['suspend_cpu_usage']['#title']} [x] {$form['prefs']['advanced']['processor']['suspend_cpu_usage']['#field_suffix']}"))); |
|
| 573 | + if (!verify_numeric($values['processor']['start_hour'], 0, 23)) form_set_error('start_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['start_hour']['#title']} [x] {$form['prefs']['advanced']['processor']['start_hour']['#field_suffix']}"))); |
|
| 574 | + if (!verify_numeric($values['processor']['end_hour'], 0, 23)) form_set_error('end_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['end_hour']['#title']} [x] {$form['prefs']['advanced']['processor']['end_hour']['#field_suffix']}"))); |
|
| 575 | + if (!verify_numeric($values['processor']['cpu_scheduling_period_minutes'], 1, 9999)) form_set_error('cpu_scheduling_period_minutes', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['cpu_scheduling_period_minutes']['#title']} [x] {$form['prefs']['advanced']['processor']['cpu_scheduling_period_minutes']['#field_suffix']}"))); |
|
| 576 | + if (!verify_numeric($values['processor']['max_ncpus_pct'], 0, 100)) form_set_error('max_ncpus_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['max_ncpus_pct']['#title']} [x] {$form['prefs']['advanced']['processor']['max_ncpus_pct']['#field_suffix']}"))); |
|
| 577 | + if (!verify_numeric($values['processor']['cpu_usage_limit'], 0, 100)) form_set_error('cpu_usage_limit', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['cpu_usage_limit']['#title']} [x] {$form['prefs']['advanced']['processor']['cpu_usage_limit']['#field_suffix']}"))); |
|
| 578 | 578 | |
| 579 | - // Storage preferences |
|
| 580 | - if (!verify_numeric($values['storage']['disk_max_used_gb'], 0, 9999999)) form_set_error('disk_max_used_gb', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_max_used_gb']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_max_used_gb']['#field_suffix']}"))); |
|
| 581 | - if (!verify_numeric($values['storage']['disk_min_free_gb'], 0.001, 9999999)) form_set_error('disk_min_free_gb', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_min_free_gb']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_min_free_gb']['#field_suffix']}"))); |
|
| 582 | - if (!verify_numeric($values['storage']['disk_max_used_pct'], 0, 100)) form_set_error('disk_max_used_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_max_used_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_max_used_pct']['#field_suffix']}"))); |
|
| 583 | - if (!verify_numeric($values['storage']['disk_interval'], 0, 9999999)) form_set_error('disk_interval', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_interval']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_interval']['#field_suffix']}"))); |
|
| 584 | - if (!verify_numeric($values['storage']['vm_max_used_pct'], 0, 100)) form_set_error('vm_max_used_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['vm_max_used_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['vm_max_used_pct']['#field_suffix']}"))); |
|
| 585 | - if (!verify_numeric($values['storage']['ram_max_used_busy_pct'], 0, 100)) form_set_error('ram_max_used_busy_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['ram_max_used_busy_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['ram_max_used_busy_pct']['#field_suffix']}"))); |
|
| 586 | - if (!verify_numeric($values['storage']['ram_max_used_idle_pct'], 0, 100)) form_set_error('ram_max_used_idle_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['ram_max_used_idle_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['ram_max_used_idle_pct']['#field_suffix']}"))); |
|
| 579 | + // Storage preferences |
|
| 580 | + if (!verify_numeric($values['storage']['disk_max_used_gb'], 0, 9999999)) form_set_error('disk_max_used_gb', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_max_used_gb']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_max_used_gb']['#field_suffix']}"))); |
|
| 581 | + if (!verify_numeric($values['storage']['disk_min_free_gb'], 0.001, 9999999)) form_set_error('disk_min_free_gb', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_min_free_gb']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_min_free_gb']['#field_suffix']}"))); |
|
| 582 | + if (!verify_numeric($values['storage']['disk_max_used_pct'], 0, 100)) form_set_error('disk_max_used_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_max_used_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_max_used_pct']['#field_suffix']}"))); |
|
| 583 | + if (!verify_numeric($values['storage']['disk_interval'], 0, 9999999)) form_set_error('disk_interval', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_interval']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_interval']['#field_suffix']}"))); |
|
| 584 | + if (!verify_numeric($values['storage']['vm_max_used_pct'], 0, 100)) form_set_error('vm_max_used_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['vm_max_used_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['vm_max_used_pct']['#field_suffix']}"))); |
|
| 585 | + if (!verify_numeric($values['storage']['ram_max_used_busy_pct'], 0, 100)) form_set_error('ram_max_used_busy_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['ram_max_used_busy_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['ram_max_used_busy_pct']['#field_suffix']}"))); |
|
| 586 | + if (!verify_numeric($values['storage']['ram_max_used_idle_pct'], 0, 100)) form_set_error('ram_max_used_idle_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['ram_max_used_idle_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['ram_max_used_idle_pct']['#field_suffix']}"))); |
|
| 587 | 587 | |
| 588 | - // Network preferences |
|
| 589 | - if (!verify_numeric($values['network']['work_buf_min_days'], 0, 10)) form_set_error('work_buf_min_days', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['work_buf_min_days']['#title']} [x] {$form['prefs']['advanced']['network']['work_buf_min_days']['#field_suffix']}"))); |
|
| 590 | - if (!verify_numeric($values['network']['work_buf_additional_days'], 0, 10)) form_set_error('work_buf_additional_days', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['work_buf_additional_days']['#title']} [x] {$form['prefs']['advanced']['network']['work_buf_additional_days']['#field_suffix']}"))); |
|
| 591 | - if (!verify_numeric($values['network']['max_bytes_sec_down'], 0, 9999.999)) form_set_error('max_bytes_sec_down', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['max_bytes_sec_down']['#title']} [x] {$form['prefs']['advanced']['network']['max_bytes_sec_down']['#field_suffix']}"))); |
|
| 592 | - if (!verify_numeric($values['network']['max_bytes_sec_up'], 0, 9999.999)) form_set_error('max_bytes_sec_up', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['max_bytes_sec_up']['#title']} [x] {$form['prefs']['advanced']['network']['max_bytes_sec_up']['#field_suffix']}"))); |
|
| 593 | - if (!verify_numeric($values['network']['net_start_hour'], 0, 23)) form_set_error('net_start_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['net_start_hour']['#title']} [x] {$form['prefs']['advanced']['network']['net_start_hour']['#field_suffix']}"))); |
|
| 594 | - if (!verify_numeric($values['network']['net_end_hour'], 0, 23)) form_set_error('net_end_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['net_end_hour']['#title']} [x] {$form['prefs']['advanced']['network']['net_end_hour']['#field_suffix']}"))); |
|
| 595 | - if (!verify_numeric($values['network']['daily_xfer_limit_mb'], 0, 9999999)) form_set_error('daily_xfer_limit_mb', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#title']} [x] {$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#field_suffix']}"))); |
|
| 596 | - if (!verify_numeric($values['network']['daily_xfer_period_days'], 0, 9999999)) form_set_error('daily_xfer_period_days', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#title']} [x] {$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#field_suffix']}"))); |
|
| 588 | + // Network preferences |
|
| 589 | + if (!verify_numeric($values['network']['work_buf_min_days'], 0, 10)) form_set_error('work_buf_min_days', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['work_buf_min_days']['#title']} [x] {$form['prefs']['advanced']['network']['work_buf_min_days']['#field_suffix']}"))); |
|
| 590 | + if (!verify_numeric($values['network']['work_buf_additional_days'], 0, 10)) form_set_error('work_buf_additional_days', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['work_buf_additional_days']['#title']} [x] {$form['prefs']['advanced']['network']['work_buf_additional_days']['#field_suffix']}"))); |
|
| 591 | + if (!verify_numeric($values['network']['max_bytes_sec_down'], 0, 9999.999)) form_set_error('max_bytes_sec_down', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['max_bytes_sec_down']['#title']} [x] {$form['prefs']['advanced']['network']['max_bytes_sec_down']['#field_suffix']}"))); |
|
| 592 | + if (!verify_numeric($values['network']['max_bytes_sec_up'], 0, 9999.999)) form_set_error('max_bytes_sec_up', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['max_bytes_sec_up']['#title']} [x] {$form['prefs']['advanced']['network']['max_bytes_sec_up']['#field_suffix']}"))); |
|
| 593 | + if (!verify_numeric($values['network']['net_start_hour'], 0, 23)) form_set_error('net_start_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['net_start_hour']['#title']} [x] {$form['prefs']['advanced']['network']['net_start_hour']['#field_suffix']}"))); |
|
| 594 | + if (!verify_numeric($values['network']['net_end_hour'], 0, 23)) form_set_error('net_end_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['net_end_hour']['#title']} [x] {$form['prefs']['advanced']['network']['net_end_hour']['#field_suffix']}"))); |
|
| 595 | + if (!verify_numeric($values['network']['daily_xfer_limit_mb'], 0, 9999999)) form_set_error('daily_xfer_limit_mb', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#title']} [x] {$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#field_suffix']}"))); |
|
| 596 | + if (!verify_numeric($values['network']['daily_xfer_period_days'], 0, 9999999)) form_set_error('daily_xfer_period_days', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#title']} [x] {$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#field_suffix']}"))); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
| 600 | - * Handle post-validation submission of general preferences form. |
|
| 601 | - */ |
|
| 600 | + * Handle post-validation submission of general preferences form. |
|
| 601 | + */ |
|
| 602 | 602 | function boincwork_generalprefs_form_submit($form, &$form_state) { |
| 603 | - global $user; |
|
| 604 | - $account = user_load($user->uid); |
|
| 605 | - |
|
| 606 | - $values = $form_state['values']['prefs']['advanced']; |
|
| 607 | - $venue = $form_state['values']['prefs']['venue']; |
|
| 608 | - $preset = $form_state['values']['prefs']['preset']; |
|
| 609 | - |
|
| 610 | - // Load preferences from BOINC account |
|
| 611 | - $prefs = boincwork_load_prefs('general', $venue); |
|
| 612 | - |
|
| 613 | - // Processing preferences |
|
| 614 | - $prefs['run_on_batteries'] = ($values['processor']['run_on_batteries']) ? 0 : 1; |
|
| 615 | - $prefs['run_if_user_active'] = ($values['processor']['run_if_user_active']) ? 0 : 1; |
|
| 616 | - $prefs['run_gpu_if_user_active'] = ($values['processor']['run_gpu_if_user_active']) ? 0 : 1; |
|
| 617 | - $prefs['idle_time_to_run'] = $values['processor']['idle_time_to_run']; |
|
| 618 | - $prefs['suspend_if_no_recent_input'] = $values['processor']['suspend_if_no_recent_input']; |
|
| 619 | - $prefs['suspend_cpu_usage'] = $values['processor']['suspend_cpu_usage']; |
|
| 620 | - $prefs['start_hour'] = $values['processor']['start_hour']; |
|
| 621 | - $prefs['end_hour'] = $values['processor']['end_hour']; |
|
| 622 | - $prefs['leave_apps_in_memory'] = ($values['processor']['leave_apps_in_memory']) ? 1 : 0; |
|
| 623 | - $prefs['cpu_scheduling_period_minutes'] = $values['processor']['cpu_scheduling_period_minutes']; |
|
| 624 | - $prefs['max_ncpus_pct'] = $values['processor']['max_ncpus_pct']; |
|
| 625 | - $prefs['cpu_usage_limit'] = $values['processor']['cpu_usage_limit']; |
|
| 626 | - |
|
| 627 | - // Storage preferences |
|
| 628 | - $prefs['disk_max_used_gb'] = $values['storage']['disk_max_used_gb']; |
|
| 629 | - $prefs['disk_min_free_gb'] = $values['storage']['disk_min_free_gb']; |
|
| 630 | - $prefs['disk_max_used_pct'] = $values['storage']['disk_max_used_pct']; |
|
| 631 | - $prefs['disk_interval'] = $values['storage']['disk_interval']; |
|
| 632 | - $prefs['vm_max_used_pct'] = $values['storage']['vm_max_used_pct']; |
|
| 633 | - $prefs['ram_max_used_busy_pct'] = $values['storage']['ram_max_used_busy_pct']; |
|
| 634 | - $prefs['ram_max_used_idle_pct'] = $values['storage']['ram_max_used_idle_pct']; |
|
| 635 | - |
|
| 636 | - // Network preferences |
|
| 637 | - $prefs['work_buf_min_days'] = $values['network']['work_buf_min_days']; |
|
| 638 | - $prefs['work_buf_additional_days'] = $values['network']['work_buf_additional_days']; |
|
| 639 | - $prefs['confirm_before_connecting'] = ($values['network']['confirm_before_connecting']) ? 1 : 0; |
|
| 640 | - $prefs['hangup_if_dialed'] = ($values['network']['hangup_if_dialed']) ? 1 : 0; |
|
| 641 | - $prefs['max_bytes_sec_down'] = $values['network']['max_bytes_sec_down']*1000; |
|
| 642 | - $prefs['max_bytes_sec_up'] = $values['network']['max_bytes_sec_up']*1000; |
|
| 643 | - $prefs['net_start_hour'] = $values['network']['net_start_hour']; |
|
| 644 | - $prefs['net_end_hour'] = $values['network']['net_end_hour']; |
|
| 645 | - $prefs['daily_xfer_limit_mb'] = $values['network']['daily_xfer_limit_mb']; |
|
| 646 | - $prefs['daily_xfer_period_days'] = $values['network']['daily_xfer_period_days']; |
|
| 647 | - $prefs['dont_verify_images'] = ($values['network']['dont_verify_images']) ? 1 : 0; |
|
| 603 | + global $user; |
|
| 604 | + $account = user_load($user->uid); |
|
| 605 | + |
|
| 606 | + $values = $form_state['values']['prefs']['advanced']; |
|
| 607 | + $venue = $form_state['values']['prefs']['venue']; |
|
| 608 | + $preset = $form_state['values']['prefs']['preset']; |
|
| 609 | + |
|
| 610 | + // Load preferences from BOINC account |
|
| 611 | + $prefs = boincwork_load_prefs('general', $venue); |
|
| 612 | + |
|
| 613 | + // Processing preferences |
|
| 614 | + $prefs['run_on_batteries'] = ($values['processor']['run_on_batteries']) ? 0 : 1; |
|
| 615 | + $prefs['run_if_user_active'] = ($values['processor']['run_if_user_active']) ? 0 : 1; |
|
| 616 | + $prefs['run_gpu_if_user_active'] = ($values['processor']['run_gpu_if_user_active']) ? 0 : 1; |
|
| 617 | + $prefs['idle_time_to_run'] = $values['processor']['idle_time_to_run']; |
|
| 618 | + $prefs['suspend_if_no_recent_input'] = $values['processor']['suspend_if_no_recent_input']; |
|
| 619 | + $prefs['suspend_cpu_usage'] = $values['processor']['suspend_cpu_usage']; |
|
| 620 | + $prefs['start_hour'] = $values['processor']['start_hour']; |
|
| 621 | + $prefs['end_hour'] = $values['processor']['end_hour']; |
|
| 622 | + $prefs['leave_apps_in_memory'] = ($values['processor']['leave_apps_in_memory']) ? 1 : 0; |
|
| 623 | + $prefs['cpu_scheduling_period_minutes'] = $values['processor']['cpu_scheduling_period_minutes']; |
|
| 624 | + $prefs['max_ncpus_pct'] = $values['processor']['max_ncpus_pct']; |
|
| 625 | + $prefs['cpu_usage_limit'] = $values['processor']['cpu_usage_limit']; |
|
| 626 | + |
|
| 627 | + // Storage preferences |
|
| 628 | + $prefs['disk_max_used_gb'] = $values['storage']['disk_max_used_gb']; |
|
| 629 | + $prefs['disk_min_free_gb'] = $values['storage']['disk_min_free_gb']; |
|
| 630 | + $prefs['disk_max_used_pct'] = $values['storage']['disk_max_used_pct']; |
|
| 631 | + $prefs['disk_interval'] = $values['storage']['disk_interval']; |
|
| 632 | + $prefs['vm_max_used_pct'] = $values['storage']['vm_max_used_pct']; |
|
| 633 | + $prefs['ram_max_used_busy_pct'] = $values['storage']['ram_max_used_busy_pct']; |
|
| 634 | + $prefs['ram_max_used_idle_pct'] = $values['storage']['ram_max_used_idle_pct']; |
|
| 635 | + |
|
| 636 | + // Network preferences |
|
| 637 | + $prefs['work_buf_min_days'] = $values['network']['work_buf_min_days']; |
|
| 638 | + $prefs['work_buf_additional_days'] = $values['network']['work_buf_additional_days']; |
|
| 639 | + $prefs['confirm_before_connecting'] = ($values['network']['confirm_before_connecting']) ? 1 : 0; |
|
| 640 | + $prefs['hangup_if_dialed'] = ($values['network']['hangup_if_dialed']) ? 1 : 0; |
|
| 641 | + $prefs['max_bytes_sec_down'] = $values['network']['max_bytes_sec_down']*1000; |
|
| 642 | + $prefs['max_bytes_sec_up'] = $values['network']['max_bytes_sec_up']*1000; |
|
| 643 | + $prefs['net_start_hour'] = $values['network']['net_start_hour']; |
|
| 644 | + $prefs['net_end_hour'] = $values['network']['net_end_hour']; |
|
| 645 | + $prefs['daily_xfer_limit_mb'] = $values['network']['daily_xfer_limit_mb']; |
|
| 646 | + $prefs['daily_xfer_period_days'] = $values['network']['daily_xfer_period_days']; |
|
| 647 | + $prefs['dont_verify_images'] = ($values['network']['dont_verify_images']) ? 1 : 0; |
|
| 648 | 648 | |
| 649 | - // transform old way to store the preset into new way |
|
| 650 | - // ideally this should already have happened in boincwork_generalprefs_form() |
|
| 651 | - if (isset($prefs['@attributes']['preset'])) { |
|
| 649 | + // transform old way to store the preset into new way |
|
| 650 | + // ideally this should already have happened in boincwork_generalprefs_form() |
|
| 651 | + if (isset($prefs['@attributes']['preset'])) { |
|
| 652 | 652 | $prefs['preset'] = $prefs['@attributes']['preset']; |
| 653 | 653 | unset($prefs['@attributes']['preset']); |
| 654 | - } |
|
| 655 | - // Save the preset selection (or lack thereof) |
|
| 656 | - if (!$preset OR $preset == 'custom') { |
|
| 654 | + } |
|
| 655 | + // Save the preset selection (or lack thereof) |
|
| 656 | + if (!$preset OR $preset == 'custom') { |
|
| 657 | 657 | $prefs['preset'] = 'custom'; |
| 658 | - } |
|
| 659 | - else { |
|
| 658 | + } |
|
| 659 | + else { |
|
| 660 | 660 | $prefs['preset'] = $preset; |
| 661 | - } |
|
| 661 | + } |
|
| 662 | 662 | |
| 663 | - // If this is a new preference set, be sure to unset the "cleared" attribute |
|
| 664 | - if (isset($prefs['@attributes']['cleared'])) { |
|
| 663 | + // If this is a new preference set, be sure to unset the "cleared" attribute |
|
| 664 | + if (isset($prefs['@attributes']['cleared'])) { |
|
| 665 | 665 | unset($prefs['@attributes']['cleared']); |
| 666 | - } |
|
| 666 | + } |
|
| 667 | 667 | |
| 668 | - // Update database |
|
| 669 | - $result = boincwork_save_prefs($prefs, 'general', $venue); |
|
| 668 | + // Update database |
|
| 669 | + $result = boincwork_save_prefs($prefs, 'general', $venue); |
|
| 670 | 670 | |
| 671 | - if (!$result) { |
|
| 671 | + if (!$result) { |
|
| 672 | 672 | watchdog('boincwork', 'Error updating global prefs for user @id: @message', array('@id' => $account->id, '@message' => mysql_error()), WATCHDOG_ERROR); |
| 673 | 673 | drupal_set_message(t('Your changes could not be saved. Please contact support!'), 'error'); |
| 674 | - } |
|
| 675 | - elseif (!drupal_get_messages('status', FALSE)) { |
|
| 674 | + } |
|
| 675 | + elseif (!drupal_get_messages('status', FALSE)) { |
|
| 676 | 676 | // Show this message if the set wasn't created automatically (in which case |
| 677 | 677 | // there is a message tailored to that) { |
| 678 | 678 | drupal_set_message(t('Your preferences have been updated. |
| 679 | 679 | Client-related preferences will take effect when your computer |
| 680 | 680 | communicates with @project or you issue the "Update" |
| 681 | 681 | command from the BOINC client.', array('@project' => PROJECT))); |
| 682 | - } |
|
| 682 | + } |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | |
@@ -691,88 +691,88 @@ discard block |
||
| 691 | 691 | * Find compatible hosts for merging |
| 692 | 692 | */ |
| 693 | 693 | function boincwork_host_get_compatible_hosts($host_id) { |
| 694 | - require_boinc('host'); |
|
| 695 | - global $user; |
|
| 696 | - $account = user_load($user->uid); |
|
| 697 | - $compatible_hosts = array(); |
|
| 698 | - $host_count = 0; |
|
| 699 | - db_set_active('boinc'); |
|
| 700 | - $current_host = db_fetch_object(db_query(" |
|
| 694 | + require_boinc('host'); |
|
| 695 | + global $user; |
|
| 696 | + $account = user_load($user->uid); |
|
| 697 | + $compatible_hosts = array(); |
|
| 698 | + $host_count = 0; |
|
| 699 | + db_set_active('boinc'); |
|
| 700 | + $current_host = db_fetch_object(db_query(" |
|
| 701 | 701 | SELECT id, domain_name, create_time, total_credit, rpc_time, os_name, |
| 702 | 702 | p_vendor, p_model |
| 703 | 703 | FROM {host} |
| 704 | 704 | WHERE userid = '%d' AND id = '%d'", |
| 705 | 705 | $account->boincuser_id, $host_id |
| 706 | - )); |
|
| 707 | - db_set_active('default'); |
|
| 708 | - $current_host->task_count = boincwork_host_get_task_count($current_host->id); |
|
| 709 | - $current_host->is_new = !$current_host->total_credit AND !$current_host->task_count; |
|
| 710 | - // Get the list of all other hosts owned by this user for comparison |
|
| 711 | - db_set_active('boinc'); |
|
| 712 | - $all_other_hosts = db_query(" |
|
| 706 | + )); |
|
| 707 | + db_set_active('default'); |
|
| 708 | + $current_host->task_count = boincwork_host_get_task_count($current_host->id); |
|
| 709 | + $current_host->is_new = !$current_host->total_credit AND !$current_host->task_count; |
|
| 710 | + // Get the list of all other hosts owned by this user for comparison |
|
| 711 | + db_set_active('boinc'); |
|
| 712 | + $all_other_hosts = db_query(" |
|
| 713 | 713 | SELECT id, domain_name, create_time, total_credit, rpc_time, os_name, |
| 714 | 714 | p_vendor, p_model |
| 715 | 715 | FROM {host} |
| 716 | 716 | WHERE userid = '%d' AND id <> '%d'", |
| 717 | 717 | $account->boincuser_id, $host_id |
| 718 | - ); |
|
| 719 | - db_set_active('default'); |
|
| 720 | - // Compare all hosts to see if any are plausible duplicates |
|
| 721 | - while ($other_host = db_fetch_object($all_other_hosts)) { |
|
| 718 | + ); |
|
| 719 | + db_set_active('default'); |
|
| 720 | + // Compare all hosts to see if any are plausible duplicates |
|
| 721 | + while ($other_host = db_fetch_object($all_other_hosts)) { |
|
| 722 | 722 | // First, disqualify if hosts were active at the same time |
| 723 | 723 | if (!$current_host->is_new) { |
| 724 | - $other_host->task_count = boincwork_host_get_task_count($other_host->id); |
|
| 725 | - $other_host->is_new = !$other_host->total_credit AND !$other_host->task_count; |
|
| 726 | - if (!$other_host->is_new) { |
|
| 724 | + $other_host->task_count = boincwork_host_get_task_count($other_host->id); |
|
| 725 | + $other_host->is_new = !$other_host->total_credit AND !$other_host->task_count; |
|
| 726 | + if (!$other_host->is_new) { |
|
| 727 | 727 | // If both hosts being compared are not new, see if times overlap |
| 728 | 728 | if (!times_disjoint($current_host, $other_host)) { |
| 729 | - // Hosts were active at the same time; can't be a duplicate |
|
| 730 | - continue; |
|
| 729 | + // Hosts were active at the same time; can't be a duplicate |
|
| 730 | + continue; |
|
| 731 | + } |
|
| 731 | 732 | } |
| 732 | - } |
|
| 733 | 733 | } |
| 734 | 734 | // Next, disqualify if hosts have different OS platforms |
| 735 | 735 | if (!os_compatible($current_host, $other_host)) { |
| 736 | - // Hosts have different OS platforms; not really a duplicate |
|
| 737 | - continue; |
|
| 736 | + // Hosts have different OS platforms; not really a duplicate |
|
| 737 | + continue; |
|
| 738 | 738 | } |
| 739 | 739 | // Finally, disqualify if hosts have different CPUs |
| 740 | 740 | if (!cpus_compatible($current_host, $other_host)) { |
| 741 | - // CPUs don't match; not a duplicate |
|
| 742 | - continue; |
|
| 741 | + // CPUs don't match; not a duplicate |
|
| 742 | + continue; |
|
| 743 | 743 | } |
| 744 | 744 | // If not disqualified, this host is available for merging |
| 745 | 745 | $hosts[] = $other_host; |
| 746 | 746 | $host_count++; |
| 747 | 747 | if ($host_count == 500) { |
| 748 | - // This is enough! |
|
| 749 | - break; |
|
| 748 | + // This is enough! |
|
| 749 | + break; |
|
| 750 | 750 | } |
| 751 | - } |
|
| 752 | - return $hosts; |
|
| 751 | + } |
|
| 752 | + return $hosts; |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | /** |
| 756 | 756 | * Perform the database updates to merge the old host into the new host |
| 757 | 757 | */ |
| 758 | 758 | function boincwork_host_merge($old_host, $new_host, &$message = NULL) { |
| 759 | - // Decay the average credit of the two hosts |
|
| 760 | - require_boinc('credit'); |
|
| 761 | - $now = time(); |
|
| 762 | - update_average($now, 0, 0, $old_host->expavg_credit, $old_host->expavg_time); |
|
| 763 | - update_average($now, 0, 0, $new_host->expavg_credit, $new_host->expavg_time); |
|
| 764 | - |
|
| 765 | - // Update the database: |
|
| 766 | - // - add credit from old host to new host |
|
| 767 | - // - change results to refer to the new host |
|
| 768 | - // - put old host in "zombie" state (userid=0, rpc_seqno=[new_host_id]) |
|
| 769 | - |
|
| 770 | - $total_credit = $old_host->total_credit + $new_host->total_credit; |
|
| 771 | - $recent_credit = $old_host->expavg_credit + $new_host->expavg_credit; |
|
| 772 | - |
|
| 773 | - // Move credit from the old host to the new host |
|
| 774 | - db_set_active('boinc'); |
|
| 775 | - $credit_updated = db_query(" |
|
| 759 | + // Decay the average credit of the two hosts |
|
| 760 | + require_boinc('credit'); |
|
| 761 | + $now = time(); |
|
| 762 | + update_average($now, 0, 0, $old_host->expavg_credit, $old_host->expavg_time); |
|
| 763 | + update_average($now, 0, 0, $new_host->expavg_credit, $new_host->expavg_time); |
|
| 764 | + |
|
| 765 | + // Update the database: |
|
| 766 | + // - add credit from old host to new host |
|
| 767 | + // - change results to refer to the new host |
|
| 768 | + // - put old host in "zombie" state (userid=0, rpc_seqno=[new_host_id]) |
|
| 769 | + |
|
| 770 | + $total_credit = $old_host->total_credit + $new_host->total_credit; |
|
| 771 | + $recent_credit = $old_host->expavg_credit + $new_host->expavg_credit; |
|
| 772 | + |
|
| 773 | + // Move credit from the old host to the new host |
|
| 774 | + db_set_active('boinc'); |
|
| 775 | + $credit_updated = db_query(" |
|
| 776 | 776 | UPDATE {host} |
| 777 | 777 | SET |
| 778 | 778 | total_credit = '%d', |
@@ -780,34 +780,34 @@ discard block |
||
| 780 | 780 | expavg_time = '%d' |
| 781 | 781 | WHERE id = '%d'", |
| 782 | 782 | $total_credit, $recent_credit, $now, $new_host->id |
| 783 | - ); |
|
| 784 | - db_set_active('default'); |
|
| 785 | - if (!$credit_updated) { |
|
| 783 | + ); |
|
| 784 | + db_set_active('default'); |
|
| 785 | + if (!$credit_updated) { |
|
| 786 | 786 | if ($message !== NULL) { |
| 787 | - $message = bts('Could not update credit'); |
|
| 787 | + $message = bts('Could not update credit'); |
|
| 788 | 788 | } |
| 789 | 789 | return FALSE; |
| 790 | - } |
|
| 790 | + } |
|
| 791 | 791 | |
| 792 | - // Move results from the old host to the new host |
|
| 793 | - db_set_active('boinc'); |
|
| 794 | - $results_updated = db_query(" |
|
| 792 | + // Move results from the old host to the new host |
|
| 793 | + db_set_active('boinc'); |
|
| 794 | + $results_updated = db_query(" |
|
| 795 | 795 | UPDATE {result} |
| 796 | 796 | SET hostid = '%d' |
| 797 | 797 | WHERE hostid = '%d'", |
| 798 | 798 | $new_host->id, $old_host->id |
| 799 | - ); |
|
| 800 | - db_set_active('default'); |
|
| 801 | - if (!$results_updated) { |
|
| 799 | + ); |
|
| 800 | + db_set_active('default'); |
|
| 801 | + if (!$results_updated) { |
|
| 802 | 802 | if ($message !== NULL) { |
| 803 | - $message = bts('Could not update results'); |
|
| 803 | + $message = bts('Could not update results'); |
|
| 804 | 804 | } |
| 805 | 805 | return FALSE; |
| 806 | - } |
|
| 806 | + } |
|
| 807 | 807 | |
| 808 | - // Retire the old host |
|
| 809 | - db_set_active('boinc'); |
|
| 810 | - $old_host_retired = db_query(" |
|
| 808 | + // Retire the old host |
|
| 809 | + db_set_active('boinc'); |
|
| 810 | + $old_host_retired = db_query(" |
|
| 811 | 811 | UPDATE {host} |
| 812 | 812 | SET |
| 813 | 813 | total_credit = '0', |
@@ -816,16 +816,16 @@ discard block |
||
| 816 | 816 | rpc_seqno = '%d' |
| 817 | 817 | WHERE id = '%d'", |
| 818 | 818 | $new_host->id, $old_host->id |
| 819 | - ); |
|
| 820 | - db_set_active('default'); |
|
| 821 | - if (!$old_host_retired) { |
|
| 819 | + ); |
|
| 820 | + db_set_active('default'); |
|
| 821 | + if (!$old_host_retired) { |
|
| 822 | 822 | if ($message !== NULL) { |
| 823 | - $message = bts('Could not retire old computer'); |
|
| 823 | + $message = bts('Could not retire old computer'); |
|
| 824 | 824 | } |
| 825 | 825 | return FALSE; |
| 826 | - } |
|
| 826 | + } |
|
| 827 | 827 | |
| 828 | - return TRUE; |
|
| 828 | + return TRUE; |
|
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | /** |
@@ -833,75 +833,75 @@ discard block |
||
| 833 | 833 | */ |
| 834 | 834 | function boincwork_host_merge_form(&$form_state, $host_id) { |
| 835 | 835 | |
| 836 | - if (!boincwork_host_user_is_owner($host_id)) { |
|
| 836 | + if (!boincwork_host_user_is_owner($host_id)) { |
|
| 837 | 837 | drupal_goto("host/{$host_id}"); |
| 838 | - } |
|
| 838 | + } |
|
| 839 | 839 | |
| 840 | - $form = array(); |
|
| 841 | - $form_state['storage']['current_host_id'] = $host_id; |
|
| 842 | - $current_host = boincwork_host_get_info($host_id); |
|
| 840 | + $form = array(); |
|
| 841 | + $form_state['storage']['current_host_id'] = $host_id; |
|
| 842 | + $current_host = boincwork_host_get_info($host_id); |
|
| 843 | 843 | |
| 844 | - // Get hosts that could be merged with this one |
|
| 845 | - $hosts = boincwork_host_get_compatible_hosts($host_id); |
|
| 844 | + // Get hosts that could be merged with this one |
|
| 845 | + $hosts = boincwork_host_get_compatible_hosts($host_id); |
|
| 846 | 846 | |
| 847 | - if (!$hosts) { |
|
| 847 | + if (!$hosts) { |
|
| 848 | 848 | drupal_set_message(t('There are no computers eligible for merging with this |
| 849 | 849 | one'), 'warning' |
| 850 | 850 | ); |
| 851 | 851 | drupal_goto("host/{$host_id}"); |
| 852 | - } |
|
| 852 | + } |
|
| 853 | 853 | |
| 854 | - $form['overview'] = array( |
|
| 854 | + $form['overview'] = array( |
|
| 855 | 855 | '#value' => '<p>' . bts('Sometimes BOINC assigns separate identities to' |
| 856 | - . ' the same computer by mistake. You can correct this by merging old' |
|
| 857 | - . ' identities with the newest one.') . '</p>' |
|
| 858 | - . '<p>' |
|
| 859 | - . bts('Check the computers that are the same as @name' |
|
| 860 | - . ' (created on @date at @time with computer ID @id)', |
|
| 856 | + . ' the same computer by mistake. You can correct this by merging old' |
|
| 857 | + . ' identities with the newest one.') . '</p>' |
|
| 858 | + . '<p>' |
|
| 859 | + . bts('Check the computers that are the same as @name' |
|
| 860 | + . ' (created on @date at @time with computer ID @id)', |
|
| 861 | 861 | array( |
| 862 | - '@name' => $current_host->domain_name, |
|
| 863 | - '@date' => date('j M Y', $current_host->create_time), |
|
| 864 | - '@time' => date('H:i:s T', $current_host->create_time), |
|
| 865 | - '@id' => $current_host->id, |
|
| 862 | + '@name' => $current_host->domain_name, |
|
| 863 | + '@date' => date('j M Y', $current_host->create_time), |
|
| 864 | + '@time' => date('H:i:s T', $current_host->create_time), |
|
| 865 | + '@id' => $current_host->id, |
|
| 866 | 866 | ) |
| 867 | - ) . '</p>', |
|
| 868 | - ); |
|
| 867 | + ) . '</p>', |
|
| 868 | + ); |
|
| 869 | 869 | |
| 870 | - $options = array(); |
|
| 871 | - foreach ($hosts as $host) { |
|
| 870 | + $options = array(); |
|
| 871 | + foreach ($hosts as $host) { |
|
| 872 | 872 | $options[$host->id] = array( |
| 873 | - $host->domain_name, |
|
| 874 | - date('j M Y H:i:s T', $host->create_time), |
|
| 875 | - $host->id, |
|
| 873 | + $host->domain_name, |
|
| 874 | + date('j M Y H:i:s T', $host->create_time), |
|
| 875 | + $host->id, |
|
| 876 | 876 | ); |
| 877 | - } |
|
| 877 | + } |
|
| 878 | 878 | |
| 879 | - $form['merge'] = array( |
|
| 879 | + $form['merge'] = array( |
|
| 880 | 880 | '#title' => '', |
| 881 | 881 | '#type' => 'tableselect', |
| 882 | 882 | '#header' => array(bts('Name'), bts('Created'), bts('Computer ID')), |
| 883 | 883 | '#options' => $options, |
| 884 | - ); |
|
| 884 | + ); |
|
| 885 | 885 | |
| 886 | - $form['prefs']['separator_bottom'] = array( |
|
| 887 | - // '#value' => '<div class="separator buttons"></div>' |
|
| 888 | - ); |
|
| 886 | + $form['prefs']['separator_bottom'] = array( |
|
| 887 | + // '#value' => '<div class="separator buttons"></div>' |
|
| 888 | + ); |
|
| 889 | 889 | |
| 890 | - // Form control |
|
| 891 | - $form['prefs']['form control tabs prefix'] = array( |
|
| 890 | + // Form control |
|
| 891 | + $form['prefs']['form control tabs prefix'] = array( |
|
| 892 | 892 | '#value' => '<ul class="form-control tab-list">' |
| 893 | - ); |
|
| 894 | - $form['prefs']['submit'] = array( |
|
| 893 | + ); |
|
| 894 | + $form['prefs']['submit'] = array( |
|
| 895 | 895 | '#prefix' => '<li class="first tab">', |
| 896 | 896 | '#type' => 'submit', |
| 897 | 897 | '#value' => bts('Merge'), |
| 898 | 898 | '#suffix' => '</li>' |
| 899 | - ); |
|
| 900 | - $form['prefs']['form control tabs'] = array( |
|
| 899 | + ); |
|
| 900 | + $form['prefs']['form control tabs'] = array( |
|
| 901 | 901 | '#value' => '<li class="tab">' . l(bts('Cancel'), "host/{$host_id}") . '</li>' |
| 902 | - ); |
|
| 902 | + ); |
|
| 903 | 903 | |
| 904 | - return $form; |
|
| 904 | + return $form; |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -914,76 +914,76 @@ discard block |
||
| 914 | 914 | * Handle submission of the merge host form |
| 915 | 915 | */ |
| 916 | 916 | function boincwork_host_merge_form_submit($form, &$form_state) { |
| 917 | - $merged = array(); |
|
| 918 | - $errors = array(); |
|
| 919 | - $current_host_id = $form_state['storage']['current_host_id']; |
|
| 920 | - $current_host = boincwork_host_get_info($current_host_id); |
|
| 921 | - $selected_hosts = array_filter($form_state['values']['merge']); |
|
| 917 | + $merged = array(); |
|
| 918 | + $errors = array(); |
|
| 919 | + $current_host_id = $form_state['storage']['current_host_id']; |
|
| 920 | + $current_host = boincwork_host_get_info($current_host_id); |
|
| 921 | + $selected_hosts = array_filter($form_state['values']['merge']); |
|
| 922 | 922 | |
| 923 | - foreach ($selected_hosts as $host_id) { |
|
| 923 | + foreach ($selected_hosts as $host_id) { |
|
| 924 | 924 | // Attempt to merge each host, noting the results |
| 925 | 925 | $message = ''; |
| 926 | 926 | $old_host = boincwork_host_get_info($host_id); |
| 927 | 927 | if (boincwork_host_merge($old_host, $current_host, $message)) { |
| 928 | - $merged[$old_host->id] = $old_host->id; |
|
| 929 | - $current_host = boincwork_host_get_info($current_host_id); |
|
| 928 | + $merged[$old_host->id] = $old_host->id; |
|
| 929 | + $current_host = boincwork_host_get_info($current_host_id); |
|
| 930 | 930 | } |
| 931 | 931 | else { |
| 932 | - $errors[$old_host->id] = $message; |
|
| 932 | + $errors[$old_host->id] = $message; |
|
| 933 | + } |
|
| 933 | 934 | } |
| 934 | - } |
|
| 935 | 935 | |
| 936 | - if ($merged) { |
|
| 936 | + if ($merged) { |
|
| 937 | 937 | // Generate a natural language list of IDs that were merged |
| 938 | 938 | $oxford_comma = ','; |
| 939 | 939 | $conjunction = bts('and'); |
| 940 | 940 | $list = array_keys($merged); |
| 941 | 941 | $last = array_pop($list); |
| 942 | 942 | if ($list) { |
| 943 | - if (count($merged) == 2) { |
|
| 943 | + if (count($merged) == 2) { |
|
| 944 | 944 | $oxford_comma = ''; |
| 945 | - } |
|
| 946 | - $list = implode(', ', $list) . $oxford_comma . ' ' . $conjunction . ' ' . $last; |
|
| 945 | + } |
|
| 946 | + $list = implode(', ', $list) . $oxford_comma . ' ' . $conjunction . ' ' . $last; |
|
| 947 | 947 | } |
| 948 | 948 | else { |
| 949 | - $list = $last; |
|
| 949 | + $list = $last; |
|
| 950 | 950 | } |
| 951 | 951 | if (count($merged) == 1) { |
| 952 | - drupal_set_message(bts( |
|
| 952 | + drupal_set_message(bts( |
|
| 953 | 953 | 'Computer @old_id has been merged successfully into @id.', |
| 954 | 954 | array( |
| 955 | - '@old_id' => $list, |
|
| 956 | - '@id' => $current_host_id |
|
| 955 | + '@old_id' => $list, |
|
| 956 | + '@id' => $current_host_id |
|
| 957 | 957 | ) |
| 958 | - )); |
|
| 958 | + )); |
|
| 959 | 959 | } |
| 960 | 960 | else { |
| 961 | - drupal_set_message(bts( |
|
| 961 | + drupal_set_message(bts( |
|
| 962 | 962 | 'Computers @old_ids have been merged successfully into @id.', |
| 963 | 963 | array( |
| 964 | - '@old_ids' => $list, |
|
| 965 | - '@id' => $current_host_id |
|
| 964 | + '@old_ids' => $list, |
|
| 965 | + '@id' => $current_host_id |
|
| 966 | 966 | ) |
| 967 | - )); |
|
| 967 | + )); |
|
| 968 | + } |
|
| 968 | 969 | } |
| 969 | - } |
|
| 970 | 970 | |
| 971 | - if ($errors) { |
|
| 971 | + if ($errors) { |
|
| 972 | 972 | // Report any hosts that failed to merge |
| 973 | 973 | foreach ($errors as $id => $error) { |
| 974 | - drupal_set_message( |
|
| 974 | + drupal_set_message( |
|
| 975 | 975 | bts('Computer @old_id failed to merge: @message', |
| 976 | - array( |
|
| 976 | + array( |
|
| 977 | 977 | '@old_id' => $id, |
| 978 | 978 | '@message' => $error, |
| 979 | - ) |
|
| 979 | + ) |
|
| 980 | 980 | ), |
| 981 | 981 | 'warning' |
| 982 | - ); |
|
| 982 | + ); |
|
| 983 | + } |
|
| 983 | 984 | } |
| 984 | - } |
|
| 985 | 985 | |
| 986 | - drupal_goto("host/{$current_host_id}"); |
|
| 986 | + drupal_goto("host/{$current_host_id}"); |
|
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * |
@@ -995,38 +995,38 @@ discard block |
||
| 995 | 995 | */ |
| 996 | 996 | function boincwork_projectprefs_form(&$form_state, $venue) { |
| 997 | 997 | |
| 998 | - global $user; |
|
| 999 | - $account = user_load($user->uid); |
|
| 998 | + global $user; |
|
| 999 | + $account = user_load($user->uid); |
|
| 1000 | 1000 | |
| 1001 | - $established = TRUE; |
|
| 1001 | + $established = TRUE; |
|
| 1002 | 1002 | |
| 1003 | - // Get availability of special BOINC preferences |
|
| 1004 | - require_boinc(array('util')); |
|
| 1005 | - $app_types = get_app_types(); |
|
| 1003 | + // Get availability of special BOINC preferences |
|
| 1004 | + require_boinc(array('util')); |
|
| 1005 | + $app_types = get_app_types(); |
|
| 1006 | 1006 | |
| 1007 | - // Load any existing preferences from BOINC account |
|
| 1008 | - $prefs = boincwork_load_prefs('project', $venue); |
|
| 1007 | + // Load any existing preferences from BOINC account |
|
| 1008 | + $prefs = boincwork_load_prefs('project', $venue); |
|
| 1009 | 1009 | |
| 1010 | - // Take note if this is not an established preference set on the account |
|
| 1011 | - if (isset($prefs['@attributes']['cleared'])) { |
|
| 1010 | + // Take note if this is not an established preference set on the account |
|
| 1011 | + if (isset($prefs['@attributes']['cleared'])) { |
|
| 1012 | 1012 | $established = FALSE; |
| 1013 | - } |
|
| 1013 | + } |
|
| 1014 | 1014 | |
| 1015 | - $venue_is_default = FALSE; |
|
| 1016 | - if ($account->boincuser_default_pref_set) { |
|
| 1015 | + $venue_is_default = FALSE; |
|
| 1016 | + if ($account->boincuser_default_pref_set) { |
|
| 1017 | 1017 | if ($account->boincuser_default_pref_set == $venue) { |
| 1018 | - $venue_is_default = TRUE; |
|
| 1018 | + $venue_is_default = TRUE; |
|
| 1019 | + } |
|
| 1019 | 1020 | } |
| 1020 | - } |
|
| 1021 | - elseif (!$venue OR $venue == 'generic') { |
|
| 1021 | + elseif (!$venue OR $venue == 'generic') { |
|
| 1022 | 1022 | $venue_is_default = TRUE; |
| 1023 | - } |
|
| 1024 | - else { |
|
| 1023 | + } |
|
| 1024 | + else { |
|
| 1025 | 1025 | $venue_is_default = FALSE; |
| 1026 | - } |
|
| 1026 | + } |
|
| 1027 | 1027 | |
| 1028 | - // Define form defaults |
|
| 1029 | - $default = array( |
|
| 1028 | + // Define form defaults |
|
| 1029 | + $default = array( |
|
| 1030 | 1030 | 'resource_share' => 100, |
| 1031 | 1031 | 'no_cpu' => 0, |
| 1032 | 1032 | 'no_cuda' => 0, |
@@ -1034,329 +1034,329 @@ discard block |
||
| 1034 | 1034 | 'no_intel_gpu' => 0, |
| 1035 | 1035 | 'default_venue' => $venue_is_default, |
| 1036 | 1036 | 'allow_beta_work' => $prefs['allow_beta_work'], |
| 1037 | - ); |
|
| 1038 | - foreach ($default as $name => $value) { |
|
| 1037 | + ); |
|
| 1038 | + foreach ($default as $name => $value) { |
|
| 1039 | 1039 | if (isset($prefs[$name])) { |
| 1040 | - if (is_array($prefs[$name])) { |
|
| 1040 | + if (is_array($prefs[$name])) { |
|
| 1041 | 1041 | if (isset($prefs[$name]['@value'])) { |
| 1042 | - $default[$name] = $prefs[$name]['@value']; |
|
| 1042 | + $default[$name] = $prefs[$name]['@value']; |
|
| 1043 | 1043 | } |
| 1044 | - } |
|
| 1045 | - else { |
|
| 1044 | + } |
|
| 1045 | + else { |
|
| 1046 | 1046 | $default[$name] = $prefs[$name]; |
| 1047 | - } |
|
| 1047 | + } |
|
| 1048 | + } |
|
| 1048 | 1049 | } |
| 1049 | - } |
|
| 1050 | 1050 | |
| 1051 | - // Standard option sets |
|
| 1052 | - $form['boolean_options'] = array( |
|
| 1051 | + // Standard option sets |
|
| 1052 | + $form['boolean_options'] = array( |
|
| 1053 | 1053 | '#type' => 'value', |
| 1054 | 1054 | '#value' => array(1 => bts('yes'), 0 => bts('no')) |
| 1055 | - ); |
|
| 1055 | + ); |
|
| 1056 | 1056 | |
| 1057 | - // Identify preference sets that are established to distinguish what has been |
|
| 1058 | - // saved to the database from what is just showing default values |
|
| 1059 | - $form['#established'] = $established; |
|
| 1057 | + // Identify preference sets that are established to distinguish what has been |
|
| 1058 | + // saved to the database from what is just showing default values |
|
| 1059 | + $form['#established'] = $established; |
|
| 1060 | 1060 | |
| 1061 | - // Top level form options |
|
| 1062 | - $form['#tree'] = TRUE; |
|
| 1061 | + // Top level form options |
|
| 1062 | + $form['#tree'] = TRUE; |
|
| 1063 | 1063 | |
| 1064 | - // Hidden elements |
|
| 1065 | - $form['venue'] = array( |
|
| 1064 | + // Hidden elements |
|
| 1065 | + $form['venue'] = array( |
|
| 1066 | 1066 | '#type' => 'hidden', |
| 1067 | 1067 | '#value' => $venue |
| 1068 | - ); |
|
| 1068 | + ); |
|
| 1069 | 1069 | |
| 1070 | - $form['separator_top'] = array( |
|
| 1070 | + $form['separator_top'] = array( |
|
| 1071 | 1071 | '#value' => '<div class="separator"></div>' |
| 1072 | - ); |
|
| 1072 | + ); |
|
| 1073 | 1073 | |
| 1074 | - // Common project preferences |
|
| 1075 | - $form['resource'] = array( |
|
| 1074 | + // Common project preferences |
|
| 1075 | + $form['resource'] = array( |
|
| 1076 | 1076 | '#title' => bts('Resource settings'), |
| 1077 | 1077 | '#type' => 'fieldset', |
| 1078 | 1078 | '#description' => null, |
| 1079 | 1079 | '#collapsible' => TRUE, |
| 1080 | 1080 | '#collapsed' => FALSE |
| 1081 | - ); |
|
| 1082 | - $form['resource']['resource_share'] = array( |
|
| 1081 | + ); |
|
| 1082 | + $form['resource']['resource_share'] = array( |
|
| 1083 | 1083 | '#title' => bts('Resource share'), |
| 1084 | 1084 | '#type' => 'textfield', |
| 1085 | 1085 | '#default_value' => $default['resource_share'], |
| 1086 | 1086 | '#size' => 5, |
| 1087 | 1087 | '#description' => bts("Determines the proportion of your computer's resources allocated to this project. Example: if you participate in two BOINC projects with resource shares of 100 and 200, the first will get 1/3 of your resources and the second will get 2/3.") |
| 1088 | - ); |
|
| 1089 | - if ($app_types->count > 1) { |
|
| 1088 | + ); |
|
| 1089 | + if ($app_types->count > 1) { |
|
| 1090 | 1090 | if ($app_types->cpu) { |
| 1091 | - $form['resource']['no_cpu'] = array( |
|
| 1091 | + $form['resource']['no_cpu'] = array( |
|
| 1092 | 1092 | '#title' => bts('Use CPU'), |
| 1093 | 1093 | '#type' => 'radios', |
| 1094 | 1094 | '#options' => $form['boolean_options']['#value'], |
| 1095 | 1095 | '#attributes' => array('class' => 'fancy'), |
| 1096 | 1096 | '#default_value' => $default['no_cpu'] ? 0 : 1, |
| 1097 | 1097 | '#description' => bts('Request CPU-only tasks from this project.') |
| 1098 | - ); |
|
| 1098 | + ); |
|
| 1099 | 1099 | } |
| 1100 | 1100 | if ($app_types->cuda) { |
| 1101 | - $form['resource']['no_cuda'] = array( |
|
| 1101 | + $form['resource']['no_cuda'] = array( |
|
| 1102 | 1102 | '#title' => bts('Use NVIDIA GPU'), |
| 1103 | 1103 | '#type' => 'radios', |
| 1104 | 1104 | '#options' => $form['boolean_options']['#value'], |
| 1105 | 1105 | '#attributes' => array('class' => 'fancy'), |
| 1106 | 1106 | '#default_value' => $default['no_cuda'] ? 0 : 1, |
| 1107 | 1107 | '#description' => bts('Request NVIDIA GPU tasks from this project.') |
| 1108 | - ); |
|
| 1108 | + ); |
|
| 1109 | 1109 | } |
| 1110 | 1110 | if ($app_types->ati) { |
| 1111 | - $form['resource']['no_ati'] = array( |
|
| 1111 | + $form['resource']['no_ati'] = array( |
|
| 1112 | 1112 | '#title' => bts('Use ATI GPU'), |
| 1113 | 1113 | '#type' => 'radios', |
| 1114 | 1114 | '#options' => $form['boolean_options']['#value'], |
| 1115 | 1115 | '#attributes' => array('class' => 'fancy'), |
| 1116 | 1116 | '#default_value' => $default['no_ati'] ? 0 : 1, |
| 1117 | 1117 | '#description' => bts('Request ATI GPU tasks from this project.') |
| 1118 | - ); |
|
| 1118 | + ); |
|
| 1119 | 1119 | } |
| 1120 | 1120 | if ($app_types->intel_gpu) { |
| 1121 | - $form['resource']['no_intel_gpu'] = array( |
|
| 1121 | + $form['resource']['no_intel_gpu'] = array( |
|
| 1122 | 1122 | '#title' => bts('Use INTEL GPU'), |
| 1123 | 1123 | '#type' => 'radios', |
| 1124 | 1124 | '#options' => $form['boolean_options']['#value'], |
| 1125 | 1125 | '#attributes' => array('class' => 'fancy'), |
| 1126 | 1126 | '#default_value' => $default['no_intel_gpu'] ? 0 : 1, |
| 1127 | 1127 | '#description' => bts('Request Intel GPU tasks from this project.') |
| 1128 | - ); |
|
| 1128 | + ); |
|
| 1129 | + } |
|
| 1129 | 1130 | } |
| 1130 | - } |
|
| 1131 | 1131 | |
| 1132 | - if (variable_get('boinc_prefs_options_beta', FALSE)) { |
|
| 1132 | + if (variable_get('boinc_prefs_options_beta', FALSE)) { |
|
| 1133 | 1133 | $form['beta'] = array( |
| 1134 | - '#title' => bts('Beta settings'), |
|
| 1135 | - '#type' => 'fieldset', |
|
| 1136 | - '#description' => null, |
|
| 1137 | - '#collapsible' => TRUE, |
|
| 1138 | - '#collapsed' => FALSE |
|
| 1134 | + '#title' => bts('Beta settings'), |
|
| 1135 | + '#type' => 'fieldset', |
|
| 1136 | + '#description' => null, |
|
| 1137 | + '#collapsible' => TRUE, |
|
| 1138 | + '#collapsed' => FALSE |
|
| 1139 | 1139 | ); |
| 1140 | 1140 | $form['beta']['allow_beta_work'] = array( |
| 1141 | - '#title' => bts('Run test applications?'), |
|
| 1142 | - '#type' => 'radios', |
|
| 1143 | - '#options' => $form['boolean_options']['#value'], |
|
| 1144 | - '#attributes' => array('class' => 'fancy'), |
|
| 1145 | - '#default_value' => ($default['allow_beta_work']) ? 1 : 0, |
|
| 1146 | - '#description' => bts('This helps us develop applications, but may cause jobs to fail on your computer') |
|
| 1141 | + '#title' => bts('Run test applications?'), |
|
| 1142 | + '#type' => 'radios', |
|
| 1143 | + '#options' => $form['boolean_options']['#value'], |
|
| 1144 | + '#attributes' => array('class' => 'fancy'), |
|
| 1145 | + '#default_value' => ($default['allow_beta_work']) ? 1 : 0, |
|
| 1146 | + '#description' => bts('This helps us develop applications, but may cause jobs to fail on your computer') |
|
| 1147 | 1147 | ); |
| 1148 | - } |
|
| 1148 | + } |
|
| 1149 | 1149 | |
| 1150 | - // Add project specific prefs to the form |
|
| 1151 | - boincwork_add_project_specific_prefs($form, $prefs); |
|
| 1150 | + // Add project specific prefs to the form |
|
| 1151 | + boincwork_add_project_specific_prefs($form, $prefs); |
|
| 1152 | 1152 | |
| 1153 | - // Set whether to use this preference set by default for new computers |
|
| 1154 | - $form['default_set'] = array( |
|
| 1153 | + // Set whether to use this preference set by default for new computers |
|
| 1154 | + $form['default_set'] = array( |
|
| 1155 | 1155 | '#title' => bts('Default set'), |
| 1156 | 1156 | '#type' => 'fieldset', |
| 1157 | 1157 | '#description' => null, |
| 1158 | 1158 | '#collapsible' => TRUE, |
| 1159 | 1159 | '#collapsed' => FALSE |
| 1160 | - ); |
|
| 1161 | - $form['default_set']['default_venue'] = array( |
|
| 1160 | + ); |
|
| 1161 | + $form['default_set']['default_venue'] = array( |
|
| 1162 | 1162 | '#title' => bts('Set used for new computers'), |
| 1163 | 1163 | '#type' => 'radios', |
| 1164 | 1164 | '#options' => $form['boolean_options']['#value'], |
| 1165 | 1165 | '#attributes' => array('class' => 'fancy'), |
| 1166 | 1166 | '#default_value' => $default['default_venue'] ? 1 : 0, |
| 1167 | 1167 | '#description' => '' |
| 1168 | - ); |
|
| 1168 | + ); |
|
| 1169 | 1169 | |
| 1170 | - $form['prefs']['separator_bottom'] = array( |
|
| 1170 | + $form['prefs']['separator_bottom'] = array( |
|
| 1171 | 1171 | '#value' => '<div class="separator buttons"></div>' |
| 1172 | - ); |
|
| 1172 | + ); |
|
| 1173 | 1173 | |
| 1174 | - // Form control |
|
| 1175 | - $form['prefs']['form control tabs prefix'] = array( |
|
| 1174 | + // Form control |
|
| 1175 | + $form['prefs']['form control tabs prefix'] = array( |
|
| 1176 | 1176 | '#value' => '<ul class="form-control tab-list">' |
| 1177 | - ); |
|
| 1178 | - $form['prefs']['submit'] = array( |
|
| 1177 | + ); |
|
| 1178 | + $form['prefs']['submit'] = array( |
|
| 1179 | 1179 | '#prefix' => '<li class="first tab">', |
| 1180 | 1180 | '#type' => 'submit', |
| 1181 | 1181 | '#value' => bts('Save changes'), |
| 1182 | 1182 | '#suffix' => '</li>' |
| 1183 | - ); |
|
| 1184 | - $form['prefs']['form control tabs'] = array( |
|
| 1183 | + ); |
|
| 1184 | + $form['prefs']['form control tabs'] = array( |
|
| 1185 | 1185 | '#value' => '<li class="tab">' . l(bts('Cancel'), $_GET['q']) . '</li>' |
| 1186 | - ); |
|
| 1187 | - if ($venue AND $venue != 'generic') { |
|
| 1186 | + ); |
|
| 1187 | + if ($venue AND $venue != 'generic') { |
|
| 1188 | 1188 | global $base_path; |
| 1189 | 1189 | $form['prefs']['form control tabs']['#value'] .= '<li class="tab">' . |
| 1190 | - l(bts('Clear'), "account/prefs/project/clear/{$venue}", |
|
| 1190 | + l(bts('Clear'), "account/prefs/project/clear/{$venue}", |
|
| 1191 | 1191 | array( |
| 1192 | - 'query' => 'destination=' . urlencode(drupal_get_path_alias('account/prefs/project/combined')), |
|
| 1193 | - 'attributes' => array( |
|
| 1192 | + 'query' => 'destination=' . urlencode(drupal_get_path_alias('account/prefs/project/combined')), |
|
| 1193 | + 'attributes' => array( |
|
| 1194 | 1194 | 'onclick' => 'return confirm(\'' . bts('This will remove all of your settings from the @name preference set. Are you sure?', |
| 1195 | - array('@name' => $venue)) . '\')' |
|
| 1196 | - ) |
|
| 1195 | + array('@name' => $venue)) . '\')' |
|
| 1196 | + ) |
|
| 1197 | 1197 | ) |
| 1198 | - ) . '</li>'; |
|
| 1199 | - } |
|
| 1200 | - $form['prefs']['view control'] = array( |
|
| 1198 | + ) . '</li>'; |
|
| 1199 | + } |
|
| 1200 | + $form['prefs']['view control'] = array( |
|
| 1201 | 1201 | '#value' => '<li class="first alt tab">' . l('(' . bts('Show comparison view') . ')', 'account/prefs/project/combined') . '</li>' |
| 1202 | - ); |
|
| 1203 | - $form['prefs']['form control tabs suffix'] = array( |
|
| 1202 | + ); |
|
| 1203 | + $form['prefs']['form control tabs suffix'] = array( |
|
| 1204 | 1204 | '#value' => '</ul>' |
| 1205 | - ); |
|
| 1205 | + ); |
|
| 1206 | 1206 | |
| 1207 | - return $form; |
|
| 1207 | + return $form; |
|
| 1208 | 1208 | } |
| 1209 | 1209 | |
| 1210 | 1210 | /** |
| 1211 | 1211 | * Add project specific preferences to the project preferences form |
| 1212 | 1212 | */ |
| 1213 | 1213 | function boincwork_add_project_specific_prefs(&$form, $prefs) { |
| 1214 | - // Load project specific preferences from XML config |
|
| 1215 | - $xml = boincwork_get_project_specific_config(); |
|
| 1214 | + // Load project specific preferences from XML config |
|
| 1215 | + $xml = boincwork_get_project_specific_config(); |
|
| 1216 | 1216 | |
| 1217 | - // Respect the order of the top level elements |
|
| 1218 | - $ordered_array = array(); |
|
| 1219 | - $unordered_array = array(); |
|
| 1220 | - foreach ($xml['project_specific_preferences'] as $type => $element) { |
|
| 1217 | + // Respect the order of the top level elements |
|
| 1218 | + $ordered_array = array(); |
|
| 1219 | + $unordered_array = array(); |
|
| 1220 | + foreach ($xml['project_specific_preferences'] as $type => $element) { |
|
| 1221 | 1221 | if (is_array($element) AND is_numeric(key($element))) { |
| 1222 | - foreach ($element as $ordered_element) { |
|
| 1222 | + foreach ($element as $ordered_element) { |
|
| 1223 | 1223 | if (isset($ordered_element['@position'])) { |
| 1224 | - $ordered_array[$ordered_element['@position']] = array($type => $ordered_element); |
|
| 1224 | + $ordered_array[$ordered_element['@position']] = array($type => $ordered_element); |
|
| 1225 | 1225 | } |
| 1226 | 1226 | else { |
| 1227 | - $unordered_array[] = array($type => $ordered_element); |
|
| 1227 | + $unordered_array[] = array($type => $ordered_element); |
|
| 1228 | + } |
|
| 1228 | 1229 | } |
| 1229 | - } |
|
| 1230 | 1230 | } |
| 1231 | 1231 | elseif (isset($element['@position'])) { |
| 1232 | - $ordered_array[$element['@position']] = array($type => $element); |
|
| 1232 | + $ordered_array[$element['@position']] = array($type => $element); |
|
| 1233 | 1233 | } |
| 1234 | 1234 | else { |
| 1235 | - $unordered_array[] = array($type => $element); |
|
| 1235 | + $unordered_array[] = array($type => $element); |
|
| 1236 | + } |
|
| 1236 | 1237 | } |
| 1237 | - } |
|
| 1238 | - ksort($ordered_array); |
|
| 1239 | - $primed_array = array_merge($ordered_array, $unordered_array); |
|
| 1240 | - $xml = array('project_specific_preferences' => $primed_array); |
|
| 1238 | + ksort($ordered_array); |
|
| 1239 | + $primed_array = array_merge($ordered_array, $unordered_array); |
|
| 1240 | + $xml = array('project_specific_preferences' => $primed_array); |
|
| 1241 | 1241 | |
| 1242 | - foreach ($xml['project_specific_preferences'] as $wrapped_element) { |
|
| 1242 | + foreach ($xml['project_specific_preferences'] as $wrapped_element) { |
|
| 1243 | 1243 | $type = key($wrapped_element); |
| 1244 | 1244 | $element= reset($wrapped_element); |
| 1245 | 1245 | boincwork_generate_prefs_element($form, $type, $element, $prefs['project_specific']); |
| 1246 | - } |
|
| 1246 | + } |
|
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | 1249 | /** |
| 1250 | - * Validate the project preferences form. |
|
| 1251 | - */ |
|
| 1250 | + * Validate the project preferences form. |
|
| 1251 | + */ |
|
| 1252 | 1252 | function boincwork_projectprefs_form_validate($form, &$form_state) { |
| 1253 | 1253 | |
| 1254 | - // Verify all text user input values and notify form API of failures |
|
| 1255 | - $validation_rules = array( |
|
| 1254 | + // Verify all text user input values and notify form API of failures |
|
| 1255 | + $validation_rules = array( |
|
| 1256 | 1256 | 'resource' => array( |
| 1257 | - 'resource_share' => array( |
|
| 1257 | + 'resource_share' => array( |
|
| 1258 | 1258 | 'datatype' => 'integer', |
| 1259 | 1259 | 'min' => 0 |
| 1260 | - ), |
|
| 1260 | + ), |
|
| 1261 | 1261 | ), |
| 1262 | - ); |
|
| 1262 | + ); |
|
| 1263 | 1263 | |
| 1264 | - // Add validation rules for project specific settings |
|
| 1265 | - $validation_rules += boincwork_get_project_specific_config_validation_rules(); |
|
| 1264 | + // Add validation rules for project specific settings |
|
| 1265 | + $validation_rules += boincwork_get_project_specific_config_validation_rules(); |
|
| 1266 | 1266 | |
| 1267 | - // Perform validation |
|
| 1268 | - boincwork_validate_form($validation_rules, $form_state['values']); |
|
| 1267 | + // Perform validation |
|
| 1268 | + boincwork_validate_form($validation_rules, $form_state['values']); |
|
| 1269 | 1269 | |
| 1270 | - // Check for app validation |
|
| 1271 | - if (isset($validation_rules['apps'])) { |
|
| 1270 | + // Check for app validation |
|
| 1271 | + if (isset($validation_rules['apps'])) { |
|
| 1272 | 1272 | if (isset($validation_rules['apps']['minimum selected']) |
| 1273 | 1273 | AND $validation_rules['apps']['minimum selected'] > 0) { |
| 1274 | - $apps_selected = 0; |
|
| 1275 | - foreach ($validation_rules['apps']['list'] as $app) { |
|
| 1274 | + $apps_selected = 0; |
|
| 1275 | + foreach ($validation_rules['apps']['list'] as $app) { |
|
| 1276 | 1276 | if ($form_state['values']['applications'][$app]) $apps_selected++; |
| 1277 | - } |
|
| 1278 | - if ($apps_selected < $validation_rules['apps']['minimum selected']) { |
|
| 1277 | + } |
|
| 1278 | + if ($apps_selected < $validation_rules['apps']['minimum selected']) { |
|
| 1279 | 1279 | form_set_error( |
| 1280 | - 'applications', |
|
| 1281 | - bts('At least one application must be selected') |
|
| 1280 | + 'applications', |
|
| 1281 | + bts('At least one application must be selected') |
|
| 1282 | 1282 | ); |
| 1283 | - } |
|
| 1284 | - if ($apps_selected == count($validation_rules['apps']['list'])) { |
|
| 1283 | + } |
|
| 1284 | + if ($apps_selected == count($validation_rules['apps']['list'])) { |
|
| 1285 | 1285 | foreach ($validation_rules['apps']['list'] as $app) { |
| 1286 | - unset($form_state['values']['applications'][$app]); |
|
| 1286 | + unset($form_state['values']['applications'][$app]); |
|
| 1287 | 1287 | } |
| 1288 | 1288 | $form_state['storage']['all apps selected'] = TRUE; |
| 1289 | - } |
|
| 1289 | + } |
|
| 1290 | + } |
|
| 1290 | 1291 | } |
| 1291 | - } |
|
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | 1294 | /** |
| 1295 | - * Handle post-validation submission of project preferences form. |
|
| 1296 | - */ |
|
| 1295 | + * Handle post-validation submission of project preferences form. |
|
| 1296 | + */ |
|
| 1297 | 1297 | function boincwork_projectprefs_form_submit($form, &$form_state) { |
| 1298 | - global $user; |
|
| 1299 | - global $site_name; |
|
| 1298 | + global $user; |
|
| 1299 | + global $site_name; |
|
| 1300 | 1300 | |
| 1301 | - require_boinc(array('util')); |
|
| 1302 | - $app_types = get_app_types(); |
|
| 1301 | + require_boinc(array('util')); |
|
| 1302 | + $app_types = get_app_types(); |
|
| 1303 | 1303 | |
| 1304 | - $account = user_load($user->uid); |
|
| 1305 | - $edit = $form_state['values']; |
|
| 1306 | - $venue = $edit['venue']; |
|
| 1304 | + $account = user_load($user->uid); |
|
| 1305 | + $edit = $form_state['values']; |
|
| 1306 | + $venue = $edit['venue']; |
|
| 1307 | 1307 | |
| 1308 | - // Load preferences from BOINC account |
|
| 1309 | - $prefs = boincwork_load_prefs('project', $venue); |
|
| 1308 | + // Load preferences from BOINC account |
|
| 1309 | + $prefs = boincwork_load_prefs('project', $venue); |
|
| 1310 | 1310 | |
| 1311 | - // Resource preferences |
|
| 1312 | - $prefs['resource_share'] = $edit['resource']['resource_share']; |
|
| 1313 | - if ($app_types->count > 1) { |
|
| 1311 | + // Resource preferences |
|
| 1312 | + $prefs['resource_share'] = $edit['resource']['resource_share']; |
|
| 1313 | + if ($app_types->count > 1) { |
|
| 1314 | 1314 | if ($app_types->cpu) $prefs['no_cpu'] = ($edit['resource']['no_cpu']) ? 0 : 1; |
| 1315 | 1315 | if ($app_types->cuda) $prefs['no_cuda'] = ($edit['resource']['no_cuda']) ? 0 : 1; |
| 1316 | 1316 | if ($app_types->ati) $prefs['no_ati'] = ($edit['resource']['no_ati']) ? 0 : 1; |
| 1317 | 1317 | if ($app_types->intel_gpu) $prefs['no_intel_gpu'] = ($edit['resource']['no_intel_gpu']) ? 0 : 1; |
| 1318 | - } |
|
| 1318 | + } |
|
| 1319 | 1319 | |
| 1320 | - // Beta preferences |
|
| 1321 | - if (variable_get('boinc_prefs_options_beta', FALSE)) { |
|
| 1320 | + // Beta preferences |
|
| 1321 | + if (variable_get('boinc_prefs_options_beta', FALSE)) { |
|
| 1322 | 1322 | $prefs['allow_beta_work'] = ($edit['beta']['allow_beta_work']) ? 1 : 0; |
| 1323 | - } |
|
| 1323 | + } |
|
| 1324 | 1324 | |
| 1325 | - // Load project specific preferences from XML config |
|
| 1326 | - $xml = boincwork_get_project_specific_config(); |
|
| 1327 | - $updated_prefs = array( |
|
| 1325 | + // Load project specific preferences from XML config |
|
| 1326 | + $xml = boincwork_get_project_specific_config(); |
|
| 1327 | + $updated_prefs = array( |
|
| 1328 | 1328 | 'project_specific' => boincwork_format_project_specific_prefs_data($edit) |
| 1329 | - ); |
|
| 1330 | - $prefs = $updated_prefs + $prefs; |
|
| 1329 | + ); |
|
| 1330 | + $prefs = $updated_prefs + $prefs; |
|
| 1331 | 1331 | |
| 1332 | - // Don't specify apps if all are selected |
|
| 1333 | - if (isset($form_state['storage']['all apps selected'])) { |
|
| 1332 | + // Don't specify apps if all are selected |
|
| 1333 | + if (isset($form_state['storage']['all apps selected'])) { |
|
| 1334 | 1334 | unset($prefs['project_specific']['app_id']); |
| 1335 | 1335 | unset($form_state['storage']['all apps selected']); |
| 1336 | - } |
|
| 1336 | + } |
|
| 1337 | 1337 | |
| 1338 | - // If this is a new preference set, be sure to unset the "cleared" attribute |
|
| 1339 | - if (isset($prefs['@attributes']['cleared'])) { |
|
| 1338 | + // If this is a new preference set, be sure to unset the "cleared" attribute |
|
| 1339 | + if (isset($prefs['@attributes']['cleared'])) { |
|
| 1340 | 1340 | unset($prefs['@attributes']['cleared']); |
| 1341 | - } |
|
| 1341 | + } |
|
| 1342 | 1342 | |
| 1343 | - // Save preferences back to the BOINC account |
|
| 1344 | - $result = boincwork_save_prefs($prefs, 'project', $venue); |
|
| 1343 | + // Save preferences back to the BOINC account |
|
| 1344 | + $result = boincwork_save_prefs($prefs, 'project', $venue); |
|
| 1345 | 1345 | |
| 1346 | - // Update the user's default preference set |
|
| 1347 | - if ($edit['default_set']['default_venue']) { |
|
| 1346 | + // Update the user's default preference set |
|
| 1347 | + if ($edit['default_set']['default_venue']) { |
|
| 1348 | 1348 | boincwork_set_default_venue($venue); |
| 1349 | - } |
|
| 1350 | - elseif ($venue == $account->boincuser_default_pref_set) { |
|
| 1349 | + } |
|
| 1350 | + elseif ($venue == $account->boincuser_default_pref_set) { |
|
| 1351 | 1351 | // User has cleared out the default venue setting |
| 1352 | 1352 | boincwork_set_default_venue(); |
| 1353 | - } |
|
| 1353 | + } |
|
| 1354 | 1354 | |
| 1355 | - if (!$result) { |
|
| 1355 | + if (!$result) { |
|
| 1356 | 1356 | watchdog('boincwork', 'Error updating project prefs for user @id: @message', array('@id' => $user->id, '@message' => mysql_error()), WATCHDOG_ERROR); |
| 1357 | 1357 | drupal_set_message(t('Your changes could not be saved. Please contact support!'), 'error'); |
| 1358 | - } |
|
| 1359 | - elseif (!drupal_get_messages('status', FALSE)) { |
|
| 1358 | + } |
|
| 1359 | + elseif (!drupal_get_messages('status', FALSE)) { |
|
| 1360 | 1360 | // Show this message if the set wasn't created automatically (in which case |
| 1361 | 1361 | // there is a message tailored to that) |
| 1362 | 1362 | drupal_set_message(t('Your preferences have been updated. |
@@ -1364,53 +1364,53 @@ discard block |
||
| 1364 | 1364 | communicates with @project or you issue the "Update" |
| 1365 | 1365 | command from the BOINC client.', |
| 1366 | 1366 | array('@project' => $site_name))); |
| 1367 | - } |
|
| 1367 | + } |
|
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | 1370 | /** |
| 1371 | 1371 | * The structure of the community preferences form |
| 1372 | 1372 | */ |
| 1373 | 1373 | function communityprefs_form(&$form_state) { |
| 1374 | - global $user; |
|
| 1375 | - $account = user_load($user->uid); |
|
| 1376 | - $form = array(); |
|
| 1377 | - |
|
| 1378 | - // Pull in some elements from the profile form |
|
| 1379 | - $profile_form_state = array(); |
|
| 1380 | - $profile = new stdClass(); |
|
| 1381 | - $profile->type = 'profile'; |
|
| 1382 | - $profile->language = ''; |
|
| 1383 | - if ($profile_nid = content_profile_profile_exists($profile, $account->uid)) { |
|
| 1374 | + global $user; |
|
| 1375 | + $account = user_load($user->uid); |
|
| 1376 | + $form = array(); |
|
| 1377 | + |
|
| 1378 | + // Pull in some elements from the profile form |
|
| 1379 | + $profile_form_state = array(); |
|
| 1380 | + $profile = new stdClass(); |
|
| 1381 | + $profile->type = 'profile'; |
|
| 1382 | + $profile->language = ''; |
|
| 1383 | + if ($profile_nid = content_profile_profile_exists($profile, $account->uid)) { |
|
| 1384 | 1384 | $profile_node = node_load($profile_nid); |
| 1385 | 1385 | $form_state['storage']['profile_node'] = $profile_node; |
| 1386 | 1386 | module_load_include('inc', 'node', 'node.pages'); |
| 1387 | 1387 | $profile_form = drupal_retrieve_form('profile_node_form', $profile_form_state, $profile_node); |
| 1388 | 1388 | drupal_prepare_form('profile_node_form', $profile_form, $profile_form_state); |
| 1389 | - } |
|
| 1389 | + } |
|
| 1390 | 1390 | |
| 1391 | - // Standard option sets |
|
| 1392 | - $form['boolean_options'] = array( |
|
| 1391 | + // Standard option sets |
|
| 1392 | + $form['boolean_options'] = array( |
|
| 1393 | 1393 | '#type' => 'value', |
| 1394 | 1394 | '#value' => array(1 => bts('yes'), 0 => bts('no')) |
| 1395 | - ); |
|
| 1395 | + ); |
|
| 1396 | 1396 | |
| 1397 | - $default = array( |
|
| 1397 | + $default = array( |
|
| 1398 | 1398 | 'pm_send_notification' => '', // This is set already in pm_email_notify_user |
| 1399 | 1399 | 'friend_notification' => isset($account->friend_notification) ? $account->friend_notification : 0, |
| 1400 | 1400 | 'comments_per_page' => (isset($account->comments_per_page) AND $account->comments_per_page) ? $account->comments_per_page : variable_get('comment_default_per_page_forum', 50), |
| 1401 | 1401 | 'comments_order' => (isset($account->sort) AND $account->sort) ? $account->sort : variable_get('comment_default_order_forum', COMMENT_ORDER_OLDEST_FIRST), |
| 1402 | - ); |
|
| 1402 | + ); |
|
| 1403 | 1403 | |
| 1404 | - // General options |
|
| 1405 | - $form['general'] = array( |
|
| 1404 | + // General options |
|
| 1405 | + $form['general'] = array( |
|
| 1406 | 1406 | '#type' => 'fieldset', |
| 1407 | 1407 | '#title' => bts('General settings'), |
| 1408 | 1408 | '#weight' => 0, |
| 1409 | 1409 | '#collapsible' => TRUE, |
| 1410 | 1410 | '#collapsed' => FALSE |
| 1411 | - ); |
|
| 1412 | - // Add the BOINC user name (non-unique, user editable) |
|
| 1413 | - $form['general']['boincuser_name'] = array( |
|
| 1411 | + ); |
|
| 1412 | + // Add the BOINC user name (non-unique, user editable) |
|
| 1413 | + $form['general']['boincuser_name'] = array( |
|
| 1414 | 1414 | '#type' => 'textfield', |
| 1415 | 1415 | '#title' => bts('Name'), |
| 1416 | 1416 | '#default_value' => $account->boincuser_name, |
@@ -1418,239 +1418,239 @@ discard block |
||
| 1418 | 1418 | '#required' => TRUE, |
| 1419 | 1419 | '#description' => '', |
| 1420 | 1420 | '#size' => 40 |
| 1421 | - ); |
|
| 1422 | - // Time zone |
|
| 1423 | - if (variable_get('configurable_timezones', 1)) { |
|
| 1421 | + ); |
|
| 1422 | + // Time zone |
|
| 1423 | + if (variable_get('configurable_timezones', 1)) { |
|
| 1424 | 1424 | $zones = _system_zonelist(); |
| 1425 | 1425 | $form['general']['timezone'] = array( |
| 1426 | - '#type' => 'select', |
|
| 1427 | - '#title' => bts('Time zone'), |
|
| 1428 | - '#default_value' => ($account->timezone !== NULL) ? $account->timezone : variable_get('date_default_timezone', 0), |
|
| 1429 | - '#options' => $zones, |
|
| 1430 | - '#description' => '', |
|
| 1426 | + '#type' => 'select', |
|
| 1427 | + '#title' => bts('Time zone'), |
|
| 1428 | + '#default_value' => ($account->timezone !== NULL) ? $account->timezone : variable_get('date_default_timezone', 0), |
|
| 1429 | + '#options' => $zones, |
|
| 1430 | + '#description' => '', |
|
| 1431 | 1431 | ); |
| 1432 | - } |
|
| 1432 | + } |
|
| 1433 | 1433 | |
| 1434 | - // Notification options |
|
| 1435 | - $form['notifications'] = array( |
|
| 1434 | + // Notification options |
|
| 1435 | + $form['notifications'] = array( |
|
| 1436 | 1436 | '#type' => 'fieldset', |
| 1437 | 1437 | '#title' => bts('Notification settings'), |
| 1438 | 1438 | '#weight' => 5, |
| 1439 | 1439 | '#collapsible' => TRUE, |
| 1440 | 1440 | '#collapsed' => FALSE |
| 1441 | - ); |
|
| 1442 | - // Pull in private message notification handling and tweak the form |
|
| 1443 | - $pm_notify = pm_email_notify_user('form', $edit, $account, 'account'); |
|
| 1444 | - $form['notifications']['pm_send_notifications'] = array_replace( |
|
| 1441 | + ); |
|
| 1442 | + // Pull in private message notification handling and tweak the form |
|
| 1443 | + $pm_notify = pm_email_notify_user('form', $edit, $account, 'account'); |
|
| 1444 | + $form['notifications']['pm_send_notifications'] = array_replace( |
|
| 1445 | 1445 | $pm_notify['enable_pm_mail']['pm_send_notifications'], |
| 1446 | 1446 | array( |
| 1447 | - '#type' => 'radios', |
|
| 1448 | - '#title' => bts('Receive email notification for private messages?'), |
|
| 1449 | - '#description' => ' ', |
|
| 1450 | - '#options' => $form['boolean_options']['#value'], |
|
| 1451 | - '#attributes' => array('class' => 'fancy') |
|
| 1447 | + '#type' => 'radios', |
|
| 1448 | + '#title' => bts('Receive email notification for private messages?'), |
|
| 1449 | + '#description' => ' ', |
|
| 1450 | + '#options' => $form['boolean_options']['#value'], |
|
| 1451 | + '#attributes' => array('class' => 'fancy') |
|
| 1452 | 1452 | ) |
| 1453 | - ); |
|
| 1454 | - $form['notifications']['friend_notification'] = array( |
|
| 1453 | + ); |
|
| 1454 | + $form['notifications']['friend_notification'] = array( |
|
| 1455 | 1455 | '#type' => 'radios', |
| 1456 | 1456 | '#title' => bts('Receive email notification for friend requests?'), |
| 1457 | 1457 | '#description' => ' ', |
| 1458 | 1458 | '#options' => array(0 => bts('yes'), -1 => bts('no')), |
| 1459 | 1459 | '#attributes' => array('class' => 'fancy'), |
| 1460 | 1460 | '#default_value' => $default['friend_notification'] |
| 1461 | - ); |
|
| 1461 | + ); |
|
| 1462 | 1462 | |
| 1463 | - // Internationalization options |
|
| 1464 | - if (module_exists('internationalization')) { |
|
| 1463 | + // Internationalization options |
|
| 1464 | + if (module_exists('internationalization')) { |
|
| 1465 | 1465 | $languages = language_list('enabled'); |
| 1466 | 1466 | $languages = $languages[1]; |
| 1467 | 1467 | $names = array(); |
| 1468 | 1468 | foreach ($languages as $langcode => $item) { |
| 1469 | - $name = t($item->name); |
|
| 1470 | - $names[check_plain($langcode)] = check_plain($name . ($item->native != $name ? ' ('. $item->native .')' : '')); |
|
| 1469 | + $name = t($item->name); |
|
| 1470 | + $names[check_plain($langcode)] = check_plain($name . ($item->native != $name ? ' ('. $item->native .')' : '')); |
|
| 1471 | 1471 | } |
| 1472 | 1472 | $form['locale'] = array( |
| 1473 | - '#type' => 'fieldset', |
|
| 1474 | - '#title' => bts('Language settings'), |
|
| 1475 | - '#weight' => 10, |
|
| 1476 | - '#collapsible' => TRUE, |
|
| 1477 | - '#collapsed' => FALSE, |
|
| 1473 | + '#type' => 'fieldset', |
|
| 1474 | + '#title' => bts('Language settings'), |
|
| 1475 | + '#weight' => 10, |
|
| 1476 | + '#collapsible' => TRUE, |
|
| 1477 | + '#collapsed' => FALSE, |
|
| 1478 | 1478 | ); |
| 1479 | 1479 | |
| 1480 | 1480 | // Get language negotiation settings. |
| 1481 | 1481 | $mode = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE); |
| 1482 | 1482 | $user_preferred_language = user_preferred_language($account); |
| 1483 | 1483 | $form['locale']['language'] = array( |
| 1484 | - '#type' => 'select', |
|
| 1485 | - '#title' => bts('Language'), |
|
| 1486 | - '#default_value' => check_plain($user_preferred_language->language), |
|
| 1487 | - '#options' => $names, |
|
| 1488 | - '#description' => ($mode == LANGUAGE_NEGOTIATION_PATH) ? bts("This account's default language for e-mails and preferred language for site presentation.") : bts("This account's default language for e-mails."), |
|
| 1484 | + '#type' => 'select', |
|
| 1485 | + '#title' => bts('Language'), |
|
| 1486 | + '#default_value' => check_plain($user_preferred_language->language), |
|
| 1487 | + '#options' => $names, |
|
| 1488 | + '#description' => ($mode == LANGUAGE_NEGOTIATION_PATH) ? bts("This account's default language for e-mails and preferred language for site presentation.") : bts("This account's default language for e-mails."), |
|
| 1489 | 1489 | ); |
| 1490 | - } |
|
| 1490 | + } |
|
| 1491 | 1491 | |
| 1492 | - // Avatar options |
|
| 1493 | - $form['gravatar'] = array( |
|
| 1492 | + // Avatar options |
|
| 1493 | + $form['gravatar'] = array( |
|
| 1494 | 1494 | '#type' => 'item', |
| 1495 | 1495 | '#value' => bts('If you have a <a href="@gravatar-check">valid Gravatar</a> associated with your e-mail address, it will be used for your user picture.', array('@gravatar-check' => 'http://en.gravatar.com/site/check/' . $account->mail)), |
| 1496 | 1496 | '#description' => bts('Your Gravatar will not be shown if you upload a user picture.'), |
| 1497 | - ); |
|
| 1498 | - if (user_access('disable own gravatar', $account)) { |
|
| 1497 | + ); |
|
| 1498 | + if (user_access('disable own gravatar', $account)) { |
|
| 1499 | 1499 | $form['gravatar'] = array( |
| 1500 | - '#type' => 'checkbox', |
|
| 1501 | - '#title' => bts('If you have a <a href="@gravatar-check">valid Gravatar</a> associated with your e-mail address, use it for your user picture.', array('@gravatar-check' => 'http://en.gravatar.com/site/check/' . $account->mail)), |
|
| 1502 | - '#description' => bts('Gravatar will not be shown if an avatar is uploaded.'), |
|
| 1503 | - '#default_value' => isset($account->gravatar) ? $account->gravatar : 0, |
|
| 1504 | - '#disabled' => !empty($account->picture), |
|
| 1505 | - ); |
|
| 1506 | - } |
|
| 1507 | - $form['gravatar']['#weight'] = 15; |
|
| 1508 | - $form['gravatar']['#prefix'] = '<fieldset class="collapsible"><legend><a href="#">' . bts('Avatar settings') . '</a></legend>'; |
|
| 1509 | - // Upload an avatar (pulled from profile_node_form): |
|
| 1510 | - if (!empty($profile_form['field_image'])) { |
|
| 1500 | + '#type' => 'checkbox', |
|
| 1501 | + '#title' => bts('If you have a <a href="@gravatar-check">valid Gravatar</a> associated with your e-mail address, use it for your user picture.', array('@gravatar-check' => 'http://en.gravatar.com/site/check/' . $account->mail)), |
|
| 1502 | + '#description' => bts('Gravatar will not be shown if an avatar is uploaded.'), |
|
| 1503 | + '#default_value' => isset($account->gravatar) ? $account->gravatar : 0, |
|
| 1504 | + '#disabled' => !empty($account->picture), |
|
| 1505 | + ); |
|
| 1506 | + } |
|
| 1507 | + $form['gravatar']['#weight'] = 15; |
|
| 1508 | + $form['gravatar']['#prefix'] = '<fieldset class="collapsible"><legend><a href="#">' . bts('Avatar settings') . '</a></legend>'; |
|
| 1509 | + // Upload an avatar (pulled from profile_node_form): |
|
| 1510 | + if (!empty($profile_form['field_image'])) { |
|
| 1511 | 1511 | $form['field_image'] = $profile_form['field_image']; |
| 1512 | - } |
|
| 1513 | - else { |
|
| 1512 | + } |
|
| 1513 | + else { |
|
| 1514 | 1514 | $form['field_image'] = array( |
| 1515 | - '#value' => '<div class="form-item">' |
|
| 1515 | + '#value' => '<div class="form-item">' |
|
| 1516 | 1516 | . '<label class="placeholder">' |
| 1517 | 1517 | . bts('This is not available until your profile is set up.') |
| 1518 | 1518 | . '</label>' |
| 1519 | 1519 | . l(bts('Create a profile'), 'account/profile/edit', array('attributes' => array('class' => 'form-link'))) |
| 1520 | 1520 | . '</div>', |
| 1521 | 1521 | ); |
| 1522 | - } |
|
| 1523 | - $form['field_image'][0]['#title'] = bts('Upload an avatar'); |
|
| 1524 | - $form['field_image']['#weight'] = 20; |
|
| 1525 | - $form['field_image']['#suffix'] = '</fieldset>'; |
|
| 1522 | + } |
|
| 1523 | + $form['field_image'][0]['#title'] = bts('Upload an avatar'); |
|
| 1524 | + $form['field_image']['#weight'] = 20; |
|
| 1525 | + $form['field_image']['#suffix'] = '</fieldset>'; |
|
| 1526 | 1526 | |
| 1527 | - // Forum options |
|
| 1528 | - $form['forums'] = array( |
|
| 1527 | + // Forum options |
|
| 1528 | + $form['forums'] = array( |
|
| 1529 | 1529 | '#type' => 'fieldset', |
| 1530 | 1530 | '#title' => bts('Forum settings'), |
| 1531 | 1531 | '#weight' => 25, |
| 1532 | 1532 | '#collapsible' => TRUE, |
| 1533 | 1533 | '#collapsed' => FALSE |
| 1534 | - ); |
|
| 1535 | - $form['forums']['comments_per_page'] = array( |
|
| 1534 | + ); |
|
| 1535 | + $form['forums']['comments_per_page'] = array( |
|
| 1536 | 1536 | '#type' => 'select', |
| 1537 | 1537 | '#title' => bts('In discussion topics, show at most @comments_per_page', array('@comments_per_page' => '')), |
| 1538 | 1538 | '#options' => array(10 => 10, 20 => 20, 30 => 30, 50 => 50, 100 => 100), |
| 1539 | 1539 | '#default_value' => $default['comments_per_page'] |
| 1540 | - ); |
|
| 1541 | - // Can't have a typical Drupal form suffix on a select box? |
|
| 1542 | - $form['forums']['comments_per_page_suffix'] = array( |
|
| 1540 | + ); |
|
| 1541 | + // Can't have a typical Drupal form suffix on a select box? |
|
| 1542 | + $form['forums']['comments_per_page_suffix'] = array( |
|
| 1543 | 1543 | '#value' => '<span>' . bts('comments per page') . '</span>' |
| 1544 | - ); |
|
| 1545 | - $form['forums']['comments_order'] = array( |
|
| 1544 | + ); |
|
| 1545 | + $form['forums']['comments_order'] = array( |
|
| 1546 | 1546 | '#type' => 'select', |
| 1547 | 1547 | '#title' => bts('Sort comments in discussions'), |
| 1548 | 1548 | '#options' => array(1 => bts('Newest post first'), 2 => bts('Oldest post first')), |
| 1549 | 1549 | '#default_value' => $default['comments_order'] |
| 1550 | - ); |
|
| 1551 | - // Signature (pulled from user_edit_form): |
|
| 1552 | - if (variable_get('user_signatures', 0) && module_exists('comment')) { |
|
| 1550 | + ); |
|
| 1551 | + // Signature (pulled from user_edit_form): |
|
| 1552 | + if (variable_get('user_signatures', 0) && module_exists('comment')) { |
|
| 1553 | 1553 | $form['forums']['signature'] = array( |
| 1554 | - '#type' => 'textarea', |
|
| 1555 | - '#title' => bts('Signature'), |
|
| 1556 | - '#description' => bts('Your signature will be publicly displayed at the end of your comments.'), |
|
| 1557 | - '#default_value' => $account->signature |
|
| 1558 | - ); |
|
| 1554 | + '#type' => 'textarea', |
|
| 1555 | + '#title' => bts('Signature'), |
|
| 1556 | + '#description' => bts('Your signature will be publicly displayed at the end of your comments.'), |
|
| 1557 | + '#default_value' => $account->signature |
|
| 1558 | + ); |
|
| 1559 | 1559 | // Prevent a "validation error" message when the user attempts to save with a default value they |
| 1560 | 1560 | // do not have access to. |
| 1561 | 1561 | if (!filter_access($account->signature_format) && empty($_POST)) { |
| 1562 | - drupal_set_message(t("The signature input format has been set to a format you don't have access to. It will be changed to a format you have access to when you save this page.")); |
|
| 1563 | - $edit['signature_format'] = FILTER_FORMAT_DEFAULT; |
|
| 1562 | + drupal_set_message(t("The signature input format has been set to a format you don't have access to. It will be changed to a format you have access to when you save this page.")); |
|
| 1563 | + $edit['signature_format'] = FILTER_FORMAT_DEFAULT; |
|
| 1564 | 1564 | } |
| 1565 | 1565 | $form['forums']['signature_format'] = filter_form($account->signature_format, NULL, array('signature_format')); |
| 1566 | 1566 | // Optionally hide signatures from comments |
| 1567 | 1567 | $form['forums']['hide_signatures'] = array( |
| 1568 | - '#type' => 'radios', |
|
| 1569 | - '#title' => bts('Hide signatures in forums'), |
|
| 1570 | - '#description' => ' ', |
|
| 1571 | - '#options' => $form['boolean_options']['#value'], |
|
| 1572 | - '#attributes' => array('class' => 'fancy'), |
|
| 1573 | - '#default_value' => isset($account->hide_signatures) ? $account->hide_signatures : 0, |
|
| 1574 | - ); |
|
| 1575 | - } |
|
| 1568 | + '#type' => 'radios', |
|
| 1569 | + '#title' => bts('Hide signatures in forums'), |
|
| 1570 | + '#description' => ' ', |
|
| 1571 | + '#options' => $form['boolean_options']['#value'], |
|
| 1572 | + '#attributes' => array('class' => 'fancy'), |
|
| 1573 | + '#default_value' => isset($account->hide_signatures) ? $account->hide_signatures : 0, |
|
| 1574 | + ); |
|
| 1575 | + } |
|
| 1576 | 1576 | |
| 1577 | - //Ignored users list |
|
| 1578 | - if (module_exists('ignore_user')) { |
|
| 1577 | + //Ignored users list |
|
| 1578 | + if (module_exists('ignore_user')) { |
|
| 1579 | 1579 | $form['forums']['ignored_users'] = array( |
| 1580 | - '#value' => '<div class="form-item">' |
|
| 1580 | + '#value' => '<div class="form-item">' |
|
| 1581 | 1581 | . '<label>' |
| 1582 | - . bts('Ignore Users in forums:') |
|
| 1583 | - . '</label>' |
|
| 1582 | + . bts('Ignore Users in forums:') |
|
| 1583 | + . '</label>' |
|
| 1584 | 1584 | . bts('<a href="@ignore-user-list">View/Edit</a> your ignored users list.', |
| 1585 | - array( |
|
| 1586 | - '@ignore-user-list' => url('ignore_user/list'), |
|
| 1587 | - array('attributes' => array('class' => 'form-link')) |
|
| 1588 | - ) |
|
| 1589 | - ) |
|
| 1590 | - . '</div>', |
|
| 1591 | - ); |
|
| 1592 | - }//endif module_exists('ignore_user') |
|
| 1585 | + array( |
|
| 1586 | + '@ignore-user-list' => url('ignore_user/list'), |
|
| 1587 | + array('attributes' => array('class' => 'form-link')) |
|
| 1588 | + ) |
|
| 1589 | + ) |
|
| 1590 | + . '</div>', |
|
| 1591 | + ); |
|
| 1592 | + }//endif module_exists('ignore_user') |
|
| 1593 | 1593 | |
| 1594 | - //Bottom separator |
|
| 1595 | - $form['separator_bottom'] = array( |
|
| 1594 | + //Bottom separator |
|
| 1595 | + $form['separator_bottom'] = array( |
|
| 1596 | 1596 | '#value' => '<div class="separator buttons"></div>', |
| 1597 | 1597 | '#weight' => 999, |
| 1598 | - ); |
|
| 1598 | + ); |
|
| 1599 | 1599 | |
| 1600 | - // Form control |
|
| 1601 | - $form['form control tabs prefix'] = array( |
|
| 1600 | + // Form control |
|
| 1601 | + $form['form control tabs prefix'] = array( |
|
| 1602 | 1602 | '#value' => '<ul class="form-control tab-list">', |
| 1603 | 1603 | '#weight' => 1001, |
| 1604 | - ); |
|
| 1605 | - $form['submit'] = array( |
|
| 1604 | + ); |
|
| 1605 | + $form['submit'] = array( |
|
| 1606 | 1606 | '#prefix' => '<li class="first tab">', |
| 1607 | 1607 | '#type' => 'submit', |
| 1608 | 1608 | '#value' => bts('Save changes'), |
| 1609 | 1609 | '#suffix' => '</li>', |
| 1610 | 1610 | '#weight' => 1002, |
| 1611 | - ); |
|
| 1612 | - $form['form control tabs'] = array( |
|
| 1611 | + ); |
|
| 1612 | + $form['form control tabs'] = array( |
|
| 1613 | 1613 | '#value' => '<li class="tab">' . l(bts('Cancel'), $_GET['q']) . '</li>', |
| 1614 | 1614 | '#weight' => 1003, |
| 1615 | - ); |
|
| 1616 | - $form['form control tabs suffix'] = array( |
|
| 1615 | + ); |
|
| 1616 | + $form['form control tabs suffix'] = array( |
|
| 1617 | 1617 | '#value' => '</ul>', |
| 1618 | 1618 | '#weight' => 1004, |
| 1619 | - ); |
|
| 1620 | - return $form; |
|
| 1619 | + ); |
|
| 1620 | + return $form; |
|
| 1621 | 1621 | } |
| 1622 | 1622 | |
| 1623 | 1623 | /** |
| 1624 | - * Handle post-validation submission of community preferences form. |
|
| 1625 | - */ |
|
| 1624 | + * Handle post-validation submission of community preferences form. |
|
| 1625 | + */ |
|
| 1626 | 1626 | function communityprefs_form_submit($form, &$form_state) { |
| 1627 | - require_boinc('boinc_db'); |
|
| 1628 | - global $user; |
|
| 1629 | - $account = user_load($user->uid); |
|
| 1630 | - $boinc_user = BoincUser::lookup_id($account->boincuser_id); |
|
| 1631 | - $edit = $form_state['values']; |
|
| 1632 | - $profile_node = $form_state['storage']['profile_node']; |
|
| 1633 | - |
|
| 1634 | - // Display name |
|
| 1635 | - if ($edit['boincuser_name'] != $boinc_user->name) { |
|
| 1627 | + require_boinc('boinc_db'); |
|
| 1628 | + global $user; |
|
| 1629 | + $account = user_load($user->uid); |
|
| 1630 | + $boinc_user = BoincUser::lookup_id($account->boincuser_id); |
|
| 1631 | + $edit = $form_state['values']; |
|
| 1632 | + $profile_node = $form_state['storage']['profile_node']; |
|
| 1633 | + |
|
| 1634 | + // Display name |
|
| 1635 | + if ($edit['boincuser_name'] != $boinc_user->name) { |
|
| 1636 | 1636 | $boincuser_name = $edit['boincuser_name']; |
| 1637 | 1637 | $result = $boinc_user->update( |
| 1638 | 1638 | "name='{$boincuser_name}'" |
| 1639 | 1639 | ); |
| 1640 | - } |
|
| 1640 | + } |
|
| 1641 | 1641 | |
| 1642 | - // Private message settings |
|
| 1643 | - pm_email_notify_user('submit', $edit, $user); |
|
| 1642 | + // Private message settings |
|
| 1643 | + pm_email_notify_user('submit', $edit, $user); |
|
| 1644 | 1644 | |
| 1645 | - // Avatar settings |
|
| 1646 | - if (!$edit['field_image']) $edit['field_image'] = array(); |
|
| 1647 | - $profile_node->field_image = $edit['field_image']; |
|
| 1648 | - node_save($profile_node); |
|
| 1649 | - // Flush this from the node cache or changes won't show up immediately! |
|
| 1650 | - $profile_node = node_load($profile_node->nid, NULL, TRUE); |
|
| 1645 | + // Avatar settings |
|
| 1646 | + if (!$edit['field_image']) $edit['field_image'] = array(); |
|
| 1647 | + $profile_node->field_image = $edit['field_image']; |
|
| 1648 | + node_save($profile_node); |
|
| 1649 | + // Flush this from the node cache or changes won't show up immediately! |
|
| 1650 | + $profile_node = node_load($profile_node->nid, NULL, TRUE); |
|
| 1651 | 1651 | |
| 1652 | - // All other settings |
|
| 1653 | - $settings = array( |
|
| 1652 | + // All other settings |
|
| 1653 | + $settings = array( |
|
| 1654 | 1654 | 'signature' => $edit['signature'], |
| 1655 | 1655 | 'signature_format' => $edit['signature_format'], |
| 1656 | 1656 | 'timezone' => $edit['timezone'], |
@@ -1659,134 +1659,134 @@ discard block |
||
| 1659 | 1659 | 'hide_signatures' => $edit['hide_signatures'], |
| 1660 | 1660 | 'sort' => $edit['comments_order'], |
| 1661 | 1661 | 'gravatar' => $edit['gravatar'], |
| 1662 | - ); |
|
| 1663 | - if (module_exists('internationalization')) { |
|
| 1662 | + ); |
|
| 1663 | + if (module_exists('internationalization')) { |
|
| 1664 | 1664 | $settings['language'] = $edit['language']; |
| 1665 | 1665 | global $language; |
| 1666 | 1666 | if ($user->language != $edit['language']) { |
| 1667 | - global $base_url; |
|
| 1668 | - if ($edit['language'] != language_default('language')) { |
|
| 1667 | + global $base_url; |
|
| 1668 | + if ($edit['language'] != language_default('language')) { |
|
| 1669 | 1669 | $form_state['redirect'] = $base_url . '/' . $edit['language'] . '/' . $_GET['q']; |
| 1670 | - } |
|
| 1671 | - else { |
|
| 1670 | + } |
|
| 1671 | + else { |
|
| 1672 | 1672 | $form_state['redirect'] = $base_url . '/' . $_GET['q']; |
| 1673 | - } |
|
| 1673 | + } |
|
| 1674 | + } |
|
| 1674 | 1675 | } |
| 1675 | - } |
|
| 1676 | - user_save($user, $settings); |
|
| 1676 | + user_save($user, $settings); |
|
| 1677 | 1677 | |
| 1678 | - drupal_set_message(bts('Your community preferences have been updated.')); |
|
| 1678 | + drupal_set_message(bts('Your community preferences have been updated.')); |
|
| 1679 | 1679 | |
| 1680 | - // Form will not redirect if storage is set; not good if language changes |
|
| 1681 | - unset($form_state['storage']); |
|
| 1680 | + // Form will not redirect if storage is set; not good if language changes |
|
| 1681 | + unset($form_state['storage']); |
|
| 1682 | 1682 | } |
| 1683 | 1683 | |
| 1684 | 1684 | /** |
| 1685 | 1685 | * The structure of the privacy preferences form |
| 1686 | 1686 | */ |
| 1687 | 1687 | function boincwork_privacyprefs_form(&$form_state) { |
| 1688 | - require_boinc(array('user', 'prefs', 'util')); |
|
| 1688 | + require_boinc(array('user', 'prefs', 'util')); |
|
| 1689 | 1689 | |
| 1690 | - global $user; |
|
| 1691 | - $account = user_load($user->uid); |
|
| 1692 | - $boincuser = BoincUser::lookup_id($account->boincuser_id); |
|
| 1690 | + global $user; |
|
| 1691 | + $account = user_load($user->uid); |
|
| 1692 | + $boincuser = BoincUser::lookup_id($account->boincuser_id); |
|
| 1693 | 1693 | |
| 1694 | - // Load preferences from BOINC account |
|
| 1695 | - $prefs = boincwork_load_prefs('project'); |
|
| 1694 | + // Load preferences from BOINC account |
|
| 1695 | + $prefs = boincwork_load_prefs('project'); |
|
| 1696 | 1696 | |
| 1697 | - //if (!$prefs AND !$initialize_if_empty) return null; |
|
| 1697 | + //if (!$prefs AND !$initialize_if_empty) return null; |
|
| 1698 | 1698 | |
| 1699 | - // Define form defaults |
|
| 1700 | - $default = array( |
|
| 1699 | + // Define form defaults |
|
| 1700 | + $default = array( |
|
| 1701 | 1701 | 'privacy' => array( |
| 1702 | - 'send_email' => ($boincuser->send_email) ? 1 : 0, |
|
| 1703 | - 'show_hosts' => ($boincuser->show_hosts) ? 1 : 0 |
|
| 1702 | + 'send_email' => ($boincuser->send_email) ? 1 : 0, |
|
| 1703 | + 'show_hosts' => ($boincuser->show_hosts) ? 1 : 0 |
|
| 1704 | 1704 | ) |
| 1705 | - ); |
|
| 1705 | + ); |
|
| 1706 | 1706 | |
| 1707 | - // Standard option sets |
|
| 1708 | - $form['boolean_options'] = array( |
|
| 1707 | + // Standard option sets |
|
| 1708 | + $form['boolean_options'] = array( |
|
| 1709 | 1709 | '#type' => 'value', |
| 1710 | 1710 | '#value' => array(1 => bts('yes'), 0 => bts('no')) |
| 1711 | - ); |
|
| 1711 | + ); |
|
| 1712 | 1712 | |
| 1713 | - $form['privacy'] = array( |
|
| 1713 | + $form['privacy'] = array( |
|
| 1714 | 1714 | '#title' => bts('Privacy settings'), |
| 1715 | 1715 | '#type' => 'fieldset', |
| 1716 | 1716 | '#description' => null, |
| 1717 | 1717 | '#collapsible' => TRUE, |
| 1718 | 1718 | '#collapsed' => FALSE |
| 1719 | - ); |
|
| 1720 | - $form['privacy']['send_email'] = array( |
|
| 1719 | + ); |
|
| 1720 | + $form['privacy']['send_email'] = array( |
|
| 1721 | 1721 | '#title' => bts('Is it OK for @project and your team (if any) to email you?', array('@project' => variable_get('site_name', 'BOINC'))), |
| 1722 | 1722 | '#type' => 'radios', |
| 1723 | 1723 | '#options' => $form['boolean_options']['#value'], |
| 1724 | 1724 | '#attributes' => array('class' => 'fancy'), |
| 1725 | 1725 | '#default_value' => $default['privacy']['send_email'] |
| 1726 | - ); |
|
| 1727 | - $form['privacy']['show_hosts'] = array( |
|
| 1726 | + ); |
|
| 1727 | + $form['privacy']['show_hosts'] = array( |
|
| 1728 | 1728 | '#title' => bts('Should @project show your computers on its web site?', array('@project' => variable_get('site_name', 'BOINC'))), |
| 1729 | 1729 | '#type' => 'radios', |
| 1730 | 1730 | '#options' => $form['boolean_options']['#value'], |
| 1731 | 1731 | '#attributes' => array('class' => 'fancy'), |
| 1732 | 1732 | '#default_value' => $default['privacy']['show_hosts'] |
| 1733 | - ); |
|
| 1733 | + ); |
|
| 1734 | 1734 | |
| 1735 | - $form['prefs']['separator_bottom'] = array( |
|
| 1735 | + $form['prefs']['separator_bottom'] = array( |
|
| 1736 | 1736 | '#value' => '<div class="separator buttons"></div>' |
| 1737 | - ); |
|
| 1737 | + ); |
|
| 1738 | 1738 | |
| 1739 | - // Form control |
|
| 1740 | - $form['prefs']['form control tabs prefix'] = array( |
|
| 1739 | + // Form control |
|
| 1740 | + $form['prefs']['form control tabs prefix'] = array( |
|
| 1741 | 1741 | '#value' => '<ul class="form-control tab-list">' |
| 1742 | - ); |
|
| 1743 | - $form['prefs']['submit'] = array( |
|
| 1742 | + ); |
|
| 1743 | + $form['prefs']['submit'] = array( |
|
| 1744 | 1744 | '#prefix' => '<li class="first tab">', |
| 1745 | 1745 | '#type' => 'submit', |
| 1746 | 1746 | '#value' => bts('Save changes'), |
| 1747 | 1747 | '#suffix' => '</li>' |
| 1748 | - ); |
|
| 1749 | - $form['prefs']['form control tabs'] = array( |
|
| 1748 | + ); |
|
| 1749 | + $form['prefs']['form control tabs'] = array( |
|
| 1750 | 1750 | '#value' => '<li class="tab">' . l(bts('Cancel'), $_GET['q']) . '</li>' |
| 1751 | - ); |
|
| 1752 | - $form['prefs']['form control tabs suffix'] = array( |
|
| 1751 | + ); |
|
| 1752 | + $form['prefs']['form control tabs suffix'] = array( |
|
| 1753 | 1753 | '#value' => '</ul>' |
| 1754 | - ); |
|
| 1754 | + ); |
|
| 1755 | 1755 | |
| 1756 | - return $form; |
|
| 1756 | + return $form; |
|
| 1757 | 1757 | } |
| 1758 | 1758 | |
| 1759 | 1759 | /** |
| 1760 | - * Validate the privacy preferences form. |
|
| 1761 | - */ |
|
| 1760 | + * Validate the privacy preferences form. |
|
| 1761 | + */ |
|
| 1762 | 1762 | function boincwork_privacyprefs_form_validate($form, &$form_state) { |
| 1763 | - require_boinc('util'); |
|
| 1763 | + require_boinc('util'); |
|
| 1764 | 1764 | |
| 1765 | - // Verify all non-boolean user input values and notify form API of failures |
|
| 1766 | - // ... currently there are no non-boolean values! |
|
| 1765 | + // Verify all non-boolean user input values and notify form API of failures |
|
| 1766 | + // ... currently there are no non-boolean values! |
|
| 1767 | 1767 | } |
| 1768 | 1768 | |
| 1769 | 1769 | /** |
| 1770 | - * Handle post-validation submission of privacy preferences form. |
|
| 1771 | - */ |
|
| 1770 | + * Handle post-validation submission of privacy preferences form. |
|
| 1771 | + */ |
|
| 1772 | 1772 | function boincwork_privacyprefs_form_submit($form, &$form_state) { |
| 1773 | - require_boinc(array('user', 'prefs')); |
|
| 1773 | + require_boinc(array('user', 'prefs')); |
|
| 1774 | 1774 | |
| 1775 | - global $user; |
|
| 1776 | - $account = user_load($user->uid); |
|
| 1775 | + global $user; |
|
| 1776 | + $account = user_load($user->uid); |
|
| 1777 | 1777 | |
| 1778 | - // Load BOINC account |
|
| 1779 | - $boincuser = BoincUser::lookup_id($account->boincuser_id); |
|
| 1778 | + // Load BOINC account |
|
| 1779 | + $boincuser = BoincUser::lookup_id($account->boincuser_id); |
|
| 1780 | 1780 | |
| 1781 | - // Privacy preferences |
|
| 1782 | - $boincuser->send_email = ($form_state['values']['send_email']) ? true : false; |
|
| 1783 | - $boincuser->show_hosts = ($form_state['values']['show_hosts']) ? true : false; |
|
| 1781 | + // Privacy preferences |
|
| 1782 | + $boincuser->send_email = ($form_state['values']['send_email']) ? true : false; |
|
| 1783 | + $boincuser->show_hosts = ($form_state['values']['show_hosts']) ? true : false; |
|
| 1784 | 1784 | |
| 1785 | - //project_prefs_update($boincuser, $main_prefs); |
|
| 1785 | + //project_prefs_update($boincuser, $main_prefs); |
|
| 1786 | 1786 | |
| 1787 | - db_set_active('boinc'); |
|
| 1788 | - db_query("UPDATE user SET send_email = '{$boincuser->send_email}', show_hosts = '{$boincuser->show_hosts}' WHERE id = '{$boincuser->id}'"); |
|
| 1789 | - db_set_active('default'); |
|
| 1787 | + db_set_active('boinc'); |
|
| 1788 | + db_query("UPDATE user SET send_email = '{$boincuser->send_email}', show_hosts = '{$boincuser->show_hosts}' WHERE id = '{$boincuser->id}'"); |
|
| 1789 | + db_set_active('default'); |
|
| 1790 | 1790 | |
| 1791 | - drupal_set_message(t('Your privacy preferences have been updated.')); |
|
| 1791 | + drupal_set_message(t('Your privacy preferences have been updated.')); |
|
| 1792 | 1792 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | }// switch |
| 72 | 72 | } else { |
| 73 | 73 | $form_state['storage']['wip'] = TRUE; |
| 74 | - if ( !in_array($prefs_preset, array('standard','maximum','green','minimum','custom')) ) { |
|
| 74 | + if (!in_array($prefs_preset, array('standard', 'maximum', 'green', 'minimum', 'custom'))) { |
|
| 75 | 75 | if ($established) { |
| 76 | 76 | $prefs_preset = 'custom'; |
| 77 | 77 | } else { |
@@ -141,10 +141,10 @@ discard block |
||
| 141 | 141 | ); |
| 142 | 142 | $form['hour_options'] = array( |
| 143 | 143 | '#type' => 'value', |
| 144 | - '#value' => array('0:00','1:00','2:00','3:00','4:00', |
|
| 145 | - '5:00','6:00','7:00','8:00','9:00','10:00','11:00', |
|
| 146 | - '12:00','13:00','14:00','15:00','16:00','17:00', |
|
| 147 | - '18:00','19:00','20:00','21:00','22:00','23:00') |
|
| 144 | + '#value' => array('0:00', '1:00', '2:00', '3:00', '4:00', |
|
| 145 | + '5:00', '6:00', '7:00', '8:00', '9:00', '10:00', '11:00', |
|
| 146 | + '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', |
|
| 147 | + '18:00', '19:00', '20:00', '21:00', '22:00', '23:00') |
|
| 148 | 148 | ); |
| 149 | 149 | |
| 150 | 150 | // Identify preference sets that are established to distinguish what has been |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | '#description' => bts('Suspend computing when your computer is busy running other programs.'), |
| 282 | 282 | ); |
| 283 | 283 | $form['prefs']['advanced']['processor']['hour_label'] = array( |
| 284 | - '#value' => '<div class="form-item"><label>' . bts('Compute only between:') . '</label></div>' |
|
| 284 | + '#value' => '<div class="form-item"><label>'.bts('Compute only between:').'</label></div>' |
|
| 285 | 285 | ); |
| 286 | 286 | $form['prefs']['advanced']['processor']['start_hour'] = array( |
| 287 | 287 | '#type' => 'select', |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | '#default_value' => $default['start_hour'] |
| 290 | 290 | ); |
| 291 | 291 | $form['prefs']['advanced']['processor']['hour_delimiter'] = array( |
| 292 | - '#value' => '<span>' . bts('and') . '</span>' |
|
| 292 | + '#value' => '<span>'.bts('and').'</span>' |
|
| 293 | 293 | ); |
| 294 | 294 | $form['prefs']['advanced']['processor']['end_hour'] = array( |
| 295 | 295 | '#type' => 'select', |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | '#default_value' => $default['end_hour'] |
| 298 | 298 | ); |
| 299 | 299 | $form['prefs']['advanced']['processor']['hour_description'] = array( |
| 300 | - '#value' => '<div class="form-item slim"><div class="description">' . bts('Compute only during a particular period each day.') . '</div></div>' |
|
| 300 | + '#value' => '<div class="form-item slim"><div class="description">'.bts('Compute only during a particular period each day.').'</div></div>' |
|
| 301 | 301 | ); |
| 302 | 302 | $form['prefs']['advanced']['processor']['leave_apps_in_memory'] = array( |
| 303 | 303 | '#title' => bts('Leave non-GPU tasks in memory while suspended?'), |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | '#description' => bts('Limit the upload rate of file transfers.') |
| 455 | 455 | ); |
| 456 | 456 | $form['prefs']['advanced']['network']['hour_label'] = array( |
| 457 | - '#value' => '<div class="form-item"><label>' . bts('Transfer files only between') . '</label></div>' |
|
| 457 | + '#value' => '<div class="form-item"><label>'.bts('Transfer files only between').'</label></div>' |
|
| 458 | 458 | ); |
| 459 | 459 | $form['prefs']['advanced']['network']['net_start_hour'] = array( |
| 460 | 460 | '#type' => 'select', |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | '#default_value' => $default['net_start_hour'] |
| 463 | 463 | ); |
| 464 | 464 | $form['prefs']['advanced']['network']['hour_delimiter'] = array( |
| 465 | - '#value' => '<span>' . bts('and') . '</span>' |
|
| 465 | + '#value' => '<span>'.bts('and').'</span>' |
|
| 466 | 466 | ); |
| 467 | 467 | $form['prefs']['advanced']['network']['net_end_hour'] = array( |
| 468 | 468 | '#type' => 'select', |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | '#default_value' => $default['net_end_hour'] |
| 471 | 471 | ); |
| 472 | 472 | $form['prefs']['advanced']['network']['hour_description'] = array( |
| 473 | - '#value' => '<div class="form-item slim"><div class="description">' . bts('Transfer files only during a particular period each day.') . '</div></div>' |
|
| 473 | + '#value' => '<div class="form-item slim"><div class="description">'.bts('Transfer files only during a particular period each day.').'</div></div>' |
|
| 474 | 474 | ); |
| 475 | 475 | $form['prefs']['advanced']['network']['daily_xfer_limit_mb'] = array( |
| 476 | 476 | '#title' => bts('Limit usage to'), |
@@ -530,23 +530,23 @@ discard block |
||
| 530 | 530 | '#suffix' => '</li>' |
| 531 | 531 | ); |
| 532 | 532 | $form['prefs']['form control tabs'] = array( |
| 533 | - '#value' => '<li class="tab">' . l(bts('Cancel'), drupal_get_path_alias("account/prefs/computing/edit")) . '</li>' |
|
| 533 | + '#value' => '<li class="tab">'.l(bts('Cancel'), drupal_get_path_alias("account/prefs/computing/edit")).'</li>' |
|
| 534 | 534 | ); |
| 535 | 535 | if ($venue AND $venue != 'generic') { |
| 536 | 536 | global $base_path; |
| 537 | - $form['prefs']['form control tabs']['#value'] .= '<li class="tab">' . |
|
| 537 | + $form['prefs']['form control tabs']['#value'] .= '<li class="tab">'. |
|
| 538 | 538 | l(bts('Clear'), "account/prefs/computing/clear/{$venue}", |
| 539 | 539 | array( |
| 540 | - 'query' => 'destination=' . urlencode(drupal_get_path_alias('account/prefs/computing/combined')), |
|
| 540 | + 'query' => 'destination='.urlencode(drupal_get_path_alias('account/prefs/computing/combined')), |
|
| 541 | 541 | 'attributes' => array( |
| 542 | - 'onclick' => 'return confirm(\'' . bts('This will remove all of your settings from the @name preference set. Are you sure?', |
|
| 543 | - array('@name' => $venue)) . '\')' |
|
| 542 | + 'onclick' => 'return confirm(\''.bts('This will remove all of your settings from the @name preference set. Are you sure?', |
|
| 543 | + array('@name' => $venue)).'\')' |
|
| 544 | 544 | ) |
| 545 | 545 | ) |
| 546 | - ) . '</li>'; |
|
| 546 | + ).'</li>'; |
|
| 547 | 547 | } |
| 548 | 548 | $form['prefs']['view control'] = array( |
| 549 | - '#value' => '<li class="first alt tab">' . l('(' . bts('Show comparison view') . ')', 'account/prefs/computing/combined') . '</li>' |
|
| 549 | + '#value' => '<li class="first alt tab">'.l('('.bts('Show comparison view').')', 'account/prefs/computing/combined').'</li>' |
|
| 550 | 550 | ); |
| 551 | 551 | $form['prefs']['form control tabs suffix'] = array( |
| 552 | 552 | '#value' => '</ul>' |
@@ -852,9 +852,9 @@ discard block |
||
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | $form['overview'] = array( |
| 855 | - '#value' => '<p>' . bts('Sometimes BOINC assigns separate identities to' |
|
| 855 | + '#value' => '<p>'.bts('Sometimes BOINC assigns separate identities to' |
|
| 856 | 856 | . ' the same computer by mistake. You can correct this by merging old' |
| 857 | - . ' identities with the newest one.') . '</p>' |
|
| 857 | + . ' identities with the newest one.').'</p>' |
|
| 858 | 858 | . '<p>' |
| 859 | 859 | . bts('Check the computers that are the same as @name' |
| 860 | 860 | . ' (created on @date at @time with computer ID @id)', |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | '@time' => date('H:i:s T', $current_host->create_time), |
| 865 | 865 | '@id' => $current_host->id, |
| 866 | 866 | ) |
| 867 | - ) . '</p>', |
|
| 867 | + ).'</p>', |
|
| 868 | 868 | ); |
| 869 | 869 | |
| 870 | 870 | $options = array(); |
@@ -898,7 +898,7 @@ discard block |
||
| 898 | 898 | '#suffix' => '</li>' |
| 899 | 899 | ); |
| 900 | 900 | $form['prefs']['form control tabs'] = array( |
| 901 | - '#value' => '<li class="tab">' . l(bts('Cancel'), "host/{$host_id}") . '</li>' |
|
| 901 | + '#value' => '<li class="tab">'.l(bts('Cancel'), "host/{$host_id}").'</li>' |
|
| 902 | 902 | ); |
| 903 | 903 | |
| 904 | 904 | return $form; |
@@ -943,7 +943,7 @@ discard block |
||
| 943 | 943 | if (count($merged) == 2) { |
| 944 | 944 | $oxford_comma = ''; |
| 945 | 945 | } |
| 946 | - $list = implode(', ', $list) . $oxford_comma . ' ' . $conjunction . ' ' . $last; |
|
| 946 | + $list = implode(', ', $list).$oxford_comma.' '.$conjunction.' '.$last; |
|
| 947 | 947 | } |
| 948 | 948 | else { |
| 949 | 949 | $list = $last; |
@@ -1182,23 +1182,23 @@ discard block |
||
| 1182 | 1182 | '#suffix' => '</li>' |
| 1183 | 1183 | ); |
| 1184 | 1184 | $form['prefs']['form control tabs'] = array( |
| 1185 | - '#value' => '<li class="tab">' . l(bts('Cancel'), $_GET['q']) . '</li>' |
|
| 1185 | + '#value' => '<li class="tab">'.l(bts('Cancel'), $_GET['q']).'</li>' |
|
| 1186 | 1186 | ); |
| 1187 | 1187 | if ($venue AND $venue != 'generic') { |
| 1188 | 1188 | global $base_path; |
| 1189 | - $form['prefs']['form control tabs']['#value'] .= '<li class="tab">' . |
|
| 1189 | + $form['prefs']['form control tabs']['#value'] .= '<li class="tab">'. |
|
| 1190 | 1190 | l(bts('Clear'), "account/prefs/project/clear/{$venue}", |
| 1191 | 1191 | array( |
| 1192 | - 'query' => 'destination=' . urlencode(drupal_get_path_alias('account/prefs/project/combined')), |
|
| 1192 | + 'query' => 'destination='.urlencode(drupal_get_path_alias('account/prefs/project/combined')), |
|
| 1193 | 1193 | 'attributes' => array( |
| 1194 | - 'onclick' => 'return confirm(\'' . bts('This will remove all of your settings from the @name preference set. Are you sure?', |
|
| 1195 | - array('@name' => $venue)) . '\')' |
|
| 1194 | + 'onclick' => 'return confirm(\''.bts('This will remove all of your settings from the @name preference set. Are you sure?', |
|
| 1195 | + array('@name' => $venue)).'\')' |
|
| 1196 | 1196 | ) |
| 1197 | 1197 | ) |
| 1198 | - ) . '</li>'; |
|
| 1198 | + ).'</li>'; |
|
| 1199 | 1199 | } |
| 1200 | 1200 | $form['prefs']['view control'] = array( |
| 1201 | - '#value' => '<li class="first alt tab">' . l('(' . bts('Show comparison view') . ')', 'account/prefs/project/combined') . '</li>' |
|
| 1201 | + '#value' => '<li class="first alt tab">'.l('('.bts('Show comparison view').')', 'account/prefs/project/combined').'</li>' |
|
| 1202 | 1202 | ); |
| 1203 | 1203 | $form['prefs']['form control tabs suffix'] = array( |
| 1204 | 1204 | '#value' => '</ul>' |
@@ -1241,7 +1241,7 @@ discard block |
||
| 1241 | 1241 | |
| 1242 | 1242 | foreach ($xml['project_specific_preferences'] as $wrapped_element) { |
| 1243 | 1243 | $type = key($wrapped_element); |
| 1244 | - $element= reset($wrapped_element); |
|
| 1244 | + $element = reset($wrapped_element); |
|
| 1245 | 1245 | boincwork_generate_prefs_element($form, $type, $element, $prefs['project_specific']); |
| 1246 | 1246 | } |
| 1247 | 1247 | } |
@@ -1467,7 +1467,7 @@ discard block |
||
| 1467 | 1467 | $names = array(); |
| 1468 | 1468 | foreach ($languages as $langcode => $item) { |
| 1469 | 1469 | $name = t($item->name); |
| 1470 | - $names[check_plain($langcode)] = check_plain($name . ($item->native != $name ? ' ('. $item->native .')' : '')); |
|
| 1470 | + $names[check_plain($langcode)] = check_plain($name.($item->native != $name ? ' ('.$item->native.')' : '')); |
|
| 1471 | 1471 | } |
| 1472 | 1472 | $form['locale'] = array( |
| 1473 | 1473 | '#type' => 'fieldset', |
@@ -1492,20 +1492,20 @@ discard block |
||
| 1492 | 1492 | // Avatar options |
| 1493 | 1493 | $form['gravatar'] = array( |
| 1494 | 1494 | '#type' => 'item', |
| 1495 | - '#value' => bts('If you have a <a href="@gravatar-check">valid Gravatar</a> associated with your e-mail address, it will be used for your user picture.', array('@gravatar-check' => 'http://en.gravatar.com/site/check/' . $account->mail)), |
|
| 1495 | + '#value' => bts('If you have a <a href="@gravatar-check">valid Gravatar</a> associated with your e-mail address, it will be used for your user picture.', array('@gravatar-check' => 'http://en.gravatar.com/site/check/'.$account->mail)), |
|
| 1496 | 1496 | '#description' => bts('Your Gravatar will not be shown if you upload a user picture.'), |
| 1497 | 1497 | ); |
| 1498 | 1498 | if (user_access('disable own gravatar', $account)) { |
| 1499 | 1499 | $form['gravatar'] = array( |
| 1500 | 1500 | '#type' => 'checkbox', |
| 1501 | - '#title' => bts('If you have a <a href="@gravatar-check">valid Gravatar</a> associated with your e-mail address, use it for your user picture.', array('@gravatar-check' => 'http://en.gravatar.com/site/check/' . $account->mail)), |
|
| 1501 | + '#title' => bts('If you have a <a href="@gravatar-check">valid Gravatar</a> associated with your e-mail address, use it for your user picture.', array('@gravatar-check' => 'http://en.gravatar.com/site/check/'.$account->mail)), |
|
| 1502 | 1502 | '#description' => bts('Gravatar will not be shown if an avatar is uploaded.'), |
| 1503 | 1503 | '#default_value' => isset($account->gravatar) ? $account->gravatar : 0, |
| 1504 | 1504 | '#disabled' => !empty($account->picture), |
| 1505 | 1505 | ); |
| 1506 | 1506 | } |
| 1507 | 1507 | $form['gravatar']['#weight'] = 15; |
| 1508 | - $form['gravatar']['#prefix'] = '<fieldset class="collapsible"><legend><a href="#">' . bts('Avatar settings') . '</a></legend>'; |
|
| 1508 | + $form['gravatar']['#prefix'] = '<fieldset class="collapsible"><legend><a href="#">'.bts('Avatar settings').'</a></legend>'; |
|
| 1509 | 1509 | // Upload an avatar (pulled from profile_node_form): |
| 1510 | 1510 | if (!empty($profile_form['field_image'])) { |
| 1511 | 1511 | $form['field_image'] = $profile_form['field_image']; |
@@ -1540,7 +1540,7 @@ discard block |
||
| 1540 | 1540 | ); |
| 1541 | 1541 | // Can't have a typical Drupal form suffix on a select box? |
| 1542 | 1542 | $form['forums']['comments_per_page_suffix'] = array( |
| 1543 | - '#value' => '<span>' . bts('comments per page') . '</span>' |
|
| 1543 | + '#value' => '<span>'.bts('comments per page').'</span>' |
|
| 1544 | 1544 | ); |
| 1545 | 1545 | $form['forums']['comments_order'] = array( |
| 1546 | 1546 | '#type' => 'select', |
@@ -1610,7 +1610,7 @@ discard block |
||
| 1610 | 1610 | '#weight' => 1002, |
| 1611 | 1611 | ); |
| 1612 | 1612 | $form['form control tabs'] = array( |
| 1613 | - '#value' => '<li class="tab">' . l(bts('Cancel'), $_GET['q']) . '</li>', |
|
| 1613 | + '#value' => '<li class="tab">'.l(bts('Cancel'), $_GET['q']).'</li>', |
|
| 1614 | 1614 | '#weight' => 1003, |
| 1615 | 1615 | ); |
| 1616 | 1616 | $form['form control tabs suffix'] = array( |
@@ -1666,10 +1666,10 @@ discard block |
||
| 1666 | 1666 | if ($user->language != $edit['language']) { |
| 1667 | 1667 | global $base_url; |
| 1668 | 1668 | if ($edit['language'] != language_default('language')) { |
| 1669 | - $form_state['redirect'] = $base_url . '/' . $edit['language'] . '/' . $_GET['q']; |
|
| 1669 | + $form_state['redirect'] = $base_url.'/'.$edit['language'].'/'.$_GET['q']; |
|
| 1670 | 1670 | } |
| 1671 | 1671 | else { |
| 1672 | - $form_state['redirect'] = $base_url . '/' . $_GET['q']; |
|
| 1672 | + $form_state['redirect'] = $base_url.'/'.$_GET['q']; |
|
| 1673 | 1673 | } |
| 1674 | 1674 | } |
| 1675 | 1675 | } |
@@ -1747,7 +1747,7 @@ discard block |
||
| 1747 | 1747 | '#suffix' => '</li>' |
| 1748 | 1748 | ); |
| 1749 | 1749 | $form['prefs']['form control tabs'] = array( |
| 1750 | - '#value' => '<li class="tab">' . l(bts('Cancel'), $_GET['q']) . '</li>' |
|
| 1750 | + '#value' => '<li class="tab">'.l(bts('Cancel'), $_GET['q']).'</li>' |
|
| 1751 | 1751 | ); |
| 1752 | 1752 | $form['prefs']['form control tabs suffix'] = array( |
| 1753 | 1753 | '#value' => '</ul>' |
@@ -127,8 +127,7 @@ discard block |
||
| 127 | 127 | if (isset($prefs[$name]['@value'])) { |
| 128 | 128 | $default[$name] = $prefs[$name]['@value']; |
| 129 | 129 | } |
| 130 | - } |
|
| 131 | - else { |
|
| 130 | + } else { |
|
| 132 | 131 | $default[$name] = $prefs[$name]; |
| 133 | 132 | } |
| 134 | 133 | } |
@@ -567,34 +566,80 @@ discard block |
||
| 567 | 566 | // Verify all non-boolean user input values and notify form API of failures |
| 568 | 567 | |
| 569 | 568 | // Processing preferences |
| 570 | - if (!verify_numeric($values['processor']['idle_time_to_run'], 1, 9999)) form_set_error('idle_time_to_run', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['idle_time_to_run']['#title']} [x] {$form['prefs']['advanced']['processor']['idle_time_to_run']['#field_suffix']}"))); |
|
| 571 | - if (!verify_numeric($values['processor']['suspend_if_no_recent_input'], 0, 9999)) form_set_error('suspend_if_no_recent_input', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['suspend_if_no_recent_input']['#title']} [x] {$form['prefs']['advanced']['processor']['suspend_if_no_recent_input']['#field_suffix']}"))); |
|
| 572 | - if (!verify_numeric($values['processor']['suspend_cpu_usage'], 0, 100)) form_set_error('suspend_cpu_usage', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['suspend_cpu_usage']['#title']} [x] {$form['prefs']['advanced']['processor']['suspend_cpu_usage']['#field_suffix']}"))); |
|
| 573 | - if (!verify_numeric($values['processor']['start_hour'], 0, 23)) form_set_error('start_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['start_hour']['#title']} [x] {$form['prefs']['advanced']['processor']['start_hour']['#field_suffix']}"))); |
|
| 574 | - if (!verify_numeric($values['processor']['end_hour'], 0, 23)) form_set_error('end_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['end_hour']['#title']} [x] {$form['prefs']['advanced']['processor']['end_hour']['#field_suffix']}"))); |
|
| 575 | - if (!verify_numeric($values['processor']['cpu_scheduling_period_minutes'], 1, 9999)) form_set_error('cpu_scheduling_period_minutes', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['cpu_scheduling_period_minutes']['#title']} [x] {$form['prefs']['advanced']['processor']['cpu_scheduling_period_minutes']['#field_suffix']}"))); |
|
| 576 | - if (!verify_numeric($values['processor']['max_ncpus_pct'], 0, 100)) form_set_error('max_ncpus_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['max_ncpus_pct']['#title']} [x] {$form['prefs']['advanced']['processor']['max_ncpus_pct']['#field_suffix']}"))); |
|
| 577 | - if (!verify_numeric($values['processor']['cpu_usage_limit'], 0, 100)) form_set_error('cpu_usage_limit', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['cpu_usage_limit']['#title']} [x] {$form['prefs']['advanced']['processor']['cpu_usage_limit']['#field_suffix']}"))); |
|
| 569 | + if (!verify_numeric($values['processor']['idle_time_to_run'], 1, 9999)) { |
|
| 570 | + form_set_error('idle_time_to_run', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['idle_time_to_run']['#title']} [x] {$form['prefs']['advanced']['processor']['idle_time_to_run']['#field_suffix']}"))); |
|
| 571 | + } |
|
| 572 | + if (!verify_numeric($values['processor']['suspend_if_no_recent_input'], 0, 9999)) { |
|
| 573 | + form_set_error('suspend_if_no_recent_input', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['suspend_if_no_recent_input']['#title']} [x] {$form['prefs']['advanced']['processor']['suspend_if_no_recent_input']['#field_suffix']}"))); |
|
| 574 | + } |
|
| 575 | + if (!verify_numeric($values['processor']['suspend_cpu_usage'], 0, 100)) { |
|
| 576 | + form_set_error('suspend_cpu_usage', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['suspend_cpu_usage']['#title']} [x] {$form['prefs']['advanced']['processor']['suspend_cpu_usage']['#field_suffix']}"))); |
|
| 577 | + } |
|
| 578 | + if (!verify_numeric($values['processor']['start_hour'], 0, 23)) { |
|
| 579 | + form_set_error('start_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['start_hour']['#title']} [x] {$form['prefs']['advanced']['processor']['start_hour']['#field_suffix']}"))); |
|
| 580 | + } |
|
| 581 | + if (!verify_numeric($values['processor']['end_hour'], 0, 23)) { |
|
| 582 | + form_set_error('end_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['end_hour']['#title']} [x] {$form['prefs']['advanced']['processor']['end_hour']['#field_suffix']}"))); |
|
| 583 | + } |
|
| 584 | + if (!verify_numeric($values['processor']['cpu_scheduling_period_minutes'], 1, 9999)) { |
|
| 585 | + form_set_error('cpu_scheduling_period_minutes', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['cpu_scheduling_period_minutes']['#title']} [x] {$form['prefs']['advanced']['processor']['cpu_scheduling_period_minutes']['#field_suffix']}"))); |
|
| 586 | + } |
|
| 587 | + if (!verify_numeric($values['processor']['max_ncpus_pct'], 0, 100)) { |
|
| 588 | + form_set_error('max_ncpus_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['max_ncpus_pct']['#title']} [x] {$form['prefs']['advanced']['processor']['max_ncpus_pct']['#field_suffix']}"))); |
|
| 589 | + } |
|
| 590 | + if (!verify_numeric($values['processor']['cpu_usage_limit'], 0, 100)) { |
|
| 591 | + form_set_error('cpu_usage_limit', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['processor']['cpu_usage_limit']['#title']} [x] {$form['prefs']['advanced']['processor']['cpu_usage_limit']['#field_suffix']}"))); |
|
| 592 | + } |
|
| 578 | 593 | |
| 579 | 594 | // Storage preferences |
| 580 | - if (!verify_numeric($values['storage']['disk_max_used_gb'], 0, 9999999)) form_set_error('disk_max_used_gb', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_max_used_gb']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_max_used_gb']['#field_suffix']}"))); |
|
| 581 | - if (!verify_numeric($values['storage']['disk_min_free_gb'], 0.001, 9999999)) form_set_error('disk_min_free_gb', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_min_free_gb']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_min_free_gb']['#field_suffix']}"))); |
|
| 582 | - if (!verify_numeric($values['storage']['disk_max_used_pct'], 0, 100)) form_set_error('disk_max_used_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_max_used_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_max_used_pct']['#field_suffix']}"))); |
|
| 583 | - if (!verify_numeric($values['storage']['disk_interval'], 0, 9999999)) form_set_error('disk_interval', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_interval']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_interval']['#field_suffix']}"))); |
|
| 584 | - if (!verify_numeric($values['storage']['vm_max_used_pct'], 0, 100)) form_set_error('vm_max_used_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['vm_max_used_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['vm_max_used_pct']['#field_suffix']}"))); |
|
| 585 | - if (!verify_numeric($values['storage']['ram_max_used_busy_pct'], 0, 100)) form_set_error('ram_max_used_busy_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['ram_max_used_busy_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['ram_max_used_busy_pct']['#field_suffix']}"))); |
|
| 586 | - if (!verify_numeric($values['storage']['ram_max_used_idle_pct'], 0, 100)) form_set_error('ram_max_used_idle_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['ram_max_used_idle_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['ram_max_used_idle_pct']['#field_suffix']}"))); |
|
| 595 | + if (!verify_numeric($values['storage']['disk_max_used_gb'], 0, 9999999)) { |
|
| 596 | + form_set_error('disk_max_used_gb', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_max_used_gb']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_max_used_gb']['#field_suffix']}"))); |
|
| 597 | + } |
|
| 598 | + if (!verify_numeric($values['storage']['disk_min_free_gb'], 0.001, 9999999)) { |
|
| 599 | + form_set_error('disk_min_free_gb', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_min_free_gb']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_min_free_gb']['#field_suffix']}"))); |
|
| 600 | + } |
|
| 601 | + if (!verify_numeric($values['storage']['disk_max_used_pct'], 0, 100)) { |
|
| 602 | + form_set_error('disk_max_used_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_max_used_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_max_used_pct']['#field_suffix']}"))); |
|
| 603 | + } |
|
| 604 | + if (!verify_numeric($values['storage']['disk_interval'], 0, 9999999)) { |
|
| 605 | + form_set_error('disk_interval', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['disk_interval']['#title']} [x] {$form['prefs']['advanced']['storage']['disk_interval']['#field_suffix']}"))); |
|
| 606 | + } |
|
| 607 | + if (!verify_numeric($values['storage']['vm_max_used_pct'], 0, 100)) { |
|
| 608 | + form_set_error('vm_max_used_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['vm_max_used_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['vm_max_used_pct']['#field_suffix']}"))); |
|
| 609 | + } |
|
| 610 | + if (!verify_numeric($values['storage']['ram_max_used_busy_pct'], 0, 100)) { |
|
| 611 | + form_set_error('ram_max_used_busy_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['ram_max_used_busy_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['ram_max_used_busy_pct']['#field_suffix']}"))); |
|
| 612 | + } |
|
| 613 | + if (!verify_numeric($values['storage']['ram_max_used_idle_pct'], 0, 100)) { |
|
| 614 | + form_set_error('ram_max_used_idle_pct', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['storage']['ram_max_used_idle_pct']['#title']} [x] {$form['prefs']['advanced']['storage']['ram_max_used_idle_pct']['#field_suffix']}"))); |
|
| 615 | + } |
|
| 587 | 616 | |
| 588 | 617 | // Network preferences |
| 589 | - if (!verify_numeric($values['network']['work_buf_min_days'], 0, 10)) form_set_error('work_buf_min_days', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['work_buf_min_days']['#title']} [x] {$form['prefs']['advanced']['network']['work_buf_min_days']['#field_suffix']}"))); |
|
| 590 | - if (!verify_numeric($values['network']['work_buf_additional_days'], 0, 10)) form_set_error('work_buf_additional_days', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['work_buf_additional_days']['#title']} [x] {$form['prefs']['advanced']['network']['work_buf_additional_days']['#field_suffix']}"))); |
|
| 591 | - if (!verify_numeric($values['network']['max_bytes_sec_down'], 0, 9999.999)) form_set_error('max_bytes_sec_down', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['max_bytes_sec_down']['#title']} [x] {$form['prefs']['advanced']['network']['max_bytes_sec_down']['#field_suffix']}"))); |
|
| 592 | - if (!verify_numeric($values['network']['max_bytes_sec_up'], 0, 9999.999)) form_set_error('max_bytes_sec_up', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['max_bytes_sec_up']['#title']} [x] {$form['prefs']['advanced']['network']['max_bytes_sec_up']['#field_suffix']}"))); |
|
| 593 | - if (!verify_numeric($values['network']['net_start_hour'], 0, 23)) form_set_error('net_start_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['net_start_hour']['#title']} [x] {$form['prefs']['advanced']['network']['net_start_hour']['#field_suffix']}"))); |
|
| 594 | - if (!verify_numeric($values['network']['net_end_hour'], 0, 23)) form_set_error('net_end_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['net_end_hour']['#title']} [x] {$form['prefs']['advanced']['network']['net_end_hour']['#field_suffix']}"))); |
|
| 595 | - if (!verify_numeric($values['network']['daily_xfer_limit_mb'], 0, 9999999)) form_set_error('daily_xfer_limit_mb', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#title']} [x] {$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#field_suffix']}"))); |
|
| 596 | - if (!verify_numeric($values['network']['daily_xfer_period_days'], 0, 9999999)) form_set_error('daily_xfer_period_days', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#title']} [x] {$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#field_suffix']}"))); |
|
| 597 | -} |
|
| 618 | + if (!verify_numeric($values['network']['work_buf_min_days'], 0, 10)) { |
|
| 619 | + form_set_error('work_buf_min_days', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['work_buf_min_days']['#title']} [x] {$form['prefs']['advanced']['network']['work_buf_min_days']['#field_suffix']}"))); |
|
| 620 | + } |
|
| 621 | + if (!verify_numeric($values['network']['work_buf_additional_days'], 0, 10)) { |
|
| 622 | + form_set_error('work_buf_additional_days', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['work_buf_additional_days']['#title']} [x] {$form['prefs']['advanced']['network']['work_buf_additional_days']['#field_suffix']}"))); |
|
| 623 | + } |
|
| 624 | + if (!verify_numeric($values['network']['max_bytes_sec_down'], 0, 9999.999)) { |
|
| 625 | + form_set_error('max_bytes_sec_down', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['max_bytes_sec_down']['#title']} [x] {$form['prefs']['advanced']['network']['max_bytes_sec_down']['#field_suffix']}"))); |
|
| 626 | + } |
|
| 627 | + if (!verify_numeric($values['network']['max_bytes_sec_up'], 0, 9999.999)) { |
|
| 628 | + form_set_error('max_bytes_sec_up', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['max_bytes_sec_up']['#title']} [x] {$form['prefs']['advanced']['network']['max_bytes_sec_up']['#field_suffix']}"))); |
|
| 629 | + } |
|
| 630 | + if (!verify_numeric($values['network']['net_start_hour'], 0, 23)) { |
|
| 631 | + form_set_error('net_start_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['net_start_hour']['#title']} [x] {$form['prefs']['advanced']['network']['net_start_hour']['#field_suffix']}"))); |
|
| 632 | + } |
|
| 633 | + if (!verify_numeric($values['network']['net_end_hour'], 0, 23)) { |
|
| 634 | + form_set_error('net_end_hour', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['net_end_hour']['#title']} [x] {$form['prefs']['advanced']['network']['net_end_hour']['#field_suffix']}"))); |
|
| 635 | + } |
|
| 636 | + if (!verify_numeric($values['network']['daily_xfer_limit_mb'], 0, 9999999)) { |
|
| 637 | + form_set_error('daily_xfer_limit_mb', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#title']} [x] {$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#field_suffix']}"))); |
|
| 638 | + } |
|
| 639 | + if (!verify_numeric($values['network']['daily_xfer_period_days'], 0, 9999999)) { |
|
| 640 | + form_set_error('daily_xfer_period_days', bts('Invalid setting for "%preference"', array('%preference' => "{$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#title']} [x] {$form['prefs']['advanced']['network']['daily_xfer_limit_mb']['#field_suffix']}"))); |
|
| 641 | + } |
|
| 642 | + } |
|
| 598 | 643 | |
| 599 | 644 | /** |
| 600 | 645 | * Handle post-validation submission of general preferences form. |
@@ -655,8 +700,7 @@ discard block |
||
| 655 | 700 | // Save the preset selection (or lack thereof) |
| 656 | 701 | if (!$preset OR $preset == 'custom') { |
| 657 | 702 | $prefs['preset'] = 'custom'; |
| 658 | - } |
|
| 659 | - else { |
|
| 703 | + } else { |
|
| 660 | 704 | $prefs['preset'] = $preset; |
| 661 | 705 | } |
| 662 | 706 | |
@@ -671,8 +715,7 @@ discard block |
||
| 671 | 715 | if (!$result) { |
| 672 | 716 | watchdog('boincwork', 'Error updating global prefs for user @id: @message', array('@id' => $account->id, '@message' => mysql_error()), WATCHDOG_ERROR); |
| 673 | 717 | drupal_set_message(t('Your changes could not be saved. Please contact support!'), 'error'); |
| 674 | - } |
|
| 675 | - elseif (!drupal_get_messages('status', FALSE)) { |
|
| 718 | + } elseif (!drupal_get_messages('status', FALSE)) { |
|
| 676 | 719 | // Show this message if the set wasn't created automatically (in which case |
| 677 | 720 | // there is a message tailored to that) { |
| 678 | 721 | drupal_set_message(t('Your preferences have been updated. |
@@ -927,8 +970,7 @@ discard block |
||
| 927 | 970 | if (boincwork_host_merge($old_host, $current_host, $message)) { |
| 928 | 971 | $merged[$old_host->id] = $old_host->id; |
| 929 | 972 | $current_host = boincwork_host_get_info($current_host_id); |
| 930 | - } |
|
| 931 | - else { |
|
| 973 | + } else { |
|
| 932 | 974 | $errors[$old_host->id] = $message; |
| 933 | 975 | } |
| 934 | 976 | } |
@@ -944,8 +986,7 @@ discard block |
||
| 944 | 986 | $oxford_comma = ''; |
| 945 | 987 | } |
| 946 | 988 | $list = implode(', ', $list) . $oxford_comma . ' ' . $conjunction . ' ' . $last; |
| 947 | - } |
|
| 948 | - else { |
|
| 989 | + } else { |
|
| 949 | 990 | $list = $last; |
| 950 | 991 | } |
| 951 | 992 | if (count($merged) == 1) { |
@@ -956,8 +997,7 @@ discard block |
||
| 956 | 997 | '@id' => $current_host_id |
| 957 | 998 | ) |
| 958 | 999 | )); |
| 959 | - } |
|
| 960 | - else { |
|
| 1000 | + } else { |
|
| 961 | 1001 | drupal_set_message(bts( |
| 962 | 1002 | 'Computers @old_ids have been merged successfully into @id.', |
| 963 | 1003 | array( |
@@ -1017,11 +1057,9 @@ discard block |
||
| 1017 | 1057 | if ($account->boincuser_default_pref_set == $venue) { |
| 1018 | 1058 | $venue_is_default = TRUE; |
| 1019 | 1059 | } |
| 1020 | - } |
|
| 1021 | - elseif (!$venue OR $venue == 'generic') { |
|
| 1060 | + } elseif (!$venue OR $venue == 'generic') { |
|
| 1022 | 1061 | $venue_is_default = TRUE; |
| 1023 | - } |
|
| 1024 | - else { |
|
| 1062 | + } else { |
|
| 1025 | 1063 | $venue_is_default = FALSE; |
| 1026 | 1064 | } |
| 1027 | 1065 | |
@@ -1041,8 +1079,7 @@ discard block |
||
| 1041 | 1079 | if (isset($prefs[$name]['@value'])) { |
| 1042 | 1080 | $default[$name] = $prefs[$name]['@value']; |
| 1043 | 1081 | } |
| 1044 | - } |
|
| 1045 | - else { |
|
| 1082 | + } else { |
|
| 1046 | 1083 | $default[$name] = $prefs[$name]; |
| 1047 | 1084 | } |
| 1048 | 1085 | } |
@@ -1222,16 +1259,13 @@ discard block |
||
| 1222 | 1259 | foreach ($element as $ordered_element) { |
| 1223 | 1260 | if (isset($ordered_element['@position'])) { |
| 1224 | 1261 | $ordered_array[$ordered_element['@position']] = array($type => $ordered_element); |
| 1225 | - } |
|
| 1226 | - else { |
|
| 1262 | + } else { |
|
| 1227 | 1263 | $unordered_array[] = array($type => $ordered_element); |
| 1228 | 1264 | } |
| 1229 | 1265 | } |
| 1230 | - } |
|
| 1231 | - elseif (isset($element['@position'])) { |
|
| 1266 | + } elseif (isset($element['@position'])) { |
|
| 1232 | 1267 | $ordered_array[$element['@position']] = array($type => $element); |
| 1233 | - } |
|
| 1234 | - else { |
|
| 1268 | + } else { |
|
| 1235 | 1269 | $unordered_array[] = array($type => $element); |
| 1236 | 1270 | } |
| 1237 | 1271 | } |
@@ -1273,7 +1307,9 @@ discard block |
||
| 1273 | 1307 | AND $validation_rules['apps']['minimum selected'] > 0) { |
| 1274 | 1308 | $apps_selected = 0; |
| 1275 | 1309 | foreach ($validation_rules['apps']['list'] as $app) { |
| 1276 | - if ($form_state['values']['applications'][$app]) $apps_selected++; |
|
| 1310 | + if ($form_state['values']['applications'][$app]) { |
|
| 1311 | + $apps_selected++; |
|
| 1312 | + } |
|
| 1277 | 1313 | } |
| 1278 | 1314 | if ($apps_selected < $validation_rules['apps']['minimum selected']) { |
| 1279 | 1315 | form_set_error( |
@@ -1311,10 +1347,18 @@ discard block |
||
| 1311 | 1347 | // Resource preferences |
| 1312 | 1348 | $prefs['resource_share'] = $edit['resource']['resource_share']; |
| 1313 | 1349 | if ($app_types->count > 1) { |
| 1314 | - if ($app_types->cpu) $prefs['no_cpu'] = ($edit['resource']['no_cpu']) ? 0 : 1; |
|
| 1315 | - if ($app_types->cuda) $prefs['no_cuda'] = ($edit['resource']['no_cuda']) ? 0 : 1; |
|
| 1316 | - if ($app_types->ati) $prefs['no_ati'] = ($edit['resource']['no_ati']) ? 0 : 1; |
|
| 1317 | - if ($app_types->intel_gpu) $prefs['no_intel_gpu'] = ($edit['resource']['no_intel_gpu']) ? 0 : 1; |
|
| 1350 | + if ($app_types->cpu) { |
|
| 1351 | + $prefs['no_cpu'] = ($edit['resource']['no_cpu']) ? 0 : 1; |
|
| 1352 | + } |
|
| 1353 | + if ($app_types->cuda) { |
|
| 1354 | + $prefs['no_cuda'] = ($edit['resource']['no_cuda']) ? 0 : 1; |
|
| 1355 | + } |
|
| 1356 | + if ($app_types->ati) { |
|
| 1357 | + $prefs['no_ati'] = ($edit['resource']['no_ati']) ? 0 : 1; |
|
| 1358 | + } |
|
| 1359 | + if ($app_types->intel_gpu) { |
|
| 1360 | + $prefs['no_intel_gpu'] = ($edit['resource']['no_intel_gpu']) ? 0 : 1; |
|
| 1361 | + } |
|
| 1318 | 1362 | } |
| 1319 | 1363 | |
| 1320 | 1364 | // Beta preferences |
@@ -1346,8 +1390,7 @@ discard block |
||
| 1346 | 1390 | // Update the user's default preference set |
| 1347 | 1391 | if ($edit['default_set']['default_venue']) { |
| 1348 | 1392 | boincwork_set_default_venue($venue); |
| 1349 | - } |
|
| 1350 | - elseif ($venue == $account->boincuser_default_pref_set) { |
|
| 1393 | + } elseif ($venue == $account->boincuser_default_pref_set) { |
|
| 1351 | 1394 | // User has cleared out the default venue setting |
| 1352 | 1395 | boincwork_set_default_venue(); |
| 1353 | 1396 | } |
@@ -1355,8 +1398,7 @@ discard block |
||
| 1355 | 1398 | if (!$result) { |
| 1356 | 1399 | watchdog('boincwork', 'Error updating project prefs for user @id: @message', array('@id' => $user->id, '@message' => mysql_error()), WATCHDOG_ERROR); |
| 1357 | 1400 | drupal_set_message(t('Your changes could not be saved. Please contact support!'), 'error'); |
| 1358 | - } |
|
| 1359 | - elseif (!drupal_get_messages('status', FALSE)) { |
|
| 1401 | + } elseif (!drupal_get_messages('status', FALSE)) { |
|
| 1360 | 1402 | // Show this message if the set wasn't created automatically (in which case |
| 1361 | 1403 | // there is a message tailored to that) |
| 1362 | 1404 | drupal_set_message(t('Your preferences have been updated. |
@@ -1509,8 +1551,7 @@ discard block |
||
| 1509 | 1551 | // Upload an avatar (pulled from profile_node_form): |
| 1510 | 1552 | if (!empty($profile_form['field_image'])) { |
| 1511 | 1553 | $form['field_image'] = $profile_form['field_image']; |
| 1512 | - } |
|
| 1513 | - else { |
|
| 1554 | + } else { |
|
| 1514 | 1555 | $form['field_image'] = array( |
| 1515 | 1556 | '#value' => '<div class="form-item">' |
| 1516 | 1557 | . '<label class="placeholder">' |
@@ -1643,7 +1684,9 @@ discard block |
||
| 1643 | 1684 | pm_email_notify_user('submit', $edit, $user); |
| 1644 | 1685 | |
| 1645 | 1686 | // Avatar settings |
| 1646 | - if (!$edit['field_image']) $edit['field_image'] = array(); |
|
| 1687 | + if (!$edit['field_image']) { |
|
| 1688 | + $edit['field_image'] = array(); |
|
| 1689 | + } |
|
| 1647 | 1690 | $profile_node->field_image = $edit['field_image']; |
| 1648 | 1691 | node_save($profile_node); |
| 1649 | 1692 | // Flush this from the node cache or changes won't show up immediately! |
@@ -1667,8 +1710,7 @@ discard block |
||
| 1667 | 1710 | global $base_url; |
| 1668 | 1711 | if ($edit['language'] != language_default('language')) { |
| 1669 | 1712 | $form_state['redirect'] = $base_url . '/' . $edit['language'] . '/' . $_GET['q']; |
| 1670 | - } |
|
| 1671 | - else { |
|
| 1713 | + } else { |
|
| 1672 | 1714 | $form_state['redirect'] = $base_url . '/' . $_GET['q']; |
| 1673 | 1715 | } |
| 1674 | 1716 | } |
@@ -977,6 +977,7 @@ discard block |
||
| 977 | 977 | |
| 978 | 978 | /** |
| 979 | 979 | * Format a number to be displayed using a maximum number of digits |
| 980 | + * @param double $number |
|
| 980 | 981 | */ |
| 981 | 982 | function boincwork_format_stats($number, $max_digits = 4) { |
| 982 | 983 | $suffix = array( |
@@ -1187,6 +1188,9 @@ discard block |
||
| 1187 | 1188 | // xml_to_array(): Convert an XML DOM object to array format |
| 1188 | 1189 | //------------------------------------------------------------------------------------------------ |
| 1189 | 1190 | |
| 1191 | + /** |
|
| 1192 | + * @param DOMDocument $xml |
|
| 1193 | + */ |
|
| 1190 | 1194 | function xml_to_array($xml) { |
| 1191 | 1195 | $node = $xml->firstChild; //$xml->first_child(); |
| 1192 | 1196 | $result = ''; |
@@ -1269,6 +1273,7 @@ discard block |
||
| 1269 | 1273 | |
| 1270 | 1274 | /** |
| 1271 | 1275 | * Determine output for host list views when no hosts are found. |
| 1276 | + * @param string $context |
|
| 1272 | 1277 | */ |
| 1273 | 1278 | function boincwork_views_host_list_empty_text($context = NULL) { |
| 1274 | 1279 | |
@@ -11,19 +11,19 @@ discard block |
||
| 11 | 11 | * that was selected |
| 12 | 12 | */ |
| 13 | 13 | function boincwork_ahah_helper_venue_submit($form, &$form_state) { |
| 14 | - $form_state['storage']['prefs']['preset'] = null; |
|
| 15 | - ahah_helper_generic_submit($form, $form_state); |
|
| 14 | + $form_state['storage']['prefs']['preset'] = null; |
|
| 15 | + ahah_helper_generic_submit($form, $form_state); |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Get a predetermined set of preferences |
| 20 | 20 | */ |
| 21 | 21 | function boincwork_get_preset_prefs($preset = null) { |
| 22 | - $saved_state = variable_get('boincwork_preset_prefs', null); |
|
| 22 | + $saved_state = variable_get('boincwork_preset_prefs', null); |
|
| 23 | 23 | |
| 24 | - // If not configured yet, use these values as for inital |
|
| 25 | - // computing/general preferences. |
|
| 26 | - if (!$saved_state) { |
|
| 24 | + // If not configured yet, use these values as for inital |
|
| 25 | + // computing/general preferences. |
|
| 26 | + if (!$saved_state) { |
|
| 27 | 27 | // Get BOINC project disk space configurations from config.xml to |
| 28 | 28 | // fill in initial preference values. |
| 29 | 29 | require_boinc(array('db', 'prefs')); |
@@ -160,88 +160,88 @@ discard block |
||
| 160 | 160 | <dont_verify_images>0</dont_verify_images> |
| 161 | 161 | </preset> |
| 162 | 162 | </general_preferences>'; |
| 163 | - } |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - // Convert XML data to array format |
|
| 166 | - $preset_prefs = load_configuration($saved_state); |
|
| 165 | + // Convert XML data to array format |
|
| 166 | + $preset_prefs = load_configuration($saved_state); |
|
| 167 | 167 | |
| 168 | - if ($preset) { |
|
| 168 | + if ($preset) { |
|
| 169 | 169 | // Load preset from configuration |
| 170 | 170 | $preset_prefs = (array) $preset_prefs['general_preferences']; |
| 171 | 171 | if (isset($preset_prefs['preset'])) { |
| 172 | - if (!is_numeric(key($preset_prefs['preset']))) { |
|
| 172 | + if (!is_numeric(key($preset_prefs['preset']))) { |
|
| 173 | 173 | $preset_prefs['preset'] = array($preset_prefs['preset']); |
| 174 | - } |
|
| 175 | - foreach ($preset_prefs['preset'] as $key => $prefs) { |
|
| 174 | + } |
|
| 175 | + foreach ($preset_prefs['preset'] as $key => $prefs) { |
|
| 176 | 176 | if (isset($prefs['@attributes']['name']) AND $prefs['@attributes']['name'] == $preset) { |
| 177 | - return $preset_prefs['preset'][$key]; |
|
| 177 | + return $preset_prefs['preset'][$key]; |
|
| 178 | + } |
|
| 178 | 179 | } |
| 179 | - } |
|
| 180 | 180 | } |
| 181 | - } |
|
| 182 | - return $preset_prefs; |
|
| 181 | + } |
|
| 182 | + return $preset_prefs; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | 186 | * Load (and validate) the project specific configuration XML |
| 187 | 187 | */ |
| 188 | 188 | function boincwork_get_project_specific_config() { |
| 189 | - $raw_config_data = variable_get('boinc_project_specific_prefs_config', ''); |
|
| 189 | + $raw_config_data = variable_get('boinc_project_specific_prefs_config', ''); |
|
| 190 | 190 | |
| 191 | - $xsd = './' . drupal_get_path('module', 'boincwork') . '/includes/projectprefs.xsd'; |
|
| 192 | - libxml_use_internal_errors(true); |
|
| 191 | + $xsd = './' . drupal_get_path('module', 'boincwork') . '/includes/projectprefs.xsd'; |
|
| 192 | + libxml_use_internal_errors(true); |
|
| 193 | 193 | |
| 194 | - $xml = new DomDocument(); |
|
| 195 | - $xml->loadXML($raw_config_data, LIBXML_NOBLANKS); |
|
| 196 | - if (!$xml->schemaValidate($xsd)) { |
|
| 194 | + $xml = new DomDocument(); |
|
| 195 | + $xml->loadXML($raw_config_data, LIBXML_NOBLANKS); |
|
| 196 | + if (!$xml->schemaValidate($xsd)) { |
|
| 197 | 197 | $errors = libxml_get_errors(); |
| 198 | 198 | $lines = explode("\r", $raw_config_data); |
| 199 | 199 | drupal_set_message("{$errors[0]->message} at line {$errors[0]->line}" . |
| 200 | - ': <br/>' . htmlentities($lines[$errors[0]->line - 1]), 'error'); |
|
| 200 | + ': <br/>' . htmlentities($lines[$errors[0]->line - 1]), 'error'); |
|
| 201 | 201 | return NULL; |
| 202 | - } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - // Convert XML to array for validation |
|
| 205 | - $xml = load_configuration($raw_config_data); |
|
| 206 | - return $xml; |
|
| 204 | + // Convert XML to array for validation |
|
| 205 | + $xml = load_configuration($raw_config_data); |
|
| 206 | + return $xml; |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
| 210 | 210 | * Get rules by which to validate project specific data |
| 211 | 211 | */ |
| 212 | 212 | function boincwork_get_project_specific_config_validation_rules($xml = array()) { |
| 213 | - $rules = array(); |
|
| 214 | - if (!$xml) { |
|
| 213 | + $rules = array(); |
|
| 214 | + if (!$xml) { |
|
| 215 | 215 | // Read the config XML |
| 216 | 216 | $xml = boincwork_get_project_specific_config(); |
| 217 | 217 | $xml = $xml['project_specific_preferences']; |
| 218 | - } |
|
| 219 | - foreach ($xml as $type => $elements) { |
|
| 218 | + } |
|
| 219 | + foreach ($xml as $type => $elements) { |
|
| 220 | 220 | if (is_array($elements) AND !is_numeric(key($elements))) { |
| 221 | - $elements = array($elements); |
|
| 221 | + $elements = array($elements); |
|
| 222 | 222 | } |
| 223 | 223 | switch ($type) { |
| 224 | 224 | case 'compound': |
| 225 | 225 | foreach ($elements as $element) { |
| 226 | 226 | $name = $element['@attributes']['name']; |
| 227 | 227 | $rules[$name] = boincwork_get_project_specific_config_validation_rules($element['attributes']); |
| 228 | - } |
|
| 229 | - break; |
|
| 228 | + } |
|
| 229 | + break; |
|
| 230 | 230 | |
| 231 | 231 | case 'text': |
| 232 | 232 | foreach ($elements as $element) { |
| 233 | 233 | $name = $element['@attributes']['name']; |
| 234 | 234 | $rules[$name] = array( |
| 235 | - 'datatype' => $element['@attributes']['datatype'] |
|
| 235 | + 'datatype' => $element['@attributes']['datatype'] |
|
| 236 | 236 | ); |
| 237 | 237 | if (isset($element['@attributes']['min'])) { |
| 238 | - $rules[$name]['min'] = $element['@attributes']['min']; |
|
| 238 | + $rules[$name]['min'] = $element['@attributes']['min']; |
|
| 239 | 239 | } |
| 240 | 240 | if (isset($element['@attributes']['max'])) { |
| 241 | - $rules[$name]['max'] = $element['@attributes']['max']; |
|
| 241 | + $rules[$name]['max'] = $element['@attributes']['max']; |
|
| 242 | 242 | } |
| 243 | - } |
|
| 244 | - break; |
|
| 243 | + } |
|
| 244 | + break; |
|
| 245 | 245 | /* |
| 246 | 246 | case 'radio': |
| 247 | 247 | case 'dropdown': |
@@ -265,24 +265,24 @@ discard block |
||
| 265 | 265 | $rules['apps'] = array( |
| 266 | 266 | 'minimum selected' => 1, |
| 267 | 267 | 'list' => array() |
| 268 | - ); |
|
| 269 | - foreach ($elements as $element) { |
|
| 268 | + ); |
|
| 269 | + foreach ($elements as $element) { |
|
| 270 | 270 | foreach ($element['app'] as $app) { |
| 271 | - $name = "app_{$app['@attributes']['id']}"; |
|
| 272 | - $rules['apps']['list'][] = $name; |
|
| 273 | - //$rules[$name] = array( |
|
| 274 | - // 'options' => $options |
|
| 275 | - //); |
|
| 271 | + $name = "app_{$app['@attributes']['id']}"; |
|
| 272 | + $rules['apps']['list'][] = $name; |
|
| 273 | + //$rules[$name] = array( |
|
| 274 | + // 'options' => $options |
|
| 275 | + //); |
|
| 276 | 276 | } |
| 277 | - } |
|
| 278 | - break; |
|
| 277 | + } |
|
| 278 | + break; |
|
| 279 | 279 | |
| 280 | 280 | case 'group': |
| 281 | 281 | foreach ($elements as $element) { |
| 282 | 282 | $name = $element['@attributes']['name']; |
| 283 | 283 | $rules += boincwork_get_project_specific_config_validation_rules($element); |
| 284 | - } |
|
| 285 | - break; |
|
| 284 | + } |
|
| 285 | + break; |
|
| 286 | 286 | /* |
| 287 | 287 | case 'boolean': |
| 288 | 288 | // Shouldn't need to validate boolean... |
@@ -290,39 +290,39 @@ discard block |
||
| 290 | 290 | */ |
| 291 | 291 | default: |
| 292 | 292 | } |
| 293 | - } |
|
| 294 | - return $rules; |
|
| 293 | + } |
|
| 294 | + return $rules; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
| 298 | 298 | * Define how project specific settings should be saved |
| 299 | 299 | */ |
| 300 | 300 | function boincwork_format_project_specific_prefs_data($values, $xml = array()) { |
| 301 | - $defaults = array(); |
|
| 302 | - if (!$xml) { |
|
| 301 | + $defaults = array(); |
|
| 302 | + if (!$xml) { |
|
| 303 | 303 | // Read the config XML |
| 304 | 304 | $xml = boincwork_get_project_specific_config(); |
| 305 | 305 | $xml = $xml['project_specific_preferences']; |
| 306 | - } |
|
| 307 | - foreach ($xml as $type => $elements) { |
|
| 306 | + } |
|
| 307 | + foreach ($xml as $type => $elements) { |
|
| 308 | 308 | $structure_data = array(); |
| 309 | 309 | if (is_array($elements) AND !is_numeric(key($elements))) { |
| 310 | - $elements = array($elements); |
|
| 310 | + $elements = array($elements); |
|
| 311 | 311 | } |
| 312 | 312 | switch ($type) { |
| 313 | 313 | case 'compound': |
| 314 | 314 | foreach ($elements as $element) { |
| 315 | 315 | $name = $element['@attributes']['name']; |
| 316 | 316 | $default[$name]['@attributes'] = boincwork_format_project_specific_prefs_data($values[$name], $element['attributes']); |
| 317 | - } |
|
| 318 | - $defaults += $default; |
|
| 319 | - break; |
|
| 317 | + } |
|
| 318 | + $defaults += $default; |
|
| 319 | + break; |
|
| 320 | 320 | |
| 321 | 321 | case 'group': |
| 322 | 322 | foreach ($elements as $element) { |
| 323 | 323 | $defaults += boincwork_format_project_specific_prefs_data($values, $element); |
| 324 | - } |
|
| 325 | - break; |
|
| 324 | + } |
|
| 325 | + break; |
|
| 326 | 326 | |
| 327 | 327 | case 'text': |
| 328 | 328 | case 'radio': |
@@ -331,315 +331,315 @@ discard block |
||
| 331 | 331 | foreach ($elements as $element) { |
| 332 | 332 | $name = $element['@attributes']['name']; |
| 333 | 333 | if (isset($element['@attributes']['entitytype']) AND $element['@attributes']['entitytype'] == 'attribute') { |
| 334 | - $defaults['@attributes'][$name] = $values[$name]; |
|
| 334 | + $defaults['@attributes'][$name] = $values[$name]; |
|
| 335 | 335 | } |
| 336 | 336 | else { |
| 337 | - $defaults[$name] = $values[$name]; |
|
| 337 | + $defaults[$name] = $values[$name]; |
|
| 338 | 338 | } |
| 339 | - } |
|
| 340 | - break; |
|
| 339 | + } |
|
| 340 | + break; |
|
| 341 | 341 | |
| 342 | 342 | case 'apps': |
| 343 | 343 | foreach ($elements as $element) { |
| 344 | 344 | $defaults['app_id'] = array(); |
| 345 | 345 | foreach ($element['app'] as $app) { |
| 346 | - $app_id = $app['@attributes']['id']; |
|
| 347 | - if ($values['applications']["app_{$app_id}"]) { |
|
| 346 | + $app_id = $app['@attributes']['id']; |
|
| 347 | + if ($values['applications']["app_{$app_id}"]) { |
|
| 348 | 348 | $defaults['app_id'][] = $app_id; |
| 349 | - } |
|
| 349 | + } |
|
| 350 | 350 | } |
| 351 | - } |
|
| 352 | - break; |
|
| 351 | + } |
|
| 352 | + break; |
|
| 353 | 353 | |
| 354 | 354 | default: |
| 355 | 355 | } |
| 356 | - } |
|
| 357 | - return $defaults; |
|
| 356 | + } |
|
| 357 | + return $defaults; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
| 361 | 361 | * Add an element to the form based on its definition |
| 362 | 362 | */ |
| 363 | 363 | function boincwork_generate_prefs_element(&$form, $type, $elements, $user_prefs = null) { |
| 364 | - switch ($type) { |
|
| 365 | - case 'text': |
|
| 364 | + switch ($type) { |
|
| 365 | + case 'text': |
|
| 366 | 366 | if (!is_numeric(key($elements))) { |
| 367 | - $elements = array($elements); |
|
| 367 | + $elements = array($elements); |
|
| 368 | 368 | } |
| 369 | 369 | foreach ($elements as $element) { |
| 370 | - $name = $element['@attributes']['name']; |
|
| 371 | - $default = $element['@attributes']['default']; |
|
| 372 | - $title = is_array($element['title']) ? $element['title']['@value'] : $element['title']; |
|
| 373 | - $description = ''; |
|
| 374 | - if (isset($element['description'])) { |
|
| 370 | + $name = $element['@attributes']['name']; |
|
| 371 | + $default = $element['@attributes']['default']; |
|
| 372 | + $title = is_array($element['title']) ? $element['title']['@value'] : $element['title']; |
|
| 373 | + $description = ''; |
|
| 374 | + if (isset($element['description'])) { |
|
| 375 | 375 | $description = is_array($element['description']) ? $element['description']['@value'] : $element['description']; |
| 376 | - } |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | - $value = $default; |
|
| 379 | - $user_pref = $user_prefs; |
|
| 380 | - $entitytype = isset($element['@attributes']['entitytype']) ? $element['@attributes']['entitytype'] : 'element'; |
|
| 381 | - if ($entitytype == 'attribute') { |
|
| 378 | + $value = $default; |
|
| 379 | + $user_pref = $user_prefs; |
|
| 380 | + $entitytype = isset($element['@attributes']['entitytype']) ? $element['@attributes']['entitytype'] : 'element'; |
|
| 381 | + if ($entitytype == 'attribute') { |
|
| 382 | 382 | $user_pref = $user_prefs['@attributes']; |
| 383 | - } |
|
| 384 | - if (isset($user_pref[$name])) { |
|
| 383 | + } |
|
| 384 | + if (isset($user_pref[$name])) { |
|
| 385 | 385 | if (is_array($user_pref[$name]) AND isset($user_pref[$name]['@value'])) { |
| 386 | - $value = $user_pref[$name]['@value']; |
|
| 386 | + $value = $user_pref[$name]['@value']; |
|
| 387 | 387 | } |
| 388 | 388 | else { |
| 389 | - $value = $user_pref[$name]; |
|
| 389 | + $value = $user_pref[$name]; |
|
| 390 | + } |
|
| 390 | 391 | } |
| 391 | - } |
|
| 392 | 392 | |
| 393 | - // Use appropriate datatype |
|
| 394 | - if (isset($element['@attributes']['datatype'])) { |
|
| 393 | + // Use appropriate datatype |
|
| 394 | + if (isset($element['@attributes']['datatype'])) { |
|
| 395 | 395 | switch($element['@attributes']['datatype']) { |
| 396 | 396 | case 'integer': |
| 397 | 397 | $value = (int) $value; |
| 398 | - break; |
|
| 398 | + break; |
|
| 399 | 399 | |
| 400 | 400 | case 'float': |
| 401 | 401 | $value = number_format((float) $value, 2); |
| 402 | - break; |
|
| 402 | + break; |
|
| 403 | 403 | |
| 404 | 404 | default: |
| 405 | 405 | } |
| 406 | - } |
|
| 406 | + } |
|
| 407 | 407 | |
| 408 | - // Translate elements as appropriate |
|
| 409 | - if ($title) { |
|
| 408 | + // Translate elements as appropriate |
|
| 409 | + if ($title) { |
|
| 410 | 410 | i18nstrings_update('project:prefs_xml', $title); |
| 411 | 411 | $title = i18nstrings('project:prefs_xml', $title); |
| 412 | - } |
|
| 413 | - if ($description) { |
|
| 412 | + } |
|
| 413 | + if ($description) { |
|
| 414 | 414 | i18nstrings_update('project:prefs_xml', $description); |
| 415 | 415 | $description = i18nstrings('project:prefs_xml', $description); |
| 416 | - } |
|
| 416 | + } |
|
| 417 | 417 | |
| 418 | - $form[$name] = array( |
|
| 418 | + $form[$name] = array( |
|
| 419 | 419 | '#title' => $title, |
| 420 | 420 | '#type' => 'textfield', |
| 421 | 421 | '#default_value' => $value, |
| 422 | 422 | '#size' => 5, |
| 423 | 423 | '#description' => $description . bts(' Default value: @default', array('@default' => $default)) |
| 424 | - ); |
|
| 424 | + ); |
|
| 425 | 425 | } |
| 426 | 426 | break; |
| 427 | 427 | |
| 428 | - case 'boolean': |
|
| 428 | + case 'boolean': |
|
| 429 | 429 | if (!is_numeric(key($elements))) { |
| 430 | - $elements = array($elements); |
|
| 430 | + $elements = array($elements); |
|
| 431 | 431 | } |
| 432 | 432 | foreach ($elements as $element) { |
| 433 | - $name = $element['@attributes']['name']; |
|
| 434 | - $title = is_array($element['title']) ? $element['title']['@value'] : $element['title']; |
|
| 435 | - $default = (isset($element['@attributes']['selected']) AND $element['@attributes']['selected'] == 'true') ? 1 : 0; |
|
| 436 | - $description = ''; |
|
| 437 | - if (isset($element['description'])) { |
|
| 433 | + $name = $element['@attributes']['name']; |
|
| 434 | + $title = is_array($element['title']) ? $element['title']['@value'] : $element['title']; |
|
| 435 | + $default = (isset($element['@attributes']['selected']) AND $element['@attributes']['selected'] == 'true') ? 1 : 0; |
|
| 436 | + $description = ''; |
|
| 437 | + if (isset($element['description'])) { |
|
| 438 | 438 | $description = is_array($element['description']) ? $element['description']['@value'] : $element['description']; |
| 439 | - } |
|
| 439 | + } |
|
| 440 | 440 | |
| 441 | - $value = $default; |
|
| 442 | - $user_pref = $user_prefs; |
|
| 443 | - $entitytype = isset($element['@attributes']['entitytype']) ? $element['@attributes']['entitytype'] : 'element'; |
|
| 444 | - if ($entitytype == 'attribute') { |
|
| 441 | + $value = $default; |
|
| 442 | + $user_pref = $user_prefs; |
|
| 443 | + $entitytype = isset($element['@attributes']['entitytype']) ? $element['@attributes']['entitytype'] : 'element'; |
|
| 444 | + if ($entitytype == 'attribute') { |
|
| 445 | 445 | $user_pref = $user_prefs['@attributes']; |
| 446 | - } |
|
| 447 | - if (isset($user_pref[$name])) { |
|
| 446 | + } |
|
| 447 | + if (isset($user_pref[$name])) { |
|
| 448 | 448 | if (is_array($user_pref[$name]) AND isset($user_pref[$name]['@value'])) { |
| 449 | - $value = $user_pref[$name]['@value']; |
|
| 449 | + $value = $user_pref[$name]['@value']; |
|
| 450 | 450 | } |
| 451 | 451 | else { |
| 452 | - $value = $user_pref[$name]; |
|
| 452 | + $value = $user_pref[$name]; |
|
| 453 | + } |
|
| 453 | 454 | } |
| 454 | - } |
|
| 455 | 455 | |
| 456 | - // Translate elements as appropriate |
|
| 457 | - if ($title) { |
|
| 456 | + // Translate elements as appropriate |
|
| 457 | + if ($title) { |
|
| 458 | 458 | i18nstrings_update('project:prefs_xml', $title); |
| 459 | 459 | $title = i18nstrings('project:prefs_xml', $title); |
| 460 | - } |
|
| 461 | - if ($description) { |
|
| 460 | + } |
|
| 461 | + if ($description) { |
|
| 462 | 462 | i18nstrings_update('project:prefs_xml', $description); |
| 463 | 463 | $description = i18nstrings('project:prefs_xml', $description); |
| 464 | - } |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | - $form[$name] = array( |
|
| 466 | + $form[$name] = array( |
|
| 467 | 467 | '#title' => $title, |
| 468 | 468 | '#type' => 'radios', |
| 469 | 469 | '#options' => array(1 => bts('yes'), 0 => bts('no')), |
| 470 | 470 | '#attributes' => array('class' => 'fancy'), |
| 471 | 471 | '#default_value' => $value, |
| 472 | 472 | '#description' => $description |
| 473 | - ); |
|
| 473 | + ); |
|
| 474 | 474 | } |
| 475 | 475 | break; |
| 476 | 476 | |
| 477 | - case 'radio': |
|
| 477 | + case 'radio': |
|
| 478 | 478 | case 'dropdown': |
| 479 | 479 | |
| 480 | 480 | if (!is_numeric(key($elements))) { |
| 481 | - $elements = array($elements); |
|
| 481 | + $elements = array($elements); |
|
| 482 | 482 | } |
| 483 | 483 | foreach ($elements as $element) { |
| 484 | - $name = $element['@attributes']['name']; |
|
| 485 | - $default = null; |
|
| 486 | - $options = array(); |
|
| 487 | - foreach($element['items']['item'] as $item) { |
|
| 484 | + $name = $element['@attributes']['name']; |
|
| 485 | + $default = null; |
|
| 486 | + $options = array(); |
|
| 487 | + foreach($element['items']['item'] as $item) { |
|
| 488 | 488 | if (is_array($item)) { |
| 489 | - $value = $item['@value']; |
|
| 490 | - if ($default === NULL AND |
|
| 489 | + $value = $item['@value']; |
|
| 490 | + if ($default === NULL AND |
|
| 491 | 491 | isset($item['@attributes']) AND |
| 492 | 492 | isset($item['@attributes']['selected'])) { |
| 493 | 493 | $default = ($item['@attributes']['selected'] == 'true') ? $item['@value'] : null; |
| 494 | - } |
|
| 494 | + } |
|
| 495 | 495 | } |
| 496 | 496 | else { |
| 497 | - $value = $item; |
|
| 497 | + $value = $item; |
|
| 498 | 498 | } |
| 499 | 499 | $options[$value] = $value; |
| 500 | - } |
|
| 501 | - $title = is_array($element['title']) ? $element['title']['@value'] : $element['title']; |
|
| 502 | - $description = ''; |
|
| 503 | - if (isset($element['description'])) { |
|
| 500 | + } |
|
| 501 | + $title = is_array($element['title']) ? $element['title']['@value'] : $element['title']; |
|
| 502 | + $description = ''; |
|
| 503 | + if (isset($element['description'])) { |
|
| 504 | 504 | $description = is_array($element['description']) ? $element['description']['@value'] : $element['description']; |
| 505 | - } |
|
| 506 | - $user_pref = $user_prefs; |
|
| 507 | - $entitytype = isset($element['@attributes']['entitytype']) ? $element['@attributes']['entitytype'] : 'element'; |
|
| 508 | - if ($entitytype == 'attribute') { |
|
| 505 | + } |
|
| 506 | + $user_pref = $user_prefs; |
|
| 507 | + $entitytype = isset($element['@attributes']['entitytype']) ? $element['@attributes']['entitytype'] : 'element'; |
|
| 508 | + if ($entitytype == 'attribute') { |
|
| 509 | 509 | $user_pref = $user_prefs['@attributes']; |
| 510 | - } |
|
| 511 | - $value = isset($user_pref[$name]) ? $user_pref[$name] : $default; |
|
| 510 | + } |
|
| 511 | + $value = isset($user_pref[$name]) ? $user_pref[$name] : $default; |
|
| 512 | 512 | |
| 513 | - // Translate elements as appropriate |
|
| 514 | - if ($title) { |
|
| 513 | + // Translate elements as appropriate |
|
| 514 | + if ($title) { |
|
| 515 | 515 | i18nstrings_update('project:prefs_xml', $title); |
| 516 | 516 | $title = i18nstrings('project:prefs_xml', $title); |
| 517 | - } |
|
| 518 | - if ($description) { |
|
| 517 | + } |
|
| 518 | + if ($description) { |
|
| 519 | 519 | i18nstrings_update('project:prefs_xml', $description); |
| 520 | 520 | $description = i18nstrings('project:prefs_xml', $description); |
| 521 | - } |
|
| 521 | + } |
|
| 522 | 522 | |
| 523 | - $form[$name] = array( |
|
| 523 | + $form[$name] = array( |
|
| 524 | 524 | '#title' => $title, |
| 525 | 525 | '#type' => ($type == 'radio') ? 'radios' : 'select', |
| 526 | 526 | '#options' => $options, |
| 527 | 527 | '#attributes' => array('class' => 'fancy'), |
| 528 | 528 | '#default_value' => $value, |
| 529 | 529 | '#description' => $description . bts(' Default value: @default', array('@default' =>$default)) |
| 530 | - ); |
|
| 530 | + ); |
|
| 531 | 531 | } |
| 532 | 532 | break; |
| 533 | 533 | |
| 534 | - case 'apps': |
|
| 534 | + case 'apps': |
|
| 535 | 535 | $title = is_array($elements['title']) ? $elements['title']['@value'] : $elements['title']; |
| 536 | 536 | |
| 537 | - // Translate elements as appropriate |
|
| 538 | - if ($title) { |
|
| 537 | + // Translate elements as appropriate |
|
| 538 | + if ($title) { |
|
| 539 | 539 | i18nstrings_update('project:prefs_xml', $title); |
| 540 | 540 | $title = i18nstrings('project:prefs_xml', $title); |
| 541 | - } |
|
| 541 | + } |
|
| 542 | 542 | |
| 543 | 543 | $form['applications'] = array( |
| 544 | - '#title' => bts('Applications'), |
|
| 545 | - '#type' => 'fieldset', |
|
| 546 | - '#description' => $title, |
|
| 547 | - '#collapsible' => TRUE, |
|
| 548 | - '#collapsed' => FALSE |
|
| 544 | + '#title' => bts('Applications'), |
|
| 545 | + '#type' => 'fieldset', |
|
| 546 | + '#description' => $title, |
|
| 547 | + '#collapsible' => TRUE, |
|
| 548 | + '#collapsed' => FALSE |
|
| 549 | 549 | ); |
| 550 | 550 | $applications = array(); |
| 551 | 551 | if (!is_array($user_prefs['app_id'])) { |
| 552 | - $user_prefs['app_id'] = array($user_prefs['app_id']); |
|
| 552 | + $user_prefs['app_id'] = array($user_prefs['app_id']); |
|
| 553 | 553 | } |
| 554 | 554 | foreach ($user_prefs['app_id'] as $app) { |
| 555 | - if (!$app) continue; |
|
| 556 | - if (is_array($app) AND isset($app['@value'])) { |
|
| 555 | + if (!$app) continue; |
|
| 556 | + if (is_array($app) AND isset($app['@value'])) { |
|
| 557 | 557 | $app = $app['@value']; |
| 558 | - } |
|
| 559 | - $applications[] = $app; |
|
| 558 | + } |
|
| 559 | + $applications[] = $app; |
|
| 560 | 560 | } |
| 561 | 561 | foreach ($elements['app'] as $app) { |
| 562 | - $app_id = $app['@attributes']['id']; |
|
| 563 | - $app_name = $app['@value']; |
|
| 564 | - $app_enabled = TRUE; |
|
| 565 | - if (isset($app['@attributes']['enabled']) AND |
|
| 562 | + $app_id = $app['@attributes']['id']; |
|
| 563 | + $app_name = $app['@value']; |
|
| 564 | + $app_enabled = TRUE; |
|
| 565 | + if (isset($app['@attributes']['enabled']) AND |
|
| 566 | 566 | $app['@attributes']['enabled'] == 'false') { |
| 567 | 567 | $app_enabled = FALSE; |
| 568 | - } |
|
| 569 | - if ($applications) { |
|
| 568 | + } |
|
| 569 | + if ($applications) { |
|
| 570 | 570 | $checked = in_array($app_id, $applications); |
| 571 | - } else { |
|
| 571 | + } else { |
|
| 572 | 572 | $checked = TRUE; |
| 573 | 573 | if (isset($app['@attributes']['selected']) AND |
| 574 | 574 | $app['@attributes']['selected'] == 'false') { |
| 575 | - $checked = FALSE; |
|
| 575 | + $checked = FALSE; |
|
| 576 | 576 | } |
| 577 | - } |
|
| 578 | - $form['applications']["app_{$app_id}"] = array( |
|
| 577 | + } |
|
| 578 | + $form['applications']["app_{$app_id}"] = array( |
|
| 579 | 579 | '#title' => $app_name, |
| 580 | 580 | '#type' => 'checkbox', |
| 581 | 581 | '#default_value' => ($checked) ? 'x' : false, |
| 582 | 582 | '#disabled' => !$app_enabled |
| 583 | - ); |
|
| 583 | + ); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | break; |
| 587 | 587 | |
| 588 | - case 'group': |
|
| 588 | + case 'group': |
|
| 589 | 589 | if (!is_numeric(key($elements))) { |
| 590 | - $elements = array($elements); |
|
| 590 | + $elements = array($elements); |
|
| 591 | 591 | } |
| 592 | 592 | foreach ($elements as $key => $element) { |
| 593 | - $title = is_array($element['title']) ? $element['title']['@value'] : $element['title']; |
|
| 594 | - $name = str_replace(' ','_',strtolower($title)); |
|
| 595 | - $name = "group_{$name}"; |
|
| 593 | + $title = is_array($element['title']) ? $element['title']['@value'] : $element['title']; |
|
| 594 | + $name = str_replace(' ','_',strtolower($title)); |
|
| 595 | + $name = "group_{$name}"; |
|
| 596 | 596 | |
| 597 | - // Translate elements as appropriate |
|
| 598 | - if ($title) { |
|
| 597 | + // Translate elements as appropriate |
|
| 598 | + if ($title) { |
|
| 599 | 599 | i18nstrings_update('project:prefs_xml', $title); |
| 600 | 600 | $title = i18nstrings('project:prefs_xml', $title); |
| 601 | - } |
|
| 601 | + } |
|
| 602 | 602 | |
| 603 | - $form[$name] = array( |
|
| 604 | - '#title' => $title, |
|
| 605 | - '#type' => 'fieldset', |
|
| 606 | - '#tree' => FALSE, |
|
| 607 | - //'#description' => t('Notes about this group of fields'), |
|
| 608 | - '#collapsible' => TRUE, |
|
| 609 | - '#collapsed' => FALSE |
|
| 610 | - ); |
|
| 611 | - // Recursively populate the compound element |
|
| 612 | - foreach ($element as $child_type => $child) { |
|
| 603 | + $form[$name] = array( |
|
| 604 | + '#title' => $title, |
|
| 605 | + '#type' => 'fieldset', |
|
| 606 | + '#tree' => FALSE, |
|
| 607 | + //'#description' => t('Notes about this group of fields'), |
|
| 608 | + '#collapsible' => TRUE, |
|
| 609 | + '#collapsed' => FALSE |
|
| 610 | + ); |
|
| 611 | + // Recursively populate the compound element |
|
| 612 | + foreach ($element as $child_type => $child) { |
|
| 613 | 613 | boincwork_generate_prefs_element($form[$name], $child_type, $child, $user_prefs); |
| 614 | - } |
|
| 614 | + } |
|
| 615 | 615 | } |
| 616 | 616 | break; |
| 617 | 617 | |
| 618 | - case 'compound': |
|
| 618 | + case 'compound': |
|
| 619 | 619 | if (!is_numeric(key($elements))) { |
| 620 | - $elements = array($elements); |
|
| 620 | + $elements = array($elements); |
|
| 621 | 621 | } |
| 622 | 622 | foreach ($elements as $element) { |
| 623 | - $name = $element['@attributes']['name']; |
|
| 624 | - $title = is_array($element['title']) ? $element['title']['@value'] : $element['title']; |
|
| 623 | + $name = $element['@attributes']['name']; |
|
| 624 | + $title = is_array($element['title']) ? $element['title']['@value'] : $element['title']; |
|
| 625 | 625 | |
| 626 | - // Translate elements as appropriate |
|
| 627 | - if ($title) { |
|
| 626 | + // Translate elements as appropriate |
|
| 627 | + if ($title) { |
|
| 628 | 628 | i18nstrings_update('project:prefs_xml', $title); |
| 629 | 629 | $title = i18nstrings('project:prefs_xml', $title); |
| 630 | - } |
|
| 630 | + } |
|
| 631 | 631 | |
| 632 | - $form[$name] = array( |
|
| 633 | - '#title' => $title, |
|
| 634 | - '#type' => 'fieldset', |
|
| 635 | - //'#description' => t('Notes about this group of fields'), |
|
| 636 | - '#collapsible' => TRUE, |
|
| 637 | - '#collapsed' => FALSE |
|
| 638 | - ); |
|
| 639 | - // Recursively populate the compound element |
|
| 640 | - foreach ($element['attributes'] as $child_type => $child) { |
|
| 632 | + $form[$name] = array( |
|
| 633 | + '#title' => $title, |
|
| 634 | + '#type' => 'fieldset', |
|
| 635 | + //'#description' => t('Notes about this group of fields'), |
|
| 636 | + '#collapsible' => TRUE, |
|
| 637 | + '#collapsed' => FALSE |
|
| 638 | + ); |
|
| 639 | + // Recursively populate the compound element |
|
| 640 | + foreach ($element['attributes'] as $child_type => $child) { |
|
| 641 | 641 | boincwork_generate_prefs_element($form[$name], $child_type, $child, $user_prefs[$name]['@attributes']); |
| 642 | - } |
|
| 642 | + } |
|
| 643 | 643 | } |
| 644 | 644 | break; |
| 645 | 645 | |
@@ -655,24 +655,24 @@ discard block |
||
| 655 | 655 | */ |
| 656 | 656 | function boincwork_make_prefs_table($prefs, $top_level = TRUE) { |
| 657 | 657 | |
| 658 | - $prefs_table = array(); |
|
| 659 | - $uncategorized = array(); |
|
| 658 | + $prefs_table = array(); |
|
| 659 | + $uncategorized = array(); |
|
| 660 | 660 | |
| 661 | - // Parse the project preferences form |
|
| 662 | - foreach ($prefs as $key => $element) { |
|
| 661 | + // Parse the project preferences form |
|
| 662 | + foreach ($prefs as $key => $element) { |
|
| 663 | 663 | |
| 664 | 664 | // Determine which type of element this is and act accordingly |
| 665 | 665 | $element_type = NULL; |
| 666 | 666 | if (is_array($element) AND isset($element['#type'])) { |
| 667 | - $element_type = $element['#type']; |
|
| 667 | + $element_type = $element['#type']; |
|
| 668 | 668 | } |
| 669 | 669 | switch ($element_type) { |
| 670 | 670 | case 'fieldset': |
| 671 | 671 | $prefs_table[$key] = array( |
| 672 | 672 | 'name' => $element['#title'], |
| 673 | 673 | 'elements' => boincwork_make_prefs_table($element, FALSE), |
| 674 | - ); |
|
| 675 | - break; |
|
| 674 | + ); |
|
| 675 | + break; |
|
| 676 | 676 | case 'textfield': |
| 677 | 677 | case 'radios': |
| 678 | 678 | case 'checkbox': |
@@ -682,45 +682,45 @@ discard block |
||
| 682 | 682 | switch ($key) { |
| 683 | 683 | case 'start_hour': |
| 684 | 684 | $element['#title'] = bts('Compute only between:'); |
| 685 | - break; |
|
| 685 | + break; |
|
| 686 | 686 | case 'net_start_hour': |
| 687 | 687 | $element['#title'] = bts('Transfer files only between:'); |
| 688 | - break; |
|
| 688 | + break; |
|
| 689 | 689 | default: |
| 690 | 690 | } |
| 691 | - } |
|
| 692 | - $prefs_element = array( |
|
| 691 | + } |
|
| 692 | + $prefs_element = array( |
|
| 693 | 693 | 'name' => (isset($element['#title'])) ? $element['#title'] : '', |
| 694 | 694 | 'description' => (isset($element['#description'])) ? $element['#description'] : '', |
| 695 | 695 | 'default_value' => (isset($element['#default_value'])) ? $element['#default_value'] : NULL, |
| 696 | - ); |
|
| 697 | - if ($top_level) { |
|
| 696 | + ); |
|
| 697 | + if ($top_level) { |
|
| 698 | 698 | $uncategorized[$key] = $prefs_element; |
| 699 | - } |
|
| 700 | - else { |
|
| 699 | + } |
|
| 700 | + else { |
|
| 701 | 701 | $prefs_table[$key] = $prefs_element; |
| 702 | - } |
|
| 703 | - break; |
|
| 702 | + } |
|
| 703 | + break; |
|
| 704 | 704 | default: |
| 705 | 705 | } |
| 706 | - } |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | - if ($prefs_table AND $uncategorized) { |
|
| 708 | + if ($prefs_table AND $uncategorized) { |
|
| 709 | 709 | // Throw any settings that don't fit elsewhere into "other" |
| 710 | 710 | $prefs_table['other'] = array( |
| 711 | - 'name' => bts('Other settings'), |
|
| 712 | - 'elements' => $uncategorized, |
|
| 711 | + 'name' => bts('Other settings'), |
|
| 712 | + 'elements' => $uncategorized, |
|
| 713 | 713 | ); |
| 714 | - } |
|
| 715 | - elseif ($uncategorized) { |
|
| 714 | + } |
|
| 715 | + elseif ($uncategorized) { |
|
| 716 | 716 | // If nothing is categorized, output all prefs under a general "settings" |
| 717 | 717 | $prefs_table['settings'] = array( |
| 718 | - 'name' => bts('Settings'), |
|
| 719 | - 'elements' => $uncategorized, |
|
| 718 | + 'name' => bts('Settings'), |
|
| 719 | + 'elements' => $uncategorized, |
|
| 720 | 720 | ); |
| 721 | - } |
|
| 721 | + } |
|
| 722 | 722 | |
| 723 | - return $prefs_table; |
|
| 723 | + return $prefs_table; |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | /** |
@@ -728,33 +728,33 @@ discard block |
||
| 728 | 728 | */ |
| 729 | 729 | function boincwork_load_prefs($type = 'general', $venue = null, $account = null) { |
| 730 | 730 | |
| 731 | - require_boinc(array('user')); |
|
| 731 | + require_boinc(array('user')); |
|
| 732 | 732 | |
| 733 | - // Load the BOINC user object |
|
| 734 | - if (!$account) { |
|
| 733 | + // Load the BOINC user object |
|
| 734 | + if (!$account) { |
|
| 735 | 735 | global $user; |
| 736 | 736 | $account = $user; |
| 737 | - } |
|
| 738 | - $account = user_load($account->uid); |
|
| 739 | - $boincuser = BoincUser::lookup_id($account->boincuser_id); |
|
| 737 | + } |
|
| 738 | + $account = user_load($account->uid); |
|
| 739 | + $boincuser = BoincUser::lookup_id($account->boincuser_id); |
|
| 740 | 740 | |
| 741 | - // Load the desired preferences for the user |
|
| 742 | - $main_prefs = array(); |
|
| 743 | - if ($type == 'project') { |
|
| 741 | + // Load the desired preferences for the user |
|
| 742 | + $main_prefs = array(); |
|
| 743 | + if ($type == 'project') { |
|
| 744 | 744 | if ($boincuser->project_prefs) { |
| 745 | - $main_prefs = load_configuration($boincuser->project_prefs); |
|
| 746 | - $main_prefs = (array) $main_prefs['project_preferences']; |
|
| 745 | + $main_prefs = load_configuration($boincuser->project_prefs); |
|
| 746 | + $main_prefs = (array) $main_prefs['project_preferences']; |
|
| 747 | 747 | } |
| 748 | - } |
|
| 749 | - else { |
|
| 748 | + } |
|
| 749 | + else { |
|
| 750 | 750 | if ($boincuser->global_prefs) { |
| 751 | - $main_prefs = load_configuration($boincuser->global_prefs); |
|
| 752 | - $main_prefs = (array) $main_prefs['global_preferences']; |
|
| 751 | + $main_prefs = load_configuration($boincuser->global_prefs); |
|
| 752 | + $main_prefs = (array) $main_prefs['global_preferences']; |
|
| 753 | + } |
|
| 753 | 754 | } |
| 754 | - } |
|
| 755 | 755 | |
| 756 | - // Return general preferences or a subset based on venue |
|
| 757 | - if (!$venue OR $venue == 'generic') { |
|
| 756 | + // Return general preferences or a subset based on venue |
|
| 757 | + if (!$venue OR $venue == 'generic') { |
|
| 758 | 758 | unset($main_prefs['venue']); |
| 759 | 759 | // Use the length of the $main_prefs array as a condition as to |
| 760 | 760 | // whether the preferences have already been set. This is |
@@ -762,23 +762,23 @@ discard block |
||
| 762 | 762 | if (count($main_prefs) < 3) |
| 763 | 763 | $main_prefs['@attributes'] = array('cleared' => 1); |
| 764 | 764 | return $main_prefs; |
| 765 | - } |
|
| 766 | - else { |
|
| 765 | + } |
|
| 766 | + else { |
|
| 767 | 767 | if (isset($main_prefs['venue'])) { |
| 768 | - if (!is_numeric(key($main_prefs['venue']))) { |
|
| 768 | + if (!is_numeric(key($main_prefs['venue']))) { |
|
| 769 | 769 | $main_prefs['venue'] = array($main_prefs['venue']); |
| 770 | - } |
|
| 771 | - foreach ($main_prefs['venue'] as $key => $prefs_venue) { |
|
| 770 | + } |
|
| 771 | + foreach ($main_prefs['venue'] as $key => $prefs_venue) { |
|
| 772 | 772 | if (isset($prefs_venue['@attributes']['name']) AND $prefs_venue['@attributes']['name'] == $venue) { |
| 773 | - return $main_prefs['venue'][$key]; |
|
| 773 | + return $main_prefs['venue'][$key]; |
|
| 774 | + } |
|
| 774 | 775 | } |
| 775 | - } |
|
| 776 | 776 | } |
| 777 | - } |
|
| 777 | + } |
|
| 778 | 778 | |
| 779 | - return array( |
|
| 779 | + return array( |
|
| 780 | 780 | '@attributes' => array('name' => $venue, 'cleared' => 1) |
| 781 | - ); |
|
| 781 | + ); |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | /** |
@@ -786,99 +786,99 @@ discard block |
||
| 786 | 786 | */ |
| 787 | 787 | function boincwork_save_prefs($prefs, $type = 'general', $venue = null, $account = null) { |
| 788 | 788 | |
| 789 | - require_boinc(array('user')); |
|
| 789 | + require_boinc(array('user')); |
|
| 790 | 790 | |
| 791 | - // Load existing project prefs from the BOINC user object |
|
| 792 | - if (!$account) { |
|
| 791 | + // Load existing project prefs from the BOINC user object |
|
| 792 | + if (!$account) { |
|
| 793 | 793 | global $user; |
| 794 | 794 | $account = $user; |
| 795 | - } |
|
| 796 | - $account = user_load($account->uid); |
|
| 797 | - $boincuser = BoincUser::lookup_id($account->boincuser_id); |
|
| 795 | + } |
|
| 796 | + $account = user_load($account->uid); |
|
| 797 | + $boincuser = BoincUser::lookup_id($account->boincuser_id); |
|
| 798 | 798 | |
| 799 | - // Load the specified preferences for the user |
|
| 800 | - $main_prefs = array(); |
|
| 801 | - if ($type == 'project') { |
|
| 799 | + // Load the specified preferences for the user |
|
| 800 | + $main_prefs = array(); |
|
| 801 | + if ($type == 'project') { |
|
| 802 | 802 | if ($boincuser->project_prefs) { |
| 803 | - $main_prefs = load_configuration($boincuser->project_prefs); |
|
| 804 | - $main_prefs = (array) $main_prefs['project_preferences']; |
|
| 803 | + $main_prefs = load_configuration($boincuser->project_prefs); |
|
| 804 | + $main_prefs = (array) $main_prefs['project_preferences']; |
|
| 805 | 805 | } |
| 806 | - } |
|
| 807 | - else { |
|
| 806 | + } |
|
| 807 | + else { |
|
| 808 | 808 | if ($boincuser->global_prefs) { |
| 809 | - $main_prefs = load_configuration($boincuser->global_prefs); |
|
| 810 | - $main_prefs = (array) $main_prefs['global_preferences']; |
|
| 809 | + $main_prefs = load_configuration($boincuser->global_prefs); |
|
| 810 | + $main_prefs = (array) $main_prefs['global_preferences']; |
|
| 811 | + } |
|
| 811 | 812 | } |
| 812 | - } |
|
| 813 | 813 | |
| 814 | - // Save all preferences or a subset based on venue |
|
| 815 | - //drupal_set_message('<pre>' . print_r($main_prefs, true) . '</pre>'); |
|
| 816 | - $new_venue = true; |
|
| 817 | - if (!$venue OR $venue == 'generic') { |
|
| 814 | + // Save all preferences or a subset based on venue |
|
| 815 | + //drupal_set_message('<pre>' . print_r($main_prefs, true) . '</pre>'); |
|
| 816 | + $new_venue = true; |
|
| 817 | + if (!$venue OR $venue == 'generic') { |
|
| 818 | 818 | //$main_prefs = $prefs; |
| 819 | 819 | $main_prefs = $prefs + $main_prefs; |
| 820 | - } |
|
| 821 | - else { |
|
| 820 | + } |
|
| 821 | + else { |
|
| 822 | 822 | if (isset($main_prefs['venue'])) { |
| 823 | - if (!is_numeric(key($main_prefs['venue']))) { |
|
| 823 | + if (!is_numeric(key($main_prefs['venue']))) { |
|
| 824 | 824 | $main_prefs['venue'] = array($main_prefs['venue']); |
| 825 | - } |
|
| 826 | - foreach ($main_prefs['venue'] as $key => $prefs_venue) { |
|
| 825 | + } |
|
| 826 | + foreach ($main_prefs['venue'] as $key => $prefs_venue) { |
|
| 827 | 827 | if (isset($prefs_venue['@attributes']['name']) AND $prefs_venue['@attributes']['name'] == $venue) { |
| 828 | - if ($prefs) { |
|
| 828 | + if ($prefs) { |
|
| 829 | 829 | $main_prefs['venue'][$key] = $prefs; |
| 830 | - } |
|
| 831 | - else { |
|
| 830 | + } |
|
| 831 | + else { |
|
| 832 | 832 | // If prefs is null, clear out this preference set |
| 833 | 833 | unset($main_prefs['venue'][$key]); |
| 834 | 834 | if (count($main_prefs['venue']) == 0) { |
| 835 | - // If that was the only preference set configured, unset the |
|
| 836 | - // venue tag altogether |
|
| 837 | - unset($main_prefs['venue']); |
|
| 835 | + // If that was the only preference set configured, unset the |
|
| 836 | + // venue tag altogether |
|
| 837 | + unset($main_prefs['venue']); |
|
| 838 | 838 | } |
| 839 | - } |
|
| 840 | - $new_venue = false; |
|
| 841 | - break; |
|
| 839 | + } |
|
| 840 | + $new_venue = false; |
|
| 841 | + break; |
|
| 842 | + } |
|
| 842 | 843 | } |
| 843 | - } |
|
| 844 | 844 | } |
| 845 | 845 | if ($new_venue) { |
| 846 | - $main_prefs['venue'][] = $prefs; |
|
| 846 | + $main_prefs['venue'][] = $prefs; |
|
| 847 | + } |
|
| 847 | 848 | } |
| 848 | - } |
|
| 849 | 849 | |
| 850 | - // Set modified time |
|
| 851 | - if ($type == 'general') { |
|
| 850 | + // Set modified time |
|
| 851 | + if ($type == 'general') { |
|
| 852 | 852 | if (!isset($main_prefs['mod_time'])) { |
| 853 | - $main_prefs = array_merge(array('mod_time' => 0), $main_prefs); |
|
| 853 | + $main_prefs = array_merge(array('mod_time' => 0), $main_prefs); |
|
| 854 | 854 | } |
| 855 | 855 | $main_prefs['mod_time'] = time(); |
| 856 | 856 | // unset source information, the Client will fill this in again |
| 857 | 857 | if (isset($main_prefs['source_project'])) { |
| 858 | - unset($main_prefs['source_project']); |
|
| 858 | + unset($main_prefs['source_project']); |
|
| 859 | 859 | } |
| 860 | 860 | if (isset($main_prefs['source_scheduler'])) { |
| 861 | - unset($main_prefs['source_scheduler']); |
|
| 861 | + unset($main_prefs['source_scheduler']); |
|
| 862 | + } |
|
| 862 | 863 | } |
| 863 | - } |
|
| 864 | 864 | |
| 865 | - // Convert prefs back to XML and save to database |
|
| 866 | - $result = null; |
|
| 867 | - if ($type == 'project') { |
|
| 865 | + // Convert prefs back to XML and save to database |
|
| 866 | + $result = null; |
|
| 867 | + if ($type == 'project') { |
|
| 868 | 868 | $main_prefs = array('project_preferences' => $main_prefs); |
| 869 | 869 | $boincuser->project_prefs = save_configuration($main_prefs); |
| 870 | 870 | db_set_active('boinc'); |
| 871 | 871 | $result = db_query("UPDATE user SET project_prefs = '{$boincuser->project_prefs}' WHERE id = '{$boincuser->id}'"); |
| 872 | 872 | db_set_active('default'); |
| 873 | - } |
|
| 874 | - else { |
|
| 873 | + } |
|
| 874 | + else { |
|
| 875 | 875 | $main_prefs = array('global_preferences' => $main_prefs); |
| 876 | 876 | $boincuser->global_prefs = save_configuration($main_prefs); |
| 877 | 877 | db_set_active('boinc'); |
| 878 | 878 | $result = db_query("UPDATE user SET global_prefs = '{$boincuser->global_prefs}' WHERE id = '{$boincuser->id}'"); |
| 879 | 879 | db_set_active('default'); |
| 880 | - } |
|
| 881 | - return $result; |
|
| 880 | + } |
|
| 881 | + return $result; |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | |
@@ -892,94 +892,94 @@ discard block |
||
| 892 | 892 | */ |
| 893 | 893 | function boincwork_set_default_venue($venue = '') { |
| 894 | 894 | |
| 895 | - global $user; |
|
| 896 | - $account = user_load($user->uid); |
|
| 895 | + global $user; |
|
| 896 | + $account = user_load($user->uid); |
|
| 897 | 897 | |
| 898 | - if ($venue == 'generic') { |
|
| 898 | + if ($venue == 'generic') { |
|
| 899 | 899 | $venue = ''; |
| 900 | - } |
|
| 900 | + } |
|
| 901 | 901 | |
| 902 | - db_set_active('boinc'); |
|
| 903 | - db_query(" |
|
| 902 | + db_set_active('boinc'); |
|
| 903 | + db_query(" |
|
| 904 | 904 | UPDATE user |
| 905 | 905 | SET venue = '%s' |
| 906 | 906 | WHERE id = %d", |
| 907 | 907 | $venue, $account->boincuser_id |
| 908 | - ); |
|
| 909 | - db_set_active('default'); |
|
| 908 | + ); |
|
| 909 | + db_set_active('default'); |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | /** |
| 913 | 913 | * Recursively validate submitted form values against a set of rules |
| 914 | 914 | */ |
| 915 | 915 | function boincwork_validate_form($validation_rules, $values, $path = array()) { |
| 916 | - foreach ($validation_rules as $field => $rules) { |
|
| 916 | + foreach ($validation_rules as $field => $rules) { |
|
| 917 | 917 | $parents = $path; |
| 918 | 918 | if (is_array($values[$field])) { |
| 919 | - // Process nested form elements |
|
| 920 | - $parents[] = $field; |
|
| 921 | - boincwork_validate_form($rules, $values[$field], $parents); |
|
| 919 | + // Process nested form elements |
|
| 920 | + $parents[] = $field; |
|
| 921 | + boincwork_validate_form($rules, $values[$field], $parents); |
|
| 922 | 922 | } |
| 923 | 923 | else { |
| 924 | - if ($parents) { |
|
| 924 | + if ($parents) { |
|
| 925 | 925 | // form_set_error() identifies nested form elements with '][' as a |
| 926 | 926 | // delimiter between each parent and child element |
| 927 | 927 | $parents[] = $field; |
| 928 | 928 | $form_field = implode('][', $parents); |
| 929 | - } |
|
| 930 | - else { |
|
| 929 | + } |
|
| 930 | + else { |
|
| 931 | 931 | $form_field = $field; |
| 932 | - } |
|
| 933 | - if (isset($rules['datatype']) AND !boincwork_validate_datatype($values[$field], $rules['datatype'])) { |
|
| 932 | + } |
|
| 933 | + if (isset($rules['datatype']) AND !boincwork_validate_datatype($values[$field], $rules['datatype'])) { |
|
| 934 | 934 | form_set_error($form_field, bts('Invalid data type for @field', array('@field' => $field))); |
| 935 | - } |
|
| 936 | - if (isset($rules['min']) AND $values[$field] < $rules['min']) { |
|
| 935 | + } |
|
| 936 | + if (isset($rules['min']) AND $values[$field] < $rules['min']) { |
|
| 937 | 937 | form_set_error($form_field, bts('Minimum value not met for @field', array('@field' => $field))); |
| 938 | - } |
|
| 939 | - if (isset($rules['max']) AND $values[$field] > $rules['max']) { |
|
| 938 | + } |
|
| 939 | + if (isset($rules['max']) AND $values[$field] > $rules['max']) { |
|
| 940 | 940 | form_set_error($form_field, bts('Maximum value exceeded for @field', array('@field' => $field))); |
| 941 | - } |
|
| 941 | + } |
|
| 942 | + } |
|
| 942 | 943 | } |
| 943 | - } |
|
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | /** |
| 947 | 947 | * Check that numeric data conforms to specifications |
| 948 | 948 | */ |
| 949 | 949 | function boincwork_validate_datatype($data, $datatype = NULL) { |
| 950 | - switch ($datatype) { |
|
| 951 | - case 'float': |
|
| 950 | + switch ($datatype) { |
|
| 951 | + case 'float': |
|
| 952 | 952 | if (!is_numeric($data)) { |
| 953 | - return FALSE; |
|
| 953 | + return FALSE; |
|
| 954 | 954 | } |
| 955 | 955 | $data += 0; |
| 956 | 956 | if (!is_float($data)) { |
| 957 | - return FALSE; |
|
| 957 | + return FALSE; |
|
| 958 | 958 | } |
| 959 | 959 | break; |
| 960 | 960 | |
| 961 | - case 'integer': |
|
| 961 | + case 'integer': |
|
| 962 | 962 | if (!is_numeric($data)) { |
| 963 | - return FALSE; |
|
| 963 | + return FALSE; |
|
| 964 | 964 | } |
| 965 | 965 | $data += 0; |
| 966 | 966 | if (!is_int($data)) { |
| 967 | - return FALSE; |
|
| 967 | + return FALSE; |
|
| 968 | 968 | } |
| 969 | 969 | break; |
| 970 | 970 | |
| 971 | - case 'text': |
|
| 971 | + case 'text': |
|
| 972 | 972 | default: |
| 973 | 973 | |
| 974 | 974 | } |
| 975 | - return TRUE; |
|
| 975 | + return TRUE; |
|
| 976 | 976 | } |
| 977 | 977 | |
| 978 | 978 | /** |
| 979 | 979 | * Format a number to be displayed using a maximum number of digits |
| 980 | 980 | */ |
| 981 | 981 | function boincwork_format_stats($number, $max_digits = 4) { |
| 982 | - $suffix = array( |
|
| 982 | + $suffix = array( |
|
| 983 | 983 | 0 => '', |
| 984 | 984 | 1 => 'k', |
| 985 | 985 | 2 => 'M', |
@@ -989,95 +989,95 @@ discard block |
||
| 989 | 989 | 6 => 'E', |
| 990 | 990 | 7 => 'Z', |
| 991 | 991 | 8 => 'Y' |
| 992 | - ); |
|
| 993 | - if (!is_numeric($number)) $number = 0; |
|
| 992 | + ); |
|
| 993 | + if (!is_numeric($number)) $number = 0; |
|
| 994 | 994 | |
| 995 | - $digits = floor(log($number, 10)) + 1; |
|
| 996 | - $magnitude = 0; |
|
| 997 | - $precision = 0; |
|
| 998 | - if ($digits > $max_digits) { |
|
| 995 | + $digits = floor(log($number, 10)) + 1; |
|
| 996 | + $magnitude = 0; |
|
| 997 | + $precision = 0; |
|
| 998 | + if ($digits > $max_digits) { |
|
| 999 | 999 | $magnitude = floor(($digits - ($max_digits - 3)) / 3); |
| 1000 | 1000 | $precision = $max_digits - ($digits - ($magnitude * 3) + 1); |
| 1001 | 1001 | $number = round($number / pow(1000, $magnitude), $precision); |
| 1002 | - } |
|
| 1003 | - $number = number_format($number, $precision) . (($magnitude) ? "{$suffix[$magnitude]}" : ''); |
|
| 1002 | + } |
|
| 1003 | + $number = number_format($number, $precision) . (($magnitude) ? "{$suffix[$magnitude]}" : ''); |
|
| 1004 | 1004 | |
| 1005 | - return $number; |
|
| 1005 | + return $number; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | |
| 1009 | - //------------------------------------------------------------------------------------------------ |
|
| 1010 | - // load_configuration(): Convert structured text/xml to array |
|
| 1011 | - //------------------------------------------------------------------------------------------------ |
|
| 1009 | + //------------------------------------------------------------------------------------------------ |
|
| 1010 | + // load_configuration(): Convert structured text/xml to array |
|
| 1011 | + //------------------------------------------------------------------------------------------------ |
|
| 1012 | 1012 | |
| 1013 | - function load_configuration($text) |
|
| 1014 | - { |
|
| 1015 | - if (preg_match('/^\<\?xml .*\?\>$/i', $text)) return null; |
|
| 1016 | - if ($xml = text_to_xml($text)) return xml_to_array($xml); |
|
| 1017 | - return false; |
|
| 1018 | - } |
|
| 1013 | + function load_configuration($text) |
|
| 1014 | + { |
|
| 1015 | + if (preg_match('/^\<\?xml .*\?\>$/i', $text)) return null; |
|
| 1016 | + if ($xml = text_to_xml($text)) return xml_to_array($xml); |
|
| 1017 | + return false; |
|
| 1018 | + } |
|
| 1019 | 1019 | |
| 1020 | - //------------------------------------------------------------------------------------------------ |
|
| 1021 | - // save_configuration(): Convert array to structured text/xml |
|
| 1022 | - //------------------------------------------------------------------------------------------------ |
|
| 1020 | + //------------------------------------------------------------------------------------------------ |
|
| 1021 | + // save_configuration(): Convert array to structured text/xml |
|
| 1022 | + //------------------------------------------------------------------------------------------------ |
|
| 1023 | 1023 | |
| 1024 | - function save_configuration($array) |
|
| 1025 | - { |
|
| 1026 | - if ($xml = array_to_xml($array)) return xml_to_text($xml, false, true); |
|
| 1027 | - return false; |
|
| 1028 | - } |
|
| 1024 | + function save_configuration($array) |
|
| 1025 | + { |
|
| 1026 | + if ($xml = array_to_xml($array)) return xml_to_text($xml, false, true); |
|
| 1027 | + return false; |
|
| 1028 | + } |
|
| 1029 | 1029 | |
| 1030 | - //------------------------------------------------------------------------------------------------ |
|
| 1031 | - // array_to_xml(): Take a multidimensional array and convert it to a structured |
|
| 1032 | - // DOM XML object |
|
| 1033 | - //------------------------------------------------------------------------------------------------ |
|
| 1030 | + //------------------------------------------------------------------------------------------------ |
|
| 1031 | + // array_to_xml(): Take a multidimensional array and convert it to a structured |
|
| 1032 | + // DOM XML object |
|
| 1033 | + //------------------------------------------------------------------------------------------------ |
|
| 1034 | 1034 | |
| 1035 | - function array_to_xml($array, $dom = false, $parent_node = false) { |
|
| 1035 | + function array_to_xml($array, $dom = false, $parent_node = false) { |
|
| 1036 | 1036 | $is_root = false; |
| 1037 | 1037 | if (!$dom) $dom = new DomDocument('1.0'); |
| 1038 | 1038 | if (!$parent_node) { |
| 1039 | - $parent_node = $dom; |
|
| 1040 | - $is_root = true; |
|
| 1039 | + $parent_node = $dom; |
|
| 1040 | + $is_root = true; |
|
| 1041 | 1041 | } |
| 1042 | 1042 | // Created an intermediate array to attempt to sort by @position |
| 1043 | 1043 | $ordered_array = array(); |
| 1044 | 1044 | $unordered_array = array(); |
| 1045 | 1045 | foreach ($array as $name => $value) { |
| 1046 | - if ($is_root) { |
|
| 1046 | + if ($is_root) { |
|
| 1047 | 1047 | $unordered_array[] = $array; |
| 1048 | 1048 | break; |
| 1049 | - } |
|
| 1050 | - if (is_array($value)) { |
|
| 1049 | + } |
|
| 1050 | + if (is_array($value)) { |
|
| 1051 | 1051 | if (is_numeric(key($value))) { |
| 1052 | - foreach ($value as $item) { |
|
| 1052 | + foreach ($value as $item) { |
|
| 1053 | 1053 | if (is_array($item) AND isset($item['@position'])) { |
| 1054 | - $ordered_array[$item['@position']] = array( |
|
| 1054 | + $ordered_array[$item['@position']] = array( |
|
| 1055 | 1055 | $name => $item |
| 1056 | - ); |
|
| 1056 | + ); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | else { |
| 1059 | - $unordered_array[] = array( |
|
| 1059 | + $unordered_array[] = array( |
|
| 1060 | 1060 | $name => $item |
| 1061 | - ); |
|
| 1061 | + ); |
|
| 1062 | + } |
|
| 1062 | 1063 | } |
| 1063 | - } |
|
| 1064 | 1064 | } |
| 1065 | 1065 | elseif (isset($value['@position'])) { |
| 1066 | - $ordered_array[$value['@position']] = array( |
|
| 1066 | + $ordered_array[$value['@position']] = array( |
|
| 1067 | 1067 | $name => $value |
| 1068 | - ); |
|
| 1068 | + ); |
|
| 1069 | 1069 | } |
| 1070 | 1070 | else { |
| 1071 | - $unordered_array[] = array( |
|
| 1071 | + $unordered_array[] = array( |
|
| 1072 | 1072 | $name => $value |
| 1073 | - ); |
|
| 1073 | + ); |
|
| 1074 | 1074 | } |
| 1075 | - } |
|
| 1076 | - else { |
|
| 1075 | + } |
|
| 1076 | + else { |
|
| 1077 | 1077 | $unordered_array[] = array( |
| 1078 | - $name => $value |
|
| 1078 | + $name => $value |
|
| 1079 | 1079 | ); |
| 1080 | - } |
|
| 1080 | + } |
|
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | 1083 | // Now append items without explicit positions at the end |
@@ -1085,39 +1085,39 @@ discard block |
||
| 1085 | 1085 | |
| 1086 | 1086 | // Convert to XML... |
| 1087 | 1087 | foreach ($primed_array as $item) { |
| 1088 | - list($name, $value) = each($item); |
|
| 1089 | - if (strcmp($name, '@attributes') == 0) { |
|
| 1088 | + list($name, $value) = each($item); |
|
| 1089 | + if (strcmp($name, '@attributes') == 0) { |
|
| 1090 | 1090 | if (!is_array($value)) continue; |
| 1091 | 1091 | foreach ($value as $attributeName => $attributeValue) { |
| 1092 | - $parent_node->setAttribute($attributeName, $attributeValue); |
|
| 1092 | + $parent_node->setAttribute($attributeName, $attributeValue); |
|
| 1093 | 1093 | } |
| 1094 | - } elseif (strcmp($name, '@value') == 0) { |
|
| 1094 | + } elseif (strcmp($name, '@value') == 0) { |
|
| 1095 | 1095 | if (isset($value)) $parent_node->nodeValue = $value; |
| 1096 | - } elseif (strcmp($name, '@position') == 0) { |
|
| 1096 | + } elseif (strcmp($name, '@position') == 0) { |
|
| 1097 | 1097 | continue; |
| 1098 | - } else { |
|
| 1098 | + } else { |
|
| 1099 | 1099 | if (is_numeric($name)) { |
| 1100 | - $name = $parent_node->tagName; |
|
| 1100 | + $name = $parent_node->tagName; |
|
| 1101 | 1101 | } |
| 1102 | 1102 | $current_item = $dom->createElement($name); |
| 1103 | 1103 | if (is_array($value)) { |
| 1104 | - if (is_numeric(key($value))) { |
|
| 1104 | + if (is_numeric(key($value))) { |
|
| 1105 | 1105 | $current_node = $parent_node->appendChild($current_item); |
| 1106 | 1106 | $current_node = array_to_xml($value, $dom, $current_node); |
| 1107 | 1107 | $child_count = $current_node->childNodes->length; |
| 1108 | 1108 | for ($i = 0; $i < $child_count; $i++) { |
| 1109 | - $parent_node->appendChild($current_node->childNodes->item(0)); |
|
| 1109 | + $parent_node->appendChild($current_node->childNodes->item(0)); |
|
| 1110 | 1110 | } |
| 1111 | 1111 | $parent_node->removeChild($current_node); |
| 1112 | - } else { |
|
| 1112 | + } else { |
|
| 1113 | 1113 | $current_node = $dom->appendChild($current_item); |
| 1114 | 1114 | $parent_node->appendChild(array_to_xml($value, $dom, $current_node)); |
| 1115 | - } |
|
| 1115 | + } |
|
| 1116 | 1116 | } else { |
| 1117 | - if (isset($value)) $current_item->nodeValue = $value; |
|
| 1118 | - $parent_node->appendChild($current_item); |
|
| 1117 | + if (isset($value)) $current_item->nodeValue = $value; |
|
| 1118 | + $parent_node->appendChild($current_item); |
|
| 1119 | + } |
|
| 1119 | 1120 | } |
| 1120 | - } |
|
| 1121 | 1121 | } |
| 1122 | 1122 | /* |
| 1123 | 1123 | foreach ($array as $name => $value) { |
@@ -1153,114 +1153,114 @@ discard block |
||
| 1153 | 1153 | } |
| 1154 | 1154 | }*/ |
| 1155 | 1155 | return $parent_node; |
| 1156 | - } |
|
| 1156 | + } |
|
| 1157 | 1157 | |
| 1158 | - //------------------------------------------------------------------------------------------------ |
|
| 1159 | - // xml_to_text(): Convert an XML DOM object to string format |
|
| 1160 | - //------------------------------------------------------------------------------------------------ |
|
| 1158 | + //------------------------------------------------------------------------------------------------ |
|
| 1159 | + // xml_to_text(): Convert an XML DOM object to string format |
|
| 1160 | + //------------------------------------------------------------------------------------------------ |
|
| 1161 | 1161 | |
| 1162 | - function xml_to_text($xml, $include_xml_declaration = true, $add_carriage_returns = false) |
|
| 1163 | - { |
|
| 1164 | - $xml->formatOutput = true; |
|
| 1165 | - $text = $xml->saveXML(); |
|
| 1166 | - if (!$include_xml_declaration) { |
|
| 1162 | + function xml_to_text($xml, $include_xml_declaration = true, $add_carriage_returns = false) |
|
| 1163 | + { |
|
| 1164 | + $xml->formatOutput = true; |
|
| 1165 | + $text = $xml->saveXML(); |
|
| 1166 | + if (!$include_xml_declaration) { |
|
| 1167 | 1167 | $text = preg_replace('/<\?xml version=.*\?>\s*/i', '', $text, 1); |
| 1168 | - } |
|
| 1169 | - if ($add_carriage_returns) {; |
|
| 1168 | + } |
|
| 1169 | + if ($add_carriage_returns) {; |
|
| 1170 | 1170 | $text = preg_replace('/\n/i', "\r\n", $text); |
| 1171 | - } |
|
| 1172 | - return trim($text); |
|
| 1173 | - } |
|
| 1171 | + } |
|
| 1172 | + return trim($text); |
|
| 1173 | + } |
|
| 1174 | 1174 | |
| 1175 | - //------------------------------------------------------------------------------------------------ |
|
| 1176 | - // text_to_xml(): Convert an XML DOM object to string format |
|
| 1177 | - //------------------------------------------------------------------------------------------------ |
|
| 1175 | + //------------------------------------------------------------------------------------------------ |
|
| 1176 | + // text_to_xml(): Convert an XML DOM object to string format |
|
| 1177 | + //------------------------------------------------------------------------------------------------ |
|
| 1178 | 1178 | |
| 1179 | - function text_to_xml($text) { |
|
| 1179 | + function text_to_xml($text) { |
|
| 1180 | 1180 | $xml = new DomDocument(); |
| 1181 | 1181 | if ( !($xml->loadXML($text)) ) return false; |
| 1182 | 1182 | return $xml; |
| 1183 | - } |
|
| 1183 | + } |
|
| 1184 | 1184 | |
| 1185 | 1185 | |
| 1186 | - //------------------------------------------------------------------------------------------------ |
|
| 1187 | - // xml_to_array(): Convert an XML DOM object to array format |
|
| 1188 | - //------------------------------------------------------------------------------------------------ |
|
| 1186 | + //------------------------------------------------------------------------------------------------ |
|
| 1187 | + // xml_to_array(): Convert an XML DOM object to array format |
|
| 1188 | + //------------------------------------------------------------------------------------------------ |
|
| 1189 | 1189 | |
| 1190 | - function xml_to_array($xml) { |
|
| 1191 | - $node = $xml->firstChild; //$xml->first_child(); |
|
| 1192 | - $result = ''; |
|
| 1193 | - $index = 1; |
|
| 1194 | - $position = 0; |
|
| 1195 | - while (!is_null($node)) { |
|
| 1196 | - switch ($node->nodeType) { |
|
| 1197 | - case XML_TEXT_NODE: |
|
| 1190 | + function xml_to_array($xml) { |
|
| 1191 | + $node = $xml->firstChild; //$xml->first_child(); |
|
| 1192 | + $result = ''; |
|
| 1193 | + $index = 1; |
|
| 1194 | + $position = 0; |
|
| 1195 | + while (!is_null($node)) { |
|
| 1196 | + switch ($node->nodeType) { |
|
| 1197 | + case XML_TEXT_NODE: |
|
| 1198 | 1198 | if (trim($node->nodeValue) != '') $result = $node->nodeValue; |
| 1199 | - break; |
|
| 1200 | - case XML_ELEMENT_NODE: |
|
| 1199 | + break; |
|
| 1200 | + case XML_ELEMENT_NODE: |
|
| 1201 | 1201 | $node_name = $node->nodeName; |
| 1202 | - $parent = $node->parentNode; |
|
| 1203 | - $sibling = $node->nextSibling; |
|
| 1202 | + $parent = $node->parentNode; |
|
| 1203 | + $sibling = $node->nextSibling; |
|
| 1204 | 1204 | |
| 1205 | - // Determine if this node forms a set with siblings (share a node name) |
|
| 1206 | - while (($sibling) AND (($sibling->nodeType != XML_ELEMENT_NODE) OR ($sibling->nodeName != $node->nodeName))) $sibling = $sibling->nextSibling; |
|
| 1207 | - if (!$sibling) { |
|
| 1208 | - $sibling = $node->previousSibling; |
|
| 1209 | - while (($sibling) AND (($sibling->nodeType != XML_ELEMENT_NODE) OR ($sibling->nodeName != $node->nodeName))) $sibling = $sibling->previousSibling; |
|
| 1210 | - } |
|
| 1205 | + // Determine if this node forms a set with siblings (share a node name) |
|
| 1206 | + while (($sibling) AND (($sibling->nodeType != XML_ELEMENT_NODE) OR ($sibling->nodeName != $node->nodeName))) $sibling = $sibling->nextSibling; |
|
| 1207 | + if (!$sibling) { |
|
| 1208 | + $sibling = $node->previousSibling; |
|
| 1209 | + while (($sibling) AND (($sibling->nodeType != XML_ELEMENT_NODE) OR ($sibling->nodeName != $node->nodeName))) $sibling = $sibling->previousSibling; |
|
| 1210 | + } |
|
| 1211 | 1211 | |
| 1212 | - if ($sibling) { |
|
| 1213 | - $result[$node_name][$index] = ''; |
|
| 1214 | - if ($node->childNodes) { |
|
| 1215 | - $result[$node_name][$index] = xml_to_array($node) ; |
|
| 1216 | - } |
|
| 1217 | - if ($node->hasAttributes()) { |
|
| 1218 | - $attributes = $node->attributes; |
|
| 1219 | - if ($result[$node_name][$index] !== '' AND !is_array($result[$node_name][$index])) { |
|
| 1220 | - $result[$node_name][$index] = array('@value' => $result[$node_name][$index]); |
|
| 1221 | - } |
|
| 1222 | - foreach ($attributes as $key => $attribute) { |
|
| 1223 | - $result[$node_name][$index]['@attributes'][$attribute->name] = $attribute->value; |
|
| 1224 | - } |
|
| 1225 | - } |
|
| 1226 | - // Retain the position of the element |
|
| 1227 | - if (!is_array($result[$node_name][$index])) { |
|
| 1212 | + if ($sibling) { |
|
| 1213 | + $result[$node_name][$index] = ''; |
|
| 1214 | + if ($node->childNodes) { |
|
| 1215 | + $result[$node_name][$index] = xml_to_array($node) ; |
|
| 1216 | + } |
|
| 1217 | + if ($node->hasAttributes()) { |
|
| 1218 | + $attributes = $node->attributes; |
|
| 1219 | + if ($result[$node_name][$index] !== '' AND !is_array($result[$node_name][$index])) { |
|
| 1220 | + $result[$node_name][$index] = array('@value' => $result[$node_name][$index]); |
|
| 1221 | + } |
|
| 1222 | + foreach ($attributes as $key => $attribute) { |
|
| 1223 | + $result[$node_name][$index]['@attributes'][$attribute->name] = $attribute->value; |
|
| 1224 | + } |
|
| 1225 | + } |
|
| 1226 | + // Retain the position of the element |
|
| 1227 | + if (!is_array($result[$node_name][$index])) { |
|
| 1228 | 1228 | $result[$node_name][$index] = array( |
| 1229 | - '@value' => $result[$node_name][$index] |
|
| 1229 | + '@value' => $result[$node_name][$index] |
|
| 1230 | 1230 | ); |
| 1231 | - } |
|
| 1232 | - $result[$node_name][$index]['@position'] = $position; |
|
| 1233 | - $position++; |
|
| 1234 | - $index++; |
|
| 1235 | - } else { |
|
| 1236 | - $result[$node_name] = ''; |
|
| 1237 | - if ($node->childNodes) { |
|
| 1238 | - $result[$node_name] = xml_to_array($node) ; |
|
| 1239 | - } |
|
| 1240 | - if ($node->hasAttributes()) { |
|
| 1241 | - $attributes = $node->attributes; |
|
| 1242 | - if ($result[$node_name] !== '' AND !is_array($result[$node_name])) { |
|
| 1243 | - $result[$node_name] = array('@value' => $result[$node_name]); |
|
| 1244 | - } |
|
| 1245 | - foreach($attributes as $key => $attribute) { |
|
| 1246 | - $result[$node_name]['@attributes'][$attribute->name] = $attribute->value; |
|
| 1247 | - } |
|
| 1248 | - } |
|
| 1249 | - // Retain the position of the element |
|
| 1250 | - if (!is_array($result[$node_name])) { |
|
| 1231 | + } |
|
| 1232 | + $result[$node_name][$index]['@position'] = $position; |
|
| 1233 | + $position++; |
|
| 1234 | + $index++; |
|
| 1235 | + } else { |
|
| 1236 | + $result[$node_name] = ''; |
|
| 1237 | + if ($node->childNodes) { |
|
| 1238 | + $result[$node_name] = xml_to_array($node) ; |
|
| 1239 | + } |
|
| 1240 | + if ($node->hasAttributes()) { |
|
| 1241 | + $attributes = $node->attributes; |
|
| 1242 | + if ($result[$node_name] !== '' AND !is_array($result[$node_name])) { |
|
| 1243 | + $result[$node_name] = array('@value' => $result[$node_name]); |
|
| 1244 | + } |
|
| 1245 | + foreach($attributes as $key => $attribute) { |
|
| 1246 | + $result[$node_name]['@attributes'][$attribute->name] = $attribute->value; |
|
| 1247 | + } |
|
| 1248 | + } |
|
| 1249 | + // Retain the position of the element |
|
| 1250 | + if (!is_array($result[$node_name])) { |
|
| 1251 | 1251 | $result[$node_name] = array( |
| 1252 | - '@value' => $result[$node_name] |
|
| 1252 | + '@value' => $result[$node_name] |
|
| 1253 | 1253 | ); |
| 1254 | - } |
|
| 1255 | - $result[$node_name]['@position'] = $position; |
|
| 1256 | - $position++; |
|
| 1257 | - } |
|
| 1258 | - break; |
|
| 1259 | - } |
|
| 1260 | - $node = $node->nextSibling; |
|
| 1261 | - } |
|
| 1262 | - return $result; |
|
| 1263 | - } |
|
| 1254 | + } |
|
| 1255 | + $result[$node_name]['@position'] = $position; |
|
| 1256 | + $position++; |
|
| 1257 | + } |
|
| 1258 | + break; |
|
| 1259 | + } |
|
| 1260 | + $node = $node->nextSibling; |
|
| 1261 | + } |
|
| 1262 | + return $result; |
|
| 1263 | + } |
|
| 1264 | 1264 | |
| 1265 | 1265 | |
| 1266 | 1266 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * |
@@ -1268,172 +1268,172 @@ discard block |
||
| 1268 | 1268 | * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 1269 | 1269 | |
| 1270 | 1270 | /** |
| 1271 | - * Determine output for host list views when no hosts are found. |
|
| 1272 | - */ |
|
| 1271 | + * Determine output for host list views when no hosts are found. |
|
| 1272 | + */ |
|
| 1273 | 1273 | function boincwork_views_host_list_empty_text($context = NULL) { |
| 1274 | 1274 | |
| 1275 | - // Pull the BOINC user ID from the view arguments to get show_hosts |
|
| 1276 | - // preference for that user |
|
| 1277 | - require_boinc('boinc_db'); |
|
| 1278 | - $view = views_get_current_view(); |
|
| 1279 | - $account = user_load($view->args[0]); |
|
| 1280 | - $boincuser = BoincUser::lookup_id($account->boincuser_id); |
|
| 1275 | + // Pull the BOINC user ID from the view arguments to get show_hosts |
|
| 1276 | + // preference for that user |
|
| 1277 | + require_boinc('boinc_db'); |
|
| 1278 | + $view = views_get_current_view(); |
|
| 1279 | + $account = user_load($view->args[0]); |
|
| 1280 | + $boincuser = BoincUser::lookup_id($account->boincuser_id); |
|
| 1281 | 1281 | |
| 1282 | - // Determine if hosts are associated at all or just hidden |
|
| 1283 | - $output = ''; |
|
| 1284 | - if ($boincuser->show_hosts) { |
|
| 1282 | + // Determine if hosts are associated at all or just hidden |
|
| 1283 | + $output = ''; |
|
| 1284 | + if ($boincuser->show_hosts) { |
|
| 1285 | 1285 | switch($context) { |
| 1286 | 1286 | case 'active': |
| 1287 | 1287 | $output .= '<h2>' . bts('No active computers') . '</h2>'; |
| 1288 | - $output .= '<p>' . bts('This user has no computers that have been' |
|
| 1289 | - . ' active in the last 30 days.') . '</p>'; |
|
| 1290 | - break; |
|
| 1288 | + $output .= '<p>' . bts('This user has no computers that have been' |
|
| 1289 | + . ' active in the last 30 days.') . '</p>'; |
|
| 1290 | + break; |
|
| 1291 | 1291 | |
| 1292 | 1292 | case 'preferences': |
| 1293 | 1293 | $output .= '<h2>' . bts('No computers') . '</h2>'; |
| 1294 | - $output .= '<p>' . bts('There are no computers assigned to this' |
|
| 1295 | - . ' preference set.') . '</p>'; |
|
| 1296 | - break; |
|
| 1294 | + $output .= '<p>' . bts('There are no computers assigned to this' |
|
| 1295 | + . ' preference set.') . '</p>'; |
|
| 1296 | + break; |
|
| 1297 | 1297 | |
| 1298 | 1298 | default: |
| 1299 | 1299 | $output .= '<h2>' . bts('Computers pending') . '</h2>'; |
| 1300 | - $output .= '<p>' . bts('This user does not yet have any associated' |
|
| 1301 | - . ' computers. Computers will be displayed when they have earned their' |
|
| 1302 | - . ' first credits.') . '</p>'; |
|
| 1300 | + $output .= '<p>' . bts('This user does not yet have any associated' |
|
| 1301 | + . ' computers. Computers will be displayed when they have earned their' |
|
| 1302 | + . ' first credits.') . '</p>'; |
|
| 1303 | 1303 | } |
| 1304 | - } |
|
| 1305 | - else { |
|
| 1304 | + } |
|
| 1305 | + else { |
|
| 1306 | 1306 | $output .= '<h2>' . bts('Computers hidden') . '</h2>'; |
| 1307 | 1307 | $output .= '<p>' . bts('This user has chosen not to show information' |
| 1308 | 1308 | . ' about their computers.') . '</p>'; |
| 1309 | - } |
|
| 1310 | - return $output; |
|
| 1309 | + } |
|
| 1310 | + return $output; |
|
| 1311 | 1311 | } |
| 1312 | 1312 | |
| 1313 | 1313 | /** |
| 1314 | - * Determine output for task list views when no tasks are found. |
|
| 1315 | - */ |
|
| 1314 | + * Determine output for task list views when no tasks are found. |
|
| 1315 | + */ |
|
| 1316 | 1316 | function boincwork_views_task_list_empty_text($context = NULL) { |
| 1317 | 1317 | |
| 1318 | - // |
|
| 1319 | - $output = ''; |
|
| 1320 | - switch($context) { |
|
| 1321 | - default: |
|
| 1318 | + // |
|
| 1319 | + $output = ''; |
|
| 1320 | + switch($context) { |
|
| 1321 | + default: |
|
| 1322 | 1322 | $output .= '<h2>' . bts('No @type tasks', array('@type' => $context)) |
| 1323 | 1323 | . '</h2>'; |
| 1324 | 1324 | $output .= '<p>' . bts('There are no tasks of this type on record') |
| 1325 | 1325 | . '</p>'; |
| 1326 | - } |
|
| 1327 | - return $output; |
|
| 1326 | + } |
|
| 1327 | + return $output; |
|
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | /** |
| 1331 | - * Output links to perform host actions |
|
| 1332 | - */ |
|
| 1331 | + * Output links to perform host actions |
|
| 1332 | + */ |
|
| 1333 | 1333 | function boincwork_host_action_links($host_id) { |
| 1334 | - $output = ''; |
|
| 1335 | - if (boincwork_host_user_is_owner($host_id)) { |
|
| 1334 | + $output = ''; |
|
| 1335 | + if (boincwork_host_user_is_owner($host_id)) { |
|
| 1336 | 1336 | // Show merge hosts option |
| 1337 | 1337 | $output = '<ul class="tab-list"><li class="first tab">'; |
| 1338 | 1338 | $output .= l(bts('Merge'), "host/{$host_id}/merge"); |
| 1339 | 1339 | $output .= '</li>'; |
| 1340 | 1340 | // If host has no tasks, allow the host to be deleted |
| 1341 | 1341 | if (!boincwork_host_get_task_count($host_id)) { |
| 1342 | - $output .= '<li class="tab">'; |
|
| 1343 | - $output .= l(bts('Delete'), "host/{$host_id}/delete", |
|
| 1342 | + $output .= '<li class="tab">'; |
|
| 1343 | + $output .= l(bts('Delete'), "host/{$host_id}/delete", |
|
| 1344 | 1344 | array( |
| 1345 | - 'attributes' => array( |
|
| 1345 | + 'attributes' => array( |
|
| 1346 | 1346 | 'onclick' => 'return confirm(\'' . bts('This will delete host @id' |
| 1347 | - . ' from your account forever. Are you sure this is OK?', |
|
| 1348 | - array('@id' => $host_id) |
|
| 1347 | + . ' from your account forever. Are you sure this is OK?', |
|
| 1348 | + array('@id' => $host_id) |
|
| 1349 | 1349 | ) . '\')' |
| 1350 | - ) |
|
| 1350 | + ) |
|
| 1351 | 1351 | ) |
| 1352 | - ); |
|
| 1353 | - $output .= '</li>'; |
|
| 1352 | + ); |
|
| 1353 | + $output .= '</li>'; |
|
| 1354 | 1354 | } |
| 1355 | 1355 | $output .= '</ul>'; |
| 1356 | - } |
|
| 1357 | - return $output; |
|
| 1356 | + } |
|
| 1357 | + return $output; |
|
| 1358 | 1358 | } |
| 1359 | 1359 | |
| 1360 | 1360 | /** |
| 1361 | 1361 | * Get details for a given host |
| 1362 | 1362 | */ |
| 1363 | 1363 | function boincwork_host_get_info($host_id) { |
| 1364 | - db_set_active('boinc'); |
|
| 1365 | - $host = db_fetch_object(db_query( |
|
| 1364 | + db_set_active('boinc'); |
|
| 1365 | + $host = db_fetch_object(db_query( |
|
| 1366 | 1366 | "SELECT * FROM {host} WHERE id = '%d'", |
| 1367 | 1367 | $host_id |
| 1368 | - )); |
|
| 1369 | - db_set_active('default'); |
|
| 1370 | - return $host; |
|
| 1368 | + )); |
|
| 1369 | + db_set_active('default'); |
|
| 1370 | + return $host; |
|
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | 1373 | /** |
| 1374 | 1374 | * Get the number of tasks associated with a given host |
| 1375 | 1375 | */ |
| 1376 | 1376 | function boincwork_host_get_task_count($host_id) { |
| 1377 | - db_set_active('boinc'); |
|
| 1378 | - $count = db_result(db_query( |
|
| 1377 | + db_set_active('boinc'); |
|
| 1378 | + $count = db_result(db_query( |
|
| 1379 | 1379 | "SELECT COUNT(*) FROM {result} WHERE hostid = '%d'", |
| 1380 | 1380 | $host_id |
| 1381 | - )); |
|
| 1382 | - db_set_active('default'); |
|
| 1383 | - return $count; |
|
| 1381 | + )); |
|
| 1382 | + db_set_active('default'); |
|
| 1383 | + return $count; |
|
| 1384 | 1384 | } |
| 1385 | 1385 | |
| 1386 | 1386 | /** |
| 1387 | 1387 | * Check whether a user is the owner of a host |
| 1388 | 1388 | */ |
| 1389 | 1389 | function boincwork_host_user_is_owner($host_id, $uid = NULL) { |
| 1390 | - if (!$uid) { |
|
| 1390 | + if (!$uid) { |
|
| 1391 | 1391 | global $user; |
| 1392 | 1392 | $uid = $user->uid; |
| 1393 | - } |
|
| 1394 | - $account = user_load($uid); |
|
| 1395 | - // Get host owner |
|
| 1396 | - db_set_active('boinc'); |
|
| 1397 | - $owner = db_result(db_query( |
|
| 1393 | + } |
|
| 1394 | + $account = user_load($uid); |
|
| 1395 | + // Get host owner |
|
| 1396 | + db_set_active('boinc'); |
|
| 1397 | + $owner = db_result(db_query( |
|
| 1398 | 1398 | "SELECT userid FROM {host} WHERE id = '%d'", |
| 1399 | 1399 | $host_id |
| 1400 | - )); |
|
| 1401 | - db_set_active('default'); |
|
| 1402 | - return ($account->boincuser_id === $owner); |
|
| 1400 | + )); |
|
| 1401 | + db_set_active('default'); |
|
| 1402 | + return ($account->boincuser_id === $owner); |
|
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | 1405 | /** |
| 1406 | - * Determine output for host last contact time |
|
| 1407 | - */ |
|
| 1406 | + * Determine output for host last contact time |
|
| 1407 | + */ |
|
| 1408 | 1408 | function boincwork_host_last_contact($timestamp, $host_id = NULL, $context = NULL) { |
| 1409 | - $output = '---'; |
|
| 1410 | - $root_log_dir = variable_get('boinc_host_sched_logs_dir', ''); |
|
| 1411 | - $log = ''; |
|
| 1412 | - if ($timestamp) { |
|
| 1409 | + $output = '---'; |
|
| 1410 | + $root_log_dir = variable_get('boinc_host_sched_logs_dir', ''); |
|
| 1411 | + $log = ''; |
|
| 1412 | + if ($timestamp) { |
|
| 1413 | 1413 | $output = gmdate('j M Y | G:i:s', $timestamp) . ' UTC'; |
| 1414 | - } |
|
| 1415 | - if ($root_log_dir AND $host_id) { |
|
| 1414 | + } |
|
| 1415 | + if ($root_log_dir AND $host_id) { |
|
| 1416 | 1416 | $subdir = substr($host_id, 0, -3) OR $subdir = 0; |
| 1417 | 1417 | $log = implode('/', array($root_log_dir, $subdir, $host_id)); |
| 1418 | - } |
|
| 1419 | - if ($log AND file_exists($log)) { |
|
| 1418 | + } |
|
| 1419 | + if ($log AND file_exists($log)) { |
|
| 1420 | 1420 | $output = l($output, "host/{$host_id}/log"); |
| 1421 | - } |
|
| 1422 | - return $output; |
|
| 1421 | + } |
|
| 1422 | + return $output; |
|
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | /** |
| 1426 | 1426 | * |
| 1427 | 1427 | */ |
| 1428 | 1428 | function boincwork_host_venue_selector($host_id) { |
| 1429 | - $output = ''; |
|
| 1430 | - if (function_exists('jump_quickly')) { |
|
| 1429 | + $output = ''; |
|
| 1430 | + if (function_exists('jump_quickly')) { |
|
| 1431 | 1431 | $path = "host/{$host_id}/set-venue"; |
| 1432 | 1432 | $venues = array( |
| 1433 | - "{$path}/generic" => bts('Generic'), |
|
| 1434 | - "{$path}/home" => bts('Home'), |
|
| 1435 | - "{$path}/work" => bts('Work'), |
|
| 1436 | - "{$path}/school" => bts('School') |
|
| 1433 | + "{$path}/generic" => bts('Generic'), |
|
| 1434 | + "{$path}/home" => bts('Home'), |
|
| 1435 | + "{$path}/work" => bts('Work'), |
|
| 1436 | + "{$path}/school" => bts('School') |
|
| 1437 | 1437 | ); |
| 1438 | 1438 | variable_set('jump_use_js_venues-Array', 1); |
| 1439 | 1439 | drupal_add_js(drupal_get_path('module', 'jump') . '/jump.js'); |
@@ -1441,32 +1441,32 @@ discard block |
||
| 1441 | 1441 | // Get current venue |
| 1442 | 1442 | db_set_active('boinc'); |
| 1443 | 1443 | $venue = db_result(db_query( |
| 1444 | - "SELECT venue FROM {host} WHERE id = '%d'", |
|
| 1445 | - $host_id |
|
| 1444 | + "SELECT venue FROM {host} WHERE id = '%d'", |
|
| 1445 | + $host_id |
|
| 1446 | 1446 | )); |
| 1447 | 1447 | db_set_active('default'); |
| 1448 | 1448 | $output .= jump_quickly($venues, 'venues', 1, "{$path}/{$venue}"); |
| 1449 | - } |
|
| 1450 | - return $output; |
|
| 1449 | + } |
|
| 1450 | + return $output; |
|
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | 1453 | /** |
| 1454 | - * Determine output for task reported time / deadline |
|
| 1455 | - */ |
|
| 1454 | + * Determine output for task reported time / deadline |
|
| 1455 | + */ |
|
| 1456 | 1456 | function boincwork_task_time_reported($received_time = NULL, $deadline = NULL, $context = NULL) { |
| 1457 | - $output = '---'; |
|
| 1458 | - if ($received_time OR $deadline) { |
|
| 1457 | + $output = '---'; |
|
| 1458 | + if ($received_time OR $deadline) { |
|
| 1459 | 1459 | $timestamp = ($received_time) ? $received_time : $deadline; |
| 1460 | 1460 | $output = gmdate('j M Y, G:i:s', $timestamp) . ' UTC'; |
| 1461 | 1461 | // Add a wrapper to deadline text |
| 1462 | 1462 | if (!$received_time) { |
| 1463 | - if (time() < $deadline) { |
|
| 1463 | + if (time() < $deadline) { |
|
| 1464 | 1464 | $output = '<span class="on-time">' . $output . '</span>'; |
| 1465 | - } |
|
| 1466 | - else { |
|
| 1465 | + } |
|
| 1466 | + else { |
|
| 1467 | 1467 | $output = '<span class="past-due">' . $output . '</span>'; |
| 1468 | - } |
|
| 1468 | + } |
|
| 1469 | 1469 | } |
| 1470 | - } |
|
| 1471 | - return $output; |
|
| 1470 | + } |
|
| 1471 | + return $output; |
|
| 1472 | 1472 | } |
@@ -643,9 +643,9 @@ |
||
| 643 | 643 | } |
| 644 | 644 | break; |
| 645 | 645 | |
| 646 | - default: |
|
| 647 | - // Don't generate form elements for things that aren't explicitly form |
|
| 648 | - // elements (i.e. 'title', '@attributes' keys, and the like) |
|
| 646 | + default: |
|
| 647 | + // Don't generate form elements for things that aren't explicitly form |
|
| 648 | + // elements (i.e. 'title', '@attributes' keys, and the like) |
|
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | 651 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | if ($preset) { |
| 169 | 169 | // Load preset from configuration |
| 170 | - $preset_prefs = (array) $preset_prefs['general_preferences']; |
|
| 170 | + $preset_prefs = (array)$preset_prefs['general_preferences']; |
|
| 171 | 171 | if (isset($preset_prefs['preset'])) { |
| 172 | 172 | if (!is_numeric(key($preset_prefs['preset']))) { |
| 173 | 173 | $preset_prefs['preset'] = array($preset_prefs['preset']); |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | function boincwork_get_project_specific_config() { |
| 189 | 189 | $raw_config_data = variable_get('boinc_project_specific_prefs_config', ''); |
| 190 | 190 | |
| 191 | - $xsd = './' . drupal_get_path('module', 'boincwork') . '/includes/projectprefs.xsd'; |
|
| 191 | + $xsd = './'.drupal_get_path('module', 'boincwork').'/includes/projectprefs.xsd'; |
|
| 192 | 192 | libxml_use_internal_errors(true); |
| 193 | 193 | |
| 194 | 194 | $xml = new DomDocument(); |
@@ -196,8 +196,8 @@ discard block |
||
| 196 | 196 | if (!$xml->schemaValidate($xsd)) { |
| 197 | 197 | $errors = libxml_get_errors(); |
| 198 | 198 | $lines = explode("\r", $raw_config_data); |
| 199 | - drupal_set_message("{$errors[0]->message} at line {$errors[0]->line}" . |
|
| 200 | - ': <br/>' . htmlentities($lines[$errors[0]->line - 1]), 'error'); |
|
| 199 | + drupal_set_message("{$errors[0]->message} at line {$errors[0]->line}". |
|
| 200 | + ': <br/>'.htmlentities($lines[$errors[0]->line - 1]), 'error'); |
|
| 201 | 201 | return NULL; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -392,13 +392,13 @@ discard block |
||
| 392 | 392 | |
| 393 | 393 | // Use appropriate datatype |
| 394 | 394 | if (isset($element['@attributes']['datatype'])) { |
| 395 | - switch($element['@attributes']['datatype']) { |
|
| 395 | + switch ($element['@attributes']['datatype']) { |
|
| 396 | 396 | case 'integer': |
| 397 | - $value = (int) $value; |
|
| 397 | + $value = (int)$value; |
|
| 398 | 398 | break; |
| 399 | 399 | |
| 400 | 400 | case 'float': |
| 401 | - $value = number_format((float) $value, 2); |
|
| 401 | + $value = number_format((float)$value, 2); |
|
| 402 | 402 | break; |
| 403 | 403 | |
| 404 | 404 | default: |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | '#type' => 'textfield', |
| 421 | 421 | '#default_value' => $value, |
| 422 | 422 | '#size' => 5, |
| 423 | - '#description' => $description . bts(' Default value: @default', array('@default' => $default)) |
|
| 423 | + '#description' => $description.bts(' Default value: @default', array('@default' => $default)) |
|
| 424 | 424 | ); |
| 425 | 425 | } |
| 426 | 426 | break; |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | $name = $element['@attributes']['name']; |
| 485 | 485 | $default = null; |
| 486 | 486 | $options = array(); |
| 487 | - foreach($element['items']['item'] as $item) { |
|
| 487 | + foreach ($element['items']['item'] as $item) { |
|
| 488 | 488 | if (is_array($item)) { |
| 489 | 489 | $value = $item['@value']; |
| 490 | 490 | if ($default === NULL AND |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | '#options' => $options, |
| 527 | 527 | '#attributes' => array('class' => 'fancy'), |
| 528 | 528 | '#default_value' => $value, |
| 529 | - '#description' => $description . bts(' Default value: @default', array('@default' =>$default)) |
|
| 529 | + '#description' => $description.bts(' Default value: @default', array('@default' =>$default)) |
|
| 530 | 530 | ); |
| 531 | 531 | } |
| 532 | 532 | break; |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | } |
| 592 | 592 | foreach ($elements as $key => $element) { |
| 593 | 593 | $title = is_array($element['title']) ? $element['title']['@value'] : $element['title']; |
| 594 | - $name = str_replace(' ','_',strtolower($title)); |
|
| 594 | + $name = str_replace(' ', '_', strtolower($title)); |
|
| 595 | 595 | $name = "group_{$name}"; |
| 596 | 596 | |
| 597 | 597 | // Translate elements as appropriate |
@@ -743,13 +743,13 @@ discard block |
||
| 743 | 743 | if ($type == 'project') { |
| 744 | 744 | if ($boincuser->project_prefs) { |
| 745 | 745 | $main_prefs = load_configuration($boincuser->project_prefs); |
| 746 | - $main_prefs = (array) $main_prefs['project_preferences']; |
|
| 746 | + $main_prefs = (array)$main_prefs['project_preferences']; |
|
| 747 | 747 | } |
| 748 | 748 | } |
| 749 | 749 | else { |
| 750 | 750 | if ($boincuser->global_prefs) { |
| 751 | 751 | $main_prefs = load_configuration($boincuser->global_prefs); |
| 752 | - $main_prefs = (array) $main_prefs['global_preferences']; |
|
| 752 | + $main_prefs = (array)$main_prefs['global_preferences']; |
|
| 753 | 753 | } |
| 754 | 754 | } |
| 755 | 755 | |
@@ -801,13 +801,13 @@ discard block |
||
| 801 | 801 | if ($type == 'project') { |
| 802 | 802 | if ($boincuser->project_prefs) { |
| 803 | 803 | $main_prefs = load_configuration($boincuser->project_prefs); |
| 804 | - $main_prefs = (array) $main_prefs['project_preferences']; |
|
| 804 | + $main_prefs = (array)$main_prefs['project_preferences']; |
|
| 805 | 805 | } |
| 806 | 806 | } |
| 807 | 807 | else { |
| 808 | 808 | if ($boincuser->global_prefs) { |
| 809 | 809 | $main_prefs = load_configuration($boincuser->global_prefs); |
| 810 | - $main_prefs = (array) $main_prefs['global_preferences']; |
|
| 810 | + $main_prefs = (array)$main_prefs['global_preferences']; |
|
| 811 | 811 | } |
| 812 | 812 | } |
| 813 | 813 | |
@@ -996,11 +996,11 @@ discard block |
||
| 996 | 996 | $magnitude = 0; |
| 997 | 997 | $precision = 0; |
| 998 | 998 | if ($digits > $max_digits) { |
| 999 | - $magnitude = floor(($digits - ($max_digits - 3)) / 3); |
|
| 1000 | - $precision = $max_digits - ($digits - ($magnitude * 3) + 1); |
|
| 1001 | - $number = round($number / pow(1000, $magnitude), $precision); |
|
| 999 | + $magnitude = floor(($digits - ($max_digits - 3))/3); |
|
| 1000 | + $precision = $max_digits - ($digits - ($magnitude*3) + 1); |
|
| 1001 | + $number = round($number/pow(1000, $magnitude), $precision); |
|
| 1002 | 1002 | } |
| 1003 | - $number = number_format($number, $precision) . (($magnitude) ? "{$suffix[$magnitude]}" : ''); |
|
| 1003 | + $number = number_format($number, $precision).(($magnitude) ? "{$suffix[$magnitude]}" : ''); |
|
| 1004 | 1004 | |
| 1005 | 1005 | return $number; |
| 1006 | 1006 | } |
@@ -1178,7 +1178,7 @@ discard block |
||
| 1178 | 1178 | |
| 1179 | 1179 | function text_to_xml($text) { |
| 1180 | 1180 | $xml = new DomDocument(); |
| 1181 | - if ( !($xml->loadXML($text)) ) return false; |
|
| 1181 | + if (!($xml->loadXML($text))) return false; |
|
| 1182 | 1182 | return $xml; |
| 1183 | 1183 | } |
| 1184 | 1184 | |
@@ -1195,7 +1195,7 @@ discard block |
||
| 1195 | 1195 | while (!is_null($node)) { |
| 1196 | 1196 | switch ($node->nodeType) { |
| 1197 | 1197 | case XML_TEXT_NODE: |
| 1198 | - if (trim($node->nodeValue) != '') $result = $node->nodeValue; |
|
| 1198 | + if (trim($node->nodeValue) != '') $result = $node->nodeValue; |
|
| 1199 | 1199 | break; |
| 1200 | 1200 | case XML_ELEMENT_NODE: |
| 1201 | 1201 | $node_name = $node->nodeName; |
@@ -1212,7 +1212,7 @@ discard block |
||
| 1212 | 1212 | if ($sibling) { |
| 1213 | 1213 | $result[$node_name][$index] = ''; |
| 1214 | 1214 | if ($node->childNodes) { |
| 1215 | - $result[$node_name][$index] = xml_to_array($node) ; |
|
| 1215 | + $result[$node_name][$index] = xml_to_array($node); |
|
| 1216 | 1216 | } |
| 1217 | 1217 | if ($node->hasAttributes()) { |
| 1218 | 1218 | $attributes = $node->attributes; |
@@ -1235,14 +1235,14 @@ discard block |
||
| 1235 | 1235 | } else { |
| 1236 | 1236 | $result[$node_name] = ''; |
| 1237 | 1237 | if ($node->childNodes) { |
| 1238 | - $result[$node_name] = xml_to_array($node) ; |
|
| 1238 | + $result[$node_name] = xml_to_array($node); |
|
| 1239 | 1239 | } |
| 1240 | 1240 | if ($node->hasAttributes()) { |
| 1241 | 1241 | $attributes = $node->attributes; |
| 1242 | 1242 | if ($result[$node_name] !== '' AND !is_array($result[$node_name])) { |
| 1243 | 1243 | $result[$node_name] = array('@value' => $result[$node_name]); |
| 1244 | 1244 | } |
| 1245 | - foreach($attributes as $key => $attribute) { |
|
| 1245 | + foreach ($attributes as $key => $attribute) { |
|
| 1246 | 1246 | $result[$node_name]['@attributes'][$attribute->name] = $attribute->value; |
| 1247 | 1247 | } |
| 1248 | 1248 | } |
@@ -1282,30 +1282,30 @@ discard block |
||
| 1282 | 1282 | // Determine if hosts are associated at all or just hidden |
| 1283 | 1283 | $output = ''; |
| 1284 | 1284 | if ($boincuser->show_hosts) { |
| 1285 | - switch($context) { |
|
| 1285 | + switch ($context) { |
|
| 1286 | 1286 | case 'active': |
| 1287 | - $output .= '<h2>' . bts('No active computers') . '</h2>'; |
|
| 1288 | - $output .= '<p>' . bts('This user has no computers that have been' |
|
| 1289 | - . ' active in the last 30 days.') . '</p>'; |
|
| 1287 | + $output .= '<h2>'.bts('No active computers').'</h2>'; |
|
| 1288 | + $output .= '<p>'.bts('This user has no computers that have been' |
|
| 1289 | + . ' active in the last 30 days.').'</p>'; |
|
| 1290 | 1290 | break; |
| 1291 | 1291 | |
| 1292 | 1292 | case 'preferences': |
| 1293 | - $output .= '<h2>' . bts('No computers') . '</h2>'; |
|
| 1294 | - $output .= '<p>' . bts('There are no computers assigned to this' |
|
| 1295 | - . ' preference set.') . '</p>'; |
|
| 1293 | + $output .= '<h2>'.bts('No computers').'</h2>'; |
|
| 1294 | + $output .= '<p>'.bts('There are no computers assigned to this' |
|
| 1295 | + . ' preference set.').'</p>'; |
|
| 1296 | 1296 | break; |
| 1297 | 1297 | |
| 1298 | 1298 | default: |
| 1299 | - $output .= '<h2>' . bts('Computers pending') . '</h2>'; |
|
| 1300 | - $output .= '<p>' . bts('This user does not yet have any associated' |
|
| 1299 | + $output .= '<h2>'.bts('Computers pending').'</h2>'; |
|
| 1300 | + $output .= '<p>'.bts('This user does not yet have any associated' |
|
| 1301 | 1301 | . ' computers. Computers will be displayed when they have earned their' |
| 1302 | - . ' first credits.') . '</p>'; |
|
| 1302 | + . ' first credits.').'</p>'; |
|
| 1303 | 1303 | } |
| 1304 | 1304 | } |
| 1305 | 1305 | else { |
| 1306 | - $output .= '<h2>' . bts('Computers hidden') . '</h2>'; |
|
| 1307 | - $output .= '<p>' . bts('This user has chosen not to show information' |
|
| 1308 | - . ' about their computers.') . '</p>'; |
|
| 1306 | + $output .= '<h2>'.bts('Computers hidden').'</h2>'; |
|
| 1307 | + $output .= '<p>'.bts('This user has chosen not to show information' |
|
| 1308 | + . ' about their computers.').'</p>'; |
|
| 1309 | 1309 | } |
| 1310 | 1310 | return $output; |
| 1311 | 1311 | } |
@@ -1317,11 +1317,11 @@ discard block |
||
| 1317 | 1317 | |
| 1318 | 1318 | // |
| 1319 | 1319 | $output = ''; |
| 1320 | - switch($context) { |
|
| 1320 | + switch ($context) { |
|
| 1321 | 1321 | default: |
| 1322 | - $output .= '<h2>' . bts('No @type tasks', array('@type' => $context)) |
|
| 1322 | + $output .= '<h2>'.bts('No @type tasks', array('@type' => $context)) |
|
| 1323 | 1323 | . '</h2>'; |
| 1324 | - $output .= '<p>' . bts('There are no tasks of this type on record') |
|
| 1324 | + $output .= '<p>'.bts('There are no tasks of this type on record') |
|
| 1325 | 1325 | . '</p>'; |
| 1326 | 1326 | } |
| 1327 | 1327 | return $output; |
@@ -1343,10 +1343,10 @@ discard block |
||
| 1343 | 1343 | $output .= l(bts('Delete'), "host/{$host_id}/delete", |
| 1344 | 1344 | array( |
| 1345 | 1345 | 'attributes' => array( |
| 1346 | - 'onclick' => 'return confirm(\'' . bts('This will delete host @id' |
|
| 1346 | + 'onclick' => 'return confirm(\''.bts('This will delete host @id' |
|
| 1347 | 1347 | . ' from your account forever. Are you sure this is OK?', |
| 1348 | 1348 | array('@id' => $host_id) |
| 1349 | - ) . '\')' |
|
| 1349 | + ).'\')' |
|
| 1350 | 1350 | ) |
| 1351 | 1351 | ) |
| 1352 | 1352 | ); |
@@ -1410,7 +1410,7 @@ discard block |
||
| 1410 | 1410 | $root_log_dir = variable_get('boinc_host_sched_logs_dir', ''); |
| 1411 | 1411 | $log = ''; |
| 1412 | 1412 | if ($timestamp) { |
| 1413 | - $output = gmdate('j M Y | G:i:s', $timestamp) . ' UTC'; |
|
| 1413 | + $output = gmdate('j M Y | G:i:s', $timestamp).' UTC'; |
|
| 1414 | 1414 | } |
| 1415 | 1415 | if ($root_log_dir AND $host_id) { |
| 1416 | 1416 | $subdir = substr($host_id, 0, -3) OR $subdir = 0; |
@@ -1436,8 +1436,8 @@ discard block |
||
| 1436 | 1436 | "{$path}/school" => bts('School') |
| 1437 | 1437 | ); |
| 1438 | 1438 | variable_set('jump_use_js_venues-Array', 1); |
| 1439 | - drupal_add_js(drupal_get_path('module', 'jump') . '/jump.js'); |
|
| 1440 | - drupal_add_js(drupal_get_path('theme', 'boinc') . '/js/prefs.js', 'theme'); |
|
| 1439 | + drupal_add_js(drupal_get_path('module', 'jump').'/jump.js'); |
|
| 1440 | + drupal_add_js(drupal_get_path('theme', 'boinc').'/js/prefs.js', 'theme'); |
|
| 1441 | 1441 | // Get current venue |
| 1442 | 1442 | db_set_active('boinc'); |
| 1443 | 1443 | $venue = db_result(db_query( |
@@ -1457,14 +1457,14 @@ discard block |
||
| 1457 | 1457 | $output = '---'; |
| 1458 | 1458 | if ($received_time OR $deadline) { |
| 1459 | 1459 | $timestamp = ($received_time) ? $received_time : $deadline; |
| 1460 | - $output = gmdate('j M Y, G:i:s', $timestamp) . ' UTC'; |
|
| 1460 | + $output = gmdate('j M Y, G:i:s', $timestamp).' UTC'; |
|
| 1461 | 1461 | // Add a wrapper to deadline text |
| 1462 | 1462 | if (!$received_time) { |
| 1463 | 1463 | if (time() < $deadline) { |
| 1464 | - $output = '<span class="on-time">' . $output . '</span>'; |
|
| 1464 | + $output = '<span class="on-time">'.$output.'</span>'; |
|
| 1465 | 1465 | } |
| 1466 | 1466 | else { |
| 1467 | - $output = '<span class="past-due">' . $output . '</span>'; |
|
| 1467 | + $output = '<span class="past-due">'.$output.'</span>'; |
|
| 1468 | 1468 | } |
| 1469 | 1469 | } |
| 1470 | 1470 | } |
@@ -332,8 +332,7 @@ discard block |
||
| 332 | 332 | $name = $element['@attributes']['name']; |
| 333 | 333 | if (isset($element['@attributes']['entitytype']) AND $element['@attributes']['entitytype'] == 'attribute') { |
| 334 | 334 | $defaults['@attributes'][$name] = $values[$name]; |
| 335 | - } |
|
| 336 | - else { |
|
| 335 | + } else { |
|
| 337 | 336 | $defaults[$name] = $values[$name]; |
| 338 | 337 | } |
| 339 | 338 | } |
@@ -384,8 +383,7 @@ discard block |
||
| 384 | 383 | if (isset($user_pref[$name])) { |
| 385 | 384 | if (is_array($user_pref[$name]) AND isset($user_pref[$name]['@value'])) { |
| 386 | 385 | $value = $user_pref[$name]['@value']; |
| 387 | - } |
|
| 388 | - else { |
|
| 386 | + } else { |
|
| 389 | 387 | $value = $user_pref[$name]; |
| 390 | 388 | } |
| 391 | 389 | } |
@@ -447,8 +445,7 @@ discard block |
||
| 447 | 445 | if (isset($user_pref[$name])) { |
| 448 | 446 | if (is_array($user_pref[$name]) AND isset($user_pref[$name]['@value'])) { |
| 449 | 447 | $value = $user_pref[$name]['@value']; |
| 450 | - } |
|
| 451 | - else { |
|
| 448 | + } else { |
|
| 452 | 449 | $value = $user_pref[$name]; |
| 453 | 450 | } |
| 454 | 451 | } |
@@ -492,8 +489,7 @@ discard block |
||
| 492 | 489 | isset($item['@attributes']['selected'])) { |
| 493 | 490 | $default = ($item['@attributes']['selected'] == 'true') ? $item['@value'] : null; |
| 494 | 491 | } |
| 495 | - } |
|
| 496 | - else { |
|
| 492 | + } else { |
|
| 497 | 493 | $value = $item; |
| 498 | 494 | } |
| 499 | 495 | $options[$value] = $value; |
@@ -552,7 +548,9 @@ discard block |
||
| 552 | 548 | $user_prefs['app_id'] = array($user_prefs['app_id']); |
| 553 | 549 | } |
| 554 | 550 | foreach ($user_prefs['app_id'] as $app) { |
| 555 | - if (!$app) continue; |
|
| 551 | + if (!$app) { |
|
| 552 | + continue; |
|
| 553 | + } |
|
| 556 | 554 | if (is_array($app) AND isset($app['@value'])) { |
| 557 | 555 | $app = $app['@value']; |
| 558 | 556 | } |
@@ -696,8 +694,7 @@ discard block |
||
| 696 | 694 | ); |
| 697 | 695 | if ($top_level) { |
| 698 | 696 | $uncategorized[$key] = $prefs_element; |
| 699 | - } |
|
| 700 | - else { |
|
| 697 | + } else { |
|
| 701 | 698 | $prefs_table[$key] = $prefs_element; |
| 702 | 699 | } |
| 703 | 700 | break; |
@@ -711,8 +708,7 @@ discard block |
||
| 711 | 708 | 'name' => bts('Other settings'), |
| 712 | 709 | 'elements' => $uncategorized, |
| 713 | 710 | ); |
| 714 | - } |
|
| 715 | - elseif ($uncategorized) { |
|
| 711 | + } elseif ($uncategorized) { |
|
| 716 | 712 | // If nothing is categorized, output all prefs under a general "settings" |
| 717 | 713 | $prefs_table['settings'] = array( |
| 718 | 714 | 'name' => bts('Settings'), |
@@ -745,8 +741,7 @@ discard block |
||
| 745 | 741 | $main_prefs = load_configuration($boincuser->project_prefs); |
| 746 | 742 | $main_prefs = (array) $main_prefs['project_preferences']; |
| 747 | 743 | } |
| 748 | - } |
|
| 749 | - else { |
|
| 744 | + } else { |
|
| 750 | 745 | if ($boincuser->global_prefs) { |
| 751 | 746 | $main_prefs = load_configuration($boincuser->global_prefs); |
| 752 | 747 | $main_prefs = (array) $main_prefs['global_preferences']; |
@@ -759,11 +754,11 @@ discard block |
||
| 759 | 754 | // Use the length of the $main_prefs array as a condition as to |
| 760 | 755 | // whether the preferences have already been set. This is |
| 761 | 756 | // HARDCODED here. |
| 762 | - if (count($main_prefs) < 3) |
|
| 763 | - $main_prefs['@attributes'] = array('cleared' => 1); |
|
| 757 | + if (count($main_prefs) < 3) { |
|
| 758 | + $main_prefs['@attributes'] = array('cleared' => 1); |
|
| 759 | + } |
|
| 764 | 760 | return $main_prefs; |
| 765 | - } |
|
| 766 | - else { |
|
| 761 | + } else { |
|
| 767 | 762 | if (isset($main_prefs['venue'])) { |
| 768 | 763 | if (!is_numeric(key($main_prefs['venue']))) { |
| 769 | 764 | $main_prefs['venue'] = array($main_prefs['venue']); |
@@ -803,8 +798,7 @@ discard block |
||
| 803 | 798 | $main_prefs = load_configuration($boincuser->project_prefs); |
| 804 | 799 | $main_prefs = (array) $main_prefs['project_preferences']; |
| 805 | 800 | } |
| 806 | - } |
|
| 807 | - else { |
|
| 801 | + } else { |
|
| 808 | 802 | if ($boincuser->global_prefs) { |
| 809 | 803 | $main_prefs = load_configuration($boincuser->global_prefs); |
| 810 | 804 | $main_prefs = (array) $main_prefs['global_preferences']; |
@@ -817,8 +811,7 @@ discard block |
||
| 817 | 811 | if (!$venue OR $venue == 'generic') { |
| 818 | 812 | //$main_prefs = $prefs; |
| 819 | 813 | $main_prefs = $prefs + $main_prefs; |
| 820 | - } |
|
| 821 | - else { |
|
| 814 | + } else { |
|
| 822 | 815 | if (isset($main_prefs['venue'])) { |
| 823 | 816 | if (!is_numeric(key($main_prefs['venue']))) { |
| 824 | 817 | $main_prefs['venue'] = array($main_prefs['venue']); |
@@ -827,8 +820,7 @@ discard block |
||
| 827 | 820 | if (isset($prefs_venue['@attributes']['name']) AND $prefs_venue['@attributes']['name'] == $venue) { |
| 828 | 821 | if ($prefs) { |
| 829 | 822 | $main_prefs['venue'][$key] = $prefs; |
| 830 | - } |
|
| 831 | - else { |
|
| 823 | + } else { |
|
| 832 | 824 | // If prefs is null, clear out this preference set |
| 833 | 825 | unset($main_prefs['venue'][$key]); |
| 834 | 826 | if (count($main_prefs['venue']) == 0) { |
@@ -870,8 +862,7 @@ discard block |
||
| 870 | 862 | db_set_active('boinc'); |
| 871 | 863 | $result = db_query("UPDATE user SET project_prefs = '{$boincuser->project_prefs}' WHERE id = '{$boincuser->id}'"); |
| 872 | 864 | db_set_active('default'); |
| 873 | - } |
|
| 874 | - else { |
|
| 865 | + } else { |
|
| 875 | 866 | $main_prefs = array('global_preferences' => $main_prefs); |
| 876 | 867 | $boincuser->global_prefs = save_configuration($main_prefs); |
| 877 | 868 | db_set_active('boinc'); |
@@ -919,15 +910,13 @@ discard block |
||
| 919 | 910 | // Process nested form elements |
| 920 | 911 | $parents[] = $field; |
| 921 | 912 | boincwork_validate_form($rules, $values[$field], $parents); |
| 922 | - } |
|
| 923 | - else { |
|
| 913 | + } else { |
|
| 924 | 914 | if ($parents) { |
| 925 | 915 | // form_set_error() identifies nested form elements with '][' as a |
| 926 | 916 | // delimiter between each parent and child element |
| 927 | 917 | $parents[] = $field; |
| 928 | 918 | $form_field = implode('][', $parents); |
| 929 | - } |
|
| 930 | - else { |
|
| 919 | + } else { |
|
| 931 | 920 | $form_field = $field; |
| 932 | 921 | } |
| 933 | 922 | if (isset($rules['datatype']) AND !boincwork_validate_datatype($values[$field], $rules['datatype'])) { |
@@ -990,7 +979,9 @@ discard block |
||
| 990 | 979 | 7 => 'Z', |
| 991 | 980 | 8 => 'Y' |
| 992 | 981 | ); |
| 993 | - if (!is_numeric($number)) $number = 0; |
|
| 982 | + if (!is_numeric($number)) { |
|
| 983 | + $number = 0; |
|
| 984 | + } |
|
| 994 | 985 | |
| 995 | 986 | $digits = floor(log($number, 10)) + 1; |
| 996 | 987 | $magnitude = 0; |
@@ -1012,8 +1003,12 @@ discard block |
||
| 1012 | 1003 | |
| 1013 | 1004 | function load_configuration($text) |
| 1014 | 1005 | { |
| 1015 | - if (preg_match('/^\<\?xml .*\?\>$/i', $text)) return null; |
|
| 1016 | - if ($xml = text_to_xml($text)) return xml_to_array($xml); |
|
| 1006 | + if (preg_match('/^\<\?xml .*\?\>$/i', $text)) { |
|
| 1007 | + return null; |
|
| 1008 | + } |
|
| 1009 | + if ($xml = text_to_xml($text)) { |
|
| 1010 | + return xml_to_array($xml); |
|
| 1011 | + } |
|
| 1017 | 1012 | return false; |
| 1018 | 1013 | } |
| 1019 | 1014 | |
@@ -1023,7 +1018,9 @@ discard block |
||
| 1023 | 1018 | |
| 1024 | 1019 | function save_configuration($array) |
| 1025 | 1020 | { |
| 1026 | - if ($xml = array_to_xml($array)) return xml_to_text($xml, false, true); |
|
| 1021 | + if ($xml = array_to_xml($array)) { |
|
| 1022 | + return xml_to_text($xml, false, true); |
|
| 1023 | + } |
|
| 1027 | 1024 | return false; |
| 1028 | 1025 | } |
| 1029 | 1026 | |
@@ -1034,7 +1031,9 @@ discard block |
||
| 1034 | 1031 | |
| 1035 | 1032 | function array_to_xml($array, $dom = false, $parent_node = false) { |
| 1036 | 1033 | $is_root = false; |
| 1037 | - if (!$dom) $dom = new DomDocument('1.0'); |
|
| 1034 | + if (!$dom) { |
|
| 1035 | + $dom = new DomDocument('1.0'); |
|
| 1036 | + } |
|
| 1038 | 1037 | if (!$parent_node) { |
| 1039 | 1038 | $parent_node = $dom; |
| 1040 | 1039 | $is_root = true; |
@@ -1054,26 +1053,22 @@ discard block |
||
| 1054 | 1053 | $ordered_array[$item['@position']] = array( |
| 1055 | 1054 | $name => $item |
| 1056 | 1055 | ); |
| 1057 | - } |
|
| 1058 | - else { |
|
| 1056 | + } else { |
|
| 1059 | 1057 | $unordered_array[] = array( |
| 1060 | 1058 | $name => $item |
| 1061 | 1059 | ); |
| 1062 | 1060 | } |
| 1063 | 1061 | } |
| 1064 | - } |
|
| 1065 | - elseif (isset($value['@position'])) { |
|
| 1062 | + } elseif (isset($value['@position'])) { |
|
| 1066 | 1063 | $ordered_array[$value['@position']] = array( |
| 1067 | 1064 | $name => $value |
| 1068 | 1065 | ); |
| 1069 | - } |
|
| 1070 | - else { |
|
| 1066 | + } else { |
|
| 1071 | 1067 | $unordered_array[] = array( |
| 1072 | 1068 | $name => $value |
| 1073 | 1069 | ); |
| 1074 | 1070 | } |
| 1075 | - } |
|
| 1076 | - else { |
|
| 1071 | + } else { |
|
| 1077 | 1072 | $unordered_array[] = array( |
| 1078 | 1073 | $name => $value |
| 1079 | 1074 | ); |
@@ -1087,12 +1082,16 @@ discard block |
||
| 1087 | 1082 | foreach ($primed_array as $item) { |
| 1088 | 1083 | list($name, $value) = each($item); |
| 1089 | 1084 | if (strcmp($name, '@attributes') == 0) { |
| 1090 | - if (!is_array($value)) continue; |
|
| 1085 | + if (!is_array($value)) { |
|
| 1086 | + continue; |
|
| 1087 | + } |
|
| 1091 | 1088 | foreach ($value as $attributeName => $attributeValue) { |
| 1092 | 1089 | $parent_node->setAttribute($attributeName, $attributeValue); |
| 1093 | 1090 | } |
| 1094 | 1091 | } elseif (strcmp($name, '@value') == 0) { |
| 1095 | - if (isset($value)) $parent_node->nodeValue = $value; |
|
| 1092 | + if (isset($value)) { |
|
| 1093 | + $parent_node->nodeValue = $value; |
|
| 1094 | + } |
|
| 1096 | 1095 | } elseif (strcmp($name, '@position') == 0) { |
| 1097 | 1096 | continue; |
| 1098 | 1097 | } else { |
@@ -1114,7 +1113,9 @@ discard block |
||
| 1114 | 1113 | $parent_node->appendChild(array_to_xml($value, $dom, $current_node)); |
| 1115 | 1114 | } |
| 1116 | 1115 | } else { |
| 1117 | - if (isset($value)) $current_item->nodeValue = $value; |
|
| 1116 | + if (isset($value)) { |
|
| 1117 | + $current_item->nodeValue = $value; |
|
| 1118 | + } |
|
| 1118 | 1119 | $parent_node->appendChild($current_item); |
| 1119 | 1120 | } |
| 1120 | 1121 | } |
@@ -1178,7 +1179,9 @@ discard block |
||
| 1178 | 1179 | |
| 1179 | 1180 | function text_to_xml($text) { |
| 1180 | 1181 | $xml = new DomDocument(); |
| 1181 | - if ( !($xml->loadXML($text)) ) return false; |
|
| 1182 | + if ( !($xml->loadXML($text)) ) { |
|
| 1183 | + return false; |
|
| 1184 | + } |
|
| 1182 | 1185 | return $xml; |
| 1183 | 1186 | } |
| 1184 | 1187 | |
@@ -1195,7 +1198,9 @@ discard block |
||
| 1195 | 1198 | while (!is_null($node)) { |
| 1196 | 1199 | switch ($node->nodeType) { |
| 1197 | 1200 | case XML_TEXT_NODE: |
| 1198 | - if (trim($node->nodeValue) != '') $result = $node->nodeValue; |
|
| 1201 | + if (trim($node->nodeValue) != '') { |
|
| 1202 | + $result = $node->nodeValue; |
|
| 1203 | + } |
|
| 1199 | 1204 | break; |
| 1200 | 1205 | case XML_ELEMENT_NODE: |
| 1201 | 1206 | $node_name = $node->nodeName; |
@@ -1203,10 +1208,14 @@ discard block |
||
| 1203 | 1208 | $sibling = $node->nextSibling; |
| 1204 | 1209 | |
| 1205 | 1210 | // Determine if this node forms a set with siblings (share a node name) |
| 1206 | - while (($sibling) AND (($sibling->nodeType != XML_ELEMENT_NODE) OR ($sibling->nodeName != $node->nodeName))) $sibling = $sibling->nextSibling; |
|
| 1211 | + while (($sibling) AND (($sibling->nodeType != XML_ELEMENT_NODE) OR ($sibling->nodeName != $node->nodeName))) { |
|
| 1212 | + $sibling = $sibling->nextSibling; |
|
| 1213 | + } |
|
| 1207 | 1214 | if (!$sibling) { |
| 1208 | 1215 | $sibling = $node->previousSibling; |
| 1209 | - while (($sibling) AND (($sibling->nodeType != XML_ELEMENT_NODE) OR ($sibling->nodeName != $node->nodeName))) $sibling = $sibling->previousSibling; |
|
| 1216 | + while (($sibling) AND (($sibling->nodeType != XML_ELEMENT_NODE) OR ($sibling->nodeName != $node->nodeName))) { |
|
| 1217 | + $sibling = $sibling->previousSibling; |
|
| 1218 | + } |
|
| 1210 | 1219 | } |
| 1211 | 1220 | |
| 1212 | 1221 | if ($sibling) { |
@@ -1301,8 +1310,7 @@ discard block |
||
| 1301 | 1310 | . ' computers. Computers will be displayed when they have earned their' |
| 1302 | 1311 | . ' first credits.') . '</p>'; |
| 1303 | 1312 | } |
| 1304 | - } |
|
| 1305 | - else { |
|
| 1313 | + } else { |
|
| 1306 | 1314 | $output .= '<h2>' . bts('Computers hidden') . '</h2>'; |
| 1307 | 1315 | $output .= '<p>' . bts('This user has chosen not to show information' |
| 1308 | 1316 | . ' about their computers.') . '</p>'; |
@@ -1462,8 +1470,7 @@ discard block |
||
| 1462 | 1470 | if (!$received_time) { |
| 1463 | 1471 | if (time() < $deadline) { |
| 1464 | 1472 | $output = '<span class="on-time">' . $output . '</span>'; |
| 1465 | - } |
|
| 1466 | - else { |
|
| 1473 | + } else { |
|
| 1467 | 1474 | $output = '<span class="past-due">' . $output . '</span>'; |
| 1468 | 1475 | } |
| 1469 | 1476 | } |
@@ -1,6 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | // $Id: bbcode-filter.inc,v 1.66 2008/11/30 08:50:08 naudefj Exp $ |
| 3 | 3 | |
| 4 | +/** |
|
| 5 | + * @param string $body |
|
| 6 | + */ |
|
| 4 | 7 | function _bbcode_filter_process(&$body, $format = -1) { |
| 5 | 8 | |
| 6 | 9 | $quote_text = t('Quote:'); |
@@ -3,128 +3,128 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | function _bbcode_filter_process(&$body, $format = -1) { |
| 5 | 5 | |
| 6 | - $quote_text = t('Quote:'); |
|
| 7 | - $quote_user = t('\\1 wrote:'); |
|
| 6 | + $quote_text = t('Quote:'); |
|
| 7 | + $quote_user = t('\\1 wrote:'); |
|
| 8 | 8 | |
| 9 | - // Encode all script tags to prevent XSS html injection attacks |
|
| 10 | - $body = preg_replace(array('#<script([^>]*)>#i', '#</script([^>]*)>#i'), array('<script\\1>', '</script\\1>'), $body); |
|
| 9 | + // Encode all script tags to prevent XSS html injection attacks |
|
| 10 | + $body = preg_replace(array('#<script([^>]*)>#i', '#</script([^>]*)>#i'), array('<script\\1>', '</script\\1>'), $body); |
|
| 11 | 11 | |
| 12 | - // Find all [code] tags and check if they contain a newline. If we find a newline, |
|
| 13 | - // that [code] should be rendered as a block, otherwise it will still be inline |
|
| 14 | - $mode = variable_get("bbcode_paragraph_breaks_$format", 2); |
|
| 15 | - $pre = array(); $i = 0; |
|
| 16 | - if (preg_match_all('#\[code(?::\w+)?\](.*?)\[/code(?::\w+)?\]#si', $body, $code_tags, PREG_SET_ORDER)) { |
|
| 12 | + // Find all [code] tags and check if they contain a newline. If we find a newline, |
|
| 13 | + // that [code] should be rendered as a block, otherwise it will still be inline |
|
| 14 | + $mode = variable_get("bbcode_paragraph_breaks_$format", 2); |
|
| 15 | + $pre = array(); $i = 0; |
|
| 16 | + if (preg_match_all('#\[code(?::\w+)?\](.*?)\[/code(?::\w+)?\]#si', $body, $code_tags, PREG_SET_ORDER)) { |
|
| 17 | 17 | foreach ($code_tags as $code_tag) { |
| 18 | - $code_tag[1] = str_replace(array('<', '>'), array('<', '>'), $code_tag[1]); |
|
| 19 | - if (strpos($code_tag[1], "\n") === FALSE) |
|
| 18 | + $code_tag[1] = str_replace(array('<', '>'), array('<', '>'), $code_tag[1]); |
|
| 19 | + if (strpos($code_tag[1], "\n") === FALSE) |
|
| 20 | 20 | $body = str_replace($code_tag[0], '<code class="bb-code">'. $code_tag[1] .'</code>', $body); |
| 21 | - elseif ($mode) { |
|
| 21 | + elseif ($mode) { |
|
| 22 | 22 | // Strip preformatted code blocks from text during line break processing, replaced below |
| 23 | 23 | $body = str_replace($code_tag[0], "***pRe_sTrInG$i***", $body); |
| 24 | 24 | $pre[$i++] = '<pre class="bb-code-block">'. $code_tag[1] .'</pre>'; |
| 25 | - } |
|
| 26 | - else |
|
| 25 | + } |
|
| 26 | + else |
|
| 27 | 27 | $body = str_replace($code_tag[0], '<pre class="bb-code-block">'. $code_tag[1] .'</pre>', $body); |
| 28 | 28 | } |
| 29 | - } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - // Apply line and paragraph breaks (skipping preformatted code) |
|
| 32 | - if ($mode) { |
|
| 31 | + // Apply line and paragraph breaks (skipping preformatted code) |
|
| 32 | + if ($mode) { |
|
| 33 | 33 | |
| 34 | 34 | if ($mode == 1) // Line breaks only (starting with PHP 4.0.5, nl2br() is XHTML compliant) |
| 35 | - $body = nl2br($body); |
|
| 35 | + $body = nl2br($body); |
|
| 36 | 36 | |
| 37 | 37 | if ($mode == 2) { // Line and paragraph breaks (may not always be XHTML compliant) |
| 38 | - $body = preg_replace("/(\r\n|\n|\r)/", "\n", $body); |
|
| 39 | - $body = preg_replace("/\n\n+/", "\n\n", $body); |
|
| 40 | - $parts = explode("\n\n", $body); |
|
| 41 | - for ($i=0; $i<sizeof($parts); $i++) { |
|
| 42 | - // No linebreaks if paragraph starts with an HTML tag |
|
| 43 | - if ( !preg_match('/^<.*>/', $parts[$i]) ) |
|
| 44 | - $parts[$i] = nl2br($parts[$i]); |
|
| 45 | - |
|
| 46 | - // Some tags should not be in paragraph blocks |
|
| 47 | - if ( !preg_match('/^(?:<|\[)(?:table|list|ol|ul|pre|select|form|blockquote|hr)/i', $parts[$i]) ) |
|
| 48 | - $parts[$i] = '<p>'. $parts[$i] .'</p>'; |
|
| 49 | - } |
|
| 50 | - $body = implode("\n\n", $parts); |
|
| 38 | + $body = preg_replace("/(\r\n|\n|\r)/", "\n", $body); |
|
| 39 | + $body = preg_replace("/\n\n+/", "\n\n", $body); |
|
| 40 | + $parts = explode("\n\n", $body); |
|
| 41 | + for ($i=0; $i<sizeof($parts); $i++) { |
|
| 42 | + // No linebreaks if paragraph starts with an HTML tag |
|
| 43 | + if ( !preg_match('/^<.*>/', $parts[$i]) ) |
|
| 44 | + $parts[$i] = nl2br($parts[$i]); |
|
| 45 | + |
|
| 46 | + // Some tags should not be in paragraph blocks |
|
| 47 | + if ( !preg_match('/^(?:<|\[)(?:table|list|ol|ul|pre|select|form|blockquote|hr)/i', $parts[$i]) ) |
|
| 48 | + $parts[$i] = '<p>'. $parts[$i] .'</p>'; |
|
| 49 | + } |
|
| 50 | + $body = implode("\n\n", $parts); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Reinsert preformatted code blocks |
| 54 | 54 | foreach ($pre as $i => $code_tag) |
| 55 | - $body = str_replace("***pRe_sTrInG$i***", $code_tag, $body); |
|
| 56 | - } |
|
| 55 | + $body = str_replace("***pRe_sTrInG$i***", $code_tag, $body); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - // Replace any improper quote tags with proper quote tags |
|
| 59 | - $body = str_replace('[quote/]', '[/quote]', $body); |
|
| 58 | + // Replace any improper quote tags with proper quote tags |
|
| 59 | + $body = str_replace('[quote/]', '[/quote]', $body); |
|
| 60 | 60 | |
| 61 | - // Add closing tags to prevent users from disruping your site's HTML |
|
| 62 | - // (required for nestable tags only: [list] and [quote]) |
|
| 63 | - preg_match_all('/\[quote/i', $body, $matches); |
|
| 64 | - $opentags = count($matches['0']); |
|
| 65 | - preg_match_all('/\[\/quote\]/i', $body, $matches); |
|
| 66 | - $unclosed = $opentags - count($matches['0']); |
|
| 67 | - for ($i = 0; $i < $unclosed; $i++) { |
|
| 61 | + // Add closing tags to prevent users from disruping your site's HTML |
|
| 62 | + // (required for nestable tags only: [list] and [quote]) |
|
| 63 | + preg_match_all('/\[quote/i', $body, $matches); |
|
| 64 | + $opentags = count($matches['0']); |
|
| 65 | + preg_match_all('/\[\/quote\]/i', $body, $matches); |
|
| 66 | + $unclosed = $opentags - count($matches['0']); |
|
| 67 | + for ($i = 0; $i < $unclosed; $i++) { |
|
| 68 | 68 | $body .= '[/quote]'; |
| 69 | - } |
|
| 70 | - // Also add opening tags, if needed |
|
| 71 | - for ($i = $unclosed; $i < 0; $i++) { |
|
| 69 | + } |
|
| 70 | + // Also add opening tags, if needed |
|
| 71 | + for ($i = $unclosed; $i < 0; $i++) { |
|
| 72 | 72 | $body = '[quote]' . $body; |
| 73 | - } |
|
| 74 | - preg_match_all('/\[list/i', $body, $matches); |
|
| 75 | - $opentags = count($matches['0']); |
|
| 76 | - preg_match_all('/\[\/list\]/i', $body, $matches); |
|
| 77 | - $unclosed = $opentags - count($matches['0']); |
|
| 78 | - for ($i = 0; $i < $unclosed; $i++) { |
|
| 73 | + } |
|
| 74 | + preg_match_all('/\[list/i', $body, $matches); |
|
| 75 | + $opentags = count($matches['0']); |
|
| 76 | + preg_match_all('/\[\/list\]/i', $body, $matches); |
|
| 77 | + $unclosed = $opentags - count($matches['0']); |
|
| 78 | + for ($i = 0; $i < $unclosed; $i++) { |
|
| 79 | 79 | $body .= '[/list]'; |
| 80 | - } |
|
| 81 | - for ($i = $unclosed; $i < 0; $i++) { |
|
| 80 | + } |
|
| 81 | + for ($i = $unclosed; $i < 0; $i++) { |
|
| 82 | 82 | $body = '[list]' . $body; |
| 83 | - } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // begin processing for [size] |
|
| 86 | - if (stristr($body, '[size=') !== FALSE) { // prevent useless processing |
|
| 85 | + // begin processing for [size] |
|
| 86 | + if (stristr($body, '[size=') !== FALSE) { // prevent useless processing |
|
| 87 | 87 | $arr = array( |
| 88 | - 'tag' => 'size', |
|
| 89 | - 'pattern' => '#\[\x07=([\d]+)(?::\w+)?\]([^\x07]*)\[/\x07(?::\w+)?\]#esi', |
|
| 90 | - 'replacement' => '"<span style=\"font-size:". _bbcode_round_size_val(\'$1\') ."px\">". str_replace(\'\"\', \'"\', \'$2\') ."</span>"', |
|
| 91 | - 'text' => $body); |
|
| 88 | + 'tag' => 'size', |
|
| 89 | + 'pattern' => '#\[\x07=([\d]+)(?::\w+)?\]([^\x07]*)\[/\x07(?::\w+)?\]#esi', |
|
| 90 | + 'replacement' => '"<span style=\"font-size:". _bbcode_round_size_val(\'$1\') ."px\">". str_replace(\'\"\', \'"\', \'$2\') ."</span>"', |
|
| 91 | + 'text' => $body); |
|
| 92 | 92 | $body = _bbcode_replace_nest_tag($arr); |
| 93 | - } // end processing for [size] |
|
| 93 | + } // end processing for [size] |
|
| 94 | 94 | |
| 95 | - // begin processing for [color] |
|
| 96 | - if (stristr($body, '[color=') !== FALSE) { // prevent useless processing |
|
| 95 | + // begin processing for [color] |
|
| 96 | + if (stristr($body, '[color=') !== FALSE) { // prevent useless processing |
|
| 97 | 97 | $arr = array( |
| 98 | - 'tag' => 'color', |
|
| 99 | - 'pattern' => '#\[\x07=([\#\w]+)(?::\w+)?\]([^\x07]*)\[/\x07(?::\w+)?\]#si', |
|
| 100 | - 'replacement' => '<span style="color:$1">$2</span>', |
|
| 101 | - 'text' => $body); |
|
| 98 | + 'tag' => 'color', |
|
| 99 | + 'pattern' => '#\[\x07=([\#\w]+)(?::\w+)?\]([^\x07]*)\[/\x07(?::\w+)?\]#si', |
|
| 100 | + 'replacement' => '<span style="color:$1">$2</span>', |
|
| 101 | + 'text' => $body); |
|
| 102 | 102 | $body = _bbcode_replace_nest_tag($arr); |
| 103 | - } // end processing for [color] |
|
| 103 | + } // end processing for [color] |
|
| 104 | 104 | |
| 105 | - // begin processing for [font] |
|
| 106 | - if (stristr($body, '[font=') !== FALSE) { // prevent useless processing |
|
| 105 | + // begin processing for [font] |
|
| 106 | + if (stristr($body, '[font=') !== FALSE) { // prevent useless processing |
|
| 107 | 107 | $arr = array( |
| 108 | - 'tag' => 'font', |
|
| 109 | - 'pattern' => '#\[\x07=([\w\s]+)(?::\w+)?\]([^\x07]*)\[/\x07(?::\w+)?\]#si', |
|
| 110 | - 'replacement' => '<span style="font-family:$1">$2</span>', |
|
| 111 | - 'text' => $body); |
|
| 108 | + 'tag' => 'font', |
|
| 109 | + 'pattern' => '#\[\x07=([\w\s]+)(?::\w+)?\]([^\x07]*)\[/\x07(?::\w+)?\]#si', |
|
| 110 | + 'replacement' => '<span style="font-family:$1">$2</span>', |
|
| 111 | + 'text' => $body); |
|
| 112 | 112 | $body = _bbcode_replace_nest_tag($arr); |
| 113 | - } // end processing for [font] |
|
| 113 | + } // end processing for [font] |
|
| 114 | 114 | |
| 115 | - // begin processing for [list] and [*] |
|
| 116 | - if (stristr($body, '[list') !== FALSE) { // prevent useless processing |
|
| 115 | + // begin processing for [list] and [*] |
|
| 116 | + if (stristr($body, '[list') !== FALSE) { // prevent useless processing |
|
| 117 | 117 | $l_type = array( |
| 118 | - NULL => array('style' => 'circle', 'tag' => 'ul'), |
|
| 119 | - 'c' => array('style' => 'circle', 'tag' => 'ul'), |
|
| 120 | - 'd' => array('style' => 'disc', 'tag' => 'ul'), |
|
| 121 | - 's' => array('style' => 'square', 'tag' => 'ul'), |
|
| 122 | - '1' => array('style' => 'decimal', 'tag' => 'ol'), |
|
| 123 | - 'a' => array('style' => 'lower-alpha', 'tag' => 'ol'), |
|
| 124 | - 'A' => array('style' => 'upper-alpha', 'tag' => 'ol'), |
|
| 125 | - 'i' => array('style' => 'lower-roman', 'tag' => 'ol'), |
|
| 126 | - 'I' => array('style' => 'upper-roman', 'tag' => 'ol') |
|
| 127 | - ); |
|
| 118 | + NULL => array('style' => 'circle', 'tag' => 'ul'), |
|
| 119 | + 'c' => array('style' => 'circle', 'tag' => 'ul'), |
|
| 120 | + 'd' => array('style' => 'disc', 'tag' => 'ul'), |
|
| 121 | + 's' => array('style' => 'square', 'tag' => 'ul'), |
|
| 122 | + '1' => array('style' => 'decimal', 'tag' => 'ol'), |
|
| 123 | + 'a' => array('style' => 'lower-alpha', 'tag' => 'ol'), |
|
| 124 | + 'A' => array('style' => 'upper-alpha', 'tag' => 'ol'), |
|
| 125 | + 'i' => array('style' => 'lower-roman', 'tag' => 'ol'), |
|
| 126 | + 'I' => array('style' => 'upper-roman', 'tag' => 'ol') |
|
| 127 | + ); |
|
| 128 | 128 | $body = preg_replace('#(\[[/]*)list(.*?\])#si', "$1\x07$2", $body); |
| 129 | 129 | |
| 130 | 130 | // replace to <li> tags - [*]..[*]|[*]..[/list] |
@@ -139,15 +139,15 @@ discard block |
||
| 139 | 139 | // replace to <ol>/<ul> and </ol>/</ul> tags |
| 140 | 140 | // It will be better to use &count and do-while, if php 5 or higher. |
| 141 | 141 | while (preg_match("#\[\x07[=]*((?-i)[cds1aAiI])*(?::\w+)?\]([^\x07]*)\[/\x07(?::\w+)?\]#si", $body)) { |
| 142 | - $body = preg_replace("#\[\x07[=]*((?-i)[cds1aAiI])*(?::\w+)?\]([^\x07]*)\[/\x07(?::\w+)?\]#esi", '"<". $l_type[\'$1\']["tag"] ." class=\"bb-list\" style=\"list-style-type:". $l_type[\'$1\']["style"] .";\">". str_replace(\'\"\', \'"\', \'$2\') ."</". $l_type[\'$1\']["tag"] .">"', $body); |
|
| 142 | + $body = preg_replace("#\[\x07[=]*((?-i)[cds1aAiI])*(?::\w+)?\]([^\x07]*)\[/\x07(?::\w+)?\]#esi", '"<". $l_type[\'$1\']["tag"] ." class=\"bb-list\" style=\"list-style-type:". $l_type[\'$1\']["style"] .";\">". str_replace(\'\"\', \'"\', \'$2\') ."</". $l_type[\'$1\']["tag"] .">"', $body); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // remove <br /> tags |
| 146 | 146 | $body = preg_replace('#(<[/]*([uo]l|li).*>.*)<br />#i', '$1', $body); |
| 147 | - } // end processing for [list] and [*] |
|
| 147 | + } // end processing for [list] and [*] |
|
| 148 | 148 | |
| 149 | - // Define BBCode tags |
|
| 150 | - $preg = array( |
|
| 149 | + // Define BBCode tags |
|
| 150 | + $preg = array( |
|
| 151 | 151 | // Implement [notag] |
| 152 | 152 | '#\[notag(?::\w+)?\](.*?)\[/notag(?::\w+)?\]#sie' => '_bbcode_notag_tag(\'\\1\')', |
| 153 | 153 | |
@@ -215,36 +215,36 @@ discard block |
||
| 215 | 215 | // Cleanup table output (td, th and tr tags) |
| 216 | 216 | '#<([\/]?)t([dhr])><br />#si' => '<\\1t\\2>', |
| 217 | 217 | '#<table(.+?)><br />#si' => '<table\\1>', |
| 218 | - ); |
|
| 219 | - $body = preg_replace(array_keys($preg), array_values($preg), $body); |
|
| 218 | + ); |
|
| 219 | + $body = preg_replace(array_keys($preg), array_values($preg), $body); |
|
| 220 | 220 | |
| 221 | - // Simple replacements (str_replace is faster than preg_replace) |
|
| 222 | - $str = array( |
|
| 221 | + // Simple replacements (str_replace is faster than preg_replace) |
|
| 222 | + $str = array( |
|
| 223 | 223 | // Horizontal delimiter |
| 224 | 224 | '[hr]' => '<hr class="bb-hr" />', |
| 225 | 225 | // Force line break |
| 226 | 226 | '[br]' => '<br class="bb-br" />', |
| 227 | 227 | // Force space |
| 228 | 228 | '[sp]' => ' ', |
| 229 | - ); |
|
| 230 | - $body = str_replace(array_keys($str), array_values($str), $body); |
|
| 229 | + ); |
|
| 230 | + $body = str_replace(array_keys($str), array_values($str), $body); |
|
| 231 | 231 | |
| 232 | - // We cannot evaluate the variable in callback function because |
|
| 233 | - // there is no way to pass the $format variable |
|
| 234 | - if (variable_get("bbcode_encode_mailto_$format", 1)) { |
|
| 232 | + // We cannot evaluate the variable in callback function because |
|
| 233 | + // there is no way to pass the $format variable |
|
| 234 | + if (variable_get("bbcode_encode_mailto_$format", 1)) { |
|
| 235 | 235 | // Replacing email addresses with encoded html |
| 236 | 236 | $body = preg_replace_callback('#\[email(?::\w+)?\]([\w\.\-\+~@]+)\[/email(?::\w+)?\]#si', '_bbcode_encode_mailto', $body); |
| 237 | 237 | $body = preg_replace_callback('#\[email=(.*?)(?::\w+)?\](.*?)\[/email(?::\w+)?\]#si', '_bbcode_encode_mailto', $body); |
| 238 | - } |
|
| 239 | - else { |
|
| 238 | + } |
|
| 239 | + else { |
|
| 240 | 240 | $body = preg_replace( |
| 241 | - array('#\[email(?::\w+)?\](.*?)\[/email(?::\w+)?\]#si','#\[email=(.*?)(?::\w+)?\]([\w\s]+)\[/email(?::\w+)?\]#si'), |
|
| 242 | - array('<a href="mailto:\\1" class="bb-email">\\1</a>', '<a href="mailto:\\1" class="bb-email">\\2</a>'), |
|
| 243 | - $body); |
|
| 244 | - } |
|
| 241 | + array('#\[email(?::\w+)?\](.*?)\[/email(?::\w+)?\]#si','#\[email=(.*?)(?::\w+)?\]([\w\s]+)\[/email(?::\w+)?\]#si'), |
|
| 242 | + array('<a href="mailto:\\1" class="bb-email">\\1</a>', '<a href="mailto:\\1" class="bb-email">\\2</a>'), |
|
| 243 | + $body); |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - // Turns web and e-mail addresses into clickable links |
|
| 247 | - if (variable_get("bbcode_make_links_$format", 1)) { |
|
| 246 | + // Turns web and e-mail addresses into clickable links |
|
| 247 | + if (variable_get("bbcode_make_links_$format", 1)) { |
|
| 248 | 248 | |
| 249 | 249 | // pad with a space so we can match things at the start of the 1st line |
| 250 | 250 | $ret = ' ' . $body; |
@@ -260,109 +260,109 @@ discard block |
||
| 260 | 260 | // Must contain at least 2 dots. xxxx contains either alphanum, or "-" |
| 261 | 261 | // zzzz is optional.. will contain everything up to the first space, newline, |
| 262 | 262 | // comma, double quote or <. |
| 263 | - $ret = preg_replace('#([\t\r\n >\(\[\|])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\'\(\n\r\t<\)\[\]\|]*)?)#i', '\1<a href="http://\2.\3">\2.\3</a>', $ret); |
|
| 263 | + $ret = preg_replace('#([\t\r\n >\(\[\|])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\'\(\n\r\t<\)\[\]\|]*)?)#i', '\1<a href="http://\2.\3">\2.\3</a>', $ret); |
|
| 264 | 264 | |
| 265 | 265 | // matches an email@domain type address at the start of a line, or after a space. |
| 266 | 266 | // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". |
| 267 | 267 | if (variable_get("bbcode_encode_mailto_$format", 1)) |
| 268 | - $ret = preg_replace_callback("#([\t\r\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", '_bbcode_encode_mailto', $ret); |
|
| 268 | + $ret = preg_replace_callback("#([\t\r\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", '_bbcode_encode_mailto', $ret); |
|
| 269 | 269 | else |
| 270 | - $ret = preg_replace('#([\t\r\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i', '\\1<a href="mailto:\\2@\\3">\\2@\\3</a>', $ret); |
|
| 270 | + $ret = preg_replace('#([\t\r\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i', '\\1<a href="mailto:\\2@\\3">\\2@\\3</a>', $ret); |
|
| 271 | 271 | |
| 272 | 272 | // Remove our padding |
| 273 | 273 | $ret = str_replace("\x07", '', $ret); |
| 274 | 274 | $body = substr($ret, 1); |
| 275 | - } |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - if (variable_get("bbcode_filter_nofollow_$format", 0)) { |
|
| 277 | + if (variable_get("bbcode_filter_nofollow_$format", 0)) { |
|
| 278 | 278 | $body = preg_replace('#<a([^>]+)>#i', '<a\\1 rel="nofollow">', $body); |
| 279 | - } |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - return $body; |
|
| 281 | + return $body; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | function _bbcode_generate_heading($level, $text) { |
| 285 | - $anchor = preg_replace('/([\s]+)/', '_', $text); |
|
| 286 | - $anchor = preg_replace('/([\W]+)/', '', $anchor); |
|
| 287 | - return '<h'. $level .'><a name="'. $anchor .'">'. $text .'</a></h'. $level .'>'; |
|
| 285 | + $anchor = preg_replace('/([\s]+)/', '_', $text); |
|
| 286 | + $anchor = preg_replace('/([\W]+)/', '', $anchor); |
|
| 287 | + return '<h'. $level .'><a name="'. $anchor .'">'. $text .'</a></h'. $level .'>'; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | function _bbcode_generate_index($body, $tag = 'ol') { |
| 291 | - $level = 0; |
|
| 292 | - $index = '<'. $tag .">\n"; |
|
| 293 | - $close_tags = 0; |
|
| 291 | + $level = 0; |
|
| 292 | + $index = '<'. $tag .">\n"; |
|
| 293 | + $close_tags = 0; |
|
| 294 | 294 | |
| 295 | - if (preg_match_all('#\[h([1-6]).*?\](.*?)\[/h([1-6]).*?\]#si', $body, $head_tags, PREG_SET_ORDER)) { |
|
| 295 | + if (preg_match_all('#\[h([1-6]).*?\](.*?)\[/h([1-6]).*?\]#si', $body, $head_tags, PREG_SET_ORDER)) { |
|
| 296 | 296 | foreach ($head_tags as $head_tag) { |
| 297 | - if ($level == 0) $level = $head_tag[1]; |
|
| 298 | - $anchor = preg_replace('/([\s]+)/', '_', $head_tag[2]); |
|
| 299 | - $anchor = preg_replace('/([\W]+)/', '', $anchor); |
|
| 297 | + if ($level == 0) $level = $head_tag[1]; |
|
| 298 | + $anchor = preg_replace('/([\s]+)/', '_', $head_tag[2]); |
|
| 299 | + $anchor = preg_replace('/([\W]+)/', '', $anchor); |
|
| 300 | 300 | |
| 301 | - if ($head_tag[1] > $level) { |
|
| 301 | + if ($head_tag[1] > $level) { |
|
| 302 | 302 | $index .= '<'. $tag .">\n"; |
| 303 | 303 | $index .= '<li><a href="#'. $anchor .'">'. $head_tag[2] ."</a>\n"; |
| 304 | 304 | $close_tags++; |
| 305 | 305 | $level = $head_tag[1]; |
| 306 | - } else if ($head_tag[1] < $level) { |
|
| 306 | + } else if ($head_tag[1] < $level) { |
|
| 307 | 307 | while ($close_tags > 0) { |
| 308 | - $index .= '</'. $tag .">\n"; |
|
| 309 | - $close_tags--; |
|
| 308 | + $index .= '</'. $tag .">\n"; |
|
| 309 | + $close_tags--; |
|
| 310 | 310 | } |
| 311 | 311 | $index .= '<li><a href="#'. $anchor .'">'. $head_tag[2] ."</a>\n"; |
| 312 | 312 | $level = $head_tag[1]; |
| 313 | - } else { |
|
| 313 | + } else { |
|
| 314 | 314 | $index .= '<li><a href="#'. $anchor .'">'. $head_tag[2] ."</a>\n"; |
| 315 | 315 | $level = $head_tag[1]; |
| 316 | - } |
|
| 316 | + } |
|
| 317 | + } |
|
| 317 | 318 | } |
| 318 | - } |
|
| 319 | - while ($close_tags >= 0) { |
|
| 319 | + while ($close_tags >= 0) { |
|
| 320 | 320 | $index .= '</'. $tag .">\n"; |
| 321 | 321 | $close_tags--; |
| 322 | - } |
|
| 323 | - return $index; |
|
| 322 | + } |
|
| 323 | + return $index; |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | function _bbcode_encode_mailto($matches) { |
| 327 | - if (isset($matches[3])) |
|
| 327 | + if (isset($matches[3])) |
|
| 328 | 328 | $link = 'document.write(\'<a href="mailto:' . $matches[2].'@'.$matches[3] . '">' . $matches[2].'@'.$matches[3] . '</a>\');'; |
| 329 | - else |
|
| 329 | + else |
|
| 330 | 330 | $link = 'document.write(\'<a href="mailto:' . $matches[1] . '" class="bb-email">' . (isset($matches[2]) ? $matches[2] : $matches[1]) . '</a>\');'; |
| 331 | 331 | |
| 332 | - $js_encode = ''; |
|
| 333 | - for ($x = 0; $x < strlen($link); $x++) |
|
| 332 | + $js_encode = ''; |
|
| 333 | + for ($x = 0; $x < strlen($link); $x++) |
|
| 334 | 334 | $js_encode .= '%' . bin2hex($link{$x}); |
| 335 | 335 | |
| 336 | - $link = '<script type="text/javascript">eval(unescape(\''.$js_encode.'\'))</script>'; |
|
| 337 | - if (isset($matches[3])) |
|
| 336 | + $link = '<script type="text/javascript">eval(unescape(\''.$js_encode.'\'))</script>'; |
|
| 337 | + if (isset($matches[3])) |
|
| 338 | 338 | $link = $matches[1] . $link; |
| 339 | 339 | |
| 340 | - return $link; |
|
| 340 | + return $link; |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | function _bbcode_notag_tag($text = NULL) { |
| 344 | - return str_replace( array('[', ']', '@'), array('[', ']', '@'), stripslashes($text)); |
|
| 344 | + return str_replace( array('[', ']', '@'), array('[', ']', '@'), stripslashes($text)); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | function _bbcode_php_tag($text = NULL) { |
| 348 | - return '<pre>'. highlight_string( str_replace('<br />', '', stripslashes($text)), true) .'</pre>'; |
|
| 348 | + return '<pre>'. highlight_string( str_replace('<br />', '', stripslashes($text)), true) .'</pre>'; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | function _bbcode_round_size_val($size) { |
| 352 | - if ($size < 6) |
|
| 353 | - return 6; |
|
| 354 | - elseif ($size > 48) |
|
| 355 | - return 48; |
|
| 356 | - else |
|
| 357 | - return $size; |
|
| 352 | + if ($size < 6) |
|
| 353 | + return 6; |
|
| 354 | + elseif ($size > 48) |
|
| 355 | + return 48; |
|
| 356 | + else |
|
| 357 | + return $size; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | function _bbcode_replace_nest_tag($arr = NULL) { |
| 361 | - $text = preg_replace('#(\[[/]*)'. $arr['tag'] .'(.*?\])#si', "$1\x07$2", $arr['text']); |
|
| 362 | - // It will be better to use &count and do-while, if php 5 or higher. |
|
| 363 | - while (preg_match($arr['pattern'], $text)) { |
|
| 361 | + $text = preg_replace('#(\[[/]*)'. $arr['tag'] .'(.*?\])#si', "$1\x07$2", $arr['text']); |
|
| 362 | + // It will be better to use &count and do-while, if php 5 or higher. |
|
| 363 | + while (preg_match($arr['pattern'], $text)) { |
|
| 364 | 364 | $text = preg_replace($arr['pattern'], $arr['replacement'], $text); |
| 365 | - } |
|
| 366 | - return $text; |
|
| 365 | + } |
|
| 366 | + return $text; |
|
| 367 | 367 | } |
| 368 | 368 | |
@@ -17,14 +17,14 @@ discard block |
||
| 17 | 17 | foreach ($code_tags as $code_tag) { |
| 18 | 18 | $code_tag[1] = str_replace(array('<', '>'), array('<', '>'), $code_tag[1]); |
| 19 | 19 | if (strpos($code_tag[1], "\n") === FALSE) |
| 20 | - $body = str_replace($code_tag[0], '<code class="bb-code">'. $code_tag[1] .'</code>', $body); |
|
| 20 | + $body = str_replace($code_tag[0], '<code class="bb-code">'.$code_tag[1].'</code>', $body); |
|
| 21 | 21 | elseif ($mode) { |
| 22 | 22 | // Strip preformatted code blocks from text during line break processing, replaced below |
| 23 | 23 | $body = str_replace($code_tag[0], "***pRe_sTrInG$i***", $body); |
| 24 | - $pre[$i++] = '<pre class="bb-code-block">'. $code_tag[1] .'</pre>'; |
|
| 24 | + $pre[$i++] = '<pre class="bb-code-block">'.$code_tag[1].'</pre>'; |
|
| 25 | 25 | } |
| 26 | 26 | else |
| 27 | - $body = str_replace($code_tag[0], '<pre class="bb-code-block">'. $code_tag[1] .'</pre>', $body); |
|
| 27 | + $body = str_replace($code_tag[0], '<pre class="bb-code-block">'.$code_tag[1].'</pre>', $body); |
|
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | $body = preg_replace("/(\r\n|\n|\r)/", "\n", $body); |
| 39 | 39 | $body = preg_replace("/\n\n+/", "\n\n", $body); |
| 40 | 40 | $parts = explode("\n\n", $body); |
| 41 | - for ($i=0; $i<sizeof($parts); $i++) { |
|
| 41 | + for ($i = 0; $i < sizeof($parts); $i++) { |
|
| 42 | 42 | // No linebreaks if paragraph starts with an HTML tag |
| 43 | - if ( !preg_match('/^<.*>/', $parts[$i]) ) |
|
| 43 | + if (!preg_match('/^<.*>/', $parts[$i])) |
|
| 44 | 44 | $parts[$i] = nl2br($parts[$i]); |
| 45 | 45 | |
| 46 | 46 | // Some tags should not be in paragraph blocks |
| 47 | - if ( !preg_match('/^(?:<|\[)(?:table|list|ol|ul|pre|select|form|blockquote|hr)/i', $parts[$i]) ) |
|
| 48 | - $parts[$i] = '<p>'. $parts[$i] .'</p>'; |
|
| 47 | + if (!preg_match('/^(?:<|\[)(?:table|list|ol|ul|pre|select|form|blockquote|hr)/i', $parts[$i])) |
|
| 48 | + $parts[$i] = '<p>'.$parts[$i].'</p>'; |
|
| 49 | 49 | } |
| 50 | 50 | $body = implode("\n\n", $parts); |
| 51 | 51 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | // Also add opening tags, if needed |
| 71 | 71 | for ($i = $unclosed; $i < 0; $i++) { |
| 72 | - $body = '[quote]' . $body; |
|
| 72 | + $body = '[quote]'.$body; |
|
| 73 | 73 | } |
| 74 | 74 | preg_match_all('/\[list/i', $body, $matches); |
| 75 | 75 | $opentags = count($matches['0']); |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $body .= '[/list]'; |
| 80 | 80 | } |
| 81 | 81 | for ($i = $unclosed; $i < 0; $i++) { |
| 82 | - $body = '[list]' . $body; |
|
| 82 | + $body = '[list]'.$body; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | // begin processing for [size] |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | } |
| 239 | 239 | else { |
| 240 | 240 | $body = preg_replace( |
| 241 | - array('#\[email(?::\w+)?\](.*?)\[/email(?::\w+)?\]#si','#\[email=(.*?)(?::\w+)?\]([\w\s]+)\[/email(?::\w+)?\]#si'), |
|
| 241 | + array('#\[email(?::\w+)?\](.*?)\[/email(?::\w+)?\]#si', '#\[email=(.*?)(?::\w+)?\]([\w\s]+)\[/email(?::\w+)?\]#si'), |
|
| 242 | 242 | array('<a href="mailto:\\1" class="bb-email">\\1</a>', '<a href="mailto:\\1" class="bb-email">\\2</a>'), |
| 243 | 243 | $body); |
| 244 | 244 | } |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | if (variable_get("bbcode_make_links_$format", 1)) { |
| 248 | 248 | |
| 249 | 249 | // pad with a space so we can match things at the start of the 1st line |
| 250 | - $ret = ' ' . $body; |
|
| 250 | + $ret = ' '.$body; |
|
| 251 | 251 | // padding to already filtered links |
| 252 | 252 | $ret = preg_replace('#(<a.+>)(.+</a>)#i', "$1\x07$2", $ret); |
| 253 | 253 | |
@@ -283,41 +283,41 @@ discard block |
||
| 283 | 283 | |
| 284 | 284 | function _bbcode_generate_heading($level, $text) { |
| 285 | 285 | $anchor = preg_replace('/([\s]+)/', '_', $text); |
| 286 | - $anchor = preg_replace('/([\W]+)/', '', $anchor); |
|
| 287 | - return '<h'. $level .'><a name="'. $anchor .'">'. $text .'</a></h'. $level .'>'; |
|
| 286 | + $anchor = preg_replace('/([\W]+)/', '', $anchor); |
|
| 287 | + return '<h'.$level.'><a name="'.$anchor.'">'.$text.'</a></h'.$level.'>'; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | function _bbcode_generate_index($body, $tag = 'ol') { |
| 291 | 291 | $level = 0; |
| 292 | - $index = '<'. $tag .">\n"; |
|
| 292 | + $index = '<'.$tag.">\n"; |
|
| 293 | 293 | $close_tags = 0; |
| 294 | 294 | |
| 295 | 295 | if (preg_match_all('#\[h([1-6]).*?\](.*?)\[/h([1-6]).*?\]#si', $body, $head_tags, PREG_SET_ORDER)) { |
| 296 | 296 | foreach ($head_tags as $head_tag) { |
| 297 | 297 | if ($level == 0) $level = $head_tag[1]; |
| 298 | 298 | $anchor = preg_replace('/([\s]+)/', '_', $head_tag[2]); |
| 299 | - $anchor = preg_replace('/([\W]+)/', '', $anchor); |
|
| 299 | + $anchor = preg_replace('/([\W]+)/', '', $anchor); |
|
| 300 | 300 | |
| 301 | 301 | if ($head_tag[1] > $level) { |
| 302 | - $index .= '<'. $tag .">\n"; |
|
| 303 | - $index .= '<li><a href="#'. $anchor .'">'. $head_tag[2] ."</a>\n"; |
|
| 302 | + $index .= '<'.$tag.">\n"; |
|
| 303 | + $index .= '<li><a href="#'.$anchor.'">'.$head_tag[2]."</a>\n"; |
|
| 304 | 304 | $close_tags++; |
| 305 | 305 | $level = $head_tag[1]; |
| 306 | 306 | } else if ($head_tag[1] < $level) { |
| 307 | 307 | while ($close_tags > 0) { |
| 308 | - $index .= '</'. $tag .">\n"; |
|
| 308 | + $index .= '</'.$tag.">\n"; |
|
| 309 | 309 | $close_tags--; |
| 310 | 310 | } |
| 311 | - $index .= '<li><a href="#'. $anchor .'">'. $head_tag[2] ."</a>\n"; |
|
| 311 | + $index .= '<li><a href="#'.$anchor.'">'.$head_tag[2]."</a>\n"; |
|
| 312 | 312 | $level = $head_tag[1]; |
| 313 | 313 | } else { |
| 314 | - $index .= '<li><a href="#'. $anchor .'">'. $head_tag[2] ."</a>\n"; |
|
| 314 | + $index .= '<li><a href="#'.$anchor.'">'.$head_tag[2]."</a>\n"; |
|
| 315 | 315 | $level = $head_tag[1]; |
| 316 | 316 | } |
| 317 | 317 | } |
| 318 | 318 | } |
| 319 | 319 | while ($close_tags >= 0) { |
| 320 | - $index .= '</'. $tag .">\n"; |
|
| 320 | + $index .= '</'.$tag.">\n"; |
|
| 321 | 321 | $close_tags--; |
| 322 | 322 | } |
| 323 | 323 | return $index; |
@@ -325,27 +325,27 @@ discard block |
||
| 325 | 325 | |
| 326 | 326 | function _bbcode_encode_mailto($matches) { |
| 327 | 327 | if (isset($matches[3])) |
| 328 | - $link = 'document.write(\'<a href="mailto:' . $matches[2].'@'.$matches[3] . '">' . $matches[2].'@'.$matches[3] . '</a>\');'; |
|
| 328 | + $link = 'document.write(\'<a href="mailto:'.$matches[2].'@'.$matches[3].'">'.$matches[2].'@'.$matches[3].'</a>\');'; |
|
| 329 | 329 | else |
| 330 | - $link = 'document.write(\'<a href="mailto:' . $matches[1] . '" class="bb-email">' . (isset($matches[2]) ? $matches[2] : $matches[1]) . '</a>\');'; |
|
| 330 | + $link = 'document.write(\'<a href="mailto:'.$matches[1].'" class="bb-email">'.(isset($matches[2]) ? $matches[2] : $matches[1]).'</a>\');'; |
|
| 331 | 331 | |
| 332 | 332 | $js_encode = ''; |
| 333 | 333 | for ($x = 0; $x < strlen($link); $x++) |
| 334 | - $js_encode .= '%' . bin2hex($link{$x}); |
|
| 334 | + $js_encode .= '%'.bin2hex($link{$x}); |
|
| 335 | 335 | |
| 336 | 336 | $link = '<script type="text/javascript">eval(unescape(\''.$js_encode.'\'))</script>'; |
| 337 | 337 | if (isset($matches[3])) |
| 338 | - $link = $matches[1] . $link; |
|
| 338 | + $link = $matches[1].$link; |
|
| 339 | 339 | |
| 340 | 340 | return $link; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | function _bbcode_notag_tag($text = NULL) { |
| 344 | - return str_replace( array('[', ']', '@'), array('[', ']', '@'), stripslashes($text)); |
|
| 344 | + return str_replace(array('[', ']', '@'), array('[', ']', '@'), stripslashes($text)); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | function _bbcode_php_tag($text = NULL) { |
| 348 | - return '<pre>'. highlight_string( str_replace('<br />', '', stripslashes($text)), true) .'</pre>'; |
|
| 348 | + return '<pre>'.highlight_string(str_replace('<br />', '', stripslashes($text)), true).'</pre>'; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | function _bbcode_round_size_val($size) { |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | function _bbcode_replace_nest_tag($arr = NULL) { |
| 361 | - $text = preg_replace('#(\[[/]*)'. $arr['tag'] .'(.*?\])#si', "$1\x07$2", $arr['text']); |
|
| 361 | + $text = preg_replace('#(\[[/]*)'.$arr['tag'].'(.*?\])#si', "$1\x07$2", $arr['text']); |
|
| 362 | 362 | // It will be better to use &count and do-while, if php 5 or higher. |
| 363 | 363 | while (preg_match($arr['pattern'], $text)) { |
| 364 | 364 | $text = preg_replace($arr['pattern'], $arr['replacement'], $text); |
@@ -16,23 +16,25 @@ discard block |
||
| 16 | 16 | if (preg_match_all('#\[code(?::\w+)?\](.*?)\[/code(?::\w+)?\]#si', $body, $code_tags, PREG_SET_ORDER)) { |
| 17 | 17 | foreach ($code_tags as $code_tag) { |
| 18 | 18 | $code_tag[1] = str_replace(array('<', '>'), array('<', '>'), $code_tag[1]); |
| 19 | - if (strpos($code_tag[1], "\n") === FALSE) |
|
| 20 | - $body = str_replace($code_tag[0], '<code class="bb-code">'. $code_tag[1] .'</code>', $body); |
|
| 21 | - elseif ($mode) { |
|
| 19 | + if (strpos($code_tag[1], "\n") === FALSE) { |
|
| 20 | + $body = str_replace($code_tag[0], '<code class="bb-code">'. $code_tag[1] .'</code>', $body); |
|
| 21 | + } elseif ($mode) { |
|
| 22 | 22 | // Strip preformatted code blocks from text during line break processing, replaced below |
| 23 | 23 | $body = str_replace($code_tag[0], "***pRe_sTrInG$i***", $body); |
| 24 | 24 | $pre[$i++] = '<pre class="bb-code-block">'. $code_tag[1] .'</pre>'; |
| 25 | + } else { |
|
| 26 | + $body = str_replace($code_tag[0], '<pre class="bb-code-block">'. $code_tag[1] .'</pre>', $body); |
|
| 25 | 27 | } |
| 26 | - else |
|
| 27 | - $body = str_replace($code_tag[0], '<pre class="bb-code-block">'. $code_tag[1] .'</pre>', $body); |
|
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | // Apply line and paragraph breaks (skipping preformatted code) |
| 32 | 32 | if ($mode) { |
| 33 | 33 | |
| 34 | - if ($mode == 1) // Line breaks only (starting with PHP 4.0.5, nl2br() is XHTML compliant) |
|
| 34 | + if ($mode == 1) { |
|
| 35 | + // Line breaks only (starting with PHP 4.0.5, nl2br() is XHTML compliant) |
|
| 35 | 36 | $body = nl2br($body); |
| 37 | + } |
|
| 36 | 38 | |
| 37 | 39 | if ($mode == 2) { // Line and paragraph breaks (may not always be XHTML compliant) |
| 38 | 40 | $body = preg_replace("/(\r\n|\n|\r)/", "\n", $body); |
@@ -40,19 +42,22 @@ discard block |
||
| 40 | 42 | $parts = explode("\n\n", $body); |
| 41 | 43 | for ($i=0; $i<sizeof($parts); $i++) { |
| 42 | 44 | // No linebreaks if paragraph starts with an HTML tag |
| 43 | - if ( !preg_match('/^<.*>/', $parts[$i]) ) |
|
| 44 | - $parts[$i] = nl2br($parts[$i]); |
|
| 45 | + if ( !preg_match('/^<.*>/', $parts[$i]) ) { |
|
| 46 | + $parts[$i] = nl2br($parts[$i]); |
|
| 47 | + } |
|
| 45 | 48 | |
| 46 | 49 | // Some tags should not be in paragraph blocks |
| 47 | - if ( !preg_match('/^(?:<|\[)(?:table|list|ol|ul|pre|select|form|blockquote|hr)/i', $parts[$i]) ) |
|
| 48 | - $parts[$i] = '<p>'. $parts[$i] .'</p>'; |
|
| 50 | + if ( !preg_match('/^(?:<|\[)(?:table|list|ol|ul|pre|select|form|blockquote|hr)/i', $parts[$i]) ) { |
|
| 51 | + $parts[$i] = '<p>'. $parts[$i] .'</p>'; |
|
| 52 | + } |
|
| 49 | 53 | } |
| 50 | 54 | $body = implode("\n\n", $parts); |
| 51 | 55 | } |
| 52 | 56 | |
| 53 | 57 | // Reinsert preformatted code blocks |
| 54 | - foreach ($pre as $i => $code_tag) |
|
| 55 | - $body = str_replace("***pRe_sTrInG$i***", $code_tag, $body); |
|
| 58 | + foreach ($pre as $i => $code_tag) { |
|
| 59 | + $body = str_replace("***pRe_sTrInG$i***", $code_tag, $body); |
|
| 60 | + } |
|
| 56 | 61 | } |
| 57 | 62 | |
| 58 | 63 | // Replace any improper quote tags with proper quote tags |
@@ -235,8 +240,7 @@ discard block |
||
| 235 | 240 | // Replacing email addresses with encoded html |
| 236 | 241 | $body = preg_replace_callback('#\[email(?::\w+)?\]([\w\.\-\+~@]+)\[/email(?::\w+)?\]#si', '_bbcode_encode_mailto', $body); |
| 237 | 242 | $body = preg_replace_callback('#\[email=(.*?)(?::\w+)?\](.*?)\[/email(?::\w+)?\]#si', '_bbcode_encode_mailto', $body); |
| 238 | - } |
|
| 239 | - else { |
|
| 243 | + } else { |
|
| 240 | 244 | $body = preg_replace( |
| 241 | 245 | array('#\[email(?::\w+)?\](.*?)\[/email(?::\w+)?\]#si','#\[email=(.*?)(?::\w+)?\]([\w\s]+)\[/email(?::\w+)?\]#si'), |
| 242 | 246 | array('<a href="mailto:\\1" class="bb-email">\\1</a>', '<a href="mailto:\\1" class="bb-email">\\2</a>'), |
@@ -264,10 +268,11 @@ discard block |
||
| 264 | 268 | |
| 265 | 269 | // matches an email@domain type address at the start of a line, or after a space. |
| 266 | 270 | // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". |
| 267 | - if (variable_get("bbcode_encode_mailto_$format", 1)) |
|
| 268 | - $ret = preg_replace_callback("#([\t\r\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", '_bbcode_encode_mailto', $ret); |
|
| 269 | - else |
|
| 270 | - $ret = preg_replace('#([\t\r\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i', '\\1<a href="mailto:\\2@\\3">\\2@\\3</a>', $ret); |
|
| 271 | + if (variable_get("bbcode_encode_mailto_$format", 1)) { |
|
| 272 | + $ret = preg_replace_callback("#([\t\r\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", '_bbcode_encode_mailto', $ret); |
|
| 273 | + } else { |
|
| 274 | + $ret = preg_replace('#([\t\r\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i', '\\1<a href="mailto:\\2@\\3">\\2@\\3</a>', $ret); |
|
| 275 | + } |
|
| 271 | 276 | |
| 272 | 277 | // Remove our padding |
| 273 | 278 | $ret = str_replace("\x07", '', $ret); |
@@ -294,7 +299,9 @@ discard block |
||
| 294 | 299 | |
| 295 | 300 | if (preg_match_all('#\[h([1-6]).*?\](.*?)\[/h([1-6]).*?\]#si', $body, $head_tags, PREG_SET_ORDER)) { |
| 296 | 301 | foreach ($head_tags as $head_tag) { |
| 297 | - if ($level == 0) $level = $head_tag[1]; |
|
| 302 | + if ($level == 0) { |
|
| 303 | + $level = $head_tag[1]; |
|
| 304 | + } |
|
| 298 | 305 | $anchor = preg_replace('/([\s]+)/', '_', $head_tag[2]); |
| 299 | 306 | $anchor = preg_replace('/([\W]+)/', '', $anchor); |
| 300 | 307 | |
@@ -324,18 +331,21 @@ discard block |
||
| 324 | 331 | } |
| 325 | 332 | |
| 326 | 333 | function _bbcode_encode_mailto($matches) { |
| 327 | - if (isset($matches[3])) |
|
| 328 | - $link = 'document.write(\'<a href="mailto:' . $matches[2].'@'.$matches[3] . '">' . $matches[2].'@'.$matches[3] . '</a>\');'; |
|
| 329 | - else |
|
| 330 | - $link = 'document.write(\'<a href="mailto:' . $matches[1] . '" class="bb-email">' . (isset($matches[2]) ? $matches[2] : $matches[1]) . '</a>\');'; |
|
| 334 | + if (isset($matches[3])) { |
|
| 335 | + $link = 'document.write(\'<a href="mailto:' . $matches[2].'@'.$matches[3] . '">' . $matches[2].'@'.$matches[3] . '</a>\');'; |
|
| 336 | + } else { |
|
| 337 | + $link = 'document.write(\'<a href="mailto:' . $matches[1] . '" class="bb-email">' . (isset($matches[2]) ? $matches[2] : $matches[1]) . '</a>\');'; |
|
| 338 | + } |
|
| 331 | 339 | |
| 332 | 340 | $js_encode = ''; |
| 333 | - for ($x = 0; $x < strlen($link); $x++) |
|
| 334 | - $js_encode .= '%' . bin2hex($link{$x}); |
|
| 341 | + for ($x = 0; $x < strlen($link); $x++) { |
|
| 342 | + $js_encode .= '%' . bin2hex($link{$x}); |
|
| 343 | + } |
|
| 335 | 344 | |
| 336 | 345 | $link = '<script type="text/javascript">eval(unescape(\''.$js_encode.'\'))</script>'; |
| 337 | - if (isset($matches[3])) |
|
| 338 | - $link = $matches[1] . $link; |
|
| 346 | + if (isset($matches[3])) { |
|
| 347 | + $link = $matches[1] . $link; |
|
| 348 | + } |
|
| 339 | 349 | |
| 340 | 350 | return $link; |
| 341 | 351 | } |
@@ -349,13 +359,14 @@ discard block |
||
| 349 | 359 | } |
| 350 | 360 | |
| 351 | 361 | function _bbcode_round_size_val($size) { |
| 352 | - if ($size < 6) |
|
| 353 | - return 6; |
|
| 354 | - elseif ($size > 48) |
|
| 355 | - return 48; |
|
| 356 | - else |
|
| 357 | - return $size; |
|
| 358 | -} |
|
| 362 | + if ($size < 6) { |
|
| 363 | + return 6; |
|
| 364 | + } elseif ($size > 48) { |
|
| 365 | + return 48; |
|
| 366 | + } else { |
|
| 367 | + return $size; |
|
| 368 | + } |
|
| 369 | + } |
|
| 359 | 370 | |
| 360 | 371 | function _bbcode_replace_nest_tag($arr = NULL) { |
| 361 | 372 | $text = preg_replace('#(\[[/]*)'. $arr['tag'] .'(.*?\])#si', "$1\x07$2", $arr['text']); |
@@ -1234,6 +1234,8 @@ discard block |
||
| 1234 | 1234 | * |
| 1235 | 1235 | * For each operation, both this function and _content_field_invoke_default() are |
| 1236 | 1236 | * called so that the default database handling can occur. |
| 1237 | + * @param string $op |
|
| 1238 | + * @param boolean $page |
|
| 1237 | 1239 | */ |
| 1238 | 1240 | function _content_field_invoke($op, &$node, $teaser = NULL, $page = NULL) { |
| 1239 | 1241 | $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); |
@@ -1268,6 +1270,8 @@ discard block |
||
| 1268 | 1270 | |
| 1269 | 1271 | /** |
| 1270 | 1272 | * Invoke content.module's version of a field hook. |
| 1273 | + * @param string $op |
|
| 1274 | + * @param boolean $page |
|
| 1271 | 1275 | */ |
| 1272 | 1276 | function _content_field_invoke_default($op, &$node, $teaser = NULL, $page = NULL) { |
| 1273 | 1277 | $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); |
@@ -1746,6 +1750,7 @@ discard block |
||
| 1746 | 1750 | * Used for items entered by administrators, like field descriptions, |
| 1747 | 1751 | * allowed values, where some (mainly inline) mark-up may be desired |
| 1748 | 1752 | * (so check_plain() is not acceptable). |
| 1753 | + * @return string |
|
| 1749 | 1754 | */ |
| 1750 | 1755 | function content_filter_xss($string) { |
| 1751 | 1756 | return filter_xss($string, _content_filter_xss_allowed_tags()); |
@@ -1975,7 +1980,7 @@ discard block |
||
| 1975 | 1980 | * |
| 1976 | 1981 | * @param $name |
| 1977 | 1982 | * The name of the content type or content field |
| 1978 | - * @param $storage |
|
| 1983 | + * @param integer $storage |
|
| 1979 | 1984 | * CONTENT_DB_STORAGE_PER_FIELD or CONTENT_DB_STORAGE_PER_CONTENT_TYPE |
| 1980 | 1985 | * @return |
| 1981 | 1986 | * A string containing the generated name for the database table |
@@ -2109,7 +2114,7 @@ discard block |
||
| 2109 | 2114 | * @param $name |
| 2110 | 2115 | * Name of the index. |
| 2111 | 2116 | * @return |
| 2112 | - * TRUE if the table exists. Otherwise FALSE. |
|
| 2117 | + boolean TRUE if the table exists. Otherwise FALSE. |
|
| 2113 | 2118 | */ |
| 2114 | 2119 | function content_db_index_exists($table, $name) { |
| 2115 | 2120 | global $db_type; |
@@ -2139,9 +2144,9 @@ discard block |
||
| 2139 | 2144 | * with respect to a given operation. (currently used for field 'view', |
| 2140 | 2145 | * and widget 'default values' and 'multiple values') |
| 2141 | 2146 | * |
| 2142 | - * @param $entity |
|
| 2147 | + * @param string $entity |
|
| 2143 | 2148 | * 'field' or 'widget' |
| 2144 | - * @param $op |
|
| 2149 | + * @param string $op |
|
| 2145 | 2150 | * the name of the operation ('view', 'default value'...) |
| 2146 | 2151 | * @param $field |
| 2147 | 2152 | * The field array, including widget info. |
@@ -2169,9 +2174,9 @@ discard block |
||
| 2169 | 2174 | * |
| 2170 | 2175 | * Currently used for widgets and formatters 'multiple values'. |
| 2171 | 2176 | * |
| 2172 | - * @param $entity |
|
| 2177 | + * @param string $entity |
|
| 2173 | 2178 | * 'field', 'widget' or 'formatter' |
| 2174 | - * @param $op |
|
| 2179 | + * @param string $op |
|
| 2175 | 2180 | * the name of the operation ('default values'...) |
| 2176 | 2181 | * @param $object |
| 2177 | 2182 | * - if $entity is 'field' or 'widget': the field array, |
@@ -2232,7 +2237,7 @@ discard block |
||
| 2232 | 2237 | /** |
| 2233 | 2238 | * Determine whether the user has access to a given field. |
| 2234 | 2239 | * |
| 2235 | - * @param $op |
|
| 2240 | + * @param string $op |
|
| 2236 | 2241 | * The operation to be performed. Possible values: |
| 2237 | 2242 | * - "edit" |
| 2238 | 2243 | * - "view" |
@@ -2243,7 +2248,7 @@ discard block |
||
| 2243 | 2248 | * @param $node |
| 2244 | 2249 | * (optional) The node on which the operation is to be performed. |
| 2245 | 2250 | * @return |
| 2246 | - * TRUE if the operation is allowed; |
|
| 2251 | + boolean TRUE if the operation is allowed; |
|
| 2247 | 2252 | * FALSE if the operation is denied. |
| 2248 | 2253 | */ |
| 2249 | 2254 | function content_access($op, $field, $account = NULL, $node = NULL) { |
@@ -2324,7 +2329,7 @@ discard block |
||
| 2324 | 2329 | * hook_content_build_modes(). |
| 2325 | 2330 | * |
| 2326 | 2331 | * @return |
| 2327 | - * Whether or not content is to be added to $content in this context. |
|
| 2332 | + boolean Whether or not content is to be added to $content in this context. |
|
| 2328 | 2333 | * Uses the value of the 'Exclude' checkbox for this field |
| 2329 | 2334 | * as set on the Manage fields screen. |
| 2330 | 2335 | */ |
@@ -16,88 +16,88 @@ discard block |
||
| 16 | 16 | define('CONTENT_HANDLE_MODULE', 0x0002); |
| 17 | 17 | |
| 18 | 18 | function content_help($path, $arg) { |
| 19 | - switch ($path) { |
|
| 19 | + switch ($path) { |
|
| 20 | 20 | case 'admin/help#content': |
| 21 | 21 | $output = '<p>'. t('The content module, a required component of the Content Construction Kit (CCK), allows administrators to associate custom fields with content types. In Drupal, content types are used to define the characteristics of a post, including the title and description of the fields displayed on its add and edit pages. Using the content module (and the other helper modules included in CCK), custom fields beyond the default "Title" and "Body" may be added. CCK features are accessible through tabs on the <a href="@content-types">content types administration page</a>. (See the <a href="@node-help">node module help page</a> for more information about content types.)', array('@content-types' => url('admin/content/types'), '@node-help' => url('admin/help/node'))) .'</p>'; |
| 22 | - $output .= '<p>'. t('When adding a custom field to a content type, you determine its type (whether it will contain text, numbers, or references to other objects) and how it will be displayed (either as a text field or area, a select box, checkbox, radio button, or autocompleting field). A field may have multiple values (i.e., a "person" may have multiple e-mail addresses) or a single value (i.e., an "employee" has a single employee identification number). As you add and edit fields, CCK automatically adjusts the structure of the database as necessary. CCK also provides a number of other features, including intelligent caching for your custom data, an import and export facility for content type definitions, and integration with other contributed modules.') .'</p>'; |
|
| 23 | - $output .= '<p>'. t('Custom field types are provided by a set of optional modules included with CCK (each module provides a different type). The <a href="@modules">modules page</a> allows you to enable or disable CCK components. A default installation of CCK includes:', array('@modules' => url('admin/build/modules'))) .'</p>'; |
|
| 24 | - $output .= '<ul>'; |
|
| 25 | - $output .= '<li>'. t('<em>number</em>, which adds numeric field types, in integer, decimal or floating point form. You may define a set of allowed inputs, or specify an allowable range of values. A variety of common formats for displaying numeric data are available.') .'</li>'; |
|
| 26 | - $output .= '<li>'. t("<em>text</em>, which adds text field types. A text field may contain plain text only, or optionally, may use Drupal's input format filters to securely manage rich text input. Text input fields may be either a single line (text field), multiple lines (text area), or for greater input control, a select box, checkbox, or radio buttons. If desired, CCK can validate the input to a set of allowed values.") .'</li>'; |
|
| 27 | - $output .= '<li>'. t('<em>nodereference</em>, which creates custom references between Drupal nodes. By adding a <em>nodereference</em> field and two different content types, for instance, you can easily create complex parent/child relationships between data (multiple "employee" nodes may contain a <em>nodereference</em> field linking to an "employer" node).') .'</li>'; |
|
| 28 | - $output .= '<li>'. t('<em>userreference</em>, which creates custom references to your sites\' user accounts. By adding a <em>userreference</em> field, you can create complex relationships between your site\'s users and posts. To track user involvement in a post beyond Drupal\'s standard <em>Authored by</em> field, for instance, add a <em>userreference</em> field named "Edited by" to a content type to store a link to an editor\'s user account page.') .'</li>'; |
|
| 29 | - $output .= '<li>'. t('<em>fieldgroup</em>, which creates collapsible fieldsets to hold a group of related fields. A fieldset may either be open or closed by default. The order of your fieldsets, and the order of fields within a fieldset, is managed via a drag-and-drop interface provided by content module.') .'</li>'; |
|
| 30 | - $output .= '</ul>'; |
|
| 31 | - $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@handbook-cck">CCK</a> or the <a href="@project-cck">CCK project page</a>.', array('@handbook-cck' => 'http://drupal.org/handbook/modules/cck', '@project-cck' => 'http://drupal.org/project/cck')) .'</p>'; |
|
| 32 | - return $output; |
|
| 33 | - } |
|
| 22 | + $output .= '<p>'. t('When adding a custom field to a content type, you determine its type (whether it will contain text, numbers, or references to other objects) and how it will be displayed (either as a text field or area, a select box, checkbox, radio button, or autocompleting field). A field may have multiple values (i.e., a "person" may have multiple e-mail addresses) or a single value (i.e., an "employee" has a single employee identification number). As you add and edit fields, CCK automatically adjusts the structure of the database as necessary. CCK also provides a number of other features, including intelligent caching for your custom data, an import and export facility for content type definitions, and integration with other contributed modules.') .'</p>'; |
|
| 23 | + $output .= '<p>'. t('Custom field types are provided by a set of optional modules included with CCK (each module provides a different type). The <a href="@modules">modules page</a> allows you to enable or disable CCK components. A default installation of CCK includes:', array('@modules' => url('admin/build/modules'))) .'</p>'; |
|
| 24 | + $output .= '<ul>'; |
|
| 25 | + $output .= '<li>'. t('<em>number</em>, which adds numeric field types, in integer, decimal or floating point form. You may define a set of allowed inputs, or specify an allowable range of values. A variety of common formats for displaying numeric data are available.') .'</li>'; |
|
| 26 | + $output .= '<li>'. t("<em>text</em>, which adds text field types. A text field may contain plain text only, or optionally, may use Drupal's input format filters to securely manage rich text input. Text input fields may be either a single line (text field), multiple lines (text area), or for greater input control, a select box, checkbox, or radio buttons. If desired, CCK can validate the input to a set of allowed values.") .'</li>'; |
|
| 27 | + $output .= '<li>'. t('<em>nodereference</em>, which creates custom references between Drupal nodes. By adding a <em>nodereference</em> field and two different content types, for instance, you can easily create complex parent/child relationships between data (multiple "employee" nodes may contain a <em>nodereference</em> field linking to an "employer" node).') .'</li>'; |
|
| 28 | + $output .= '<li>'. t('<em>userreference</em>, which creates custom references to your sites\' user accounts. By adding a <em>userreference</em> field, you can create complex relationships between your site\'s users and posts. To track user involvement in a post beyond Drupal\'s standard <em>Authored by</em> field, for instance, add a <em>userreference</em> field named "Edited by" to a content type to store a link to an editor\'s user account page.') .'</li>'; |
|
| 29 | + $output .= '<li>'. t('<em>fieldgroup</em>, which creates collapsible fieldsets to hold a group of related fields. A fieldset may either be open or closed by default. The order of your fieldsets, and the order of fields within a fieldset, is managed via a drag-and-drop interface provided by content module.') .'</li>'; |
|
| 30 | + $output .= '</ul>'; |
|
| 31 | + $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@handbook-cck">CCK</a> or the <a href="@project-cck">CCK project page</a>.', array('@handbook-cck' => 'http://drupal.org/handbook/modules/cck', '@project-cck' => 'http://drupal.org/project/cck')) .'</p>'; |
|
| 32 | + return $output; |
|
| 33 | + } |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Implementation of hook_flush_caches. |
| 38 | 38 | */ |
| 39 | 39 | function content_flush_caches() { |
| 40 | - return array(content_cache_tablename()); |
|
| 40 | + return array(content_cache_tablename()); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Implementation of hook_init(). |
| 45 | 45 | */ |
| 46 | 46 | function content_init() { |
| 47 | - drupal_add_css(drupal_get_path('module', 'content') .'/theme/content-module.css'); |
|
| 48 | - if (module_exists('token') && !function_exists('content_token_values')) { |
|
| 47 | + drupal_add_css(drupal_get_path('module', 'content') .'/theme/content-module.css'); |
|
| 48 | + if (module_exists('token') && !function_exists('content_token_values')) { |
|
| 49 | 49 | module_load_include('inc', 'content', 'includes/content.token'); |
| 50 | - } |
|
| 51 | - if (module_exists('diff') && !function_exists('content_diff')) { |
|
| 50 | + } |
|
| 51 | + if (module_exists('diff') && !function_exists('content_diff')) { |
|
| 52 | 52 | module_load_include('inc', 'content', 'includes/content.diff'); |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * Implementation of hook_perm(). |
| 58 | 58 | */ |
| 59 | 59 | function content_perm() { |
| 60 | - return array('Use PHP input for field settings (dangerous - grant with care)'); |
|
| 60 | + return array('Use PHP input for field settings (dangerous - grant with care)'); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Implementation of hook_menu_alter(). |
| 65 | 65 | */ |
| 66 | 66 | function content_menu_alter(&$items) { |
| 67 | - // Customize the content types page with our own callback |
|
| 68 | - $items['admin/content/types']['page callback'] = 'content_types_overview'; |
|
| 69 | - $items['admin/content/types']['file'] = 'content.admin.inc'; |
|
| 70 | - $items['admin/content/types']['file path'] = drupal_get_path('module', 'content') .'/includes'; |
|
| 67 | + // Customize the content types page with our own callback |
|
| 68 | + $items['admin/content/types']['page callback'] = 'content_types_overview'; |
|
| 69 | + $items['admin/content/types']['file'] = 'content.admin.inc'; |
|
| 70 | + $items['admin/content/types']['file path'] = drupal_get_path('module', 'content') .'/includes'; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * Implementation of hook_menu(). |
| 75 | 75 | */ |
| 76 | 76 | function content_menu() { |
| 77 | - $items = array(); |
|
| 78 | - $items['admin/content/types/fields'] = array( |
|
| 77 | + $items = array(); |
|
| 78 | + $items['admin/content/types/fields'] = array( |
|
| 79 | 79 | 'title' => 'Fields', |
| 80 | 80 | 'page callback' => 'content_fields_list', |
| 81 | 81 | 'access arguments' => array('administer content types'), |
| 82 | 82 | 'file' => 'includes/content.admin.inc', |
| 83 | 83 | 'type' => MENU_LOCAL_TASK, |
| 84 | - ); |
|
| 85 | - // Callback for AHAH add more buttons. |
|
| 86 | - $items['content/js_add_more'] = array( |
|
| 84 | + ); |
|
| 85 | + // Callback for AHAH add more buttons. |
|
| 86 | + $items['content/js_add_more'] = array( |
|
| 87 | 87 | 'page callback' => 'content_add_more_js', |
| 88 | 88 | 'access arguments' => array('access content'), |
| 89 | 89 | 'file' => 'includes/content.node_form.inc', |
| 90 | 90 | 'type' => MENU_CALLBACK, |
| 91 | - ); |
|
| 91 | + ); |
|
| 92 | 92 | |
| 93 | - // Make sure this doesn't fire until content_types is working, |
|
| 94 | - // and tables are updated, needed to avoid errors on initial installation. |
|
| 95 | - if (!defined('MAINTENANCE_MODE') && variable_get('content_schema_version', -1) >= 6007) { |
|
| 93 | + // Make sure this doesn't fire until content_types is working, |
|
| 94 | + // and tables are updated, needed to avoid errors on initial installation. |
|
| 95 | + if (!defined('MAINTENANCE_MODE') && variable_get('content_schema_version', -1) >= 6007) { |
|
| 96 | 96 | foreach (node_get_types() as $type) { |
| 97 | - $type_name = $type->type; |
|
| 98 | - $content_type = content_types($type_name); |
|
| 99 | - $type_url_str = $content_type['url_str']; |
|
| 100 | - $items['admin/content/node-type/'. $type_url_str .'/fields'] = array( |
|
| 97 | + $type_name = $type->type; |
|
| 98 | + $content_type = content_types($type_name); |
|
| 99 | + $type_url_str = $content_type['url_str']; |
|
| 100 | + $items['admin/content/node-type/'. $type_url_str .'/fields'] = array( |
|
| 101 | 101 | 'title' => 'Manage fields', |
| 102 | 102 | 'page callback' => 'drupal_get_form', |
| 103 | 103 | 'page arguments' => array('content_field_overview_form', $type_name), |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | 'file' => 'includes/content.admin.inc', |
| 106 | 106 | 'type' => MENU_LOCAL_TASK, |
| 107 | 107 | 'weight' => 1, |
| 108 | - ); |
|
| 109 | - $items['admin/content/node-type/'. $type_url_str .'/display'] = array( |
|
| 108 | + ); |
|
| 109 | + $items['admin/content/node-type/'. $type_url_str .'/display'] = array( |
|
| 110 | 110 | 'title' => 'Display fields', |
| 111 | 111 | 'page callback' => 'drupal_get_form', |
| 112 | 112 | 'page arguments' => array('content_display_overview_form', $type_name), |
@@ -114,41 +114,41 @@ discard block |
||
| 114 | 114 | 'file' => 'includes/content.admin.inc', |
| 115 | 115 | 'type' => MENU_LOCAL_TASK, |
| 116 | 116 | 'weight' => 2, |
| 117 | - ); |
|
| 118 | - $contexts = content_build_modes('_tabs'); |
|
| 119 | - foreach ($contexts as $key => $tab) { |
|
| 117 | + ); |
|
| 118 | + $contexts = content_build_modes('_tabs'); |
|
| 119 | + foreach ($contexts as $key => $tab) { |
|
| 120 | 120 | $items['admin/content/node-type/'. $type_url_str .'/display/'. $key] = array( |
| 121 | - 'title' => $tab['title'], |
|
| 122 | - 'page arguments' => array('content_display_overview_form', $type_name, $key), |
|
| 123 | - 'access arguments' => array('administer content types'), |
|
| 124 | - 'type' => $key == 'basic' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, |
|
| 125 | - 'weight' => $key == 'basic' ? 0 : 1, |
|
| 121 | + 'title' => $tab['title'], |
|
| 122 | + 'page arguments' => array('content_display_overview_form', $type_name, $key), |
|
| 123 | + 'access arguments' => array('administer content types'), |
|
| 124 | + 'type' => $key == 'basic' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, |
|
| 125 | + 'weight' => $key == 'basic' ? 0 : 1, |
|
| 126 | 126 | ); |
| 127 | - } |
|
| 128 | - // Cast as an array in case this is called before any fields have |
|
| 129 | - // been added, like when a new content type is created. |
|
| 130 | - foreach ((array) $content_type['fields'] as $field) { |
|
| 127 | + } |
|
| 128 | + // Cast as an array in case this is called before any fields have |
|
| 129 | + // been added, like when a new content type is created. |
|
| 130 | + foreach ((array) $content_type['fields'] as $field) { |
|
| 131 | 131 | $field_name = $field['field_name']; |
| 132 | 132 | $items['admin/content/node-type/'. $type_url_str .'/fields/'. $field_name] = array( |
| 133 | - 'title' => $field['widget']['label'], |
|
| 134 | - 'page callback' => 'drupal_get_form', |
|
| 135 | - 'page arguments' => array('content_field_edit_form', $type_name, $field_name), |
|
| 136 | - 'access arguments' => array('administer content types'), |
|
| 137 | - 'file' => 'includes/content.admin.inc', |
|
| 138 | - 'type' => MENU_LOCAL_TASK, |
|
| 133 | + 'title' => $field['widget']['label'], |
|
| 134 | + 'page callback' => 'drupal_get_form', |
|
| 135 | + 'page arguments' => array('content_field_edit_form', $type_name, $field_name), |
|
| 136 | + 'access arguments' => array('administer content types'), |
|
| 137 | + 'file' => 'includes/content.admin.inc', |
|
| 138 | + 'type' => MENU_LOCAL_TASK, |
|
| 139 | 139 | ); |
| 140 | 140 | $items['admin/content/node-type/'. $type_url_str .'/fields/'. $field_name .'/remove'] = array( |
| 141 | - 'title' => 'Remove field', |
|
| 142 | - 'page callback' => 'drupal_get_form', |
|
| 143 | - 'page arguments' => array('content_field_remove_form', $type_name, $field_name), |
|
| 144 | - 'access arguments' => array('administer content types'), |
|
| 145 | - 'file' => 'includes/content.admin.inc', |
|
| 146 | - 'type' => MENU_CALLBACK, |
|
| 141 | + 'title' => 'Remove field', |
|
| 142 | + 'page callback' => 'drupal_get_form', |
|
| 143 | + 'page arguments' => array('content_field_remove_form', $type_name, $field_name), |
|
| 144 | + 'access arguments' => array('administer content types'), |
|
| 145 | + 'file' => 'includes/content.admin.inc', |
|
| 146 | + 'type' => MENU_CALLBACK, |
|
| 147 | 147 | ); |
| 148 | - } |
|
| 148 | + } |
|
| 149 | + } |
|
| 149 | 150 | } |
| 150 | - } |
|
| 151 | - return $items; |
|
| 151 | + return $items; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -163,69 +163,69 @@ discard block |
||
| 163 | 163 | * the same name as the hook_elements key. |
| 164 | 164 | */ |
| 165 | 165 | function content_elements() { |
| 166 | - return array( |
|
| 166 | + return array( |
|
| 167 | 167 | 'content_multiple_values' => array(), |
| 168 | 168 | 'content_field' => array(), |
| 169 | - ); |
|
| 169 | + ); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
| 173 | 173 | * Implementation of hook_theme(). |
| 174 | 174 | */ |
| 175 | 175 | function content_theme() { |
| 176 | - $path = drupal_get_path('module', 'content') .'/theme'; |
|
| 177 | - require_once "./$path/theme.inc"; |
|
| 176 | + $path = drupal_get_path('module', 'content') .'/theme'; |
|
| 177 | + require_once "./$path/theme.inc"; |
|
| 178 | 178 | |
| 179 | - return array( |
|
| 179 | + return array( |
|
| 180 | 180 | 'content_field' => array( |
| 181 | - 'template' => 'content-field', |
|
| 182 | - 'arguments' => array('element' => NULL), |
|
| 183 | - 'path' => $path, |
|
| 181 | + 'template' => 'content-field', |
|
| 182 | + 'arguments' => array('element' => NULL), |
|
| 183 | + 'path' => $path, |
|
| 184 | 184 | ), |
| 185 | 185 | 'content_overview_links' => array( |
| 186 | - 'arguments' => array(), |
|
| 186 | + 'arguments' => array(), |
|
| 187 | 187 | ), |
| 188 | 188 | 'content_field_overview_form' => array( |
| 189 | - 'template' => 'content-admin-field-overview-form', |
|
| 190 | - 'file' => 'theme.inc', |
|
| 191 | - 'path' => $path, |
|
| 192 | - 'arguments' => array('form' => NULL), |
|
| 189 | + 'template' => 'content-admin-field-overview-form', |
|
| 190 | + 'file' => 'theme.inc', |
|
| 191 | + 'path' => $path, |
|
| 192 | + 'arguments' => array('form' => NULL), |
|
| 193 | 193 | ), |
| 194 | 194 | 'content_display_overview_form' => array( |
| 195 | - 'template' => 'content-admin-display-overview-form', |
|
| 196 | - 'file' => 'theme.inc', |
|
| 197 | - 'path' => $path, |
|
| 198 | - 'arguments' => array('form' => NULL), |
|
| 195 | + 'template' => 'content-admin-display-overview-form', |
|
| 196 | + 'file' => 'theme.inc', |
|
| 197 | + 'path' => $path, |
|
| 198 | + 'arguments' => array('form' => NULL), |
|
| 199 | 199 | ), |
| 200 | 200 | 'content_exclude' => array( |
| 201 | - 'arguments' => array('content' => NULL, 'object' => array(), 'context' => NULL), |
|
| 201 | + 'arguments' => array('content' => NULL, 'object' => array(), 'context' => NULL), |
|
| 202 | 202 | ), |
| 203 | 203 | 'content_view_multiple_field' => array( |
| 204 | - 'arguments' => array('items' => NULL, 'field' => NULL, 'data' => NULL), |
|
| 204 | + 'arguments' => array('items' => NULL, 'field' => NULL, 'data' => NULL), |
|
| 205 | 205 | ), |
| 206 | 206 | 'content_multiple_values' => array( |
| 207 | - 'arguments' => array('element' => NULL), |
|
| 207 | + 'arguments' => array('element' => NULL), |
|
| 208 | 208 | ), |
| 209 | - ); |
|
| 209 | + ); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
| 213 | 213 | * Implementation of hook_views_api(). |
| 214 | 214 | */ |
| 215 | 215 | function content_views_api() { |
| 216 | - return array( |
|
| 216 | + return array( |
|
| 217 | 217 | 'api' => 2, |
| 218 | 218 | 'path' => drupal_get_path('module', 'content') . '/includes/views', |
| 219 | - ); |
|
| 219 | + ); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | 223 | * Implementation of hook_ctools_plugin_directory(). |
| 224 | 224 | */ |
| 225 | 225 | function content_ctools_plugin_directory($module, $plugin) { |
| 226 | - if ($module == 'ctools' && $plugin == 'content_types') { |
|
| 226 | + if ($module == 'ctools' && $plugin == 'content_types') { |
|
| 227 | 227 | return 'includes/panels/' . $plugin; |
| 228 | - } |
|
| 228 | + } |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -237,28 +237,28 @@ discard block |
||
| 237 | 237 | * cache the loaded object structure and invalidate it during the update process. |
| 238 | 238 | */ |
| 239 | 239 | function content_load(&$node) { |
| 240 | - $cid = 'content:'. $node->nid .':'. $node->vid; |
|
| 241 | - if ($cached = cache_get($cid, content_cache_tablename())) { |
|
| 240 | + $cid = 'content:'. $node->nid .':'. $node->vid; |
|
| 241 | + if ($cached = cache_get($cid, content_cache_tablename())) { |
|
| 242 | 242 | foreach ($cached->data as $key => $value) { |
| 243 | - $node->$key = $value; |
|
| 243 | + $node->$key = $value; |
|
| 244 | 244 | } |
| 245 | - } |
|
| 246 | - else { |
|
| 245 | + } |
|
| 246 | + else { |
|
| 247 | 247 | $default_additions = _content_field_invoke_default('load', $node); |
| 248 | 248 | if ($default_additions) { |
| 249 | - foreach ($default_additions as $key => $value) { |
|
| 249 | + foreach ($default_additions as $key => $value) { |
|
| 250 | 250 | $node->$key = $value; |
| 251 | - } |
|
| 251 | + } |
|
| 252 | 252 | } |
| 253 | 253 | $additions = _content_field_invoke('load', $node); |
| 254 | 254 | if ($additions) { |
| 255 | - foreach ($additions as $key => $value) { |
|
| 255 | + foreach ($additions as $key => $value) { |
|
| 256 | 256 | $node->$key = $value; |
| 257 | 257 | $default_additions[$key] = $value; |
| 258 | - } |
|
| 258 | + } |
|
| 259 | 259 | } |
| 260 | 260 | cache_set($cid, $default_additions, content_cache_tablename()); |
| 261 | - } |
|
| 261 | + } |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -266,8 +266,8 @@ discard block |
||
| 266 | 266 | * |
| 267 | 267 | */ |
| 268 | 268 | function content_validate(&$node, $form = NULL) { |
| 269 | - _content_field_invoke('validate', $node, $form); |
|
| 270 | - _content_field_invoke_default('validate', $node, $form); |
|
| 269 | + _content_field_invoke('validate', $node, $form); |
|
| 270 | + _content_field_invoke_default('validate', $node, $form); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -275,8 +275,8 @@ discard block |
||
| 275 | 275 | * |
| 276 | 276 | */ |
| 277 | 277 | function content_presave(&$node) { |
| 278 | - _content_field_invoke('presave', $node); |
|
| 279 | - _content_field_invoke_default('presave', $node); |
|
| 278 | + _content_field_invoke('presave', $node); |
|
| 279 | + _content_field_invoke_default('presave', $node); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -285,8 +285,8 @@ discard block |
||
| 285 | 285 | * Insert node type fields. |
| 286 | 286 | */ |
| 287 | 287 | function content_insert(&$node) { |
| 288 | - _content_field_invoke('insert', $node); |
|
| 289 | - _content_field_invoke_default('insert', $node); |
|
| 288 | + _content_field_invoke('insert', $node); |
|
| 289 | + _content_field_invoke_default('insert', $node); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -295,9 +295,9 @@ discard block |
||
| 295 | 295 | * Update node type fields. |
| 296 | 296 | */ |
| 297 | 297 | function content_update(&$node) { |
| 298 | - _content_field_invoke('update', $node); |
|
| 299 | - _content_field_invoke_default('update', $node); |
|
| 300 | - cache_clear_all('content:'. $node->nid .':'. $node->vid, content_cache_tablename()); |
|
| 298 | + _content_field_invoke('update', $node); |
|
| 299 | + _content_field_invoke_default('update', $node); |
|
| 300 | + cache_clear_all('content:'. $node->nid .':'. $node->vid, content_cache_tablename()); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | /** |
@@ -306,9 +306,9 @@ discard block |
||
| 306 | 306 | * Delete node type fields. |
| 307 | 307 | */ |
| 308 | 308 | function content_delete(&$node) { |
| 309 | - _content_field_invoke('delete', $node); |
|
| 310 | - _content_field_invoke_default('delete', $node); |
|
| 311 | - cache_clear_all('content:'. $node->nid .':', content_cache_tablename(), TRUE); |
|
| 309 | + _content_field_invoke('delete', $node); |
|
| 310 | + _content_field_invoke_default('delete', $node); |
|
| 311 | + cache_clear_all('content:'. $node->nid .':', content_cache_tablename(), TRUE); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -317,9 +317,9 @@ discard block |
||
| 317 | 317 | * Delete node type fields for a revision. |
| 318 | 318 | */ |
| 319 | 319 | function content_delete_revision(&$node) { |
| 320 | - _content_field_invoke('delete revision', $node); |
|
| 321 | - _content_field_invoke_default('delete revision', $node); |
|
| 322 | - cache_clear_all('content:'. $node->nid .':'. $node->vid, content_cache_tablename()); |
|
| 320 | + _content_field_invoke('delete revision', $node); |
|
| 321 | + _content_field_invoke_default('delete revision', $node); |
|
| 322 | + cache_clear_all('content:'. $node->nid .':'. $node->vid, content_cache_tablename()); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
@@ -328,12 +328,12 @@ discard block |
||
| 328 | 328 | * Generate field render arrays. |
| 329 | 329 | */ |
| 330 | 330 | function content_view(&$node, $teaser = FALSE, $page = FALSE) { |
| 331 | - // Let field modules sanitize their data for output. |
|
| 332 | - _content_field_invoke('sanitize', $node, $teaser, $page); |
|
| 331 | + // Let field modules sanitize their data for output. |
|
| 332 | + _content_field_invoke('sanitize', $node, $teaser, $page); |
|
| 333 | 333 | |
| 334 | - // Merge fields. |
|
| 335 | - $additions = _content_field_invoke_default('view', $node, $teaser, $page); |
|
| 336 | - $node->content = array_merge((array) $node->content, $additions); |
|
| 334 | + // Merge fields. |
|
| 335 | + $additions = _content_field_invoke_default('view', $node, $teaser, $page); |
|
| 336 | + $node->content = array_merge((array) $node->content, $additions); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -361,8 +361,8 @@ discard block |
||
| 361 | 361 | * The themed output for the field. |
| 362 | 362 | */ |
| 363 | 363 | function content_view_field($field, $node, $teaser = FALSE, $page = FALSE) { |
| 364 | - $output = ''; |
|
| 365 | - if (isset($node->$field['field_name'])) { |
|
| 364 | + $output = ''; |
|
| 365 | + if (isset($node->$field['field_name'])) { |
|
| 366 | 366 | $items = $node->$field['field_name']; |
| 367 | 367 | |
| 368 | 368 | // Use 'full'/'teaser' if not specified otherwise. |
@@ -373,16 +373,16 @@ discard block |
||
| 373 | 373 | $module = $field_types[$field['type']]['module']; |
| 374 | 374 | $function = $module .'_field'; |
| 375 | 375 | if (function_exists($function)) { |
| 376 | - $function('sanitize', $node, $field, $items, $teaser, $page); |
|
| 377 | - $node->$field['field_name'] = $items; |
|
| 376 | + $function('sanitize', $node, $field, $items, $teaser, $page); |
|
| 377 | + $node->$field['field_name'] = $items; |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | $view = content_field('view', $node, $field, $items, $teaser, $page); |
| 381 | 381 | // content_field('view') adds a wrapper to handle variables and 'excluded' |
| 382 | 382 | // fields for node templates. We bypass it and render the actual field. |
| 383 | 383 | $output = drupal_render($view[$field['field_name']]['field']); |
| 384 | - } |
|
| 385 | - return $output; |
|
| 384 | + } |
|
| 385 | + return $output; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | * so that node templates can use it. |
| 393 | 393 | */ |
| 394 | 394 | function content_alter(&$node, $teaser = FALSE, $page = FALSE) { |
| 395 | - _content_field_invoke_default('alter', $node, $teaser, $page); |
|
| 395 | + _content_field_invoke_default('alter', $node, $teaser, $page); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -401,70 +401,70 @@ discard block |
||
| 401 | 401 | * Generate field render arrays. |
| 402 | 402 | */ |
| 403 | 403 | function content_prepare_translation(&$node) { |
| 404 | - $default_additions = _content_field_invoke_default('prepare translation', $node); |
|
| 405 | - $additions = _content_field_invoke('prepare translation', $node); |
|
| 406 | - // Merge module additions after the default ones to enable overriding |
|
| 407 | - // of field values. |
|
| 408 | - $node = (object) array_merge((array) $node, $default_additions, $additions); |
|
| 404 | + $default_additions = _content_field_invoke_default('prepare translation', $node); |
|
| 405 | + $additions = _content_field_invoke('prepare translation', $node); |
|
| 406 | + // Merge module additions after the default ones to enable overriding |
|
| 407 | + // of field values. |
|
| 408 | + $node = (object) array_merge((array) $node, $default_additions, $additions); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
| 412 | 412 | * Implementation of hook_nodeapi(). |
| 413 | 413 | */ |
| 414 | 414 | function content_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
| 415 | - // Prevent against invalid 'nodes' built by broken 3rd party code. |
|
| 416 | - if (isset($node->type)) { |
|
| 415 | + // Prevent against invalid 'nodes' built by broken 3rd party code. |
|
| 416 | + if (isset($node->type)) { |
|
| 417 | 417 | $type = content_types($node->type); |
| 418 | 418 | // Save cycles if the type has no CCK fields. |
| 419 | 419 | if (!empty($type['fields'])) { |
| 420 | - $callback = 'content_'. str_replace(' ', '_', $op); |
|
| 421 | - if (function_exists($callback)) { |
|
| 420 | + $callback = 'content_'. str_replace(' ', '_', $op); |
|
| 421 | + if (function_exists($callback)) { |
|
| 422 | 422 | $callback($node, $a3, $a4); |
| 423 | - } |
|
| 423 | + } |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | // Special case for 'view' op, we want to adjust weights of non-cck fields |
| 427 | 427 | // even if there are no actual fields for this type. |
| 428 | 428 | if ($op == 'view') { |
| 429 | - $node->content['#pre_render'][] = 'content_alter_extra_weights'; |
|
| 430 | - $node->content['#content_extra_fields'] = $type['extra']; |
|
| 429 | + $node->content['#pre_render'][] = 'content_alter_extra_weights'; |
|
| 430 | + $node->content['#content_extra_fields'] = $type['extra']; |
|
| 431 | + } |
|
| 431 | 432 | } |
| 432 | - } |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | /** |
| 436 | 436 | * Implementation of hook_form_alter(). |
| 437 | 437 | */ |
| 438 | 438 | function content_form_alter(&$form, $form_state, $form_id) { |
| 439 | - if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { |
|
| 439 | + if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { |
|
| 440 | 440 | $type = content_types($form['#node']->type); |
| 441 | 441 | if (!empty($type['fields'])) { |
| 442 | - module_load_include('inc', 'content', 'includes/content.node_form'); |
|
| 443 | - // Merge field widgets. |
|
| 444 | - $form = array_merge($form, content_form($form, $form_state)); |
|
| 442 | + module_load_include('inc', 'content', 'includes/content.node_form'); |
|
| 443 | + // Merge field widgets. |
|
| 444 | + $form = array_merge($form, content_form($form, $form_state)); |
|
| 445 | 445 | } |
| 446 | 446 | $form['#pre_render'][] = 'content_alter_extra_weights'; |
| 447 | 447 | $form['#content_extra_fields'] = $type['extra']; |
| 448 | - } |
|
| 448 | + } |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
| 452 | 452 | * Pre-render callback to adjust weights of non-CCK fields. |
| 453 | 453 | */ |
| 454 | 454 | function content_alter_extra_weights($elements) { |
| 455 | - if (isset($elements['#content_extra_fields'])) { |
|
| 455 | + if (isset($elements['#content_extra_fields'])) { |
|
| 456 | 456 | foreach ($elements['#content_extra_fields'] as $key => $value) { |
| 457 | - // Some core 'fields' use a different key in node forms and in 'view' |
|
| 458 | - // render arrays. Check we're not on a form first. |
|
| 459 | - if (!isset($elements['#build_id']) && isset($value['view']) && isset($elements[$value['view']])) { |
|
| 457 | + // Some core 'fields' use a different key in node forms and in 'view' |
|
| 458 | + // render arrays. Check we're not on a form first. |
|
| 459 | + if (!isset($elements['#build_id']) && isset($value['view']) && isset($elements[$value['view']])) { |
|
| 460 | 460 | $elements[$value['view']]['#weight'] = $value['weight']; |
| 461 | - } |
|
| 462 | - elseif (isset($elements[$key])) { |
|
| 461 | + } |
|
| 462 | + elseif (isset($elements[$key])) { |
|
| 463 | 463 | $elements[$key]['#weight'] = $value['weight']; |
| 464 | - } |
|
| 464 | + } |
|
| 465 | + } |
|
| 465 | 466 | } |
| 466 | - } |
|
| 467 | - return $elements; |
|
| 467 | + return $elements; |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /** |
@@ -472,8 +472,8 @@ discard block |
||
| 472 | 472 | * included yet when the form is processed and invokes the callback. |
| 473 | 473 | */ |
| 474 | 474 | function content_add_more_submit_proxy($form, &$form_state) { |
| 475 | - module_load_include('inc', 'content', 'includes/content.node_form'); |
|
| 476 | - content_add_more_submit($form, $form_state); |
|
| 475 | + module_load_include('inc', 'content', 'includes/content.node_form'); |
|
| 476 | + content_add_more_submit($form, $form_state); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
@@ -482,21 +482,21 @@ discard block |
||
| 482 | 482 | * Combine multiple values into a table with drag-n-drop reordering. |
| 483 | 483 | */ |
| 484 | 484 | function theme_content_multiple_values($element) { |
| 485 | - $field_name = $element['#field_name']; |
|
| 486 | - $field = content_fields($field_name); |
|
| 487 | - $output = ''; |
|
| 485 | + $field_name = $element['#field_name']; |
|
| 486 | + $field = content_fields($field_name); |
|
| 487 | + $output = ''; |
|
| 488 | 488 | |
| 489 | - if ($field['multiple'] >= 1) { |
|
| 489 | + if ($field['multiple'] >= 1) { |
|
| 490 | 490 | $table_id = $element['#field_name'] .'_values'; |
| 491 | 491 | $order_class = $element['#field_name'] .'-delta-order'; |
| 492 | 492 | $required = !empty($element['#required']) ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : ''; |
| 493 | 493 | |
| 494 | 494 | $header = array( |
| 495 | - array( |
|
| 495 | + array( |
|
| 496 | 496 | 'data' => t('!title: !required', array('!title' => $element['#title'], '!required' => $required)), |
| 497 | 497 | 'colspan' => 2 |
| 498 | - ), |
|
| 499 | - t('Order'), |
|
| 498 | + ), |
|
| 499 | + t('Order'), |
|
| 500 | 500 | ); |
| 501 | 501 | $rows = array(); |
| 502 | 502 | |
@@ -504,25 +504,25 @@ discard block |
||
| 504 | 504 | // preview or failed validation) |
| 505 | 505 | $items = array(); |
| 506 | 506 | foreach (element_children($element) as $key) { |
| 507 | - if ($key !== $element['#field_name'] .'_add_more') { |
|
| 507 | + if ($key !== $element['#field_name'] .'_add_more') { |
|
| 508 | 508 | $items[] = &$element[$key]; |
| 509 | - } |
|
| 509 | + } |
|
| 510 | 510 | } |
| 511 | 511 | usort($items, '_content_sort_items_value_helper'); |
| 512 | 512 | |
| 513 | 513 | // Add the items as table rows. |
| 514 | 514 | foreach ($items as $key => $item) { |
| 515 | - $item['_weight']['#attributes']['class'] = $order_class; |
|
| 516 | - $delta_element = drupal_render($item['_weight']); |
|
| 517 | - $cells = array( |
|
| 515 | + $item['_weight']['#attributes']['class'] = $order_class; |
|
| 516 | + $delta_element = drupal_render($item['_weight']); |
|
| 517 | + $cells = array( |
|
| 518 | 518 | array('data' => '', 'class' => 'content-multiple-drag'), |
| 519 | 519 | drupal_render($item), |
| 520 | 520 | array('data' => $delta_element, 'class' => 'delta-order'), |
| 521 | - ); |
|
| 522 | - $rows[] = array( |
|
| 521 | + ); |
|
| 522 | + $rows[] = array( |
|
| 523 | 523 | 'data' => $cells, |
| 524 | 524 | 'class' => 'draggable', |
| 525 | - ); |
|
| 525 | + ); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | $output .= theme('table', $header, $rows, array('id' => $table_id, 'class' => 'content-multiple-table')); |
@@ -530,14 +530,14 @@ discard block |
||
| 530 | 530 | $output .= drupal_render($element[$element['#field_name'] .'_add_more']); |
| 531 | 531 | |
| 532 | 532 | drupal_add_tabledrag($table_id, 'order', 'sibling', $order_class); |
| 533 | - } |
|
| 534 | - else { |
|
| 533 | + } |
|
| 534 | + else { |
|
| 535 | 535 | foreach (element_children($element) as $key) { |
| 536 | - $output .= drupal_render($element[$key]); |
|
| 536 | + $output .= drupal_render($element[$key]); |
|
| 537 | + } |
|
| 537 | 538 | } |
| 538 | - } |
|
| 539 | 539 | |
| 540 | - return $output; |
|
| 540 | + return $output; |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | /** |
@@ -552,29 +552,29 @@ discard block |
||
| 552 | 552 | * field modules are installed, uninstalled, enabled or disabled. |
| 553 | 553 | */ |
| 554 | 554 | function content_notify($op, $module) { |
| 555 | - switch ($op) { |
|
| 555 | + switch ($op) { |
|
| 556 | 556 | case 'install': |
| 557 | 557 | content_clear_type_cache(); |
| 558 | - break; |
|
| 558 | + break; |
|
| 559 | 559 | case 'uninstall': |
| 560 | 560 | module_load_include('inc', 'content', 'includes/content.crud'); |
| 561 | - content_module_delete($module); |
|
| 562 | - break; |
|
| 561 | + content_module_delete($module); |
|
| 562 | + break; |
|
| 563 | 563 | case 'enable': |
| 564 | 564 | content_associate_fields($module); |
| 565 | - content_clear_type_cache(); |
|
| 566 | - break; |
|
| 565 | + content_clear_type_cache(); |
|
| 566 | + break; |
|
| 567 | 567 | case 'disable': |
| 568 | 568 | // When CCK modules are disabled before content module's update is run |
| 569 | 569 | // to add the active column, we can't do this. |
| 570 | 570 | if (variable_get('content_schema_version', -1) < 6007) { |
| 571 | 571 | return FALSE; |
| 572 | - } |
|
| 573 | - db_query("UPDATE {". content_field_tablename() ."} SET active=0 WHERE module='%s'", $module); |
|
| 574 | - db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=0 WHERE widget_module='%s'", $module); |
|
| 575 | - content_clear_type_cache(TRUE); |
|
| 576 | - break; |
|
| 577 | - } |
|
| 572 | + } |
|
| 573 | + db_query("UPDATE {". content_field_tablename() ."} SET active=0 WHERE module='%s'", $module); |
|
| 574 | + db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=0 WHERE widget_module='%s'", $module); |
|
| 575 | + content_clear_type_cache(TRUE); |
|
| 576 | + break; |
|
| 577 | + } |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | /** |
@@ -584,39 +584,39 @@ discard block |
||
| 584 | 584 | * The name of the module to update on. |
| 585 | 585 | */ |
| 586 | 586 | function content_associate_fields($module) { |
| 587 | - // When CCK modules are enabled before content module's update is run, |
|
| 588 | - // to add module and active columns, we can't do this. |
|
| 589 | - if (variable_get('content_schema_version', -1) < 6007) { |
|
| 587 | + // When CCK modules are enabled before content module's update is run, |
|
| 588 | + // to add module and active columns, we can't do this. |
|
| 589 | + if (variable_get('content_schema_version', -1) < 6007) { |
|
| 590 | 590 | return FALSE; |
| 591 | - } |
|
| 592 | - $module_fields = module_invoke($module, 'field_info'); |
|
| 593 | - if ($module_fields) { |
|
| 591 | + } |
|
| 592 | + $module_fields = module_invoke($module, 'field_info'); |
|
| 593 | + if ($module_fields) { |
|
| 594 | 594 | foreach ($module_fields as $name => $field_info) { |
| 595 | - watchdog('content', 'Updating field type %type with module %module.', array('%type' => $name, '%module' => $module)); |
|
| 596 | - db_query("UPDATE {". content_field_tablename() ."} SET module = '%s', active = %d WHERE type = '%s'", $module, 1, $name); |
|
| 595 | + watchdog('content', 'Updating field type %type with module %module.', array('%type' => $name, '%module' => $module)); |
|
| 596 | + db_query("UPDATE {". content_field_tablename() ."} SET module = '%s', active = %d WHERE type = '%s'", $module, 1, $name); |
|
| 597 | 597 | } |
| 598 | - } |
|
| 599 | - $module_widgets = module_invoke($module, 'widget_info'); |
|
| 600 | - if ($module_widgets) { |
|
| 598 | + } |
|
| 599 | + $module_widgets = module_invoke($module, 'widget_info'); |
|
| 600 | + if ($module_widgets) { |
|
| 601 | 601 | foreach ($module_widgets as $name => $widget_info) { |
| 602 | - watchdog('content', 'Updating widget type %type with module %module.', array('%type' => $name, '%module' => $module)); |
|
| 603 | - db_query("UPDATE {". content_instance_tablename() ."} SET widget_module = '%s', widget_active = %d WHERE widget_type = '%s'", $module, 1, $name); |
|
| 604 | - } |
|
| 605 | - } |
|
| 606 | - // This is called from updates and installs, so get the install-safe |
|
| 607 | - // version of a fields array. |
|
| 608 | - $fields_set = array(); |
|
| 609 | - module_load_include('install', 'content'); |
|
| 610 | - $types = content_types_install(); |
|
| 611 | - foreach ($types as $type_name => $fields) { |
|
| 602 | + watchdog('content', 'Updating widget type %type with module %module.', array('%type' => $name, '%module' => $module)); |
|
| 603 | + db_query("UPDATE {". content_instance_tablename() ."} SET widget_module = '%s', widget_active = %d WHERE widget_type = '%s'", $module, 1, $name); |
|
| 604 | + } |
|
| 605 | + } |
|
| 606 | + // This is called from updates and installs, so get the install-safe |
|
| 607 | + // version of a fields array. |
|
| 608 | + $fields_set = array(); |
|
| 609 | + module_load_include('install', 'content'); |
|
| 610 | + $types = content_types_install(); |
|
| 611 | + foreach ($types as $type_name => $fields) { |
|
| 612 | 612 | foreach ($fields as $field) { |
| 613 | - if ($field['module'] == $module && !in_array($field['field_name'], $fields_set)) { |
|
| 613 | + if ($field['module'] == $module && !in_array($field['field_name'], $fields_set)) { |
|
| 614 | 614 | $columns = (array) module_invoke($field['module'], 'field_settings', 'database columns', $field); |
| 615 | 615 | db_query("UPDATE {". content_field_tablename() ."} SET db_columns = '%s' WHERE field_name = '%s'", serialize($columns), $field['field_name']); |
| 616 | 616 | $fields_set[] = $field['field_name']; |
| 617 | - } |
|
| 617 | + } |
|
| 618 | + } |
|
| 618 | 619 | } |
| 619 | - } |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | * ); |
| 685 | 685 | */ |
| 686 | 686 | function content_field($op, &$node, $field, &$items, $teaser, $page) { |
| 687 | - switch ($op) { |
|
| 687 | + switch ($op) { |
|
| 688 | 688 | case 'validate': |
| 689 | 689 | // TODO: here we could validate that the number of multiple data is correct ? |
| 690 | 690 | // We're controlling the number of fields to fill out and saving empty |
@@ -699,107 +699,107 @@ discard block |
||
| 699 | 699 | include_once('./'. drupal_get_path('module', 'content') .'/includes/content.devel.inc'); |
| 700 | 700 | content_generate_fields($node, $field); |
| 701 | 701 | $items = $node->{$field['field_name']}; |
| 702 | - } |
|
| 703 | - |
|
| 704 | - // Manual node_save calls might not have all fields filled in. |
|
| 705 | - // On node insert, we need to make sure all tables get at least an empty |
|
| 706 | - // record, or subsequent edits, using drupal_write_record() in update mode, |
|
| 707 | - // won't insert any data. |
|
| 708 | - // Missing fields on node update are handled in content_storage(). |
|
| 709 | - if (empty($items) && !isset($node->nid)) { |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + // Manual node_save calls might not have all fields filled in. |
|
| 705 | + // On node insert, we need to make sure all tables get at least an empty |
|
| 706 | + // record, or subsequent edits, using drupal_write_record() in update mode, |
|
| 707 | + // won't insert any data. |
|
| 708 | + // Missing fields on node update are handled in content_storage(). |
|
| 709 | + if (empty($items) && !isset($node->nid)) { |
|
| 710 | 710 | foreach (array_keys($field['columns']) as $column) { |
| 711 | - $items[0][$column] = NULL; |
|
| 711 | + $items[0][$column] = NULL; |
|
| 712 | 712 | } |
| 713 | 713 | $node->$field['field_name'] = $items; |
| 714 | - } |
|
| 714 | + } |
|
| 715 | 715 | |
| 716 | - // If there was an AHAH add more button in this field, don't save it. |
|
| 717 | - // TODO: is it still needed ? |
|
| 718 | - unset($items[$field['field_name'] .'_add_more']); |
|
| 716 | + // If there was an AHAH add more button in this field, don't save it. |
|
| 717 | + // TODO: is it still needed ? |
|
| 718 | + unset($items[$field['field_name'] .'_add_more']); |
|
| 719 | 719 | |
| 720 | - if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
| 720 | + if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
| 721 | 721 | // Reorder items to account for drag-n-drop reordering. |
| 722 | 722 | $items = _content_sort_items($field, $items); |
| 723 | - } |
|
| 723 | + } |
|
| 724 | 724 | |
| 725 | - // Filter out empty values. |
|
| 726 | - $items = content_set_empty($field, $items); |
|
| 725 | + // Filter out empty values. |
|
| 726 | + $items = content_set_empty($field, $items); |
|
| 727 | 727 | |
| 728 | - break; |
|
| 728 | + break; |
|
| 729 | 729 | |
| 730 | 730 | case 'view': |
| 731 | 731 | $addition = array(); |
| 732 | 732 | |
| 733 | - // Previewed nodes bypass the 'presave' op, so we need to some massaging. |
|
| 734 | - if ($node->build_mode == NODE_BUILD_PREVIEW && content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
| 733 | + // Previewed nodes bypass the 'presave' op, so we need to some massaging. |
|
| 734 | + if ($node->build_mode == NODE_BUILD_PREVIEW && content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
| 735 | 735 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
| 736 | - // Reorder items to account for drag-n-drop reordering. |
|
| 737 | - $items = _content_sort_items($field, $items); |
|
| 736 | + // Reorder items to account for drag-n-drop reordering. |
|
| 737 | + $items = _content_sort_items($field, $items); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | // Filter out empty values. |
| 741 | 741 | $items = content_set_empty($field, $items); |
| 742 | - } |
|
| 742 | + } |
|
| 743 | 743 | |
| 744 | - // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
|
| 745 | - if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
|
| 744 | + // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
|
| 745 | + if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
|
| 746 | 746 | $context = $teaser ? 'teaser' : 'full'; |
| 747 | - } |
|
| 748 | - else { |
|
| 747 | + } |
|
| 748 | + else { |
|
| 749 | 749 | $context = $node->build_mode; |
| 750 | - } |
|
| 751 | - // The field may be missing info for $contexts added by modules |
|
| 752 | - // enabled after the field was last edited. |
|
| 753 | - $formatter_name = isset($field['display_settings'][$context]) && isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default'; |
|
| 754 | - if ($formatter = _content_get_formatter($formatter_name, $field['type'])) { |
|
| 750 | + } |
|
| 751 | + // The field may be missing info for $contexts added by modules |
|
| 752 | + // enabled after the field was last edited. |
|
| 753 | + $formatter_name = isset($field['display_settings'][$context]) && isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default'; |
|
| 754 | + if ($formatter = _content_get_formatter($formatter_name, $field['type'])) { |
|
| 755 | 755 | $theme = $formatter['module'] .'_formatter_'. $formatter_name; |
| 756 | 756 | $single = (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE); |
| 757 | 757 | |
| 758 | 758 | $label_display = isset($field['display_settings']['label']['format']) ? $field['display_settings']['label']['format'] : 'above'; |
| 759 | 759 | // Do not include field labels when indexing content. |
| 760 | 760 | if ($context == NODE_BUILD_SEARCH_INDEX) { |
| 761 | - $label_display = 'hidden'; |
|
| 761 | + $label_display = 'hidden'; |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | $element = array( |
| 765 | - '#type' => 'content_field', |
|
| 766 | - '#title' => check_plain(t($field['widget']['label'])), |
|
| 767 | - '#field_name' => $field['field_name'], |
|
| 768 | - '#access' => $formatter_name != 'hidden' && content_access('view', $field, NULL, $node), |
|
| 769 | - '#label_display' => $label_display, |
|
| 770 | - '#node' => $node, |
|
| 771 | - '#teaser' => $teaser, |
|
| 772 | - '#page' => $page, |
|
| 773 | - '#context' => $context, |
|
| 774 | - '#single' => $single, |
|
| 775 | - 'items' => array(), |
|
| 765 | + '#type' => 'content_field', |
|
| 766 | + '#title' => check_plain(t($field['widget']['label'])), |
|
| 767 | + '#field_name' => $field['field_name'], |
|
| 768 | + '#access' => $formatter_name != 'hidden' && content_access('view', $field, NULL, $node), |
|
| 769 | + '#label_display' => $label_display, |
|
| 770 | + '#node' => $node, |
|
| 771 | + '#teaser' => $teaser, |
|
| 772 | + '#page' => $page, |
|
| 773 | + '#context' => $context, |
|
| 774 | + '#single' => $single, |
|
| 775 | + 'items' => array(), |
|
| 776 | 776 | ); |
| 777 | 777 | |
| 778 | 778 | // Fill-in items. |
| 779 | 779 | foreach ($items as $delta => $item) { |
| 780 | - $element['items'][$delta] = array( |
|
| 780 | + $element['items'][$delta] = array( |
|
| 781 | 781 | '#item' => $item, |
| 782 | 782 | '#weight' => $delta, |
| 783 | - ); |
|
| 783 | + ); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | // Append formatter information either on each item ('single-value' formatter) |
| 787 | 787 | // or at the upper 'items' level ('multiple-value' formatter) |
| 788 | 788 | $format_info = array( |
| 789 | - '#theme' => $theme, |
|
| 790 | - '#field_name' => $field['field_name'], |
|
| 791 | - '#type_name' => $node->type, |
|
| 792 | - '#formatter' => $formatter_name, |
|
| 793 | - '#node' => $node, |
|
| 789 | + '#theme' => $theme, |
|
| 790 | + '#field_name' => $field['field_name'], |
|
| 791 | + '#type_name' => $node->type, |
|
| 792 | + '#formatter' => $formatter_name, |
|
| 793 | + '#node' => $node, |
|
| 794 | 794 | ); |
| 795 | 795 | if ($single) { |
| 796 | - foreach ($items as $delta => $item) { |
|
| 796 | + foreach ($items as $delta => $item) { |
|
| 797 | 797 | $element['items'][$delta] += $format_info; |
| 798 | 798 | $element['items'][$delta]['#item']['#delta'] = $delta; |
| 799 | - } |
|
| 799 | + } |
|
| 800 | 800 | } |
| 801 | 801 | else { |
| 802 | - $element['items'] += $format_info; |
|
| 802 | + $element['items'] += $format_info; |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | // The wrapper lets us get the themed output for the whole field |
@@ -807,17 +807,17 @@ discard block |
||
| 807 | 807 | // and hide it from the $content variable if needed. |
| 808 | 808 | // See 'preprocess_node' op and theme_content_field_wrapper()? |
| 809 | 809 | $wrapper = array( |
| 810 | - 'field' => $element, |
|
| 811 | - '#weight' => $field['widget']['weight'], |
|
| 812 | - '#post_render' => array('content_field_wrapper_post_render'), |
|
| 813 | - '#field_name' => $field['field_name'], |
|
| 814 | - '#type_name' => $node->type, |
|
| 815 | - '#context' => $context, |
|
| 810 | + 'field' => $element, |
|
| 811 | + '#weight' => $field['widget']['weight'], |
|
| 812 | + '#post_render' => array('content_field_wrapper_post_render'), |
|
| 813 | + '#field_name' => $field['field_name'], |
|
| 814 | + '#type_name' => $node->type, |
|
| 815 | + '#context' => $context, |
|
| 816 | 816 | ); |
| 817 | 817 | |
| 818 | 818 | $addition = array($field['field_name'] => $wrapper); |
| 819 | - } |
|
| 820 | - return $addition; |
|
| 819 | + } |
|
| 820 | + return $addition; |
|
| 821 | 821 | |
| 822 | 822 | case 'alter': |
| 823 | 823 | // Add back the formatted values in the 'view' element, |
@@ -827,64 +827,64 @@ discard block |
||
| 827 | 827 | // The location of the field's rendered output depends on whether the |
| 828 | 828 | // field is in a fieldgroup or not. |
| 829 | 829 | $wrapper = NULL; |
| 830 | - if (isset($node->content[$field['field_name']])) { |
|
| 830 | + if (isset($node->content[$field['field_name']])) { |
|
| 831 | 831 | $wrapper = $node->content[$field['field_name']]; |
| 832 | - } |
|
| 833 | - elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
| 832 | + } |
|
| 833 | + elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
| 834 | 834 | $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
| 835 | - } |
|
| 835 | + } |
|
| 836 | 836 | |
| 837 | - if ($wrapper) { |
|
| 837 | + if ($wrapper) { |
|
| 838 | 838 | $element = $wrapper['field']; |
| 839 | 839 | // '#single' is not set if the field is hidden or inaccessible. |
| 840 | 840 | if (isset($element['#single'])) { |
| 841 | - if (!empty($element['#single'])) { |
|
| 841 | + if (!empty($element['#single'])) { |
|
| 842 | 842 | // Single value formatter. |
| 843 | 843 | foreach (element_children($element['items']) as $delta) { |
| 844 | - // '#chilren' is not set if the field is empty. |
|
| 845 | - $items[$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
|
| 844 | + // '#chilren' is not set if the field is empty. |
|
| 845 | + $items[$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
|
| 846 | + } |
|
| 846 | 847 | } |
| 847 | - } |
|
| 848 | - elseif (isset($element['items']['#children'])) { |
|
| 848 | + elseif (isset($element['items']['#children'])) { |
|
| 849 | 849 | // Multiple values formatter. |
| 850 | 850 | $items[0]['view'] = $element['items']['#children']; |
| 851 | - } |
|
| 851 | + } |
|
| 852 | 852 | } |
| 853 | 853 | else { |
| 854 | - // Hidden or inaccessible field. |
|
| 855 | - $items[0]['view'] = ''; |
|
| 854 | + // Hidden or inaccessible field. |
|
| 855 | + $items[0]['view'] = ''; |
|
| 856 | 856 | } |
| 857 | - } |
|
| 858 | - break; |
|
| 857 | + } |
|
| 858 | + break; |
|
| 859 | 859 | |
| 860 | 860 | case 'preprocess_node': |
| 861 | 861 | // Add $FIELD_NAME_rendered variables. |
| 862 | 862 | $addition = array(); |
| 863 | 863 | |
| 864 | - // The location of the field's rendered output depends on whether the |
|
| 865 | - // field is in a fieldgroup or not. |
|
| 866 | - $wrapper = NULL; |
|
| 867 | - if (isset($node->content[$field['field_name']])) { |
|
| 864 | + // The location of the field's rendered output depends on whether the |
|
| 865 | + // field is in a fieldgroup or not. |
|
| 866 | + $wrapper = NULL; |
|
| 867 | + if (isset($node->content[$field['field_name']])) { |
|
| 868 | 868 | $wrapper = $node->content[$field['field_name']]; |
| 869 | - } |
|
| 870 | - elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
| 869 | + } |
|
| 870 | + elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
| 871 | 871 | $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
| 872 | - } |
|
| 872 | + } |
|
| 873 | 873 | |
| 874 | - if ($wrapper) { |
|
| 874 | + if ($wrapper) { |
|
| 875 | 875 | // '#chilren' is not set if the field is empty. |
| 876 | 876 | $addition[$field['field_name'] .'_rendered'] = isset($wrapper['#children']) ? $wrapper['#children'] : ''; |
| 877 | - } |
|
| 877 | + } |
|
| 878 | 878 | |
| 879 | - return $addition; |
|
| 879 | + return $addition; |
|
| 880 | 880 | |
| 881 | 881 | case 'prepare translation': |
| 882 | 882 | $addition = array(); |
| 883 | - if (isset($node->translation_source->$field['field_name'])) { |
|
| 883 | + if (isset($node->translation_source->$field['field_name'])) { |
|
| 884 | 884 | $addition[$field['field_name']] = $node->translation_source->$field['field_name']; |
| 885 | - } |
|
| 886 | - return $addition; |
|
| 887 | - } |
|
| 885 | + } |
|
| 886 | + return $addition; |
|
| 887 | + } |
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | /** |
@@ -899,24 +899,24 @@ discard block |
||
| 899 | 899 | * returns filtered and adjusted item array |
| 900 | 900 | */ |
| 901 | 901 | function content_set_empty($field, $items) { |
| 902 | - // Filter out empty values. |
|
| 903 | - $filtered = array(); |
|
| 904 | - $function = $field['module'] .'_content_is_empty'; |
|
| 905 | - foreach ((array) $items as $delta => $item) { |
|
| 902 | + // Filter out empty values. |
|
| 903 | + $filtered = array(); |
|
| 904 | + $function = $field['module'] .'_content_is_empty'; |
|
| 905 | + foreach ((array) $items as $delta => $item) { |
|
| 906 | 906 | if (!$function($item, $field)) { |
| 907 | - $filtered[] = $item; |
|
| 907 | + $filtered[] = $item; |
|
| 908 | + } |
|
| 908 | 909 | } |
| 909 | - } |
|
| 910 | 910 | |
| 911 | - // Make sure we store the right number of 'empty' values. |
|
| 912 | - $empty = array(); |
|
| 913 | - foreach (array_keys($field['columns']) as $column) { |
|
| 911 | + // Make sure we store the right number of 'empty' values. |
|
| 912 | + $empty = array(); |
|
| 913 | + foreach (array_keys($field['columns']) as $column) { |
|
| 914 | 914 | $empty[$column] = NULL; |
| 915 | - } |
|
| 916 | - $pad = $field['multiple'] > 1 ? $field['multiple'] : 1; |
|
| 917 | - $filtered = array_pad($filtered, $pad, $empty); |
|
| 915 | + } |
|
| 916 | + $pad = $field['multiple'] > 1 ? $field['multiple'] : 1; |
|
| 917 | + $filtered = array_pad($filtered, $pad, $empty); |
|
| 918 | 918 | |
| 919 | - return $filtered; |
|
| 919 | + return $filtered; |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | /** |
@@ -924,15 +924,15 @@ discard block |
||
| 924 | 924 | * user drag-n-drop reordering. |
| 925 | 925 | */ |
| 926 | 926 | function _content_sort_items($field, $items) { |
| 927 | - if ($field['multiple'] >= 1 && isset($items[0]['_weight'])) { |
|
| 927 | + if ($field['multiple'] >= 1 && isset($items[0]['_weight'])) { |
|
| 928 | 928 | usort($items, '_content_sort_items_helper'); |
| 929 | 929 | foreach ($items as $delta => $item) { |
| 930 | - if (is_array($items[$delta])) { |
|
| 930 | + if (is_array($items[$delta])) { |
|
| 931 | 931 | unset($items[$delta]['_weight']); |
| 932 | - } |
|
| 932 | + } |
|
| 933 | + } |
|
| 933 | 934 | } |
| 934 | - } |
|
| 935 | - return $items; |
|
| 935 | + return $items; |
|
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | /** |
@@ -940,50 +940,50 @@ discard block |
||
| 940 | 940 | * (copied form element_sort(), which acts on #weight keys) |
| 941 | 941 | */ |
| 942 | 942 | function _content_sort_items_helper($a, $b) { |
| 943 | - $a_weight = (is_array($a) && isset($a['_weight'])) ? $a['_weight'] : 0; |
|
| 944 | - $b_weight = (is_array($b) && isset($b['_weight'])) ? $b['_weight'] : 0; |
|
| 945 | - if ($a_weight == $b_weight) { |
|
| 943 | + $a_weight = (is_array($a) && isset($a['_weight'])) ? $a['_weight'] : 0; |
|
| 944 | + $b_weight = (is_array($b) && isset($b['_weight'])) ? $b['_weight'] : 0; |
|
| 945 | + if ($a_weight == $b_weight) { |
|
| 946 | 946 | return 0; |
| 947 | - } |
|
| 948 | - return ($a_weight < $b_weight) ? -1 : 1; |
|
| 947 | + } |
|
| 948 | + return ($a_weight < $b_weight) ? -1 : 1; |
|
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | /** |
| 952 | 952 | * Same as above, using ['_weight']['#value'] |
| 953 | 953 | */ |
| 954 | 954 | function _content_sort_items_value_helper($a, $b) { |
| 955 | - $a_weight = (is_array($a) && isset($a['_weight']['#value'])) ? $a['_weight']['#value'] : 0; |
|
| 956 | - $b_weight = (is_array($b) && isset($b['_weight']['#value'])) ? $b['_weight']['#value'] : 0; |
|
| 957 | - if ($a_weight == $b_weight) { |
|
| 955 | + $a_weight = (is_array($a) && isset($a['_weight']['#value'])) ? $a['_weight']['#value'] : 0; |
|
| 956 | + $b_weight = (is_array($b) && isset($b['_weight']['#value'])) ? $b['_weight']['#value'] : 0; |
|
| 957 | + if ($a_weight == $b_weight) { |
|
| 958 | 958 | return 0; |
| 959 | - } |
|
| 960 | - return ($a_weight < $b_weight) ? -1 : 1; |
|
| 959 | + } |
|
| 960 | + return ($a_weight < $b_weight) ? -1 : 1; |
|
| 961 | 961 | } |
| 962 | 962 | |
| 963 | 963 | /** |
| 964 | 964 | * Handle storage ops for _content_field_invoke_default(). |
| 965 | 965 | */ |
| 966 | 966 | function content_storage($op, $node) { |
| 967 | - // Don't try this before content module's update is run to add |
|
| 968 | - // the active and module columns. |
|
| 969 | - if (variable_get('content_schema_version', -1) < 6007) { |
|
| 967 | + // Don't try this before content module's update is run to add |
|
| 968 | + // the active and module columns. |
|
| 969 | + if (variable_get('content_schema_version', -1) < 6007) { |
|
| 970 | 970 | return FALSE; |
| 971 | - } |
|
| 971 | + } |
|
| 972 | 972 | |
| 973 | - $type_name = $node->type; |
|
| 974 | - $type = content_types($type_name); |
|
| 973 | + $type_name = $node->type; |
|
| 974 | + $type = content_types($type_name); |
|
| 975 | 975 | |
| 976 | - switch ($op) { |
|
| 976 | + switch ($op) { |
|
| 977 | 977 | case 'load': |
| 978 | 978 | // OPTIMIZE: load all non multiple fields in a single JOIN query ? |
| 979 | 979 | // warning: 61-join limit in MySQL ? |
| 980 | 980 | $additions = array(); |
| 981 | - // For each table used by this content type, |
|
| 982 | - foreach ($type['tables'] as $table) { |
|
| 981 | + // For each table used by this content type, |
|
| 982 | + foreach ($type['tables'] as $table) { |
|
| 983 | 983 | $schema = drupal_get_schema($table); |
| 984 | 984 | // The per-type table might not have any fields actually stored in it. |
| 985 | 985 | if (!$schema['content fields']) { |
| 986 | - continue; |
|
| 986 | + continue; |
|
| 987 | 987 | } |
| 988 | 988 | $query = 'SELECT * FROM {'. $table .'} WHERE vid = %d'; |
| 989 | 989 | |
@@ -994,25 +994,25 @@ discard block |
||
| 994 | 994 | |
| 995 | 995 | // For each table row, populate the fields. |
| 996 | 996 | while ($row = db_fetch_array($result)) { |
| 997 | - // For each field stored in the table, add the field item. |
|
| 998 | - foreach ($schema['content fields'] as $field_name) { |
|
| 997 | + // For each field stored in the table, add the field item. |
|
| 998 | + foreach ($schema['content fields'] as $field_name) { |
|
| 999 | 999 | $item = array(); |
| 1000 | 1000 | $field = content_fields($field_name, $type_name); |
| 1001 | 1001 | $db_info = content_database_info($field); |
| 1002 | 1002 | // For each column declared by the field, populate the item. |
| 1003 | 1003 | foreach ($db_info['columns'] as $column => $attributes) { |
| 1004 | - $item[$column] = $row[$attributes['column']]; |
|
| 1004 | + $item[$column] = $row[$attributes['column']]; |
|
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | 1007 | // Add the item to the field values for the node. |
| 1008 | 1008 | if (!isset($additions[$field_name])) { |
| 1009 | - $additions[$field_name] = array(); |
|
| 1009 | + $additions[$field_name] = array(); |
|
| 1010 | 1010 | } |
| 1011 | 1011 | $additions[$field_name][] = $item; |
| 1012 | - } |
|
| 1012 | + } |
|
| 1013 | 1013 | } |
| 1014 | - } |
|
| 1015 | - return $additions; |
|
| 1014 | + } |
|
| 1015 | + return $additions; |
|
| 1016 | 1016 | |
| 1017 | 1017 | case 'insert': |
| 1018 | 1018 | case 'update': |
@@ -1020,17 +1020,17 @@ discard block |
||
| 1020 | 1020 | $schema = drupal_get_schema($table); |
| 1021 | 1021 | $record = array(); |
| 1022 | 1022 | foreach ($schema['content fields'] as $field_name) { |
| 1023 | - if (isset($node->$field_name)) { |
|
| 1023 | + if (isset($node->$field_name)) { |
|
| 1024 | 1024 | $field = content_fields($field_name, $type_name); |
| 1025 | 1025 | // Multiple fields need specific handling, we'll deal with them later on. |
| 1026 | 1026 | if ($field['multiple']) { |
| 1027 | - continue; |
|
| 1027 | + continue; |
|
| 1028 | 1028 | } |
| 1029 | 1029 | $db_info = content_database_info($field); |
| 1030 | 1030 | foreach ($db_info['columns'] as $column => $attributes) { |
| 1031 | - $record[$attributes['column']] = $node->{$field_name}[0][$column]; |
|
| 1031 | + $record[$attributes['column']] = $node->{$field_name}[0][$column]; |
|
| 1032 | + } |
|
| 1032 | 1033 | } |
| 1033 | - } |
|
| 1034 | 1034 | } |
| 1035 | 1035 | // $record might be empty because |
| 1036 | 1036 | // - the table stores a multiple field : |
@@ -1038,59 +1038,59 @@ discard block |
||
| 1038 | 1038 | // - this is the per-type table and no field is actually stored in it : |
| 1039 | 1039 | // we still store the nid and vid |
| 1040 | 1040 | if (count($record) || empty($schema['content fields'])) { |
| 1041 | - $record['nid'] = $node->nid; |
|
| 1042 | - $record['vid'] = $node->vid; |
|
| 1043 | - // Can't rely on the insert/update op of the node to decide if this |
|
| 1044 | - // is an insert or an update, a node or revision may have existed |
|
| 1045 | - // before any fields were created, so there may not be an entry here. |
|
| 1046 | - |
|
| 1047 | - // TODO - should we auto create an entry for all existing nodes when |
|
| 1048 | - // fields are added to content types -- either a NULL value |
|
| 1049 | - // or the default value? May need to offer the user an option of |
|
| 1050 | - // how to handle that. |
|
| 1051 | - if (db_result(db_query("SELECT COUNT(*) FROM {". $table ."} WHERE vid = %d", $node->vid))) { |
|
| 1041 | + $record['nid'] = $node->nid; |
|
| 1042 | + $record['vid'] = $node->vid; |
|
| 1043 | + // Can't rely on the insert/update op of the node to decide if this |
|
| 1044 | + // is an insert or an update, a node or revision may have existed |
|
| 1045 | + // before any fields were created, so there may not be an entry here. |
|
| 1046 | + |
|
| 1047 | + // TODO - should we auto create an entry for all existing nodes when |
|
| 1048 | + // fields are added to content types -- either a NULL value |
|
| 1049 | + // or the default value? May need to offer the user an option of |
|
| 1050 | + // how to handle that. |
|
| 1051 | + if (db_result(db_query("SELECT COUNT(*) FROM {". $table ."} WHERE vid = %d", $node->vid))) { |
|
| 1052 | 1052 | content_write_record($table, $record, array('vid')); |
| 1053 | - } |
|
| 1054 | - else { |
|
| 1053 | + } |
|
| 1054 | + else { |
|
| 1055 | 1055 | content_write_record($table, $record); |
| 1056 | - } |
|
| 1056 | + } |
|
| 1057 | + } |
|
| 1057 | 1058 | } |
| 1058 | - } |
|
| 1059 | 1059 | |
| 1060 | - // Handle multiple fields. |
|
| 1061 | - foreach ($type['fields'] as $field) { |
|
| 1060 | + // Handle multiple fields. |
|
| 1061 | + foreach ($type['fields'] as $field) { |
|
| 1062 | 1062 | if ($field['multiple'] && isset($node->$field['field_name'])) { |
| 1063 | - $db_info = content_database_info($field); |
|
| 1064 | - // Delete and insert, rather than update, in case a value was added. |
|
| 1065 | - if ($op == 'update') { |
|
| 1063 | + $db_info = content_database_info($field); |
|
| 1064 | + // Delete and insert, rather than update, in case a value was added. |
|
| 1065 | + if ($op == 'update') { |
|
| 1066 | 1066 | db_query('DELETE FROM {'. $db_info['table'] .'} WHERE vid = %d', $node->vid); |
| 1067 | - } |
|
| 1068 | - foreach ($node->$field['field_name'] as $delta => $item) { |
|
| 1067 | + } |
|
| 1068 | + foreach ($node->$field['field_name'] as $delta => $item) { |
|
| 1069 | 1069 | $record = array(); |
| 1070 | 1070 | foreach ($db_info['columns'] as $column => $attributes) { |
| 1071 | - $record[$attributes['column']] = $item[$column]; |
|
| 1071 | + $record[$attributes['column']] = $item[$column]; |
|
| 1072 | 1072 | } |
| 1073 | 1073 | $record['nid'] = $node->nid; |
| 1074 | 1074 | $record['vid'] = $node->vid; |
| 1075 | 1075 | $record['delta'] = $delta; |
| 1076 | 1076 | content_write_record($db_info['table'], $record); |
| 1077 | - } |
|
| 1077 | + } |
|
| 1078 | 1078 | } |
| 1079 | - } |
|
| 1080 | - break; |
|
| 1079 | + } |
|
| 1080 | + break; |
|
| 1081 | 1081 | |
| 1082 | 1082 | case 'delete': |
| 1083 | 1083 | foreach ($type['tables'] as $table) { |
| 1084 | 1084 | db_query('DELETE FROM {'. $table .'} WHERE nid = %d', $node->nid); |
| 1085 | - } |
|
| 1086 | - break; |
|
| 1085 | + } |
|
| 1086 | + break; |
|
| 1087 | 1087 | |
| 1088 | 1088 | case 'delete revision': |
| 1089 | 1089 | foreach ($type['tables'] as $table) { |
| 1090 | 1090 | db_query('DELETE FROM {'. $table .'} WHERE vid = %d', $node->vid); |
| 1091 | - } |
|
| 1092 | - break; |
|
| 1093 | - } |
|
| 1091 | + } |
|
| 1092 | + break; |
|
| 1093 | + } |
|
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | 1096 | /** |
@@ -1125,108 +1125,108 @@ discard block |
||
| 1125 | 1125 | * a new node. |
| 1126 | 1126 | */ |
| 1127 | 1127 | function content_write_record($table, &$object, $update = array()) { |
| 1128 | - // Standardize $update to an array. |
|
| 1129 | - if (is_string($update)) { |
|
| 1128 | + // Standardize $update to an array. |
|
| 1129 | + if (is_string($update)) { |
|
| 1130 | 1130 | $update = array($update); |
| 1131 | - } |
|
| 1131 | + } |
|
| 1132 | 1132 | |
| 1133 | - // Convert to an object if needed. |
|
| 1134 | - if (is_array($object)) { |
|
| 1133 | + // Convert to an object if needed. |
|
| 1134 | + if (is_array($object)) { |
|
| 1135 | 1135 | $object = (object) $object; |
| 1136 | 1136 | $array = TRUE; |
| 1137 | - } |
|
| 1138 | - else { |
|
| 1137 | + } |
|
| 1138 | + else { |
|
| 1139 | 1139 | $array = FALSE; |
| 1140 | - } |
|
| 1140 | + } |
|
| 1141 | 1141 | |
| 1142 | - $schema = drupal_get_schema($table); |
|
| 1143 | - if (empty($schema)) { |
|
| 1142 | + $schema = drupal_get_schema($table); |
|
| 1143 | + if (empty($schema)) { |
|
| 1144 | 1144 | return FALSE; |
| 1145 | - } |
|
| 1145 | + } |
|
| 1146 | 1146 | |
| 1147 | - $fields = $defs = $values = $serials = $placeholders = array(); |
|
| 1147 | + $fields = $defs = $values = $serials = $placeholders = array(); |
|
| 1148 | 1148 | |
| 1149 | - // Go through our schema, build SQL, and when inserting, fill in defaults for |
|
| 1150 | - // fields that are not set. |
|
| 1151 | - foreach ($schema['fields'] as $field => $info) { |
|
| 1149 | + // Go through our schema, build SQL, and when inserting, fill in defaults for |
|
| 1150 | + // fields that are not set. |
|
| 1151 | + foreach ($schema['fields'] as $field => $info) { |
|
| 1152 | 1152 | // Special case -- skip serial types if we are updating. |
| 1153 | 1153 | if ($info['type'] == 'serial' && count($update)) { |
| 1154 | - continue; |
|
| 1154 | + continue; |
|
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | 1157 | // For inserts, populate defaults from Schema if not already provided |
| 1158 | 1158 | if (!isset($object->$field) && !count($update) && isset($info['default'])) { |
| 1159 | - $object->$field = $info['default']; |
|
| 1159 | + $object->$field = $info['default']; |
|
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | // Track serial fields so we can helpfully populate them after the query. |
| 1163 | 1163 | if ($info['type'] == 'serial') { |
| 1164 | - $serials[] = $field; |
|
| 1165 | - // Ignore values for serials when inserting data. Unsupported. |
|
| 1166 | - unset($object->$field); |
|
| 1164 | + $serials[] = $field; |
|
| 1165 | + // Ignore values for serials when inserting data. Unsupported. |
|
| 1166 | + unset($object->$field); |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | // Build arrays for the fields, placeholders, and values in our query. |
| 1170 | 1170 | if (isset($object->$field) || array_key_exists($field, $object)) { |
| 1171 | - $fields[] = $field; |
|
| 1172 | - if (isset($object->$field)) { |
|
| 1171 | + $fields[] = $field; |
|
| 1172 | + if (isset($object->$field)) { |
|
| 1173 | 1173 | $placeholders[] = db_type_placeholder($info['type']); |
| 1174 | 1174 | |
| 1175 | 1175 | if (empty($info['serialize'])) { |
| 1176 | - $values[] = $object->$field; |
|
| 1176 | + $values[] = $object->$field; |
|
| 1177 | 1177 | } |
| 1178 | 1178 | else { |
| 1179 | - $values[] = serialize($object->$field); |
|
| 1179 | + $values[] = serialize($object->$field); |
|
| 1180 | + } |
|
| 1180 | 1181 | } |
| 1181 | - } |
|
| 1182 | - else { |
|
| 1182 | + else { |
|
| 1183 | 1183 | $placeholders[] = 'NULL'; |
| 1184 | - } |
|
| 1184 | + } |
|
| 1185 | + } |
|
| 1185 | 1186 | } |
| 1186 | - } |
|
| 1187 | 1187 | |
| 1188 | - // Build the SQL. |
|
| 1189 | - $query = ''; |
|
| 1190 | - if (!count($update)) { |
|
| 1188 | + // Build the SQL. |
|
| 1189 | + $query = ''; |
|
| 1190 | + if (!count($update)) { |
|
| 1191 | 1191 | $query = "INSERT INTO {". $table ."} (". implode(', ', $fields) .') VALUES ('. implode(', ', $placeholders) .')'; |
| 1192 | 1192 | $return = SAVED_NEW; |
| 1193 | - } |
|
| 1194 | - else { |
|
| 1193 | + } |
|
| 1194 | + else { |
|
| 1195 | 1195 | $query = ''; |
| 1196 | 1196 | foreach ($fields as $id => $field) { |
| 1197 | - if ($query) { |
|
| 1197 | + if ($query) { |
|
| 1198 | 1198 | $query .= ', '; |
| 1199 | - } |
|
| 1200 | - $query .= $field .' = '. $placeholders[$id]; |
|
| 1199 | + } |
|
| 1200 | + $query .= $field .' = '. $placeholders[$id]; |
|
| 1201 | 1201 | } |
| 1202 | 1202 | |
| 1203 | 1203 | foreach ($update as $key) { |
| 1204 | - $conditions[] = "$key = ". db_type_placeholder($schema['fields'][$key]['type']); |
|
| 1205 | - $values[] = $object->$key; |
|
| 1204 | + $conditions[] = "$key = ". db_type_placeholder($schema['fields'][$key]['type']); |
|
| 1205 | + $values[] = $object->$key; |
|
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | 1208 | $query = "UPDATE {". $table ."} SET $query WHERE ". implode(' AND ', $conditions); |
| 1209 | 1209 | $return = SAVED_UPDATED; |
| 1210 | - } |
|
| 1210 | + } |
|
| 1211 | 1211 | |
| 1212 | - // Execute the SQL. |
|
| 1213 | - if (db_query($query, $values)) { |
|
| 1212 | + // Execute the SQL. |
|
| 1213 | + if (db_query($query, $values)) { |
|
| 1214 | 1214 | if ($serials) { |
| 1215 | - // Get last insert ids and fill them in. |
|
| 1216 | - foreach ($serials as $field) { |
|
| 1215 | + // Get last insert ids and fill them in. |
|
| 1216 | + foreach ($serials as $field) { |
|
| 1217 | 1217 | $object->$field = db_last_insert_id($table, $field); |
| 1218 | - } |
|
| 1218 | + } |
|
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | 1221 | // If we began with an array, convert back so we don't surprise the caller. |
| 1222 | 1222 | if ($array) { |
| 1223 | - $object = (array) $object; |
|
| 1223 | + $object = (array) $object; |
|
| 1224 | 1224 | } |
| 1225 | 1225 | |
| 1226 | 1226 | return $return; |
| 1227 | - } |
|
| 1227 | + } |
|
| 1228 | 1228 | |
| 1229 | - return FALSE; |
|
| 1229 | + return FALSE; |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | /** |
@@ -1236,12 +1236,12 @@ discard block |
||
| 1236 | 1236 | * called so that the default database handling can occur. |
| 1237 | 1237 | */ |
| 1238 | 1238 | function _content_field_invoke($op, &$node, $teaser = NULL, $page = NULL) { |
| 1239 | - $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); |
|
| 1240 | - $type = content_types($type_name); |
|
| 1241 | - $field_types = _content_field_types(); |
|
| 1239 | + $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); |
|
| 1240 | + $type = content_types($type_name); |
|
| 1241 | + $field_types = _content_field_types(); |
|
| 1242 | 1242 | |
| 1243 | - $return = array(); |
|
| 1244 | - foreach ($type['fields'] as $field) { |
|
| 1243 | + $return = array(); |
|
| 1244 | + foreach ($type['fields'] as $field) { |
|
| 1245 | 1245 | $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array(); |
| 1246 | 1246 | |
| 1247 | 1247 | // Make sure AHAH 'add more' button isn't sent to the fields for processing. |
@@ -1250,52 +1250,52 @@ discard block |
||
| 1250 | 1250 | $module = $field_types[$field['type']]['module']; |
| 1251 | 1251 | $function = $module .'_field'; |
| 1252 | 1252 | if (function_exists($function)) { |
| 1253 | - $result = $function($op, $node, $field, $items, $teaser, $page); |
|
| 1254 | - if (is_array($result)) { |
|
| 1253 | + $result = $function($op, $node, $field, $items, $teaser, $page); |
|
| 1254 | + if (is_array($result)) { |
|
| 1255 | 1255 | $return = array_merge($return, $result); |
| 1256 | - } |
|
| 1257 | - else if (isset($result)) { |
|
| 1256 | + } |
|
| 1257 | + else if (isset($result)) { |
|
| 1258 | 1258 | $return[] = $result; |
| 1259 | - } |
|
| 1259 | + } |
|
| 1260 | 1260 | } |
| 1261 | 1261 | // test for values in $items in case modules added items on insert |
| 1262 | 1262 | if (isset($node->$field['field_name']) || count($items)) { |
| 1263 | - $node->$field['field_name'] = $items; |
|
| 1263 | + $node->$field['field_name'] = $items; |
|
| 1264 | + } |
|
| 1264 | 1265 | } |
| 1265 | - } |
|
| 1266 | - return $return; |
|
| 1266 | + return $return; |
|
| 1267 | 1267 | } |
| 1268 | 1268 | |
| 1269 | 1269 | /** |
| 1270 | 1270 | * Invoke content.module's version of a field hook. |
| 1271 | 1271 | */ |
| 1272 | 1272 | function _content_field_invoke_default($op, &$node, $teaser = NULL, $page = NULL) { |
| 1273 | - $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); |
|
| 1274 | - $type = content_types($type_name); |
|
| 1275 | - $field_types = _content_field_types(); |
|
| 1276 | - |
|
| 1277 | - $return = array(); |
|
| 1278 | - // The operations involving database queries are better off handled by table |
|
| 1279 | - // rather than by field. |
|
| 1280 | - if (in_array($op, array('load', 'insert', 'update', 'delete', 'delete revision'))) { |
|
| 1273 | + $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); |
|
| 1274 | + $type = content_types($type_name); |
|
| 1275 | + $field_types = _content_field_types(); |
|
| 1276 | + |
|
| 1277 | + $return = array(); |
|
| 1278 | + // The operations involving database queries are better off handled by table |
|
| 1279 | + // rather than by field. |
|
| 1280 | + if (in_array($op, array('load', 'insert', 'update', 'delete', 'delete revision'))) { |
|
| 1281 | 1281 | return content_storage($op, $node); |
| 1282 | - } |
|
| 1283 | - else { |
|
| 1282 | + } |
|
| 1283 | + else { |
|
| 1284 | 1284 | foreach ($type['fields'] as $field) { |
| 1285 | - $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array(); |
|
| 1286 | - $result = content_field($op, $node, $field, $items, $teaser, $page); |
|
| 1287 | - if (is_array($result)) { |
|
| 1285 | + $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array(); |
|
| 1286 | + $result = content_field($op, $node, $field, $items, $teaser, $page); |
|
| 1287 | + if (is_array($result)) { |
|
| 1288 | 1288 | $return = array_merge($return, $result); |
| 1289 | - } |
|
| 1290 | - else if (isset($result)) { |
|
| 1289 | + } |
|
| 1290 | + else if (isset($result)) { |
|
| 1291 | 1291 | $return[] = $result; |
| 1292 | - } |
|
| 1293 | - if (isset($node->$field['field_name'])) { |
|
| 1292 | + } |
|
| 1293 | + if (isset($node->$field['field_name'])) { |
|
| 1294 | 1294 | $node->$field['field_name'] = $items; |
| 1295 | - } |
|
| 1295 | + } |
|
| 1296 | + } |
|
| 1296 | 1297 | } |
| 1297 | - } |
|
| 1298 | - return $return; |
|
| 1298 | + return $return; |
|
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | 1301 | /** |
@@ -1308,19 +1308,19 @@ discard block |
||
| 1308 | 1308 | * info to avoid foreach errors elsewhere in the code. |
| 1309 | 1309 | */ |
| 1310 | 1310 | function content_types($type_name = NULL) { |
| 1311 | - // handle type name with either an underscore or a dash |
|
| 1312 | - $type_name = !empty($type_name) ? str_replace('-', '_', $type_name) : NULL; |
|
| 1311 | + // handle type name with either an underscore or a dash |
|
| 1312 | + $type_name = !empty($type_name) ? str_replace('-', '_', $type_name) : NULL; |
|
| 1313 | 1313 | |
| 1314 | - $info = _content_type_info(); |
|
| 1315 | - if (isset($info['content types'])) { |
|
| 1314 | + $info = _content_type_info(); |
|
| 1315 | + if (isset($info['content types'])) { |
|
| 1316 | 1316 | if (!isset($type_name)) { |
| 1317 | - return $info['content types']; |
|
| 1317 | + return $info['content types']; |
|
| 1318 | 1318 | } |
| 1319 | 1319 | if (isset($info['content types'][$type_name])) { |
| 1320 | - return $info['content types'][$type_name]; |
|
| 1320 | + return $info['content types'][$type_name]; |
|
| 1321 | + } |
|
| 1321 | 1322 | } |
| 1322 | - } |
|
| 1323 | - return array('tables' => array(), 'fields' => array(), 'extra' => array()); |
|
| 1323 | + return array('tables' => array(), 'fields' => array(), 'extra' => array()); |
|
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | /** |
@@ -1337,36 +1337,36 @@ discard block |
||
| 1337 | 1337 | * but empty, as sometimes happens in the formatter. |
| 1338 | 1338 | */ |
| 1339 | 1339 | function content_fields($field_name = NULL, $content_type_name = NULL) { |
| 1340 | - $info = _content_type_info(); |
|
| 1341 | - if (isset($info['fields'])) { |
|
| 1340 | + $info = _content_type_info(); |
|
| 1341 | + if (isset($info['fields'])) { |
|
| 1342 | 1342 | if (empty($field_name)) { |
| 1343 | - return $info['fields']; |
|
| 1343 | + return $info['fields']; |
|
| 1344 | 1344 | } |
| 1345 | 1345 | if (isset($info['fields'][$field_name])) { |
| 1346 | - if (empty($content_type_name)) { |
|
| 1346 | + if (empty($content_type_name)) { |
|
| 1347 | 1347 | return $info['fields'][$field_name]; |
| 1348 | - } |
|
| 1349 | - if (isset($info['content types'][$content_type_name]['fields'][$field_name])) { |
|
| 1348 | + } |
|
| 1349 | + if (isset($info['content types'][$content_type_name]['fields'][$field_name])) { |
|
| 1350 | 1350 | return $info['content types'][$content_type_name]['fields'][$field_name]; |
| 1351 | - } |
|
| 1351 | + } |
|
| 1352 | + } |
|
| 1352 | 1353 | } |
| 1353 | - } |
|
| 1354 | 1354 | } |
| 1355 | 1355 | |
| 1356 | 1356 | /** |
| 1357 | 1357 | * Return a list of field types. |
| 1358 | 1358 | */ |
| 1359 | 1359 | function _content_field_types() { |
| 1360 | - $info = _content_type_info(); |
|
| 1361 | - return isset($info['field types']) ? $info['field types'] : array(); |
|
| 1360 | + $info = _content_type_info(); |
|
| 1361 | + return isset($info['field types']) ? $info['field types'] : array(); |
|
| 1362 | 1362 | } |
| 1363 | 1363 | |
| 1364 | 1364 | /** |
| 1365 | 1365 | * Return a list of widget types. |
| 1366 | 1366 | */ |
| 1367 | 1367 | function _content_widget_types() { |
| 1368 | - $info = _content_type_info(); |
|
| 1369 | - return isset($info['widget types']) ? $info['widget types'] : array(); |
|
| 1368 | + $info = _content_type_info(); |
|
| 1369 | + return isset($info['widget types']) ? $info['widget types'] : array(); |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | 1372 | /** |
@@ -1374,16 +1374,16 @@ discard block |
||
| 1374 | 1374 | * defaulting to 'default' if none is found. |
| 1375 | 1375 | */ |
| 1376 | 1376 | function _content_get_formatter($formatter_name, $field_type) { |
| 1377 | - $field_types = _content_field_types(); |
|
| 1378 | - $formatters = $field_types[$field_type]['formatters']; |
|
| 1377 | + $field_types = _content_field_types(); |
|
| 1378 | + $formatters = $field_types[$field_type]['formatters']; |
|
| 1379 | 1379 | |
| 1380 | - if (!isset($formatters[$formatter_name]) && $formatter_name != 'hidden') { |
|
| 1380 | + if (!isset($formatters[$formatter_name]) && $formatter_name != 'hidden') { |
|
| 1381 | 1381 | // This might happen when the selected formatter has been renamed in the |
| 1382 | 1382 | // module, or if the module has been disabled since then. |
| 1383 | 1383 | $formatter_name = 'default'; |
| 1384 | - } |
|
| 1384 | + } |
|
| 1385 | 1385 | |
| 1386 | - return isset($formatters[$formatter_name]) ? $formatters[$formatter_name] : FALSE; |
|
| 1386 | + return isset($formatters[$formatter_name]) ? $formatters[$formatter_name] : FALSE; |
|
| 1387 | 1387 | } |
| 1388 | 1388 | |
| 1389 | 1389 | /** |
@@ -1393,10 +1393,10 @@ discard block |
||
| 1393 | 1393 | * If TRUE, clear the cache and fetch the information from the database again. |
| 1394 | 1394 | */ |
| 1395 | 1395 | function _content_type_info($reset = FALSE) { |
| 1396 | - global $language; |
|
| 1397 | - static $info; |
|
| 1396 | + global $language; |
|
| 1397 | + static $info; |
|
| 1398 | 1398 | |
| 1399 | - if ($reset || !isset($info)) { |
|
| 1399 | + if ($reset || !isset($info)) { |
|
| 1400 | 1400 | // Make sure this function doesn't run until the tables have been created, |
| 1401 | 1401 | // For instance: when first enabled and called from content_menu(), |
| 1402 | 1402 | // or when uninstalled and some subsequent field module uninstall |
@@ -1405,38 +1405,38 @@ discard block |
||
| 1405 | 1405 | // Don't try this before content module's update is run |
| 1406 | 1406 | // to add module and active columns to the table. |
| 1407 | 1407 | if (variable_get('content_schema_version', -1) < 6007) { |
| 1408 | - return array(); |
|
| 1408 | + return array(); |
|
| 1409 | 1409 | } |
| 1410 | 1410 | |
| 1411 | 1411 | if (!$reset && $cached = cache_get('content_type_info:'. $language->language, content_cache_tablename())) { |
| 1412 | - $info = $cached->data; |
|
| 1412 | + $info = $cached->data; |
|
| 1413 | 1413 | } |
| 1414 | 1414 | else { |
| 1415 | - $info = array( |
|
| 1415 | + $info = array( |
|
| 1416 | 1416 | 'field types' => array(), |
| 1417 | 1417 | 'widget types' => array(), |
| 1418 | 1418 | 'fields' => array(), |
| 1419 | 1419 | 'content types' => array(), |
| 1420 | - ); |
|
| 1420 | + ); |
|
| 1421 | 1421 | |
| 1422 | - // Populate field types. |
|
| 1423 | - foreach (module_list() as $module) { |
|
| 1422 | + // Populate field types. |
|
| 1423 | + foreach (module_list() as $module) { |
|
| 1424 | 1424 | $module_field_types = module_invoke($module, 'field_info'); |
| 1425 | 1425 | if ($module_field_types) { |
| 1426 | - foreach ($module_field_types as $name => $field_info) { |
|
| 1426 | + foreach ($module_field_types as $name => $field_info) { |
|
| 1427 | 1427 | // Truncate names to match the value that is stored in the database. |
| 1428 | 1428 | $db_name = substr($name, 0, 32); |
| 1429 | 1429 | $info['field types'][$db_name] = $field_info; |
| 1430 | 1430 | $info['field types'][$db_name]['module'] = $module; |
| 1431 | 1431 | $info['field types'][$db_name]['formatters'] = array(); |
| 1432 | - } |
|
| 1432 | + } |
|
| 1433 | + } |
|
| 1433 | 1434 | } |
| 1434 | - } |
|
| 1435 | 1435 | |
| 1436 | - // Populate widget types and formatters for known field types. |
|
| 1437 | - foreach (module_list() as $module) { |
|
| 1436 | + // Populate widget types and formatters for known field types. |
|
| 1437 | + foreach (module_list() as $module) { |
|
| 1438 | 1438 | if ($module_widgets = module_invoke($module, 'widget_info')) { |
| 1439 | - foreach ($module_widgets as $name => $widget_info) { |
|
| 1439 | + foreach ($module_widgets as $name => $widget_info) { |
|
| 1440 | 1440 | // Truncate names to match the value that is stored in the database. |
| 1441 | 1441 | $db_name = substr($name, 0, 32); |
| 1442 | 1442 | $info['widget types'][$db_name] = $widget_info; |
@@ -1444,44 +1444,44 @@ discard block |
||
| 1444 | 1444 | // Replace field types with db_compatible version of known field types. |
| 1445 | 1445 | $info['widget types'][$db_name]['field types'] = array(); |
| 1446 | 1446 | foreach ($widget_info['field types'] as $field_type) { |
| 1447 | - $field_type_db_name = substr($field_type, 0, 32); |
|
| 1448 | - if (isset($info['field types'][$field_type_db_name])) { |
|
| 1447 | + $field_type_db_name = substr($field_type, 0, 32); |
|
| 1448 | + if (isset($info['field types'][$field_type_db_name])) { |
|
| 1449 | 1449 | $info['widget types'][$db_name]['field types'][] = $field_type_db_name; |
| 1450 | - } |
|
| 1450 | + } |
|
| 1451 | + } |
|
| 1451 | 1452 | } |
| 1452 | - } |
|
| 1453 | 1453 | } |
| 1454 | 1454 | |
| 1455 | 1455 | if ($module_formatters = module_invoke($module, 'field_formatter_info')) { |
| 1456 | - foreach ($module_formatters as $name => $formatter_info) { |
|
| 1456 | + foreach ($module_formatters as $name => $formatter_info) { |
|
| 1457 | 1457 | foreach ($formatter_info['field types'] as $field_type) { |
| 1458 | - // Truncate names to match the value that is stored in the database. |
|
| 1459 | - $db_name = substr($field_type, 0, 32); |
|
| 1460 | - if (isset($info['field types'][$db_name])) { |
|
| 1458 | + // Truncate names to match the value that is stored in the database. |
|
| 1459 | + $db_name = substr($field_type, 0, 32); |
|
| 1460 | + if (isset($info['field types'][$db_name])) { |
|
| 1461 | 1461 | $info['field types'][$db_name]['formatters'][$name] = $formatter_info; |
| 1462 | 1462 | $info['field types'][$db_name]['formatters'][$name]['module'] = $module; |
| 1463 | - } |
|
| 1463 | + } |
|
| 1464 | 1464 | } |
| 1465 | - } |
|
| 1465 | + } |
|
| 1466 | + } |
|
| 1466 | 1467 | } |
| 1467 | - } |
|
| 1468 | 1468 | |
| 1469 | - // Populate actual field instances. |
|
| 1470 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 1471 | - foreach (node_get_types('types', NULL, TRUE) as $type_name => $data) { |
|
| 1469 | + // Populate actual field instances. |
|
| 1470 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 1471 | + foreach (node_get_types('types', NULL, TRUE) as $type_name => $data) { |
|
| 1472 | 1472 | $type = (array) $data; |
| 1473 | 1473 | $type['url_str'] = str_replace('_', '-', $type['type']); |
| 1474 | 1474 | $type['fields'] = array(); |
| 1475 | 1475 | $type['tables'] = array(); |
| 1476 | 1476 | if ($fields = content_field_instance_read(array('type_name' => $type_name))) { |
| 1477 | - foreach ($fields as $field) { |
|
| 1477 | + foreach ($fields as $field) { |
|
| 1478 | 1478 | $db_info = content_database_info($field); |
| 1479 | 1479 | $type['tables'][$db_info['table']] = $db_info['table']; |
| 1480 | 1480 | |
| 1481 | 1481 | // Allow external modules to translate field strings. |
| 1482 | 1482 | $field_strings = array( |
| 1483 | - 'widget_label' => $field['widget']['label'], |
|
| 1484 | - 'widget_description' => $field['widget']['description'], |
|
| 1483 | + 'widget_label' => $field['widget']['label'], |
|
| 1484 | + 'widget_description' => $field['widget']['description'], |
|
| 1485 | 1485 | ); |
| 1486 | 1486 | drupal_alter('content_field_strings', $field_strings, $field['type_name'], $field['field_name']); |
| 1487 | 1487 | $field['widget']['label'] = $field_strings['widget_label']; |
@@ -1491,11 +1491,11 @@ discard block |
||
| 1491 | 1491 | // This means that content_fields($field_name) (no type name) |
| 1492 | 1492 | // returns the last instance loaded. |
| 1493 | 1493 | $info['fields'][$field['field_name']] = $field; |
| 1494 | - } |
|
| 1495 | - // Make sure the per-type table is added, even if no field is actually |
|
| 1496 | - // stored in it. |
|
| 1497 | - $table = _content_tablename($type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE); |
|
| 1498 | - $type['tables'][$table] = $table; |
|
| 1494 | + } |
|
| 1495 | + // Make sure the per-type table is added, even if no field is actually |
|
| 1496 | + // stored in it. |
|
| 1497 | + $table = _content_tablename($type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE); |
|
| 1498 | + $type['tables'][$table] = $table; |
|
| 1499 | 1499 | } |
| 1500 | 1500 | |
| 1501 | 1501 | // Gather information about non-CCK 'fields'. |
@@ -1503,21 +1503,21 @@ discard block |
||
| 1503 | 1503 | drupal_alter('content_extra_fields', $extra, $type_name); |
| 1504 | 1504 | // Add saved weights. |
| 1505 | 1505 | foreach (variable_get('content_extra_weights_'. $type_name, array()) as $key => $value) { |
| 1506 | - // Some stored entries might not exist anymore, for instance if uploads |
|
| 1507 | - // have been disabled, or vocabularies removed... |
|
| 1508 | - if (isset($extra[$key])) { |
|
| 1506 | + // Some stored entries might not exist anymore, for instance if uploads |
|
| 1507 | + // have been disabled, or vocabularies removed... |
|
| 1508 | + if (isset($extra[$key])) { |
|
| 1509 | 1509 | $extra[$key]['weight'] = $value; |
| 1510 | - } |
|
| 1510 | + } |
|
| 1511 | 1511 | } |
| 1512 | 1512 | $type['extra'] = $extra; |
| 1513 | 1513 | |
| 1514 | 1514 | $info['content types'][$type_name] = $type; |
| 1515 | - } |
|
| 1515 | + } |
|
| 1516 | 1516 | |
| 1517 | - cache_set('content_type_info:'. $language->language, $info, content_cache_tablename()); |
|
| 1517 | + cache_set('content_type_info:'. $language->language, $info, content_cache_tablename()); |
|
| 1518 | + } |
|
| 1518 | 1519 | } |
| 1519 | - } |
|
| 1520 | - return $info; |
|
| 1520 | + return $info; |
|
| 1521 | 1521 | } |
| 1522 | 1522 | |
| 1523 | 1523 | /** |
@@ -1525,20 +1525,20 @@ discard block |
||
| 1525 | 1525 | * React to change in node types |
| 1526 | 1526 | */ |
| 1527 | 1527 | function content_node_type($op, $info) { |
| 1528 | - switch ($op) { |
|
| 1528 | + switch ($op) { |
|
| 1529 | 1529 | case 'insert': |
| 1530 | 1530 | module_load_include('inc', 'content', 'includes/content.crud'); |
| 1531 | - content_type_create($info); |
|
| 1532 | - break; |
|
| 1531 | + content_type_create($info); |
|
| 1532 | + break; |
|
| 1533 | 1533 | case 'update': |
| 1534 | 1534 | module_load_include('inc', 'content', 'includes/content.crud'); |
| 1535 | - content_type_update($info); |
|
| 1536 | - break; |
|
| 1535 | + content_type_update($info); |
|
| 1536 | + break; |
|
| 1537 | 1537 | case 'delete': |
| 1538 | 1538 | module_load_include('inc', 'content', 'includes/content.crud'); |
| 1539 | - content_type_delete($info); |
|
| 1540 | - break; |
|
| 1541 | - } |
|
| 1539 | + content_type_delete($info); |
|
| 1540 | + break; |
|
| 1541 | + } |
|
| 1542 | 1542 | } |
| 1543 | 1543 | |
| 1544 | 1544 | /** |
@@ -1546,19 +1546,19 @@ discard block |
||
| 1546 | 1546 | * information is changed. |
| 1547 | 1547 | */ |
| 1548 | 1548 | function content_clear_type_cache($rebuild_schema = FALSE) { |
| 1549 | - cache_clear_all('*', content_cache_tablename(), TRUE); |
|
| 1550 | - _content_type_info(TRUE); |
|
| 1549 | + cache_clear_all('*', content_cache_tablename(), TRUE); |
|
| 1550 | + _content_type_info(TRUE); |
|
| 1551 | 1551 | |
| 1552 | - // Refresh the schema to pick up new information. |
|
| 1553 | - if ($rebuild_schema) { |
|
| 1552 | + // Refresh the schema to pick up new information. |
|
| 1553 | + if ($rebuild_schema) { |
|
| 1554 | 1554 | $schema = drupal_get_schema(NULL, TRUE); |
| 1555 | - } |
|
| 1555 | + } |
|
| 1556 | 1556 | |
| 1557 | - if (module_exists('views')) { |
|
| 1557 | + if (module_exists('views')) { |
|
| 1558 | 1558 | // Needed because this can be called from .install files |
| 1559 | 1559 | module_load_include('module', 'views'); |
| 1560 | 1560 | views_invalidate_cache(); |
| 1561 | - } |
|
| 1561 | + } |
|
| 1562 | 1562 | } |
| 1563 | 1563 | |
| 1564 | 1564 | /** |
@@ -1577,38 +1577,38 @@ discard block |
||
| 1577 | 1577 | * database column that stores the data. |
| 1578 | 1578 | */ |
| 1579 | 1579 | function content_database_info($field) { |
| 1580 | - $db_info = array(); |
|
| 1581 | - if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
|
| 1580 | + $db_info = array(); |
|
| 1581 | + if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
|
| 1582 | 1582 | $db_info['table'] = _content_tablename($field['field_name'], CONTENT_DB_STORAGE_PER_FIELD); |
| 1583 | - } |
|
| 1584 | - else { |
|
| 1583 | + } |
|
| 1584 | + else { |
|
| 1585 | 1585 | $db_info['table'] = _content_tablename($field['type_name'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE); |
| 1586 | - } |
|
| 1586 | + } |
|
| 1587 | 1587 | |
| 1588 | - $db_info['columns'] = (array) $field['columns']; |
|
| 1589 | - // Generate column names for this field from generic column names. |
|
| 1590 | - foreach ($db_info['columns'] as $column_name => $attributes) { |
|
| 1588 | + $db_info['columns'] = (array) $field['columns']; |
|
| 1589 | + // Generate column names for this field from generic column names. |
|
| 1590 | + foreach ($db_info['columns'] as $column_name => $attributes) { |
|
| 1591 | 1591 | $db_info['columns'][$column_name]['column'] = $field['field_name'] .'_'. $column_name; |
| 1592 | - } |
|
| 1592 | + } |
|
| 1593 | 1593 | |
| 1594 | - return $db_info; |
|
| 1594 | + return $db_info; |
|
| 1595 | 1595 | } |
| 1596 | 1596 | |
| 1597 | 1597 | /** |
| 1598 | 1598 | * Helper function for identifying the storage type for a field. |
| 1599 | 1599 | */ |
| 1600 | 1600 | function content_storage_type($field) { |
| 1601 | - if ($field['multiple'] > 0) { |
|
| 1601 | + if ($field['multiple'] > 0) { |
|
| 1602 | 1602 | return CONTENT_DB_STORAGE_PER_FIELD; |
| 1603 | - } |
|
| 1604 | - else { |
|
| 1603 | + } |
|
| 1604 | + else { |
|
| 1605 | 1605 | module_load_include('inc', 'content', 'includes/content.crud'); |
| 1606 | 1606 | $instances = content_field_instance_read(array('field_name' => $field['field_name'])); |
| 1607 | 1607 | if (count($instances) > 1) { |
| 1608 | - return CONTENT_DB_STORAGE_PER_FIELD; |
|
| 1608 | + return CONTENT_DB_STORAGE_PER_FIELD; |
|
| 1609 | + } |
|
| 1609 | 1610 | } |
| 1610 | - } |
|
| 1611 | - return CONTENT_DB_STORAGE_PER_CONTENT_TYPE; |
|
| 1611 | + return CONTENT_DB_STORAGE_PER_CONTENT_TYPE; |
|
| 1612 | 1612 | } |
| 1613 | 1613 | |
| 1614 | 1614 | /** |
@@ -1625,20 +1625,20 @@ discard block |
||
| 1625 | 1625 | * The transposed array. |
| 1626 | 1626 | */ |
| 1627 | 1627 | function content_transpose_array_rows_cols($array) { |
| 1628 | - $result = array(); |
|
| 1629 | - if (is_array($array)) { |
|
| 1628 | + $result = array(); |
|
| 1629 | + if (is_array($array)) { |
|
| 1630 | 1630 | foreach ($array as $key1 => $value1) { |
| 1631 | - if (is_array($value1)) { |
|
| 1631 | + if (is_array($value1)) { |
|
| 1632 | 1632 | foreach ($value1 as $key2 => $value2) { |
| 1633 | - if (!isset($result[$key2])) { |
|
| 1633 | + if (!isset($result[$key2])) { |
|
| 1634 | 1634 | $result[$key2] = array(); |
| 1635 | - } |
|
| 1636 | - $result[$key2][$key1] = $value2; |
|
| 1635 | + } |
|
| 1636 | + $result[$key2][$key1] = $value2; |
|
| 1637 | 1637 | } |
| 1638 | - } |
|
| 1638 | + } |
|
| 1639 | + } |
|
| 1639 | 1640 | } |
| 1640 | - } |
|
| 1641 | - return $result; |
|
| 1641 | + return $result; |
|
| 1642 | 1642 | } |
| 1643 | 1643 | |
| 1644 | 1644 | /** |
@@ -1650,18 +1650,18 @@ discard block |
||
| 1650 | 1650 | * A flattened array. |
| 1651 | 1651 | */ |
| 1652 | 1652 | function content_array_flatten($array) { |
| 1653 | - $result = array(); |
|
| 1654 | - if (is_array($array)) { |
|
| 1653 | + $result = array(); |
|
| 1654 | + if (is_array($array)) { |
|
| 1655 | 1655 | foreach ($array as $key => $value) { |
| 1656 | - if (is_array($value)) { |
|
| 1656 | + if (is_array($value)) { |
|
| 1657 | 1657 | $result += content_array_flatten($value); |
| 1658 | - } |
|
| 1659 | - else { |
|
| 1658 | + } |
|
| 1659 | + else { |
|
| 1660 | 1660 | $result[$key] = $value; |
| 1661 | - } |
|
| 1661 | + } |
|
| 1662 | + } |
|
| 1662 | 1663 | } |
| 1663 | - } |
|
| 1664 | - return $result; |
|
| 1664 | + return $result; |
|
| 1665 | 1665 | } |
| 1666 | 1666 | |
| 1667 | 1667 | /** |
@@ -1680,46 +1680,46 @@ discard block |
||
| 1680 | 1680 | * when allowed values list is generated using PHP code. |
| 1681 | 1681 | */ |
| 1682 | 1682 | function content_allowed_values($field, $flatten = TRUE) { |
| 1683 | - static $allowed_values; |
|
| 1683 | + static $allowed_values; |
|
| 1684 | 1684 | |
| 1685 | - $cid = $field['field_name'] .':'. ($flatten ? '1' : '0'); |
|
| 1686 | - if (isset($allowed_values[$cid])) { |
|
| 1685 | + $cid = $field['field_name'] .':'. ($flatten ? '1' : '0'); |
|
| 1686 | + if (isset($allowed_values[$cid])) { |
|
| 1687 | 1687 | return $allowed_values[$cid]; |
| 1688 | - } |
|
| 1688 | + } |
|
| 1689 | 1689 | |
| 1690 | - $allowed_values[$cid] = array(); |
|
| 1690 | + $allowed_values[$cid] = array(); |
|
| 1691 | 1691 | |
| 1692 | - if (isset($field['allowed_values_php'])) { |
|
| 1692 | + if (isset($field['allowed_values_php'])) { |
|
| 1693 | 1693 | ob_start(); |
| 1694 | 1694 | $result = eval($field['allowed_values_php']); |
| 1695 | 1695 | if (is_array($result)) { |
| 1696 | - if ($flatten) { |
|
| 1696 | + if ($flatten) { |
|
| 1697 | 1697 | $result = content_array_flatten($result); |
| 1698 | - } |
|
| 1699 | - $allowed_values[$cid] = $result; |
|
| 1698 | + } |
|
| 1699 | + $allowed_values[$cid] = $result; |
|
| 1700 | 1700 | } |
| 1701 | 1701 | ob_end_clean(); |
| 1702 | - } |
|
| 1702 | + } |
|
| 1703 | 1703 | |
| 1704 | - if (empty($allowed_values[$cid]) && isset($field['allowed_values'])) { |
|
| 1704 | + if (empty($allowed_values[$cid]) && isset($field['allowed_values'])) { |
|
| 1705 | 1705 | $list = explode("\n", $field['allowed_values']); |
| 1706 | 1706 | $list = array_map('trim', $list); |
| 1707 | 1707 | $list = array_filter($list, 'strlen'); |
| 1708 | 1708 | foreach ($list as $opt) { |
| 1709 | - // Sanitize the user input with a permissive filter. |
|
| 1710 | - $opt = content_filter_xss($opt); |
|
| 1711 | - if (strpos($opt, '|') !== FALSE) { |
|
| 1709 | + // Sanitize the user input with a permissive filter. |
|
| 1710 | + $opt = content_filter_xss($opt); |
|
| 1711 | + if (strpos($opt, '|') !== FALSE) { |
|
| 1712 | 1712 | list($key, $value) = explode('|', $opt); |
| 1713 | 1713 | $allowed_values[$cid][$key] = (isset($value) && $value !=='') ? $value : $key; |
| 1714 | - } |
|
| 1715 | - else { |
|
| 1714 | + } |
|
| 1715 | + else { |
|
| 1716 | 1716 | $allowed_values[$cid][$opt] = $opt; |
| 1717 | - } |
|
| 1717 | + } |
|
| 1718 | 1718 | } |
| 1719 | 1719 | // Allow external modules to translate allowed values list. |
| 1720 | 1720 | drupal_alter('content_allowed_values', $allowed_values[$cid], $field); |
| 1721 | - } |
|
| 1722 | - return $allowed_values[$cid]; |
|
| 1721 | + } |
|
| 1722 | + return $allowed_values[$cid]; |
|
| 1723 | 1723 | } |
| 1724 | 1724 | |
| 1725 | 1725 | /** |
@@ -1730,14 +1730,14 @@ discard block |
||
| 1730 | 1730 | * @see content_handler_filter_many_to_one::allowed_values() |
| 1731 | 1731 | */ |
| 1732 | 1732 | function content_allowed_values_filter_html(&$options) { |
| 1733 | - foreach ($options as $key => $opt) { |
|
| 1733 | + foreach ($options as $key => $opt) { |
|
| 1734 | 1734 | if (is_array($opt)) { |
| 1735 | - content_allowed_values_filter_html($options[$key]); |
|
| 1735 | + content_allowed_values_filter_html($options[$key]); |
|
| 1736 | 1736 | } |
| 1737 | 1737 | else { |
| 1738 | - $options[$key] = html_entity_decode(strip_tags($opt), ENT_QUOTES); |
|
| 1738 | + $options[$key] = html_entity_decode(strip_tags($opt), ENT_QUOTES); |
|
| 1739 | + } |
|
| 1739 | 1740 | } |
| 1740 | - } |
|
| 1741 | 1741 | } |
| 1742 | 1742 | |
| 1743 | 1743 | /** |
@@ -1748,21 +1748,21 @@ discard block |
||
| 1748 | 1748 | * (so check_plain() is not acceptable). |
| 1749 | 1749 | */ |
| 1750 | 1750 | function content_filter_xss($string) { |
| 1751 | - return filter_xss($string, _content_filter_xss_allowed_tags()); |
|
| 1751 | + return filter_xss($string, _content_filter_xss_allowed_tags()); |
|
| 1752 | 1752 | } |
| 1753 | 1753 | |
| 1754 | 1754 | /** |
| 1755 | 1755 | * List of tags allowed by content_filter_xss(). |
| 1756 | 1756 | */ |
| 1757 | 1757 | function _content_filter_xss_allowed_tags() { |
| 1758 | - return array('a', 'b', 'big', 'code', 'del', 'em', 'i', 'ins', 'pre', 'q', 'small', 'span', 'strong', 'sub', 'sup', 'tt', 'ol', 'ul', 'li', 'p', 'br', 'img'); |
|
| 1758 | + return array('a', 'b', 'big', 'code', 'del', 'em', 'i', 'ins', 'pre', 'q', 'small', 'span', 'strong', 'sub', 'sup', 'tt', 'ol', 'ul', 'li', 'p', 'br', 'img'); |
|
| 1759 | 1759 | } |
| 1760 | 1760 | |
| 1761 | 1761 | /** |
| 1762 | 1762 | * Human-readable list of allowed tags, for display in help texts. |
| 1763 | 1763 | */ |
| 1764 | 1764 | function _content_filter_xss_display_allowed_tags() { |
| 1765 | - return '<'. implode('> <', _content_filter_xss_allowed_tags()) .'>'; |
|
| 1765 | + return '<'. implode('> <', _content_filter_xss_allowed_tags()) .'>'; |
|
| 1766 | 1766 | } |
| 1767 | 1767 | |
| 1768 | 1768 | /** |
@@ -1790,52 +1790,52 @@ discard block |
||
| 1790 | 1790 | * functions as necessary. |
| 1791 | 1791 | */ |
| 1792 | 1792 | function content_format($field, $item, $formatter_name = 'default', $node = NULL) { |
| 1793 | - if (!is_array($field)) { |
|
| 1793 | + if (!is_array($field)) { |
|
| 1794 | 1794 | $field = content_fields($field); |
| 1795 | - } |
|
| 1795 | + } |
|
| 1796 | 1796 | |
| 1797 | - if (content_access('view', $field, NULL, $node) && $formatter = _content_get_formatter($formatter_name, $field['type'])) { |
|
| 1797 | + if (content_access('view', $field, NULL, $node) && $formatter = _content_get_formatter($formatter_name, $field['type'])) { |
|
| 1798 | 1798 | $theme = $formatter['module'] .'_formatter_'. $formatter_name; |
| 1799 | 1799 | |
| 1800 | 1800 | $element = array( |
| 1801 | - '#theme' => $theme, |
|
| 1802 | - '#field_name' => $field['field_name'], |
|
| 1803 | - '#type_name' => isset($node->type) ? $node->type :'', |
|
| 1804 | - '#formatter' => $formatter_name, |
|
| 1805 | - '#node' => $node, |
|
| 1806 | - '#delta' => isset($item['#delta']) ? $item['#delta'] : NULL, |
|
| 1801 | + '#theme' => $theme, |
|
| 1802 | + '#field_name' => $field['field_name'], |
|
| 1803 | + '#type_name' => isset($node->type) ? $node->type :'', |
|
| 1804 | + '#formatter' => $formatter_name, |
|
| 1805 | + '#node' => $node, |
|
| 1806 | + '#delta' => isset($item['#delta']) ? $item['#delta'] : NULL, |
|
| 1807 | 1807 | ); |
| 1808 | 1808 | |
| 1809 | 1809 | if (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE) { |
| 1810 | - // Single value formatter. |
|
| 1810 | + // Single value formatter. |
|
| 1811 | 1811 | |
| 1812 | - // hook_field('sanitize') expects an array of items, so we build one. |
|
| 1813 | - $items = array($item); |
|
| 1814 | - $function = $field['module'] .'_field'; |
|
| 1815 | - if (function_exists($function)) { |
|
| 1812 | + // hook_field('sanitize') expects an array of items, so we build one. |
|
| 1813 | + $items = array($item); |
|
| 1814 | + $function = $field['module'] .'_field'; |
|
| 1815 | + if (function_exists($function)) { |
|
| 1816 | 1816 | $function('sanitize', $node, $field, $items, FALSE, FALSE); |
| 1817 | - } |
|
| 1817 | + } |
|
| 1818 | 1818 | |
| 1819 | - $element['#item'] = $items[0]; |
|
| 1819 | + $element['#item'] = $items[0]; |
|
| 1820 | 1820 | } |
| 1821 | 1821 | else { |
| 1822 | - // Multiple values formatter. |
|
| 1823 | - $items = $item; |
|
| 1824 | - $function = $field['module'] .'_field'; |
|
| 1825 | - if (function_exists($function)) { |
|
| 1822 | + // Multiple values formatter. |
|
| 1823 | + $items = $item; |
|
| 1824 | + $function = $field['module'] .'_field'; |
|
| 1825 | + if (function_exists($function)) { |
|
| 1826 | 1826 | $function('sanitize', $node, $field, $items, FALSE, FALSE); |
| 1827 | - } |
|
| 1827 | + } |
|
| 1828 | 1828 | |
| 1829 | - foreach ($items as $delta => $item) { |
|
| 1829 | + foreach ($items as $delta => $item) { |
|
| 1830 | 1830 | $element[$delta] = array( |
| 1831 | - '#item' => $item, |
|
| 1832 | - '#weight' => $delta, |
|
| 1831 | + '#item' => $item, |
|
| 1832 | + '#weight' => $delta, |
|
| 1833 | 1833 | ); |
| 1834 | - } |
|
| 1834 | + } |
|
| 1835 | 1835 | } |
| 1836 | 1836 | |
| 1837 | 1837 | return theme($theme, $element); |
| 1838 | - } |
|
| 1838 | + } |
|
| 1839 | 1839 | } |
| 1840 | 1840 | |
| 1841 | 1841 | /** |
@@ -1851,31 +1851,31 @@ discard block |
||
| 1851 | 1851 | * - a string tab id: the build modes in this tab. |
| 1852 | 1852 | */ |
| 1853 | 1853 | function content_build_modes($selector = NULL) { |
| 1854 | - static $info; |
|
| 1854 | + static $info; |
|
| 1855 | 1855 | |
| 1856 | - if (!isset($info)) { |
|
| 1856 | + if (!isset($info)) { |
|
| 1857 | 1857 | $data = array(); |
| 1858 | 1858 | foreach (module_implements('content_build_modes') as $module) { |
| 1859 | - $function = $module .'_content_build_modes'; |
|
| 1860 | - $data = array_merge($data, (array) $function()); |
|
| 1859 | + $function = $module .'_content_build_modes'; |
|
| 1860 | + $data = array_merge($data, (array) $function()); |
|
| 1861 | 1861 | } |
| 1862 | 1862 | $flat = array(); |
| 1863 | 1863 | foreach ($data as $tab) { |
| 1864 | - // Use the + operator to preserve numeric indexes (core build modes). |
|
| 1865 | - $flat += (array) $tab['build modes']; |
|
| 1864 | + // Use the + operator to preserve numeric indexes (core build modes). |
|
| 1865 | + $flat += (array) $tab['build modes']; |
|
| 1866 | 1866 | } |
| 1867 | 1867 | $info = array('tabs' => $data, 'build modes' => $flat); |
| 1868 | - } |
|
| 1868 | + } |
|
| 1869 | 1869 | |
| 1870 | - if ($selector === '_tabs') { |
|
| 1870 | + if ($selector === '_tabs') { |
|
| 1871 | 1871 | return $info['tabs']; |
| 1872 | - } |
|
| 1873 | - elseif (isset($selector) && isset($info['tabs'][$selector])) { |
|
| 1872 | + } |
|
| 1873 | + elseif (isset($selector) && isset($info['tabs'][$selector])) { |
|
| 1874 | 1874 | return isset($info['tabs'][$selector]) ? $info['tabs'][$selector]['build modes'] : array(); |
| 1875 | - } |
|
| 1876 | - else { |
|
| 1875 | + } |
|
| 1876 | + else { |
|
| 1877 | 1877 | return $info['build modes']; |
| 1878 | - } |
|
| 1878 | + } |
|
| 1879 | 1879 | } |
| 1880 | 1880 | |
| 1881 | 1881 | /** |
@@ -1914,60 +1914,60 @@ discard block |
||
| 1914 | 1914 | * ); |
| 1915 | 1915 | */ |
| 1916 | 1916 | function node_content_build_modes() { |
| 1917 | - return array( |
|
| 1917 | + return array( |
|
| 1918 | 1918 | 'basic' => array( |
| 1919 | - 'title' => t('Basic'), |
|
| 1920 | - 'build modes' => array( |
|
| 1919 | + 'title' => t('Basic'), |
|
| 1920 | + 'build modes' => array( |
|
| 1921 | 1921 | 'teaser' => array( |
| 1922 | - 'title' => t('Teaser'), |
|
| 1923 | - 'views style' => TRUE, |
|
| 1922 | + 'title' => t('Teaser'), |
|
| 1923 | + 'views style' => TRUE, |
|
| 1924 | 1924 | ), |
| 1925 | 1925 | 'full' => array( |
| 1926 | - 'title' => t('Full node'), |
|
| 1927 | - 'views style' => TRUE, |
|
| 1926 | + 'title' => t('Full node'), |
|
| 1927 | + 'views style' => TRUE, |
|
| 1928 | + ), |
|
| 1928 | 1929 | ), |
| 1929 | - ), |
|
| 1930 | 1930 | ), |
| 1931 | 1931 | 'rss' => array( |
| 1932 | - 'title' => t('RSS'), |
|
| 1933 | - 'build modes' => array( |
|
| 1932 | + 'title' => t('RSS'), |
|
| 1933 | + 'build modes' => array( |
|
| 1934 | 1934 | NODE_BUILD_RSS => array( |
| 1935 | - 'title' => t('RSS'), |
|
| 1936 | - 'views style' => FALSE, |
|
| 1935 | + 'title' => t('RSS'), |
|
| 1936 | + 'views style' => FALSE, |
|
| 1937 | + ), |
|
| 1937 | 1938 | ), |
| 1938 | - ), |
|
| 1939 | 1939 | ), |
| 1940 | - ); |
|
| 1940 | + ); |
|
| 1941 | 1941 | } |
| 1942 | 1942 | function search_content_build_modes() { |
| 1943 | - return array( |
|
| 1943 | + return array( |
|
| 1944 | 1944 | 'search' => array( |
| 1945 | - 'title' => t('Search'), |
|
| 1946 | - 'build modes' => array( |
|
| 1945 | + 'title' => t('Search'), |
|
| 1946 | + 'build modes' => array( |
|
| 1947 | 1947 | NODE_BUILD_SEARCH_INDEX => array( |
| 1948 | - 'title' => t('Search Index'), |
|
| 1949 | - 'views style' => FALSE, |
|
| 1948 | + 'title' => t('Search Index'), |
|
| 1949 | + 'views style' => FALSE, |
|
| 1950 | 1950 | ), |
| 1951 | 1951 | NODE_BUILD_SEARCH_RESULT => array( |
| 1952 | - 'title' => t('Search Result'), |
|
| 1953 | - 'views style' => FALSE, |
|
| 1952 | + 'title' => t('Search Result'), |
|
| 1953 | + 'views style' => FALSE, |
|
| 1954 | + ), |
|
| 1954 | 1955 | ), |
| 1955 | - ), |
|
| 1956 | 1956 | ), |
| 1957 | - ); |
|
| 1957 | + ); |
|
| 1958 | 1958 | } |
| 1959 | 1959 | function book_content_build_modes() { |
| 1960 | - return array( |
|
| 1960 | + return array( |
|
| 1961 | 1961 | 'print' => array( |
| 1962 | - 'title' => t('Print'), |
|
| 1963 | - 'build modes' => array( |
|
| 1962 | + 'title' => t('Print'), |
|
| 1963 | + 'build modes' => array( |
|
| 1964 | 1964 | NODE_BUILD_PRINT => array( |
| 1965 | - 'title' => t('Print'), |
|
| 1966 | - 'views style' => TRUE, |
|
| 1965 | + 'title' => t('Print'), |
|
| 1966 | + 'views style' => TRUE, |
|
| 1967 | + ), |
|
| 1967 | 1968 | ), |
| 1968 | - ), |
|
| 1969 | 1969 | ), |
| 1970 | - ); |
|
| 1970 | + ); |
|
| 1971 | 1971 | } |
| 1972 | 1972 | |
| 1973 | 1973 | /** |
@@ -1981,19 +1981,19 @@ discard block |
||
| 1981 | 1981 | * A string containing the generated name for the database table |
| 1982 | 1982 | */ |
| 1983 | 1983 | function _content_tablename($name, $storage, $version = NULL) { |
| 1984 | - if (is_null($version)) { |
|
| 1984 | + if (is_null($version)) { |
|
| 1985 | 1985 | $version = variable_get('content_schema_version', 0); |
| 1986 | - } |
|
| 1986 | + } |
|
| 1987 | 1987 | |
| 1988 | - if ($version < 1003) { |
|
| 1988 | + if ($version < 1003) { |
|
| 1989 | 1989 | $version = 0; |
| 1990 | - } |
|
| 1991 | - else { |
|
| 1990 | + } |
|
| 1991 | + else { |
|
| 1992 | 1992 | $version = 1003; |
| 1993 | - } |
|
| 1993 | + } |
|
| 1994 | 1994 | |
| 1995 | - $name = str_replace('-', '_', $name); |
|
| 1996 | - switch ("$version-$storage") { |
|
| 1995 | + $name = str_replace('-', '_', $name); |
|
| 1996 | + switch ("$version-$storage") { |
|
| 1997 | 1997 | case '0-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
| 1998 | 1998 | return "node_$name"; |
| 1999 | 1999 | case '0-'. CONTENT_DB_STORAGE_PER_FIELD : |
@@ -2002,7 +2002,7 @@ discard block |
||
| 2002 | 2002 | return "content_type_$name"; |
| 2003 | 2003 | case '1003-'. CONTENT_DB_STORAGE_PER_FIELD : |
| 2004 | 2004 | return "content_$name"; |
| 2005 | - } |
|
| 2005 | + } |
|
| 2006 | 2006 | } |
| 2007 | 2007 | |
| 2008 | 2008 | /** |
@@ -2014,10 +2014,10 @@ discard block |
||
| 2014 | 2014 | * with 'content_field'. |
| 2015 | 2015 | */ |
| 2016 | 2016 | function content_field_tablename($version = NULL) { |
| 2017 | - if (is_null($version)) { |
|
| 2017 | + if (is_null($version)) { |
|
| 2018 | 2018 | $version = variable_get('content_schema_version', 0); |
| 2019 | - } |
|
| 2020 | - return $version < 6001 ? 'node_field' : 'content_node_field'; |
|
| 2019 | + } |
|
| 2020 | + return $version < 6001 ? 'node_field' : 'content_node_field'; |
|
| 2021 | 2021 | } |
| 2022 | 2022 | |
| 2023 | 2023 | /** |
@@ -2026,10 +2026,10 @@ discard block |
||
| 2026 | 2026 | * Needed because the table name changes depending on version. |
| 2027 | 2027 | */ |
| 2028 | 2028 | function content_instance_tablename($version = NULL) { |
| 2029 | - if (is_null($version)) { |
|
| 2029 | + if (is_null($version)) { |
|
| 2030 | 2030 | $version = variable_get('content_schema_version', 0); |
| 2031 | - } |
|
| 2032 | - return $version < 6001 ? 'node_field_instance' : 'content_node_field_instance'; |
|
| 2031 | + } |
|
| 2032 | + return $version < 6001 ? 'node_field_instance' : 'content_node_field_instance'; |
|
| 2033 | 2033 | } |
| 2034 | 2034 | |
| 2035 | 2035 | /** |
@@ -2040,12 +2040,12 @@ discard block |
||
| 2040 | 2040 | * update 6000 runs, so the cache table will be used instead. |
| 2041 | 2041 | */ |
| 2042 | 2042 | function content_cache_tablename() { |
| 2043 | - if (variable_get('content_schema_version', -1) < 6000) { |
|
| 2043 | + if (variable_get('content_schema_version', -1) < 6000) { |
|
| 2044 | 2044 | return 'cache'; |
| 2045 | - } |
|
| 2046 | - else { |
|
| 2045 | + } |
|
| 2046 | + else { |
|
| 2047 | 2047 | return 'cache_content'; |
| 2048 | - } |
|
| 2048 | + } |
|
| 2049 | 2049 | } |
| 2050 | 2050 | |
| 2051 | 2051 | /** |
@@ -2056,45 +2056,45 @@ discard block |
||
| 2056 | 2056 | * otherwise the function will return the whole thing. |
| 2057 | 2057 | */ |
| 2058 | 2058 | function content_table_schema($field = NULL) { |
| 2059 | - $schema = array( |
|
| 2059 | + $schema = array( |
|
| 2060 | 2060 | 'fields' => array( |
| 2061 | - 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
|
| 2062 | - 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) |
|
| 2061 | + 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
|
| 2062 | + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) |
|
| 2063 | 2063 | ), |
| 2064 | 2064 | 'primary key' => array('vid'), |
| 2065 | 2065 | 'indexes' => array( |
| 2066 | - 'nid' => array('nid'), |
|
| 2066 | + 'nid' => array('nid'), |
|
| 2067 | 2067 | ), |
| 2068 | - ); |
|
| 2068 | + ); |
|
| 2069 | 2069 | |
| 2070 | - // Add delta column if needed. |
|
| 2071 | - if (!empty($field['multiple'])) { |
|
| 2070 | + // Add delta column if needed. |
|
| 2071 | + if (!empty($field['multiple'])) { |
|
| 2072 | 2072 | $schema['fields']['delta'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0); |
| 2073 | 2073 | $schema['primary key'][] = 'delta'; |
| 2074 | - } |
|
| 2075 | - $schema['content fields'] = array(); |
|
| 2074 | + } |
|
| 2075 | + $schema['content fields'] = array(); |
|
| 2076 | 2076 | |
| 2077 | - // Add field columns column if needed. |
|
| 2078 | - // This function is called from install files where it is not safe |
|
| 2079 | - // to use content_fields() or content_database_info(), so we |
|
| 2080 | - // just used the column values stored in the $field. |
|
| 2081 | - // We also need the schema to include fields from disabled modules |
|
| 2082 | - // or there will be no way to delete those fields. |
|
| 2077 | + // Add field columns column if needed. |
|
| 2078 | + // This function is called from install files where it is not safe |
|
| 2079 | + // to use content_fields() or content_database_info(), so we |
|
| 2080 | + // just used the column values stored in the $field. |
|
| 2081 | + // We also need the schema to include fields from disabled modules |
|
| 2082 | + // or there will be no way to delete those fields. |
|
| 2083 | 2083 | |
| 2084 | - if (!empty($field['columns'])) { |
|
| 2084 | + if (!empty($field['columns'])) { |
|
| 2085 | 2085 | foreach ($field['columns'] as $column => $attributes) { |
| 2086 | - $column_name = $field['field_name'] .'_'. $column; |
|
| 2087 | - if (isset($attributes['index']) && $attributes['index']) { |
|
| 2086 | + $column_name = $field['field_name'] .'_'. $column; |
|
| 2087 | + if (isset($attributes['index']) && $attributes['index']) { |
|
| 2088 | 2088 | $schema['indexes'][$column_name] = array($column_name); |
| 2089 | 2089 | unset($attributes['index']); |
| 2090 | - } |
|
| 2091 | - unset($attributes['column']); |
|
| 2092 | - unset($attributes['sortable']); |
|
| 2093 | - $schema['fields'][$column_name] = $attributes; |
|
| 2090 | + } |
|
| 2091 | + unset($attributes['column']); |
|
| 2092 | + unset($attributes['sortable']); |
|
| 2093 | + $schema['fields'][$column_name] = $attributes; |
|
| 2094 | 2094 | } |
| 2095 | 2095 | $schema['content fields'][] = $field['field_name']; |
| 2096 | - } |
|
| 2097 | - return $schema; |
|
| 2096 | + } |
|
| 2097 | + return $schema; |
|
| 2098 | 2098 | } |
| 2099 | 2099 | |
| 2100 | 2100 | /** |
@@ -2112,26 +2112,26 @@ discard block |
||
| 2112 | 2112 | * TRUE if the table exists. Otherwise FALSE. |
| 2113 | 2113 | */ |
| 2114 | 2114 | function content_db_index_exists($table, $name) { |
| 2115 | - global $db_type; |
|
| 2116 | - if ($db_type == 'mysql' || $db_type == 'mysqli') { |
|
| 2115 | + global $db_type; |
|
| 2116 | + if ($db_type == 'mysql' || $db_type == 'mysqli') { |
|
| 2117 | 2117 | if (version_compare(db_version(), '5.0.3') < 0) { |
| 2118 | - // Earlier versions of MySQL don't support a WHERE clause for SHOW. |
|
| 2119 | - $result = db_query('SHOW INDEX FROM {'. $table .'}'); |
|
| 2120 | - while ($row = db_fetch_array($result)) { |
|
| 2118 | + // Earlier versions of MySQL don't support a WHERE clause for SHOW. |
|
| 2119 | + $result = db_query('SHOW INDEX FROM {'. $table .'}'); |
|
| 2120 | + while ($row = db_fetch_array($result)) { |
|
| 2121 | 2121 | if ($row['Key_name'] == $name) { |
| 2122 | - return TRUE; |
|
| 2122 | + return TRUE; |
|
| 2123 | + } |
|
| 2123 | 2124 | } |
| 2124 | - } |
|
| 2125 | - return FALSE; |
|
| 2125 | + return FALSE; |
|
| 2126 | 2126 | } |
| 2127 | 2127 | return (bool)db_result(db_query("SHOW INDEX FROM {". $table ."} WHERE key_name = '$name'")); |
| 2128 | - } |
|
| 2129 | - elseif ($db_type == 'pgsql') { |
|
| 2128 | + } |
|
| 2129 | + elseif ($db_type == 'pgsql') { |
|
| 2130 | 2130 | // Note that the index names in Schema API for PostgreSQL are prefixed by |
| 2131 | 2131 | // the table name and suffixed by '_idx'. |
| 2132 | 2132 | return (bool)db_result(db_query("SELECT COUNT(indexname) FROM pg_indexes WHERE indexname = '{". $table ."}_{$name}_idx'")); |
| 2133 | - } |
|
| 2134 | - return FALSE; |
|
| 2133 | + } |
|
| 2134 | + return FALSE; |
|
| 2135 | 2135 | } |
| 2136 | 2136 | |
| 2137 | 2137 | /** |
@@ -2152,15 +2152,15 @@ discard block |
||
| 2152 | 2152 | * |
| 2153 | 2153 | */ |
| 2154 | 2154 | function content_callback($entity, $op, $field) { |
| 2155 | - switch ($entity) { |
|
| 2155 | + switch ($entity) { |
|
| 2156 | 2156 | case 'field': |
| 2157 | 2157 | $info = module_invoke($field['module'], "field_info"); |
| 2158 | - return isset($info[$field['type']]['callbacks'][$op]) ? $info[$field['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
| 2158 | + return isset($info[$field['type']]['callbacks'][$op]) ? $info[$field['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
| 2159 | 2159 | |
| 2160 | 2160 | case 'widget': |
| 2161 | 2161 | $info = module_invoke($field['widget']['module'], "widget_info"); |
| 2162 | - return isset($info[$field['widget']['type']]['callbacks'][$op]) ? $info[$field['widget']['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
| 2163 | - } |
|
| 2162 | + return isset($info[$field['widget']['type']]['callbacks'][$op]) ? $info[$field['widget']['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
| 2163 | + } |
|
| 2164 | 2164 | } |
| 2165 | 2165 | |
| 2166 | 2166 | /** |
@@ -2182,20 +2182,20 @@ discard block |
||
| 2182 | 2182 | * CONTENT_HANDLE_MODULE - the implementing module handles this operation. |
| 2183 | 2183 | */ |
| 2184 | 2184 | function content_handle($entity, $op, $object) { |
| 2185 | - switch ($entity) { |
|
| 2185 | + switch ($entity) { |
|
| 2186 | 2186 | case 'field': |
| 2187 | 2187 | $info = module_invoke($object['module'], "field_info"); |
| 2188 | - return isset($info[$object['type']][$op]) ? $info[$object['type']][$op] : CONTENT_HANDLE_CORE; |
|
| 2188 | + return isset($info[$object['type']][$op]) ? $info[$object['type']][$op] : CONTENT_HANDLE_CORE; |
|
| 2189 | 2189 | |
| 2190 | 2190 | case 'widget': |
| 2191 | 2191 | $info = module_invoke($object['widget']['module'], "widget_info"); |
| 2192 | - return isset($info[$object['widget']['type']][$op]) ? $info[$object['widget']['type']][$op] : CONTENT_HANDLE_CORE; |
|
| 2192 | + return isset($info[$object['widget']['type']][$op]) ? $info[$object['widget']['type']][$op] : CONTENT_HANDLE_CORE; |
|
| 2193 | 2193 | |
| 2194 | 2194 | case 'formatter': |
| 2195 | 2195 | // Much simpler, formatters arrays *are* the 'formatter_info' itself. |
| 2196 | 2196 | // We let content_handle deal with them only for code consistency. |
| 2197 | 2197 | return isset($object[$op]) ? $object[$op] : CONTENT_HANDLE_CORE; |
| 2198 | - } |
|
| 2198 | + } |
|
| 2199 | 2199 | } |
| 2200 | 2200 | |
| 2201 | 2201 | /** |
@@ -2211,22 +2211,22 @@ discard block |
||
| 2211 | 2211 | * The default value for that field. |
| 2212 | 2212 | */ |
| 2213 | 2213 | function content_default_value(&$form, &$form_state, $field, $delta) { |
| 2214 | - $widget_types = _content_widget_types(); |
|
| 2215 | - $module = $widget_types[$field['widget']['type']]['module']; |
|
| 2214 | + $widget_types = _content_widget_types(); |
|
| 2215 | + $module = $widget_types[$field['widget']['type']]['module']; |
|
| 2216 | 2216 | |
| 2217 | - $default_value = array(); |
|
| 2218 | - if (!empty($field['widget']['default_value_php'])) { |
|
| 2217 | + $default_value = array(); |
|
| 2218 | + if (!empty($field['widget']['default_value_php'])) { |
|
| 2219 | 2219 | ob_start(); |
| 2220 | 2220 | $result = eval($field['widget']['default_value_php']); |
| 2221 | 2221 | ob_end_clean(); |
| 2222 | 2222 | if (is_array($result)) { |
| 2223 | - $default_value = $result; |
|
| 2223 | + $default_value = $result; |
|
| 2224 | + } |
|
| 2224 | 2225 | } |
| 2225 | - } |
|
| 2226 | - elseif (!empty($field['widget']['default_value'])) { |
|
| 2226 | + elseif (!empty($field['widget']['default_value'])) { |
|
| 2227 | 2227 | $default_value = $field['widget']['default_value']; |
| 2228 | - } |
|
| 2229 | - return (array) $default_value; |
|
| 2228 | + } |
|
| 2229 | + return (array) $default_value; |
|
| 2230 | 2230 | } |
| 2231 | 2231 | |
| 2232 | 2232 | /** |
@@ -2247,33 +2247,33 @@ discard block |
||
| 2247 | 2247 | * FALSE if the operation is denied. |
| 2248 | 2248 | */ |
| 2249 | 2249 | function content_access($op, $field, $account = NULL, $node = NULL) { |
| 2250 | - global $user; |
|
| 2250 | + global $user; |
|
| 2251 | 2251 | |
| 2252 | - if (is_null($account)) { |
|
| 2252 | + if (is_null($account)) { |
|
| 2253 | 2253 | $account = $user; |
| 2254 | - } |
|
| 2255 | - // Check for valid field data. |
|
| 2256 | - if (!isset($field['field_name'])) { |
|
| 2254 | + } |
|
| 2255 | + // Check for valid field data. |
|
| 2256 | + if (!isset($field['field_name'])) { |
|
| 2257 | 2257 | return FALSE; |
| 2258 | - } |
|
| 2259 | - $access = module_invoke_all('field_access', $op, $field, $account, $node); |
|
| 2260 | - foreach ($access as $value) { |
|
| 2258 | + } |
|
| 2259 | + $access = module_invoke_all('field_access', $op, $field, $account, $node); |
|
| 2260 | + foreach ($access as $value) { |
|
| 2261 | 2261 | if ($value === FALSE) { |
| 2262 | - return FALSE; |
|
| 2262 | + return FALSE; |
|
| 2263 | + } |
|
| 2263 | 2264 | } |
| 2264 | - } |
|
| 2265 | - return TRUE; |
|
| 2265 | + return TRUE; |
|
| 2266 | 2266 | } |
| 2267 | 2267 | |
| 2268 | - /** |
|
| 2269 | - * Hide specified fields from the $content variable in node templates. |
|
| 2270 | - */ |
|
| 2268 | + /** |
|
| 2269 | + * Hide specified fields from the $content variable in node templates. |
|
| 2270 | + */ |
|
| 2271 | 2271 | function content_field_wrapper_post_render($content, $element) { |
| 2272 | - $field = content_fields($element['#field_name'], $element['#type_name']); |
|
| 2273 | - if (theme('content_exclude', $content, $field, $element['#context'])) { |
|
| 2272 | + $field = content_fields($element['#field_name'], $element['#type_name']); |
|
| 2273 | + if (theme('content_exclude', $content, $field, $element['#context'])) { |
|
| 2274 | 2274 | return ''; |
| 2275 | - } |
|
| 2276 | - return $content; |
|
| 2275 | + } |
|
| 2276 | + return $content; |
|
| 2277 | 2277 | } |
| 2278 | 2278 | |
| 2279 | 2279 | |
@@ -2329,17 +2329,17 @@ discard block |
||
| 2329 | 2329 | * as set on the Manage fields screen. |
| 2330 | 2330 | */ |
| 2331 | 2331 | function theme_content_exclude($content, $object, $context) { |
| 2332 | - // The field may be missing info for $contexts added by modules |
|
| 2333 | - // enabled after the field was last edited. |
|
| 2334 | - if (empty($object['display_settings']) |
|
| 2332 | + // The field may be missing info for $contexts added by modules |
|
| 2333 | + // enabled after the field was last edited. |
|
| 2334 | + if (empty($object['display_settings']) |
|
| 2335 | 2335 | || empty($object['display_settings'][$context]) |
| 2336 | 2336 | || !is_array($object['display_settings'][$context]) |
| 2337 | 2337 | || empty($object['display_settings'][$context]['exclude'])) { |
| 2338 | 2338 | return FALSE; |
| 2339 | - } |
|
| 2340 | - else { |
|
| 2339 | + } |
|
| 2340 | + else { |
|
| 2341 | 2341 | return TRUE; |
| 2342 | - } |
|
| 2342 | + } |
|
| 2343 | 2343 | } |
| 2344 | 2344 | |
| 2345 | 2345 | /** |
@@ -2358,48 +2358,48 @@ discard block |
||
| 2358 | 2358 | * doesn't get called when the theme overrides the template. Bug in theme layer ? |
| 2359 | 2359 | */ |
| 2360 | 2360 | function template_preprocess_content_field(&$variables) { |
| 2361 | - $element = $variables['element']; |
|
| 2362 | - $field = content_fields($element['#field_name'], $element['#node']->type); |
|
| 2361 | + $element = $variables['element']; |
|
| 2362 | + $field = content_fields($element['#field_name'], $element['#node']->type); |
|
| 2363 | 2363 | |
| 2364 | - $variables['node'] = $element['#node']; |
|
| 2365 | - $variables['field'] = $field; |
|
| 2366 | - $variables['items'] = array(); |
|
| 2364 | + $variables['node'] = $element['#node']; |
|
| 2365 | + $variables['field'] = $field; |
|
| 2366 | + $variables['items'] = array(); |
|
| 2367 | 2367 | |
| 2368 | - if ($element['#single']) { |
|
| 2368 | + if ($element['#single']) { |
|
| 2369 | 2369 | // Single value formatter. |
| 2370 | 2370 | foreach (element_children($element['items']) as $delta) { |
| 2371 | - $variables['items'][$delta] = $element['items'][$delta]['#item']; |
|
| 2372 | - // Use isset() to avoid undefined index message on #children when field values are empty. |
|
| 2373 | - $variables['items'][$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
|
| 2371 | + $variables['items'][$delta] = $element['items'][$delta]['#item']; |
|
| 2372 | + // Use isset() to avoid undefined index message on #children when field values are empty. |
|
| 2373 | + $variables['items'][$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
|
| 2374 | 2374 | } |
| 2375 | - } |
|
| 2376 | - else { |
|
| 2375 | + } |
|
| 2376 | + else { |
|
| 2377 | 2377 | // Multiple values formatter. |
| 2378 | 2378 | // We display the 'all items' output as $items[0], as if it was the |
| 2379 | 2379 | // output of a single valued field. |
| 2380 | 2380 | // Raw values are still exposed for all items. |
| 2381 | 2381 | foreach (element_children($element['items']) as $delta) { |
| 2382 | - $variables['items'][$delta] = $element['items'][$delta]['#item']; |
|
| 2382 | + $variables['items'][$delta] = $element['items'][$delta]['#item']; |
|
| 2383 | 2383 | } |
| 2384 | 2384 | $variables['items'][0]['view'] = $element['items']['#children']; |
| 2385 | - } |
|
| 2385 | + } |
|
| 2386 | 2386 | |
| 2387 | - $variables['teaser'] = $element['#teaser']; |
|
| 2388 | - $variables['page'] = $element['#page']; |
|
| 2387 | + $variables['teaser'] = $element['#teaser']; |
|
| 2388 | + $variables['page'] = $element['#page']; |
|
| 2389 | 2389 | |
| 2390 | - $field_empty = TRUE; |
|
| 2390 | + $field_empty = TRUE; |
|
| 2391 | 2391 | |
| 2392 | - foreach ($variables['items'] as $delta => $item) { |
|
| 2392 | + foreach ($variables['items'] as $delta => $item) { |
|
| 2393 | 2393 | if (!isset($item['view']) || (empty($item['view']) && (string)$item['view'] !== '0')) { |
| 2394 | - $variables['items'][$delta]['empty'] = TRUE; |
|
| 2394 | + $variables['items'][$delta]['empty'] = TRUE; |
|
| 2395 | 2395 | } |
| 2396 | 2396 | else { |
| 2397 | - $field_empty = FALSE; |
|
| 2398 | - $variables['items'][$delta]['empty'] = FALSE; |
|
| 2397 | + $field_empty = FALSE; |
|
| 2398 | + $variables['items'][$delta]['empty'] = FALSE; |
|
| 2399 | + } |
|
| 2399 | 2400 | } |
| 2400 | - } |
|
| 2401 | 2401 | |
| 2402 | - $additions = array( |
|
| 2402 | + $additions = array( |
|
| 2403 | 2403 | 'field_type' => $field['type'], |
| 2404 | 2404 | 'field_name' => $field['field_name'], |
| 2405 | 2405 | 'field_type_css' => strtr($field['type'], '_', '-'), |
@@ -2408,13 +2408,13 @@ discard block |
||
| 2408 | 2408 | 'label_display' => $element['#label_display'], |
| 2409 | 2409 | 'field_empty' => $field_empty, |
| 2410 | 2410 | 'template_files' => array( |
| 2411 | - 'content-field', |
|
| 2412 | - 'content-field-'. $element['#field_name'], |
|
| 2413 | - 'content-field-'. $element['#node']->type, |
|
| 2414 | - 'content-field-'. $element['#field_name'] .'-'. $element['#node']->type, |
|
| 2411 | + 'content-field', |
|
| 2412 | + 'content-field-'. $element['#field_name'], |
|
| 2413 | + 'content-field-'. $element['#node']->type, |
|
| 2414 | + 'content-field-'. $element['#field_name'] .'-'. $element['#node']->type, |
|
| 2415 | 2415 | ), |
| 2416 | - ); |
|
| 2417 | - $variables = array_merge($variables, $additions); |
|
| 2416 | + ); |
|
| 2417 | + $variables = array_merge($variables, $additions); |
|
| 2418 | 2418 | } |
| 2419 | 2419 | |
| 2420 | 2420 | /** |
@@ -2425,8 +2425,8 @@ discard block |
||
| 2425 | 2425 | * - Adds the formatted values in the 'view' key of the items. |
| 2426 | 2426 | */ |
| 2427 | 2427 | function content_preprocess_node(&$vars) { |
| 2428 | - $additions = _content_field_invoke_default('preprocess_node', $vars['node']); |
|
| 2429 | - $vars = array_merge($vars, $additions); |
|
| 2428 | + $additions = _content_field_invoke_default('preprocess_node', $vars['node']); |
|
| 2429 | + $vars = array_merge($vars, $additions); |
|
| 2430 | 2430 | } |
| 2431 | 2431 | |
| 2432 | 2432 | /** |
@@ -2438,10 +2438,10 @@ discard block |
||
| 2438 | 2438 | * @param $field |
| 2439 | 2439 | */ |
| 2440 | 2440 | function content_content_fieldapi($op, $field) { |
| 2441 | - if (module_exists('devel')) { |
|
| 2441 | + if (module_exists('devel')) { |
|
| 2442 | 2442 | //dsm($op); |
| 2443 | 2443 | //dsm($field); |
| 2444 | - } |
|
| 2444 | + } |
|
| 2445 | 2445 | } |
| 2446 | 2446 | |
| 2447 | 2447 | /** |
@@ -2450,115 +2450,115 @@ discard block |
||
| 2450 | 2450 | * Informations for non-CCK 'node fields' defined in core. |
| 2451 | 2451 | */ |
| 2452 | 2452 | function content_content_extra_fields($type_name) { |
| 2453 | - $type = node_get_types('type', $type_name); |
|
| 2454 | - $extra = array(); |
|
| 2453 | + $type = node_get_types('type', $type_name); |
|
| 2454 | + $extra = array(); |
|
| 2455 | 2455 | |
| 2456 | - if ($type->has_title) { |
|
| 2456 | + if ($type->has_title) { |
|
| 2457 | 2457 | $extra['title'] = array( |
| 2458 | - 'label' => $type->title_label, |
|
| 2459 | - 'description' => t('Node module form.'), |
|
| 2460 | - 'weight' => -5 |
|
| 2458 | + 'label' => $type->title_label, |
|
| 2459 | + 'description' => t('Node module form.'), |
|
| 2460 | + 'weight' => -5 |
|
| 2461 | 2461 | ); |
| 2462 | - } |
|
| 2463 | - if ($type->has_body) { |
|
| 2462 | + } |
|
| 2463 | + if ($type->has_body) { |
|
| 2464 | 2464 | $extra['body_field'] = array( |
| 2465 | - 'label' => $type->body_label, |
|
| 2466 | - 'description' => t('Node module form.'), |
|
| 2467 | - 'weight' => 0, |
|
| 2468 | - 'view' => 'body' |
|
| 2465 | + 'label' => $type->body_label, |
|
| 2466 | + 'description' => t('Node module form.'), |
|
| 2467 | + 'weight' => 0, |
|
| 2468 | + 'view' => 'body' |
|
| 2469 | 2469 | ); |
| 2470 | - } |
|
| 2471 | - $extra['revision_information'] = array( |
|
| 2470 | + } |
|
| 2471 | + $extra['revision_information'] = array( |
|
| 2472 | 2472 | 'label' => t('Revision information'), |
| 2473 | 2473 | 'description' => t('Node module form.'), |
| 2474 | 2474 | 'weight' => 20 |
| 2475 | - ); |
|
| 2476 | - $extra['author'] = array( |
|
| 2475 | + ); |
|
| 2476 | + $extra['author'] = array( |
|
| 2477 | 2477 | 'label' => t('Authoring information'), |
| 2478 | 2478 | 'description' => t('Node module form.'), |
| 2479 | 2479 | 'weight' => 20, |
| 2480 | - ); |
|
| 2481 | - $extra['options'] = array( |
|
| 2480 | + ); |
|
| 2481 | + $extra['options'] = array( |
|
| 2482 | 2482 | 'label' => t('Publishing options'), |
| 2483 | 2483 | 'description' => t('Node module form.'), |
| 2484 | 2484 | 'weight' => 25, |
| 2485 | - ); |
|
| 2486 | - if (module_exists('comment')) { |
|
| 2485 | + ); |
|
| 2486 | + if (module_exists('comment')) { |
|
| 2487 | 2487 | $extra['comment_settings'] = array( |
| 2488 | - 'label' => t('Comment settings'), |
|
| 2489 | - 'description' => t('Comment module form.'), |
|
| 2490 | - 'weight' => 30 |
|
| 2488 | + 'label' => t('Comment settings'), |
|
| 2489 | + 'description' => t('Comment module form.'), |
|
| 2490 | + 'weight' => 30 |
|
| 2491 | 2491 | ); |
| 2492 | - } |
|
| 2493 | - if (module_exists('locale') && variable_get("language_content_type_$type_name", 0)) { |
|
| 2492 | + } |
|
| 2493 | + if (module_exists('locale') && variable_get("language_content_type_$type_name", 0)) { |
|
| 2494 | 2494 | $extra['language'] = array( |
| 2495 | - 'label' => t('Language'), |
|
| 2496 | - 'description' => t('Locale module form.'), |
|
| 2497 | - 'weight' => 0 |
|
| 2495 | + 'label' => t('Language'), |
|
| 2496 | + 'description' => t('Locale module form.'), |
|
| 2497 | + 'weight' => 0 |
|
| 2498 | 2498 | ); |
| 2499 | - } |
|
| 2500 | - if (module_exists('translation') && translation_supported_type($type_name)) { |
|
| 2499 | + } |
|
| 2500 | + if (module_exists('translation') && translation_supported_type($type_name)) { |
|
| 2501 | 2501 | $extra['translation'] = array( |
| 2502 | - 'label' => t('Translation settings'), |
|
| 2503 | - 'description' => t('Translation module form.'), |
|
| 2504 | - 'weight' => 30 |
|
| 2502 | + 'label' => t('Translation settings'), |
|
| 2503 | + 'description' => t('Translation module form.'), |
|
| 2504 | + 'weight' => 30 |
|
| 2505 | 2505 | ); |
| 2506 | - } |
|
| 2507 | - if (module_exists('menu')) { |
|
| 2506 | + } |
|
| 2507 | + if (module_exists('menu')) { |
|
| 2508 | 2508 | $extra['menu'] = array( |
| 2509 | - 'label' => t('Menu settings'), |
|
| 2510 | - 'description' => t('Menu module form.'), |
|
| 2511 | - 'weight' => -2 |
|
| 2509 | + 'label' => t('Menu settings'), |
|
| 2510 | + 'description' => t('Menu module form.'), |
|
| 2511 | + 'weight' => -2 |
|
| 2512 | 2512 | ); |
| 2513 | - } |
|
| 2514 | - if (module_exists('taxonomy') && taxonomy_get_vocabularies($type_name)) { |
|
| 2513 | + } |
|
| 2514 | + if (module_exists('taxonomy') && taxonomy_get_vocabularies($type_name)) { |
|
| 2515 | 2515 | $extra['taxonomy'] = array( |
| 2516 | - 'label' => t('Taxonomy'), |
|
| 2517 | - 'description' => t('Taxonomy module form.'), |
|
| 2518 | - 'weight' => -3 |
|
| 2516 | + 'label' => t('Taxonomy'), |
|
| 2517 | + 'description' => t('Taxonomy module form.'), |
|
| 2518 | + 'weight' => -3 |
|
| 2519 | 2519 | ); |
| 2520 | - } |
|
| 2521 | - if (module_exists('book')) { |
|
| 2520 | + } |
|
| 2521 | + if (module_exists('book')) { |
|
| 2522 | 2522 | $extra['book'] = array( |
| 2523 | - 'label' => t('Book'), |
|
| 2524 | - 'description' => t('Book module form.'), |
|
| 2525 | - 'weight' => 10 |
|
| 2523 | + 'label' => t('Book'), |
|
| 2524 | + 'description' => t('Book module form.'), |
|
| 2525 | + 'weight' => 10 |
|
| 2526 | 2526 | ); |
| 2527 | - } |
|
| 2528 | - if (module_exists('path')) { |
|
| 2527 | + } |
|
| 2528 | + if (module_exists('path')) { |
|
| 2529 | 2529 | $extra['path'] = array( |
| 2530 | - 'label' => t('Path settings'), |
|
| 2531 | - 'description' => t('Path module form.'), |
|
| 2532 | - 'weight' => 30 |
|
| 2530 | + 'label' => t('Path settings'), |
|
| 2531 | + 'description' => t('Path module form.'), |
|
| 2532 | + 'weight' => 30 |
|
| 2533 | 2533 | ); |
| 2534 | - } |
|
| 2535 | - if ($type_name == 'poll' && module_exists('poll')) { |
|
| 2534 | + } |
|
| 2535 | + if ($type_name == 'poll' && module_exists('poll')) { |
|
| 2536 | 2536 | $extra['title'] = array( |
| 2537 | - 'label' => t('Poll title'), |
|
| 2538 | - 'description' => t('Poll module title.'), |
|
| 2539 | - 'weight' => -5 |
|
| 2537 | + 'label' => t('Poll title'), |
|
| 2538 | + 'description' => t('Poll module title.'), |
|
| 2539 | + 'weight' => -5 |
|
| 2540 | 2540 | ); |
| 2541 | 2541 | $extra['choice_wrapper'] = array( |
| 2542 | - 'label' => t('Poll choices'), |
|
| 2543 | - 'description' => t('Poll module choices.'), |
|
| 2544 | - 'weight' => -4 |
|
| 2542 | + 'label' => t('Poll choices'), |
|
| 2543 | + 'description' => t('Poll module choices.'), |
|
| 2544 | + 'weight' => -4 |
|
| 2545 | 2545 | ); |
| 2546 | 2546 | $extra['settings'] = array( |
| 2547 | - 'label' => t('Poll settings'), |
|
| 2548 | - 'description' => t('Poll module settings.'), |
|
| 2549 | - 'weight' => -3 |
|
| 2547 | + 'label' => t('Poll settings'), |
|
| 2548 | + 'description' => t('Poll module settings.'), |
|
| 2549 | + 'weight' => -3 |
|
| 2550 | 2550 | ); |
| 2551 | - } |
|
| 2552 | - if (module_exists('upload') && variable_get("upload_$type_name", TRUE)) { |
|
| 2551 | + } |
|
| 2552 | + if (module_exists('upload') && variable_get("upload_$type_name", TRUE)) { |
|
| 2553 | 2553 | $extra['attachments'] = array( |
| 2554 | - 'label' => t('File attachments'), |
|
| 2555 | - 'description' => t('Upload module form.'), |
|
| 2556 | - 'weight' => 30, |
|
| 2557 | - 'view' => 'files' |
|
| 2554 | + 'label' => t('File attachments'), |
|
| 2555 | + 'description' => t('Upload module form.'), |
|
| 2556 | + 'weight' => 30, |
|
| 2557 | + 'view' => 'files' |
|
| 2558 | 2558 | ); |
| 2559 | - } |
|
| 2559 | + } |
|
| 2560 | 2560 | |
| 2561 | - return $extra; |
|
| 2561 | + return $extra; |
|
| 2562 | 2562 | } |
| 2563 | 2563 | |
| 2564 | 2564 | /** |
@@ -2579,18 +2579,18 @@ discard block |
||
| 2579 | 2579 | * by content.module. |
| 2580 | 2580 | */ |
| 2581 | 2581 | function content_extra_field_weight($type_name, $pseudo_field_name) { |
| 2582 | - $type = content_types($type_name); |
|
| 2582 | + $type = content_types($type_name); |
|
| 2583 | 2583 | |
| 2584 | - // If we don't have the requested item, this may be because the cached |
|
| 2585 | - // information for 'extra' fields hasn't been refreshed yet. |
|
| 2586 | - if (!isset($type['extra'][$pseudo_field_name])) { |
|
| 2584 | + // If we don't have the requested item, this may be because the cached |
|
| 2585 | + // information for 'extra' fields hasn't been refreshed yet. |
|
| 2586 | + if (!isset($type['extra'][$pseudo_field_name])) { |
|
| 2587 | 2587 | content_clear_type_cache(); |
| 2588 | 2588 | $type = content_types($type_name); |
| 2589 | - } |
|
| 2589 | + } |
|
| 2590 | 2590 | |
| 2591 | - if (isset($type['extra'][$pseudo_field_name])) { |
|
| 2591 | + if (isset($type['extra'][$pseudo_field_name])) { |
|
| 2592 | 2592 | return $type['extra'][$pseudo_field_name]['weight']; |
| 2593 | - } |
|
| 2593 | + } |
|
| 2594 | 2594 | } |
| 2595 | 2595 | |
| 2596 | 2596 | /** |
@@ -2617,68 +2617,68 @@ discard block |
||
| 2617 | 2617 | * Do we want to eliminate them from the results? |
| 2618 | 2618 | */ |
| 2619 | 2619 | function content_max_delta($field_name, $type_name = NULL) { |
| 2620 | - $fields = content_fields(); |
|
| 2621 | - $field = $fields[$field_name]; |
|
| 2620 | + $fields = content_fields(); |
|
| 2621 | + $field = $fields[$field_name]; |
|
| 2622 | 2622 | |
| 2623 | - // Non-multiple value fields don't use the delta column, |
|
| 2624 | - // but could exist in multiple databases. If any value |
|
| 2625 | - // exists in any examined table, the max delta will be zero. |
|
| 2626 | - if (empty($field['multiple'])) { |
|
| 2623 | + // Non-multiple value fields don't use the delta column, |
|
| 2624 | + // but could exist in multiple databases. If any value |
|
| 2625 | + // exists in any examined table, the max delta will be zero. |
|
| 2626 | + if (empty($field['multiple'])) { |
|
| 2627 | 2627 | $content_types = content_types(); |
| 2628 | 2628 | foreach ($content_types as $content_type) { |
| 2629 | - if (empty($type_name) || $content_type['type'] == $type_name) { |
|
| 2629 | + if (empty($type_name) || $content_type['type'] == $type_name) { |
|
| 2630 | 2630 | foreach ($content_type['fields'] as $field) { |
| 2631 | - $db_info = content_database_info($field); |
|
| 2632 | - if (db_result(db_query("SELECT COUNT(*) FROM {". $db_info['table'] ."}")) >= 1) { |
|
| 2631 | + $db_info = content_database_info($field); |
|
| 2632 | + if (db_result(db_query("SELECT COUNT(*) FROM {". $db_info['table'] ."}")) >= 1) { |
|
| 2633 | 2633 | return 0; |
| 2634 | - } |
|
| 2634 | + } |
|
| 2635 | + } |
|
| 2635 | 2636 | } |
| 2636 | - } |
|
| 2637 | 2637 | } |
| 2638 | - } |
|
| 2639 | - // Multiple value fields always share the same table and use the delta. |
|
| 2640 | - // If we want to find delta values for a particular type, we join |
|
| 2641 | - // in the node table to limit the type. |
|
| 2642 | - else { |
|
| 2638 | + } |
|
| 2639 | + // Multiple value fields always share the same table and use the delta. |
|
| 2640 | + // If we want to find delta values for a particular type, we join |
|
| 2641 | + // in the node table to limit the type. |
|
| 2642 | + else { |
|
| 2643 | 2643 | $db_info = content_database_info($field); |
| 2644 | 2644 | if (!empty($type_name)) { |
| 2645 | - $delta = db_result(db_query("SELECT MAX(delta) FROM {". $db_info['table'] ."} f LEFT JOIN {node} n ON f.vid = n.vid WHERE n.type = '%s'", $type_name)); |
|
| 2645 | + $delta = db_result(db_query("SELECT MAX(delta) FROM {". $db_info['table'] ."} f LEFT JOIN {node} n ON f.vid = n.vid WHERE n.type = '%s'", $type_name)); |
|
| 2646 | 2646 | } |
| 2647 | 2647 | else { |
| 2648 | - $delta = db_result(db_query("SELECT MAX(delta) FROM {". $db_info['table'] ."}")); |
|
| 2648 | + $delta = db_result(db_query("SELECT MAX(delta) FROM {". $db_info['table'] ."}")); |
|
| 2649 | 2649 | } |
| 2650 | 2650 | if ($delta >= 0) { |
| 2651 | - return $delta; |
|
| 2651 | + return $delta; |
|
| 2652 | 2652 | } |
| 2653 | - } |
|
| 2654 | - // If we got this far, there is no data for this field. |
|
| 2655 | - return NULL; |
|
| 2653 | + } |
|
| 2654 | + // If we got this far, there is no data for this field. |
|
| 2655 | + return NULL; |
|
| 2656 | 2656 | } |
| 2657 | 2657 | |
| 2658 | 2658 | /** |
| 2659 | 2659 | * Helper function to identify inactive fields. |
| 2660 | 2660 | */ |
| 2661 | 2661 | function content_inactive_fields($type_name = NULL) { |
| 2662 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 2663 | - if (!empty($type_name)) { |
|
| 2662 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 2663 | + if (!empty($type_name)) { |
|
| 2664 | 2664 | $param = array('type_name' => $type_name); |
| 2665 | 2665 | $inactive = array($type_name => array()); |
| 2666 | - } |
|
| 2667 | - else { |
|
| 2666 | + } |
|
| 2667 | + else { |
|
| 2668 | 2668 | $param = array(); |
| 2669 | 2669 | $inactive = array(); |
| 2670 | - } |
|
| 2671 | - $all = content_field_instance_read($param, TRUE); |
|
| 2672 | - $active = array_keys(content_fields()); |
|
| 2673 | - foreach ($all as $field) { |
|
| 2670 | + } |
|
| 2671 | + $all = content_field_instance_read($param, TRUE); |
|
| 2672 | + $active = array_keys(content_fields()); |
|
| 2673 | + foreach ($all as $field) { |
|
| 2674 | 2674 | if (!in_array($field['field_name'], $active)) { |
| 2675 | - $inactive[$field['type_name']][$field['field_name']] = content_field_instance_expand($field); |
|
| 2675 | + $inactive[$field['type_name']][$field['field_name']] = content_field_instance_expand($field); |
|
| 2676 | + } |
|
| 2676 | 2677 | } |
| 2677 | - } |
|
| 2678 | - if (!empty($type_name)) { |
|
| 2678 | + if (!empty($type_name)) { |
|
| 2679 | 2679 | return $inactive[$type_name]; |
| 2680 | - } |
|
| 2681 | - return $inactive; |
|
| 2680 | + } |
|
| 2681 | + return $inactive; |
|
| 2682 | 2682 | } |
| 2683 | 2683 | |
| 2684 | 2684 | |
@@ -2689,21 +2689,21 @@ discard block |
||
| 2689 | 2689 | * if the fields have other (shared) instances that are still active. |
| 2690 | 2690 | */ |
| 2691 | 2691 | function content_inactive_instances($type_name = NULL) { |
| 2692 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 2693 | - if (!empty($type_name)) { |
|
| 2692 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 2693 | + if (!empty($type_name)) { |
|
| 2694 | 2694 | $param = array('type_name' => $type_name); |
| 2695 | 2695 | $inactive = array($type_name => array()); |
| 2696 | - } |
|
| 2697 | - else { |
|
| 2696 | + } |
|
| 2697 | + else { |
|
| 2698 | 2698 | $param = array(); |
| 2699 | 2699 | $inactive = array(); |
| 2700 | - } |
|
| 2701 | - $all = content_field_instance_read($param, TRUE); |
|
| 2702 | - foreach ($all as $field) { |
|
| 2700 | + } |
|
| 2701 | + $all = content_field_instance_read($param, TRUE); |
|
| 2702 | + foreach ($all as $field) { |
|
| 2703 | 2703 | $inactive[$field['type_name']][$field['field_name']] = content_field_instance_expand($field); |
| 2704 | - } |
|
| 2705 | - if (!empty($type_name)) { |
|
| 2704 | + } |
|
| 2705 | + if (!empty($type_name)) { |
|
| 2706 | 2706 | return $inactive[$type_name]; |
| 2707 | - } |
|
| 2708 | - return $inactive; |
|
| 2707 | + } |
|
| 2708 | + return $inactive; |
|
| 2709 | 2709 | } |
@@ -17,19 +17,19 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | function content_help($path, $arg) { |
| 19 | 19 | switch ($path) { |
| 20 | - case 'admin/help#content': |
|
| 21 | - $output = '<p>'. t('The content module, a required component of the Content Construction Kit (CCK), allows administrators to associate custom fields with content types. In Drupal, content types are used to define the characteristics of a post, including the title and description of the fields displayed on its add and edit pages. Using the content module (and the other helper modules included in CCK), custom fields beyond the default "Title" and "Body" may be added. CCK features are accessible through tabs on the <a href="@content-types">content types administration page</a>. (See the <a href="@node-help">node module help page</a> for more information about content types.)', array('@content-types' => url('admin/content/types'), '@node-help' => url('admin/help/node'))) .'</p>'; |
|
| 22 | - $output .= '<p>'. t('When adding a custom field to a content type, you determine its type (whether it will contain text, numbers, or references to other objects) and how it will be displayed (either as a text field or area, a select box, checkbox, radio button, or autocompleting field). A field may have multiple values (i.e., a "person" may have multiple e-mail addresses) or a single value (i.e., an "employee" has a single employee identification number). As you add and edit fields, CCK automatically adjusts the structure of the database as necessary. CCK also provides a number of other features, including intelligent caching for your custom data, an import and export facility for content type definitions, and integration with other contributed modules.') .'</p>'; |
|
| 23 | - $output .= '<p>'. t('Custom field types are provided by a set of optional modules included with CCK (each module provides a different type). The <a href="@modules">modules page</a> allows you to enable or disable CCK components. A default installation of CCK includes:', array('@modules' => url('admin/build/modules'))) .'</p>'; |
|
| 24 | - $output .= '<ul>'; |
|
| 25 | - $output .= '<li>'. t('<em>number</em>, which adds numeric field types, in integer, decimal or floating point form. You may define a set of allowed inputs, or specify an allowable range of values. A variety of common formats for displaying numeric data are available.') .'</li>'; |
|
| 26 | - $output .= '<li>'. t("<em>text</em>, which adds text field types. A text field may contain plain text only, or optionally, may use Drupal's input format filters to securely manage rich text input. Text input fields may be either a single line (text field), multiple lines (text area), or for greater input control, a select box, checkbox, or radio buttons. If desired, CCK can validate the input to a set of allowed values.") .'</li>'; |
|
| 27 | - $output .= '<li>'. t('<em>nodereference</em>, which creates custom references between Drupal nodes. By adding a <em>nodereference</em> field and two different content types, for instance, you can easily create complex parent/child relationships between data (multiple "employee" nodes may contain a <em>nodereference</em> field linking to an "employer" node).') .'</li>'; |
|
| 28 | - $output .= '<li>'. t('<em>userreference</em>, which creates custom references to your sites\' user accounts. By adding a <em>userreference</em> field, you can create complex relationships between your site\'s users and posts. To track user involvement in a post beyond Drupal\'s standard <em>Authored by</em> field, for instance, add a <em>userreference</em> field named "Edited by" to a content type to store a link to an editor\'s user account page.') .'</li>'; |
|
| 29 | - $output .= '<li>'. t('<em>fieldgroup</em>, which creates collapsible fieldsets to hold a group of related fields. A fieldset may either be open or closed by default. The order of your fieldsets, and the order of fields within a fieldset, is managed via a drag-and-drop interface provided by content module.') .'</li>'; |
|
| 30 | - $output .= '</ul>'; |
|
| 31 | - $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@handbook-cck">CCK</a> or the <a href="@project-cck">CCK project page</a>.', array('@handbook-cck' => 'http://drupal.org/handbook/modules/cck', '@project-cck' => 'http://drupal.org/project/cck')) .'</p>'; |
|
| 32 | - return $output; |
|
| 20 | + case 'admin/help#content': |
|
| 21 | + $output = '<p>'. t('The content module, a required component of the Content Construction Kit (CCK), allows administrators to associate custom fields with content types. In Drupal, content types are used to define the characteristics of a post, including the title and description of the fields displayed on its add and edit pages. Using the content module (and the other helper modules included in CCK), custom fields beyond the default "Title" and "Body" may be added. CCK features are accessible through tabs on the <a href="@content-types">content types administration page</a>. (See the <a href="@node-help">node module help page</a> for more information about content types.)', array('@content-types' => url('admin/content/types'), '@node-help' => url('admin/help/node'))) .'</p>'; |
|
| 22 | + $output .= '<p>'. t('When adding a custom field to a content type, you determine its type (whether it will contain text, numbers, or references to other objects) and how it will be displayed (either as a text field or area, a select box, checkbox, radio button, or autocompleting field). A field may have multiple values (i.e., a "person" may have multiple e-mail addresses) or a single value (i.e., an "employee" has a single employee identification number). As you add and edit fields, CCK automatically adjusts the structure of the database as necessary. CCK also provides a number of other features, including intelligent caching for your custom data, an import and export facility for content type definitions, and integration with other contributed modules.') .'</p>'; |
|
| 23 | + $output .= '<p>'. t('Custom field types are provided by a set of optional modules included with CCK (each module provides a different type). The <a href="@modules">modules page</a> allows you to enable or disable CCK components. A default installation of CCK includes:', array('@modules' => url('admin/build/modules'))) .'</p>'; |
|
| 24 | + $output .= '<ul>'; |
|
| 25 | + $output .= '<li>'. t('<em>number</em>, which adds numeric field types, in integer, decimal or floating point form. You may define a set of allowed inputs, or specify an allowable range of values. A variety of common formats for displaying numeric data are available.') .'</li>'; |
|
| 26 | + $output .= '<li>'. t("<em>text</em>, which adds text field types. A text field may contain plain text only, or optionally, may use Drupal's input format filters to securely manage rich text input. Text input fields may be either a single line (text field), multiple lines (text area), or for greater input control, a select box, checkbox, or radio buttons. If desired, CCK can validate the input to a set of allowed values.") .'</li>'; |
|
| 27 | + $output .= '<li>'. t('<em>nodereference</em>, which creates custom references between Drupal nodes. By adding a <em>nodereference</em> field and two different content types, for instance, you can easily create complex parent/child relationships between data (multiple "employee" nodes may contain a <em>nodereference</em> field linking to an "employer" node).') .'</li>'; |
|
| 28 | + $output .= '<li>'. t('<em>userreference</em>, which creates custom references to your sites\' user accounts. By adding a <em>userreference</em> field, you can create complex relationships between your site\'s users and posts. To track user involvement in a post beyond Drupal\'s standard <em>Authored by</em> field, for instance, add a <em>userreference</em> field named "Edited by" to a content type to store a link to an editor\'s user account page.') .'</li>'; |
|
| 29 | + $output .= '<li>'. t('<em>fieldgroup</em>, which creates collapsible fieldsets to hold a group of related fields. A fieldset may either be open or closed by default. The order of your fieldsets, and the order of fields within a fieldset, is managed via a drag-and-drop interface provided by content module.') .'</li>'; |
|
| 30 | + $output .= '</ul>'; |
|
| 31 | + $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@handbook-cck">CCK</a> or the <a href="@project-cck">CCK project page</a>.', array('@handbook-cck' => 'http://drupal.org/handbook/modules/cck', '@project-cck' => 'http://drupal.org/project/cck')) .'</p>'; |
|
| 32 | + return $output; |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
@@ -553,27 +553,27 @@ discard block |
||
| 553 | 553 | */ |
| 554 | 554 | function content_notify($op, $module) { |
| 555 | 555 | switch ($op) { |
| 556 | - case 'install': |
|
| 557 | - content_clear_type_cache(); |
|
| 558 | - break; |
|
| 559 | - case 'uninstall': |
|
| 560 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 561 | - content_module_delete($module); |
|
| 562 | - break; |
|
| 563 | - case 'enable': |
|
| 564 | - content_associate_fields($module); |
|
| 565 | - content_clear_type_cache(); |
|
| 566 | - break; |
|
| 567 | - case 'disable': |
|
| 568 | - // When CCK modules are disabled before content module's update is run |
|
| 569 | - // to add the active column, we can't do this. |
|
| 570 | - if (variable_get('content_schema_version', -1) < 6007) { |
|
| 571 | - return FALSE; |
|
| 572 | - } |
|
| 573 | - db_query("UPDATE {". content_field_tablename() ."} SET active=0 WHERE module='%s'", $module); |
|
| 574 | - db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=0 WHERE widget_module='%s'", $module); |
|
| 575 | - content_clear_type_cache(TRUE); |
|
| 576 | - break; |
|
| 556 | + case 'install': |
|
| 557 | + content_clear_type_cache(); |
|
| 558 | + break; |
|
| 559 | + case 'uninstall': |
|
| 560 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 561 | + content_module_delete($module); |
|
| 562 | + break; |
|
| 563 | + case 'enable': |
|
| 564 | + content_associate_fields($module); |
|
| 565 | + content_clear_type_cache(); |
|
| 566 | + break; |
|
| 567 | + case 'disable': |
|
| 568 | + // When CCK modules are disabled before content module's update is run |
|
| 569 | + // to add the active column, we can't do this. |
|
| 570 | + if (variable_get('content_schema_version', -1) < 6007) { |
|
| 571 | + return FALSE; |
|
| 572 | + } |
|
| 573 | + db_query("UPDATE {". content_field_tablename() ."} SET active=0 WHERE module='%s'", $module); |
|
| 574 | + db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=0 WHERE widget_module='%s'", $module); |
|
| 575 | + content_clear_type_cache(TRUE); |
|
| 576 | + break; |
|
| 577 | 577 | } |
| 578 | 578 | } |
| 579 | 579 | |
@@ -685,38 +685,53 @@ discard block |
||
| 685 | 685 | */ |
| 686 | 686 | function content_field($op, &$node, $field, &$items, $teaser, $page) { |
| 687 | 687 | switch ($op) { |
| 688 | - case 'validate': |
|
| 689 | - // TODO: here we could validate that the number of multiple data is correct ? |
|
| 690 | - // We're controlling the number of fields to fill out and saving empty |
|
| 691 | - // ones if a specified number is requested, so no reason to do any validation |
|
| 692 | - // here right now, but if later create a method to indicate whether |
|
| 693 | - // 'required' means all values must be filled out, we can come back |
|
| 694 | - // here and check that they're not empty. |
|
| 695 | - break; |
|
| 696 | - |
|
| 697 | - case 'presave': |
|
| 698 | - if (!empty($node->devel_generate)) { |
|
| 699 | - include_once('./'. drupal_get_path('module', 'content') .'/includes/content.devel.inc'); |
|
| 700 | - content_generate_fields($node, $field); |
|
| 701 | - $items = $node->{$field['field_name']}; |
|
| 702 | - } |
|
| 688 | + case 'validate': |
|
| 689 | + // TODO: here we could validate that the number of multiple data is correct ? |
|
| 690 | + // We're controlling the number of fields to fill out and saving empty |
|
| 691 | + // ones if a specified number is requested, so no reason to do any validation |
|
| 692 | + // here right now, but if later create a method to indicate whether |
|
| 693 | + // 'required' means all values must be filled out, we can come back |
|
| 694 | + // here and check that they're not empty. |
|
| 695 | + break; |
|
| 696 | + |
|
| 697 | + case 'presave': |
|
| 698 | + if (!empty($node->devel_generate)) { |
|
| 699 | + include_once('./'. drupal_get_path('module', 'content') .'/includes/content.devel.inc'); |
|
| 700 | + content_generate_fields($node, $field); |
|
| 701 | + $items = $node->{$field['field_name']}; |
|
| 702 | + } |
|
| 703 | 703 | |
| 704 | - // Manual node_save calls might not have all fields filled in. |
|
| 705 | - // On node insert, we need to make sure all tables get at least an empty |
|
| 706 | - // record, or subsequent edits, using drupal_write_record() in update mode, |
|
| 707 | - // won't insert any data. |
|
| 708 | - // Missing fields on node update are handled in content_storage(). |
|
| 709 | - if (empty($items) && !isset($node->nid)) { |
|
| 710 | - foreach (array_keys($field['columns']) as $column) { |
|
| 711 | - $items[0][$column] = NULL; |
|
| 712 | - } |
|
| 713 | - $node->$field['field_name'] = $items; |
|
| 704 | + // Manual node_save calls might not have all fields filled in. |
|
| 705 | + // On node insert, we need to make sure all tables get at least an empty |
|
| 706 | + // record, or subsequent edits, using drupal_write_record() in update mode, |
|
| 707 | + // won't insert any data. |
|
| 708 | + // Missing fields on node update are handled in content_storage(). |
|
| 709 | + if (empty($items) && !isset($node->nid)) { |
|
| 710 | + foreach (array_keys($field['columns']) as $column) { |
|
| 711 | + $items[0][$column] = NULL; |
|
| 714 | 712 | } |
| 713 | + $node->$field['field_name'] = $items; |
|
| 714 | + } |
|
| 715 | 715 | |
| 716 | - // If there was an AHAH add more button in this field, don't save it. |
|
| 717 | - // TODO: is it still needed ? |
|
| 718 | - unset($items[$field['field_name'] .'_add_more']); |
|
| 716 | + // If there was an AHAH add more button in this field, don't save it. |
|
| 717 | + // TODO: is it still needed ? |
|
| 718 | + unset($items[$field['field_name'] .'_add_more']); |
|
| 719 | + |
|
| 720 | + if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
| 721 | + // Reorder items to account for drag-n-drop reordering. |
|
| 722 | + $items = _content_sort_items($field, $items); |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + // Filter out empty values. |
|
| 726 | + $items = content_set_empty($field, $items); |
|
| 719 | 727 | |
| 728 | + break; |
|
| 729 | + |
|
| 730 | + case 'view': |
|
| 731 | + $addition = array(); |
|
| 732 | + |
|
| 733 | + // Previewed nodes bypass the 'presave' op, so we need to some massaging. |
|
| 734 | + if ($node->build_mode == NODE_BUILD_PREVIEW && content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
| 720 | 735 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
| 721 | 736 | // Reorder items to account for drag-n-drop reordering. |
| 722 | 737 | $items = _content_sort_items($field, $items); |
@@ -724,166 +739,151 @@ discard block |
||
| 724 | 739 | |
| 725 | 740 | // Filter out empty values. |
| 726 | 741 | $items = content_set_empty($field, $items); |
| 742 | + } |
|
| 727 | 743 | |
| 728 | - break; |
|
| 729 | - |
|
| 730 | - case 'view': |
|
| 731 | - $addition = array(); |
|
| 744 | + // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
|
| 745 | + if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
|
| 746 | + $context = $teaser ? 'teaser' : 'full'; |
|
| 747 | + } |
|
| 748 | + else { |
|
| 749 | + $context = $node->build_mode; |
|
| 750 | + } |
|
| 751 | + // The field may be missing info for $contexts added by modules |
|
| 752 | + // enabled after the field was last edited. |
|
| 753 | + $formatter_name = isset($field['display_settings'][$context]) && isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default'; |
|
| 754 | + if ($formatter = _content_get_formatter($formatter_name, $field['type'])) { |
|
| 755 | + $theme = $formatter['module'] .'_formatter_'. $formatter_name; |
|
| 756 | + $single = (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE); |
|
| 757 | + |
|
| 758 | + $label_display = isset($field['display_settings']['label']['format']) ? $field['display_settings']['label']['format'] : 'above'; |
|
| 759 | + // Do not include field labels when indexing content. |
|
| 760 | + if ($context == NODE_BUILD_SEARCH_INDEX) { |
|
| 761 | + $label_display = 'hidden'; |
|
| 762 | + } |
|
| 732 | 763 | |
| 733 | - // Previewed nodes bypass the 'presave' op, so we need to some massaging. |
|
| 734 | - if ($node->build_mode == NODE_BUILD_PREVIEW && content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
| 735 | - if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
|
| 736 | - // Reorder items to account for drag-n-drop reordering. |
|
| 737 | - $items = _content_sort_items($field, $items); |
|
| 738 | - } |
|
| 764 | + $element = array( |
|
| 765 | + '#type' => 'content_field', |
|
| 766 | + '#title' => check_plain(t($field['widget']['label'])), |
|
| 767 | + '#field_name' => $field['field_name'], |
|
| 768 | + '#access' => $formatter_name != 'hidden' && content_access('view', $field, NULL, $node), |
|
| 769 | + '#label_display' => $label_display, |
|
| 770 | + '#node' => $node, |
|
| 771 | + '#teaser' => $teaser, |
|
| 772 | + '#page' => $page, |
|
| 773 | + '#context' => $context, |
|
| 774 | + '#single' => $single, |
|
| 775 | + 'items' => array(), |
|
| 776 | + ); |
|
| 739 | 777 | |
| 740 | - // Filter out empty values. |
|
| 741 | - $items = content_set_empty($field, $items); |
|
| 778 | + // Fill-in items. |
|
| 779 | + foreach ($items as $delta => $item) { |
|
| 780 | + $element['items'][$delta] = array( |
|
| 781 | + '#item' => $item, |
|
| 782 | + '#weight' => $delta, |
|
| 783 | + ); |
|
| 742 | 784 | } |
| 743 | 785 | |
| 744 | - // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
|
| 745 | - if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
|
| 746 | - $context = $teaser ? 'teaser' : 'full'; |
|
| 786 | + // Append formatter information either on each item ('single-value' formatter) |
|
| 787 | + // or at the upper 'items' level ('multiple-value' formatter) |
|
| 788 | + $format_info = array( |
|
| 789 | + '#theme' => $theme, |
|
| 790 | + '#field_name' => $field['field_name'], |
|
| 791 | + '#type_name' => $node->type, |
|
| 792 | + '#formatter' => $formatter_name, |
|
| 793 | + '#node' => $node, |
|
| 794 | + ); |
|
| 795 | + if ($single) { |
|
| 796 | + foreach ($items as $delta => $item) { |
|
| 797 | + $element['items'][$delta] += $format_info; |
|
| 798 | + $element['items'][$delta]['#item']['#delta'] = $delta; |
|
| 799 | + } |
|
| 747 | 800 | } |
| 748 | 801 | else { |
| 749 | - $context = $node->build_mode; |
|
| 802 | + $element['items'] += $format_info; |
|
| 750 | 803 | } |
| 751 | - // The field may be missing info for $contexts added by modules |
|
| 752 | - // enabled after the field was last edited. |
|
| 753 | - $formatter_name = isset($field['display_settings'][$context]) && isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default'; |
|
| 754 | - if ($formatter = _content_get_formatter($formatter_name, $field['type'])) { |
|
| 755 | - $theme = $formatter['module'] .'_formatter_'. $formatter_name; |
|
| 756 | - $single = (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE); |
|
| 757 | - |
|
| 758 | - $label_display = isset($field['display_settings']['label']['format']) ? $field['display_settings']['label']['format'] : 'above'; |
|
| 759 | - // Do not include field labels when indexing content. |
|
| 760 | - if ($context == NODE_BUILD_SEARCH_INDEX) { |
|
| 761 | - $label_display = 'hidden'; |
|
| 762 | - } |
|
| 763 | 804 | |
| 764 | - $element = array( |
|
| 765 | - '#type' => 'content_field', |
|
| 766 | - '#title' => check_plain(t($field['widget']['label'])), |
|
| 767 | - '#field_name' => $field['field_name'], |
|
| 768 | - '#access' => $formatter_name != 'hidden' && content_access('view', $field, NULL, $node), |
|
| 769 | - '#label_display' => $label_display, |
|
| 770 | - '#node' => $node, |
|
| 771 | - '#teaser' => $teaser, |
|
| 772 | - '#page' => $page, |
|
| 773 | - '#context' => $context, |
|
| 774 | - '#single' => $single, |
|
| 775 | - 'items' => array(), |
|
| 776 | - ); |
|
| 805 | + // The wrapper lets us get the themed output for the whole field |
|
| 806 | + // to populate the $FIELD_NAME_rendered variable for node templates, |
|
| 807 | + // and hide it from the $content variable if needed. |
|
| 808 | + // See 'preprocess_node' op and theme_content_field_wrapper()? |
|
| 809 | + $wrapper = array( |
|
| 810 | + 'field' => $element, |
|
| 811 | + '#weight' => $field['widget']['weight'], |
|
| 812 | + '#post_render' => array('content_field_wrapper_post_render'), |
|
| 813 | + '#field_name' => $field['field_name'], |
|
| 814 | + '#type_name' => $node->type, |
|
| 815 | + '#context' => $context, |
|
| 816 | + ); |
|
| 777 | 817 | |
| 778 | - // Fill-in items. |
|
| 779 | - foreach ($items as $delta => $item) { |
|
| 780 | - $element['items'][$delta] = array( |
|
| 781 | - '#item' => $item, |
|
| 782 | - '#weight' => $delta, |
|
| 783 | - ); |
|
| 784 | - } |
|
| 818 | + $addition = array($field['field_name'] => $wrapper); |
|
| 819 | + } |
|
| 820 | + return $addition; |
|
| 821 | + |
|
| 822 | + case 'alter': |
|
| 823 | + // Add back the formatted values in the 'view' element, |
|
| 824 | + // so that tokens and node templates can use it. |
|
| 825 | + // Note: Doing this in 'preprocess_node' breaks token integration. |
|
| 826 | + |
|
| 827 | + // The location of the field's rendered output depends on whether the |
|
| 828 | + // field is in a fieldgroup or not. |
|
| 829 | + $wrapper = NULL; |
|
| 830 | + if (isset($node->content[$field['field_name']])) { |
|
| 831 | + $wrapper = $node->content[$field['field_name']]; |
|
| 832 | + } |
|
| 833 | + elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
| 834 | + $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
|
| 835 | + } |
|
| 785 | 836 | |
| 786 | - // Append formatter information either on each item ('single-value' formatter) |
|
| 787 | - // or at the upper 'items' level ('multiple-value' formatter) |
|
| 788 | - $format_info = array( |
|
| 789 | - '#theme' => $theme, |
|
| 790 | - '#field_name' => $field['field_name'], |
|
| 791 | - '#type_name' => $node->type, |
|
| 792 | - '#formatter' => $formatter_name, |
|
| 793 | - '#node' => $node, |
|
| 794 | - ); |
|
| 795 | - if ($single) { |
|
| 796 | - foreach ($items as $delta => $item) { |
|
| 797 | - $element['items'][$delta] += $format_info; |
|
| 798 | - $element['items'][$delta]['#item']['#delta'] = $delta; |
|
| 837 | + if ($wrapper) { |
|
| 838 | + $element = $wrapper['field']; |
|
| 839 | + // '#single' is not set if the field is hidden or inaccessible. |
|
| 840 | + if (isset($element['#single'])) { |
|
| 841 | + if (!empty($element['#single'])) { |
|
| 842 | + // Single value formatter. |
|
| 843 | + foreach (element_children($element['items']) as $delta) { |
|
| 844 | + // '#chilren' is not set if the field is empty. |
|
| 845 | + $items[$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
|
| 799 | 846 | } |
| 800 | 847 | } |
| 801 | - else { |
|
| 802 | - $element['items'] += $format_info; |
|
| 848 | + elseif (isset($element['items']['#children'])) { |
|
| 849 | + // Multiple values formatter. |
|
| 850 | + $items[0]['view'] = $element['items']['#children']; |
|
| 803 | 851 | } |
| 804 | - |
|
| 805 | - // The wrapper lets us get the themed output for the whole field |
|
| 806 | - // to populate the $FIELD_NAME_rendered variable for node templates, |
|
| 807 | - // and hide it from the $content variable if needed. |
|
| 808 | - // See 'preprocess_node' op and theme_content_field_wrapper()? |
|
| 809 | - $wrapper = array( |
|
| 810 | - 'field' => $element, |
|
| 811 | - '#weight' => $field['widget']['weight'], |
|
| 812 | - '#post_render' => array('content_field_wrapper_post_render'), |
|
| 813 | - '#field_name' => $field['field_name'], |
|
| 814 | - '#type_name' => $node->type, |
|
| 815 | - '#context' => $context, |
|
| 816 | - ); |
|
| 817 | - |
|
| 818 | - $addition = array($field['field_name'] => $wrapper); |
|
| 819 | - } |
|
| 820 | - return $addition; |
|
| 821 | - |
|
| 822 | - case 'alter': |
|
| 823 | - // Add back the formatted values in the 'view' element, |
|
| 824 | - // so that tokens and node templates can use it. |
|
| 825 | - // Note: Doing this in 'preprocess_node' breaks token integration. |
|
| 826 | - |
|
| 827 | - // The location of the field's rendered output depends on whether the |
|
| 828 | - // field is in a fieldgroup or not. |
|
| 829 | - $wrapper = NULL; |
|
| 830 | - if (isset($node->content[$field['field_name']])) { |
|
| 831 | - $wrapper = $node->content[$field['field_name']]; |
|
| 832 | 852 | } |
| 833 | - elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
| 834 | - $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - if ($wrapper) { |
|
| 838 | - $element = $wrapper['field']; |
|
| 839 | - // '#single' is not set if the field is hidden or inaccessible. |
|
| 840 | - if (isset($element['#single'])) { |
|
| 841 | - if (!empty($element['#single'])) { |
|
| 842 | - // Single value formatter. |
|
| 843 | - foreach (element_children($element['items']) as $delta) { |
|
| 844 | - // '#chilren' is not set if the field is empty. |
|
| 845 | - $items[$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
|
| 846 | - } |
|
| 847 | - } |
|
| 848 | - elseif (isset($element['items']['#children'])) { |
|
| 849 | - // Multiple values formatter. |
|
| 850 | - $items[0]['view'] = $element['items']['#children']; |
|
| 851 | - } |
|
| 852 | - } |
|
| 853 | - else { |
|
| 854 | - // Hidden or inaccessible field. |
|
| 855 | - $items[0]['view'] = ''; |
|
| 856 | - } |
|
| 853 | + else { |
|
| 854 | + // Hidden or inaccessible field. |
|
| 855 | + $items[0]['view'] = ''; |
|
| 857 | 856 | } |
| 858 | - break; |
|
| 857 | + } |
|
| 858 | + break; |
|
| 859 | 859 | |
| 860 | - case 'preprocess_node': |
|
| 861 | - // Add $FIELD_NAME_rendered variables. |
|
| 862 | - $addition = array(); |
|
| 860 | + case 'preprocess_node': |
|
| 861 | + // Add $FIELD_NAME_rendered variables. |
|
| 862 | + $addition = array(); |
|
| 863 | 863 | |
| 864 | - // The location of the field's rendered output depends on whether the |
|
| 865 | - // field is in a fieldgroup or not. |
|
| 866 | - $wrapper = NULL; |
|
| 867 | - if (isset($node->content[$field['field_name']])) { |
|
| 868 | - $wrapper = $node->content[$field['field_name']]; |
|
| 869 | - } |
|
| 870 | - elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
| 871 | - $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
|
| 872 | - } |
|
| 864 | + // The location of the field's rendered output depends on whether the |
|
| 865 | + // field is in a fieldgroup or not. |
|
| 866 | + $wrapper = NULL; |
|
| 867 | + if (isset($node->content[$field['field_name']])) { |
|
| 868 | + $wrapper = $node->content[$field['field_name']]; |
|
| 869 | + } |
|
| 870 | + elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
| 871 | + $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
|
| 872 | + } |
|
| 873 | 873 | |
| 874 | - if ($wrapper) { |
|
| 875 | - // '#chilren' is not set if the field is empty. |
|
| 876 | - $addition[$field['field_name'] .'_rendered'] = isset($wrapper['#children']) ? $wrapper['#children'] : ''; |
|
| 877 | - } |
|
| 874 | + if ($wrapper) { |
|
| 875 | + // '#chilren' is not set if the field is empty. |
|
| 876 | + $addition[$field['field_name'] .'_rendered'] = isset($wrapper['#children']) ? $wrapper['#children'] : ''; |
|
| 877 | + } |
|
| 878 | 878 | |
| 879 | - return $addition; |
|
| 879 | + return $addition; |
|
| 880 | 880 | |
| 881 | - case 'prepare translation': |
|
| 882 | - $addition = array(); |
|
| 883 | - if (isset($node->translation_source->$field['field_name'])) { |
|
| 884 | - $addition[$field['field_name']] = $node->translation_source->$field['field_name']; |
|
| 885 | - } |
|
| 886 | - return $addition; |
|
| 881 | + case 'prepare translation': |
|
| 882 | + $addition = array(); |
|
| 883 | + if (isset($node->translation_source->$field['field_name'])) { |
|
| 884 | + $addition[$field['field_name']] = $node->translation_source->$field['field_name']; |
|
| 885 | + } |
|
| 886 | + return $addition; |
|
| 887 | 887 | } |
| 888 | 888 | } |
| 889 | 889 | |
@@ -974,122 +974,122 @@ discard block |
||
| 974 | 974 | $type = content_types($type_name); |
| 975 | 975 | |
| 976 | 976 | switch ($op) { |
| 977 | - case 'load': |
|
| 978 | - // OPTIMIZE: load all non multiple fields in a single JOIN query ? |
|
| 979 | - // warning: 61-join limit in MySQL ? |
|
| 980 | - $additions = array(); |
|
| 981 | - // For each table used by this content type, |
|
| 982 | - foreach ($type['tables'] as $table) { |
|
| 983 | - $schema = drupal_get_schema($table); |
|
| 984 | - // The per-type table might not have any fields actually stored in it. |
|
| 985 | - if (!$schema['content fields']) { |
|
| 986 | - continue; |
|
| 987 | - } |
|
| 988 | - $query = 'SELECT * FROM {'. $table .'} WHERE vid = %d'; |
|
| 989 | - |
|
| 990 | - // If we're loading a table for a multiple field, |
|
| 991 | - // we fetch all rows (values) ordered by delta, |
|
| 992 | - // else we only fetch one row. |
|
| 993 | - $result = isset($schema['fields']['delta']) ? db_query($query .' ORDER BY delta', $node->vid) : db_query_range($query, $node->vid, 0, 1); |
|
| 994 | - |
|
| 995 | - // For each table row, populate the fields. |
|
| 996 | - while ($row = db_fetch_array($result)) { |
|
| 997 | - // For each field stored in the table, add the field item. |
|
| 998 | - foreach ($schema['content fields'] as $field_name) { |
|
| 999 | - $item = array(); |
|
| 1000 | - $field = content_fields($field_name, $type_name); |
|
| 1001 | - $db_info = content_database_info($field); |
|
| 1002 | - // For each column declared by the field, populate the item. |
|
| 1003 | - foreach ($db_info['columns'] as $column => $attributes) { |
|
| 1004 | - $item[$column] = $row[$attributes['column']]; |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - // Add the item to the field values for the node. |
|
| 1008 | - if (!isset($additions[$field_name])) { |
|
| 1009 | - $additions[$field_name] = array(); |
|
| 1010 | - } |
|
| 1011 | - $additions[$field_name][] = $item; |
|
| 1012 | - } |
|
| 1013 | - } |
|
| 977 | + case 'load': |
|
| 978 | + // OPTIMIZE: load all non multiple fields in a single JOIN query ? |
|
| 979 | + // warning: 61-join limit in MySQL ? |
|
| 980 | + $additions = array(); |
|
| 981 | + // For each table used by this content type, |
|
| 982 | + foreach ($type['tables'] as $table) { |
|
| 983 | + $schema = drupal_get_schema($table); |
|
| 984 | + // The per-type table might not have any fields actually stored in it. |
|
| 985 | + if (!$schema['content fields']) { |
|
| 986 | + continue; |
|
| 1014 | 987 | } |
| 1015 | - return $additions; |
|
| 988 | + $query = 'SELECT * FROM {'. $table .'} WHERE vid = %d'; |
|
| 989 | + |
|
| 990 | + // If we're loading a table for a multiple field, |
|
| 991 | + // we fetch all rows (values) ordered by delta, |
|
| 992 | + // else we only fetch one row. |
|
| 993 | + $result = isset($schema['fields']['delta']) ? db_query($query .' ORDER BY delta', $node->vid) : db_query_range($query, $node->vid, 0, 1); |
|
| 1016 | 994 | |
| 1017 | - case 'insert': |
|
| 1018 | - case 'update': |
|
| 1019 | - foreach ($type['tables'] as $table) { |
|
| 1020 | - $schema = drupal_get_schema($table); |
|
| 1021 | - $record = array(); |
|
| 995 | + // For each table row, populate the fields. |
|
| 996 | + while ($row = db_fetch_array($result)) { |
|
| 997 | + // For each field stored in the table, add the field item. |
|
| 1022 | 998 | foreach ($schema['content fields'] as $field_name) { |
| 1023 | - if (isset($node->$field_name)) { |
|
| 1024 | - $field = content_fields($field_name, $type_name); |
|
| 1025 | - // Multiple fields need specific handling, we'll deal with them later on. |
|
| 1026 | - if ($field['multiple']) { |
|
| 1027 | - continue; |
|
| 1028 | - } |
|
| 1029 | - $db_info = content_database_info($field); |
|
| 1030 | - foreach ($db_info['columns'] as $column => $attributes) { |
|
| 1031 | - $record[$attributes['column']] = $node->{$field_name}[0][$column]; |
|
| 1032 | - } |
|
| 999 | + $item = array(); |
|
| 1000 | + $field = content_fields($field_name, $type_name); |
|
| 1001 | + $db_info = content_database_info($field); |
|
| 1002 | + // For each column declared by the field, populate the item. |
|
| 1003 | + foreach ($db_info['columns'] as $column => $attributes) { |
|
| 1004 | + $item[$column] = $row[$attributes['column']]; |
|
| 1033 | 1005 | } |
| 1006 | + |
|
| 1007 | + // Add the item to the field values for the node. |
|
| 1008 | + if (!isset($additions[$field_name])) { |
|
| 1009 | + $additions[$field_name] = array(); |
|
| 1010 | + } |
|
| 1011 | + $additions[$field_name][] = $item; |
|
| 1034 | 1012 | } |
| 1035 | - // $record might be empty because |
|
| 1036 | - // - the table stores a multiple field : |
|
| 1037 | - // we do nothing, this is handled later on |
|
| 1038 | - // - this is the per-type table and no field is actually stored in it : |
|
| 1039 | - // we still store the nid and vid |
|
| 1040 | - if (count($record) || empty($schema['content fields'])) { |
|
| 1041 | - $record['nid'] = $node->nid; |
|
| 1042 | - $record['vid'] = $node->vid; |
|
| 1043 | - // Can't rely on the insert/update op of the node to decide if this |
|
| 1044 | - // is an insert or an update, a node or revision may have existed |
|
| 1045 | - // before any fields were created, so there may not be an entry here. |
|
| 1046 | - |
|
| 1047 | - // TODO - should we auto create an entry for all existing nodes when |
|
| 1048 | - // fields are added to content types -- either a NULL value |
|
| 1049 | - // or the default value? May need to offer the user an option of |
|
| 1050 | - // how to handle that. |
|
| 1051 | - if (db_result(db_query("SELECT COUNT(*) FROM {". $table ."} WHERE vid = %d", $node->vid))) { |
|
| 1052 | - content_write_record($table, $record, array('vid')); |
|
| 1013 | + } |
|
| 1014 | + } |
|
| 1015 | + return $additions; |
|
| 1016 | + |
|
| 1017 | + case 'insert': |
|
| 1018 | + case 'update': |
|
| 1019 | + foreach ($type['tables'] as $table) { |
|
| 1020 | + $schema = drupal_get_schema($table); |
|
| 1021 | + $record = array(); |
|
| 1022 | + foreach ($schema['content fields'] as $field_name) { |
|
| 1023 | + if (isset($node->$field_name)) { |
|
| 1024 | + $field = content_fields($field_name, $type_name); |
|
| 1025 | + // Multiple fields need specific handling, we'll deal with them later on. |
|
| 1026 | + if ($field['multiple']) { |
|
| 1027 | + continue; |
|
| 1053 | 1028 | } |
| 1054 | - else { |
|
| 1055 | - content_write_record($table, $record); |
|
| 1029 | + $db_info = content_database_info($field); |
|
| 1030 | + foreach ($db_info['columns'] as $column => $attributes) { |
|
| 1031 | + $record[$attributes['column']] = $node->{$field_name}[0][$column]; |
|
| 1056 | 1032 | } |
| 1057 | 1033 | } |
| 1058 | 1034 | } |
| 1035 | + // $record might be empty because |
|
| 1036 | + // - the table stores a multiple field : |
|
| 1037 | + // we do nothing, this is handled later on |
|
| 1038 | + // - this is the per-type table and no field is actually stored in it : |
|
| 1039 | + // we still store the nid and vid |
|
| 1040 | + if (count($record) || empty($schema['content fields'])) { |
|
| 1041 | + $record['nid'] = $node->nid; |
|
| 1042 | + $record['vid'] = $node->vid; |
|
| 1043 | + // Can't rely on the insert/update op of the node to decide if this |
|
| 1044 | + // is an insert or an update, a node or revision may have existed |
|
| 1045 | + // before any fields were created, so there may not be an entry here. |
|
| 1046 | + |
|
| 1047 | + // TODO - should we auto create an entry for all existing nodes when |
|
| 1048 | + // fields are added to content types -- either a NULL value |
|
| 1049 | + // or the default value? May need to offer the user an option of |
|
| 1050 | + // how to handle that. |
|
| 1051 | + if (db_result(db_query("SELECT COUNT(*) FROM {". $table ."} WHERE vid = %d", $node->vid))) { |
|
| 1052 | + content_write_record($table, $record, array('vid')); |
|
| 1053 | + } |
|
| 1054 | + else { |
|
| 1055 | + content_write_record($table, $record); |
|
| 1056 | + } |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | 1059 | |
| 1060 | - // Handle multiple fields. |
|
| 1061 | - foreach ($type['fields'] as $field) { |
|
| 1062 | - if ($field['multiple'] && isset($node->$field['field_name'])) { |
|
| 1063 | - $db_info = content_database_info($field); |
|
| 1064 | - // Delete and insert, rather than update, in case a value was added. |
|
| 1065 | - if ($op == 'update') { |
|
| 1066 | - db_query('DELETE FROM {'. $db_info['table'] .'} WHERE vid = %d', $node->vid); |
|
| 1067 | - } |
|
| 1068 | - foreach ($node->$field['field_name'] as $delta => $item) { |
|
| 1069 | - $record = array(); |
|
| 1070 | - foreach ($db_info['columns'] as $column => $attributes) { |
|
| 1071 | - $record[$attributes['column']] = $item[$column]; |
|
| 1072 | - } |
|
| 1073 | - $record['nid'] = $node->nid; |
|
| 1074 | - $record['vid'] = $node->vid; |
|
| 1075 | - $record['delta'] = $delta; |
|
| 1076 | - content_write_record($db_info['table'], $record); |
|
| 1060 | + // Handle multiple fields. |
|
| 1061 | + foreach ($type['fields'] as $field) { |
|
| 1062 | + if ($field['multiple'] && isset($node->$field['field_name'])) { |
|
| 1063 | + $db_info = content_database_info($field); |
|
| 1064 | + // Delete and insert, rather than update, in case a value was added. |
|
| 1065 | + if ($op == 'update') { |
|
| 1066 | + db_query('DELETE FROM {'. $db_info['table'] .'} WHERE vid = %d', $node->vid); |
|
| 1067 | + } |
|
| 1068 | + foreach ($node->$field['field_name'] as $delta => $item) { |
|
| 1069 | + $record = array(); |
|
| 1070 | + foreach ($db_info['columns'] as $column => $attributes) { |
|
| 1071 | + $record[$attributes['column']] = $item[$column]; |
|
| 1077 | 1072 | } |
| 1073 | + $record['nid'] = $node->nid; |
|
| 1074 | + $record['vid'] = $node->vid; |
|
| 1075 | + $record['delta'] = $delta; |
|
| 1076 | + content_write_record($db_info['table'], $record); |
|
| 1078 | 1077 | } |
| 1079 | 1078 | } |
| 1080 | - break; |
|
| 1079 | + } |
|
| 1080 | + break; |
|
| 1081 | 1081 | |
| 1082 | - case 'delete': |
|
| 1083 | - foreach ($type['tables'] as $table) { |
|
| 1084 | - db_query('DELETE FROM {'. $table .'} WHERE nid = %d', $node->nid); |
|
| 1085 | - } |
|
| 1086 | - break; |
|
| 1082 | + case 'delete': |
|
| 1083 | + foreach ($type['tables'] as $table) { |
|
| 1084 | + db_query('DELETE FROM {'. $table .'} WHERE nid = %d', $node->nid); |
|
| 1085 | + } |
|
| 1086 | + break; |
|
| 1087 | 1087 | |
| 1088 | - case 'delete revision': |
|
| 1089 | - foreach ($type['tables'] as $table) { |
|
| 1090 | - db_query('DELETE FROM {'. $table .'} WHERE vid = %d', $node->vid); |
|
| 1091 | - } |
|
| 1092 | - break; |
|
| 1088 | + case 'delete revision': |
|
| 1089 | + foreach ($type['tables'] as $table) { |
|
| 1090 | + db_query('DELETE FROM {'. $table .'} WHERE vid = %d', $node->vid); |
|
| 1091 | + } |
|
| 1092 | + break; |
|
| 1093 | 1093 | } |
| 1094 | 1094 | } |
| 1095 | 1095 | |
@@ -1526,18 +1526,18 @@ discard block |
||
| 1526 | 1526 | */ |
| 1527 | 1527 | function content_node_type($op, $info) { |
| 1528 | 1528 | switch ($op) { |
| 1529 | - case 'insert': |
|
| 1530 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 1531 | - content_type_create($info); |
|
| 1532 | - break; |
|
| 1533 | - case 'update': |
|
| 1534 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 1535 | - content_type_update($info); |
|
| 1536 | - break; |
|
| 1537 | - case 'delete': |
|
| 1538 | - module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 1539 | - content_type_delete($info); |
|
| 1540 | - break; |
|
| 1529 | + case 'insert': |
|
| 1530 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 1531 | + content_type_create($info); |
|
| 1532 | + break; |
|
| 1533 | + case 'update': |
|
| 1534 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 1535 | + content_type_update($info); |
|
| 1536 | + break; |
|
| 1537 | + case 'delete': |
|
| 1538 | + module_load_include('inc', 'content', 'includes/content.crud'); |
|
| 1539 | + content_type_delete($info); |
|
| 1540 | + break; |
|
| 1541 | 1541 | } |
| 1542 | 1542 | } |
| 1543 | 1543 | |
@@ -1994,14 +1994,14 @@ discard block |
||
| 1994 | 1994 | |
| 1995 | 1995 | $name = str_replace('-', '_', $name); |
| 1996 | 1996 | switch ("$version-$storage") { |
| 1997 | - case '0-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
|
| 1998 | - return "node_$name"; |
|
| 1999 | - case '0-'. CONTENT_DB_STORAGE_PER_FIELD : |
|
| 2000 | - return "node_data_$name"; |
|
| 2001 | - case '1003-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
|
| 2002 | - return "content_type_$name"; |
|
| 2003 | - case '1003-'. CONTENT_DB_STORAGE_PER_FIELD : |
|
| 2004 | - return "content_$name"; |
|
| 1997 | + case '0-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
|
| 1998 | + return "node_$name"; |
|
| 1999 | + case '0-'. CONTENT_DB_STORAGE_PER_FIELD : |
|
| 2000 | + return "node_data_$name"; |
|
| 2001 | + case '1003-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
|
| 2002 | + return "content_type_$name"; |
|
| 2003 | + case '1003-'. CONTENT_DB_STORAGE_PER_FIELD : |
|
| 2004 | + return "content_$name"; |
|
| 2005 | 2005 | } |
| 2006 | 2006 | } |
| 2007 | 2007 | |
@@ -2153,13 +2153,13 @@ discard block |
||
| 2153 | 2153 | */ |
| 2154 | 2154 | function content_callback($entity, $op, $field) { |
| 2155 | 2155 | switch ($entity) { |
| 2156 | - case 'field': |
|
| 2157 | - $info = module_invoke($field['module'], "field_info"); |
|
| 2158 | - return isset($info[$field['type']]['callbacks'][$op]) ? $info[$field['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
| 2156 | + case 'field': |
|
| 2157 | + $info = module_invoke($field['module'], "field_info"); |
|
| 2158 | + return isset($info[$field['type']]['callbacks'][$op]) ? $info[$field['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
| 2159 | 2159 | |
| 2160 | - case 'widget': |
|
| 2161 | - $info = module_invoke($field['widget']['module'], "widget_info"); |
|
| 2162 | - return isset($info[$field['widget']['type']]['callbacks'][$op]) ? $info[$field['widget']['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
| 2160 | + case 'widget': |
|
| 2161 | + $info = module_invoke($field['widget']['module'], "widget_info"); |
|
| 2162 | + return isset($info[$field['widget']['type']]['callbacks'][$op]) ? $info[$field['widget']['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT; |
|
| 2163 | 2163 | } |
| 2164 | 2164 | } |
| 2165 | 2165 | |
@@ -2183,18 +2183,18 @@ discard block |
||
| 2183 | 2183 | */ |
| 2184 | 2184 | function content_handle($entity, $op, $object) { |
| 2185 | 2185 | switch ($entity) { |
| 2186 | - case 'field': |
|
| 2187 | - $info = module_invoke($object['module'], "field_info"); |
|
| 2188 | - return isset($info[$object['type']][$op]) ? $info[$object['type']][$op] : CONTENT_HANDLE_CORE; |
|
| 2189 | - |
|
| 2190 | - case 'widget': |
|
| 2191 | - $info = module_invoke($object['widget']['module'], "widget_info"); |
|
| 2192 | - return isset($info[$object['widget']['type']][$op]) ? $info[$object['widget']['type']][$op] : CONTENT_HANDLE_CORE; |
|
| 2193 | - |
|
| 2194 | - case 'formatter': |
|
| 2195 | - // Much simpler, formatters arrays *are* the 'formatter_info' itself. |
|
| 2196 | - // We let content_handle deal with them only for code consistency. |
|
| 2197 | - return isset($object[$op]) ? $object[$op] : CONTENT_HANDLE_CORE; |
|
| 2186 | + case 'field': |
|
| 2187 | + $info = module_invoke($object['module'], "field_info"); |
|
| 2188 | + return isset($info[$object['type']][$op]) ? $info[$object['type']][$op] : CONTENT_HANDLE_CORE; |
|
| 2189 | + |
|
| 2190 | + case 'widget': |
|
| 2191 | + $info = module_invoke($object['widget']['module'], "widget_info"); |
|
| 2192 | + return isset($info[$object['widget']['type']][$op]) ? $info[$object['widget']['type']][$op] : CONTENT_HANDLE_CORE; |
|
| 2193 | + |
|
| 2194 | + case 'formatter': |
|
| 2195 | + // Much simpler, formatters arrays *are* the 'formatter_info' itself. |
|
| 2196 | + // We let content_handle deal with them only for code consistency. |
|
| 2197 | + return isset($object[$op]) ? $object[$op] : CONTENT_HANDLE_CORE; |
|
| 2198 | 2198 | } |
| 2199 | 2199 | } |
| 2200 | 2200 | |
@@ -18,17 +18,17 @@ discard block |
||
| 18 | 18 | function content_help($path, $arg) { |
| 19 | 19 | switch ($path) { |
| 20 | 20 | case 'admin/help#content': |
| 21 | - $output = '<p>'. t('The content module, a required component of the Content Construction Kit (CCK), allows administrators to associate custom fields with content types. In Drupal, content types are used to define the characteristics of a post, including the title and description of the fields displayed on its add and edit pages. Using the content module (and the other helper modules included in CCK), custom fields beyond the default "Title" and "Body" may be added. CCK features are accessible through tabs on the <a href="@content-types">content types administration page</a>. (See the <a href="@node-help">node module help page</a> for more information about content types.)', array('@content-types' => url('admin/content/types'), '@node-help' => url('admin/help/node'))) .'</p>'; |
|
| 22 | - $output .= '<p>'. t('When adding a custom field to a content type, you determine its type (whether it will contain text, numbers, or references to other objects) and how it will be displayed (either as a text field or area, a select box, checkbox, radio button, or autocompleting field). A field may have multiple values (i.e., a "person" may have multiple e-mail addresses) or a single value (i.e., an "employee" has a single employee identification number). As you add and edit fields, CCK automatically adjusts the structure of the database as necessary. CCK also provides a number of other features, including intelligent caching for your custom data, an import and export facility for content type definitions, and integration with other contributed modules.') .'</p>'; |
|
| 23 | - $output .= '<p>'. t('Custom field types are provided by a set of optional modules included with CCK (each module provides a different type). The <a href="@modules">modules page</a> allows you to enable or disable CCK components. A default installation of CCK includes:', array('@modules' => url('admin/build/modules'))) .'</p>'; |
|
| 21 | + $output = '<p>'.t('The content module, a required component of the Content Construction Kit (CCK), allows administrators to associate custom fields with content types. In Drupal, content types are used to define the characteristics of a post, including the title and description of the fields displayed on its add and edit pages. Using the content module (and the other helper modules included in CCK), custom fields beyond the default "Title" and "Body" may be added. CCK features are accessible through tabs on the <a href="@content-types">content types administration page</a>. (See the <a href="@node-help">node module help page</a> for more information about content types.)', array('@content-types' => url('admin/content/types'), '@node-help' => url('admin/help/node'))).'</p>'; |
|
| 22 | + $output .= '<p>'.t('When adding a custom field to a content type, you determine its type (whether it will contain text, numbers, or references to other objects) and how it will be displayed (either as a text field or area, a select box, checkbox, radio button, or autocompleting field). A field may have multiple values (i.e., a "person" may have multiple e-mail addresses) or a single value (i.e., an "employee" has a single employee identification number). As you add and edit fields, CCK automatically adjusts the structure of the database as necessary. CCK also provides a number of other features, including intelligent caching for your custom data, an import and export facility for content type definitions, and integration with other contributed modules.').'</p>'; |
|
| 23 | + $output .= '<p>'.t('Custom field types are provided by a set of optional modules included with CCK (each module provides a different type). The <a href="@modules">modules page</a> allows you to enable or disable CCK components. A default installation of CCK includes:', array('@modules' => url('admin/build/modules'))).'</p>'; |
|
| 24 | 24 | $output .= '<ul>'; |
| 25 | - $output .= '<li>'. t('<em>number</em>, which adds numeric field types, in integer, decimal or floating point form. You may define a set of allowed inputs, or specify an allowable range of values. A variety of common formats for displaying numeric data are available.') .'</li>'; |
|
| 26 | - $output .= '<li>'. t("<em>text</em>, which adds text field types. A text field may contain plain text only, or optionally, may use Drupal's input format filters to securely manage rich text input. Text input fields may be either a single line (text field), multiple lines (text area), or for greater input control, a select box, checkbox, or radio buttons. If desired, CCK can validate the input to a set of allowed values.") .'</li>'; |
|
| 27 | - $output .= '<li>'. t('<em>nodereference</em>, which creates custom references between Drupal nodes. By adding a <em>nodereference</em> field and two different content types, for instance, you can easily create complex parent/child relationships between data (multiple "employee" nodes may contain a <em>nodereference</em> field linking to an "employer" node).') .'</li>'; |
|
| 28 | - $output .= '<li>'. t('<em>userreference</em>, which creates custom references to your sites\' user accounts. By adding a <em>userreference</em> field, you can create complex relationships between your site\'s users and posts. To track user involvement in a post beyond Drupal\'s standard <em>Authored by</em> field, for instance, add a <em>userreference</em> field named "Edited by" to a content type to store a link to an editor\'s user account page.') .'</li>'; |
|
| 29 | - $output .= '<li>'. t('<em>fieldgroup</em>, which creates collapsible fieldsets to hold a group of related fields. A fieldset may either be open or closed by default. The order of your fieldsets, and the order of fields within a fieldset, is managed via a drag-and-drop interface provided by content module.') .'</li>'; |
|
| 25 | + $output .= '<li>'.t('<em>number</em>, which adds numeric field types, in integer, decimal or floating point form. You may define a set of allowed inputs, or specify an allowable range of values. A variety of common formats for displaying numeric data are available.').'</li>'; |
|
| 26 | + $output .= '<li>'.t("<em>text</em>, which adds text field types. A text field may contain plain text only, or optionally, may use Drupal's input format filters to securely manage rich text input. Text input fields may be either a single line (text field), multiple lines (text area), or for greater input control, a select box, checkbox, or radio buttons. If desired, CCK can validate the input to a set of allowed values.").'</li>'; |
|
| 27 | + $output .= '<li>'.t('<em>nodereference</em>, which creates custom references between Drupal nodes. By adding a <em>nodereference</em> field and two different content types, for instance, you can easily create complex parent/child relationships between data (multiple "employee" nodes may contain a <em>nodereference</em> field linking to an "employer" node).').'</li>'; |
|
| 28 | + $output .= '<li>'.t('<em>userreference</em>, which creates custom references to your sites\' user accounts. By adding a <em>userreference</em> field, you can create complex relationships between your site\'s users and posts. To track user involvement in a post beyond Drupal\'s standard <em>Authored by</em> field, for instance, add a <em>userreference</em> field named "Edited by" to a content type to store a link to an editor\'s user account page.').'</li>'; |
|
| 29 | + $output .= '<li>'.t('<em>fieldgroup</em>, which creates collapsible fieldsets to hold a group of related fields. A fieldset may either be open or closed by default. The order of your fieldsets, and the order of fields within a fieldset, is managed via a drag-and-drop interface provided by content module.').'</li>'; |
|
| 30 | 30 | $output .= '</ul>'; |
| 31 | - $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@handbook-cck">CCK</a> or the <a href="@project-cck">CCK project page</a>.', array('@handbook-cck' => 'http://drupal.org/handbook/modules/cck', '@project-cck' => 'http://drupal.org/project/cck')) .'</p>'; |
|
| 31 | + $output .= '<p>'.t('For more information, see the online handbook entry for <a href="@handbook-cck">CCK</a> or the <a href="@project-cck">CCK project page</a>.', array('@handbook-cck' => 'http://drupal.org/handbook/modules/cck', '@project-cck' => 'http://drupal.org/project/cck')).'</p>'; |
|
| 32 | 32 | return $output; |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * Implementation of hook_init(). |
| 45 | 45 | */ |
| 46 | 46 | function content_init() { |
| 47 | - drupal_add_css(drupal_get_path('module', 'content') .'/theme/content-module.css'); |
|
| 47 | + drupal_add_css(drupal_get_path('module', 'content').'/theme/content-module.css'); |
|
| 48 | 48 | if (module_exists('token') && !function_exists('content_token_values')) { |
| 49 | 49 | module_load_include('inc', 'content', 'includes/content.token'); |
| 50 | 50 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | // Customize the content types page with our own callback |
| 68 | 68 | $items['admin/content/types']['page callback'] = 'content_types_overview'; |
| 69 | 69 | $items['admin/content/types']['file'] = 'content.admin.inc'; |
| 70 | - $items['admin/content/types']['file path'] = drupal_get_path('module', 'content') .'/includes'; |
|
| 70 | + $items['admin/content/types']['file path'] = drupal_get_path('module', 'content').'/includes'; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $type_name = $type->type; |
| 98 | 98 | $content_type = content_types($type_name); |
| 99 | 99 | $type_url_str = $content_type['url_str']; |
| 100 | - $items['admin/content/node-type/'. $type_url_str .'/fields'] = array( |
|
| 100 | + $items['admin/content/node-type/'.$type_url_str.'/fields'] = array( |
|
| 101 | 101 | 'title' => 'Manage fields', |
| 102 | 102 | 'page callback' => 'drupal_get_form', |
| 103 | 103 | 'page arguments' => array('content_field_overview_form', $type_name), |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | 'type' => MENU_LOCAL_TASK, |
| 107 | 107 | 'weight' => 1, |
| 108 | 108 | ); |
| 109 | - $items['admin/content/node-type/'. $type_url_str .'/display'] = array( |
|
| 109 | + $items['admin/content/node-type/'.$type_url_str.'/display'] = array( |
|
| 110 | 110 | 'title' => 'Display fields', |
| 111 | 111 | 'page callback' => 'drupal_get_form', |
| 112 | 112 | 'page arguments' => array('content_display_overview_form', $type_name), |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | ); |
| 118 | 118 | $contexts = content_build_modes('_tabs'); |
| 119 | 119 | foreach ($contexts as $key => $tab) { |
| 120 | - $items['admin/content/node-type/'. $type_url_str .'/display/'. $key] = array( |
|
| 120 | + $items['admin/content/node-type/'.$type_url_str.'/display/'.$key] = array( |
|
| 121 | 121 | 'title' => $tab['title'], |
| 122 | 122 | 'page arguments' => array('content_display_overview_form', $type_name, $key), |
| 123 | 123 | 'access arguments' => array('administer content types'), |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | // Cast as an array in case this is called before any fields have |
| 129 | 129 | // been added, like when a new content type is created. |
| 130 | - foreach ((array) $content_type['fields'] as $field) { |
|
| 130 | + foreach ((array)$content_type['fields'] as $field) { |
|
| 131 | 131 | $field_name = $field['field_name']; |
| 132 | - $items['admin/content/node-type/'. $type_url_str .'/fields/'. $field_name] = array( |
|
| 132 | + $items['admin/content/node-type/'.$type_url_str.'/fields/'.$field_name] = array( |
|
| 133 | 133 | 'title' => $field['widget']['label'], |
| 134 | 134 | 'page callback' => 'drupal_get_form', |
| 135 | 135 | 'page arguments' => array('content_field_edit_form', $type_name, $field_name), |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | 'file' => 'includes/content.admin.inc', |
| 138 | 138 | 'type' => MENU_LOCAL_TASK, |
| 139 | 139 | ); |
| 140 | - $items['admin/content/node-type/'. $type_url_str .'/fields/'. $field_name .'/remove'] = array( |
|
| 140 | + $items['admin/content/node-type/'.$type_url_str.'/fields/'.$field_name.'/remove'] = array( |
|
| 141 | 141 | 'title' => 'Remove field', |
| 142 | 142 | 'page callback' => 'drupal_get_form', |
| 143 | 143 | 'page arguments' => array('content_field_remove_form', $type_name, $field_name), |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | * Implementation of hook_theme(). |
| 174 | 174 | */ |
| 175 | 175 | function content_theme() { |
| 176 | - $path = drupal_get_path('module', 'content') .'/theme'; |
|
| 176 | + $path = drupal_get_path('module', 'content').'/theme'; |
|
| 177 | 177 | require_once "./$path/theme.inc"; |
| 178 | 178 | |
| 179 | 179 | return array( |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | function content_views_api() { |
| 216 | 216 | return array( |
| 217 | 217 | 'api' => 2, |
| 218 | - 'path' => drupal_get_path('module', 'content') . '/includes/views', |
|
| 218 | + 'path' => drupal_get_path('module', 'content').'/includes/views', |
|
| 219 | 219 | ); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | function content_ctools_plugin_directory($module, $plugin) { |
| 226 | 226 | if ($module == 'ctools' && $plugin == 'content_types') { |
| 227 | - return 'includes/panels/' . $plugin; |
|
| 227 | + return 'includes/panels/'.$plugin; |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | * cache the loaded object structure and invalidate it during the update process. |
| 238 | 238 | */ |
| 239 | 239 | function content_load(&$node) { |
| 240 | - $cid = 'content:'. $node->nid .':'. $node->vid; |
|
| 240 | + $cid = 'content:'.$node->nid.':'.$node->vid; |
|
| 241 | 241 | if ($cached = cache_get($cid, content_cache_tablename())) { |
| 242 | 242 | foreach ($cached->data as $key => $value) { |
| 243 | 243 | $node->$key = $value; |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | function content_update(&$node) { |
| 298 | 298 | _content_field_invoke('update', $node); |
| 299 | 299 | _content_field_invoke_default('update', $node); |
| 300 | - cache_clear_all('content:'. $node->nid .':'. $node->vid, content_cache_tablename()); |
|
| 300 | + cache_clear_all('content:'.$node->nid.':'.$node->vid, content_cache_tablename()); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | /** |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | function content_delete(&$node) { |
| 309 | 309 | _content_field_invoke('delete', $node); |
| 310 | 310 | _content_field_invoke_default('delete', $node); |
| 311 | - cache_clear_all('content:'. $node->nid .':', content_cache_tablename(), TRUE); |
|
| 311 | + cache_clear_all('content:'.$node->nid.':', content_cache_tablename(), TRUE); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | function content_delete_revision(&$node) { |
| 320 | 320 | _content_field_invoke('delete revision', $node); |
| 321 | 321 | _content_field_invoke_default('delete revision', $node); |
| 322 | - cache_clear_all('content:'. $node->nid .':'. $node->vid, content_cache_tablename()); |
|
| 322 | + cache_clear_all('content:'.$node->nid.':'.$node->vid, content_cache_tablename()); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | |
| 334 | 334 | // Merge fields. |
| 335 | 335 | $additions = _content_field_invoke_default('view', $node, $teaser, $page); |
| 336 | - $node->content = array_merge((array) $node->content, $additions); |
|
| 336 | + $node->content = array_merge((array)$node->content, $additions); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | // One-field equivalent to _content_field_invoke('sanitize'). |
| 372 | 372 | $field_types = _content_field_types(); |
| 373 | 373 | $module = $field_types[$field['type']]['module']; |
| 374 | - $function = $module .'_field'; |
|
| 374 | + $function = $module.'_field'; |
|
| 375 | 375 | if (function_exists($function)) { |
| 376 | 376 | $function('sanitize', $node, $field, $items, $teaser, $page); |
| 377 | 377 | $node->$field['field_name'] = $items; |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | $additions = _content_field_invoke('prepare translation', $node); |
| 406 | 406 | // Merge module additions after the default ones to enable overriding |
| 407 | 407 | // of field values. |
| 408 | - $node = (object) array_merge((array) $node, $default_additions, $additions); |
|
| 408 | + $node = (object)array_merge((array)$node, $default_additions, $additions); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | $type = content_types($node->type); |
| 418 | 418 | // Save cycles if the type has no CCK fields. |
| 419 | 419 | if (!empty($type['fields'])) { |
| 420 | - $callback = 'content_'. str_replace(' ', '_', $op); |
|
| 420 | + $callback = 'content_'.str_replace(' ', '_', $op); |
|
| 421 | 421 | if (function_exists($callback)) { |
| 422 | 422 | $callback($node, $a3, $a4); |
| 423 | 423 | } |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | * Implementation of hook_form_alter(). |
| 437 | 437 | */ |
| 438 | 438 | function content_form_alter(&$form, $form_state, $form_id) { |
| 439 | - if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { |
|
| 439 | + if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'].'_node_form' == $form_id) { |
|
| 440 | 440 | $type = content_types($form['#node']->type); |
| 441 | 441 | if (!empty($type['fields'])) { |
| 442 | 442 | module_load_include('inc', 'content', 'includes/content.node_form'); |
@@ -487,9 +487,9 @@ discard block |
||
| 487 | 487 | $output = ''; |
| 488 | 488 | |
| 489 | 489 | if ($field['multiple'] >= 1) { |
| 490 | - $table_id = $element['#field_name'] .'_values'; |
|
| 491 | - $order_class = $element['#field_name'] .'-delta-order'; |
|
| 492 | - $required = !empty($element['#required']) ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : ''; |
|
| 490 | + $table_id = $element['#field_name'].'_values'; |
|
| 491 | + $order_class = $element['#field_name'].'-delta-order'; |
|
| 492 | + $required = !empty($element['#required']) ? '<span class="form-required" title="'.t('This field is required.').'">*</span>' : ''; |
|
| 493 | 493 | |
| 494 | 494 | $header = array( |
| 495 | 495 | array( |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | // preview or failed validation) |
| 505 | 505 | $items = array(); |
| 506 | 506 | foreach (element_children($element) as $key) { |
| 507 | - if ($key !== $element['#field_name'] .'_add_more') { |
|
| 507 | + if ($key !== $element['#field_name'].'_add_more') { |
|
| 508 | 508 | $items[] = &$element[$key]; |
| 509 | 509 | } |
| 510 | 510 | } |
@@ -526,8 +526,8 @@ discard block |
||
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | $output .= theme('table', $header, $rows, array('id' => $table_id, 'class' => 'content-multiple-table')); |
| 529 | - $output .= $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : ''; |
|
| 530 | - $output .= drupal_render($element[$element['#field_name'] .'_add_more']); |
|
| 529 | + $output .= $element['#description'] ? '<div class="description">'.$element['#description'].'</div>' : ''; |
|
| 530 | + $output .= drupal_render($element[$element['#field_name'].'_add_more']); |
|
| 531 | 531 | |
| 532 | 532 | drupal_add_tabledrag($table_id, 'order', 'sibling', $order_class); |
| 533 | 533 | } |
@@ -570,8 +570,8 @@ discard block |
||
| 570 | 570 | if (variable_get('content_schema_version', -1) < 6007) { |
| 571 | 571 | return FALSE; |
| 572 | 572 | } |
| 573 | - db_query("UPDATE {". content_field_tablename() ."} SET active=0 WHERE module='%s'", $module); |
|
| 574 | - db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=0 WHERE widget_module='%s'", $module); |
|
| 573 | + db_query("UPDATE {".content_field_tablename()."} SET active=0 WHERE module='%s'", $module); |
|
| 574 | + db_query("UPDATE {".content_instance_tablename()."} SET widget_active=0 WHERE widget_module='%s'", $module); |
|
| 575 | 575 | content_clear_type_cache(TRUE); |
| 576 | 576 | break; |
| 577 | 577 | } |
@@ -593,14 +593,14 @@ discard block |
||
| 593 | 593 | if ($module_fields) { |
| 594 | 594 | foreach ($module_fields as $name => $field_info) { |
| 595 | 595 | watchdog('content', 'Updating field type %type with module %module.', array('%type' => $name, '%module' => $module)); |
| 596 | - db_query("UPDATE {". content_field_tablename() ."} SET module = '%s', active = %d WHERE type = '%s'", $module, 1, $name); |
|
| 596 | + db_query("UPDATE {".content_field_tablename()."} SET module = '%s', active = %d WHERE type = '%s'", $module, 1, $name); |
|
| 597 | 597 | } |
| 598 | 598 | } |
| 599 | 599 | $module_widgets = module_invoke($module, 'widget_info'); |
| 600 | 600 | if ($module_widgets) { |
| 601 | 601 | foreach ($module_widgets as $name => $widget_info) { |
| 602 | 602 | watchdog('content', 'Updating widget type %type with module %module.', array('%type' => $name, '%module' => $module)); |
| 603 | - db_query("UPDATE {". content_instance_tablename() ."} SET widget_module = '%s', widget_active = %d WHERE widget_type = '%s'", $module, 1, $name); |
|
| 603 | + db_query("UPDATE {".content_instance_tablename()."} SET widget_module = '%s', widget_active = %d WHERE widget_type = '%s'", $module, 1, $name); |
|
| 604 | 604 | } |
| 605 | 605 | } |
| 606 | 606 | // This is called from updates and installs, so get the install-safe |
@@ -611,8 +611,8 @@ discard block |
||
| 611 | 611 | foreach ($types as $type_name => $fields) { |
| 612 | 612 | foreach ($fields as $field) { |
| 613 | 613 | if ($field['module'] == $module && !in_array($field['field_name'], $fields_set)) { |
| 614 | - $columns = (array) module_invoke($field['module'], 'field_settings', 'database columns', $field); |
|
| 615 | - db_query("UPDATE {". content_field_tablename() ."} SET db_columns = '%s' WHERE field_name = '%s'", serialize($columns), $field['field_name']); |
|
| 614 | + $columns = (array)module_invoke($field['module'], 'field_settings', 'database columns', $field); |
|
| 615 | + db_query("UPDATE {".content_field_tablename()."} SET db_columns = '%s' WHERE field_name = '%s'", serialize($columns), $field['field_name']); |
|
| 616 | 616 | $fields_set[] = $field['field_name']; |
| 617 | 617 | } |
| 618 | 618 | } |
@@ -696,7 +696,7 @@ discard block |
||
| 696 | 696 | |
| 697 | 697 | case 'presave': |
| 698 | 698 | if (!empty($node->devel_generate)) { |
| 699 | - include_once('./'. drupal_get_path('module', 'content') .'/includes/content.devel.inc'); |
|
| 699 | + include_once('./'.drupal_get_path('module', 'content').'/includes/content.devel.inc'); |
|
| 700 | 700 | content_generate_fields($node, $field); |
| 701 | 701 | $items = $node->{$field['field_name']}; |
| 702 | 702 | } |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | |
| 716 | 716 | // If there was an AHAH add more button in this field, don't save it. |
| 717 | 717 | // TODO: is it still needed ? |
| 718 | - unset($items[$field['field_name'] .'_add_more']); |
|
| 718 | + unset($items[$field['field_name'].'_add_more']); |
|
| 719 | 719 | |
| 720 | 720 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { |
| 721 | 721 | // Reorder items to account for drag-n-drop reordering. |
@@ -752,7 +752,7 @@ discard block |
||
| 752 | 752 | // enabled after the field was last edited. |
| 753 | 753 | $formatter_name = isset($field['display_settings'][$context]) && isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default'; |
| 754 | 754 | if ($formatter = _content_get_formatter($formatter_name, $field['type'])) { |
| 755 | - $theme = $formatter['module'] .'_formatter_'. $formatter_name; |
|
| 755 | + $theme = $formatter['module'].'_formatter_'.$formatter_name; |
|
| 756 | 756 | $single = (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE); |
| 757 | 757 | |
| 758 | 758 | $label_display = isset($field['display_settings']['label']['format']) ? $field['display_settings']['label']['format'] : 'above'; |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | $items[$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
| 846 | 846 | } |
| 847 | 847 | } |
| 848 | - elseif (isset($element['items']['#children'])) { |
|
| 848 | + elseif (isset($element['items']['#children'])) { |
|
| 849 | 849 | // Multiple values formatter. |
| 850 | 850 | $items[0]['view'] = $element['items']['#children']; |
| 851 | 851 | } |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | |
| 874 | 874 | if ($wrapper) { |
| 875 | 875 | // '#chilren' is not set if the field is empty. |
| 876 | - $addition[$field['field_name'] .'_rendered'] = isset($wrapper['#children']) ? $wrapper['#children'] : ''; |
|
| 876 | + $addition[$field['field_name'].'_rendered'] = isset($wrapper['#children']) ? $wrapper['#children'] : ''; |
|
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | return $addition; |
@@ -901,8 +901,8 @@ discard block |
||
| 901 | 901 | function content_set_empty($field, $items) { |
| 902 | 902 | // Filter out empty values. |
| 903 | 903 | $filtered = array(); |
| 904 | - $function = $field['module'] .'_content_is_empty'; |
|
| 905 | - foreach ((array) $items as $delta => $item) { |
|
| 904 | + $function = $field['module'].'_content_is_empty'; |
|
| 905 | + foreach ((array)$items as $delta => $item) { |
|
| 906 | 906 | if (!$function($item, $field)) { |
| 907 | 907 | $filtered[] = $item; |
| 908 | 908 | } |
@@ -985,12 +985,12 @@ discard block |
||
| 985 | 985 | if (!$schema['content fields']) { |
| 986 | 986 | continue; |
| 987 | 987 | } |
| 988 | - $query = 'SELECT * FROM {'. $table .'} WHERE vid = %d'; |
|
| 988 | + $query = 'SELECT * FROM {'.$table.'} WHERE vid = %d'; |
|
| 989 | 989 | |
| 990 | 990 | // If we're loading a table for a multiple field, |
| 991 | 991 | // we fetch all rows (values) ordered by delta, |
| 992 | 992 | // else we only fetch one row. |
| 993 | - $result = isset($schema['fields']['delta']) ? db_query($query .' ORDER BY delta', $node->vid) : db_query_range($query, $node->vid, 0, 1); |
|
| 993 | + $result = isset($schema['fields']['delta']) ? db_query($query.' ORDER BY delta', $node->vid) : db_query_range($query, $node->vid, 0, 1); |
|
| 994 | 994 | |
| 995 | 995 | // For each table row, populate the fields. |
| 996 | 996 | while ($row = db_fetch_array($result)) { |
@@ -1048,7 +1048,7 @@ discard block |
||
| 1048 | 1048 | // fields are added to content types -- either a NULL value |
| 1049 | 1049 | // or the default value? May need to offer the user an option of |
| 1050 | 1050 | // how to handle that. |
| 1051 | - if (db_result(db_query("SELECT COUNT(*) FROM {". $table ."} WHERE vid = %d", $node->vid))) { |
|
| 1051 | + if (db_result(db_query("SELECT COUNT(*) FROM {".$table."} WHERE vid = %d", $node->vid))) { |
|
| 1052 | 1052 | content_write_record($table, $record, array('vid')); |
| 1053 | 1053 | } |
| 1054 | 1054 | else { |
@@ -1063,7 +1063,7 @@ discard block |
||
| 1063 | 1063 | $db_info = content_database_info($field); |
| 1064 | 1064 | // Delete and insert, rather than update, in case a value was added. |
| 1065 | 1065 | if ($op == 'update') { |
| 1066 | - db_query('DELETE FROM {'. $db_info['table'] .'} WHERE vid = %d', $node->vid); |
|
| 1066 | + db_query('DELETE FROM {'.$db_info['table'].'} WHERE vid = %d', $node->vid); |
|
| 1067 | 1067 | } |
| 1068 | 1068 | foreach ($node->$field['field_name'] as $delta => $item) { |
| 1069 | 1069 | $record = array(); |
@@ -1081,13 +1081,13 @@ discard block |
||
| 1081 | 1081 | |
| 1082 | 1082 | case 'delete': |
| 1083 | 1083 | foreach ($type['tables'] as $table) { |
| 1084 | - db_query('DELETE FROM {'. $table .'} WHERE nid = %d', $node->nid); |
|
| 1084 | + db_query('DELETE FROM {'.$table.'} WHERE nid = %d', $node->nid); |
|
| 1085 | 1085 | } |
| 1086 | 1086 | break; |
| 1087 | 1087 | |
| 1088 | 1088 | case 'delete revision': |
| 1089 | 1089 | foreach ($type['tables'] as $table) { |
| 1090 | - db_query('DELETE FROM {'. $table .'} WHERE vid = %d', $node->vid); |
|
| 1090 | + db_query('DELETE FROM {'.$table.'} WHERE vid = %d', $node->vid); |
|
| 1091 | 1091 | } |
| 1092 | 1092 | break; |
| 1093 | 1093 | } |
@@ -1132,7 +1132,7 @@ discard block |
||
| 1132 | 1132 | |
| 1133 | 1133 | // Convert to an object if needed. |
| 1134 | 1134 | if (is_array($object)) { |
| 1135 | - $object = (object) $object; |
|
| 1135 | + $object = (object)$object; |
|
| 1136 | 1136 | $array = TRUE; |
| 1137 | 1137 | } |
| 1138 | 1138 | else { |
@@ -1188,7 +1188,7 @@ discard block |
||
| 1188 | 1188 | // Build the SQL. |
| 1189 | 1189 | $query = ''; |
| 1190 | 1190 | if (!count($update)) { |
| 1191 | - $query = "INSERT INTO {". $table ."} (". implode(', ', $fields) .') VALUES ('. implode(', ', $placeholders) .')'; |
|
| 1191 | + $query = "INSERT INTO {".$table."} (".implode(', ', $fields).') VALUES ('.implode(', ', $placeholders).')'; |
|
| 1192 | 1192 | $return = SAVED_NEW; |
| 1193 | 1193 | } |
| 1194 | 1194 | else { |
@@ -1197,15 +1197,15 @@ discard block |
||
| 1197 | 1197 | if ($query) { |
| 1198 | 1198 | $query .= ', '; |
| 1199 | 1199 | } |
| 1200 | - $query .= $field .' = '. $placeholders[$id]; |
|
| 1200 | + $query .= $field.' = '.$placeholders[$id]; |
|
| 1201 | 1201 | } |
| 1202 | 1202 | |
| 1203 | 1203 | foreach ($update as $key) { |
| 1204 | - $conditions[] = "$key = ". db_type_placeholder($schema['fields'][$key]['type']); |
|
| 1204 | + $conditions[] = "$key = ".db_type_placeholder($schema['fields'][$key]['type']); |
|
| 1205 | 1205 | $values[] = $object->$key; |
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | - $query = "UPDATE {". $table ."} SET $query WHERE ". implode(' AND ', $conditions); |
|
| 1208 | + $query = "UPDATE {".$table."} SET $query WHERE ".implode(' AND ', $conditions); |
|
| 1209 | 1209 | $return = SAVED_UPDATED; |
| 1210 | 1210 | } |
| 1211 | 1211 | |
@@ -1220,7 +1220,7 @@ discard block |
||
| 1220 | 1220 | |
| 1221 | 1221 | // If we began with an array, convert back so we don't surprise the caller. |
| 1222 | 1222 | if ($array) { |
| 1223 | - $object = (array) $object; |
|
| 1223 | + $object = (array)$object; |
|
| 1224 | 1224 | } |
| 1225 | 1225 | |
| 1226 | 1226 | return $return; |
@@ -1245,10 +1245,10 @@ discard block |
||
| 1245 | 1245 | $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array(); |
| 1246 | 1246 | |
| 1247 | 1247 | // Make sure AHAH 'add more' button isn't sent to the fields for processing. |
| 1248 | - unset($items[$field['field_name'] .'_add_more']); |
|
| 1248 | + unset($items[$field['field_name'].'_add_more']); |
|
| 1249 | 1249 | |
| 1250 | 1250 | $module = $field_types[$field['type']]['module']; |
| 1251 | - $function = $module .'_field'; |
|
| 1251 | + $function = $module.'_field'; |
|
| 1252 | 1252 | if (function_exists($function)) { |
| 1253 | 1253 | $result = $function($op, $node, $field, $items, $teaser, $page); |
| 1254 | 1254 | if (is_array($result)) { |
@@ -1408,7 +1408,7 @@ discard block |
||
| 1408 | 1408 | return array(); |
| 1409 | 1409 | } |
| 1410 | 1410 | |
| 1411 | - if (!$reset && $cached = cache_get('content_type_info:'. $language->language, content_cache_tablename())) { |
|
| 1411 | + if (!$reset && $cached = cache_get('content_type_info:'.$language->language, content_cache_tablename())) { |
|
| 1412 | 1412 | $info = $cached->data; |
| 1413 | 1413 | } |
| 1414 | 1414 | else { |
@@ -1469,7 +1469,7 @@ discard block |
||
| 1469 | 1469 | // Populate actual field instances. |
| 1470 | 1470 | module_load_include('inc', 'content', 'includes/content.crud'); |
| 1471 | 1471 | foreach (node_get_types('types', NULL, TRUE) as $type_name => $data) { |
| 1472 | - $type = (array) $data; |
|
| 1472 | + $type = (array)$data; |
|
| 1473 | 1473 | $type['url_str'] = str_replace('_', '-', $type['type']); |
| 1474 | 1474 | $type['fields'] = array(); |
| 1475 | 1475 | $type['tables'] = array(); |
@@ -1502,7 +1502,7 @@ discard block |
||
| 1502 | 1502 | $extra = module_invoke_all('content_extra_fields', $type_name); |
| 1503 | 1503 | drupal_alter('content_extra_fields', $extra, $type_name); |
| 1504 | 1504 | // Add saved weights. |
| 1505 | - foreach (variable_get('content_extra_weights_'. $type_name, array()) as $key => $value) { |
|
| 1505 | + foreach (variable_get('content_extra_weights_'.$type_name, array()) as $key => $value) { |
|
| 1506 | 1506 | // Some stored entries might not exist anymore, for instance if uploads |
| 1507 | 1507 | // have been disabled, or vocabularies removed... |
| 1508 | 1508 | if (isset($extra[$key])) { |
@@ -1514,7 +1514,7 @@ discard block |
||
| 1514 | 1514 | $info['content types'][$type_name] = $type; |
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | - cache_set('content_type_info:'. $language->language, $info, content_cache_tablename()); |
|
| 1517 | + cache_set('content_type_info:'.$language->language, $info, content_cache_tablename()); |
|
| 1518 | 1518 | } |
| 1519 | 1519 | } |
| 1520 | 1520 | return $info; |
@@ -1585,10 +1585,10 @@ discard block |
||
| 1585 | 1585 | $db_info['table'] = _content_tablename($field['type_name'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE); |
| 1586 | 1586 | } |
| 1587 | 1587 | |
| 1588 | - $db_info['columns'] = (array) $field['columns']; |
|
| 1588 | + $db_info['columns'] = (array)$field['columns']; |
|
| 1589 | 1589 | // Generate column names for this field from generic column names. |
| 1590 | 1590 | foreach ($db_info['columns'] as $column_name => $attributes) { |
| 1591 | - $db_info['columns'][$column_name]['column'] = $field['field_name'] .'_'. $column_name; |
|
| 1591 | + $db_info['columns'][$column_name]['column'] = $field['field_name'].'_'.$column_name; |
|
| 1592 | 1592 | } |
| 1593 | 1593 | |
| 1594 | 1594 | return $db_info; |
@@ -1682,7 +1682,7 @@ discard block |
||
| 1682 | 1682 | function content_allowed_values($field, $flatten = TRUE) { |
| 1683 | 1683 | static $allowed_values; |
| 1684 | 1684 | |
| 1685 | - $cid = $field['field_name'] .':'. ($flatten ? '1' : '0'); |
|
| 1685 | + $cid = $field['field_name'].':'.($flatten ? '1' : '0'); |
|
| 1686 | 1686 | if (isset($allowed_values[$cid])) { |
| 1687 | 1687 | return $allowed_values[$cid]; |
| 1688 | 1688 | } |
@@ -1710,7 +1710,7 @@ discard block |
||
| 1710 | 1710 | $opt = content_filter_xss($opt); |
| 1711 | 1711 | if (strpos($opt, '|') !== FALSE) { |
| 1712 | 1712 | list($key, $value) = explode('|', $opt); |
| 1713 | - $allowed_values[$cid][$key] = (isset($value) && $value !=='') ? $value : $key; |
|
| 1713 | + $allowed_values[$cid][$key] = (isset($value) && $value !== '') ? $value : $key; |
|
| 1714 | 1714 | } |
| 1715 | 1715 | else { |
| 1716 | 1716 | $allowed_values[$cid][$opt] = $opt; |
@@ -1755,14 +1755,14 @@ discard block |
||
| 1755 | 1755 | * List of tags allowed by content_filter_xss(). |
| 1756 | 1756 | */ |
| 1757 | 1757 | function _content_filter_xss_allowed_tags() { |
| 1758 | - return array('a', 'b', 'big', 'code', 'del', 'em', 'i', 'ins', 'pre', 'q', 'small', 'span', 'strong', 'sub', 'sup', 'tt', 'ol', 'ul', 'li', 'p', 'br', 'img'); |
|
| 1758 | + return array('a', 'b', 'big', 'code', 'del', 'em', 'i', 'ins', 'pre', 'q', 'small', 'span', 'strong', 'sub', 'sup', 'tt', 'ol', 'ul', 'li', 'p', 'br', 'img'); |
|
| 1759 | 1759 | } |
| 1760 | 1760 | |
| 1761 | 1761 | /** |
| 1762 | 1762 | * Human-readable list of allowed tags, for display in help texts. |
| 1763 | 1763 | */ |
| 1764 | 1764 | function _content_filter_xss_display_allowed_tags() { |
| 1765 | - return '<'. implode('> <', _content_filter_xss_allowed_tags()) .'>'; |
|
| 1765 | + return '<'.implode('> <', _content_filter_xss_allowed_tags()).'>'; |
|
| 1766 | 1766 | } |
| 1767 | 1767 | |
| 1768 | 1768 | /** |
@@ -1795,12 +1795,12 @@ discard block |
||
| 1795 | 1795 | } |
| 1796 | 1796 | |
| 1797 | 1797 | if (content_access('view', $field, NULL, $node) && $formatter = _content_get_formatter($formatter_name, $field['type'])) { |
| 1798 | - $theme = $formatter['module'] .'_formatter_'. $formatter_name; |
|
| 1798 | + $theme = $formatter['module'].'_formatter_'.$formatter_name; |
|
| 1799 | 1799 | |
| 1800 | 1800 | $element = array( |
| 1801 | 1801 | '#theme' => $theme, |
| 1802 | 1802 | '#field_name' => $field['field_name'], |
| 1803 | - '#type_name' => isset($node->type) ? $node->type :'', |
|
| 1803 | + '#type_name' => isset($node->type) ? $node->type : '', |
|
| 1804 | 1804 | '#formatter' => $formatter_name, |
| 1805 | 1805 | '#node' => $node, |
| 1806 | 1806 | '#delta' => isset($item['#delta']) ? $item['#delta'] : NULL, |
@@ -1811,7 +1811,7 @@ discard block |
||
| 1811 | 1811 | |
| 1812 | 1812 | // hook_field('sanitize') expects an array of items, so we build one. |
| 1813 | 1813 | $items = array($item); |
| 1814 | - $function = $field['module'] .'_field'; |
|
| 1814 | + $function = $field['module'].'_field'; |
|
| 1815 | 1815 | if (function_exists($function)) { |
| 1816 | 1816 | $function('sanitize', $node, $field, $items, FALSE, FALSE); |
| 1817 | 1817 | } |
@@ -1821,7 +1821,7 @@ discard block |
||
| 1821 | 1821 | else { |
| 1822 | 1822 | // Multiple values formatter. |
| 1823 | 1823 | $items = $item; |
| 1824 | - $function = $field['module'] .'_field'; |
|
| 1824 | + $function = $field['module'].'_field'; |
|
| 1825 | 1825 | if (function_exists($function)) { |
| 1826 | 1826 | $function('sanitize', $node, $field, $items, FALSE, FALSE); |
| 1827 | 1827 | } |
@@ -1856,13 +1856,13 @@ discard block |
||
| 1856 | 1856 | if (!isset($info)) { |
| 1857 | 1857 | $data = array(); |
| 1858 | 1858 | foreach (module_implements('content_build_modes') as $module) { |
| 1859 | - $function = $module .'_content_build_modes'; |
|
| 1860 | - $data = array_merge($data, (array) $function()); |
|
| 1859 | + $function = $module.'_content_build_modes'; |
|
| 1860 | + $data = array_merge($data, (array)$function()); |
|
| 1861 | 1861 | } |
| 1862 | 1862 | $flat = array(); |
| 1863 | 1863 | foreach ($data as $tab) { |
| 1864 | 1864 | // Use the + operator to preserve numeric indexes (core build modes). |
| 1865 | - $flat += (array) $tab['build modes']; |
|
| 1865 | + $flat += (array)$tab['build modes']; |
|
| 1866 | 1866 | } |
| 1867 | 1867 | $info = array('tabs' => $data, 'build modes' => $flat); |
| 1868 | 1868 | } |
@@ -1994,13 +1994,13 @@ discard block |
||
| 1994 | 1994 | |
| 1995 | 1995 | $name = str_replace('-', '_', $name); |
| 1996 | 1996 | switch ("$version-$storage") { |
| 1997 | - case '0-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
|
| 1997 | + case '0-'.CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
|
| 1998 | 1998 | return "node_$name"; |
| 1999 | - case '0-'. CONTENT_DB_STORAGE_PER_FIELD : |
|
| 1999 | + case '0-'.CONTENT_DB_STORAGE_PER_FIELD : |
|
| 2000 | 2000 | return "node_data_$name"; |
| 2001 | - case '1003-'. CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
|
| 2001 | + case '1003-'.CONTENT_DB_STORAGE_PER_CONTENT_TYPE : |
|
| 2002 | 2002 | return "content_type_$name"; |
| 2003 | - case '1003-'. CONTENT_DB_STORAGE_PER_FIELD : |
|
| 2003 | + case '1003-'.CONTENT_DB_STORAGE_PER_FIELD : |
|
| 2004 | 2004 | return "content_$name"; |
| 2005 | 2005 | } |
| 2006 | 2006 | } |
@@ -2083,7 +2083,7 @@ discard block |
||
| 2083 | 2083 | |
| 2084 | 2084 | if (!empty($field['columns'])) { |
| 2085 | 2085 | foreach ($field['columns'] as $column => $attributes) { |
| 2086 | - $column_name = $field['field_name'] .'_'. $column; |
|
| 2086 | + $column_name = $field['field_name'].'_'.$column; |
|
| 2087 | 2087 | if (isset($attributes['index']) && $attributes['index']) { |
| 2088 | 2088 | $schema['indexes'][$column_name] = array($column_name); |
| 2089 | 2089 | unset($attributes['index']); |
@@ -2116,7 +2116,7 @@ discard block |
||
| 2116 | 2116 | if ($db_type == 'mysql' || $db_type == 'mysqli') { |
| 2117 | 2117 | if (version_compare(db_version(), '5.0.3') < 0) { |
| 2118 | 2118 | // Earlier versions of MySQL don't support a WHERE clause for SHOW. |
| 2119 | - $result = db_query('SHOW INDEX FROM {'. $table .'}'); |
|
| 2119 | + $result = db_query('SHOW INDEX FROM {'.$table.'}'); |
|
| 2120 | 2120 | while ($row = db_fetch_array($result)) { |
| 2121 | 2121 | if ($row['Key_name'] == $name) { |
| 2122 | 2122 | return TRUE; |
@@ -2124,12 +2124,12 @@ discard block |
||
| 2124 | 2124 | } |
| 2125 | 2125 | return FALSE; |
| 2126 | 2126 | } |
| 2127 | - return (bool)db_result(db_query("SHOW INDEX FROM {". $table ."} WHERE key_name = '$name'")); |
|
| 2127 | + return (bool)db_result(db_query("SHOW INDEX FROM {".$table."} WHERE key_name = '$name'")); |
|
| 2128 | 2128 | } |
| 2129 | 2129 | elseif ($db_type == 'pgsql') { |
| 2130 | 2130 | // Note that the index names in Schema API for PostgreSQL are prefixed by |
| 2131 | 2131 | // the table name and suffixed by '_idx'. |
| 2132 | - return (bool)db_result(db_query("SELECT COUNT(indexname) FROM pg_indexes WHERE indexname = '{". $table ."}_{$name}_idx'")); |
|
| 2132 | + return (bool)db_result(db_query("SELECT COUNT(indexname) FROM pg_indexes WHERE indexname = '{".$table."}_{$name}_idx'")); |
|
| 2133 | 2133 | } |
| 2134 | 2134 | return FALSE; |
| 2135 | 2135 | } |
@@ -2226,7 +2226,7 @@ discard block |
||
| 2226 | 2226 | elseif (!empty($field['widget']['default_value'])) { |
| 2227 | 2227 | $default_value = $field['widget']['default_value']; |
| 2228 | 2228 | } |
| 2229 | - return (array) $default_value; |
|
| 2229 | + return (array)$default_value; |
|
| 2230 | 2230 | } |
| 2231 | 2231 | |
| 2232 | 2232 | /** |
@@ -2373,7 +2373,7 @@ discard block |
||
| 2373 | 2373 | $variables['items'][$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
| 2374 | 2374 | } |
| 2375 | 2375 | } |
| 2376 | - else { |
|
| 2376 | + else { |
|
| 2377 | 2377 | // Multiple values formatter. |
| 2378 | 2378 | // We display the 'all items' output as $items[0], as if it was the |
| 2379 | 2379 | // output of a single valued field. |
@@ -2409,9 +2409,9 @@ discard block |
||
| 2409 | 2409 | 'field_empty' => $field_empty, |
| 2410 | 2410 | 'template_files' => array( |
| 2411 | 2411 | 'content-field', |
| 2412 | - 'content-field-'. $element['#field_name'], |
|
| 2413 | - 'content-field-'. $element['#node']->type, |
|
| 2414 | - 'content-field-'. $element['#field_name'] .'-'. $element['#node']->type, |
|
| 2412 | + 'content-field-'.$element['#field_name'], |
|
| 2413 | + 'content-field-'.$element['#node']->type, |
|
| 2414 | + 'content-field-'.$element['#field_name'].'-'.$element['#node']->type, |
|
| 2415 | 2415 | ), |
| 2416 | 2416 | ); |
| 2417 | 2417 | $variables = array_merge($variables, $additions); |
@@ -2629,7 +2629,7 @@ discard block |
||
| 2629 | 2629 | if (empty($type_name) || $content_type['type'] == $type_name) { |
| 2630 | 2630 | foreach ($content_type['fields'] as $field) { |
| 2631 | 2631 | $db_info = content_database_info($field); |
| 2632 | - if (db_result(db_query("SELECT COUNT(*) FROM {". $db_info['table'] ."}")) >= 1) { |
|
| 2632 | + if (db_result(db_query("SELECT COUNT(*) FROM {".$db_info['table']."}")) >= 1) { |
|
| 2633 | 2633 | return 0; |
| 2634 | 2634 | } |
| 2635 | 2635 | } |
@@ -2642,10 +2642,10 @@ discard block |
||
| 2642 | 2642 | else { |
| 2643 | 2643 | $db_info = content_database_info($field); |
| 2644 | 2644 | if (!empty($type_name)) { |
| 2645 | - $delta = db_result(db_query("SELECT MAX(delta) FROM {". $db_info['table'] ."} f LEFT JOIN {node} n ON f.vid = n.vid WHERE n.type = '%s'", $type_name)); |
|
| 2645 | + $delta = db_result(db_query("SELECT MAX(delta) FROM {".$db_info['table']."} f LEFT JOIN {node} n ON f.vid = n.vid WHERE n.type = '%s'", $type_name)); |
|
| 2646 | 2646 | } |
| 2647 | 2647 | else { |
| 2648 | - $delta = db_result(db_query("SELECT MAX(delta) FROM {". $db_info['table'] ."}")); |
|
| 2648 | + $delta = db_result(db_query("SELECT MAX(delta) FROM {".$db_info['table']."}")); |
|
| 2649 | 2649 | } |
| 2650 | 2650 | if ($delta >= 0) { |
| 2651 | 2651 | return $delta; |
@@ -242,8 +242,7 @@ discard block |
||
| 242 | 242 | foreach ($cached->data as $key => $value) { |
| 243 | 243 | $node->$key = $value; |
| 244 | 244 | } |
| 245 | - } |
|
| 246 | - else { |
|
| 245 | + } else { |
|
| 247 | 246 | $default_additions = _content_field_invoke_default('load', $node); |
| 248 | 247 | if ($default_additions) { |
| 249 | 248 | foreach ($default_additions as $key => $value) { |
@@ -458,8 +457,7 @@ discard block |
||
| 458 | 457 | // render arrays. Check we're not on a form first. |
| 459 | 458 | if (!isset($elements['#build_id']) && isset($value['view']) && isset($elements[$value['view']])) { |
| 460 | 459 | $elements[$value['view']]['#weight'] = $value['weight']; |
| 461 | - } |
|
| 462 | - elseif (isset($elements[$key])) { |
|
| 460 | + } elseif (isset($elements[$key])) { |
|
| 463 | 461 | $elements[$key]['#weight'] = $value['weight']; |
| 464 | 462 | } |
| 465 | 463 | } |
@@ -530,8 +528,7 @@ discard block |
||
| 530 | 528 | $output .= drupal_render($element[$element['#field_name'] .'_add_more']); |
| 531 | 529 | |
| 532 | 530 | drupal_add_tabledrag($table_id, 'order', 'sibling', $order_class); |
| 533 | - } |
|
| 534 | - else { |
|
| 531 | + } else { |
|
| 535 | 532 | foreach (element_children($element) as $key) { |
| 536 | 533 | $output .= drupal_render($element[$key]); |
| 537 | 534 | } |
@@ -744,8 +741,7 @@ discard block |
||
| 744 | 741 | // NODE_BUILD_NORMAL is 0, and ('whatever' == 0) is TRUE, so we need a ===. |
| 745 | 742 | if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) { |
| 746 | 743 | $context = $teaser ? 'teaser' : 'full'; |
| 747 | - } |
|
| 748 | - else { |
|
| 744 | + } else { |
|
| 749 | 745 | $context = $node->build_mode; |
| 750 | 746 | } |
| 751 | 747 | // The field may be missing info for $contexts added by modules |
@@ -797,8 +793,7 @@ discard block |
||
| 797 | 793 | $element['items'][$delta] += $format_info; |
| 798 | 794 | $element['items'][$delta]['#item']['#delta'] = $delta; |
| 799 | 795 | } |
| 800 | - } |
|
| 801 | - else { |
|
| 796 | + } else { |
|
| 802 | 797 | $element['items'] += $format_info; |
| 803 | 798 | } |
| 804 | 799 | |
@@ -829,8 +824,7 @@ discard block |
||
| 829 | 824 | $wrapper = NULL; |
| 830 | 825 | if (isset($node->content[$field['field_name']])) { |
| 831 | 826 | $wrapper = $node->content[$field['field_name']]; |
| 832 | - } |
|
| 833 | - elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
| 827 | + } elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
| 834 | 828 | $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
| 835 | 829 | } |
| 836 | 830 | |
@@ -844,13 +838,11 @@ discard block |
||
| 844 | 838 | // '#chilren' is not set if the field is empty. |
| 845 | 839 | $items[$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
| 846 | 840 | } |
| 847 | - } |
|
| 848 | - elseif (isset($element['items']['#children'])) { |
|
| 841 | + } elseif (isset($element['items']['#children'])) { |
|
| 849 | 842 | // Multiple values formatter. |
| 850 | 843 | $items[0]['view'] = $element['items']['#children']; |
| 851 | 844 | } |
| 852 | - } |
|
| 853 | - else { |
|
| 845 | + } else { |
|
| 854 | 846 | // Hidden or inaccessible field. |
| 855 | 847 | $items[0]['view'] = ''; |
| 856 | 848 | } |
@@ -866,8 +858,7 @@ discard block |
||
| 866 | 858 | $wrapper = NULL; |
| 867 | 859 | if (isset($node->content[$field['field_name']])) { |
| 868 | 860 | $wrapper = $node->content[$field['field_name']]; |
| 869 | - } |
|
| 870 | - elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
| 861 | + } elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) { |
|
| 871 | 862 | $wrapper = $node->content[$group_name]['group'][$field['field_name']]; |
| 872 | 863 | } |
| 873 | 864 | |
@@ -1050,8 +1041,7 @@ discard block |
||
| 1050 | 1041 | // how to handle that. |
| 1051 | 1042 | if (db_result(db_query("SELECT COUNT(*) FROM {". $table ."} WHERE vid = %d", $node->vid))) { |
| 1052 | 1043 | content_write_record($table, $record, array('vid')); |
| 1053 | - } |
|
| 1054 | - else { |
|
| 1044 | + } else { |
|
| 1055 | 1045 | content_write_record($table, $record); |
| 1056 | 1046 | } |
| 1057 | 1047 | } |
@@ -1134,8 +1124,7 @@ discard block |
||
| 1134 | 1124 | if (is_array($object)) { |
| 1135 | 1125 | $object = (object) $object; |
| 1136 | 1126 | $array = TRUE; |
| 1137 | - } |
|
| 1138 | - else { |
|
| 1127 | + } else { |
|
| 1139 | 1128 | $array = FALSE; |
| 1140 | 1129 | } |
| 1141 | 1130 | |
@@ -1174,12 +1163,10 @@ discard block |
||
| 1174 | 1163 | |
| 1175 | 1164 | if (empty($info['serialize'])) { |
| 1176 | 1165 | $values[] = $object->$field; |
| 1177 | - } |
|
| 1178 | - else { |
|
| 1166 | + } else { |
|
| 1179 | 1167 | $values[] = serialize($object->$field); |
| 1180 | 1168 | } |
| 1181 | - } |
|
| 1182 | - else { |
|
| 1169 | + } else { |
|
| 1183 | 1170 | $placeholders[] = 'NULL'; |
| 1184 | 1171 | } |
| 1185 | 1172 | } |
@@ -1190,8 +1177,7 @@ discard block |
||
| 1190 | 1177 | if (!count($update)) { |
| 1191 | 1178 | $query = "INSERT INTO {". $table ."} (". implode(', ', $fields) .') VALUES ('. implode(', ', $placeholders) .')'; |
| 1192 | 1179 | $return = SAVED_NEW; |
| 1193 | - } |
|
| 1194 | - else { |
|
| 1180 | + } else { |
|
| 1195 | 1181 | $query = ''; |
| 1196 | 1182 | foreach ($fields as $id => $field) { |
| 1197 | 1183 | if ($query) { |
@@ -1253,8 +1239,7 @@ discard block |
||
| 1253 | 1239 | $result = $function($op, $node, $field, $items, $teaser, $page); |
| 1254 | 1240 | if (is_array($result)) { |
| 1255 | 1241 | $return = array_merge($return, $result); |
| 1256 | - } |
|
| 1257 | - else if (isset($result)) { |
|
| 1242 | + } else if (isset($result)) { |
|
| 1258 | 1243 | $return[] = $result; |
| 1259 | 1244 | } |
| 1260 | 1245 | } |
@@ -1279,15 +1264,13 @@ discard block |
||
| 1279 | 1264 | // rather than by field. |
| 1280 | 1265 | if (in_array($op, array('load', 'insert', 'update', 'delete', 'delete revision'))) { |
| 1281 | 1266 | return content_storage($op, $node); |
| 1282 | - } |
|
| 1283 | - else { |
|
| 1267 | + } else { |
|
| 1284 | 1268 | foreach ($type['fields'] as $field) { |
| 1285 | 1269 | $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array(); |
| 1286 | 1270 | $result = content_field($op, $node, $field, $items, $teaser, $page); |
| 1287 | 1271 | if (is_array($result)) { |
| 1288 | 1272 | $return = array_merge($return, $result); |
| 1289 | - } |
|
| 1290 | - else if (isset($result)) { |
|
| 1273 | + } else if (isset($result)) { |
|
| 1291 | 1274 | $return[] = $result; |
| 1292 | 1275 | } |
| 1293 | 1276 | if (isset($node->$field['field_name'])) { |
@@ -1410,8 +1393,7 @@ discard block |
||
| 1410 | 1393 | |
| 1411 | 1394 | if (!$reset && $cached = cache_get('content_type_info:'. $language->language, content_cache_tablename())) { |
| 1412 | 1395 | $info = $cached->data; |
| 1413 | - } |
|
| 1414 | - else { |
|
| 1396 | + } else { |
|
| 1415 | 1397 | $info = array( |
| 1416 | 1398 | 'field types' => array(), |
| 1417 | 1399 | 'widget types' => array(), |
@@ -1580,8 +1562,7 @@ discard block |
||
| 1580 | 1562 | $db_info = array(); |
| 1581 | 1563 | if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { |
| 1582 | 1564 | $db_info['table'] = _content_tablename($field['field_name'], CONTENT_DB_STORAGE_PER_FIELD); |
| 1583 | - } |
|
| 1584 | - else { |
|
| 1565 | + } else { |
|
| 1585 | 1566 | $db_info['table'] = _content_tablename($field['type_name'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE); |
| 1586 | 1567 | } |
| 1587 | 1568 | |
@@ -1600,8 +1581,7 @@ discard block |
||
| 1600 | 1581 | function content_storage_type($field) { |
| 1601 | 1582 | if ($field['multiple'] > 0) { |
| 1602 | 1583 | return CONTENT_DB_STORAGE_PER_FIELD; |
| 1603 | - } |
|
| 1604 | - else { |
|
| 1584 | + } else { |
|
| 1605 | 1585 | module_load_include('inc', 'content', 'includes/content.crud'); |
| 1606 | 1586 | $instances = content_field_instance_read(array('field_name' => $field['field_name'])); |
| 1607 | 1587 | if (count($instances) > 1) { |
@@ -1655,8 +1635,7 @@ discard block |
||
| 1655 | 1635 | foreach ($array as $key => $value) { |
| 1656 | 1636 | if (is_array($value)) { |
| 1657 | 1637 | $result += content_array_flatten($value); |
| 1658 | - } |
|
| 1659 | - else { |
|
| 1638 | + } else { |
|
| 1660 | 1639 | $result[$key] = $value; |
| 1661 | 1640 | } |
| 1662 | 1641 | } |
@@ -1711,8 +1690,7 @@ discard block |
||
| 1711 | 1690 | if (strpos($opt, '|') !== FALSE) { |
| 1712 | 1691 | list($key, $value) = explode('|', $opt); |
| 1713 | 1692 | $allowed_values[$cid][$key] = (isset($value) && $value !=='') ? $value : $key; |
| 1714 | - } |
|
| 1715 | - else { |
|
| 1693 | + } else { |
|
| 1716 | 1694 | $allowed_values[$cid][$opt] = $opt; |
| 1717 | 1695 | } |
| 1718 | 1696 | } |
@@ -1733,8 +1711,7 @@ discard block |
||
| 1733 | 1711 | foreach ($options as $key => $opt) { |
| 1734 | 1712 | if (is_array($opt)) { |
| 1735 | 1713 | content_allowed_values_filter_html($options[$key]); |
| 1736 | - } |
|
| 1737 | - else { |
|
| 1714 | + } else { |
|
| 1738 | 1715 | $options[$key] = html_entity_decode(strip_tags($opt), ENT_QUOTES); |
| 1739 | 1716 | } |
| 1740 | 1717 | } |
@@ -1817,8 +1794,7 @@ discard block |
||
| 1817 | 1794 | } |
| 1818 | 1795 | |
| 1819 | 1796 | $element['#item'] = $items[0]; |
| 1820 | - } |
|
| 1821 | - else { |
|
| 1797 | + } else { |
|
| 1822 | 1798 | // Multiple values formatter. |
| 1823 | 1799 | $items = $item; |
| 1824 | 1800 | $function = $field['module'] .'_field'; |
@@ -1869,11 +1845,9 @@ discard block |
||
| 1869 | 1845 | |
| 1870 | 1846 | if ($selector === '_tabs') { |
| 1871 | 1847 | return $info['tabs']; |
| 1872 | - } |
|
| 1873 | - elseif (isset($selector) && isset($info['tabs'][$selector])) { |
|
| 1848 | + } elseif (isset($selector) && isset($info['tabs'][$selector])) { |
|
| 1874 | 1849 | return isset($info['tabs'][$selector]) ? $info['tabs'][$selector]['build modes'] : array(); |
| 1875 | - } |
|
| 1876 | - else { |
|
| 1850 | + } else { |
|
| 1877 | 1851 | return $info['build modes']; |
| 1878 | 1852 | } |
| 1879 | 1853 | } |
@@ -1987,8 +1961,7 @@ discard block |
||
| 1987 | 1961 | |
| 1988 | 1962 | if ($version < 1003) { |
| 1989 | 1963 | $version = 0; |
| 1990 | - } |
|
| 1991 | - else { |
|
| 1964 | + } else { |
|
| 1992 | 1965 | $version = 1003; |
| 1993 | 1966 | } |
| 1994 | 1967 | |
@@ -2042,8 +2015,7 @@ discard block |
||
| 2042 | 2015 | function content_cache_tablename() { |
| 2043 | 2016 | if (variable_get('content_schema_version', -1) < 6000) { |
| 2044 | 2017 | return 'cache'; |
| 2045 | - } |
|
| 2046 | - else { |
|
| 2018 | + } else { |
|
| 2047 | 2019 | return 'cache_content'; |
| 2048 | 2020 | } |
| 2049 | 2021 | } |
@@ -2125,8 +2097,7 @@ discard block |
||
| 2125 | 2097 | return FALSE; |
| 2126 | 2098 | } |
| 2127 | 2099 | return (bool)db_result(db_query("SHOW INDEX FROM {". $table ."} WHERE key_name = '$name'")); |
| 2128 | - } |
|
| 2129 | - elseif ($db_type == 'pgsql') { |
|
| 2100 | + } elseif ($db_type == 'pgsql') { |
|
| 2130 | 2101 | // Note that the index names in Schema API for PostgreSQL are prefixed by |
| 2131 | 2102 | // the table name and suffixed by '_idx'. |
| 2132 | 2103 | return (bool)db_result(db_query("SELECT COUNT(indexname) FROM pg_indexes WHERE indexname = '{". $table ."}_{$name}_idx'")); |
@@ -2222,8 +2193,7 @@ discard block |
||
| 2222 | 2193 | if (is_array($result)) { |
| 2223 | 2194 | $default_value = $result; |
| 2224 | 2195 | } |
| 2225 | - } |
|
| 2226 | - elseif (!empty($field['widget']['default_value'])) { |
|
| 2196 | + } elseif (!empty($field['widget']['default_value'])) { |
|
| 2227 | 2197 | $default_value = $field['widget']['default_value']; |
| 2228 | 2198 | } |
| 2229 | 2199 | return (array) $default_value; |
@@ -2336,8 +2306,7 @@ discard block |
||
| 2336 | 2306 | || !is_array($object['display_settings'][$context]) |
| 2337 | 2307 | || empty($object['display_settings'][$context]['exclude'])) { |
| 2338 | 2308 | return FALSE; |
| 2339 | - } |
|
| 2340 | - else { |
|
| 2309 | + } else { |
|
| 2341 | 2310 | return TRUE; |
| 2342 | 2311 | } |
| 2343 | 2312 | } |
@@ -2372,8 +2341,7 @@ discard block |
||
| 2372 | 2341 | // Use isset() to avoid undefined index message on #children when field values are empty. |
| 2373 | 2342 | $variables['items'][$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : ''; |
| 2374 | 2343 | } |
| 2375 | - } |
|
| 2376 | - else { |
|
| 2344 | + } else { |
|
| 2377 | 2345 | // Multiple values formatter. |
| 2378 | 2346 | // We display the 'all items' output as $items[0], as if it was the |
| 2379 | 2347 | // output of a single valued field. |
@@ -2392,8 +2360,7 @@ discard block |
||
| 2392 | 2360 | foreach ($variables['items'] as $delta => $item) { |
| 2393 | 2361 | if (!isset($item['view']) || (empty($item['view']) && (string)$item['view'] !== '0')) { |
| 2394 | 2362 | $variables['items'][$delta]['empty'] = TRUE; |
| 2395 | - } |
|
| 2396 | - else { |
|
| 2363 | + } else { |
|
| 2397 | 2364 | $field_empty = FALSE; |
| 2398 | 2365 | $variables['items'][$delta]['empty'] = FALSE; |
| 2399 | 2366 | } |
@@ -2643,8 +2610,7 @@ discard block |
||
| 2643 | 2610 | $db_info = content_database_info($field); |
| 2644 | 2611 | if (!empty($type_name)) { |
| 2645 | 2612 | $delta = db_result(db_query("SELECT MAX(delta) FROM {". $db_info['table'] ."} f LEFT JOIN {node} n ON f.vid = n.vid WHERE n.type = '%s'", $type_name)); |
| 2646 | - } |
|
| 2647 | - else { |
|
| 2613 | + } else { |
|
| 2648 | 2614 | $delta = db_result(db_query("SELECT MAX(delta) FROM {". $db_info['table'] ."}")); |
| 2649 | 2615 | } |
| 2650 | 2616 | if ($delta >= 0) { |
@@ -2663,8 +2629,7 @@ discard block |
||
| 2663 | 2629 | if (!empty($type_name)) { |
| 2664 | 2630 | $param = array('type_name' => $type_name); |
| 2665 | 2631 | $inactive = array($type_name => array()); |
| 2666 | - } |
|
| 2667 | - else { |
|
| 2632 | + } else { |
|
| 2668 | 2633 | $param = array(); |
| 2669 | 2634 | $inactive = array(); |
| 2670 | 2635 | } |
@@ -2693,8 +2658,7 @@ discard block |
||
| 2693 | 2658 | if (!empty($type_name)) { |
| 2694 | 2659 | $param = array('type_name' => $type_name); |
| 2695 | 2660 | $inactive = array($type_name => array()); |
| 2696 | - } |
|
| 2697 | - else { |
|
| 2661 | + } else { |
|
| 2698 | 2662 | $param = array(); |
| 2699 | 2663 | $inactive = array(); |
| 2700 | 2664 | } |
@@ -68,6 +68,7 @@ |
||
| 68 | 68 | * custom multiple value widgets but don't need any other special multiple |
| 69 | 69 | * values handling. This will call the field generation function |
| 70 | 70 | * a random number of times and compile the results into a node array. |
| 71 | + * @param string $function |
|
| 71 | 72 | */ |
| 72 | 73 | function content_devel_multiple($function, $node, $field) { |
| 73 | 74 | $node_field = array(); |
@@ -19,48 +19,48 @@ discard block |
||
| 19 | 19 | * information in each of its CCK fields. |
| 20 | 20 | **/ |
| 21 | 21 | function content_generate_fields(&$node, $field) { |
| 22 | - $type_name = $node->type; |
|
| 23 | - $type = content_types($type_name); |
|
| 24 | - $field_types = _content_field_types(); |
|
| 22 | + $type_name = $node->type; |
|
| 23 | + $type = content_types($type_name); |
|
| 24 | + $field_types = _content_field_types(); |
|
| 25 | 25 | |
| 26 | - if (!empty($type['fields'])) { |
|
| 26 | + if (!empty($type['fields'])) { |
|
| 27 | 27 | foreach ($type['fields'] as $field) { |
| 28 | - $node_field = array(); |
|
| 29 | - // If module handles own multiples, then only call its hook once. |
|
| 30 | - if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
|
| 28 | + $node_field = array(); |
|
| 29 | + // If module handles own multiples, then only call its hook once. |
|
| 30 | + if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
|
| 31 | 31 | $max = 0; |
| 32 | - } |
|
| 33 | - else { |
|
| 32 | + } |
|
| 33 | + else { |
|
| 34 | 34 | switch ($field['multiple']) { |
| 35 | - case 0: |
|
| 35 | + case 0: |
|
| 36 | 36 | $max = 0; |
| 37 | 37 | break; |
| 38 | - case 1: |
|
| 38 | + case 1: |
|
| 39 | 39 | $max = rand(0, 3); //just an arbitrary number for 'unlimited' |
| 40 | 40 | break; |
| 41 | - default: |
|
| 41 | + default: |
|
| 42 | 42 | $max = $field['multiple']; |
| 43 | 43 | break; |
| 44 | 44 | } |
| 45 | - } |
|
| 46 | - for ($i = 0; $i <= $max; $i++) { |
|
| 45 | + } |
|
| 46 | + for ($i = 0; $i <= $max; $i++) { |
|
| 47 | 47 | $module = $field_types[$field['type']]['module']; |
| 48 | 48 | $function = $module .'_content_generate'; |
| 49 | 49 | if (function_exists($function)) { |
| 50 | - $result = $function($node, $field); // $items, $teaser, $page |
|
| 51 | - if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
|
| 50 | + $result = $function($node, $field); // $items, $teaser, $page |
|
| 51 | + if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
|
| 52 | 52 | // Fields that handle their own multiples will add their own deltas. |
| 53 | 53 | $node_field = $result; |
| 54 | - } |
|
| 55 | - else { |
|
| 54 | + } |
|
| 55 | + else { |
|
| 56 | 56 | // When multiples are handled by the content module, add a delta for each result. |
| 57 | 57 | $node_field[$i] = $result; |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | } |
| 60 | - } |
|
| 61 | - $node->{$field['field_name']} = $node_field; |
|
| 60 | + } |
|
| 61 | + $node->{$field['field_name']} = $node_field; |
|
| 62 | + } |
|
| 62 | 63 | } |
| 63 | - } |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -70,149 +70,149 @@ discard block |
||
| 70 | 70 | * a random number of times and compile the results into a node array. |
| 71 | 71 | */ |
| 72 | 72 | function content_devel_multiple($function, $node, $field) { |
| 73 | - $node_field = array(); |
|
| 74 | - if (function_exists($function)) { |
|
| 73 | + $node_field = array(); |
|
| 74 | + if (function_exists($function)) { |
|
| 75 | 75 | switch ($field['multiple']) { |
| 76 | - case 0: |
|
| 76 | + case 0: |
|
| 77 | 77 | $max = 0; |
| 78 | 78 | break; |
| 79 | - case 1: |
|
| 79 | + case 1: |
|
| 80 | 80 | $max = rand(0, 3); //just an arbitrary number for 'unlimited' |
| 81 | 81 | break; |
| 82 | - default: |
|
| 82 | + default: |
|
| 83 | 83 | $max = $field['multiple']; |
| 84 | 84 | break; |
| 85 | 85 | } |
| 86 | 86 | for ($i = 0; $i <= $max; $i++) { |
| 87 | - $node_field[$i] = $function($node, $field); |
|
| 87 | + $node_field[$i] = $function($node, $field); |
|
| 88 | + } |
|
| 88 | 89 | } |
| 89 | - } |
|
| 90 | - return $node_field; |
|
| 90 | + return $node_field; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | if (module_exists('text')) { |
| 94 | - function text_content_generate($node, $field) { |
|
| 94 | + function text_content_generate($node, $field) { |
|
| 95 | 95 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
| 96 | - return content_devel_multiple('_text_content_generate', $node, $field); |
|
| 96 | + return content_devel_multiple('_text_content_generate', $node, $field); |
|
| 97 | 97 | } |
| 98 | 98 | else { |
| 99 | - return _text_content_generate($node, $field); |
|
| 99 | + return _text_content_generate($node, $field); |
|
| 100 | + } |
|
| 100 | 101 | } |
| 101 | - } |
|
| 102 | 102 | |
| 103 | - function _text_content_generate($node, $field) { |
|
| 103 | + function _text_content_generate($node, $field) { |
|
| 104 | 104 | $node_field = array(); |
| 105 | 105 | if ($field['widget']['type'] == 'text_textarea') { |
| 106 | - $format = $field['text_processing'] ? rand(0, 3) : 0; |
|
| 107 | - $node_field['value'] = devel_create_content($format); |
|
| 108 | - $node_field['format'] = $format; |
|
| 106 | + $format = $field['text_processing'] ? rand(0, 3) : 0; |
|
| 107 | + $node_field['value'] = devel_create_content($format); |
|
| 108 | + $node_field['format'] = $format; |
|
| 109 | 109 | } |
| 110 | 110 | else { |
| 111 | - $allowed_values = content_allowed_values($field); |
|
| 112 | - if (!empty($allowed_values)) { |
|
| 111 | + $allowed_values = content_allowed_values($field); |
|
| 112 | + if (!empty($allowed_values)) { |
|
| 113 | 113 | // Just pick one of the specified allowed values. |
| 114 | 114 | $node_field['value'] = array_rand($allowed_values); |
| 115 | - } |
|
| 116 | - else { |
|
| 115 | + } |
|
| 116 | + else { |
|
| 117 | 117 | // Generate a value that respects max_length. |
| 118 | 118 | if (empty($field['max_length'])) { |
| 119 | - $field['max_length'] = 12; |
|
| 119 | + $field['max_length'] = 12; |
|
| 120 | 120 | } |
| 121 | 121 | $node_field['value'] = user_password($field['max_length']); |
| 122 | - } |
|
| 122 | + } |
|
| 123 | 123 | } |
| 124 | 124 | return $node_field; |
| 125 | - } |
|
| 125 | + } |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if (module_exists('number')) { |
| 129 | - function number_content_generate($node, $field) { |
|
| 129 | + function number_content_generate($node, $field) { |
|
| 130 | 130 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
| 131 | - return content_devel_multiple('_number_content_generate', $node, $field); |
|
| 131 | + return content_devel_multiple('_number_content_generate', $node, $field); |
|
| 132 | 132 | } |
| 133 | 133 | else { |
| 134 | - return _number_content_generate($node, $field); |
|
| 134 | + return _number_content_generate($node, $field); |
|
| 135 | + } |
|
| 135 | 136 | } |
| 136 | - } |
|
| 137 | 137 | |
| 138 | - function _number_content_generate($node, $field) { |
|
| 138 | + function _number_content_generate($node, $field) { |
|
| 139 | 139 | $node_field = array(); |
| 140 | 140 | $allowed_values = content_allowed_values($field); |
| 141 | 141 | if (!empty($allowed_values)) { |
| 142 | - // Just pick one of the specified allowed values. |
|
| 143 | - $node_field['value'] = array_rand($allowed_values); |
|
| 142 | + // Just pick one of the specified allowed values. |
|
| 143 | + $node_field['value'] = array_rand($allowed_values); |
|
| 144 | 144 | } |
| 145 | 145 | else { |
| 146 | - $min = is_numeric($field['min']) ? $field['min'] : 0; |
|
| 147 | - switch ($field['type']) { |
|
| 146 | + $min = is_numeric($field['min']) ? $field['min'] : 0; |
|
| 147 | + switch ($field['type']) { |
|
| 148 | 148 | case 'number_integer': |
| 149 | 149 | $max = is_numeric($field['max']) ? $field['max'] : 10000; |
| 150 | - $decimal = 0; |
|
| 151 | - $scale = 0; |
|
| 152 | - break; |
|
| 150 | + $decimal = 0; |
|
| 151 | + $scale = 0; |
|
| 152 | + break; |
|
| 153 | 153 | |
| 154 | 154 | case 'number_decimal': |
| 155 | 155 | $precision = is_numeric($field['precision']) ? $field['precision'] : 10; |
| 156 | - $scale = is_numeric($field['scale']) ? $field['scale'] : 2; |
|
| 157 | - $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
|
| 158 | - $decimal = rand(0, (10 * $scale)) / 100; |
|
| 159 | - break; |
|
| 156 | + $scale = is_numeric($field['scale']) ? $field['scale'] : 2; |
|
| 157 | + $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
|
| 158 | + $decimal = rand(0, (10 * $scale)) / 100; |
|
| 159 | + break; |
|
| 160 | 160 | |
| 161 | 161 | case 'number_float': |
| 162 | 162 | $precision = rand(10, 32); |
| 163 | - $scale = rand(0, 2); |
|
| 164 | - $decimal = rand(0, (10 * $scale)) / 100; |
|
| 165 | - $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
|
| 166 | - break; |
|
| 167 | - } |
|
| 168 | - $node_field['value'] = round((rand($min, $max) + $decimal), $scale); |
|
| 163 | + $scale = rand(0, 2); |
|
| 164 | + $decimal = rand(0, (10 * $scale)) / 100; |
|
| 165 | + $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
|
| 166 | + break; |
|
| 167 | + } |
|
| 168 | + $node_field['value'] = round((rand($min, $max) + $decimal), $scale); |
|
| 169 | 169 | } |
| 170 | 170 | return $node_field; |
| 171 | - } |
|
| 171 | + } |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | if (module_exists('nodereference')) { |
| 175 | - function nodereference_content_generate($node, $field) { |
|
| 175 | + function nodereference_content_generate($node, $field) { |
|
| 176 | 176 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
| 177 | - return content_devel_multiple('_nodereference_content_generate', $node, $field); |
|
| 177 | + return content_devel_multiple('_nodereference_content_generate', $node, $field); |
|
| 178 | 178 | } |
| 179 | 179 | else { |
| 180 | - return _nodereference_content_generate($node, $field); |
|
| 180 | + return _nodereference_content_generate($node, $field); |
|
| 181 | + } |
|
| 181 | 182 | } |
| 182 | - } |
|
| 183 | 183 | |
| 184 | - function _nodereference_content_generate($node, $field) { |
|
| 184 | + function _nodereference_content_generate($node, $field) { |
|
| 185 | 185 | $node_field = array(); |
| 186 | 186 | $allowed_values = nodereference_allowed_values($field); |
| 187 | 187 | unset($allowed_values[0]); |
| 188 | 188 | if (!empty($allowed_values)) { |
| 189 | - // Just pick one of the specified allowed values. |
|
| 190 | - $node_field['nid'] = array_rand($allowed_values); |
|
| 189 | + // Just pick one of the specified allowed values. |
|
| 190 | + $node_field['nid'] = array_rand($allowed_values); |
|
| 191 | 191 | } |
| 192 | 192 | return $node_field; |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | if (module_exists('userreference')) { |
| 197 | - function userreference_content_generate($node, $field) { |
|
| 197 | + function userreference_content_generate($node, $field) { |
|
| 198 | 198 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
| 199 | - return content_devel_multiple('_userreference_content_generate', $node, $field); |
|
| 199 | + return content_devel_multiple('_userreference_content_generate', $node, $field); |
|
| 200 | 200 | } |
| 201 | 201 | else { |
| 202 | - return _userreference_content_generate($node, $field); |
|
| 202 | + return _userreference_content_generate($node, $field); |
|
| 203 | + } |
|
| 203 | 204 | } |
| 204 | - } |
|
| 205 | 205 | |
| 206 | - function _userreference_content_generate($node, $field) { |
|
| 206 | + function _userreference_content_generate($node, $field) { |
|
| 207 | 207 | $node_field = array(); |
| 208 | 208 | $allowed_values = userreference_allowed_values($field); |
| 209 | 209 | if (isset($allowed_values['none'])) { |
| 210 | - unset($allowed_values['none']); |
|
| 210 | + unset($allowed_values['none']); |
|
| 211 | 211 | } |
| 212 | 212 | if (!empty($allowed_values)) { |
| 213 | - // Just pick one of the specified allowed values. |
|
| 214 | - $node_field['uid'] = array_rand($allowed_values); |
|
| 213 | + // Just pick one of the specified allowed values. |
|
| 214 | + $node_field['uid'] = array_rand($allowed_values); |
|
| 215 | 215 | } |
| 216 | 216 | return $node_field; |
| 217 | - } |
|
| 217 | + } |
|
| 218 | 218 | } |
| 219 | 219 | \ No newline at end of file |
@@ -32,15 +32,15 @@ discard block |
||
| 32 | 32 | } |
| 33 | 33 | else { |
| 34 | 34 | switch ($field['multiple']) { |
| 35 | - case 0: |
|
| 36 | - $max = 0; |
|
| 37 | - break; |
|
| 38 | - case 1: |
|
| 39 | - $max = rand(0, 3); //just an arbitrary number for 'unlimited' |
|
| 40 | - break; |
|
| 41 | - default: |
|
| 42 | - $max = $field['multiple']; |
|
| 43 | - break; |
|
| 35 | + case 0: |
|
| 36 | + $max = 0; |
|
| 37 | + break; |
|
| 38 | + case 1: |
|
| 39 | + $max = rand(0, 3); //just an arbitrary number for 'unlimited' |
|
| 40 | + break; |
|
| 41 | + default: |
|
| 42 | + $max = $field['multiple']; |
|
| 43 | + break; |
|
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | for ($i = 0; $i <= $max; $i++) { |
@@ -73,15 +73,15 @@ discard block |
||
| 73 | 73 | $node_field = array(); |
| 74 | 74 | if (function_exists($function)) { |
| 75 | 75 | switch ($field['multiple']) { |
| 76 | - case 0: |
|
| 77 | - $max = 0; |
|
| 78 | - break; |
|
| 79 | - case 1: |
|
| 80 | - $max = rand(0, 3); //just an arbitrary number for 'unlimited' |
|
| 81 | - break; |
|
| 82 | - default: |
|
| 83 | - $max = $field['multiple']; |
|
| 84 | - break; |
|
| 76 | + case 0: |
|
| 77 | + $max = 0; |
|
| 78 | + break; |
|
| 79 | + case 1: |
|
| 80 | + $max = rand(0, 3); //just an arbitrary number for 'unlimited' |
|
| 81 | + break; |
|
| 82 | + default: |
|
| 83 | + $max = $field['multiple']; |
|
| 84 | + break; |
|
| 85 | 85 | } |
| 86 | 86 | for ($i = 0; $i <= $max; $i++) { |
| 87 | 87 | $node_field[$i] = $function($node, $field); |
@@ -145,25 +145,25 @@ discard block |
||
| 145 | 145 | else { |
| 146 | 146 | $min = is_numeric($field['min']) ? $field['min'] : 0; |
| 147 | 147 | switch ($field['type']) { |
| 148 | - case 'number_integer': |
|
| 149 | - $max = is_numeric($field['max']) ? $field['max'] : 10000; |
|
| 150 | - $decimal = 0; |
|
| 151 | - $scale = 0; |
|
| 152 | - break; |
|
| 148 | + case 'number_integer': |
|
| 149 | + $max = is_numeric($field['max']) ? $field['max'] : 10000; |
|
| 150 | + $decimal = 0; |
|
| 151 | + $scale = 0; |
|
| 152 | + break; |
|
| 153 | 153 | |
| 154 | - case 'number_decimal': |
|
| 155 | - $precision = is_numeric($field['precision']) ? $field['precision'] : 10; |
|
| 156 | - $scale = is_numeric($field['scale']) ? $field['scale'] : 2; |
|
| 157 | - $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
|
| 158 | - $decimal = rand(0, (10 * $scale)) / 100; |
|
| 159 | - break; |
|
| 154 | + case 'number_decimal': |
|
| 155 | + $precision = is_numeric($field['precision']) ? $field['precision'] : 10; |
|
| 156 | + $scale = is_numeric($field['scale']) ? $field['scale'] : 2; |
|
| 157 | + $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
|
| 158 | + $decimal = rand(0, (10 * $scale)) / 100; |
|
| 159 | + break; |
|
| 160 | 160 | |
| 161 | - case 'number_float': |
|
| 162 | - $precision = rand(10, 32); |
|
| 163 | - $scale = rand(0, 2); |
|
| 164 | - $decimal = rand(0, (10 * $scale)) / 100; |
|
| 165 | - $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
|
| 166 | - break; |
|
| 161 | + case 'number_float': |
|
| 162 | + $precision = rand(10, 32); |
|
| 163 | + $scale = rand(0, 2); |
|
| 164 | + $decimal = rand(0, (10 * $scale)) / 100; |
|
| 165 | + $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
|
| 166 | + break; |
|
| 167 | 167 | } |
| 168 | 168 | $node_field['value'] = round((rand($min, $max) + $decimal), $scale); |
| 169 | 169 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | for ($i = 0; $i <= $max; $i++) { |
| 47 | 47 | $module = $field_types[$field['type']]['module']; |
| 48 | - $function = $module .'_content_generate'; |
|
| 48 | + $function = $module.'_content_generate'; |
|
| 49 | 49 | if (function_exists($function)) { |
| 50 | 50 | $result = $function($node, $field); // $items, $teaser, $page |
| 51 | 51 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
@@ -155,13 +155,13 @@ discard block |
||
| 155 | 155 | $precision = is_numeric($field['precision']) ? $field['precision'] : 10; |
| 156 | 156 | $scale = is_numeric($field['scale']) ? $field['scale'] : 2; |
| 157 | 157 | $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
| 158 | - $decimal = rand(0, (10 * $scale)) / 100; |
|
| 158 | + $decimal = rand(0, (10*$scale))/100; |
|
| 159 | 159 | break; |
| 160 | 160 | |
| 161 | 161 | case 'number_float': |
| 162 | 162 | $precision = rand(10, 32); |
| 163 | 163 | $scale = rand(0, 2); |
| 164 | - $decimal = rand(0, (10 * $scale)) / 100; |
|
| 164 | + $decimal = rand(0, (10*$scale))/100; |
|
| 165 | 165 | $max = is_numeric($field['max']) ? $field['max'] : pow(10, ($precision - $scale)); |
| 166 | 166 | break; |
| 167 | 167 | } |
@@ -29,8 +29,7 @@ discard block |
||
| 29 | 29 | // If module handles own multiples, then only call its hook once. |
| 30 | 30 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
| 31 | 31 | $max = 0; |
| 32 | - } |
|
| 33 | - else { |
|
| 32 | + } else { |
|
| 34 | 33 | switch ($field['multiple']) { |
| 35 | 34 | case 0: |
| 36 | 35 | $max = 0; |
@@ -51,8 +50,7 @@ discard block |
||
| 51 | 50 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
| 52 | 51 | // Fields that handle their own multiples will add their own deltas. |
| 53 | 52 | $node_field = $result; |
| 54 | - } |
|
| 55 | - else { |
|
| 53 | + } else { |
|
| 56 | 54 | // When multiples are handled by the content module, add a delta for each result. |
| 57 | 55 | $node_field[$i] = $result; |
| 58 | 56 | } |
@@ -94,8 +92,7 @@ discard block |
||
| 94 | 92 | function text_content_generate($node, $field) { |
| 95 | 93 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
| 96 | 94 | return content_devel_multiple('_text_content_generate', $node, $field); |
| 97 | - } |
|
| 98 | - else { |
|
| 95 | + } else { |
|
| 99 | 96 | return _text_content_generate($node, $field); |
| 100 | 97 | } |
| 101 | 98 | } |
@@ -106,14 +103,12 @@ discard block |
||
| 106 | 103 | $format = $field['text_processing'] ? rand(0, 3) : 0; |
| 107 | 104 | $node_field['value'] = devel_create_content($format); |
| 108 | 105 | $node_field['format'] = $format; |
| 109 | - } |
|
| 110 | - else { |
|
| 106 | + } else { |
|
| 111 | 107 | $allowed_values = content_allowed_values($field); |
| 112 | 108 | if (!empty($allowed_values)) { |
| 113 | 109 | // Just pick one of the specified allowed values. |
| 114 | 110 | $node_field['value'] = array_rand($allowed_values); |
| 115 | - } |
|
| 116 | - else { |
|
| 111 | + } else { |
|
| 117 | 112 | // Generate a value that respects max_length. |
| 118 | 113 | if (empty($field['max_length'])) { |
| 119 | 114 | $field['max_length'] = 12; |
@@ -129,8 +124,7 @@ discard block |
||
| 129 | 124 | function number_content_generate($node, $field) { |
| 130 | 125 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
| 131 | 126 | return content_devel_multiple('_number_content_generate', $node, $field); |
| 132 | - } |
|
| 133 | - else { |
|
| 127 | + } else { |
|
| 134 | 128 | return _number_content_generate($node, $field); |
| 135 | 129 | } |
| 136 | 130 | } |
@@ -141,8 +135,7 @@ discard block |
||
| 141 | 135 | if (!empty($allowed_values)) { |
| 142 | 136 | // Just pick one of the specified allowed values. |
| 143 | 137 | $node_field['value'] = array_rand($allowed_values); |
| 144 | - } |
|
| 145 | - else { |
|
| 138 | + } else { |
|
| 146 | 139 | $min = is_numeric($field['min']) ? $field['min'] : 0; |
| 147 | 140 | switch ($field['type']) { |
| 148 | 141 | case 'number_integer': |
@@ -175,8 +168,7 @@ discard block |
||
| 175 | 168 | function nodereference_content_generate($node, $field) { |
| 176 | 169 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
| 177 | 170 | return content_devel_multiple('_nodereference_content_generate', $node, $field); |
| 178 | - } |
|
| 179 | - else { |
|
| 171 | + } else { |
|
| 180 | 172 | return _nodereference_content_generate($node, $field); |
| 181 | 173 | } |
| 182 | 174 | } |
@@ -197,8 +189,7 @@ discard block |
||
| 197 | 189 | function userreference_content_generate($node, $field) { |
| 198 | 190 | if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_MODULE) { |
| 199 | 191 | return content_devel_multiple('_userreference_content_generate', $node, $field); |
| 200 | - } |
|
| 201 | - else { |
|
| 192 | + } else { |
|
| 202 | 193 | return _userreference_content_generate($node, $field); |
| 203 | 194 | } |
| 204 | 195 | } |