if (is_uploaded_file($this->data['CharacterSheet']['file']['tmp_name']) && move_uploaded_file($this->data['CharacterSheet']['file']['tmp_name'], $tmpfile)) {
$upfile = file_get_contents($tmpfile);
- // スキン変換
+ /* スキン変換 */
+ // Character
+ $upfile = $this->_charcterData($upfile);
+
+ // Profiles
// 繰り返し系
$upfile = $this->_key_name2multiValue($upfile);
$upfile = $this->_tablekeyname_keyname2tr($upfile);
return preg_replace($pattern, $replacement, $data);
}
+ // Character
+ function _charcterData($data)
+ {
+ $data = $this->__charcterData($data, 'name');
+ $data = $this->__charcterData($data, 'notes');
+ $data = $this->__charcterData($data, 'modified');
+ $data = $this->__charcterData($data, 'userName');
+
+ return $data;
+ }
+ function __charcterData($data, $key_name)
+ {
+ switch($key_name) {
+ case 'name':
+ $pattern = '/{C:name}/';
+ $replacement = '\$character[\'Character\'][\'name\']';
+ break;
+ case 'notes':
+ $pattern = '/{C:notes}/';
+ $replacement = '\$character[\'Character\'][\'notes\']';
+ break;
+ case 'modified':
+ $pattern = '/{C:modified:?(.*)?}/';
+ $format = 'Y/m/d H:i';
+
+ if (preg_match($pattern, $data, $matches)) {
+ if (!empty($matches[1])) {
+ if ($matches[1] == 'short') {
+ $replacement = '\$time->niceshort(\$character[\'Character\'][\'modified\'], array(\'format\' => \''. $format. '\'))';
+ } else {
+ $format = $matches[1];
+ }
+ }
+ }
+
+ if (empty($replacement)) {
+ $replacement = '\$time->format("'. $format. '", \$character[\'Character\'][\'modified\'])';
+ }
+
+ break;
+ case 'userName':
+ $pattern = '/{C:userName}/';
+ $replacement = '\$character[\'User\'][\'name\']';
+ break;
+ default:
+ return $data;
+ break;
+ }
+
+ return $this->__changeSkin($data, "echo ".$replacement, $pattern);
+ }
+
+ // Profiles
// 単純表示
function _key_name2value($data)
{
$pattern = '/{([_0-9a-z]+)}/';
- preg_match_all($pattern, $key_names_parts, $key_matches);
+ preg_match_all($pattern, $key_names_parts, $key_matches);
$keys = $key_matches[1];
$keys_str = 'array(';