Permalink
Browse files

Updated Template Editor

  • Loading branch information...
1 parent 46f8114 commit 07525e16b1fa1194b31e9eb75a8e4101aec9e069 @ArchiCroc committed May 21, 2012
Showing with 358 additions and 131 deletions.
  1. +1 −1 application/modules/Content/controllers/CategorySetController.php
  2. +5 −0 application/modules/Content/controllers/TemplateController.php
  3. +3 −0 application/modules/Content/forms/Field.php
  4. +18 −8 application/modules/Content/models/Content/MapperDbTable.php
  5. +2 −3 application/modules/Content/models/Field/Service.php
  6. +5 −4 application/modules/Content/models/Plugin/Template.php
  7. +10 −0 application/modules/Content/plugins/Element/DateTime/Element.php
  8. +2 −2 application/modules/Content/plugins/Template/Base/Installer.php
  9. +92 −0 application/modules/Content/plugins/Template/Blog/Installer.php
  10. +7 −0 application/modules/Content/plugins/Template/Blog/category.phtml
  11. +7 −0 application/modules/Content/plugins/Template/Blog/index.phtml
  12. +7 −0 application/modules/Content/plugins/Template/Blog/tag.phtml
  13. +7 −0 application/modules/Content/plugins/Template/Blog/view.phtml
  14. +10 −4 application/modules/Content/plugins/Template/Pages/Installer.php
  15. +13 −24 application/modules/Content/plugins/Template/Projects/Installer.php
  16. +35 −0 application/modules/Content/plugins/Template/Projects/category.phtml
  17. +7 −0 application/modules/Content/plugins/Template/Projects/index.phtml
  18. +13 −0 application/modules/Content/plugins/Template/Projects/view.phtml
  19. +2 −2 application/modules/Core/forms/Confirm.php
  20. +4 −4 application/modules/Core/models/Reflection/Service.php
  21. +8 −0 library/CMS/Form/Element/JsCodeEditor.php
  22. +65 −52 library/CMS/Test/PHPUnit/ControllerTestCase.php
  23. +11 −2 library/CMS/View/Helper/FormJsCodeEditor.php
  24. +2 −2 tests/application/modules/Content/controllers/Content_CategoryControllerTest.php
  25. +5 −2 tests/application/modules/Content/controllers/Content_CategorySetControllerTest.php
  26. +2 −2 tests/application/modules/Content/controllers/Content_ContentControllerTest.php
  27. +2 −2 tests/application/modules/Content/controllers/Content_FieldControllerTest.php
  28. +2 −2 tests/application/modules/Content/controllers/Content_FieldSetControllerTest.php
  29. +1 −1 tests/application/modules/Content/controllers/Content_IndexControllerTest.php
  30. +2 −2 tests/application/modules/Content/controllers/Content_SectionControllerTest.php
  31. +2 −2 tests/application/modules/Content/controllers/Content_TemplateControllerTest.php
  32. +1 −1 tests/application/modules/Content/models/Field/Content_Model_Field_ServiceTest.php
  33. +1 −1 tests/application/modules/Content/models/Section/Content_Model_Section_ManagerTest.php
  34. +1 −1 tests/application/modules/Core/models/Acl/Core_Model_Acl_ManagerTest.php
  35. +3 −7 tests/application/modules/Core/models/Reflection/Core_Model_Reflection_ServiceTest.php
