Index: /plugins/srPageChooserPlugin/trunk/LICENSE =================================================================== --- /plugins/srPageChooserPlugin/trunk/LICENSE (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/LICENSE (revision 29277) @@ -0,0 +1,22 @@ +-------------------------------------------------------------------------------- + srPageChooserPlugin +-------------------------------------------------------------------------------- + +Copyright (c) 2010 SunRun Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Index: /plugins/srPageChooserPlugin/trunk/config/srPageChooserPluginConfiguration.class.php =================================================================== --- /plugins/srPageChooserPlugin/trunk/config/srPageChooserPluginConfiguration.class.php (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/config/srPageChooserPluginConfiguration.class.php (revision 29277) @@ -0,0 +1,22 @@ + + * @version SVN: $Id: PluginConfiguration.class.php 17207 2009-04-10 15:36:26Z Kris.Wallsmith $ + */ +class srPageChooserPluginConfiguration extends sfPluginConfiguration +{ + const VERSION = '1.0.0-DEV'; + + /** + * @see sfPluginConfiguration + */ + public function initialize() + { + $this->dispatcher->connect('routing.load_configuration', array('srPageChooserRouting', 'listenToRoutingLoadConfigurationEvent')); + } +} Index: /plugins/srPageChooserPlugin/trunk/package.xml.tmpl =================================================================== --- /plugins/srPageChooserPlugin/trunk/package.xml.tmpl (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/package.xml.tmpl (revision 29277) @@ -0,0 +1,48 @@ + + + srPageChooserPlugin + plugins.symfony-project.org + This plugin is designed to work with the Apostrophe CMS by P'unk Ave. It allows + developers to add an srPageChooserWidget to forms, for use with choosing links + in slots, and also in the rich text slot. + This plugin is designed to work with the Apostrophe CMS by P'unk Ave. It allows + developers to add an srPageChooserWidget to forms, for use with choosing links + in slots, and also in the rich text slot. + + Alexander "Spike" Brehm + spikebrehm + ocelot@gmail.com + yes + + 27 April 2010 + + 1.0.0-DEV + + + alpha + + MIT license + - + + ##CONTENTS## + + + + + 5.2.4 + + + 1.4.1 + + + symfony + pear.symfony-project.com + 1.2.0 + 1.3.0 + 1.3.0 + + + + + + Index: /plugins/srPageChooserPlugin/trunk/lib/srValidatorSlug.class.php =================================================================== --- /plugins/srPageChooserPlugin/trunk/lib/srValidatorSlug.class.php (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/lib/srValidatorSlug.class.php (revision 29277) @@ -0,0 +1,66 @@ + + * @version SVN: $$ + */ +class srValidatorSlug extends sfValidatorRegex +{ + /** + * Configures the current validator. + * + * Available options: + * + * * strip_slash: Whether to strip the leading slash off the slug + * * add_slash: Whether to add a leading slash to the slug + * * pattern: A regex pattern compatible with PCRE or {@link sfCallable} that returns one (required) + * + * @param array $options An array of options + * @param array $messages An array of error messages + * + * @see sfValidatorString + */ + protected function configure($options = array(), $messages = array()) + { + parent::configure($options, $messages); + + $this->addRequiredOption('pattern'); + $this->addOption('strip_slash', false); + $this->addOption('add_slash', true); + $this->addOption('pattern', $this->getPattern()); + } + + /** + * @see sfValidatorString + */ + protected function doClean($value) + { + $clean = parent::doClean($value); + + if ($this->getOption('strip_slash')) + { + $clean = trim($value, '/'); + } + elseif ($this->getOption('add_slash')) + { + $clean = trim($value, '/'); + $clean = '/'.$clean; + } + + return $clean; + } + + /** + * Returns the current validator's regular expression. + * + * @return string + */ + public function getPattern() + { + return '/^[\w\/\-\+]+$/'; + } +} Index: /plugins/srPageChooserPlugin/trunk/lib/srPageChooserRouting.class.php =================================================================== --- /plugins/srPageChooserPlugin/trunk/lib/srPageChooserRouting.class.php (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/lib/srPageChooserRouting.class.php (revision 29277) @@ -0,0 +1,21 @@ + + */ +class srPageChooserRouting extends sfPatternRouting +{ + static public function listenToRoutingLoadConfigurationEvent(sfEvent $event) + { + $r = $event->getSubject(); + + $r->prependRoute('sr_page_chooser', + new sfRoute('/admin/srPageChooser', + array('module' => 'srPageChooser', 'action' => 'choose') + )); + } +} Index: /plugins/srPageChooserPlugin/trunk/lib/srWidgetFormPageChooser.class.php =================================================================== --- /plugins/srPageChooserPlugin/trunk/lib/srWidgetFormPageChooser.class.php (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/lib/srWidgetFormPageChooser.class.php (revision 29277) @@ -0,0 +1,94 @@ + + * @version SVN: $$ + */ +class srWidgetFormPageChooser extends sfWidgetForm +{ + + /** + * Constructor. + * + * Available options: + * + * * type: The widget type + * + * @param array $options An array of options + * @param array $attributes An array of default HTML attributes + * + * @see sfWidgetForm + */ + protected function configure($options = array(), $attributes = array()) + { + parent::configure($options, $attributes); + + $this->addOption('type', 'hidden'); + $this->addOption('buttonText', 'Select a Link'); + } + + /** + * @param string $name The element name + * @param string $value The value displayed in this widget + * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes + * @param array $errors An array of errors for the field + * + * @return string An HTML tag string + * + * @see sfWidgetForm + */ + public function render($name, $value = null, $attributes = array(), $errors = array()) + { + $attributes = array_merge(array('span' => array(), 'input' => array(), 'button' => array()), $attributes); + + $spanTag = $this->renderContentTag('span', $value, array_merge(array('class' => 'srwidgetformpagechooser'), $attributes['span'])); + + $inputTag = $this->renderTag('input', array_merge(array('type' => $this->getOption('type'), 'name' => $name, 'value' => $value, 'class' => 'srwidgetformpagechooser'), $attributes['input'])); + + $buttonTag = $this->renderContentTag('button', $this->getOption('buttonText'), array_merge(array('class' => 'srwidgetformpagechooser', 'type' => 'button'), $attributes['button'])); + + $iframe = self::renderIframe(); + + return '
' . $spanTag . $inputTag . $buttonTag . $iframe . '
'; + } + + static public function renderIframe() + { + $url = url_for('@sr_page_chooser'); + + return << +var sPageChooserWidgetUrl = '$url'; + +EOT; + //return ''; + } + + /** + * Gets the stylesheet paths associated with the widget. + * + * The array keys are files and values are the media names (separated by a ,): + * + * array('/path/to/file.css' => 'all', '/another/file.css' => 'screen,print') + * + * @return array An array of stylesheet paths + */ + public function getStylesheets() + { + return array('/srPageChooserPlugin/css/srPageChooserPlugin.css'); + } + + /** + * Gets the JavaScript paths associated with the widget. + * + * @return array An array of JavaScript paths + */ + public function getJavaScripts() + { + return array('/srPageChooserPlugin/js/srPageChooserPlugin.js'); + } +} Index: /plugins/srPageChooserPlugin/trunk/lib/BasesrPageChooserActions.class.php =================================================================== --- /plugins/srPageChooserPlugin/trunk/lib/BasesrPageChooserActions.class.php (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/lib/BasesrPageChooserActions.class.php (revision 29277) @@ -0,0 +1,32 @@ + + * @version SVN: $Id: BaseActions.class.php 12534 2008-11-01 13:38:27Z Kris.Wallsmith $ + */ +abstract class BasesrPageChooserActions extends sfActions +{ + /** + * Executes index action + * + * @param sfRequest $request A request object + */ + public function executeChoose(sfWebRequest $request) + { + // manually disable the web debug toolbar cause it screws up the small screen real estate + sfConfig::set('sf_web_debug', false); + + if ( ! $this->getUser()->hasCredential('cms_admin')) + { + return 'InvalidCredentials'; + } + + $root = aPageTable::retrieveBySlug('/'); + + $this->treeData = $root->getTreeJSONReadySR(false); + } +} Index: /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/actions/actions.class.php =================================================================== --- /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/actions/actions.class.php (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/actions/actions.class.php (revision 29277) @@ -0,0 +1,15 @@ + + * @version SVN: $Id: actions.class.php 12534 2008-11-01 13:38:27Z Kris.Wallsmith $ + */ +class srPageChooserActions extends BasesrPageChooserActions +{ +} Index: /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/config/view.yml =================================================================== --- /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/config/view.yml (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/config/view.yml (revision 29277) @@ -0,0 +1,5 @@ +default: + layout: bare + + javascripts: [-tmpHover.js] + stylesheets: [-website.css, -templates.css] Index: /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/templates/_includeFormAssets.php =================================================================== --- /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/templates/_includeFormAssets.php (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/templates/_includeFormAssets.php (revision 29277) @@ -0,0 +1,50 @@ + + + Index: /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/templates/chooseSuccess.php =================================================================== --- /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/templates/chooseSuccess.php (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/templates/chooseSuccess.php (revision 29277) @@ -0,0 +1,98 @@ + + +getResponse()->addJavascript('/apostrophePlugin/js/jsTree/_lib/css.js') ?> +getResponse()->addJavascript('/apostrophePlugin/js/jsTree/source/tree_component.js') ?> +getResponse()->addStylesheet('/apostrophePlugin/js/jsTree/source/tree_component.css') ?> + + + +
+ +
+ +
+ + Index: /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/templates/chooseInvalidCredentials.php =================================================================== --- /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/templates/chooseInvalidCredentials.php (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/modules/srPageChooser/templates/chooseInvalidCredentials.php (revision 29277) @@ -0,0 +1,1 @@ +You must be logged in as a CMS administrator. Index: /plugins/srPageChooserPlugin/trunk/README =================================================================== --- /plugins/srPageChooserPlugin/trunk/README (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/README (revision 29277) @@ -0,0 +1,9 @@ +# srPageChooserPlugin + +This plugin is designed to work with the Apostrophe CMS by P'unk Ave. It allows +developers to add an srPageChooserWidget to forms, for use with choosing links +in slots, and also in the rich text slot. + +Contact the developer at ocelot [a] gmail. + +Copyright (c) 2010 SunRun Inc. Index: /plugins/srPageChooserPlugin/trunk/web/css/srPageChooserPlugin.css =================================================================== --- /plugins/srPageChooserPlugin/trunk/web/css/srPageChooserPlugin.css (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/web/css/srPageChooserPlugin.css (revision 29277) @@ -0,0 +1,26 @@ +div.srwidgetformpagechooser-container { +} +span.srwidgetformpagechooser { + float: left; +} +span.srwidgetformpagechooser span.title, +p.srwidgetformpagechooser-url span.title { + font-weight: bold; + display: block; +} +button.srwidgetformpagechooser { + float: right; +} +div.srwidgetformpagechooser-iframe-container { + background: #fff url(../images/loading.gif) no-repeat scroll center center; + border: 1px solid #aaa; + padding: 10px; + position: absolute; + z-index: 1000; +} + +iframe.srwidgetformpagechooser { + overflow: auto; + height: 300px; + width: 340px; +} Index: /plugins/srPageChooserPlugin/trunk/web/js/srPageChooserPlugin.js =================================================================== --- /plugins/srPageChooserPlugin/trunk/web/js/srPageChooserPlugin.js (revision 29277) +++ /plugins/srPageChooserPlugin/trunk/web/js/srPageChooserPlugin.js (revision 29277) @@ -0,0 +1,80 @@ +(function($){ + + srPageChooserWidget = { + + elInput: 'input.srwidgetformpagechooser', + elSpan: 'span.srwidgetformpagechooser', + elButton: 'button.srwidgetformpagechooser', + elIframeContainer: 'div.srwidgetformpagechooser-iframe-container', + elIframe: 'iframe.srwidgetformpagechooser', + elButtonDone: 'button.srwidgetformpagechooser-done', + elPUrl: 'p.srwidgetformpagechooser-url', + elWidgetContainer: 'div.srwidgetformpagechooser-container', + + isEnabled: false, + + frameId: 'sr-page-chooser-frame', + + currentContainer: null, + + init: function() { + $(srPageChooserWidget.elButton).click(function(){ + srPageChooserWidget.clickHandler(this) + }); + + if (!$(srPageChooserWidget.elIframe).length) { + srPageChooserWidget.createIframe(); + } + }, + + createIframe: function(){ + var ifrm = $(''); + ifrm.appendTo('body'); + }, + + clickHandler: function(elButton) { + // so we can have multiple page choosers on one page or one slot + srPageChooserWidget.currentContainer = $(elButton).parents(srPageChooserWidget.elWidgetContainer); + var c = $(srPageChooserWidget.elIframeContainer); + var i = $(srPageChooserWidget.elIframe) + var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height(); + var h = viewportHeight/2 - c.height()/2; + var w = $(window).width()/2 - c.width()/2; + var offset = { + top: $(window).scrollTop(), //h > 0 ? h : 0, + left: w > 0 ? w : 0 + } + if (i.attr('src') === '') { + i.attr('src', sPageChooserWidgetUrl); + } + c.css(offset).show(); + c.find(srPageChooserWidget.elButtonDone).click(function(){ + srPageChooserWidget.doneHandler(this) + }) + return false; + }, + + doneHandler: function(elButtonDone) { + $(srPageChooserWidget.elIframeContainer).css().hide(); + }, + + pageSelectHandler: function(pageInfo, baseUrl) { + var url = (typeof(baseUrl) !== 'undefined' && baseUrl) ? 'http://' + baseUrl + pageInfo.slug : pageInfo.title; + var c = srPageChooserWidget.currentContainer; + c.find(srPageChooserWidget.elPUrl).html(''+pageInfo.title+''+pageInfo.slug); + c.find(srPageChooserWidget.elInput).val(pageInfo.slug); + c.find(srPageChooserWidget.elSpan).html(''+pageInfo.title+''+pageInfo.slug); + } + + } + + PageChooserParent = { + onPageSelect: function(pageInfo, baseUrl) { + srPageChooserWidget.pageSelectHandler(pageInfo, baseUrl) + } + } + + $(document).ready(function(){ + srPageChooserWidget.init(); + }); +})(jQuery);