Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ariadne_object often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ariadne_object, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 38 | abstract class ariadne_object extends object { // ariadne_object class definition |
||
| 39 | |||
| 40 | public $store; |
||
| 41 | public $path; |
||
| 42 | public $data; |
||
| 43 | |||
| 44 | 184 | public function init($store, $path, $data) { |
|
| 52 | |||
| 53 | 184 | public function call($arCallFunction="view.html", $arCallArgs=array()) { |
|
| 54 | /*********************************************************************** |
||
| 55 | call tries to find the template ($arCallFunction) for the current |
||
| 56 | object. If it is not defined there, call will search the superclasses |
||
| 57 | until either it or the template 'default.phtml' is found. |
||
| 58 | |||
| 59 | $arCallFunction must be the name of a class or object template. |
||
| 60 | it can be prepended with "{classname}::". classname must be either |
||
| 61 | a valid ariadne class (derived from pobject). call() |
||
| 62 | will then try to find the template starting at the given classname. |
||
| 63 | e.g.: |
||
| 64 | call("pobject::view.html") will show the view.html template of |
||
| 65 | pobject, with the data of the current object. |
||
| 66 | |||
| 67 | variables available to templates: |
||
| 68 | local: arCallFunction, arCallArgs, arCallTemplate, data |
||
| 69 | global: AR, ARConfig, ARCurrent, ARBeenHere, ARnls |
||
| 70 | ***********************************************************************/ |
||
| 71 | 184 | global $AR, $ARConfig, $ARCurrent, $ARBeenHere, $ARnls; |
|
| 72 | |||
| 73 | 184 | if ( $arCallFunction instanceof \Closure ) { |
|
| 74 | 4 | $arCallFunctionName = 'Closure'; |
|
| 75 | 9 | } else { |
|
| 76 | 184 | $arCallFunctionName = (string) $arCallFunction; |
|
| 77 | } |
||
| 78 | 184 | debug("pobject: ".$this->path.": call($arCallFunctionName, ".debug_serialize($arCallArgs).")","object","all","IN"); |
|
| 79 | |||
| 80 | // default to view.html |
||
| 81 | 184 | if (!$arCallFunction) { |
|
| 82 | 15 | $arCallFunction="view.html"; |
|
| 83 | } |
||
| 84 | // clear previous results |
||
| 85 | 184 | unset($ARCurrent->arResult); |
|
| 86 | |||
| 87 | // callstack is needed for getvar() |
||
| 88 | 184 | $ARCurrent->arCallStack[]=&$arCallArgs; |
|
| 89 | // keep track of the context (php or pinp) in which the called template runs. call always sets it php, CheckConfig sets it to pinp if necessary. |
||
| 90 | 184 | $this->pushContext( array( |
|
| 91 | 184 | "arSuperContext" => array(), |
|
| 92 | 184 | "arCurrentObject" => $this, |
|
| 93 | 184 | "scope" => "php", |
|
| 94 | 46 | "arCallFunction" => $arCallFunction |
|
| 95 | 138 | ) ); |
|
| 96 | |||
| 97 | // convert the deprecated urlencoded arguments to an array |
||
| 98 | 184 | if (is_string($arCallArgs)) { |
|
| 99 | 184 | $ARCurrent->arTemp=$arCallArgs; |
|
| 100 | 184 | $arCallArgs=array(); |
|
| 101 | 184 | Parse_str($ARCurrent->arTemp, $arCallArgs); |
|
| 102 | 138 | } |
|
| 103 | // import the arguments in the current scope, but don't overwrite existing |
||
| 104 | // variables. |
||
| 105 | 184 | if (is_array($arCallArgs)) { |
|
| 106 | 184 | extract($arCallArgs,EXTR_SKIP); |
|
| 107 | 138 | } |
|
| 108 | // now find the initial nls selection (CheckConfig is needed for per |
||
| 109 | // tree selected defaults) |
||
| 110 | 184 | if ($ARCurrent->nls) { |
|
| 111 | $this->reqnls=$ARCurrent->nls; |
||
| 112 | 184 | } else if (isset($ARConfig->cache[$this->path]) && $ARConfig->cache[$this->path]->nls->default) { |
|
| 113 | 100 | $this->reqnls = $ARConfig->cache[$this->path]->nls->default; |
|
| 114 | 75 | } else { |
|
| 115 | 184 | $this->reqnls=$AR->nls->default; |
|
| 116 | } |
||
| 117 | 184 | if (isset($this->data->nls->list[$this->reqnls]) || !isset($this->data->nls)) { |
|
| 118 | // the requested language is available |
||
| 119 | 184 | $this->nls=$this->reqnls; |
|
| 120 | 184 | $nls=&$this->nls; |
|
| 121 | 138 | } else { |
|
| 122 | // the requested language is not available, use default of the |
||
| 123 | // current object instead. |
||
| 124 | $this->nls=$this->data->nls->default; |
||
| 125 | 3 | $nls=&$this->nls; |
|
| 126 | } |
||
| 127 | 184 | if ($nls && isset($this->data->$nls)) { |
|
| 128 | // now set the data and nlsdata pointers |
||
| 129 | 132 | $this->nlsdata=$this->data->$nls; |
|
| 130 | 132 | $nlsdata=&$this->nlsdata; |
|
| 131 | 132 | $data=&$this->data; |
|
| 132 | 99 | } else { |
|
| 133 | // this object doesn't support nls data |
||
| 134 | 184 | $this->nlsdata=$this->data; |
|
| 135 | 184 | $nlsdata=&$this->data; |
|
| 136 | 184 | $data=&$this->data; |
|
| 137 | 3 | } |
|
| 138 | 184 | if (isset($this->data->custom['none'])) { |
|
| 139 | 7 | $customdata=$this->data->custom['none']; |
|
| 140 | 6 | } |
|
| 141 | 184 | if (isset($this->data->custom[$nls])) { |
|
| 142 | $customnlsdata=$this->data->custom[$nls]; |
||
| 143 | } |
||
| 144 | |||
| 145 | 184 | $arCallFunctionOrig = $arCallFunction; |
|
| 146 | 184 | if (strpos($arCallFunctionName,"::")!==false) { |
|
| 147 | // template of a specific class defined via call("class::template"); |
||
| 148 | 24 | list($arType, $arCallFunction)=explode("::",$arCallFunctionName); |
|
| 149 | 24 | $temp = explode(":", $arType ); |
|
| 150 | 24 | if( count($temp) > 1 ) { |
|
| 151 | $libname = $temp[0]; |
||
| 152 | $arType = $temp[1]; |
||
| 153 | 6 | $arCallFunction = $libname.":".$arCallFunction; |
|
| 154 | } |
||
| 155 | 18 | } else { |
|
| 156 | 184 | $arType=$this->type; |
|
| 157 | } |
||
| 158 | |||
| 159 | 184 | if ( $arCallFunction instanceof \Closure ) { |
|
| 160 | 4 | $context = $this->getContext(ARCALLINGCONTEXT); |
|
| 161 | 4 | if ( $context["scope"] != "pinp" ) { |
|
| 162 | $arResult = $arCallFunction($this ); |
||
| 163 | } else { |
||
| 164 | 4 | if ( $this->CheckSilent('read') ) { |
|
| 165 | 4 | $arResult = $arCallFunction($this); |
|
| 166 | 3 | } |
|
| 167 | } |
||
| 168 | 3 | } else { |
|
| 169 | 184 | if ($arCallFunction[0] === "#") { |
|
| 170 | 15 | $ARCurrent->arCallClassTemplate = true; |
|
| 171 | $arCallFunction = substr($arCallFunction, 1); |
||
| 172 | } else { |
||
| 173 | 184 | $ARCurrent->arCallClassTemplate = false; |
|
| 174 | } |
||
| 175 | |||
| 176 | 184 | if( $arCallFunction == "system.get.phtml" && ( $context = $this->getContext(ARCALLINGCONTEXT) ) && $context["scope"] != "pinp" ) { |
|
| 177 | 35 | $arResult = $this; |
|
| 178 | 24 | } else { |
|
| 179 | 184 | $libtemplate = strpos($arCallFunction,":"); |
|
| 180 | 184 | $codedir = $this->store->get_config("code"); |
|
| 181 | |||
| 182 | // if it is a subtype object, disk templates do not exists, |
||
| 183 | 184 | $subcpos = strpos($arType, '.'); |
|
| 184 | 184 | if ($subcpos !== false ) { |
|
| 185 | // subtype, skip looking for templates |
||
| 186 | 24 | $arSuper = substr($arType, 0, $subcpos); |
|
| 187 | 24 | if(!isset($AR->superClass[$arType])){ |
|
| 188 | 4 | $AR->superClass[$arType]=$arSuper; |
|
| 189 | 3 | } |
|
| 190 | 24 | $arType=$arSuper; |
|
| 191 | 18 | } |
|
| 192 | |||
| 193 | 184 | while ($arType !== "ariadne_object") { |
|
| 194 | |||
| 195 | // search for the template, stop at the root class ('ariadne_object') |
||
| 196 | // (this should not happen, as pobject must have a 'default.phtml') |
||
| 197 | 184 | $arCallTemplate=$codedir."templates/".$arType."/".$arCallFunction; |
|
| 198 | 184 | if ($libtemplate === false && file_exists($arCallTemplate)) { |
|
| 199 | //debug('found '.$arCallTemplate, 'all'); |
||
| 200 | // template found |
||
| 201 | 184 | $arCallFunction = $arCallFunctionOrig; |
|
| 202 | 184 | include($arCallTemplate); |
|
| 203 | 184 | break; |
|
| 204 | 184 | } else if (file_exists($codedir."templates/".$arType."/default.phtml")) { |
|
| 205 | //debug('found default.phtml', 'all'); |
||
| 206 | // template not found, but we did find a 'default.phtml' |
||
| 207 | 8 | include($this->store->get_config("code")."templates/".$arType."/default.phtml"); |
|
| 208 | 11 | break; |
|
| 209 | 18 | } else { |
|
| 210 | 184 | if (!($arSuper=$AR->superClass[$arType])) { |
|
| 211 | // no template found, no default.phtml found, try superclass. |
||
| 212 | |||
| 213 | 8 | if (!class_exists($arType, false)) { |
|
| 214 | // the given class was not yet loaded, so do that now |
||
| 215 | $this->store->newobject('','',$arType,new object); |
||
| 216 | } |
||
| 217 | 11 | $arSuper=get_parent_class($arType); |
|
| 218 | |||
| 219 | 26 | $AR->superClass[$arType]=$arSuper; |
|
| 220 | 6 | } |
|
| 221 | 184 | $arType=$arSuper; |
|
| 222 | 3 | } |
|
| 223 | 138 | } |
|
| 224 | } |
||
| 225 | 3 | } |
|
| 226 | 184 | array_pop($ARCurrent->arCallStack); |
|
| 227 | 184 | $this->popContext(); |
|
| 228 | 184 | debug("pobject: call: end","all","all","OUT"); |
|
| 229 | 184 | if (isset($ARCurrent->arResult)) { |
|
| 230 | // pinp templates can return results via putvar("arResult",$result); |
||
| 231 | 20 | $arResult=$ARCurrent->arResult; |
|
| 232 | 20 | unset($ARCurrent->arResult); |
|
| 233 | 15 | } |
|
| 234 | 184 | if (isset($arResult)) { |
|
| 235 | // only do a return if we really have something to return |
||
| 236 | 184 | return $arResult; |
|
| 237 | } |
||
| 238 | 24 | } |
|
| 239 | |||
| 240 | 3 | public function ls($path="", $function="list.html", $args="") { |
|
| 244 | |||
| 245 | 56 | public function get($path, $function="view.html", $args="") { |
|
| 249 | |||
| 250 | 7 | public function parents($path, $function="list.html", $args="", $top="") { |
|
| 285 | |||
| 286 | 4 | public function find($path, $criteria, $function="list.html", $args="", $limit=100, $offset=0) { |
|
| 297 | |||
| 298 | public function count_find($path='', $query='') { |
||
| 307 | |||
| 308 | public function count_ls($path) { |
||
| 311 | |||
| 312 | 3 | private function saveMergeWorkflowResult($properties, $wf_result) { |
|
| 346 | |||
| 347 | /* |
||
| 348 | saves custom data |
||
| 349 | returns properties for custom data |
||
| 350 | */ |
||
| 351 | 48 | private function saveCustomData($configcache, $properties) { |
|
| 397 | |||
| 398 | 51 | public function save($properties="", $vtype="") { |
|
| 399 | /*********************************************************************** |
||
| 400 | save the current object. |
||
| 401 | if this is a new object ($this->arIsNewObject) the path is checked and |
||
| 402 | the object is saved under the new path. |
||
| 403 | ***********************************************************************/ |
||
| 404 | 48 | global $AR, $ARnls, $ARCurrent; |
|
| 405 | 48 | debug("pobject: save([properties], $vtype)","object"); |
|
| 406 | 48 | debug("pobject: save: path=".$this->path,"object"); |
|
| 407 | 48 | $configcache=$this->loadConfig(); |
|
| 408 | 48 | $needsUnlock = false; |
|
| 409 | 48 | $arIsNewObject = false; |
|
| 410 | 48 | $result = false; |
|
| 411 | 48 | $this->error = ''; |
|
| 412 | 48 | if ($this->arIsNewObject) { // save a new object |
|
| 413 | 24 | debug("pobject: save: new object","all"); |
|
| 414 | 24 | $this->path = $this->make_path(); |
|
| 415 | 24 | $arNewParent=$this->make_path(".."); |
|
| 416 | 24 | $arNewFilename=basename($this->path); |
|
| 417 | 24 | $arIsNewObject = true; |
|
| 418 | 24 | if (preg_match("|^[a-z0-9_\{\}\.\:-]+$|i",$arNewFilename)) { // no "/" allowed, these will void the 'add' grant check. |
|
| 419 | 24 | if (!$this->exists($this->path)) { //arNewFilename)) { |
|
| 420 | 24 | if ($this->exists($arNewParent)) { |
|
| 421 | 24 | if (!$config = $this->data->config) { |
|
| 422 | 24 | $config=new object(); |
|
| 423 | 18 | } |
|
| 424 | 18 | } else { |
|
| 425 | 6 | $this->error = ar::error( sprintf($ARnls["err:noparent"],$arNewParent), 1102); |
|
| 426 | } |
||
| 427 | 18 | } else { |
|
| 428 | 6 | $this->error = ar::error( sprintf($ARnls["err:alreadyexists"],$arNewFilename), 1103); |
|
| 429 | } |
||
| 430 | 18 | } else { |
|
| 431 | 6 | $this->error = ar::error( sprintf($ARnls["err:fileillegalchars"],$arNewFilename), 1104); |
|
| 432 | } |
||
| 433 | 18 | } else { // existing object |
|
| 434 | 48 | debug("pobject: save: existing object","all"); |
|
| 435 | 48 | if ($this->exists($this->path)) { // prevent 'funny stuff' |
|
| 436 | 48 | if (!$this->lock()) { |
|
| 437 | $this->error = ar::error( $ARnls["err:objectalreadylocked"], 1105); |
||
| 438 | } else { |
||
| 439 | 48 | $needsUnlock = true; |
|
| 440 | 48 | $config = $this->data->config; |
|
| 441 | } |
||
| 442 | 36 | } else { |
|
| 443 | $this->error = ar::error($ARnls["err:corruptpathnosave"], 1106); |
||
| 444 | } |
||
| 445 | } |
||
| 446 | // pre checks done |
||
| 447 | // return now on error |
||
| 448 | 48 | if ($this->error) { |
|
| 449 | return $result;; |
||
| 450 | } |
||
| 451 | |||
| 452 | |||
| 453 | 48 | if ($ARCurrent->arCallStack) { |
|
| 454 | 48 | $arCallArgs = end($ARCurrent->arCallStack); |
|
| 455 | 36 | } else { |
|
| 456 | 20 | $arCallArgs = array(); |
|
| 457 | } |
||
| 458 | |||
| 459 | 48 | $context = $this->getContext(); |
|
| 460 | |||
| 461 | 48 | $wf_object = $this->store->newobject($this->path, $this->parent, $this->type, $this->data, $this->id, $this->lastchanged, $this->vtype, 0, $this->priority); |
|
| 462 | 48 | if ( $arIsNewObject) { |
|
| 463 | 24 | $wf_object->arIsNewObject=$arIsNewObject; |
|
| 464 | 18 | } |
|
| 465 | |||
| 466 | // this makes sure the event handlers are run on $wf_object, so that $this->data changes don't change the data of the object to be saved |
||
| 467 | 48 | $this->pushContext(array('scope' => 'php', 'arCurrentObject' => $wf_object)); |
|
| 468 | |||
| 469 | 48 | $eventData = new object(); |
|
| 470 | 48 | $eventData->arCallArgs = $arCallArgs; |
|
| 471 | 48 | $eventData->arCallFunction = $context['arCallFunction']; |
|
| 472 | 48 | $eventData->arIsNewObject = $arIsNewObject; |
|
| 473 | 48 | $eventData->arProperties = $properties; |
|
| 474 | 48 | $eventData = ar_events::fire( 'onbeforesave', $eventData ); |
|
| 475 | |||
| 476 | // pop the wf_object, not needed later, the extra scope might hinder other code |
||
| 477 | 48 | $this->popContext(); |
|
| 478 | |||
| 479 | 48 | if ( !$eventData ) { |
|
| 480 | return false; // prevent saving of the object. |
||
| 481 | } |
||
| 482 | |||
| 483 | // arguments can be altered by event handlers, only usefull when a workflow template is also defined |
||
| 484 | 48 | $arCallArgs = $eventData->arCallArgs; |
|
| 485 | |||
| 486 | // the properties from the eventData are the new property list |
||
| 487 | // no need to merge them with $properties, just manipulate the properties array directly |
||
| 488 | // in the event data. unlike the user.workflow.pre.html template |
||
| 489 | 48 | if ( is_array( $eventData->arProperties ) ) { |
|
| 490 | 48 | $properties = $eventData->arProperties; |
|
| 491 | 37 | } else { |
|
| 492 | 44 | $properties = array(); |
|
| 493 | } |
||
| 494 | |||
| 495 | // pass the current properties list to the workflow template |
||
| 496 | // for backwards compatibility and workflow templates that just |
||
| 497 | // returned only their own properties, merge them afterwards |
||
| 498 | // don't do this for the eventData arProperties! |
||
| 499 | 48 | $arCallArgs['properties'] = $properties; |
|
| 500 | 48 | $wf_result = $wf_object->call("user.workflow.pre.html", $arCallArgs); |
|
| 501 | /* merge workflow properties */ |
||
| 502 | 50 | if ( is_array($wf_result) ){ |
|
| 503 | $properties = $this->saveMergeWorkflowResult($properties,$wf_result); |
||
| 504 | } |
||
| 505 | |||
| 506 | 48 | $this->error = $wf_object->error; |
|
| 507 | 48 | $this->priority = $wf_object->priority; |
|
| 508 | 48 | $this->data = $wf_object->data; |
|
| 509 | 48 | $this->data->config = $config; |
|
| 510 | 48 | $this->data->mtime=time(); |
|
| 511 | 48 | if($arIsNewObject) { |
|
| 512 | 24 | $this->data->ctime=$this->data->mtime; |
|
| 513 | 18 | } |
|
| 514 | |||
| 515 | 48 | $this->data->muser=$AR->user->data->login; |
|
| 516 | 48 | if( !$this->data->config->owner ) { |
|
| 517 | 24 | if( !$this->data->config->owner_name) { |
|
| 518 | 24 | $this->data->config->owner_name=$AR->user->data->name; |
|
| 519 | 18 | } |
|
| 520 | 24 | $this->data->config->owner=$AR->user->data->login; |
|
| 521 | 24 | $properties["owner"][0]["value"]=$this->data->config->owner; |
|
| 522 | 18 | } |
|
| 523 | 48 | $properties["time"][0]["ctime"]=$this->data->ctime; |
|
| 524 | 48 | $properties["time"][0]["mtime"]=$this->data->mtime; |
|
| 525 | 48 | $properties["time"][0]["muser"]=$this->data->muser; |
|
| 526 | |||
| 527 | /* save custom data */ |
||
| 528 | 48 | $properties = $this->saveCustomData($configcache, $properties); |
|
| 529 | |||
| 530 | 48 | if (!$this->error) { |
|
| 531 | 48 | if ($this->path=$this->store->save($this->path, $this->type, $this->data, $properties, $vtype, $this->priority)) { |
|
| 532 | 48 | unset($this->arIsNewObject); |
|
| 533 | 48 | $this->id=$this->exists($this->path); |
|
| 534 | 48 | $result=$this->path; |
|
| 535 | |||
| 536 | 48 | $config=$this->data->config; // need to set it again, to copy owner config data |
|
| 537 | |||
| 538 | 48 | $wf_object = $this->store->newobject($this->path, $this->parent, $this->type, $this->data, $this->id, $this->lastchanged, $this->vtype, 0, $this->priority); |
|
| 539 | 48 | $arCallArgs = $eventData->arCallArgs; // returned from onbeforesave event |
|
| 540 | 48 | $arCallArgs['properties'] = $properties; |
|
| 541 | |||
| 542 | 48 | if ($arIsNewObject) { |
|
| 543 | 24 | $wf_object->arIsNewObject = $arIsNewObject; |
|
| 544 | 18 | } |
|
| 545 | 48 | $wf_result = $wf_object->call("user.workflow.post.html", $arCallArgs); |
|
| 546 | 48 | $this->error = $wf_object->error; |
|
| 547 | 48 | $this->priority = $wf_object->priority; |
|
| 548 | 48 | $this->data = $wf_object->data; |
|
| 549 | 48 | $this->data->config = $config; |
|
| 550 | /* merge workflow properties */ |
||
| 551 | |||
| 552 | 48 | if ( is_array($wf_result) ){ |
|
| 553 | $properties = $this->saveMergeWorkflowResult($properties,$wf_result); |
||
| 554 | |||
| 555 | if (!$this->store->save($this->path, $this->type, $this->data, $properties, $this->vtype, $this->priority)) { |
||
| 556 | $this->error = ar::error( ''.$this->store->error, 1108, $this->store->error); |
||
| 557 | $result = false; |
||
| 558 | } |
||
| 559 | } |
||
| 560 | // all save actions have been done, fire onsave. |
||
| 561 | 48 | $this->data->config = $config; |
|
| 562 | |||
| 563 | //$this->ClearCache($this->path, true, false); |
||
| 564 | 48 | $eventData->arProperties = $properties; |
|
| 565 | 48 | $this->pushContext(array('scope' => 'php', 'arCurrentObject' => $this)); |
|
| 566 | 48 | ar_events::fire( 'onsave', $eventData ); // nothing to prevent here, so ignore return value |
|
| 567 | 48 | $this->popContext(); |
|
| 568 | 36 | View Code Duplication | } else { |
| 569 | $this->error = ar::error( ''.$this->store->error, 1107, $this->store->error); |
||
| 570 | $result = false; |
||
| 571 | } |
||
| 572 | 36 | } |
|
| 573 | 48 | if( $needsUnlock == true ){ |
|
| 574 | 48 | $this->unlock(); |
|
| 575 | 36 | } |
|
| 576 | |||
| 577 | 48 | if ($this->data->nls->list[$this->nls]) { |
|
| 578 | 48 | $mynlsdata=$this->data->{$this->nls}; |
|
| 579 | 36 | } else if ($this->data->nls->default) { |
|
| 580 | $mynlsdata=$this->data->{$this->data->nls->default}; |
||
| 581 | } else { |
||
| 582 | $mynlsdata=$this->data; |
||
| 583 | } |
||
| 584 | |||
| 585 | 48 | unset($this->nlsdata); |
|
| 586 | 48 | $this->nlsdata=$mynlsdata; |
|
| 587 | |||
| 588 | 48 | debug("pobject: save: end","all"); |
|
| 589 | 48 | return $result; |
|
| 590 | } |
||
| 591 | |||
| 592 | public function link($to) { |
||
| 595 | |||
| 596 | public function delete() { |
||
| 626 | |||
| 627 | 56 | public function exists($path) { |
|
| 631 | |||
| 632 | 72 | public function make_path($path="") { |
|
| 646 | |||
| 647 | public function make_ariadne_url($path="") { |
||
| 652 | |||
| 653 | |||
| 654 | 52 | public function make_url($path="", $nls=false, $session=true, $https=null, $keephost=null) { |
|
| 655 | 52 | global $ARConfig, $AR, $ARCurrent; |
|
| 656 | |||
| 657 | 52 | $rootoptions=$this->store->get_config('rootoptions'); |
|
| 658 | 52 | if (!$session || ($nls !== false)) { |
|
| 659 | 52 | $rootoptions = ""; |
|
| 660 | 52 | if ($session && isset($ARCurrent->session->id) && !$AR->hideSessionIDfromURL) { |
|
| 661 | $rootoptions .= "/-".$ARCurrent->session->id."-"; |
||
| 662 | } |
||
| 663 | 52 | if ($nls) { |
|
| 664 | 48 | $rootoptions_nonls = $rootoptions; |
|
| 665 | 48 | $rootoptions .= '/'.$nls; |
|
| 666 | 36 | } |
|
| 667 | 39 | } |
|
| 668 | 52 | $path=$this->make_path($path); |
|
| 669 | |||
| 670 | // now run CheckConfig and get the parentsite of the path found |
||
| 671 | 52 | if (!$temp_config=$ARConfig->cache[$path]) { |
|
| 672 | 4 | $temp_path = $path; |
|
| 673 | 4 | while (!($temp_site = $this->currentsite($temp_path)) && $temp_path!='/') { |
|
| 674 | $temp_path = $this->make_path($temp_path.'../'); |
||
| 675 | } |
||
| 676 | 4 | $temp_config=$ARConfig->cache[$temp_site]; |
|
| 677 | 3 | } |
|
| 678 | |||
| 679 | 52 | if ( !isset($keephost) && ( |
|
| 680 | 52 | (!$nls && $this->compare_hosts($AR->host, $temp_config->root["value"])) || |
|
| 681 | 52 | ($nls && ($this->compare_hosts($AR->host, $temp_config->root['list']['nls'][$nls]))) |
|
| 682 | 39 | )) { |
|
| 683 | $keephost = false; |
||
| 684 | } |
||
| 685 | |||
| 686 | 52 | if (!$keephost) { |
|
| 687 | 52 | if ($nls) { |
|
| 688 | 48 | $url=$temp_config->root["list"]["nls"][$nls]; |
|
| 689 | 48 | if (is_array($url)) { |
|
| 690 | $url = current( $url ); |
||
| 691 | } |
||
| 692 | 48 | if ($url) { |
|
| 693 | View Code Duplication | if (substr($url, -1)=='/') { |
|
| 694 | $url=substr($url, 0, -1); |
||
| 695 | } |
||
| 696 | $url .= $rootoptions_nonls; |
||
| 697 | } |
||
| 698 | 36 | } |
|
| 699 | 52 | if (!$url) { |
|
| 700 | 52 | $checkNLS = $nls; |
|
| 701 | 52 | if (!$checkNLS) { |
|
| 702 | 28 | $checkNLS = $this->nls; |
|
| 703 | 21 | } |
|
| 704 | 52 | $urlList = $temp_config->root['list']['nls'][$checkNLS]; |
|
| 705 | 52 | if (is_array($urlList)) { |
|
| 706 | $url = reset($urlList) . $rootoptions; |
||
| 707 | } else { |
||
| 708 | 52 | $url = $temp_config->root["value"].$rootoptions; |
|
| 709 | } |
||
| 710 | 39 | } |
|
| 711 | 52 | $url.=substr($path, strlen($temp_config->root["path"])-1); |
|
| 712 | |||
| 713 | 52 | if (is_bool($https)) { |
|
| 714 | if ($https) { |
||
| 715 | if ($AR->https) { |
||
| 716 | $url = preg_replace('/^http:/', 'https:', $url); |
||
| 717 | } |
||
| 718 | } else { |
||
| 719 | 13 | $url = preg_replace('/^https:/', 'http:', $url); |
|
| 720 | } |
||
| 721 | } |
||
| 722 | 39 | } else { |
|
| 723 | 48 | $checkNLS = $nls; |
|
| 724 | 48 | if (!$checkNLS) { |
|
| 725 | $checkNLS = $this->nls; |
||
| 726 | } |
||
| 727 | 48 | $urlCheck = $temp_config->root['list']['nls'][$checkNLS]; |
|
| 728 | 48 | if (!is_array($urlCheck)) { |
|
| 729 | 48 | $urlCheck = $temp_config->root["value"]; |
|
| 730 | 36 | } |
|
| 731 | 48 | $requestedHost = ldGetRequestedHost(); |
|
| 732 | 48 | if ($this->compare_hosts($requestedHost, $urlCheck)) { |
|
| 733 | $url = $requestedHost . $rootoptions; |
||
| 734 | $url .= substr($path, strlen($temp_config->root["path"])-1); |
||
| 735 | } else { |
||
| 736 | //$url=$AR->host.$AR->root.$rootoptions.$path; |
||
| 737 | 48 | $url = $protocol . $requestedHost . $AR->root . $rootoptions . $path; |
|
| 738 | } |
||
| 739 | } |
||
| 740 | 52 | return $url; |
|
| 741 | } |
||
| 742 | |||
| 743 | 52 | protected function compare_hosts($url1, $url2) { |
|
| 760 | |||
| 761 | 48 | public function make_local_url($path="", $nls=false, $session=true, $https=null) { |
|
| 815 | |||
| 816 | public function AR_implements($implements) { |
||
| 820 | |||
| 821 | View Code Duplication | public function getlocks() { |
|
| 830 | |||
| 831 | 48 | View Code Duplication | public function lock($mode="O", $time=0) { |
| 840 | |||
| 841 | 48 | View Code Duplication | public function unlock() { |
| 850 | |||
| 851 | public function touch($id=0, $timestamp=-1) { |
||
| 861 | |||
| 862 | public function mogrify($id=0, $type, $vtype=null) { |
||
| 878 | |||
| 879 | public function can_mogrify() { |
||
| 885 | |||
| 886 | public function load_properties($scope='') { |
||
| 889 | |||
| 890 | public function _load_properties($scope='') { |
||
| 893 | |||
| 894 | public function load_property($property, $scope='') { |
||
| 897 | |||
| 898 | public function _load_property($property, $scope='') { |
||
| 901 | |||
| 902 | 4 | public function GetValidGrants($path="") { |
|
| 903 | /******************************************************************** |
||
| 904 | |||
| 905 | This function finds all grants in effect on this object for the |
||
| 906 | logged in user! $AR->user must already be set. |
||
| 907 | |||
| 908 | Grants are checked in the following way: |
||
| 909 | 1) First all parents of this object are checked for grants for this |
||
| 910 | specific user. The 'nearest' grants are valid, and the path of |
||
| 911 | parent that set these grants will be the upper limit for the |
||
| 912 | checking of group grants. |
||
| 913 | 2) Now all groups of which the user is a member are checked for |
||
| 914 | grants. Likewise, all parents are checked for group grants, upto |
||
| 915 | but not including the upperlimit as set in 1. All group grants |
||
| 916 | found are merged into one grants list. |
||
| 917 | 3) If there are gropup grants, this means that there are group |
||
| 918 | grants set in a parent nearer to this object than the user grants |
||
| 919 | and therefore the groupgrants must be merged with the |
||
| 920 | usergrants. |
||
| 921 | |||
| 922 | this results in: |
||
| 923 | 1 / user: read edit group: none |
||
| 924 | 2 /dir/ group: read |
||
| 925 | 3 /dir2/ user: none group: read |
||
| 926 | 4 /dir/dir3/ group2: edit |
||
| 927 | case 1: the user takes precedence over the group, grants are 'read edit' |
||
| 928 | case 2: groupgrants are merged with usergrants, as its grants are set |
||
| 929 | in a 'nearer' parent (itself). grants are 'read edit'. |
||
| 930 | case 3: user takes precedence again. grants are 'none'. |
||
| 931 | case 4: All group grants are merged with the usergrants. |
||
| 932 | Therefore the grants are 'none read edit'. |
||
| 933 | ********************************************************************/ |
||
| 934 | |||
| 935 | 4 | global $AR; |
|
| 936 | |||
| 937 | 4 | if ($AR->user) { // login and retrieval of user object |
|
| 938 | 4 | if (!$path) { |
|
| 939 | 4 | $path=$this->path; |
|
| 940 | 3 | } |
|
| 941 | 4 | if (!$AR->user->grants[$path]) { |
|
| 942 | 4 | $grants=array(); |
|
| 943 | 4 | $userpath=$AR->user->FindGrants($path, $grants); |
|
| 944 | // if not already done, find all groups of which the user is a member |
||
| 945 | 4 | if (!is_array($AR->user->externalgroupmemberships) || count($AR->user->externalgroupmemberships)==0) { |
|
| 946 | 4 | $criteria["members"]["login"]["="]=$AR->user->data->login; |
|
| 947 | 3 | } else { |
|
| 948 | // Use the group memberships of external databases (e.g. LDAP) |
||
| 949 | $criteria="members.login='".AddSlashes($AR->user->data->login)."'"; |
||
| 950 | foreach (array_keys($AR->user->externalgroupmemberships) as $group) { |
||
| 951 | $criteria.=" or login.value='".AddSlashes($group)."'"; |
||
| 952 | } |
||
| 953 | } |
||
| 954 | 4 | if (!$AR->user->groups) { |
|
| 955 | 4 | $groups=$this->find("/system/groups/",$criteria, "system.get.phtml"); |
|
| 956 | 4 | if (is_array($groups)) { |
|
| 957 | 4 | foreach($groups as $group ){ |
|
| 958 | 4 | if (is_object($group)) { |
|
| 959 | 4 | $AR->user->groups[$group->path] = $group; |
|
| 960 | 3 | } |
|
| 961 | 3 | } |
|
| 962 | 3 | } |
|
| 963 | 4 | if (is_array($AR->user->data->config->groups)) { |
|
| 964 | 4 | foreach ($AR->user->data->config->groups as $groupPath => $groupId) { |
|
| 965 | 4 | if (!$AR->user->groups[$groupPath]) { |
|
| 966 | 1 | $AR->user->groups[$groupPath] = current($this->get($groupPath, "system.get.phtml")); |
|
| 967 | } |
||
| 968 | 3 | } |
|
| 969 | 3 | } |
|
| 970 | 4 | if (!$AR->user->groups["/system/groups/public/"]) { |
|
| 971 | if ($public=current($this->get("/system/groups/public/", "system.get.phtml"))) { |
||
| 972 | $AR->user->groups[$public->path] = $public; |
||
| 973 | } |
||
| 974 | } |
||
| 975 | 3 | } |
|
| 976 | 4 | if ($AR->user->groups) { |
|
| 977 | /* check for owner grants (set by system.get.config.phtml) */ |
||
| 978 | 4 | if (is_array($AR->user->ownergrants)) { |
|
| 979 | if (!$AR->user->groups["owner"]) { |
||
| 980 | $AR->user->groups["owner"] = @current($this->get("/system/groups/owner/", "system.get.phtml")); |
||
| 981 | } |
||
| 982 | $AR->user->groups["owner"]->data->config->usergrants = $AR->user->ownergrants; |
||
| 983 | } |
||
| 984 | 4 | foreach($AR->user->groups as $group){ |
|
| 985 | 4 | $groupgrants=array(); |
|
| 986 | 4 | if (is_object($group)) { |
|
| 987 | 4 | $group->FindGrants($path, $groupgrants, $userpath); |
|
| 988 | 4 | View Code Duplication | if (is_array($grants)) { |
| 989 | 4 | foreach($groupgrants as $gkey => $gval ){ |
|
| 990 | if (is_array($grants[$gkey]) && is_array($gval)) { |
||
| 991 | $grants[$gkey]=array_merge($gval, $grants[$gkey]); |
||
| 992 | } else |
||
| 993 | if ($gval && !is_array($gval)) { |
||
| 994 | $grants[$gkey] = $gval; |
||
| 995 | } else |
||
| 996 | if ($gval && !$grants[$gkey]) { |
||
| 997 | 1 | $grants[$gkey] = $gval; |
|
| 998 | } |
||
| 999 | 3 | } |
|
| 1000 | 3 | } else { |
|
| 1001 | 1 | $grants = $groupgrants; |
|
| 1002 | } |
||
| 1003 | 3 | } |
|
| 1004 | 3 | } |
|
| 1005 | 3 | } |
|
| 1006 | 4 | if( is_array($AR->sgGrants) ) { |
|
| 1007 | ksort($AR->sgGrants); |
||
| 1008 | $ppath = $this->make_path($path); |
||
| 1009 | foreach( $AR->sgGrants as $sgpath => $sggrants) { |
||
| 1010 | $sgpath = $this->make_path($sgpath); |
||
| 1011 | if( substr($ppath, 0, strlen($sgpath)) == $sgpath ) { // sgpath is parent of ppath or equal to ppath |
||
| 1012 | View Code Duplication | if (is_array($grants)) { |
|
| 1013 | foreach($sggrants as $gkey => $gval ){ |
||
| 1014 | if (is_array($grants[$gkey]) && is_array($gval)) { |
||
| 1015 | $grants[$gkey]=array_merge($gval, $grants[$gkey]); |
||
| 1016 | } else |
||
| 1017 | if ($gval && !is_array($gval)) { |
||
| 1018 | $grants[$gkey] = $gval; |
||
| 1019 | } else |
||
| 1020 | if ($gval && !$grants[$gkey]) { |
||
| 1021 | $grants[$gkey] = $gval; |
||
| 1022 | } |
||
| 1023 | } |
||
| 1024 | } else { |
||
| 1025 | $grants = $sggrants; |
||
| 1026 | } |
||
| 1027 | } |
||
| 1028 | } |
||
| 1029 | } |
||
| 1030 | 4 | $AR->user->grants[$path]=$grants; |
|
| 1031 | 3 | } |
|
| 1032 | 4 | $grants=$AR->user->grants[$path]; |
|
| 1033 | |||
| 1034 | 3 | } |
|
| 1035 | 4 | debug("pobject: GetValidGrants(user:".$AR->user->data->login."): end ( ".debug_serialize($grants)." )","all"); |
|
| 1036 | 4 | return $grants; |
|
| 1037 | } |
||
| 1038 | |||
| 1039 | |||
| 1040 | 184 | public function pushContext($context) { |
|
| 1049 | |||
| 1050 | public function setContext($context, $level=0) { |
||
| 1056 | |||
| 1057 | 184 | public function popContext() { |
|
| 1064 | |||
| 1065 | 184 | public static function getContext($level=0) { |
|
| 1072 | |||
| 1073 | 72 | public function CheckAdmin($user) { |
|
| 1082 | |||
| 1083 | 60 | public function CheckLogin($grant, $modifier=ARTHISTYPE) { |
|
| 1128 | |||
| 1129 | |||
| 1130 | 4 | public function CheckPublic($grant, $modifier=ARTHISTYPE) { |
|
| 1147 | |||
| 1148 | 44 | public function CheckSilent($grant, $modifier=ARTHISTYPE, $path=".") { |
|
| 1172 | |||
| 1173 | public function CheckNewFile($newfilename) { |
||
| 1206 | |||
| 1207 | View Code Duplication | public function resetConfig($path='') { |
|
| 1219 | |||
| 1220 | 36 | View Code Duplication | public function clearChildConfigs($path='') { |
| 1233 | |||
| 1234 | 36 | protected function getConfig() { |
|
| 1235 | 36 | global $ARConfig, $ARCurrent, $ARConfigChecked; |
|
| 1236 | // $context=$this->getContext(0); |
||
| 1237 | // debug("getConfig(".$this->path.") context: ".$context['scope'] ); |
||
| 1238 | // debug(print_r($ARConfig->nls, true)); |
||
| 1239 | 36 | if( !$ARConfig->cache[$this->parent] && $this->parent!=".." ) { |
|
| 1240 | 4 | $parent = current($this->get($this->parent, "system.get.phtml")); |
|
| 1241 | 4 | if ($parent) { |
|
| 1242 | 4 | $parent->getConfig(); |
|
| 1243 | 3 | } |
|
| 1244 | 3 | } |
|
| 1245 | |||
| 1246 | 36 | $this->getConfigData(); |
|
| 1247 | |||
| 1248 | 36 | $ARConfig->pinpcache[$this->path] = $ARConfig->pinpcache[$this->parent]; |
|
| 1249 | // backwards compatibility when calling templates from config.ini |
||
| 1250 | 36 | $prevArConfig = $ARCurrent->arConfig; |
|
| 1251 | 36 | $ARCurrent->arConfig = $ARConfig->pinpcache[$this->path]; |
|
| 1252 | |||
| 1253 | 36 | $arCallArgs['arConfig'] = $ARConfig->pinpcache[$this->path]; |
|
| 1254 | |||
| 1255 | /* calling config.ini directly for each system.get.config.phtml call */ |
||
| 1256 | 36 | $loginSilent = $ARCurrent->arLoginSilent; |
|
| 1257 | 36 | $ARCurrent->arLoginSilent = true; |
|
| 1258 | // debug("getConfig:checkconfig start"); |
||
| 1259 | |||
| 1260 | 36 | $initialNLS = $ARCurrent->nls; |
|
| 1261 | 36 | $initialConfigChecked = $ARConfigChecked; |
|
| 1262 | |||
| 1263 | 36 | $ARConfig->cache[$this->path]->inConfigIni = true; |
|
| 1264 | 36 | if ($ARConfig->cache[$this->path]->hasConfigIni && !$this->CheckConfig('config.ini', $arCallArgs)) { |
|
| 1265 | //debug("pobject::getConfig() loaded config.ini @ ".$this->path); |
||
| 1266 | // debug("getConfig:checkconfig einde"); |
||
| 1267 | 4 | $arConfig = $ARCurrent->arResult; |
|
| 1268 | 4 | if (!isset($arConfig)) { |
|
| 1269 | $arConfig = $ARCurrent->arConfig; |
||
| 1270 | } |
||
| 1271 | 4 | unset($ARCurrent->arResult); |
|
| 1272 | 4 | if (is_array($arConfig['library'])) { |
|
| 1273 | if (!$ARConfig->libraries[$this->path]) { |
||
| 1274 | $ARConfig->libraries[$this->path] = array(); |
||
| 1275 | } |
||
| 1276 | foreach ($arConfig['library'] as $libName => $libPath) { |
||
| 1277 | $this->loadLibrary($libName, $libPath); |
||
| 1278 | } |
||
| 1279 | unset($arConfig['library']); |
||
| 1280 | } |
||
| 1281 | 4 | $ARConfig->pinpcache[$this->path] = (array) $arConfig; |
|
| 1282 | 3 | } |
|
| 1283 | 36 | $ARConfig->cache[$this->path]->inConfigIni = false; |
|
| 1284 | 36 | $this->clearChildConfigs( $this->path ); // remove any config data for child objects, since these are set before their parent config was set |
|
| 1285 | 36 | $ARConfigChecked = $initialConfigChecked; |
|
| 1286 | 36 | $ARCurrent->nls = $initialNLS; |
|
| 1287 | |||
| 1288 | 36 | $arConfig = &$ARConfig->pinpcache[$this->path]; |
|
| 1289 | 36 | View Code Duplication | if (!is_array($arConfig['authentication']['userdirs'])) { |
| 1290 | $arConfig['authentication']['userdirs'] = array('/system/users/'); |
||
| 1291 | } else { |
||
| 1292 | 36 | if (reset($arConfig['authentication']['userdirs']) != '/system/users/') { |
|
| 1293 | array_unshift($arConfig['authentication']['userdirs'], '/system/users/'); |
||
| 1294 | } |
||
| 1295 | } |
||
| 1296 | 36 | View Code Duplication | if (!is_array($arConfig['authentication']['groupdirs'])) { |
| 1297 | $arConfig['authentication']['groupdirs'] = array('/system/groups/'); |
||
| 1298 | } else { |
||
| 1299 | 36 | if (reset($arConfig['authentication']['groupdirs']) != '/system/groups/') { |
|
| 1300 | array_unshift($arConfig['authentication']['groupdirs'], '/system/groups/'); |
||
| 1301 | } |
||
| 1302 | } |
||
| 1303 | |||
| 1304 | 36 | $ARCurrent->arLoginSilent = $loginSilent; |
|
| 1305 | 36 | $ARCurrent->arConfig = $prevArConfig; |
|
| 1306 | 36 | } |
|
| 1307 | |||
| 1308 | 36 | protected function getConfigData() { |
|
| 1408 | |||
| 1409 | 60 | public function loadConfig($path='') { |
|
| 1456 | |||
| 1457 | |||
| 1458 | // TODO: look for a way to merge loadConfig and loadUserConfig into one function |
||
| 1459 | |||
| 1460 | 12 | public function loadUserConfig($path='') { |
|
| 1475 | |||
| 1476 | 48 | protected function getTemplateFromCache($path, $type, $function, &$arSuperContext) { |
|
| 1477 | 48 | global $AR, $ARConfig; |
|
| 1478 | 48 | $templatesList = $ARConfig->libraryCache[$path][$function]; |
|
| 1479 | 48 | if (!is_array($templatesList)) { |
|
| 1480 | 48 | return false; |
|
| 1481 | } |
||
| 1482 | foreach ($templatesList as $checkpath => $templates) { |
||
| 1483 | $arType = $type; |
||
| 1484 | while ($arType!='ariadne_object') { |
||
| 1485 | // echo "checking $i::$arType<br>\n"; |
||
| 1486 | if (!$arSuperContext[$checkpath.":".$arType.":".$function] && ($arTemplate=$templates[$arType][$this->reqnls])) { |
||
| 1487 | $arCallTemplate=$arType.".".$function.".".$this->reqnls; |
||
| 1488 | $arCallTemplateName = $function; |
||
| 1489 | $arCallTemplateNLS = $this->reqnls; |
||
| 1490 | break 2; |
||
| 1491 | View Code Duplication | } else if (!$arSuperContext[$checkpath.":".$arType.":".$function] && ($arTemplate=$templates[$arType]['any'])) { |
|
| 1492 | $arCallTemplate=$arType.".".$function.".any"; |
||
| 1493 | $arCallTemplateName = $function; |
||
| 1494 | $arCallTemplateNLS = "any"; |
||
| 1495 | break 2; |
||
| 1496 | } else { |
||
| 1497 | |||
| 1498 | if (!($arSuper=$AR->superClass[$arType])) { |
||
| 1499 | // no template found, no default.phtml found, try superclass. |
||
| 1500 | if ($subcpos = strpos($arType, '.')) { |
||
| 1501 | $arSuper = substr($arType, 0, $subcpos); |
||
| 1502 | } else { |
||
| 1503 | if (!class_exists($arType, false)) { |
||
| 1504 | // the given class was not yet loaded, so do that now |
||
| 1505 | $arTemp=$this->store->newobject('','',$arType,new object); |
||
| 1506 | } else { |
||
| 1507 | $arTemp=new $arType(); |
||
| 1508 | } |
||
| 1509 | $arSuper=get_parent_class($arTemp); |
||
| 1510 | } |
||
| 1511 | $AR->superClass[$arType]=$arSuper; |
||
| 1512 | } |
||
| 1513 | $arType=$arSuper; |
||
| 1514 | } |
||
| 1515 | } |
||
| 1516 | } |
||
| 1517 | |||
| 1518 | $config = ($ARConfig->cache[$arTemplate["arLibraryLocalPath"]]) ? $ARConfig->cache[$arTemplate["arLibraryLocalPath"]] : $this->loadConfig($arTemplate["arLibraryLocalPath"]); |
||
| 1519 | $arPrivateTemplate = $config->privatetemplates[$arType][$function]; |
||
| 1520 | |||
| 1521 | return array( |
||
| 1522 | "arTemplateId" => $arTemplate["arTemplateId"], |
||
| 1523 | "arCallTemplate" => $arCallTemplate, |
||
| 1524 | "arCallType" => $type, |
||
| 1525 | "arCallTemplateName" => $arCallTemplateName, |
||
| 1526 | "arCallTemplateNLS" => $arCallTemplateNLS, |
||
| 1527 | "arCallTemplateType" => $arType, |
||
| 1528 | "arCallTemplatePath" => $arTemplate["arLibraryLocalPath"], |
||
| 1529 | "arLibrary" => "current", |
||
| 1530 | "arLibraryPath" => $arTemplate["arLibraryPath"], |
||
| 1531 | "arPrivateTemplate" => $arPrivateTemplate |
||
| 1532 | ); |
||
| 1533 | } |
||
| 1534 | |||
| 1535 | public function loadLibraryCache($base, $path, $arLibraryPath = "") { |
||
| 1536 | global $ARConfig; |
||
| 1537 | if (!$arLibraryPath) { |
||
| 1538 | $arLibraryPath = $path; |
||
| 1539 | } |
||
| 1540 | $config = ($ARConfig->cache[$path]) ? $ARConfig->cache[$path] : $this->loadConfig($path); |
||
| 1541 | $templates = $config->localTemplates; |
||
| 1542 | if (is_array($templates)) { |
||
| 1543 | $list = array(); |
||
| 1544 | foreach ($templates as $type => $functions) { |
||
| 1545 | foreach ($functions as $function => $template) { |
||
| 1546 | foreach ($template as $nls => $templateId) { |
||
| 1547 | $list[$function][$type][$nls] = array( |
||
| 1548 | "arTemplateId" => $templateId, |
||
| 1549 | "arLibraryPath" => $arLibraryPath, |
||
| 1550 | "arLibraryLocalPath" => $path |
||
| 1551 | ); |
||
| 1552 | } |
||
| 1553 | } |
||
| 1554 | } |
||
| 1555 | |||
| 1556 | foreach ($list as $function => $types) { |
||
| 1557 | if (!is_array($ARConfig->libraryCache[$base][$function])) { |
||
| 1558 | $ARConfig->libraryCache[$base][$function] = array( |
||
| 1559 | $path => $types |
||
| 1560 | ); |
||
| 1561 | } else { |
||
| 1562 | $ARConfig->libraryCache[$base][$function][$path] = $types; |
||
| 1563 | } |
||
| 1564 | } |
||
| 1565 | } |
||
| 1566 | list($basetype,) = explode('.', $config->type,2); |
||
| 1567 | if ($path != '/' && $basetype != 'psection') { |
||
| 1568 | $this->loadLibraryCache($base, $this->store->make_path($path, '../'), $arLibraryPath); |
||
| 1569 | } |
||
| 1570 | } |
||
| 1571 | |||
| 1572 | 4 | public function loadLibrary($name, $path) { |
|
| 1615 | |||
| 1616 | // returns a list of libraries loaded on $path |
||
| 1617 | public function getLibraries($path = '') { |
||
| 1622 | |||
| 1623 | public function mergeLibraryConfig( $defaultLibraryName, $defaults ) { |
||
| 1636 | |||
| 1637 | public function _mergeLibraryConfig( $defaultLibraryName, $defaults ) { |
||
| 1640 | |||
| 1641 | 60 | public function getPinpTemplate($arCallFunction='view.html', $path=".", $top="", $inLibrary = false, $librariesSeen = null, $arSuperContext=array()) { |
|
| 1791 | |||
| 1792 | 64 | public function CheckConfig($arCallFunction="", $arCallArgs="") { |
|
| 1793 | // returns true when cache isn't up to date and no other template is |
||
| 1794 | // defined for $path/$function. Else it takes care of output to the |
||
| 1795 | // browser. |
||
| 1796 | // All these templates must exist under a fixed directory, $AR->dir->templates |
||
| 1797 | 64 | global $nocache, $AR, $ARConfig, $ARCurrent, $ARBeenHere, $ARnls, $ARConfigChecked; |
|
| 1798 | 64 | $MAX_LOOP_COUNT=10; |
|
| 1799 | |||
| 1800 | |||
| 1801 | // system templates (.phtml) have $arCallFunction=='', so the first check in the next line is to |
||
| 1802 | // make sure that loopcounts don't apply to those templates. |
||
| 1803 | 64 | if (0 && $arCallFunction && $ARBeenHere[$this->path][$arCallFunction]>$MAX_LOOP_COUNT) { // protect against infinite loops |
|
| 1804 | error(sprintf($ARnls["err:maxloopexceed"],$this->path,$arCallFunction,$arCallArgs)); |
||
| 1805 | $this->store->close(); |
||
| 1806 | exit(); |
||
| 1807 | } else { |
||
| 1808 | 64 | $ARBeenHere[$this->path][$arCallFunction]+=1; |
|
| 1809 | |||
| 1810 | // this will prevent the parents from setting the cache time |
||
| 1811 | 64 | $initialConfigChecked = $ARConfigChecked; |
|
| 1812 | 64 | $ARConfigChecked = true; |
|
| 1813 | 64 | $config = ($ARConfig->cache[$this->path]) ? $ARConfig->cache[$this->path] : $this->loadConfig(); |
|
| 1814 | 64 | $ARConfigChecked = $initialConfigChecked; |
|
| 1815 | 64 | $ARConfig->nls=$config->nls; |
|
| 1816 | |||
| 1817 | |||
| 1818 | // if a default language is entered in a parent and no language is |
||
| 1819 | // explicitly selected in the url, use that default. |
||
| 1820 | // The root starts with the system default (ariadne.phtml config file) |
||
| 1821 | 64 | if ( !$ARCurrent->nls ) { |
|
| 1822 | 64 | if ( $config->root['nls'] ) { |
|
| 1823 | $this->reqnls = $config->root['nls']; |
||
| 1824 | if ( !$ARConfigChecked ) { |
||
| 1825 | $ARCurrent->nls = $this->reqnls; |
||
| 1826 | } |
||
| 1827 | 64 | } else if ( $config->nls->default ) { |
|
| 1828 | 64 | $this->reqnls = $config->nls->default; |
|
| 1829 | 64 | $this->nls = $this->reqnls; |
|
| 1830 | 64 | if ( !$ARConfigChecked ) { |
|
| 1831 | 16 | $ARCurrent->nls = $this->nls; |
|
| 1832 | } |
||
| 1833 | 48 | } |
|
| 1834 | 48 | } else { |
|
| 1835 | $this->reqnls = $ARCurrent->nls; |
||
| 1836 | } |
||
| 1837 | 64 | $nls = &$this->nls; |
|
| 1838 | 64 | $reqnls = &$this->reqnls; |
|
| 1839 | |||
| 1840 | 64 | if (!$ARConfigChecked && is_object($ARnls)) { |
|
| 1841 | $ARnls->setLanguage($ARCurrent->nls); |
||
| 1842 | } |
||
| 1843 | |||
| 1844 | |||
| 1845 | 64 | if (!$ARCurrent->arContentTypeSent) { |
|
| 1846 | ldHeader("Content-Type: text/html; charset=UTF-8"); |
||
| 1847 | $ARCurrent->arContentTypeSent = true; |
||
| 1848 | } |
||
| 1849 | |||
| 1850 | /* // FIXME: the acceptlang code works a bit too well.. it overrides psite configuration settings. |
||
| 1851 | |||
| 1852 | if ($ARCurrent->acceptlang && !$ARCurrent->nls) { |
||
| 1853 | if ($ARCurrent->acceptlang && is_array($this->data->nls->list)) { |
||
| 1854 | $validlangs = array_intersect(array_keys($ARCurrent->acceptlang), array_keys($this->data->nls->list)); |
||
| 1855 | } |
||
| 1856 | if ($validlangs) { |
||
| 1857 | $reqnls=array_shift($validlangs); |
||
| 1858 | $ARCurrent->nls = $reqnls; |
||
| 1859 | } |
||
| 1860 | } |
||
| 1861 | */ |
||
| 1862 | 64 | if (is_array($this->data->custom) && $this->data->custom['none']) { |
|
| 1863 | 4 | $this->customdata=$this->data->custom['none']; |
|
| 1864 | 3 | } |
|
| 1865 | 64 | if (is_array($this->data->custom) && $this->data->custom[$nls]) { |
|
| 1866 | $this->customnlsdata=$this->data->custom[$nls]; |
||
| 1867 | } |
||
| 1868 | |||
| 1869 | 64 | if (!$ARConfigChecked) { |
|
| 1870 | // this template is the first template called in this request. |
||
| 1871 | $eventData = new object(); |
||
| 1872 | $eventData->arCallArgs = $arCallArgs; |
||
| 1873 | $eventData->arCallFunction = $arCallFunction; |
||
| 1874 | |||
| 1875 | $ARConfigChecked = true; |
||
| 1876 | $result = ar_events::fire( 'onbeforeview', $eventData ); |
||
| 1877 | $ARConfigChecked = $initialConfigChecked; |
||
| 1878 | if ( !$result ) { //prevent default action: view |
||
| 1879 | return false; |
||
| 1880 | } |
||
| 1881 | } |
||
| 1882 | |||
| 1883 | 64 | if (!$ARConfigChecked) { |
|
| 1884 | // if this object isn't available in the requested language, show |
||
| 1885 | // a language select dialog with all available languages for this object. |
||
| 1886 | if (isset($this->data->nls) && !$this->data->name) { |
||
| 1887 | if (!$ARCurrent->forcenls && (!isset($this->data->nls->list[$reqnls]) || !$config->nls->list[$reqnls])) { |
||
| 1888 | if (!$ARCurrent->nolangcheck && $arCallFunction != 'config.ini') { |
||
| 1889 | $ARCurrent->nolangcheck=1; |
||
| 1890 | $eventData = new object(); |
||
| 1891 | $eventData->arCallFunction = $arCallFunction; |
||
| 1892 | $eventData->arCallArgs = $arCallArgs; |
||
| 1893 | $eventData->arRequestedNLS = $reqnls; |
||
| 1894 | $result = ar_events::fire( 'onlanguagenotfound', $eventData ); |
||
| 1895 | if ( $result ) { // continue with default action: langaugeselect |
||
| 1896 | $result->arCallArgs["arOriginalFunction"] = $result->arCallFunction; |
||
| 1897 | $this->call("user.languageselect.html", $result->arCallArgs); |
||
| 1898 | return false; |
||
| 1899 | } |
||
| 1900 | } else { |
||
| 1901 | $this->nlsdata=$this->data->$nls; |
||
| 1902 | } |
||
| 1903 | } else { |
||
| 1904 | $this->nlsdata=$this->data->$reqnls; |
||
| 1905 | } |
||
| 1906 | } |
||
| 1907 | $ARCurrent->nolangcheck=1; |
||
| 1908 | } |
||
| 1909 | |||
| 1910 | /* |
||
| 1911 | Set ARConfigChecked to true to indicate that we have been here |
||
| 1912 | earlier. |
||
| 1913 | */ |
||
| 1914 | 64 | $ARConfigChecked = true; |
|
| 1915 | 64 | if ($arCallFunction) { // don't search for templates named '' |
|
| 1916 | // FIXME: Redirect code has to move to getPinpTemplate() |
||
| 1917 | 60 | $redirects = $ARCurrent->shortcut_redirect; |
|
| 1918 | 60 | if (is_array($redirects)) { |
|
| 1919 | $redirpath = $this->path; |
||
| 1920 | while (!$template['arTemplateId'] && |
||
| 1921 | ($redir = array_pop($redirects)) && |
||
| 1922 | $redir["keepurl"] && |
||
| 1923 | (substr($redirpath, 0, strlen($redir["dest"])) == $redir["dest"]) |
||
| 1924 | ) { |
||
| 1925 | $template = $this->getPinpTemplate($arCallFunction, $redirpath, $redir["dest"]); |
||
| 1926 | $redirpath = $redir['src']; |
||
| 1927 | } |
||
| 1928 | |||
| 1929 | if (!$template["arTemplateId"] && $redirpath) { |
||
| 1930 | $template = $this->getPinpTemplate($arCallFunction, $redirpath); |
||
| 1931 | } |
||
| 1932 | } |
||
| 1933 | 60 | if (!$template["arTemplateId"]) { |
|
| 1934 | 60 | $template = $this->getPinpTemplate($arCallFunction); |
|
| 1935 | 45 | } |
|
| 1936 | |||
| 1937 | 60 | if ($template["arCallTemplate"] && $template["arTemplateId"]) { |
|
| 1938 | 12 | if (!is_array($ARCurrent->cacheTemplateChain)) { |
|
| 1939 | $ARCurrent->cacheTemplateChain = array(); |
||
| 1940 | } |
||
| 1941 | 12 | if (!is_array($ARCurrent->cacheTemplateChain[$template["arTemplateId"]])) { |
|
| 1942 | 8 | $ARCurrent->cacheTemplateChain[$template["arTemplateId"]] = array(); |
|
| 1943 | 6 | } |
|
| 1944 | 12 | if (!is_array($ARCurrent->cacheTemplateChain[$template["arTemplateId"]][$template['arCallTemplate']])) { |
|
| 1945 | 12 | $ARCurrent->cacheTemplateChain[$template["arTemplateId"]][$template['arCallTemplate']] = array(); |
|
| 1946 | 9 | } |
|
| 1947 | 12 | if (!$ARCurrent->cacheTemplateChain[$template["arTemplateId"]][$template['arCallTemplate']][$template['arCallTemplateType']]) { |
|
| 1948 | 12 | $ARCurrent->cacheTemplateChain[$template["arTemplateId"]][$template['arCallTemplate']][$template['arCallTemplateType']] = 0; |
|
| 1949 | 9 | } |
|
| 1950 | 12 | $ARCurrent->cacheTemplateChain[$template["arTemplateId"]][$template['arCallTemplate']][$template['arCallTemplateType']]++; |
|
| 1951 | |||
| 1952 | |||
| 1953 | 12 | debug("CheckConfig: arCallTemplate=".$template["arCallTemplate"].", arTemplateId=".$template["arTemplateId"],"object"); |
|
| 1954 | // $arCallTemplate=$this->store->get_config("files")."templates".$arCallTemplate; |
||
| 1955 | // check if template exists, if it doesn't exist, then continue the original template that called CheckConfig |
||
| 1956 | 12 | $arTemplates=$this->store->get_filestore("templates"); |
|
| 1957 | if ( |
||
| 1958 | 12 | $arTemplates->exists($template["arTemplateId"], $template["arCallTemplate"].".inc") |
|
| 1959 | 9 | ) { |
|
| 1960 | // check if the requested language exists, if not do not display anything, |
||
| 1961 | // unless otherwise indicated by $ARCurrent->allnls |
||
| 1962 | // This triggers only for pinp templates called by other templates, |
||
| 1963 | // as the first template (in the url) will first trigger the language |
||
| 1964 | // choice dialogue instead. |
||
| 1965 | 12 | $arLibrary = $template['arLibrary']; |
|
| 1966 | 12 | if (is_int($arLibrary)) { |
|
| 1967 | // set the library name for unnamed libraries to 'current' |
||
| 1968 | // so that calls using getvar('arLibrary') will keep on working |
||
| 1969 | $arLibrary = "current"; |
||
| 1970 | } |
||
| 1971 | |||
| 1972 | 12 | View Code Duplication | if (!is_string($arCallArgs)) { |
| 1973 | 12 | $arCallArgs['arCallFunction'] = $arCallFunction; |
|
| 1974 | 12 | $arCallArgs['arLibrary'] = $arLibrary; |
|
| 1975 | 12 | $arCallArgs['arLibraryPath'] = $template["arLibraryPath"]; |
|
| 1976 | 9 | } |
|
| 1977 | |||
| 1978 | 12 | $ARCurrent->arCallStack[]=$arCallArgs; |
|
| 1979 | // start running a pinp template |
||
| 1980 | |||
| 1981 | 12 | $this->pushContext( |
|
| 1982 | array( |
||
| 1983 | 12 | "scope" => "pinp", |
|
| 1984 | 12 | "arLibrary" => $arLibrary, |
|
| 1985 | 12 | "arLibraryPath" => $template['arLibraryPath'], |
|
| 1986 | 12 | "arCallFunction" => $arCallFunction, |
|
| 1987 | 12 | "arCurrentObject" => $this, |
|
| 1988 | 12 | "arCallType" => $template['arCallType'], |
|
| 1989 | 12 | "arCallTemplateName" => $template['arCallTemplateName'], |
|
| 1990 | 12 | "arCallTemplateNLS" => $template['arCallTemplateNLS'], |
|
| 1991 | 12 | "arCallTemplateType" => $template['arCallTemplateType'], |
|
| 1992 | 12 | "arCallTemplatePath" => $template['arCallTemplatePath'], |
|
| 1993 | 12 | "arLibrariesSeen" => $template['arLibrariesSeen'] |
|
| 1994 | 9 | ) |
|
| 1995 | 9 | ); |
|
| 1996 | |||
| 1997 | // FIXME: is 2 het correcte getal? Kan dit minder magisch? |
||
| 1998 | 12 | if (count($ARCurrent->arCallStack) == 2 && $template['arPrivateTemplate']) { |
|
| 1999 | // Do not allow private templates to be called first in the stack. |
||
| 2000 | // echo "Bad request"; |
||
| 2001 | |||
| 2002 | // FIXME: Echte header sturen? Of gewoon niet uitvoeren? Wat is het correcte gedrag? |
||
| 2003 | // Return true zorgt er voor dat de default 404 handler het oppikt alsof het template niet bestaat. |
||
| 2004 | $this->popContext(); |
||
| 2005 | array_pop($ARCurrent->arCallStack); |
||
| 2006 | return true; |
||
| 2007 | 12 | } else if ($ARCurrent->forcenls || isset($this->data->nls->list[$reqnls])) { |
|
| 2008 | // the requested language is available. |
||
| 2009 | 12 | $this->nlsdata=$this->data->$reqnls; |
|
| 2010 | 12 | $this->nls=$reqnls; |
|
| 2011 | 12 | $continue=true; |
|
| 2012 | 9 | } else if (!isset($this->data->nls)) { |
|
| 2013 | // the object has no language support |
||
| 2014 | $this->nlsdata=$this->data; |
||
| 2015 | $continue=true; |
||
| 2016 | } else if (($ARCurrent->allnls) || (!$initialConfigChecked && $ARCurrent->nolangcheck)) { |
||
| 2017 | // all objects must be displayed |
||
| 2018 | // $this->reqnls=$this->nls; // set requested nls, for checks |
||
| 2019 | $this->nls = isset($this->data->nls->default) ? $this->data->nls->default : $this->reqnls; |
||
| 2020 | $this->nlsdata = $this->data->$nls ?: $this->data->{$this->nls} ?: $this->data; |
||
| 2021 | $continue=true; |
||
| 2022 | } else { |
||
| 2023 | debug("CheckConfig: requested language not available, allnls not set","object"); |
||
| 2024 | // -> skip this object (do not run template but do return false) |
||
| 2025 | $continue=false; |
||
| 2026 | } |
||
| 2027 | 12 | if ($continue) { |
|
| 2028 | 12 | $eventData = new object(); |
|
| 2029 | 12 | View Code Duplication | if ( !$AR->contextCallHandler ) { /* prevent onbeforecall from re-entering here */ |
| 2030 | 12 | $AR->contextCallHandler = true; |
|
| 2031 | 12 | $eventData->arCallArgs = $arCallArgs; |
|
| 2032 | 12 | $eventData->arCallFunction = $arCallFunction; |
|
| 2033 | 12 | $eventData->arContext = $this->getContext(); |
|
| 2034 | 12 | $eventData = ar_events::fire('onbeforecall', $eventData); |
|
| 2035 | 12 | $ARCurrent->arResult = $eventData->arResult; |
|
| 2036 | 12 | $AR->contextCallHandler = false; |
|
| 2037 | 12 | $continue = ($eventData!=false); |
|
| 2038 | 9 | } |
|
| 2039 | 12 | if ( $continue ) { |
|
| 2040 | 12 | if (!is_array($ARCurrent->cacheCallChainSettings)) { |
|
| 2041 | $ARCurrent->cacheCallChainSettings = array(); |
||
| 2042 | } |
||
| 2043 | 12 | if ($ARConfig->cache[$this->path]->inConfigIni == false) { |
|
| 2044 | 8 | $ARCurrent->cacheCallChainSettings[$this->id] = $config->cacheSettings; |
|
| 2045 | 6 | } |
|
| 2046 | |||
| 2047 | 12 | if ($ARCurrent->ARShowTemplateBorders) { |
|
| 2048 | echo "<!-- arTemplateStart\nData: ".$this->type." ".$this->path." \nTemplate: ".$template["arCallTemplatePath"]." ".$template["arCallTemplate"]." \nLibrary:".$template["arLibrary"]." -->"; |
||
| 2049 | } |
||
| 2050 | 12 | set_error_handler(array('pobject','pinpErrorHandler'),error_reporting()); |
|
| 2051 | 12 | $arResult=$arTemplates->import($template["arTemplateId"], $template["arCallTemplate"], "", $this); |
|
| 2052 | 12 | restore_error_handler(); |
|
| 2053 | 12 | if (isset($arResult)) { |
|
| 2054 | 12 | $ARCurrent->arResult=$arResult; |
|
| 2055 | 9 | } |
|
| 2056 | 12 | if ($ARCurrent->ARShowTemplateBorders) { |
|
| 2057 | echo "<!-- arTemplateEnd -->"; |
||
| 2058 | } |
||
| 2059 | 12 | View Code Duplication | if ( !$AR->contextCallHandler ) { /* prevent oncall from re-entering here */ |
| 2060 | 12 | $AR->contextCallHandler = true; |
|
| 2061 | 12 | $temp = $ARCurrent->arResult; /* event listeners will change ARCurrent->arResult */ |
|
| 2062 | 12 | $eventData->arResult = $temp; |
|
| 2063 | 12 | ar_events::fire('oncall', $eventData ); |
|
| 2064 | 12 | $ARCurrent->arResult = $temp; /* restore correct result */ |
|
| 2065 | 12 | $AR->contextCallHandler = false; |
|
| 2066 | 9 | } |
|
| 2067 | 9 | } |
|
| 2068 | 9 | } |
|
| 2069 | 12 | array_pop($ARCurrent->arCallStack); |
|
| 2070 | 12 | $this->popContext(); |
|
| 2071 | |||
| 2072 | 12 | if ( !$initialConfigChecked && $arCallFunction != 'config.ini' ) { |
|
| 2073 | // this template was the first template called in this request. |
||
| 2074 | $eventData = new object(); |
||
| 2075 | $eventData->arCallArgs = $arCallArgs; |
||
| 2076 | $eventData->arCallFunction = $arCallFunction; |
||
| 2077 | ar_events::fire( 'onview', $eventData ); // no default action to prevent, so ignore return value. |
||
| 2078 | } |
||
| 2079 | 12 | return false; |
|
| 2080 | } else { |
||
| 2081 | 4 | debug("pobject: CheckConfig: no such file: ".$template["arTemplateId"].$template["arCallTemplate"]."","all"); |
|
| 2082 | } |
||
| 2083 | 3 | } else { |
|
| 2084 | 48 | debug("CheckConfig: no arCallTemplate ($arCallFunction from '$this->path')","object"); |
|
| 2085 | } |
||
| 2086 | |||
| 2087 | 39 | } |
|
| 2088 | } |
||
| 2089 | 56 | return true; |
|
| 2090 | } |
||
| 2091 | |||
| 2092 | public function ClearCache($path="", $private=true, $recurse=false) { |
||
| 2216 | |||
| 2217 | public function getcache($name, $nls="") { |
||
| 2269 | |||
| 2270 | public function cached($name, $nls="") { |
||
| 2279 | |||
| 2280 | public function savecache($time="") { |
||
| 2327 | |||
| 2328 | public function getdatacache($name) { |
||
| 2351 | |||
| 2352 | public function savedatacache($name,$data,$time="") { |
||
| 2369 | |||
| 2370 | 52 | public function getdata($varname, $nls="none", $emptyResult=false) { |
|
| 2436 | |||
| 2437 | public function showdata($varname, $nls="none", $emptyResult=false) { |
||
| 2440 | |||
| 2441 | public function setnls($nls) { |
||
| 2444 | |||
| 2445 | public function getcharset() { |
||
| 2448 | |||
| 2449 | public function HTTPRequest($method, $url, $postdata = "", $port=80 ) { |
||
| 2553 | |||
| 2554 | public function make_filesize( $size="" ,$precision=0) { |
||
| 2571 | |||
| 2572 | public function convertToUTF8($data, $charset = "CP1252") { |
||
| 2590 | |||
| 2591 | 28 | public function resetloopcheck() { |
|
| 2595 | |||
| 2596 | /******************************************************************** |
||
| 2597 | |||
| 2598 | "safe" functions. |
||
| 2599 | |||
| 2600 | The following functions are safe versions of existing functions |
||
| 2601 | above. |
||
| 2602 | - They don't change anything in the database. |
||
| 2603 | This means that to save/delete something, a user will need to call |
||
| 2604 | "system.save.data.phtml" or "system.delete.phtml" which check grants. |
||
| 2605 | - All functions except _get and _exists don't take a path as |
||
| 2606 | argument, they use the current objects path instead. |
||
| 2607 | |||
| 2608 | These are meant to be used by 'pinp' versions of templates, |
||
| 2609 | meaning user defined templates. 'pinp' rewrites call to functions |
||
| 2610 | to the form '$this->_function'. |
||
| 2611 | |||
| 2612 | All pinp files automatically first call CheckLogin('read'). |
||
| 2613 | |||
| 2614 | ********************************************************************/ |
||
| 2615 | |||
| 2616 | public function _call($function, $args="") { |
||
| 2623 | |||
| 2624 | public function _call_super($arCallArgs="") { |
||
| 2735 | |||
| 2736 | public function _get($path, $function="view.html", $args="") { |
||
| 2745 | |||
| 2746 | public function _call_object($object, $function, $args="") { |
||
| 2749 | |||
| 2750 | View Code Duplication | public function _ls($function="list.html", $args="") { |
|
| 2758 | |||
| 2759 | View Code Duplication | public function _parents($function="list.html", $args="", $top="") { |
|
| 2766 | |||
| 2767 | public function _find($criteria, $function="list.html", $args="", $limit=100, $offset=0) { |
||
| 2780 | |||
| 2781 | public function _exists($path) { |
||
| 2784 | |||
| 2785 | public function _implements($implements) { |
||
| 2788 | |||
| 2789 | 52 | public function getvar($var) { |
|
| 2817 | |||
| 2818 | public function _getvar($var) { |
||
| 2821 | |||
| 2822 | public function putvar($var, $value) { |
||
| 2827 | |||
| 2828 | public function _putvar($var, $value) { |
||
| 2831 | |||
| 2832 | public function _setnls($nls) { |
||
| 2835 | |||
| 2836 | // not exposed to pinp for obvious reasons |
||
| 2837 | public function sgKey($grants) { |
||
| 2850 | |||
| 2851 | public function sgBegin($grants, $key = '', $path = '.') { |
||
| 2879 | |||
| 2880 | public function sgEnd($path = '.') { |
||
| 2887 | |||
| 2888 | public function sgCall($grants, $key, $function="view.html", $args="") { |
||
| 2896 | |||
| 2897 | public function _sgBegin($grants, $key, $path = '.') { |
||
| 2900 | |||
| 2901 | public function _sgEnd($path = '.') { |
||
| 2904 | |||
| 2905 | public function _sgCall($grants, $key, $function="view.html", $args="") { |
||
| 2908 | |||
| 2909 | public function _widget($arWidgetName, $arWidgetTemplate, $arWidgetArgs="", $arWidgetType="lib") { |
||
| 2938 | |||
| 2939 | public function _getdata($varname, $nls="none", $emptyResult=false) { |
||
| 2942 | |||
| 2943 | public function _showdata($varname, $nls="none", $emptyResult=false) { |
||
| 2946 | |||
| 2947 | public function _gettext($index=false) { |
||
| 2955 | |||
| 2956 | public function _loadtext($nls, $section="") { |
||
| 2989 | |||
| 2990 | public function _startsession() { |
||
| 2995 | |||
| 2996 | public function _putsessionvar($varname, $varvalue) { |
||
| 3005 | |||
| 3006 | public function _getsessionvar($varname) { |
||
| 3015 | |||
| 3016 | public function _setsessiontimeout($timeout = 0) { |
||
| 3024 | |||
| 3025 | public function _killsession() { |
||
| 3033 | |||
| 3034 | public function _sessionid() { |
||
| 3042 | |||
| 3043 | public function _resetloopcheck() { |
||
| 3046 | |||
| 3047 | public function _make_path($path="") { |
||
| 3050 | |||
| 3051 | public function _make_ariadne_url($path="") { |
||
| 3054 | |||
| 3055 | public function _make_url($path="", $nls=false, $session=true, $https=null, $keephost=null) { |
||
| 3058 | |||
| 3059 | public function _make_local_url($path="", $nls=false, $session=true, $https=null) { |
||
| 3062 | |||
| 3063 | public function _getcache($name, $nls='') { |
||
| 3066 | |||
| 3067 | public function _cached($name, $nls='') { |
||
| 3070 | |||
| 3071 | public function _savecache($time="") { |
||
| 3074 | |||
| 3075 | public function _getdatacache($name) { |
||
| 3078 | |||
| 3079 | public function _savedatacache($name,$data,$time="") |
||
| 3083 | |||
| 3084 | 56 | public function currentsite($path="", $skipRedirects = false) { |
|
| 3101 | |||
| 3102 | public function parentsite($site) { |
||
| 3108 | |||
| 3109 | 4 | View Code Duplication | public function currentsection($path="") { |
| 3117 | |||
| 3118 | View Code Duplication | public function parentsection($path) { |
|
| 3124 | |||
| 3125 | View Code Duplication | public function currentproject($path="") { |
|
| 3133 | |||
| 3134 | public function parentproject($path) { |
||
| 3140 | |||
| 3141 | public function validateFormSecret() { |
||
| 3153 | |||
| 3154 | public function _validateFormSecret() { |
||
| 3157 | |||
| 3158 | public function getValue($name, $nls=false) { |
||
| 3175 | |||
| 3176 | public function setValue($name, $value, $nls=false) { |
||
| 3216 | |||
| 3217 | public function showValue($name, $nls=false) { |
||
| 3222 | |||
| 3223 | public function _getValue($name, $nls=false) { |
||
| 3226 | |||
| 3227 | public function _setValue($name, $value, $nls=false) { |
||
| 3230 | |||
| 3231 | public function _showValue($name, $nls=false) { |
||
| 3234 | |||
| 3235 | public function _currentsite($path="", $skipRedirects = false) { |
||
| 3238 | |||
| 3239 | public function _parentsite($site) { |
||
| 3242 | |||
| 3243 | public function _currentsection() { |
||
| 3246 | |||
| 3247 | public function _parentsection($section) { |
||
| 3250 | |||
| 3251 | public function _currentproject() { |
||
| 3254 | |||
| 3255 | public function _parentproject($path) { |
||
| 3258 | |||
| 3259 | public function _checkAdmin($user) { |
||
| 3262 | |||
| 3263 | public function _checkgrant($grant, $modifier=ARTHISTYPE, $path=".") { |
||
| 3272 | |||
| 3273 | public function _checkpublic($grant, $modifier=ARTHISTYPE) { |
||
| 3277 | |||
| 3278 | public function _getcharset() { |
||
| 3281 | |||
| 3282 | public function _count_find($query='') { |
||
| 3285 | |||
| 3286 | public function _count_ls() { |
||
| 3289 | |||
| 3290 | public function _HTTPRequest($method, $url, $postdata = "", $port=80) { |
||
| 3293 | |||
| 3294 | public function _make_filesize( $size="" ,$precision=0) { |
||
| 3297 | |||
| 3298 | public function _convertToUTF8($data, $charset = "CP1252") { |
||
| 3301 | |||
| 3302 | public function _getuser() { |
||
| 3318 | |||
| 3319 | public function ARinclude($file) { |
||
| 3322 | |||
| 3323 | 4 | public function _load($class) { |
|
| 3328 | |||
| 3329 | public function _import($class) { |
||
| 3333 | |||
| 3334 | 52 | public function html_to_text($text) { |
|
| 3351 | |||
| 3352 | public function _html_to_text($text) { |
||
| 3355 | |||
| 3356 | public function _newobject($filename, $type) { |
||
| 3364 | |||
| 3365 | public function _save($properties="", $vtype="") { |
||
| 3402 | |||
| 3403 | public function _is_supported($feature) { |
||
| 3406 | |||
| 3407 | /* |
||
| 3408 | since the preg_replace() function is able to execute normal php code |
||
| 3409 | we have to intercept all preg_replace() calls and parse the |
||
| 3410 | php code with the pinp parser. |
||
| 3411 | */ |
||
| 3412 | |||
| 3413 | |||
| 3414 | /* this is a private function used by the _preg_replace wrapper */ |
||
| 3415 | // FIXME: remove this function when the minimal php version for ariadne is raised to php 7.0 |
||
| 3416 | protected function preg_replace_compile($pattern, $replacement) { |
||
| 3428 | |||
| 3429 | public function _preg_replace($pattern, $replacement, $text, $limit = -1) { |
||
| 3430 | if (version_compare(PHP_VERSION, '7.0.0', '<')) { |
||
| 3431 | if (is_array($pattern)) { |
||
| 3432 | $newrepl = array(); |
||
| 3433 | reset($replacement); |
||
| 3434 | foreach ($pattern as $i_pattern) { |
||
| 3435 | list(, $i_replacement) = each($replacement); |
||
| 3436 | $newrepl[] = $this->preg_replace_compile($i_pattern, $i_replacement); |
||
| 3437 | } |
||
| 3438 | } else { |
||
| 3439 | $newrepl = $this->preg_replace_compile($pattern, $replacement); |
||
| 3440 | } |
||
| 3441 | } else { |
||
| 3442 | // php7 is safe, no more eval |
||
| 3443 | $newrepl = $replacement; |
||
| 3444 | } |
||
| 3445 | return preg_replace($pattern, $newrepl, $text, $limit); |
||
| 3446 | } |
||
| 3447 | |||
| 3448 | /* ob_start accepts a callback but we don't want that |
||
| 3449 | * this wrapper removes the arguments from the ob_start call |
||
| 3450 | */ |
||
| 3451 | public function _ob_start() { |
||
| 3454 | |||
| 3455 | public function _loadConfig($path='') { |
||
| 3458 | |||
| 3459 | public function _loadUserConfig($path='') { |
||
| 3460 | return $this->loadUserConfig($path); |
||
| 3461 | } |
||
| 3462 | |||
| 3463 | public function _loadLibrary($name, $path) { |
||
| 3464 | 4 | return $this->loadLibrary($name, $path); |
|
| 3465 | } |
||
| 3466 | |||
| 3467 | public function _resetConfig($path='') { |
||
| 3470 | |||
| 3471 | public function _getLibraries($path = '') { |
||
| 3474 | |||
| 3475 | |||
| 3476 | public function _getSetting($setting) { |
||
| 3477 | global $AR; |
||
| 3504 | |||
| 3505 | public function __call($name,$arguments) { |
||
| 3523 | |||
| 3524 | static public function pinpErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) { |
||
| 3546 | |||
| 3547 | } // end of ariadne_object class definition |
||
| 3548 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.