Ejemplo n.º 1
0
 /**
  * @param int $id
  * @return String
  */
 public function getBlock($id = null)
 {
     $id = $this->isAjax() ? intval($_POST['id']) : $id;
     $tree = $this->blockModel->getBlock($id);
     $entity = new Entity_Block();
     $entity->init($tree);
     $toReplace = array('{action}', '{tree_title}', '{tree_name}', '{tree_pid}', '{id_value}', '{side_value}', '{text_value}', '{is_text_value}', '{choiceFile}', '{uniqID}');
     $choice = new Admin_Controllers_ChoiceFile(false);
     $replace = array(empty($id) ? 'add' : 'update', $tree['title'], $tree['name'], empty($id) ? intval($_POST['pid']) : $tree['pid'], $tree['id'], $entity->getSide(), $entity->getText(), $entity->getIs_text(), $choice->genHTML(), uniqid());
     $typeModel = new Admin_Models_Type();
     $type = $typeModel->getTypeByName('block');
     $fields = json_decode($type->getJson(), true);
     $cnt = count($fields);
     if (empty($id)) {
         for ($i = 0; $i < $cnt; $i++) {
             $cntJ = count($fields[$i]['variants']);
             for ($j = 0; $j < $cntJ; $j++) {
                 $toReplace[] = '{' . $fields[$i]['name'] . '_' . $j . '_value}';
                 $replace[] = $fields[$i]['selects'] == $j ? $fields[$i]['type'] == 'select' ? 'selected="selected"' : 'checked="checked"' : '';
             }
         }
     } else {
         for ($i = 0; $i < $cnt; $i++) {
             $cntJ = count($fields[$i]['variants']);
             $str = 'get' . ucfirst($fields[$i]['name']);
             $arr = explode(',', $entity->{$str}());
             for ($j = 0; $j < $cntJ; $j++) {
                 $toReplace[] = '{' . $fields[$i]['name'] . '_' . $j . '_value}';
                 if (in_array($fields[$i]['variants'][$j], $arr)) {
                     $replace[] = $fields[$i]['type'] == 'select' ? 'selected="selected"' : 'checked="checked"';
                 } else {
                     $replace[] = '';
                 }
             }
         }
     }
     $file = file_get_contents(ADMIN . '/views/types/block.tpl');
     $result = str_replace($toReplace, $replace, $file);
     if ($this->isAjax()) {
         $this->putAjax($result);
     }
     return $result;
 }
