Author: weaverryan
Date: 2010-01-23 06:43:18 +0100 (Sat, 23 Jan 2010)
New Revision: 27084

Modified:
   plugins/sfSympalCommentsPlugin/branches/1.4/config/app.yml
   plugins/sfSympalCommentsPlugin/branches/1.4/config/doctrine/schema.yml
   plugins/sfSympalCommentsPlugin/branches/1.4/config/routing.yml
   
plugins/sfSympalCommentsPlugin/branches/1.4/config/sfSympalCommentsPluginConfiguration.class.php
   
plugins/sfSympalCommentsPlugin/branches/1.4/lib/filter/doctrine/PluginsfSympalCommentFormFilter.class.php
   
plugins/sfSympalCommentsPlugin/branches/1.4/lib/form/doctrine/sfSympalNewCommentForm.class.php
   plugins/sfSympalCommentsPlugin/branches/1.4/lib/helper/CommentsHelper.php
   
plugins/sfSympalCommentsPlugin/branches/1.4/lib/model/doctrine/PluginsfSympalComment.class.php
   
plugins/sfSympalCommentsPlugin/branches/1.4/modules/sympal_comments/lib/Basesympal_commentsActions.class.php
   
plugins/sfSympalCommentsPlugin/branches/1.4/modules/sympal_comments/templates/_for_content.php
Log:
[1.4][sfSympalPlugin][1.0] Refactoring the comments plugin: 
 - The subject field was removed         
 - An email (if not logged in, required) and a website (optional) field were 
added
 - Tests were improved
 - Backend configuration was improved - status is a drop-down menu
 - comment posting was made a post route
 - two new configuration values related to the website field

Some of the configuration behavior still needs to be tested and there is still 
a de-sync
between the format of the backend configuration editor and the app.yml key for 
this plugin.
As of now, editing this plugin's config through the backend just won't work.


Modified: plugins/sfSympalCommentsPlugin/branches/1.4/config/app.yml
===================================================================
--- plugins/sfSympalCommentsPlugin/branches/1.4/config/app.yml  2010-01-23 
04:28:43 UTC (rev 27083)
+++ plugins/sfSympalCommentsPlugin/branches/1.4/config/app.yml  2010-01-23 
05:43:18 UTC (rev 27084)
@@ -7,6 +7,8 @@
       sfSympalNewCommentForm: ~
 
     sfSympalCommentsPlugin:
-      default_status: Approved
-      enabled: true
-      requires_auth: true
\ No newline at end of file
+      default_status: Approved    # Approved, Pending, Denied
+      enabled:        true
+      requires_auth:  false
+      allow_websites: true        # whether to allow a "websites" field on the 
comments
+      websites_no_follow: true    # whether to make website links nofollow

Modified: plugins/sfSympalCommentsPlugin/branches/1.4/config/doctrine/schema.yml
===================================================================
--- plugins/sfSympalCommentsPlugin/branches/1.4/config/doctrine/schema.yml      
2010-01-23 04:28:43 UTC (rev 27083)
+++ plugins/sfSympalCommentsPlugin/branches/1.4/config/doctrine/schema.yml      
2010-01-23 05:43:18 UTC (rev 27084)
@@ -8,9 +8,9 @@
       default: Pending
       notnull: true
     user_id: integer
-    name: string(255)
-    subject:
-      type: string(255)
+    name:    string(255)
+    email_address:   string(255)
+    website: string(255)
     body:
       type: clob
       notnull: true

Modified: plugins/sfSympalCommentsPlugin/branches/1.4/config/routing.yml
===================================================================
--- plugins/sfSympalCommentsPlugin/branches/1.4/config/routing.yml      
2010-01-23 04:28:43 UTC (rev 27083)
+++ plugins/sfSympalCommentsPlugin/branches/1.4/config/routing.yml      
2010-01-23 05:43:18 UTC (rev 27084)
@@ -1,6 +1,9 @@
 sympal_create_comment:
   url:   /create_comment
+  class: sfRequestRoute
   param: { module: sympal_comments, action: create }
+  requirements:
+    sf_method:  [post]
 
 sympal_comments:
   class:                  sfDoctrineRouteCollection

Modified: 
plugins/sfSympalCommentsPlugin/branches/1.4/config/sfSympalCommentsPluginConfiguration.class.php
===================================================================
--- 
plugins/sfSympalCommentsPlugin/branches/1.4/config/sfSympalCommentsPluginConfiguration.class.php
    2010-01-23 04:28:43 UTC (rev 27083)
