id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
46,600
grrr-amsterdam/garp3
application/modules/g/views/helpers/Social.php
G_View_Helper_Social._getCurrentUrl
protected function _getCurrentUrl() { $url = $this->view->fullUrl($this->view->url()); $quesPos = strpos($url, '?'); if ($quesPos !== false) { $url = substr($url, 0, $quesPos); } return $url; }
php
protected function _getCurrentUrl() { $url = $this->view->fullUrl($this->view->url()); $quesPos = strpos($url, '?'); if ($quesPos !== false) { $url = substr($url, 0, $quesPos); } return $url; }
[ "protected", "function", "_getCurrentUrl", "(", ")", "{", "$", "url", "=", "$", "this", "->", "view", "->", "fullUrl", "(", "$", "this", "->", "view", "->", "url", "(", ")", ")", ";", "$", "quesPos", "=", "strpos", "(", "$", "url", ",", "'?'", ")...
Returns current url, stripped of any possible url queries. @return string
[ "Returns", "current", "url", "stripped", "of", "any", "possible", "url", "queries", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/Social.php#L431-L438
46,601
grrr-amsterdam/garp3
application/modules/g/views/helpers/Social.php
G_View_Helper_Social._setFacebookPageUrlAsHref
protected function _setFacebookPageUrlAsHref(Garp_Util_Configuration $params) { $ini = Zend_Registry::get('config'); if (!$ini->organization->facebook) { throw new Exception("Missing url: organization.facebook in application.ini"); } $params['href'] = $ini->organization->facebook; }
php
protected function _setFacebookPageUrlAsHref(Garp_Util_Configuration $params) { $ini = Zend_Registry::get('config'); if (!$ini->organization->facebook) { throw new Exception("Missing url: organization.facebook in application.ini"); } $params['href'] = $ini->organization->facebook; }
[ "protected", "function", "_setFacebookPageUrlAsHref", "(", "Garp_Util_Configuration", "$", "params", ")", "{", "$", "ini", "=", "Zend_Registry", "::", "get", "(", "'config'", ")", ";", "if", "(", "!", "$", "ini", "->", "organization", "->", "facebook", ")", ...
Modify params by making the organization's Facebook page the href. @param Garp_Util_Configuration $params @return void
[ "Modify", "params", "by", "making", "the", "organization", "s", "Facebook", "page", "the", "href", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/Social.php#L460-L466
46,602
grrr-amsterdam/garp3
library/Garp/Spawn/Config/Model/Base.php
Garp_Spawn_Config_Model_Base._addIdField
protected function _addIdField() { $params = array( 'type' => 'numeric', 'editable' => false, 'visible' => false, // next to being primary, an extra index key is also needed, // to enable the flexibility to modify primary keys. 'index' => true ); $params['primary'] = !$this->_primaryKeyFieldIsPresent(); $this['inputs'] = array('id' => $params) + $this['inputs']; }
php
protected function _addIdField() { $params = array( 'type' => 'numeric', 'editable' => false, 'visible' => false, // next to being primary, an extra index key is also needed, // to enable the flexibility to modify primary keys. 'index' => true ); $params['primary'] = !$this->_primaryKeyFieldIsPresent(); $this['inputs'] = array('id' => $params) + $this['inputs']; }
[ "protected", "function", "_addIdField", "(", ")", "{", "$", "params", "=", "array", "(", "'type'", "=>", "'numeric'", ",", "'editable'", "=>", "false", ",", "'visible'", "=>", "false", ",", "// next to being primary, an extra index key is also needed,", "// to enabl...
Adds an 'id' field to the model structure. Make it the primary key if there is no other primary key defined yet.
[ "Adds", "an", "id", "field", "to", "the", "model", "structure", ".", "Make", "it", "the", "primary", "key", "if", "there", "is", "no", "other", "primary", "key", "defined", "yet", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Config/Model/Base.php#L32-L45
46,603
grrr-amsterdam/garp3
library/Garp/Social/Facebook.php
Garp_Social_Facebook.mapFriends
public function mapFriends(array $config) { $config = $config instanceof Garp_Util_Configuration ? $config : new Garp_Util_Configuration($config); $config->obligate('bindingModel') ->obligate('user_id') ->setDefault('accessToken', $this->getAccessToken()) ; if (!$config['accessToken']) { // Find the auth record $authModel = new Model_AuthFacebook(); $authRow = $authModel->fetchRow($authModel->select()->where('user_id = ?', $config['user_id'])); if (!$authRow || !$authRow->access_token) { return false; } // Use the stored access token to create a user session. Me() in the FQL ahead will contain the user's Facebook ID. // Note that the access token is available for a very limited time. Chances are it's not valid anymore. $accessToken = $authRow->access_token; } try { $this->_client->setAccessToken($config['accessToken']); // Find the friends' Facebook UIDs $friends = $this->_client->api(array( 'method' => 'fql.query', 'query' => 'SELECT uid2 FROM friend WHERE uid1 = me()' )); // Find local user records $userModel = new Model_User(); $userTable = $userModel->getName(); $authFbModel = new Model_AuthFacebook(); $authFbTable = $authFbModel->getName(); $fbIds = ''; $friendCount = count($friends); foreach ($friends as $i => $friend) { $fbIds .= $userModel->getAdapter()->quote($friend['uid2']); if ($i < ($friendCount-1)) { $fbIds .= ','; } } $friendQuery = $userModel->select() ->setIntegrityCheck(false) ->from($userTable, array('id')) ->join($authFbTable, $authFbTable.'.user_id = '.$userTable.'.id', array()) ->where('facebook_uid IN ('.$fbIds.')') ->order($userTable.'.id') ; $localUsers = $userModel->fetchAll($friendQuery); $localUserCount = count($localUsers); // Insert new friendships into binding model $bindingModel = new $config['bindingModel']; $insertSql = 'INSERT IGNORE INTO '.$bindingModel->getName().' (user1_id, user2_id) VALUES '; foreach ($localUsers as $i => $localUser) { $insertSql .= '('.$localUser->id.','.$config['user_id'].'),'; $insertSql .= '('.$config['user_id'].','.$localUser->id.')'; if ($i < ($localUserCount-1)) { $insertSql .= ','; } } $result = $bindingModel->getAdapter()->query($insertSql); // Clear cache manually, since the table isn't updated thru conventional paths. Garp_Cache_Manager::purge($bindingModel); return !!$result; } catch (Exception $e) { return false; } }
php
public function mapFriends(array $config) { $config = $config instanceof Garp_Util_Configuration ? $config : new Garp_Util_Configuration($config); $config->obligate('bindingModel') ->obligate('user_id') ->setDefault('accessToken', $this->getAccessToken()) ; if (!$config['accessToken']) { // Find the auth record $authModel = new Model_AuthFacebook(); $authRow = $authModel->fetchRow($authModel->select()->where('user_id = ?', $config['user_id'])); if (!$authRow || !$authRow->access_token) { return false; } // Use the stored access token to create a user session. Me() in the FQL ahead will contain the user's Facebook ID. // Note that the access token is available for a very limited time. Chances are it's not valid anymore. $accessToken = $authRow->access_token; } try { $this->_client->setAccessToken($config['accessToken']); // Find the friends' Facebook UIDs $friends = $this->_client->api(array( 'method' => 'fql.query', 'query' => 'SELECT uid2 FROM friend WHERE uid1 = me()' )); // Find local user records $userModel = new Model_User(); $userTable = $userModel->getName(); $authFbModel = new Model_AuthFacebook(); $authFbTable = $authFbModel->getName(); $fbIds = ''; $friendCount = count($friends); foreach ($friends as $i => $friend) { $fbIds .= $userModel->getAdapter()->quote($friend['uid2']); if ($i < ($friendCount-1)) { $fbIds .= ','; } } $friendQuery = $userModel->select() ->setIntegrityCheck(false) ->from($userTable, array('id')) ->join($authFbTable, $authFbTable.'.user_id = '.$userTable.'.id', array()) ->where('facebook_uid IN ('.$fbIds.')') ->order($userTable.'.id') ; $localUsers = $userModel->fetchAll($friendQuery); $localUserCount = count($localUsers); // Insert new friendships into binding model $bindingModel = new $config['bindingModel']; $insertSql = 'INSERT IGNORE INTO '.$bindingModel->getName().' (user1_id, user2_id) VALUES '; foreach ($localUsers as $i => $localUser) { $insertSql .= '('.$localUser->id.','.$config['user_id'].'),'; $insertSql .= '('.$config['user_id'].','.$localUser->id.')'; if ($i < ($localUserCount-1)) { $insertSql .= ','; } } $result = $bindingModel->getAdapter()->query($insertSql); // Clear cache manually, since the table isn't updated thru conventional paths. Garp_Cache_Manager::purge($bindingModel); return !!$result; } catch (Exception $e) { return false; } }
[ "public", "function", "mapFriends", "(", "array", "$", "config", ")", "{", "$", "config", "=", "$", "config", "instanceof", "Garp_Util_Configuration", "?", "$", "config", ":", "new", "Garp_Util_Configuration", "(", "$", "config", ")", ";", "$", "config", "->...
Find friends of logged in user and map to local friends table. @param Array $config @return Bool Success
[ "Find", "friends", "of", "logged", "in", "user", "and", "map", "to", "local", "friends", "table", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Social/Facebook.php#L87-L156
46,604
grrr-amsterdam/garp3
library/Garp/Social/Facebook.php
Garp_Social_Facebook._getClient
protected function _getClient(array $config) { $ini = Zend_Registry::get('config'); $type = !empty($ini->store->type) ? $ini->store->type : 'Session'; if ($type == 'Cookie') { return new Garp_Social_Facebook_Client($config); } else { require_once APPLICATION_PATH.'/../garp/library/Garp/3rdParty/facebook/src/facebook.php'; $facebook = new Facebook($config); return $facebook; } }
php
protected function _getClient(array $config) { $ini = Zend_Registry::get('config'); $type = !empty($ini->store->type) ? $ini->store->type : 'Session'; if ($type == 'Cookie') { return new Garp_Social_Facebook_Client($config); } else { require_once APPLICATION_PATH.'/../garp/library/Garp/3rdParty/facebook/src/facebook.php'; $facebook = new Facebook($config); return $facebook; } }
[ "protected", "function", "_getClient", "(", "array", "$", "config", ")", "{", "$", "ini", "=", "Zend_Registry", "::", "get", "(", "'config'", ")", ";", "$", "type", "=", "!", "empty", "(", "$", "ini", "->", "store", "->", "type", ")", "?", "$", "in...
Create Facebook SDK @param Array $config @return Facebook
[ "Create", "Facebook", "SDK" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Social/Facebook.php#L174-L184
46,605
grrr-amsterdam/garp3
library/Garp/Cache/Store/Versioned.php
Garp_Cache_Store_Versioned.write
public function write($key, $data) { $cache = Zend_Registry::get('CacheFrontend'); // include the current version in the cached results $version = (int)$cache->load($this->_versionKey); // save the data to cache but include the version number return $cache->save( array( 'data' => $data, 'version' => $version ), $key ); }
php
public function write($key, $data) { $cache = Zend_Registry::get('CacheFrontend'); // include the current version in the cached results $version = (int)$cache->load($this->_versionKey); // save the data to cache but include the version number return $cache->save( array( 'data' => $data, 'version' => $version ), $key ); }
[ "public", "function", "write", "(", "$", "key", ",", "$", "data", ")", "{", "$", "cache", "=", "Zend_Registry", "::", "get", "(", "'CacheFrontend'", ")", ";", "// include the current version in the cached results", "$", "version", "=", "(", "int", ")", "$", ...
Write data to cache @param string $key The cache id @param mixed $data Data @return bool
[ "Write", "data", "to", "cache" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cache/Store/Versioned.php#L36-L48
46,606
grrr-amsterdam/garp3
library/Garp/Cache/Store/Versioned.php
Garp_Cache_Store_Versioned.read
public function read($key) { $cache = Zend_Registry::get('CacheFrontend'); // fetch results from cache if ($cache->test($key)) { $results = $cache->load($key); if (!is_array($results)) { return -1; } $version = (int)$cache->load($this->_versionKey); // compare version numbers if (array_key_exists('version', $results) && (int)$results['version'] === $version) { return $results['data']; } } return -1; }
php
public function read($key) { $cache = Zend_Registry::get('CacheFrontend'); // fetch results from cache if ($cache->test($key)) { $results = $cache->load($key); if (!is_array($results)) { return -1; } $version = (int)$cache->load($this->_versionKey); // compare version numbers if (array_key_exists('version', $results) && (int)$results['version'] === $version) { return $results['data']; } } return -1; }
[ "public", "function", "read", "(", "$", "key", ")", "{", "$", "cache", "=", "Zend_Registry", "::", "get", "(", "'CacheFrontend'", ")", ";", "// fetch results from cache", "if", "(", "$", "cache", "->", "test", "(", "$", "key", ")", ")", "{", "$", "resu...
Read data from cache @param string $key The cache id @return mixed -1 if no valid cache is found.
[ "Read", "data", "from", "cache" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cache/Store/Versioned.php#L57-L72
46,607
grrr-amsterdam/garp3
library/Garp/Cache/Store/Versioned.php
Garp_Cache_Store_Versioned.incrementVersion
public function incrementVersion() { $cache = Zend_Registry::get('CacheFrontend'); $version = (int)$cache->load($this->_versionKey); $version += 1; $cache->save($version, $this->_versionKey); return $this; }
php
public function incrementVersion() { $cache = Zend_Registry::get('CacheFrontend'); $version = (int)$cache->load($this->_versionKey); $version += 1; $cache->save($version, $this->_versionKey); return $this; }
[ "public", "function", "incrementVersion", "(", ")", "{", "$", "cache", "=", "Zend_Registry", "::", "get", "(", "'CacheFrontend'", ")", ";", "$", "version", "=", "(", "int", ")", "$", "cache", "->", "load", "(", "$", "this", "->", "_versionKey", ")", ";...
Increment the cached version. This invalidates the current cached results. @return Garp_Cache_Store_Versioned $this
[ "Increment", "the", "cached", "version", ".", "This", "invalidates", "the", "current", "cached", "results", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cache/Store/Versioned.php#L79-L85
46,608
grrr-amsterdam/garp3
library/Garp/Cache/Manager.php
Garp_Cache_Manager.readQueryCache
public static function readQueryCache(Garp_Model_Db $model, $key) { $cache = new Garp_Cache_Store_Versioned($model->getName() . '_version'); return $cache->read($key); }
php
public static function readQueryCache(Garp_Model_Db $model, $key) { $cache = new Garp_Cache_Store_Versioned($model->getName() . '_version'); return $cache->read($key); }
[ "public", "static", "function", "readQueryCache", "(", "Garp_Model_Db", "$", "model", ",", "$", "key", ")", "{", "$", "cache", "=", "new", "Garp_Cache_Store_Versioned", "(", "$", "model", "->", "getName", "(", ")", ".", "'_version'", ")", ";", "return", "$...
Read query cache @param Garp_Model_Db $model @param String $key @return Mixed
[ "Read", "query", "cache" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cache/Manager.php#L18-L21
46,609
grrr-amsterdam/garp3
library/Garp/Cache/Manager.php
Garp_Cache_Manager.writeQueryCache
public static function writeQueryCache(Garp_Model_Db $model, $key, $results) { $cache = new Garp_Cache_Store_Versioned($model->getName() . '_version'); $cache->write($key, $results); }
php
public static function writeQueryCache(Garp_Model_Db $model, $key, $results) { $cache = new Garp_Cache_Store_Versioned($model->getName() . '_version'); $cache->write($key, $results); }
[ "public", "static", "function", "writeQueryCache", "(", "Garp_Model_Db", "$", "model", ",", "$", "key", ",", "$", "results", ")", "{", "$", "cache", "=", "new", "Garp_Cache_Store_Versioned", "(", "$", "model", "->", "getName", "(", ")", ".", "'_version'", ...
Write query cache @param Garp_Model_Db $model @param String $key @param Mixed $results @return Void
[ "Write", "query", "cache" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cache/Manager.php#L31-L34
46,610
grrr-amsterdam/garp3
library/Garp/Cache/Manager.php
Garp_Cache_Manager.purge
public static function purge($tags = array(), $createClusterJob = true, $cacheDir = false) { $messageBag = array(); if ($tags instanceof Garp_Model_Db) { $tags = self::getTagsFromModel($tags); } $clearOpcache = !empty($tags['opcache']); unset($tags['opcache']); $messageBag = self::purgeStaticCache($tags, $cacheDir, $messageBag); $messageBag = self::purgeMemcachedCache($tags, $messageBag); if ($clearOpcache) { $messageBag = self::purgeOpcache($messageBag); } $ini = Zend_Registry::get('config'); if ($createClusterJob && $ini->app->clusteredHosting) { Garp_Cache_Store_Cluster::createJob($tags); $messageBag[] = 'Cluster: created clear cache job for cluster'; } return $messageBag; }
php
public static function purge($tags = array(), $createClusterJob = true, $cacheDir = false) { $messageBag = array(); if ($tags instanceof Garp_Model_Db) { $tags = self::getTagsFromModel($tags); } $clearOpcache = !empty($tags['opcache']); unset($tags['opcache']); $messageBag = self::purgeStaticCache($tags, $cacheDir, $messageBag); $messageBag = self::purgeMemcachedCache($tags, $messageBag); if ($clearOpcache) { $messageBag = self::purgeOpcache($messageBag); } $ini = Zend_Registry::get('config'); if ($createClusterJob && $ini->app->clusteredHosting) { Garp_Cache_Store_Cluster::createJob($tags); $messageBag[] = 'Cluster: created clear cache job for cluster'; } return $messageBag; }
[ "public", "static", "function", "purge", "(", "$", "tags", "=", "array", "(", ")", ",", "$", "createClusterJob", "=", "true", ",", "$", "cacheDir", "=", "false", ")", "{", "$", "messageBag", "=", "array", "(", ")", ";", "if", "(", "$", "tags", "ins...
Purge all cache system wide @param Array|Garp_Model_Db $tags @param Boolean $createClusterJob Whether this purge should create a job to clear the other nodes in this server cluster, if applicable. @param String $cacheDir Directory which stores static HTML cache files. @return Void
[ "Purge", "all", "cache", "system", "wide" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cache/Manager.php#L45-L69
46,611
grrr-amsterdam/garp3
library/Garp/Cache/Manager.php
Garp_Cache_Manager.purgeMemcachedCache
public static function purgeMemcachedCache($modelNames = array(), $messageBag = array()) { if (!Zend_Registry::isRegistered('CacheFrontend')) { $messageBag[] = 'Memcached: No caching enabled'; return $messageBag; } if (!Zend_Registry::get('CacheFrontend')->getOption('caching')) { $messageBag[] = 'Memcached: No caching enabled'; return $messageBag;; } if ($modelNames instanceof Garp_Model_Db) { $modelNames = self::getTagsFromModel($modelNames); } if (empty($modelNames)) { $cacheFront = Zend_Registry::get('CacheFrontend'); $cacheFront->clean(Zend_Cache::CLEANING_MODE_ALL); $messageBag[] = 'Memcached: Purged All'; return $messageBag; } foreach ($modelNames as $modelName) { $model = new $modelName(); self::_incrementMemcacheVersion($model); if (!$model->getObserver('Translatable')) { continue; } // Make sure cache is cleared for all languages. $locales = Garp_I18n::getLocales(); foreach ($locales as $locale) { try { $modelFactory = new Garp_I18n_ModelFactory($locale); $i18nModel = $modelFactory->getModel($model); self::_incrementMemcacheVersion($i18nModel); } catch (Garp_I18n_ModelFactory_Exception_ModelAlreadyLocalized $e) { // all good in the hood 。^‿^。 } } } $messageBag[] = 'Memcached: Purged all given models'; return $messageBag; }
php
public static function purgeMemcachedCache($modelNames = array(), $messageBag = array()) { if (!Zend_Registry::isRegistered('CacheFrontend')) { $messageBag[] = 'Memcached: No caching enabled'; return $messageBag; } if (!Zend_Registry::get('CacheFrontend')->getOption('caching')) { $messageBag[] = 'Memcached: No caching enabled'; return $messageBag;; } if ($modelNames instanceof Garp_Model_Db) { $modelNames = self::getTagsFromModel($modelNames); } if (empty($modelNames)) { $cacheFront = Zend_Registry::get('CacheFrontend'); $cacheFront->clean(Zend_Cache::CLEANING_MODE_ALL); $messageBag[] = 'Memcached: Purged All'; return $messageBag; } foreach ($modelNames as $modelName) { $model = new $modelName(); self::_incrementMemcacheVersion($model); if (!$model->getObserver('Translatable')) { continue; } // Make sure cache is cleared for all languages. $locales = Garp_I18n::getLocales(); foreach ($locales as $locale) { try { $modelFactory = new Garp_I18n_ModelFactory($locale); $i18nModel = $modelFactory->getModel($model); self::_incrementMemcacheVersion($i18nModel); } catch (Garp_I18n_ModelFactory_Exception_ModelAlreadyLocalized $e) { // all good in the hood 。^‿^。 } } } $messageBag[] = 'Memcached: Purged all given models'; return $messageBag; }
[ "public", "static", "function", "purgeMemcachedCache", "(", "$", "modelNames", "=", "array", "(", ")", ",", "$", "messageBag", "=", "array", "(", ")", ")", "{", "if", "(", "!", "Zend_Registry", "::", "isRegistered", "(", "'CacheFrontend'", ")", ")", "{", ...
Clear the Memcached cache that stores queries and ini files and whatnot. @param Array|Garp_Model_Db $modelNames @param Array $messageBag @return Void
[ "Clear", "the", "Memcached", "cache", "that", "stores", "queries", "and", "ini", "files", "and", "whatnot", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cache/Manager.php#L78-L120
46,612
grrr-amsterdam/garp3
library/Garp/Cache/Manager.php
Garp_Cache_Manager.purgeStaticCache
public static function purgeStaticCache($modelNames = array(), $cacheDir = false, $messageBag = array()) { if (!Zend_Registry::get('CacheFrontend')->getOption('caching')) { // caching is disabled (yes, this particular frontend is not in charge of static // cache, but in practice this toggle is used to enable/disable caching globally, so // this matches developer expectations better, probably) $messageBag[] = 'Static cache: No caching enabled'; return $messageBag; } if ($modelNames instanceof Garp_Model_Db) { $modelNames = self::getTagsFromModel($modelNames); } $cacheDir = $cacheDir ?: self::_getStaticCacheDir(); if (!$cacheDir) { $messageBag[] = 'Static cache: No cache directory configured'; return $messageBag; } $cacheDir = str_replace(' ', '\ ', $cacheDir); $cacheDir = rtrim($cacheDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; // Destroy all if no model names are given if (empty($modelNames)) { $allPath = $cacheDir . '*'; $response = self::_deleteStaticCacheFile($allPath); $messageBag[] = $response ? 'Static cache: Deleted all static cache files' : 'Static cache: There was a problem with deleting the static cache files'; return $messageBag; } // Fetch model names from configuration if (!$tagList = self::_getTagList()) { $messageBag[] = 'Static cache: No cache tags found'; return $messageBag; } $_purged = array(); foreach ($modelNames as $tag) { if (!$tagList->{$tag}) { continue; } foreach ($tagList->{$tag} as $path) { while (strpos($path, '..') !== false) { $path = str_replace('..', '.', $path); } $filePath = $cacheDir . $path; // Keep track of purged paths, forget about duplicates if (in_array($filePath, $_purged)) { continue; } self::_deleteStaticCacheFile($filePath); $_purged[] = $filePath; } } $messageBag[] = 'Static cache: purged'; return $messageBag; }
php
public static function purgeStaticCache($modelNames = array(), $cacheDir = false, $messageBag = array()) { if (!Zend_Registry::get('CacheFrontend')->getOption('caching')) { // caching is disabled (yes, this particular frontend is not in charge of static // cache, but in practice this toggle is used to enable/disable caching globally, so // this matches developer expectations better, probably) $messageBag[] = 'Static cache: No caching enabled'; return $messageBag; } if ($modelNames instanceof Garp_Model_Db) { $modelNames = self::getTagsFromModel($modelNames); } $cacheDir = $cacheDir ?: self::_getStaticCacheDir(); if (!$cacheDir) { $messageBag[] = 'Static cache: No cache directory configured'; return $messageBag; } $cacheDir = str_replace(' ', '\ ', $cacheDir); $cacheDir = rtrim($cacheDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; // Destroy all if no model names are given if (empty($modelNames)) { $allPath = $cacheDir . '*'; $response = self::_deleteStaticCacheFile($allPath); $messageBag[] = $response ? 'Static cache: Deleted all static cache files' : 'Static cache: There was a problem with deleting the static cache files'; return $messageBag; } // Fetch model names from configuration if (!$tagList = self::_getTagList()) { $messageBag[] = 'Static cache: No cache tags found'; return $messageBag; } $_purged = array(); foreach ($modelNames as $tag) { if (!$tagList->{$tag}) { continue; } foreach ($tagList->{$tag} as $path) { while (strpos($path, '..') !== false) { $path = str_replace('..', '.', $path); } $filePath = $cacheDir . $path; // Keep track of purged paths, forget about duplicates if (in_array($filePath, $_purged)) { continue; } self::_deleteStaticCacheFile($filePath); $_purged[] = $filePath; } } $messageBag[] = 'Static cache: purged'; return $messageBag; }
[ "public", "static", "function", "purgeStaticCache", "(", "$", "modelNames", "=", "array", "(", ")", ",", "$", "cacheDir", "=", "false", ",", "$", "messageBag", "=", "array", "(", ")", ")", "{", "if", "(", "!", "Zend_Registry", "::", "get", "(", "'Cache...
This clears Zend's Static caching. @param Array|Garp_Model_Db $modelNames Clear the cache of a specific bunch of models. @param String $cacheDir Directory containing the cache files @param Array $messageBag @return Void
[ "This", "clears", "Zend", "s", "Static", "caching", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cache/Manager.php#L130-L185
46,613
grrr-amsterdam/garp3
library/Garp/Cache/Manager.php
Garp_Cache_Manager.purgeOpcache
public static function purgeOpcache($messageBag = array()) { // This only clears the Opcache on CLI, // which is often separate from the HTTP Opcache. if (function_exists('opcache_reset')) { opcache_reset(); $messageBag[] = 'OPCache: purged on the CLI'; } if (function_exists('apc_clear_cache')) { apc_clear_cache(); $messageBag[] = 'APC: purged on the CLI'; } // Next, trigger the Opcache clear calls through HTTP. $deployConfig = new Garp_Deploy_Config; if (!$deployConfig->isConfigured(APPLICATION_ENV)) { return $messageBag; } $hostName = Zend_Registry::get('config')->app->domain; foreach (self::_getServerNames() as $serverName) { $opcacheResetWithServerName = self::_resetOpcacheHttp($serverName, $hostName); if ($opcacheResetWithServerName) { $messageBag[] = "OPCache: http purged on `{$serverName}`"; } if (!$opcacheResetWithServerName) { $opcacheResetWithHostName = self::_resetOpcacheHttp($hostName, $hostName); $messageBag[] = $opcacheResetWithHostName ? "OPCache: http purged on `{$hostName}`" : "OPCache: failed purging OPCache in http context on `{$hostName}`"; } } return $messageBag; }
php
public static function purgeOpcache($messageBag = array()) { // This only clears the Opcache on CLI, // which is often separate from the HTTP Opcache. if (function_exists('opcache_reset')) { opcache_reset(); $messageBag[] = 'OPCache: purged on the CLI'; } if (function_exists('apc_clear_cache')) { apc_clear_cache(); $messageBag[] = 'APC: purged on the CLI'; } // Next, trigger the Opcache clear calls through HTTP. $deployConfig = new Garp_Deploy_Config; if (!$deployConfig->isConfigured(APPLICATION_ENV)) { return $messageBag; } $hostName = Zend_Registry::get('config')->app->domain; foreach (self::_getServerNames() as $serverName) { $opcacheResetWithServerName = self::_resetOpcacheHttp($serverName, $hostName); if ($opcacheResetWithServerName) { $messageBag[] = "OPCache: http purged on `{$serverName}`"; } if (!$opcacheResetWithServerName) { $opcacheResetWithHostName = self::_resetOpcacheHttp($hostName, $hostName); $messageBag[] = $opcacheResetWithHostName ? "OPCache: http purged on `{$hostName}`" : "OPCache: failed purging OPCache in http context on `{$hostName}`"; } } return $messageBag; }
[ "public", "static", "function", "purgeOpcache", "(", "$", "messageBag", "=", "array", "(", ")", ")", "{", "// This only clears the Opcache on CLI,", "// which is often separate from the HTTP Opcache.", "if", "(", "function_exists", "(", "'opcache_reset'", ")", ")", "{", ...
This clears the Opcache, and APC for legacy systems. This reset can only be done with an http request. @param Array $messageBag @return Void
[ "This", "clears", "the", "Opcache", "and", "APC", "for", "legacy", "systems", ".", "This", "reset", "can", "only", "be", "done", "with", "an", "http", "request", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cache/Manager.php#L195-L228
46,614
grrr-amsterdam/garp3
library/Garp/Cache/Manager.php
Garp_Cache_Manager.scheduleClear
public static function scheduleClear($timestamp, array $tags = array()) { // Use ScheduledJob model if available, otherwise fall back to `at` if (!class_exists('Model_ScheduledJob')) { return static::createAtCommand($timestamp, $tags); } return static::createScheduledJob($timestamp, $tags); }
php
public static function scheduleClear($timestamp, array $tags = array()) { // Use ScheduledJob model if available, otherwise fall back to `at` if (!class_exists('Model_ScheduledJob')) { return static::createAtCommand($timestamp, $tags); } return static::createScheduledJob($timestamp, $tags); }
[ "public", "static", "function", "scheduleClear", "(", "$", "timestamp", ",", "array", "$", "tags", "=", "array", "(", ")", ")", "{", "// Use ScheduledJob model if available, otherwise fall back to `at`", "if", "(", "!", "class_exists", "(", "'Model_ScheduledJob'", ")"...
Schedule a cache clear in the future. @param Int $timestamp @param Array $tags @see Garp_Model_Behavior_Draftable for a likely pairing @return Bool A guesstimate of wether the command has successfully been scheduled. Note that it's hard to determine if this is true. I have, for instance, not yet found a way to determine if the atrun daemon actually is active.
[ "Schedule", "a", "cache", "clear", "in", "the", "future", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cache/Manager.php#L281-L287
46,615
grrr-amsterdam/garp3
library/Garp/Cache/Manager.php
Garp_Cache_Manager.getTagsFromModel
public static function getTagsFromModel(Garp_Model_Db $model) { $tags = array(get_class($model)); foreach ($model->getBindableModels() as $modelName) { if (!in_array($modelName, $tags)) { $tags[] = $modelName; } } return $tags; }
php
public static function getTagsFromModel(Garp_Model_Db $model) { $tags = array(get_class($model)); foreach ($model->getBindableModels() as $modelName) { if (!in_array($modelName, $tags)) { $tags[] = $modelName; } } return $tags; }
[ "public", "static", "function", "getTagsFromModel", "(", "Garp_Model_Db", "$", "model", ")", "{", "$", "tags", "=", "array", "(", "get_class", "(", "$", "model", ")", ")", ";", "foreach", "(", "$", "model", "->", "getBindableModels", "(", ")", "as", "$",...
Get cache tags used with a given model. @param Garp_Model_Db $model @return Array
[ "Get", "cache", "tags", "used", "with", "a", "given", "model", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cache/Manager.php#L354-L362
46,616
grrr-amsterdam/garp3
library/Garp/Cache/Manager.php
Garp_Cache_Manager._getStaticCacheDir
protected static function _getStaticCacheDir() { $config = Zend_Registry::get('config'); if (!isset($config->resources->cacheManager->page->backend->options->public_dir)) { return false; } return $config->resources->cacheManager->page->backend->options->public_dir; /** * Cache dir used to be read from the Front controller, which I would prefer under normal * circumstances. But the front controller is not bootstrapped in CLI environment, so I've * refactored to read from cache. I'm leaving this for future me to think about some more * * (full disclaimer: I'm probably never going to think about it anymore) * $front = Zend_Controller_Front::getInstance(); if (!$front->getParam('bootstrap') || !$front->getParam('bootstrap')->getResource('cachemanager')) { Garp_Cli::errorOut('no bootstrap or whatever'); return false; } $cacheManager = $front->getParam('bootstrap')->getResource('cachemanager'); $cache = $cacheManager->getCache(Zend_Cache_Manager::PAGECACHE); $cacheDir = $cache->getBackend()->getOption('public_dir'); return $cacheDir; */ }
php
protected static function _getStaticCacheDir() { $config = Zend_Registry::get('config'); if (!isset($config->resources->cacheManager->page->backend->options->public_dir)) { return false; } return $config->resources->cacheManager->page->backend->options->public_dir; /** * Cache dir used to be read from the Front controller, which I would prefer under normal * circumstances. But the front controller is not bootstrapped in CLI environment, so I've * refactored to read from cache. I'm leaving this for future me to think about some more * * (full disclaimer: I'm probably never going to think about it anymore) * $front = Zend_Controller_Front::getInstance(); if (!$front->getParam('bootstrap') || !$front->getParam('bootstrap')->getResource('cachemanager')) { Garp_Cli::errorOut('no bootstrap or whatever'); return false; } $cacheManager = $front->getParam('bootstrap')->getResource('cachemanager'); $cache = $cacheManager->getCache(Zend_Cache_Manager::PAGECACHE); $cacheDir = $cache->getBackend()->getOption('public_dir'); return $cacheDir; */ }
[ "protected", "static", "function", "_getStaticCacheDir", "(", ")", "{", "$", "config", "=", "Zend_Registry", "::", "get", "(", "'config'", ")", ";", "if", "(", "!", "isset", "(", "$", "config", "->", "resources", "->", "cacheManager", "->", "page", "->", ...
Fetch the cache directory for static caching @return String
[ "Fetch", "the", "cache", "directory", "for", "static", "caching" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cache/Manager.php#L393-L418
46,617
grrr-amsterdam/garp3
library/Garp/Cache/Manager.php
Garp_Cache_Manager._getTagList
protected static function _getTagList() { $config = Zend_Registry::get('config'); if (!empty($config->staticcaching->tags)) { return $config->staticcaching->tags; } // For backward-compatibility: fall back to a separate cache.ini $ini = new Garp_Config_Ini(APPLICATION_PATH . '/configs/cache.ini', APPLICATION_ENV); if (!empty($ini->tags)) { return $ini->tags; } return null; }
php
protected static function _getTagList() { $config = Zend_Registry::get('config'); if (!empty($config->staticcaching->tags)) { return $config->staticcaching->tags; } // For backward-compatibility: fall back to a separate cache.ini $ini = new Garp_Config_Ini(APPLICATION_PATH . '/configs/cache.ini', APPLICATION_ENV); if (!empty($ini->tags)) { return $ini->tags; } return null; }
[ "protected", "static", "function", "_getTagList", "(", ")", "{", "$", "config", "=", "Zend_Registry", "::", "get", "(", "'config'", ")", ";", "if", "(", "!", "empty", "(", "$", "config", "->", "staticcaching", "->", "tags", ")", ")", "{", "return", "$"...
Fetch mapping of available tags to file paths @return Zend_Config
[ "Fetch", "mapping", "of", "available", "tags", "to", "file", "paths" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cache/Manager.php#L425-L438
46,618
grrr-amsterdam/garp3
library/Garp/Model/Db/Info.php
Garp_Model_Db_Info.fetchAsConfig
public function fetchAsConfig(Zend_Db_Select $select = null, $env = APPLICATION_ENV) { if (is_null($select)) { $select = $this->select(); } $results = $this->fetchAll($select); $ini = $this->_createIniFromResults($results, $env); return $ini; }
php
public function fetchAsConfig(Zend_Db_Select $select = null, $env = APPLICATION_ENV) { if (is_null($select)) { $select = $this->select(); } $results = $this->fetchAll($select); $ini = $this->_createIniFromResults($results, $env); return $ini; }
[ "public", "function", "fetchAsConfig", "(", "Zend_Db_Select", "$", "select", "=", "null", ",", "$", "env", "=", "APPLICATION_ENV", ")", "{", "if", "(", "is_null", "(", "$", "select", ")", ")", "{", "$", "select", "=", "$", "this", "->", "select", "(", ...
Fetch results and converts to Zend_Config object @param Zend_Db_Select $select A select object to filter results @param String $env Which application env to use @return Zend_Config
[ "Fetch", "results", "and", "converts", "to", "Zend_Config", "object" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/Info.php#L27-L35
46,619
grrr-amsterdam/garp3
library/Garp/Model/Db/Info.php
Garp_Model_Db_Info._createIniFromResults
protected function _createIniFromResults($results, $env) { // Create a parse_ini_string() compatible string. $ini = "[$env]\n"; foreach ($results as $result) { $keyValue = "{$result->key} = \"{$result->value}\"\n"; $ini .= $keyValue; } $iniObj = Garp_Config_Ini::fromString($ini); return $iniObj; }
php
protected function _createIniFromResults($results, $env) { // Create a parse_ini_string() compatible string. $ini = "[$env]\n"; foreach ($results as $result) { $keyValue = "{$result->key} = \"{$result->value}\"\n"; $ini .= $keyValue; } $iniObj = Garp_Config_Ini::fromString($ini); return $iniObj; }
[ "protected", "function", "_createIniFromResults", "(", "$", "results", ",", "$", "env", ")", "{", "// Create a parse_ini_string() compatible string.", "$", "ini", "=", "\"[$env]\\n\"", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "key...
Create a Zend_Config instance from database results @param Zend_Db_Table_Rowset $results @param Array $config The array that's recursively filled with the right keys @return Zend_Config
[ "Create", "a", "Zend_Config", "instance", "from", "database", "results" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/Info.php#L44-L54
46,620
grrr-amsterdam/garp3
library/Garp/Cli/Command/Log.php
Garp_Cli_Command_Log.clean
public function clean(array $args = array()) { // Resolve parameters $logRoot = array_get($args, 'root', APPLICATION_PATH . '/data/logs'); $pattern = array_get($args, 'pattern', '/\.log$/i'); $threshold = array_get($args, 'threshold', '1 month ago'); $verbose = array_get($args, 'verbose', false); $count = 0; $leanOut = ''; $verboseOut = ''; if ($handle = opendir($logRoot)) { while (false !== ($entry = readdir($handle))) { $isLogFile = preg_match($pattern, $entry); $isTooOld = filemtime($logRoot . '/' . $entry) < strtotime($threshold); if ($isLogFile && $isTooOld) { @unlink($logRoot . '/' . $entry); ++$count; $verboseOut .= " - $entry\n"; } } $leanOut = "$count log files successfully removed"; $verboseOut = $leanOut . ":\n" . $verboseOut; closedir($handle); } if ($count) { if ($verbose) { Garp_Cli::lineOut($verboseOut); } else { Garp_Cli::lineOut($leanOut); } } else { Garp_Cli::lineOut('No log files matched the given criteria.'); } return true; }
php
public function clean(array $args = array()) { // Resolve parameters $logRoot = array_get($args, 'root', APPLICATION_PATH . '/data/logs'); $pattern = array_get($args, 'pattern', '/\.log$/i'); $threshold = array_get($args, 'threshold', '1 month ago'); $verbose = array_get($args, 'verbose', false); $count = 0; $leanOut = ''; $verboseOut = ''; if ($handle = opendir($logRoot)) { while (false !== ($entry = readdir($handle))) { $isLogFile = preg_match($pattern, $entry); $isTooOld = filemtime($logRoot . '/' . $entry) < strtotime($threshold); if ($isLogFile && $isTooOld) { @unlink($logRoot . '/' . $entry); ++$count; $verboseOut .= " - $entry\n"; } } $leanOut = "$count log files successfully removed"; $verboseOut = $leanOut . ":\n" . $verboseOut; closedir($handle); } if ($count) { if ($verbose) { Garp_Cli::lineOut($verboseOut); } else { Garp_Cli::lineOut($leanOut); } } else { Garp_Cli::lineOut('No log files matched the given criteria.'); } return true; }
[ "public", "function", "clean", "(", "array", "$", "args", "=", "array", "(", ")", ")", "{", "// Resolve parameters", "$", "logRoot", "=", "array_get", "(", "$", "args", ",", "'root'", ",", "APPLICATION_PATH", ".", "'/data/logs'", ")", ";", "$", "pattern", ...
Cleanup log files @param array $args @return bool
[ "Cleanup", "log", "files" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Log.php#L33-L69
46,621
grrr-amsterdam/garp3
library/Garp/Image/PngQuant.php
Garp_Image_PngQuant.optimizeData
public function optimizeData($data) { if (!$this->isPngData($data)) { return $data; } // store data in a temporary file to feed pngquant $sourcePath = $this->_getNewTempFilePath(); $this->_store($sourcePath, $data); // run pngquant on temporary file $this->_createOptimizedFile($sourcePath); // retrieve data from optimized file $optimizedFilePath = $this->_getOptimizedFilePath($sourcePath); $optimizedData = $this->_fetchFileData($optimizedFilePath); // verify data $this->_verifyData($optimizedData); unlink($sourcePath); unlink($optimizedFilePath); return $optimizedData; }
php
public function optimizeData($data) { if (!$this->isPngData($data)) { return $data; } // store data in a temporary file to feed pngquant $sourcePath = $this->_getNewTempFilePath(); $this->_store($sourcePath, $data); // run pngquant on temporary file $this->_createOptimizedFile($sourcePath); // retrieve data from optimized file $optimizedFilePath = $this->_getOptimizedFilePath($sourcePath); $optimizedData = $this->_fetchFileData($optimizedFilePath); // verify data $this->_verifyData($optimizedData); unlink($sourcePath); unlink($optimizedFilePath); return $optimizedData; }
[ "public", "function", "optimizeData", "(", "$", "data", ")", "{", "if", "(", "!", "$", "this", "->", "isPngData", "(", "$", "data", ")", ")", "{", "return", "$", "data", ";", "}", "// store data in a temporary file to feed pngquant", "$", "sourcePath", "=",...
Optimizes PNG data. If this is not a PNG, the original data is returned. @param String $data Binary image data @return String $data Optimized binary image data
[ "Optimizes", "PNG", "data", ".", "If", "this", "is", "not", "a", "PNG", "the", "original", "data", "is", "returned", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Image/PngQuant.php#L12-L35
46,622
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Bitlyable.php
Garp_Model_Behavior_Bitlyable.beforeUpdate
public function beforeUpdate(array &$args) { $model = $args[0]; $data = &$args[1]; $where = $args[2]; // When updating, it's quite possible {$this->_column} is not in $data. // If so, collect it live. if (empty($data[$this->_column])) { $row = $model->fetchRow($where); if ($row->{$this->_column}) { $data[$this->_column] = $row->{$this->_column}; } } $this->_setBitlyUrl($data); }
php
public function beforeUpdate(array &$args) { $model = $args[0]; $data = &$args[1]; $where = $args[2]; // When updating, it's quite possible {$this->_column} is not in $data. // If so, collect it live. if (empty($data[$this->_column])) { $row = $model->fetchRow($where); if ($row->{$this->_column}) { $data[$this->_column] = $row->{$this->_column}; } } $this->_setBitlyUrl($data); }
[ "public", "function", "beforeUpdate", "(", "array", "&", "$", "args", ")", "{", "$", "model", "=", "$", "args", "[", "0", "]", ";", "$", "data", "=", "&", "$", "args", "[", "1", "]", ";", "$", "where", "=", "$", "args", "[", "2", "]", ";", ...
Before update callback @param Array $args #return Void
[ "Before", "update", "callback" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Bitlyable.php#L79-L93
46,623
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Bitlyable.php
Garp_Model_Behavior_Bitlyable._setBitlyUrl
protected function _setBitlyUrl(array &$data) { if (!empty($data[$this->_column])) { $bitly = new Garp_Service_Bitly(); $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view'); $url = sprintf($this->_url, $data[$this->_column]); $response = $bitly->shorten(array( 'longUrl' => $view->fullUrl($url) )); if ($response['status_code'] == 200) { $shortenedUrl = $response['data']['url']; $data[$this->_targetColumn] = $shortenedUrl; } } }
php
protected function _setBitlyUrl(array &$data) { if (!empty($data[$this->_column])) { $bitly = new Garp_Service_Bitly(); $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view'); $url = sprintf($this->_url, $data[$this->_column]); $response = $bitly->shorten(array( 'longUrl' => $view->fullUrl($url) )); if ($response['status_code'] == 200) { $shortenedUrl = $response['data']['url']; $data[$this->_targetColumn] = $shortenedUrl; } } }
[ "protected", "function", "_setBitlyUrl", "(", "array", "&", "$", "data", ")", "{", "if", "(", "!", "empty", "(", "$", "data", "[", "$", "this", "->", "_column", "]", ")", ")", "{", "$", "bitly", "=", "new", "Garp_Service_Bitly", "(", ")", ";", "$",...
Set Bit.ly URL @param Array $data Record data passed to an update or insert call @return Void
[ "Set", "Bit", ".", "ly", "URL" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Bitlyable.php#L101-L114
46,624
grrr-amsterdam/garp3
application/modules/g/controllers/AuthController.php
G_AuthController.resetpasswordAction
public function resetpasswordAction() { $this->view->title = __('reset password page title'); $authVars = Garp_Auth::getInstance()->getConfigValues(); $activationCode = $this->getRequest()->getParam('c'); $activationEmail = $this->getRequest()->getParam('e'); $expirationColumn = $authVars['forgotpassword']['activation_code_expiration_date_column']; $userModel = new Model_User(); $activationCodeClause = 'MD5(CONCAT(' . $userModel->getAdapter()->quoteIdentifier( $authVars['forgotpassword']['activation_token_column'] ) . ',' . 'MD5(email),' . 'MD5(' . $userModel->getAdapter()->quote($authVars['salt']) . '),' . 'MD5(id)' . ')) = ?' ; $select = $userModel->select() // check if a user matches up to the given code ->where($activationCodeClause, $activationCode) // check if the given email address is part of the same user record ->where('MD5(email) = ?', $activationEmail); $user = $userModel->fetchRow($select); if (!$user) { $this->view->error = __('reset password user not found'); return; } if (strtotime($user->{$expirationColumn}) < time()) { $this->view->error = __('reset password link expired'); return; } if (!$this->getRequest()->isPost()) { return; } $password = $this->getRequest()->getPost('password'); if (!$password) { $this->view->formError = sprintf(__('%s is a required field'), ucfirst(__('password'))); return; } if (!empty($authVars['forgotpassword']['repeatPassword']) && !empty($authVars['forgotpassword']['repeatPasswordField']) ) { $repeatPasswordField = $this->getRequest()->getPost( $authVars['forgotpassword']['repeatPasswordField'] ); if ($password != $repeatPasswordField) { $this->view->formError = __('the passwords do not match'); return; } } // Update the user's password and send him along to the login page $updateClause = $userModel->getAdapter()->quoteInto('id = ?', $user->id); $userModel->update( array( 'password' => $password, $authVars['forgotpassword']['activation_token_column'] => null, $authVars['forgotpassword']['activation_code_expiration_date_column'] => null ), $updateClause ); $this->_helper->flashMessenger(__($authVars['resetpassword']['success_message'])); $this->_redirect('/g/auth/login'); }
php
public function resetpasswordAction() { $this->view->title = __('reset password page title'); $authVars = Garp_Auth::getInstance()->getConfigValues(); $activationCode = $this->getRequest()->getParam('c'); $activationEmail = $this->getRequest()->getParam('e'); $expirationColumn = $authVars['forgotpassword']['activation_code_expiration_date_column']; $userModel = new Model_User(); $activationCodeClause = 'MD5(CONCAT(' . $userModel->getAdapter()->quoteIdentifier( $authVars['forgotpassword']['activation_token_column'] ) . ',' . 'MD5(email),' . 'MD5(' . $userModel->getAdapter()->quote($authVars['salt']) . '),' . 'MD5(id)' . ')) = ?' ; $select = $userModel->select() // check if a user matches up to the given code ->where($activationCodeClause, $activationCode) // check if the given email address is part of the same user record ->where('MD5(email) = ?', $activationEmail); $user = $userModel->fetchRow($select); if (!$user) { $this->view->error = __('reset password user not found'); return; } if (strtotime($user->{$expirationColumn}) < time()) { $this->view->error = __('reset password link expired'); return; } if (!$this->getRequest()->isPost()) { return; } $password = $this->getRequest()->getPost('password'); if (!$password) { $this->view->formError = sprintf(__('%s is a required field'), ucfirst(__('password'))); return; } if (!empty($authVars['forgotpassword']['repeatPassword']) && !empty($authVars['forgotpassword']['repeatPasswordField']) ) { $repeatPasswordField = $this->getRequest()->getPost( $authVars['forgotpassword']['repeatPasswordField'] ); if ($password != $repeatPasswordField) { $this->view->formError = __('the passwords do not match'); return; } } // Update the user's password and send him along to the login page $updateClause = $userModel->getAdapter()->quoteInto('id = ?', $user->id); $userModel->update( array( 'password' => $password, $authVars['forgotpassword']['activation_token_column'] => null, $authVars['forgotpassword']['activation_code_expiration_date_column'] => null ), $updateClause ); $this->_helper->flashMessenger(__($authVars['resetpassword']['success_message'])); $this->_redirect('/g/auth/login'); }
[ "public", "function", "resetpasswordAction", "(", ")", "{", "$", "this", "->", "view", "->", "title", "=", "__", "(", "'reset password page title'", ")", ";", "$", "authVars", "=", "Garp_Auth", "::", "getInstance", "(", ")", "->", "getConfigValues", "(", ")"...
Allow a user to reset his password after he had forgotten it. @return void
[ "Allow", "a", "user", "to", "reset", "his", "password", "after", "he", "had", "forgotten", "it", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/controllers/AuthController.php#L355-L419
46,625
grrr-amsterdam/garp3
application/modules/g/controllers/AuthController.php
G_AuthController.validateemailAction
public function validateemailAction() { $this->view->title = __('activate email page title'); $auth = Garp_Auth::getInstance(); $authVars = $auth->getConfigValues(); $request = $this->getRequest(); $activationCode = $request->getParam('c'); $activationEmail = $request->getParam('e'); $emailValidColumn = $authVars['validateemail']['email_valid_column']; if (!$activationEmail || !$activationCode) { throw new Zend_Controller_Action_Exception('Invalid request.', 404); } $userModel = new Model_User(); // always collect fresh data for this one $userModel->setCacheQueries(false); $activationCodeClause = 'MD5(CONCAT(' . $userModel->getAdapter()->quoteIdentifier( $authVars['validateemail']['token_column'] ) . ',' . 'MD5(email),' . 'MD5(' . $userModel->getAdapter()->quote($authVars['salt']) . '),' . 'MD5(id)' . ')) = ?' ; $select = $userModel->select() // check if a user matches up to the given code ->where($activationCodeClause, $activationCode) // check if the given email address is part of the same user record ->where('MD5(email) = ?', $activationEmail); $user = $userModel->fetchRow($select); if (!$user) { $this->view->error = __('invalid email activation code'); } else { $user->{$emailValidColumn} = 1; if (!$user->save()) { $this->view->error = __('activate email error'); } elseif ($auth->isLoggedIn()) { // If the user is currently logged in, update the cookie $method = $auth->getStore()->method; $userData = $auth->getUserData(); // Sanity check: is the user that has just validated his email address // the currently logged in user? if ($userData['id'] == $user->id) { $userData[$emailValidColumn] = 1; $auth->store($userData, $method); } } $this->view->user = $user; } }
php
public function validateemailAction() { $this->view->title = __('activate email page title'); $auth = Garp_Auth::getInstance(); $authVars = $auth->getConfigValues(); $request = $this->getRequest(); $activationCode = $request->getParam('c'); $activationEmail = $request->getParam('e'); $emailValidColumn = $authVars['validateemail']['email_valid_column']; if (!$activationEmail || !$activationCode) { throw new Zend_Controller_Action_Exception('Invalid request.', 404); } $userModel = new Model_User(); // always collect fresh data for this one $userModel->setCacheQueries(false); $activationCodeClause = 'MD5(CONCAT(' . $userModel->getAdapter()->quoteIdentifier( $authVars['validateemail']['token_column'] ) . ',' . 'MD5(email),' . 'MD5(' . $userModel->getAdapter()->quote($authVars['salt']) . '),' . 'MD5(id)' . ')) = ?' ; $select = $userModel->select() // check if a user matches up to the given code ->where($activationCodeClause, $activationCode) // check if the given email address is part of the same user record ->where('MD5(email) = ?', $activationEmail); $user = $userModel->fetchRow($select); if (!$user) { $this->view->error = __('invalid email activation code'); } else { $user->{$emailValidColumn} = 1; if (!$user->save()) { $this->view->error = __('activate email error'); } elseif ($auth->isLoggedIn()) { // If the user is currently logged in, update the cookie $method = $auth->getStore()->method; $userData = $auth->getUserData(); // Sanity check: is the user that has just validated his email address // the currently logged in user? if ($userData['id'] == $user->id) { $userData[$emailValidColumn] = 1; $auth->store($userData, $method); } } $this->view->user = $user; } }
[ "public", "function", "validateemailAction", "(", ")", "{", "$", "this", "->", "view", "->", "title", "=", "__", "(", "'activate email page title'", ")", ";", "$", "auth", "=", "Garp_Auth", "::", "getInstance", "(", ")", ";", "$", "authVars", "=", "$", "...
Validate email address. In scenarios where users receive an email validation email, this action is used to validate the address. @return void
[ "Validate", "email", "address", ".", "In", "scenarios", "where", "users", "receive", "an", "email", "validation", "email", "this", "action", "is", "used", "to", "validate", "the", "address", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/controllers/AuthController.php#L427-L478
46,626
grrr-amsterdam/garp3
application/modules/g/controllers/AuthController.php
G_AuthController._setViewSettings
protected function _setViewSettings($action) { $authVars = Garp_Auth::getInstance()->getConfigValues(); if (!isset($authVars[$action])) { return; } $authVars = $authVars[$action]; $module = isset($authVars['module']) ? $authVars['module'] : 'default'; $moduleDirectory = $this->getFrontController() ->getModuleDirectory($module); $viewPath = $moduleDirectory . '/views/scripts/'; $this->view->addScriptPath($viewPath); $view = isset($authVars['view']) ? $authVars['view'] : $action; $this->_helper->viewRenderer($view); $layout = isset($authVars['layout']) ? $authVars['layout'] : 'layout'; if ($this->_helper->layout->isEnabled()) { $this->_helper->layout->setLayoutPath($moduleDirectory . '/views/layouts'); $this->_helper->layout->setLayout($layout); } }
php
protected function _setViewSettings($action) { $authVars = Garp_Auth::getInstance()->getConfigValues(); if (!isset($authVars[$action])) { return; } $authVars = $authVars[$action]; $module = isset($authVars['module']) ? $authVars['module'] : 'default'; $moduleDirectory = $this->getFrontController() ->getModuleDirectory($module); $viewPath = $moduleDirectory . '/views/scripts/'; $this->view->addScriptPath($viewPath); $view = isset($authVars['view']) ? $authVars['view'] : $action; $this->_helper->viewRenderer($view); $layout = isset($authVars['layout']) ? $authVars['layout'] : 'layout'; if ($this->_helper->layout->isEnabled()) { $this->_helper->layout->setLayoutPath($moduleDirectory . '/views/layouts'); $this->_helper->layout->setLayout($layout); } }
[ "protected", "function", "_setViewSettings", "(", "$", "action", ")", "{", "$", "authVars", "=", "Garp_Auth", "::", "getInstance", "(", ")", "->", "getConfigValues", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "authVars", "[", "$", "action", "]", ...
Render a configured view @param string $action Config key @return void
[ "Render", "a", "configured", "view" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/controllers/AuthController.php#L503-L523
46,627
grrr-amsterdam/garp3
application/modules/g/controllers/AuthController.php
G_AuthController._storeRoleInCookie
protected function _storeRoleInCookie() { $userRecord = Garp_Auth::getInstance()->getUserData(); if (!empty($userRecord['role'])) { $cookie = new Garp_Store_Cookie('Garp_Auth'); $cookie->userData = array('role' => $userRecord['role']); } }
php
protected function _storeRoleInCookie() { $userRecord = Garp_Auth::getInstance()->getUserData(); if (!empty($userRecord['role'])) { $cookie = new Garp_Store_Cookie('Garp_Auth'); $cookie->userData = array('role' => $userRecord['role']); } }
[ "protected", "function", "_storeRoleInCookie", "(", ")", "{", "$", "userRecord", "=", "Garp_Auth", "::", "getInstance", "(", ")", "->", "getUserData", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "userRecord", "[", "'role'", "]", ")", ")", "{", "$...
Store user role in cookie, so it can be used with Javascript @return void
[ "Store", "user", "role", "in", "cookie", "so", "it", "can", "be", "used", "with", "Javascript" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/controllers/AuthController.php#L530-L536
46,628
grrr-amsterdam/garp3
application/modules/g/controllers/AuthController.php
G_AuthController._beforeLogin
protected function _beforeLogin( array $authVars, Garp_Auth_Adapter_Abstract $adapter, array $postData ) { if ($loginHelper = $this->_getLoginHelper()) { $loginHelper->beforeLogin($authVars, $adapter, $postData); } }
php
protected function _beforeLogin( array $authVars, Garp_Auth_Adapter_Abstract $adapter, array $postData ) { if ($loginHelper = $this->_getLoginHelper()) { $loginHelper->beforeLogin($authVars, $adapter, $postData); } }
[ "protected", "function", "_beforeLogin", "(", "array", "$", "authVars", ",", "Garp_Auth_Adapter_Abstract", "$", "adapter", ",", "array", "$", "postData", ")", "{", "if", "(", "$", "loginHelper", "=", "$", "this", "->", "_getLoginHelper", "(", ")", ")", "{", ...
Before login hook @param array $authVars Containing auth-related configuration. @param Garp_Auth_Adapter_Abstract $adapter The chosen adapter. @param array $postData @return void
[ "Before", "login", "hook" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/controllers/AuthController.php#L580-L586
46,629
grrr-amsterdam/garp3
application/modules/g/controllers/AuthController.php
G_AuthController._afterLogin
protected function _afterLogin(array $userData, &$targetUrl) { if ($loginHelper = $this->_getLoginHelper()) { $loginHelper->afterLogin($userData, $targetUrl); } }
php
protected function _afterLogin(array $userData, &$targetUrl) { if ($loginHelper = $this->_getLoginHelper()) { $loginHelper->afterLogin($userData, $targetUrl); } }
[ "protected", "function", "_afterLogin", "(", "array", "$", "userData", ",", "&", "$", "targetUrl", ")", "{", "if", "(", "$", "loginHelper", "=", "$", "this", "->", "_getLoginHelper", "(", ")", ")", "{", "$", "loginHelper", "->", "afterLogin", "(", "$", ...
After login hook @param array $userData The data of the logged in user @param string $targetUrl The URL the user is being redirected to @return void
[ "After", "login", "hook" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/controllers/AuthController.php#L595-L599
46,630
grrr-amsterdam/garp3
application/modules/g/controllers/AuthController.php
G_AuthController._getLoginHelper
protected function _getLoginHelper() { $loginHelper = $this->_helper->getHelper('Login'); if (!$loginHelper) { return null; } if (!$loginHelper instanceof Garp_Controller_Helper_Login) { throw new Garp_Auth_Exception(self::EXCEPTION_INVALID_LOGIN_HELPER); } return $loginHelper; }
php
protected function _getLoginHelper() { $loginHelper = $this->_helper->getHelper('Login'); if (!$loginHelper) { return null; } if (!$loginHelper instanceof Garp_Controller_Helper_Login) { throw new Garp_Auth_Exception(self::EXCEPTION_INVALID_LOGIN_HELPER); } return $loginHelper; }
[ "protected", "function", "_getLoginHelper", "(", ")", "{", "$", "loginHelper", "=", "$", "this", "->", "_helper", "->", "getHelper", "(", "'Login'", ")", ";", "if", "(", "!", "$", "loginHelper", ")", "{", "return", "null", ";", "}", "if", "(", "!", "...
Get the Login helper, if registered. @return Zend_Controller_Action_Helper_Abstract
[ "Get", "the", "Login", "helper", "if", "registered", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/controllers/AuthController.php#L630-L639
46,631
grrr-amsterdam/garp3
application/modules/g/controllers/AuthController.php
G_AuthController._getRegisterHelper
protected function _getRegisterHelper() { $registerHelper = $this->_helper->getHelper('Register'); if (!$registerHelper) { return null; } if (!$registerHelper instanceof Garp_Controller_Helper_Register) { throw new Garp_Auth_Exception(self::EXCEPTION_INVALID_REGISTER_HELPER); } return $registerHelper; }
php
protected function _getRegisterHelper() { $registerHelper = $this->_helper->getHelper('Register'); if (!$registerHelper) { return null; } if (!$registerHelper instanceof Garp_Controller_Helper_Register) { throw new Garp_Auth_Exception(self::EXCEPTION_INVALID_REGISTER_HELPER); } return $registerHelper; }
[ "protected", "function", "_getRegisterHelper", "(", ")", "{", "$", "registerHelper", "=", "$", "this", "->", "_helper", "->", "getHelper", "(", "'Register'", ")", ";", "if", "(", "!", "$", "registerHelper", ")", "{", "return", "null", ";", "}", "if", "("...
Get the Register helper, if registered. @return Zend_Controller_Action_Helper_Abstract
[ "Get", "the", "Register", "helper", "if", "registered", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/controllers/AuthController.php#L646-L655
46,632
grrr-amsterdam/garp3
application/modules/g/controllers/AuthController.php
G_AuthController._respondToFaultyProcess
protected function _respondToFaultyProcess(Garp_Auth_Adapter_Abstract $authAdapter) { if ($redirectUrl = $authAdapter->getRedirect()) { $this->_helper->redirector->gotoUrl($redirectUrl); return; } // Show the login page again. $request = clone $this->getRequest(); $request->setActionName('login') ->setParam('errors', $authAdapter->getErrors()) ->setParam('postData', $this->getRequest()->getPost()); $this->_helper->actionStack($request); $this->_setViewSettings('login'); }
php
protected function _respondToFaultyProcess(Garp_Auth_Adapter_Abstract $authAdapter) { if ($redirectUrl = $authAdapter->getRedirect()) { $this->_helper->redirector->gotoUrl($redirectUrl); return; } // Show the login page again. $request = clone $this->getRequest(); $request->setActionName('login') ->setParam('errors', $authAdapter->getErrors()) ->setParam('postData', $this->getRequest()->getPost()); $this->_helper->actionStack($request); $this->_setViewSettings('login'); }
[ "protected", "function", "_respondToFaultyProcess", "(", "Garp_Auth_Adapter_Abstract", "$", "authAdapter", ")", "{", "if", "(", "$", "redirectUrl", "=", "$", "authAdapter", "->", "getRedirect", "(", ")", ")", "{", "$", "this", "->", "_helper", "->", "redirector"...
Auth adapters may return false if no user is logged in yet. We then have a couple of options on how to respond. Showing the login page again with errors would be the default, but some adapters require a redirect to an external site. @param Garp_Auth_Adapter_Abstract $authAdapter @return void
[ "Auth", "adapters", "may", "return", "false", "if", "no", "user", "is", "logged", "in", "yet", ".", "We", "then", "have", "a", "couple", "of", "options", "on", "how", "to", "respond", ".", "Showing", "the", "login", "page", "again", "with", "errors", "...
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/controllers/AuthController.php#L665-L677
46,633
grrr-amsterdam/garp3
library/Garp/Cli/Command/Snippet.php
Garp_Cli_Command_Snippet.create
public function create(array $args = array()) { $this->_overwrite = isset($args['overwrite']) && $args['overwrite']; if (isset($args['i']) || isset($args['interactive'])) { return $this->_createInteractive(); } $file = $this->_parseFileFromArguments($args); $file = APPLICATION_PATH . '/configs/' . $file; $this->_createFromFile($file); return true; }
php
public function create(array $args = array()) { $this->_overwrite = isset($args['overwrite']) && $args['overwrite']; if (isset($args['i']) || isset($args['interactive'])) { return $this->_createInteractive(); } $file = $this->_parseFileFromArguments($args); $file = APPLICATION_PATH . '/configs/' . $file; $this->_createFromFile($file); return true; }
[ "public", "function", "create", "(", "array", "$", "args", "=", "array", "(", ")", ")", "{", "$", "this", "->", "_overwrite", "=", "isset", "(", "$", "args", "[", "'overwrite'", "]", ")", "&&", "$", "args", "[", "'overwrite'", "]", ";", "if", "(", ...
Create new snippet @param array $args @return bool
[ "Create", "new", "snippet" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Snippet.php#L36-L45
46,634
grrr-amsterdam/garp3
library/Garp/Cli/Command/Snippet.php
Garp_Cli_Command_Snippet._createFromFile
protected function _createFromFile($file) { if (!file_exists($file)) { Garp_Cli::errorOut("File not found: {$file}. Adding no snippets."); return false; } $config = new Garp_Config_Ini($file, APPLICATION_ENV); if (!isset($config->snippets)) { Garp_Cli::lineOut('Could not find any snippets. I\'m stopping now... This is awkward.'); return true; } $snippetNoun = 'snippets'; $snippetCount = count($config->snippets); if ($snippetCount === 1) { $snippetNoun = 'snippet'; } Garp_Cli::lineOut("About to add {$snippetCount} {$snippetNoun} from {$file}"); Garp_Cli::lineOut(''); $this->_createSnippets($config->snippets); Garp_Cli::lineOut('Done.'); Garp_Cli::lineOut(''); return true; }
php
protected function _createFromFile($file) { if (!file_exists($file)) { Garp_Cli::errorOut("File not found: {$file}. Adding no snippets."); return false; } $config = new Garp_Config_Ini($file, APPLICATION_ENV); if (!isset($config->snippets)) { Garp_Cli::lineOut('Could not find any snippets. I\'m stopping now... This is awkward.'); return true; } $snippetNoun = 'snippets'; $snippetCount = count($config->snippets); if ($snippetCount === 1) { $snippetNoun = 'snippet'; } Garp_Cli::lineOut("About to add {$snippetCount} {$snippetNoun} from {$file}"); Garp_Cli::lineOut(''); $this->_createSnippets($config->snippets); Garp_Cli::lineOut('Done.'); Garp_Cli::lineOut(''); return true; }
[ "protected", "function", "_createFromFile", "(", "$", "file", ")", "{", "if", "(", "!", "file_exists", "(", "$", "file", ")", ")", "{", "Garp_Cli", "::", "errorOut", "(", "\"File not found: {$file}. Adding no snippets.\"", ")", ";", "return", "false", ";", "}"...
Create a bunch of snippets from a file @param string $file @return bool
[ "Create", "a", "bunch", "of", "snippets", "from", "a", "file" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Snippet.php#L91-L113
46,635
grrr-amsterdam/garp3
library/Garp/Cli/Command/Snippet.php
Garp_Cli_Command_Snippet._createInteractive
protected function _createInteractive() { Garp_Cli::lineOut('Please provide the following values'); $data = array( 'identifier' => Garp_Cli::prompt('Identifier') ); if ($snippet = $this->_fetchExisting($data['identifier'])) { Garp_Cli::lineOut('Snippet already exists. Id: #' . $snippet->id, Garp_Cli::GREEN); return true; } $data['uri'] = Garp_Cli::prompt('Url'); $checks = array( array('has_name', 'Does this snippet have a name?', 'y'), array('has_html', 'Does this snippet contain HTML?', 'y'), array('has_text', 'Does this snippet contain text?', 'n'), array('has_image', 'Does this snippet have an image?', 'n'), ); foreach ($checks as $check) { $key = $check[0]; $question = $check[1]; $default = $check[2]; if ($default == 'y') { $question .= ' Yn'; } elseif ($default == 'n') { $question .= ' yN'; } $userResponse = trim(Garp_Cli::prompt($question)); if (!$userResponse) { $userResponse = $default; } if (strtolower($userResponse) == 'y' || $userResponse == 1) { $data[$key] = 1; } elseif (strtolower($userResponse) == 'n' || $userResponse == 0) { $data[$key] = 0; } } $snippet = $this->_create($data); Garp_Cli::lineOut( 'New snippet inserted. Id: #' . $snippet->id . ', Identifier: "' . $snippet->identifier . '"' ); return true; }
php
protected function _createInteractive() { Garp_Cli::lineOut('Please provide the following values'); $data = array( 'identifier' => Garp_Cli::prompt('Identifier') ); if ($snippet = $this->_fetchExisting($data['identifier'])) { Garp_Cli::lineOut('Snippet already exists. Id: #' . $snippet->id, Garp_Cli::GREEN); return true; } $data['uri'] = Garp_Cli::prompt('Url'); $checks = array( array('has_name', 'Does this snippet have a name?', 'y'), array('has_html', 'Does this snippet contain HTML?', 'y'), array('has_text', 'Does this snippet contain text?', 'n'), array('has_image', 'Does this snippet have an image?', 'n'), ); foreach ($checks as $check) { $key = $check[0]; $question = $check[1]; $default = $check[2]; if ($default == 'y') { $question .= ' Yn'; } elseif ($default == 'n') { $question .= ' yN'; } $userResponse = trim(Garp_Cli::prompt($question)); if (!$userResponse) { $userResponse = $default; } if (strtolower($userResponse) == 'y' || $userResponse == 1) { $data[$key] = 1; } elseif (strtolower($userResponse) == 'n' || $userResponse == 0) { $data[$key] = 0; } } $snippet = $this->_create($data); Garp_Cli::lineOut( 'New snippet inserted. Id: #' . $snippet->id . ', Identifier: "' . $snippet->identifier . '"' ); return true; }
[ "protected", "function", "_createInteractive", "(", ")", "{", "Garp_Cli", "::", "lineOut", "(", "'Please provide the following values'", ")", ";", "$", "data", "=", "array", "(", "'identifier'", "=>", "Garp_Cli", "::", "prompt", "(", "'Identifier'", ")", ")", ";...
Create snippet interactively @return bool
[ "Create", "snippet", "interactively" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Snippet.php#L150-L193
46,636
grrr-amsterdam/garp3
library/Garp/Cli/Command/Snippet.php
Garp_Cli_Command_Snippet._create
protected function _create(array $data) { $this->_validateLoadable(); $snippetModel = new Model_Snippet(); try { $snippetID = $snippetModel->insert($data); $snippet = $snippetModel->fetchRow( $snippetModel->select()->where('id = ?', $snippetID) ); return $snippet; } catch (Garp_Model_Validator_Exception $e) { Garp_Cli::errorOut($e->getMessage()); } }
php
protected function _create(array $data) { $this->_validateLoadable(); $snippetModel = new Model_Snippet(); try { $snippetID = $snippetModel->insert($data); $snippet = $snippetModel->fetchRow( $snippetModel->select()->where('id = ?', $snippetID) ); return $snippet; } catch (Garp_Model_Validator_Exception $e) { Garp_Cli::errorOut($e->getMessage()); } }
[ "protected", "function", "_create", "(", "array", "$", "data", ")", "{", "$", "this", "->", "_validateLoadable", "(", ")", ";", "$", "snippetModel", "=", "new", "Model_Snippet", "(", ")", ";", "try", "{", "$", "snippetID", "=", "$", "snippetModel", "->",...
Insert new snippet @param array $data Snippet data @return Garp_Db_Table_Row
[ "Insert", "new", "snippet" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Snippet.php#L201-L213
46,637
grrr-amsterdam/garp3
library/Garp/Cli/Command/Snippet.php
Garp_Cli_Command_Snippet._fetchExisting
protected function _fetchExisting($identifier) { $this->_validateLoadable(); $snippetModel = new Model_Snippet(); $select = $snippetModel->select() ->where('identifier = ?', $identifier); $row = $snippetModel->fetchRow($select); return $row; }
php
protected function _fetchExisting($identifier) { $this->_validateLoadable(); $snippetModel = new Model_Snippet(); $select = $snippetModel->select() ->where('identifier = ?', $identifier); $row = $snippetModel->fetchRow($select); return $row; }
[ "protected", "function", "_fetchExisting", "(", "$", "identifier", ")", "{", "$", "this", "->", "_validateLoadable", "(", ")", ";", "$", "snippetModel", "=", "new", "Model_Snippet", "(", ")", ";", "$", "select", "=", "$", "snippetModel", "->", "select", "(...
Fetch existing snippet by identifier @param string $identifier @return Garp_Db_Table_Row
[ "Fetch", "existing", "snippet", "by", "identifier" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Snippet.php#L235-L242
46,638
grrr-amsterdam/garp3
library/Garp/Cli/Command/Snippet.php
Garp_Cli_Command_Snippet._validateLoadable
protected function _validateLoadable() { if ($this->_loadable) { return true; } if (!class_exists('Model_Snippet')) { throw new Exception( 'The Snippet model could not be autoloaded. Spawn it first, dumbass!' ); } $this->_loadable = true; return $this->_loadable; }
php
protected function _validateLoadable() { if ($this->_loadable) { return true; } if (!class_exists('Model_Snippet')) { throw new Exception( 'The Snippet model could not be autoloaded. Spawn it first, dumbass!' ); } $this->_loadable = true; return $this->_loadable; }
[ "protected", "function", "_validateLoadable", "(", ")", "{", "if", "(", "$", "this", "->", "_loadable", ")", "{", "return", "true", ";", "}", "if", "(", "!", "class_exists", "(", "'Model_Snippet'", ")", ")", "{", "throw", "new", "Exception", "(", "'The S...
Make sure the snippet model is loadable @return bool
[ "Make", "sure", "the", "snippet", "model", "is", "loadable" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Snippet.php#L249-L260
46,639
grrr-amsterdam/garp3
library/Garp/Cli/Command/Snippet.php
Garp_Cli_Command_Snippet._loadI18nStrings
protected function _loadI18nStrings($locale) { $file = APPLICATION_PATH . '/data/i18n/' . $locale . '.php'; if (!file_exists($file)) { throw new Exception('File not found: ' . $file); } ob_start(); $data = include $file; ob_end_clean(); return $data; }
php
protected function _loadI18nStrings($locale) { $file = APPLICATION_PATH . '/data/i18n/' . $locale . '.php'; if (!file_exists($file)) { throw new Exception('File not found: ' . $file); } ob_start(); $data = include $file; ob_end_clean(); return $data; }
[ "protected", "function", "_loadI18nStrings", "(", "$", "locale", ")", "{", "$", "file", "=", "APPLICATION_PATH", ".", "'/data/i18n/'", ".", "$", "locale", ".", "'.php'", ";", "if", "(", "!", "file_exists", "(", "$", "file", ")", ")", "{", "throw", "new",...
Load i18n strings @param string $locale @return array
[ "Load", "i18n", "strings" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Snippet.php#L268-L277
46,640
grrr-amsterdam/garp3
library/Garp/Service/Google/Chart.php
Garp_Service_Google_Chart.fetchQRCodeUrl
public function fetchQRCodeUrl($refUrl) { $size = 150; $EC_level = 'L'; $margin = 0; $trail = '?qr=1'; return self::CHART_API_URL .'chs='.$size.'x'.$size.'&cht=qr' .'&chld='.$EC_level.'|'.$margin .'&chl=' .urlencode($refUrl.$trail); }
php
public function fetchQRCodeUrl($refUrl) { $size = 150; $EC_level = 'L'; $margin = 0; $trail = '?qr=1'; return self::CHART_API_URL .'chs='.$size.'x'.$size.'&cht=qr' .'&chld='.$EC_level.'|'.$margin .'&chl=' .urlencode($refUrl.$trail); }
[ "public", "function", "fetchQRCodeUrl", "(", "$", "refUrl", ")", "{", "$", "size", "=", "150", ";", "$", "EC_level", "=", "'L'", ";", "$", "margin", "=", "0", ";", "$", "trail", "=", "'?qr=1'", ";", "return", "self", "::", "CHART_API_URL", ".", "'chs...
Fetches the URL to the QR code image for a specific reference URL. @param String $refUrl The unencoded URL this QR code should point to. A QR code identifier is automatically attached at the end @return String URL to the QR code image
[ "Fetches", "the", "URL", "to", "the", "QR", "code", "image", "for", "a", "specific", "reference", "URL", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Service/Google/Chart.php#L28-L39
46,641
grrr-amsterdam/garp3
library/Garp/Spawn/Js/ModelsIncluder.php
Garp_Spawn_Js_ModelsIncluder._save
protected function _save($content) { if (!file_put_contents($this->_getIncludesFilename(), $content)) { throw new Exception(sprintf(self::EXCEPTION_WRITE_ERROR)); } return true; }
php
protected function _save($content) { if (!file_put_contents($this->_getIncludesFilename(), $content)) { throw new Exception(sprintf(self::EXCEPTION_WRITE_ERROR)); } return true; }
[ "protected", "function", "_save", "(", "$", "content", ")", "{", "if", "(", "!", "file_put_contents", "(", "$", "this", "->", "_getIncludesFilename", "(", ")", ",", "$", "content", ")", ")", "{", "throw", "new", "Exception", "(", "sprintf", "(", "self", ...
Write the file @param String $content The full content to write to the includes file. @return bool
[ "Write", "the", "file" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Js/ModelsIncluder.php#L78-L83
46,642
grrr-amsterdam/garp3
library/Garp/Cli/Command/Composer.php
Garp_Cli_Command_Composer.migrate
public function migrate() { $this->_requireGarpComposerPackage(); $this->_updateSymlinks(); $this->_updateIndexPhp(); $this->_updateLocaleFiles(); $this->_updateRoutesInclude(); $this->_updateCapFile(); Garp_Cli::lineOut('Done!'); Garp_Cli::lineOut( 'I\'m leaving the original garp folder in case you ' . 'still have to push something from the subtree.', Garp_Cli::BLUE ); return true; }
php
public function migrate() { $this->_requireGarpComposerPackage(); $this->_updateSymlinks(); $this->_updateIndexPhp(); $this->_updateLocaleFiles(); $this->_updateRoutesInclude(); $this->_updateCapFile(); Garp_Cli::lineOut('Done!'); Garp_Cli::lineOut( 'I\'m leaving the original garp folder in case you ' . 'still have to push something from the subtree.', Garp_Cli::BLUE ); return true; }
[ "public", "function", "migrate", "(", ")", "{", "$", "this", "->", "_requireGarpComposerPackage", "(", ")", ";", "$", "this", "->", "_updateSymlinks", "(", ")", ";", "$", "this", "->", "_updateIndexPhp", "(", ")", ";", "$", "this", "->", "_updateLocaleFile...
Migrate garp to the composer version. @return bool
[ "Migrate", "garp", "to", "the", "composer", "version", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Composer.php#L25-L40
46,643
grrr-amsterdam/garp3
library/Garp/Spawn/Behavior/Type/Sluggable.php
Garp_Spawn_Behavior_Type_Sluggable._baseFieldIsMultilingual
protected function _baseFieldIsMultilingual() { $modelBaseFields = $this->_getModelBaseFields(); foreach ($modelBaseFields as $field) { if ($field->isMultilingual()) { return true; } } return false; }
php
protected function _baseFieldIsMultilingual() { $modelBaseFields = $this->_getModelBaseFields(); foreach ($modelBaseFields as $field) { if ($field->isMultilingual()) { return true; } } return false; }
[ "protected", "function", "_baseFieldIsMultilingual", "(", ")", "{", "$", "modelBaseFields", "=", "$", "this", "->", "_getModelBaseFields", "(", ")", ";", "foreach", "(", "$", "modelBaseFields", "as", "$", "field", ")", "{", "if", "(", "$", "field", "->", "...
Whether one or more base fields are multilingual
[ "Whether", "one", "or", "more", "base", "fields", "are", "multilingual" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Behavior/Type/Sluggable.php#L98-L108
46,644
grrr-amsterdam/garp3
library/Garp/Content/Export/Txt.php
Garp_Content_Export_Txt._formatRow
protected function _formatRow(array $row) { $out = ''; foreach ($row as $key => $value) { if (is_array($value)) { // This is the case with hasMany and hasAndBelongsToMany related // rowsets. $value = $this->_formatRelatedRowset($value); } $out .= "$key: $value\n"; } return $out; }
php
protected function _formatRow(array $row) { $out = ''; foreach ($row as $key => $value) { if (is_array($value)) { // This is the case with hasMany and hasAndBelongsToMany related // rowsets. $value = $this->_formatRelatedRowset($value); } $out .= "$key: $value\n"; } return $out; }
[ "protected", "function", "_formatRow", "(", "array", "$", "row", ")", "{", "$", "out", "=", "''", ";", "foreach", "(", "$", "row", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "// This i...
Format a single row @param array $row @return string
[ "Format", "a", "single", "row" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Export/Txt.php#L43-L54
46,645
grrr-amsterdam/garp3
library/Garp/Model/Behavior/FileRelatable.php
Garp_Model_Behavior_FileRelatable.beforeUpdate
public function beforeUpdate(array &$args) { $data = &$args[1]; foreach ($data as $key => $value) { /** * Save the current file value. * If it differs from the given value, it will be cleared * by afterUpdate. */ if (in_array($key, $this->_fields)) { $this->_newValues[$key] = $value; if (!$this->_affectedRows) { $model = $args[0]; $where = $args[2]; $affectedRows = $model->fetchAll($where); $this->_affectedRows = $affectedRows; } } } }
php
public function beforeUpdate(array &$args) { $data = &$args[1]; foreach ($data as $key => $value) { /** * Save the current file value. * If it differs from the given value, it will be cleared * by afterUpdate. */ if (in_array($key, $this->_fields)) { $this->_newValues[$key] = $value; if (!$this->_affectedRows) { $model = $args[0]; $where = $args[2]; $affectedRows = $model->fetchAll($where); $this->_affectedRows = $affectedRows; } } } }
[ "public", "function", "beforeUpdate", "(", "array", "&", "$", "args", ")", "{", "$", "data", "=", "&", "$", "args", "[", "1", "]", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "/**\n * Save the current f...
Before update callback. Save the original file values here. If they have changed afterUpdate, clear them. @param Array $options The new data is in $args[0] @return Array Or throw Exception if you wish to stop the insert
[ "Before", "update", "callback", ".", "Save", "the", "original", "file", "values", "here", ".", "If", "they", "have", "changed", "afterUpdate", "clear", "them", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/FileRelatable.php#L70-L88
46,646
grrr-amsterdam/garp3
library/Garp/Model/Behavior/FileRelatable.php
Garp_Model_Behavior_FileRelatable.afterUpdate
public function afterUpdate(array &$args) { foreach ($this->_affectedRows as $row) { foreach ($this->_newValues as $key => $value) { // compare the old and new values if ($row->$key != $value) { $this->_deleteFile($row->$key); } } } }
php
public function afterUpdate(array &$args) { foreach ($this->_affectedRows as $row) { foreach ($this->_newValues as $key => $value) { // compare the old and new values if ($row->$key != $value) { $this->_deleteFile($row->$key); } } } }
[ "public", "function", "afterUpdate", "(", "array", "&", "$", "args", ")", "{", "foreach", "(", "$", "this", "->", "_affectedRows", "as", "$", "row", ")", "{", "foreach", "(", "$", "this", "->", "_newValues", "as", "$", "key", "=>", "$", "value", ")",...
After update callback. Clear the files if the columns are modified. We do this afterUpdate to make sure the update succeeded. @param Array $args The new data is in $args[1] @return Void
[ "After", "update", "callback", ".", "Clear", "the", "files", "if", "the", "columns", "are", "modified", ".", "We", "do", "this", "afterUpdate", "to", "make", "sure", "the", "update", "succeeded", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/FileRelatable.php#L97-L106
46,647
grrr-amsterdam/garp3
library/Garp/Form/Element/File.php
Garp_Form_Element_File._getUploadInfoString
protected function _getUploadInfoString() { $maxFileSize = $this->getUploadMaxFilesize(); $allowedExtensions = $this->getAllowedExtensions(); $lastExtension = array_pop($allowedExtensions); $translator = $this->getTranslator(); $uploadInfoStr = $translator->translate('Only %1$s and %2$s files with a maximum of %3$s MB are allowed'); $uploadInfoStr = sprintf($uploadInfoStr, implode(', ', $allowedExtensions), $lastExtension, $maxFileSize); return $uploadInfoStr; }
php
protected function _getUploadInfoString() { $maxFileSize = $this->getUploadMaxFilesize(); $allowedExtensions = $this->getAllowedExtensions(); $lastExtension = array_pop($allowedExtensions); $translator = $this->getTranslator(); $uploadInfoStr = $translator->translate('Only %1$s and %2$s files with a maximum of %3$s MB are allowed'); $uploadInfoStr = sprintf($uploadInfoStr, implode(', ', $allowedExtensions), $lastExtension, $maxFileSize); return $uploadInfoStr; }
[ "protected", "function", "_getUploadInfoString", "(", ")", "{", "$", "maxFileSize", "=", "$", "this", "->", "getUploadMaxFilesize", "(", ")", ";", "$", "allowedExtensions", "=", "$", "this", "->", "getAllowedExtensions", "(", ")", ";", "$", "lastExtension", "=...
Retrieve an informative string describing upload restrictions. @return String
[ "Retrieve", "an", "informative", "string", "describing", "upload", "restrictions", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Form/Element/File.php#L62-L72
46,648
grrr-amsterdam/garp3
library/Garp/Form/Element/File.php
Garp_Form_Element_File.getFileObject
public function getFileObject() { if ($this->getAttrib('data-type') === Garp_File::TYPE_IMAGES) { $file = new Garp_Image_File(); } else { $file = new Garp_File(); } return $file; }
php
public function getFileObject() { if ($this->getAttrib('data-type') === Garp_File::TYPE_IMAGES) { $file = new Garp_Image_File(); } else { $file = new Garp_File(); } return $file; }
[ "public", "function", "getFileObject", "(", ")", "{", "if", "(", "$", "this", "->", "getAttrib", "(", "'data-type'", ")", "===", "Garp_File", "::", "TYPE_IMAGES", ")", "{", "$", "file", "=", "new", "Garp_Image_File", "(", ")", ";", "}", "else", "{", "$...
Get file object based on attribute data-type @return Garp_File
[ "Get", "file", "object", "based", "on", "attribute", "data", "-", "type" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Form/Element/File.php#L101-L108
46,649
grrr-amsterdam/garp3
library/Garp/Spawn/Model/Binding/Factory.php
Garp_Spawn_Model_Binding_Factory._areRulesEgocentricallySorted
protected function _areRulesEgocentricallySorted(array $ruleNames) { $relation = $this->getRelation(); $localModel = $relation->getLocalModel(); return $ruleNames[0] === $localModel->id; }
php
protected function _areRulesEgocentricallySorted(array $ruleNames) { $relation = $this->getRelation(); $localModel = $relation->getLocalModel(); return $ruleNames[0] === $localModel->id; }
[ "protected", "function", "_areRulesEgocentricallySorted", "(", "array", "$", "ruleNames", ")", "{", "$", "relation", "=", "$", "this", "->", "getRelation", "(", ")", ";", "$", "localModel", "=", "$", "relation", "->", "getLocalModel", "(", ")", ";", "return"...
Order in such a way that the reference to the referring model comes before the referred model.
[ "Order", "in", "such", "a", "way", "that", "the", "reference", "to", "the", "referring", "model", "comes", "before", "the", "referred", "model", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Model/Binding/Factory.php#L69-L73
46,650
grrr-amsterdam/garp3
library/Garp/Spawn/Model/Binding/Factory.php
Garp_Spawn_Model_Binding_Factory._getRules
protected function _getRules() { $relation = $this->getRelation(); $localModel = $relation->getLocalModel(); $hasNameConflict = $relation->name === $localModel->id; if ($hasNameConflict) { return array($relation->name . '1', $relation->name . '2'); } $modelIds = $this->_getModelIdsAlphabetically(); $rules = array($relation->name, $this->_getSecondRule()); $rules = $this->_sortRulesEgocentrically($rules); return $rules; }
php
protected function _getRules() { $relation = $this->getRelation(); $localModel = $relation->getLocalModel(); $hasNameConflict = $relation->name === $localModel->id; if ($hasNameConflict) { return array($relation->name . '1', $relation->name . '2'); } $modelIds = $this->_getModelIdsAlphabetically(); $rules = array($relation->name, $this->_getSecondRule()); $rules = $this->_sortRulesEgocentrically($rules); return $rules; }
[ "protected", "function", "_getRules", "(", ")", "{", "$", "relation", "=", "$", "this", "->", "getRelation", "(", ")", ";", "$", "localModel", "=", "$", "relation", "->", "getLocalModel", "(", ")", ";", "$", "hasNameConflict", "=", "$", "relation", "->",...
Returns relation rules, sorted egocentrically. @return Array First rule refers to the model itself, second to the related model referenced in the $relation object.
[ "Returns", "relation", "rules", "sorted", "egocentrically", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Model/Binding/Factory.php#L87-L102
46,651
grrr-amsterdam/garp3
library/Garp/Spawn/Model/Binding/Factory.php
Garp_Spawn_Model_Binding_Factory._getSecondRule
protected function _getSecondRule() { $relation = $this->getRelation(); $firstRule = $relation->name; $hasCustomRelName = $this->_hasCustomRelName(); $modelIds = $this->_getModelIdsAlphabetically(); if ($hasCustomRelName) { return $modelIds[0]; } return $modelIds[0] !== $firstRule ? $modelIds[0] : $modelIds[1] ; }
php
protected function _getSecondRule() { $relation = $this->getRelation(); $firstRule = $relation->name; $hasCustomRelName = $this->_hasCustomRelName(); $modelIds = $this->_getModelIdsAlphabetically(); if ($hasCustomRelName) { return $modelIds[0]; } return $modelIds[0] !== $firstRule ? $modelIds[0] : $modelIds[1] ; }
[ "protected", "function", "_getSecondRule", "(", ")", "{", "$", "relation", "=", "$", "this", "->", "getRelation", "(", ")", ";", "$", "firstRule", "=", "$", "relation", "->", "name", ";", "$", "hasCustomRelName", "=", "$", "this", "->", "_hasCustomRelName"...
Displays second HABTM rule. The first rule is always the name of the direct relation to the end model.
[ "Displays", "second", "HABTM", "rule", ".", "The", "first", "rule", "is", "always", "the", "name", "of", "the", "direct", "relation", "to", "the", "end", "model", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Model/Binding/Factory.php#L107-L121
46,652
grrr-amsterdam/garp3
library/Garp/Spawn/Model/Binding/Factory.php
Garp_Spawn_Model_Binding_Factory._areModelIdsSortedByRule
protected function _areModelIdsSortedByRule(array $modelIds) { $rules = $this->_getRules(); foreach ($modelIds as $modelId) { $ruleNumber = array_search($modelId, $rules); if ($ruleNumber !== false) { return $rules[$ruleNumber] === $modelIds[$ruleNumber]; } } }
php
protected function _areModelIdsSortedByRule(array $modelIds) { $rules = $this->_getRules(); foreach ($modelIds as $modelId) { $ruleNumber = array_search($modelId, $rules); if ($ruleNumber !== false) { return $rules[$ruleNumber] === $modelIds[$ruleNumber]; } } }
[ "protected", "function", "_areModelIdsSortedByRule", "(", "array", "$", "modelIds", ")", "{", "$", "rules", "=", "$", "this", "->", "_getRules", "(", ")", ";", "foreach", "(", "$", "modelIds", "as", "$", "modelId", ")", "{", "$", "ruleNumber", "=", "arra...
Whether modelId sorting is coherent with the egocentric sorting of rules. @return Boolean
[ "Whether", "modelId", "sorting", "is", "coherent", "with", "the", "egocentric", "sorting", "of", "rules", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Model/Binding/Factory.php#L161-L170
46,653
grrr-amsterdam/garp3
library/Garp/Model/Db/Location.php
Garp_Model_Db_Location.normalizeZip
public function normalizeZip($zip) { if (strlen($zip) === 6) { $zip = substr($zip, 0, 4) . ' ' . strtoupper(substr($zip, 4, 2)); } return $zip; }
php
public function normalizeZip($zip) { if (strlen($zip) === 6) { $zip = substr($zip, 0, 4) . ' ' . strtoupper(substr($zip, 4, 2)); } return $zip; }
[ "public", "function", "normalizeZip", "(", "$", "zip", ")", "{", "if", "(", "strlen", "(", "$", "zip", ")", "===", "6", ")", "{", "$", "zip", "=", "substr", "(", "$", "zip", ",", "0", ",", "4", ")", ".", "' '", ".", "strtoupper", "(", "substr",...
Normalize the input so that it matches the stored format.
[ "Normalize", "the", "input", "so", "that", "it", "matches", "the", "stored", "format", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/Location.php#L45-L51
46,654
grrr-amsterdam/garp3
library/Garp/Model/IniFile.php
Garp_Model_IniFile.init
public function init($file, $namespace = null) { $ini = Garp_Config_Ini::getCached($file); if ($namespace) { $namespaces = explode('.', $namespace); do { $namespace = array_shift($namespaces); $ini = $ini->{$namespace}; } while ($namespaces); } $this->_ini = $ini; }
php
public function init($file, $namespace = null) { $ini = Garp_Config_Ini::getCached($file); if ($namespace) { $namespaces = explode('.', $namespace); do { $namespace = array_shift($namespaces); $ini = $ini->{$namespace}; } while ($namespaces); } $this->_ini = $ini; }
[ "public", "function", "init", "(", "$", "file", ",", "$", "namespace", "=", "null", ")", "{", "$", "ini", "=", "Garp_Config_Ini", "::", "getCached", "(", "$", "file", ")", ";", "if", "(", "$", "namespace", ")", "{", "$", "namespaces", "=", "explode",...
Initialize the ini file. @param string $file The path to the ini file @param string $namespace What namespace to use in the ini file @return void
[ "Initialize", "the", "ini", "file", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/IniFile.php#L60-L70
46,655
grrr-amsterdam/garp3
library/Garp/Model/IniFile.php
Garp_Model_IniFile.registerObserver
public function registerObserver(Garp_Util_Observer $observer, $name = false) { $name = $name ?: $observer->getName(); $this->_observers[$name] = $observer; return $this; }
php
public function registerObserver(Garp_Util_Observer $observer, $name = false) { $name = $name ?: $observer->getName(); $this->_observers[$name] = $observer; return $this; }
[ "public", "function", "registerObserver", "(", "Garp_Util_Observer", "$", "observer", ",", "$", "name", "=", "false", ")", "{", "$", "name", "=", "$", "name", "?", ":", "$", "observer", "->", "getName", "(", ")", ";", "$", "this", "->", "_observers", "...
Register observer. The observer will then listen to events broadcasted from this class. @param Garp_Util_Observer $observer The observer @param string $name Optional custom name @return Garp_Util_Observable $this
[ "Register", "observer", ".", "The", "observer", "will", "then", "listen", "to", "events", "broadcasted", "from", "this", "class", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/IniFile.php#L126-L130
46,656
grrr-amsterdam/garp3
library/Garp/Content/Manager/Proxy.php
Garp_Content_Manager_Proxy.pass
public function pass($model, $method, $args = array()) { $manager = new Garp_Content_Manager( Garp_Content_Api::modelAliasToClass($model)); if (!method_exists($manager, $method)) { throw new Garp_Content_Exception('Unknown method requested.'); } $params = !empty($args) ? $args[0] : array(); $result = $this->_produceResult($manager, $method, $params); if ($result instanceof Zend_Db_Table_Rowset_Abstract || $result instanceof Zend_Db_Table_Row_Abstract) { $result = $result->toArray(); } return $result; }
php
public function pass($model, $method, $args = array()) { $manager = new Garp_Content_Manager( Garp_Content_Api::modelAliasToClass($model)); if (!method_exists($manager, $method)) { throw new Garp_Content_Exception('Unknown method requested.'); } $params = !empty($args) ? $args[0] : array(); $result = $this->_produceResult($manager, $method, $params); if ($result instanceof Zend_Db_Table_Rowset_Abstract || $result instanceof Zend_Db_Table_Row_Abstract) { $result = $result->toArray(); } return $result; }
[ "public", "function", "pass", "(", "$", "model", ",", "$", "method", ",", "$", "args", "=", "array", "(", ")", ")", "{", "$", "manager", "=", "new", "Garp_Content_Manager", "(", "Garp_Content_Api", "::", "modelAliasToClass", "(", "$", "model", ")", ")", ...
Pass methods along to Garp_Content_Manager. @param String $model The desired model to manipulate @param String $method The desired method to execute @param Array $args Arguments @return Mixed Whatever the Garp_Content_Manager returns, optionally converted to array.
[ "Pass", "methods", "along", "to", "Garp_Content_Manager", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager/Proxy.php#L19-L34
46,657
grrr-amsterdam/garp3
library/Garp/Content/Manager/Proxy.php
Garp_Content_Manager_Proxy._handleDatabaseException
protected function _handleDatabaseException(Zend_Db_Statement_Exception $e) { if (strpos($e->getMessage(), 'Duplicate entry') === false) { throw $e; } // Note the double spaces in the template string are required since quotes would be // added greedily to the parsed values. list($value, $index) = sscanf($e->getMessage(), 'SQLSTATE[23000]: Integrity constraint violation: ' . '1062 Duplicate entry %s for key %s '); // Throw an exception with a human-friendly error throw new Exception( sprintf(__('%s is already in use, please provide a unique value.'), $value)); }
php
protected function _handleDatabaseException(Zend_Db_Statement_Exception $e) { if (strpos($e->getMessage(), 'Duplicate entry') === false) { throw $e; } // Note the double spaces in the template string are required since quotes would be // added greedily to the parsed values. list($value, $index) = sscanf($e->getMessage(), 'SQLSTATE[23000]: Integrity constraint violation: ' . '1062 Duplicate entry %s for key %s '); // Throw an exception with a human-friendly error throw new Exception( sprintf(__('%s is already in use, please provide a unique value.'), $value)); }
[ "protected", "function", "_handleDatabaseException", "(", "Zend_Db_Statement_Exception", "$", "e", ")", "{", "if", "(", "strpos", "(", "$", "e", "->", "getMessage", "(", ")", ",", "'Duplicate entry'", ")", "===", "false", ")", "{", "throw", "$", "e", ";", ...
Look for 'Duplicate entry' exceptions, and convert to a human-friendly message.
[ "Look", "for", "Duplicate", "entry", "exceptions", "and", "convert", "to", "a", "human", "-", "friendly", "message", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Content/Manager/Proxy.php#L48-L61
46,658
grrr-amsterdam/garp3
library/Garp/Auth/Adapter/Passwordless.php
Garp_Auth_Adapter_Passwordless.requestToken
public function requestToken(array $userData) { if (empty($userData['email'])) { $this->_addError( sprintf( __('%s is a required field'), __('Email') ) ); return false; } $validator = new Zend_Validate_EmailAddress(); if (!$validator->isValid($userData['email'])) { $this->_addError( sprintf( __('%s is not a valid email address'), __('Email') ) ); return false; } $userId = $this->_createOrFetchUserRecord($userData); $token = $this->createOrUpdateAuthRecord($userId); $this->_sendTokenEmail($userData['email'], $userId, $token); $this->setRedirect($this->_getRedirectUrl()); }
php
public function requestToken(array $userData) { if (empty($userData['email'])) { $this->_addError( sprintf( __('%s is a required field'), __('Email') ) ); return false; } $validator = new Zend_Validate_EmailAddress(); if (!$validator->isValid($userData['email'])) { $this->_addError( sprintf( __('%s is not a valid email address'), __('Email') ) ); return false; } $userId = $this->_createOrFetchUserRecord($userData); $token = $this->createOrUpdateAuthRecord($userId); $this->_sendTokenEmail($userData['email'], $userId, $token); $this->setRedirect($this->_getRedirectUrl()); }
[ "public", "function", "requestToken", "(", "array", "$", "userData", ")", "{", "if", "(", "empty", "(", "$", "userData", "[", "'email'", "]", ")", ")", "{", "$", "this", "->", "_addError", "(", "sprintf", "(", "__", "(", "'%s is a required field'", ")", ...
Request a new token @param array $userData @return void @todo Allow different delivery-methods, such as SMS?
[ "Request", "a", "new", "token" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Auth/Adapter/Passwordless.php#L54-L81
46,659
grrr-amsterdam/garp3
library/Garp/Auth/Adapter/Passwordless.php
Garp_Auth_Adapter_Passwordless.acceptToken
public function acceptToken($token, $uid) { if (!$token || !$uid) { $this->_addError(__('Insufficient data received')); return false; } $authPwlessModel = $this->_getPasswordlessModel(); $select = $authPwlessModel->select() ->where('`token` = ?', $token) ->where('user_id = ?', $uid); $row = $authPwlessModel->fetchRow($select); if (!$row || !$row->Model_User) { $this->_addError(__('passwordless token not found')); return false; } // Check wether the user is already logged in. Let's not inconvenience them // with security when it's not that important if ($this->_userIsAlreadyLoggedIn($row)) { return $row->Model_User; } if (!$this->_tokenIsValid($row)) { return false; } $authPwlessModel->getObserver('Authenticatable')->updateLoginStats( $row->Model_User->id, array( 'claimed' => 1 ) ); return $row->Model_User; }
php
public function acceptToken($token, $uid) { if (!$token || !$uid) { $this->_addError(__('Insufficient data received')); return false; } $authPwlessModel = $this->_getPasswordlessModel(); $select = $authPwlessModel->select() ->where('`token` = ?', $token) ->where('user_id = ?', $uid); $row = $authPwlessModel->fetchRow($select); if (!$row || !$row->Model_User) { $this->_addError(__('passwordless token not found')); return false; } // Check wether the user is already logged in. Let's not inconvenience them // with security when it's not that important if ($this->_userIsAlreadyLoggedIn($row)) { return $row->Model_User; } if (!$this->_tokenIsValid($row)) { return false; } $authPwlessModel->getObserver('Authenticatable')->updateLoginStats( $row->Model_User->id, array( 'claimed' => 1 ) ); return $row->Model_User; }
[ "public", "function", "acceptToken", "(", "$", "token", ",", "$", "uid", ")", "{", "if", "(", "!", "$", "token", "||", "!", "$", "uid", ")", "{", "$", "this", "->", "_addError", "(", "__", "(", "'Insufficient data received'", ")", ")", ";", "return",...
Accept a user token @param string $token @param int $uid User id @return Garp_Model_Db Logged in user
[ "Accept", "a", "user", "token" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Auth/Adapter/Passwordless.php#L90-L123
46,660
grrr-amsterdam/garp3
library/Garp/Auth/Adapter/Passwordless.php
Garp_Auth_Adapter_Passwordless.createOrUpdateAuthRecord
public function createOrUpdateAuthRecord($userId) { $token = $this->_getToken($userId); $authPwlessModel = new Model_AuthPasswordless(); $select = $authPwlessModel->select()->where('user_id = ?', $userId); if ($authRecord = $authPwlessModel->fetchRow($select)) { $authPwlessModel->update( array( 'token' => $token, 'token_expiration_date' => $this->_getExpirationDate(), 'claimed' => 0 ), 'id = ' . $authRecord->id ); return $token; } $authPwlessModel->insert( array( 'user_id' => $userId, 'token' => $token, 'token_expiration_date' => $this->_getExpirationDate() ) ); return $token; }
php
public function createOrUpdateAuthRecord($userId) { $token = $this->_getToken($userId); $authPwlessModel = new Model_AuthPasswordless(); $select = $authPwlessModel->select()->where('user_id = ?', $userId); if ($authRecord = $authPwlessModel->fetchRow($select)) { $authPwlessModel->update( array( 'token' => $token, 'token_expiration_date' => $this->_getExpirationDate(), 'claimed' => 0 ), 'id = ' . $authRecord->id ); return $token; } $authPwlessModel->insert( array( 'user_id' => $userId, 'token' => $token, 'token_expiration_date' => $this->_getExpirationDate() ) ); return $token; }
[ "public", "function", "createOrUpdateAuthRecord", "(", "$", "userId", ")", "{", "$", "token", "=", "$", "this", "->", "_getToken", "(", "$", "userId", ")", ";", "$", "authPwlessModel", "=", "new", "Model_AuthPasswordless", "(", ")", ";", "$", "select", "="...
Create auth record containing the token a user can log in with @param int $userId @return string The token
[ "Create", "auth", "record", "containing", "the", "token", "a", "user", "can", "log", "in", "with" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Auth/Adapter/Passwordless.php#L131-L153
46,661
grrr-amsterdam/garp3
library/Garp/Auth/Adapter/Passwordless.php
Garp_Auth_Adapter_Passwordless._getToken
protected function _getToken($userId = null) { if ($userId && $this->_getAuthVars() && array_get($this->_getAuthVars()->toArray(), 'reuse_existing_token') ) { return $this->_fetchExistingToken($userId) ?: $this->_getToken(); } if (function_exists('openssl_random_pseudo_bytes')) { return bin2hex(openssl_random_pseudo_bytes(32)); } return mt_rand(); }
php
protected function _getToken($userId = null) { if ($userId && $this->_getAuthVars() && array_get($this->_getAuthVars()->toArray(), 'reuse_existing_token') ) { return $this->_fetchExistingToken($userId) ?: $this->_getToken(); } if (function_exists('openssl_random_pseudo_bytes')) { return bin2hex(openssl_random_pseudo_bytes(32)); } return mt_rand(); }
[ "protected", "function", "_getToken", "(", "$", "userId", "=", "null", ")", "{", "if", "(", "$", "userId", "&&", "$", "this", "->", "_getAuthVars", "(", ")", "&&", "array_get", "(", "$", "this", "->", "_getAuthVars", "(", ")", "->", "toArray", "(", "...
Generate a unique token. If `reuse_existing_token` is configured thus, we will check if a token is known already for the given userid. @param int $userId @return string
[ "Generate", "a", "unique", "token", ".", "If", "reuse_existing_token", "is", "configured", "thus", "we", "will", "check", "if", "a", "token", "is", "known", "already", "for", "the", "given", "userid", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Auth/Adapter/Passwordless.php#L193-L204
46,662
grrr-amsterdam/garp3
library/Garp/Spawn/Relation/Set.php
Garp_Spawn_Relation_Set._addSingularRelation
protected function _addSingularRelation( array $relationSet, $relName, Garp_Spawn_Relation $relation ) { if ($relation->isSingular()) { $relationSet[$relName] = $relation; } return $relationSet; }
php
protected function _addSingularRelation( array $relationSet, $relName, Garp_Spawn_Relation $relation ) { if ($relation->isSingular()) { $relationSet[$relName] = $relation; } return $relationSet; }
[ "protected", "function", "_addSingularRelation", "(", "array", "$", "relationSet", ",", "$", "relName", ",", "Garp_Spawn_Relation", "$", "relation", ")", "{", "if", "(", "$", "relation", "->", "isSingular", "(", ")", ")", "{", "$", "relationSet", "[", "$", ...
Adds the relation to the relation set, if it's singular. @param array $relationSet The set to add the relation to @param string $relName The relation name @param Garp_Spawn_Relation $relation The relation instance, plural or singular @return array The relation set with the added singular relation
[ "Adds", "the", "relation", "to", "the", "relation", "set", "if", "it", "s", "singular", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Spawn/Relation/Set.php#L262-L270
46,663
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Timestampable.php
Garp_Model_Behavior_Timestampable._setup
protected function _setup($config) { if (empty($config['createdField'])) { $config['createdField'] = 'created'; } if (empty($config['modifiedField'])) { $config['modifiedField'] = 'modified'; } $this->_fields = $config; }
php
protected function _setup($config) { if (empty($config['createdField'])) { $config['createdField'] = 'created'; } if (empty($config['modifiedField'])) { $config['modifiedField'] = 'modified'; } $this->_fields = $config; }
[ "protected", "function", "_setup", "(", "$", "config", ")", "{", "if", "(", "empty", "(", "$", "config", "[", "'createdField'", "]", ")", ")", "{", "$", "config", "[", "'createdField'", "]", "=", "'created'", ";", "}", "if", "(", "empty", "(", "$", ...
Make sure the config array is at least filled with some default values to work with. @param Array $config Configuration values @return Void
[ "Make", "sure", "the", "config", "array", "is", "at", "least", "filled", "with", "some", "default", "values", "to", "work", "with", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Timestampable.php#L32-L40
46,664
grrr-amsterdam/garp3
library/Garp/Model/Validator/Email.php
Garp_Model_Validator_Email.validate
public function validate(array $data, Garp_Model_Db $model, $onlyIfAvailable = true) { $theColumns = $this->_fields; $regexp = self::EMAIL_REGEXP; $validate = function($c) use ($data, $onlyIfAvailable, $regexp) { if ( $onlyIfAvailable && ( !array_key_exists($c, $data) || empty($data[$c]) ) ) { return; } if (empty($data[$c]) || !preg_match($regexp, $data[$c])) { $value = !empty($data[$c]) ? $data[$c] : ''; $error = sprintf(__("'%value%' is not a valid email address in the basic format local-part@hostname"), $value); throw new Garp_Model_Validator_Email_Exception($error); } }; array_walk($theColumns, $validate); }
php
public function validate(array $data, Garp_Model_Db $model, $onlyIfAvailable = true) { $theColumns = $this->_fields; $regexp = self::EMAIL_REGEXP; $validate = function($c) use ($data, $onlyIfAvailable, $regexp) { if ( $onlyIfAvailable && ( !array_key_exists($c, $data) || empty($data[$c]) ) ) { return; } if (empty($data[$c]) || !preg_match($regexp, $data[$c])) { $value = !empty($data[$c]) ? $data[$c] : ''; $error = sprintf(__("'%value%' is not a valid email address in the basic format local-part@hostname"), $value); throw new Garp_Model_Validator_Email_Exception($error); } }; array_walk($theColumns, $validate); }
[ "public", "function", "validate", "(", "array", "$", "data", ",", "Garp_Model_Db", "$", "model", ",", "$", "onlyIfAvailable", "=", "true", ")", "{", "$", "theColumns", "=", "$", "this", "->", "_fields", ";", "$", "regexp", "=", "self", "::", "EMAIL_REGEX...
Validate wether the given columns are not empty @param Array $data The data to validate @param Boolean $onlyIfAvailable Wether to skip validation on fields that are not in the array @return Void @throws Garp_Model_Validator_Exception
[ "Validate", "wether", "the", "given", "columns", "are", "not", "empty" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Validator/Email.php#L44-L64
46,665
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable.getI18nModel
public function getI18nModel(Garp_Model_Db $model) { $modelName = get_class($model); $modelName .= self::I18N_MODEL_SUFFIX; $model = new $modelName; // Do not block unpublished items, we might not get the right record from the fetchRow() // call in self::_saveI18nRecord() if ($draftable = $model->getObserver('Draftable')) { $draftable->setBlockOfflineItems(false); } return $model; }
php
public function getI18nModel(Garp_Model_Db $model) { $modelName = get_class($model); $modelName .= self::I18N_MODEL_SUFFIX; $model = new $modelName; // Do not block unpublished items, we might not get the right record from the fetchRow() // call in self::_saveI18nRecord() if ($draftable = $model->getObserver('Draftable')) { $draftable->setBlockOfflineItems(false); } return $model; }
[ "public", "function", "getI18nModel", "(", "Garp_Model_Db", "$", "model", ")", "{", "$", "modelName", "=", "get_class", "(", "$", "model", ")", ";", "$", "modelName", ".=", "self", "::", "I18N_MODEL_SUFFIX", ";", "$", "model", "=", "new", "$", "modelName",...
Retrieve i18n model @param Garp_Model_Db $model @return Garp_Model_Db
[ "Retrieve", "i18n", "model" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L87-L98
46,666
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable.bindWithI18nModel
public function bindWithI18nModel(Garp_Model_Db $model) { $i18nModel = $this->getI18nModel($model); $model->bindModel( self::I18N_MODEL_BINDING_ALIAS, array( 'modelClass' => $i18nModel, 'conditions' => $i18nModel->select()->from( $i18nModel->getName(), array_merge($this->_translatableFields, array(self::LANG_COLUMN)) ) ) ); }
php
public function bindWithI18nModel(Garp_Model_Db $model) { $i18nModel = $this->getI18nModel($model); $model->bindModel( self::I18N_MODEL_BINDING_ALIAS, array( 'modelClass' => $i18nModel, 'conditions' => $i18nModel->select()->from( $i18nModel->getName(), array_merge($this->_translatableFields, array(self::LANG_COLUMN)) ) ) ); }
[ "public", "function", "bindWithI18nModel", "(", "Garp_Model_Db", "$", "model", ")", "{", "$", "i18nModel", "=", "$", "this", "->", "getI18nModel", "(", "$", "model", ")", ";", "$", "model", "->", "bindModel", "(", "self", "::", "I18N_MODEL_BINDING_ALIAS", ",...
Bind with i18n model @param Garp_Model_Db $model @return Void
[ "Bind", "with", "i18n", "model" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L106-L117
46,667
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable.mergeTranslatedFields
public function mergeTranslatedFields($result) { if (!isset($result->{self::I18N_MODEL_BINDING_ALIAS})) { return; } $translationRecordList = $result->{self::I18N_MODEL_BINDING_ALIAS}; if ($translationRecordList instanceof Zend_Db_Table_Rowset_Abstract) { $translationRecordList = $translationRecordList->toArray(); } $translatedFields = array(); $allLocales = Garp_I18n::getLocales(); foreach ($this->_translatableFields as $translatableField) { // provide default values foreach ($allLocales as $locale) { $translatedFields[$translatableField][$locale] = null; } foreach ($translationRecordList as $translationRecord) { $lang = $translationRecord[self::LANG_COLUMN]; $translatedFields[$translatableField][$lang] = $translationRecord[$translatableField]; } $result->setVirtual($translatableField, $translatedFields[$translatableField]); //$lang] = $translationRecord[$translatableField]; } // We now have a $translatedFields array like this: // array( // "name" => array( // "nl" => "Schaap", // "en" => "Sheep" // ) // ) //$result->setFromArray($translatedFields); unset($result->{self::I18N_MODEL_BINDING_ALIAS}); }
php
public function mergeTranslatedFields($result) { if (!isset($result->{self::I18N_MODEL_BINDING_ALIAS})) { return; } $translationRecordList = $result->{self::I18N_MODEL_BINDING_ALIAS}; if ($translationRecordList instanceof Zend_Db_Table_Rowset_Abstract) { $translationRecordList = $translationRecordList->toArray(); } $translatedFields = array(); $allLocales = Garp_I18n::getLocales(); foreach ($this->_translatableFields as $translatableField) { // provide default values foreach ($allLocales as $locale) { $translatedFields[$translatableField][$locale] = null; } foreach ($translationRecordList as $translationRecord) { $lang = $translationRecord[self::LANG_COLUMN]; $translatedFields[$translatableField][$lang] = $translationRecord[$translatableField]; } $result->setVirtual($translatableField, $translatedFields[$translatableField]); //$lang] = $translationRecord[$translatableField]; } // We now have a $translatedFields array like this: // array( // "name" => array( // "nl" => "Schaap", // "en" => "Sheep" // ) // ) //$result->setFromArray($translatedFields); unset($result->{self::I18N_MODEL_BINDING_ALIAS}); }
[ "public", "function", "mergeTranslatedFields", "(", "$", "result", ")", "{", "if", "(", "!", "isset", "(", "$", "result", "->", "{", "self", "::", "I18N_MODEL_BINDING_ALIAS", "}", ")", ")", "{", "return", ";", "}", "$", "translationRecordList", "=", "$", ...
Merge translated fields into the main records @param Garp_Db_Table_Row $result @return void
[ "Merge", "translated", "fields", "into", "the", "main", "records" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L167-L199
46,668
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._beforeSave
protected function _beforeSave($model, &$data, $where = null) { $localizedData = array(); foreach ($this->_translatableFields as $field) { if (array_key_exists($field, $data)) { $localizedData[$field] = $data[$field]; unset($data[$field]); } } // Can't use values that are not arrays $localizedData = array_filter($localizedData, 'is_array'); // We now have an array containing all values that are provided in one or more languages $languages = Garp_I18n::getLocales(); $existingRows = array_fill_keys($languages, array()); if (!is_null($where)) { $pKeys = $this->_getPrimaryKeysOfAffectedRows($model, $where); if (!count($pKeys)) { // No primary keys found in update? // That means there aren't any affected rows and there's nothing for us to do. return; } $existingRows = $this->_fetchLocalizedRows($languages, $model, $pKeys); } $defaultLanguage = Garp_I18n::getDefaultLocale(); $languages = array_diff($languages, array($defaultLanguage)); foreach ($localizedData as $column => $val) { foreach ($languages as $language) { if (!empty($val[$language])) { // If value provided in language: good! continue; } if (empty($val[$defaultLanguage])) { // No default? Nothing to fall back to continue; } if (!$where) { // If insert, just use default value $localizedData[$column][$language] = $val[$defaultLanguage]; continue; } // Else if update, make sure existing row isn't different from default language row if (!$this->_translatedVersionHasBeenChanged( $existingRows[$defaultLanguage], $existingRows[$language], $column ) ) { $localizedData[$column][$language] = $val[$defaultLanguage]; } } } $this->_queue = $localizedData; }
php
protected function _beforeSave($model, &$data, $where = null) { $localizedData = array(); foreach ($this->_translatableFields as $field) { if (array_key_exists($field, $data)) { $localizedData[$field] = $data[$field]; unset($data[$field]); } } // Can't use values that are not arrays $localizedData = array_filter($localizedData, 'is_array'); // We now have an array containing all values that are provided in one or more languages $languages = Garp_I18n::getLocales(); $existingRows = array_fill_keys($languages, array()); if (!is_null($where)) { $pKeys = $this->_getPrimaryKeysOfAffectedRows($model, $where); if (!count($pKeys)) { // No primary keys found in update? // That means there aren't any affected rows and there's nothing for us to do. return; } $existingRows = $this->_fetchLocalizedRows($languages, $model, $pKeys); } $defaultLanguage = Garp_I18n::getDefaultLocale(); $languages = array_diff($languages, array($defaultLanguage)); foreach ($localizedData as $column => $val) { foreach ($languages as $language) { if (!empty($val[$language])) { // If value provided in language: good! continue; } if (empty($val[$defaultLanguage])) { // No default? Nothing to fall back to continue; } if (!$where) { // If insert, just use default value $localizedData[$column][$language] = $val[$defaultLanguage]; continue; } // Else if update, make sure existing row isn't different from default language row if (!$this->_translatedVersionHasBeenChanged( $existingRows[$defaultLanguage], $existingRows[$language], $column ) ) { $localizedData[$column][$language] = $val[$defaultLanguage]; } } } $this->_queue = $localizedData; }
[ "protected", "function", "_beforeSave", "(", "$", "model", ",", "&", "$", "data", ",", "$", "where", "=", "null", ")", "{", "$", "localizedData", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "_translatableFields", "as", "$", "field",...
Callback before inserting or updating. Extracts translatable fields. @param Garp_Model_Db $model @param Array $data The submitted data @param String $where WHERE clause (in case of update) @return Void
[ "Callback", "before", "inserting", "or", "updating", ".", "Extracts", "translatable", "fields", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L270-L322
46,669
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._afterSave
protected function _afterSave(Garp_Model_Db $model, $pKeys) { if (!$this->_queue) { return; } $locales = Garp_I18n::getLocales(); foreach ($pKeys as $primaryKey) { foreach ($locales as $locale) { $this->_saveI18nRecord($locale, $model, $primaryKey); } } // Reset queue $this->_queue = array(); }
php
protected function _afterSave(Garp_Model_Db $model, $pKeys) { if (!$this->_queue) { return; } $locales = Garp_I18n::getLocales(); foreach ($pKeys as $primaryKey) { foreach ($locales as $locale) { $this->_saveI18nRecord($locale, $model, $primaryKey); } } // Reset queue $this->_queue = array(); }
[ "protected", "function", "_afterSave", "(", "Garp_Model_Db", "$", "model", ",", "$", "pKeys", ")", "{", "if", "(", "!", "$", "this", "->", "_queue", ")", "{", "return", ";", "}", "$", "locales", "=", "Garp_I18n", "::", "getLocales", "(", ")", ";", "f...
Callback after inserting or updating. @param Garp_Model_Db $model @param array $pKeys @return void
[ "Callback", "after", "inserting", "or", "updating", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L370-L382
46,670
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._saveI18nRecord
protected function _saveI18nRecord($language, Garp_Model_Db $model, array $pKeys) { $data = $this->_extractDataForLanguage($language, $model); // If no data was given in the specified language, we don't save anything if (empty($data)) { return; } // Add the language... $data[self::LANG_COLUMN] = $language; // ...and foreign keys $data = $this->_mergeDataWithForeignKeyColumns($data, $model, $pKeys); $i18nModel = $this->getI18nModel($model); $row = $this->_fetchLocalizedRow($language, $model, $pKeys) ?: $i18nModel->createRow(); if (!$row->isConnected()) { $row->setTable($i18nModel); } $row->setFromArray($data); if (!$row->save()) { throw new Garp_Model_Behavior_Exception( sprintf(self::SAVE_IN_LANG_EXCEPTION, $language) ); } return true; }
php
protected function _saveI18nRecord($language, Garp_Model_Db $model, array $pKeys) { $data = $this->_extractDataForLanguage($language, $model); // If no data was given in the specified language, we don't save anything if (empty($data)) { return; } // Add the language... $data[self::LANG_COLUMN] = $language; // ...and foreign keys $data = $this->_mergeDataWithForeignKeyColumns($data, $model, $pKeys); $i18nModel = $this->getI18nModel($model); $row = $this->_fetchLocalizedRow($language, $model, $pKeys) ?: $i18nModel->createRow(); if (!$row->isConnected()) { $row->setTable($i18nModel); } $row->setFromArray($data); if (!$row->save()) { throw new Garp_Model_Behavior_Exception( sprintf(self::SAVE_IN_LANG_EXCEPTION, $language) ); } return true; }
[ "protected", "function", "_saveI18nRecord", "(", "$", "language", ",", "Garp_Model_Db", "$", "model", ",", "array", "$", "pKeys", ")", "{", "$", "data", "=", "$", "this", "->", "_extractDataForLanguage", "(", "$", "language", ",", "$", "model", ")", ";", ...
Save a new i18n record in the given language @param String $language @param Garp_Model_Db $model @param Array $pKeys @return Boolean
[ "Save", "a", "new", "i18n", "record", "in", "the", "given", "language" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L392-L416
46,671
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._extractDataForLanguage
protected function _extractDataForLanguage($language, Garp_Model_Db $model) { $localizedData = array_filter($this->_queue, 'is_array'); $out = array(); foreach ($localizedData as $key => $value) { if (array_key_exists($language, $value)) { $out[$key] = $value[$language]; } } return $out; }
php
protected function _extractDataForLanguage($language, Garp_Model_Db $model) { $localizedData = array_filter($this->_queue, 'is_array'); $out = array(); foreach ($localizedData as $key => $value) { if (array_key_exists($language, $value)) { $out[$key] = $value[$language]; } } return $out; }
[ "protected", "function", "_extractDataForLanguage", "(", "$", "language", ",", "Garp_Model_Db", "$", "model", ")", "{", "$", "localizedData", "=", "array_filter", "(", "$", "this", "->", "_queue", ",", "'is_array'", ")", ";", "$", "out", "=", "array", "(", ...
Make a regular insertable data array from the localized version we saved. @param string $language @param Garp_Model_Db $model @return array
[ "Make", "a", "regular", "insertable", "data", "array", "from", "the", "localized", "version", "we", "saved", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L431-L440
46,672
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._getPrimaryKeysOfAffectedRows
protected function _getPrimaryKeysOfAffectedRows(Garp_Model_Db $model, $where) { if ($draftableObserver = $model->getObserver('Draftable')) { // Unregister so it doesn't screw up the upcoming fetch call $model->unregisterObserver($draftableObserver); } $pkExtractor = new Garp_Db_PrimaryKeyExtractor($model, $where); $pks = $pkExtractor->extract(); if (count($pks)) { return array($pks); } $rows = $model->fetchAll($where); $pks = array(); foreach ($rows as $row) { if (!$row->isConnected()) { $row->setTable($model); } $pks[] = (array)$row->getPrimaryKey(); } if ($draftableObserver) { $model->registerObserver($draftableObserver); } return $pks; }
php
protected function _getPrimaryKeysOfAffectedRows(Garp_Model_Db $model, $where) { if ($draftableObserver = $model->getObserver('Draftable')) { // Unregister so it doesn't screw up the upcoming fetch call $model->unregisterObserver($draftableObserver); } $pkExtractor = new Garp_Db_PrimaryKeyExtractor($model, $where); $pks = $pkExtractor->extract(); if (count($pks)) { return array($pks); } $rows = $model->fetchAll($where); $pks = array(); foreach ($rows as $row) { if (!$row->isConnected()) { $row->setTable($model); } $pks[] = (array)$row->getPrimaryKey(); } if ($draftableObserver) { $model->registerObserver($draftableObserver); } return $pks; }
[ "protected", "function", "_getPrimaryKeysOfAffectedRows", "(", "Garp_Model_Db", "$", "model", ",", "$", "where", ")", "{", "if", "(", "$", "draftableObserver", "=", "$", "model", "->", "getObserver", "(", "'Draftable'", ")", ")", "{", "// Unregister so it doesn't ...
Retrieve primary keys of affected records @param Garp_Model_Db $model @param String $where @return Array
[ "Retrieve", "primary", "keys", "of", "affected", "records" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L449-L472
46,673
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._getForeignKeyData
protected function _getForeignKeyData(array $referenceMap, array $pKeys) { $data = array(); $foreignKeyColumns = $referenceMap['columns']; if (count($foreignKeyColumns) !== count($pKeys)) { throw new Garp_Model_Behavior_Exception( sprintf( self::SAVE_FOREIGN_KEY_EXCEPTION, count($pKeys), count($foreignKeyColumns) ) ); } $data = array_combine($foreignKeyColumns, $pKeys); return $data; }
php
protected function _getForeignKeyData(array $referenceMap, array $pKeys) { $data = array(); $foreignKeyColumns = $referenceMap['columns']; if (count($foreignKeyColumns) !== count($pKeys)) { throw new Garp_Model_Behavior_Exception( sprintf( self::SAVE_FOREIGN_KEY_EXCEPTION, count($pKeys), count($foreignKeyColumns) ) ); } $data = array_combine($foreignKeyColumns, $pKeys); return $data; }
[ "protected", "function", "_getForeignKeyData", "(", "array", "$", "referenceMap", ",", "array", "$", "pKeys", ")", "{", "$", "data", "=", "array", "(", ")", ";", "$", "foreignKeyColumns", "=", "$", "referenceMap", "[", "'columns'", "]", ";", "if", "(", "...
Create array containing the foreign keys in the relationship mapped to the primary keys from the save. @param Array $referenceMap The referenceMap describing the relationship @param Arary $pKeys The given primary keys @return Array
[ "Create", "array", "containing", "the", "foreign", "keys", "in", "the", "relationship", "mapped", "to", "the", "primary", "keys", "from", "the", "save", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L482-L495
46,674
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._cleanClause
protected function _cleanClause($clause) { $clause = trim($clause); while ($clause[0] === '(' && $clause[strlen($clause)-1] === ')') { $clause = substr($clause, 1, -1); } return $clause; }
php
protected function _cleanClause($clause) { $clause = trim($clause); while ($clause[0] === '(' && $clause[strlen($clause)-1] === ')') { $clause = substr($clause, 1, -1); } return $clause; }
[ "protected", "function", "_cleanClause", "(", "$", "clause", ")", "{", "$", "clause", "=", "trim", "(", "$", "clause", ")", ";", "while", "(", "$", "clause", "[", "0", "]", "===", "'('", "&&", "$", "clause", "[", "strlen", "(", "$", "clause", ")", ...
Remove parentheses and whitespace around the clause @param string $clause @return string
[ "Remove", "parentheses", "and", "whitespace", "around", "the", "clause" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L540-L546
46,675
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._joinCmsSearchQuery
protected function _joinCmsSearchQuery( Garp_Model_Db $model, Zend_Db_Select &$select, $likeValue ) { $languages = Garp_I18n::getLocales(); $default_language = array(Garp_I18n::getDefaultLocale()); $langColumn = self::LANG_COLUMN; // Exclude default language, since that's already joined in the joint view $languages = array_diff($languages, $default_language); $adapter = $model->getAdapter(); $where = array(); foreach ($languages as $language) { $i18nModel = $this->getI18nModel($model); $i18nAlias = $model->getName() . '_i18n_' . $language; $onClause = $i18nModel->refMapToOnClause( get_class($model), $i18nAlias, $model->getJointView() ); // join i18n model $select->joinLeft( array($i18nAlias => $i18nModel->getName()), "$onClause AND {$i18nAlias}.{$langColumn} = '{$language}'", array() ); // add WHERE clauses that search in the i18n model $translatedFields = $this->_translatableFields; foreach ($translatedFields as $i18nField) { $where[] = "{$i18nAlias}.{$i18nField} LIKE " . $adapter->quote($likeValue); } } return implode(' OR ', $where); }
php
protected function _joinCmsSearchQuery( Garp_Model_Db $model, Zend_Db_Select &$select, $likeValue ) { $languages = Garp_I18n::getLocales(); $default_language = array(Garp_I18n::getDefaultLocale()); $langColumn = self::LANG_COLUMN; // Exclude default language, since that's already joined in the joint view $languages = array_diff($languages, $default_language); $adapter = $model->getAdapter(); $where = array(); foreach ($languages as $language) { $i18nModel = $this->getI18nModel($model); $i18nAlias = $model->getName() . '_i18n_' . $language; $onClause = $i18nModel->refMapToOnClause( get_class($model), $i18nAlias, $model->getJointView() ); // join i18n model $select->joinLeft( array($i18nAlias => $i18nModel->getName()), "$onClause AND {$i18nAlias}.{$langColumn} = '{$language}'", array() ); // add WHERE clauses that search in the i18n model $translatedFields = $this->_translatableFields; foreach ($translatedFields as $i18nField) { $where[] = "{$i18nAlias}.{$i18nField} LIKE " . $adapter->quote($likeValue); } } return implode(' OR ', $where); }
[ "protected", "function", "_joinCmsSearchQuery", "(", "Garp_Model_Db", "$", "model", ",", "Zend_Db_Select", "&", "$", "select", ",", "$", "likeValue", ")", "{", "$", "languages", "=", "Garp_I18n", "::", "getLocales", "(", ")", ";", "$", "default_language", "=",...
A real hacky solution to enable admins to search for translated content in the CMS @param Garp_Model_Db $model @param Zend_Db_Select $select @param string $likeValue @return string A search clause
[ "A", "real", "hacky", "solution", "to", "enable", "admins", "to", "search", "for", "translated", "content", "in", "the", "CMS" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L556-L589
46,676
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Translatable.php
Garp_Model_Behavior_Translatable._setup
protected function _setup($config) { if (empty($config['columns'])) { throw new Garp_Model_Behavior_Exception(self::MISSING_COLUMNS_EXCEPTION); } $this->_translatableFields = $config['columns']; }
php
protected function _setup($config) { if (empty($config['columns'])) { throw new Garp_Model_Behavior_Exception(self::MISSING_COLUMNS_EXCEPTION); } $this->_translatableFields = $config['columns']; }
[ "protected", "function", "_setup", "(", "$", "config", ")", "{", "if", "(", "empty", "(", "$", "config", "[", "'columns'", "]", ")", ")", "{", "throw", "new", "Garp_Model_Behavior_Exception", "(", "self", "::", "MISSING_COLUMNS_EXCEPTION", ")", ";", "}", "...
Configure this behavior @param Array $config @return Void
[ "Configure", "this", "behavior" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Translatable.php#L597-L602
46,677
grrr-amsterdam/garp3
library/Garp/Cli/Command/S3.php
Garp_Cli_Command_S3.makeBucket
public function makeBucket(array $args = array()) { $bucket = isset($args[0]) ? $args[0] : null; if (is_null($bucket)) { $config = Zend_Registry::get('config'); $bucket = isset($config->cdn->s3->bucket) ? $config->cdn->s3->bucket : null; } if (is_null($bucket)) { Garp_Cli::errorOut('No bucket configured'); return false; } return $this->s3( 'mb', array( 's3://' . $bucket ) ); }
php
public function makeBucket(array $args = array()) { $bucket = isset($args[0]) ? $args[0] : null; if (is_null($bucket)) { $config = Zend_Registry::get('config'); $bucket = isset($config->cdn->s3->bucket) ? $config->cdn->s3->bucket : null; } if (is_null($bucket)) { Garp_Cli::errorOut('No bucket configured'); return false; } return $this->s3( 'mb', array( 's3://' . $bucket ) ); }
[ "public", "function", "makeBucket", "(", "array", "$", "args", "=", "array", "(", ")", ")", "{", "$", "bucket", "=", "isset", "(", "$", "args", "[", "0", "]", ")", "?", "$", "args", "[", "0", "]", ":", "null", ";", "if", "(", "is_null", "(", ...
Create a new bucket on S3. This defaults to the configured bucket. @param array $args @return bool
[ "Create", "a", "new", "bucket", "on", "S3", ".", "This", "defaults", "to", "the", "configured", "bucket", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/S3.php#L18-L33
46,678
grrr-amsterdam/garp3
library/Garp/Cli/Command/S3.php
Garp_Cli_Command_S3.setCors
public function setCors() { $corsConfig = array( 'CORSRules' => array(array( 'AllowedHeaders' => array('*'), 'AllowedMethods' => array('GET'), 'AllowedOrigins' => array('*'), )) ); $args = array( 'bucket' => Zend_Registry::get('config')->cdn->s3->bucket, 'cors-configuration' => "'" . json_encode($corsConfig) . "'" ); return $this->s3api('put-bucket-cors', $args); }
php
public function setCors() { $corsConfig = array( 'CORSRules' => array(array( 'AllowedHeaders' => array('*'), 'AllowedMethods' => array('GET'), 'AllowedOrigins' => array('*'), )) ); $args = array( 'bucket' => Zend_Registry::get('config')->cdn->s3->bucket, 'cors-configuration' => "'" . json_encode($corsConfig) . "'" ); return $this->s3api('put-bucket-cors', $args); }
[ "public", "function", "setCors", "(", ")", "{", "$", "corsConfig", "=", "array", "(", "'CORSRules'", "=>", "array", "(", "array", "(", "'AllowedHeaders'", "=>", "array", "(", "'*'", ")", ",", "'AllowedMethods'", "=>", "array", "(", "'GET'", ")", ",", "'A...
Set CORS settings on bucket @return bool @todo Make CORS options configurable? Do you ever want full-fletched control over these?
[ "Set", "CORS", "settings", "on", "bucket" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/S3.php#L102-L115
46,679
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article._setup
protected function _setup($config) { $config = new Garp_Util_Configuration($config); $config->obligate('contentTypes'); $this->_config = $config; }
php
protected function _setup($config) { $config = new Garp_Util_Configuration($config); $config->obligate('contentTypes'); $this->_config = $config; }
[ "protected", "function", "_setup", "(", "$", "config", ")", "{", "$", "config", "=", "new", "Garp_Util_Configuration", "(", "$", "config", ")", ";", "$", "config", "->", "obligate", "(", "'contentTypes'", ")", ";", "$", "this", "->", "_config", "=", "$",...
Configure the behavior @param array $config @return void
[ "Configure", "the", "behavior" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L31-L35
46,680
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article.bindWithChapters
public function bindWithChapters(Garp_Model_Db &$model) { $chapterModel = new Model_Chapter(); $contentNodeModel = new Model_ContentNode(); $contentNodeModel->setCmsContext($model->isCmsContext()); $chapterModel->bindModel( 'content', array('modelClass' => $contentNodeModel) ); foreach ($this->_config['contentTypes'] as $chapterType) { $chapterAlias = $this->_extractContentTypeAlias($chapterType); $options = $this->_extractContentTypeBindOptions($chapterType, $contentNodeModel); $contentNodeModel->bindModel($chapterAlias, $options); } $model->bindModel( 'chapters', array('modelClass' => $chapterModel) ); }
php
public function bindWithChapters(Garp_Model_Db &$model) { $chapterModel = new Model_Chapter(); $contentNodeModel = new Model_ContentNode(); $contentNodeModel->setCmsContext($model->isCmsContext()); $chapterModel->bindModel( 'content', array('modelClass' => $contentNodeModel) ); foreach ($this->_config['contentTypes'] as $chapterType) { $chapterAlias = $this->_extractContentTypeAlias($chapterType); $options = $this->_extractContentTypeBindOptions($chapterType, $contentNodeModel); $contentNodeModel->bindModel($chapterAlias, $options); } $model->bindModel( 'chapters', array('modelClass' => $chapterModel) ); }
[ "public", "function", "bindWithChapters", "(", "Garp_Model_Db", "&", "$", "model", ")", "{", "$", "chapterModel", "=", "new", "Model_Chapter", "(", ")", ";", "$", "contentNodeModel", "=", "new", "Model_ContentNode", "(", ")", ";", "$", "contentNodeModel", "->"...
Bind all the Chapters and ContentNodes to fetch the complete Article. @param Garp_Model_Db $model @return void
[ "Bind", "all", "the", "Chapters", "and", "ContentNodes", "to", "fetch", "the", "complete", "Article", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L44-L61
46,681
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article.afterFetch
public function afterFetch(&$args) { $results = &$args[1]; $iterator = new Garp_Db_Table_Rowset_Iterator( $results, array($this, 'convertArticleLayout') ); $iterator->walk(); return true; }
php
public function afterFetch(&$args) { $results = &$args[1]; $iterator = new Garp_Db_Table_Rowset_Iterator( $results, array($this, 'convertArticleLayout') ); $iterator->walk(); return true; }
[ "public", "function", "afterFetch", "(", "&", "$", "args", ")", "{", "$", "results", "=", "&", "$", "args", "[", "1", "]", ";", "$", "iterator", "=", "new", "Garp_Db_Table_Rowset_Iterator", "(", "$", "results", ",", "array", "(", "$", "this", ",", "'...
AfterFetch callback, reforms the bound Chapters into a more concise collection. @param array $args Event listener parameters @return void
[ "AfterFetch", "callback", "reforms", "the", "bound", "Chapters", "into", "a", "more", "concise", "collection", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L86-L94
46,682
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article._convertChapterLayout
protected function _convertChapterLayout(array $chapterRow) { $chapter = array(); $chapter['type'] = $chapterRow['type']; if (!isset($chapterRow['content'])) { return $chapter; } $chapter['content'] = array_map( array($this, '_convertContentNodeLayout'), $chapterRow['content'] ); return $chapter; }
php
protected function _convertChapterLayout(array $chapterRow) { $chapter = array(); $chapter['type'] = $chapterRow['type']; if (!isset($chapterRow['content'])) { return $chapter; } $chapter['content'] = array_map( array($this, '_convertContentNodeLayout'), $chapterRow['content'] ); return $chapter; }
[ "protected", "function", "_convertChapterLayout", "(", "array", "$", "chapterRow", ")", "{", "$", "chapter", "=", "array", "(", ")", ";", "$", "chapter", "[", "'type'", "]", "=", "$", "chapterRow", "[", "'type'", "]", ";", "if", "(", "!", "isset", "(",...
Convert bound Chapters to a more concise format. @param array $chapterRow @return array
[ "Convert", "bound", "Chapters", "to", "a", "more", "concise", "format", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L200-L211
46,683
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article._convertContentNodeLayout
protected function _convertContentNodeLayout(array $contentNodeRow) { $contentTypes = $this->_config['contentTypes']; $contentNode = array(); foreach ($contentTypes as $contentType) { $contentType = $this->_extractContentTypeAlias($contentType); if ($contentNodeRow[$contentType]) { $modelName = explode('_', $contentType); $modelName = array_pop($modelName); $contentNode['model'] = $modelName; $contentNode['type'] = $contentNodeRow['type']; $contentNode['data'] = $contentNodeRow[$contentType]; $contentNode['columns'] = $contentNodeRow['columns']; $contentNode['classes'] = $contentNodeRow['classes']; break; } } return $contentNode; }
php
protected function _convertContentNodeLayout(array $contentNodeRow) { $contentTypes = $this->_config['contentTypes']; $contentNode = array(); foreach ($contentTypes as $contentType) { $contentType = $this->_extractContentTypeAlias($contentType); if ($contentNodeRow[$contentType]) { $modelName = explode('_', $contentType); $modelName = array_pop($modelName); $contentNode['model'] = $modelName; $contentNode['type'] = $contentNodeRow['type']; $contentNode['data'] = $contentNodeRow[$contentType]; $contentNode['columns'] = $contentNodeRow['columns']; $contentNode['classes'] = $contentNodeRow['classes']; break; } } return $contentNode; }
[ "protected", "function", "_convertContentNodeLayout", "(", "array", "$", "contentNodeRow", ")", "{", "$", "contentTypes", "=", "$", "this", "->", "_config", "[", "'contentTypes'", "]", ";", "$", "contentNode", "=", "array", "(", ")", ";", "foreach", "(", "$"...
Convert bound ContentNodes to a more concise format. @param array $contentNodeRow @return array
[ "Convert", "bound", "ContentNodes", "to", "a", "more", "concise", "format", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L219-L236
46,684
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article.relateChapters
public function relateChapters(array $chapters, Garp_Model_Db $model, $articleId) { // Start by unrelating all chapters Garp_Content_Relation_Manager::unrelate( array( 'modelA' => $model, 'modelB' => 'Model_Chapter', 'keyA' => $articleId, ) ); // Reverse order since the Weighable behavior sorts chapter by weight DESC, // giving each new chapter the highest weight. $chapters = array_reverse($chapters); foreach ($chapters as $chapterData) { $chapterData = $this->_getValidChapterData($chapterData); /** * Insert a new chapter. * The chapter will take care of storing and relating the * content nodes. */ $chapterModel = new Model_Chapter(); $chapterId = $chapterModel->insert( array( 'type' => $chapterData['type'], 'content' => $chapterData['content'], ) ); Garp_Content_Relation_Manager::relate( array( 'modelA' => $model, 'modelB' => 'Model_Chapter', 'keyA' => $articleId, 'keyB' => $chapterId, ) ); } }
php
public function relateChapters(array $chapters, Garp_Model_Db $model, $articleId) { // Start by unrelating all chapters Garp_Content_Relation_Manager::unrelate( array( 'modelA' => $model, 'modelB' => 'Model_Chapter', 'keyA' => $articleId, ) ); // Reverse order since the Weighable behavior sorts chapter by weight DESC, // giving each new chapter the highest weight. $chapters = array_reverse($chapters); foreach ($chapters as $chapterData) { $chapterData = $this->_getValidChapterData($chapterData); /** * Insert a new chapter. * The chapter will take care of storing and relating the * content nodes. */ $chapterModel = new Model_Chapter(); $chapterId = $chapterModel->insert( array( 'type' => $chapterData['type'], 'content' => $chapterData['content'], ) ); Garp_Content_Relation_Manager::relate( array( 'modelA' => $model, 'modelB' => 'Model_Chapter', 'keyA' => $articleId, 'keyB' => $chapterId, ) ); } }
[ "public", "function", "relateChapters", "(", "array", "$", "chapters", ",", "Garp_Model_Db", "$", "model", ",", "$", "articleId", ")", "{", "// Start by unrelating all chapters", "Garp_Content_Relation_Manager", "::", "unrelate", "(", "array", "(", "'modelA'", "=>", ...
Relate Chapters. Called after insert and after update. @param array $chapters @param Garp_Model_Db $model The subject model @param int $articleId The id of the involved article @return void
[ "Relate", "Chapters", ".", "Called", "after", "insert", "and", "after", "update", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L248-L285
46,685
grrr-amsterdam/garp3
library/Garp/Model/Behavior/Article.php
Garp_Model_Behavior_Article._getValidChapterData
protected function _getValidChapterData($chapterData) { $chapterData = $chapterData instanceof Garp_Util_Configuration ? $chapterData : new Garp_Util_Configuration($chapterData); $chapterData ->obligate('content') ->setDefault('type', ''); return $chapterData; }
php
protected function _getValidChapterData($chapterData) { $chapterData = $chapterData instanceof Garp_Util_Configuration ? $chapterData : new Garp_Util_Configuration($chapterData); $chapterData ->obligate('content') ->setDefault('type', ''); return $chapterData; }
[ "protected", "function", "_getValidChapterData", "(", "$", "chapterData", ")", "{", "$", "chapterData", "=", "$", "chapterData", "instanceof", "Garp_Util_Configuration", "?", "$", "chapterData", ":", "new", "Garp_Util_Configuration", "(", "$", "chapterData", ")", ";...
Convert chapter to Garp_Util_Configuration and validate its keys. @param array|Garp_Util_Configuration $chapterData @return Garp_Util_Configuration
[ "Convert", "chapter", "to", "Garp_Util_Configuration", "and", "validate", "its", "keys", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Behavior/Article.php#L293-L300
46,686
grrr-amsterdam/garp3
library/Garp/Cli/Command/Email.php
Garp_Cli_Command_Email._validateArgs
protected function _validateArgs(array $args): bool { foreach (self::REQUIRED_FLAGS as $flag) { if (!array_key_exists($flag, $args)) { Garp_Cli::errorOut("No {$flag} flag provided."); return false; } } return true; }
php
protected function _validateArgs(array $args): bool { foreach (self::REQUIRED_FLAGS as $flag) { if (!array_key_exists($flag, $args)) { Garp_Cli::errorOut("No {$flag} flag provided."); return false; } } return true; }
[ "protected", "function", "_validateArgs", "(", "array", "$", "args", ")", ":", "bool", "{", "foreach", "(", "self", "::", "REQUIRED_FLAGS", "as", "$", "flag", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "flag", ",", "$", "args", ")", ")", ...
Validates given arguments @param array $args @return boolean
[ "Validates", "given", "arguments" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Email.php#L50-L58
46,687
grrr-amsterdam/garp3
library/Garp/Auth/Adapter/Facebook.php
Garp_Auth_Adapter_Facebook._getFacebookClient
protected function _getFacebookClient() { $authVars = $this->_getAuthVars(); $facebook = Garp_Social_Facebook::getInstance(array( 'appId' => $authVars->appId, 'secret' => $authVars->secret, 'cookie' => false, )); return $facebook; }
php
protected function _getFacebookClient() { $authVars = $this->_getAuthVars(); $facebook = Garp_Social_Facebook::getInstance(array( 'appId' => $authVars->appId, 'secret' => $authVars->secret, 'cookie' => false, )); return $facebook; }
[ "protected", "function", "_getFacebookClient", "(", ")", "{", "$", "authVars", "=", "$", "this", "->", "_getAuthVars", "(", ")", ";", "$", "facebook", "=", "Garp_Social_Facebook", "::", "getInstance", "(", "array", "(", "'appId'", "=>", "$", "authVars", "->"...
Load Facebook's own client @return Facebook
[ "Load", "Facebook", "s", "own", "client" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Auth/Adapter/Facebook.php#L132-L140
46,688
grrr-amsterdam/garp3
application/modules/g/views/helpers/FullUrl.php
G_View_Helper_FullUrl.fullUrl
public function fullUrl($url = false, $omitProtocol = false, $omitBaseUrl = false) { if (!$url) { $url = $this->view->url(); } $fullUrl = new Garp_Util_FullUrl($url, $omitProtocol, $omitBaseUrl); return $fullUrl->__toString(); }
php
public function fullUrl($url = false, $omitProtocol = false, $omitBaseUrl = false) { if (!$url) { $url = $this->view->url(); } $fullUrl = new Garp_Util_FullUrl($url, $omitProtocol, $omitBaseUrl); return $fullUrl->__toString(); }
[ "public", "function", "fullUrl", "(", "$", "url", "=", "false", ",", "$", "omitProtocol", "=", "false", ",", "$", "omitBaseUrl", "=", "false", ")", "{", "if", "(", "!", "$", "url", ")", "{", "$", "url", "=", "$", "this", "->", "view", "->", "url"...
Create full URL from relative URL. @param string|bool $url Relative URL (will be passed thru baseUrl() if $omitBaseUrl = false) @param bool $omitProtocol @param bool $omitBaseUrl @return string Full URL
[ "Create", "full", "URL", "from", "relative", "URL", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/FullUrl.php#L18-L24
46,689
grrr-amsterdam/garp3
library/Garp/Controller/Helper/Upload.php
Garp_Controller_Helper_Upload.uploadRaw
public function uploadRaw($uploadType, $filename, $bytes) { $uploadType = $uploadType ?: Garp_File::TYPE_IMAGES; return array( $filename => $this->_store($uploadType, $filename, $bytes) ); }
php
public function uploadRaw($uploadType, $filename, $bytes) { $uploadType = $uploadType ?: Garp_File::TYPE_IMAGES; return array( $filename => $this->_store($uploadType, $filename, $bytes) ); }
[ "public", "function", "uploadRaw", "(", "$", "uploadType", ",", "$", "filename", ",", "$", "bytes", ")", "{", "$", "uploadType", "=", "$", "uploadType", "?", ":", "Garp_File", "::", "TYPE_IMAGES", ";", "return", "array", "(", "$", "filename", "=>", "$", ...
Upload raw POST data. @param string $uploadType The type of file being uploaded, either 'images' or 'documents' @param string $filename The filename @param string $bytes @return array Response is consistent with self::uploadFromFiles.
[ "Upload", "raw", "POST", "data", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Controller/Helper/Upload.php#L122-L127
46,690
grrr-amsterdam/garp3
library/Garp/Controller/Helper/Upload.php
Garp_Controller_Helper_Upload._store
protected function _store($uploadType, $name, $bytes, $overwrite = false) { if (!array_key_exists($uploadType, $this->_fileHandlers)) { $this->_fileHandlers[$uploadType] = $uploadType === Garp_File::TYPE_IMAGES ? new Garp_Image_File() : new Garp_File($uploadType); } return $this->_fileHandlers[$uploadType]->store($name, $bytes, $overwrite); }
php
protected function _store($uploadType, $name, $bytes, $overwrite = false) { if (!array_key_exists($uploadType, $this->_fileHandlers)) { $this->_fileHandlers[$uploadType] = $uploadType === Garp_File::TYPE_IMAGES ? new Garp_Image_File() : new Garp_File($uploadType); } return $this->_fileHandlers[$uploadType]->store($name, $bytes, $overwrite); }
[ "protected", "function", "_store", "(", "$", "uploadType", ",", "$", "name", ",", "$", "bytes", ",", "$", "overwrite", "=", "false", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "uploadType", ",", "$", "this", "->", "_fileHandlers", ")", ")"...
Store the uploaded bytes in a file. @param string $uploadType The type of file being uploaded, either 'images' or 'documents' @param string $name The filename @param string $bytes @param bool $overwrite @return string The new filename
[ "Store", "the", "uploaded", "bytes", "in", "a", "file", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Controller/Helper/Upload.php#L138-L145
46,691
grrr-amsterdam/garp3
application/modules/g/views/helpers/Browsebox.php
G_View_Helper_Browsebox.browsebox
public function browsebox(Garp_Browsebox $browsebox = null, $params = array()) { if (is_null($browsebox)) { return $this; } static::$_store[$browsebox->getId()] = $browsebox; $params = array_merge( $params, array( 'results' => $browsebox->getResults(), 'next' => $browsebox->getNextUrl(), 'prev' => $browsebox->getPrevUrl() ) ); return $this->view->partial( $browsebox->getViewPath(), 'default', $params ); }
php
public function browsebox(Garp_Browsebox $browsebox = null, $params = array()) { if (is_null($browsebox)) { return $this; } static::$_store[$browsebox->getId()] = $browsebox; $params = array_merge( $params, array( 'results' => $browsebox->getResults(), 'next' => $browsebox->getNextUrl(), 'prev' => $browsebox->getPrevUrl() ) ); return $this->view->partial( $browsebox->getViewPath(), 'default', $params ); }
[ "public", "function", "browsebox", "(", "Garp_Browsebox", "$", "browsebox", "=", "null", ",", "$", "params", "=", "array", "(", ")", ")", "{", "if", "(", "is_null", "(", "$", "browsebox", ")", ")", "{", "return", "$", "this", ";", "}", "static", "::"...
Render a browsebox object @param Garp_Browsebox $browsebox @param array $params Extra parameters sent to the partial @return string
[ "Render", "a", "browsebox", "object" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/Browsebox.php#L24-L42
46,692
grrr-amsterdam/garp3
application/modules/g/views/helpers/Browsebox.php
G_View_Helper_Browsebox.config
public function config($id = false) { $boxes = $this->_getAllBrowseboxes(); if (count($boxes)) { $script = "Garp.browseboxes = [];\n"; foreach ($boxes as $boxId => $box) { $jsConfig = $this->_getJavascriptOptions($box); $boxScript = ''; $boxScript .= "new Garp.Browsebox({\n"; $boxScript .= "\t\"id\": \"$boxId\",\n"; $i = 0; $total = count($jsConfig); foreach ($jsConfig as $confKey => $confVal) { $boxScript .= "\t\"$confKey\": \"$confVal\""; if ($i < ($total-1)) { $boxScript .= ','; } $boxScript .= "\n"; $i++; } $boxScript .= "})"; if ($id && $boxId === $id) { return $this->_wrapInTags($boxScript); } $script .= "Garp.browseboxes.push($boxScript);\n"; } return $this->_wrapInTags($script); } return ''; }
php
public function config($id = false) { $boxes = $this->_getAllBrowseboxes(); if (count($boxes)) { $script = "Garp.browseboxes = [];\n"; foreach ($boxes as $boxId => $box) { $jsConfig = $this->_getJavascriptOptions($box); $boxScript = ''; $boxScript .= "new Garp.Browsebox({\n"; $boxScript .= "\t\"id\": \"$boxId\",\n"; $i = 0; $total = count($jsConfig); foreach ($jsConfig as $confKey => $confVal) { $boxScript .= "\t\"$confKey\": \"$confVal\""; if ($i < ($total-1)) { $boxScript .= ','; } $boxScript .= "\n"; $i++; } $boxScript .= "})"; if ($id && $boxId === $id) { return $this->_wrapInTags($boxScript); } $script .= "Garp.browseboxes.push($boxScript);\n"; } return $this->_wrapInTags($script); } return ''; }
[ "public", "function", "config", "(", "$", "id", "=", "false", ")", "{", "$", "boxes", "=", "$", "this", "->", "_getAllBrowseboxes", "(", ")", ";", "if", "(", "count", "(", "$", "boxes", ")", ")", "{", "$", "script", "=", "\"Garp.browseboxes = [];\\n\""...
Create Javascript configuration for browsebox objects. @param string $id The browsebox id. If given, only config for this browsebox is returned. @return string
[ "Create", "Javascript", "configuration", "for", "browsebox", "objects", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/Browsebox.php#L51-L80
46,693
grrr-amsterdam/garp3
application/modules/g/views/helpers/Browsebox.php
G_View_Helper_Browsebox._getJavascriptOptions
protected function _getJavascriptOptions(Garp_Browsebox $box) { $options = $box->getJavascriptOptions(); $options = $options instanceof Garp_Util_Configuration ? $options : new Garp_Util_Configuration($options); return $options->setDefault('rememberState', false) ->setDefault('transition', 'crossFade'); }
php
protected function _getJavascriptOptions(Garp_Browsebox $box) { $options = $box->getJavascriptOptions(); $options = $options instanceof Garp_Util_Configuration ? $options : new Garp_Util_Configuration($options); return $options->setDefault('rememberState', false) ->setDefault('transition', 'crossFade'); }
[ "protected", "function", "_getJavascriptOptions", "(", "Garp_Browsebox", "$", "box", ")", "{", "$", "options", "=", "$", "box", "->", "getJavascriptOptions", "(", ")", ";", "$", "options", "=", "$", "options", "instanceof", "Garp_Util_Configuration", "?", "$", ...
Get JS options @param Garp_Browsebox $box @return Garp_Util_Configuration
[ "Get", "JS", "options" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/Browsebox.php#L108-L115
46,694
grrr-amsterdam/garp3
application/modules/g/views/helpers/Chapter.php
G_View_Helper_Chapter.render
public function render(array $chapter, array $params = array()) { $partial = 'partials/chapters/' . ($chapter['type'] ?: 'default') . '.phtml'; $params['content'] = $chapter['content']; return $this->view->partial($partial, 'default', $params); }
php
public function render(array $chapter, array $params = array()) { $partial = 'partials/chapters/' . ($chapter['type'] ?: 'default') . '.phtml'; $params['content'] = $chapter['content']; return $this->view->partial($partial, 'default', $params); }
[ "public", "function", "render", "(", "array", "$", "chapter", ",", "array", "$", "params", "=", "array", "(", ")", ")", "{", "$", "partial", "=", "'partials/chapters/'", ".", "(", "$", "chapter", "[", "'type'", "]", "?", ":", "'default'", ")", ".", "...
Render the chapter @param array $chapter @param array $params Additional parameters for the partial. @return string
[ "Render", "the", "chapter" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/Chapter.php#L26-L30
46,695
grrr-amsterdam/garp3
application/modules/g/views/helpers/Chapter.php
G_View_Helper_Chapter.renderContentNode
public function renderContentNode(array $contentNode, array $params = array()) { if (empty($contentNode)) { return ''; } $model = strtolower($contentNode['model']); $type = $contentNode['type'] ?: 'default'; $partial = "partials/chapters/$model/$type.phtml"; $params['contentNode'] = $contentNode; return $this->view->partial($partial, 'default', $params); }
php
public function renderContentNode(array $contentNode, array $params = array()) { if (empty($contentNode)) { return ''; } $model = strtolower($contentNode['model']); $type = $contentNode['type'] ?: 'default'; $partial = "partials/chapters/$model/$type.phtml"; $params['contentNode'] = $contentNode; return $this->view->partial($partial, 'default', $params); }
[ "public", "function", "renderContentNode", "(", "array", "$", "contentNode", ",", "array", "$", "params", "=", "array", "(", ")", ")", "{", "if", "(", "empty", "(", "$", "contentNode", ")", ")", "{", "return", "''", ";", "}", "$", "model", "=", "strt...
Render a content node @param array $contentNode @param array $params Additional parameters for the partial @return string
[ "Render", "a", "content", "node" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/application/modules/g/views/helpers/Chapter.php#L39-L48
46,696
grrr-amsterdam/garp3
library/Garp/Cli/Command/Figlet.php
Garp_Cli_Command_Figlet.display
public function display(array $args = array()) { if (empty($args)) { Garp_Cli::errorOut('The least you can do is provide a text...'); } else { $text = implode(' ', $args); $figlet = new Zend_Text_Figlet(); Garp_Cli::lineOut($figlet->render($text)); } return true; }
php
public function display(array $args = array()) { if (empty($args)) { Garp_Cli::errorOut('The least you can do is provide a text...'); } else { $text = implode(' ', $args); $figlet = new Zend_Text_Figlet(); Garp_Cli::lineOut($figlet->render($text)); } return true; }
[ "public", "function", "display", "(", "array", "$", "args", "=", "array", "(", ")", ")", "{", "if", "(", "empty", "(", "$", "args", ")", ")", "{", "Garp_Cli", "::", "errorOut", "(", "'The least you can do is provide a text...'", ")", ";", "}", "else", "{...
Display a figlet @param array $args @return bool
[ "Display", "a", "figlet" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Cli/Command/Figlet.php#L16-L25
46,697
grrr-amsterdam/garp3
library/Garp/Model/Db/CropTemplate.php
Garp_Model_Db_CropTemplate.fetchAll
public function fetchAll() { $templates = parent::fetchAll(); $out = array(); $id = 1; foreach ($templates as $key => $value) { if (!array_key_exists('richtextable', $value) || !$value['richtextable']) { continue; } $out[] = array( 'id' => $id++, 'name' => $key, 'w' => !empty($value['w']) ? $value['w'] : null, 'h' => !empty($value['h']) ? $value['h'] : null, 'crop' => !empty($value['crop']) ? $value['crop'] : null, 'grow' => !empty($value['grow']) ? $value['grow'] : null ); } return $out; }
php
public function fetchAll() { $templates = parent::fetchAll(); $out = array(); $id = 1; foreach ($templates as $key => $value) { if (!array_key_exists('richtextable', $value) || !$value['richtextable']) { continue; } $out[] = array( 'id' => $id++, 'name' => $key, 'w' => !empty($value['w']) ? $value['w'] : null, 'h' => !empty($value['h']) ? $value['h'] : null, 'crop' => !empty($value['crop']) ? $value['crop'] : null, 'grow' => !empty($value['grow']) ? $value['grow'] : null ); } return $out; }
[ "public", "function", "fetchAll", "(", ")", "{", "$", "templates", "=", "parent", "::", "fetchAll", "(", ")", ";", "$", "out", "=", "array", "(", ")", ";", "$", "id", "=", "1", ";", "foreach", "(", "$", "templates", "as", "$", "key", "=>", "$", ...
Fetch all entries @return array
[ "Fetch", "all", "entries" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/CropTemplate.php#L29-L47
46,698
grrr-amsterdam/garp3
library/Garp/Model/Db/Chapter.php
Garp_Model_Db_Chapter.relateContentNodes
public function relateContentNodes($contentNodeList, $chapterId) { // Reverse node list because the Weighable behavior sorts different from the way // the CMS sends us the nodes. $contentNodeList = array_reverse($contentNodeList); foreach ($contentNodeList as $contentNode) { $node = $this->_getValidContentNodeData($contentNode); // Save ContentNode $node['chapter_id'] = $chapterId; $contentNodeId = $this->_insertContentNode($node); // @todo Move everything below here to Model_ContentNode::afterInsert() // Determine content type $contentTypeModelName = 'Model_'.$node['model']; $contentTypeModel = new $contentTypeModelName(); // Check for existing id $data = $node['data']; if (empty($data['id'])) { // If no id is present, create a new subtype record $contentTypeId = $contentTypeModel->insert($data); } else { // Update the chapter subtype's content $contentTypeModel->update($data, 'id = '.$contentTypeModel->getAdapter()->quote($data['id'])); $contentTypeId = $data['id']; } // Relate the ContentNode to the subtype record Garp_Content_Relation_Manager::relate(array( 'modelA' => 'Model_ContentNode', 'modelB' => $contentTypeModel, 'keyA' => $contentNodeId, 'keyB' => $contentTypeId, )); } }
php
public function relateContentNodes($contentNodeList, $chapterId) { // Reverse node list because the Weighable behavior sorts different from the way // the CMS sends us the nodes. $contentNodeList = array_reverse($contentNodeList); foreach ($contentNodeList as $contentNode) { $node = $this->_getValidContentNodeData($contentNode); // Save ContentNode $node['chapter_id'] = $chapterId; $contentNodeId = $this->_insertContentNode($node); // @todo Move everything below here to Model_ContentNode::afterInsert() // Determine content type $contentTypeModelName = 'Model_'.$node['model']; $contentTypeModel = new $contentTypeModelName(); // Check for existing id $data = $node['data']; if (empty($data['id'])) { // If no id is present, create a new subtype record $contentTypeId = $contentTypeModel->insert($data); } else { // Update the chapter subtype's content $contentTypeModel->update($data, 'id = '.$contentTypeModel->getAdapter()->quote($data['id'])); $contentTypeId = $data['id']; } // Relate the ContentNode to the subtype record Garp_Content_Relation_Manager::relate(array( 'modelA' => 'Model_ContentNode', 'modelB' => $contentTypeModel, 'keyA' => $contentNodeId, 'keyB' => $contentTypeId, )); } }
[ "public", "function", "relateContentNodes", "(", "$", "contentNodeList", ",", "$", "chapterId", ")", "{", "// Reverse node list because the Weighable behavior sorts different from the way", "// the CMS sends us the nodes.", "$", "contentNodeList", "=", "array_reverse", "(", "$", ...
Relate ContentNodes to a chapter. @param Array $contentNodeList @param Int $chapterId @return Void
[ "Relate", "ContentNodes", "to", "a", "chapter", "." ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/Chapter.php#L103-L139
46,699
grrr-amsterdam/garp3
library/Garp/Model/Db/Chapter.php
Garp_Model_Db_Chapter._insertContentNode
protected function _insertContentNode(Garp_Util_Configuration $contentNodeData) { $contentNodeModel = new Model_ContentNode(); $contentNodeId = $contentNodeModel->insert(array( 'columns' => $contentNodeData['columns'], 'classes' => $contentNodeData['classes'], 'type' => $contentNodeData['type'], 'chapter_id' => $contentNodeData['chapter_id'], )); return $contentNodeId; }
php
protected function _insertContentNode(Garp_Util_Configuration $contentNodeData) { $contentNodeModel = new Model_ContentNode(); $contentNodeId = $contentNodeModel->insert(array( 'columns' => $contentNodeData['columns'], 'classes' => $contentNodeData['classes'], 'type' => $contentNodeData['type'], 'chapter_id' => $contentNodeData['chapter_id'], )); return $contentNodeId; }
[ "protected", "function", "_insertContentNode", "(", "Garp_Util_Configuration", "$", "contentNodeData", ")", "{", "$", "contentNodeModel", "=", "new", "Model_ContentNode", "(", ")", ";", "$", "contentNodeId", "=", "$", "contentNodeModel", "->", "insert", "(", "array"...
Insert new ContentNode record @param Garp_Util_Configuration $contentNodeData @return Int The primary key
[ "Insert", "new", "ContentNode", "record" ]
ee6fa716406047568bc5227670748d3b1dd7290d
https://github.com/grrr-amsterdam/garp3/blob/ee6fa716406047568bc5227670748d3b1dd7290d/library/Garp/Model/Db/Chapter.php#L147-L156