Author: Jonathan.Wage
Date: 2010-01-15 21:54:48 +0100 (Fri, 15 Jan 2010)
New Revision: 26692

Modified:
   
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalFrontendEditorPlugin/config/sfSympalFrontendEditorPluginConfiguration.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/content/sfSympalContentRenderer.class.php
Log:
[1.4][sfSympalPlugin][1.0] Improving functionality which allows you to view 
your content in other formats


Modified: 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php 
    2010-01-15 19:30:01 UTC (rev 26691)
+++ 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php 
    2010-01-15 20:54:48 UTC (rev 26692)
@@ -299,13 +299,77 @@
     }
   }
 
+  public function getFeedDescriptionPotentialSlots()
+  {
+    return array(
+      'body'
+    );
+  }
+
   public function getFeedDescription()
   {
-    return sfSympalContext::getInstance()
-      ->getRenderer($this)
-      ->render();
+    if (method_exists($this->getContentTypeClassName(), 'getFeedDescription'))
+    {
+      return $this->getRecord()->getFeedDescription();
+    }
+
+    foreach ($this->getFeedDescriptionPotentialSlots() as $slot)
+    {
+      if ($this->hasSlot($slot))
+      {
+        return $this->getSlot($slot)->render();
+      }
+    }
+    if ($this->Slots->count() > 0)
+    {
+      return $this->Slots->getFirst()->render();
+    }
   }
 
+  public function getFormatData($format)
+  {
+    $method = 'get'.ucfirst($format).'FormatData';
+    if (method_exists($this->getContentTypeClassName(), $method))
+    {
+      return $this->getRecord()->$method();
+    } else if (method_exists($this, $method)) {
+      $data = $this->$method();
+    } else {
+      $data = $this->getDefaultFormatData();
+    }
+    return Doctrine_Parser::dump($this->$method(), $format);
+  }
+
+  public function getDefaultFormatData()
+  {
+    $data = $this->toArray(true);
+    unset(
+      $data['MenuItem']['__children'],
+      $data['MenuItem']['Groups'],
+      $data['Groups'],
+      $data['Links'],
+      $data['Assets'],
+      $data['CreatedBy'],
+      $data['Site']
+    );
+    return $data;
+  }
+
+  public function getXmlFormatData()
+  {
+    return $this->getDefaultFormatData();
+  }
+
+  public function getYmlFormatData()
+  {
+    return $this->getDefaultFormatData();
+  }
+
+  public function getJsonFormatData()
+  {
+    return $this->getDefaultFormatData();
+  }
+
   public function getIsPublished()
   {
     return ($this->getDatePublished() && strtotime($this->getDatePublished()) 
<= time()) ? true : false;

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalFrontendEditorPlugin/config/sfSympalFrontendEditorPluginConfiguration.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalFrontendEditorPlugin/config/sfSympalFrontendEditorPluginConfiguration.class.php
    2010-01-15 19:30:01 UTC (rev 26691)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalFrontendEditorPlugin/config/sfSympalFrontendEditorPluginConfiguration.class.php
    2010-01-15 20:54:48 UTC (rev 26692)
@@ -6,15 +6,27 @@
 
   public function initialize()
   {
-    $this->dispatcher->connect('response.filter_content', array($this, 
'addEditorHtml'));
     $this->dispatcher->connect('sympal.load_content', array($this, 
'loadEditor'));
   }
 
+  private function _shouldLoadEditor()
+  {
+    // Only load the editor if
+    // ... edit mode is on
+    // ... request format is html
+    return sfContext::getInstance()->getUser()->isEditMode()
+      && sfContext::getInstance()->getRequest()->getRequestFormat() == 'html';
+  }
+
   public function loadEditor(sfEvent $event)
   {
-    if (sfContext::getInstance()->getUser()->isEditMode() && 
sfSympalContext::getInstance()->getCurrentContent())
+    if ($this->_shouldLoadEditor())
     {
+      // Load the editor assets (css/js)
       $this->loadEditorAssets();
+
+      // Use the response.filter_content event to add the editor html
+      $this->dispatcher->connect('response.filter_content', array($this, 
'addEditorHtml'));
     }
   }
 
@@ -55,11 +67,6 @@
 
   public function addEditorHtml(sfEvent $event, $content)
   {
-    if ($contentRecord = sfSympalContext::getInstance()->getCurrentContent())
-    {
-      return str_replace('</body>', get_sympal_editor().'</body>', $content);
-    } else {
-      return $content;
-    }
+    return str_replace('</body>', get_sympal_editor().'</body>', $content);
   }
 }
\ No newline at end of file

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/content/sfSympalContentRenderer.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/content/sfSympalContentRenderer.class.php
      2010-01-15 19:30:01 UTC (rev 26691)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/content/sfSympalContentRenderer.class.php
      2010-01-15 20:54:48 UTC (rev 26692)
@@ -70,7 +70,7 @@
       case 'xml':
       case 'json':
       case 'yml':
-        $return = $this->_content->exportTo($this->_format, true);
+        $return = $this->_content->getFormatData($this->_format);
       default:
         $event = $this->_dispatcher->notifyUntil(new sfEvent($this, 
'sympal.content_renderer.unknown_format', $this->getRenderVariables()));
 

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.


Reply via email to