+++ 
plugins/sfSympalCommentsPlugin/branches/1.4/config/sfSympalCommentsPluginConfiguration.class.php
    2010-01-23 05:43:18 UTC (rev 27084)
@@ -47,6 +47,15 @@
       $form->addSetting($contentType['slug'], 'enable_comments', 'Enable 
Comments', 'InputCheckbox', 'Boolean');
     }
 
+    $choices = array(
+      'Approved'  => 'Approved',
+      'Pending'   => 'Pending',
+      'Denied'    => 'Denied',
+    );
+    $widget = new sfWidgetFormChoice(array('choices' => $choices));
+    $validator = new sfValidatorChoice(array('choices' => 
array_keys($choices)));
+    $form->addSetting('Comments', 'default_status', 'Default Status', $widget, 
$validator);
+
     $form->addSetting('Comments', 'default_status', 'Default Status');
     $form->addSetting('Comments', 'enabled', 'Enabled', 'InputCheckbox', 
'Boolean');
     $form->addSetting('Comments', 'requires_auth', 'Commenting Requires 
Authentication', 'InputCheckbox', 'Boolean');

Modified: 
plugins/sfSympalCommentsPlugin/branches/1.4/lib/filter/doctrine/PluginsfSympalCommentFormFilter.class.php
===================================================================
--- 
plugins/sfSympalCommentsPlugin/branches/1.4/lib/filter/doctrine/PluginsfSympalCommentFormFilter.class.php
   2010-01-23 04:28:43 UTC (rev 27083)
+++ 
plugins/sfSympalCommentsPlugin/branches/1.4/lib/filter/doctrine/PluginsfSympalCommentFormFilter.class.php
   2010-01-23 05:43:18 UTC (rev 27084)
@@ -12,6 +12,14 @@
   public function setup()
   {
     parent::setup();
-    unset($this['created_at'], $this['updated_at'], $this['body']);
+    
+    $this->useFields(array(
+      'status',
+      'user_id',
+      'name',
+      'email',
+      'website',
+      'content_list',
+    ));
   }
 }
\ No newline at end of file

Modified: 
plugins/sfSympalCommentsPlugin/branches/1.4/lib/form/doctrine/sfSympalNewCommentForm.class.php
===================================================================
--- 
plugins/sfSympalCommentsPlugin/branches/1.4/lib/form/doctrine/sfSympalNewCommentForm.class.php
      2010-01-23 04:28:43 UTC (rev 27083)
+++ 
plugins/sfSympalCommentsPlugin/branches/1.4/lib/form/doctrine/sfSympalNewCommentForm.class.php
      2010-01-23 05:43:18 UTC (rev 27084)
