Author: weaverryan
Date: 2010-01-30 23:44:27 +0100 (Sat, 30 Jan 2010)
New Revision: 27343

Added:
   plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/replacer/
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/replacer/sfSympalContentSyntaxAssetReplacer.class.php
   plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/
   plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/config/
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/config/sfSympalContentSyntaxPluginConfiguration.class.php
   plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/replacer/
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/replacer/sfSympalContentSyntaxReplacer.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/sfSympalContentReplacer.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/sfSympalContentSlotReplacer.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/config/app.yml
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/replacer/
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/replacer/sfSympalContentSyntaxLinkReplacer.class.php
Removed:
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/sfSympalAssetReplacer.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/modules/sympal_editor/templates/objectsSuccess.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/web/js/objects.js
Modified:
   plugins/sfSympalPlugin/trunk/config/app.yml
   plugins/sfSympalPlugin/trunk/config/sfSympalPluginConfiguration.class.php
   plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/config/app.yml
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/config/sfSympalAssetsPluginConfiguration.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/config/routing.yml
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/lib/helper/SympalContentSlotEditorHelper.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/modules/sympal_editor/lib/Basesympal_editorActions.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/config/sfSympalRenderingPluginConfiguration.class.php
Log:
[1.4][sfSympalPlugin][1.0] Refactoring the text replacement system so that 
additional types beyond link and asset can be added. This creates a new plugin 
which handles this process.

The replacement system is also slot-agnostic, which means that it can be used 
as a standalone processor for text (though you'll lose efficiency compared to 
slots that use asset and link).

The pieces of the "object" replacement system have been removed and will be 
used for a standalone plugin that allows you to render any object via the 
[myObject:5] syntax.


Modified: plugins/sfSympalPlugin/trunk/config/app.yml
===================================================================
--- plugins/sfSympalPlugin/trunk/config/app.yml 2010-01-30 21:35:52 UTC (rev 
27342)
+++ plugins/sfSympalPlugin/trunk/config/app.yml 2010-01-30 22:44:27 UTC (rev 
27343)
@@ -203,13 +203,6 @@
         form_renderer: sympal_edit_slot/slot_editor_renderer
         widget_options:
           config: 'handle_event_callback : "sympalHandleTinyMCEEvent"'
-    
-    # configure doctrine objects that can be inserted into slots
-    content_slot_objects: {}
-      #MyObjectSlot:
-      #  label: Label of My Object Slot
-      #  class: MyObjectSlotClass
-      #  template: myModule/template
         
 
     # Enable and disable the check for upgrades via the web when on the Sympal 
dashboard

Modified: 
plugins/sfSympalPlugin/trunk/config/sfSympalPluginConfiguration.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/config/sfSympalPluginConfiguration.class.php   
2010-01-30 21:35:52 UTC (rev 27342)
+++ plugins/sfSympalPlugin/trunk/config/sfSympalPluginConfiguration.class.php   
2010-01-30 22:44:27 UTC (rev 27343)
@@ -25,7 +25,8 @@
       'sfSympalRenderingPlugin',
       'sfSympalAdminPlugin',
       'sfSympalEditorPlugin',
-      'sfSympalAssetsPlugin'
+      'sfSympalAssetsPlugin',
+      'sfSympalContentSyntaxPlugin',
     );
 
   public

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/config/app.yml
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/config/app.yml    
    2010-01-30 21:35:52 UTC (rev 27342)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/config/app.yml    
    2010-01-30 22:44:27 UTC (rev 27343)
@@ -29,6 +29,11 @@
           extensions: [txt]
         tarball:
           extensions: [tar, gz, zip, bzip, gzip, rar, 7z]
+    
+    content_syntax_types:
+      asset:
+        replacer_class:    sfSympalContentSyntaxAssetReplacer
+    
   sfImageTransformPlugin:
     mime_type:
       auto_detect: true
\ No newline at end of file

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/config/sfSympalAssetsPluginConfiguration.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/config/sfSympalAssetsPluginConfiguration.class.php
    2010-01-30 21:35:52 UTC (rev 27342)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/config/sfSympalAssetsPluginConfiguration.class.php
    2010-01-30 22:44:27 UTC (rev 27343)
@@ -6,7 +6,6 @@
   {
     $this->dispatcher->connect('sympal.load_admin_menu', array($this, 
'loadAdminMenu'));
     $this->dispatcher->connect('sympal.load_config_form', array($this, 
'loadConfigForm'));
-    $this->dispatcher->connect('sympal.content_renderer.filter_slot_content', 
array('sfSympalAssetReplacer', 'listenToFilterSlotContent'));
     $this->dispatcher->connect('sympal.load_inline_edit_bar_buttons', 
array($this, 'loadInlineEditBarButtons'));
   }
 

