Author: boutell
Date: 2010-01-15 22:11:07 +0100 (Fri, 15 Jan 2010)
New Revision: 26695

Modified:
   plugins/pkContextCMSPlugin/trunk/lib/pkContextCMSTools.php
   
plugins/pkContextCMSPlugin/trunk/modules/pkContextCMS/lib/BasepkContextCMSActions.class.php
   plugins/pkContextCMSPlugin/trunk/modules/pkContextCMS/templates/_addSlot.php
Log:
"Add slot" slot names and slot CSS classes are now computed once and cached 
rather than being recomputed for each add slot button on the page.

The css class name is now arrived at by a regexp that is safer and will work 
better with a really short prefix like, I don't know, "a".



Modified: plugins/pkContextCMSPlugin/trunk/lib/pkContextCMSTools.php
===================================================================
--- plugins/pkContextCMSPlugin/trunk/lib/pkContextCMSTools.php  2010-01-15 
21:08:37 UTC (rev 26694)
+++ plugins/pkContextCMSPlugin/trunk/lib/pkContextCMSTools.php  2010-01-15 
21:11:07 UTC (rev 26695)
@@ -138,27 +138,49 @@
     }
     throw new sfException("Option group $groupName is not defined in app.yml");
   }
-  static public function getSlotTypeOptions($options)
+
+  // Cache this information for the duration of the request
+  static public $slotTypesInfo = null;
+  
+  static public function getSlotTypesInfo($options)
   {
-    $slotTypes = array_merge(
-      array(
-        'pkContextCMSText' => 'Plain Text',
-        'pkContextCMSRichText' => 'Rich Text'),
-      sfConfig::get('app_pkContextCMS_slot_types', array()));
-    if (isset($options['allowed_types']))
+    if (!isset(self::$slotTypesInfo))
     {
-      $newSlotTypes = array();
-      foreach($options['allowed_types'] as $type)
+      $slotTypes = array_merge(
+        array(
+          'pkContextCMSText' => 'Plain Text',
+          'pkContextCMSRichText' => 'Rich Text'),
+        sfConfig::get('app_pkContextCMS_slot_types', array()));
+      if (isset($options['allowed_types']))
       {
-        if (isset($slotTypes[$type]))
+        $newSlotTypes = array();
+        foreach($options['allowed_types'] as $type)
         {
-          $newSlotTypes[$type] = $slotTypes[$type];
+          if (isset($slotTypes[$type]))
+          {
+            $newSlotTypes[$type] = $slotTypes[$type];
+          }
         }
+        $slotTypes = $newSlotTypes;
       }
-      $slotTypes = $newSlotTypes;
+      $info = array();
+      
+      foreach ($slotTypes as $type => $label)
+      {
+        $info[$type]['label'] = $label;
+        $info[$type]['class'] = strtolower(preg_replace('/^pkContextCMS(\w)/', 
'pk-$1', $type));
+      }
+      self::$slotTypesInfo = $info;
     }
-    return $slotTypes; 
+    return self::$slotTypesInfo;
   }
+  
+  // Includes classes for buttons for adding each slot type
+  static public function getSlotTypeOptionsAndClasses($options)
+  {
+    
+  }
+  
   static public function getOption($array, $name, $default)
   {
     if (isset($array[$name]))

Modified: 
plugins/pkContextCMSPlugin/trunk/modules/pkContextCMS/lib/BasepkContextCMSActions.class.php
===================================================================
--- 
plugins/pkContextCMSPlugin/trunk/modules/pkContextCMS/lib/BasepkContextCMSActions.class.php
 2010-01-15 21:08:37 UTC (rev 26694)
+++ 
plugins/pkContextCMSPlugin/trunk/modules/pkContextCMS/lib/BasepkContextCMSActions.class.php
 2010-01-15 21:11:07 UTC (rev 26695)
@@ -277,7 +277,7 @@
     // allowed slots for this area, not just the allowed slots globally.
     // There is very little harm in this as slots rarely have
     // security implications, but custom slots someday might.
-    if (!in_array($this->type, 
array_keys(pkContextCMSTools::getSlotTypeOptions($options))))
+    if (!in_array($this->type, 
array_keys(pkContextCMSTools::getSlotTypesInfo($options))))
     {
       $this->forward404();
     }

Modified: 
plugins/pkContextCMSPlugin/trunk/modules/pkContextCMS/templates/_addSlot.php
===================================================================
--- 
plugins/pkContextCMSPlugin/trunk/modules/pkContextCMS/templates/_addSlot.php    
    2010-01-15 21:08:37 UTC (rev 26694)
+++ 
plugins/pkContextCMSPlugin/trunk/modules/pkContextCMS/templates/_addSlot.php    
    2010-01-15 21:11:07 UTC (rev 26695)
@@ -1,16 +1,17 @@
 <?php
-$slotoptions = pkContextCMSTools::getSlotTypeOptions($options);
+$slotTypesInfo = pkContextCMSTools::getSlotTypesInfo($options);
 
-foreach ($slotoptions as $option => $label) {
-
+foreach ($slotTypesInfo as $type => $info) {
+  $label = $info['label'];
+  $class = $info['class'];
        $link = jq_link_to_remote($label, array(
-               "url" => "pkContextCMS/addSlot?" . 
http_build_query(array('name' => $name, 'id' => $id, 'type' => $option, )),
+               "url" => "pkContextCMS/addSlot?" . 
http_build_query(array('name' => $name, 'id' => $id, 'type' => $type, )),
                "update" => "pk-slots-$name",
                'script' => true,
                'complete' => 'pkUI("#pk-area-'.$name.'","add-slot");', 
                ), 
                array(
-                       'class' => 'pk-btn icon 
'.str_replace('pkcontextcms','pk-', strtolower($option)).' slot', 
+                       'class' => 'pk-btn icon ' . $class .' slot', 
        ));
 
        echo "<li>".$link."</li>";

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