Ejemplo n.º 2
0
    public function genView($name, $fields, $seo)
    {
        $toReplace = array('{formFile}', '{name}', '{class_name}', '{fields}', '{seo}', '{tree}');
        $formFile = '';
        $fieldsHTML = '';
        $seoHTML = '';
        $cnt = count($fields);
        for ($i = 0; $i < $cnt; $i++) {
            switch ($fields[$i]['type']) {
                case 'textarea':
                    $file = file_get_contents(TPL . '/generation/form/textarea.tpl');
                    break;
                case 'tinymce':
                    $file = file_get_contents(TPL . '/generation/form/tinymce.tpl');
                    if (empty($formFile)) {
                        $choice = new Admin_Controllers_ChoiceFile(false);
                        $formFile = "\r\n" . $choice->genHiddenForm();
                    }
                    break;
                case 'checkbox':
                    $file = file_get_contents(TPL . '/generation/form/checkbox.tpl');
                    $tmp = '';
                    $cntJ = count($fields[$i]['variants']);
                    for ($j = 0; $j < $cntJ; $j++) {
                        $tmp .= "\r\n\t\t\t\t" . '<div class="row-variants">' . "\r\n\t\t\t\t\t" . '<input type="checkbox" name="' . $name . '_' . $fields[$i]['name'] . '[]" value="' . $fields[$i]['variants'][$j] . '" {' . $fields[$i]['name'] . '_' . $j . '_value}
					 	   id="' . $name . '_' . $fields[$i]['name'] . '_' . $j . '" class="in-radio">
					<label for="' . $name . '_' . $fields[$i]['name'] . '_' . $j . '">
						' . $fields[$i]['variants'][$j] . '
					</label>
				</div>';
                    }
                    $file = str_replace('{checkbox}', $tmp, $file);
                    break;
                case 'radio':
                    $file = file_get_contents(TPL . '/generation/form/radio.tpl');
                    $tmp = '';
                    $cntJ = count($fields[$i]['variants']);
                    for ($j = 0; $j < $cntJ; $j++) {
                        $tmp .= "\r\n\t\t\t\t" . '<div class="row-variants">' . "\r\n\t\t\t\t\t" . '<input type="radio" name="' . $name . '_' . $fields[$i]['name'] . '" value="' . $fields[$i]['variants'][$j] . '" {' . $fields[$i]['name'] . '_' . $j . '_value}
						   id="' . $name . '_' . $fields[$i]['name'] . '_' . $j . '" class="in-radio">
					<label for="' . $name . '_' . $fields[$i]['name'] . '_' . $j . '">
						' . $fields[$i]['variants'][$j] . '
					</label>
				</div>';
                    }
                    $file = str_replace('{radio}', $tmp, $file);
                    break;
                case 'select':
                    $file = file_get_contents(TPL . '/generation/form/select.tpl');
                    $tmp = '';
                    $cntJ = count($fields[$i]['variants']);
                    for ($j = 0; $j < $cntJ; $j++) {
                        $tmp .= "\r\n" . "\t\t\t\t\t" . '<option value="' . $fields[$i]['variants'][$j] . '" {' . $fields[$i]['name'] . '_' . $j . '_value}>' . $fields[$i]['variants'][$j] . '</option>';
                    }
                    $file = str_replace('{option}', $tmp, $file);
                    break;
                case 'file':
                    $file = file_get_contents(TPL . '/generation/form/file.tpl');
                    break;
                case 'hidden':
                    $file = file_get_contents(TPL . '/generation/form/hidden.tpl');
                    break;
                default:
                    $file = file_get_contents(TPL . '/generation/form/default.tpl');
                    $file = str_replace('{type}', $fields[$i]['type'], $file);
            }
            $toReplaceRow = array('{id}', '{title}', '{name}', '{value}', '{namePrev}');
            $replaceRow = array($name . '_' . $fields[$i]['name'], $fields[$i]['title'], $name . '_' . $fields[$i]['name'], '{' . $fields[$i]['name'] . '_value}', ucfirst($fields[$i]['name']));
            $result = str_replace($toReplaceRow, $replaceRow, $file);
            $fieldsHTML .= $result;
        }
        if ($seo) {
            $seoHTML = '<div class="seo_part">' . "\r\n\t\t\t";
            $seoHTML .= '<div class="row">
				<label for="seo_title" class="row-item">SEO Титулка</label>
				<div class="row-item">
				    <input class="in in-text" type="text" value="{seo_title_value}" name="seo_title"
					        id="seo_title">
				</div>
			</div>' . "\r\n\t\t\t";
            $seoHTML .= '<div class="row">
				<label for="seo_keywords" class="row-item">SEO Ключи</label>
				<div class="row-item">
				    <textarea class="in in-area" name="seo_keywords" id="seo_keywords">{seo_keywords_value}</textarea>
				</div>
			</div>' . "\r\n\t\t\t";
            $seoHTML .= '<div class="row">
				<label for="seo_description" class="row-item">SEO Описание</label>
				<div class="row-item">
				    <textarea class="in in-area" name="seo_description" id="seo_description">{seo_description_value}</textarea>
				</div>
			</div>' . "\r\n\t\t";
            $seoHTML .= '</div>';
        }
        $tree = $this->genTreeRows();
        $replace = array($formFile, $name, ucfirst($name), $fieldsHTML, $seoHTML, $tree);
        $file = file_get_contents(TPL_GEN_TYPE . '/view.tpl');
        $result = str_replace($toReplace, $replace, $file);
        file_put_contents(ADMIN . '/views/types/' . $name . '.tpl', $result);
    }