Added: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/replacer/sfSympalContentSyntaxAssetReplacer.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/replacer/sfSympalContentSyntaxAssetReplacer.class.php
                             (rev 0)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/replacer/sfSympalContentSyntaxAssetReplacer.class.php
     2010-01-30 22:44:27 UTC (rev 27343)
@@ -0,0 +1,80 @@
+<?php
+
+/**
+ * Class responsible for actually processing the asset syntaxes:
+ * 
+ * [asset:1]
+ * [asset:1 alt="my cool image"]
+ * 
+ * @package     sfSympalAssetsPlugin
+ * @subpackage  replacer
+ * @author      Jonathan H. Wage <[email protected]>
+ * @author      Ryan Weaver <[email protected]>
+ * @since       2010-01-30
+ * @version     svn:$Id$ $Author$
+ */
+class sfSympalContentSyntaxAssetReplacer extends sfSympalContentSyntaxReplacer
+{
+  /**
+   * @see sfSympalContentSyntaxReplacer
+   */
+  public function process($replacements, $content)
+  {
+    $assetObjects = $this->_getAssetObjects(array_keys($replacements));
+    $assetObjects = self::_buildObjects($assetObjects);
+    
+    foreach ($replacements as $id => $replacement)
+    {
+      $assetObject = $assetObjects[$id];
+      $content = $assetObject->filterContent($content, 
$replacement['replace'], $replacement['options']);
+    }
+    
+    return $content;
+  }
+  
+  /**
+   * Retrieves the Doctrine_Collection of asset objects.
+   * 
+   * If the core replacer is of type sfSympalContentSlotReplacer then
+   * we have access to a sfSympalContent object to which we'll want to
+   * relate these sfSympalAsset objects
+   */
+  protected function _getAssetObjects($ids)
+  {
+    if ($this->_replacer instanceof sfSympalContentSlotReplacer)
+    {
+      $sympalContent = $this->_replacer->getContent();
+      if (array_diff($ids, $sympalContent->Assets->getPrimaryKeys()) || 
array_diff($sympalContent->Assets->getPrimaryKeys(), $ids))
+      {
+        $assetObjects = $this->_getQueryForAssetObjects($ids)->execute();
+        
+        foreach ($assetObjects as $assetObject)
+        {
+          $sympalContent->Assets[] = $assetObject;
+        }
+        
+        $sympalContent->save();
+      }
+
+      return $sympalContent->Assets;
+    }
+    else
+    {
+      return $this->_getQueryForAssetObjects($ids)->execute();
+    }
+  }
+  
+  /**
+   * Returns the query that should be used if we need to query out
+   * and get a collection of sfSympalContent objects
+   */
+  protected function _getQueryForAssetObjects($ids)
+  {
+    $q = Doctrine_Core::getTable('sfSympalAsset')
+      ->createQuery()
+      ->from('sfSympalAsset a')
+      ->whereIn('a.id', array_unique($ids));
+    
+    return $q;
+  }
+}
\ No newline at end of file

Deleted: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/sfSympalAssetReplacer.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/sfSympalAssetReplacer.class.php
   2010-01-30 21:35:52 UTC (rev 27342)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAssetsPlugin/lib/sfSympalAssetReplacer.class.php
   2010-01-30 22:44:27 UTC (rev 27343)
