public function get($tag, $attr = 'content') { $tag = trim($tag); $attrName = 'widget_' . $attr; if (empty($tag)) { return; } $unlimCache = K_Cache_Manager::get('unlim'); $blockCacheID = 'widget_' . $tag; if ($unlimCache->test($blockCacheID)) { $cacheData = $unlimCache->load($blockCacheID); if (isset($cacheData[$attrName])) { echo $cacheData[$attrName]; } } else { K_Loader::load('widgets', APP_PATH . '/default/model/'); $widgetsTable = new widgetsModel(); $widgetInfo = $widgetsTable->fetchRow(K_Db_Select::create()->where(array('widget_tag' => $tag))->limit(1)); if (count($widgetInfo)) { $unlimCache->save($blockCacheID, $widgetInfo); if (isset($widgetInfo[$attrName])) { echo $widgetInfo[$attrName]; } } } }
public function previewAction() { $form_post_array = isset($_POST['frmb']) ? $_POST : false; if ($form_post_array != false) { K_Loader::load('formbuilder', APP_PATH . '/plugins'); $form_builder = new Formbuilder($form_post_array); $this->putAjax($form_builder->generate_html()); } else { $this->putAjax('ERROR'); } }
public function loadAction() { $typeClientForm = new Admin_Model_ClientForm(); $clientFormKey = $this->getParam('key'); $clientFormData = $typeClientForm->fetchRow(K_Db_Select::create()->where("type_clientform_id={$clientFormKey}")); if ($clientFormData) { K_Loader::load('formbuilder', APP_PATH . '/plugins'); $formBuilder = new Formbuilder(unserialize($clientFormData['type_clientform_content'])); $this->putAjax($formBuilder->render_json()); } else { $this->putAjax('ERROR'); } }
<?php K_Loader::load('Db/Model'); class rewriteUrlsModel extends K_Db_Model { var $name = 'urls'; var $primary = 'url_url'; var $allowDuplicate = false; // use on validation and save var $validate = array('url_url' => array('required' => true, 'urlTest'), 'url_module' => array('regex' => '#.{1,255}#is'), 'url_controller' => array('regex' => '#.{1,255}#is'), 'url_action' => array('regex' => '#.{1,255}#is'), 'url_cache_key' => array('regex' => '#.{0,128}#is'), 'url_page_type' => array('regex' => '#.{0,100}#is'), 'url_status' => array('enum' => array('hidden', 'public', 'preview'))); // @TODO dopisat' function public function urlTest(&$text, $fieldName) { if (mb_strlen($text, 'UTF-8') > 255) { $this->errors[$fieldName] = 'Максимальный размер поля 255 символов'; return false; } if (mb_strlen($text, 'UTF-8') < 2) { $this->errors[$fieldName] = 'Минимальный размер поля 2 символа'; return false; } if (!$this->allowDuplicate) { // test on duplicate $result = $this->fetchRow(K_Db_Select::create()->where(array('url_url' => $text))); if (count($result)) { $this->errors[$fieldName] = 'Найден дубликат поля'; return false; } } return true; }
public function updateAction() { $this->disableRender = true; $typesTable = new K_Tree_Types_Model(); $typeId = $this->getParam('id'); $types = $typesTable->select()->where('`type_id`=' . (int) $typeId)->fetchRow(); $types = $types->toArray(); $form = new K_Form(); $allowedkeys = array('type_desc', 'type_fields'); $values = array(); $formData = $form->getData(); $formPostArray = isset($_POST['type_fields']) ? $_POST['type_fields'] : false; parse_str(substr($_POST['type_fields'], 1), $formPostArray); if ($formPostArray != false) { K_Loader::load('formbuilder', APP_PATH . '/plugins'); $formBuilder = new Formbuilder($formPostArray); $formArray = $formBuilder->get_encoded_form_array(); } else { throw new Exception("Не заданы поля для нового типа!"); } if (!$formData) { throw new Exception("Невозможно обработать форму без данных!"); } foreach ($formData as $elementKey => $elementValue) { if (in_array($elementKey, $allowedkeys)) { if (is_string($elementValue)) { $elementValue = trim($elementValue); } $values[$elementKey] = $elementValue; if ($elementKey == 'type_fields' && json_decode($formArray['form_structure']) == null && !empty($formArray['form_structure'])) { throw new Exception("Поля переданы не в json-формате! " . json_last_error()); } } } K_Tree_Types::update($types['type_name'], $values['type_desc'], $formArray['form_structure'], $formArray); echo 'Тип успешно обновлён!'; }
public static function addField($form, $type, $element, $elementData, $formData) { switch ($type) { case 'text': $form->{$type}($element->values->name, !empty($elementData) ? $elementData : (!empty($element->values->default) ? $element->values->default : ''), array('class' => $element->values->class, 'id' => $element->values->id, 'placeholder' => $element->values->placeholder)); break; case 'textarea': $form->{$type}($element->values->name, !empty($elementData) ? $elementData : (!empty($element->values->default) ? $element->values->default : ''), array('class' => $element->values->class, 'id' => $element->values->id, 'placeholder' => $element->values->placeholder)); break; case 'wysiwyg': $form->textarea($element->values->name, !empty($elementData) ? $elementData : (!empty($element->values->default) ? $element->values->default : ''), array('class' => $element->values->class . ' wysiwyg-redactor', 'id' => $element->values->id)); echo ' <script type="text/javascript"> $(function() { $(".wysiwyg-redactor").ckeditor({ allowedContent: true, toolbar: "Standard", removePlugins : "resize,about,save", filebrowserBrowseUrl : "/adm/plugins/ckfinder/ckfinder.html", filebrowserImageBrowseUrl : "/adm/plugins/ckfinder/ckfinder.html?Type=Images", filebrowserFlashBrowseUrl : "/adm/plugins/ckfinder/ckfinder.html?Type=Flash", filebrowserUploadUrl : "/adm/plugins/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files", filebrowserImageUploadUrl : "/adm/plugins/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images", filebrowserFlashUploadUrl : "/adm/plugins/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash", editorConfig : function( config ) { CKEDITOR.replace( "content_id", { allowedContent: true}) config.protectedSource.push(/<(style)[^>]*>.*<\\/style>/ig); return config; } }); }); </script>'; /* $(".wysiwyg-redactor").redactor({ imageUpload: "/admin/api/uploadImage", autoformat: true, cleanUp: true, convertDivs: false, removeClasses: true, removeStyles: true, convertLinks: false, buttons: ["html", "|", "formatting", "|", "bold", "italic" , "deleted","|","norderedlist", "orderedlist", "outdent", "indent", "|","image","video","table", "link", "|","fontcolor", "backcolor", "|","alignleft", "aligncenter", "alignright", "justify", "|","horizontalrule", "fullscreen"] }); */ break; case 'formbuilder': K_Loader::load('formbuilder', APP_PATH . '/plugins'); $form_builder = new Formbuilder(unserialize($elementData)); echo ' <div id="my-form-builder"></div> <input type="hidden" name="' . $element->values->name . '" id="f_' . $element->values->name . '"></div> <script type="text/javascript"> $("#my-form-builder").formbuilder({ "save_url": false, "load_url": false, "preview_url": false, "saveInDom": true, ' . (!empty($elementData) ? '"load_source": ' . $form_builder->render_json(false) . ',' : '') . ' "domElementId": "f_' . $element->values->name . '", "useJson" : true }); </script> '; break; case 'file': $form->{$type}($element->values->name, array('class' => $element->values->class, 'id' => $element->values->id)); if (self::$adminka) { echo ' <input type="checkbox" name="' . $element->values->name . '_delete">Удалить файл</input>'; } if ($elementData) { echo '<div>' . (preg_match('/^.*\\.(jpg|png|jpeg|gif|bmp)$/im', $elementData) ? '<br /><img src="/images/' . $elementData . '?h=120" style="margin-top:5px" /></div>' : '<span class="file_address_text"><a href="/upload/' . htmlentities(urlencode($elementData)) . '">' . $elementData . '</a></span></div>'); } break; case 'multifile': echo '<div id = ' . $element->values->id . ' data-filename = ' . $element->values->name . ' class = "multifile">'; $i = 0; if ($elementData) { $fileArr = unserialize($elementData); if (count($fileArr)) { foreach ($fileArr as $v) { echo '<div style="margin:15px 0" id="' . $element->values->id . '_a_' . $i . '">'; echo '<input type="text" value="' . $v['t'] . '" style="width:150px;margin-right:5px" name="' . $element->values->name . '_t_' . $i . '" id="' . $element->values->id . '_t_' . $i . '"/>'; $form->file($element->values->name . '_f_' . $i, array('class' => $element->values->class, 'id' => $element->values->id . '_f_' . $i)); if (self::$adminka) { echo '<br/> <input type="checkbox" name="' . $element->values->name . '_delete_' . $i . '">Удалить файл</input>'; } echo '<div>' . (preg_match('/^.*\\.(jpg|png|jpeg|gif|bmp)$/im', $v['f']) ? '<br /><img src="/images/' . $v['f'] . '?w=150&h=150&zc=C" style="margin-top:5px" /></div><br/>' : '<span class="file_address_text"><a href="/upload/' . htmlentities(urlencode($v['f'])) . '">' . ($v['t'] ? $v['t'] : $v['f']) . '</a></span></div><br/>'); $i++; echo '</div>'; } } } if (!$i) { echo '<div style="margin:15px 0" id="' . $element->values->id . '_a_0">'; echo '<input type="text" style="width:150px;margin-right:5px" name="' . $element->values->name . '_t_0" id="' . $element->values->id . '_t_0"/>'; $form->file($element->values->name . '_f_0', array('style' => 'width:220px', 'class' => $element->values->class, 'id' => $element->values->id . '_f_0')); echo '<a data-fileid="' . $element->values->id . '_0' . '" class="file_field_delete" href="javascript:void(0);" title="Убрать лишний"></a>'; echo '</div>'; } echo '</div>'; echo "<script type=\"text/javascript\"> \n \$(function(){\n \$('#" . $element->values->id . "').multifile(); \n });\n </script>"; break; case 'select': $listOptions = self::getListOptions($element); $listAttr = array('class' => $element->values->class, 'id' => $element->values->id); if ($element->multiple == "checked") { $listAttr['multiple'] = 'multiple'; } // var_dump($element); $treeIds = array(); if ($element->values->method) { $params = json_decode($element->values->method, true); // var_dump($params); // $params = explode(':',$element->values->method); $source = trim($params['node']); $field = 'tree_' . $params['field']; if (strpos($params['field'], 'type') !== false) { $field = str_replace('type_', '', $params['field']); } if (preg_match('/^\\/.*\\/$/', $source)) { // var_dump($params); $goParams = array_merge($params['go'], array('orderby' => $params['order'][1])); // var_dump($goParams); $nodeChilds = K_TreeQuery::crt($source)->types($params['filter'])->limit($params['limit'])->order($params['order'][0])->go($goParams); // var_dump($nodeChilds); // var_dump($nodeChilds); // $start=$nodeChilds[1]['tree_level']; // var_dump($treeBrach); // str_repeat(' ',$v['tree_level']).$v['tree_title'] $firstNode = true; foreach ($nodeChilds as $v) { if ($firstNode == true) { $startLevel = $v['tree_level']; } $firstNode = false; $title = $v[$field]; $treeIds[$title] = $v['tree_id']; // str_repeat(' ',$v['tree_level']-$start). if ($params['title'] && count($params['title'])) { $optTitle = array(); foreach ($params['title'] as $tile) { $optTitle[] = $v[$tile]; } $listOptions[0][$title] = str_repeat(' ', $v['tree_level'] - $startLevel) . implode(' - ', $optTitle); } else { $listOptions[0][$title] = str_repeat(' ', $v['tree_level'] - $startLevel) . $v['tree_title']; } } //var_dump( $listOptions[0] ); } else { $node = K_Tree::getNode($elementData); $nodesBro = K_Tree::getChilds($node['tree_pid']); foreach ($nodesBro as $v) { $title = $v[$field]; $treeIds[$title] = $v['tree_id']; $listOptions[0][$title] = $v['tree_title']; } echo "<script type=\"text/javascript\"> \n \$('#" . $source . "').off('.formsel'); \n \$('#" . $source . "').on('change.formsel',function(){selectLoad(this,'#{$listAttr['id']}','{$params['0']}','')});\n </script>"; /* if(! empty($elementData)){ $checkJs="if(v.value=='$elementData'){cheked='selected=\"selected\"}"; // $this->loadSelect[$source]=array('select'=>$listAttr['id'],'field'=>$params['0'],'opt'=>$elementData); echo "selectLoad('#".$source ."','#{$listAttr['id']}','{$params['0']}','$elementData',);"; } */ } } $form->{$type}($element->values->name . (isset($listAttr['multiple']) && $listAttr['multiple'] ? '[]' : ''), $listOptions[0], !empty($elementData) ? $elementData : $listOptions[0], $listAttr, $treeIds); break; case 'checkbox': $listOptions = self::getListOptions($element); $listAttr = array('class' => $element->values->class, 'id' => $element->values->id); if (count($listOptions[0]) > 0) { $i = 1; foreach ($listOptions[0] as $key => $value) { echo '<label>'; $form->{$type}($element->values->name . (count($listOptions[0]) > 1 ? '[]' : ''), $listOptions[1] == $i || count($listOptions[0]) == 1 && $elementData == 'on' ? true : false, $key, $listAttr); echo $key . ' ' . '</label>'; $i++; } } break; case 'radio': $listOptions = self::getListOptions($element); $listAttr = array('class' => $element->values->class, 'id' => $element->values->id); if (count($listOptions[0]) > 0) { $i = 1; foreach ($listOptions[0] as $key => $value) { echo '<label>'; $form->{$type}($element->values->name . (count($listOptions[0]) > 1 ? '[]' : ''), $listOptions[1] == $i || count($listOptions[0]) == 1 && $elementData == 'on' ? true : false, $key, $listAttr); echo $key . ' ' . '</label>'; $i++; } } // var_dump($listOptions[0]); // $form->$type($element->values->name . (''), $listOptions[0], $listOptions[1], $listAttr); break; case 'submit': $form->{$type}($element->values->label, array('class' => $element->values->class, 'id' => $element->values->id)); break; case 'reset': $form->{$type}($element->values->label, array('class' => $element->values->class, 'id' => $element->values->id)); break; case 'hidden': $form->{$type}($element->values->name, $element->values->value, array('class' => $element->values->class, 'id' => $element->values->id)); break; } }