@@ -5,18 +5,32 @@
   public function setup()
   {
     parent::setup();
+    
+    $this->useFields(array(
+      'name',
+      'email_address',
+      'website',
+      'body',
+      'user_id',
+    ));
 
-    unset($this['id'], $this['content_list'], $this['status'], 
$this['created_at'], $this['updated_at'], $this['blog_posts_list'], 
$this['users_list'], $this['pages_list']);
-
-    $this->widgetSchema['subject']->setAttribute('style', 'width: 300px');
     $this->widgetSchema['body']->setAttribute('style', 'width: 400px; height: 
200px;');
     $this->widgetSchema->setHelp('body', 'Markdown syntax is enabled.');
-
-    if (sfSympalConfig::get('sfSympalCommentsPlugin', 'requires_auth'))
+    
+    $this->validatorSchema['website'] = new sfValidatorUrl(array('required' => 
false));
+    $this->validatorSchema['website']->setMessage('invalid', 'Please enter a 
valid url (e.g. http://www.sympalphp.org)');
+    
+    $this->validatorSchema['email_address']->setOption('required', true);
+    $this->validatorSchema['body']->setOption('required', true);
+    
+    // if auth is required, the User will be set, the name and email aren't 
needed
+    if (sfContext::getInstance()->getUser()->isAuthenticated())
     {
       unset($this['name'], $this['email_address']);
       $this->widgetSchema['user_id'] = new sfWidgetFormInputHidden();
-    } else {
+    }
+    else
+    {
       unset($this['user_id']);
     }
 

Modified: 
plugins/sfSympalCommentsPlugin/branches/1.4/lib/helper/CommentsHelper.php
===================================================================
--- plugins/sfSympalCommentsPlugin/branches/1.4/lib/helper/CommentsHelper.php   
2010-01-23 04:28:43 UTC (rev 27083)
+++ plugins/sfSympalCommentsPlugin/branches/1.4/lib/helper/CommentsHelper.php   
2010-01-23 05:43:18 UTC (rev 27084)
@@ -13,10 +13,29 @@
   $user = sfContext::getInstance()->getUser();
   $form = new sfSympalNewCommentForm();
   $form->setDefault('content_id', $content->getId());
-
-  if (sfSympalConfig::get('sfSympalCommentsPlugin', 'requires_auth') && 
$user->isAuthenticated())
+  
+  // if authenticated, set the user_id default value
+  if ($user->isAuthenticated())
   {
     $form->setDefault('user_id', $user->getGuardUser()->getId());
   }
   return $form;
+}
+
+/**
+ * Returns the anchor tag to a comment's website
+ * 
+ * @param   string $url     The url of the website to link to
+ * @param   string $label   The text to include inside the link
+ * @param   array  $options An array of link options
+ * @return  string
+ */
+function link_to_sympal_comment_website(sfSympalComment $comment, $options = 
array())
+{
+  if (sfSympalConfig::get('sfSympalCommentsPlugin', 'websites_no_follow'))
+  {
+    $options['rel'] = 'nofollow';
+  }
+  
+  return link_to($comment['author_name'], $comment['website'], $options);
 }
\ No newline at end of file

Modified: 
plugins/sfSympalCommentsPlugin/branches/1.4/lib/model/doctrine/PluginsfSympalComment.class.php
===================================================================
--- 
plugins/sfSympalCommentsPlugin/branches/1.4/lib/model/doctrine/PluginsfSympalComment.class.php
      2010-01-23 04:28:43 UTC (rev 27083)
+++ 
plugins/sfSympalCommentsPlugin/branches/1.4/lib/model/doctrine/PluginsfSympalComment.class.php
      2010-01-23 05:43:18 UTC (rev 27084)
@@ -11,7 +11,23 @@
     {
       return $this->getAuthor()->getName();
     } else {
-      return $this->name;
+      return ($this->name) ? $this->name : 'anonymous';
     }
   }
+  
+  /**
+   * Returns the relevant email address for this comment - either from
+   * the logged-in user or the actual email that was entered
+   * 
+   * @return string
+   */
+  public function getAuthorEmailAddress()
+  {
+    if ($this->user_id)
+    {
+      return $this->getAuthor()->getEmailAddress();
+    } else {
+      return $this->email_address;
+    }
+  }
 }
\ No newline at end of file

Modified: 
plugins/sfSympalCommentsPlugin/branches/1.4/modules/sympal_comments/lib/Basesympal_commentsActions.class.php
===================================================================
--- 
plugins/sfSympalCommentsPlugin/branches/1.4/modules/sympal_comments/lib/Basesympal_commentsActions.class.php
        2010-01-23 04:28:43 UTC (rev 27083)
+++ 
plugins/sfSympalCommentsPlugin/branches/1.4/modules/sympal_comments/lib/Basesympal_commentsActions.class.php
        2010-01-23 05:43:18 UTC (rev 27084)
@@ -4,13 +4,10 @@
 {
   public function executeCreate(sfWebRequest $request)
   {
+    $this->authComments();
+    
     $this->loadDefaultTheme();
 
-    if (sfSympalConfig::get('sfSympalCommentsPlugin', 'requires_auth') && 
!$this->getUser()->isAuthenticated())
-    {
-      throw new sfException('Comments require that you are authenticated!');
-    }
-
     $this->content = 
Doctrine::getTable('sfSympalContent')->find($request['sf_sympal_comment']['content_id']);
 
     $this->form = new sfSympalNewCommentForm();
@@ -65,4 +62,23 @@
       $object->save();
     }
   }
+  
+  /**
+   * Function validates if the current user has the rights to be posting
+   * comments.
+   * 
+   * @throws sfException
+   */
+  protected function authComments()
+  {
+    if (sfSympalConfig::get('sfSympalCommentsPlugin', 'requires_auth') && 
!$this->getUser()->isAuthenticated())
+    {
+      throw new sfException('Comments require that you are authenticated!');
+    }
+    
+    if (!sfSympalConfig::get('sfSympalCommentsPlugin', 'enabled'))
+    {
+      throw new sfException('Commenting is disabled');
+    }
+  }
 }
\ No newline at end of file

Modified: 
plugins/sfSympalCommentsPlugin/branches/1.4/modules/sympal_comments/templates/_for_content.php
===================================================================
--- 
plugins/sfSympalCommentsPlugin/branches/1.4/modules/sympal_comments/templates/_for_content.php
      2010-01-23 04:28:43 UTC (rev 27083)
+++ 
plugins/sfSympalCommentsPlugin/branches/1.4/modules/sympal_comments/templates/_for_content.php
      2010-01-23 05:43:18 UTC (rev 27084)
