import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
62
libs/Monkeys/AntiSpam.php
Normal file
62
libs/Monkeys/AntiSpam.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2008 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
|
||||
* @author Alejandro Pedraza
|
||||
* @since Sciret 1.2
|
||||
* @package Sciret
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_AntiSpam extends Zend_Service_Akismet
|
||||
{
|
||||
const TYPE_AKISMET = 1;
|
||||
const TYPE_TYPEPAD = 2;
|
||||
|
||||
const TYPEPAD_API_URL = 'api.antispam.typepad.com';
|
||||
|
||||
private $_type;
|
||||
|
||||
public function __construct($type)
|
||||
{
|
||||
$this->_type = $type;
|
||||
|
||||
switch ($type) {
|
||||
case self::TYPE_AKISMET:
|
||||
$apiKey = Zend_Registry::get('config')->akismet->key;
|
||||
break;
|
||||
case self::TYPE_TYPEPAD:
|
||||
$apiKey = Zend_Registry::get('config')->typePadAntiSpam->key;
|
||||
break;
|
||||
default:
|
||||
throw new Exception('Wrong spam service type');
|
||||
}
|
||||
|
||||
parent::__construct($apiKey, 'http://www.kb-m.com');
|
||||
}
|
||||
|
||||
protected function _post($host, $path, array $params)
|
||||
{
|
||||
if ($this->_type == self::TYPE_TYPEPAD) {
|
||||
$caller = $this->_getCallerMethod();
|
||||
if (strtolower($caller) == 'verifykey') {
|
||||
$host = self::TYPEPAD_API_URL;
|
||||
} else {
|
||||
$host = $this->getApiKey() . '.' . self::TYPEPAD_API_URL;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::_post($host, $path, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function _getCallerMethod()
|
||||
{
|
||||
$backTrace = debug_backtrace();
|
||||
|
||||
return $backTrace[2]['function'];
|
||||
}
|
||||
}
|
10
libs/Monkeys/Application/Module/Autoloader.php
Normal file
10
libs/Monkeys/Application/Module/Autoloader.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
class Monkeys_Application_Module_Autoloader extends Zend_Application_Module_Autoloader
|
||||
{
|
||||
public function __construct($options)
|
||||
{
|
||||
parent::__construct($options);
|
||||
$this->addResourceType('controllerHelpers', 'controllers', 'Controller');
|
||||
}
|
||||
}
|
@ -1,14 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
{
|
||||
/**
|
||||
@ -18,20 +9,30 @@ abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
protected $targetUser;
|
||||
|
||||
protected $_config;
|
||||
protected $_settings;
|
||||
protected $_numCols = 2;
|
||||
protected $_title = '';
|
||||
protected $underMaintenance = false;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->_config = Zend_Registry::get('config');
|
||||
$this->_settings = new Model_Settings();
|
||||
|
||||
if ($this->_request->getModuleName() != 'install'
|
||||
&& strtoupper(get_class($this)) != 'ERRORCONTROLLER'
|
||||
&& $this->_needsUpgrade()) {
|
||||
$this->_redirect('/install/upgrade');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Zend_Registry::isRegistered('user')) {
|
||||
// guest user
|
||||
$users = new Users();
|
||||
$users = new Users_Model_Users();
|
||||
$user = $users->createRow();
|
||||
Zend_Registry::set('user', $user);
|
||||
}
|
||||
|
||||
$this->_config = Zend_Registry::get('config');
|
||||
|
||||
$this->user = Zend_Registry::get('user');
|
||||
$this->view->user = $this->user;
|
||||
|
||||
@ -45,6 +46,18 @@ abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
$this->_setBase();
|
||||
$this->view->numCols = $this->_numCols;
|
||||
|
||||
$this->view->module = $this->getRequest()->getModuleName();
|
||||
|
||||
if ($this->_getParam('subtitle')) {
|
||||
$this->view->pageSubtitle = $this->view->escape($this->_getParam('subtitle'));
|
||||
}
|
||||
|
||||
if ($this->getRequest()->getParam('next')) {
|
||||
$this->view->nextAction = $this->getRequest()->getParam('next');
|
||||
} else {
|
||||
$this->view->nextAction = '';
|
||||
}
|
||||
|
||||
if ($this->getRequest()->isXmlHttpRequest()) {
|
||||
$slowdown = $this->_config->environment->ajax_slowdown;
|
||||
if ($slowdown > 0) {
|
||||
@ -52,13 +65,20 @@ abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
}
|
||||
$this->_helper->layout->disableLayout();
|
||||
} else {
|
||||
$this->view->version = Setup::VERSION;
|
||||
$this->view->version = Application::VERSION;
|
||||
$this->view->messages = $this->_helper->FlashMessenger->getMessages();
|
||||
$this->view->loaderCombine = $this->_config->environment->YDN? 'true' : 'false';
|
||||
$this->view->loaderBase = $this->_config->environment->YDN?
|
||||
'http://yui.yahooapis.com/2.6.0/build/'
|
||||
'http://yui.yahooapis.com/2.7.0/build/'
|
||||
: $this->view->base . '/javascript/yui/';
|
||||
}
|
||||
|
||||
$this->view->min = $this->_config->environment->production ? '-min' : '';
|
||||
}
|
||||
|
||||
public function postDispatch()
|
||||
{
|
||||
$this->view->title = $this->_title;
|
||||
}
|
||||
|
||||
private function _setScriptPaths()
|
||||
@ -75,43 +95,29 @@ abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
$view->addScriptPath($newPath);
|
||||
}
|
||||
|
||||
private function _setBase()
|
||||
protected function _setBase()
|
||||
{
|
||||
if ($this->_config->subdomain->enabled) {
|
||||
$protocol = $this->_getProtocol();
|
||||
|
||||
$this->view->base = "$protocol://"
|
||||
. ($this->_config->subdomain->use_www? 'www.' : '')
|
||||
. $this->_config->subdomain->hostname;
|
||||
} else {
|
||||
$this->view->base = $this->view->getBase();
|
||||
}
|
||||
$this->view->base = $this->view->getBase();
|
||||
}
|
||||
|
||||
private function _validateTargetUser()
|
||||
{
|
||||
if (Zend_Registry::isRegistered('targetUser')) {
|
||||
// used by unit tests to inject the target user
|
||||
$this->targetUser = Zend_Registry::get('targetUser');
|
||||
} else {
|
||||
$userId = $this->_getParam('userid');
|
||||
protected abstract function _validateTargetUser();
|
||||
|
||||
if (is_null($userId)) {
|
||||
$this->targetUser = $this->user;
|
||||
} elseif ($this->_getParam('userid') == 0) {
|
||||
$users = new Users();
|
||||
$this->targetUser = $users->createRow();
|
||||
} else {
|
||||
if ($userId != $this->user->id && $this->user->role != User::ROLE_ADMIN) {
|
||||
$this->_helper->FlashMessenger->addMessage('Error: Invalid user id');
|
||||
$this->_redirect('profile/edit');
|
||||
}
|
||||
$users = new Users();
|
||||
$this->targetUser = $users->getRowInstance($userId);
|
||||
}
|
||||
protected function _needsUpgrade()
|
||||
{
|
||||
require 'setup/versions.php';
|
||||
|
||||
$lastVersion = array_pop($versions);
|
||||
|
||||
return $lastVersion != $this->_getDbVersion();
|
||||
}
|
||||
|
||||
protected function _getDbVersion()
|
||||
{
|
||||
if (!$version = $this->_settings->getVersion()) {
|
||||
$version = '1.0.1';
|
||||
}
|
||||
|
||||
$this->view->targetUser = $this->targetUser;
|
||||
return $version;
|
||||
}
|
||||
|
||||
protected function _checkMaintenanceMode()
|
||||
@ -122,20 +128,10 @@ abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = new Settings();
|
||||
$this->underMaintenance = $settings->isMaintenanceMode();
|
||||
$this->underMaintenance = $this->_settings->isMaintenanceMode();
|
||||
$this->view->underMaintenance = $this->underMaintenance;
|
||||
}
|
||||
|
||||
protected function _redirectToNormalConnection()
|
||||
{
|
||||
if ($this->_config->SSL->enable_mixed_mode) {
|
||||
$this->_redirect('http://' . $_SERVER['HTTP_HOST'] . $this->view->base);
|
||||
} else {
|
||||
$this->_redirect('');
|
||||
}
|
||||
}
|
||||
|
||||
protected function _redirectForMaintenance($backToNormalConnection = false)
|
||||
{
|
||||
if ($backToNormalConnection) {
|
||||
@ -152,7 +148,7 @@ abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
return parent::_redirect($url, $options);
|
||||
}
|
||||
|
||||
protected function _getProtocol()
|
||||
public function getProtocol()
|
||||
{
|
||||
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
|
||||
return 'https';
|
||||
@ -160,4 +156,16 @@ abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
return 'http';
|
||||
}
|
||||
}
|
||||
|
||||
protected function _checkPermission($permission)
|
||||
{
|
||||
if (!$this->_hasPermission($permission)) {
|
||||
throw new Monkeys_AccessDeniedException();
|
||||
}
|
||||
}
|
||||
|
||||
protected function _overrideNumCols($numCols)
|
||||
{
|
||||
$this->view->numCols = $this->_numCols = $numCols;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,5 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
abstract class Monkeys_Controller_Error extends Monkeys_Controller_Action
|
||||
{
|
||||
protected $_numCols = 1;
|
||||
@ -115,4 +106,8 @@ EOD;
|
||||
|
||||
return $mail;
|
||||
}
|
||||
|
||||
protected function _validateTargetUser()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
private $_acl;
|
||||
@ -18,6 +9,10 @@ class Monkeys_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
|
||||
$this->_acl = $acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Here we only check for the basic action access permissions.
|
||||
* In Monkeys_Controller_Action we check for more specific permissions
|
||||
*/
|
||||
public function preDispatch($request)
|
||||
{
|
||||
if (!Zend_Registry::get('config')->environment->installed
|
||||
@ -36,7 +31,7 @@ class Monkeys_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
|
||||
$user= Zend_Registry::get('user');
|
||||
} else {
|
||||
$auth = Zend_Auth::getInstance();
|
||||
$users = new Users();
|
||||
$users = new Users_Model_Users();
|
||||
if ($auth->hasIdentity()) {
|
||||
$user = $auth->getStorage()->read();
|
||||
$user->init();
|
||||
@ -59,7 +54,7 @@ class Monkeys_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
|
||||
}
|
||||
|
||||
// if an admin is not allowed for this action, then the action doesn't exist
|
||||
if (!$this->_acl->isAllowed(User::ROLE_ADMIN, $resource, $request->getActionName())) {
|
||||
if (!$this->_acl->isAllowed(Users_Model_User::ROLE_ADMIN, $resource, $request->getActionName())) {
|
||||
//echo "role: " . $user->role . " - resource: $resource - privilege: " . $request->getActionName() . "<br>\n";
|
||||
throw new Monkeys_BadUrlException($this->getRequest()->getRequestUri());
|
||||
}
|
||||
|
@ -1,14 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Db_Profiler extends Zend_Db_Profiler
|
||||
{
|
||||
public function Monkeys_Db_Profiler()
|
||||
|
@ -1,14 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
abstract class Monkeys_Db_Table_Gateway extends Zend_Db_Table_Abstract
|
||||
{
|
||||
public function getRowInstance($id)
|
||||
|
4
libs/Monkeys/DuplicateException.php
Normal file
4
libs/Monkeys/DuplicateException.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
class Monkeys_DuplicateException extends Zend_Exception {}
|
||||
|
@ -1,15 +1,20 @@
|
||||
<?
|
||||
|
||||
class Monkeys_Form_Decorator_Composite extends Zend_Form_Decorator_Abstract
|
||||
implements Zend_Form_Decorator_Marker_File_Interface // to avoid Zend_Form_Element_File to whine
|
||||
{
|
||||
public function buildLabel()
|
||||
{
|
||||
$element = $this->getElement();
|
||||
$label = $element->getLabel();
|
||||
if ($label == '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($translator = $element->getTranslator()) {
|
||||
$label = $translator->translate($label);
|
||||
}
|
||||
if ($element->isRequired()) {
|
||||
if ($element->isRequired() && !$this->getOption('dontMarkRequired')) {
|
||||
$label .= '*';
|
||||
}
|
||||
|
||||
@ -83,6 +88,7 @@ class Monkeys_Form_Decorator_Composite extends Zend_Form_Decorator_Abstract
|
||||
return $content;
|
||||
}
|
||||
|
||||
$separator = $this->getSeparator();
|
||||
$placement = $this->getPlacement();
|
||||
$label = $this->buildLabel();
|
||||
$input = $this->buildInput($content);
|
||||
@ -102,15 +108,30 @@ class Monkeys_Form_Decorator_Composite extends Zend_Form_Decorator_Abstract
|
||||
}
|
||||
|
||||
if ($this->getOption('wideLabel')) {
|
||||
$output = "<div class=\"yui-$yuiGridType\" style=\"padding-bottom:10px\">\n"
|
||||
." <div class=\"formLabel\" style=\"padding-bottom:10px\">$label</div>\n"
|
||||
." <div class=\"yui-u first\"> </div>\n"
|
||||
." <div class=\"yui-u\">\n"
|
||||
." $input\n"
|
||||
." $desc\n"
|
||||
. ($errors? " <div>$errors</div>\n" : "")
|
||||
." </div>\n"
|
||||
."</div>\n";
|
||||
if ($label !== false) {
|
||||
$output = "<div class=\"yui-$yuiGridType\" style=\"padding-bottom:10px\">\n"
|
||||
." <div class=\"formLabel\" style=\"padding-bottom:10px\">$label</div>\n"
|
||||
." <div class=\"yui-u first\"> </div>\n"
|
||||
." <div class=\"yui-u\">\n"
|
||||
." $input\n"
|
||||
." $desc\n"
|
||||
. ($errors? " <div>$errors</div>\n" : "")
|
||||
." </div>\n"
|
||||
."</div>\n";
|
||||
} else {
|
||||
$output = "<div style=\"padding-bottom:10px\">\n"
|
||||
." $input\n"
|
||||
." $desc\n"
|
||||
. ($errors? " <div>$errors</div>\n" : "")
|
||||
."</div>\n";
|
||||
}
|
||||
} else if ($this->getOption('separateLine')) {
|
||||
$output = "<div class=\"yui-$yuiGridType\" style=\"font-weight:bold\">\n"
|
||||
." $label\n"
|
||||
."</div>\n"
|
||||
."<div>$input</div>\n"
|
||||
."<div>$desc</div>\n"
|
||||
. ($errors? "<div>$errors</div>\n" : "");
|
||||
} else if ($this->getOption('continuous')) {
|
||||
$output = "<div style=\"padding-bottom:10px\">\n"
|
||||
." <span class=\"formLabel\">$label</span> $input"
|
||||
@ -131,6 +152,15 @@ class Monkeys_Form_Decorator_Composite extends Zend_Form_Decorator_Abstract
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
// I believe we shouldn't use $placement (messes up the captcha, but I'm not sure about radios)
|
||||
/*switch ($placement) {
|
||||
case (self::PREPEND):
|
||||
return $output . $separator . $content;
|
||||
case (self::APPEND):
|
||||
default:
|
||||
return $content . $separator . $output;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
142
libs/Monkeys/Form/Element/DateTime.php
Normal file
142
libs/Monkeys/Form/Element/DateTime.php
Normal file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @since CommunityID0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Form_Element_DateTime extends Zend_Form_Element_Xhtml
|
||||
{
|
||||
public $helper = 'formDateTimeSelects';
|
||||
|
||||
public $options = array();
|
||||
|
||||
protected $_decorator;
|
||||
|
||||
public function __construct($spec, $options = array())
|
||||
{
|
||||
$options = array_merge($options, array('disableLoadDefaultDecorators' =>true));
|
||||
parent::__construct($spec, $options);
|
||||
|
||||
$this->_decorator = new Monkeys_Form_Decorator_Composite();
|
||||
$this->addDecorator($this->_decorator);
|
||||
}
|
||||
|
||||
public function setDecoratorOptions(array $options)
|
||||
{
|
||||
$this->_decorator->setOptions($options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->options['showEmpty'] = true;
|
||||
$this->options['startYear'] = 1900;
|
||||
$this->options['endYear'] = (int) date("Y");
|
||||
$this->options['reverseYears'] = false;
|
||||
}
|
||||
|
||||
public function setShowEmptyValues($value)
|
||||
{
|
||||
$this->options['showEmpty'] = (bool) $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setStartEndYear($start = null, $end = null)
|
||||
{
|
||||
if ($start)
|
||||
{
|
||||
$this->options['startYear'] = (int) $start;
|
||||
}
|
||||
|
||||
if ($end)
|
||||
{
|
||||
$this->options['endYear'] = (int) $end;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setReverseYears($value)
|
||||
{
|
||||
$this->options['reverseYears'] = (bool) $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isValid($value, $context = null)
|
||||
{
|
||||
$fieldName = $this->getName();
|
||||
$auxiliaryFieldsNames = $this->getDayMonthYearTimeFieldNames($fieldName);
|
||||
if (isset($context[$auxiliaryFieldsNames['day']]) && isset($context[$auxiliaryFieldsNames['month']])
|
||||
&& isset($context[$auxiliaryFieldsNames['year']]) && isset($context[$auxiliaryFieldsNames['hour']])
|
||||
&& isset($context[$auxiliaryFieldsNames['minutes']]) && isset($context[$auxiliaryFieldsNames['ampm']]))
|
||||
{
|
||||
if ($context[$auxiliaryFieldsNames['year']] == '-'
|
||||
|| $context[$auxiliaryFieldsNames['month']] == '-'
|
||||
|| $context[$auxiliaryFieldsNames['day']] == '-'
|
||||
|| $context[$auxiliaryFieldsNames['hour']] == '-'
|
||||
|| $context[$auxiliaryFieldsNames['minutes']] == '-'
|
||||
|| $context[$auxiliaryFieldsNames['ampm']] == '-')
|
||||
{
|
||||
$value = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$hour = $context[$auxiliaryFieldsNames['hour']];
|
||||
if ($context[$auxiliaryFieldsNames['ampm']] == 'pm') {
|
||||
$hour += 12;
|
||||
}
|
||||
$value = str_pad($context[$auxiliaryFieldsNames['year']], 4, '0', STR_PAD_LEFT) . '-'
|
||||
. str_pad($context[$auxiliaryFieldsNames['month']], 2, '0', STR_PAD_LEFT) . '-'
|
||||
. str_pad($context[$auxiliaryFieldsNames['day']], 2, '0', STR_PAD_LEFT) . ' '
|
||||
. str_pad($hour, 2, '0', STR_PAD_LEFT) . ':'
|
||||
. str_pad($context[$auxiliaryFieldsNames['minutes']], 2, '0', STR_PAD_LEFT) . ':00';
|
||||
}
|
||||
|
||||
$this->setValue($value);
|
||||
}
|
||||
|
||||
return parent::isValid($value, $context);
|
||||
}
|
||||
|
||||
protected function getDayMonthYearTimeFieldNames($value)
|
||||
{
|
||||
if (empty($value) || !is_string($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$ret = array(
|
||||
'day' => $value . '_day',
|
||||
'month' => $value . '_month',
|
||||
'year' => $value . '_year',
|
||||
'hour' => $value . '_hour',
|
||||
'minutes' => $value . '_minutes',
|
||||
'ampm' => $value . '_ampm',
|
||||
);
|
||||
|
||||
if (strstr($value, '['))
|
||||
{
|
||||
$endPos = strlen($value) - 1;
|
||||
if (']' != $value[$endPos]) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$start = strrpos($value, '[') + 1;
|
||||
$name = substr($value, $start, $endPos - $start);
|
||||
$arrayName = substr($value, 0, $start-1);
|
||||
$ret = array(
|
||||
'day' => $arrayName . '[' . $name . '_day' . ']',
|
||||
'month' => $arrayName . '[' . $name . '_month' . ']',
|
||||
'year' => $arrayName . '[' . $name . '_year' . ']',
|
||||
'hour' => $arrayName . '[' . $name . '_hour' . ']',
|
||||
'minutes' => $arrayName . '[' . $name . '_minutes' . ']',
|
||||
'ampm' => $arrayName . '[' . $name . '_ampm' . ']',
|
||||
);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
@ -2,12 +2,22 @@
|
||||
|
||||
class Monkeys_Form_Element_Password extends Zend_Form_Element_Password
|
||||
{
|
||||
private $_decorator;
|
||||
|
||||
public function __construct($spec, $options = array())
|
||||
{
|
||||
$options = array_merge($options, array('disableLoadDefaultDecorators' =>true));
|
||||
parent::__construct($spec, $options);
|
||||
|
||||
$this->addDecorator(new Monkeys_Form_Decorator_Composite());
|
||||
$this->_decorator = new Monkeys_Form_Decorator_Composite();
|
||||
$this->addDecorator($this->_decorator);
|
||||
}
|
||||
|
||||
public function setDecoratorOptions(array $options)
|
||||
{
|
||||
$this->_decorator->setOptions($options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
|
24
libs/Monkeys/Form/Element/Richtextarea.php
Normal file
24
libs/Monkeys/Form/Element/Richtextarea.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
class Monkeys_Form_Element_Richtextarea extends Zend_Form_Element_Xhtml
|
||||
{
|
||||
public $helper = 'formRichtextarea';
|
||||
|
||||
private $_decorator;
|
||||
|
||||
public function __construct($spec, $options = array())
|
||||
{
|
||||
$options = array_merge($options, array('disableLoadDefaultDecorators' =>true));
|
||||
parent::__construct($spec, $options);
|
||||
|
||||
$this->_decorator = new Monkeys_Form_Decorator_Composite();
|
||||
$this->addDecorator($this->_decorator);
|
||||
}
|
||||
|
||||
public function setDecoratorOptions(array $options)
|
||||
{
|
||||
$this->_decorator->setOptions($options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
23
libs/Monkeys/Form/Element/Select.php
Normal file
23
libs/Monkeys/Form/Element/Select.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class Monkeys_Form_Element_Select extends Zend_Form_Element_Select
|
||||
{
|
||||
private $_decorator;
|
||||
|
||||
public function __construct($spec, $options = array())
|
||||
{
|
||||
$options = array_merge($options, array('disableLoadDefaultDecorators' =>true));
|
||||
parent::__construct($spec, $options);
|
||||
|
||||
$this->_decorator = new Monkeys_Form_Decorator_Composite();
|
||||
$this->addDecorator($this->_decorator);
|
||||
}
|
||||
|
||||
public function setDecoratorOptions(array $options)
|
||||
{
|
||||
$this->_decorator->setOptions($options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
246
libs/Monkeys/Form/Element/list-en1-semic-2.txt
Normal file
246
libs/Monkeys/Form/Element/list-en1-semic-2.txt
Normal file
@ -0,0 +1,246 @@
|
||||
AFGHANISTAN;AF
|
||||
ÅLAND ISLANDS;AX
|
||||
ALBANIA;AL
|
||||
ALGERIA;DZ
|
||||
AMERICAN SAMOA;AS
|
||||
ANDORRA;AD
|
||||
ANGOLA;AO
|
||||
ANGUILLA;AI
|
||||
ANTARCTICA;AQ
|
||||
ANTIGUA AND BARBUDA;AG
|
||||
ARGENTINA;AR
|
||||
ARMENIA;AM
|
||||
ARUBA;AW
|
||||
AUSTRALIA;AU
|
||||
AUSTRIA;AT
|
||||
AZERBAIJAN;AZ
|
||||
BAHAMAS;BS
|
||||
BAHRAIN;BH
|
||||
BANGLADESH;BD
|
||||
BARBADOS;BB
|
||||
BELARUS;BY
|
||||
BELGIUM;BE
|
||||
BELIZE;BZ
|
||||
BENIN;BJ
|
||||
BERMUDA;BM
|
||||
BHUTAN;BT
|
||||
BOLIVIA;BO
|
||||
BOSNIA AND HERZEGOVINA;BA
|
||||
BOTSWANA;BW
|
||||
BOUVET ISLAND;BV
|
||||
BRAZIL;BR
|
||||
BRITISH INDIAN OCEAN TERRITORY;IO
|
||||
BRUNEI DARUSSALAM;BN
|
||||
BULGARIA;BG
|
||||
BURKINA FASO;BF
|
||||
BURUNDI;BI
|
||||
CAMBODIA;KH
|
||||
CAMEROON;CM
|
||||
CANADA;CA
|
||||
CAPE VERDE;CV
|
||||
CAYMAN ISLANDS;KY
|
||||
CENTRAL AFRICAN REPUBLIC;CF
|
||||
CHAD;TD
|
||||
CHILE;CL
|
||||
CHINA;CN
|
||||
CHRISTMAS ISLAND;CX
|
||||
COCOS (KEELING) ISLANDS;CC
|
||||
COLOMBIA;CO
|
||||
COMOROS;KM
|
||||
CONGO;CG
|
||||
CONGO, THE DEMOCRATIC REPUBLIC OF THE;CD
|
||||
COOK ISLANDS;CK
|
||||
COSTA RICA;CR
|
||||
CÔTE D'IVOIRE;CI
|
||||
CROATIA;HR
|
||||
CUBA;CU
|
||||
CYPRUS;CY
|
||||
CZECH REPUBLIC;CZ
|
||||
DENMARK;DK
|
||||
DJIBOUTI;DJ
|
||||
DOMINICA;DM
|
||||
DOMINICAN REPUBLIC;DO
|
||||
ECUADOR;EC
|
||||
EGYPT;EG
|
||||
EL SALVADOR;SV
|
||||
EQUATORIAL GUINEA;GQ
|
||||
ERITREA;ER
|
||||
ESTONIA;EE
|
||||
ETHIOPIA;ET
|
||||
FALKLAND ISLANDS (MALVINAS);FK
|
||||
FAROE ISLANDS;FO
|
||||
FIJI;FJ
|
||||
FINLAND;FI
|
||||
FRANCE;FR
|
||||
FRENCH GUIANA;GF
|
||||
FRENCH POLYNESIA;PF
|
||||
FRENCH SOUTHERN TERRITORIES;TF
|
||||
GABON;GA
|
||||
GAMBIA;GM
|
||||
GEORGIA;GE
|
||||
GERMANY;DE
|
||||
GHANA;GH
|
||||
GIBRALTAR;GI
|
||||
GREECE;GR
|
||||
GREENLAND;GL
|
||||
GRENADA;GD
|
||||
GUADELOUPE;GP
|
||||
GUAM;GU
|
||||
GUATEMALA;GT
|
||||
GUERNSEY;GG
|
||||
GUINEA;GN
|
||||
GUINEA-BISSAU;GW
|
||||
GUYANA;GY
|
||||
HAITI;HT
|
||||
HEARD ISLAND AND MCDONALD ISLANDS;HM
|
||||
HOLY SEE (VATICAN CITY STATE);VA
|
||||
HONDURAS;HN
|
||||
HONG KONG;HK
|
||||
HUNGARY;HU
|
||||
ICELAND;IS
|
||||
INDIA;IN
|
||||
INDONESIA;ID
|
||||
IRAN, ISLAMIC REPUBLIC OF;IR
|
||||
IRAQ;IQ
|
||||
IRELAND;IE
|
||||
ISLE OF MAN;IM
|
||||
ISRAEL;IL
|
||||
ITALY;IT
|
||||
JAMAICA;JM
|
||||
JAPAN;JP
|
||||
JERSEY;JE
|
||||
JORDAN;JO
|
||||
KAZAKHSTAN;KZ
|
||||
KENYA;KE
|
||||
KIRIBATI;KI
|
||||
KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF;KP
|
||||
KOREA, REPUBLIC OF;KR
|
||||
KUWAIT;KW
|
||||
KYRGYZSTAN;KG
|
||||
LAO PEOPLE'S DEMOCRATIC REPUBLIC;LA
|
||||
LATVIA;LV
|
||||
LEBANON;LB
|
||||
LESOTHO;LS
|
||||
LIBERIA;LR
|
||||
LIBYAN ARAB JAMAHIRIYA;LY
|
||||
LIECHTENSTEIN;LI
|
||||
LITHUANIA;LT
|
||||
LUXEMBOURG;LU
|
||||
MACAO;MO
|
||||
MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF;MK
|
||||
MADAGASCAR;MG
|
||||
MALAWI;MW
|
||||
MALAYSIA;MY
|
||||
MALDIVES;MV
|
||||
MALI;ML
|
||||
MALTA;MT
|
||||
MARSHALL ISLANDS;MH
|
||||
MARTINIQUE;MQ
|
||||
MAURITANIA;MR
|
||||
MAURITIUS;MU
|
||||
MAYOTTE;YT
|
||||
MEXICO;MX
|
||||
MICRONESIA, FEDERATED STATES OF;FM
|
||||
MOLDOVA, REPUBLIC OF;MD
|
||||
MONACO;MC
|
||||
MONGOLIA;MN
|
||||
MONTENEGRO;ME
|
||||
MONTSERRAT;MS
|
||||
MOROCCO;MA
|
||||
MOZAMBIQUE;MZ
|
||||
MYANMAR;MM
|
||||
NAMIBIA;NA
|
||||
NAURU;NR
|
||||
NEPAL;NP
|
||||
NETHERLANDS;NL
|
||||
NETHERLANDS ANTILLES;AN
|
||||
NEW CALEDONIA;NC
|
||||
NEW ZEALAND;NZ
|
||||
NICARAGUA;NI
|
||||
NIGER;NE
|
||||
NIGERIA;NG
|
||||
NIUE;NU
|
||||
NORFOLK ISLAND;NF
|
||||
NORTHERN MARIANA ISLANDS;MP
|
||||
NORWAY;NO
|
||||
OMAN;OM
|
||||
PAKISTAN;PK
|
||||
PALAU;PW
|
||||
PALESTINIAN TERRITORY, OCCUPIED;PS
|
||||
PANAMA;PA
|
||||
PAPUA NEW GUINEA;PG
|
||||
PARAGUAY;PY
|
||||
PERU;PE
|
||||
PHILIPPINES;PH
|
||||
PITCAIRN;PN
|
||||
POLAND;PL
|
||||
PORTUGAL;PT
|
||||
PUERTO RICO;PR
|
||||
QATAR;QA
|
||||
REUNION;RE
|
||||
ROMANIA;RO
|
||||
RUSSIAN FEDERATION;RU
|
||||
RWANDA;RW
|
||||
SAINT BARTHÉLEMY;BL
|
||||
SAINT HELENA;SH
|
||||
SAINT KITTS AND NEVIS;KN
|
||||
SAINT LUCIA;LC
|
||||
SAINT MARTIN;MF
|
||||
SAINT PIERRE AND MIQUELON;PM
|
||||
SAINT VINCENT AND THE GRENADINES;VC
|
||||
SAMOA;WS
|
||||
SAN MARINO;SM
|
||||
SAO TOME AND PRINCIPE;ST
|
||||
SAUDI ARABIA;SA
|
||||
SENEGAL;SN
|
||||
SERBIA;RS
|
||||
SEYCHELLES;SC
|
||||
SIERRA LEONE;SL
|
||||
SINGAPORE;SG
|
||||
SLOVAKIA;SK
|
||||
SLOVENIA;SI
|
||||
SOLOMON ISLANDS;SB
|
||||
SOMALIA;SO
|
||||
SOUTH AFRICA;ZA
|
||||
SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS;GS
|
||||
SPAIN;ES
|
||||
SRI LANKA;LK
|
||||
SUDAN;SD
|
||||
SURINAME;SR
|
||||
SVALBARD AND JAN MAYEN;SJ
|
||||
SWAZILAND;SZ
|
||||
SWEDEN;SE
|
||||
SWITZERLAND;CH
|
||||
SYRIAN ARAB REPUBLIC;SY
|
||||
TAIWAN, PROVINCE OF CHINA;TW
|
||||
TAJIKISTAN;TJ
|
||||
TANZANIA, UNITED REPUBLIC OF;TZ
|
||||
THAILAND;TH
|
||||
TIMOR-LESTE;TL
|
||||
TOGO;TG
|
||||
TOKELAU;TK
|
||||
TONGA;TO
|
||||
TRINIDAD AND TOBAGO;TT
|
||||
TUNISIA;TN
|
||||
TURKEY;TR
|
||||
TURKMENISTAN;TM
|
||||
TURKS AND CAICOS ISLANDS;TC
|
||||
TUVALU;TV
|
||||
UGANDA;UG
|
||||
UKRAINE;UA
|
||||
UNITED ARAB EMIRATES;AE
|
||||
UNITED KINGDOM;GB
|
||||
UNITED STATES;US
|
||||
UNITED STATES MINOR OUTLYING ISLANDS;UM
|
||||
URUGUAY;UY
|
||||
UZBEKISTAN;UZ
|
||||
VANUATU;VU
|
||||
VENEZUELA;VE
|
||||
VIET NAM;VN
|
||||
VIRGIN ISLANDS, BRITISH;VG
|
||||
VIRGIN ISLANDS, U.S.;VI
|
||||
WALLIS AND FUTUNA;WF
|
||||
WESTERN SAHARA;EH
|
||||
YEMEN;YE
|
||||
ZAMBIA;ZM
|
||||
ZIMBABWE;ZW
|
54
libs/Monkeys/Iterator.php
Normal file
54
libs/Monkeys/Iterator.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This iterator builds a collection filled with zeroes, except for the range it knows
|
||||
* the paginator will query it for.
|
||||
*/
|
||||
class Monkeys_Iterator implements Iterator, Countable
|
||||
{
|
||||
private $_numItems;
|
||||
private $_items;
|
||||
private $_index = 0;
|
||||
|
||||
public function __construct($items, $numItems, $recordsPerPage, $page)
|
||||
{
|
||||
if ($items) {
|
||||
$this->_items = array_fill(0, $numItems- 1, 0);
|
||||
} else {
|
||||
$this->_items = array();
|
||||
}
|
||||
|
||||
array_splice($this->_items, $recordsPerPage * ($page - 1), $recordsPerPage, $items);
|
||||
$this->_numItems = $numItems;
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
return $this->_items[$this->_index];
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return $this->_index;
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
$this->_index++;
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
$this->_index = 0;
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return isset($this->_items[$this->_index]);
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return $this->_numItems;
|
||||
}
|
||||
}
|
100
libs/Monkeys/Ldap.php
Normal file
100
libs/Monkeys/Ldap.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
class Monkeys_Ldap
|
||||
{
|
||||
private static $_instance;
|
||||
|
||||
private $_ldapConfig;
|
||||
|
||||
/**
|
||||
* Ldap link identifier
|
||||
*/
|
||||
private $_dp;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
$this->_ldapConfig = Zend_Registry::get('config')->ldap;
|
||||
|
||||
if (!$this->_dp= @ldap_connect($this->_ldapConfig->host)) {
|
||||
throw new Exception('Could not connect to LDAP server');
|
||||
}
|
||||
ldap_set_option($this->_dp, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
if (!@ldap_bind($this->_dp, $this->_ldapConfig->username, $this->_ldapConfig->password)) {
|
||||
throw new Exception('Could not bind to LDAP server: ' . ldap_error($this->_dp));
|
||||
}
|
||||
}
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if (!isset(self::$_instance)) {
|
||||
self::$_instance = new Monkeys_Ldap();
|
||||
}
|
||||
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
|
||||
public function get($dn)
|
||||
{
|
||||
if (!$resultId = @ldap_search($this->_dp, $dn, "(&(objectClass=*))")) {
|
||||
throw new Exception('Could not retrieve record to LDAP server (1): ' . ldap_error($this->_dp));
|
||||
}
|
||||
|
||||
if (!$result = @ldap_get_entries($this->_dp, $resultId)) {
|
||||
throw new Exception('Could not retrieve record to LDAP server (2): ' . ldap_error($this->_dp));
|
||||
}
|
||||
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* lastname (sn) is required for the "inetOrgPerson" schema
|
||||
*/
|
||||
public function add(Users_Model_User $user)
|
||||
{
|
||||
$dn = 'cn=' . $user->username . ',' . $this->_ldapConfig->baseDn;
|
||||
$info = array(
|
||||
'cn' => $user->username,
|
||||
'givenName' => $user->firstname,
|
||||
'sn' => $user->lastname,
|
||||
'mail' => $user->email,
|
||||
'userPassword' => $user->password,
|
||||
'objectclass' => 'inetOrgPerson',
|
||||
);
|
||||
if (!@ldap_add($this->_dp, $dn, $info) && ldap_error($this->_dp) != 'Success') {
|
||||
throw new Exception('Could not add record to LDAP server: ' . ldap_error($this->_dp));
|
||||
}
|
||||
}
|
||||
|
||||
public function modify(User $user)
|
||||
{
|
||||
$dn = 'cn=' . $user->username . ',' . $this->_ldapConfig->baseDn;
|
||||
$info = array(
|
||||
'cn' => $user->username,
|
||||
'givenName' => $user->firstname,
|
||||
'sn' => $user->lastname,
|
||||
'mail' => $user->email,
|
||||
'objectclass' => 'inetOrgPerson',
|
||||
);
|
||||
if (!@ldap_modify($this->_dp, $dn, $info) && ldap_error($this->_dp) != 'Success') {
|
||||
throw new Exception('Could not modify record in LDAP server: ' . ldap_error($this->_dp));
|
||||
}
|
||||
}
|
||||
|
||||
public function modifyUsername(User $user, $oldUsername)
|
||||
{
|
||||
$dn = 'cn=' . $oldUsername . ',' . $this->_ldapConfig->baseDn;
|
||||
$newRdn = 'cn=' . $user->username;
|
||||
if (!@ldap_rename($this->_dp, $dn, $newRdn, $this->_ldapConfig->baseDn, true) && ldap_error($this->_dp) != 'Success') {
|
||||
throw new Exception('Could not modify username in LDAP server: ' . ldap_error($this->_dp));
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($username)
|
||||
{
|
||||
$dn = "cn=$username," . $this->_ldapConfig->baseDn;
|
||||
if (!@ldap_delete($this->_dp, $dn) && ldap_error($this->_dp) != 'Success') {
|
||||
throw new Exception('Could not delete record from LDAP server: ' . ldap_error($this->_dp));
|
||||
}
|
||||
}
|
||||
}
|
21
libs/Monkeys/Lib.php
Normal file
21
libs/Monkeys/Lib.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
class Monkeys_Lib
|
||||
{
|
||||
/**
|
||||
* Converts the HTML BR tag into plain-text linebreaks
|
||||
*
|
||||
* Taken from comments on the nl2br function PHP's online manual.
|
||||
* "Since nl2br doesn't remove the line breaks when adding in the <br /> tags, it is necessary to strip those off before you convert all of the tags, otherwise you will get double spacing"
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
static function br2nl($str)
|
||||
{
|
||||
$str = preg_replace("/(\r\n|\n|\r)/", "", $str);
|
||||
return preg_replace('=<br */?>=i', "\n", $str);
|
||||
}
|
||||
}
|
89
libs/Monkeys/Lucene.php
Normal file
89
libs/Monkeys/Lucene.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @since Textroller 0.9
|
||||
* @package TextRoller
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Lucene
|
||||
{
|
||||
const LUCENE_DIR = '/lucene';
|
||||
|
||||
/**
|
||||
* @throws Zend_Search_Lucene_exception
|
||||
*/
|
||||
public static function getIndex()
|
||||
{
|
||||
try {
|
||||
$index = Zend_Search_Lucene::open(APP_DIR . self::LUCENE_DIR);
|
||||
} catch (Zend_Search_Lucene_Exception $e) {
|
||||
$index = Zend_Search_Lucene::create(APP_DIR . self::LUCENE_DIR);
|
||||
Zend_Registry::get('logger')->log('Created Lucene index file', Zend_Log::INFO);
|
||||
}
|
||||
|
||||
return $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Zend_Search_Lucene_exception
|
||||
* @return void
|
||||
*/
|
||||
public static function indexArticle(Model_Blog $blog, Zend_Db_Table_Rowset $tagsSet, $isNew)
|
||||
{
|
||||
if ($blog->draft || !$blog->hasBeenPublished()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tags = array();
|
||||
foreach ($tagsSet as $tag) {
|
||||
$tags[] = $tag->tag;
|
||||
}
|
||||
$tags = implode(' ', $tags);
|
||||
|
||||
$index = self::getIndex();
|
||||
|
||||
if (!$isNew) {
|
||||
$existingDocIds = $index->termDocs(new Zend_Search_Lucene_Index_Term($blog->id, 'blog_id'));
|
||||
if ($existingDocIds) {
|
||||
$index->delete($existingDocIds[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// I won't be using Zend_Search_Lucene_Document_HTML 'cause articles are not full HTML documents
|
||||
$doc = new Zend_Search_Lucene_Document();
|
||||
|
||||
$doc->addField(Zend_Search_Lucene_Field::Keyword('blog_id', $blog->id));
|
||||
|
||||
$doc->addField(Zend_Search_Lucene_Field::Text('title', $blog->title, 'utf-8'));
|
||||
$doc->addField(Zend_Search_Lucene_Field::Text('excerpt', $blog->excerpt, 'utf-8'));
|
||||
$doc->addField(Zend_Search_Lucene_Field::Unstored('tag', $tags, 'utf-8'));
|
||||
$doc->addField(Zend_Search_Lucene_Field::Unstored('contents', $blog->getContentWithoutTags(), 'utf-8'));
|
||||
$index->addDocument($doc);
|
||||
$index->commit();
|
||||
}
|
||||
|
||||
public static function unIndexArticle(Blog $blog)
|
||||
{
|
||||
try {
|
||||
$index = self::getIndex();
|
||||
} catch (Zend_Search_Lucene_Exception $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existingDocIds = $index->termDocs(new Zend_Search_Lucene_Index_Term($blog->id, 'blog_id'));
|
||||
|
||||
if ($existingDocIds) {
|
||||
$index->delete($existingDocIds[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function optimizeIndex()
|
||||
{
|
||||
$index = self::getIndex();
|
||||
$index->optimize();
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ class Monkeys_OpenId_Provider_Storage_Database extends Zend_OpenId_Provider_Stor
|
||||
{
|
||||
public function addAssociation($handle, $macFunc, $secret, $expires)
|
||||
{
|
||||
$associations = new Associations();
|
||||
$associations = new Model_Associations();
|
||||
$association = $associations->createRow();
|
||||
$association->handle = $handle;
|
||||
$association->macfunc = $macFunc;
|
||||
@ -26,7 +26,7 @@ class Monkeys_OpenId_Provider_Storage_Database extends Zend_OpenId_Provider_Stor
|
||||
|
||||
public function getAssociation($handle, &$macFunc, &$secret, &$expires)
|
||||
{
|
||||
$associations = new Associations();
|
||||
$associations = new Model_Associations();
|
||||
$association = $associations->getAssociationGivenHandle($handle);
|
||||
if (!$association) {
|
||||
return false;
|
||||
@ -52,7 +52,7 @@ class Monkeys_OpenId_Provider_Storage_Database extends Zend_OpenId_Provider_Stor
|
||||
|
||||
public function hasUser($id)
|
||||
{
|
||||
$users = new Users();
|
||||
$users = new Users_Model_Users();
|
||||
$user = $users->getUserWithOpenId($id);
|
||||
|
||||
return $user? true : false;
|
||||
@ -86,10 +86,10 @@ class Monkeys_OpenId_Provider_Storage_Database extends Zend_OpenId_Provider_Stor
|
||||
*/
|
||||
public function getTrustedSites($id)
|
||||
{
|
||||
$users = new Users();
|
||||
$users = new Users_Model_Users();
|
||||
$user = $users->getUserWithOpenId($id);
|
||||
|
||||
$sites = new Sites();
|
||||
$sites = new Model_Sites();
|
||||
|
||||
$trustedSites = array();
|
||||
foreach ($sites->getTrusted($user) as $site) {
|
||||
@ -109,10 +109,10 @@ class Monkeys_OpenId_Provider_Storage_Database extends Zend_OpenId_Provider_Stor
|
||||
*/
|
||||
public function addSite($id, $site, $trusted)
|
||||
{
|
||||
$users = new Users();
|
||||
$users = new Users_Model_Users();
|
||||
$user = $users->getUserWithOpenId($id);
|
||||
|
||||
$sites = new Sites();
|
||||
$sites = new Model_Sites();
|
||||
$sites->deleteForUserSite($user, $site);
|
||||
|
||||
if (!is_null($trusted)) {
|
||||
|
34
libs/Monkeys/Validate/Username.php
Normal file
34
libs/Monkeys/Validate/Username.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
/**
|
||||
* Validates URL element syntax to avoid encoding issues, according to rfc 1738, section 2.2
|
||||
*/
|
||||
class Monkeys_Validate_Username extends Zend_Validate_Abstract
|
||||
{
|
||||
const BAD = 'bad';
|
||||
|
||||
protected $_messageTemplates = array(
|
||||
self::BAD => 'Username can only contain US-ASCII alphanumeric characters, plus any of the symbols $-_.+!*\'(), and "'
|
||||
);
|
||||
|
||||
public function isValid($value, $context = null)
|
||||
{
|
||||
$this->_setValue($value);
|
||||
|
||||
if (preg_match('/^[A-Za-z\$-_.\+!\*\'\(\)",]+$/', $value)) {
|
||||
return true;
|
||||
} else {
|
||||
$this->_error(self::BAD);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
class Monkeys_View_Helper_FormDateSelects extends Zend_View_Helper_FormElement
|
||||
{
|
||||
private $_months = array(
|
||||
protected $_months = array(
|
||||
1 => 'January',
|
||||
2 => 'February',
|
||||
3 => 'March',
|
||||
@ -38,7 +38,7 @@ class Monkeys_View_Helper_FormDateSelects extends Zend_View_Helper_FormElement
|
||||
protected $_translator;
|
||||
|
||||
public function formDateSelects($name, $value = null, $attribs = null,
|
||||
$options = null, $listsep = "<br />\n")
|
||||
$options = null, $listsep = "<br />\n")
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
|
||||
extract($info); // name, id, value, attribs, options, listsep, disable
|
||||
@ -262,7 +262,7 @@ class Monkeys_View_Helper_FormDateSelects extends Zend_View_Helper_FormElement
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function _translationsHolder()
|
||||
protected function _translationsHolder()
|
||||
{
|
||||
translate('January');
|
||||
translate('February');
|
||||
|
254
libs/Monkeys/View/Helper/FormDateTimeSelects.php
Normal file
254
libs/Monkeys/View/Helper/FormDateTimeSelects.php
Normal file
@ -0,0 +1,254 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @since Textroller 0.9
|
||||
* @package TextRoller
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_View_Helper_FormDateTimeSelects extends Monkeys_View_Helper_FormDateSelects
|
||||
{
|
||||
public function formDateTimeSelects($name, $value = null, $attribs = null,
|
||||
$options = null, $listsep = "<br />\n")
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
|
||||
extract($info); // name, id, value, attribs, options, listsep, disable
|
||||
|
||||
// now start building the XHTML.
|
||||
$disabled = '';
|
||||
if (true === $disable) {
|
||||
$disabled = ' disabled="disabled"';
|
||||
}
|
||||
|
||||
$elementNamesArray = $this->getDayMonthYearTimeFieldNames($name);
|
||||
$valueDay = $valueMonth = $valueYear = $valueHour = $valueMinutes = $valueAmPm = null;
|
||||
|
||||
if ($value !== null)
|
||||
{
|
||||
$valueExploded = explode(' ', $value);
|
||||
|
||||
$dateValueExploded = explode('-', $valueExploded[0]);
|
||||
if (!isset($dateValueExploded[2])) {
|
||||
$value = null;
|
||||
} else {
|
||||
$valueDay = (int) $dateValueExploded[2];
|
||||
$valueMonth = (int) $dateValueExploded[1];
|
||||
$valueYear = (int) $dateValueExploded[0];
|
||||
}
|
||||
|
||||
$timeValueExploded = explode(':', $valueExploded[1]);
|
||||
$valueHour = $timeValueExploded[0];
|
||||
if ($valueHour > 12) {
|
||||
$valueHour -= 12;
|
||||
$valueAmPm = 'pm';
|
||||
} elseif ($valueHour == 0) {
|
||||
$valueHour = 12;
|
||||
$valueAmPm = 'am';
|
||||
} else {
|
||||
$valueAmPm = 'am';
|
||||
}
|
||||
$valueMinutes = (int) $timeValueExploded[1];
|
||||
}
|
||||
|
||||
// Build the surrounding day element first.
|
||||
$xhtml = '<select '
|
||||
. ' name="' . $this->view->escape($elementNamesArray['day']) . '"'
|
||||
. ' id="' . $this->view->escape($id . '_day') . '"'
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. ">\n ";
|
||||
|
||||
// build the list of options
|
||||
$list = array();
|
||||
if ($options['showEmpty'])
|
||||
{
|
||||
$list[] = '<option value="-"> </option>';
|
||||
}
|
||||
for ($i = 1; $i <= 31; $i++)
|
||||
{
|
||||
$list[] = '<option'
|
||||
. ' value="' . $i . '"'
|
||||
. ($valueDay === $i ? ' selected="selected"' : '')
|
||||
. '>' . $i . '';
|
||||
}
|
||||
|
||||
// add the options to the xhtml and close the select
|
||||
$xhtml .= implode("\n ", $list) . "\n</select>";
|
||||
|
||||
// Build the month next
|
||||
$xhtml .= ' <select '
|
||||
. ' name="' . $this->view->escape($elementNamesArray['month']) . '"'
|
||||
. ' id="' . $this->view->escape($id . '_month') . '"'
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. ">\n ";
|
||||
|
||||
// build the list of options
|
||||
$list = array();
|
||||
if ($options['showEmpty'])
|
||||
{
|
||||
$list[] = '<option value="-"> </option>';
|
||||
}
|
||||
for ($i = 1; $i <= 12; $i++)
|
||||
{
|
||||
$list[] = '<option'
|
||||
. ' value="' . $i . '"'
|
||||
. ($valueMonth === $i ? ' selected="selected"' : '')
|
||||
. '>' . $this->_translateValue($this->_months[$i]) . '';
|
||||
}
|
||||
|
||||
// add the options to the xhtml and close the select
|
||||
$xhtml .= implode("\n ", $list) . "\n</select>";
|
||||
|
||||
|
||||
// Build the years next
|
||||
$xhtml .= ' <select '
|
||||
. ' name="' . $this->view->escape($elementNamesArray['year']) . '"'
|
||||
. ' id="' . $this->view->escape($id . '_year') . '"'
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. ">\n ";
|
||||
|
||||
// build the list of options
|
||||
$list = array();
|
||||
if ($options['showEmpty'])
|
||||
{
|
||||
$list[] = '<option value="-"> </option>';
|
||||
}
|
||||
|
||||
|
||||
if ($options['reverseYears'])
|
||||
{
|
||||
for ($i = $options['endYear']; $i >= $options['startYear']; $i--)
|
||||
{
|
||||
$list[] = '<option '
|
||||
. ' value="' . $i . '"'
|
||||
. ($valueYear === $i ? ' selected="selected"' : '')
|
||||
. '>' . $i . '</option>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ($i = $options['startYear']; $i >= $options['endYear']; $i++)
|
||||
{
|
||||
$list[] = '<option '
|
||||
. ' value="' . $i . '"'
|
||||
. ($valueYear === $i ? ' selected="selected"' : '')
|
||||
. '>' . $i . '</option>';
|
||||
}
|
||||
}
|
||||
|
||||
// add the options to the xhtml and close the select
|
||||
$xhtml .= implode("\n ", $list) . "\n</select>";
|
||||
|
||||
// Build the hours next
|
||||
$xhtml .= ' <select '
|
||||
. ' name="' . $this->view->escape($elementNamesArray['hour']) . '"'
|
||||
. ' id="' . $this->view->escape($id . '_hour') . '"'
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. ">\n ";
|
||||
|
||||
$list = array();
|
||||
if ($options['showEmpty'])
|
||||
{
|
||||
$list[] = '<option value="-"> </option>';
|
||||
}
|
||||
for ($i = 1; $i <= 12; $i++)
|
||||
{
|
||||
$list[] = '<option'
|
||||
. ' value="' . $i . '"'
|
||||
. ($valueHour === $i ? ' selected="selected"' : '')
|
||||
. '>' . sprintf('%02u', $i) . '';
|
||||
}
|
||||
|
||||
// add the options to the xhtml and close the select
|
||||
$xhtml .= implode("\n ", $list) . "\n</select>";
|
||||
|
||||
// Build the minutes next
|
||||
$xhtml .= '<select '
|
||||
. ' name="' . $this->view->escape($elementNamesArray['minutes']) . '"'
|
||||
. ' id="' . $this->view->escape($id . '_minutes') . '"'
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. ">\n ";
|
||||
|
||||
$list = array();
|
||||
if ($options['showEmpty'])
|
||||
{
|
||||
$list[] = '<option value="-"> </option>';
|
||||
}
|
||||
for ($i = 0; $i <= 59; $i++)
|
||||
{
|
||||
$list[] = '<option'
|
||||
. ' value="' . $i . '"'
|
||||
. ($valueMinutes === $i ? ' selected="selected"' : '')
|
||||
. '>' . sprintf('%02u', $i) . '';
|
||||
}
|
||||
|
||||
// add the options to the xhtml and close the select
|
||||
$xhtml .= implode("\n ", $list) . "\n</select>";
|
||||
|
||||
|
||||
// Build the ampm next
|
||||
$xhtml .= '<select '
|
||||
. ' name="' . $this->view->escape($elementNamesArray['ampm']) . '"'
|
||||
. ' id="' . $this->view->escape($id . '_ampm') . '"'
|
||||
. $disabled
|
||||
. $this->_htmlAttribs($attribs)
|
||||
. ">\n ";
|
||||
|
||||
$list = array();
|
||||
if ($options['showEmpty'])
|
||||
{
|
||||
$list[] = '<option value="-"> </option>';
|
||||
}
|
||||
$list[] = '<option value="am" ' . ($valueAmPm == 'am' ? 'selected="selected"' : '') . '>am';
|
||||
$list[] = '<option value="pm" ' . ($valueAmPm == 'pm' ? 'selected="selected"' : '') . '>pm';
|
||||
|
||||
// add the options to the xhtml and close the select
|
||||
$xhtml .= implode("\n ", $list) . "\n</select>";
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
|
||||
protected function getDayMonthYearTimeFieldNames($value)
|
||||
{
|
||||
if (empty($value) || !is_string($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$ret = array(
|
||||
'day' => $value . '_day',
|
||||
'month' => $value . '_month',
|
||||
'year' => $value . '_year',
|
||||
'hour' => $value . '_hour',
|
||||
'minutes' => $value . '_minutes',
|
||||
'ampm' => $value . '_ampm',
|
||||
);
|
||||
|
||||
if (strstr($value, '['))
|
||||
{
|
||||
$endPos = strlen($value) - 1;
|
||||
if (']' != $value[$endPos]) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$start = strrpos($value, '[') + 1;
|
||||
$name = substr($value, $start, $endPos - $start);
|
||||
$arrayName = substr($value, 0, $start-1);
|
||||
$ret = array(
|
||||
'day' => $arrayName . '[' . $name . '_day' . ']',
|
||||
'month' => $arrayName . '[' . $name . '_month' . ']',
|
||||
'year' => $arrayName . '[' . $name . '_year' . ']',
|
||||
'hour' => $arrayName . '[' . $name . '_hour' . ']',
|
||||
'minutes' => $arrayName . '[' . $name . '_minutes' . ']',
|
||||
'ampm' => $arrayName . '[' . $name . '_ampm' . ']',
|
||||
);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
25
libs/Monkeys/View/Helper/FormRichtextarea.php
Normal file
25
libs/Monkeys/View/Helper/FormRichtextarea.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
require_once WEB_DIR . '/fckeditor/fckeditor.php';
|
||||
|
||||
class Monkeys_View_Helper_FormRichtextarea extends Zend_View_Helper_FormElement
|
||||
{
|
||||
public function formRichtextarea($name, $value = null, $attribs = null, $options = null, $listSep = null)
|
||||
{
|
||||
$info = $this->_getInfo($name, $value, $attribs);
|
||||
extract($info); // name, value, attribs, options, listsep, disable
|
||||
|
||||
$fck = new FCKEditor($this->view->escape($name));
|
||||
$fck->BasePath = $this->view->base . '/fckeditor/';
|
||||
$fck->Value = $value;
|
||||
if (isset($attribs['width'])) {
|
||||
$fck->Width = $attribs['width'];
|
||||
} else {
|
||||
$fck->Width = '890';
|
||||
}
|
||||
$fck->Height = '600';
|
||||
$fck->Config['CustomConfigurationsPath'] = '../../javascript/fck_custom_config.js';
|
||||
$fck->ToolbarSet = 'MonkeysToolbar';
|
||||
return $fck->CreateHtml();
|
||||
}
|
||||
}
|
@ -1,14 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_View_Helper_GetBase
|
||||
{
|
||||
public function getBase()
|
||||
|
1637
libs/Monkeys/tests/sampletext.txt
Normal file
1637
libs/Monkeys/tests/sampletext.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -175626,6 +175626,7 @@ scytopetalaceous
|
||||
Scytopetalum
|
||||
sdeath
|
||||
sdrucciola
|
||||
se
|
||||
sea
|
||||
seabeach
|
||||
seabeard
|
||||
|
Reference in New Issue
Block a user