@@ -1,284 +0,0 @@
-<?php
-
-/**
- * Class responsible for parsing and replacing syntaxes for linking to assets,
- * embedding assets, linking to other content, etc.
- *
- * Examples:
- *
- *  * [asset:1 label="Linking to content id #1"]
- *  * [link:123]
- *  * [asset:1 link=true]
- *  * [asset:1 embed=true]
- */
-class sfSympalAssetReplacer
-{
-  private
-    $_slot,
-    $_content;
-  
-  /**
-   * Array of possible keys (e.g. asset, link) that should be searched
-   * for along with the callback that should be called to make that replacement
-   * 
-   * 'link'   => array('sfSympalAssetReplacer' => '_replaceLinks')
-   * 'asset'  => array('sfSympalAssetReplacer' => '_replaceAssets')
-   */
-  protected
-    $_replacementMap = null;
-
-  public function __construct(sfSympalContentSlot $slot)
-  {
-    $this->_slot = $slot;
-    $this->_content = $slot->getContentRenderedFor();
-  }
-
-  public static function listenToFilterSlotContent(sfEvent $event, $content)
-  {
-    $replacer = new self($event->getSubject());
-
-    return $replacer->replace($content);
-  }
-
-  public function replace($content)
-  {
-    if ($parsed = $this->_parseSyntaxes($content))
-    {
-      $ids = $parsed['ids'];
-      $replacements = $parsed['replacements'];
-      
-      $replacementKeys = array_keys($ids);
-      // iterate through all of the replacement types
-      foreach($replacementKeys as $key)
-      {
-        $content = $this->handleReplacementCallback($key, $ids[$key], 
$replacements[$key], $content);
-      }
-    }
-
-    return $content;
-  }
-  
-  /**
-   * Handles the callbacks for each type of replacement and returns the
-   * filtered content
-   */
-  protected function handleReplacementCallback($key, $ids, $replacements, 
$content)
-  {
-    $map = $this->getReplacementMap();
-    $callback = $map[$key];
-    
-    return call_user_func($callback, $key, $ids, $replacements, $content, 
$this);
-  }
-  
-  /**
-   * Searches through the content and extracts out any matches. The return
-   * value is a formatted array of what needs to be replaced
-   */
-  private function _parseSyntaxes($content)
-  {
-    // create the replacement string (e.g. link|asset|myObject)
-    $replacementString = implode('|', array_keys($this->getReplacementMap()));
-    
-    preg_match_all("/\[($replacementString):(.*?)\]/", $content, $matches);
-
-    if (isset($matches[0]) && $matches[0])
-    {
-      $ids = array();
-      $replacements = array();
-
-      $types = $matches[1];
-      $bodies = $matches[2];
-
-      foreach ($bodies as $key => $body)
-      {
-        $e = explode(' ', $body);
-        $ids[$types[$key]][] = $e[0];
-        $replacements[$types[$key]][] = array(
-          'id' => $e[0],
-          'options' => _parse_attributes(substr($body, strlen($e[0]))),
-          'replace' => $matches[0][$key]
-        );
-      }
-      return array(
-        'ids' => $ids,
-        'replacements' => $replacements
-      );
-    } else {
-      return false;
-    }
-  }
-  
-  /**
-   * Handles the replacement of "asset" keys
-   */
-  public static function _replaceAssets($key, $ids, $replacements, $content, 
sfSympalAssetReplacer $replacer)
-  {
-    if (array_diff($ids, $replacer->getContent()->Assets->getPrimaryKeys()) || 
array_diff($replacer->getContent()->Assets->getPrimaryKeys(), $ids))
-    {
-      $assetObjects = Doctrine_Core::getTable('sfSympalAsset')
-        ->createQuery()
-        ->from('sfSympalAsset a')
-        ->whereIn('a.id', array_unique($ids))
-        ->execute();
-      foreach ($assetObjects as $assetObject)
-      {
-        $replacer->getContent()->Assets[] = $assetObject;
-      }
-      $replacer->getContent()->save();
-    }
-
-    $assetObjects = self::_buildObjects($replacer->getContent()->Assets);
-    foreach ($replacements as $replacement)
-    {
-      $assetObject = $assetObjects[$replacement['id']];
-      $content = $assetObject->filterContent($content, 
$replacement['replace'], $replacement['options']);
-    }
-    return $content;
-  }
-  
-  /**
-   * Handles the replacement of "link" keys
-   */
-  public static function _replaceLinks($key, $ids, $replacements, $content, 
sfSympalAssetReplacer $replacer)
-  {
-    if (array_diff($ids, $replacer->getContent()->Links->getPrimaryKeys()) || 
array_diff($replacer->getContent()->Links->getPrimaryKeys(), $ids))
-    {
-      $q = Doctrine_Core::getTable('sfSympalAsset')
-        ->createQuery('c')
-        ->from('sfSympalContent c')
-        ->innerJoin('c.Type t')
-        ->whereIn('c.id', array_unique($ids));
-
-      if (sfSympalConfig::isI18nEnabled('sfSympalContent'))
-      {
-        $q->leftJoin('c.Translation ct');
-      }
-
-      $contentObjects = $q->execute();
-      foreach ($contentObjects as $contentObject)
-      {
-        $replacer->getContent()->Links[] = $contentObject;
-      }
-      $replacer->getContent()->save();
-    }
-
-    $contentObjects = self::_buildObjects($replacer->getContent()->Links);
-    foreach ($replacements as $replacement)
-    {
-      $contentObject = $contentObjects[$replacement['id']];
-      
-      $urlOnly = isset($replacement['options']['url']) ? 
$replacement['options']['url'] : false;
-      unset($replacement['options']['url']);
-      
-      if ($urlOnly)
-      {
-        $content = str_replace($replacement['replace'], 
url_for($contentObject->getRoute(), $replacement['options']), $content);
-      }
-      else
-      {
-        $label = isset($replacement['options']['label']) ? 
$replacer->replace($replacement['options']['label']) : 'Link to content id 
#'.$replacement['id'];
-        unset($replacement['options']['label']);
-        
-        $content = str_replace($replacement['replace'], link_to($label, 
$contentObject->getRoute(), $replacement['options']), $content);
-      }
-    }
-    return $content;
-  }
-  
-  /**
-   * Replaces objects, we can correspond to a wide-variety of keys
-   */
-  public static function _replaceObjects($key, $ids, $replacements, $content, 
sfSympalAssetReplacer $replacer)
-  {
-    $slotObjectConfig = sfSympalConfig::get('content_slot_objects', $key, 
array());
-    
-    // of we can't locate the key, just replace everything with nothing
-    if (!isset($slotObjectConfig['class']))
-    {
-      foreach($replacements as $replacement)
-      {
-        $content = str_replace($replacement['replace'], '', $content);
-      }
-      
-      return $content;
-    }
-    
-    $template = $slotObjectConfig['template'];
-    $class = $slotObjectConfig['class'];
-    
-    // retrieve the Doctrine_Collection of objects
-    $tbl = Doctrine_Core::getTable($class);
-    if (method_exists($tbl, 'fetchForSlot'))
-    {
-      $slotObjects = $tbl->fetchForSlot($ids);
-    }
-    else
-    {
-      $slotObjects = $tbl->createQuery('s')
-        ->whereIn('s.id', $ids)
-        ->execute();
-    }
-    
-    $slotObjects = self::_buildObjects($slotObjects);
-    foreach ($replacements as $replacement)
-    {
-      $slotObject = $slotObjects[$replacement['id']];
-      
-      $replacement['options'][$class] = $slotObject;
-      $ret = get_partial($template, $replacement['options']);
-      
-      $content = str_replace($replacement['replace'], $ret, $content);
-    }
-    
-    return $content;
-  }
-  
-  /**
-   * Remaps a doctrine collection so that the keys of the colleciton "array"
-   * are the ids of the underlying objects. This makes the collection
-   * easier to deal with then replacing objects
-   * 
-   * @return Doctrine_Collection
-   */
-  public static function _buildObjects(Doctrine_Collection $collection)
-  {
-    $objects = new Doctrine_Collection($collection->getTable());
-    foreach ($collection as $key => $value)
-    {
-      $objects[$value->id] = $value;
-    }
-
-    return $objects;
-  }
-  
-  /**
-   * Retrieves all of the replacements and their associated callbacks
-   */
-  protected function getReplacementMap()
-  {
-    if ($this->_replacementMap === null)
-    {
-      $map = array(
-        'link'   => array('sfSympalAssetReplacer', '_replaceLinks'),
-        'asset'  => array('sfSympalAssetReplacer', '_replaceAssets')
-      );
-      
-      $dispatcher = 
sfContext::getInstance()->getConfiguration()->getEventDispatcher();
-      
-      $this->_replacementMap = $dispatcher->filter(
-        new sfEvent($this, 'sympal.asset_replacer.filter_map'),
-        $map
-      )->getReturnValue();
-    }
-    
-    return $this->_replacementMap;
-  }
-  
-  /**
-   * @return sfSympalContent
-   */
-  public function getContent()
-  {
-    return $this->_content;
-  }
-}
\ No newline at end of file