@@ -2,43 +2,44 @@
 <?php use_stylesheet('/sfSympalCommentsPlugin/css/comments.css') ?>
 
 <?php $record = $content->getRecord() ?>
-<?php if ($content->getTable()->hasRelation('Comments')): ?>
-  <div id="sympal_comments">
-    <?php if ($num = count($content['Comments'])): ?>
-      <h2>Comments (<?php echo $num ?>)</h2>
-      <ul>
-        <?php foreach ($content['Comments'] as $comment): ?>
-          <li>
-            <a name="comment_<?php echo $comment->getId() ?>"></a>
-            <h3><?php echo $comment['subject'] ?></h3>
-            <?php if ($comment['user_id']): ?>
-              <small>Posted on <?php echo date('m/d/Y h:i', 
strtotime($comment['created_at'])) ?> by <?php echo $comment['author_name'] 
?>.</small>
-              <?php echo 
image_tag(get_gravatar_url($comment->Author->getEmailAddress()), 'align=right') 
?>
+<div id="sympal_comments">
+  <?php if ($num = count($content['Comments'])): ?>
+    <h2>Comments (<?php echo $num ?>)</h2>
+    <ul>
+      <?php foreach ($content['Comments'] as $comment): ?>
+        <li>
+          <a name="comment_<?php echo $comment->getId() ?>"></a>
+          
+          <small>
+            Posted on <?php echo date('m/d/Y h:i', 
strtotime($comment['created_at'])) ?> by
+            <?php if ($comment->website && 
sfSympalConfig::get('sfSympalCommentsPlugin', 'allow_websites')): ?>
+              <?php echo link_to_sympal_comment_website($comment) ?>.
             <?php else: ?>
-              <small>Posted on <?php echo date('m/d/Y h:i', 
strtotime($comment['created_at'])) ?> by <?php echo $comment['author_name'] 
?>.</small>
+              <?php echo $comment['author_name'] ?>.
             <?php endif; ?>
+          </small>
+          <?php echo 
image_tag(get_gravatar_url($comment['author_email_address']), 'align=right') ?>
 
-            <?php echo 
sfSympalMarkdownRenderer::convertToHtml($comment['body']) ?>
-          </li>
-        <?php endforeach; ?>
-      </ul>
-    <?php else: ?>
-      <h2>No Comments Created. Be the first to <a 
href="#form">comment</a>.</h2>
-    <?php endif; ?>
-  </div>
-
-  <?php if ((sfSympalConfig::get('sfSympalCommentsPlugin', 'requires_auth') && 
$sf_user->isAuthenticated()) || !sfSympalConfig::get('sfSympalCommentsPlugin', 
'requires_auth')): ?>
-    <?php echo $form->renderFormTag(url_for('@sympal_create_comment')) ?>
-      <input type="hidden" name="from_url" value="<?php echo 
$sf_request->getParameter('from_url', $sf_request->getUri()) ?>" />
-      <table id="form">
-        <?php echo $form; ?>
-      </table>
-      <input type="submit" name="save_comment" value="Save Comment" />
-    </form>
+          <?php echo sfSympalMarkdownRenderer::convertToHtml($comment['body']) 
?>
+        </li>
+      <?php endforeach; ?>
+    </ul>
   <?php else: ?>
-    <div class="notice">
-    You must <?php echo link_to('signin', '@sympal_signin') ?> to post 
comments.
-    If you don't already have an account then you can <?php echo 
link_to('register', '@sympal_register') ?>.
-    </div>
+    <h2>No Comments Created. Be the first to <a href="#form">comment</a>.</h2>
   <?php endif; ?>
-<?php endif; ?>
\ No newline at end of file
+</div>
+
+<?php if (($sf_user->isAuthenticated() || 
!sfSympalConfig::get('sfSympalCommentsPlugin', 'requires_auth'))): ?>
+  <?php echo $form->renderFormTag(url_for('@sympal_create_comment')) ?>
+    <input type="hidden" name="from_url" value="<?php echo 
$sf_request->getParameter('from_url', $sf_request->getUri()) ?>" />
+    <table id="form">
+      <?php echo $form; ?>
+    </table>
+    <input type="submit" name="save_comment" value="Save Comment" />
+  </form>
+<?php else: ?>
+  <div class="notice">
+  You must <?php echo link_to('signin', '@sympal_signin') ?> to post comments.
+  If you don't already have an account then you can <?php echo 
link_to('register', '@sympal_register') ?>.
+  </div>
+<?php endif; ?>

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