@@ -159,6 +159,6 @@ public function deleteAction()
$csService->delete($object);
$this->view->messages()->add('Successfully Deleted Category Set "'.$title.'"');
}
- return $this->_redirect($this->view->url(array('controller'=>'category-set'),'content-admin'));
+ return $this->_redirect($this->view->url(array('controller'=>'category-set'),'content-admin'));
}
}
@@ -97,6 +97,7 @@ public function newAction() {
//save
$values = $form->getValues();
+ $values['content'] = base64_decode($values['content']);
$values['owner'] = Core_Model_User_Manager::getUser()->id;
$values['section'] = $this->view->id;
$values['type'] = Content_Model_Template::USER;
@@ -136,6 +137,10 @@ public function editAction() {
//save
$values = $form->getValues();
+
+
+ $values['content'] = base64_decode($values['content']);
+
$values['owner'] = Core_Model_User_Manager::getUser()->id;
$object->fromArray($values);
$service->update($object);
@@ -42,6 +42,9 @@ public function init()
$service = new Core_Model_Reflection_Service();
$configs = $service->getPluginConfigsByModuleType('Content','Element');
+ //var_dump($configs);
+ //exit;
+
$options = array('' => 'Select One');
foreach($configs as $key => $value){
@@ -43,8 +43,9 @@ public function getTable() {
}
public function getCustomTable($section) {
+
if (!array_key_exists($section, $this->_customTables)) {
- $customTable = new Zend_Db_Table('content_custom_' . $section);
+ $customTable = new Zend_Db_Table('content_custom_' . $this->escapeInt($section));
// die(debugArray($customTable->info(Zend_Db_Table::METADATA)));
$this->_customTables[$section] = $customTable;
}
@@ -110,7 +111,7 @@ public function fetchObjectsBySection($section, $query = array(), $itemsPerPage
$select = $this->getTable()->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
$select->setIntegrityCheck(false)
->where('section = ?', $section)
- ->join(array('c' => 'content_custom_' . $section), 'content_content.id = c.id AND
+ ->join(array('c' => 'content_custom_' . $this->escapeInt($section)), 'content_content.id = c.id AND
content_content.active_revision = c.revision'
); //,'homenet_node_models.id = homenet_nodes.model', array('driver', 'name AS modelName', 'type', 'settings')
@@ -327,7 +328,7 @@ public function fetchObjectById($id) {
public function addCustomTable($section) {
- $table = 'content_custom_' . mysql_real_escape_string($section);
+ $table = 'content_custom_' . $this->escapeInt($section);
//@todo security issue validate $section
// return $this->getMapper()->prepareTable($section, $fields);
@@ -366,7 +367,7 @@ public function addCustomField(Content_Model_Field_Interface $field) {
}
$element = new $class();
- $result = $this->getTable()->getAdapter()->query('ALTER TABLE `content_custom_' . mysql_real_escape_string($field->section) . '` ADD `' . mysql_real_escape_string($field->name) . '` ' . $element->getMysqlColumn() . ' ');;
+ $result = $this->getTable()->getAdapter()->query('ALTER TABLE `content_custom_' . $this->escapeInt($field->section) . '` ADD `' . $this->escapeString($field->name) . '` ' . $element->getMysqlColumn() . ' ');;
$this->cleanCache(); //reset metadata cache
return $result;
}
@@ -380,6 +381,13 @@ public function cleanCache(){
}
}
+ public function escapeString($string){
+ return $this->getTable()->getAdapter()->quote($string);
+ }
+
+ public function escapeInt($int){
+ return $this->getTable()->getAdapter()->quote($int,'INT');
+ }
public function renameCustomField(Content_Model_Field_Interface $old, Content_Model_Field_Interface $field) {
//@todo check to make sure section is valid
@@ -400,25 +408,27 @@ public function renameCustomField(Content_Model_Field_Interface $old, Content_Mo
$element = new $class();
-
+ if($field->section === null){
+ throw new Exception('Section Cannot be NULL');
+ }
- $result = $this->getTable()->getAdapter()->query('ALTER TABLE `content_custom_' . mysql_real_escape_string($field->section) . '` CHANGE `' . mysql_real_escape_string($old->name) . '` `' . mysql_real_escape_string($field->name) . '` ' . $element->getMysqlColumn() . ' ');
+ $result = $this->getTable()->getAdapter()->query('ALTER TABLE `content_custom_' . $this->escapeInt($field->section) . '` CHANGE `' . $this->escapeString($old->name) . '` `' . $this->escapeString($field->name) . '` ' . $element->getMysqlColumn() . ' ');
$this->cleanCache(); //reset metadata cache
return $result;
}
public function removeCustomField(Content_Model_Field_Interface $field) {
//alter table
- $result = $this->getTable()->getAdapter()->query('ALTER TABLE `content_custom_' . mysql_real_escape_string($field->section) . '` DROP `' . mysql_real_escape_string($field->name) . '`');
+ $result = $this->getTable()->getAdapter()->query('ALTER TABLE `content_custom_' . $this->escapeInt($field->section) . '` DROP `' . $this->escapeString($field->name) . '`');
$this->cleanCache(); //reset metadata cache
return $result;
}
public function removeCustomTable($section) {
//drop table
//DROP TABLE `content_section_5`
- $result = $this->getTable()->getAdapter()->query('DROP TABLE IF EXISTS `content_custom_' . mysql_real_escape_string($section));
+ $result = $this->getTable()->getAdapter()->query('DROP TABLE IF EXISTS `content_custom_' . $this->escapeInt($section));
$this->cleanCache(); //reset metadata cache
return $result;
}
@@ -171,7 +171,7 @@ public function update($mixed) {
try {
$found = $this->getObjectBySectionName($object->section, $object->name);
} catch (NotFoundException $e) {
-
+ //throw new DuplicateEntryException('Name already exists ');
}
if ($found !== null) {
@@ -182,10 +182,9 @@ public function update($mixed) {
$old = $this->getObjectById($object->id);
-
$field = $this->getMapper()->save($object);
- if ($field->type != Content_Model_Field::SYSTEM) {
+ if (($field->type != Content_Model_Field::SYSTEM) && ($old->name != $field->name)) {
$service = new Content_Model_Content_Service();
$service->renameCustomField($old, $field);
}
@@ -33,14 +33,15 @@ public function getTemplates(){
public function getFieldSets(){
$fieldSets = array();
- $fieldSets['publish'] = array('title' => 'Publish', 'visible' => true);
+ $fieldSets['default'] = array('title' => 'Publish', 'visible' => true);
return $fieldSets;
}
- public function getFields($fieldSets){
+ public function getFields(){
+ $fieldSets = $this->getFields();
$fields = array();
$fields['title'] = array(
- 'set' => $fieldSets['publish'],
+ 'set' => $fieldSets['default'],
'order' => 1,
'type' => Content_Model_Field::SYSTEM,
'element' => 'Text',
@@ -53,7 +54,7 @@ public function getFields($fieldSets){
'required' => true,
'visible' => true);
$fields['url'] = array(
- 'set' => $fieldSets['publish'],
+ 'set' => $fieldSets['default'],
'order' => 2,
'type' => Content_Model_Field::SYSTEM,
'element' => 'Slug',
@@ -227,5 +227,15 @@ public function format($format){
$tempDate = new Zend_Date($this->_value, Zend_Date::ISO_8601);
return $tempDate->toString($format);
}
+
+ public function render() {
+
+ if(!empty($this->_options['format'])){
+ // die(strtotime());
+
+ return $this->format($this->_options['format']);
+ }
+ return parent::render();
+ }
}
@@ -36,8 +36,8 @@ function getDependencies(){
}
- function getFields($fieldSets){
- $fields = parent::getFields($fieldSets);
+ function getFields(){
+ $fields = parent::getFields();
// $fields[] = array(
// 'set' => $fieldSets['publish'],
// 'order' => 2,
@@ -0,0 +1,92 @@
+<?php
+
+/*
+ * Installer.php
+ *
+ * Copyright (c) 2011 Matthew Doll <mdoll at homenet.me>.
+ *
+ * This file is part of HomeNet.
+ *
+ * HomeNet is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HomeNet is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HomeNet. If not, see <http ://www.gnu.org/licenses/>.
+ */
+
+/**
+ * Description of Installer
+ *
+ * @author Matthew Doll <mdoll at homenet.me>
+ */
+class Content_Plugin_Template_Blog_Installer extends Content_Model_Plugin_Template {
+
+ public function getDependencies() {
+ $dependencies = array(
+ );
+ return $dependencies;
+ }
+
+ public function getTemplates() {
+
+ $path = dirname(__FILE__);
+
+ $templates = array();
+ $templates[] = array(
+ 'type' => Content_Model_Template::TEMPLATE,
+ 'url' => 'index',
+ 'content' => file_get_contents($path . '/index.phtml'));
+ return $templates;
+ }
+
+ public function getFields() {
+
+ $fieldSets = $this->getFieldSets();
+ $fields = parent::getFields($fieldSets);
+ $fields['date'] = array(
+ 'set' => $fieldSets['publish'],
+ 'order' => 4,
+ 'type' => Content_Model_Field::TEMPLATE,
+ 'element' => 'DateTime',
+ 'name' => 'date',
+ 'label' => 'Date',
+ 'locked' => false,
+ 'required' => true,
+ 'visible' => true);
+ $fields['categories'] = array(
+ 'set' => $fieldSets['publish'],
+ 'order' => 2,
+ 'type' => Content_Model_Field::TEMPLATE,
+ 'element' => 'Categories',
+ 'name' => 'categories',
+ 'label' => 'Categories',
+ 'locked' => false,
+ 'required' => true,
+ 'visible' => true);
+ $fields['content'] = array(
+ 'set' => $fieldSets['publish'],
+ 'order' => 3,
+ 'type' => Content_Model_Field::TEMPLATE,
+ 'element' => 'Editor',
+ 'name' => 'content',
+ 'label' => 'Content',
+ 'required' => true);
+
+ return $fields;
+ }
+
+// function getContent(){
+// return;
+// }
+//
+// function getOptionalContent(){
+// return array();
+// }
+}
@@ -0,0 +1,7 @@
+<?php
+$service = new Content_Model_Content_Service();
+$object = $service->getObjectByUrl($this->params['id']);
+
+echo $this->heading($object->title);
+echo $object->content;
+?>
@@ -0,0 +1,7 @@
+<?php
+$service = new Content_Model_Content_Service();
+$object = $service->getObjectByUrl($this->params['id']);
+
+echo $this->heading($object->title);
+echo $object->content;
+?>
@@ -0,0 +1,7 @@
+<?php
+$service = new Content_Model_Content_Service();
+$object = $service->getObjectByUrl($this->params['id']);
+
+echo $this->heading($object->title);
+echo $object->content;
+?>
@@ -0,0 +1,7 @@
+<?php
+$service = new Content_Model_Content_Service();
+$object = $service->getObjectByUrl($this->params['id']);
+
+echo $this->heading($object->title);
+echo $object->content;
+?>
@@ -48,16 +48,22 @@ public function getTemplates(){
}
- public function getFields($fieldSets){
- $fields = parent::getFields($fieldSets);
- $fields[] = array(
- 'set' => $fieldSets['publish'],
+ public function getFields(){
+
+ $fields = parent::getFields();
+ $fieldSets = $this->getFieldSets();
+ $fields['content'] = array(
+ 'set' => $fieldSets['default'],
'order' => 2,
'type' => Content_Model_Field::TEMPLATE,
'element' => 'Editor',
'name' => 'content',
'label' => 'Content',
'required' => true);
+
+
+
+
return $fields;
}
Oops, something went wrong.

0 comments on commit 07525e1

Please sign in to comment.