Permalink
Browse files

Initial commit of just the configuration panel. More to come.

  • Loading branch information...
0 parents commit 8a79d1f296db87c63be96a52cb4559ae02309dcd @mikelietz mikelietz committed Jan 11, 2012
Showing with 57 additions and 0 deletions.
  1. +38 −0 membership.plugin.php
  2. +19 −0 membership.plugin.xml
@@ -0,0 +1,38 @@
+<?php
+
+class Membership extends Plugin
+{
+ public function configure()
+ {
+ $ui = new FormUI( "membership" );
+ $tokens = $ui->append( 'textarea', 'tokens', 'option:membership__tokens', _t( 'Tokens, one per line', 'membership' ) );
+ $tokens->rows = 4;
+ $tokens->class[] = 'resizable';
+ $tokens->add_validator( array( $this, "duplicate_validator" ) );
+ $ui->on_success( array( $this, 'updated_config' ) );
+ $ui->append( 'submit', 'save', _t( 'Save', 'membership' ) );
+ return $ui;
+ }
+
+ public function duplicate_validator( $list, $control, $form )
+ {
+ $values = explode( "\n", $list );
+ $values = array_map( 'trim', $values );
+ $dupes = array_keys( array_filter( array_count_values( $values ), create_function( '$v', 'return $v > 1;' ) ) );
+
+ if( count( $dupes ) ) {
+ return array( _t( 'Tokens must be unique. There is more than one: %s', array( implode( ", ", $dupes ) ), 'membership' ) );
+ }
+ else {
+ return array();
+ }
+ }
+
+ public function updated_config( FormUI $ui )
+ {
+ Session::notice( _t( 'Tokens saved.' , 'membership' ) );
+ $ui->save();
+ }
+
+}
+?>
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<pluggable type="plugin" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schemas.habariproject.org/pluggable/0.8">
+ <name>Membership</name>
+ <license url="http://www.apache.org/licenses/LICENSE-2.0.html">Apache Software License 2.0</license>
+
+ <author url="http://habariproject.org/">The Habari Community</author>
+
+ <version>1.0</version>
+ <url>http://habariproject.org/</url>
+ <description><![CDATA[Restrict access to posts based on customizable tokens.]]></description>
+
+ <copyright>2011</copyright>
+
+ <help>
+ <value><![CDATA[
+ If you need help with this plugin don't bother to contact me.
+ ]]></value>
+ </help>
+</pluggable>

0 comments on commit 8a79d1f

Please sign in to comment.