Skip to content

Commit

Permalink
Fixed a bug with the Fonts.com project list not showing more than 10 …
Browse files Browse the repository at this point in the history
…projects

Fixed a bug where 1 font returned in Fonts.com would show as several fonts returned and broken

Updated the missing metadata message to be less casual

Switched the grid in Fonts.com to be 5x3 instead of 5x5

Updated the web fonts plugin to be more flexible for a variety of system events

Updated the web fonts plugin to place the javascript include right before the ending header

Switched component package to tar.gz

Fixed a bug where when no domain was added to an initial Fonts.com project it would come back with an empty row
  • Loading branch information
webfonts committed Oct 30, 2011
1 parent 062b437 commit f7c5e05
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 36 deletions.
Binary file modified com_webfonts.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion com_webfonts/admin/helpers/ServiceDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function filterFonts($args){
if($free) $query .= '&wfsFree=' . urlencode($free);
if($alphabet) $query .= '&wfsAlphabet=' . urlencode($alphabet);
$query .= ($limitStart) ? '&wfspstart=' . $limitStart : '&wfspstart=0';
$query .= ($limit) ? '&wfsplimit=' . $limit : '&wfsplimit=25';
$query .= ($limit) ? '&wfsplimit=' . $limit : '&wfsplimit=15';
$query = $base . substr($query, 1);
return $this->wfs_getInfo_post('', $query);
}
Expand Down
9 changes: 6 additions & 3 deletions com_webfonts/admin/helpers/Services_WFS.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

define('ROOT_URL', "%%apiLocation%%");
define('APPKEY', "%%apiKey%%");
define('ROOT_URL', "https://api.fonts.com");
define('APPKEY', "693c8014-ddb8-4282-883e-551b375a2ddb1090995");

define('MAIN_API_URL',"/rest/");