Added: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/config/sfSympalContentSyntaxPluginConfiguration.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/config/sfSympalContentSyntaxPluginConfiguration.class.php
                              (rev 0)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/config/sfSympalContentSyntaxPluginConfiguration.class.php
      2010-01-30 22:44:27 UTC (rev 27343)
@@ -0,0 +1,9 @@
+<?php
+
+class sfSympalContentSyntaxPluginConfiguration extends sfPluginConfiguration
+{
+  public function initialize()
+  {
+    $this->dispatcher->connect('sympal.content_renderer.filter_slot_content', 
array('sfSympalContentSlotReplacer', 'listenToFilterSlotContent'));
+  }
+}
\ No newline at end of file

Added: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/replacer/sfSympalContentSyntaxReplacer.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/replacer/sfSympalContentSyntaxReplacer.class.php
                           (rev 0)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/replacer/sfSympalContentSyntaxReplacer.class.php
   2010-01-30 22:44:27 UTC (rev 27343)
@@ -0,0 +1,71 @@
+<?php
+
+/**
+ * Abstract class that handles the replacement of one type of syntax type.
+ * 
+ * @package     sfSympalContentSyntaxPlugin
+ * @subpackage  replacer
+ * @author      Ryan Weaver <[email protected]>
+ * @since       2010-01-30
+ * @version     svn:$Id$ $Author$
+ */
+
+abstract class sfSympalContentSyntaxReplacer
+{
+  protected
+    $_replacer,
+    $_type,
+    $_options;
+  
+  /**
+   * Class constructor
+   * 
+   * @param sfSympalContentReplacer $replacer The replacer class that is 
overseeing the entire replacement process
+   * @param string                  $type     The type (asset, link) that is 
being replaced
+   * @param array                   $options  An array of options
+   */
+  public function __construct(sfSympalContentReplacer $replacer, $type, 
$options = array())
+  {
+    $this->_replacer = $replacer;
+    $this->_type = $type;
+    $this->_options = $options;
+  }
+  
+  /**
+   * The main function that is called to run the replacement
+   * 
+   * @see sfSympalContentReplacer::_parseSyntaxes
+   * 
+   * @param   array   $replacements The array of replacements to process
+   * @param   string  $content      The raw content to make the replacements to
+   * 
+   * @return  string The processed/replaced content
+   */
+  abstract public function process($replacements, $content);
+  
+  /**
+   * Remaps a doctrine collection so that the keys of the colleciton "array"
+   * are the ids of the underlying objects. This makes the collection
+   * easier to deal with then replacing objects
+   * 
+   * @return Doctrine_Collection
+   */
+  protected static function _buildObjects(Doctrine_Collection $collection)
+  {
+    $objects = new Doctrine_Collection($collection->getTable());
+    foreach ($collection as $key => $value)
+    {
+      $objects[$value->id] = $value;
+    }
+
+    return $objects;
+  }
+  
+  /**
+   * @return mixed
+   */
+  public function getOption($name, $default = null)
+  {
+    return isset($this->_options[$name]) ? $this->_options[$name] : $default;
+  }
+}
\ No newline at end of file

