예제 #1
0
 protected function parse_value($value, array $replacements = null)
 {
     //remove double-slashes (//)
     $value = preg_replace('/[\\/]{2,}/', '\\/', $value);
     //remove leading slash for string replaces (i.e. "{/MAIN/SITE_ROOT}" becomes "{MAIN/SITE_ROOT}")
     $value = preg_replace('/{\\//', '{', $value);
     //replace special vars.
     $value = ToolBox::mini_parser($value, $replacements, '{', '}');
     if (strlen($value)) {
         $value = ToolBox::resolve_path_with_dots($value);
     }
     return $value;
 }
 public function create_ability_select(cs_genericPage $page, $skillId = null, $selectThis = null)
 {
     $abilityList = Ability::get_all_abilities($this->dbObj, true);
     $abilityOptionList = ToolBox::array_as_option_list($abilityList, $selectThis);
     if (is_null($skillId)) {
         $skillId = 'new';
     }
     $optionListRepArr = array('skills__selectAbility__extra' => '', 'skill_id' => $skillId, 'optionList' => $abilityOptionList);
     if (is_numeric($skillId)) {
     } else {
         $optionListRepArr['skills__selectAbility__extra'] = 'class="newRecord"';
         $optionListRepArr['skillNum'] = 'new';
         $optionListRepArr['skill_id'] = 'new';
     }
     $retval = ToolBox::mini_parser($page->templateRows['skills__selectAbility'], $optionListRepArr, '%%', '%%');
     return $retval;
 }
예제 #3
0
 /**
  * @param bool $stripUndefinedVars      Removes undefined template vars
  * @return mixed|string                 Rendered template
  */
 public function render($stripUndefinedVars = false)
 {
     $numLoops = 0;
     if (is_string($this->_contents) || is_numeric($this->_contents)) {
         $out = $this->_contents;
     } else {
         $out = "";
     }
     $rendered = array();
     foreach ($this->_templates as $name => $contents) {
         $rendered[$name] = $contents;
     }
     $tags = array();
     while (preg_match_all('~\\{' . self::VARIABLE_REGEX . '\\}~U', $out, $tags) && $numLoops < $this->recursionDepth) {
         $out = ToolBox::mini_parser($out, $rendered, '{', '}');
         $numLoops++;
     }
     if ($stripUndefinedVars === true) {
         $out = preg_replace('/\\{' . self::VARIABLE_REGEX . '\\}/', '', $out);
     }
     return $out;
 }
예제 #4
0
 public function test_mini_parser()
 {
     $replacements = array('1' => 't', '2' => 'e', '3' => 's');
     $this->assertEquals("test", ToolBox::mini_parser('%1%%2%%3%%1%', $replacements, '%', '%'));
 }
예제 #5
0
 public static function array_as_option_list(array $data, $checkedValue = NULL, $type = "select", $useTemplateString = NULL, array $repArr = NULL)
 {
     $typeArr = array("select" => "selected", "radio" => "checked", "checkbox" => "checked");
     $myType = $typeArr[$type];
     if (is_null($useTemplateString)) {
         //
         $useTemplateString = "\t\t<option value='%%value%%'%%selectedString%%>%%display%%</option>";
     }
     $retval = "";
     foreach ($data as $value => $display) {
         //see if it's the value that's been selected.
         $selectedString = "";
         if ($value == $checkedValue || $display == $checkedValue) {
             //yep, it's selected.
             $selectedString = " " . $myType;
         }
         //create the string.
         $myRepArr = array('value' => $value, 'display' => $display, 'selectedString' => $selectedString);
         if (is_array($repArr) && is_array($repArr[$value])) {
             //merge the arrays.
             $myRepArr = array_merge($repArr[$value], $myRepArr);
         }
         $addThis = ToolBox::mini_parser($useTemplateString, $myRepArr, "%%", "%%");
         $retval = ToolBox::create_list($retval, $addThis, "\n");
     }
     return $retval;
 }
예제 #6
0
 public function _process_single_session_message($type, array $data)
 {
     $tmpl = $this->file_to_string("system/message_box.tmpl");
     $data['messageType'] = strtolower($type);
     $data['type'] = $type;
     $errorBox = ToolBox::mini_parser($tmpl, $data, '{', '}');
     return $errorBox;
 }