define('PROJECTS', "Projects/");
Expand Down Expand Up @@ -151,6 +152,7 @@ protected function parseOutput($msg, $path, $values){
$arr[MESSAGE] = $message;
if($message == SUCCESS){
//follow the path given as a parameter (e.g. Projects->Project)
if((!property_exists($doc, $path[0])) || (!property_exists($doc->$path[0], $path[1]))) return $arr;
foreach($doc->$path[0]->$path[1] as $e){
//for each object, extract the values requested in parameters (e.g. ProjectName, ProjectKey)
if(is_object($e)){
Expand Down Expand Up @@ -224,7 +226,8 @@ protected function listInternal($what){
* @return an associative array of project name => project key -value pairs or xml/json if completeResponses is true
**/
function listProjects(){
$returnMsg = $this->wfs_getInfo_post("", PROJECTS);
$limit = ($this->wfspParams) ? '?' . substr($this->wfspParams, 1) : '';
$returnMsg = $this->wfs_getInfo_post("", PROJECTS . $limit);

//return whole xml/json and do nothing else?
if($this->completeResponses){
Expand Down
5 changes: 2 additions & 3 deletions com_webfonts/admin/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ CREATE TABLE IF NOT EXISTS `#__webfonts_vendor` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;

INSERT INTO `#__webfonts_vendor` (`id`, `name`, `properties`) VALUES
(1, 'Fonts.com', '{"account":{"email":"","firstName":"","lastName":""},"key":"","designers":{},"foundries":{},"classifications":{},"languages":{},"wfspid":""}'),
(2, 'Google Web Fonts', '{"hash":""}');
(1, 'Fonts.com', '{"account":{"email":"","firstName":"","lastName":""},"key":"","designers":{},"foundries":{},"classifications":{},"languages":{},"wfspid":""}');

CREATE TABLE IF NOT EXISTS `#__webfonts_fontscom` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand All @@ -28,7 +27,7 @@ CREATE TABLE IF NOT EXISTS `#__webfonts_fontscom` (
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;

CREATE TABLE `#__webfonts_google` (
CREATE TABLE IF NOT EXISTS `#__webfonts_google` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`kind` VARCHAR( 100 ) NOT NULL ,
`name` VARCHAR( 150 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
Expand Down
2 changes: 1 addition & 1 deletion com_webfonts/admin/language/en-GB/en-GB.com_webfonts.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ WF_FOUNDRY = "- Foundry -"
WF_DESIGNER = "- Designer -"
WF_CLASSIFICATION = "- Classification -"
WF_LANGUAGE = "- Language -"
WF_MISSING_FONT = "Whoops! This font is missing its pants (and metadata)."
WF_MISSING_FONT = "Sorry, this font is missing metadata and cannot be used."
WF_NOFONTS_MSG = "No fonts were found for your search criteria."
WF_NOFONTS = "Lame! We've got nothing."
WF_RESET = "Reset and Start Again"
Expand Down
8 changes: 5 additions & 3 deletions com_webfonts/admin/models/fontscom.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ protected function _saveAccountAuthKey($key){

public function getProjects(){
if(!$this->_table->properties->key) return false;
$this->_service->setWfspParams('0','50');
$projects = json_decode($this->_service->listProjects());
if((!property_exists($projects, 'Projects')) || ($projects->Projects->Message !== 'Success')) return false;
return $projects->Projects;
Expand All @@ -96,6 +97,7 @@ public function getDomains(){
$this->_service->setProjectKey($wfspid);
$domains = json_decode($this->_service->listDomains());
if((!property_exists($domains, 'Domains')) || ($domains->Domains->Message !== 'Success')) return false;
if(!property_exists($domains->Domains, 'Domain')) return false;
return (!is_array($domains->Domains->Domain)) ? array($domains->Domains->Domain) : $domains->Domains->Domain;
}

Expand Down Expand Up @@ -136,7 +138,7 @@ protected function _projectNameHasNotChanged($post){
}

protected function _saveDomains(&$domains){
if(empty($domains)) return;
if(!is_array($domains)) return;
$current = $this->getDomains();
$this->_processForWWWorHttp($domains);
$response = $this->_saveNewDomains($domains);
Expand Down Expand Up @@ -257,7 +259,7 @@ public function getFonts(){
'AllFonts');
if($response->wasSuccessful()) {
$this->_totalResults = $response->TotalRecords;
return $response->Font;
return (is_array($response->Font)) ? $response->Font : array($response->Font);
}
return false;
}
Expand All @@ -271,7 +273,7 @@ protected function _getFontSearchArguments(){
'keyword' => JRequest::getVar('keyword', '', 'post'),
'alphabet' => JRequest::getVar('alphabet', 'All', 'post'),
'free' => 'all',
'limit' => 25,
'limit' => 15,
'limitStart' => $this->getState('list.start'));
return $this->_fontSearch;
}
Expand Down
3 changes: 2 additions & 1 deletion com_webfonts/admin/uninstall.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DROP TABLE IF EXISTS `#__webfonts`;
DROP TABLE IF EXISTS `#__webfonts_vendor`;
DROP TABLE IF EXISTS `#__webfonts_fontscom`;
DROP TABLE IF EXISTS `#__webfonts_fontscom`;
DROP TABLE IF EXISTS `#__webfonts_google`;
2 changes: 1 addition & 1 deletion com_webfonts/admin/views/fontscom/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@

<?php endif; //End have we selected a project ?>

<input type="hidden" name="limit" id="realLimit" value="25" />
<input type="hidden" name="limit" id="realLimit" value="15" />
<input type="hidden" name="option" value="com_webfonts" />
<input type="hidden" name="view" value="fontscom" />
<input type="hidden" name="editingFonts" value="1" />
Expand Down
Binary file removed plg_webfonts.tar.bz2
Binary file not shown.
Binary file added plg_webfonts.tar.gz
Binary file not shown.
34 changes: 27 additions & 7 deletions plugins/webfonts/handlers/fontscom.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,48 @@

defined ('_JEXEC') or die();

class PluginWebfontsFontscom implements PluginWebfonts {
class PluginWebfontsFontscom {

public function execute(){
protected $_key = false;
protected $_isAdmin = null;

public function onBeforeCompileHead(){
if($this->_isAdmin()) return;
$key = $this->_getActiveProject();
if(!$key) return false;
$doc = JFactory::getDocument();
$doc->addScript("http://fast.fonts.com/jsapi/{$key}.js");
$fallBack = $this->_buildFallbackDeclarations($key);
if($fallBack) $doc->addStyledeclaration($fallBack);
}

/* Has to be last line in Head element to override equivalent styles */
public function onAfterRender(){
if($this->_isAdmin()) return;
$response = JResponse::getBody();
$key = $this->_getActiveProject();
if(!$key) return false;
$link = "<script type=\"text/javascript\" src=\"http://fast.fonts.com/jsapi/{$key}.js\"></script>";
$link .= "<!-- Fonts.com CDN call -->" . PHP_EOL . "</head>";
// Manipulating this causes the event to be called again, so we do a check here
if(strpos($response, '<!-- Fonts.com CDN call -->') > 0) return;
$response = str_ireplace('</head>', $link, $response);
JResponse::setBody($response);
}

protected function _isAdmin(){
$user = JFactory::getUser();
return in_array('8', $user->getAuthorisedGroups());
if($this->_isAdmin !== null) return $this->_isAdmin;
$app =& JFactory::getApplication();
$this->_isAdmin = $app->isAdmin();
return $this->_isAdmin;
}

protected function _getActiveProject(){
$db = JFactory::getDBO();
$key = $this->_getProjectKey($db);
if($this->_projectHasFonts($db, $key)) return $key;
return false;
if($this->_projectHasFonts($db, $key)) {
$this->_key = $key;
}
return $this->_key;
}

protected function _getProjectKey(&$db){
Expand Down
33 changes: 17 additions & 16 deletions plugins/webfonts/webfonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@

jimport('joomla.event.plugin');

/*
This class essentially dispatches the same system events
to multiple Web Fonts vendor specific implementations in
the handlers folder
*/

class plgSystemWebfonts extends JPlugin {

protected $_onBeforeCompileHead = array('fontscom.php' => 'fontscom');
protected $_onBeforeCompileHead = array('fontscom.php' => 'fontscom');
protected $_onAfterRender = array('fontscom.php' => 'fontscom');
protected $_active = array();

/* Othersystem events can be initiated by creating a method
signature mapped to the desired files in the same manner as this
one */

public function onBeforeCompileHead(){
$this->_initHandlers('_onBeforeCompileHead');
$this->_fireActive();
$this->_fireActive('onBeforeCompileHead');
}

public function onAfterRender(){
$this->_initHandlers('_onAfterRender');
$this->_fireActive('onAfterRender');
}

protected function _fireActive(){
protected function _fireActive($evt){
foreach($this->_active as $plugin){
$plugin->execute();
$plugin->$evt();
}
}

Expand All @@ -29,16 +37,9 @@ protected function _initHandlers($event){
if(file_exists(dirname(__FILE__) . "/handlers/$filename")){
include_once(dirname(__FILE__) . "/handlers/$filename");
$className = 'PluginWebfonts' . ucfirst($handler);
if(class_exists($className)) $this->_active[] = new $className;
if(class_exists($className)) $this->_active[] = new $className();
}
}
}

}


interface PluginWebfonts {

public function execute();

}

0 comments on commit f7c5e05

Please sign in to comment.