Added: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/sfSympalContentReplacer.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/sfSympalContentReplacer.class.php
                          (rev 0)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/sfSympalContentReplacer.class.php
  2010-01-30 22:44:27 UTC (rev 27343)
@@ -0,0 +1,114 @@
+<?php
+
+/**
+ * Core class that handles the processing and replacing of raw text
+ * 
+ * @package     sfSympalContentSyntaxPlugin
+ * @subpackage  core
+ * @author      Jonathan H. Wage <[email protected]>
+ * @author      Ryan Weaver <[email protected]>
+ * @since       2010-01-30
+ * @version     svn:$Id$ $Author$
+ */
+
+class sfSympalContentReplacer
+{
+  public function __construct()
+  {
+  }
+  
+  /**
+   * Processes the given content and returns it
+   * 
+   * @param   string $content The raw content to process
+   * @return  string The processed content
+   */
+  public function replace($content)
+  {
+    if ($parsed = $this->_parseSyntaxes($content))
+    {      
+      // iterate through all of the replacement types
+      foreach($parsed as $type => $replacements)
+      {
+        $content = $this->processReplacerType($type, $replacements, $content);
+      }
+    }
+
+    return $content;
+  }
+  
+  /**
+   * Processes the array of replacements for the given type
+   */
+  protected function processReplacerType($type, $replacements, $content)
+  {
+    $config = sfSympalConfig::get('content_syntax_types', $type, array());
+    
+    if (!isset($config['replacer_class']))
+    {
+      throw new sfException(sprintf('No replacer_class defined for "%s" key in 
content_syntax_types', $type));
+    }
+    
+    $class = $config['replacer_class'];
+    $options = isset($config['replacer_options']) ? 
$config['replacer_options'] : array();
+    $replacer = new $class($this, $type, $options);
+      
+    return $replacer->process($replacements, $content);
+  }
+  
+  /**
+   * Searches through the content and extracts out any matches. The return
+   * value is a formatted array of what needs to be replaced
+   * 
+   * Returned syntax will look like this:
+   *   array(
+   *     'link' => array(
+   *       3 => array('options' => array(), 'replace' => '[link:3]'),
+   *       5 => array('options' => array('option' => 'value'), 'replace' => 
'[link:5 option=value]'),
+   *     ), asset => array(
+   *       10 => array('options' => array(), 'replace' => '[asset:10]'),
+   *     ),
+   *   )
+   * 
+   * @return array
+   */
+  private function _parseSyntaxes($content)
+  {
+    // create the replacement string (e.g. link|asset|myObject)
+    $replacementString = implode('|', 
array_keys(sfSympalConfig::get('content_syntax_types')));
+    preg_match_all("/\[($replacementString):(.*?)\]/", $content, $matches);
+
+    if (isset($matches[0]) && $matches[0])
+    {
+      $replacements = array();
+      $types = $matches[1];
+      $bodies = $matches[2];
+      
+      foreach($types as $type)
+      {
+        $replacements[$type] = array();
+      }
+      
+      /*
+       * body matches (e.g. "3" or "5 option=value")
+       */
+      foreach ($bodies as $key => $body)
+      {
+        // use the key to find the corresponding type
+        $typeKey = $types[$key];
+        
+        $e = explode(' ', $body);
+        $id = $e[0];
+        
+        $replacements[$typeKey][$id] = array(
+          'options' => _parse_attributes(substr($body, strlen($e[0]))),
+          'replace' => $matches[0][$key],
+        );
+      }
+      
+      return $replacements;
+    } else {
+      return false;
+    }
+  }
+}
\ No newline at end of file

Added: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/sfSympalContentSlotReplacer.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/sfSympalContentSlotReplacer.class.php
                              (rev 0)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentSyntaxPlugin/lib/sfSympalContentSlotReplacer.class.php
      2010-01-30 22:44:27 UTC (rev 27343)
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Subclass of the main replacer class, which allows some special functionality
+ * when we know that the content is linked to a sfSympalContentSlot object
+ * 
+ * @package     sfSympalContentSyntaxPlugin
+ * @subpackage  core
+ * @author      Ryan Weaver <[email protected]>
+ * @since       2010-01-30
+ * @version     svn:$Id$ $Author$
+ */
+
+class sfSympalContentSlotReplacer extends sfSympalContentReplacer
+{
+  protected
+    $_content;
+  
+  public function __construct(sfSympalContent $content)
+  {
+    $this->_content = $content;
+    
+    parent::__construct();
+  }
+  
+  /*
+   * Responds to the sympal.content_renderer.filter_slot_content filter
+   * event. This creates a new replacer and returns the processed content
+   */
+  public static function listenToFilterSlotContent(sfEvent $event, $content)
+  {
+    $replacer = new self($event->getSubject()->getContentRenderedFor());
+    
+    return $replacer->replace($content);
+  }
+  
+  /**
+   * @return sfSympalContent
+   */
+  public function getContent()
+  {
+    return $this->_content;
+  }
+}
\ No newline at end of file

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/config/routing.yml
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/config/routing.yml
    2010-01-30 21:35:52 UTC (rev 27342)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/config/routing.yml
    2010-01-30 22:44:27 UTC (rev 27343)
@@ -9,7 +9,3 @@
 sympal_editor_links:
   url:   /editor/links
   param: { module: sympal_editor, action: links }
-
-sympal_editor_objects:
-  url:   /editor/objects
-  param: { module: sympal_editor, action: objects }

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/lib/helper/SympalContentSlotEditorHelper.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/lib/helper/SympalContentSlotEditorHelper.php
  2010-01-30 21:35:52 UTC (rev 27342)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/lib/helper/SympalContentSlotEditorHelper.php
  2010-01-30 22:44:27 UTC (rev 27343)
@@ -48,11 +48,6 @@
       isEditModeButton(true)->
       setInputClass('toggle_sympal_links')
     ;
-
-    $menu->addChild('Objects', '@sympal_editor_objects')->
-      isEditModeButton(true)->
-      setInputClass('toggle_sympal_objects')
-    ;
   }
 
   sfApplicationConfiguration::getActive()->getEventDispatcher()->notify(

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/modules/sympal_editor/lib/Basesympal_editorActions.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/modules/sympal_editor/lib/Basesympal_editorActions.class.php
  2010-01-30 21:35:52 UTC (rev 27342)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/modules/sympal_editor/lib/Basesympal_editorActions.class.php
  2010-01-30 22:44:27 UTC (rev 27343)
@@ -46,34 +46,4 @@
       ->orderBy('m.root_id, m.lft ASC')
       ->execute();
   }
-  
-  /**
-   * Ajax action that populates the object choose on the editor toolbar
-   */
-  public function executeObjects(sfWebRequest $request)
-  {
-    $this->slotKeys = array_keys(sfSympalConfig::get('content_slot_objects', 
null, array()));
-    
-    if (count($this->slotKeys))
-    {
-      if (!$object_slug = $request->getParameter('slot_key'))
-      {
-        $this->slotKey = $this->slotKeys[0];
-      } else {
-        $this->slotKey = $object_slug;
-      }
-      
-      $config = sfSympalConfig::get('content_slot_objects', $this->slotKey);
-      $class = $config['class'];
-      
-      $tbl = Doctrine_Core::getTable($class);
-      
-      $q = (method_exists($tbl, 'getObjectSlotQuery')) ? 
$tbl->getObjectSlotQuery() : $tbl->createQuery();
-      $this->objects = $q->execute();
-    }
-    else
-    {
-      $this->slotKey = false;
-    }
-  }
 }
