import v2.0.0.0_RC3 | 2012-07-01
https://github.com/lucanos/CommunityID -> http://www.itadmins.net/archives/357
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
@ -11,16 +11,33 @@
|
||||
|
||||
abstract class CommunityID_Controller_Action extends Monkeys_Controller_Action
|
||||
{
|
||||
/**
|
||||
* flag to avoid duplicating the metas by the various controllers
|
||||
* that can make a single page
|
||||
*/
|
||||
private static $_metasRendered = false;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
if (!self::$_metasRendered) {
|
||||
if (@$this->_config->metadata->description) {
|
||||
$this->view->headMeta()->appendName('description', $this->_config->metadata->description);
|
||||
}
|
||||
if (@$this->_config->metadata->keywords) {
|
||||
$this->view->headMeta()->appendName('keywords', $this->_config->metadata->keywords);
|
||||
}
|
||||
self::$_metasRendered = true;
|
||||
}
|
||||
|
||||
Zend_Controller_Action_HelperBroker::addPrefix('CommunityID_Controller_Action_Helper');
|
||||
}
|
||||
|
||||
protected function _setBase()
|
||||
{
|
||||
if ($this->_config->subdomain->enabled) {
|
||||
$protocol = $this->getProtocol();
|
||||
$protocol = self::getProtocol();
|
||||
|
||||
$this->view->base = "$protocol://"
|
||||
. ($this->_config->subdomain->use_www? 'www.' : '')
|
||||
@ -45,11 +62,18 @@ abstract class CommunityID_Controller_Action extends Monkeys_Controller_Action
|
||||
$this->targetUser = $users->createRow();
|
||||
} else {
|
||||
if ($userId != $this->user->id && $this->user->role != Users_Model_User::ROLE_ADMIN) {
|
||||
$this->_helper->FlashMessenger->addMessage('Error: Invalid user id');
|
||||
$this->_helper->FlashMessenger->addMessage($this->view->translate('Error: Invalid user id'));
|
||||
$this->_redirect('profile/edit');
|
||||
}
|
||||
|
||||
$users = new Users_Model_Users();
|
||||
$this->targetUser = $users->getRowInstance($userId);
|
||||
|
||||
if ($this->_config->ldap->enabled) {
|
||||
$ldap = Monkeys_Ldap::getInstance();
|
||||
$ldapUserData = $ldap->get("cn={$this->targetUser->username},{$this->_config->ldap->baseDn}");
|
||||
$this->targetUser->overrideWithLdapData($ldapUserData, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,9 +83,60 @@ abstract class CommunityID_Controller_Action extends Monkeys_Controller_Action
|
||||
protected function _redirectToNormalConnection()
|
||||
{
|
||||
if ($this->_config->SSL->enable_mixed_mode) {
|
||||
$this->_redirect('http://' . $_SERVER['HTTP_HOST'] . $this->view->base);
|
||||
if ($this->_config->subdomain->enabled) {
|
||||
// in this case $this->view->base contains the full URL, so we just gotta replace the protocol
|
||||
$this->_redirect('http' . substr($this->view->base, strpos($this->view->base, '://')));
|
||||
} else {
|
||||
$this->_redirect('http://' . $_SERVER['HTTP_HOST'] . $this->view->base);
|
||||
}
|
||||
} else {
|
||||
$this->_redirect('');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Circumvent PHP's automatic replacement of dots by underscore in var names in $_GET and $_POST
|
||||
*/
|
||||
protected function _queryString()
|
||||
{
|
||||
$unfilteredVars = array_merge($_GET, $_POST);
|
||||
$varsTemp = array();
|
||||
$vars = array();
|
||||
$extensions = array();
|
||||
foreach ($unfilteredVars as $key => $value) {
|
||||
if ($key == 'password') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (substr($key, 0, 10) == 'openid_ns_') {
|
||||
$extensions[] = substr($key, 10);
|
||||
$varsTemp[str_replace('openid_ns_', 'openid.ns.', $key)] = $value;
|
||||
} else {
|
||||
$varsTemp[str_replace('openid_', 'openid.', $key)] = $value;
|
||||
}
|
||||
}
|
||||
foreach ($extensions as $extension) {
|
||||
foreach ($varsTemp as $key => $value) {
|
||||
if (strpos($key, "openid.$extension") === 0) {
|
||||
$prefix = "openid.$extension.";
|
||||
$key = $prefix . substr($key, strlen($prefix));
|
||||
}
|
||||
$vars[$key] = $value;
|
||||
}
|
||||
}
|
||||
if (!$extensions) {
|
||||
$vars = $varsTemp;
|
||||
}
|
||||
|
||||
return '?' . http_build_query($vars);
|
||||
}
|
||||
|
||||
protected function _getOpenIdProvider()
|
||||
{
|
||||
$connection = new CommunityID_OpenId_DatabaseConnection(Zend_Registry::get('db'));
|
||||
$store = new Auth_OpenID_MySQLStore($connection, 'associations', 'nonces');
|
||||
$server = new Auth_OpenID_Server($store, $this->_helper->ProviderUrl($this->_config));
|
||||
|
||||
return $server;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
@ -20,7 +20,7 @@ class CommunityID_Controller_Action_Helper_ProviderUrl
|
||||
$currentUrl = urldecode(Zend_OpenId::selfURL());
|
||||
|
||||
if ($config->subdomain->enabled) {
|
||||
$protocol = $this->_actionController->getProtocol();
|
||||
$protocol = Monkeys_Controller_Action::getProtocol();
|
||||
preg_match('#(.*)\.'.$config->subdomain->hostname.'#', $currentUrl, $matches);
|
||||
|
||||
return "$protocol://"
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
|
37
libs/CommunityID/Resources.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
class CommunityID_Resources
|
||||
{
|
||||
public static function getResourcePath($fileName)
|
||||
{
|
||||
$locale = Zend_Registry::get('Zend_Locale');
|
||||
$localeElements = explode('_', $locale);
|
||||
|
||||
$template = Zend_Registry::get('config')->environment->template;
|
||||
if ($template == 'default') {
|
||||
$template = '';
|
||||
} else {
|
||||
$template = "_$template";
|
||||
}
|
||||
|
||||
if (file_exists(APP_DIR . "/resources$template/$locale/$fileName")) {
|
||||
$file = APP_DIR . "/resources$template/$locale/$fileName";
|
||||
} else if (count($localeElements == 2)
|
||||
&& file_exists(APP_DIR . "/resources$template/{$localeElements[0]}/$fileName")) {
|
||||
$file = APP_DIR . "/resources$template/{$localeElements[0]}/$fileName";
|
||||
} else if (file_exists(APP_DIR . "/resources$template/en/$fileName")){
|
||||
$file = APP_DIR . "/resources$template/en/$fileName";
|
||||
} else if (file_exists(APP_DIR . "/resources/$locale/$fileName")) {
|
||||
$file = APP_DIR . "/resources/$locale/$fileName";
|
||||
} else if (count($localeElements == 2)
|
||||
&& file_exists(APP_DIR . "/resources/{$localeElements[0]}/$fileName")) {
|
||||
$file = APP_DIR . "/resources/{$localeElements[0]}/$fileName";
|
||||
} else if (file_exists(APP_DIR . "/resources/en/$fileName")){
|
||||
$file = APP_DIR . "/resources/en/$fileName";
|
||||
} else {
|
||||
throw new Exception("Resource $fileName could not be found");
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
}
|
31
libs/CommunityID/UpgradeStage.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 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 CommunityID_UpgradeStage
|
||||
{
|
||||
protected $_view;
|
||||
protected $_user;
|
||||
protected $_db;
|
||||
|
||||
public function __construct(Users_Model_User $user, Zend_Db_Adapter_Abstract $db, Zend_View $view)
|
||||
{
|
||||
$this->_user = $user;
|
||||
$this->_view = $view;
|
||||
$this->_db = $db;
|
||||
}
|
||||
|
||||
public function requirements()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
abstract function proceed();
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
Modifications to the jpgraph lib:
|
||||
- this is just the src directory
|
||||
- copied the README, VERSION and QPL.txt files
|
||||
- copied the README and VERSION files
|
||||
- removed the Examples dir
|
||||
- removed the flags* files
|
||||
- added fonts path in file jpg-config.inc.php, line 43
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @copyright Copyright (C) 2005-2010 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
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?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
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Application_Module_Autoloader extends Zend_Application_Module_Autoloader
|
||||
{
|
||||
public function __construct($options)
|
||||
|
92
libs/Monkeys/Auth/Adapter/Yubikey.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
class Monkeys_Auth_Adapter_Yubikey implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
const TOKEN_SIZE = 32;
|
||||
const MIN_IDENTITY_SIZE = 12;
|
||||
|
||||
protected $_options = null;
|
||||
protected $_identity = null;
|
||||
protected $_password = null;
|
||||
|
||||
public function __construct(array $options = array(), $identity= null, $password = null)
|
||||
{
|
||||
$this->setOptions($options);
|
||||
if ($identity !== null) {
|
||||
$this->setIdentity($identity);
|
||||
}
|
||||
if ($password !== null) {
|
||||
$this->setPassword($password);
|
||||
}
|
||||
}
|
||||
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->_options = is_array($options) ? $options : array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->_options;
|
||||
}
|
||||
|
||||
public function getIdentity()
|
||||
{
|
||||
return $this->_identity;
|
||||
}
|
||||
|
||||
public function setIdentity($identity)
|
||||
{
|
||||
$this->_identity = (string) $identity;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->_password;
|
||||
}
|
||||
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->_password = (string) $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCredential($credential)
|
||||
{
|
||||
return $this->setPassword($credential);
|
||||
}
|
||||
|
||||
public function authenticate()
|
||||
{
|
||||
if (strlen ($this->_password) < self::TOKEN_SIZE + self::MIN_IDENTITY_SIZE) {
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
|
||||
$this->_identity,
|
||||
array('Provided Yubikey is too short')
|
||||
);
|
||||
}
|
||||
|
||||
$identity = substr ($this->_password, 0, strlen ($this->_password) - self::TOKEN_SIZE);
|
||||
|
||||
$this->_options['yubiClient'] = new Yubico_Auth(
|
||||
$this->_options['api_id'],
|
||||
$this->_options['api_key']
|
||||
);
|
||||
|
||||
try {
|
||||
$auth = $this->_options['yubiClient']->verify($this->_password);
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::SUCCESS,
|
||||
$this->_identity
|
||||
);
|
||||
} catch (Zend_Exception $e) {
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
|
||||
$this->_identity,
|
||||
array($e->getMessage(), 'Yubico response: ' . $this->_options['yubiClient']->getLastResponse())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
5
libs/Monkeys/BadUrlException.php
Executable file → Normal file
@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @copyright Copyright (C) 2005-2010 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
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?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
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
20
libs/Monkeys/Controller/Action.php
Executable file → Normal file
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
{
|
||||
/**
|
||||
@ -16,6 +24,7 @@ abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
|
||||
public function init()
|
||||
{
|
||||
Zend_Registry::get('logger')->log('Route used: ' . Application::$front->getRouter()->getCurrentRouteName(), Zend_Log::DEBUG);
|
||||
$this->_config = Zend_Registry::get('config');
|
||||
$this->_settings = new Model_Settings();
|
||||
|
||||
@ -43,7 +52,9 @@ abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
|
||||
$this->view->addHelperPath('libs/Monkeys/View/Helper', 'Monkeys_View_Helper');
|
||||
$this->view->setUseStreamWrapper(true);
|
||||
$this->_setScriptPaths();
|
||||
$this->_addCustomTemplatePath();
|
||||
$this->view->addBasePath(APP_DIR . '/views');
|
||||
$this->_addCustomTemplatePath();
|
||||
$this->_setBase();
|
||||
$this->view->numCols = $this->_numCols;
|
||||
|
||||
@ -59,6 +70,8 @@ abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
$this->view->nextAction = '';
|
||||
}
|
||||
|
||||
$this->view->messages = $this->_helper->FlashMessenger->getMessages();
|
||||
|
||||
if ($this->getRequest()->isXmlHttpRequest()) {
|
||||
$slowdown = $this->_config->environment->ajax_slowdown;
|
||||
if ($slowdown > 0) {
|
||||
@ -67,7 +80,6 @@ abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
$this->_helper->layout->disableLayout();
|
||||
} else {
|
||||
$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.7.0/build/'
|
||||
@ -82,7 +94,7 @@ abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
$this->view->title = $this->_title;
|
||||
}
|
||||
|
||||
private function _setScriptPaths()
|
||||
private function _addCustomTemplatePath()
|
||||
{
|
||||
if (($template = $this->_config->environment->template) == 'default') {
|
||||
return;
|
||||
@ -149,7 +161,7 @@ abstract class Monkeys_Controller_Action extends Zend_Controller_Action
|
||||
return parent::_redirect($url, $options);
|
||||
}
|
||||
|
||||
public function getProtocol()
|
||||
public static function getProtocol()
|
||||
{
|
||||
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
|
||||
return 'https';
|
||||
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
abstract class Monkeys_Controller_Error extends Monkeys_Controller_Action
|
||||
{
|
||||
protected $_numCols = 1;
|
||||
@ -24,11 +32,11 @@ abstract class Monkeys_Controller_Error extends Monkeys_Controller_Action
|
||||
case 'Monkeys_BadUrlException';
|
||||
$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
|
||||
|
||||
$this->view->message = 'The URL you entered is incorrect. Please correct and try again.';
|
||||
$this->view->message = $this->_getTranslationForException($exceptionClass);
|
||||
break;
|
||||
case 'Monkeys_AccessDeniedException';
|
||||
$this->getResponse()->setRawHeader('HTTP/1.1 401 Unauthorized');
|
||||
$this->view->message = 'Access Denied - Maybe your session has expired? Try logging-in again.';
|
||||
$this->view->message = $this->_getTranslationForException($exceptionClass);
|
||||
break;
|
||||
default:
|
||||
$this->view->message = get_class($errors->exception) . '<br />' . $errors->exception->getMessage();
|
||||
@ -37,7 +45,8 @@ abstract class Monkeys_Controller_Error extends Monkeys_Controller_Action
|
||||
} else if ($this->_config->email->adminemail) {
|
||||
$mail = self::getMail($errors->exception, $this->user, $errors);
|
||||
$mail->send();
|
||||
$this->view->message .= '<br />The system administrator has been notified.';
|
||||
$this->view->message .= "<br />\n";
|
||||
$this->view->message .= 'The system administrator has been notified.';
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -110,4 +119,23 @@ EOD;
|
||||
protected function _validateTargetUser()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns translation for an exception message
|
||||
*
|
||||
* Override using your translation engine.
|
||||
*/
|
||||
protected function _getTranslationForException($ex)
|
||||
{
|
||||
switch ($ex) {
|
||||
case 'Monkeys_BadUrlException':
|
||||
return 'The URL you entered is incorrect. Please correct and try again.';
|
||||
break;
|
||||
case 'Monkeys_AccessDeniedException':
|
||||
return 'Access Denied - Maybe your session has expired? Try logging-in again.';
|
||||
break;
|
||||
default:
|
||||
return $ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
libs/Monkeys/Controller/Plugin/Auth.php
Executable file → Normal file
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
private $_acl;
|
||||
@ -49,18 +57,18 @@ class Monkeys_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
|
||||
$resource = $request->getModuleName() . '_' . $request->getControllerName();
|
||||
|
||||
if (!$this->_acl->has($resource)) {
|
||||
//echo "role: " . $user->role . " - resource: $resource - privilege: " . $request->getActionName() . "<br>\n";
|
||||
//echo "role: " . $user->role . " - resource: $resource - privilege: " . $request->getActionName() . "<br>\n";exit;
|
||||
throw new Monkeys_BadUrlException($this->getRequest()->getRequestUri());
|
||||
}
|
||||
|
||||
// if an admin is not allowed for this action, then the action doesn't exist
|
||||
if (!$this->_acl->isAllowed(Users_Model_User::ROLE_ADMIN, $resource, $request->getActionName())) {
|
||||
//echo "role: " . $user->role . " - resource: $resource - privilege: " . $request->getActionName() . "<br>\n";
|
||||
//echo "role: " . $user->role . " - resource: $resource - privilege: " . $request->getActionName() . "<br>\n";exit;
|
||||
throw new Monkeys_BadUrlException($this->getRequest()->getRequestUri());
|
||||
}
|
||||
|
||||
if (!$this->_acl->isAllowed($user->role, $resource, $request->getActionName())) {
|
||||
//echo "role: " . $user->role . " - resource: $resource - privilege: " . $request->getActionName() . "<br>\n";
|
||||
//echo "role: " . $user->role . " - resource: $resource - privilege: " . $request->getActionName() . "<br>\n";exit;
|
||||
throw new Monkeys_AccessDeniedException();
|
||||
}
|
||||
}
|
||||
|
8
libs/Monkeys/Db/Profiler.php
Executable file → Normal file
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Db_Profiler extends Zend_Db_Profiler
|
||||
{
|
||||
public function Monkeys_Db_Profiler()
|
||||
|
20
libs/Monkeys/Db/Table/Gateway.php
Executable file → Normal file
@ -1,9 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
abstract class Monkeys_Db_Table_Gateway extends Zend_Db_Table_Abstract
|
||||
{
|
||||
const ASC = 'ASC';
|
||||
const DESC = 'DESC';
|
||||
|
||||
public function getRowInstance($id)
|
||||
{
|
||||
return $this->fetchRow($this->select()->where('id = ?', $id));
|
||||
return $this->find($id)->current();
|
||||
}
|
||||
|
||||
public function getRandomRowInstance(Projects_Model_Project $project)
|
||||
{
|
||||
$select = $this->select()->where('project_id=?', $project->id)->order(new Zend_Db_Expr('RAND()'));
|
||||
|
||||
return $this->fetchRow($select);
|
||||
}
|
||||
}
|
||||
|
234936
libs/Monkeys/Dictionaries/english.txt
Normal file
@ -1,4 +1,12 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_DuplicateException extends Zend_Exception {}
|
||||
|
||||
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
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
|
||||
{
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?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
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Form_Element_Checkbox extends Zend_Form_Element_Checkbox
|
||||
{
|
||||
private $_decorator;
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?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
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @copyright Copyright (C) 2005-2010 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
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @copyright Copyright (C) 2005-2010 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
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Form_Element_File extends Zend_Form_Element_File
|
||||
{
|
||||
private $_decorator;
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?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
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Form_Element_Password extends Zend_Form_Element_Password
|
||||
{
|
||||
private $_decorator;
|
||||
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Form_Element_Radio extends Zend_Form_Element_Radio
|
||||
{
|
||||
private $_decorator;
|
||||
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Form_Element_Richtextarea extends Zend_Form_Element_Xhtml
|
||||
{
|
||||
public $helper = 'formRichtextarea';
|
||||
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Form_Element_Select extends Zend_Form_Element_Select
|
||||
{
|
||||
private $_decorator;
|
||||
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Form_Element_Text extends Zend_Form_Element_Text
|
||||
{
|
||||
private $_decorator;
|
||||
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Form_Element_Textarea extends Zend_Form_Element_Textarea
|
||||
{
|
||||
private $_decorator;
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?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
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
11
libs/Monkeys/InvalidTypeException.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_InvalidTypeException extends Zend_Exception {}
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
/**
|
||||
* This iterator builds a collection filled with zeroes, except for the range it knows
|
||||
* the paginator will query it for.
|
||||
@ -12,7 +20,7 @@ class Monkeys_Iterator implements Iterator, Countable
|
||||
|
||||
public function __construct($items, $numItems, $recordsPerPage, $page)
|
||||
{
|
||||
if ($items) {
|
||||
if ($items && $numItems > 1) {
|
||||
$this->_items = array_fill(0, $numItems- 1, 0);
|
||||
} else {
|
||||
$this->_items = array();
|
||||
|
@ -1,7 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Ldap
|
||||
{
|
||||
const EXCEPTION_SEARCH = 1;
|
||||
const EXCEPTION_GET_ENTRIES = 2;
|
||||
|
||||
private static $_instance;
|
||||
|
||||
private $_ldapConfig;
|
||||
@ -11,6 +22,8 @@ class Monkeys_Ldap
|
||||
*/
|
||||
private $_dp;
|
||||
|
||||
private $_slappasswd = '/usr/sbin/slappasswd';
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
$this->_ldapConfig = Zend_Registry::get('config')->ldap;
|
||||
@ -37,16 +50,48 @@ class Monkeys_Ldap
|
||||
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));
|
||||
throw new Exception('Could not retrieve record from LDAP server (' . self::EXCEPTION_SEARCH . '): '
|
||||
. ldap_error($this->_dp), self::EXCEPTION_SEARCH);
|
||||
}
|
||||
|
||||
if (!$result = @ldap_get_entries($this->_dp, $resultId)) {
|
||||
throw new Exception('Could not retrieve record to LDAP server (2): ' . ldap_error($this->_dp));
|
||||
throw new Exception('Could not retrieve record from LDAP server (' . self::EXCEPTION_GET_ENTRIES . '): '
|
||||
. ldap_error($this->_dp), self::EXCEPTION_GET_ENTRIES);
|
||||
}
|
||||
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
public function search($baseDn, $field, $value)
|
||||
{
|
||||
if (!$resultId = @ldap_search($this->_dp, $baseDn, "(&(objectClass=*)($field=$value))")) {
|
||||
throw new Exception('Could not retrieve record from LDAP server (' . self::EXCEPTION_SEARCH . '): '
|
||||
. ldap_error($this->_dp), self::EXCEPTION_SEARCH);
|
||||
}
|
||||
|
||||
if (!$result = @ldap_get_entries($this->_dp, $resultId)) {
|
||||
throw new Exception('Could not retrieve record from LDAP server (' . self::EXCEPTION_GET_ENTRIES . '): '
|
||||
. ldap_error($this->_dp), self::EXCEPTION_GET_ENTRIES);
|
||||
}
|
||||
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
public function getAll($baseDn)
|
||||
{
|
||||
if (!$resultId = @ldap_search($this->_dp, $baseDn, "(&(objectClass=*))")) {
|
||||
throw new Exception('Could not retrieve record from LDAP server (' . self::EXCEPTION_SEARCH . '): '
|
||||
. ldap_error($this->_dp), self::EXCEPTION_SEARCH);
|
||||
}
|
||||
|
||||
if (!$result = @ldap_get_entries($this->_dp, $resultId)) {
|
||||
throw new Exception('Could not retrieve record from LDAP server (' . self::EXCEPTION_GET_ENTRIES . '): '
|
||||
. ldap_error($this->_dp), self::EXCEPTION_GET_ENTRIES);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* lastname (sn) is required for the "inetOrgPerson" schema
|
||||
*/
|
||||
@ -58,7 +103,7 @@ class Monkeys_Ldap
|
||||
'givenName' => $user->firstname,
|
||||
'sn' => $user->lastname,
|
||||
'mail' => $user->email,
|
||||
'userPassword' => $user->password,
|
||||
'userPassword' => $this->_hashPassword($user->password),
|
||||
'objectclass' => 'inetOrgPerson',
|
||||
);
|
||||
if (!@ldap_add($this->_dp, $dn, $info) && ldap_error($this->_dp) != 'Success') {
|
||||
@ -66,7 +111,7 @@ class Monkeys_Ldap
|
||||
}
|
||||
}
|
||||
|
||||
public function modify(User $user)
|
||||
public function modify(Users_Model_User $user, $newPassword = false)
|
||||
{
|
||||
$dn = 'cn=' . $user->username . ',' . $this->_ldapConfig->baseDn;
|
||||
$info = array(
|
||||
@ -74,14 +119,16 @@ class Monkeys_Ldap
|
||||
'givenName' => $user->firstname,
|
||||
'sn' => $user->lastname,
|
||||
'mail' => $user->email,
|
||||
'objectclass' => 'inetOrgPerson',
|
||||
);
|
||||
if ($newPassword) {
|
||||
$info['userPassword'] = $this->_hashPassword($newPassword);
|
||||
}
|
||||
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)
|
||||
public function modifyUsername(Users_Model_User $user, $oldUsername)
|
||||
{
|
||||
$dn = 'cn=' . $oldUsername . ',' . $this->_ldapConfig->baseDn;
|
||||
$newRdn = 'cn=' . $user->username;
|
||||
@ -90,11 +137,30 @@ class Monkeys_Ldap
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($username)
|
||||
public function delete(Users_Model_User $user)
|
||||
{
|
||||
$dn = "cn=$username," . $this->_ldapConfig->baseDn;
|
||||
$dn = "cn={$user->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));
|
||||
}
|
||||
}
|
||||
|
||||
private function _hashPassword($password)
|
||||
{
|
||||
if ($algorithm = $this->_ldapConfig->passwordHashing) {
|
||||
if (!@is_executable($this->_slappasswd)) {
|
||||
throw new Exception($this->_slappasswd . ' doesn\'t exist, or is not executable.');
|
||||
}
|
||||
|
||||
$trash = array();
|
||||
$password = escapeshellarg($password);
|
||||
if (!$returnVar = @exec("{$this->_slappasswd} -h " . '{' . $algorithm . '}' . " -s $password")) {
|
||||
throw new Exception("There was a problem executing {$this->_slappasswd}");
|
||||
}
|
||||
|
||||
$password = $returnVar;
|
||||
}
|
||||
|
||||
return $password;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Lib
|
||||
{
|
||||
/**
|
||||
|
@ -1,84 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @copyright Copyright (C) 2005-2010 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
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Lucene
|
||||
abstract class Monkeys_Lucene
|
||||
{
|
||||
const LUCENE_DIR = '/lucene';
|
||||
|
||||
private static $_index;
|
||||
|
||||
/**
|
||||
* @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]);
|
||||
if (!@self::$_index) {
|
||||
try {
|
||||
self::$_index = Zend_Search_Lucene::open(APP_DIR . self::LUCENE_DIR);
|
||||
} catch (Zend_Search_Lucene_Exception $e) {
|
||||
self::$_index = Zend_Search_Lucene::create(APP_DIR . self::LUCENE_DIR);
|
||||
Zend_Registry::get('logger')->log('Created Lucene index file', Zend_Log::INFO);
|
||||
}
|
||||
}
|
||||
|
||||
// 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]);
|
||||
}
|
||||
return self::$_index;
|
||||
}
|
||||
|
||||
public static function optimizeIndex()
|
||||
@ -86,4 +36,59 @@ class Monkeys_Lucene
|
||||
$index = self::getIndex();
|
||||
$index->optimize();
|
||||
}
|
||||
|
||||
public static function checkPcreUtf8Support()
|
||||
{
|
||||
if (@preg_match('/\pL/u', 'a') == 1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function clearIndex()
|
||||
{
|
||||
// need to remove the locks, otherwise error under windows
|
||||
self::getIndex()->removeReference();
|
||||
self::$_index = null;
|
||||
|
||||
self::_rmdirr(APP_DIR . self::LUCENE_DIR);
|
||||
}
|
||||
|
||||
/** * Delete a file, or a folder and its contents
|
||||
*
|
||||
* @author Aidan Lister <aidan@php.net>
|
||||
* @version 1.0.1
|
||||
* @param string $dirname Directory to delete
|
||||
* @return bool Returns TRUE on success, FALSE on failure
|
||||
*/
|
||||
private static function _rmdirr($dirname)
|
||||
{
|
||||
// Sanity check
|
||||
if (!file_exists($dirname)) {
|
||||
return false;
|
||||
}
|
||||
// Simple delete for a file
|
||||
if (is_file($dirname)) {
|
||||
return unlink($dirname);
|
||||
}
|
||||
// Loop through the folder
|
||||
$dir = dir($dirname);
|
||||
while (false !== $entry = $dir->read()) {
|
||||
// Skip pointers and dot directories
|
||||
if (substr($entry, 0, 1) == '.') {
|
||||
continue;
|
||||
}
|
||||
// Deep delete directories
|
||||
if (is_dir("$dirname/$entry")) {
|
||||
self::_rmdirr("$dirname/$entry");
|
||||
} else {
|
||||
unlink("$dirname/$entry");
|
||||
}
|
||||
}
|
||||
// Clean up
|
||||
$dir->close();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
14
libs/Monkeys/Model/Identifiable.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
interface Monkeys_Model_Identifiable
|
||||
{
|
||||
public function getItemId();
|
||||
}
|
20
libs/Monkeys/Model/Indexable.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
interface Monkeys_Model_Indexable
|
||||
{
|
||||
public function getProjectId();
|
||||
public function getExcerpt();
|
||||
public function getContentWithoutTags();
|
||||
public function isPublished();
|
||||
public function isDraft();
|
||||
public function getTitle();
|
||||
public function getType();
|
||||
}
|
13
libs/Monkeys/Model/Relationable.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
interface Monkeys_Model_Relationable
|
||||
{
|
||||
}
|
13
libs/Monkeys/Model/Taggable.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
interface Monkeys_Model_Taggable extends Monkeys_Model_Identifiable
|
||||
{
|
||||
}
|
844
libs/Monkeys/Translate/Adapter/Gettext.php
Normal file
@ -0,0 +1,844 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Keyboard Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class' only purpose is to backport change r7813 from ZF trunk code,
|
||||
* which fixes the directory scan on following smaller entries (pt_BR wasn't working, for example)
|
||||
*/
|
||||
class Monkeys_Translate_Adapter_Gettext extends Zend_Translate_Adapter
|
||||
{
|
||||
// THIS IS THE COPY OF THE ADAPTER ABSTRACT CLASS, WITH THE BACKPORTED addTranslation() METHOD
|
||||
|
||||
/**
|
||||
* Shows if locale detection is in automatic level
|
||||
* @var boolean
|
||||
*/
|
||||
private $_automatic = true;
|
||||
|
||||
/**
|
||||
* Internal cache for all adapters
|
||||
* @var Zend_Cache_Core
|
||||
*/
|
||||
protected static $_cache = null;
|
||||
|
||||
/**
|
||||
* Scans for the locale within the name of the directory
|
||||
* @constant integer
|
||||
*/
|
||||
const LOCALE_DIRECTORY = 'directory';
|
||||
|
||||
/**
|
||||
* Scans for the locale within the name of the file
|
||||
* @constant integer
|
||||
*/
|
||||
const LOCALE_FILENAME = 'filename';
|
||||
|
||||
/**
|
||||
* Array with all options, each adapter can have own additional options
|
||||
* 'clear' => clears already loaded data when adding new files
|
||||
* 'scan' => searches for translation files using the LOCALE constants
|
||||
* 'locale' => the actual set locale to use
|
||||
* @var array
|
||||
*/
|
||||
protected $_options = array(
|
||||
'clear' => false,
|
||||
'disableNotices' => false,
|
||||
'ignore' => '.',
|
||||
'locale' => 'auto',
|
||||
'log' => null,
|
||||
'logMessage' => "Untranslated message within '%locale%': %message%",
|
||||
'logUntranslated' => false,
|
||||
'scan' => null
|
||||
);
|
||||
|
||||
/**
|
||||
* Translation table
|
||||
* @var array
|
||||
*/
|
||||
protected $_translate = array();
|
||||
|
||||
/**
|
||||
* Generates the adapter
|
||||
*
|
||||
* @param string|array $data Translation data or filename for this adapter
|
||||
* @param string|Zend_Locale $locale (optional) Locale/Language to set, identical with Locale
|
||||
* identifiers see Zend_Locale for more information
|
||||
* @param array $options (optional) Options for the adaptor
|
||||
* @throws Zend_Translate_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($data, $locale = null, array $options = array())
|
||||
{
|
||||
if (isset(self::$_cache)) {
|
||||
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
||||
$result = self::$_cache->load($id);
|
||||
if ($result) {
|
||||
$this->_options = unserialize($result);
|
||||
}
|
||||
}
|
||||
|
||||
if (($locale === "auto") or ($locale === null)) {
|
||||
$this->_automatic = true;
|
||||
} else {
|
||||
$this->_automatic = false;
|
||||
}
|
||||
|
||||
$this->addTranslation($data, $locale, $options);
|
||||
if ($this->getLocale() !== (string) $locale) {
|
||||
$this->setLocale($locale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets new adapter options
|
||||
*
|
||||
* @param array $options Adapter options
|
||||
* @throws Zend_Translate_Exception
|
||||
* @return Zend_Translate_Adapter Provides fluent interface
|
||||
*/
|
||||
public function setOptions(array $options = array())
|
||||
{
|
||||
$change = false;
|
||||
$locale = null;
|
||||
foreach ($options as $key => $option) {
|
||||
if ($key == 'locale') {
|
||||
$locale = $option;
|
||||
} else if ((isset($this->_options[$key]) and ($this->_options[$key] != $option)) or
|
||||
!isset($this->_options[$key])) {
|
||||
if (($key == 'log') && !($option instanceof Zend_Log)) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('Instance of Zend_Log expected for option log');
|
||||
}
|
||||
|
||||
$this->_options[$key] = $option;
|
||||
$change = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($locale !== null) {
|
||||
$this->setLocale($locale);
|
||||
}
|
||||
|
||||
if (isset(self::$_cache) and ($change == true)) {
|
||||
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
||||
self::$_cache->save( serialize($this->_options), $id, array('Zend_Translate'));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapters name and it's options
|
||||
*
|
||||
* @param string|null $optionKey String returns this option
|
||||
* null returns all options
|
||||
* @return integer|string|array|null
|
||||
*/
|
||||
public function getOptions($optionKey = null)
|
||||
{
|
||||
if ($optionKey === null) {
|
||||
return $this->_options;
|
||||
}
|
||||
|
||||
if (isset($this->_options[$optionKey]) === true) {
|
||||
return $this->_options[$optionKey];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets locale
|
||||
*
|
||||
* @return Zend_Locale|string|null
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->_options['locale'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets locale
|
||||
*
|
||||
* @param string|Zend_Locale $locale Locale to set
|
||||
* @throws Zend_Translate_Exception
|
||||
* @return Zend_Translate_Adapter Provides fluent interface
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
if (($locale === "auto") or ($locale === null)) {
|
||||
$this->_automatic = true;
|
||||
} else {
|
||||
$this->_automatic = false;
|
||||
}
|
||||
|
||||
try {
|
||||
$locale = Zend_Locale::findLocale($locale);
|
||||
} catch (Zend_Locale_Exception $e) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception("The given Language ({$locale}) does not exist");
|
||||
}
|
||||
|
||||
if (!isset($this->_translate[$locale])) {
|
||||
$temp = explode('_', $locale);
|
||||
if (!isset($this->_translate[$temp[0]]) and !isset($this->_translate[$locale])) {
|
||||
if (!$this->_options['disableNotices']) {
|
||||
if ($this->_options['log']) {
|
||||
$this->_options['log']->notice("The language '{$locale}' has to be added before it can be used.");
|
||||
} else {
|
||||
trigger_error("The language '{$locale}' has to be added before it can be used.", E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$locale = $temp[0];
|
||||
}
|
||||
|
||||
if (empty($this->_translate[$locale])) {
|
||||
if (!$this->_options['disableNotices']) {
|
||||
if ($this->_options['log']) {
|
||||
$this->_options['log']->notice("No translation for the language '{$locale}' available.");
|
||||
} else {
|
||||
trigger_error("No translation for the language '{$locale}' available.", E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_options['locale'] != $locale) {
|
||||
$this->_options['locale'] = $locale;
|
||||
|
||||
if (isset(self::$_cache)) {
|
||||
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
||||
self::$_cache->save( serialize($this->_options), $id, array('Zend_Translate'));
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the available languages from this adapter
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
$list = array_keys($this->_translate);
|
||||
$result = null;
|
||||
foreach($list as $value) {
|
||||
if (!empty($this->_translate[$value])) {
|
||||
$result[$value] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all available message ids from this adapter
|
||||
* If no locale is given, the actual language will be used
|
||||
*
|
||||
* @param string|Zend_Locale $locale (optional) Language to return the message ids from
|
||||
* @return array
|
||||
*/
|
||||
public function getMessageIds($locale = null)
|
||||
{
|
||||
if (empty($locale) or !$this->isAvailable($locale)) {
|
||||
$locale = $this->_options['locale'];
|
||||
}
|
||||
|
||||
return array_keys($this->_translate[(string) $locale]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all available translations from this adapter
|
||||
* If no locale is given, the actual language will be used
|
||||
* If 'all' is given the complete translation dictionary will be returned
|
||||
*
|
||||
* @param string|Zend_Locale $locale (optional) Language to return the messages from
|
||||
* @return array
|
||||
*/
|
||||
public function getMessages($locale = null)
|
||||
{
|
||||
if ($locale === 'all') {
|
||||
return $this->_translate;
|
||||
}
|
||||
|
||||
if ((empty($locale) === true) or ($this->isAvailable($locale) === false)) {
|
||||
$locale = $this->_options['locale'];
|
||||
}
|
||||
|
||||
return $this->_translate[(string) $locale];
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the wished language available ?
|
||||
*
|
||||
* @see Zend_Locale
|
||||
* @param string|Zend_Locale $locale Language to search for, identical with locale identifier,
|
||||
* @see Zend_Locale for more information
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAvailable($locale)
|
||||
{
|
||||
$return = isset($this->_translate[(string) $locale]);
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function for adding translation data
|
||||
*
|
||||
* It may be a new language or additional data for existing language
|
||||
* If $clear parameter is true, then translation data for specified
|
||||
* language is replaced and added otherwise
|
||||
*
|
||||
* @see Zend_Locale
|
||||
* @param array|string $data Translation data
|
||||
* @param string|Zend_Locale $locale Locale/Language to add data for, identical with locale identifier,
|
||||
* @see Zend_Locale for more information
|
||||
* @param array $options (optional) Option for this Adapter
|
||||
* @throws Zend_Translate_Exception
|
||||
* @return Zend_Translate_Adapter Provides fluent interface
|
||||
*/
|
||||
private function _addTranslationData($data, $locale, array $options = array())
|
||||
{
|
||||
try {
|
||||
$locale = Zend_Locale::findLocale($locale);
|
||||
} catch (Zend_Locale_Exception $e) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception("The given Language '{$locale}' does not exist");
|
||||
}
|
||||
|
||||
if (!isset($this->_translate[$locale])) {
|
||||
$this->_translate[$locale] = array();
|
||||
}
|
||||
|
||||
$read = true;
|
||||
if (isset(self::$_cache)) {
|
||||
$id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString();
|
||||
$result = self::$_cache->load($id);
|
||||
if ($result) {
|
||||
$temp = unserialize($result);
|
||||
$read = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($read) {
|
||||
$temp = $this->_loadTranslationData($data, $locale, $options);
|
||||
}
|
||||
|
||||
if (empty($temp)) {
|
||||
$temp = array();
|
||||
}
|
||||
|
||||
$keys = array_keys($temp);
|
||||
foreach($keys as $key) {
|
||||
if (!isset($this->_translate[$key])) {
|
||||
$this->_translate[$key] = array();
|
||||
}
|
||||
|
||||
$this->_translate[$key] = $temp[$key] + $this->_translate[$key];
|
||||
}
|
||||
|
||||
if ($this->_automatic === true) {
|
||||
$find = new Zend_Locale($locale);
|
||||
$browser = $find->getEnvironment() + $find->getBrowser();
|
||||
arsort($browser);
|
||||
foreach($browser as $language => $quality) {
|
||||
if (isset($this->_translate[$language])) {
|
||||
$this->_options['locale'] = $language;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (($read) and (isset(self::$_cache))) {
|
||||
$id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString();
|
||||
self::$_cache->save( serialize($temp), $id, array('Zend_Translate'));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the given string
|
||||
* returns the translation
|
||||
*
|
||||
* @see Zend_Locale
|
||||
* @param string|array $messageId Translation string, or Array for plural translations
|
||||
* @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with
|
||||
* locale identifier, @see Zend_Locale for more information
|
||||
* @return string
|
||||
*/
|
||||
public function translate($messageId, $locale = null)
|
||||
{
|
||||
if ($locale === null) {
|
||||
$locale = $this->_options['locale'];
|
||||
}
|
||||
|
||||
$plural = null;
|
||||
if (is_array($messageId)) {
|
||||
if (count($messageId) > 2) {
|
||||
$number = array_pop($messageId);
|
||||
if (!is_numeric($number)) {
|
||||
$plocale = $number;
|
||||
$number = array_pop($messageId);
|
||||
} else {
|
||||
$plocale = 'en';
|
||||
}
|
||||
|
||||
$plural = $messageId;
|
||||
$messageId = $messageId[0];
|
||||
} else {
|
||||
$messageId = $messageId[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (!Zend_Locale::isLocale($locale, true, false)) {
|
||||
if (!Zend_Locale::isLocale($locale, false, false)) {
|
||||
// language does not exist, return original string
|
||||
$this->_log($messageId, $locale);
|
||||
if ($plural === null) {
|
||||
return $messageId;
|
||||
}
|
||||
|
||||
$rule = Zend_Translate_Plural::getPlural($number, $plocale);
|
||||
if (!isset($plural[$rule])) {
|
||||
$rule = 0;
|
||||
}
|
||||
|
||||
return $plural[$rule];
|
||||
}
|
||||
|
||||
$locale = new Zend_Locale($locale);
|
||||
}
|
||||
|
||||
$locale = (string) $locale;
|
||||
if (isset($this->_translate[$locale][$messageId])) {
|
||||
// return original translation
|
||||
if ($plural === null) {
|
||||
return $this->_translate[$locale][$messageId];
|
||||
}
|
||||
|
||||
$rule = Zend_Translate_Plural::getPlural($number, $locale);
|
||||
if (isset($this->_translate[$locale][$plural[0]][$rule])) {
|
||||
return $this->_translate[$locale][$plural[0]][$rule];
|
||||
}
|
||||
} else if (strlen($locale) != 2) {
|
||||
// faster than creating a new locale and separate the leading part
|
||||
$locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
|
||||
|
||||
if (isset($this->_translate[$locale][$messageId])) {
|
||||
// return regionless translation (en_US -> en)
|
||||
if ($plural === null) {
|
||||
return $this->_translate[$locale][$messageId];
|
||||
}
|
||||
|
||||
$rule = Zend_Translate_Plural::getPlural($number, $locale);
|
||||
if (isset($this->_translate[$locale][$plural[0]][$rule])) {
|
||||
return $this->_translate[$locale][$plural[0]][$rule];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_log($messageId, $locale);
|
||||
if ($plural === null) {
|
||||
return $messageId;
|
||||
}
|
||||
|
||||
$rule = Zend_Translate_Plural::getPlural($number, $plocale);
|
||||
if (!isset($plural[$rule])) {
|
||||
$rule = 0;
|
||||
}
|
||||
|
||||
return $plural[$rule];
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the given string using plural notations
|
||||
* Returns the translated string
|
||||
*
|
||||
* @see Zend_Locale
|
||||
* @param string $singular Singular translation string
|
||||
* @param string $plural Plural translation string
|
||||
* @param integer $number Number for detecting the correct plural
|
||||
* @param string|Zend_Locale $locale (Optional) Locale/Language to use, identical with
|
||||
* locale identifier, @see Zend_Locale for more information
|
||||
* @return string
|
||||
*/
|
||||
public function plural($singular, $plural, $number, $locale = null)
|
||||
{
|
||||
return $this->translate(array($singular, $plural, $number), $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message when the log option is set
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param String $locale Locale to log
|
||||
*/
|
||||
protected function _log($message, $locale) {
|
||||
if ($this->_options['logUntranslated']) {
|
||||
$message = str_replace('%message%', $message, $this->_options['logMessage']);
|
||||
$message = str_replace('%locale%', $locale, $message);
|
||||
if ($this->_options['log']) {
|
||||
$this->_options['log']->notice($message);
|
||||
} else {
|
||||
trigger_error($message, E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the given string
|
||||
* returns the translation
|
||||
*
|
||||
* @param string $messageId Translation string
|
||||
* @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale
|
||||
* identifier, @see Zend_Locale for more information
|
||||
* @return string
|
||||
*/
|
||||
public function _($messageId, $locale = null)
|
||||
{
|
||||
return $this->translate($messageId, $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a string is translated within the source or not
|
||||
* returns boolean
|
||||
*
|
||||
* @param string $messageId Translation string
|
||||
* @param boolean $original (optional) Allow translation only for original language
|
||||
* when true, a translation for 'en_US' would give false when it can
|
||||
* be translated with 'en' only
|
||||
* @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @return boolean
|
||||
*/
|
||||
public function isTranslated($messageId, $original = false, $locale = null)
|
||||
{
|
||||
if (($original !== false) and ($original !== true)) {
|
||||
$locale = $original;
|
||||
$original = false;
|
||||
}
|
||||
|
||||
if ($locale === null) {
|
||||
$locale = $this->_options['locale'];
|
||||
}
|
||||
|
||||
if (!Zend_Locale::isLocale($locale, true, false)) {
|
||||
if (!Zend_Locale::isLocale($locale, false, false)) {
|
||||
// language does not exist, return original string
|
||||
$this->_log($messageId, $locale);
|
||||
return false;
|
||||
}
|
||||
|
||||
$locale = new Zend_Locale($locale);
|
||||
}
|
||||
|
||||
$locale = (string) $locale;
|
||||
if (isset($this->_translate[$locale][$messageId]) === true) {
|
||||
// return original translation
|
||||
return true;
|
||||
} else if ((strlen($locale) != 2) and ($original === false)) {
|
||||
// faster than creating a new locale and separate the leading part
|
||||
$locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
|
||||
|
||||
if (isset($this->_translate[$locale][$messageId]) === true) {
|
||||
// return regionless translation (en_US -> en)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// No translation found, return original
|
||||
$this->_log($messageId, $locale);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set cache
|
||||
*
|
||||
* @return Zend_Cache_Core The set cache
|
||||
*/
|
||||
public static function getCache()
|
||||
{
|
||||
return self::$_cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a cache for all Zend_Translate_Adapters
|
||||
*
|
||||
* @param Zend_Cache_Core $cache Cache to store to
|
||||
*/
|
||||
public static function setCache(Zend_Cache_Core $cache)
|
||||
{
|
||||
self::$_cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when a cache is set
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function hasCache()
|
||||
{
|
||||
if (self::$_cache !== null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any set cache
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function removeCache()
|
||||
{
|
||||
self::$_cache = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all set cache data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function clearCache()
|
||||
{
|
||||
require_once 'Zend/Cache.php';
|
||||
self::$_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('Zend_Translate'));
|
||||
}
|
||||
|
||||
public function addTranslation($data, $locale = null, array $options = array())
|
||||
{
|
||||
$this->setOptions($options);
|
||||
|
||||
$originate = (string) $locale;
|
||||
if (array_key_exists('locale', $options)) {
|
||||
if ($locale == null) {
|
||||
$locale = $options['locale'];
|
||||
}
|
||||
unset($options['locale']);
|
||||
}
|
||||
|
||||
if ((array_key_exists('log', $options)) && !($options['log'] instanceof Zend_Log)) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('Instance of Zend_Log expected for option log');
|
||||
}
|
||||
|
||||
try {
|
||||
$locale = Zend_Locale::findLocale($locale);
|
||||
} catch (Zend_Locale_Exception $e) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception("The given Language '{$locale}' does not exist");
|
||||
}
|
||||
|
||||
if (is_string($data) and is_dir($data)) {
|
||||
$data = realpath($data);
|
||||
$prev = '';
|
||||
foreach (new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($data, RecursiveDirectoryIterator::KEY_AS_PATHNAME),
|
||||
RecursiveIteratorIterator::SELF_FIRST) as $directory => $info) {
|
||||
$file = $info->getFilename();
|
||||
if (strpos($directory, DIRECTORY_SEPARATOR . $options['ignore']) !== false) {
|
||||
// ignore files matching first characters from option 'ignore' and all files below
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($info->isDir()) {
|
||||
// pathname as locale
|
||||
if (($options['scan'] === self::LOCALE_DIRECTORY) and (Zend_Locale::isLocale($file, true, false))) {
|
||||
$locale = $file;
|
||||
$prev = (string) $locale;
|
||||
}
|
||||
} else if ($info->isFile()) {
|
||||
// filename as locale
|
||||
if ($options['scan'] === self::LOCALE_FILENAME) {
|
||||
$filename = explode('.', $file);
|
||||
array_pop($filename);
|
||||
$filename = implode('.', $filename);
|
||||
if (Zend_Locale::isLocale((string) $filename, true, false)) {
|
||||
$locale = (string) $filename;
|
||||
} else {
|
||||
$parts = explode('.', $file);
|
||||
$parts2 = array();
|
||||
foreach($parts as $token) {
|
||||
$parts2 += explode('_', $token);
|
||||
}
|
||||
$parts = array_merge($parts, $parts2);
|
||||
$parts2 = array();
|
||||
foreach($parts as $token) {
|
||||
$parts2 += explode('-', $token);
|
||||
}
|
||||
$parts = array_merge($parts, $parts2);
|
||||
$parts = array_unique($parts);
|
||||
$prev = '';
|
||||
foreach($parts as $token) {
|
||||
if (Zend_Locale::isLocale($token, true, false)) {
|
||||
if (strlen($prev) <= strlen($token)) {
|
||||
$locale = $token;
|
||||
$prev = $token;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
$this->_addTranslationData($info->getPathname(), (string) $locale, $options);
|
||||
} catch (Zend_Translate_Exception $e) {
|
||||
// ignore failed sources while scanning
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->_addTranslationData($data, (string) $locale, $options);
|
||||
}
|
||||
|
||||
if ((isset($this->_translate[$originate]) === true) and (count($this->_translate[$originate]) > 0)) {
|
||||
$this->setLocale($originate);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
// THIS IS THE COPY OF THE GETTEXT CLASS
|
||||
|
||||
// Internal variables
|
||||
private $_bigEndian = false;
|
||||
private $_file = false;
|
||||
private $_adapterInfo = array();
|
||||
private $_data = array();
|
||||
|
||||
/**
|
||||
* Read values from the MO file
|
||||
*
|
||||
* @param string $bytes
|
||||
*/
|
||||
private function _readMOData($bytes)
|
||||
{
|
||||
if ($this->_bigEndian === false) {
|
||||
return unpack('V' . $bytes, fread($this->_file, 4 * $bytes));
|
||||
} else {
|
||||
return unpack('N' . $bytes, fread($this->_file, 4 * $bytes));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load translation data (MO file reader)
|
||||
*
|
||||
* @param string $filename MO file to add, full path must be given for access
|
||||
* @param string $locale New Locale/Language to set, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $option OPTIONAL Options to use
|
||||
* @throws Zend_Translation_Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$this->_data = array();
|
||||
$this->_bigEndian = false;
|
||||
$this->_file = @fopen($filename, 'rb');
|
||||
if (!$this->_file) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('Error opening translation file \'' . $filename . '\'.');
|
||||
}
|
||||
if (@filesize($filename) < 10) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('\'' . $filename . '\' is not a gettext file');
|
||||
}
|
||||
|
||||
// get Endian
|
||||
$input = $this->_readMOData(1);
|
||||
if (strtolower(substr(dechex($input[1]), -8)) == "950412de") {
|
||||
$this->_bigEndian = false;
|
||||
} else if (strtolower(substr(dechex($input[1]), -8)) == "de120495") {
|
||||
$this->_bigEndian = true;
|
||||
} else {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('\'' . $filename . '\' is not a gettext file');
|
||||
}
|
||||
// read revision - not supported for now
|
||||
$input = $this->_readMOData(1);
|
||||
|
||||
// number of bytes
|
||||
$input = $this->_readMOData(1);
|
||||
$total = $input[1];
|
||||
|
||||
// number of original strings
|
||||
$input = $this->_readMOData(1);
|
||||
$OOffset = $input[1];
|
||||
|
||||
// number of translation strings
|
||||
$input = $this->_readMOData(1);
|
||||
$TOffset = $input[1];
|
||||
|
||||
// fill the original table
|
||||
fseek($this->_file, $OOffset);
|
||||
$origtemp = $this->_readMOData(2 * $total);
|
||||
fseek($this->_file, $TOffset);
|
||||
$transtemp = $this->_readMOData(2 * $total);
|
||||
|
||||
for($count = 0; $count < $total; ++$count) {
|
||||
if ($origtemp[$count * 2 + 1] != 0) {
|
||||
fseek($this->_file, $origtemp[$count * 2 + 2]);
|
||||
$original = @fread($this->_file, $origtemp[$count * 2 + 1]);
|
||||
$original = explode(chr(00), $original);
|
||||
} else {
|
||||
$original[0] = '';
|
||||
}
|
||||
|
||||
if ($transtemp[$count * 2 + 1] != 0) {
|
||||
fseek($this->_file, $transtemp[$count * 2 + 2]);
|
||||
$translate = fread($this->_file, $transtemp[$count * 2 + 1]);
|
||||
$translate = explode(chr(00), $translate);
|
||||
if ((count($original) > 1) && (count($translate) > 1)) {
|
||||
$this->_data[$locale][$original[0]] = $translate;
|
||||
array_shift($original);
|
||||
foreach ($original as $orig) {
|
||||
$this->_data[$locale][$orig] = '';
|
||||
}
|
||||
} else {
|
||||
$this->_data[$locale][$original[0]] = $translate[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_data[$locale][''] = trim($this->_data[$locale]['']);
|
||||
if (empty($this->_data[$locale][''])) {
|
||||
$this->_adapterInfo[$filename] = 'No adapter information available';
|
||||
} else {
|
||||
$this->_adapterInfo[$filename] = $this->_data[$locale][''];
|
||||
}
|
||||
|
||||
unset($this->_data[$locale]['']);
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapter informations
|
||||
*
|
||||
* @return array Each loaded adapter information as array value
|
||||
*/
|
||||
public function getAdapterInfo()
|
||||
{
|
||||
return $this->_adapterInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapter name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return "Gettext";
|
||||
}
|
||||
}
|
12
libs/Monkeys/UnsupportedOperationException.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_UnsupportedOperationException extends Zend_Exception {}
|
||||
|
187
libs/Monkeys/Validate/Password.php
Normal file
@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_Validate_Password extends Zend_Validate_Abstract
|
||||
{
|
||||
const MSG_DICTIONARY = 'dictionary';
|
||||
const MSG_USERNAME = 'username';
|
||||
const MSG_LENGTH = 'length';
|
||||
const MSG_NUMBERS = 'numbers';
|
||||
const MSG_SYMBOLS = 'symbols';
|
||||
const MSG_CASE = 'case';
|
||||
|
||||
const MIN_LENGTH_INCLUDED_WORD = 4;
|
||||
|
||||
public $word;
|
||||
public $minLength;
|
||||
|
||||
protected $_messageVariables = array(
|
||||
'minLength' => 'minLength',
|
||||
);
|
||||
|
||||
protected $_messageTemplates = array(
|
||||
self::MSG_DICTIONARY => 'Password can\'t be a dictionary word',
|
||||
self::MSG_USERNAME => 'Password can\'t contain the username',
|
||||
self::MSG_LENGTH => 'Password must be longer than %minLength% characters',
|
||||
self::MSG_NUMBERS => 'Password must contain numbers',
|
||||
self::MSG_SYMBOLS => 'Password must contain symbols',
|
||||
self::MSG_CASE => 'Password needs to have lowercase and uppercase characters',
|
||||
);
|
||||
|
||||
private $_username;
|
||||
private $_config;
|
||||
|
||||
public function __construct($username = null)
|
||||
{
|
||||
$this->_username = $username;
|
||||
$this->_config = Zend_Registry::get('config');
|
||||
$this->minLength = $this->_config->security->passwords->minimum_length;
|
||||
}
|
||||
|
||||
public function getPasswordRestrictionsDescription()
|
||||
{
|
||||
$restrictions = array();
|
||||
|
||||
if ($this->_config->security->passwords->dictionary) {
|
||||
$restrictions[] = $this->_messageTemplates[self::MSG_DICTIONARY];
|
||||
}
|
||||
|
||||
if ($this->_config->security->passwords->username_different) {
|
||||
$restrictions[] = $this->_messageTemplates[self::MSG_USERNAME];
|
||||
}
|
||||
|
||||
if ($this->minLength) {
|
||||
$restrictions[] = str_replace('%minLength%', $this->minLength, $this->_messageTemplates[self::MSG_LENGTH]);
|
||||
}
|
||||
|
||||
if ($this->_config->security->passwords->include_numbers) {
|
||||
$restrictions[] = $this->_messageTemplates[self::MSG_NUMBERS];
|
||||
}
|
||||
|
||||
if ($this->_config->security->passwords->include_symbols) {
|
||||
$restrictions[] = $this->_messageTemplates[self::MSG_SYMBOLS];
|
||||
}
|
||||
|
||||
if ($this->_config->security->passwords->lowercase_and_uppercase) {
|
||||
$restrictions[] = $this->_messageTemplates[self::MSG_CASE];
|
||||
}
|
||||
|
||||
if (!$restrictions) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return '<ul><li>' . implode('</li><li>', $restrictions) . '</li></ul>';
|
||||
}
|
||||
|
||||
public function isValid($value, $context = null)
|
||||
{
|
||||
$this->_setValue($value);
|
||||
$isValid = true;
|
||||
|
||||
if ($this->_config->security->passwords->dictionary
|
||||
&& !$this->_checkDictionary($value, $this->_config->security->passwords->dictionary)) {
|
||||
$this->_error(self::MSG_DICTIONARY);
|
||||
$isValid = false;
|
||||
}
|
||||
|
||||
if ($this->_config->security->passwords->username_different
|
||||
&& !$this->_checkUsername($value, $context)) {
|
||||
$this->_error(self::MSG_USERNAME);
|
||||
$isValid = false;
|
||||
}
|
||||
|
||||
if ($this->minLength
|
||||
&& !$this->_checkLength($value, $this->minLength)) {
|
||||
$this->_error(self::MSG_LENGTH);
|
||||
$isValid = false;
|
||||
}
|
||||
|
||||
if ($this->_config->security->passwords->include_numbers
|
||||
&& !$this->_checkNumbers($value)) {
|
||||
$this->_error(self::MSG_NUMBERS);
|
||||
$isValid = false;
|
||||
}
|
||||
|
||||
if ($this->_config->security->passwords->include_symbols
|
||||
&& !$this->_checkSymbols($value)) {
|
||||
$this->_error(self::MSG_SYMBOLS);
|
||||
$isValid = false;
|
||||
}
|
||||
|
||||
if ($this->_config->security->passwords->lowercase_and_uppercase
|
||||
&& !$this->_checkCase($value)) {
|
||||
$this->_error(self::MSG_CASE);
|
||||
$isValid = false;
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
private function _checkDictionary($value, $dictionary)
|
||||
{
|
||||
$value = strtolower($value);
|
||||
if (!@$file = fopen(APP_DIR . "/$dictionary", 'r')) {
|
||||
throw new Exception('Dictionary file could not be read');
|
||||
}
|
||||
|
||||
while (!feof($file)) {
|
||||
$word = strtolower(trim(fgets($file)));
|
||||
if (strlen($word) >= self::MIN_LENGTH_INCLUDED_WORD
|
||||
&& $value == $word) {
|
||||
$this->word = $word;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
fclose($file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function _checkUsername($value, $context)
|
||||
{
|
||||
$username = '';
|
||||
if (is_array($context) && isset($context['username'])) {
|
||||
$username = $context['username'];
|
||||
} elseif (is_string($context)) {
|
||||
$username = $context;
|
||||
} elseif ($this->_username) {
|
||||
$username = $this->_username;
|
||||
} else {
|
||||
throw new Exception('Username context was not passed');
|
||||
}
|
||||
|
||||
if ($username == '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return strpos(strtolower($value), strtolower($username)) === false;
|
||||
}
|
||||
|
||||
private function _checkLength($value, $minimumLength)
|
||||
{
|
||||
return strlen($value) >= $minimumLength;
|
||||
}
|
||||
|
||||
private function _checkNumbers($value)
|
||||
{
|
||||
return preg_match('/[0-9]+/', $value);
|
||||
}
|
||||
|
||||
private function _checkSymbols($value)
|
||||
{
|
||||
return preg_match('/[\W]+/', $value);
|
||||
}
|
||||
|
||||
private function _checkCase($value)
|
||||
{
|
||||
return (preg_match('/[A-Z]+/', $value)
|
||||
&& preg_match('/[a-z]+/', $value));
|
||||
}
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
<?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
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?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
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
@ -15,20 +14,34 @@
|
||||
class Monkeys_Validate_Username extends Zend_Validate_Abstract
|
||||
{
|
||||
const BAD = 'bad';
|
||||
const BAD2 = 'bad2';
|
||||
|
||||
protected $_messageTemplates = array(
|
||||
self::BAD => 'Username can only contain US-ASCII alphanumeric characters, plus any of the symbols $-_.+!*\'(), and "'
|
||||
self::BAD => 'Username can only contain US-ASCII alphanumeric characters, plus any of the symbols $-_.+!*\'(), and "',
|
||||
self::BAD2 => 'Username is invalid'
|
||||
);
|
||||
|
||||
public function isValid($value, $context = null)
|
||||
{
|
||||
$this->_setValue($value);
|
||||
|
||||
if (preg_match('/^[A-Za-z\$-_.\+!\*\'\(\)",]+$/', $value)) {
|
||||
return true;
|
||||
} else {
|
||||
if (!preg_match('/^[A-Za-z\$-_.\+!\*\'\(\)",]+$/', $value)) {
|
||||
$this->_error(self::BAD);
|
||||
return false;
|
||||
}
|
||||
|
||||
$config = Zend_Registry::get('config');
|
||||
foreach ($config->security->usernames->exclude as $regex) {
|
||||
if (!$regex) {
|
||||
continue;
|
||||
}
|
||||
$regex = preg_quote($regex);
|
||||
if (preg_match("/$regex/", $value)) {
|
||||
$this->_error(self::BAD2);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @copyright Copyright (C) 2005-2010 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
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @copyright Copyright (C) 2005-2010 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
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
require_once WEB_DIR . '/fckeditor/fckeditor.php';
|
||||
|
||||
class Monkeys_View_Helper_FormRichtextarea extends Zend_View_Helper_FormElement
|
||||
|
8
libs/Monkeys/View/Helper/GetBase.php
Executable file → Normal file
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_View_Helper_GetBase
|
||||
{
|
||||
public function getBase()
|
||||
|
25
libs/Monkeys/View/Helper/Messages.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD Licensese
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @package Monkeys Framework
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class Monkeys_View_Helper_Messages
|
||||
{
|
||||
public function messages($messages)
|
||||
{
|
||||
if ($messages) {
|
||||
$str = "<div id=\"messages\">\n";
|
||||
$str .= implode('<br />', $messages);
|
||||
$str .= "</div>\n";
|
||||
} else {
|
||||
$str = '';
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
BIN
libs/Monkeys/fonts/ipam.ttf
Normal file
0
libs/Monkeys/tests/names.txt
Executable file → Normal file
BIN
libs/Monkeys/tests/sampleavatars/bbhhbhb.jpeg
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
libs/Monkeys/tests/sampleavatars/bbuyu.jpeg
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
libs/Monkeys/tests/sampleavatars/bbyuu.jpeg
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
libs/Monkeys/tests/sampleavatars/bbyyb.jpeg
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
libs/Monkeys/tests/sampleavatars/bhbuuybyb.jpeg
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
libs/Monkeys/tests/sampleavatars/bhhuh.jpeg
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
libs/Monkeys/tests/sampleavatars/bnybyb.jpeg
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
libs/Monkeys/tests/sampleavatars/bnyubyb.jpeg
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
libs/Monkeys/tests/sampleavatars/bubyby.jpeg
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
libs/Monkeys/tests/sampleavatars/bybj.jpeg
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
libs/Monkeys/tests/sampleavatars/bybyb.jpeg
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
libs/Monkeys/tests/sampleavatars/bybyby.jpeg
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
libs/Monkeys/tests/sampleavatars/bybybyb.jpeg
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
libs/Monkeys/tests/sampleavatars/byybyb.jpeg
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
libs/Monkeys/tests/sampleavatars/cfvc.jpeg
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
libs/Monkeys/tests/sampleavatars/frfr.jpeg
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
libs/Monkeys/tests/sampleavatars/ggbbgg.jpeg
Normal file
After Width: | Height: | Size: 3.1 KiB |
BIN
libs/Monkeys/tests/sampleavatars/gtubyb.jpeg
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
libs/Monkeys/tests/sampleavatars/gyubyubuyb.jpeg
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hbhbhb.jpeg
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hbhbhbhnjn.jpeg
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hbhbjhbjn.jpeg
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hbnjhbjhhn.jpeg
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hhbhbv.jpeg
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hhhuuh.jpeg
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hhuinbv.jpeg
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hhunnyuh.jpeg
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hjnyn.jpeg
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hnjnjnhbhb.jpeg
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hnuiuh.jpeg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
libs/Monkeys/tests/sampleavatars/huhh.jpeg
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
libs/Monkeys/tests/sampleavatars/huhujuj.jpeg
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
libs/Monkeys/tests/sampleavatars/huhuyuyb.jpeg
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hunnun.jpeg
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
libs/Monkeys/tests/sampleavatars/huuhunun.jpeg
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
libs/Monkeys/tests/sampleavatars/huunun.jpeg
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
libs/Monkeys/tests/sampleavatars/huybnuybnuny.jpeg
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hybbb.jpeg
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hybuyb.jpeg
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hybuybhh.jpeg
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hyhgg.jpeg
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hyhjhu.jpeg
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hyhy.jpeg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hyhybhyb.jpeg
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
libs/Monkeys/tests/sampleavatars/hyhybyg.jpeg
Normal file
After Width: | Height: | Size: 2.8 KiB |