Changeset 14249
- Timestamp:
- 12/22/08 17:25:22 (4 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfXSLTViewPlugin/trunk/lib/sfArray2XML.php
r12290 r14249 1 1 <?php 2 2 sfContext::getInstance()->getConfiguration()->loadHelpers('Helper'); 3 4 use_helper('Date'); 3 5 /** 4 6 * associative array to xml transformation class … … 159 161 $newKey = $key; 160 162 } 161 163 162 164 if ( strpos($newKey, ' ') !== False || $newKey=='') 163 165 { … … 165 167 continue; 166 168 } 167 169 //If key is not alpha numeric 170 if(!preg_match('|^\w+$|', $newKey)){ 171 // Bad key name, skip this entry 172 continue; 173 } 174 168 175 $node = $this->doc->createElement($newKey); 176 169 177 $append=false; 170 178 if (is_array($val)){ 171 $this->addArray($arr[$key], $node, $ key);179 $this->addArray($arr[$key], $node, $newKey); 172 180 $append=true; 173 181 } … … 186 194 } 187 195 elseif(is_string($val)){ 188 $nodeText = $this->doc->createCDATASection($val); 189 $node->appendChild($nodeText); 190 $append=true; 196 if(isValidDateTime($val)){ 197 $ts = strtotime($val); 198 $timeinwords = distance_of_time_in_words($ts); 199 $nodeText = $this->doc->createCDATASection($val); 200 $node->setAttribute("timeinwords", $timeinwords); 201 $node->setAttribute("ts", $ts); 202 $node->setAttribute("d", date("d",$ts)); 203 $node->setAttribute("D", date("D",$ts)); 204 $node->setAttribute("l", date("l",$ts)); 205 $node->setAttribute("S", date("S",$ts)); 206 $node->setAttribute("m", date("m",$ts)); 207 $node->setAttribute("M", date("M",$ts)); 208 $node->setAttribute("F", date("F",$ts)); 209 $node->setAttribute("n", date("n",$ts)); 210 $node->setAttribute("t", date("t",$ts)); 211 $node->setAttribute("y", date("y",$ts)); 212 $node->setAttribute("Y", date("Y",$ts)); 213 $node->setAttribute("g", date("g",$ts)); 214 $node->setAttribute("G", date("G",$ts)); 215 $node->setAttribute("h", date("h",$ts)); 216 $node->setAttribute("H", date("H",$ts)); 217 $node->setAttribute("i", date("i",$ts)); 218 $node->setAttribute("s", date("s",$ts)); 219 $node->appendChild($nodeText); 220 $append=true; 221 }else{ 222 $nodeText = $this->doc->createCDATASection($val); 223 $node->appendChild($nodeText); 224 $append=true; 225 } 191 226 } 192 227 elseif(is_bool($val)){ … … 194 229 $node->appendChild($nodeText); 195 230 $append=true; 231 } 232 elseif(true===method_exists($val,"toDom")){ 233 $fragment = $val->toDom($this->doc); 234 if ($fragment instanceof DOMDocumentFragment) 235 { 236 $node->appendChild($fragment); 237 $append=true; 238 } 196 239 } 197 240 elseif(true===method_exists($val,"toArray")){ … … 232 275 } 233 276 } 277 if(true===method_exists($val,"loadThese")){ 278 //Add what ever the values of each of the array to the data array 279 $these = $val->loadThese(); 280 if(is_array($these)){ 281 foreach($these as $loadkey => $loadmethod){ 282 $data[$loadkey]=call_user_func(array($val,$loadmethod)); 283 } 284 } 285 } 234 286 $this->addArray($data, $node, $key); 235 287 $append=true; … … 257 309 $data = $val->getResults(); 258 310 if ($val->haveToPaginate()){ 259 $data["page s"] = $val->getLinks();311 $data["pagelinks"] = $val->getLinks(); 260 312 $data["pages"]['ResultCount'] = $val->getNbResults(); 261 313 $data["pages"]['FirstPage'] = $val->getFirstPage(); … … 265 317 $data["pages"]['CurrentPage'] = $val->getPage(); 266 318 $data["pages"]['CurrentMaxLink'] = $val->getCurrentMaxLink(); 267 } 319 $data["pages"]['MaxPerPage'] = $val->getMaxPerPage(); 320 } 321 $data["total"] = $val->getNbResults(); 268 322 if($data){ 269 323 $this->addArray($data, $node, $key); … … 300 354 } 301 355 302 ?> 356 function isValidDateTime($dateTime) 357 { 358 $matches = array(); 359 if (preg_match("/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $dateTime, $matches)) { 360 if(isset($matches[1]) && isset($matches[2]) && isset($matches[3])){ 361 if (checkdate($matches[2], $matches[3], $matches[1])) { 362 return true; 363 } 364 } 365 } 366 367 return false; 368 } plugins/sfXSLTViewPlugin/trunk/lib/sfXSLTView.class.php
r12290 r14249 1 1 <?php 2 2 3 4 $e = error_reporting(0);5 error_reporting($e);3 //Not sure why i have this set..commenting out for now 4 //$e = error_reporting(0); 5 //error_reporting($e); 6 6 7 7 /** … … 47 47 $this->buildcomp = $buildcomponents; 48 48 $this->context = $context; 49 $this->attributeHolder = new sfParameterHolder(); 49 50 $this->dispatcher = $context->getEventDispatcher(); 51 52 $this->attributeHolder = $this->initializeAttributeHolder(); 50 53 $this->parameterHolder = new sfParameterHolder(); 51 54 $this->parameterHolder->add(sfConfig::get('mod_'.strtolower($moduleName).'_view_param', array())); … … 202 205 203 206 $timer = sfTimerManager::getTimer('renderFile'); 207 204 208 if (sfConfig::get('sf_logging_enabled')) 205 { 206 $this->getContext()->getLogger()->info('{sfView} render "'.$_sfFile.'"'); 207 } 208 $_escaping = $this->getEscaping(); 209 { 210 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Render "%s"', $_sfFile)))); 211 } 209 212 210 213 $this->loadCoreAndStandardHelpers(); … … 216 219 $this->attributeHolder->set("UploadPath", sfContext::getInstance()->getRequest()->getRelativeUrlRoot().'/'.sfConfig::get('sf_upload_dir_name')); 217 220 218 219 220 // Add any request errors that have been generated221 if (sfContext::getInstance()->getRequest()->hasErrors())222 {223 $this->attributeHolder->set('RequestErrors',sfContext::getInstance()->getRequest()->getErrors());224 }225 226 221 $array2xml = new sfArray2XML(); 227 222 … … 230 225 $xmlstr=$array2xml->saveArray("","XML",true); 231 226 $GLOBALS['XMLSTR'] = $xmlstr; 232 if($this->context->getRequest()-> getParameter("dumpXML") && SF_DEBUG==true&& $this->buildcomp==true){227 if($this->context->getRequest()->hasParameter("dumpXML") && $this->buildcomp==true){ 233 228 header('Content-type: text/xml'); 234 229 echo $xmlstr; … … 256 251 257 252 } 258 259 260 ?>