\ No newline at end of file

Deleted: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/modules/sympal_editor/templates/objectsSuccess.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/modules/sympal_editor/templates/objectsSuccess.php
    2010-01-30 21:35:52 UTC (rev 27342)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/modules/sympal_editor/templates/objectsSuccess.php
    2010-01-30 22:44:27 UTC (rev 27343)
@@ -1,56 +0,0 @@
-<?php sympal_use_jquery() ?>
-<script type="text/javascript" src="<?php echo 
javascript_path('/sfSympalEditorPlugin/js/objects.js') ?>"></script>
-
-<div id="sympal_objects_container">
-  <h1><?php echo __('Object Browser') ?></h1>
-
-  <p>
-    <?php echo __(
-      'Browse your objects below and insert objects into the currently focused 
editor by '.
-      'just clicking the object you want to choose.') ?>
-  </p>
-
-  <div id="content_types">
-    <?php if (count($slotKeys)): ?>
-      <h2><?php echo __('Classes') ?></h2>
-      <ul id="editor_slot_object_classes">
-        <?php foreach ($slotKeys as $key): ?>
-          <li>
-            <?php if ($slotKey === $key): ?>
-              <strong><?php echo $key ?></strong>
-            <?php else: ?>
-              <?php echo jq_link_to_remote($key, array(
-                'url' => url_for('@sympal_editor_objects?slot_key='.$key),
-                'update' => 'sympal_objects_container'
-              )) ?>
-            <?php endif; ?>
-          </li>
-        <?php endforeach; ?>
-      </ul>
-    <?php else: ?>
-      <h2><?php echo __('No objects slots have been defined') ?></h2>
-    <?php endif; ?>
-  </div>
-
-  <div id="sympal_objects_list">
-    <?php if ($slotKey): ?>
-      <h2><?php echo $slotKey ?> <?php echo __('Objects') ?></h2>
-      <ul>
-        <?php if (count($objects)): ?>
-
-          <?php foreach ($objects as $object): ?>
-            <li rel="<?php echo $slotKey.':'.$object->id ?>">
-              <?php echo image_tag('/sfSympalPlugin/images/file_icon.gif') ?>
-
-              <a href="#"><?php echo $object ?></a>
-            </li>
-          <?php endforeach; ?>
-        <?php else: ?>
-          <?php echo __('Nothing found') ?>
-        <?php endif; ?>
-      </ul>
-    <?php endif; ?>
-  </div>
-
-  <a class="sympal_close_menu"><?php echo __('Close') ?></a>
-</div>
\ No newline at end of file

Deleted: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/web/js/objects.js
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/web/js/objects.js 
    2010-01-30 21:35:52 UTC (rev 27342)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalEditorPlugin/web/js/objects.js 
    2010-01-30 22:44:27 UTC (rev 27343)
@@ -1,10 +0,0 @@
-$(function() {
-  $('#sympal_objects_container #sympal_objects_list ul li a').click(function() 
{
-    parentEle = $(this).parents('li');
-    
-    var text = '['+ parentEle.attr('rel') + ']';
-    sympalInsertIntoCurrentEditor(text);
-    
-    return false;
-  });
-});
\ No newline at end of file

Added: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/config/app.yml
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/config/app.yml 
                            (rev 0)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/config/app.yml 
    2010-01-30 22:44:27 UTC (rev 27343)
@@ -0,0 +1,5 @@
+all:
+  sympal_config:
+    content_syntax_types:
+      link:
+        replacer_class:    sfSympalContentSyntaxLinkReplacer

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/config/sfSympalRenderingPluginConfiguration.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/config/sfSympalRenderingPluginConfiguration.class.php
      2010-01-30 21:35:52 UTC (rev 27342)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/config/sfSympalRenderingPluginConfiguration.class.php
      2010-01-30 22:44:27 UTC (rev 27343)
@@ -5,8 +5,6 @@
   public function initialize()
   {
     $this->dispatcher->connect('response.filter_content', array($this, 
'listenToResponseFilterContent'));
-    
-    $this->dispatcher->connect('sympal.asset_replacer.filter_map', 
array($this, 'listenToAssetReplacerFilterMap'));
   }
 
   public function listenToResponseFilterContent(sfEvent $event, $content)
@@ -24,20 +22,4 @@
       return $content;
     }
   }
-  
-  /**
-   * Listens to sympal.asset_replacer.filter_map and adds in all of the
-   * content slot objects that should be filtered
-   */
-  public function listenToAssetReplacerFilterMap(sfEvent $event, $map)
-  {
-    $slotObjects = sfSympalConfig::get('content_slot_objects', null, array());
-    foreach($slotObjects as $slotKey => $slotConfig)
-    {
-      $callback = isset($slotConfig['replacement_callback']) ? 
$slotConfig['replacement_callback'] : array('sfSympalAssetReplacer', 
'_replaceObjects');
-      $map[$slotKey] = $callback;
-    }
-    
-    return $map;
-  }
 }
\ No newline at end of file

Added: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/replacer/sfSympalContentSyntaxLinkReplacer.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/replacer/sfSympalContentSyntaxLinkReplacer.class.php
                           (rev 0)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/replacer/sfSympalContentSyntaxLinkReplacer.class.php
   2010-01-30 22:44:27 UTC (rev 27343)
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * Class responsible for actually processing the link syntaxes:
+ * 
+ * [link:1]
+ * [link:1 title="click me"]
+ * 
+ * @package     sfSympalAssetsPlugin
+ * @subpackage  replacer
+ * @author      Jonathan H. Wage <[email protected]>
+ * @author      Ryan Weaver <[email protected]>
+ * @since       2010-01-30
+ * @version     svn:$Id$ $Author$
+ */
+class sfSympalContentSyntaxLinkReplacer extends sfSympalContentSyntaxReplacer
+{
+  /**
+   * @see sfSympalContentSyntaxReplacer
+   */
+  public function process($replacements, $content)
+  {
+    $contentObjects = $this->_getContentObjects(array_keys($replacements));
+    $contentObjects = self::_buildObjects($contentObjects);
+    
+    foreach ($replacements as $id => $replacement)
+    {
+      $contentObject = $contentObjects[$id];
+      
+      $urlOnly = isset($replacement['options']['url']) ? 
$replacement['options']['url'] : false;
+      unset($replacement['options']['url']);
+      
+      if ($urlOnly)
+      {
+        $content = str_replace($replacement['replace'], 
url_for($contentObject->getRoute(), $replacement['options']), $content);
+      }
+      else
+      {
+        $label = isset($replacement['options']['label']) ? 
$this->_replacer->replace($replacement['options']['label']) : 'Link to content 
id #'.$id;
+        unset($replacement['options']['label']);
+        
+        $content = str_replace($replacement['replace'], link_to($label, 
$contentObject->getRoute(), $replacement['options']), $content);
+      }
+    }
+    
+    return $content;
+  }
+  
+  /**
+   * Retrieves the Doctrine_Collection of sfSympalContent objects.
+   * 
+   * If the core replacer is of type sfSympalContentSlotReplacer then
+   * we have access to a sfSympalContent object to which we'll want to
+   * relate these sfSympalContent objects
+   */
+  protected function _getContentObjects($ids)
+  {
+    if ($this->_replacer instanceof sfSympalContentSlotReplacer)
+    {
+      $sympalContent = $this->_replacer->getContent();
+      if (array_diff($ids, $sympalContent->Links->getPrimaryKeys()) || 
array_diff($sympalContent->Links->getPrimaryKeys(), $ids))
+      {
+        $contentObjects = $this->_getQueryForContentObjects($ids)->execute();
+        
+        foreach ($contentObjects as $contentObject)
+        {
+          $sympalContent->Links[] = $contentObject;
+        }
+        
+        $sympalContent->save();
+      }
+
+      return $sympalContent->Links;
+    }
+    else
+    {
+      return $this->_getQueryForContentObjects($ids)->execute();
+    }
+  }
+  
+  /**
+   * Returns the query that should be used if we need to query out
+   * and get a collection of sfSympalContent objects
+   */
+  protected function _getQueryForContentObjects($ids)
+  {
+    $q = Doctrine_Core::getTable('sfSympalContent')
+      ->createQuery('c')
+      ->from('sfSympalContent c')
+      ->innerJoin('c.Type t')
+      ->whereIn('c.id', array_unique($ids));
+
+    if (sfSympalConfig::isI18nEnabled('sfSympalContent'))
+    {
+      $q->leftJoin('c.Translation ct');
+    }
+    
+    return $q;
+  }
+}
\ No newline at end of file

-- 
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